<?xml version="1.0" encoding="UTF-8"?>
<feed xml:lang="en-US" xmlns="http://www.w3.org/2005/Atom">
  <title>James Smith - Main</title>
  <id>tag:www.floppy.org.uk,2008:mephisto/</id>
  <generator version="0.8.0" uri="http://mephistoblog.com">Mephisto Drax</generator>
  <link href="http://www.floppy.org.uk/feed/atom.xml" rel="self" type="application/atom+xml"/>
  <link href="http://www.floppy.org.uk/" rel="alternate" type="text/html"/>
  <updated>2008-08-29T10:17:24Z</updated>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-08-31:116</id>
    <published>2008-08-31T10:15:00Z</published>
    <updated>2008-08-29T10:17:24Z</updated>
    <category term="amee"/>
    <category term="json"/>
    <category term="monkeypatching"/>
    <category term="ruby"/>
    <link href="http://www.floppy.org.uk/2008/8/31/mocking-kernel-require" rel="alternate" type="text/html"/>
    <title>Mocking Kernel#require</title>
<content type="html">
            &lt;p&gt;
The other day, I remembered to add coverage analysis to my &lt;a href=&quot;http://github.com/Floppy/amee-ruby&quot;&gt;AMEE-Ruby&lt;/a&gt; tests, using &lt;a href=&quot;&quot;&gt;rcov&lt;/a&gt;. The results were pretty good - most of the code was already tested, except a few failure cases, and I quickly wrote some new tests to make sure those were working properly. One little bit of code stood out though. Because AMEE talks XML and JSON, my gem can use JSON, but only if the JSON gem is available on the system (XML support is built into core Ruby). Problem is, require calls throw errors if they fail, so I had to write some code to handle the load failure and carry on regardless. This is the code inside amee.rb:
&lt;/p&gt;&lt;p&gt;
&lt;pre class=&quot;zenburnesque&quot;&gt;
&lt;span class=&quot;LanguageKeyword&quot;&gt;begin&lt;/span&gt;
  &lt;span class=&quot;LanguageKeyword&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;json&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;LanguageKeyword&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;Variable&quot;&gt;LoadError&lt;/span&gt;
  &lt;span class=&quot;BuiltInConstant&quot;&gt;nil&lt;/span&gt;
&lt;span class=&quot;LanguageKeyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/p&gt;&lt;p&gt;
Problem with this is that the gem is installed on my system, so the require never fails, and the rescue is never used. Rcov notices, and I can't get to 100% coverage, which is &lt;em&gt;annoying&lt;/em&gt;.
&lt;/p&gt;&lt;p&gt;
So, mocking to the rescue. We have to make Kernel#rescue throw an error if we try to require 'json', even if the gem is installed. At first, I tried to use flexmock to do this, but couldn't make it work - if anyone knows how, &lt;em&gt;please&lt;/em&gt; tell me. My final approach was to monkeypatch Kernel#require inside my test so that require 'json' (and only json) would fail:
&lt;/p&gt;&lt;p&gt;
&lt;pre class=&quot;zenburnesque&quot;&gt;
it &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;should cope if json gem isn't available&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt; &lt;span class=&quot;LanguageKeyword&quot;&gt;do&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt;  &lt;span class=&quot;Comment&quot;&gt;#&lt;/span&gt; Monkeypatch Kernel#require to make sure that require 'json'&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt;  &lt;span class=&quot;Comment&quot;&gt;#&lt;/span&gt; raises a LoadError&lt;/span&gt;
  &lt;span class=&quot;LanguageKeyword&quot;&gt;module&lt;/span&gt; &lt;span class=&quot;TypeName&quot;&gt;Kernel&lt;/span&gt;
    &lt;span class=&quot;LanguageKeyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;FunctionName&quot;&gt;require_with_mock&lt;/span&gt;(&lt;span class=&quot;Variable&quot;&gt;string&lt;/span&gt;)
      &lt;span class=&quot;LanguageKeyword&quot;&gt;raise&lt;/span&gt; &lt;span class=&quot;LibraryClassType&quot;&gt;LoadError&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;LanguageKeyword&quot;&gt;if&lt;/span&gt; string &lt;span class=&quot;Operators&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;json&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;&lt;/span&gt; 
      &lt;span class=&quot;FunctionName&quot;&gt;require_without_mock&lt;/span&gt;(string)
    &lt;span class=&quot;LanguageKeyword&quot;&gt;end&lt;/span&gt;
    &lt;span class=&quot;LanguageKeyword&quot;&gt;alias_method&lt;/span&gt; &lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;require_without_mock&lt;/span&gt;, &lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;require&lt;/span&gt; 
    &lt;span class=&quot;LanguageKeyword&quot;&gt;alias_method&lt;/span&gt; &lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;require&lt;/span&gt;, &lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;require_with_mock&lt;/span&gt;
  &lt;span class=&quot;LanguageKeyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt;  &lt;span class=&quot;Comment&quot;&gt;#&lt;/span&gt; Remove amee.rb from required file list so we can load it again&lt;/span&gt;
  &lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Variable&quot;&gt;$&lt;/span&gt;&amp;quot;&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;delete_if&lt;/span&gt;{|&lt;span class=&quot;Variable&quot;&gt;x&lt;/span&gt;| x.&lt;span class=&quot;FunctionName&quot;&gt;include?&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;amee.rb&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;&lt;/span&gt;}
&lt;span class=&quot;Comment&quot;&gt;  &lt;span class=&quot;Comment&quot;&gt;#&lt;/span&gt; Require file - require 'json' should throw a LoadError,&lt;/span&gt;
&lt;span class=&quot;Comment&quot;&gt;  &lt;span class=&quot;Comment&quot;&gt;#&lt;/span&gt; but we should cope with it OK.&lt;/span&gt;
  lambda {
    &lt;span class=&quot;LanguageKeyword&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;amee&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;&lt;/span&gt;
  }.&lt;span class=&quot;FunctionName&quot;&gt;should_not&lt;/span&gt; raise_error
&lt;span class=&quot;LanguageKeyword&quot;&gt;end&lt;/span&gt;
&lt;/pre&gt;
&lt;/p&gt;&lt;p&gt;
We have to make a new require function, then use alias_method to rename the old one and install our new one in it's place. Rails includes alias_method_chain to make this easier, but that's not available in pure Ruby. Never mind. Once we've done the monkeypatch, we take amee.rb out of the $&quot; array, which lists all the currently-required files, to make sure we can require it again, then simply run the require and make sure it catches the error that is thrown by our patched require. And the most satisfying part? The rescue is executed, the test works, and we get to 100% coverage. I've got a nice warm fuzzy feeling inside... mmmmmm.
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-08-29:115</id>
    <published>2008-08-29T09:56:00Z</published>
    <updated>2008-08-29T10:18:39Z</updated>
    <category term="currentcost"/>
    <category term="eeml"/>
    <category term="github"/>
    <category term="pachube"/>
    <category term="ruby"/>
    <category term="webrick"/>
    <link href="http://www.floppy.org.uk/2008/8/29/currentcost-data-live-on-pachube" rel="alternate" type="text/html"/>
    <title>CurrentCost data live on Pachube</title>
<content type="html">
            &lt;p&gt;
So, the other day I got a nice little &lt;a href=&quot;&quot;&gt;tray icon&lt;/a&gt; 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.
&lt;/p&gt;&lt;p&gt;
&lt;a href=&quot;http://pachube.com&quot;&gt;Pachube&lt;/a&gt; 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.
&lt;/p&gt;&lt;p&gt;
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, &lt;a href=&quot;http://github.com/Floppy/eeml-ruby/tree/master&quot;&gt;available from GitHub&lt;/a&gt; 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.
&lt;/p&gt;&lt;p&gt;
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:
&lt;/p&gt;&lt;p&gt;
&lt;pre class=&quot;zenburnesque&quot;&gt;
&lt;span class=&quot;Comment&quot;&gt;&lt;span class=&quot;Comment&quot;&gt;#&lt;/span&gt; Create WEBrick server&lt;/span&gt;
s &lt;span class=&quot;Operators&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Variable&quot;&gt;WEBrick&lt;/span&gt;::&lt;span class=&quot;FunctionName&quot;&gt;HTTPServer&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;new&lt;/span&gt;( &lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;Port&lt;/span&gt; =&amp;gt; &lt;span class=&quot;Number&quot;&gt;50000&lt;/span&gt; )
&lt;span class=&quot;Comment&quot;&gt;&lt;span class=&quot;Comment&quot;&gt;#&lt;/span&gt; A simple &amp;quot;hello world&amp;quot; servlet &lt;/span&gt;
&lt;span class=&quot;LanguageKeyword&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;TypeName&quot;&gt;HelloServlet&lt;span class=&quot;InheritedClass&quot;&gt; &lt;span class=&quot;InheritedClass&quot;&gt;&amp;lt;&lt;/span&gt; WEBrick::HTTPServlet::AbstractServlet&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;LanguageKeyword&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;FunctionName&quot;&gt;do_GET&lt;/span&gt;(&lt;span class=&quot;Variable&quot;&gt;request&lt;span class=&quot;Variable&quot;&gt;,&lt;/span&gt; response&lt;/span&gt;)
    response.&lt;span class=&quot;FunctionName&quot;&gt;status&lt;/span&gt; &lt;span class=&quot;Operators&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;Number&quot;&gt;200&lt;/span&gt;
    response[&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;Content-Type&lt;span class=&quot;String&quot;&gt;'&lt;/span&gt;&lt;/span&gt;] &lt;span class=&quot;Operators&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;text/xml&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
    response.&lt;span class=&quot;FunctionName&quot;&gt;body&lt;/span&gt; &lt;span class=&quot;Operators&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;hello world&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
  &lt;span class=&quot;LanguageKeyword&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;LanguageKeyword&quot;&gt;end&lt;/span&gt;
s.&lt;span class=&quot;FunctionName&quot;&gt;mount&lt;/span&gt;(&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;/&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, &lt;span class=&quot;Variable&quot;&gt;HelloServlet&lt;/span&gt;)
&lt;/pre&gt;
&lt;/p&gt;&lt;p&gt;
Now, http://localhost:50000/ will say &quot;hello world&quot;. From here it's a simple modification to publish the EEML feed. EEML-Ruby includes a &lt;a href=&quot;http://github.com/Floppy/eeml-ruby/tree/master/examples/simple_server.rb&quot;&gt;simple EEML server script&lt;/a&gt; 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) &lt;a href=&quot;http://pachube.com/feeds/488&quot;&gt;live on Pachube&lt;/a&gt;.
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-08-22:60</id>
    <published>2008-08-22T09:25:00Z</published>
    <updated>2008-08-22T09:34:59Z</updated>
    <category term="currentcost"/>
    <category term="gem"/>
    <category term="github"/>
    <category term="ruby"/>
    <link href="http://www.floppy.org.uk/2008/8/22/some-successful-currentcost-hacking" rel="alternate" type="text/html"/>
    <title>Some successful CurrentCost hacking</title>
<content type="html">
            &lt;p&gt;
After a bit of work, I've finally got my &lt;a href=&quot;http://www.currentcost.com&quot;&gt;CurrentCost&lt;/a&gt; meter working in Ruby, and I now have a power monitor sitting in my system tray! There were a few stages involved...
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Serial comms:&lt;/strong&gt; 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 &lt;a href=&quot;http://github.com/Floppy/rb232&quot;&gt;GitHub&lt;/a&gt;. It only supports reading at the moment, and only works on Linux systems, but it's a start. Next!
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Reading CurrentCost data:&lt;/strong&gt; 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 &lt;a href=&quot;http://github.com/Floppy/currentcost-ruby&quot;&gt;Github&lt;/a&gt;.
&lt;/p&gt;
&lt;img src=&quot;http://www.floppy.org.uk/assets/2008/8/22/currentcost-tray-monitor.png&quot;&gt;
&lt;p&gt;
&lt;strong&gt;User interface:&lt;/strong&gt; 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 &lt;a href=&quot;http://rubyforge.org/projects/cctrayrb/&quot;&gt;cctrayrb&lt;/a&gt;, 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.
&lt;/p&gt;
&lt;p&gt;
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 :)
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-08-07:33</id>
    <published>2008-08-07T21:10:00Z</published>
    <updated>2008-08-07T21:15:17Z</updated>
    <category term="co2updates"/>
    <category term="facebook"/>
    <category term="github"/>
    <category term="jabber"/>
    <category term="twitter"/>
    <category term="xmpp"/>
    <link href="http://www.floppy.org.uk/2008/8/7/twitter-support-in-jabberstatus" rel="alternate" type="text/html"/>
    <title>Twitter support in JabberStatus</title>
<content type="html">
            &lt;p&gt;
&lt;a href=&quot;http://www.jabberstatus.org&quot;&gt;JabberStatus&lt;/a&gt; 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. 
&lt;/p&gt;
&lt;p&gt;
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.
&lt;/p&gt;
&lt;p&gt;
The JabberStatus code has &lt;a href=&quot;http://github.com/Floppy/jabberstatus&quot;&gt;moved to GitHub&lt;/a&gt; now, so you can grab it from there. The &lt;a href=&quot;http://github.com/Floppy/co2updates&quot;&gt;code for the CO2Updates app&lt;/a&gt; has also moved there.
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-08-06:32</id>
    <published>2008-08-06T09:56:00Z</published>
    <updated>2008-08-06T10:22:42Z</updated>
    <category term="Projects"/>
    <category term="carbon"/>
    <category term="github"/>
    <category term="ruby"/>
    <category term="twitter"/>
    <link href="http://www.floppy.org.uk/2008/8/6/one-hundred-months" rel="alternate" type="text/html"/>
    <title>One Hundred Months</title>
<content type="html">
            &lt;p&gt;
I just saw the &lt;a href=&quot;http://onehundredmonths.org/&quot;&gt;One Hundred Months&lt;/a&gt; campaign, and decided it was ripe for a bit of automated Twittering. So, 5 minutes hacking and we have &lt;a href=&quot;http://twitter.com/100months&quot;&gt;One Hundred Months on Twitter&lt;/a&gt;. Code (as ever these days) is available from &lt;a href=&quot;http://github.com/Floppy/onehundredmonths&quot;&gt;GitHub&lt;/a&gt;.
&lt;/p&gt;&lt;p&gt;
I'm amazed by what computers can do sometimes. This one seriously took me longer to publish to the world than to write.
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-08-06:31</id>
    <published>2008-08-06T00:09:00Z</published>
    <updated>2008-08-06T00:19:36Z</updated>
    <category term="amee"/>
    <category term="currentcost"/>
    <category term="energy"/>
    <category term="gem"/>
    <category term="github"/>
    <category term="meter"/>
    <category term="ruby"/>
    <link href="http://www.floppy.org.uk/2008/8/6/hacking-your-energy-usage-with-the-currentcost" rel="alternate" type="text/html"/>
    <title>Hacking your energy usage with the CurrentCost</title>
<content type="html">
            &lt;p&gt;
The other day, I managed to get hold of a &lt;a href=&quot;http://www.currentcost.com/&quot;&gt;CurrentCost&lt;/a&gt; energy monitor (available to buy from &lt;a href=&quot;https://www.ecogadgetshop.co.uk/ProductDetails.aspx?ProductCode=Current%20Cost%20Device%20(TEST)&amp;amp;Category=1&quot;&gt;here&lt;/a&gt;, 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 &lt;a href=&quot;http://rooreynolds.com/2008/07/06/current-cost-presentation-at-open-tech-2008/&quot;&gt;a bit of hacking&lt;/a&gt;) plug into your PC, and - bingo - lovely XML data!
&lt;/p&gt;&lt;p&gt;
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 &lt;a href=&quot;http://github.com/Floppy/currentcost-ruby/tree/master&quot;&gt;GitHub&lt;/a&gt;. So far it can only parse the XML data from the meter - direct access to the serial port is hopefully coming soon.
&lt;/p&gt;&lt;p&gt;
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.
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-07-10:30</id>
    <published>2008-07-10T21:29:00Z</published>
    <updated>2008-08-06T10:22:49Z</updated>
    <category term="Projects"/>
    <category term="amee"/>
    <category term="carbon"/>
    <category term="gem"/>
    <category term="github"/>
    <category term="ruby"/>
    <link href="http://www.floppy.org.uk/2008/7/10/amee-for-ruby" rel="alternate" type="text/html"/>
    <title>AMEE for Ruby</title>
<content type="html">
            &lt;p&gt;
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 &lt;a href=&quot;http://amee.cc&quot;&gt;AMEE&lt;/a&gt; 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 &lt;a href=&quot;http://github.com/Floppy/amee-ruby&quot;&gt;GitHub&lt;/a&gt;.
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-07-10:29</id>
    <published>2008-07-10T17:29:00Z</published>
    <updated>2008-07-11T08:58:01Z</updated>
    <category term="pipes"/>
    <category term="rss"/>
    <category term="twitter"/>
    <link href="http://www.floppy.org.uk/2008/7/10/filtering-twitter-with-pipes" rel="alternate" type="text/html"/>
    <title>Filtering Twitter with Pipes</title>
<content type="html">
            &lt;p&gt;
I like &lt;a href=&quot;http://twitter.com&quot;&gt;Twitter&lt;/a&gt;. 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 &lt;a href=&quot;http://pipes.yahoo.com&quot;&gt;Yahoo! Pipe&lt;/a&gt; to filter my own updates out of my feed, and you can use it too. Check it out &lt;a href=&quot;http://pipes.yahoo.com/floppy/twitter_filter&quot;&gt;here&lt;/a&gt;.
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-05-30:26</id>
    <published>2008-05-30T20:07:00Z</published>
    <updated>2008-08-10T21:36:25Z</updated>
    <category term="facebook"/>
    <category term="jabber"/>
    <category term="projects"/>
    <link href="http://www.floppy.org.uk/2008/5/30/announcing-jabberstatus" rel="alternate" type="text/html"/>
    <title>Announcing JabberStatus</title>
<content type="html">
            &lt;p&gt;
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 &lt;em&gt;so&lt;/em&gt; 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!
&lt;/p&gt;
&lt;p&gt;
&lt;a href=&quot;http://www.jabberstatus.org&quot;&gt;JabberStatus&lt;/a&gt; is a simple Ruby script which listens on a Jabber account and updates your Facebook status for you. You add &lt;strong&gt;facebook@jabber.org&lt;/strong&gt; 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!
&lt;/p&gt;
&lt;p&gt;
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 &lt;a href=&quot;http://github.com/Floppy/jabberstatus/&quot;&gt;take a look yourself&lt;/a&gt;. 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.
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-05-19:23</id>
    <published>2008-05-19T10:05:00Z</published>
    <updated>2008-05-19T10:27:50Z</updated>
    <category term="geekyoto"/>
    <category term="talks"/>
    <link href="http://www.floppy.org.uk/2008/5/19/geekyoto-08" rel="alternate" type="text/html"/>
    <title>geeKyoto 08</title>
<content type="html">
            &lt;p&gt;
&lt;a href=&quot;http://www.flickr.com/photos/cristiano_betta/2501865363/&quot;&gt;&lt;img src=&quot;http://farm3.static.flickr.com/2105/2501865363_d5e0e04c99_m.jpg&quot;&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
Well, Saturday was &lt;a href=&quot;http://www.geekyoto.com/&quot;&gt;geeKyoto 08&lt;/a&gt; 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.
&lt;/p&gt;
&lt;p&gt;
It was a great day though! The speakers were incredibly varied, from &lt;a href=&quot;http://www.google.co.uk/search?q=%22alex+haw%22+atmos&quot;&gt;Alex Haw&lt;/a&gt;, an architect/artist who has more ideas in a second than I do in a year, to a great presentation by Gavin Starks about &lt;a href=&quot;http://www.amee.cc&quot;&gt;AMEE&lt;/a&gt;, to a design student who &lt;a href=&quot;http://www.youtube.com/watch?v=nDqbb0eHVXA&quot;&gt;hung a swing in a bus stop&lt;/a&gt; (which got the day's most spontaneous round of applause). The whole thing was then rounded off by &lt;a href=&quot;http://www.bensaunders.com&quot;&gt;Ben Saunders&lt;/a&gt;, 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!
&lt;/p&gt;
&lt;p&gt;
Hopefully my talk (&quot;Can software save the world?&quot; - 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:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://www.carbondiet.org&quot;&gt;The Carbon Diet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://www.dothegreenthing.com&quot;&gt;Green Thing&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://twitter.com/co2updates&quot;&gt;CO2 Updates on Twitter&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://groups.google.com/group/green-web-uk&quot;&gt;Green Web UK mailing list&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-05-09:22</id>
    <published>2008-05-09T15:31:00Z</published>
    <updated>2008-05-09T15:35:38Z</updated>
    <category term="git"/>
    <category term="github"/>
    <category term="mephisto"/>
    <link href="http://www.floppy.org.uk/2008/5/9/adventures-with-github" rel="alternate" type="text/html"/>
    <title>Adventures with GitHub</title>
<summary type="html">&lt;p&gt;
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.
&lt;/p&gt;</summary><content type="html">
            &lt;p&gt;
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.
&lt;/p&gt;
&lt;p&gt;
While moving this site over to &lt;a href=&quot;http://mephistoblog.com&quot;&gt;Mephisto&lt;/a&gt;, I had a problem with the asset system, in that while assets have a &quot;title&quot; 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 &lt;a href=&quot;http://github.com&quot;&gt;GitHub&lt;/a&gt; these days, so it was time to dive in!
&lt;/p&gt;&lt;p&gt;
Normally, the process of sending a patch to an open source project is &lt;em&gt;just&lt;/em&gt; 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 &lt;a href=&quot;http://railsontherun.com/2008/3/3/how-to-use-github-and-submit-a-patch&quot;&gt;Rails on the Run GitHub tutorial&lt;/a&gt;, I was done in 5 minutes, even accounting for learning a new version control tool!
&lt;/p&gt;&lt;p&gt;
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 &quot;pull request&quot; 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.
&lt;/p&gt;&lt;p&gt;
Thanks, git (and specifically GitHub's web toolset), for solving problems I never even really knew I had.
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-05-09:18</id>
    <published>2008-05-09T10:55:00Z</published>
    <updated>2008-05-09T11:01:30Z</updated>
    <category term="mephisto"/>
    <category term="mod_rails"/>
    <category term="rails"/>
    <link href="http://www.floppy.org.uk/2008/5/9/a-whole-new-look" rel="alternate" type="text/html"/>
    <title>A whole new look</title>
<content type="html">
            &lt;p&gt;
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 &lt;a href=&quot;http://mephistobog.com&quot;&gt;Mephisto&lt;/a&gt;. It's deployed on my own virtual server, and is running under &lt;a href=&quot;http://www.modrails.com/&quot;&gt;Phusion Passenger&lt;/a&gt;, 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. 
&lt;/p&gt;&lt;p&gt;
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...
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-05-07:3</id>
    <published>2008-05-07T13:08:00Z</published>
    <updated>2008-08-10T21:38:02Z</updated>
    <category term="Projects"/>
    <category term="carbon"/>
    <category term="ruby"/>
    <category term="twitter"/>
    <link href="http://www.floppy.org.uk/2008/5/7/co2-on-twitter" rel="alternate" type="text/html"/>
    <title>CO2 on Twitter</title>
<content type="html">
            &lt;p&gt;
I read &lt;a href=&quot;http://infovore.org/archives/2008/02/28/making-bridges-talk/&quot;&gt;this article&lt;/a&gt; last night, about using Twitter to make machines talk, specifically &lt;a href=&quot;http://twitter.com/towerbridge&quot;&gt;Tower Bridge&lt;/a&gt;. &quot;What a fantastic idea&quot;, I thought to myself. &quot;Maybe I can do the same thing for climate change&quot;. Also, it would be a good way to flex my Ruby muscles a little and get some &quot;fun&quot; coding in for the first time since Amelia was born.
&lt;/p&gt;&lt;p&gt;
So, a couple of hours of Ruby later, and we have &lt;a href=&quot;http://twitter.com/co2updates&quot;&gt;atmospheric CO2 updates on Twitter&lt;/a&gt;. The code is dead simple, and can be grabbed from &lt;a href=&quot;http://github.com/Floppy/co2updates&quot;&gt;GitHub&lt;/a&gt;.
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-02-01:2</id>
    <published>2008-02-01T09:54:00Z</published>
    <updated>2008-08-29T10:08:10Z</updated>
    <category term="limit"/>
    <category term="offset"/>
    <category term="rails"/>
    <category term="sanitize"/>
    <link href="http://www.floppy.org.uk/2008/2/1/sanitizing-limit-and-offset" rel="alternate" type="text/html"/>
    <title>Sanitizing :limit and :offset</title>
<content type="html">
            &lt;p&gt;
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:
&lt;/p&gt;&lt;p&gt;
&lt;pre class=&quot;zenburnesque&quot;&gt;
&lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Variable&quot;&gt;@&lt;/span&gt;examples&lt;/span&gt; &lt;span class=&quot;Operators&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;LibraryClassType&quot;&gt;Example&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;find&lt;/span&gt;(&lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;all&lt;/span&gt;, &lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;limit&lt;/span&gt; =&amp;gt; params[&lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;limit&lt;/span&gt;], &lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;offset&lt;/span&gt; =&amp;gt; params[&lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;offset&lt;/span&gt;])
&lt;/pre&gt;
&lt;/p&gt;&lt;p&gt;
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:
&lt;/p&gt;&lt;p&gt;
&lt;pre class=&quot;zenburnesque&quot;&gt;
&lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Variable&quot;&gt;@&lt;/span&gt;examples&lt;/span&gt; &lt;span class=&quot;Operators&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;LibraryClassType&quot;&gt;Example&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;find&lt;/span&gt;(&lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;all&lt;/span&gt;, &lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;conditions&lt;/span&gt; =&amp;gt; [&lt;span class=&quot;String&quot;&gt;&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;name LIKE ?&lt;span class=&quot;String&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;, params[&lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;name&lt;/span&gt;])
&lt;/pre&gt;
&lt;/p&gt;&lt;p&gt;
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):
&lt;/p&gt;&lt;p&gt;
&lt;pre class=&quot;zenburnesque&quot;&gt;
&lt;span class=&quot;Variable&quot;&gt;&lt;span class=&quot;Variable&quot;&gt;@&lt;/span&gt;examples&lt;/span&gt; &lt;span class=&quot;Operators&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;LibraryClassType&quot;&gt;Example&lt;/span&gt;.&lt;span class=&quot;FunctionName&quot;&gt;find&lt;/span&gt;(&lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;all&lt;/span&gt;, &lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;limit&lt;/span&gt; =&amp;gt; (params[&lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;limit&lt;/span&gt;].&lt;span class=&quot;FunctionName&quot;&gt;nil?&lt;/span&gt; &lt;span class=&quot;Operators&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;BuiltInConstant&quot;&gt;nil&lt;/span&gt; : params[&lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;limit&lt;/span&gt;].&lt;span class=&quot;FunctionName&quot;&gt;to_i&lt;/span&gt;),
                               &lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;offset&lt;/span&gt; =&amp;gt; (params[&lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;offset&lt;/span&gt;].&lt;span class=&quot;FunctionName&quot;&gt;nil?&lt;/span&gt; &lt;span class=&quot;Operators&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;BuiltInConstant&quot;&gt;nil&lt;/span&gt; : params[&lt;span class=&quot;UserDefinedConstant&quot;&gt;&lt;span class=&quot;UserDefinedConstant&quot;&gt;:&lt;/span&gt;offset&lt;/span&gt;].&lt;span class=&quot;FunctionName&quot;&gt;to_i&lt;/span&gt;))
&lt;/pre&gt;
&lt;/p&gt;&lt;p&gt;
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.
&lt;/p&gt;&lt;p&gt;
Of course, if I've missed something glaringly obvious, please let me know ;)
&lt;/p&gt;
          </content>  </entry>
  <entry xml:base="http://www.floppy.org.uk/">
    <author>
      <name>james</name>
    </author>
    <id>tag:www.floppy.org.uk,2008-01-09:1</id>
    <published>2008-01-09T01:39:00Z</published>
    <updated>2008-05-07T21:24:34Z</updated>
    <category term="testing"/>
    <category term="trac"/>
    <category term="workflow"/>
    <link href="http://www.floppy.org.uk/2008/1/9/testing-in-trac" rel="alternate" type="text/html"/>
    <title>Testing in Trac</title>
<content type="html">
            &lt;p&gt;
Hurrah, I've just contributed my first code back to the &lt;a href=&quot;http://trac.edgewall.org/&quot;&gt;Trac&lt;/a&gt; project. I've created a workflow for the 0.11 release which adds a simple &quot;testing&quot; state to tickets before they are closed. For the Trac addicts amongst you, it's available at &lt;a href=&quot;http://trac-hacks.swapoff.org/wiki/TestingWorkflow&quot;&gt;Trac Hacks&lt;/a&gt;. I'm rather proud of it, because it's actually the first workflow hack on the site!
&lt;/p&gt;
          </content>  </entry>
</feed>
