Archive for the 'Uncategorized' Category

Elephant spotting in the London Elephant Parade 2010

Thursday, May 13th, 2010

Meeting 'Around the World'

Anyone that’s spoken to me in the past week will know I’m currently slightly obsessed with Elephant Parade London 2010 currently on display all around the city. Public over the top art displays intrigue me, and this one’s no different. With Cow Parade having totally passed me by back in 2000, and day trips to Bath and Liverpool for Bladud’s Pigs and Super Lamb Bananas respectively firmly behind me, I’m pretty excited at the prospect of finding all 258 elephants, and taking photos of them all. I’ll even go as far as Heathrow Terminal 5. If I find the rest.

Elephant Parade is not unique to London, but the elephants that are here, are. Local artists both professional and amateur have given their time and efforts to the project, to create 258 unique colourful, thoughtful, or just plain mad designs. My favourites so far – The City in the Elephant, the uniquely London Taxi Elephant, Panda (I bought a small model, I can’t leave it out), and Woodland.

You can follow my progress on Blakepics where I’m storing photos of all the elephants that I find.

It’s not all about the fun of exploring your city in a new light though. Elephant Family have a serious message to put across, to save the Asian Elephant from the desperation the loss of their habitats is causing. They are working with communities and governments to help re-establish migratory corridors, and help the elephants to nearby villages peacefully. It would be completely selfish of me to take all the joy they’ve given me over the past week (and for the weeks to come) of diving around London spotting elephants, without mentioning this serious part to their mission. Who doesn’t like cash donations? But there are plenty of other ways to donate to their numerous projects, buy some Pink Elephant wine, buy some miniatures of your favourite elephants, sign the petition, give up some time, or even buy one of the big elephants in the final auction.

Like some many of projects like these – Elephant Family have been an absolute inspiration. Transforming a city like London is no small task, but when companies like this take the plunge, you can see the happiness and smiles in everyone.  Sometimes it takes something like this to take a break from the rat race – notice something new, something interesting, or just unexpected. Yes, I’m totally obsessed with finding them all, but I’m loving every minute.

Switch Location – Make your hosts file location-aware

Sunday, April 25th, 2010

I run a few different services from my home network on local IPs.  When I take my laptop elsewhere – to Starbucks for example, those services no longer work because I’ve had to add their local IP addresses to my hosts file.

E.g.

192.168.0.5  dev.blakepics.com

When I take my laptop outside of the network, I want that IP to be removed from my hosts file, so it finds the right public IP address.  There are a few different ways of doing this, including:

  • Run a local network DNS server like named and configure those addresses locally.  This work pretty well, but adding another point of failure to my small network wasn’t ideal.
  • Manually edit your hosts file each time (C:\Windows\System32\drivers\etc\hosts).

I Googled around, and came across Mobile Net Switcher which will do exactly what I need – and switch a whole bunch of settings based on my current network.  It also has a huge amount of features I don’t need and costs €29 for the nag-free version.

It’s a perfectly price reason for an app like this, but I thought back to a quote from a friend of mine a few days ago: “The joys of being a programmer: when I want a program, I don’t have to pirate it. I just make it myself.”

So I wrote my own.

Download Switch Location here

It’s a far more limited version, and only supports switching your hosts file, but it does the job for what I need right now.  One of the features required which I hadn’t used before is some tasks requiring elevated permissions via UAC.

Adding a UAC shielded button was surprisingly simple.  Then it is just a case of starting a new process with elevated permissions:

var proc = new ProcessStartInfo
{
UseShellExecute = true,
WorkingDirectory = Application.StartupPath,
FileName = Application.ExecutablePath,
Arguments = commandArguments,
 Verb = "runas"
 };
Process.Start(proc);

Then just detect the commandArguments parameter on the main application start and run your elevated tasks as necessary.

Once I’ve tidied up the source a little bit (it needs some Resharper loving), I’ll release the source code of the whole app here – in the meantime, you can download Switch Location here.

Auto running commands when plugging in usb drives with udev in Linux

Wednesday, January 20th, 2010

Backups of Backups

My backup strategy for my machines at home can be effectively described as “scatty, but thorough“.  Or at least until I actually have a major crash and need to recover that important file that was outside of my normal documents, code repositories, and archived folders.

I am one of those sorts of people that has backups everywhere.  Folders stacked away with old dusty (and probably now useless) dvds.  Old hard drives filled with duplicates and archived files, stacked up in the back of cupboards and flung next to jam jars.  SD cards, USB keys, backups to other drives, backups to the machines on the other side of my flat, backups off-site.  Backups of backups backed up during the last backup.

So I decided to add one more with an external hard drive that I could plug in every now and then.  But backups aren’t really the point of this post.

Linux has a really powerful device manager called udev which detects when things are plugged into your machine (including hard drives), which you can write rules against, and have commands automagically executed.  This is really cool for my new hard drive, which can now automatically start backing up without regular cron jobs checking to see if it’s plugged in or not.  This is not the same as autorun files, it relies on that hard drive being plugged into that machine.  So don’t start crying about all the security risks with autorun, please.

Here’s how you do it.

udevadm info -a -p  $(udevadm info -q path -n /dev/sdc)

You’ll get a whole bunch of output from that, including (among a lot of other output) a line that might look a little like this:

ATTR{serial}=="312581808"

There are a lot more you can use as well, but this will identify your device.

Now create a new file inside /etc/udev/rules.d/, such as /etc/udev/rules.d/81-usb-drive.rules

KERNEL=="sd?1", ATTRS{serial}=="312581808", SYMLINK+="backup-drive", RUN+="/bin/sh /home/user/scripts/backup-to-drive.sh"

Now every time you plug in that drive, that command is going to be executed (so include for example, the script that is going to run your backups).  Cool, eh?

I started thinking about other applications; syncing podcasts, ebooks and music are the obvious choices. Even as a crude simple method of executing commands on a box you don’t even usually login to.  Or you could use this technique to build yourself some poor man usb-based security.  Keep decryption keys on your thumb drive, and have it auto decrypt volumes on your machine when you plug in that particular drive.

Just don’t forget to keep a backup of the thumb drive, yeah?

Google Wave – My First Bot

Sunday, November 1st, 2009

Last week, I went to the Google Technology User Group in London, which was all on the subject of Google Wave.  Lars and Steph, of Google Wave video, and Google Maps fame gave an excellent talk on Wave, how it was doing, where it was going, and the challenges they’re still facing in getting Wave ready for prime time and a public release.

I’ve had a developer account for some time now, and the talk finally got me motivated into messing around with more of the APIs.  So I created a bot.  Then I created another one.  Because the first one didn’t do anything.

1.  Get Eclipse

So far, the choices for creating Google bots are rather limited because there are rules that they must be hosted on AppEngine (for now).   So first off, get Eclipse – because it makes the entire process of doing that incredibly easy.  You can download Eclipse here.

2.  Get the AppEngine SDK.

Once you’ve got Eclipse installed and running, go to Help -> Install New Software.  Enter this URL to get at the Google AppEngine SDK.

http://dl.google.com/eclipse/plugin/3.5

3.  Create your project.

Go to File->New, and select Web Application Project.  If you don’t have that option, something’s gone wrong with your SDK download, so check step 2.

Uncheck the Googe Web Toolkit, we don’t need that.  But otherwise fill out the Project Name and Package as you see fit.

4.  Add the libraries from the Wave extensions SDK

Download wave-robots-api.jar, json.jar, and jsonrpc.jar and drop those into your project under war/WEB-INF/lib/.

Once you’ve done that, select File->Refresh, then Project->Properties from the main menu, and select Java Build Path.  Click Libraries, and Add JARs, to select the three that you’ve just added.

5.  Write your servlet class.

This is where the bulk of your bot logic (or lack of it), goes.

package helloworld;
import com.google.wave.api.*;
public class HelloWorldServlet extends AbstractRobotServlet {
	public void processEvents(RobotMessageBundle bundle) {
		for (Event e: bundle.getEvents()) {
			if (e.getType() == EventType.BLIP_SUBMITTED) {
			Blip blip = e.getBlip().createChild();
			TextView textView = blip.getDocument();
			textView.append("Hello.  Are you the world?");
			break;
			}
		}
	}
}

6. Add a servlet mapping.

Edit the file, war/WEB-INF/web.xml and add a servet-mapping just below the one you have already.

<servlet-mapping>
<servlet-name>HelloWorld<servlet-name>
<url-pattern>/_wave/robot/jsonrpc</url-pattern>
</servlet-mapping>

7. Add a capabilities file.

Add a folder under war/_wave. Create a file under that called capabilities.xml. This tells Wave which events your robot is going to respond to. In our case, we’re going to respond whenever a blip is saved (blip_submitted)./ There is a full list of capabilities in the full api docs.

<?xml version="1.0" encoding="utf-8"?>
<w:robot xmlns:w="http://wave.google.com/extensions/robots/1.0">
<w:capabilities>
<w:capability name="BLIP_SUBMITTED" content="true" />
</w:capabilities>
<w:version>3</w:version>
</w:robot>

8.  Get an AppEngine account.

That kind of finishes off the Wave-bot.  So you’ll need an AppEngine account to continue.  So go ahead and sign up, and create an application.  Incidently, I couldn’t find my created apps since I have a Google Apps / Domain account.  if that’s the case for you as well, you can find your apps list at http://appengine.google.com/a/<domain>.  Not sure why Google don’t detect that, but there we go.

9.  Deploy to AppEngine

Click the friendly little icon ae_deploy_button from your Eclipse toolbar, and enter your details to deploy you new robot.  Try not to scream “fly my pretties” as you do so.  I dare you.  Make sure you click the App Engine Project Settings button, and provide you Application ID, the same as you created in step 8.

10.  Add your app to a wave

The address of your robot will be applicationid@appspot.com, and you can add it just like any other robot.

You should now be able to interact with your bot.

bot

And if you’d like to see my first bot in action – please drop in and say hello by adding it to your wave: insulteveryone@appspot.com.

Now. World peace.  Where did I leave that file?

Google Wave – Embedding for the first time

Thursday, October 22nd, 2009

This is the first of the embedded Waves using the embed api (embeddy@appspot.com).  If you’re in the Wave, you can add comments to this one and see them both here, and on my blog.  This really demonstrates a lot of the appeal of Wave for me.  Although it’s a bit chicken-and-egg, as it’s still in a relatively closed beta.  So if you can’t see anything below, and you don’t have a Wave account.  Sorry :)

If you want to do the same sort of thing, just add embeddy@appspot.com to any Wave, and you can get your hands on some embed code, and your Wave ID.  Cool, eh?