AMEE for Ruby

Posted by james on July 10th, 2008

In a fit of why-the-hell-not, I've just started writing my first gem for Ruby, which is going to be a wrapper around the AMEE carbon calculation engine. It's still in a very early incarnation, but more will be forthcoming soon. At the moment it can authenticate, and parse DataCategory nodes. DataItems and DataItemValues will be following after a short (UK-based) holiday. Source code and installation instructions are available from GitHub.

Filtering Twitter with Pipes

Posted by james on July 10th, 2008

I like Twitter. I'm not sure why, but I do. However, I don't like the fact that I can't view my friends timeline via RSS without seeing my own updates in there as well. I already know what I've written, I just want to see what other people wrote. To scratch that particular itch, over lunchtime I built a Yahoo! Pipe to filter my own updates out of my feed, and you can use it too. Check it out here.

Announcing JabberStatus

Posted by james on May 30th, 2008

Twitter, while it has its problems, does one thing very well. The IM interface allows you to update your status via a Jabber account, which just makes it so easy to do. Facebook, on the other hand, has no such facility, which is unfortunate because although I like the Facebook service, I hate using the website itself. Yes, OK, you can update your Facebook status via Twitter, but I write different things on Facebook and Twitter, so I didn't want to go down that route. So, my solution? Write my own!

JabberStatus is a simple Ruby script which listens on a Jabber account and updates your Facebook status for you. You add facebook@jabber.org to your Jabber contact list, then it says hello and gives you instructions on what to do. You click a couple of URLs to give it access to your Facebook account, and that's it! Then you just send it status updates, and it posts them on Facebook for you. It's free for anyone to use, so give it a go!

Technically, it's pretty cunning though I say so myself. It stores Facebook session data for each person that talks to it in it's own Jabber contact list, so no backend database is required. Anyway, it's all open source so you can take a look yourself. You can even run your own instance of it. It's still under development (needs code tidying up, as well as better error handling), but it's out there working now, so have a go.

geeKyoto 08

Posted by james on May 19th, 2008

Well, Saturday was geeKyoto 08 in London, and I finally had to get round to writing my presentation. Had to finish it on the train on the way in, hoping I wouldn't run the laptop battery down too much in case I had to use it during the talk.

It was a great day though! The speakers were incredibly varied, from Alex Haw, an architect/artist who has more ideas in a second than I do in a year, to a great presentation by Gavin Starks about AMEE, to a design student who hung a swing in a bus stop (which got the day's most spontaneous round of applause). The whole thing was then rounded off by Ben Saunders, an arctic explorer who has really seen the ice melting up there. Add onto that a fascinating post-conference pub session, and you can't lose. The day left me so energised and full of ideas. Now I just need to decide which to attack first!

Hopefully my talk ("Can software save the world?" - pretentious title intentional) will be up online soon. For those of you who saw my talk but didn't get the links down, here they are again:

Adventures with GitHub

Posted by james on May 9th, 2008

When the Linux kernel moved to using git for version control, I didn't really pay much attention, to be honest. When Rails moved, I only really paid attention because it made my life harder, as Piston doesn't support git fully yet. However, I've now had a reason to use it myself, and I have to say I'm actually rather more impressed than I thought I'd be.

Read the rest of this entry

A whole new look

Posted by james on May 9th, 2008

Well, it was about time for an overhaul... my old site was looking increasingly outdated, and it didn't really fulfill what I wanted from it any more, so I've moved over to a new one, using Mephisto. It's deployed on my own virtual server, and is running under Phusion Passenger, the new mod_rails solution for Apache. It's definitely been the easiest Rails installation I've ever done! Not sure how well it would stand up to heavy use, but this site certainly doesn't need to be high-capacity, so it does the job admirably.

The hardest thing about getting the new site up and running was deciphering Mephisto's liquid code. While there is *some* documentation, most of it seems to be out of date and scattered across the net, so it was a bit awkward. I'm sure you can expect a couple of blog posts detailing exactly what I had to do to get the site into a good shape at some point...

CO2 on Twitter

Posted by james on May 7th, 2008

I read this article last night, about using Twitter to make machines talk, specifically Tower Bridge. "What a fantastic idea", I thought to myself. "Maybe I can do the same thing for climate change". Also, it would be a good way to flex my Ruby muscles a little and get some "fun" coding in for the first time since Amelia was born.

So, a couple of hours of Ruby later, and we have atmospheric CO2 updates on Twitter. The code is dead simple, and can be grabbed from Google Code.

Sanitizing :limit and :offset

Posted by james on February 1st, 2008

I have a need in the Green Thing Rails app to pass in limit and offset parameters to a find query, and these parameters come from the URL. For example:

@examples = Example.find(:all, :limit => params[:limit], :offset => params[:offset])

This works fine, but is vulnerable to dodgy things making their way in through the parameters. Normally, to defend against SQL injection, you would use the array form of :conditions to sanitize the parameters, like so:

@examples = Example.find(:all, :conditions => ["name LIKE ?", params[:name])

This is great for :conditions. However, you can't use it with :limit and :offset, despite the fact that they are just as vulnerable to SQL injection. The trick I came up with is this. :limit and :offset are both integers, so simply force the conversion to an integer before using them (checking for nil first, of course):

@examples = Example.find(:all, :limit => (params[:limit].nil? ? nil : params[:limit].to_i),
                               :offset => (params[:offset].nil? ? nil : params[:offset].to_i))

This means that no nasty SQL can get in, because it won't get through the integer conversion. Simple and effective. Probably blindingly obvious, but I didn't find anything online to point me to this solution while I was looking around for :conditions-style sanitizing, so I thought I'd share.

Of course, if I've missed something glaringly obvious, please let me know ;)

Testing in Trac

Posted by james on January 9th, 2008

Hurrah, I've just contributed my first code back to the Trac project. I've created a workflow for the 0.11 release which adds a simple "testing" state to tickets before they are closed. For the Trac addicts amongst you, it's available at Trac Hacks. I'm rather proud of it, because it's actually the first workflow hack on the site!

Sky Channel Changer

Posted by james on June 1st, 2007

My MythTV box was changing channels a bit slowly, so with pointers from Wilf, I've hacked the Sky Digibox channel change script from The Nexus to send the commands all in one go for (marginally) faster channel changing. It also allows extra options to the irsend command. Download the updated version below.

Announcing: The Carbon Diet

Posted by james on May 28th, 2007

Well, it's been quiet here recently, but that's because I've been working on a new project, which is slowly getting closer and closer to being ready. It's only open to testers at the moment, but there is now a tour which can be seen by anyone, so I thought I'd link it.

I present to you: The Carbon Diet!

The what now? Well, it's basically a carbon calculator on steroids. We've all seen the dodgy carbon calculators on various websites, but they're not really any good to tell you what you're really contributing. You can get a rough idea, but they're not great. The Carbon Diet is different. By entering easily-obtained data like actual electricity and gas readings, as well as fuel purchases, the site can calculate exactly what your contribution to climate change is, both for right now, and over time. It should allow people to really see how much CO2 they are producing, it should allow them to work out how best to reduce that amount, and it should prove to them that what they have done has worked.

If that sounds interesting, head on over and take the tour! If you want to help with the testing phase, then sign up and I'll get you sorted out :)

Problems with Rails and MySQL

Posted by james on February 8th, 2007

I recently reinstalled my laptop with Fedora Core 6, and when I went to fiddle with my prototype Rails project, I found that nothing worked. I had a bunch of problems, and I thought I'd note down the solutions here, in case anyone else had the same problem. So, forgive me, it's going to be techy for a while.

First, the thing wouldn't connect to the MySQL database at all, claiming that /tmp/mysql.sock didn't exist. Odd. Well, not that odd, in fact, because the MySQL RPM for FC6 creates its socket in /var/lib/mysql/mysql.sock instead of /tmp/mysql.sock. So, the addition of a socket line to config/database.yml and we're off again:

socket: /var/lib/mysql/mysql.sock

Next problem: the thing is now connecting, but when I try to recreate the tables using rake db:migrate, it complains thusly:

Mysql::Error: Lost connection to MySQL server during query: SELECT version FROM schema_info

Bugger. Turns out, after some web research, that Rails has changed to new-style password authentication for MySQL. However, the FC6 MySQL installation hasn't, in order to keep compatibility with older clients. Fair enough. Again, it's a fairly simple fix. I had to change the appropriate setting from 1 to 0 in /etc/my.cnf:

old_passwords=0

I was feeling good at this point, and restarted the MySQL server, ready for my Rails app to spring into life. Alas, no, same problem. However, resetting the MySQL password using mysqladmin sorted it all out, and the thing is now happy.

mysqladmin -u user -p password xxxxx

If you're having similar problems, I hope this helps!

MythRename

Posted by james on June 18th, 2005

Here in the UK, T4 (a weekend morning kids show thing) put a "T4:" prefix on the front of every program they show, so rather than "Futurama", you get "T4:Futurama". If you want to record these shows, you need to have two rules, you end up with two different titles in the program list, and you get duplicated episodes.

Well, no more. I've written a script called mythrename which strips prefixes from programs in the MythTV database. Configuration is simple - just edit the perl script and add the prefixes you want to remove to the @prefixes array, edit the database options, and away you go. It's best run after every mythfilldatabase run, as the listings grabber does away with all our hard work and puts back the original titles.

There's no readme file - all the explanation you need should be in the Perl script. If there's anything I've left out, please let me know!