Wednesday 31 December 2008

Gnome wallpaper switching

Having gathered a few wallpapers I went looking for a wallpaper switcher that would change my Gnome wallpaper automatically on a regular basis.

I found a couple of scripts that would work off a folder (such as Gnome Wallpaper Changer), but I wanted a script/app that used the Gnome wallpaper manager. No point managing wallpaper in two separate places, and when pulling them out of a folder, Gnome doesn't know whether they should be stretched, tiled, centred, etc, etc.

To meet my needs, I threw together the following script:
#!/usr/bin/php
define(DELAY,30 * 60);//Delay between backgrounds, in seconds
define(GNOME_BACKGROUND_FILE,'/home/nick/.gnome2/backgrounds.xml');//XML file containing backgrounds, as per gnome

function getBackgrounds($file = GNOME_BACKGROUND_FILE){
try{
$backgrounds_xml = @new SimpleXMLElement($file,null,true);
} catch (Exception $e){
echo "Couldn't open '$file' to get list of backgrounds\n";
die;
}
$backgrounds = $backgrounds_xml->xpath('wallpaper[@deleted="false"]');
shuffle($backgrounds);
return $backgrounds;
}

function setBackground(SimpleXMLElement $background){
$file = (string)$background->filename;
$options = (string)$background->options;
if(!file_exists($file)) return false;
exec( 'gconftool -s /desktop/gnome/background/picture_filename -t string "'.$file.'";'.
'gconftool -s /desktop/gnome/background/picture_options -t string "'.$options.'"');
return true;
}

do {
$backgrounds = getBackgrounds();
$backgrounds_exist = false;
foreach ($backgrounds as $background){
if(setBackground($background)){
$backgrounds_exist = true;
sleep(DELAY);
}
}
}while ($backgrounds_exist);
echo "None of the backgrounds could be found\n";

It could be tweaked relatively easily to take command line input and/or make use of the other elements available from the XML file, but, as it is, it does just enough for me. Hopefully someone will find it useful, even it's just as a base to customise to their needs.

Monday 1 December 2008

Flash overlapping html elements

I don't have to change the Z-Index of flash animations very often, which is why I forget how to do it.

To fix it:
  • Add <param name="wmode" value="transparent"> to the OBJECT tag.
  • Add wmode="transparent" to the EMBED tag.
Found the solution (most recently) here.

Thursday 27 November 2008

Reporting data in PHP

Has anyone got a good reporting library for PHP/MySQL based sites?

I'm working on songoftheelves.com and I'm tracking downloads of chapters to get some stats on who's downloading what and when.

I wanted to present these stats in a nice table and be able to drive the table as to group the results arbitrarily by time, date, which chapter and/or user. Googling for a library to do this didn't turn up anything useful immediately, so I'm throwing one together, not MySQL specific, able to be driven by an arbitrary data source (MySQL, an array, XML feed, etc).

If anyone wants to save me from re-inventing the wheel and point me in the direction of something similar, that would be much appreciated! This must be a commonly encountered problem, so there must be a pre-existing solution out there somewhere. If not, there will be soon.

Monday 3 November 2008

Image Navigation Firefox Extension

I've been working on an extension for Firefox for a while now. It's aim is to allow you to browse through image urls sequentially, prefetching the next image to remove delay. A use case is someone sends you a link to an image, rather than the gallery page (or there is no gallery), you can click buttons to go to the next/previous image in the sequence.

A few months ago I put the source code on code.google.com so I could work on it when I'm not at home, and hopefully get some interest in the project. The url is http://code.google.com/p/imagenav-firefoxextension/.

Tuesday 16 September 2008

Busybox keymaps

I'm currently developing an embedded system using BusyBox. I've had it up and running for a week or two and I'd been putting up with a US keyboard layout, quite annoying when I'm using a UK keyboard.

I finally took the time to look into solving it and found out that BusyBox uses a binary keymap rather than the usual Linux keymaps ("man keymaps" for more info).

Quick solution was to apt-get install busybox on my ubuntu box and run busybox dumpkmap > uk to dump my current keymap into the binary keymap format busybox understands. Running loadkmap <>in busybox now gives me the correct keymap. No more ">" when I'm expecting "|"!