deferred until inspiration hits

Pwdhash Widget

Posted by Chris Roos Mon, 19 May 2008 21:58:15

I’ve been using pwdhash for ages. Apart from some pathetic sites that impose password limitations (less than x characters, or no ‘strange’ characters), I’ve used it on every site I’ve signed up to. This has started to change recently as more sites offer a client application that sits alongside the online app (flickr, twitter and last.fm come to mind): It’s a pain to visit pwdhash.com every time I need to generate a password for an offline app. So, I decided to have a stab at creating a dashboard widget to generate password hashes. I used dashcode (which makes this stuff really easy) and got something knocked up, in about an hour, on Friday. The fact that pwdhash.com is already composed of html and javascript helped just a bit too…

Anyway, if it sounds useful feel then free to download it here.

A trip to the tip

Posted by Chris Roos Mon, 19 May 2008 09:42:29

A recent trip to the local tip got me thinking. Shouldn’t the council be pimping alternative services (freecycle and charity shops come to mind) at the tip? I saw a couple of things that I struggle to believe couldn’t have been of use to someone else: a golf bag and computer tower (even if it didn’t contain a computer – I just sold a similar case on ebay, proving the demand). In addition to these two items were the mountain (ok, not a mountain, but a fair number) of discarded fridge/freezers. I wonder how many of these had actually broken and how many were no longer required for different reasons: maybe England beer fridges are out of fashion now?

So, at the very least, I think the council should just pop some signs up suggesting alternative fates for your unwanted stuff. But, taking it further, I wonder whether the council couldn’t operate a similar sized (to the current tip) site that served as a drop-off/pick-up point for freecycle? I’d hope that, after a while, the cost of this second site would be offset by the savings made at the tip by the reduction in use (although that may be wishful thinking).

Maybe a hybrid alternative would be to train the current tip workers to filter out items of possible reuse from the actual rubbish, thereby allowing the existing site to be use for both purposes.

Redesigning my blog

Posted by Chris Roos Tue, 29 Apr 2008 06:17:07

I finally got round to updating my blog template this weekend. I based the new design on the yui grids css in an attempt to provide the same look to users of different browsers. In addition I’ve ‘borrowed’ some ideas from both the w3c specification pages (the blue colour) and the copyblogger wordpress theme (mainly the header, seen on Ben’s blog).

I’ve also created a really simple print stylesheet (it just removes the right nav) that should make it possible to print the content out if you so wish.

There’s still work to do: the code snippets seem to break IE6 (not sure about IE7) but in general I’m pretty happy with the way it’s looking.

Exporting query results to a remote machine with MySql (an alternative to SELECT INTO OUTFILE)

Posted by Chris Roos Thu, 10 Apr 2008 16:45:29

Exporting query results to a remote machine with MySql (an alternative to SELECT INTO OUTFILE)

MySql’s SELECT INTO OUTFILE syntax provides a nice way to export the results of a query into a tab delimited (by default) text file. Unfortunately, the file has to be created on the MySql host (by a user with file permissions), rendering it unsuitable for dumping the data to a remote machine. If you wish to dump the query results to a different machine then the mysql docs suggest redirecting the output from the mysql command line client:

The SELECTINTO OUTFILE statement is intended primarily to let you very quickly dump a table to a text file on the server machine. If you want to create the resulting file on some client host other than the server host, you cannot use SELECTINTO OUTFILE. In that case, you should instead use a command such as mysql -e “SELECT …” > file_name to generate the file on the client host.

This works great but the default output you’ll get from redirecting STDOUT won’t be the same as using SELECT INTO OUTFILE. The two main (only?) differences are, in the redirected output, the addition of the headers and that NULL values are output as NULL instead of the special \N (backslash-N) sequence. We can fix both of these things by specifying an optional switch (skip-column-names) to the mysql client and employing some sed magic.

mysql -h"my-host" -u"my-user" -p"my-password" -e"select * from my-database.my-table" --skip-column-names |\
  sed -e 's/[[:<:]]NULL[[:>:]]/\\N/g' >\
  my-export-directory/my-table.csv`

That sed magic is replacing instances of NULL, surrounded by some whitespace, with the special \N escape sequence.

Oh, and it’s probably worth mentioning that this is only really important if you want to load this data back into mysql (using LOAD DATA INFILE for example). If you were to load the default output, from redirecting the mysql client, back into mysql then you’d end up with an unwanted header row and NULL strings (or 0 for numeric columns) where you expected actual NULL values.

It took us a while to figure this out so I thought it might be of some use to others.

Another project - Public Swimming Pools in the UK

Posted by Chris Roos Mon, 31 Mar 2008 14:18:43

Not content with already having a bunch of unfinished projects I thought I’d embark upon another.

I’ve struggled in the past to find public swimming pools that I can use when staying in London. I’ve searched on multiple occasions and never really found anything useful so figured there was probably a gap waiting to be filled. Interestingly, I think that someone in or around the government must realise this too. A search, on google, for uk public swimming pools results in an Adword for DirectGov that takes you to a page promoting the Active Places website. This website allows you to search for leisure facilities by postcode or by clicking around a map. As noted in my del.icio.us note, I think this could be a valuable site but the current implementation is very very poor: Both from a usability and search engine friendly point of view (I can’t help but wonder, as it appears to be a Government funded project, through Sport England, how much money has been spent on it). One last point about the site is that it appears to include data about pools that can’t actually be used by members of the public (a pool belonging to a local private school appears when searching for pools near home).

According to this parliamentary question, the department for Culture, Media and Sport know the number and type of pools opened and closed since 2004: actually, I’ve just noticed that they appear to rely on the Active Places database. There’s an email address (actually, a Sport England address) on the Active Places website that I’m going to use to see if I can get hold of this data.

The initial, and most basic, site will just list all the public swimming pools and, I’m hoping this is pretty easy with the Google Maps API, allow you to search for one by location. As, and indeed if, the site evolves, I’d like to get lots more useful information about these pools up: I’m hoping that allowing users to comment will reveal useful info about the best times to visit depending on what you’re trying to get out of it.

Reference Trackback Server implementation

Posted by Chris Roos Sat, 29 Mar 2008 06:27:05

To aid my development of the del.icio.us trackbacks firefox extension I created a reference trackback server implementation based on the trackback specification.

It’s written in Ruby as a Mongrel handler and stores the trackbacks serialized to YAML on the filesystem. The code is over in my google code repository (no direct link as I plan to move the trackback-server from its current home in /trunk/scratch to /trunk/www/trackbacks.seagul.co.uk).

On the off-chance that someone else might find it useful I’m currently hosting it at http://trackbacks.seagul.co.uk. You might use it to see the del.icio.us trackbacks extension in action or to test the sending of trackbacks from your blog (the trackback URL is http://trackbacks.seagul.co.uk/trackback). Or, you could just play with it using curl.

# Let's just try to GET the trackback URL
$ curl http://trackbacks.seagul.co.uk/trackback
<?xml version="1.0" encoding="utf-8"?>
<response>
  <error>1</error>
  <message>Http Method MUST be POST</message>
</response>

# OK, so we'll POST to the trackback URL
$ curl http://trackbacks.seagul.co.uk/trackback -X"POST"
<?xml version="1.0" encoding="utf-8"?>
<response>
  <error>1</error>
  <message>Content-Type MUST be 'application/x-www-form-urlencoded' with OPTIONAL character encoding</message>
</response>

# Posting with the correct Content-Type
$ curl http://trackbacks.seagul.co.uk/trackback -X"POST" -H"Content-Type: application/x-wencoded"
<?xml version="1.0" encoding="utf-8"?>
<response>
  <error>1</error>
  <message>You MUST send the URL of your post (permalink) that mentions this post.</message>
</response>

# Post with the correct Content-Type and the required URL parameter to actually have a trackback created on the server
$ curl http://trackbacks.seagul.co.uk/trackback -X"POST" -H"Content-Type: application/x-wencoded" -d"url=http://example.com"
<?xml version="1.0" encoding="utf-8"?>
<response>
  <error>0</error>
</response>

Files hosted on Google Groups cannot be opened in Safari (or Internet Explorer)

Posted by Chris Roos Sat, 29 Mar 2008 06:06:02

I noticed a little while ago that opening a, Google Groups hosted, file in Safari didn’t work. I have a file at http://delicious-trackbacks.googlegroups.com/web/installation.html that you can try out if you’re so inclined. Requests for that file result in a page being rendered in Firefox but not in Safari or Internet Explorer (6 at least). James noticed that requests for these hosted files were resulting in a 302 response, as we can see from this curl output.

curl "http://delicious-trackbacks.googlegroups.com/web/installation.html" -v -X"HEAD"

< HTTP/1.1 302 Moved Temporarily
< Content-Type: text/html; charset=UTF-8
< Content-Length: 0
< Cache-control: private
< Server: GFE/1.3
< Date: Fri, 28 Mar 2008 19:55:58 GMT

The response also includes a body that contains a link to the actual file you want with some kind of key in the querystring. Interestingly the response doesn’t return a Location header.

The HTTP specification states the following:

The temporary URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI.

So, it looks like Google are sending a valid response according to the spec (although I’m not sure whether they’re intentionally leaving the Location header out) but that Safari and Internet Explorer are unable to deal with it.

I found an existing report of the bug over at the webkit bug tracker and added this information to it. I also sent a message to the Google Groups: Is Something Broken group.

Version Control Commit Note Best Practice (or not, you decide)

Posted by Chris Roos Fri, 28 Mar 2008 19:17:57

This is my own opinion but it has evolved from the need to dig back into past commit notes a lot. The lazy approach to writing commit notes is just to explain what’s in the changeset (much like a code comment that says “set x to 1”): It’s exactly what I used to write (and still do if I’m not concentrating). The more useful approach is to explain why the changeset is there. I can take two of my own commit notes as examples.

Useless commit note

Capistrano deploy:setup should generate apache proxy cluster configuration.

This is a fairly useless commit note: If I was to come back to this (as I did today when looking at it) I would have no idea what I was trying to achieve. Why should the config be generated at setup and not at some other point in the deploy process? If I’d spent an extra 30 seconds writing the note in the first place I wouldn’t have to try to work out what I was trying to achieve.

More useful commit note

This isn't a card but _has_ been bugging me for a long time. You can now click on the in the 'Top 3 ' headings on super category pages to visit that product type. Oh, I also made them h2s as having multiple h1s on a page just doesn't make sense.

This is a much more useful (imho) comment. If at some point in the future we want to know why the ‘top 3 product types’ is now a link, we can come back to the note and see that it was because I, personally, was fed up of it not being so. I also explain why I’ve changed the heading from a h1 to h2 (although that comment could be open to interpretation: why doesn’t it make sense?).

This all ties into submitting small checkins that are only doing one thing, but I might try to give some examples of that separately.

Anyone else have any thoughts or alternative approaches?

Version 0.2 of the del.icio.us trackback extension

Posted by Chris Roos Tue, 04 Mar 2008 09:30:00

I finally got round to compiling the del.icio.us trackback extension I wrote about a while back.

You can install it from the installation.html1 page on the del.icio.us trackbacks google group. Feel free to use that group to post any questions you have too.

Current features:

  • Scans the html of the page you’re bookmarking looking for a link (anchor) with a rel attribute whose value is trackback.
  • Sends a request to the trackback URI if it was found.
  • Records (by adding the ‘dtb-sent’ tag) the sending of the trackback so that we can avoid sending multiple trackbacks to the same site.
  • Records the success (‘dtb-success’ tag) or failure (‘dtb-failure’) of the trackback request.

That’s all for now.

1 I don’t appear to be able to link directly to that page which is a bit odd.

National Rail Train Times by SMS (again)

Posted by Chris Roos Thu, 28 Feb 2008 17:45:00

A while back I hacked a simple SMS interface onto the national rail enquiries website. It turned out to be more gimmicky than functional and I left it to die. Over the past couple of weeks I’ve found myself, once again, in need of such a service and so spent a couple of hours last night reviving it: making it work, making it simpler and tidying the code. The previous interface required the source station and destination station as well as the date and time of travel. The format was very strict (requiring you to use the unique three digit station codes) and, as I found, overly complex (I could never remember what it was). All I really wanted to do was specify the source and destination stations and get a list of the next few departures/arrival times.

The new interface is simply in the format of SOURCE_STATION to DESTINATION_STATION. So, to find the next few trains from Ramsgate to London Waterloo East we can send the following direct message to the natrailenq user on twitter

d natrailenq ramsgate to london waterloo east

Although you can now use the full station name it will only, currently, work if you know the exact name of the station (so, waterloo east wouldn’t work in that above example, but london waterloo east will). It will still work if you supply the three digit station code.

In order to use this service, you will need to create a twitter account, follow the natrailenq user and enable SMS notifications from natrailenq.