<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Warren Seen &#187; ruby on rails</title>
	<atom:link href="http://warrenseen.com/blog/category/ruby-on-rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://warrenseen.com/blog</link>
	<description>freelance software developer</description>
	<lastBuildDate>Wed, 03 Jun 2009 23:54:34 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Rails auto complete with form_for and fields_for support</title>
		<link>http://warrenseen.com/blog/2009/01/16/rails-auto-complete-with-form_for-and-fields_for-support/</link>
		<comments>http://warrenseen.com/blog/2009/01/16/rails-auto-complete-with-form_for-and-fields_for-support/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 02:44:21 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[Add new tag]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/?p=81</guid>
		<description><![CDATA[I&#8217;ve forked the Rails auto_complete plugin to add support for the following usage:

 Ruby [Show Styled Code]:


  




 Ruby [Show Plain Code]:



&#60;% form_for&#40;@foo&#41; do &#124;f&#124; %&#62;


&#160; &#60;%= f.text_field_with_auto_complete :bar %&#62;


&#60;% end %&#62; 




This fork also supports nested fields_for calls:

 Ruby [Show Styled Code]:


  
    
  




 Ruby [Show Plain [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve forked the <a href="http://github.com/rails/auto_complete/tree/master">Rails auto_complete plugin</a> to add support for the following usage:</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c856e0397e3f">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c856e0397e3f').style.display='block';document.getElementById('plain_synthi_4c856e0397e3f').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
<% form_for(@foo) do |f| %>
  <%= f.text_field_with_auto_complete :bar %>
<% end %>
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c856e0397e3f">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c856e0397e3f').style.display='block';document.getElementById('styled_synthi_4c856e0397e3f').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="ruby" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;% form_for<span style="color:#006600; font-weight:bold;">&#40;</span>@foo<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |f| %&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &lt;%= f.<span style="color:#9900CC;">text_field_with_auto_complete</span> :bar %&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;% <span style="color:#9966CC; font-weight:bold;">end</span> %&gt; </div>
</li>
</ol>
</div>
</div>
<p>This fork also supports nested fields_for calls:</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c856e039a55a">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c856e039a55a').style.display='block';document.getElementById('plain_synthi_4c856e039a55a').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
<% form_for(@foo) do |f| %>
  <% f.fields_for(@foo.baz) do |baz_f| %>
    <%= baz_f.text_field_with_auto_complete :quux %>
  <% end %>
<% end %>
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c856e039a55a">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c856e039a55a').style.display='block';document.getElementById('styled_synthi_4c856e039a55a').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="ruby" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;% form_for<span style="color:#006600; font-weight:bold;">&#40;</span>@foo<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |f| %&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &lt;% f.<span style="color:#9900CC;">fields_for</span><span style="color:#006600; font-weight:bold;">&#40;</span>@foo.<span style="color:#9900CC;">baz</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> |baz_f| %&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &lt;%= baz_f.<span style="color:#9900CC;">text_field_with_auto_complete</span> :quux %&gt;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &lt;% <span style="color:#9966CC; font-weight:bold;">end</span> %&gt;&nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;% <span style="color:#9966CC; font-weight:bold;">end</span> %&gt; </div>
</li>
</ol>
</div>
</div>
<p>You can find my fork on Github, <a href="http://github.com/warrenseen/auto_complete/tree/master">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2009/01/16/rails-auto-complete-with-form_for-and-fields_for-support/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>You know Rails is getting traction&#8230;</title>
		<link>http://warrenseen.com/blog/2007/05/04/you-know-rails-is-getting-traction/</link>
		<comments>http://warrenseen.com/blog/2007/05/04/you-know-rails-is-getting-traction/#comments</comments>
		<pubDate>Thu, 03 May 2007 23:07:51 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2007/05/04/you-know-rails-is-getting-traction/</guid>
		<description><![CDATA[&#8230; when job ads start appearing asking for unrealistic and bordering on impossible levels of experience.
I thought we&#8217;d gotten past this back in 2000 when .Net came out&#8230; but 3 Years of Ruby on Rails experience you say?
Mathematically impossible for the average (read: non-core) rails developer, considering Ruby on Rails was only released publicly in [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; when job ads start appearing asking for unrealistic and bordering on impossible levels of experience.</p>
<p>I thought we&#8217;d gotten past this back in 2000 when .Net came out&#8230; but <a href="http://www.indeed.com/rc/clk?jk=78bd0227827dfd4a&#038;cd=_hq65fXc-evh9Mp4FGmrR88YCUiEYte2wloTl8RMme7aDjepm7mHQa_VS5QdCwlafoIAhPp4NLUkoLHnACib3X4jvGPR4gk9A00hJPB4XdRYFnQc_g_UztBw7KdRi2E8&#038;qd=RnZhMybXSk4M3QtTVGXWoY-ygtZLXr_zwggEpygkL3t9H96ZIR7xaaAsUt8TqwFwIXNAyT1kiwH_s3jSJ2StEg&#038;rd=">3 Years of Ruby on Rails experience you say?</a></p>
<p>Mathematically impossible for the average (read: non-core) rails developer, considering Ruby on Rails was only released publicly in <a href="http://www.rubyonrails.org/core">July of 2004</a>.</p>
<p>They&#8217;re obviously very picky and so are willing to pay up to a whopping US$35-US$55/hr for all those <a href="http://workingwithrails.com/browse/people/authority">Rails rockstars</a> who were using it before it was released to the public! I&#8217;m sure they&#8217;ll drop everything and come running to apply!</p>
<p> <img src='http://warrenseen.com/blog/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />
</p>
<p><!--96f14fcdea813b4332902dbf9301f39e-->
</p>
<p><!--5d6d68a0fa1d74c5997294541c1e8047-->
</p>
<p><!--2c0b9d963c2156a62b73722ac0c3a4a6-->
</p>
<p><!--397fbe8a24319ed0cd6e61aaa95b33cd-->
</p>
<p><!--fc49bba0bfbec6f929030e3f5e22a4b5--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2007/05/04/you-know-rails-is-getting-traction/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Is platform selection premature optimisation?</title>
		<link>http://warrenseen.com/blog/2007/04/16/is-platform-selection-premature-optimisation/</link>
		<comments>http://warrenseen.com/blog/2007/04/16/is-platform-selection-premature-optimisation/#comments</comments>
		<pubDate>Mon, 16 Apr 2007 13:43:06 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[scaling]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2007/04/16/is-platform-selection-premature-optimisation/</guid>
		<description><![CDATA[&#8220;We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.&#8221;
Donald Knuth

Earlier today, I suggested that we should hold language and platform selection to the same standard we do with our code when avoiding premature optimisation. 
The thrust of my argument was that, in relation to [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p><em>&#8220;We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.&#8221;</em><br />
<strong>Donald Knuth</strong></p>
</blockquote>
<p>Earlier today, <a href="http://warrenseen.com/blog/2007/04/16/rails-twitter-and-the-800lb-gorilla-in-the-room/">I suggested</a> that we should hold language and platform selection to the same standard we do with our code when avoiding premature optimisation. </p>
<p>The thrust of my argument was that, in relation to scalability, 99% of sites will never become so popular as to require scalability beyond that which is possible with Rails, so worrying about scalability feels like the start of <a href="http://en.wikipedia.org/wiki/Big_Design_Up_Front">big design up front</a>.</p>
<p>We should aim to not be dogmatic about our selection of language or platform, instead choosing the tools to get the job done, so we can <em>get something out there</em>. </p>
<p>After all, I think it was <strong>Fred Brooks</strong> who told us to <em>build a first version and throw it away</em>; the inherent wisdom in this approach is that you learn far more by building something and failing fast, than doggedly sticking to a flawed design that dies a slow, painful death.</p>
<p>If I can return to the example of Twitter, I don&#8217;t have any references, but I think their development time was quoted at something like 4 months? That&#8217;s not a lot of time really, and therefore, it&#8217;s not a lot of time to write off in the case that Twitter doesn&#8217;t get adopted and turned out to be an idea that was DOA. </p>
<p>Happily for the guys at Obvious, this wasn&#8217;t the case, and now they have a scaling issue, but I bet you they know a hell of a lot more about their users and usage patterns than what they ever could have predicted if they had set out to design it up front.</p>
<p>Could they have not followed the same path with J2EE or ASP.Net? Sure, if you ignore the fact that they&#8217;re Rails developers and therefore are more productive with&#8230; Rails. They chose the platform that was right for them, that got out of their way and let them implement the service to see if it would even work.</p>
<p>Another example, Reddit. The first version was written in Lisp before being <a href="http://www.aaronsw.com/weblog/rewritingreddit">rewritten in Python</a> &#8211; rewriting a proof-of-concept application (the cool kids call it <em>beta software</em> these days) into something that is &#8220;commercially ready&#8221; is not a bad thing.</p>
<p>I&#8217;m sure there are plenty of counter-examples where such an approach has failed, but I&#8217;m not getting into <em>reductio ad absurdum</em> arguments like &#8220;if your premise is true, then I could write #{compute_intensive_app} in #{slow_high_level_language}!&#8221;
</p>
<p><!--e6e8716e718d451b48de8222fe05a7ab-->
</p>
<p><!--f92266a2296131e7d8ccdf1ce51c7b51-->
</p>
<p><!--5b4e417bce981b848687706d16f3ff9b--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2007/04/16/is-platform-selection-premature-optimisation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rails, Twitter and the 800lb Gorilla in the Room&#8230;</title>
		<link>http://warrenseen.com/blog/2007/04/16/rails-twitter-and-the-800lb-gorilla-in-the-room/</link>
		<comments>http://warrenseen.com/blog/2007/04/16/rails-twitter-and-the-800lb-gorilla-in-the-room/#comments</comments>
		<pubDate>Mon, 16 Apr 2007 01:24:39 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[scaling]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2007/04/16/rails-twitter-and-the-800lb-gorilla-in-the-room/</guid>
		<description><![CDATA[When you first start using Rails, you quickly find there&#8217;s an 800lb gorilla in the room that no-one really wants to acknowledge. Yes, the &#8217;s&#8217; word: Scaling. Oh, they&#8217;re quick to tell you that it&#8217;s an uninteresting problem (at least for a programmer), if you do Rails right, and you&#8217;ve shared-nothing, then you just throw [...]]]></description>
			<content:encoded><![CDATA[<p>When you first start using Rails, you quickly find there&#8217;s an <a href="http://www.loudthinking.com/arc/000596.html">800lb gorilla</a> in the room that no-one really wants to acknowledge. Yes, the &#8217;s&#8217; word: <a href="http://www.radicalbehavior.com/5-question-interview-with-twitter-developer-alex-payne/">Scaling</a>. Oh, they&#8217;re quick to tell you that it&#8217;s an uninteresting problem (at least for a programmer), if you <a href="http://www.loudthinking.com/arc/000399.html">do Rails right</a>, and you&#8217;ve <a href="http://en.wikipedia.org/wiki/Shared-nothing">shared-nothing</a>, then you just throw more hardware at the problem. That if you have a real bottleneck in your code, just <a href="http://www.loudthinking.com/arc/000598.html">rewrite the performance critical parts of it in C</a>. Oh, and <a href="http://www.atdot.net/yarv/">YARV</a> will be here soon (for certain values of soon), so Ruby will be faster!</p>
<p>And suddenly, that gorilla shrinks; or at least it seems to.</p>
<p>Until <a href="http://obvious.com/">someone</a> goes and <a href="http://twitter.com/">pushes the boundary</a> way beyond <a href="http://penny-arcade.com/">those</a> <a href="http://43things.com/">who&#8217;ve</a> <a href="http://alistapart.com/">come</a> <a href="http://37signals.com">before</a>. Suddenly, the gorilla has grabbed your <a href="http://thebull.macsimumweb.com/2007/04/14/twitter-starting-to-get-de-railed/">girl</a>, climbed to the top of the Empire State and is angrily swatting light aircraft left, right and centre.</p>
<p>Scaling suddenly gets interesting again.</p>
<p><strong>Nay-sayers and trolls cloud the issue</strong><br />
Those who for whatever reason <a href="http://www.loudthinking.com/arc/000610.html#comments">want to see Rails fail</a>, have grabbed ahold of the issue and are casting it as a reason to abandon Rails: &#8220;<a href="http://www.codinghorror.com/blog/archives/000838.html">Behold, the savage beast that cannot be tamed!</a>&#8221; Often, they&#8217;ve got their <a href="http://www.loudthinking.com/arc/000399.html">own agenda</a>, whether it&#8217;s a desire to see their pet platform succeed, or to see DHH kicked to the dirt, these folks don&#8217;t really care about the scaling issue at all. They latch onto these issues not to help improve the platform, in the worst case they want to destroy it.</p>
<p>So forget them. </p>
<p>We&#8217;re here because we want to solve this without changing platforms.</p>
<p><strong>It doesn&#8217;t matter to most of us anyway</strong><br />
The truth is, 99% of Rails projects will *never* hit a performance wall that cannot be solved using existing wisdom. So the issue is a non-issue and certainly not a reason to ditch Rails. </p>
<p>If perchance, you&#8217;re part of the other 1%, you should be <a href="http://laughingmeme.org/2007/04/12/twitter-ruby-and-scaling/">thrilled to have this problem</a>, it means your software has been successful! Fact is, you don&#8217;t <em>accidentally</em> create a site/service which generates 11,000+ requests/sec. You <em>explicitly set out to do so</em>. And presumably, you chose Rails for a reason. Why shouldn&#8217;t we extend the concept of &#8220;no premature optimisation&#8221; to language and platform selection? If Twitter had <a href="http://bobondevelopment.com/2007/04/13/ruby-on-rails-hits-a-wall-twitter-stutters/">chosen an &#8220;enterprise&#8221; class platform</a> and <a href="http://www.codinghorror.com/blog/archives/000838.html">tried to architect</a> for 11k reqs/sec, chances are they would still be building&#8230; </p>
<p><a href="http://obvious.com/">Obvious</a> had a reason to choose Rails; they aren&#8217;t naive, they&#8217;ve been <a href="http://odeo.com/">around the block with Rails</a> before. </p>
<p>Generally, it&#8217;s much better to <a href="http://www.tbray.org/ongoing/When/200x/2007/04/13/Twitter-and-Rails">throw something out there NOW</a>, and let the real problems come out in the wash, rather than sit in a dark room, worrying about what might happen and giving yourself a case of analysis paralysis.</p>
<p><strong>Escalation Sucks</strong><br />
This issue has been blown up by a combination of <a href="http://gettingreal.37signals.com/ch04_Make_Opinionated_Software.php">strong opinions</a>, incomplete information and folks from other camps pouring fuel on the fire. It&#8217;s time this &#8220;conflict&#8221; was de-escalated and the combative nature of the discussion toned down.</p>
<p>The situation itself can be summed up pretty easily</p>
<ul>
<li>We&#8217;re in uncharted waters in terms of this sort of throughput, although others have <a href="http://tomayko.com/weblog/2007/04/13/rails-multiple-connections">suggestions</a> and maybe even <a href="http://drnicwilliams.com/2007/04/12/magic-multi-connections-a-facility-in-rails-to-talk-to-more-than-one-database-at-a-time/">solutions</a>.</li>
<li>The problem didn&#8217;t just suddenly spring up on the Twitter guys, <a href="http://romeda.org/blog/2007/04/scaling-twitter-talk.html">clearly they&#8217;ve been working on it for a while</a> &#8211; implying they&#8217;re now crying to core because Rails is broken for them is disingenuous. (In fact, the whole &#8220;<a href="http://www.loudthinking.com/arc/000608.html">they&#8217;ve forsaken that opportunity for an arms-crossed alternative.</a>&#8221; thing smells like something of a <a href="http://en.wikipedia.org/wiki/Strawman_argument">strawman argument</a> &#8211; I didn&#8217;t get that from the interview, so unless that&#8217;s come out of some backchannel, it seems a peculiar accusation to make.)</li>
<li>Solutions that work for Twitter may not work for other Rails apps. Once you exhaust all of the conventional scaling wisdom, you start to move into application-specific optimisations. Are we there yet? I guess we&#8217;ll wait and see. </li>
</ul>
<p><strong>When the storm is over</strong><br />
This is a learning opportunity for everyone, but those who stand to learn the most are the core team and the Twitter guys. I hope each can continue to be open to the other&#8217;s position. We need to remember at the end of the day, Twitter are under no obligation to release patches, and the core team are under no obligation to accept them &#8211; I hope that doesn&#8217;t happen though, as the community would be the worse for it.</p>
<p><!--1c738554a3f914e9bede627286dc5c4e--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2007/04/16/rails-twitter-and-the-800lb-gorilla-in-the-room/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>New Biz Cards, New Template</title>
		<link>http://warrenseen.com/blog/2007/04/14/new-biz-cards-new-template/</link>
		<comments>http://warrenseen.com/blog/2007/04/14/new-biz-cards-new-template/#comments</comments>
		<pubDate>Sat, 14 Apr 2007 05:59:36 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[bizcards]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2007/04/14/new-biz-cards-new-template/</guid>
		<description><![CDATA[
For some time now, I&#8217;ve needed some new business cards printed up, so I&#8217;ve been tooling around a bit in Adobe Illustrator in my spare time, until I finally came up with a style that suited me. 
Now I was happy with my design, on the recommendation of a friend, I shot a PDF off [...]]]></description>
			<content:encoded><![CDATA[<div>
For some time now, I&#8217;ve needed some new business cards printed up, so I&#8217;ve been tooling around a bit in Adobe Illustrator in my spare time, until I finally came up with a style that suited me. </p>
<p>Now I was happy with my design, on the recommendation of a friend, I shot a PDF off to Click Business Cards via <a href="http://clickbusinesscards.com.au/">their website</a>, and within 24 hours my cards had been printed and express posted to my door (they arrived yesterday). Their website may not be much chop, but their service sure is.</div>
<div style="float:right;margin: 5px;"><a href="http://www.flickr.com/photos/warren_seen/458332397/"><img src="http://farm1.static.flickr.com/245/458332397_799319bb0e_m.jpg" alt="New Biz Cards" /></a></div>
<p>With a little hesitation, I cracked open the box, hoping that I&#8217;d gotten the resolution, colours and bleeds right. I had, they look excellent, if I do say so myself! </p>
<p>I&#8217;m the first to admit I&#8217;m no designer, and I&#8217;ll cop to the fact that the design was largely inspired by <a href="http://davidseah.com/archives/2006/11/11/quickie-business-card-design-iv/">Dave Seah&#8217;s cards</a>, whilst the loco image and ruby red was chosen to tie into the fact that I&#8217;m moving towards specialising in Ruby on Rails.</p>
<p>So, with new cards, I realised that the Wordpress template I&#8217;ve been using was pretty tired. </p>
<p>Time for some branding re-alignment! </p>
<p>A quick CSS change and a new header image later, here we are. I&#8217;ve kept the layout the same for the time being, I don&#8217;t want to sink a lot of time into a new Wordpress template as I&#8217;m thinking of packing this whole site up and moving to a <a href="http://www.slicehost.com/">Slicehost</a> slice. If I do that, it will be goodbye Wordpress, hello to either <a href="http://trac.typosphere.org/">Typo</a> or <a href="http://mephistoblog.com/">Mephisto</a>.</p>
<p>For the time being however, it&#8217;s steady as she goes!
</p>
<p><!--c22930bd2a5a4cc1b67cca8f4db30f35-->
</p>
<p><!--6188499cf736f45c468802611819326f-->
</p>
<p><!--2c2b3994dd06989f82c93f33d7811646-->
</p>
<p><!--1ccd515d5feeffb5b0717e28030e3aeb--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2007/04/14/new-biz-cards-new-template/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Local company taking on Google over GWT?</title>
		<link>http://warrenseen.com/blog/2007/04/03/local-company-taking-on-google-over-gwt/</link>
		<comments>http://warrenseen.com/blog/2007/04/03/local-company-taking-on-google-over-gwt/#comments</comments>
		<pubDate>Mon, 02 Apr 2007 23:40:26 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[patents]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2007/04/03/local-company-taking-on-google-over-gwt/</guid>
		<description><![CDATA[


Tasmania is a small place, which is why I&#8217;m surprised that very few people in the IT industry here have heard of Morfik, a Hobart based development company. Reading this morning&#8217;s Read/Write Web however, things may be about change there. As reported by Richard, slashdot are running a post about the Morfik patent which appears [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right;padding:5px">
<a href="http://www.flickr.com/photos/warren_seen/444206142/"><img src="http://farm1.static.flickr.com/207/444206142_306575a4ce_m.jpg" alt="Morfik" /></a>
</div>
<p>Tasmania is a small place, which is why I&#8217;m surprised that very few people in the IT industry here have heard of <a href="http://www.morfik.com/">Morfik</a>, a Hobart based development company. Reading this morning&#8217;s <a href="http://www.readwriteweb.com/archives/morfik_patents_ajax_compiler.php">Read/Write Web</a> however, things may be about change there. As reported by Richard, <a href="http://yro.slashdot.org/article.pl?sid=07/04/02/1059211">slashdot</a> are running a post about the <a href="http://appft1.uspto.gov/netacgi/nph-Parser?Sect1=PTO2&#038;Sect2=HITOFF&#038;p=1&#038;u=%2Fnetahtml%2FPTO%2Fsearch-bool.html&#038;r=1&#038;f=G&#038;l=50&#038;co1=AND&#038;d=PG01&#038;s1=morfik&#038;OS=morfik&#038;RS=morfik">Morfik patent</a> which appears to be aimed squarely at Google&#8217;s <a href="http://code.google.com/webtoolkit/">GWT</a>.</p>
<p>I&#8217;m in two minds about this, as I always am about software patents. On the one hand, Morfik was clearly first to the party in terms of public release of a JavaScript compiler, according to the patent they had a provisional granted prior to the release of the GWT. On the other, I have to wonder how this is any different to the multitude of language translation techniques already out there, or at least whether it&#8217;s significantly inventive enough to pass the &#8220;not obvious to a practitioner in the field&#8221; test.</p>
<p>But hey, this wouldn&#8217;t be the first patent to be granted despite the obviousness of it to someone with half a brain. I mean, thank goodness the patent doesn&#8217;t mention Ruby, I guess that means <a href="http://www.rubyinside.com/16-rjs-resources-and-tutorials-for-rails-programmers-5.html">RJS</a> is safe!
</p>
<p><!--c803f5fd0a94c87801a54b068fb22c3e-->
</p>
<p><!--d6255acec078e3ea5472f22cbce239a8-->
</p>
<p><!--7ef154d3b0ecc4f6ac914533288de280-->
</p>
<p><!--0d4e8a0bf70f98b503dd59ca2f735a62--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2007/04/03/local-company-taking-on-google-over-gwt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby Cheap Tricks &#8211; Monkeypatching unit conversion</title>
		<link>http://warrenseen.com/blog/2007/02/22/ruby-cheap-tricks-monkeypatching-unit-conversion/</link>
		<comments>http://warrenseen.com/blog/2007/02/22/ruby-cheap-tricks-monkeypatching-unit-conversion/#comments</comments>
		<pubDate>Wed, 21 Feb 2007 22:46:04 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[snippets]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2007/02/22/ruby-cheap-tricks-monkeypatching-unit-conversion/</guid>
		<description><![CDATA[A little something I cooked up, inspired by Rails&#8217; ActiveSupport Numeric::Bytes and friends.


 Ruby [Show Styled Code]:

class Numeric

  def grams
    self
  end

  alias :gram :grams
  alias :g    :grams

  def kilograms
    self * 1000.grams
  end

  alias :kilogram :kilograms
  alias [...]]]></description>
			<content:encoded><![CDATA[<p>A little something I cooked up, inspired by Rails&#8217; ActiveSupport <code>Numeric::Bytes</code> and friends.<br />
<span id="more-40"></span></p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c856e03d27ba">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c856e03d27ba').style.display='block';document.getElementById('plain_synthi_4c856e03d27ba').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
class Numeric

  def grams
    self
  end

  alias :gram :grams
  alias :g    :grams

  def kilograms
    self * 1000.grams
  end

  alias :kilogram :kilograms
  alias :kg       :kilograms

  def tonne
    self * 1000.kilograms
  end

  alias :tonnes :tonne

  def pounds
    self * 453.59237.grams
  end

  alias :pound  :pounds
  alias :lb     :pounds
  alias :lbs    :pounds

  def stone
    self * 14.pounds
  end

  def ton
    self * 2240.pounds
  end
  alias :tons :ton

  def method_missing(method_id, *arguments)
    if match = /^to_([a-zA-Z]w*)$/.match(method_id.to_s)
      self / (1.0 * 1.send(match[1]))
    else
      super
    end
  end
end
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c856e03d27ba">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c856e03d27ba').style.display='block';document.getElementById('styled_synthi_4c856e03d27ba').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="ruby" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">class</span> Numeric</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> grams</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">alias</span> :gram :grams</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">alias</span> :g&nbsp; &nbsp; :grams</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> kilograms</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span> * <span style="color:#006666;">1000</span>.<span style="color:#9900CC;">grams</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">alias</span> :kilogram :kilograms</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">alias</span> :kg&nbsp; &nbsp; &nbsp; &nbsp;:kilograms</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> tonne</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span> * <span style="color:#006666;">1000</span>.<span style="color:#9900CC;">kilograms</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">alias</span> :tonnes :tonne</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> pounds</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span> * <span style="color:#006666;">453.59237</span>.<span style="color:#9900CC;">grams</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">alias</span> :pound&nbsp; :pounds</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">alias</span> :lb&nbsp; &nbsp; &nbsp;:pounds</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">alias</span> :lbs&nbsp; &nbsp; :pounds</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> stone</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span> * <span style="color:#006666;">14</span>.<span style="color:#9900CC;">pounds</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> ton</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span> * <span style="color:#006666;">2240</span>.<span style="color:#9900CC;">pounds</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">alias</span> :tons :ton</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>method_id, *arguments<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">if</span> match = /^to_<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>a-zA-Z<span style="color:#006600; font-weight:bold;">&#93;</span>w*<span style="color:#006600; font-weight:bold;">&#41;</span>$/.<span style="color:#9900CC;">match</span><span style="color:#006600; font-weight:bold;">&#40;</span>method_id.<span style="color:#9900CC;">to_s</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#0000FF; font-weight:bold;">self</span> / <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1.0</span> * <span style="color:#006666;">1</span>.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>match<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">else</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">super</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
<p>Being that we use the metric system in AU, I reduce all units to their respective value in grams.</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c856e03d75db">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c856e03d75db').style.display='block';document.getElementById('plain_synthi_4c856e03d75db').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
10.kilograms
# => 10000
1.lb
# => 453.59237
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c856e03d75db">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c856e03d75db').style.display='block';document.getElementById('styled_synthi_4c856e03d75db').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="ruby" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006666;">10</span>.<span style="color:#9900CC;">kilograms</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># =&gt; 10000</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006666;">1</span>.<span style="color:#9900CC;">lb</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># =&gt; 453.59237 </span></div>
</li>
</ol>
</div>
</div>
<p>And here&#8217;s the payoff: the method_missing override lets you do neat conversion tricks like:</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c856e03d9cf7">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c856e03d9cf7').style.display='block';document.getElementById('plain_synthi_4c856e03d9cf7').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
1.kg.to_lbs
# => 2.20462262184878
0.3.tonne.to_kg
# => 300.0
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c856e03d9cf7">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c856e03d9cf7').style.display='block';document.getElementById('styled_synthi_4c856e03d9cf7').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="ruby" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006666;">1</span>.<span style="color:#9900CC;">kg</span>.<span style="color:#9900CC;">to_lbs</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># =&gt; 2.20462262184878</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006666;">0.3</span>.<span style="color:#9900CC;">tonne</span>.<span style="color:#9900CC;">to_kg</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># =&gt; 300.0 </span></div>
</li>
</ol>
</div>
</div>
<p>(<em>There is one caveat, I currently don&#8217;t check for the existence of the method given in <code>match[1]</code>, so it&#8217;s not exactly prime time code just yet&#8230;</em>)
</p>
<p><!--fcc99072141ec7132bcd9ec65c9a1209-->
</p>
<p><!--24de506b3736eac5d3dc38086f1a49a7-->
</p>
<p><!--7a2b85521487ec15d8327c27fc671fa1-->
</p>
<p><!--24de506b3736eac5d3dc38086f1a49a7-->
</p>
<p><!--fcc99072141ec7132bcd9ec65c9a1209--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2007/02/22/ruby-cheap-tricks-monkeypatching-unit-conversion/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Ruby Cheap Tricks &#8211; Stats</title>
		<link>http://warrenseen.com/blog/2007/02/22/ruby-cheap-tricks-stats/</link>
		<comments>http://warrenseen.com/blog/2007/02/22/ruby-cheap-tricks-stats/#comments</comments>
		<pubDate>Wed, 21 Feb 2007 22:32:01 +0000</pubDate>
		<dc:creator>warren</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[snippets]]></category>
		<category><![CDATA[statistics]]></category>

		<guid isPermaLink="false">http://warrenseen.com/blog/2007/02/22/ruby-cheap-tricks-stats/</guid>
		<description><![CDATA[For when it&#8217;s just as quick to roll your own &#8230;


 Ruby [Show Styled Code]:

# In each of these functions, data is just an array of numbers
# average
def avg(data)
  data.inject(0.0) { &#124;sum, i&#124; sum + i } / data.length
end

# median value
def median(data)
  data.sort!
  index = data.length / 2
  (data.length % 2 [...]]]></description>
			<content:encoded><![CDATA[<p>For when it&#8217;s just as quick to roll your own &#8230;<br />
<span id="more-39"></span></p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4c856e03f084b">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4c856e03f084b').style.display='block';document.getElementById('plain_synthi_4c856e03f084b').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
# In each of these functions, data is just an array of numbers
# average
def avg(data)
  data.inject(0.0) { |sum, i| sum + i } / data.length
end

# median value
def median(data)
  data.sort!
  index = data.length / 2
  (data.length % 2 == 0) ? data[index] : avg(data.values_at(index.floor, index.ceil))
end

# interquartile mean
def iqm(data)
  data.sort!
  first = (data.length/4).truncate
  last = 3 * first
  avg(data[first..last])
end
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4c856e03f084b">
<div class="synthi_header" style="font-weight:bold;"> Ruby <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4c856e03f084b').style.display='block';document.getElementById('styled_synthi_4c856e03f084b').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="ruby" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># In each of these functions, data is just an array of numbers</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># average</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> avg<span style="color:#006600; font-weight:bold;">&#40;</span>data<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; data.<span style="color:#9900CC;">inject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0.0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> |sum, i| sum + i <span style="color:#006600; font-weight:bold;">&#125;</span> / data.<span style="color:#9900CC;">length</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># median value</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> median<span style="color:#006600; font-weight:bold;">&#40;</span>data<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; data.<span style="color:#9900CC;">sort</span>!</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; index = data.<span style="color:#9900CC;">length</span> / <span style="color:#006666;">2</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span>data.<span style="color:#9900CC;">length</span> % <span style="color:#006666;">2</span> == <span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> ? data<span style="color:#006600; font-weight:bold;">&#91;</span>index<span style="color:#006600; font-weight:bold;">&#93;</span> : avg<span style="color:#006600; font-weight:bold;">&#40;</span>data.<span style="color:#9900CC;">values_at</span><span style="color:#006600; font-weight:bold;">&#40;</span>index.<span style="color:#9900CC;">floor</span>, index.<span style="color:#9900CC;">ceil</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#008000; font-style:italic;"># interquartile mean</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">def</span> iqm<span style="color:#006600; font-weight:bold;">&#40;</span>data<span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; data.<span style="color:#9900CC;">sort</span>!</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; first = <span style="color:#006600; font-weight:bold;">&#40;</span>data.<span style="color:#9900CC;">length</span>/<span style="color:#006666;">4</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">truncate</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; last = <span style="color:#006666;">3</span> * first</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; avg<span style="color:#006600; font-weight:bold;">&#40;</span>data<span style="color:#006600; font-weight:bold;">&#91;</span>first..<span style="color:#9900CC;">last</span><span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#9966CC; font-weight:bold;">end</span> </div>
</li>
</ol>
</div>
</div>
<p><!--1def8278666ed1e705338f87bf9b8486-->
</p>
<p><!--d0890cb21dbba288a190a998ec627c92-->
</p>
<p><!--1def8278666ed1e705338f87bf9b8486--></p>
]]></content:encoded>
			<wfw:commentRss>http://warrenseen.com/blog/2007/02/22/ruby-cheap-tricks-stats/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
