Author Archives: Alex Forbes

Changing boot order in Ubuntu 13.04 (or Debian) – the easy way

I wanted nice, concise instructions on changing the boot order in Ubuntu 13.04, which uses Grub 2. Being a newbie focused OS however, Googling “ubuntu boot order” results in SEO blogs with lots of fluff, and then the actual instructions start out with “install package from ppa”…

What the hell, I just want to change the boot order!

Continue reading

Site move

Just moved this site to a larger VPS. If you can see this message you’re visiting the new host so the migration was clearly a success!

It should also be accessible over IPv6, although this has yet to be tested.

Calling mysqldump in Python

Python is a fantastic tool to know, and despite being a beginner I find myself using it more and more for everyday tasks. Bash is great for knocking together quick scripts, but when you want to something a little more complex such as interfacing with APIs or other systems over a network, you really need a more fully-featured programming language.

The topic of this post, however, is the kind of task that bash is perfect for. Thanks to mysqldump, a database backup script can be written in a few lines and dump/restores are easily automated. So why on earth would we do this in Python?
Continue reading

Targus Laptop Mat – Buyer Review

While staying with a friend recently I was instantly jealous of his Belkin Laptop cushion. It looked like a great way to chill out with a laptop in the evening while avoiding a hot lap.

While researching the Belkin above though, I came across the Targus Laptop Lap Store Mat, which was almost half the price. There were no negative reviews, so living by the philosophy that if you regret buying the cheaper one you can always get the more expensive one later (poor philosophy, but both are cheap enough to get away with applying it here!), I decided to give it a shot.

Continue reading

How not to program Bash

Came across this gem today:
[shell]
COMP=$1

if [ -e $COMP ]; then
echo “Please supply a competition_id”
exit
fi
[/shell]

On first read it looks backwards – “if exist $COMP then exit”, and the programmer clearly wanted to do the exact opposite. However it actually works as desired. Mostly.

If no argument is supplied, $COMP will be a blank string, i.e. “”. Thus [ -e $COMP ] will parse to [ -e ], which returns 0 (effectively true). It’s basically like saying “does nothing exist”.

This is because the -e argument tests whether a file exists. So if an argument is supplied, [ -e $COMP ] will return 1 (effectively false), which does what the programmer intended UNLESS the argument supplied is a valid file path.

In this case a number was expected, so sure it’s unlikely to fail in this way, but it’s still an incredibly bad way to test if an argument is set. Not to mention confusing to read!

The correct way to test this by the way would be to use -z, which simply tests if a string’s length is zero:
[shell]
COMP=$1

if [ -z “$COMP” ]; then
echo “Please supply a competition id”
exit
fi
[/shell]

Or better still, use getopts. For more info run ‘man test’ from a bash terminal.

Nexus 7 jelly bean update brings home screen rotation

image

Brief post as I’m writing this on the device in question – an update to Jelly Bean (4.1.2) came through a few minutes ago. I think this is the slickest handling of screen rotation yet – effectively the layout is the same, the Android engineers simply moved the launcher and (the useless) search to the sides. This is a nice improvement for Nexus 7 owners.

Xen Server “The SR failed to complete the operation”

Had this problem when trying to start a newly created VM and install from certain ISO files. Some ISO images would work and others would not.

Removing the ISO image allowed the VM to start but obviously there was no OS image to install from.

The error message is generic and not very helpful, but if you do encounter it check that the ISO is readable by the Xen server. In our case it was on an NFS share but the permissions were read-only to all but the owner…. so a simple `chmod a+r *.iso` fixed it!

Google’s new app policy seems a little… hypocritical

Google updated its Play Store policy recently, and the changes appear to be designed to reign in spam on its app store. One of the policies reads “Product descriptions should not be misleading or loaded with keywords in an attempt to manipulate ranking or relevancy in the Store’s search results.”

Amusingly, the description for Google’s own Maps app contains a block of text which would do just that:

Continue reading

Creating samba share in Nautilus: ‘net usershare’ returned error 255

I was having this problem on Ubuntu 12.04 (precise), but most of the Google results pointed to a bug in Hardy. However there are other causes of this problem.

In my case it was a previously-created share with a different user ID – Nautilus couldn’t create the share because there was already a share file with the same name owned by a different user.

The directory is /var/lib/samba/usershares. You should already have write access assuming you’re a member of the sambashare group (which the gui should handle for you), so all that remains to be done is remove the offending share with the same name as the one you’re trying to create.

alex@al4:~$ cd /var/lib/samba/usershares/
alex@al4:/var/lib/samba/usershares$ ls -lah
total 16K
drwxrwx--T 2 root       sambashare 4.0K Jul 25 12:33 .
drwxr-xr-x 5 root       root       4.0K May  1 10:40 ..
-rw-r--r-- 1 2046297271 2046296576  142 Oct 25  2011 music
-rw-r--r-- 1 2046297271 2046296576  128 Feb  7 17:13 videos
alex@al4:/var/lib/samba/usershares$ sudo rm music
[sudo] password for alex:
alex@al4:/var/lib/samba/usershares$ sudo rm videos
alex@al4:/var/lib/samba/usershares$

After doing the above, Nautilus was able to recreate the shares without trouble.