Bash script to reduce file count to a given number removing the oldest files first FIFO

I needed a simple automated way to remove any number of old backup tar files from a directory leaving only the newest 30 files. As the only thing in this directory was compressed backup files, the script didn’t need to worry about file names or file types, it could just delete the oldest files in the directory (as all the files were effectively the same but just for a different period in time).

So I wrote this bash script ( to handle it for me, it takes two arguments. The first is the number of files to leave (in my case 30), and the second the absolute file path to the directory you want to keep in check.

Continue reading

zRSSFeed unable to load feeds with GET Parameters

zRSSFeed is a nice little RSS Reader for jQuery which uses Google’s Feeds API to parse the RSS Feed.

However if your RSS URL contains required GET variables you’ll find zRSSFeed will just display: “Feed could not be loaded.” – Or similar (if you’ve changed the default error message). There is however a really easy fix, although you will probably want to make the change in the non-minified version of the source and then re-minify. Change line 46 from:

var api = "" + url;


var api = "" + encodeURIComponent(url);

This encodes the URL to allow it to be embedded as a GET parameter. (See MDN for more info…)


Another thing I noticed with zRSSFeed is it won’t load the feed from Google over SSL if your site is using https. However this is easily fixed just modify the same line as above, from:

var api = "" + encodeURIComponent(url);


var api = location.protocol + "//" + encodeURIComponent(url);

Upgrading to Ubuntu 10.10 – Not booting, freezing on loading screen (Nvidia Driver issue) – FIX

After restarting my newly upgraded Ubuntu machine (from 10.04 to 10.10) was greeted with my computer freezing on the loading screen (whilst booting).

After rebooting and getting access to the console I discovered it appeared to be an issue with the Nvidia drivers, which were causing the X server to not start:

Failed to load /usr/lib/xorg/extra-modules/
[    23.651] (II) UnloadModule: "nvidia"
[    23.651] (EE) Failed to load module "nvidia" (loader failed, 7)
[    23.651] (EE) No drivers available.
Failed to load /usr/lib/xorg/extra-modules/[    23.651] (II) UnloadModule: "nvidia"[    23.651] (EE) Failed to load module "nvidia" (loader failed, 7)[    23.651] (EE) No drivers available.

So after trying a number of different ways I finally found out how to fix this issue:

run the nvidia-xconfig program:

cd /usr/lib/nvidia-96/bin/
sudo ./nvidia-xconfig

Modify the xorg.conf file, and replace the driver name nvidia with nv.

sudo vi /etc/X11/xorg.conf


Driver         "nvidia"


Driver         "nv"
Then just try and start the Xserver again:

Hopefully this will help  others fix this quicker than I managed.

“b[0] is undefined” error when using Google’s Visualization API

When playing around with google’s visualization API I came across the following error, which just appeared in the place of lovely colourful chart. No javascript errors were thrown or anything else.

b[0] is undefined

After searching the internet a bit I did not manage to find any answers, at which point I decided it was time to change values passed to the API at random and see when it started working.

The Fix:

It turns out is was the width and height properties it didn’t like, apparently they were too small?!?

Original Code:

function drawVisualization() {
var data = new google.visualization.DataTable();
 data.addColumn('string', 'fruit');
 data.addColumn('number', 'quantity');
 data.setValue(0, 0, 'Oranges');
 data.setValue(0, 1, 3);
 data.setValue(1, 0, 'Bananas');
 data.setValue(1, 1, 4);
 data.setValue(2, 0, 'Grapes');
 data.setValue(2, 1, 2);
 data.setValue(3, 0, 'Apples');
 data.setValue(3, 1, 6);
 var chart = new google.visualization.BarChart(document.getElementById('visualization'));
 chart.draw(data, {width: 150, height: 200, title: 'Fruit',
 vAxis: {title: 'Type of Fruit', titleTextStyle: {color: 'blue'}}

When I modified width and height values I gave to the draw function (as so):

chart.draw(data, {width: 190, height: 200, title: 'Fruit',
 vAxis: {title: 'Type of Fruit', titleTextStyle: {color: 'blue'}}

It started working again. Not quite sure why setting small sizes on the charts causes this, or why it only produces are fairly useless error message.

By the way: At first I was just testing out the API using Googles Code Playground, which is quite smart!

Any way this is how my chart looked after the fix (and I bit more resizing)

Flat image of bar graph created using Google's Visualization API

Flat image of bar graph created using Google's Visualization API

Scheduling MySQL Backups on Linux

There are a number of ways to automatically backup MySQL databases, the simplest one is just to use the mysqldump program and schedule a cron job.

The mysqldump program typically produces an SQL file which can used to restore any where between one to all databases on a server.

Running the mysqldump program is done using the following command:

mysqldump [OPTIONS] (Database name or list of databases)
NOTE: You can use --all-databases in the place of a single or list of database
names to backup all the databases in one file!

Whilst there are a large number of options to give the program the most important ones are probably the “username” and “password” ones.

Continue reading

Disabling Bluetooth on Ubuntu/Debian

If you don’t use you Bluetooth on your laptop then you might want to disable it. Firstly it’s another service your computer does not have to start up when it boots and secondly it will use less power.

For all the following commands you will probably need root access, i.e. you may need to prefix “sudo”.

To stop the bluetooth service use the following command.

/etc/init.d/bluetooth stop

Now lets remove the Bluetooth services from starting when you boot up:

update-rc.d bluetooth remove

Unfortunately Bluetooth support is build into the Kernal itself, but the following line should prevent the Kernel from loading up:

echo 'alias net-pf-31 off' >> /etc/modprobe.conf

That’s it, all done. When you reboot Bluetooth should not restart itself any more.

Saving PNG files for the web using Fireworks CS5

When you save an image/photo/icon for the web you want the file-size to be as small as possible. Why… you ask, firstly it reduces the time taken to download the image (i.e. the image loads faster in the users browser), and secondly it reduces your bandwidth usage.

This little tutorial covers the basics of saving PNG files in Fireworks CS5 for use on the internet, and goes through a few different versions of the PNG format to show you their differences.
Continue reading

Changing PHP settings with FastCGI and suPHP

Recently I needed to change the upload_max_filesize for php running on one of my sites. As this can only be done in either .htaccess (when running php as an apache module) or using php.ini, I was forced to use the php.ini method.

So I created a new php.ini file and added the following lines:

upload_max_filesize = 32M
post_max_size = 64M

The post max size all ways needs to be greater than the upload max filesize other wise the upload max filesize can never be reached as it will get limited by the post max size before hand. Uploaded this to the server and I a look at the phpinfo() output. But still the post_max_size was set to 2MB.

After scouring the internet for quite a while wondering why my php.ini file was not being picked up by php running in FastCGI mode I finally discovered I had to add an extra line into my .htaccess file to tell suPHP where to find my php.ini file.

I opened up my .htaccess file directly under my web root and added the line:

suPHP_ConfigPath /<path to my public_html>/public_html

And like magic PHP picked up the new php settings and the upload_max_filesize went upto 32MB.

I hope this helps someone else having the same issue solve it far quicker than I did.