Archive for the ‘Ruby’ Category

Midibeep

Thursday, October 29th, 2009

Last week I posted possibly the most tedious Basic type-in listing ever to World Of Spectrum:

5 BEEP 0.212765, 20; 10 BEEP 0.106383,19...
(continues for approx 1500 more lines)

Anyone typing it in in its entirety would be rewarded with this:

Download midibeep_minute_waltz.mp3

Not bad for an evening’s work. Mind you, I did take an ever so teeny shortcut, by writing a Ruby program to convert a MIDI file to BEEP format. (Any .mid file will do, although ones with a single instrument will survive the rather primitive selective-note-butchering process better. Oh, and anything much longer than this one will exceed the 48K Spectrum memory…) And now you can try it out too:

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.

Deploying a Rails app without a database using Capistrano

Thursday, March 5th, 2009

So you’ve got a simple-but-devastatingly-clever Rails app that doesn’t use a database, you’ve dutifully added the line to config/environment.rb to disable the ActiveRecord framework, and now you’re ready to unleash it to the world, using Capistrano for deployment. But when you run ‘cap deploy:cold’, it merrily tries to run database migrations and fails with “uninitialized constant ActiveRecord”. How do you make Capistrano behave?

A simple question, with a simple answer, but one which is curiously absent from the internet. Googlejuice ahoy!

Stick this at the bottom of config/deploy.rb:

namespace :deploy do
	desc "Override deploy:cold to NOT run migrations - there's no database"
	task :cold do
		update
		start
	end
end

FreshBEEP

Sunday, January 4th, 2009

Kicking off 2009 in style with a website-in-a-day, FreshBEEP is my answer to a pressing problem on the Spectrum scene: people are releasing new games all the time, but they’re being overlooked due to a lack of a prominent central place to announce them. However, it turns out that on the World of Spectrum What’s New page, nestled amongst the hive of other site activity that gets mentioned there, Martijn has been dutifully labelling new releases under a “New software for 2008″ banner. One swift bit of mashup work later (does it count as a mashup if it’s only coming from one site?) and these are now being pulled out into a friendly blog-like format, with an all-important RSS feed. It’s not particularly clever, but it scratches an itch…

The Ninja Milkman Conspiracy (and Maze)

Sunday, October 5th, 2008

I’m a bit behind in my blogging, so I’ve got a bit of a “what I did this summer” catchup to do. First up is The Ninja Milkman Conspiracy, a cheap and cheerful oldskool scrolly Speccy demo made for this August’s International Vodka Party, featuring the classic circle interference effect, some creative use of dithering, and a dancing robot. What more could you ask for? The title, incidentally, was just something random and irrelevant to save it from being called ‘IVP 2008 demo’ (which is just as well, because there were already 2 other demos in the competition called that) but is actually a reference to the milkman at one of our offices who is able to deliver the milk and disappear without making a sound.

…All of which is ordinary enough, but the exciting thing (if you’re the sort of person to get excited about build scripts) is, um, the build script. I’ve been happily using makefiles for ages, but this time I finally flipped at the amount of redundant boilerplate you need to shove in there for a typical Spectrum project, even a small one like this – having to remember command line syntax, having to explicitly set up dependencies even though they’re all clearly marked as ‘include’ lines in the assembler file – so I came up with Maze, a Spectrum-oriented replacement for Make written in Ruby. Inevitably, being a scratch-my-own-itch sort of program, it’s a bit more hard-coded (and tuned towards my own way of working) than I’d like, but I reckon it’s enough of an improvement over bog-standard makefiles that it could conceivably be useful to other people. And if it is, maybe I’ll be encouraged to rewrite it in a more open-ended way some time…

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

tracker2ay

Saturday, May 10th, 2008

Here’s a utility prompted by zxbruno and Eq both asking, in the space of two days, how to convert STC, SQT and PT3 music files to something you can actually play on a Spectrum. For those not in the know, STC and friends are Spectrum tracker file formats originally introduced by Sergey Bulba’s AY Emulator and which are now the de-facto standard for archiving Spectrum demoscene music (most prominently on ZXDemo, ZXTunes and Sergey’s epic Tr_songs archive). Which means it’s a bit unfortunate that there’s not been an obvious way to transfer them back to the Spectrum.

In principle it should just be a case of locating the appropriate Z80 player routine and bundling that together with the music data. In practice it involves a lot of faffing about (such as repointing pointers to make up for slight rubbishness in the SQT data format, and writing a 5-line Basic loader/player). Now, thanks to this utility, you just need to type tracker2ay mysong.stc mysong.tap instead. (Oh, and it can convert to TAP, TZX or AY.)

If at this point you’re screaming “But why does it have separate source code if it’s written in Ruby, which is an interpreted language?” then award yourself 20 geek points. Ah, you see, this time I’ve been playing with rubyscript2exe (and tar2rubyscript) to create all-in-one executables that everyone can enjoy without worrying about library dependencies and things. (But obfuscates the code in the process. But in a good way.) Please do check out the source code if you’re curious about that sort of thing, because I reckon it’s one of the best bits of code I’ve written in a long time, in a ‘nicely-written code’ sort of way rather than ‘evil complicated hacks that go together to do something superficially elegant’.

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

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.