Archive for the ‘Hacks’ Category

Sleeper – mapping European night trains

Wednesday, June 10th, 2009

It’s now been 10 months and 10 demo parties since I last saw the inside of an airport (with plenty more to come over the next couple of months… parties that is, not airports), and for any eco-conscious European traveller like me, knowing which sleeper trains to catch is the key to happy travels. So, it’s a bit of a shame that there’s no single website you can go to to find out the best sleeper train to get to European Destination X. Sure, Seat 61 is a fantastic resource for finding out how to get to your country of choice, but you can never be sure whether you’d get better results by heading just across the border, or tweaking your journey times slightly…

So, in a classic case of building a website to scratch a personal itch, and not wanting to let niggly licencing issues get in the way of a cool idea… Sleeper is my new website aimed at searching and mapping the European sleeper train network in its entirety. It’s been put together with Ruby, Rails (gosh, that’s rather apt isn’t it…), Geokit, Google Maps, Hpricot and my own freshly open-sourced Bahn library for snarfing data from Deutsche Bahn‘s website, and hopefully it can give you a fuller picture than ever before of what actually exists in the wonderful world of sleeper trains. Right now it stops short of providing one overall definitive map of the network (it would probably crash your browser if I tried plotting it on Google Maps), but that’s on the todo list.

Ode To Claire / Snakebite

Wednesday, June 10th, 2009

A couple of fast-made Spectrum releases for last month’s most excellent Outline demo party. Ode To Claire is a curious little 128 byte intro, using a trick I’ve been wanting to try out for ages. It’s not exactly a fast-paced action extravaganza, but it does fit 150-odd characters of avant-garde poetry, the printing routine, and a demo effect into 128 bytes of code. Working out how is an exercise for the reader (and I’m quite interested to know whether the secret is immediately obvious to anyone who’s at all familiar with the Spectrum…)

On the musical front, Snakebite is a chiptune with a middle-eastern vibe, modelled after every Turkish Eurovision entry ever. It got third place in the competition, and originally they weren’t going to give out a third prize, but they had some spare food left over on the Saturday night, so I won a jar of sausages. Best. Prize. Ever.

Download gasman_-_snakebite.mp3

JSSpeccy: A ZX Spectrum emulator in Javascript

Sunday, October 19th, 2008

I’m really typecasting myself here. If there were an international “Person most likely to write a Spectrum emulator in Javascript” award, I’d have taken it for the last five years running. So here it is – probably the most stereotypical project I’ll ever come up with.

Writing this wasn’t actually such a big deal – the Z80 core was ported from the one in Fuse, with the Perl-and-C-preprocessor-munging trickery still intact, and Javascript is syntactically close enough to C that that wasn’t a mammoth task. (I got 90% of it done on the train journey back from International Vodka Party alongside recording silly songs about tube stations.) The one fiddly bit was working around the places where the Fuse code used low-level C constructs to its advantage: using unions to chop and change between individual registers and 16-bit register pairs, and relying on limited-size C data types (often in pretty subtle ways) to truncate 8-bit and 16-bit values at the right time, whereas Javascript only has integers. (Actually, the really time-consuming bit was debugging it all… luckily, Fuse has a rather excellent test suite too.)

The rest is just creative abuse of the <canvas> element, as usual… it’ll take advantage of the putImageData interface to do the pixel pushing if available (on my machine Firefox has it, Safari doesn’t) and fall back on drawing 1×1 pixel rectangles otherwise. This time I’ve thrown in Google’s ExplorerCanvas as a nod to those poor unfortunates still stuck with Internet Explorer. Incidentally, I’d be curious to know how it rates on Google Chrome (I don’t have an XP/Vista box to test on) – if the hype is true (and it implements the putImageData interface like all good up-to-date browsers should) then I’d expect it to comfortably reach 100% Spectrum speed on modest hardware.

Antisocial

Thursday, October 9th, 2008

This is it then… my big comeback to the Javascript demo scene after a two year absence, and also the moment when my demo coding muse returned from a long holiday, I guess. Ladies and gentlemen, I give you… Antisocial, a biting satire on social networking phenomena.

Visit the Antisocial microsite…

With my characteristic lack of organisation, I found myself with two weeks to go to the Sundown party, having promised a demo release, and with nothing specific in the pipeline. So, I decided to take a chance and run with an idea that had been sitting on top of my “demos to write when I have more free time than I do right now” pile for the best part of a year. I had it all planned out in my head, right down to the soundtrack: a mysterious track from an unlabelled CD I picked up at a ZX Spectrum Orchestra gig in 2005 (which turned out to be Round, from their Clive Live^3 EP). A quick bit of permission-getting later, and I was at the point of no return.

I knew it would be an ambitious job, and a bit of a leap artistically and technically from my usual stuff. I pencilled in a rough project plan in my diary. I drew up storyboards. I read up on the maths that was too nasty to contemplate on previous projects. And shockingly enough, I actually enjoyed all of the above.

(more…)

Some rather opinionated plugins

Saturday, August 30th, 2008

Update: The belongs_to patch has now made it into core Rails. Thanks to Jon for persevering with it where I threw in the towel, and to Koz and Pratik for giving it their attention. I’m still not entirely convinced that going through the conventional channels (as opposed to “whinging on a blog”) would have yielded the crucial feedback to get the patch in a state where it could be accepted, but all’s well that ends well…


A shark, being jumped, yesterday.Take this as the rantings of a pissed-off curmudgeon who’s had his second core patch rejected if you will, but it’s my sad duty to report that Rails has jumped the shark. It happened when it stopped being a framework and started being a collection of opinions instead.

You see, in my book a framework is something that’s meant to make programmers work more effectively – not to lecture them about what they’re doing wrong. Lecturing can be a good thing, as long as it ultimately results in better code – I’ll happily admit that following the Rails learning curve has taught me an awful lot about good programming practices. More and more though, I’m finding it being used to justify just plain broken features: If it doesn’t work, it’s your fault for not doing it the right way. Take this bit of profoundly broken behaviour:

let’s say we have a Company model, which belongs_to :city

>> torchbox = Company.find_by_name('Torchbox')
=> #<Company id: 1, name: "Torchbox", city_id: 1>
>> torchbox.city
=> #<City id: 1, name: "London">

Aha, we’ve got the city wrong. Let’s reassign a bundle of attributes then, like we would if we were doing this through a web form:

>> torchbox.attributes = {:name => 'Torchbox', :city_id => 2}
=> {:name => 'Torchbox', :city_id => 2}

Right, so now we should retrieve the correct one.

>> torchbox.city
=> #<City id: 1, name: "London">

Er, oops.
(more…)

Comet Chaos

Monday, July 7th, 2008

Thanks to Oleg for reminding me at OpenTech that I still hadn’t written this up yet…

This started out as an experiment in Comet techniques (which allow you to actively push data out from web servers without the client having to initiate the request) which quickly ballooned in ambitiousness – I didn’t set out to write Just Another Chat Application after all. The end result is a realtime multiplayer Javascript conversion of the Spectrum wargame Chaos… or a reasonable chunk of it, at least.

Play Comet Chaos now

If you’re interested in the workings behind it, check out this video from my Oxford Geek Nights presentation to hear about how Comet is like a small child on a car journey, find out how close web developers can get to world domination, and watch a live demonstration going pear-shaped.

(more…)

Djerb: Django-ish templates in Ruby

Thursday, April 10th, 2008

As is fairly well documented by now, I like Rails, and I’ve done quite a bit of stuff in it. However, through a brief stint of work on The Carbon Account I’ve been getting my feet wet with arch-rival (ok, not really) framework Django, and I found myself hugely impressed with its templating system. A less stubborn person than me would think “That’s a nice idea. Maybe I should think about switching to Django.” My reaction, however, is “That’s a nice idea. I think I’ll steal it.”
(more…)

Across Wales

Monday, February 11th, 2008

Not in fact a continuation of the Through Poland series, despite what you might expect. This is not so much a song, more an experiment with backwards recording, to test the theory that the Welsh language is actually just a bunch of people talking backwards for a laugh, and to create a completely palindromic piece of music. (There can’t be many of those around, surely…)

Apologies to any actual Welsh speakers reading this. Please don’t kill me.

Download matt_westcott_-_across_wales.mp3

Across Wales on FAWM

New album from Glencoe Horse!

Monday, January 14th, 2008

Tonight I’m thrilled to be able to bring you an exclusive first glimpse of Are Great Things Born, the forthcoming album from Glencoe Horse.

[cover art: Are Great Things Born by Glencoe Horse]

…okay, so that’s a lie. Glencoe Horse (and their album) are a figment of random chance, generated by the following fiendishly complicated algorithm as introduced by Burr on the FAWM forum:

A general call went out to come up with an automatic online generator, and, well, how could I resist? My first attempt at an application in Camping (chosen so that I could take advantage of the wonderful HTML-parsing capabilities of Hpricot without the monster truck of Rails sitting underneath), it took about 3 hours to complete starting from no knowledge of the framework whatsoever, of which half was taken up finding out the best way to deploy it.

It lacks the human touch of the lovingly-photoshopped artworks that have previously come out of this concept (and replaces it with some rather horrific random colour schemes instead) but it’s still a curiously addictive way to pass a few minutes, with your finger poised over the Refresh key.

Passing remote web data to attachment_fu

Thursday, August 16th, 2007

This week I have been mostly discovering what a wonderful Rails plugin attachment_fu is for handling image uploads. You just hand it the contents of an upload field on a form, and it takes care of everything else – checking that it’s a valid image, working out its file type, choosing a sensible filename for it, resizing it appropriately, and sticking the resulting image file into either the filesystem, the database, or Amazon S3.

That last feature has been particularly handy on Demozoo, which is currently hosted in borrowed space on a server that doesn’t really have 100-odd megabytes of free space for demo screenshots. However, attachment_fu comes a bit unstuck when you’re dealing with files that don’t come from a form upload – for instance, in my case I’m planning to have a scheduled task that leeches new productions and their screenshots from Pouët, and I’d quite like to take advantage of the Imagemagick-and-S3 goodness that attachment_fu brings. A bit of digging around was in order.
(more…)