May 21st, 2009

The Carbon Diet goes open source

Well, I finally got round to it. I started developing The Carbon Diet 2 years ago (had the idea 3 years ago!), and it’s finally spread it’s wings and joined the world of open source.

After I’d been developing it for a few months, it became obvious that it was never going to be a commercial proposition, so it’s been my intention to open it up for a very long time now. However, I was putting it off until “after I get it finished”, or “after I tidy up the code”, or any number of other reasons. Having a small child puts paid to all those plans, so I’ve finally bitten the bullet and released my dodgy code to the world as it is, warts and all.

The site is built in Rails, but it’s pretty creaky. It was originally written in version 1.2 as I was learning, and a lot of the old-style controller and route code is still hanging around, waiting to be improved. I’ve started, but there is a long way to go to bring it up to a decent standard.

Anyway, if you use the site (or not!) and fancy improving it, now you can. Head on over to github to grab the code and join in. I hope to see you there!

October 13th, 2008

Gems, Bookmarks, and Sandwiches

I’ve been crazy busy for a while, but what little spare time I have grabbed here and there has been used investigating some areas of Rails I hadn’t played with before, like route globbing and running without a database. The results are a couple of tools, one useful, one most definitely not.

The first (and most useful) is Has My Gem Built Yet?. I have a bunch of ruby gems on GitHub and get annoyed that I have to keep running “gem update” while waiting for GitHub to build the gem once I’ve pushed the code. Well, no more. Just put in the details, and the page checks for you and pops up a message when the gem is done. Nice. It got picked up on the GitHub blog, and I’ve even had some patches sent in. It’s a nice feeling :)

The second app is somewhat less useful (though still entertaining). After a suggestion on Twitter by Tom Taylor, I built a website which lets you bookmark sandwich combinations. There are a couple of interesting bits in this though - first is route globbing, which is the Rails way of using arbitrary bits of the URL as parameters to an action. Not something you use in every project, but still. More importantly, I’ve used it to test out rubymarks, a Rails plugin for generating links for social bookmarking services.

I love Rails for this sort of thing. I can’t think of other system I’ve used that would let me create such fun things in the tiny snippets of spare time I have at the moment. And of course, everything above is open source and available on Github.

August 29th, 2008

CurrentCost data live on Pachube

So, the other day I got a nice little tray icon working for my CurrentCost power monitor. That’s great, but data is only really gets fun when it’s mashable, so the next step was to get it online somehow.

Pachube is a site which aggregates data feeds from real-world (and virtual-world) devices, shows them on a map, makes graphs, things like that, so it seemed like a good first attempt at putting my power data online. My first thought was to get my app to post data at regular intervals to the service, but unfortunately Pachube doesn’t work like that. Instead, it acts more like a news reader, not a publishing platform - Google Reader instead of Blogger, if that makes sense. So, I had to publish my feed live on the web and point Pachube at the URL.

First step: EEML. This is an XML-based format which Pachube reads which can contain not only multiple data feeds, but tags and other metadata. So (as seems to be the fashion), I wrapped it up in a Ruby gem, available from GitHub as ever. The gem simply provides utility classes to build an EEML feed and convert it to the XML-based format for delivery over the web.

Then, the final step was to publish the data on the web. For that, we need a web server. However, having a full web server for just one feed seemed overkill, and I didn’t want to publish to yet another intermediate server, so we need to serve the data directly. Ruby to the rescue once again. WEBrick is a simple web server which is part of the core Ruby libraries. You create a server, write simple servlet classes, and mount them at particular locations. For instance:

# Create WEBrick server s = WEBrick::HTTPServer.new( :Port => 50000 ) # A simple "hello world" servlet class HelloServlet

Now, http://localhost:50000/ will say “hello world”. From here it’s a simple modification to publish the EEML feed. EEML-Ruby includes a simple EEML server script as an example. So, after building this into the tray app, now whenever my CurrentCost is connected and the app is running, it serves up EEML data to the web. You can see the data feed (fairly intermittent, as obviously the meter isn’t always connected to my PC at the moment) live on Pachube.

August 22nd, 2008

Some successful CurrentCost hacking

After a bit of work, I’ve finally got my CurrentCost meter working in Ruby, and I now have a power monitor sitting in my system tray! There were a few stages involved…

Serial comms: The ruby-serialport library that already existed for Ruby was no good to me. Firstly, it didn’t seem to be in a working state, but more importantly, the license it is under (GPL) is no good to me. So, I had to write my own. I’ve created a nice simple serial library (including a gem) for Ruby called RB232, which is available on GitHub. It only supports reading at the moment, and only works on Linux systems, but it’s a start. Next!

Reading CurrentCost data: Once RB232 was in place, this was pretty easy. Just create a couple of classes to wrap up the process of getting data from the meter, and away you go. Easy. Also released as a Ruby gem on Github.

User interface: Last step was to make a simple user interface for the meter, which you can see in the picture above. It’s a simple tray icon that changes colour based on power usage. It’s based heavily on another very useful tool called cctrayrb, so many thanks to Daniel Parnell for doing the heavy GUI lifting there. The app is included as part of the currentcost-ruby gem mentioned above.

Anyway, it’s all freely available, so if you have a CurrentCost meter and a serial cable for it, you can grab the code and get going. Enjoy :)

August 7th, 2008

Twitter support in JabberStatus

JabberStatus was originally inspired by Twitter’s facility to update your status via XMPP/Jabber. Unfortunately, Twitter’s Jabber interface has been down for months now, which is rather sucky.

The solution to this? Extend JabberStatus to work for Twitter as well as Facebook. It turned out to be very easy, so it’s online now. Just add twitterstatus@jabber.org to your contact list and it will talk you through the rest.

The JabberStatus code has moved to GitHub now, so you can grab it from there. The code for the CO2Updates app has also moved there.

August 6th, 2008

One Hundred Months

I just saw the One Hundred Months campaign, and decided it was ripe for a bit of automated Twittering. So, 5 minutes hacking and we have One Hundred Months on Twitter. Code (as ever these days) is available from GitHub.

I’m amazed by what computers can do sometimes. This one seriously took me longer to publish to the world than to write.

Hacking your energy usage with the CurrentCost

The other day, I managed to get hold of a CurrentCost energy monitor (available to buy from here, or maybe from your electricity supplier). Now, the nice thing about this particular monitor (apart from the ton of information on-screen) is the fact that it has a serial output on the bottom, which you can (with a bit of hacking) plug into your PC, and - bingo - lovely XML data!

However, once you have it connected and spewing XML at you, you really need something to do with all that data. I don’t have anything big written yet, but my first step towards making something useful is a Ruby gem, which is available from GitHub. So far it can only parse the XML data from the meter - direct access to the serial port is hopefully coming soon.

In other news, the AMEE gem I started a while ago is still coming on. It can now use the XML and JSON interfaces, parse the whole Data API, and retrieve a list of Profiles. Not a bad start.

July 10th, 2008

AMEE for Ruby

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.

May 9th, 2008

Adventures with GitHub

While moving this site over to Mephisto, I had a problem with the asset system, in that while assets have a “title” field in the database, it’s not editable in the admin interface, or accessible in liquid templates. The fix was simple, just a couple of lines (once I found where to put them), but patching my local copy of Mephisto was somehow unsatisfying. Well, Mephisto is hosted on GitHub these days, so it was time to dive in!

Normally, the process of sending a patch to an open source project is just too laborious to bother with for small stuff. Check out the code, editing it, creating a patchfile, subscribing to the mailing list, introducing yourself, explaining the patch, and so on. However, following the Rails on the Run GitHub tutorial, I was done in 5 minutes, even accounting for learning a new version control tool!

The way it works is just great - press the button to get your own fork, check it out, change the code, commit, and then press another button to send a “pull request” back to the main trunk. It really does make quite a difference - and if they don’t like my change, who cares? I now have my own version-controlled branch of Mephisto which I can use to manage my local copy, and make any other changes I feel like.

Thanks, git (and specifically GitHub’s web toolset), for solving problems I never even really knew I had.