<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Philip Mcmahon</title>
 <link href="http://snaggled.github.com/atom.xml" rel="self"/>
 <link href="http://snaggled.github.com/"/>
 <updated>2011-06-22T08:38:28-07:00</updated>
 <id>http://snaggled.github.com/</id>
 <author>
   <name>Philip Mcmahon</name>
   <email>philip@packetnode.com</email>
 </author>

 
 <entry>
   <title>Sim Hacking</title>
   <link href="/2011/06/22/sim-hacking.html"/>
   <updated>2011-06-22T00:00:00-07:00</updated>
   <id>/2011/06/22/sim-hacking</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2011/06/22/sim-hacking.html&quot;&gt;Sim Hacking&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;22 June 2011 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;p&gt;Summer is here and its epic. Quit the enterprisey &lt;a href=&quot;http://ibm.com&quot;&gt;&lt;span class=&quot;caps&quot;&gt;IBM&lt;/span&gt;&lt;/a&gt; product management job to go back to startup-land. &lt;a href=&quot;http://snugghome.com&quot;&gt;These guys&lt;/a&gt; are very smart, great to work with, and trying to change the world. I&amp;#8217;ve also been knocking out some iPad &amp;amp; Android code at the weekend, so posts to come.&lt;/p&gt;
&lt;p&gt;I picked up a used Samsung Captivate so I could get my hands dirty with some &lt;a href=&quot;http://developer.android.com/reference/android/os/package-summary.html&quot;&gt;Android OS&lt;/a&gt; code.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img class=&quot;centered&quot; src=&quot;http://reviews.cnet.com/sc/34121737-2-440-OVR-1.gif&quot; alt=&quot;Samsung Captivate&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;The only snag is that it wanted a standard &lt;span class=&quot;caps&quot;&gt;SIM&lt;/span&gt; and all I had to hand (from my iPhone 4)was  a micro-sim:&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img class=&quot;centered&quot; src=&quot;/images/before.jpg&quot; alt=&quot; Before&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;A quandary! Not to be outdone, and in the interests of the &lt;a href=&quot;http://en.wikipedia.org/wiki/Hacker_ethic#Hands-on_imperative&quot;&gt;hands on imperative&lt;/a&gt; I decided to butcher an old &lt;span class=&quot;caps&quot;&gt;SIM&lt;/span&gt;-card and turn it into a placeholder for the micro-&lt;span class=&quot;caps&quot;&gt;SIM&lt;/span&gt;. In short:&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img class=&quot;centered&quot; src=&quot;/images/after.jpg&quot; alt=&quot; After&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;And it works! This pleases me immensely. Android code to come!&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>The Summer of Horror, Carrion Crown, Legacy of Fire</title>
   <link href="/2011/04/03/summer-of-horror.html"/>
   <updated>2011-04-03T00:00:00-07:00</updated>
   <id>/2011/04/03/summer-of-horror</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2011/04/03/summer-of-horror.html&quot;&gt;The Summer of Horror, Carrion Crown, Legacy of Fire&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;3 April 2011 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;p&gt;It&amp;#8217;s rare (ever ?) that I make a non-programming post, but there&amp;#8217;s so much roleplaying awesome-sauce going on at the minute that I had to let it out.&lt;/p&gt;
&lt;p&gt;Firstly, the upcoming trip to Ireland provided a well-timed opportunity to wrap up a couple of the campaigns I&amp;#8217;ve been partaking in. The first was the conclusion of the &amp;#8220;Price of Immortality&amp;#8221; trilogy I was DMing. Lasting 9 sessions, this mini-campaign took the characters from the sleepy town of &lt;a href=&quot;http://s202.photobucket.com/albums/aa143/cpanthersfan/Golarion/?action=view&amp;amp;current=Kassen.png&amp;amp;sort=ascending&quot;&gt;Kassen&lt;/a&gt; to a final showdown with a &lt;a href=&quot;http://pathfinder.wikia.com/wiki/Razmir&quot;&gt;Razmir&lt;/a&gt; obsessed elven sorceress called &lt;a href=&quot;http://7eme-ruellerouge.deviantart.com/art/Elf-Iramine-159731653?q=sort%3Atime+gallery%3A7eme-ruellerouge&amp;amp;qo=3&amp;amp;offset=30&quot;&gt;Iramine&lt;/a&gt; in the impressive and deadly City of Golden Death.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img class=&quot;centered&quot; src=&quot;http://paizo.com/image/product/catalog/PZO/PZO9524_500.jpeg&quot; alt=&quot;City of Golden Death&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;Secondly was the conclusion of the epic and stunningly good &lt;a href=&quot;http://paizo.com/pathfinder/adventurePath/legacyOfFire&quot;&gt;Legacy of Fire&lt;/a&gt; adventure path, led by a good friend and incredible DM &lt;a href=&quot;http://www.facebook.com/people/Dave-Dostaler/100001001179978&quot;&gt;Dave&lt;/a&gt;. I cannot speak highly enough about the dedication, skill-set and general awesomeness of Dave, the ensemble of characters he gathered around, and the great story that was spun. Lasting around 2 years, it culminated on Friday evening with an epic battle between the party (2 of whom died) and the epic efreet villan &amp;#8220;Javhul&amp;#8221; (pictured below). We celebrated the finale with a couple of six packs (of &lt;a href=&quot;http://www.newbelgium.com/beer/detail.aspx?id=c35e8a3e-0a8c-404d-8b74-b03fe3e90c44&quot;&gt;Ranger&lt;/a&gt;  beer no less) and the stoke has lasted all weekend.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img class=&quot;centered&quot; src=&quot;http://paizo.com/image/product/catalog/PZO/PZO9024_500.jpeg&quot; alt=&quot;The Final Wish&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;All in all, this campaign was the essence and the justification for my roleplaying hobby. As far as I am concerned, in an economic system designed to encourage (if not mandate) competitiveness, and a social system that fosters selfishness, greed and the enforcement of group-derived values, principles and definitions of normality, there exists no higher calling than that of seeking out compatible companions, led by the grand over-arching vision of a single person, and embarking upon a communal storytelling exercise. An exercise that facilitates the abandonment of all known (societal and self-imposed) restrictions, pre-conceptions rules, and that effectively allows the creation of a utopian (or perhaps even dystopian) alternate existence.&lt;/p&gt;
&lt;p&gt;For kicks, here&amp;#8217;s a few happy memories from the campaign.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img class=&quot;centered&quot; src=&quot;http://paizo.com/image/content/Blog/3DBattleMarket1.jpg&quot; alt=&quot;Battle Market&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img class=&quot;centered&quot; src=&quot;images/b.jpg&quot; alt=&quot;The Assault on Kelmarane&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;And the final roll that ended the campaign:&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img class=&quot;centered&quot; src=&quot;images/d20.jpg&quot; alt=&quot;The Final Roll&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;After a brief vacation, I&amp;#8217;ll be kicking off the summer with 2 horror-related storylines that I&amp;#8217;m very excited about. First up is the &lt;a href=&quot;http://paizo.com/pathfinder/adventurePath/carrionCrown&quot;&gt;Carrion Crown&lt;/a&gt; adventure path, currently being published with paizo. I intend to run this on a weekly basis, possibly getting through it in about 9 months. With undead, werewolves, flesh-golems and ultimately a cult desperate to bring back the arch-lich &lt;a href=&quot;http://paizo.com/image/product/catalog/PZO/PZO2002-2_500.jpeg&quot;&gt;Tar-Baphon&lt;/a&gt;, it promises to provide some fun horrortainment.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img class=&quot;centered&quot; src=&quot;http://paizo.com/image/product/catalog/PZO/PZO9043_500.jpeg&quot; alt=&quot;Tar Baphon&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;Secondly, I promised some friends I&amp;#8217;d run them through a &lt;a href=&quot;http://en.wikipedia.org/wiki/Call_of_Cthulhu_(role-playing_game)&quot;&gt;Call of Cthulhu&lt;/a&gt; one-shot. I&amp;#8217;ve select &amp;#8220;Bad Moon Rising&amp;#8221; from the &amp;#8220;Great Old Ones&amp;#8221; sourcebook, which I&amp;#8217;m very excited about &amp;#8211; it&amp;#8217;s a lot more epic that previous CoC one-shots, so we&amp;#8217;ll see how it goes.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;img class=&quot;centered&quot; src=&quot;http://www.collectibles-articles.com/antique/collectible-image-large/cal-of-cthulhu-1920s-the-great-old-ones-chaosium-1989_170611949462.jpg&quot; alt=&quot;Great Old Ones&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;And that&amp;#8217;s about it, celebrating the kids birthday today, so we&amp;#8217;re heading out to PF Changs. I&amp;#8217;m in the mood for some IPad programming, so expect to see some related posts soon.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Two Quick Gems to Round Out the Week</title>
   <link href="/2011/01/21/two-quick-gems.html"/>
   <updated>2011-01-21T00:00:00-08:00</updated>
   <id>/2011/01/21/two-quick-gems</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2011/01/21/two-quick-gems.html&quot;&gt;Two Quick Gems to Round Out the Week&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;21 Jan 2011 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;p&gt;Good week, lots accomplished. 60 minutes until I knock off for pizza and beer, here&amp;#8217;s something I thought up as I started to wind down for the week and knocked up this Friday afternoon. I&amp;#8217;ve been thinking about an automated file-storage solution in ruby for a while now. This afternoon I thought &amp;#8220;What if I wanted to backup some of my files to an internal (enterprise) file server ?&amp;#8221;. The two modules I&amp;#8217;m about to detail are the result of that thought process.&lt;/p&gt;
&lt;p&gt;The first thing we need to do is gather the details of all the files we need. &lt;a href=&quot;http://www.sqlite.org/&quot;&gt;SQLite3&lt;/a&gt; is probably suitable enough. All we need to do is accept some parameters and build a nice little cache of file information. Source code &lt;a href=&quot;https://github.com/snaggled/hungrynoodle&quot;&gt;here&lt;/a&gt; (you can tell I was getting hungry by the name). The gem is built &lt;a href=&quot;https://rubygems.org/gems/hungrynoodle&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To use it is very simple, lets say we want to build a quick cache of all the pdf files in our home directory:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
  require 'rubygems'
  require 'hungrynoodle'
  h = HungryNoodle.new('/Users/snaggled', '\.pdf')
  h.find_and_insert
&lt;/pre&gt;
&lt;p&gt;We can query that via the following:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt;   
  h.basenames
&lt;/pre&gt;

&lt;p&gt;Secondly, I picked the internal &lt;a href=&quot;http://domino.watson.ibm.com/cambridge/research.nsf/99751d8eb5a20c1f852568db004efc90/7ea66f4eb9382eaf852573d1005cff95!OpenDocument&quot;&gt;&lt;span class=&quot;caps&quot;&gt;IBM&lt;/span&gt; Cattail&lt;/a&gt;&lt;br /&gt;
as a file storage destination because I like it &amp;#8211; it&amp;#8217;s a cool system, its &lt;span class=&quot;caps&quot;&gt;REST&lt;/span&gt; based, etc, etc.&lt;/p&gt;
&lt;p&gt;A quick &lt;a href=&quot;https://rubygems.org/gems/cattail&quot;&gt;gem&lt;/a&gt; to facilitate uploading and querying files, and we&amp;#8217;re in a position to back up files we care about.&lt;/p&gt;
&lt;p&gt;Heres a quick and dirty script to facilitate:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
  require 'rubygems'
  require 'cattail'
  require 'hungrynoodle'

  if ARGV.length != 4
    p &quot;Usage: cattail &amp;lt;directory, e.g. '.'&amp;gt; 
                      &amp;lt;extension to be stored, e.g 'ppt'&amp;gt; 
                      &amp;lt;cattail login&amp;gt; 
                      &amp;lt;cattail passwd&amp;gt;&quot;
    exit(-1)
  end

  dir = ARGV[0]
  extension = ARGV[1]
  login = ARGV[2]
  passwd = ARGV[3]

  # establish connections 
  hungrynoodle = HungryNoodle.new(
    dir, 
    &quot;\.#{extension}&quot;, 
    &quot;#{extension}.db&quot;, 
    &quot;#{extension}.txt&quot;)
  cattail = Cattail.new(login, passwd)

  hungrynoodle.find_and_insert

  local_files = hungrynoodle.basenames
  remote_files = cattail.list
  diff = local_files - remote_files

  diff.each do |file|
  	file_record = hungrynoodle.file(file)
  	p &quot;Uploading #{file_record[0][3]}&quot;
  	cattail.insert(file_record[0][3])
  end
&lt;/pre&gt;

&lt;p&gt;And that&amp;#8217;s it. Back to our earlier example:&lt;/p&gt;
&lt;pre class='brush:bash,gutter:false'&gt; 
  ruby cattail.rb /Users/snaggled pdf login passwd
&lt;/pre&gt;
&lt;p&gt;That will grab all the PDFs in our home directory and make sure they are all sent to the backup server. I&amp;#8217;ll let that bad boy run and knock off for some pizza and beer, let the weekend begin.&lt;/p&gt;
&lt;p&gt;Todays musings in accompaniment to this sweet album:&lt;br /&gt;
&lt;br/&gt;
&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://ecx.images-amazon.com/images/I/518YM2Wn6NL._SS400_.jpg&quot; alt=&quot;Apparat - Things to be Frickled&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>The Wonderful World of Private iPhone APIs</title>
   <link href="/2011/01/14/the-wonderful-world-of-private-iphone-apis.html"/>
   <updated>2011-01-14T00:00:00-08:00</updated>
   <id>/2011/01/14/the-wonderful-world-of-private-iphone-apis</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2011/01/14/the-wonderful-world-of-private-iphone-apis.html&quot;&gt;The Wonderful World of Private iPhone APIs&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;14 Jan 2011 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;
&lt;p&gt;Also known as &amp;#8220;How to get your app submission quickly rejected from the Apple AppStore&amp;#8221;. Christmas was epic &amp;#8211; plenty of beer, parties, and the kids had a blast. I also had plenty of time to catch up on a few projects, so there&amp;#8217;s lot of material to blog about.&lt;br /&gt;
&lt;br/&gt;
First up, off the top of my head, was the discovery that not all is as it seems with the &lt;a href=&quot;http://developer.apple.com/devcenter/ios/index.action&quot;&gt;iPhone &lt;span class=&quot;caps&quot;&gt;SDK&lt;/span&gt;&lt;/a&gt;. Lets start by making an &lt;span class=&quot;caps&quot;&gt;SSL&lt;/span&gt;/&lt;span class=&quot;caps&quot;&gt;HTTPS&lt;/span&gt; call from the phone:&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&amp;amp;response error:&amp;amp;error];
&lt;/pre&gt;
&lt;p&gt;Vanilla stuff. Except, that if you&amp;#8217;re &lt;span class=&quot;caps&quot;&gt;SSL&lt;/span&gt; certificate is phoney or not valid, the phone&amp;#8217;s going to complain bitterly with an &amp;#8220;untrusted server certificate&amp;#8221; error. Fair enough, but what if we don&amp;#8217;t have a real &lt;span class=&quot;caps&quot;&gt;SSL&lt;/span&gt; certificate ? What if we&amp;#8217;re on some ad-hoc test machine and not production ?&lt;/p&gt;
&lt;p&gt;And to the rescue comes a &lt;em&gt;private&lt;/em&gt; &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt;. &lt;em&gt;Private&lt;/em&gt; as in its there in the &lt;span class=&quot;caps&quot;&gt;SDK&lt;/span&gt; but the documentation doesn&amp;#8217;t reflect it. Kind of like a little mini-christmas from Apple.&lt;/p&gt;
&lt;p&gt;We simply add this to our delegate and we&amp;#8217;re good to go. In short:&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
  + (BOOL)allowsAnyHTTPSCertificateForHost:(NSString *)host
  {
  	NSLog(@&quot;allowsAnyHTTPSCertificateForHost&quot;);

  	return YES; // Or whatever logic
  }
&lt;/pre&gt;
&lt;p&gt;My understanding is that having a private &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; in your code will result in your app getting rejected from the AppStore, so remember to take it out before you submit.&lt;/p&gt;
&lt;p&gt;One final note of importance &amp;#8211; epic album &amp;#8211; Gargantuan #minimal/#progressive/#techno.&lt;br /&gt;
&lt;br/&gt;
&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://ecx.images-amazon.com/images/I/51UAZs8cKTL._SS500_.jpg&quot; alt=&quot;Lee Burridge - Balance 12&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Autechre + Great Divide Sampler + Objective C == Nirvana</title>
   <link href="/2010/11/15/autechre-plus-objectivec-great-divide-sampler-equals-nirvana.html"/>
   <updated>2010-11-15T00:00:00-08:00</updated>
   <id>/2010/11/15/autechre-plus-objectivec-great-divide-sampler-equals-nirvana</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/11/15/autechre-plus-objectivec-great-divide-sampler-equals-nirvana.html&quot;&gt;Autechre + Great Divide Sampler + Objective C == Nirvana&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;15 Nov 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;p&gt;Honestly, it was. It was like the early 90s all over again &amp;#8211; I might as well have had &lt;a href=&quot;http://www.youtube.com/watch?v=Hlfd6kG0Lm8&quot;&gt;Poland&lt;/a&gt; by &lt;a href=&quot;http://www.tangerinedream.org/&quot;&gt;Tangerine Dream&lt;/a&gt; on the stereo and been hacking away at some Amiga 68k assembler, whilst connecting to a &lt;a href=&quot;http://www.razor1911.com/demo/?menu=history&quot;&gt;Razor 1911&lt;/a&gt; &lt;span class=&quot;caps&quot;&gt;BBS&lt;/span&gt; on my trusty &lt;a href=&quot;http://www.techfuels.com/attachments/general-networking/9618d1230698911-u-s-robotics-usr3453c-u.s.-robotics-usr3453c.jpg&quot;&gt;14.4k US Robotics &lt;span class=&quot;caps&quot;&gt;HST&lt;/span&gt; modem&lt;/a&gt; (which cost me a fortune back then). I have to say I miss those days. Nonetheless, I managed to get pretty close to that feeling on Saturday night with some iPhone coding, a few of these bad boys:     &lt;br /&gt;
&lt;br/&gt;
&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;/images/great_divide1.jpg&quot; alt=&quot;Great Divide&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;                                                                                                        &lt;br /&gt;
And this on the stereo:&lt;br /&gt;
&lt;br/&gt;
&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://www.nuevaforma.com/wp-content/uploads/2009/05/autechre-amber.jpg&quot; alt=&quot;Autechre Amber&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;
No sine-waves or fun demo comps this time, instead it was some daft Objective-C issue that took me to endorphin-land. All I wanted was to be able to check/uncheck a &amp;#8216;Same As Billing&amp;#8217; field in a registration form, and have the form modified accordingly. Hardly rocket-science, right ? Think &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; inserting some additional fields into an &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; div. I basically wanted the same thing on the iPhone.&lt;/p&gt;
&lt;p&gt;In short, we just want things to look like this when the checkbox is marked:    &lt;br /&gt;
&lt;br/&gt;
&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;/images/before.png&quot; alt=&quot;before&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;And this when its not:    &lt;br /&gt;
&lt;br/&gt;
&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;/images/after.png&quot; alt=&quot;after&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;Pretty standard &lt;a href=&quot;http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html&quot;&gt;UITableView&lt;/a&gt; stuff, we need to:&lt;/p&gt;
&lt;p&gt;1. Add ourselves as a UITableView &lt;a href=&quot;http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/occ/intf/UITableViewDelegate&quot;&gt;delegate&lt;/a&gt;&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
@interface RegisterViewController : UIViewController &amp;lt;UITableViewDelegate&amp;gt;,
&lt;/pre&gt;

&lt;p&gt;2. Implement didSelectRowAtIndexPath&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
- (void)tableView:(UITableView *)view didSelectRowAtIndexPath:(NSIndexPath*)newIndexPath
&lt;/pre&gt;
&lt;p&gt;3. Insert &amp;amp; Delete the required sections/rows accordingly&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
[view insertSections:[NSIndexSet indexSetWithIndex:5] 
  withRowAnimation:UITableViewRowAnimationFade];
&lt;/pre&gt;

&lt;p&gt;Everything worked just peachy, except when I&amp;#8217;d try to &amp;#8216;re-check&amp;#8217; what I&amp;#8217;d just unchecked. At that point, it would appear that only a subset of the rows I wanted inserted, would actually appear. In fact, just the last one:&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;/images/final.png&quot; alt=&quot;final&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;I spent several hours banging my head against the desk (i.e. drinking more beer), to eventually figure out that it was &lt;a href=&quot;http://developer.apple.com/library/ios/#documentation/uikit/reference/UIResponder_Class/Reference/Reference.html#//apple_ref/occ/cl/UIResponder&quot;&gt;becomeFirstResponder&lt;/a&gt;. I was inadvertently setting each field I created to be the first responder, and it appeared to be working fine, except when I tried to dynamically insert sections/rows and it got very confused.&lt;/p&gt;
&lt;p&gt;Some additional care taken when setting becomeFirstResponder, and its all good, got a nice buzz going and it was time to watch &lt;a href=&quot;http://www.imdb.com/title/tt1289806/&quot;&gt;this documentary&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;
&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://4.bp.blogspot.com/_8lRGZoO4YYE/S08z5lLY4TI/AAAAAAAABtU/Qlwxku_d0VA/s400/Kraftwerk-AndTheElectronicRevolutio.jpeg&quot; alt=&quot;kraftwerk&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;Which was epic :)&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Finished the Breckenridge Brewery Sampler Pack and Running on Ruby 1.9.2 + Rails 3</title>
   <link href="/2010/11/04/running-on-rails3.html"/>
   <updated>2010-11-04T00:00:00-07:00</updated>
   <id>/2010/11/04/running-on-rails3</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/11/04/running-on-rails3.html&quot;&gt;Finished the Breckenridge Brewery Sampler Pack and Running on Ruby 1.9.2 + Rails 3&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;4 Nov 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;p&gt;Todays broadcast brought to you by the always epic album:       &lt;br /&gt;
&lt;br/&gt;
&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://upload.wikimedia.org/wikipedia/en/f/f6/Shoat.jpg&quot; alt=&quot;History of a Time to Come&quot;/&gt;        &lt;br /&gt;
&lt;br/&gt;&lt;/p&gt;
&lt;p&gt;Took me a while to get round to this. I&amp;#8217;ve meet meaning to upgrade the &lt;a href=&quot;http://www.osx86project.org/&quot;&gt;hackintosh&lt;/a&gt; to Snow Leopard, so I&amp;#8217;ve been putting off most other upgrades until I get round to it. Anyway, this evening I could wait no longer and took the &lt;a href=&quot;http://www.ruby-lang.org/en/news/2010/08/18/ruby-1-9-2-is-released/&quot;&gt;Ruby 1.9.2&lt;/a&gt; plunge as well as installing the &lt;a href=&quot;http://www.rubyinside.com/rails-3-0-released-and-22-free-videos-to-bring-you-up-to-speed-3733.html&quot;&gt;Rails 3.0.1&lt;/a&gt; gems.&lt;/p&gt;
&lt;p&gt;What can I say ? Along the way I discovered something I absolutely &lt;strong&gt;love&lt;/strong&gt;. &lt;a href=&quot;http://rvm.beginrescueend.com/&quot;&gt;Ruby Version Manager&lt;/a&gt; is literally the dogs bollocks. It freaking awesome. No more &amp;#8216;sudo gem install&amp;#8217;. I now have &lt;a href=&quot;http://ruby-doc.org/core/&quot;&gt;1.8.6&lt;/a&gt;, &lt;a href=&quot;http://ruby-doc.org/core-1.8.7/index.html&quot;&gt;1.8.7&lt;/a&gt; and &lt;a href=&quot;http://ruby-doc.org/ruby-1.9/index.html&quot;&gt;1.9.2&lt;/a&gt; rubies, all with their own &lt;a href=&quot;http://rvm.beginrescueend.com/gemsets/&quot;&gt;gemsets&lt;/a&gt;, instantly switchable in 1 command line. Go check it out, I dare you not to love it.&lt;/p&gt;
&lt;p&gt;What else ? One thing I did notice is that &lt;a href=&quot;http://relishapp.com/rspec&quot;&gt;RSpec&lt;/a&gt; has changed considerably. None of the previous 1.3 specs worked in a couple of the plugins I played with. To that end, I&amp;#8217;ve checked in patches for &lt;a href=&quot;https://github.com/snaggled/feedzirra&quot;&gt;feedzilla&lt;/a&gt; and &lt;a href=&quot;https://github.com/snaggled/sax-machine&quot;&gt;sax-machine&lt;/a&gt;. You can either clone those repositories and build your own gems locally, or wait until the changes are pulled into the man repos, which are &lt;a href=&quot;https://github.com/pauldix/feedzirra&quot;&gt;here&lt;/a&gt;  and &lt;a href=&quot;https://github.com/pauldix/sax-machine&quot;&gt;here&lt;/a&gt; respectively.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Indexing Pathfinder Society Modules in Rails</title>
   <link href="/2010/11/01/indexing-pathfinder-society-modules-in-rails.html"/>
   <updated>2010-11-01T00:00:00-07:00</updated>
   <id>/2010/11/01/indexing-pathfinder-society-modules-in-rails</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/11/01/indexing-pathfinder-society-modules-in-rails.html&quot;&gt;Indexing Pathfinder Society Modules in Rails&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;1 Nov 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;p&gt;I play a lot of &lt;a href=&quot;http://paizo.com&quot;&gt;Pathfinder&lt;/a&gt;, which is actually an incarnation of &lt;a href=&quot;http://en.wikipedia.org/wiki/Dungeons_%26_Dragons&quot;&gt;Dungeons &amp;amp; Dragons&lt;/a&gt;. I love paizo and think the quality of the stuff they produce is outstanding. Anyway, I was having a little trouble navigating the list of modules/scenarios available, so a spare saturday afternoon knocked up a site called &lt;a href=&quot;http://librisarcanis.com&quot;&gt;libris arcanis&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This is perfect for Rails. Its a quick &lt;a href=&quot;http://rake.rubyforge.org/classes/Rake/Task.html&quot;&gt;rake task&lt;/a&gt; to fetch the data, with &lt;a href=&quot;http://api.rubyonrails.org/classes/ActiveRecord/Base.html&quot;&gt;active record&lt;/a&gt; abstracting all the heavy lifting. All we need to do is stick a controller in front of it and some pretty &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt; (which a grabbed from &lt;a href=&quot;http://www.gamerclubhouse.com/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;LFR&lt;/span&gt; Compendium&lt;/a&gt; so kudos to those guys for letting me use it).&lt;/p&gt;
&lt;p&gt;I haven&amp;#8217;t had a chance to add things to github yet, but in short, this is why I love rails. All in, this was about 4-8 hours effort an a saturday afternoon, fueled by:&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://sas.guidespot.com/bundles/guides_rp/assets/widget_cRoBvoHK5eG49QXtyET0Ds.jpg&quot; alt=&quot;Vanilla Porter&quot;/&gt;  &lt;br /&gt;
&lt;br/&gt;
C&amp;#8217;est tout! Getting sprinklers blown out for the winter, must run!&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Fun with MapReduce and Hadoop (Calculating Stock Market Statistics in a Parallel Fashion)</title>
   <link href="/2010/10/29/Fun-with-MapReduce-Hadoop.html"/>
   <updated>2010-10-29T00:00:00-07:00</updated>
   <id>/2010/10/29/Fun-with-MapReduce-Hadoop</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/10/29/Fun-with-MapReduce-Hadoop.html&quot;&gt;Fun with MapReduce and Hadoop (Calculating Stock Market Statistics in a Parallel Fashion)&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;19 Oct 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;p&gt;Epic summer. Lots of camping, bbq, boating and drinking great Colorado microbrews. Really can&amp;#8217;t complain. Fall coming in means my mind is wandering to some more abstract problems, and one of the things on my list was to look at &lt;a href=&quot;http://en.wikipedia.org/wiki/MapReduce&quot;&gt;MapReduce&lt;/a&gt;. The new &lt;a href=&quot;http://www.autechre.ws/move-of-ten/&quot;&gt;Autechre&lt;/a&gt; album seems fitting background music to this type of endeavor.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://ecx.images-amazon.com/images/I/51XCBZHZyQL._SS500_.jpg&quot; alt=&quot;Move Of Ten&quot;/&gt;&lt;/p&gt;
&lt;p&gt;This isn&amp;#8217;t the place for an in-depth tutorial of MapReduce (of which there are many excellent ones &amp;#8211; I recommend &lt;a href=&quot;http://labs.google.com/papers/mapreduce-osdi04.pdf&quot;&gt;this paper&lt;/a&gt; from google and the following video from Cloudera.)&lt;/p&gt;
&lt;center&gt;
&lt;p&gt;&lt;br/&gt;
	&lt;iframe src=&quot;http://player.vimeo.com/video/3584536&quot; width=&quot;400&quot; height=&quot;300&quot; frameborder=&quot;0&quot;&gt;&lt;/iframe&gt;&lt;br /&gt;
	&lt;br/&gt;&lt;/p&gt;
&lt;/center&gt;
&lt;p&gt;The short of it is that MapReduce is a paradigm that abstracts a lot of the complications that we typically face when attempting process large amounts of data in a parallel fashion. And by complications, I mean primarily scheduling, reliability, infrastructure and distribution. In effect, you end up programming to a particular abstraction or Design Pattern and not worrying about the rest of it. Of course, there are certain requirements necessary to make the best of this paradigm &amp;#8211; in short its well suited to processing non-interactive lists of data with little or no data-dependency. Sounds like fun ? On to an example!&lt;/p&gt;
&lt;h4&gt;Introducing Apache Hadoop/MapReduce&lt;/h4&gt;
&lt;p&gt;&lt;a href=&quot;http://hadoop.apache.org/mapreduce/&quot;&gt;Hadoop MapReduce&lt;/a&gt; is Apaches open source framework for supporting this paradigm. Once installed, we&amp;#8217;ll need a project to test out its capabilities. Lets write a task to compute the frequency of stock market changes. For example, given a particular stock, we&amp;#8217;d like to know how often in the past several years its changed by 1%, 2%, 3% etc (kind of like a a Fourier Transform, or transforming some temporal domain data into the frequency domain). This is typical of the type of processing the MapReduce framework should be good at.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve added to code for this example to &lt;a href=&quot;http://github.com/snaggled/hadoop-foobar&quot;&gt;github&lt;/a&gt; but the core of it is that we&amp;#8217;re going to need a couple of things to get started. The first ones a dataset. Yahoo Finance can provide what we need through the following webservices call:&lt;/p&gt;
&lt;pre class='brush:bash,gutter:false'&gt; 
	wget http://ichart.finance.yahoo.com/table.csv?s=BP
&lt;/pre&gt;

&lt;p&gt;I&amp;#8217;ve chosen BP as a stock because they are fresh in my mind given I bought in at $42 (on the way down) and its taken some time to get back into the black. Our input data should thus look like this:&lt;/p&gt;
&lt;pre class='brush:bash,gutter:false'&gt; 
2010-10-15,40.92,41.11,40.40,40.62,9023100,40.62
2010-10-14,41.15,41.37,40.96,41.02,6750300,41.02
2010-10-13,41.40,41.75,41.25,41.41,6950200,41.41
2010-10-12,40.74,41.53,40.55,41.26,8343100,41.26
&lt;/pre&gt;
&lt;p&gt;So we have out input, the next thing we need to write is a &lt;em&gt;Map&lt;/em&gt; function and a &lt;em&gt;Reduce&lt;/em&gt; function.&lt;/p&gt;
&lt;h4&gt;Map Function&lt;/h4&gt;
&lt;p&gt;Primarily we are writing a stream processor here that atomically performs what needs to happen on one line of data. Thats perfect for us, we&amp;#8217;re going to simply take the opening price, the closing price, calculate the percent change and spit it out. As follows:&lt;/p&gt;
&lt;pre class='brush:java,gutter:false'&gt; 
// Date,Open,High,Low,Close,Volume,Adj Close
String[] tokens = value.toString().split(&quot;,&quot;);  
float open = Float.valueOf(tokens[1]);
float close = Float.valueOf(tokens[4]);
float change = ((close - open)/open) * 100;   
word.set(new DecimalFormat(&quot;0.##&quot;).format((double) change) + &quot;%&quot;);
context.write(word, one);
&lt;/pre&gt;
&lt;p&gt;What thats going to give is us a stream of (name, value) pairs with the name being the percentage change for the day and the value being the integer &amp;#8216;1&amp;#8217;. Thats ok, thats all we need from our mapping function. This function can be distributed over X number of machines, each one performing its streaming function in parallel and independent of the others.&lt;/p&gt;
&lt;h4&gt;Reduce Function&lt;/h4&gt;
&lt;p&gt;Next up is the &amp;#8216;Reduce&amp;#8217; function (hence the name of the paradigm). What&amp;#8217;s going to take place here is that a reduce function is going to take the (name, value) outputs from all the mappers and process that data accordingly (often &amp;#8216;reducing&amp;#8217; it). In our case we are simply going to count the number of times a particular percentage change happens. In essence we are going to change this:&lt;/p&gt;

&lt;pre class='brush:bash,gutter:false'&gt; 
1.2% 1
1.3% 1
1.2% 1
&lt;/pre&gt;
&lt;p&gt;into:&lt;/p&gt;
&lt;pre class='brush:bash,gutter:false'&gt; 
1.2% 2
1.3% 1
&lt;/pre&gt;

&lt;p&gt;There&amp;#8217;s not much to the code:&lt;/p&gt;
&lt;pre class='brush:java,gutter:false'&gt; 
int sum = 0;
for (IntWritable val : values) {
	sum += val.get();
}
context.write(key, new IntWritable(sum));
&lt;/pre&gt;

&lt;p&gt;Thats about it, we write 2 functions and theres some setup involved (which I&amp;#8217;ve embedded into the &lt;a href=&quot;http://ant.apache.org/&quot;&gt;ant&lt;/a&gt; build.xml in the repository).&lt;/p&gt;
&lt;h4&gt;Our Output&lt;/h4&gt;
&lt;pre class='brush:bash,gutter:false'&gt; 
-0.01%  2
-0.02%  13
-0.03%  12
-0.04%  10
-0.05%  14
-0.06%  17
-0.07%  19
-0.08%  12
-0.09%  12
-0.1%   19
-0.11%  18
-0.12%  18
-0.13%  20
-0.14%  27
-0.15%  43
&lt;/pre&gt;

&lt;p&gt;That was actually pretty painless. I&amp;#8217;ve been thinking about Arthur C. Clarkes &lt;a href=&quot;http://www.fantasticfiction.co.uk/c/arthur-c-clarke/nine-billion-names-of-god.htm&quot;&gt;Nine Billion Names of God&lt;/a&gt; short Science Fiction story and think MapReduce (actually probably more-so the Map part, less the Reduce part) may be a good platform to do some experimentation on regarding that story.&lt;/p&gt;
&lt;p&gt;The source for this example can be found &lt;a href=&quot;http://github.com/snaggled/hadoop-foobar&quot;&gt;here&lt;/a&gt;. It should be placed in a subdir of the hadoop installation, i.e. jobs/hadoop-foobar.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Summer of Hawkwind (aka Running your rails tests using an in-memory database)</title>
   <link href="/2010/04/28/Summer-of-Hawkwind.html"/>
   <updated>2010-04-28T00:00:00-07:00</updated>
   <id>/2010/04/28/Summer-of-Hawkwind</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/04/28/Summer-of-Hawkwind.html&quot;&gt;Summer of Hawkwind (aka Running your rails tests using an in-memory database)&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;28 Apr 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;p&gt;2 weeks paternity leave from work means a couple of things. Firstly, it means I&amp;#8217;ve been listening to a lot of music, and it seems the most fitting for Spring/Summer 2010 is some awesome &lt;a href=&quot;http://news.nationalgeographic.com/news/2007/01/images/070105-space-rock.jpg&quot;&gt;space-rock&lt;/a&gt;. Order of the day seems to be &lt;a href=&quot;http://www.progarchives.com/Review.asp?id=25205&quot;&gt;Hawkwind&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://capitalistliontamer.files.wordpress.com/2009/11/hawkwind.jpg&quot; alt=&quot;Hawkwind&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Might get a mountain bike ride in on Friday. Mountain-biking + acid-rock == flashbacks whilst hurtling downhill at 30 mph.&lt;/p&gt;
&lt;h3&gt;Running Rails tests using an in-memory database&lt;/h3&gt;
&lt;p&gt;The second thing being off work enables is the cleaning up of old projects and things on the to-do list. One thing thats been bugging for a while is the length of time it takes to run my rails test cases (running MySQL):&lt;/p&gt;
&lt;pre class='brush:bash,gutter:false'&gt; 
	~/git/cs(master) $ rake test
	.........................
	Finished in 264.208584 seconds.

	25 tests, 2697 assertions, 0 failures, 0 errors
&lt;/pre&gt;
&lt;p&gt;Over 4 minutes, thats a long time when you&amp;#8217;ve changed one line of code. A challenge! Onwards and upwards, heres how to get your rails test to run using &lt;a href=&quot;http://www.sqlite.org/&quot;&gt;sqlite3&lt;/a&gt;.&lt;/p&gt;
&lt;h4&gt;1. Install the sqlite gem&lt;/h4&gt;
&lt;pre class='brush:bash,gutter:false'&gt; 
sudo gem install sqlite3-ruby
&lt;/pre&gt;
&lt;p&gt;This may or may not go smoothly. Native extension compilation problems could lead to &lt;a href=&quot;http://sqlite3.darwinports.com/&quot;&gt;macports&lt;/a&gt; on &lt;span class=&quot;caps&quot;&gt;OSX&lt;/span&gt;, or the equivalent &lt;a href=&quot;http://kristofhouwen.wordpress.com/2009/02/01/install-sqlite3-ruby-gem-on-ubuntu-810/&quot;&gt;apt-get&lt;/a&gt; on Ubuntu.&lt;/p&gt;
&lt;h4&gt;2. Modify database.xml&lt;/h4&gt;
&lt;pre class='brush:xml,gutter:false'&gt; 
	test: 
	   adapter: sqlite3 
	   database: &quot;:memory:&quot;
&lt;/pre&gt;
&lt;p&gt;Speaks for itself. Keep the old one around in case you want to run comparison speed-tests.&lt;/p&gt;
&lt;h4&gt;3. Install the &amp;#8216;in_memory_fix&amp;#8217; plugin&lt;/h4&gt;
&lt;p&gt;I grabbed it from the following svn repo:&lt;/p&gt;
&lt;pre class='brush:bash,gutter:false'&gt; 
./script/plugin install http://topfunky.net/svn/plugins/memory_test_fix
&lt;/pre&gt;
&lt;p&gt;But there are also a bunch of git forks &lt;a href=&quot;http://github.com/rsl/memory_test_fix/network&quot;&gt;floating around&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;What does it do ? Well, the short of it is that because the db is in memory, it needs to be re-created each time, which is what the plugin does. You can find more info over &lt;a href=&quot;http://chrisroos.co.uk/blog/2006-02-08-in-memory-sqlite-database-for-rails-testing&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h4&gt;4. Differences between MySQL and Sqlite3&lt;/h4&gt;
&lt;p&gt;At last, some meat. You can take what you have and try to run your rake tests. There&amp;#8217;s are chance you could be good to go. In my case, there were a couple of syntactic differences between the two databases that needed resolving:&lt;/p&gt;
&lt;h4&gt;&lt;span class=&quot;caps&quot;&gt;RAND&lt;/span&gt; vs &lt;span class=&quot;caps&quot;&gt;RANDOM&lt;/span&gt;&lt;/h4&gt;
&lt;p&gt;First up was that the sqlite3 random function is called &amp;#8216;&lt;span class=&quot;caps&quot;&gt;RANDOM&lt;/span&gt;()&amp;#8217; whilst the MySQL one is called &amp;#8216;&lt;span class=&quot;caps&quot;&gt;RAND&lt;/span&gt;()&amp;#8217;. This cause an active_record lookup like the following one to fail:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
@bar = Foo.find(:all, :order =&amp;gt; 'RAND()')                 
&lt;/pre&gt;

&lt;p&gt;Couple of ways to fix this. Easiest from my point of view was simply to create the &amp;#8216;&lt;span class=&quot;caps&quot;&gt;RANDOM&lt;/span&gt;&amp;#8217; function in MySQL. Sounds like a migration:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
	class CreateRandomFunction &amp;lt; ActiveRecord::Migration
	  def self.up            
	    adapter = User.connection.
			instance_variable_get(&quot;@config&quot;)
			[:adapter]      
	    if adapter == 'mysql'
	      execute &quot;create function random() returns integer return rand();&quot;
	    end
	  end

	  def self.down  
	    adapter = User.connection.
			instance_variable_get(&quot;@config&quot;)
			[:adapter]      
	    if adapter == 'mysql'
	      execute &quot;drop function if exists random;&quot;
	    end
	  end
	end              
&lt;/pre&gt;
&lt;h4&gt;Doesn&amp;#8217;t this apply to test-cases ?&lt;/h4&gt;
&lt;p&gt;Err, I suspect that should be enough, but my test cases were failing because around the time that fixtures were loaded, the function got blown away again. I ended up with this in my test_helper.rb:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
adapter = Rails.configuration.
	database_configuration
	[Rails.configuration.environment]
	[&quot;adapter&quot;]
if adapter == &quot;mysql&quot; &amp;amp;&amp;amp; ENV[&quot;RAILS_ENV&quot;] == 'test' 
  ActiveRecord::Base.connection.execute(&quot;drop function if exists random;&quot;);
  ActiveRecord::Base.connection.execute(&quot;create function random() returns integer return rand();&quot;);
end
&lt;/pre&gt;
&lt;h4&gt;Fixtures and &amp;#8220;1&amp;#8221; vs &amp;#8220;t&amp;#8221;&lt;/h4&gt;
&lt;p&gt;Almost out of the woods, but not yet. If you&amp;#8217;re using fixtures, and you&amp;#8217;ve auto-magically generated them (as I have), you might see the following entry for Booleans:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt;  
boolean_variable_in_mysql: &quot;1&quot;   
&lt;/pre&gt;
&lt;p&gt;This is all and well in MySQL, but sqlite3 doesn&amp;#8217;t like it. It stores its bools as the char &amp;#8220;t&amp;#8221; or &amp;#8220;f&amp;#8221; and you may need to convert them. &lt;em&gt;true&lt;/em&gt; or &lt;em&gt;false&lt;/em&gt; should work fine, i.e.&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt;  
boolean_variable_in_mysql: true   
&lt;/pre&gt;
&lt;p&gt;And thats it. My tests running in memory. Time to turn the &lt;a href=&quot;http://www.starfarer.net/hwalbums.html&quot;&gt;space-rock&lt;/a&gt; up.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://images.tribe.net/tribe/upload/photo/1db/de9/1dbde978-b5a1-4d3e-9934-00454971e44c&quot; alt=&quot;Doremi&quot;/&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Monkey Patching in Ruby</title>
   <link href="/2010/04/21/a-quick-note-about-monkeypatching-in-ruby.html"/>
   <updated>2010-04-21T00:00:00-07:00</updated>
   <id>/2010/04/21/a-quick-note-about-monkeypatching-in-ruby</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/04/21/a-quick-note-about-monkeypatching-in-ruby.html&quot;&gt;Monkey Patching in Ruby&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;21 Apr 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;p&gt;Todays post comes courtesy of what is possibly the greatest programming music ever invented:&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://ecx.images-amazon.com/images/I/41Q455DYGPL._SL500_AA300_.jpg&quot; alt=&quot;Conan&quot;/&gt;&lt;/p&gt;
&lt;h3&gt;Monkey Patching&lt;/h3&gt;
&lt;p&gt;More than just a cool name. No, really, its also called &lt;a href=&quot;http://www.ericdelabar.com/2008/05/metaprogramming-javascript.html&quot;&gt;Duck-Punching&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;cite&gt;Well, I was just totally sold by Adam, the idea being that if it walks like a duck and talks like a duck, it’s a duck, right? So if this duck is not giving you the noise that you want, you’ve got to just punch that duck until it returns what you expect.&lt;/cite&gt;&lt;/p&gt;
&lt;p&gt;This is not something I encountered much (ever) in Java, but I think thats indicative of the dynamic nature of the Ruby language (Python too for that matter). The reality is that the history of the name itself is somewhat more interesting that the concept. To quote &lt;a href=&quot;http://en.wikipedia.org/wiki/Monkey_patch&quot;&gt;wikipedia&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;cite&gt;Since the word guerrilla and gorilla are near-homophones, people started using the incorrect term gorilla patch instead of guerrilla patch. When a developer then created a guerrilla patch they tried very hard to avoid any battles that may ensue due to the patch and the term monkey patch was coined to make the patch sound less forceful.&lt;/cite&gt;&lt;/p&gt;
&lt;p&gt;So, what are we talking about ? Well, to make a long story short, all we are talking about is the concept of dynamically modifying a class or object at runtime. Lets think about this a little. Sample Ruby class:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
	class Foo
		def bar
			&quot;bar&quot;
		end
	end

	f = Foo.new
	f.bar	
	=&amp;gt; &quot;bar&quot;
&lt;/pre&gt;
&lt;p&gt;All is well and good until we discover that the &amp;#8220;bar&amp;#8221; method is wrong and shouldn&amp;#8217;t be returning &amp;#8220;bar&amp;#8221;. What are our options ? Well, traditionally we&amp;#8217;d probably sub-class Foo and fix the problem:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
	class Foo2 &amp;lt; Foo
		def bar
			&quot;the correct bar&quot;
		end
	end

	f = Foo2.new
	f.bar	
	=&amp;gt; &quot;the correct bar&quot;
&lt;/pre&gt;
&lt;p&gt;The advantage of this approach is of course that we know we haven&amp;#8217;t broken anything. Any of the existing calls to Foo.bar should still work. However, what about the situation where Foo is already distributed, its out there in the wild, maybe its impossible or not practical for us to subclass it. Maybe its an issue in a piece of code we really don&amp;#8217;t care about (maybe we didn&amp;#8217;t write it), we just need it fixed.&lt;/p&gt;
&lt;p&gt;This is where the absolute beauty of a dynamic language like ruby comes in. Its possible for to dynamically change the Foo class, without modifying any of its source code (on disk). Here&amp;#8217;s what we can do in Ruby that we can&amp;#8217;t do in a bunch of other languages:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
	class Foo
		def bar
			&quot;bar&quot;
		end
	end

	class Foo
		def bar
			&quot;the correct bar&quot;
		end
	end

	f = Foo.new
	puts f.bar
&lt;/pre&gt;
&lt;p&gt;Yeppers, you read that correctly. Ruby has the concept of &lt;a href=&quot;http://blog.aizatto.com/2007/06/01/ruby-and-open-classes/&quot;&gt;Open Classes&lt;/a&gt; meaning by re-declaring a class, we can effectively add or modify methods.&lt;/p&gt;
&lt;p&gt;Up next: Caching geocode lookups from google.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Chrome Bug - sends 'undefined' when no data is passed to XMLHttpRequest</title>
   <link href="/2010/04/11/Chrome-sending-undefined-in-post-requests.html"/>
   <updated>2010-04-11T00:00:00-07:00</updated>
   <id>/2010/04/11/Chrome-sending-undefined-in-post-requests</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/04/11/Chrome-sending-undefined-in-post-requests.html&quot;&gt;Chrome Bug &amp;#8211; sends &amp;#8216;undefined&amp;#8217; when no data is passed to XMLHttpRequest&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;11 Apr 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;p&gt;Spent the week trying to juggle work, our 2 year old twins, my parents visiting from Ireland, and repeatedly driving to and from the hospital to spend time with our premature twins that were born on Easter Sunday. Its been a mad, but fun week. I have a secret weapon which has kept me going:&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://tripletsmommy.com/wp-content/uploads/2010/03/freedunkindonutscoffee1.jpg&quot; alt=&quot;Dunkin Turbo&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Turbo! Babies will be home soon and parents are leaving in couple weeks, so life we be returning back to normal. In the meantime, here&amp;#8217;s a Google &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; Chrome bug I experienced this weekend.&lt;/p&gt;
&lt;h3&gt;Chrome XMLHttpRequest Issue&lt;/h3&gt;
&lt;p&gt;Its perfectly valid to perform an &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt; &lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt; and send no data, such as the following line of jQuery code:&lt;/p&gt;
&lt;pre class='brush:javascript,gutter:false'&gt; 
	$.ajax({
	  type: 'POST',
	  url: url,     
	  dataType: 'json'
	});
&lt;/pre&gt;
&lt;p&gt;This should result in no data being sent in the &lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt; but instead, Chrome sends an &amp;#8216;undefined&amp;#8217; which is incorrect. This is easily fixed by forcing the client-side Javascript to send &lt;strong&gt;something&lt;/strong&gt;:&lt;/p&gt;
&lt;pre class='brush:javascript,gutter:false'&gt; 
	$.ajax({
	  type: 'POST',
	  data: &quot;&quot;,  
	  url: url,     
	  dataType: 'json'
	});
&lt;/pre&gt;
&lt;p&gt;You can find bug reports on the issue &lt;a href=&quot;http://code.google.com/p/chromium/issues/detail?id=33062&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;http://dev.jquery.com/ticket/5123&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Understanding Cross-Domain Javascript - JSONP and IFrames</title>
   <link href="/2010/04/08/Understanding-cross-domain-javascript.html"/>
   <updated>2010-04-08T00:00:00-07:00</updated>
   <id>/2010/04/08/Understanding-cross-domain-javascript</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/04/08/Understanding-cross-domain-javascript.html&quot;&gt;Understanding Cross-Domain Javascript &amp;#8211; &lt;span class=&quot;caps&quot;&gt;JSONP&lt;/span&gt; and IFrames&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;08 Apr 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;p&gt;Been an awesome couple of weeks. I am the proud new father of twins (our second set). Still on a high from the whole experience. Think I&amp;#8217;ll celebrate by documenting some of the cross-domain issues I explored last weekend.&lt;/p&gt;
&lt;p&gt;But before I begin, the last couple of weeks have been dominated by this work of epic proportions:&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://bleepfiend.co.uk/sitebuildercontent/sitebuilderpictures/analordset.JPG&quot; alt=&quot;AFX - Analord&quot;/&gt;&lt;/p&gt;
&lt;p&gt;41 tracks of &lt;a href=&quot;http://en.wikipedia.org/wiki/Analord&quot;&gt;Afx awesomeness&lt;/a&gt;. Thats not my vinyl in the picture above, I wish it was.&lt;/p&gt;
&lt;h3&gt;The Cross Domain Problem&lt;/h3&gt;
&lt;p&gt;Its classic Philly to make the mistake of assuming things are actually easier than they are (I&amp;#8217;m a perpetual optimist). So, when over the weekend I wanted to write a piece of Javascript to connect to a remote server, pull back some content and display it, I &lt;strong&gt;of course&lt;/strong&gt; assumed that things boiled down to a quick jQuery call. Not to be. Lets make a sample ajax call using jQuery:&lt;/p&gt;
&lt;pre class='brush:javascript,gutter:false'&gt; 
$(document).ready(function(){
	var url = &quot;http://twitter.com/status/user_timeline/snaggled.json&quot;;
	$.getJSON(url, function(data) {
		// firebug
		console.info(data);
	});
});
&lt;/pre&gt;
&lt;p&gt;Pretty straightforward stuff. What we&amp;#8217;d like to see in our console window is some nicely formatted &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt;, along the lines of:&lt;/p&gt;
&lt;pre class='brush:js,gutter:false'&gt; 
[{&quot;created_at&quot;:&quot;Tue Apr 06 19:29:57 +0000&quot;,
&quot;contributors&quot;:null,
&quot;in_reply_to_status_id&quot;:null,
&quot;in_reply_to_user_id&quot;:null,
&quot;geo&quot;:null,
&quot;place&quot;:null,
&quot;in_reply_to_screen_name&quot;:null,
&quot;source&quot;:&quot;&amp;lt;a href=\&quot;http://www.tweetdeck.com/\&quot;,
...
&lt;/pre&gt;
&lt;p&gt;Of course I&amp;#8217;d completely forgotten the (&lt;a href=&quot;http://en.wikipedia.org/wiki/Same_origin_policy&quot;&gt;same origin&lt;/a&gt;) Cross Domain Security restrictions that apply when it comes to Javascript. In short:&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;We cannot make an &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; (&lt;a href=&quot;http://en.wikipedia.org/wiki/XMLHttpRequest&quot;&gt;XMLHttpRequest&lt;/a&gt;) to a different domain than the one which served the page we are currently accessing.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;This is the reason our &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; call is failing above, in fact, in FireBugs console we see this:&lt;/p&gt;
&lt;pre class='brush:text,gutter:false'&gt; 
Access to restricted URI denied&quot; code: &quot;1012
[Break on this error] xhr.open(type, s.url, s.async);
&lt;/pre&gt;
&lt;p&gt;Of course there are a &lt;a href=&quot;http://en.wikipedia.org/wiki/Cross-site_scripting&quot;&gt;wealth&lt;/a&gt; of valid reasons for same origin policy, but it does nix our idea of dropping in a line or two of Javascript and pulling back some information. So what are our options ?&lt;/p&gt;
&lt;h3&gt;IFrames&lt;/h3&gt;
&lt;p&gt;Its like the late 90s all over again. This doesn&amp;#8217;t feel like a particularly elegant solution. Nonetheless, it does work and deserves attention.&lt;/p&gt;
&lt;p&gt;An &lt;a href=&quot;http://en.wikipedia.org/wiki/HTML_element#Frames&quot;&gt;IFrame&lt;/a&gt; is an entire &lt;span class=&quot;caps&quot;&gt;HTML&lt;/span&gt; document embedded in our page. We dynamically create one of these bad boys, setting its source to a url on our server. Then, from that page we can invoke any &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; we want, because we have already established the &amp;#8220;same origin&amp;#8221;. An example!&lt;/p&gt;
&lt;pre class='brush:javascript,gutter:false'&gt; 
var url = &quot;http://mydomain.com/js/iframe&quot;;           
var myframe = $(&quot;&amp;lt;iframe/&amp;gt;&quot;).attr(&quot;src&quot;, url).attr(&quot;width&quot;, &quot;0px&quot;).attr(&quot;height&quot;, &quot;0px&quot;).attr(&quot;id&quot;, &quot;my_iframe&quot;);    
$(&quot;#container&quot;).append(myframe);
&lt;/pre&gt;
&lt;p&gt;Here we&amp;#8217;re pulling a page from the remote server we wish to communicate with. Nothing too fancy involved. Lets look inside the page we&amp;#8217;re pulling back:&lt;/p&gt;
&lt;pre class='brush:html,gutter:false'&gt; 
&amp;lt;script type=&quot;text/javascript&quot;&amp;gt;init();&amp;lt;/script&amp;gt;     
&lt;/pre&gt;
&lt;p&gt;All we&amp;#8217;re actually doing is calling a JS function. Lets look inside the Javascript:&lt;/p&gt;
&lt;pre class='brush:javascript,gutter:false'&gt; 
function init()
{
	$(document).ready(function(){
		var url = &quot;http://mydomain.com/api/v1/snaggled.json&quot;;
		$.getJSON(url, function(data) {
			// firebug
			console.info(data);
		});
	});
}   
&lt;/pre&gt;
&lt;p&gt;Aha! Now we&amp;#8217;re making the &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; call. You&amp;#8217;ll note that we&amp;#8217;re allowed to make &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; calls to this domain because we&amp;#8217;ve already established the &amp;#8216;origin&amp;#8217;. This can be taken a lot further and there&amp;#8217;s no shortage of information on this (as well as some security restrictions, such as no iframe to iframe communication). &lt;a href=&quot;http://softwareas.com/cross-domain-communication-with-iframes&quot;&gt;This&lt;/a&gt; is one of the better blogs I&amp;#8217;ve read on the subject. &lt;a href=&quot;http://orensol.com/2009/06/07/cross-domain-ajax-calls-and-iframe-communication-how-to/&quot;&gt;Here&lt;/a&gt; also.&lt;/p&gt;
&lt;h3&gt;&lt;span class=&quot;caps&quot;&gt;JSONP&lt;/span&gt;&lt;/h3&gt;
&lt;p&gt;The second solution appears to be made of win. &lt;a href=&quot;http://en.wikipedia.org/wiki/JSONP#JSONP&quot;&gt;&lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt; with Padding&lt;/a&gt; is basically a workaround where:&lt;/p&gt;
&lt;p&gt;1) We pass a function name to the server as a param in our Cross-Domain call:&lt;/p&gt;
&lt;pre class='brush:javascript,gutter:false'&gt; 
$(document).ready(function(){
	var url = &quot;http://twitter.com/status/
	user_timeline/snaggled.json
	?callback=JSONPcallbackFunction&quot;;
	$.getJSON(url, function(data) {
		// firebug
		console.info(data);
	});
});
&lt;/pre&gt;
&lt;p&gt;2) The server dosen&amp;#8217;t just return the requested data as normal, but instead wraps the requested data in a Javascript function using the callback we provided, so that the response looks like this:&lt;/p&gt;
&lt;pre class='brush:javascript,gutter:false'&gt; 
JSONPcallbackFunction([{
	&quot;in_reply_to_user_id&quot;:null,
	&quot;created_at&quot;:&quot;Tue Apr 06 19:29:57 +0000 2010&quot;,
	&quot;contributors&quot;:null,&quot;geo&quot;:null
	...
&lt;/pre&gt;
&lt;p&gt;What this actually does, rather than returning just data is return a piece of Javascript that gets executed. This works beautifully. Its not really &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; though. I&amp;#8217;m pretty sure its not using XMLHttpRequest and is nothing more than dynamic script element loading. I&amp;#8217;ve also had some problems getting it to work with &lt;span class=&quot;caps&quot;&gt;POST&lt;/span&gt; and &lt;span class=&quot;caps&quot;&gt;PUT&lt;/span&gt; requests, which I believe is symptomatic of the previous statement. Nonetheless, it does work for certain situations, and is elegant.&lt;/p&gt;
&lt;p&gt;Up next: Google Chrome/JQuery Bug!&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Maven - I've just discovered Transitive Dependency Management</title>
   <link href="/2010/03/10/Maven-ive-just-discovered-transitive-dependency-management.html"/>
   <updated>2010-03-10T00:00:00-08:00</updated>
   <id>/2010/03/10/Maven-ive-just-discovered-transitive-dependency-management</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/03/10/Maven-ive-just-discovered-transitive-dependency-management.html&quot;&gt;Maven &amp;#8211; I&amp;#8217;ve just discovered Transitive Dependency Management&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;10 Mar 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;h3&gt;Maven&lt;/h3&gt;
&lt;p&gt;Wow. I have to admit to being a little late to the party on this one. Several years ago, my days as a full-time Java developer where filled with &lt;a href=&quot;http://ant.apache.org/&quot;&gt;ant&lt;/a&gt; (if you were lucky) and &lt;a href=&quot;http://www.gnu.org/software/make/&quot;&gt;make&lt;/a&gt; (if you weren&amp;#8217;t).&lt;/p&gt;
&lt;p&gt;Before I continue, this evenings late night festivities are brought to you by this (ultimate) form of nourishment:&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://www.bestbritishfoods.com/cw2/assets/product_thumb/TayChsOninsm.jpg&quot; alt=&quot;Tayto crisps&quot;/&gt;&lt;/p&gt;
&lt;p&gt;And this fantastic album:&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://ecx.images-amazon.com/images/I/51mOm%2BZFnNL._SS500_.jpg&quot; alt=&quot;Tangerine Dream - Ricochet&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Anyhoo, this evening, I planned on spending a couple hours playing with &lt;a href=&quot;https://www.hibernate.org/&quot;&gt;hibernate&lt;/a&gt; (I wanted to check out its &lt;span class=&quot;caps&quot;&gt;ORM&lt;/span&gt; capabilities, especially compared to Rails &lt;a href=&quot;http://github.com/rails/rails/tree/master/activemodel&quot;&gt;ActiveModel&lt;/a&gt; (which I love)). 5 minutes into the tutorial and I was in jar-hell and for the millionth time starting thinking &amp;#8220;where do I download that that mysql-connector-java&amp;#8221; (its &lt;a href=&quot;http://dev.mysql.com/downloads/connector/j/&quot;&gt;here&lt;/a&gt; for those of you that care) as I started to think about hooking hibernate up-to mysql.&lt;/p&gt;
&lt;p&gt;But not this time. Introducing &lt;a href=&quot;http://maven.apache.org/&quot;&gt;maven&lt;/a&gt;. The best description of that I can think of is &lt;a href=&quot;http://ant.apache.org/&quot;&gt;ant&lt;/a&gt; coupled with something like &lt;a href=&quot;http://yum.baseurl.org/&quot;&gt;yum&lt;/a&gt; or &lt;a href=&quot;http://en.wikipedia.org/wiki/Advanced_Packaging_Tool&quot;&gt;apt-get&lt;/a&gt; or &lt;a href=&quot;http://www.macports.org/&quot;&gt;macports&lt;/a&gt; or whatever. Its kind of like a &lt;a href=&quot;http://rubyforge.org/projects/rubygems/&quot;&gt;RubyGems&lt;/a&gt; for jar files.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s a sample &lt;a href=&quot;http://maven.apache.org/pom.html&quot;&gt;&lt;span class=&quot;caps&quot;&gt;POM&lt;/span&gt;&lt;/a&gt; file, from the hibernate tutorial:&lt;/p&gt;
&lt;pre class='brush:xml,gutter:false'&gt;      
&amp;lt;modelVersion&amp;gt;4.0.0&amp;lt;/modelVersion&amp;gt; 
&amp;lt;groupId&amp;gt;org.hibernate.tutorials&amp;lt;/groupId&amp;gt; 
&amp;lt;artifactId&amp;gt;hibernate-tutorial&amp;lt;/artifactId&amp;gt; 
&amp;lt;version&amp;gt;1.0.0-SNAPSHOT&amp;lt;/version&amp;gt; 
&amp;lt;name&amp;gt;First Hibernate Tutorial&amp;lt;/name&amp;gt;   
&amp;lt;build&amp;gt; 
	&amp;lt;finalName&amp;gt;${artifactId}&amp;lt;/finalName&amp;gt;   
&amp;lt;/build&amp;gt; 
&amp;lt;dependencies&amp;gt; 
	&amp;lt;dependency&amp;gt; 
		&amp;lt;groupId&amp;gt;org.hibernate&amp;lt;/groupId&amp;gt; 
		&amp;lt;artifactId&amp;gt;hibernate-core&amp;lt;/artifactId&amp;gt;    
		&amp;lt;version&amp;gt;3.3.2.GA&amp;lt;/version&amp;gt;
	&amp;lt;/dependency&amp;gt; 
	&amp;lt;dependency&amp;gt; 
		&amp;lt;groupId&amp;gt;javax.servlet&amp;lt;/groupId&amp;gt; 
		&amp;lt;artifactId&amp;gt;servlet-api&amp;lt;/artifactId&amp;gt; 
		&amp;lt;version&amp;gt;2.5&amp;lt;/version&amp;gt;
	&amp;lt;/dependency&amp;gt;         
	&amp;lt;dependency&amp;gt; 
		&amp;lt;groupId&amp;gt;mysql&amp;lt;/groupId&amp;gt; 
		&amp;lt;artifactId&amp;gt;mysql-connector-java&amp;lt;/artifactId&amp;gt; 
		&amp;lt;version&amp;gt;5.1.9&amp;lt;/version&amp;gt;
	&amp;lt;/dependency&amp;gt;         
	&amp;lt;dependency&amp;gt; 
		&amp;lt;groupId&amp;gt;org.slf4j&amp;lt;/groupId&amp;gt; 
		&amp;lt;artifactId&amp;gt;slf4j-simple&amp;lt;/artifactId&amp;gt; 
		&amp;lt;version&amp;gt;1.5.11&amp;lt;/version&amp;gt;
	&amp;lt;/dependency&amp;gt; 
	&amp;lt;dependency&amp;gt; 
		&amp;lt;groupId&amp;gt;javassist&amp;lt;/groupId&amp;gt; 
		&amp;lt;artifactId&amp;gt;javassist&amp;lt;/artifactId&amp;gt; 
		&amp;lt;version&amp;gt;3.8.0.GA&amp;lt;/version&amp;gt;
	&amp;lt;/dependency&amp;gt; 
&amp;lt;/dependencies&amp;gt; 
&amp;lt;/project&amp;gt;
&lt;/pre&gt;
&lt;p&gt;The bit we care about are the dependencies. Lets kick off a build:&lt;/p&gt;
&lt;pre class='brush:text,gutter:false'&gt; 
	~/java/tutorial $ mvn compile
	[INFO] Scanning for projects...
	[INFO] ------------------------------------------------------------------------
	[INFO] Building First Hibernate Tutorial
	[INFO]    task-segment: [compile]
	[INFO] ------------------------------------------------------------------------
	Downloading: .../maven-plugins-12.pom
	Downloading: .../maven-parent-9.pom
	Downloading: .../apache-4.pom
	Downloading: .../maven-plugins-8.pom
	Downloading: .../maven-parent-5.pom   
	...
&lt;/pre&gt;
&lt;p&gt;And look at that bad boy go! Good lord, it actually fetched 40 jars, stored them locally in my repository, and used them in the build. Dependencies and everything. Glorious. I have to admit to being more impressed this evening with &lt;a href=&quot;http://maven.apache.org&quot;&gt;maven&lt;/a&gt; than &lt;a href=&quot;https://www.hibernate.org/&quot;&gt;hibernate&lt;/a&gt; (which is actually fine, I&amp;#8217;m just a little spoilt with &lt;a href=&quot;http://github.com/rails/rails/tree/master/activemodel&quot;&gt;ActiveModel&lt;/a&gt;).&lt;/p&gt;
&lt;p&gt;The source for the &lt;a href=&quot;http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html&quot;&gt;hibernate tutorial&lt;/a&gt; is &lt;a href=&quot;http://github.com/snaggled/hibernate_tutorial&quot;&gt;here&lt;/a&gt; for safekeeping.&lt;/p&gt;
&lt;p&gt;Tomorrow I need to burn 44 gigs of VMWare instances onto DVDs and post them to a data-center in Florida. Wonder how long it will take. I figure its easier than trying to &lt;span class=&quot;caps&quot;&gt;FTP&lt;/span&gt; them.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Objective-C for Java (and Ruby) Developers - Part 2</title>
   <link href="/2010/02/28/Objective-C-for-Java-and-Ruby-Developers-Part-2.html"/>
   <updated>2010-02-28T00:00:00-08:00</updated>
   <id>/2010/02/28/Objective-C-for-Java-and-Ruby-Developers-Part-2</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/02/28/Objective-C-for-Java-and-Ruby-Developers-Part-2.html&quot;&gt;Objective-C for Java (and Ruby) Developers &amp;#8211; Part 2&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;28 Feb 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;

&lt;h3&gt;Meta-data&lt;/h3&gt;
&lt;p&gt;No discussion about a language would be complete without covering the ability to navigate around its meta and find information about its classes and methods.&lt;/p&gt;
&lt;p&gt;Lets start with Ruby, which, as is usually the case, everything is sweet:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
	class Philly &amp;lt; String
	  def initialize
	    @var = &quot;&quot;
	  end
	  def custom_method 
	    &quot;Philly&quot;
	  end
	end

	philly = Philly.new

	p philly.class
	p philly.methods
	p philly.instance_variables
	p philly.kind_of?(String)
&lt;/pre&gt;
&lt;p&gt;Takes a couple more lines of code in Java, but still life is good:&lt;/p&gt;
&lt;pre class='brush:java,gutter:false'&gt; 
	import java.util.*;
	import java.lang.reflect.*;
	import java.io.*;

	public class Philly extends StringWriter
	{		
		public String var;
		public void custom_method()
		{
		}

		public static void main(String[] args) 
			throws InterruptedException
		{
			Object p = new Philly();
			Class c = p.getClass();
			System.out.println(c.getName());

			Method[] m = c.getMethods();
			Iterator it = Arrays.asList(m).iterator();
			while (it.hasNext())
			{
				System.out.println(it.next());
			}

			Field[] f = c.getFields();
			it = Arrays.asList(f).iterator();
			while (it.hasNext())
			{
				System.out.println(it.next());
			}

			System.out.println(StringWriter.class.
				isAssignableFrom(c));
		}
	}
&lt;/pre&gt;
&lt;p&gt;Note that the &lt;a href=&quot;http://java.sun.com/j2se/1.6.0/docs/api/java/lang/String.html&quot;&gt;String&lt;/a&gt; class is Final in Java so we couldn&amp;#8217;t over-ride it. I just over-rode StringWriter to get the message across, you get the general point.&lt;/p&gt;
&lt;p&gt;Which takes us finally to Objective-C, where things are longer still, but not too bad. Note that we do have to worry about freeing up any memory that was allocated in our calls.&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
#import &amp;lt;Foundation/Foundation.h&amp;gt;
#import &amp;lt;objc/runtime.h&amp;gt;

@interface Philly : NSString
{
	int var;
}

-(void) custom_method;

@end

@implementation Philly

-(void) custom_method 
{
}

@end

int main (int argc, const char * argv[]) 
{
    NSAutoreleasePool * pool = 
		[[NSAutoreleasePool alloc] init];

	Philly *p = [[Philly alloc] init];
    
	// the class
	NSLog(@&quot;%@&quot;, [p class]);

	// methods
	unsigned int count = 0;
	Method *methods = class_copyMethodList(
		[p class], &amp;amp;count);
	for (int i = 0; i &amp;lt; count; i++)
	{	
		SEL selector = method_getName(methods[i]); 
		NSLog(@&quot;%s&quot;, selector);
	}	
	
	// instance variables
	Ivar *vars = class_copyIvarList(
		[p class], &amp;amp;count);
	for (int i = 0; i &amp;lt; count; i++)
	{	
		NSLog(@&quot;%s&quot;, ivar_getName(vars[i]));
	}
	
	// kindof/superclass
	NSLog(@&quot;%@&quot;, [[p class] isSubclassOfClass: 
	 [NSString class]] ? @&quot;true&quot; : @&quot;false&quot;);
	
	free(methods);
	free(vars);
	[p release];
    [pool drain];
    return 0;
}
&lt;/pre&gt;
&lt;p&gt;Now this is a little interesting, because the interesting calls in this example (e.g. &lt;a href=&quot;http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html#//apple_ref/c/func/class_copyMethodList&quot;&gt;class_copyMethodList&lt;/a&gt;) calls come from the Mac OS X implementation of the Objective-C runtime platform, so things may look differently for Linux or a &lt;span class=&quot;caps&quot;&gt;GNU&lt;/span&gt;-compiler based platform. You can read more about it &lt;a href=&quot;http://developer.apple.com/mac/library/documentation/Cocoa/Reference/ObjCRuntimeRef/Reference/reference.html&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Categories&lt;/h3&gt;
&lt;p&gt;Lets spend a second talking about the &amp;#8216;Fragile Base Class&amp;#8217; problem in object orientated programming. This basically refers to the issue where (to quote wikipedia) &amp;#8220;base classes (superclasses) are considered &amp;#8216;fragile&amp;#8217; because seemingly safe modifications to a base class, when inherited by the derived classes, may cause the derived classes to malfunction&amp;#8221;. So in essence if I create a base class which is then sub-classed repeatedly (or perhaps even once), its difficult for me to make any changes to the base class because I have limited visibility into the effects that change will have to all of the sub-classes.&lt;/p&gt;
&lt;p&gt;Each language gets it own flavor of solution to deal with this. In Java (and generally in the OO world) we are told to program to interfaces, not to classes/implementations. We are also given the &amp;#8216;Final&amp;#8217; keyword to lock super-classes down. In Ruby we get Mixins, as we as (arguably) the ability to &amp;#8216;Monkey-Patch&amp;#8217;. In Objective-C, we get Categories.&lt;/p&gt;
&lt;p&gt;A Category is at its simplest, the ability to add methods (not variables) to an interface/implementation without necessarily subclassing. Its an extension to a class, and its possible to have multiple categories for the same class. An example:&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
	@interface Philly : NSString
	{
		int var;
	}

	-(void) custom_method;

	@end

	@implementation Philly

	-(void) custom_method 
	{
	}

	@end

	@interface Philly (MyCategory)

	-(void) category_method;

	@end

	@implementation Philly (MyCategory)

	-(void) category_method
	{
	}

	@end

	@interface Philly (SecondCategory)

	-(void) second_category_method;

	@end

	@implementation Philly (SecondCategory)

	-(void) second_category_method
	{
	}

	@end
&lt;/pre&gt;
&lt;p&gt;This effectively allows us to add methods to a super-class, without having to modify the superclass directly.&lt;/p&gt;
&lt;h3&gt;Protocols&lt;/h3&gt;
&lt;p&gt;A protocol is, at its simplest, very similar to a Java Interface. It enables us to define a list of methods that have to be implemented. If a Class decides to &amp;#8216;conform&amp;#8217; to that protocol, it must implement the listed methods. In short:&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
@protocol MyProtocol

-(void) protocol_method;

@end

@interface Philly &amp;lt;MyProtocol&amp;gt;
{
	int var;
}

-(void) custom_method;

@end

@implementation Philly

-(void) custom_method 
{
}

-(void) protocol_method
{
}

@end
&lt;/pre&gt;
&lt;p&gt;Early flight to Dallas tomorrow morning. Spending the week (hopefully) getting my Java on!&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Objective-C for Java (and Ruby) Developers - Part 1</title>
   <link href="/2010/02/25/Objective-C-for-Java-and-Ruby-Developers-Part-1.html"/>
   <updated>2010-02-25T00:00:00-08:00</updated>
   <id>/2010/02/25/Objective-C-for-Java-and-Ruby-Developers-Part-1</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/02/25/Objective-C-for-Java-and-Ruby-Developers-Part-1.html&quot;&gt;Objective-C for Java (and Ruby) Developers &amp;#8211; Part 1&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;25 Feb 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;
&lt;p&gt;Brought to you this morning by my current favorite method of caffeination:&lt;/p&gt;
&lt;p&gt;&lt;br/&gt;&lt;img class=&quot;centered&quot; src=&quot;http://ecx.images-amazon.com/images/I/41EGcwVE2LL._SL500_AA280_.jpg&quot; alt=&quot;Dunkin Donuts&quot;/&gt;&lt;/p&gt;
&lt;h3&gt;Classes, Variables &amp;amp; Methods&lt;/h3&gt;
&lt;p&gt;Classes are divided into 2 parts:&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
	@interface // definitions go here
	
	...
	
	@implementation // goes here
&lt;/pre&gt;
&lt;p&gt;Methods are defined using the syntax:&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
	-(void) add: (int) a and: (int) b;
&lt;/pre&gt;
&lt;p&gt;With the &amp;#8211; at the start meaning an instance-level variable, and a + meaning a class level definition. Giving variables names in each method definition can feel a little strange. Heres a couple more examples:&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
	-(void) setNumerator: (int) n overDenominator: (int) d;
	-(void) addEntryWithName: (*NSString) name andEmail: (*NSString) email andPhone: (*NSString) phone;
&lt;/pre&gt;
&lt;p&gt;The names can also be ignored if you wish.&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
	-(void) add: (int) a: (int) b;
&lt;/pre&gt;
&lt;p&gt;Methods are invoked via the syntax:&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
	[receiver message];
&lt;/pre&gt;
&lt;p&gt;Variables can be accessed using the &amp;#8216;dot operator&amp;#8217;:&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
	myInstance.myVar;
&lt;/pre&gt;
&lt;p&gt;And can be quickly defined using the @synthesize operator, which is somewhat equivalent to Rubys attr_accessible:&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
	@synthesis myVar;
&lt;/pre&gt;
&lt;p&gt;To bring it all together:&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
	#import &amp;lt;Foundation/Foundation.h&amp;gt;

	@interface Fraction : NSObject 
	{
		@public
			int public_variable;
	}

	@property int numerator, denominator;

	-(void) setNumerator: (int) n andDenominator: (int) d;
	-(void) setA: (int) a;

	@end

	@implementation Fraction

	@synthesize numerator, denominator;

	-(void) setNumerator: (int) n andDenominator: (int) d
	{
		numerator = n;
		denominator = d;
	}

	-(void) setA: (int) a
	{
		public_variable = a;
	}

	@end


	int main (int argc, const char * argv[]) {
	    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

		Fraction *f = [[Fraction alloc] init];
		[f setNumerator: 1 andDenominator: 2];
		NSLog(@&quot;numerator: %i, denominator: %i&quot;, [f numerator], [f denominator]);

		[f setA: 3];
		NSLog(@&quot;via attribute accessor: %i&quot;, f-&amp;gt;public_variable);

	    [pool drain];
	    return 0;
	}
&lt;/pre&gt;
&lt;h3&gt;The &amp;#8216;id&amp;#8217; Data Type and Static Typing&lt;/h3&gt;
&lt;p&gt;In Java if we didn&amp;#8217;t feel like being explicit about a type, we could always just define a super-class as the reference, for example:&lt;/p&gt;
&lt;pre class='brush:java,gutter:false'&gt; 
	public class Philly
	{
		public static void main(String[] args) throws InterruptedException
		{
			Object p = new Philly();
			System.out.println(p.getClass());
		}
	}
&lt;/pre&gt;
&lt;p&gt;Of course gives us the output Philly.&lt;/p&gt;
&lt;p&gt;In Objective-C we get this weird little &amp;#8216;id data type&amp;#8217; that can basically do the same thing. My, you are a weird little man, aren&amp;#8217;t you ?&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
id g = [[Fraction alloc] init];
NSLog(@&quot;numerator: %i, denominator: %i&quot;, [g numerator], [g denominator]);
&lt;/pre&gt;
&lt;p&gt;Note that we didn&amp;#8217;t even have to declare g as a pointer there.&lt;/p&gt;
&lt;p&gt;Up next: Meta-data, Categories &amp;amp; Protocols.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Sinatra + Hpricot + jQuery == Dukkha</title>
   <link href="/2010/02/24/Dukkha-equals-Sinatra-plus-Hpricot-plus-jQuery.html"/>
   <updated>2010-02-24T00:00:00-08:00</updated>
   <id>/2010/02/24/Dukkha-equals-Sinatra-plus-Hpricot-plus-jQuery</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/02/24/Dukkha-equals-Sinatra-plus-Hpricot-plus-jQuery.html&quot;&gt;Sinatra + Hpricot + jQuery == Dukkha&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;24 Feb 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;
&lt;p&gt;I realized over the weekend that I needed some form of &amp;#8216;startpage&amp;#8217;. I have a bunch of access-points, switches, servers and applications, each with its own access url, and I wanted a simple, configurable page, with a link to each server/app, that I could set my homepage to. I quick google led me to this site: &lt;a href=&quot;http://www.symbaloo.com&quot;&gt;symbaloo&lt;/a&gt;. I loved the cool grid-layout but wasn&amp;#8217;t interested in relying upon an external site, so I decided to spend Sunday afternoon knocking something similar up.&lt;/p&gt;
&lt;p&gt;Besides, I have been dying to play with the awesome &lt;a href=&quot;http://www.sinatrarb.com&quot;&gt;Sinatra&lt;/a&gt;, which looked perfect. Coupled with &lt;a href=&quot;http://wiki.github.com/hpricot/hpricot/&quot;&gt;hpricot&lt;/a&gt; for &lt;span class=&quot;caps&quot;&gt;XML&lt;/span&gt; parsing, and &lt;a href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt; for all-round awesomeness, we have everything we need to build something like this in a couple hours.&lt;/p&gt;
&lt;h3&gt;Configuration&lt;/h3&gt;
&lt;p&gt;Lets start by defining the configurable variables of a &amp;#8216;cell&amp;#8217; (one of the table elements), it looks a little like this:&lt;/p&gt;
&lt;pre class='brush:html,gutter:false'&gt; 
	&amp;lt;cell&amp;gt;
		&amp;lt;coords&amp;gt;&amp;lt;x&amp;gt;5&amp;lt;/x&amp;gt;&amp;lt;y&amp;gt;1&amp;lt;/y&amp;gt;&amp;lt;/coords&amp;gt;
		&amp;lt;image&amp;gt;router.gif&amp;lt;/image&amp;gt;
		&amp;lt;text&amp;gt;dsl router&amp;lt;/text&amp;gt;
		&amp;lt;color&amp;gt;#ffffff&amp;lt;/color&amp;gt;
		&amp;lt;background&amp;gt;blue.gif&amp;lt;/background&amp;gt;    
		&amp;lt;url&amp;gt;http://192.168.1.1&amp;lt;/url&amp;gt;
	&amp;lt;/cell&amp;gt;
&lt;/pre&gt;
&lt;p&gt;Which should give us everything we need.&lt;/p&gt;
&lt;h3&gt;Hpricot&lt;/h3&gt;
&lt;p&gt;Life couldn&amp;#8217;t be any easier when we&amp;#8217;re parsing &lt;span class=&quot;caps&quot;&gt;XML&lt;/span&gt; in ruby, so I took the liberty of firstly creating a Cell class to hold what we need:&lt;/p&gt;

&lt;pre class='brush:ruby,gutter:false'&gt; 
	class Cell
	  @@attrs = [:x, :y, :image, :text, :color, :background, :url, :tooltip]
	  @@attrs.each {|a| attr_accessor a }

	  def initialize(cell)
	    @@attrs.each do |a|
	      self.send(&quot;#{a}=&quot;, (cell/a).inner_html)
	    end    
	    [:x, :y].each {|a| self.send(&quot;#{a}=&quot;, self.send(a).to_i)}
	  end
	end
&lt;/pre&gt;
&lt;p&gt;Along with a quick &lt;span class=&quot;caps&quot;&gt;XML&lt;/span&gt; parsing routine:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt;     
	def load_config(xml_config)
	  config = File.read(xml_config)
	  doc = Hpricot.parse(config)

	  # cells = multi-d array using width &amp;amp; height
	  width = (doc/:cells/:width).inner_html.to_i
	  height = (doc/:cells/:height).inner_html.to_i
	  cells = Array.new(height)
	  height.times { |h| cells[h] = Array.new(width) }

	  (doc/:cells/:cell).each do |cell_html|
	    cell = Cell.new(cell_html)
	    cells[cell.y][cell.x] = cell
	  end
	  cells  
	end
&lt;/pre&gt;
&lt;p&gt;And we have our table config&amp;#8217;d and loaded.&lt;/p&gt;
&lt;h3&gt;Sinatra&lt;/h3&gt;
&lt;p&gt;Next up, is the fantastic &lt;a href=&quot;http://www.sinatrarb.com&quot;&gt;Sinatra&lt;/a&gt;. By no stretch of the imagination did I make use of its best features here, in fact all I&amp;#8217;m really doing is using it as a glorified web-server, but the project did give me an opportunity to play around with some of its cooler features and I have a project in mind already for next weekend.&lt;/p&gt;
&lt;p&gt;All we&amp;#8217;re really going to do here is load the &lt;span class=&quot;caps&quot;&gt;XML&lt;/span&gt; into our multi-dimensional array and delegate the display to the view (as it should be):&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt;     
get '/' do
  @cells = load_config
  erb :index
end     
&lt;/pre&gt;

&lt;p&gt;Finally, all of the Javascript resides in the &lt;a href=&quot;http://github.com/snaggled/dukkha/blob/master/views/index.erb&quot;&gt;view&lt;/a&gt;, which I won&amp;#8217;t replicate here, but lets just say that jQuery makes life easier than it should be and I&amp;#8217;d recommend it to anybody. I used &lt;a href=&quot;http://www.prototypejs.org/&quot;&gt;Prototype&lt;/a&gt; pretty extensively for a while (because it shipped with Rails), but over the last year or so, &lt;a href=&quot;http://jquery.com/&quot;&gt;jQuery&lt;/a&gt; has become my Javascript framework of choice.&lt;/p&gt;
&lt;h3&gt;The Result&lt;/h3&gt;
&lt;p&gt;And thats about it, 1 &lt;span class=&quot;caps&quot;&gt;XML&lt;/span&gt; file, 1 Ruby file and 1 View and 1 &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt; file later, we end up with something that looks like this:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/images/dukkha.jpg&quot; class=&quot;lightbox&quot;&gt;&lt;img src=&quot;/images/dukkha.jpg&quot;/&gt;&lt;/a&gt;     &lt;br /&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
$(function() {
	$('a.lightbox').lightBox(); 
});
&lt;/script&gt;&lt;/p&gt;
&lt;p&gt;You will notice I&amp;#8217;ve replicated the &lt;a href=&quot;http://www.symbaloo.com&quot;&gt;symbaloo&lt;/a&gt; layout and used some of their icons. Credit where credit&amp;#8217;s due, their site looks great and I encourage you to head over there and check it out.&lt;/p&gt;
&lt;h3&gt;A name, and Internet Explorer&lt;/h3&gt;
&lt;p&gt;Which leaves us with a name to choose. I settled upon &lt;a href=&quot;http://en.wikipedia.org/wiki/Dukkha&quot;&gt;Dukkha&lt;/a&gt; because I am reading about Buddhism and was extremely impressed to find it defined the fundamental disquiet we experience as beings, trapped between the assumption of an eternal self (atman) and the denial of such a self (anatman).&lt;/p&gt;
&lt;p&gt;Speaking of &amp;#8220;having a poor axle hole,&amp;#8221;, thats pretty much how I felt when I discovered Internet Explorer didn&amp;#8217;t want to play nicely with my &lt;span class=&quot;caps&quot;&gt;XHTML&lt;/span&gt; and &lt;span class=&quot;caps&quot;&gt;CSS&lt;/span&gt;. If Microsoft browsers are your thing, I graciously invite you to fork off in github and make it look pretty.&lt;/p&gt;
&lt;p&gt;The project is available on &lt;a href=&quot;http://github.com/snaggled/dukkha&quot;&gt;github&lt;/a&gt; to fork and/or download.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Pointers - We Meet Again</title>
   <link href="/2010/02/19/Pointers-We-Meet-Again.html"/>
   <updated>2010-02-19T00:00:00-08:00</updated>
   <id>/2010/02/19/Pointers-We-Meet-Again</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/02/19/Pointers-We-Meet-Again.html&quot;&gt;Pointers &amp;#8211; We Meet Again&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;18 Feb 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;
&lt;p&gt;After switching to Java, Python and eventually Ruby, I honestly, honestly thought I&amp;#8217;d never see another pointer again in my life. I&amp;#8217;m still traumatized by the 4000 lines of X/Motif code I wrote as part of my undergraduate thesis many years ago. Nonetheless, it appears that he who wants to code on the IPhone must take a refresher, so here it is.&lt;/p&gt;
&lt;h3&gt;Pointers&lt;/h3&gt;
&lt;p&gt;Variable, meet pointer, who is nothing more than a memory address with your address in it.&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt; 
	#import &amp;lt;Foundation/Foundation.h&amp;gt;

	int main (int argc, const char * argv[]) {
	    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

	    int count = 1;
		int *ptr;

		// ptr is equal to the address of count
		ptr = &amp;amp;count;
		NSLog(@&quot;c = %i, p = %i&quot;, count, *ptr);

		// contents of ptr is equal to the contents of count
		count = 2;
		*ptr = count;
		NSLog(@&quot;c = %i, p = %i&quot;, count, *ptr);

		// ptr is actually a memory address
		NSLog(@&quot;p == %i&quot;, ptr);

	    [pool drain];
	    return 0;
	}
&lt;/pre&gt;
&lt;p&gt;Gives us:&lt;/p&gt;
&lt;pre class='brush:bash,gutter:false'&gt;
07:07:26.919 Pointers[1958:903] c = 1, p = 1
07:07:26.922 Pointers[1958:903] c = 2, p = 2
07:07:26.923 Pointers[1958:903] p == 1606414028
&lt;/pre&gt;
&lt;h4&gt;Structs&lt;/h4&gt;
&lt;p&gt;Pointer, meet struct. You two shall become very familiar. In fact, theres even some funky shorthand you can use together.&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt;
	int main (int argc, const char * argv[]) {
	    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

		struct date 
		{
			int month;
			int day;
			int year;
		};

		struct date today;
		struct date *ptr;

		today.month = 2;
		today.day = 19;
		today.year = 2010;

		// ptr points to today
		ptr = &amp;amp;today;

		// ptr is actually a memory address
		NSLog(@&quot;t == %i&quot;, ptr);

		// we can still access the elements of thr struct
		NSLog(@&quot;t == %i&quot;, (*ptr).month);

		// but we also get this cool shorthand
		NSLog(@&quot;t == %i&quot;, ptr-&amp;gt;year);	

	    [pool drain];
	    return 0;
	}
&lt;/pre&gt;
&lt;p&gt;The product of your union (fnar, fnar):&lt;/p&gt;
&lt;pre class='brush:bash,gutter:false'&gt;
07:16:58.706 Pointers[2360:903] t = 1606413984
07:16:58.709 Pointers[2360:903] t = 2
07:16:58.709 Pointers[2360:903] t = 2010
&lt;/pre&gt;
&lt;h4&gt;Methods and Functions&lt;/h4&gt;
&lt;p&gt;We have two options here &amp;#8211; passing the address of a variable (&amp;amp;) is the same as declaring and passing a pointer.&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt;
	#import &amp;lt;Foundation/Foundation.h&amp;gt;

	// we're accepting pointers here
	void exchange(int *p1, int *p2)
	{
		int temp;

		temp = *p1;
		*p1 = *p2;
		*p2 = temp;
	}

	int main (int argc, const char * argv[]) {
	    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

		int x = 1, y = 2;

		// before exchange
		NSLog(@&quot;x, y == %i, %i&quot;, x, y);

		// we can pass in the address of x, y
		exchange(&amp;amp;x, &amp;amp;y);
		NSLog(@&quot;x, y == %i, %i&quot;, x, y);

		// or we can declare a pointer and pass that in instead
		int *p1, *p2;
		p1 = &amp;amp;x;
		p2 = &amp;amp;y;

		exchange(p1, p2);
		NSLog(@&quot;x, y == %i, %i&quot;, *p1, *p2);

	    [pool drain];
	    return 0;
	}	
&lt;/pre&gt;
&lt;p&gt;Mon cheri:&lt;/p&gt;
&lt;pre class='brush:bash,gutter:false'&gt;
07:44:36.137 Pointers[2892:903] x, y == 1, 2
07:44:36.141 Pointers[2892:903] x, y == 2, 1
07:44:36.141 Pointers[2892:903] x, y == 1, 2
&lt;/pre&gt;
&lt;h4&gt;Arrays&lt;/h4&gt;
&lt;p&gt;And this, at last, is where the fun begins.&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt;
	#import &amp;lt;Foundation/Foundation.h&amp;gt;

	int main (int argc, const char * argv[]) {
	    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

		int *ptr;
		int myArray[] = {1, 2, 3};

		// we can point at the start of the array like this
		ptr = &amp;amp;myArray[0];
		NSLog(@&quot;ptr == %i&quot;, *ptr);

		// or use the shorter version, the compiler treats the 
		// occurence of an array name with subscript as pointer
		// to first element of the array
		ptr = myArray;
		NSLog(@&quot;ptr == %i&quot;, *ptr);

		// then we can access directly
		ptr[1] = 5;
		NSLog(@&quot;ptr == %i&quot;, myArray[1]);

		// or this way. they key point here is that the compiler
		// will look after the size of the inc/decrement depending
		// on what the array objects are
		*(ptr + 1) = 6;
		NSLog(@&quot;ptr == %i&quot;, myArray[1]);

		// or increment/decrement
		*(++ptr) = 7;
		NSLog(@&quot;ptr == %i&quot;, myArray[1]);

	    [pool drain];
	    return 0;
	}
&lt;/pre&gt;
&lt;p&gt;Gives us:&lt;/p&gt;
&lt;pre class='brush:bash,gutter:false'&gt;
08:10:13.356 Pointers[3588:903] ptr == 1
08:10:13.359 Pointers[3588:903] ptr == 1
08:10:13.359 Pointers[3588:903] ptr == 5
08:10:13.360 Pointers[3588:903] ptr == 6
08:10:13.360 Pointers[3588:903] ptr == 7
&lt;/pre&gt;
&lt;h4&gt;Functions&lt;/h4&gt;
&lt;p&gt;Finally, its worth noting that you can declare a pointer to a function.&lt;/p&gt;
&lt;pre class='brush:cpp,gutter:false'&gt;
	#import &amp;lt;Foundation/Foundation.h&amp;gt;

	void myfunc(int *a, int *b)
	{
		int temp;
		temp = *a;
		*a = *b;
		*b = temp;
	}

	int main (int argc, const char * argv[]) {
	    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

		int a = 1, b = 2;

		// before function
		NSLog(@&quot;a, b == %i, %i&quot;, a, b);

		// vanilla
		myfunc(&amp;amp;a, &amp;amp;b);
		NSLog(@&quot;a, b == %i, %i&quot;, a, b);

		// we can declare a pointer to a function
		// note the parentheses around the function name
		void (*ptr) (int *a, int *b);
		ptr = myfunc;

		// using the ptr
		ptr(&amp;amp;a, &amp;amp;b);
		NSLog(@&quot;a, b == %i, %i&quot;, a, b);

	    [pool drain];
	    return 0;
	}
&lt;/pre&gt;
&lt;p&gt;Point to my function baby.&lt;/p&gt;
&lt;pre class='brush:bash,gutter:false'&gt;
08:12:16.534 Pointers[3608:903] a, b == 1, 2
08:12:16.536 Pointers[3608:903] a, b == 2, 1
08:12:16.537 Pointers[3608:903] a, b == 1, 2
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>New Layout and Style</title>
   <link href="/2010/02/18/new-layout-and-style.html"/>
   <updated>2010-02-18T00:00:00-08:00</updated>
   <id>/2010/02/18/new-layout-and-style</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2010/02/18/new-layout-and-style.html&quot;&gt;New Layout and Style&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;18 Feb 2010 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;
&lt;p&gt;First post of the new year, and a shiny new look to boot. Been spending my early morning (thank you Dunkin Donuts coffee) reading this:&lt;br /&gt;
&lt;br/&gt;&lt;img src=&quot;http://www.informit.com/ShowCover.aspx?isbn=0321566157&quot; alt=&quot;Programming in Objective C 2.0&quot;/&gt;&lt;br /&gt;
&lt;br/&gt;First reviews and notes to hopefully start this weekend.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Blocks and Procs in Ruby</title>
   <link href="/2009/05/14/blocks-and-procs-in-ruby.html"/>
   <updated>2009-05-14T00:00:00-07:00</updated>
   <id>/2009/05/14/blocks-and-procs-in-ruby</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2009/05/14/blocks-and-procs-in-ruby.html&quot;&gt;Blocks and Procs in Ruby&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;14 May 2009 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;
&lt;p&gt;So, in addition to a minor re-org (took the last post of the front page and decided to just show a list of posts), I continued reading &lt;a href=&quot;http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Method_Calls&quot;&gt;this&lt;/a&gt; awesome article. Here&amp;#8217;s the distilled version.&lt;/p&gt;
&lt;h3&gt;&lt;strong&gt;Procs&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;A Proc, at its simplest, is a block of code that has been bound to a local variable, also known in various forms (some of these more accurate than other) as &amp;#8220;function objects&amp;#8221;, &amp;#8220;functors&amp;#8221; and &amp;#8220;closures&amp;#8221;. They act like any other &amp;#8220;first-class&amp;#8221; objects, can be passed around, stored in data-structures.&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
&amp;gt;&amp;gt; def foo(a, b)
&amp;gt;&amp;gt; a.call(b)
&amp;gt;&amp;gt; end
=&amp;gt; nil
&amp;gt;&amp;gt;  a = Proc.new {|param| puts &quot;'a' being executed on param #{param}&quot;}
=&amp;gt; #&amp;lt;Proc:0x00587a14@(irb):4&amp;gt;
&amp;gt;&amp;gt; b = &quot;hello&quot;
=&amp;gt; &quot;hello&quot;
&amp;gt;&amp;gt; foo(a, b)
'a' being executed on param hello
=&amp;gt; nil
&lt;/pre&gt;
&lt;p&gt;In the above example, we&amp;#8217;ve created a proc &amp;#8220;a&amp;#8221; which accepts params &amp;#8220;param&amp;#8221;. When we pass both to foo, it simply calls &amp;#8220;a&amp;#8221; and passes &amp;#8220;b&amp;#8221; in.&lt;/p&gt;
&lt;p&gt;We have a choice when creating procs &amp;#8211; between &amp;#8220;Proc.new&amp;#8221; and &amp;#8220;lamdba&amp;#8221;.&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
?&amp;gt; x = lambda {|y| puts y}
=&amp;gt; #&amp;lt;Proc:0x0057a24c@(irb):16&amp;gt;
&amp;gt;&amp;gt; x.call(&quot;hello&quot;)
hello
=&amp;gt; nil
&lt;/pre&gt;
&lt;p&gt;In short, they differ slightly in how the return from methods (Proc.new created Procs will return immediately, lambda will not) and the fact that lambda does parameter checking and Proc.new does not.&lt;/p&gt;
&lt;h3&gt;Methods&lt;/h3&gt;
&lt;p&gt;Methods are blocks of code, bound to an object, that have access to its instance variables. The interesting thing about a method here is that you can define &amp;#8216;top-level&amp;#8217; methods, which is implicitly bound to the &lt;a href=&quot;http://www.ruby-doc.org/core/classes/Object.html&quot;&gt;Object&lt;/a&gt; class.&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
&amp;gt;&amp;gt; def s; puts &quot;s&quot;; end
=&amp;gt; nil
&amp;gt;&amp;gt; p Object.methods
[&quot;inspect&quot;, &quot;private_class_method&quot;, &quot;const_missing&quot;, &quot;clone&quot;, 
&quot;method&quot;, &quot;public_methods&quot;, &quot;public_instance_methods&quot;, ...
=&amp;gt; nil
&amp;gt;&amp;gt;
&lt;/pre&gt;
&lt;p&gt;And we can also dynamically call the method using &lt;a href=&quot;http://www.ruby-doc.org/core/classes/Object.html#M000334&quot;&gt;send&lt;/a&gt; (we can pass either a String or the Symbol for the method name).&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
?&amp;gt; o = Object.new
=&amp;gt; #&amp;lt;Object:0x5e9cf0&amp;gt;
&amp;gt;&amp;gt; o.send(:s)
s
=&amp;gt; nil
&amp;gt;&amp;gt;
&lt;/pre&gt;
&lt;h3&gt;Blocks&lt;/h3&gt;
&lt;p&gt;A Block is a (lets called it &amp;#8216;uninstantiated&amp;#8217;) proc. Its the block of code for example in the braces after the lambda command.&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
&amp;gt;&amp;gt; x = lambda {&quot;puts i am a proc&quot;}
=&amp;gt; #&amp;lt;Proc:0x005f0924@(irb):1&amp;gt;
&amp;gt;&amp;gt; def f(func)
&amp;gt;&amp;gt; func.call
&amp;gt;&amp;gt; end
=&amp;gt; nil
&amp;gt;&amp;gt; f(x)
=&amp;gt; &quot;puts i am a proc&quot;
?&amp;gt; def g
&amp;gt;&amp;gt; yield
&amp;gt;&amp;gt; end
=&amp;gt; nil
&amp;gt;&amp;gt; g {&quot;i am a block, implicitly turned into a proc when passed to method&quot;}
=&amp;gt; &quot;i am a block, implicitly turned into a proc when passed to method&quot;
&lt;/pre&gt;
&lt;p&gt;On a final note, I&amp;#8217;ve been using &lt;a href=&quot;http://www.ruby-doc.org/docbar/&quot;&gt;this sidebar&lt;/a&gt; which is truly awesome.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Method Params in Ruby</title>
   <link href="/2009/04/29/method-params-in-ruby.html"/>
   <updated>2009-04-29T00:00:00-07:00</updated>
   <id>/2009/04/29/method-params-in-ruby</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2009/04/29/method-params-in-ruby.html&quot;&gt;Method Params in Ruby&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;29 Apr 2009 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;
&lt;p&gt;Couple of things: firstly, I was a little fed-up trying to keep the format of code when I pasted it into this blog, and &lt;a href=&quot;http://gist.github.com/104176&quot;&gt;Gist&lt;/a&gt; and &lt;a href=&quot;http://pastie.org/&quot;&gt;Pastie&lt;/a&gt; felt like overkill (although I do like those services, especially &lt;a href=&quot;http://pastie.org/&quot;&gt;Pastie&lt;/a&gt;). From my github &lt;span class=&quot;caps&quot;&gt;RSS&lt;/span&gt; feed there seemed to be a lot of activity on &lt;a href=&quot;http://github.com/mojombo/jekyll/tree/master&quot;&gt;Jekyll&lt;/a&gt; so I was browsing the &lt;span class=&quot;caps&quot;&gt;README&lt;/span&gt; and chanced upon the fact that it supports &lt;a href=&quot;http://pygments.org/&quot;&gt;Pygment&lt;/a&gt; which was just what I needed. One quick python &lt;a href=&quot;http://peak.telecommunity.com/DevCenter/EasyInstall&quot;&gt;easy_install&lt;/a&gt; and I was up and running. Sweet!&lt;/p&gt;
&lt;p&gt;So, I spent some time this evening looking at methods &amp;amp; params in Ruby (actually: &lt;a href=&quot;http://en.wikibooks.org/wiki/Ruby_Programming/Syntax/Method_Calls&quot;&gt;here&lt;/a&gt;). Heres the short and sweet:&lt;/p&gt;
&lt;h3&gt;Hashes&lt;/h3&gt;
&lt;p&gt;Passing a Hash to a method will result in those parameters being rolled up into a single Hash Variable.&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
&amp;gt;&amp;gt; def accept(var)
&amp;gt;&amp;gt; var.inspect
&amp;gt;&amp;gt; end
=&amp;gt; nil
&amp;gt;&amp;gt; accept('a')
=&amp;gt; &quot;\&quot;a\&quot;&quot;
&amp;gt;&amp;gt; accept('a' =&amp;gt; 1)
=&amp;gt; &quot;{\&quot;a\&quot;=&amp;gt;1}&quot;
&amp;gt;&amp;gt; accept('a'=&amp;gt;1,'b'=&amp;gt;2)
=&amp;gt; &quot;{\&quot;a\&quot;=&amp;gt;1, \&quot;b\&quot;=&amp;gt;2}&quot;
&lt;/pre&gt;
&lt;h3&gt;Asterisk&lt;/h3&gt;
&lt;p&gt;An asterisk (the &amp;#8216;splat&amp;#8217; operator) can be used on last parameter of a method to pass additional params. Additional params are collected into an array in the last parameter.&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
&amp;gt;&amp;gt; def accept2(a, b, *c)
&amp;gt;&amp;gt; c.inspect
&amp;gt;&amp;gt; end
=&amp;gt; nil
&amp;gt;&amp;gt; accept2(1, 2, 3, 4, 5)
=&amp;gt; &quot;[3, 4, 5]&quot;
&lt;/pre&gt;
&lt;p&gt;And the reverse is true, an array parameter can be prefixed by asterisk to be expanded as its passed to the method.&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
&amp;gt;&amp;gt; a = [1, 2, 3]
=&amp;gt; [1, 2, 3]
&amp;gt;&amp;gt; accept2(*a)
=&amp;gt; &quot;[3]&quot;
&lt;/pre&gt;
&lt;h3&gt;Ampersand&lt;/h3&gt;
&lt;p&gt;Much like asterisk, except you are telling the method that a code block will be passed in. A proc object will be created and assigned to the param name.&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
&amp;gt;&amp;gt; def accept3(&amp;amp;code)
&amp;gt;&amp;gt; code.call
&amp;gt;&amp;gt; end
=&amp;gt; nil
&amp;gt;&amp;gt; accept3 {puts &quot;philly&quot;}
philly
=&amp;gt; nil
&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Too Many Open Files in Rails - Temp Files in Mongrel</title>
   <link href="/2009/03/16/temp-files-in-mongrel.html"/>
   <updated>2009-03-16T00:00:00-07:00</updated>
   <id>/2009/03/16/temp-files-in-mongrel</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2009/03/16/temp-files-in-mongrel.html&quot;&gt;Too Many Open Files in Rails &amp;#8211; Temp Files in Mongrel&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;16 Mar 2009 &amp;#8211; Denver, CO&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;
&lt;p&gt;I&amp;#8217;ve had a whole bunch of pain the last couple of days with &lt;a href=&quot;http://mongrel.rubyforge.org/&quot;&gt;mongrel&lt;/a&gt; dumping tmp files on me and filling up my ulimit quota causing Rails to fall over.&lt;/p&gt;
&lt;p&gt;It started when I started posting a bunch of multi-part files to Rails and letting &lt;a href=&quot;http://github.com/technoweenie/attachment_fu/tree/master&quot;&gt;attachment_fu&lt;/a&gt; do the dirty-work, but I quickly hit upon this:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
Processing DocumentsController#create to xml ...
...

MissingSourceFile (no such file to load -- .../git/eiger/app/models/document.rb):
	.../lib/active_support/dependencies.rb:382:in `load_without_new_constant_marking'
	.../lib/active_support/dependencies.rb:382:in `load_file'
	.../lib/active_support/dependencies.rb:521:in `new_constants_in'
&lt;/pre&gt;
&lt;p&gt;A quick check meant:&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
:eiger philipmcmahon$ ulimit -n
256
&lt;/pre&gt;
&lt;p&gt;and&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
:~ philipmcmahon$ lsof /dev/disk0s2 | grep mongrel |  wc -l
245

philip-mcmahons-macbook-pro:~ philipmcmahon$ lsof /dev/disk0s2 | grep mongrel
ruby      25400 philipmcmahon    6u   REG   14,2    712224 13096890 
/private/var/folders/+Z/+ZLlmYL1FlmQ5osVVIedbU+++TI/-Tmp-/mongrel25400-0
ruby      25400 philipmcmahon    7u   REG   14,2    348977 13102715 
/private/var/folders/+Z/+ZLlmYL1FlmQ5osVVIedbU+++TI/-Tmp-/mongrel25400-0
ruby      25400 philipmcmahon    8u   REG   14,2    626096 13096931 
/private/var/folders/+Z/+ZLlmYL1FlmQ5osVVIedbU+++TI/-Tmp-/mongrel25400-0
ruby      25400 philipmcmahon    9u   REG   14,2   1350716 13097079 
/private/var/folders/+Z/+ZLlmYL1FlmQ5osVVIedbU+++TI/-Tmp-/mongrel25400-0
ruby      25400 philipmcmahon   10u   REG   14,2    203294 13096875 
/private/var/folders/+Z/+ZLlmYL1FlmQ5osVVIedbU+++TI/-Tmp-/mongrel25400-0
ruby      25400 philipmcmahon   11u   REG   14,2   2699790 13097300 
/private/var/folders/+Z/+ZLlmYL1FlmQ5osVVIedbU+++TI/-Tmp-/mongrel25400-0
ruby      25400 philipmcmahon   12u   REG   14,2    178210 13096959 
/private/var/folders/+Z/+ZLlmYL1FlmQ5osVVIedbU+++TI/-Tmp-/mongrel25400-0
ruby      25400 philipmcmahon   13u   REG   14,2    217603 13097577 
/private/var/folders/+Z/+ZLlmYL1FlmQ5osVVIedbU+++TI/-Tmp-/mongrel25400-0
ruby      25400 philipmcmahon   14u   REG   14,2   1348152 13097069 
/private/var/folders/+Z/+ZLlmYL1FlmQ5osVVIedbU+++TI/-Tmp-/mongrel25400-0
ruby      25400 philipmcmahon   15u   REG   14,2    203292 13096968 
/private/var/folders/+Z/+ZLlmYL1FlmQ5osVVIedbU+++TI/-Tmp-/mongrel25400-0
&lt;/pre&gt;
&lt;p&gt;Holy shit!&lt;/p&gt;
&lt;p&gt;I have no idea what those file-pointers are, but I do know that they are caused by the file part of multi-part form upload data. For a while I thought it was related to creating Tempfile classes, but after it while it became clear that it was mongrel doing whatever.&lt;/p&gt;
&lt;p&gt;To cut a long story short, I switched to &lt;a href=&quot;http://www.webrick.org/&quot;&gt;webrick&lt;/a&gt; and the problem went away.&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Singleton classes or Eigenclasses</title>
   <link href="/2009/01/28/singletons_classes_or_eigenclasses.html"/>
   <updated>2009-01-28T00:00:00-08:00</updated>
   <id>/2009/01/28/singletons_classes_or_eigenclasses</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2009/01/28/singletons_classes_or_eigenclasses.html&quot;&gt;Singleton classes or Eigenclasses&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;28 Jan 2009 &amp;#8211; Las Vegas, NV&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;
&lt;p&gt;Vegas for the week at a conference. In the Java world, &amp;#8216;Singleton&amp;#8217; (at least to me) usually referred to the design pattern which allowed you to ensure that there would always only be a maximum of one object instance of a particular class. It was usually implemented by making the constructor private and providing an access method that returned a single (usually static) instance of an singular object. It might looked something like this:&lt;/p&gt;
&lt;pre class='brush:java,gutter:false'&gt; 

public class SingletonExample {

	/**
	 * Private class variable
	 */
	private static SingletonExample singleton;
	
	/**
	 * This is the only method available to access the class variable.
	 * @return the singleton instance
	 */
	public static SingletonExample onlyInstance() {
		if (singleton == null)
			singleton = new SingletonExample();
		return singleton;
	}
	
	/**
	 * The Ctr should be private
	 */
	private SingletonExample() {
	}
}

&lt;/pre&gt;
&lt;p&gt;Things appear to be slightly different in the Ruby world. A &lt;i&gt;singleton&lt;/i&gt; or &lt;i&gt;eigenclass&lt;/i&gt; in the Ruby world refers to a particular instance of an object, and ruby allows us to override the methods and behaviors of a particular object (note &amp;#8211; not class).&lt;/p&gt;
&lt;pre class='brush:ruby,gutter:false'&gt; 
	?&amp;gt; class A
	&amp;gt;&amp;gt; end
	=&amp;gt; nil
	&amp;gt;&amp;gt; 
	?&amp;gt; a = A.new
	=&amp;gt; #&amp;lt;A:0x5ef664&amp;gt;
	&amp;gt;&amp;gt; b = A.new
	=&amp;gt; #&amp;lt;A:0x5ee1d8&amp;gt;
	&amp;gt;&amp;gt; 
	?&amp;gt; class &amp;lt;&amp;lt; a
	&amp;gt;&amp;gt; def to_s; &quot;Instance method&quot;; end
	&amp;gt;&amp;gt; end
	=&amp;gt; nil
	&amp;gt;&amp;gt; 
	?&amp;gt; a
	=&amp;gt; Instance method
	&amp;gt;&amp;gt; b
	=&amp;gt; #&amp;lt;A:0x5ee1d8&amp;gt;
&lt;/pre&gt;
&lt;p&gt;For more checkout: &lt;a href=&quot;http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html&quot;&gt;whytheluckystiff&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Multiple Inheritance in Ruby</title>
   <link href="/2009/01/25/multiple-inheritance-in-ruby.html"/>
   <updated>2009-01-25T00:00:00-08:00</updated>
   <id>/2009/01/25/multiple-inheritance-in-ruby</id>
   <content type="html">&lt;h2&gt;&lt;a href=&quot;/2009/01/25/multiple-inheritance-in-ruby.html&quot;&gt;Multiple Inheritance in Ruby&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;16 Jan 2009 &amp;#8211; Miami, FL&lt;/p&gt;
&lt;div id=&quot;post-1&quot; class=&quot;post&quot;&gt;
&lt;div class=&quot;entry&quot;&gt;
&lt;p&gt;I&amp;#8217;m in Miami for a couple of days on business and spent the plane journey reading up on Ruby &lt;i&gt;Mixins&lt;/i&gt; and how it gets around the multiple inheritance problem.&lt;/p&gt;
&lt;p&gt;Coming from a Java background, where there was no multiple inheritance (&lt;i&gt;technically&lt;/i&gt; there isn&amp;#8217;t any in Ruby either), the solution to this one was pretty interesting to me. Ruby uses the concept of a &lt;i&gt;Mixin&lt;/i&gt; which is really just a module. A module can&amp;#8217;t be instantiated and is just a set of functionality.&lt;/p&gt;
&lt;pre class='brush:java,gutter:false'&gt; 
	?&amp;gt; module Mixin
	&amp;gt;&amp;gt; def mixin_method
	&amp;gt;&amp;gt; &quot;Mixin method&quot;
	&amp;gt;&amp;gt; end
	&amp;gt;&amp;gt; end
	=&amp;gt; nil
	&amp;gt;&amp;gt; 
	?&amp;gt; class A
	&amp;gt;&amp;gt; include Mixin
	&amp;gt;&amp;gt; end
	=&amp;gt; A
	&amp;gt;&amp;gt; 
	?&amp;gt; a = A.new
	&amp;gt;&amp;gt; a.mixin_method
	=&amp;gt; &quot;Mixin method&quot;
&lt;/pre&gt;
&lt;p&gt;Where it gets interesting (and the reason Java never supported multiple inheritance) is what to do if we have conflicting methods in our superclasses (&lt;i&gt;&amp;#8220;Diamond Problem&amp;#8221;&lt;/i&gt; anyone ?). Technically, Ruby does not support multiple inheritance, but you can mixin multiple modules into other classes or modules. How does Ruby deal with the diamond problem ? Well it basically uses the last method to be included. You can see below, that the returned method is based on the last one to be introduced to the lookup chain.&lt;/p&gt;
&lt;pre class='brush:java,gutter:false'&gt; 
	?&amp;gt; module MixinA
	&amp;gt;&amp;gt; def hello
	&amp;gt;&amp;gt; &quot;hello from A&quot;
	&amp;gt;&amp;gt; end
	&amp;gt;&amp;gt; end
	=&amp;gt; nil
	&amp;gt;&amp;gt; 
	?&amp;gt; module MixinB
	&amp;gt;&amp;gt; def hello
	&amp;gt;&amp;gt; &quot;hello from B&quot;
	&amp;gt;&amp;gt; end
	&amp;gt;&amp;gt; end
	=&amp;gt; nil
	&amp;gt;&amp;gt; 
	?&amp;gt; class C
	&amp;gt;&amp;gt; include MixinA
	&amp;gt;&amp;gt; include MixinB
	&amp;gt;&amp;gt; end
	=&amp;gt; C
	&amp;gt;&amp;gt; 
	?&amp;gt; c = C.new
	=&amp;gt; #&amp;lt;C:0x5e6550&amp;gt;
	&amp;gt;&amp;gt; c.hello
	=&amp;gt; &quot;hello from B&quot;
	&amp;gt;&amp;gt; 
	?&amp;gt; class D
	&amp;gt;&amp;gt; include MixinB
	&amp;gt;&amp;gt; include MixinA
	&amp;gt;&amp;gt; end
	=&amp;gt; D
	&amp;gt;&amp;gt; 
	?&amp;gt; d = D.new
	=&amp;gt; #&amp;lt;D:0x5e0ca4&amp;gt;
	&amp;gt;&amp;gt; d.hello
	=&amp;gt; &quot;hello from A&quot;
&lt;/pre&gt;
&lt;p&gt;And thats it. You can also include a module in another module, just like normal inheritance. Module is actually a super-class of Class, but classes cannot be mixed-in to other classes, only Modules can.&lt;/p&gt;
&lt;pre class='brush:java,gutter:false'&gt; 
	&amp;gt;&amp;gt; module MixinA
	&amp;gt;&amp;gt; def hello
	&amp;gt;&amp;gt; &quot;hello&quot;
	&amp;gt;&amp;gt; end
	&amp;gt;&amp;gt; end
	=&amp;gt; nil
	&amp;gt;&amp;gt; 
	?&amp;gt; module MixinB
	&amp;gt;&amp;gt; include MixinA
	&amp;gt;&amp;gt; def hello2
	&amp;gt;&amp;gt; &quot;hello2&quot;
	&amp;gt;&amp;gt; end
	&amp;gt;&amp;gt; end
	=&amp;gt; nil
	&amp;gt;&amp;gt; 
	?&amp;gt; class C
	&amp;gt;&amp;gt; include MixinB
	&amp;gt;&amp;gt; end
	=&amp;gt; C
	&amp;gt;&amp;gt; 
	?&amp;gt; c = C.new
	=&amp;gt; #&amp;lt;C:0x5e7608&amp;gt;
	&amp;gt;&amp;gt; c.hello
	=&amp;gt; &quot;hello&quot;
	&amp;gt;&amp;gt; c.hello2
	=&amp;gt; &quot;hello2&quot;
&lt;/pre&gt;
&lt;p&gt;For a more complete introduction, of course you can simply &lt;i&gt;`ri Module`&lt;/i&gt;.&lt;/p&gt;
&lt;p&gt;&lt;/div&gt;&lt;/div&gt;&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Using the GitHub API to Display your Repositories</title>
   <link href="/2008/12/29/using-the-github-api-to-display-your-repos.html"/>
   <updated>2008-12-29T00:00:00-08:00</updated>
   <id>/2008/12/29/using-the-github-api-to-display-your-repos</id>
   <content type="html">&lt;h1&gt;Using the GitHub &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt; to Display your Repositories&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;29 Dec 2008 &amp;#8211; Draperstown, Northern Ireland&lt;/p&gt;
&lt;p&gt;I wanted to display a list of my repositories on my homepage. Spent a while fluffing about with the &lt;a href=&quot;http://docs.jquery.com/Ajax/jQuery.getJSON&quot;&gt;jQuery.getJSON&lt;/a&gt; call, but in the end found it preferable to use the callback parameter combined with &lt;a href=&quot;http://docs.jquery.com/Ajax/jQuery.getScript&quot;&gt;jQuery.getScript&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Heres the code, which will populate a div with the id &amp;#8216;repos&amp;#8217;:&lt;/p&gt;
&lt;script src='http://pastie.org/349089.js'&gt;&lt;/script&gt;</content>
 </entry>
 
 <entry>
   <title>We are up and running</title>
   <link href="/2008/12/29/We+are+up+and+running.html"/>
   <updated>2008-12-29T00:00:00-08:00</updated>
   <id>/2008/12/29/We are up and running</id>
   <content type="html">&lt;h1&gt;We are up and running&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;29 Dec 2008 &amp;#8211; Draperstown, Northern Ireland&lt;/p&gt;
&lt;p&gt;Bringing the blog up was pretty painless, and full kudos must go to &lt;a href=&quot;http://mojombo.github.com&quot;&gt;mojombo&lt;/a&gt; for both the sweet &lt;a href=&quot;http://github.com/mojombo/jekyll&quot;&gt;jekyll&lt;/a&gt; idea and tool, and even css style (yes, I was that lazy). I love the ability to blog via a git commit, very cool and minimal overhead. The &lt;a href=&quot;http://hobix.com/textile/&quot;&gt;Textile&lt;/a&gt; format is pretty new to me (I know &amp;#8211; where have I been ?) but I&amp;#8217;m really enjoying it.&lt;/p&gt;
&lt;p&gt;With regard to the whole &lt;a href=&quot;http://git.or.cz/&quot;&gt;git&lt;/a&gt; vs &lt;a href=&quot;http://subversion.tigris.org/&quot;&gt;svn&lt;/a&gt; thing, I didn&amp;#8217;t really have any problems with svn, although the merging process could be a little annoying. I&amp;#8217;ve been using &lt;a href=&quot;http://svnrepository.com/&quot;&gt;these guys&lt;/a&gt; for a while without complaint, so I&amp;#8217;d recommend them if you are taking the svn path. If the git and &lt;a href=&quot;http://github.com&quot;&gt;github&lt;/a&gt; thing works out I may end end moving away from those guys. So far I like the distributed repo aspect of git &amp;#8211; the fact I can commit to a local repo and its almost instant, and then push to a remote when I am ready, is great.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve been planning some big changes to &lt;a href=&quot;http://geosack.com&quot;&gt;geosack.com&lt;/a&gt; (very interested in location based services at the minute), so it may be the first victim to be migrated to &lt;a href=&quot;http://github.com&quot;&gt;github&lt;/a&gt;. Last remaining item on the list is to find &amp;amp; install a git bundle for &lt;a href=&quot;http://macromates.com/&quot;&gt;Textmate&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Switching to Git (and GitHub)</title>
   <link href="/2008/12/28/switching-to-git.html"/>
   <updated>2008-12-28T00:00:00-08:00</updated>
   <id>/2008/12/28/switching-to-git</id>
   <content type="html">&lt;h1&gt;Switching to Git (and GitHub)&lt;/h1&gt;
&lt;p class=&quot;meta&quot;&gt;28 Dec 2008 &amp;#8211; Moy, Northern Ireland&lt;/p&gt;
&lt;p&gt;Decided to finally make the move from &lt;a href=&quot;http://subversion.tigris.org/&quot;&gt;svn&lt;/a&gt; to &lt;a href=&quot;http://git.or.cz/&quot;&gt;git&lt;/a&gt; for all my projects, and in the process am considering a move to &lt;a href=&quot;http://github.com&quot;&gt;GitHub&lt;/a&gt;, so we&amp;#8217;ll see how this goes. Mikey Finn is sitting here playing &lt;span class=&quot;caps&quot;&gt;COD&lt;/span&gt; World at War, so I&amp;#8217;m doing this to a soundtrack of explosions and death.&lt;/p&gt;
&lt;p&gt;Will probably spend a couple hours playing with &lt;a href=&quot;http://github.com/mojombo/jekyll/tree/master&quot;&gt;Jekyll&lt;/a&gt; and if things look good, will start the migration of &lt;a href=&quot;http://geosack.com&quot;&gt;Geosack&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 
</feed>