Archive for the ‘Coding’ Category

Cinnamon applets

Tuesday, November 26th, 2013

So after trying Gnome 3 for quite some time, I’ve moved on to Cinnamon nowdays.

Strangely, one thing that I sorely missed was a certain extension: Media player indicator.

At first I was resigned, having dealt with coding gnome shell extensions before (such as Pidgin integration) I thought I was in for a world of hurt if I tried.
Turns out, Cinnamon developers recognise this pain, and have specifically designed ‘applets’ with an API which is stable across versions, allowing for nice simple plugins for their bar! They even include some nice ones – their volume applet worked with Spotify out of the box, just didn’t display the title / album art on the bar.

After a quick tutorial I got the code for the applet, and it was suprisingly easy to add it in!

Check it out on cinnamon-spices or just use the cinnamon settings app to download it… nice!

Figured it was worth making a pull request for as well. I love github sometimes.

Facebook Event exports take two

Friday, February 8th, 2013

So a while ago I wrote a php script to make facebook event names appear properly on google calendar.
I’ve since noticed that all ‘full day’ events on facebook get exported as though they are on the previous day! Someone has written a page to do this, but the source code is not available and so it depends if you trust them with your events or not.

As such I updated my php script to do this date change too! Code below, but if you want to use it on my site:

Get the uid and the key from your events page on facebook by clicking the gear in the top right, and export events, then get the URL of ‘upcoming events’.

For adding this to google calendar use webcal:// instead of http://


// Facebook uses ZULU time for it's exports.

function inc_date($matches) {
        $date = new DateTime($matches[2]);
        $date->add(new DateInterval('P1D'));
        return "DT".$matches[1].":".$date->format('Ymd');
$ical = "".$_GET['uid']."&key=".$_GET['key'];

$pattern = "#DT(START|END):([0-9]{8})[\n\r]#";
$file = preg_replace_callback($pattern, "inc_date", $file);

header("Content-Type: text/Calendar");
// Give the file a name and force download
header("Content-Disposition: inline; filename=events.ics");

Exporting facebook events to google calendar

Saturday, May 21st, 2011

Update:This script has been updated to update dates on full day events as well.

Just a small php script I’ve been using so Google Calendar actually shows private facebook events on your calendar.
For some reason when Google Calendar sees an ics file with it’s class set to private, it thinks even you shouldn’t be able to see it on your own calendar :\

Get the ical link from facebook by clicking ‘export events’ on this page:


$ical = "*link here*";

header("Content-Type: text/Calendar");

// Give the file a name and force download
header("Content-Disposition: inline; filename=events.ics");

Publishing shared google reader items to twitter.

Wednesday, March 16th, 2011

Seems Feedburner by google which I’ve been using up until now is unreliable with posting to twitter, so this is a half post on what I’ve done to try getting it working, and half a post trying to test if it works with my wordpress at least 😛

Because Google reader’s rss feed of shared items is formatted a little strangely I made a short php script to parse it into a nicer format. OK, mainly getting rid of the annoying ‘Shared by <username> ‘ bit.


$username = "Psykar";

$url = "";
$page = file_get_contents($url);

echo preg_replace('/Shared +by +'.$username.'/',null,$page);


To find your shared items url, just open reader, get the url which gets replaced, and remove the html entities %2F either side of the ID
eg for mine:

is 10440293858886564202

Plug this ID into the URL above;userid&gt;/state/

I then used feedburner to import this php script (hosted on my server) and activated the ‘socialize’ feature, which should be publishing all my shared items to twitter now, in a nice format.

File recovery

Wednesday, December 22nd, 2010

So someone left us with a corrupt USB stick at work a couple of days ago, no joy with that, but she had a USB stick which was still working which she had deleted the same data off recently, and it hadn’t been used since.
After a crapload of mucking around and a lot of reference to

I combined elements of all the above to the following script which recovered most of the deleted files.

The main trick was the arguments on icat – I was confused for a while because it was finding all the files, but only creating 4kb of them. Turns out I needed the -r -a arguments.

Script is below, run on a file created by the following command

# The -r argument is used to recover only deleted files
ils -r /media/Images/USBImage | awk -F '|' '{print $1}' &gt; /tmp/inodes

# This was due to taking the raw disk data rather than just the partition
# The offset was found using autopsy - part of sleuth tools, used for this.
imgargs=" -f fat -o 63 ${imgpath} "

for inode in $(cat /tmp/inodes) ; do

	ffind ${imgargs} $inode

	if [ $? -eq 0 ]
		echo "INODE: $inode"
		INODEDIR=$(ffind ${imgargs} $inode | awk -F "* " '{print $2}')
		REALDIR=${outpath}$(dirname -- "$INODEDIR")
		mkdir -p "$REALDIR"
		# I found this worked better than the method used by one of the links
		# to create directories. What happens is a directory inode may create
		# a file if a later file tries to write to a directory which IS a
		# file, the file is removed and the directory is created instead
		if [ $? -eq 1 ]
			rm -R "${REALDIR}"
			mkdir -p "${REALDIR}"

		#echo "${imgargs} $inode &gt; $FILENAME"
		icat -r -s ${imgargs} $inode &gt; "$FILENAME"

		echo ""