<?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>Eigenjoy &#187; ruby</title>
	<atom:link href="http://eigenjoy.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://eigenjoy.com</link>
	<description>a programming blog</description>
	<lastBuildDate>Wed, 14 Dec 2011 18:22:45 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>adding macruby to multiruby versions</title>
		<link>http://eigenjoy.com/2009/05/22/adding-macruby-to-multiruby-versions/</link>
		<comments>http://eigenjoy.com/2009/05/22/adding-macruby-to-multiruby-versions/#comments</comments>
		<pubDate>Fri, 22 May 2009 21:11:20 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2009/05/22/adding-macruby-to-multiruby-versions/</guid>
		<description><![CDATA[Modified from Rob Seaman&#8217;s post.
multiruby is a great way to make sure your ruby code runs on the multitude of ruby versions (it&#8217;s part of ZenTest). It doesn&#8217;t install macruby by default. Here are instructions on how to set it up.
Since I installed macruby from the package installer my macruby files are in /Library/Frameworks/MacRuby.framework/Versions/0.4/. If [...]]]></description>
			<content:encoded><![CDATA[<p>Modified from <a href="http://blog.robseaman.com/2008/12/21/adding-jruby-to-multiruby-versions">Rob Seaman&#8217;s post</a>.</p>
<p>multiruby is a great way to make sure your ruby code runs on the multitude of ruby versions (it&#8217;s part of ZenTest). It doesn&#8217;t install macruby by default. Here are instructions on how to set it up.</p>
<p>Since I installed macruby from the <a href="http://www.macruby.org/">package installer</a> my macruby files are in <code>/Library/Frameworks/MacRuby.framework/Versions/0.4/</code>. If your macruby files are somewhere else, adjust accordingly.</p>
<p>First make sure you already have multiruby setup for other versions (don&#8217;t proceed if this doesn&#8217;t work):<br />
<code><br />
multiruby_setup the_usual<br />
</code></p>
<p>One problem I had with the above command was that I had <code>RUBYOPT</code> set in my .profile. This was calling each of these ruby versions with <code>RUBYOPT=rubygems</code> when trying to install. This won&#8217;t work because rubygems is one of the things you&#8217;re trying to install. Make sure you unset this variable etc. before trying to setup multiruby.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">ln <span style="color:#006600; font-weight:bold;">-</span>s <span style="color:#006600; font-weight:bold;">/</span>Library<span style="color:#006600; font-weight:bold;">/</span>Frameworks<span style="color:#006600; font-weight:bold;">/</span>MacRuby.<span style="color:#9900CC;">framework</span><span style="color:#006600; font-weight:bold;">/</span>Versions<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006666;">0.4</span><span style="color:#006600; font-weight:bold;">/</span>usr ~<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">multiruby</span><span style="color:#006600; font-weight:bold;">/</span>install<span style="color:#006600; font-weight:bold;">/</span>macruby<span style="color:#006600; font-weight:bold;">-</span>0.0.4
sudo ln <span style="color:#006600; font-weight:bold;">-</span>s ~<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">multiruby</span><span style="color:#006600; font-weight:bold;">/</span>install<span style="color:#006600; font-weight:bold;">/</span>macruby<span style="color:#006600; font-weight:bold;">-</span>0.0.4<span style="color:#006600; font-weight:bold;">/</span>bin<span style="color:#006600; font-weight:bold;">/</span>macruby ~<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">multiruby</span><span style="color:#006600; font-weight:bold;">/</span>install<span style="color:#006600; font-weight:bold;">/</span>macruby<span style="color:#006600; font-weight:bold;">-</span>0.0.4<span style="color:#006600; font-weight:bold;">/</span>bin<span style="color:#006600; font-weight:bold;">/</span>ruby
sudo ln <span style="color:#006600; font-weight:bold;">-</span>s ~<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">multiruby</span><span style="color:#006600; font-weight:bold;">/</span>install<span style="color:#006600; font-weight:bold;">/</span>macruby<span style="color:#006600; font-weight:bold;">-</span>0.0.4<span style="color:#006600; font-weight:bold;">/</span>bin<span style="color:#006600; font-weight:bold;">/</span>macgem ~<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">multiruby</span><span style="color:#006600; font-weight:bold;">/</span>install<span style="color:#006600; font-weight:bold;">/</span>macruby<span style="color:#006600; font-weight:bold;">-</span>0.0.4<span style="color:#006600; font-weight:bold;">/</span>bin<span style="color:#006600; font-weight:bold;">/</span>gem
touch ~<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">multiruby</span><span style="color:#006600; font-weight:bold;">/</span>versions<span style="color:#006600; font-weight:bold;">/</span>macruby<span style="color:#006600; font-weight:bold;">-</span>0.0.4.<span style="color:#9900CC;">tar</span>.<span style="color:#9900CC;">gz</span> <span style="color:#008000; font-style:italic;"># fake-out</span></pre></div></div>

<p>Now try:<br />
<code><br />
multiruby -e "p 1+1"<br />
</code></p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F22%2Fadding-macruby-to-multiruby-versions%2F&amp;title=adding%20macruby%20to%20multiruby%20versions&amp;notes=Modified%20from%20Rob%20Seaman%27s%20post.%0D%0A%0D%0Amultiruby%20is%20a%20great%20way%20to%20make%20sure%20your%20ruby%20code%20runs%20on%20the%20multitude%20of%20ruby%20versions%20%28it%27s%20part%20of%20ZenTest%29.%20It%20doesn%27t%20install%20macruby%20by%20default.%20Here%20are%20instructions%20on%20how%20to%20set%20it%20up.%0D%0A%0D%0ASince%20I%20insta" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F22%2Fadding-macruby-to-multiruby-versions%2F&amp;title=adding%20macruby%20to%20multiruby%20versions" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F22%2Fadding-macruby-to-multiruby-versions%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=adding%20macruby%20to%20multiruby%20versions%20-%20http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F22%2Fadding-macruby-to-multiruby-versions%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F22%2Fadding-macruby-to-multiruby-versions%2F&amp;t=adding%20macruby%20to%20multiruby%20versions" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F22%2Fadding-macruby-to-multiruby-versions%2F&amp;title=adding%20macruby%20to%20multiruby%20versions&amp;annotation=Modified%20from%20Rob%20Seaman%27s%20post.%0D%0A%0D%0Amultiruby%20is%20a%20great%20way%20to%20make%20sure%20your%20ruby%20code%20runs%20on%20the%20multitude%20of%20ruby%20versions%20%28it%27s%20part%20of%20ZenTest%29.%20It%20doesn%27t%20install%20macruby%20by%20default.%20Here%20are%20instructions%20on%20how%20to%20set%20it%20up.%0D%0A%0D%0ASince%20I%20insta" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F22%2Fadding-macruby-to-multiruby-versions%2F&amp;t=adding%20macruby%20to%20multiruby%20versions" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F22%2Fadding-macruby-to-multiruby-versions%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2009/05/22/adding-macruby-to-multiruby-versions/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>tweet twitter util &#8211; cli feedback on tweet length</title>
		<link>http://eigenjoy.com/2009/05/21/tweet-twitter-util-cli-feedback-on-tweet-length/</link>
		<comments>http://eigenjoy.com/2009/05/21/tweet-twitter-util-cli-feedback-on-tweet-length/#comments</comments>
		<pubDate>Thu, 21 May 2009 15:01:21 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2009/05/21/tweet-twitter-util-cli-feedback-on-tweet-length/</guid>
		<description><![CDATA[One of the nice things about the Twitter web-interface is that it gives you feedback on the number of characters you&#8217;ve typed so far.

 Since I use the command-line twitter gem (by John Nunemaker) I miss out on this feature and find myself using echo and wc to make sure I&#8217;m not over the limit.
To [...]]]></description>
			<content:encoded><![CDATA[<p>One of the nice things about the Twitter web-interface is that it gives you feedback on the number of characters you&#8217;ve typed so far.<a href='http://www.xcombinator.com/wp-content/uploads/2009/05/twitter-warning.png' title='twitter-warning.png'><img src='http://www.xcombinator.com/wp-content/uploads/2009/05/twitter-warning.thumbnail.png' alt='twitter-warning.png' /></a>
</p>
<p> Since I use the command-line <a href="http://twitter.rubyforge.org/"><tt>twitter</tt> gem</a> (by John Nunemaker) I miss out on this feature and find myself using <tt>echo</tt> and <tt>wc</tt> to make sure I&#8217;m not over the limit.</p>
<p>To fix this problem, I&#8217;ve written a small, immediate-feedback utility called <tt>tweet</tt>. It shows you the number of characters typed so far and colorizes them accordingly.</p>
<p> Screenshots: </p>
<p>warning:<br />
<a href='http://www.xcombinator.com/wp-content/uploads/2009/05/tweet-warning.png' title='tweet-warning.png'><img src='http://www.xcombinator.com/wp-content/uploads/2009/05/tweet-warning.png' alt='tweet-warning.png' /></a>
</p>
<p>over:<br />
<a href='http://www.xcombinator.com/wp-content/uploads/2009/05/tweet-overage.png' title='tweet-overage.png'><img src='http://www.xcombinator.com/wp-content/uploads/2009/05/tweet-overage.png' alt='tweet-overage.png' /></a>
</p>
<p>
Just download this script and save it as <tt>tweet</tt> somewhere in your <tt>$PATH</tt><br />
<script src="http://gist.github.com/112317.js"></script>
</p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F21%2Ftweet-twitter-util-cli-feedback-on-tweet-length%2F&amp;title=tweet%20twitter%20util%20-%20cli%20feedback%20on%20tweet%20length&amp;notes=One%20of%20the%20nice%20things%20about%20the%20Twitter%20web-interface%20is%20that%20it%20gives%20you%20feedback%20on%20the%20number%20of%20characters%20you%27ve%20typed%20so%20far.%0D%0A%0D%0A%0D%0A%20Since%20I%20use%20the%20command-line%20twitter%20gem%20%28by%20John%20Nunemaker%29%20I%20miss%20out%20on%20this%20feature%20and%20find%20myself%20using%20" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F21%2Ftweet-twitter-util-cli-feedback-on-tweet-length%2F&amp;title=tweet%20twitter%20util%20-%20cli%20feedback%20on%20tweet%20length" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F21%2Ftweet-twitter-util-cli-feedback-on-tweet-length%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=tweet%20twitter%20util%20-%20cli%20feedback%20on%20tweet%20length%20-%20http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F21%2Ftweet-twitter-util-cli-feedback-on-tweet-length%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F21%2Ftweet-twitter-util-cli-feedback-on-tweet-length%2F&amp;t=tweet%20twitter%20util%20-%20cli%20feedback%20on%20tweet%20length" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F21%2Ftweet-twitter-util-cli-feedback-on-tweet-length%2F&amp;title=tweet%20twitter%20util%20-%20cli%20feedback%20on%20tweet%20length&amp;annotation=One%20of%20the%20nice%20things%20about%20the%20Twitter%20web-interface%20is%20that%20it%20gives%20you%20feedback%20on%20the%20number%20of%20characters%20you%27ve%20typed%20so%20far.%0D%0A%0D%0A%0D%0A%20Since%20I%20use%20the%20command-line%20twitter%20gem%20%28by%20John%20Nunemaker%29%20I%20miss%20out%20on%20this%20feature%20and%20find%20myself%20using%20" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F21%2Ftweet-twitter-util-cli-feedback-on-tweet-length%2F&amp;t=tweet%20twitter%20util%20-%20cli%20feedback%20on%20tweet%20length" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2009%2F05%2F21%2Ftweet-twitter-util-cli-feedback-on-tweet-length%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2009/05/21/tweet-twitter-util-cli-feedback-on-tweet-length/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>what does this return? or &#8216;why i love ruby&#8217;</title>
		<link>http://eigenjoy.com/2009/02/19/what-does-this-return-or-why-i-love-ruby/</link>
		<comments>http://eigenjoy.com/2009/02/19/what-does-this-return-or-why-i-love-ruby/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 17:18:51 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2009/02/19/what-does-this-return-or-why-i-love-ruby/</guid>
		<description><![CDATA[
def x
  5
end
&#160;
if false
  x = 3
end
&#160;
puts x # =&#62; ?

Share:
	
	
	
	
	
	
	
	
	

]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> x
  <span style="color:#006666;">5</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#0000FF; font-weight:bold;">false</span>
  x = <span style="color:#006666;">3</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> x <span style="color:#008000; font-style:italic;"># =&gt; ?</span></pre></div></div>

<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2009%2F02%2F19%2Fwhat-does-this-return-or-why-i-love-ruby%2F&amp;title=what%20does%20this%20return%3F%20or%20%27why%20i%20love%20ruby%27&amp;notes=%0D%0Adef%20x%0D%0A%20%205%0D%0Aend%0D%0A%0D%0Aif%20false%0D%0A%20%20x%20%3D%203%0D%0Aend%0D%0A%0D%0Aputs%20x%20%23%20%3D%3E%20%3F%0D%0A" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2009%2F02%2F19%2Fwhat-does-this-return-or-why-i-love-ruby%2F&amp;title=what%20does%20this%20return%3F%20or%20%27why%20i%20love%20ruby%27" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2009%2F02%2F19%2Fwhat-does-this-return-or-why-i-love-ruby%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=what%20does%20this%20return%3F%20or%20%27why%20i%20love%20ruby%27%20-%20http%3A%2F%2Feigenjoy.com%2F2009%2F02%2F19%2Fwhat-does-this-return-or-why-i-love-ruby%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2009%2F02%2F19%2Fwhat-does-this-return-or-why-i-love-ruby%2F&amp;t=what%20does%20this%20return%3F%20or%20%27why%20i%20love%20ruby%27" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2009%2F02%2F19%2Fwhat-does-this-return-or-why-i-love-ruby%2F&amp;title=what%20does%20this%20return%3F%20or%20%27why%20i%20love%20ruby%27&amp;annotation=%0D%0Adef%20x%0D%0A%20%205%0D%0Aend%0D%0A%0D%0Aif%20false%0D%0A%20%20x%20%3D%203%0D%0Aend%0D%0A%0D%0Aputs%20x%20%23%20%3D%3E%20%3F%0D%0A" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2009%2F02%2F19%2Fwhat-does-this-return-or-why-i-love-ruby%2F&amp;t=what%20does%20this%20return%3F%20or%20%27why%20i%20love%20ruby%27" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2009%2F02%2F19%2Fwhat-does-this-return-or-why-i-love-ruby%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2009/02/19/what-does-this-return-or-why-i-love-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why Do Cells Have DNA?</title>
		<link>http://eigenjoy.com/2008/11/01/why-do-cells-have-dna/</link>
		<comments>http://eigenjoy.com/2008/11/01/why-do-cells-have-dna/#comments</comments>
		<pubDate>Sat, 01 Nov 2008 23:16:52 +0000</pubDate>
		<dc:creator>Matt Pulver</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[bach]]></category>
		<category><![CDATA[dna]]></category>
		<category><![CDATA[escher]]></category>
		<category><![CDATA[godel]]></category>
		<category><![CDATA[self-replicating code]]></category>
		<category><![CDATA[self-replication]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/11/01/why-do-cells-have-dna/</guid>
		<description><![CDATA[In order for a system to reproduce itself, it seems necessary for it to hold an encoded form of itself somehow. This idea, and the inevitability of the existence of DNA-like structures within living cells, is well-illustrated using computer code.

We start with the problem: Write a ruby script that can print itself out, without it [...]]]></description>
			<content:encoded><![CDATA[<p>In order for a system to reproduce itself, it seems necessary for it to hold an encoded form of itself somehow. This idea, and the inevitability of the existence of DNA-like structures within living cells, is well-illustrated using computer code.</p>
<p><span id="more-85"></span></p>
<p>We start with the problem: <strong>Write a ruby script that can print itself out, without it reading its own file.</strong></p>
<p>The restriction &#8220;without it reading its own file&#8221; is important, otherwise a trivial solution would be:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#0000FF; font-weight:bold;">__FILE__</span> <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Without thinking about it too much and just starting naively, we may try:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;#!/usr/bin/env ruby<span style="color:#000099;">\n</span><span style="color:#000099;">\n</span>puts <span style="color:#000099;">\&quot;</span>#!/usr/bin/env ruby<span style="color:#000099;">\\</span>n<span style="color:#000099;">\\</span>nputs <span style="color:#000099;">\\</span><span style="color:#000099;">\&quot;</span>#!/usr/bin/env ruby ...</span></pre></div></div>

<p>We soon find ourselves entering into an infinite regress that we quickly realize has no escape. Seems we have to be a little bit more clever.</p>
<p>Before getting to the solution, the interested reader is urged to stop reading at this point and try to come up with a solution independently.</p>
<p>Here&#8217;s one way to accomplish this. Create the following script, which is just the first step toward the final script:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'cgi'</span>
&nbsp;
dna = <span style="color:#996600;">'DNA'</span>
cell = <span style="color:#CC00FF; font-weight:bold;">CGI</span>.<span style="color:#9900CC;">unescape</span> dna
<span style="color:#CC0066; font-weight:bold;">puts</span> cell.<span style="color:#CC0066; font-weight:bold;">sub</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'DNA'</span>, dna <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Save the above file as &#8220;pregodel.rb&#8221;. Next create this helper script:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'cgi'</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC00FF; font-weight:bold;">CGI</span>.<span style="color:#9900CC;">escape</span><span style="color:#006600; font-weight:bold;">&#40;</span> STDIN.<span style="color:#9900CC;">read</span> <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Save this as &#8220;godelize.rb&#8221;, and run it taking pregodel.rb into STDIN:</p>
<p><code>$ ruby godelize.rb < pregodel.rb</code></p>
<p>This outputs a cgi-encoded string whose initial characters are '%23%21%2Fusr%2Fbin%2Fenv ...'. Finally, copy pregodel.rb to godel.rb and edit godel.rb. Replace the first instance of DNA with the output of godelize.rb, and save it.</p>
<p>godel.rb should now be:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;">#!/usr/bin/env ruby</span>
&nbsp;
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'cgi'</span>
&nbsp;
dna = <span style="color:#996600;">'%23%21%2Fusr%2Fbin%2Fenv+ruby%0A%0Arequire+%27cgi%27%0A%0Adna+%3D+%27DNA%27%0Acell+%3D+CGI.unescape+dna%0Aputs+cell.sub%28+%27DNA%27%2C+dna+%29%0A'</span>
cell = <span style="color:#CC00FF; font-weight:bold;">CGI</span>.<span style="color:#9900CC;">unescape</span> dna
<span style="color:#CC0066; font-weight:bold;">puts</span> cell.<span style="color:#CC0066; font-weight:bold;">sub</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'DNA'</span>, dna <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>When run, the output is identical to the file contents. A conclusive test is comparing md5 sums:</p>
<p><code>$ cat godel.rb | md5<br />
4b92a6303568cde3a98d042a67616d2d</code></p>
<p><code>$ ruby godel.rb | md5<br />
4b92a6303568cde3a98d042a67616d2d</code></p>
<p>(This was run on a Mac&mdash;many linux distros have md5sum instead.)</p>
<h4>Discussion</h4>
<p>So what does this have to do with DNA in cells? The godel.rb script is about as simple of a self-replicating ruby script that one can write (again, without invoking the file itself). Its function and structure is surprisingly similar to how a biological cell works.  The entire script is stored in the dna variable as a cgi-encoded string, just as a cell is encoded in its nucleus with deoxyribonucleic acid:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">dna = <span style="color:#996600;">'%23%21%2Fusr%2Fbin%2Fenv+ruby%0A%0Arequire+%27cgi%27%0A%0Adna+%3D+%27DNA%27%0Acell+%3D+CGI.unescape+dna%0Aputs+cell.sub%28+%27DNA%27%2C+dna+%29%0A'</span></pre></div></div>

<p>The first step in the script's self-replication process is to unescape itself from a cgi-encoded string to ruby code. This is analogous to a cell's ribosomes performing its role in translating DNA into protein. (The intermediate step of RNA transcription is omitted for simplicity without loss of accuracy.) Protein is encoded as sequences of nucleic acids in DNA, just as ruby code is encoded into cgi-encoded character sequences.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">cell = <span style="color:#CC00FF; font-weight:bold;">CGI</span>.<span style="color:#9900CC;">unescape</span> dna</pre></div></div>

<p>Finally, a cell's DNA must make a copy of itself during mitosis and insert it into the cell's copy. The analog of this is the last line of the script:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">puts</span> cell.<span style="color:#CC0066; font-weight:bold;">sub</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">'DNA'</span>, dna <span style="color:#006600; font-weight:bold;">&#41;</span></pre></div></div>

<p>Though the dna string has a representation of the whole script, observe how it was able to avoid the infinite regress. The place in the string that references itself, rather than storing itself again (which would lead to an infinitely long string) it instead uses a symbol for itself, namely, DNA. This acts as a placeholder for where the dna variable will be substituted into when the string is printed out.</p>
<p>For further reading, check out the book <em>G&#246;del, Escher, Bach</em> by Douglas Hofstadter, which applies the above ideas to not only self-replicating cells, but to the nature of mathematical truth, the art of Escher, the music of Bach, and human consciousness, among other related topics.</p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2008%2F11%2F01%2Fwhy-do-cells-have-dna%2F&amp;title=Why%20Do%20Cells%20Have%20DNA%3F&amp;notes=In%20order%20for%20a%20system%20to%20reproduce%20itself%2C%20it%20seems%20necessary%20for%20it%20to%20hold%20an%20encoded%20form%20of%20itself%20somehow.%20This%20idea%2C%20and%20the%20inevitability%20of%20the%20existence%20of%20DNA-like%20structures%20within%20living%20cells%2C%20is%20well-illustrated%20using%20computer%20code.%0D%0A%0D%0A" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2008%2F11%2F01%2Fwhy-do-cells-have-dna%2F&amp;title=Why%20Do%20Cells%20Have%20DNA%3F" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2008%2F11%2F01%2Fwhy-do-cells-have-dna%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=Why%20Do%20Cells%20Have%20DNA%3F%20-%20http%3A%2F%2Feigenjoy.com%2F2008%2F11%2F01%2Fwhy-do-cells-have-dna%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2008%2F11%2F01%2Fwhy-do-cells-have-dna%2F&amp;t=Why%20Do%20Cells%20Have%20DNA%3F" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2008%2F11%2F01%2Fwhy-do-cells-have-dna%2F&amp;title=Why%20Do%20Cells%20Have%20DNA%3F&amp;annotation=In%20order%20for%20a%20system%20to%20reproduce%20itself%2C%20it%20seems%20necessary%20for%20it%20to%20hold%20an%20encoded%20form%20of%20itself%20somehow.%20This%20idea%2C%20and%20the%20inevitability%20of%20the%20existence%20of%20DNA-like%20structures%20within%20living%20cells%2C%20is%20well-illustrated%20using%20computer%20code.%0D%0A%0D%0A" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2008%2F11%2F01%2Fwhy-do-cells-have-dna%2F&amp;t=Why%20Do%20Cells%20Have%20DNA%3F" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2008%2F11%2F01%2Fwhy-do-cells-have-dna%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2008/11/01/why-do-cells-have-dna/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>run multiple rake tasks simultaneously</title>
		<link>http://eigenjoy.com/2008/10/22/run-multiple-rake-tasks-simultaneously/</link>
		<comments>http://eigenjoy.com/2008/10/22/run-multiple-rake-tasks-simultaneously/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 17:33:22 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/10/22/run-multiple-rake-tasks-simultaneously/</guid>
		<description><![CDATA[Here&#8217;s a quick and simple tip for using threads and Rakefiles:

task :one do
  puts &#34;start one&#34;
  sleep 10 * rand
  puts &#34;one done&#34;
end
&#160;
task :two do
  puts &#34;start two&#34;
  sleep 10 * rand
  puts &#34;two done&#34;
end
&#160;
task :three do
  puts &#34;start three&#34;
  sleep 10 * rand
  puts &#34;three [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick and simple tip for using threads and Rakefiles:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">task <span style="color:#ff3333; font-weight:bold;">:one</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;start one&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">10</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#CC0066; font-weight:bold;">rand</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;one done&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
task <span style="color:#ff3333; font-weight:bold;">:two</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;start two&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">10</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#CC0066; font-weight:bold;">rand</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;two done&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
task <span style="color:#ff3333; font-weight:bold;">:three</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;start three&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006666;">10</span> <span style="color:#006600; font-weight:bold;">*</span> <span style="color:#CC0066; font-weight:bold;">rand</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;three done&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
desc <span style="color:#996600;">&quot;Submit all feed to amazon for SITE&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:do_all</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  threads = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>one two three<span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>number<span style="color:#006600; font-weight:bold;">|</span>
    threads <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>number<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>my_number<span style="color:#006600; font-weight:bold;">|</span>
      <span style="color:#6666ff; font-weight:bold;">Rake::Task</span><span style="color:#006600; font-weight:bold;">&#91;</span>my_number<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">invoke</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
  threads.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>thread<span style="color:#006600; font-weight:bold;">|</span> thread.<span style="color:#9900CC;">join</span> <span style="color:#006600; font-weight:bold;">&#125;</span> 
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Running it gives something like the following:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">$ rake do_all
start one
start two
start three
three done
one done
two done</pre></div></div>

<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2008%2F10%2F22%2Frun-multiple-rake-tasks-simultaneously%2F&amp;title=run%20multiple%20rake%20tasks%20simultaneously&amp;notes=Here%27s%20a%20quick%20and%20simple%20tip%20for%20using%20threads%20and%20Rakefiles%3A%0D%0A%0D%0A%0D%0Atask%20%3Aone%20do%0D%0A%20%20puts%20%22start%20one%22%0D%0A%20%20sleep%2010%20%2A%20rand%0D%0A%20%20puts%20%22one%20done%22%0D%0Aend%0D%0A%0D%0Atask%20%3Atwo%20do%0D%0A%20%20puts%20%22start%20two%22%0D%0A%20%20sleep%2010%20%2A%20rand%0D%0A%20%20puts%20%22two%20done%22%0D%0Aend%0D%0A%0D%0Atask%20%3Athree%20do%0D%0A%20%20puts%20%22" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2008%2F10%2F22%2Frun-multiple-rake-tasks-simultaneously%2F&amp;title=run%20multiple%20rake%20tasks%20simultaneously" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2008%2F10%2F22%2Frun-multiple-rake-tasks-simultaneously%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=run%20multiple%20rake%20tasks%20simultaneously%20-%20http%3A%2F%2Feigenjoy.com%2F2008%2F10%2F22%2Frun-multiple-rake-tasks-simultaneously%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2008%2F10%2F22%2Frun-multiple-rake-tasks-simultaneously%2F&amp;t=run%20multiple%20rake%20tasks%20simultaneously" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2008%2F10%2F22%2Frun-multiple-rake-tasks-simultaneously%2F&amp;title=run%20multiple%20rake%20tasks%20simultaneously&amp;annotation=Here%27s%20a%20quick%20and%20simple%20tip%20for%20using%20threads%20and%20Rakefiles%3A%0D%0A%0D%0A%0D%0Atask%20%3Aone%20do%0D%0A%20%20puts%20%22start%20one%22%0D%0A%20%20sleep%2010%20%2A%20rand%0D%0A%20%20puts%20%22one%20done%22%0D%0Aend%0D%0A%0D%0Atask%20%3Atwo%20do%0D%0A%20%20puts%20%22start%20two%22%0D%0A%20%20sleep%2010%20%2A%20rand%0D%0A%20%20puts%20%22two%20done%22%0D%0Aend%0D%0A%0D%0Atask%20%3Athree%20do%0D%0A%20%20puts%20%22" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2008%2F10%2F22%2Frun-multiple-rake-tasks-simultaneously%2F&amp;t=run%20multiple%20rake%20tasks%20simultaneously" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2008%2F10%2F22%2Frun-multiple-rake-tasks-simultaneously%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2008/10/22/run-multiple-rake-tasks-simultaneously/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Slides from Apriori.rb LA Ruby Presentation</title>
		<link>http://eigenjoy.com/2008/09/19/slides-from-apriorirb-la-ruby-presentation/</link>
		<comments>http://eigenjoy.com/2008/09/19/slides-from-apriorirb-la-ruby-presentation/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 18:38:35 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[gems]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/09/19/slides-from-apriorirb-la-ruby-presentation/</guid>
		<description><![CDATA[Last night I gave a talk on my new gem Apriori.rb at the LA Ruby Meetup. Here are the slides from that presentation. Coby Randquist from Confreaks recorded the talk on his MacBookPro. I&#8217;ll see if I can get a copy and post it up here in the next couple of weeks. 
Apriori.rb &#8211; LA [...]]]></description>
			<content:encoded><![CDATA[<p>Last night I gave a talk on my new gem <a href="http://apriori.rubyforge.org/">Apriori.rb</a> at the <a href="http://laxrb.tumblr.com/">LA Ruby Meetup</a>. Here are the slides from that presentation. Coby Randquist from <a href="http://www.confreaks.com/">Confreaks</a> recorded the talk on his MacBookPro. I&#8217;ll see if I can get a copy and post it up here in the next couple of weeks. </p>
<div style="width:425px;text-align:left" id="__ss_607675"><a style="font:14px Helvetica,Arial,Sans-serif;display:block;margin:12px 0 3px 0;text-decoration:underline;" href="http://www.slideshare.net/jashmenn/apriorirb-la-ruby-presentation-presentation?type=powerpoint" title="Apriori.rb - LA Ruby Presentation">Apriori.rb &#8211; LA Ruby Presentation</a><object style="margin:0px" width="425" height="355"><param name="movie" value="http://static.slideshare.net/swf/ssplayer2.swf?doc=larubypresentation-1221844679651939-8&#038;stripped_title=apriorirb-la-ruby-presentation-presentation" /><param name="allowFullScreen" value="true"/><param name="allowScriptAccess" value="always"/><embed src="http://static.slideshare.net/swf/ssplayer2.swf?doc=larubypresentation-1221844679651939-8&#038;stripped_title=apriorirb-la-ruby-presentation-presentation" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="355"></embed></object></p>
<div style="font-size:11px;font-family:tahoma,arial;height:26px;padding-top:2px;">View SlideShare <a style="text-decoration:underline;" href="http://www.slideshare.net/jashmenn/apriorirb-la-ruby-presentation-presentation?type=powerpoint" title="View Apriori.rb - LA Ruby Presentation on SlideShare">presentation</a> or <a style="text-decoration:underline;" href="http://www.slideshare.net/upload?type=powerpoint">Upload</a> your own. (tags: <a style="text-decoration:underline;" href="http://slideshare.net/tag/apriori">apriori</a> <a style="text-decoration:underline;" href="http://slideshare.net/tag/algorithm">algorithm</a>)</div>
</div>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fslides-from-apriorirb-la-ruby-presentation%2F&amp;title=Slides%20from%20Apriori.rb%20LA%20Ruby%20Presentation&amp;notes=Last%20night%20I%20gave%20a%20talk%20on%20my%20new%20gem%20Apriori.rb%20at%20the%20LA%20Ruby%20Meetup.%20Here%20are%20the%20slides%20from%20that%20presentation.%20Coby%20Randquist%20from%20Confreaks%20recorded%20the%20talk%20on%20his%20MacBookPro.%20I%27ll%20see%20if%20I%20can%20get%20a%20copy%20and%20post%20it%20up%20here%20in%20the%20next%20coupl" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fslides-from-apriorirb-la-ruby-presentation%2F&amp;title=Slides%20from%20Apriori.rb%20LA%20Ruby%20Presentation" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fslides-from-apriorirb-la-ruby-presentation%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=Slides%20from%20Apriori.rb%20LA%20Ruby%20Presentation%20-%20http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fslides-from-apriorirb-la-ruby-presentation%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fslides-from-apriorirb-la-ruby-presentation%2F&amp;t=Slides%20from%20Apriori.rb%20LA%20Ruby%20Presentation" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fslides-from-apriorirb-la-ruby-presentation%2F&amp;title=Slides%20from%20Apriori.rb%20LA%20Ruby%20Presentation&amp;annotation=Last%20night%20I%20gave%20a%20talk%20on%20my%20new%20gem%20Apriori.rb%20at%20the%20LA%20Ruby%20Meetup.%20Here%20are%20the%20slides%20from%20that%20presentation.%20Coby%20Randquist%20from%20Confreaks%20recorded%20the%20talk%20on%20his%20MacBookPro.%20I%27ll%20see%20if%20I%20can%20get%20a%20copy%20and%20post%20it%20up%20here%20in%20the%20next%20coupl" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fslides-from-apriorirb-la-ruby-presentation%2F&amp;t=Slides%20from%20Apriori.rb%20LA%20Ruby%20Presentation" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fslides-from-apriorirb-la-ruby-presentation%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2008/09/19/slides-from-apriorirb-la-ruby-presentation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Apriori.rb &#8211; a gem to find regularities in buying behavior (frequent itemsets)</title>
		<link>http://eigenjoy.com/2008/09/19/apriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets/</link>
		<comments>http://eigenjoy.com/2008/09/19/apriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 18:31:52 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[gems]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/09/19/apriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets/</guid>
		<description><![CDATA[What it is
Apriori.rb is a library to efficiently find item association rules within large sets of transactions. The goal is to find regularities in buying behavior. This library provides a thin ruby wrapper around Christian Borgelt&#8217;s C implementation of this algorithm.
Why use it?
Finding items that are frequently purchased together can be very useful in learning [...]]]></description>
			<content:encoded><![CDATA[<h2>What it is</h2>
<p><a href="http://apriori.rubyforge.org/">Apriori.rb</a> is a library to efficiently find item <em>association rules</em> within large sets of transactions. The goal is to find <b>regularities in buying behavior</b>. This library provides a thin ruby wrapper around <a href="http://www.borgelt.net/apriori.html">Christian Borgelt&#8217;s C implementation</a> of this algorithm.</p>
<h2>Why use it?</h2>
<p>Finding items that are frequently purchased together can be very useful in learning how to position products in your store or website. If you find that customers who buy product <tt>a</tt> also buy product <tt>b</tt> then you know to put <tt>a</tt> and <tt>b</tt> close together, thus increasing revenue. </p>
<p>An <em>association rule</em> is something like:</p>
<blockquote><p>
If a customer buys wine he buys cheese too.
</p>
</blockquote>
<h2>How to use it</h2>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'apriori'</span>
&nbsp;
  transactions = <span style="color:#006600; font-weight:bold;">&#91;</span>  <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>beer doritos<span style="color:#006600; font-weight:bold;">&#125;</span>,
                    <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>apple cheese<span style="color:#006600; font-weight:bold;">&#125;</span>, 
                    <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>beer doritos<span style="color:#006600; font-weight:bold;">&#125;</span>, 
                    <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>apple cheese<span style="color:#006600; font-weight:bold;">&#125;</span>, 
                    <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>apple cheese<span style="color:#006600; font-weight:bold;">&#125;</span>, 
                    <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span>apple doritos<span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
  rules = Apriori.<span style="color:#9900CC;">find_association_rules</span><span style="color:#006600; font-weight:bold;">&#40;</span>transactions,
                            <span style="color:#ff3333; font-weight:bold;">:min_items</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">2</span>,
                            <span style="color:#ff3333; font-weight:bold;">:max_items</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">5</span>,
                            <span style="color:#ff3333; font-weight:bold;">:min_support</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">1</span>, 
                            <span style="color:#ff3333; font-weight:bold;">:max_support</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">100</span>, 
                            <span style="color:#ff3333; font-weight:bold;">:min_confidence</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">20</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#CC0066; font-weight:bold;">puts</span> rules.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;<span style="color:#000099;">\n</span>&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Results: </span>
  <span style="color:#008000; font-style:italic;"># beer -&gt; doritos (33.3/2, 100.0)</span>
  <span style="color:#008000; font-style:italic;"># doritos -&gt; beer (50.0/3, 66.7)</span>
  <span style="color:#008000; font-style:italic;"># doritos -&gt; apple (50.0/3, 33.3)</span>
  <span style="color:#008000; font-style:italic;"># apple -&gt; doritos (66.7/4, 25.0)</span>
  <span style="color:#008000; font-style:italic;"># cheese -&gt; apple (50.0/3, 100.0)</span>
  <span style="color:#008000; font-style:italic;"># apple -&gt; cheese (66.7/4, 75.0)</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># NOTE:</span>
  <span style="color:#008000; font-style:italic;"># beer -&gt; doritos (33.3/2, 100.0)</span>
  <span style="color:#008000; font-style:italic;"># means: </span>
  <span style="color:#008000; font-style:italic;"># * beer appears in 33.3% (2 total) of the transactions (the support)</span>
  <span style="color:#008000; font-style:italic;"># * beer implies doritos 100% of the time (the confidence)</span></pre></div></div>

<p>More information and code samples available in the <a href="http://apriori.rubyforge.org/">documentation</a> (<a href="http://apriori.rubyforge.org/rdoc/">rdoc</a>).</p>
<h2>How to get it</h2>
<p>Install the gem:<br />
<code><br />
  gem install apriori<br />
</code><br />
Get the source:<br />
<code><br />
git clone git://github.com/jashmenn/apriori.git<br />
</code><br />
Or <a href="http://github.com/jashmenn/apriori/tree/master">view the source on github</a>.</p>
<h2>requirements</h2>
<p>requires rubygems >= 1.2.0 . This is a requirement that hopefully will be changed in the future. But for now, know that if you don&#8217;t have rubygems >= 1.2.0 it will fail silently on the install. To update your rubygems version do:</p>
<p><code><br />
  gem update --system<br />
</code></p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fapriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets%2F&amp;title=Apriori.rb%20-%20a%20gem%20to%20find%20regularities%20in%20buying%20behavior%20%28frequent%20itemsets%29&amp;notes=What%20it%20is%0D%0AApriori.rb%20is%20a%20library%20to%20efficiently%20find%20item%20association%20rules%20within%20large%20sets%20of%20transactions.%20The%20goal%20is%20to%20find%20regularities%20in%20buying%20behavior.%20This%20library%20provides%20a%20thin%20ruby%20wrapper%20around%20Christian%20Borgelt%27s%20C%20implementati" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fapriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets%2F&amp;title=Apriori.rb%20-%20a%20gem%20to%20find%20regularities%20in%20buying%20behavior%20%28frequent%20itemsets%29" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fapriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=Apriori.rb%20-%20a%20gem%20to%20find%20regularities%20in%20buying%20behavior%20%28frequent%20itemsets%29%20-%20http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fapriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fapriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets%2F&amp;t=Apriori.rb%20-%20a%20gem%20to%20find%20regularities%20in%20buying%20behavior%20%28frequent%20itemsets%29" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fapriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets%2F&amp;title=Apriori.rb%20-%20a%20gem%20to%20find%20regularities%20in%20buying%20behavior%20%28frequent%20itemsets%29&amp;annotation=What%20it%20is%0D%0AApriori.rb%20is%20a%20library%20to%20efficiently%20find%20item%20association%20rules%20within%20large%20sets%20of%20transactions.%20The%20goal%20is%20to%20find%20regularities%20in%20buying%20behavior.%20This%20library%20provides%20a%20thin%20ruby%20wrapper%20around%20Christian%20Borgelt%27s%20C%20implementati" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fapriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets%2F&amp;t=Apriori.rb%20-%20a%20gem%20to%20find%20regularities%20in%20buying%20behavior%20%28frequent%20itemsets%29" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2008%2F09%2F19%2Fapriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2008/09/19/apriorirb-a-gem-to-find-regularities-in-buying-behavior-frequent-itemsets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>String interpolation is faster than printf in Ruby</title>
		<link>http://eigenjoy.com/2008/08/13/string-interpolation-is-faster-than-printf-in-ruby/</link>
		<comments>http://eigenjoy.com/2008/08/13/string-interpolation-is-faster-than-printf-in-ruby/#comments</comments>
		<pubDate>Wed, 13 Aug 2008 14:05:15 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/08/13/string-interpolation-is-faster-than-printf-in-ruby/</guid>
		<description><![CDATA[Just wanted to make a note, string interpolation is faster than printf in Ruby. Example:

$ irb
&#62;&#62; require 'benchmark'
=&#62; true
&#62;&#62; Benchmark.measure &#123; 100000.times &#123;
  &#34;%s&#34; % &#91;&#34;hello world&#34;&#93; &#125; &#125;.total
=&#62; 0.21
&#62;&#62; Benchmark.measure &#123; 100000.times &#123;
  &#34;#{'hello world'}&#34;&#125; &#125;.total
=&#62; 0.04

Share:
	
	
	
	
	
	
	
	
	

]]></description>
			<content:encoded><![CDATA[<p>Just wanted to make a note, string interpolation is faster than printf in Ruby. Example:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">$ irb
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'benchmark'</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Benchmark</span>.<span style="color:#9900CC;">measure</span> <span style="color:#006600; font-weight:bold;">&#123;</span> 100000.<span style="color:#9900CC;">times</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#996600;">&quot;%s&quot;</span> <span style="color:#006600; font-weight:bold;">%</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;hello world&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">total</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0.21</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Benchmark</span>.<span style="color:#9900CC;">measure</span> <span style="color:#006600; font-weight:bold;">&#123;</span> 100000.<span style="color:#9900CC;">times</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
  <span style="color:#996600;">&quot;#{'hello world'}&quot;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">total</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">0.04</span></pre></div></div>

<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2008%2F08%2F13%2Fstring-interpolation-is-faster-than-printf-in-ruby%2F&amp;title=String%20interpolation%20is%20faster%20than%20printf%20in%20Ruby&amp;notes=Just%20wanted%20to%20make%20a%20note%2C%20string%20interpolation%20is%20faster%20than%20printf%20in%20Ruby.%20Example%3A%0D%0A%0D%0A%0D%0A%24%20irb%0D%0A%3E%3E%20require%20%27benchmark%27%0D%0A%3D%3E%20true%0D%0A%3E%3E%20Benchmark.measure%20%7B%20100000.times%20%7B%0D%0A%20%20%22%25s%22%20%25%20%5B%22hello%20world%22%5D%20%7D%20%7D.total%0D%0A%3D%3E%200.21%0D%0A%3E%3E%20Benchmark.measure%20%7B%20100000.ti" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2008%2F08%2F13%2Fstring-interpolation-is-faster-than-printf-in-ruby%2F&amp;title=String%20interpolation%20is%20faster%20than%20printf%20in%20Ruby" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2008%2F08%2F13%2Fstring-interpolation-is-faster-than-printf-in-ruby%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=String%20interpolation%20is%20faster%20than%20printf%20in%20Ruby%20-%20http%3A%2F%2Feigenjoy.com%2F2008%2F08%2F13%2Fstring-interpolation-is-faster-than-printf-in-ruby%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2008%2F08%2F13%2Fstring-interpolation-is-faster-than-printf-in-ruby%2F&amp;t=String%20interpolation%20is%20faster%20than%20printf%20in%20Ruby" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2008%2F08%2F13%2Fstring-interpolation-is-faster-than-printf-in-ruby%2F&amp;title=String%20interpolation%20is%20faster%20than%20printf%20in%20Ruby&amp;annotation=Just%20wanted%20to%20make%20a%20note%2C%20string%20interpolation%20is%20faster%20than%20printf%20in%20Ruby.%20Example%3A%0D%0A%0D%0A%0D%0A%24%20irb%0D%0A%3E%3E%20require%20%27benchmark%27%0D%0A%3D%3E%20true%0D%0A%3E%3E%20Benchmark.measure%20%7B%20100000.times%20%7B%0D%0A%20%20%22%25s%22%20%25%20%5B%22hello%20world%22%5D%20%7D%20%7D.total%0D%0A%3D%3E%200.21%0D%0A%3E%3E%20Benchmark.measure%20%7B%20100000.ti" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2008%2F08%2F13%2Fstring-interpolation-is-faster-than-printf-in-ruby%2F&amp;t=String%20interpolation%20is%20faster%20than%20printf%20in%20Ruby" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2008%2F08%2F13%2Fstring-interpolation-is-faster-than-printf-in-ruby%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2008/08/13/string-interpolation-is-faster-than-printf-in-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RailsConf08: Passenger or mod_rails RIP</title>
		<link>http://eigenjoy.com/2008/06/02/railsconf08-passenger-or-mod_rails-rip/</link>
		<comments>http://eigenjoy.com/2008/06/02/railsconf08-passenger-or-mod_rails-rip/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 22:43:25 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[railsconf08]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/06/02/railsconf08-passenger-or-mod_rails-rip/</guid>
		<description><![CDATA[There was no lack of hubris on the stage today as the guys from Phusion talked about their new Apache extension Passenger. If Passenger lives up to its claims it seems that it could quickly become the de-facto standard for deploying Rails (and more) applications.
The 19 22-year-old duo was obviously ecstatic about sharing about what [...]]]></description>
			<content:encoded><![CDATA[<p>There was no lack of hubris on the stage today as the guys from <a href="http://www.modrails.com/">Phusion</a> talked about their new Apache extension <b>Passenger</b>. If Passenger lives up to its claims it seems that it could quickly become the de-facto standard for deploying Rails (and more) applications.</p>
<p>The <strike>19</strike> 22-year-old duo was obviously ecstatic about sharing about what they created but I kept getting the feeling that they were surprised that the crowd didn&#8217;t give them a presidential-state-of-the-union-like standing-ovation every few minutes. (If passenger does what they claim maybe they deserve it but respect and appreciation often lose something when they are too eagerly expected.)</p>
<p>So what was it that they claimed? That passenger will not only make Rails deployment dead-simple (think PHP, upload and go) but also crank out better performance while using less memory. It&#8217;s a worthy goal and as <a href="http://en.wikipedia.org/wiki/Kent_Beck">Kent Beck</a> said in our keynote, &#8220;Humility is not a prerequisite to ideas with impact&#8221;. I&#8217;d like to write up a bit about Passenger and the session they presented at RailsConf. You can download the Keynote slides <a href="http://en.oreilly.com/rails2008/public/asset/attachment/2643">here</a> [zip] (I&#8217;m sure the PDF will appear somewhere soon. If you find it, please feel free to leave a URL in the comments).</p>
<h3>Memory Usage and Clustering</h3>
<p><b>Memory Usage</b></p>
<p>First lets talk about memory usage. When you&#8217;re using Mongrel each Mongrel process holds both a full copy of the Rails and application code in memory plus the private memory for the individual process. In this model of N Mongrel processes you have N copies of the application code. With Passenger, each process shares one copy of your Rails/application code. Each process still gets its own chunk of private memory but the shared code greatly reduces the overall memory usage.</p>
<p>The Phusion guys also patched Ruby (and they&#8217;ve horribly named it &#8220;Ruby Enterprise Edition&#8221;). This version has modified garbage collection and causes Ruby to use significantly less memory. They achieve this by doing <a href="http://en.wikipedia.org/wiki/Copy-on-write">copy-on-write</a> for memory management. This hasn&#8217;t been released so no word yet on how well it works or how stable it is.</p>
<p><b>Clustering</b></p>
<p>Another nice feature is that with clustering they use &#8220;fair load balancing&#8221;. The idea is that you keep track of how many jobs each process in the cluster has and you give the next job to the process with the least amount of work to do.</p>
<h3>Competitor Comparison</h3>
<p>They compared Passenger&#8217;s performance (as an Apache extension) to many competing products (including Nginx and Mongrel) and claimed that it used significantly less memory and was much faster. I won&#8217;t repeat all the statistics, you can check out the slides.</p>
<h3>mod_rails, RIP</h3>
<p>Although they had greatly simplified deployment for Rails they didn&#8217;t stop there. <b>Passenger now supports <a href="http://rack.rubyforge.org/">Rack</a></b>. I see this as probably the coolest thing about Passenger. Now any custom server that you write using Rack can be basically &#8220;dropped&#8221; into Apache and is effortlessly handled by Passenger. This also means that <b>rails alternatives like <a href="http://merbivore.com/">Merb</a> and <a href="http://code.whytheluckystiff.net/camping">Camping</a> work out of the box</b>. But there is more&#8230;</p>
<p>They also added in <i>support for Python&#8217;s Django</i>. It was almost comical: when they announced this the crowd nearly boo&#8217;ed them. I think it was a bit unfair, but I guess they should have expected it at a Rails conference. Either way, you have to give them props for taking the initiative and pushing the software to its boundaries.</p>
<p>Because Passenger supports frameworks other than Rails they decided to drop the name mod_rails and call it Phusion Passenger. They mentioned that their focus is still going to be developing and perfecting Rails. Passenger will simply not be exclusive to Rails.</p>
<h3>Case Studies</h3>
<p>Passenger is already being used in production at Dreamhost. It is also being used <a href="http://www.soocial.com">soocial</a> and <a href="http://www.ilike.com/">ilike</a>.</p>
<h3>The Q&amp;A</h3>
<p> By the Q&amp;A the crowd was full of skeptics; what they promised seemed too good to be true. However, one gentleman from the crowd sensed this, stood up, and said that he works with a developer/deployer Tom that has been working with production Rails deployment for 4 years. Tom apparently knows the in&#8217;s and out&#8217;s of Mongrel, Monit, Capistrano, etc. They found out about Passenger two or three weeks ago and he deployed all of their existing applications to Passenger in <b>a single day</b>. His comment was: </p>
<blockquote><p>Everything I learned [about Rails deployment] over the last few years is moot now, and that is a good thing.<i>Tom the deployer</i></p>
</blockquote>
<p>He said that &#8220;[Passenger] is incredibly awesome when it comes to rails deployment.&#8221; </p>
<p>A skeptic stood and rightly asked: &#8220;Why wasn&#8217;t this done five years ago? What was the technological hurdle?&#8221; The team answered that they believed the problem was largely social. Developers that had written Rails applications wanted to deploy them as quick as possible. They researched, learned about Capistano, Nginx, and Mongrel etc., and made it work. The Phusion team said that the people that were smart enough to tackle this problem were complacent and choose to deploy applications in this (painful) way.</p>
<blockquote><p>There is nothing technically preventing [ease of rails deployment]. We&#8217;ve shown it&#8217;s possible. Why it hasn&#8217;t been done is a social or political problem. There is no technical things stopping you. <i>-Hongli Lai (Phusion)</i></p>
</blockquote>
<h3>Summary</h3>
<p>Time will tell us if Apache/Passenger will live up to the hype and become the new standard. I, for one, am hoping that it really does take hold. If Rails deployment becomes as common and easy as PHP deployment we can spend time solving more interesting problems and that will be a good thing.</p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F02%2Frailsconf08-passenger-or-mod_rails-rip%2F&amp;title=RailsConf08%3A%20Passenger%20or%20mod_rails%20RIP&amp;notes=There%20was%20no%20lack%20of%20hubris%20on%20the%20stage%20today%20as%20the%20guys%20from%20Phusion%20talked%20about%20their%20new%20Apache%20extension%20Passenger.%20If%20Passenger%20lives%20up%20to%20its%20claims%20it%20seems%20that%20it%20could%20quickly%20become%20the%20de-facto%20standard%20for%20deploying%20Rails%20%28and%20more%29%20" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F02%2Frailsconf08-passenger-or-mod_rails-rip%2F&amp;title=RailsConf08%3A%20Passenger%20or%20mod_rails%20RIP" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F02%2Frailsconf08-passenger-or-mod_rails-rip%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=RailsConf08%3A%20Passenger%20or%20mod_rails%20RIP%20-%20http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F02%2Frailsconf08-passenger-or-mod_rails-rip%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F02%2Frailsconf08-passenger-or-mod_rails-rip%2F&amp;t=RailsConf08%3A%20Passenger%20or%20mod_rails%20RIP" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F02%2Frailsconf08-passenger-or-mod_rails-rip%2F&amp;title=RailsConf08%3A%20Passenger%20or%20mod_rails%20RIP&amp;annotation=There%20was%20no%20lack%20of%20hubris%20on%20the%20stage%20today%20as%20the%20guys%20from%20Phusion%20talked%20about%20their%20new%20Apache%20extension%20Passenger.%20If%20Passenger%20lives%20up%20to%20its%20claims%20it%20seems%20that%20it%20could%20quickly%20become%20the%20de-facto%20standard%20for%20deploying%20Rails%20%28and%20more%29%20" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F02%2Frailsconf08-passenger-or-mod_rails-rip%2F&amp;t=RailsConf08%3A%20Passenger%20or%20mod_rails%20RIP" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F02%2Frailsconf08-passenger-or-mod_rails-rip%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2008/06/02/railsconf08-passenger-or-mod_rails-rip/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>RailsConf08: Engine Yard on Rails Deployment Issues</title>
		<link>http://eigenjoy.com/2008/06/01/railsconf08-engine-yards-on-rails-deployment-issues/</link>
		<comments>http://eigenjoy.com/2008/06/01/railsconf08-engine-yards-on-rails-deployment-issues/#comments</comments>
		<pubDate>Mon, 02 Jun 2008 02:10:42 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[conferences]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/06/01/railsconf08-engine-yards-on-rails-deployment-issues/</guid>
		<description><![CDATA[Yesterday I sat in on a session on rails deployment, headed up by the guys from Engine Yard. The idea was to discuss deployment problems but it turned into general deployment tips. If anyone knows about deploying rails it is these guys and they have some fantastic ideas. I took away some interesting things that [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday I sat in on a session on rails deployment, headed up by the guys from <a href="http://www.engineyard.com/">Engine Yard</a>. The idea was to discuss deployment problems but it turned into general deployment tips. If anyone knows about deploying rails it is these guys and they have some fantastic ideas. I took away some interesting things that I&#8217;d like to share with you.</p>
<h3>Server choice</h3>
<p>One of the issues discussed was the choice of what rails server to run your application on. </p>
<ul>
<li><b>ebb</b> ebb is extremely fast, but probably not production ready today</li>
<li><b>thin</b> thin can be good for requests that are completed quickly. Because thin is event-driven it doesn&#8217;t work as well for longer running requests</li>
<li><b>mongrel</b></li>
</ul>
<p> Tom pointed out one important fact to consider when choosing between these. He said: </p>
<blockquote><p>They can all respond to requests faster than your application can generate. There are <b>way</b> more important things to spend time on.  <i>Tom Mornini, Engine Yard</i> </p>
</blockquote>
<p>The improvements you gain by switching between these is often insignificant when compared to your use of caching, limiting disk i/o in your apps, and controlling your overall application architecture.</p>
<p>Mongrel is, obviously, going to be most people&#8217;s first choice, because it&#8217;s great for general purpose. But when using mongrel, a common question is &#8220;how many mongrel processes should I be running?&#8221; Tom said that &#8220;you can burn out a modern CPU with 3 mongrels&#8221; and there is no reason to run more than <i>3 mongrel processes per core</i>. Typically if you have more than 3 mongrel processes per CPU core they are generally wasted.</p>
<p>The guys at Engine Yard love nginx. They said they&#8217;ve had no problems with it. Tom said that in internal tests against statics files they&#8217;ve seen <b>nginx serve 40 megabytes per second of static images and not show up in <tt>top</tt>.</b></p>
<h3>Misc other tips</h3>
<p><b>Static Files</b> Static files don&#8217;t have to be local. They can be shared across the entire cluster with a clustered file system. They use RedHat GFS for static storage and it is convenient because multiple machines can read the same filesystem. &#8220;If you can avoid NFS, do&#8230; NFS was really, really cool in 1979.&#8221;</p>
<p><b>Static resource domains</b> Browsers limit the number of requests per domain. At Engine Yard they have had success in improving load times by creating domain name aliases that often point to the same physical machine. e.g. images1.domain.com, images2.domain.com, etc. can all point to the exact same machine and exact same IP address but the browser is tricked into loading them concurrently because the domain names are different. They have seen significant improvement in load times by using this technique on pages that need to load a lot of files.</p>
<p><b>Virtualization</b> They use (the free, open-source version of) <a href="http://xen.xensource.org/">Xen</a> and love it. Nearly everything at Engine Yard is virtualized. Because of the way Xen works they said they have very little performance hit when using virtualization. One tip they gave was that it is not always good for each service to be on a separate virtual machine. They said that, by default, every slice (vm) at Enine Yard has nginx, 3 mongrels, and memcachd. They group the services and find that this often works well.</p>
<p>After the session I chatted with the guys. I told them that I spent a few weeks with the free version of Xen and found it very complicated to work with. They said that it took them <i>nine months</i> to perfect their use of Xen. I&#8217;m glad to find out that it wasn&#8217;t just me. However, it does inspire me to give it a second chance.</p>
<p><b>mod_rails and passenger</b> When asked about the new mod_rails they said that they are much more interested in rubinius and mod_rubinius. More posts on both rubinius and passenger to come.</p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F01%2Frailsconf08-engine-yards-on-rails-deployment-issues%2F&amp;title=RailsConf08%3A%20Engine%20Yard%20on%20Rails%20Deployment%20Issues&amp;notes=Yesterday%20I%20sat%20in%20on%20a%20session%20on%20rails%20deployment%2C%20headed%20up%20by%20the%20guys%20from%20Engine%20Yard.%20The%20idea%20was%20to%20discuss%20deployment%20problems%20but%20it%20turned%20into%20general%20deployment%20tips.%20If%20anyone%20knows%20about%20deploying%20rails%20it%20is%20these%20guys%20and%20they%20have%20" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F01%2Frailsconf08-engine-yards-on-rails-deployment-issues%2F&amp;title=RailsConf08%3A%20Engine%20Yard%20on%20Rails%20Deployment%20Issues" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F01%2Frailsconf08-engine-yards-on-rails-deployment-issues%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=RailsConf08%3A%20Engine%20Yard%20on%20Rails%20Deployment%20Issues%20-%20http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F01%2Frailsconf08-engine-yards-on-rails-deployment-issues%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F01%2Frailsconf08-engine-yards-on-rails-deployment-issues%2F&amp;t=RailsConf08%3A%20Engine%20Yard%20on%20Rails%20Deployment%20Issues" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F01%2Frailsconf08-engine-yards-on-rails-deployment-issues%2F&amp;title=RailsConf08%3A%20Engine%20Yard%20on%20Rails%20Deployment%20Issues&amp;annotation=Yesterday%20I%20sat%20in%20on%20a%20session%20on%20rails%20deployment%2C%20headed%20up%20by%20the%20guys%20from%20Engine%20Yard.%20The%20idea%20was%20to%20discuss%20deployment%20problems%20but%20it%20turned%20into%20general%20deployment%20tips.%20If%20anyone%20knows%20about%20deploying%20rails%20it%20is%20these%20guys%20and%20they%20have%20" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F01%2Frailsconf08-engine-yards-on-rails-deployment-issues%2F&amp;t=RailsConf08%3A%20Engine%20Yard%20on%20Rails%20Deployment%20Issues" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2008%2F06%2F01%2Frailsconf08-engine-yards-on-rails-deployment-issues%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2008/06/01/railsconf08-engine-yards-on-rails-deployment-issues/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RailsConf08: Testing and Contributing to Open-Source</title>
		<link>http://eigenjoy.com/2008/05/30/testing-and-contributing-to-open-source/</link>
		<comments>http://eigenjoy.com/2008/05/30/testing-and-contributing-to-open-source/#comments</comments>
		<pubDate>Fri, 30 May 2008 14:47:01 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[railsconf]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/05/30/testing-and-contributing-to-open-source/</guid>
		<description><![CDATA[Yesterday afternoon I attended a lecture and workshop on how to contribute to open-source projects and associated testing tools. I want to briefly share with you some of the tools and philosophies.
rcov
rcov.  rcov is a code coverage tool for Ruby. The idea is that you run it on your tests. Lines that get executed [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday afternoon I attended a lecture and workshop on how to contribute to open-source projects and associated testing tools. I want to briefly share with you some of the tools and philosophies.</p>
<h3>rcov</h3>
<p><a href="http://eigenclass.org/hiki.rb?rcov">rcov</a>. <a href="http://www.flickr.com/photos/nate_murray/2534584821/" title="rcov example by Nate Murray, on Flickr"><img src="http://farm4.static.flickr.com/3221/2534584821_d367d8fa9f.jpg" width="500" height="305" alt="rcov example" /></a> rcov is a code coverage tool for Ruby. The idea is that you run it on your tests. Lines that get <b>executed</b> are green and &#8220;ok&#8221; and lines that are never executed are marked red for being dangerous because they are never tested. This is an easy way for you to clearly see which lines of code are never being touched by any of your test cases.</p>
<p>I think that rcov will significantly change the way I approach testing with my own team and consultants. I&#8217;ll have to talk to my team, but it seems reasonable to me that every piece of code that is going to be used in production should have at least 50% code coverage. In growing, changing production systems this seems like a very valuable way to keep the code malleable (because you can refactor with less fear of breaking) which then leads to increased confidence and reduced cost-of-ownership.</p>
<h3>flog</h3>
<p><a href="http://ruby.sadi.st/Flog.html">flog</a> &#8211; a ruby code complexity analyzer. Now the first question you may be asking is &#8220;what in the world is a complexity analyzer?&#8221; The idea is that flog reads your code and assigns it a score based on criteria which is determined by its author, Ryan Davis. Basically it rates on the type of code Ryan Davis likes to see. This isn&#8217;t as terrible as it may sound because Ryan has some very tasteful ideas on what readable code looks like.</p>
<p>You may or may not agree with the way Ryan scores things, but as our speaker pointed out, flog and rcov <i>often agree with each other</i> about where a program&#8217;s problem areas are. More often than not the high flog score areas are not tested because they are too bulky to be tested. When one writes tests you often have to design the code in smaller, more testable pieces. Readability and testability often go hand in hand.</p>
<p>When running flog it can be helpful to just grep the output for <tt>#</tt>. This will give a high level view of the methods and their scores. Good candidates for refactoring are methods with scores between 80-150. Higher than 150 are typically serious problem areas (in terms of readability). Make sure you have them very well tested before you try to refactor them too much.</p>
<h3>heckle</h3>
<p>From the <a href="http://glu.ttono.us/articles/2006/12/19/tormenting-your-tests-with-heckle">heckle</a> website: &#8220;Heckle is a mutation tester. It modifies your code and runs your tests to make sure they fail. The idea is that if code can be changed and your tests don&#8217;t notice, either that code isn&#8217;t being covered or it doesn&#8217;t anything.&#8221; The idea is that hackle tests your tests and makes sure you are actually writing tests that are meaningful.</p>
<h3>tarantula</h3>
<p><a href="http://blog.thinkrelevance.com/2008/2/26/tarantula-vs-your-rails-app">tarantula</a> is a &#8220;fuzzy spider&#8221;. It crawls your web application and submits tons of garbage data and tries raise exceptions in your rails application. The premise of this tool is that no matter what data is posted, your application should not be returning 500 errors. You should handle bad data gracefully and not let unnecessary exceptions bubble to the surface. (I&#8217;m not entirely clear on how this gels with RESTful development where one <a href="http://www.therailsway.com/2007/9/3/using-activeresource-to-consume-web-services">often uses the return status codes</a> to return meaningful information)</p>
<h3>summary</h3>
<p>It was pointed out that none of these tools replace thought; they are here to enhance it. flog, for instance, is a tool that helps enhance your sense of code-smell. You may run flog, look at a &#8220;complex&#8221; method and decide that it is perfectly acceptable for your system. Obviously, you as the programmer know better than an automated tool. However, it is often the case that flog will point out passages of code that are challenging and difficult for anyone but the original author to read. The idea is to encourage code that is simple to test, read, and understand. This makes the code more robust and open to change.</p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F30%2Ftesting-and-contributing-to-open-source%2F&amp;title=RailsConf08%3A%20Testing%20and%20Contributing%20to%20Open-Source&amp;notes=Yesterday%20afternoon%20I%20attended%20a%20lecture%20and%20workshop%20on%20how%20to%20contribute%20to%20open-source%20projects%20and%20associated%20testing%20tools.%20I%20want%20to%20briefly%20share%20with%20you%20some%20of%20the%20tools%20and%20philosophies.%20%0D%0A%0D%0Arcov%0D%0A%0D%0Arcov.%20%20rcov%20is%20a%20code%20coverage%20tool%20for%20" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F30%2Ftesting-and-contributing-to-open-source%2F&amp;title=RailsConf08%3A%20Testing%20and%20Contributing%20to%20Open-Source" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F30%2Ftesting-and-contributing-to-open-source%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=RailsConf08%3A%20Testing%20and%20Contributing%20to%20Open-Source%20-%20http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F30%2Ftesting-and-contributing-to-open-source%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F30%2Ftesting-and-contributing-to-open-source%2F&amp;t=RailsConf08%3A%20Testing%20and%20Contributing%20to%20Open-Source" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F30%2Ftesting-and-contributing-to-open-source%2F&amp;title=RailsConf08%3A%20Testing%20and%20Contributing%20to%20Open-Source&amp;annotation=Yesterday%20afternoon%20I%20attended%20a%20lecture%20and%20workshop%20on%20how%20to%20contribute%20to%20open-source%20projects%20and%20associated%20testing%20tools.%20I%20want%20to%20briefly%20share%20with%20you%20some%20of%20the%20tools%20and%20philosophies.%20%0D%0A%0D%0Arcov%0D%0A%0D%0Arcov.%20%20rcov%20is%20a%20code%20coverage%20tool%20for%20" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F30%2Ftesting-and-contributing-to-open-source%2F&amp;t=RailsConf08%3A%20Testing%20and%20Contributing%20to%20Open-Source" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F30%2Ftesting-and-contributing-to-open-source%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2008/05/30/testing-and-contributing-to-open-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>RailsConf08: Meta-programming Ruby for Fun and Profit</title>
		<link>http://eigenjoy.com/2008/05/29/railsconf08-meta-programming-ruby-for-fun-and-profit/</link>
		<comments>http://eigenjoy.com/2008/05/29/railsconf08-meta-programming-ruby-for-fun-and-profit/#comments</comments>
		<pubDate>Fri, 30 May 2008 01:07:40 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[railsconf]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/05/29/railsconf08-meta-programming-ruby-for-fun-and-profit/</guid>
		<description><![CDATA[ I&#8217;m currently at RailsConf and it is fantastic. I&#8217;ve met a good number of interesting people and attended some interesting sessions.
Ruby Internals
 This morning Neal Ford and Patrick Farley gave a great session on Meta-programming Ruby for Fun and Profit. The slides should eventually show up
here.
Particularly interesting was Patrick&#8217;s portion about the internals of [...]]]></description>
			<content:encoded><![CDATA[<p> I&#8217;m currently at RailsConf and it is fantastic. I&#8217;ve met a good number of interesting people and attended some interesting sessions.</p>
<h3>Ruby Internals</h3>
<p> This morning <a href="http://nealford.com/">Neal Ford</a> and <a href="http://www.klankboomklang.com/">Patrick Farley</a> gave a great session on <b>Meta-programming Ruby for Fun and Profit</b>. The slides should eventually show up<br />
<a href="http://nealford.com/mypastconferences.htm">here</a>.</p>
<p>Particularly interesting was Patrick&#8217;s portion about the internals of Ruby&#8217;s method dispatch and how it relates to inheritance, mixins, and the object&#8217;s eigenclass. The basic idea is that when you call a class-method in Ruby the eigenclass (or metaclass) has a parallel inheritance structure to the actual class. I may write more about this with diagrams after Patrick posts the slides, but the the understanding of the system leads to this koan-like ruby truth:</p>
<blockquote><p>
The super-class of the meta-class is the meta-class of the super-class
</p>
</blockquote>
<p>Don&#8217;t worry if it isn&#8217;t clear right away. <a href="http://geminstallthat.wordpress.com/">Reid</a> and I<br />
attended the session and then discussed it over launch and it still took a while to sink in. In the meantime, checkout _why&#8217;s article <a href="http://whytheluckystiff.net/articles/seeingMetaclassesClearly.html">Seeing Metaclasses Clearly</a>.</p>
<h3>Use <tt>class_eval</tt> instead of reopening a class</h3>
<p>Patrick gave another very handy tip when dealing with meta-programming. He mentioned that using <tt>class_eval</tt> is much safer than re-opening a class and <tt>def</tt>ining a method. This is because you don&#8217;t always know when files are loaded and when you open a class you may be defining it without realizing it. When you use <tt>class_eval</tt> you are using an existing constant. For example:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">&nbsp;
<span style="color:#008000; font-style:italic;"># warning! this could be defining ExistingKlass and you don't even know it!</span>
<span style="color:#008000; font-style:italic;"># then the original ExisitingKlass will just overwrite your method</span>
<span style="color:#9966CC; font-weight:bold;">class</span> ExistingKlass
  <span style="color:#9966CC; font-weight:bold;">def</span> change_a_method
    <span style="color:#008000; font-style:italic;"># ...</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># do this instead as it will not try to define ExistingKlass. class_eval</span>
<span style="color:#008000; font-style:italic;"># guarantees the class already exists</span>
ExistingKlass.<span style="color:#9900CC;">class_eval</span> <span style="color:#9966CC; font-weight:bold;">do</span> 
  <span style="color:#9966CC; font-weight:bold;">def</span> change_a_method
    <span style="color:#008000; font-style:italic;"># ...</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p></code></p>
<h3>A Recorder</h3>
<p>Neal shared with us a very interesting class that records the messages sent to it`and can play them back later on. Here&#8217;s the code for it:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># recorder.rb</span>
<span style="color:#9966CC; font-weight:bold;">class</span> Recorder
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize
    <span style="color:#0066ff; font-weight:bold;">@messages</span> = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> method_missing<span style="color:#006600; font-weight:bold;">&#40;</span>method, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@messages</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>method, args, block<span style="color:#006600; font-weight:bold;">&#93;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> play_back_to<span style="color:#006600; font-weight:bold;">&#40;</span>obj<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@messages</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>method, args, block<span style="color:#006600; font-weight:bold;">|</span>
      obj.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span>method, <span style="color:#006600; font-weight:bold;">*</span>args, <span style="color:#006600; font-weight:bold;">&amp;</span>block<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>  
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># recorder_test.rb</span>
<span style="color:#9966CC; font-weight:bold;">class</span> TestRecorder <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> test_recorder
    r = Recorder.<span style="color:#9900CC;">new</span>
    r.<span style="color:#CC0066; font-weight:bold;">sub!</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>Java<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#996600;">&quot;Ruby&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
    r.<span style="color:#9900CC;">upcase</span>!
    r<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">11</span>, <span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#996600;">&quot;Universe&quot;</span>
    r <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;!&quot;</span>
&nbsp;
    s = <span style="color:#996600;">&quot;Hello Java World&quot;</span>
    r.<span style="color:#9900CC;">play_back_to</span><span style="color:#006600; font-weight:bold;">&#40;</span>s<span style="color:#006600; font-weight:bold;">&#41;</span>
    assert_equal <span style="color:#996600;">&quot;HELLO RUBY Universe!&quot;</span>, s
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p></code></p>
<p>I haven&#8217;t fully processed the power of this idea yet. However, I feel like it could have some application in genetic programming.</p>
<h3>Tabula Rasa, the Recorder, and DSLs</h3>
<p>Neal pointed out that one of the issues with <tt>Recorder</tt> is the following:</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># recorder_test.rb</span>
<span style="color:#9966CC; font-weight:bold;">class</span> TestRecorder <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> test_recorder
    r = Recorder.<span style="color:#9900CC;">new</span>
    r.<span style="color:#9900CC;">upcase</span>!
    r.<span style="color:#9900CC;">freeze</span>
&nbsp;
    s = <span style="color:#996600;">&quot;hi nate&quot;</span>
    r.<span style="color:#9900CC;">play_back_to</span><span style="color:#006600; font-weight:bold;">&#40;</span>s<span style="color:#006600; font-weight:bold;">&#41;</span>
    assert_equal <span style="color:#996600;">&quot;HI NATE&quot;</span>, s
&nbsp;
    s.<span style="color:#9900CC;">downcase</span>! <span style="color:#008000; font-style:italic;"># &lt;&lt;&lt; shouldn't work because it is frozen!</span>
    assert_equal <span style="color:#996600;">&quot;hi name&quot;</span>, s
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p></code></p>
<p>The issue is that the <tt>#freeze</tt> method went to the <tt>Recorder</tt> and not to the string. This is a problem you are likely to run into with a class like this because a standard ruby <tt>Object</tt> contains about 40 other methods; methods who&#8217;s names may conflict with what you want to delegate or capture with <tt>#method_missing</tt> (like the recorder). Thankfully <a href="http://onestepback.org/">Jim Weirich</a> has created a <a href="http://onestepback.org/index.cgi/Tech/Ruby/BlankSlate.rdoc">BlankSlate</a> class that you can use that will undefine all of the existing methods. If you have <tt>Recorder</tt> inherit from <tt>BlankSlate</tt> it will then work as expected. Neal mentioned that this class is being integrated into ruby 1.9 as <tt>SimpleObject</tt>. </p>
<p>When the slides become available checkout the section on the <tt>Quantifier</tt> module. The code is a bit lengthy to reproduce here but worth a look.</p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F29%2Frailsconf08-meta-programming-ruby-for-fun-and-profit%2F&amp;title=RailsConf08%3A%20Meta-programming%20Ruby%20for%20Fun%20and%20Profit&amp;notes=%20I%27m%20currently%20at%20RailsConf%20and%20it%20is%20fantastic.%20I%27ve%20met%20a%20good%20number%20of%20interesting%20people%20and%20attended%20some%20interesting%20sessions.%0D%0A%0D%0ARuby%20Internals%0D%0A%20This%20morning%20Neal%20Ford%20and%20Patrick%20Farley%20gave%20a%20great%20session%20on%20Meta-programming%20Ruby%20for%20Fun%20" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F29%2Frailsconf08-meta-programming-ruby-for-fun-and-profit%2F&amp;title=RailsConf08%3A%20Meta-programming%20Ruby%20for%20Fun%20and%20Profit" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F29%2Frailsconf08-meta-programming-ruby-for-fun-and-profit%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=RailsConf08%3A%20Meta-programming%20Ruby%20for%20Fun%20and%20Profit%20-%20http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F29%2Frailsconf08-meta-programming-ruby-for-fun-and-profit%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F29%2Frailsconf08-meta-programming-ruby-for-fun-and-profit%2F&amp;t=RailsConf08%3A%20Meta-programming%20Ruby%20for%20Fun%20and%20Profit" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F29%2Frailsconf08-meta-programming-ruby-for-fun-and-profit%2F&amp;title=RailsConf08%3A%20Meta-programming%20Ruby%20for%20Fun%20and%20Profit&amp;annotation=%20I%27m%20currently%20at%20RailsConf%20and%20it%20is%20fantastic.%20I%27ve%20met%20a%20good%20number%20of%20interesting%20people%20and%20attended%20some%20interesting%20sessions.%0D%0A%0D%0ARuby%20Internals%0D%0A%20This%20morning%20Neal%20Ford%20and%20Patrick%20Farley%20gave%20a%20great%20session%20on%20Meta-programming%20Ruby%20for%20Fun%20" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F29%2Frailsconf08-meta-programming-ruby-for-fun-and-profit%2F&amp;t=RailsConf08%3A%20Meta-programming%20Ruby%20for%20Fun%20and%20Profit" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2008%2F05%2F29%2Frailsconf08-meta-programming-ruby-for-fun-and-profit%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2008/05/29/railsconf08-meta-programming-ruby-for-fun-and-profit/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Rails Log Query Analyzer</title>
		<link>http://eigenjoy.com/2008/04/01/simple-rails-log-query-analyzer/</link>
		<comments>http://eigenjoy.com/2008/04/01/simple-rails-log-query-analyzer/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 19:57:51 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/04/01/simple-rails-log-query-analyzer/</guid>
		<description><![CDATA[Intro
This is a simple rails log analyzer. The initial goal is to
identify SQL queries that could be optimized or find queries that are being
called more often than they should be.
In its current state it is little more than simple regexes. My goal, however is
to build more useful tools on top of it.  I&#8217;ve added [...]]]></description>
			<content:encoded><![CDATA[<h2>Intro</h2>
<p>This is a simple rails log analyzer. The initial goal is to<br />
identify SQL queries that could be optimized or find queries that are being<br />
called more often than they should be.</p>
<p>In its current state it is little more than simple regexes. My goal, however is<br />
to build more useful tools on top of it.  I&#8217;ve added it to a git repository to<br />
allow anyone to make edits and improvements.</p>
<p>It&#8217;s not really ready for prime-time (for instance, it doesn&#8217;t work well<br />
with log colorization), but I have found it useful so I thought I would share<br />
it. If nothing else it could save someone else 10 minutes to write<br />
a similar script.</p>
<h2>What it does</h2>
<p>Right now all this does is read a log file and extract SQL &#8220;SELECT&#8221; statements<br />
and organize them by the amount of time they take. It will also show a summary<br />
of the number of queries called to load each model.</p>
<h2>How to get it</h2>
<p><code><br />
  git clone \<br />
  git://gitorious.org/simple_rails_log_analyzer/mainline.git \<br />
  simple_rails_log_analyzer<br />
</code></p>
<h2>How to use it</h2>
<p>The typical work flow looks like this:<br />
<code><br />
   rake log:clear<br />
   # hit the URL of the page we want to profile, run the rake task, etc<br />
   ruby bin/query_log_analyzer.rb log/development.log<br />
</code></p>
<p>Or visit <a href="http://gitorious.org/projects/simple_rails_log_analyzer">http://gitorious.org/projects/simple_rails_log_analyzer</a></p>
<h2>TODO</h2>
<ul>
<li>Deal with the colorization of the logs</li>
<li>Update the code to not be so SELECT centric. Support other types of queries</li>
<li>Be smarter about each request&#8217;s individual queries</li>
</ul>
<h2>Contributions</h2>
<p>I&#8217;ve placed this in a git repository, so feel free to submit any patches and<br />
I&#8217;ll integrate them into this master.</p>
<h2>Similar Projects</h2>
<ul>
<li><a href="http://rails-analyzer.rubyforge.org/">http://rails-analyzer.rubyforge.org/</a></li>
</ul>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Feigenjoy.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F&amp;title=Simple%20Rails%20Log%20Query%20Analyzer&amp;notes=Intro%0D%0AThis%20is%20a%20simple%20rails%20log%20analyzer.%20The%20initial%20goal%20is%20to%0D%0Aidentify%20SQL%20queries%20that%20could%20be%20optimized%20or%20find%20queries%20that%20are%20being%0D%0Acalled%20more%20often%20than%20they%20should%20be.%0D%0A%0D%0AIn%20its%20current%20state%20it%20is%20little%20more%20than%20simple%20regexes.%20My%20" title="del.icio.us"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/delicious.png" title="del.icio.us" alt="del.icio.us" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://reddit.com/submit?url=http%3A%2F%2Feigenjoy.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F&amp;title=Simple%20Rails%20Log%20Query%20Analyzer" title="Reddit"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/reddit.png" title="Reddit" alt="Reddit" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://technorati.com/faves?add=http%3A%2F%2Feigenjoy.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F" title="Technorati"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/technorati.png" title="Technorati" alt="Technorati" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://twitter.com/home?status=Simple%20Rails%20Log%20Query%20Analyzer%20-%20http%3A%2F%2Feigenjoy.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F" title="Twitter"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/twitter.png" title="Twitter" alt="Twitter" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.facebook.com/share.php?u=http%3A%2F%2Feigenjoy.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F&amp;t=Simple%20Rails%20Log%20Query%20Analyzer" title="Facebook"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/facebook.png" title="Facebook" alt="Facebook" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.google.com/bookmarks/mark?op=edit&amp;bkmk=http%3A%2F%2Feigenjoy.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F&amp;title=Simple%20Rails%20Log%20Query%20Analyzer&amp;annotation=Intro%0D%0AThis%20is%20a%20simple%20rails%20log%20analyzer.%20The%20initial%20goal%20is%20to%0D%0Aidentify%20SQL%20queries%20that%20could%20be%20optimized%20or%20find%20queries%20that%20are%20being%0D%0Acalled%20more%20often%20than%20they%20should%20be.%0D%0A%0D%0AIn%20its%20current%20state%20it%20is%20little%20more%20than%20simple%20regexes.%20My%20" title="Google Bookmarks"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/googlebookmark.png" title="Google Bookmarks" alt="Google Bookmarks" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://news.ycombinator.com/submitlink?u=http%3A%2F%2Feigenjoy.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F&amp;t=Simple%20Rails%20Log%20Query%20Analyzer" title="HackerNews"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/hackernews.png" title="HackerNews" alt="HackerNews" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.printfriendly.com/print?url=http%3A%2F%2Feigenjoy.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F&amp;partner=sociable" title="PDF"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://eigenjoy.com/feed/" title="RSS"><img src="http://eigenjoy.com/wp-content/plugins/sociable/images/rss.png" title="RSS" alt="RSS" class="sociable-hovers" /></a></p>
<p><br/><br/></p>
]]></content:encoded>
			<wfw:commentRss>http://eigenjoy.com/2008/04/01/simple-rails-log-query-analyzer/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

