Archive for the ‘Hacks’ Category

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.

Belorussian translation of this post provided by movavi

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…)

bbgateway: Reading web forums the 1982 way

Friday, June 29th, 2007

As anybody who’s been on the internet long enough knows, online discussion was perfected in the 1980s by Usenet, and it’s all gone downhill since. Not even Google have managed to translate it into the friendly pastel shades of the Web successfully. But time marches on, and slowly but surely the conversation moves over to web forums, attracting newcomers who will never know what they’re missing – decent message threading, tracking of the posts you’ve already read – and instead have to endure topics that get locked by moderators just as they’re getting to the good bit, and (oh, the horror) graphical smileys.

And thus a great rift opened up in the ZX Spectrum fanbase. The community was divided between the ones in comp.sys.sinclair who would never touch a web forum even if their life depended on it, and the ones in the WOS forums who would never venture into the rugged wastelands of Usenet even if they were the last person alive and the second last person alive had just, in their dying gasp, posted a message to rec.survival.post-apocalyptic entitled “Survival tips for the last person alive”.

bbgateway is my solution to this sorry state of affairs. It’s a suite of Ruby applications that will scrape a web forum of your choosing for new posts, reformat them into old-school plain text (you know, angle brackets for quoting, and – yes! – ASCII smileys) and make them available in an NNTP feed that you can follow with your newsreader, or share with the world if you’re feeling generous. (more…)

Geeks on a train

Sunday, February 18th, 2007

My talk for this weekend’s BarCamp London was Geeks on a Train (and other adventures in network theory). It covered an assortment of neat things to do with networks – both real and virtual – illustrated by Kevin Bacon, Slengpung and the London Underground.

You know the routine by now. I make the slides available, along with the warning that they’ll probably be completely unintelligible to anyone who didn’t see the talk, and then express the vague intention of putting them in more accessible form in future (possibly a screencast or something) which inevitably never happens. Tch, eh? Here’s the link.

Geeks On A Train slides – SXI (OpenOffice) format, 2.8Mb

(Technorati tag that’s presumably useful to someone somewhere: )