<?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>X-Combinator &#187; rails</title>
	<atom:link href="http://www.xcombinator.com/category/rails/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xcombinator.com</link>
	<description>making the human scalable</description>
	<lastBuildDate>Thu, 09 Sep 2010 03:46:53 +0000</lastBuildDate>
	
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>visualize state_machine&#8217;s with graphviz</title>
		<link>http://www.xcombinator.com/2008/10/14/visualize-state_machines-with-graphviz/</link>
		<comments>http://www.xcombinator.com/2008/10/14/visualize-state_machines-with-graphviz/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 16:04:23 +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/10/14/visualize-state_machines-with-graphviz/</guid>
		<description><![CDATA[The guys at Plugin-a-week have written a nice ActiveRecord state machine gem called state_machine. 
One of the great things about state machines is that they often can be visualized. To that end I&#8217;ve written a small utility that will load a class that uses state_machine and produce dot output which you can use with graphviz.
This [...]]]></description>
			<content:encoded><![CDATA[<p>The guys at <a href="http://www.pluginaweek.org/">Plugin-a-week</a> have written a nice ActiveRecord state machine gem called <a href="http://github.com/pluginaweek/state_machine/tree/master">state_machine</a>. </p>
<p>One of the great things about state machines is that they often can be visualized. To that end I&#8217;ve written a small utility that will load a class that uses <tt>state_machine</tt> and produce <tt>dot</tt> output which you can use with <a href="http://www.graphviz.org/">graphviz</a>.</p>
<p>This gem is currently used by the <a href="http://spreehq.org/">spree</a> shopping cart. Let&#8217;s look at an example of how this can be used to visualize the <tt>Order</tt> object in this project:</p>
<p>Save the gist below to <tt>visualize.rb</tt> and <tt>chmod +x visualize.rb</tt>. The arguments are 1) the path to <tt>RAILS_ROOT</tt> of the project using <tt>state_machine</tt> and 2) the class you want to visualize. Try <tt>visualize.rb --help</tt> to see all the options. </p>
<p><code><br />
 ruby visualize.rb . Order | dot -Tsvg -Grankdir=LR > graph.svg<br />
</code></p>
<p>Gives us the following image:</p>
<p><a href='http://www.xcombinator.com/wp-content/uploads/2008/10/picture-1.png' title='Spree State Machine'><img src='http://www.xcombinator.com/wp-content/uploads/2008/10/picture-1.thumbnail.png' alt='Spree State Machine' /></a></p>
<p>Download the <a href="http://gist.github.com/raw/16729/2ebb0d8e55803ca88aaf92e3278499623264360a">raw code</a> (Requires &#8216;trollop&#8217; gem).</p>
<p><script src="http://gist.github.com/16729.js"></script></p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.xcombinator.com%2F2008%2F10%2F14%2Fvisualize-state_machines-with-graphviz%2F&amp;title=visualize%20%3Ctt%3Estate_machine%3C%2Ftt%3E%27s%20with%20graphviz&amp;notes=The%20guys%20at%20Plugin-a-week%20have%20written%20a%20nice%20ActiveRecord%20state%20machine%20gem%20called%20state_machine.%20%0D%0A%0D%0AOne%20of%20the%20great%20things%20about%20state%20machines%20is%20that%20they%20often%20can%20be%20visualized.%20To%20that%20end%20I%27ve%20written%20a%20small%20utility%20that%20will%20load%20a%20class%20" title="del.icio.us"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F10%2F14%2Fvisualize-state_machines-with-graphviz%2F&amp;title=visualize%20%3Ctt%3Estate_machine%3C%2Ftt%3E%27s%20with%20graphviz" title="Reddit"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F10%2F14%2Fvisualize-state_machines-with-graphviz%2F" title="Technorati"><img src="http://www.xcombinator.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=visualize%20%3Ctt%3Estate_machine%3C%2Ftt%3E%27s%20with%20graphviz%20-%20http%3A%2F%2Fwww.xcombinator.com%2F2008%2F10%2F14%2Fvisualize-state_machines-with-graphviz%2F" title="Twitter"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F10%2F14%2Fvisualize-state_machines-with-graphviz%2F&amp;t=visualize%20%3Ctt%3Estate_machine%3C%2Ftt%3E%27s%20with%20graphviz" title="Facebook"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F10%2F14%2Fvisualize-state_machines-with-graphviz%2F&amp;title=visualize%20%3Ctt%3Estate_machine%3C%2Ftt%3E%27s%20with%20graphviz&amp;annotation=The%20guys%20at%20Plugin-a-week%20have%20written%20a%20nice%20ActiveRecord%20state%20machine%20gem%20called%20state_machine.%20%0D%0A%0D%0AOne%20of%20the%20great%20things%20about%20state%20machines%20is%20that%20they%20often%20can%20be%20visualized.%20To%20that%20end%20I%27ve%20written%20a%20small%20utility%20that%20will%20load%20a%20class%20" title="Google Bookmarks"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F10%2F14%2Fvisualize-state_machines-with-graphviz%2F&amp;t=visualize%20%3Ctt%3Estate_machine%3C%2Ftt%3E%27s%20with%20graphviz" title="HackerNews"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F10%2F14%2Fvisualize-state_machines-with-graphviz%2F&amp;partner=sociable" title="PDF"><img src="http://www.xcombinator.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.xcombinator.com/feed/" title="RSS"><img src="http://www.xcombinator.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://www.xcombinator.com/2008/10/14/visualize-state_machines-with-graphviz/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ActiveRecord from_xml (and from_json) part 2</title>
		<link>http://www.xcombinator.com/2008/08/11/activerecord-from_xml-and-from_json-part-2/</link>
		<comments>http://www.xcombinator.com/2008/08/11/activerecord-from_xml-and-from_json-part-2/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 02:33:17 +0000</pubDate>
		<dc:creator>Matt Pulver</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[from_json]]></category>
		<category><![CDATA[from_xml]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[unmarshall]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/08/11/activerecord-from_xml-and-from_json-part-2/</guid>
		<description><![CDATA[This post is an upgrade to the previous post about the unmarshalling of XML and JSON strings into rails objects, with arbitrarily deep object associations. As you may know if you are reading this, there doesn&#8217;t seem to be a way in rails to reverse to_xml and to_json when associations are included.
Example usage:

xml = firm.to_xml [...]]]></description>
			<content:encoded><![CDATA[<p>This post is an upgrade to <a href="http://www.xcombinator.com/2008/07/06/activerecord-from_json-and-from_xml/">the previous post</a> about the unmarshalling of XML and JSON strings into rails objects, with arbitrarily deep object associations. As you may know if you are reading this, there doesn&#8217;t seem to be a way in rails to reverse to_xml and to_json when associations are included.</p>
<p>Example usage:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">xml = firm.<span style="color:#9900CC;">to_xml</span> <span style="color:#ff3333; font-weight:bold;">:include</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#ff3333; font-weight:bold;">:account</span>, <span style="color:#ff3333; font-weight:bold;">:clients</span> <span style="color:#006600; font-weight:bold;">&#93;</span>  
firm = Firm.<span style="color:#9900CC;">from_xml</span> xml</pre></div></div>

<p>firm.account and firm.clients will behave as intended (by default there does not seem to be a direct way in rails to unmarshall them.)</p>
<p>Here&#8217;s how to get from_xml and from_json defined for your ActiveRecord classes:</p>
<p>Create a file lib/extensions.rb with the following code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> ActiveRecord
  <span style="color:#9966CC; font-weight:bold;">class</span> Base
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">from_hash</span><span style="color:#006600; font-weight:bold;">&#40;</span> hash <span style="color:#006600; font-weight:bold;">&#41;</span>
      h = hash.<span style="color:#9900CC;">dup</span>
      h.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>key,value<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#9966CC; font-weight:bold;">case</span> value.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">to_s</span>
        <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'Array'</span>
          h<span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">map</span>! <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span> reflect_on_association<span style="color:#006600; font-weight:bold;">&#40;</span>
             key.<span style="color:#9900CC;">to_sym</span> <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">klass</span>.<span style="color:#9900CC;">from_hash</span> e <span style="color:#006600; font-weight:bold;">&#125;</span>
        <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#006600; font-weight:bold;">/</span>\AHash<span style="color:#006600; font-weight:bold;">&#40;</span>WithIndifferentAccess<span style="color:#006600; font-weight:bold;">&#41;</span>?\Z<span style="color:#006600; font-weight:bold;">/</span>
          h<span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span> = reflect_on_association<span style="color:#006600; font-weight:bold;">&#40;</span>
             key.<span style="color:#9900CC;">to_sym</span> <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">klass</span>.<span style="color:#9900CC;">from_hash</span> value
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      new h
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">from_json</span><span style="color:#006600; font-weight:bold;">&#40;</span> json <span style="color:#006600; font-weight:bold;">&#41;</span>
      from_hash safe_json_decode<span style="color:#006600; font-weight:bold;">&#40;</span> json <span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># The xml has a surrounding class tag (e.g. ship-to),</span>
    <span style="color:#008000; font-style:italic;"># but the hash has no counterpart (e.g. 'ship_to' =&gt; {} )</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">from_xml</span><span style="color:#006600; font-weight:bold;">&#40;</span> xml <span style="color:#006600; font-weight:bold;">&#41;</span>
      from_hash <span style="color:#9966CC; font-weight:bold;">begin</span>
        <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">from_xml</span><span style="color:#006600; font-weight:bold;">&#40;</span>xml<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span>to_s.<span style="color:#9900CC;">demodulize</span>.<span style="color:#9900CC;">underscore</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      <span style="color:#9966CC; font-weight:bold;">rescue</span> ; <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#008000; font-style:italic;"># class Base</span>
<span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#008000; font-style:italic;"># module ActiveRecord</span>
&nbsp;
<span style="color:#008000; font-style:italic;">### Global functions ###</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># JSON.decode, or return {} if anything goes wrong.</span>
<span style="color:#9966CC; font-weight:bold;">def</span> safe_json_decode<span style="color:#006600; font-weight:bold;">&#40;</span> json <span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">if</span> !json
  <span style="color:#9966CC; font-weight:bold;">begin</span>
    <span style="color:#6666ff; font-weight:bold;">ActiveSupport::JSON</span>.<span style="color:#9900CC;">decode</span> json
  <span style="color:#9966CC; font-weight:bold;">rescue</span> ; <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>At the bottom of config/environments.rb, insert the line:</p>

<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;">'lib/extensions'</span> <span style="color:#008000; font-style:italic;"># custom class extensions</span></pre></div></div>

<p>You can name the &#8220;extensions.rb&#8221; file anything else you want; just update the environments.rb file accordingly.</p>
<p>This is an improvement over the previous post, in that it can work even when your associations use the :class_name parameter, you&#8217;re not editing the vendor/rails files directly, and it can deal with hashes of the rails class HashWithIndifferentAccess.</p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.xcombinator.com%2F2008%2F08%2F11%2Factiverecord-from_xml-and-from_json-part-2%2F&amp;title=ActiveRecord%20from_xml%20%28and%20from_json%29%20part%202&amp;notes=This%20post%20is%20an%20upgrade%20to%20the%20previous%20post%20about%20the%20unmarshalling%20of%20XML%20and%20JSON%20strings%20into%20rails%20objects%2C%20with%20arbitrarily%20deep%20object%20associations.%20As%20you%20may%20know%20if%20you%20are%20reading%20this%2C%20there%20doesn%27t%20seem%20to%20be%20a%20way%20in%20rails%20to%20reverse%20to" title="del.icio.us"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F08%2F11%2Factiverecord-from_xml-and-from_json-part-2%2F&amp;title=ActiveRecord%20from_xml%20%28and%20from_json%29%20part%202" title="Reddit"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F08%2F11%2Factiverecord-from_xml-and-from_json-part-2%2F" title="Technorati"><img src="http://www.xcombinator.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=ActiveRecord%20from_xml%20%28and%20from_json%29%20part%202%20-%20http%3A%2F%2Fwww.xcombinator.com%2F2008%2F08%2F11%2Factiverecord-from_xml-and-from_json-part-2%2F" title="Twitter"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F08%2F11%2Factiverecord-from_xml-and-from_json-part-2%2F&amp;t=ActiveRecord%20from_xml%20%28and%20from_json%29%20part%202" title="Facebook"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F08%2F11%2Factiverecord-from_xml-and-from_json-part-2%2F&amp;title=ActiveRecord%20from_xml%20%28and%20from_json%29%20part%202&amp;annotation=This%20post%20is%20an%20upgrade%20to%20the%20previous%20post%20about%20the%20unmarshalling%20of%20XML%20and%20JSON%20strings%20into%20rails%20objects%2C%20with%20arbitrarily%20deep%20object%20associations.%20As%20you%20may%20know%20if%20you%20are%20reading%20this%2C%20there%20doesn%27t%20seem%20to%20be%20a%20way%20in%20rails%20to%20reverse%20to" title="Google Bookmarks"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F08%2F11%2Factiverecord-from_xml-and-from_json-part-2%2F&amp;t=ActiveRecord%20from_xml%20%28and%20from_json%29%20part%202" title="HackerNews"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F08%2F11%2Factiverecord-from_xml-and-from_json-part-2%2F&amp;partner=sociable" title="PDF"><img src="http://www.xcombinator.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.xcombinator.com/feed/" title="RSS"><img src="http://www.xcombinator.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://www.xcombinator.com/2008/08/11/activerecord-from_xml-and-from_json-part-2/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ActiveRecord from_json and from_xml</title>
		<link>http://www.xcombinator.com/2008/07/06/activerecord-from_json-and-from_xml/</link>
		<comments>http://www.xcombinator.com/2008/07/06/activerecord-from_json-and-from_xml/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 20:27:25 +0000</pubDate>
		<dc:creator>Matt Pulver</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[from_json]]></category>
		<category><![CDATA[from_xml]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[to_json]]></category>
		<category><![CDATA[to_xml]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/07/06/activerecord-from_json-and-from_xml/</guid>
		<description><![CDATA[Unless I&#8217;m missing something, the default rails from_json and from_xml methods don&#8217;t work with data that have associated objects. Here are routines that work for some simple examples I&#8217;ve tested. I placed this code in vendor/rails/activerecord/lib/active_record/base.rb within the ActiveRecord::Base class, but there might be a better place to put it.

def self.from_hash&#40; hash &#41;
  h [...]]]></description>
			<content:encoded><![CDATA[<p>Unless I&#8217;m missing something, the default rails from_json and from_xml methods don&#8217;t work with data that have associated objects. Here are routines that work for some simple examples I&#8217;ve tested. I placed this code in vendor/rails/activerecord/lib/active_record/base.rb within the ActiveRecord::Base class, but there might be a better place to put it.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">from_hash</span><span style="color:#006600; font-weight:bold;">&#40;</span> hash <span style="color:#006600; font-weight:bold;">&#41;</span>
  h = hash.<span style="color:#9900CC;">dup</span>
  h.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>key,value<span style="color:#006600; font-weight:bold;">|</span> 
    <span style="color:#9966CC; font-weight:bold;">case</span> value.<span style="color:#9966CC; font-weight:bold;">class</span>.<span style="color:#9900CC;">to_s</span>
    <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'Array'</span>
      h<span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">map</span>! <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span>
         <span style="color:#CC00FF; font-weight:bold;">Object</span>.<span style="color:#9900CC;">const_get</span><span style="color:#006600; font-weight:bold;">&#40;</span>key.<span style="color:#9900CC;">camelize</span>.<span style="color:#9900CC;">singularize</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">from_hash</span> e <span style="color:#006600; font-weight:bold;">&#125;</span>
    <span style="color:#9966CC; font-weight:bold;">when</span> <span style="color:#996600;">'Hash'</span>
      h<span style="color:#006600; font-weight:bold;">&#91;</span>key<span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#CC00FF; font-weight:bold;">Object</span>.<span style="color:#9900CC;">const_get</span><span style="color:#006600; font-weight:bold;">&#40;</span>key.<span style="color:#9900CC;">camelize</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">from_hash</span> value
    <span style="color:#9966CC; font-weight:bold;">end</span> 
  <span style="color:#9966CC; font-weight:bold;">end</span>     
  <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">new</span> h
<span style="color:#9966CC; font-weight:bold;">end</span>   
&nbsp;
<span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">from_json</span><span style="color:#006600; font-weight:bold;">&#40;</span> json <span style="color:#006600; font-weight:bold;">&#41;</span>
  hash = <span style="color:#6666ff; font-weight:bold;">ActiveSupport::JSON</span>.<span style="color:#9900CC;">decode</span> json
  <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">from_hash</span> hash
<span style="color:#9966CC; font-weight:bold;">end</span>   
&nbsp;
<span style="color:#008000; font-style:italic;"># The xml has a surrounding class tag (e.g. ship-to),</span>
<span style="color:#008000; font-style:italic;"># but the hash has no counterpart (e.g. 'ship_to' =&gt; {} )</span>
<span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">from_xml</span><span style="color:#006600; font-weight:bold;">&#40;</span> xml <span style="color:#006600; font-weight:bold;">&#41;</span>
  hash = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">from_xml</span> xml
  <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">from_hash</span> hash<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">to_s</span>.<span style="color:#9900CC;">underscore</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Also available on <a href="http://pastie.org/228617">pastie</a>.</p>
<p>Example usage, using the <a href="http://api.rubyonrails.org/classes/ActiveRecord/XmlSerialization.html">to_xml example</a>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">xml = firm.<span style="color:#9900CC;">to_xml</span> <span style="color:#ff3333; font-weight:bold;">:include</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <span style="color:#ff3333; font-weight:bold;">:account</span>, <span style="color:#ff3333; font-weight:bold;">:clients</span> <span style="color:#006600; font-weight:bold;">&#93;</span>
firm = Firm.<span style="color:#9900CC;">from_xml</span> xml</pre></div></div>

<p>Note: this only works if the classes of the nested objects are canonically named. If any of your associations use the :class_name option, you will probably need to update this code to discover the proper class names.</p>
<p>I just wrote this a couple hours ago, so please consider this to be an alpha version.</p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.xcombinator.com%2F2008%2F07%2F06%2Factiverecord-from_json-and-from_xml%2F&amp;title=ActiveRecord%20from_json%20and%20from_xml&amp;notes=Unless%20I%27m%20missing%20something%2C%20the%20default%20rails%20from_json%20and%20from_xml%20methods%20don%27t%20work%20with%20data%20that%20have%20associated%20objects.%20Here%20are%20routines%20that%20work%20for%20some%20simple%20examples%20I%27ve%20tested.%20I%20placed%20this%20code%20in%20vendor%2Frails%2Factiverecord%2Flib%2Fac" title="del.icio.us"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F07%2F06%2Factiverecord-from_json-and-from_xml%2F&amp;title=ActiveRecord%20from_json%20and%20from_xml" title="Reddit"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F07%2F06%2Factiverecord-from_json-and-from_xml%2F" title="Technorati"><img src="http://www.xcombinator.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=ActiveRecord%20from_json%20and%20from_xml%20-%20http%3A%2F%2Fwww.xcombinator.com%2F2008%2F07%2F06%2Factiverecord-from_json-and-from_xml%2F" title="Twitter"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F07%2F06%2Factiverecord-from_json-and-from_xml%2F&amp;t=ActiveRecord%20from_json%20and%20from_xml" title="Facebook"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F07%2F06%2Factiverecord-from_json-and-from_xml%2F&amp;title=ActiveRecord%20from_json%20and%20from_xml&amp;annotation=Unless%20I%27m%20missing%20something%2C%20the%20default%20rails%20from_json%20and%20from_xml%20methods%20don%27t%20work%20with%20data%20that%20have%20associated%20objects.%20Here%20are%20routines%20that%20work%20for%20some%20simple%20examples%20I%27ve%20tested.%20I%20placed%20this%20code%20in%20vendor%2Frails%2Factiverecord%2Flib%2Fac" title="Google Bookmarks"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F07%2F06%2Factiverecord-from_json-and-from_xml%2F&amp;t=ActiveRecord%20from_json%20and%20from_xml" title="HackerNews"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F07%2F06%2Factiverecord-from_json-and-from_xml%2F&amp;partner=sociable" title="PDF"><img src="http://www.xcombinator.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.xcombinator.com/feed/" title="RSS"><img src="http://www.xcombinator.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://www.xcombinator.com/2008/07/06/activerecord-from_json-and-from_xml/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>RailsConf08: 23 Hacks</title>
		<link>http://www.xcombinator.com/2008/06/04/railsconf08-23-hacks/</link>
		<comments>http://www.xcombinator.com/2008/06/04/railsconf08-23-hacks/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 21:09:49 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[railsconf08]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/06/04/railsconf08-23-hacks/</guid>
		<description><![CDATA[Nathaniel Talbott (from Terralien) gave a great talk on a number of interesting hacks in ruby. There was one in particular that I want to focus on here: gitjour. Gitjour is a fun and novel app that will discover git repositories on a local network via Bonjour. It&#8217;s hardly going to change your life, but [...]]]></description>
			<content:encoded><![CDATA[<p>Nathaniel Talbott (from <a href="http://terralien.com/">Terralien</a>) gave a great talk on a number of interesting hacks in ruby. There was one in particular that I want to focus on here: <a href="http://rubyfurnace.com/gems/gitjour">gitjour</a>. Gitjour is a fun and novel app that will discover git repositories on a local network via Bonjour. It&#8217;s hardly going to change your life, but it is fantastic for ad-hoc sharing of code on a local network and quick collaboration without too much ceremony, e.g. at a conference, or <a href="http://tech.groups.yahoo.com/group/LARuby/">ruby users group</a>, etc.</p>
<p>It&#8217;s a fun tool and you should definitely try it out.</p>
<p><code></p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">$ gem install gitjour
$ gitjour list
$ gitjour clone whatever_app</pre></div></div>

<p></code></p>
<p>While I&#8217;m on the topic of git, I&#8217;d like to point out that the community at RailsConf was completely sold on using git and using <a href="http://github.com/">GitHub</a> in particular. Even though I am a git-switcher myself, it was really surprising to see that almost the whole community had either switched or was planning on switching.</p>
<p>GitHub did a great job marketing at the conference. They gave out free t-shirts that said &#8220;Fork You&#8221; on the front. On the back the shirt said &#8220;http://github.com/________&#8221; and you were expected to take a sharpee and write your GitHub user name so that others could see your projects (my projects are <a href="http://github.com/jashmenn">here</a>). The successful result was that at nearly every session or meal someone would use the phrase &#8220;I think I&#8217;ll put this code up on GitHub&#8221;.</p>
<p><b>UPDATE:</b> I&#8217;ve found a picture of the shirt <a href="http://www.flickr.com/photos/dwortlehock/2540106781/">here</a></p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.xcombinator.com%2F2008%2F06%2F04%2Frailsconf08-23-hacks%2F&amp;title=RailsConf08%3A%2023%20Hacks&amp;notes=Nathaniel%20Talbott%20%28from%20Terralien%29%20gave%20a%20great%20talk%20on%20a%20number%20of%20interesting%20hacks%20in%20ruby.%20There%20was%20one%20in%20particular%20that%20I%20want%20to%20focus%20on%20here%3A%20gitjour.%20Gitjour%20is%20a%20fun%20and%20novel%20app%20that%20will%20discover%20git%20repositories%20on%20a%20local%20network%20vi" title="del.icio.us"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F04%2Frailsconf08-23-hacks%2F&amp;title=RailsConf08%3A%2023%20Hacks" title="Reddit"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F04%2Frailsconf08-23-hacks%2F" title="Technorati"><img src="http://www.xcombinator.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%2023%20Hacks%20-%20http%3A%2F%2Fwww.xcombinator.com%2F2008%2F06%2F04%2Frailsconf08-23-hacks%2F" title="Twitter"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F04%2Frailsconf08-23-hacks%2F&amp;t=RailsConf08%3A%2023%20Hacks" title="Facebook"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F04%2Frailsconf08-23-hacks%2F&amp;title=RailsConf08%3A%2023%20Hacks&amp;annotation=Nathaniel%20Talbott%20%28from%20Terralien%29%20gave%20a%20great%20talk%20on%20a%20number%20of%20interesting%20hacks%20in%20ruby.%20There%20was%20one%20in%20particular%20that%20I%20want%20to%20focus%20on%20here%3A%20gitjour.%20Gitjour%20is%20a%20fun%20and%20novel%20app%20that%20will%20discover%20git%20repositories%20on%20a%20local%20network%20vi" title="Google Bookmarks"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F04%2Frailsconf08-23-hacks%2F&amp;t=RailsConf08%3A%2023%20Hacks" title="HackerNews"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F04%2Frailsconf08-23-hacks%2F&amp;partner=sociable" title="PDF"><img src="http://www.xcombinator.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.xcombinator.com/feed/" title="RSS"><img src="http://www.xcombinator.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://www.xcombinator.com/2008/06/04/railsconf08-23-hacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RailsConf08: Passenger or mod_rails RIP</title>
		<link>http://www.xcombinator.com/2008/06/02/railsconf08-passenger-or-mod_rails-rip/</link>
		<comments>http://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F02%2Frailsconf08-passenger-or-mod_rails-rip%2F" title="Technorati"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F02%2Frailsconf08-passenger-or-mod_rails-rip%2F" title="Twitter"><img src="http://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F02%2Frailsconf08-passenger-or-mod_rails-rip%2F&amp;partner=sociable" title="PDF"><img src="http://www.xcombinator.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.xcombinator.com/feed/" title="RSS"><img src="http://www.xcombinator.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://www.xcombinator.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://www.xcombinator.com/2008/06/01/railsconf08-engine-yards-on-rails-deployment-issues/</link>
		<comments>http://www.xcombinator.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[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[railsconf08]]></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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F01%2Frailsconf08-engine-yards-on-rails-deployment-issues%2F" title="Technorati"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F01%2Frailsconf08-engine-yards-on-rails-deployment-issues%2F" title="Twitter"><img src="http://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F06%2F01%2Frailsconf08-engine-yards-on-rails-deployment-issues%2F&amp;partner=sociable" title="PDF"><img src="http://www.xcombinator.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.xcombinator.com/feed/" title="RSS"><img src="http://www.xcombinator.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://www.xcombinator.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://www.xcombinator.com/2008/05/30/testing-and-contributing-to-open-source/</link>
		<comments>http://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F05%2F30%2Ftesting-and-contributing-to-open-source%2F" title="Technorati"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F05%2F30%2Ftesting-and-contributing-to-open-source%2F" title="Twitter"><img src="http://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F05%2F30%2Ftesting-and-contributing-to-open-source%2F&amp;partner=sociable" title="PDF"><img src="http://www.xcombinator.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.xcombinator.com/feed/" title="RSS"><img src="http://www.xcombinator.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://www.xcombinator.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://www.xcombinator.com/2008/05/29/railsconf08-meta-programming-ruby-for-fun-and-profit/</link>
		<comments>http://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F05%2F29%2Frailsconf08-meta-programming-ruby-for-fun-and-profit%2F" title="Technorati"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F05%2F29%2Frailsconf08-meta-programming-ruby-for-fun-and-profit%2F" title="Twitter"><img src="http://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F05%2F29%2Frailsconf08-meta-programming-ruby-for-fun-and-profit%2F&amp;partner=sociable" title="PDF"><img src="http://www.xcombinator.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.xcombinator.com/feed/" title="RSS"><img src="http://www.xcombinator.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://www.xcombinator.com/2008/05/29/railsconf08-meta-programming-ruby-for-fun-and-profit/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Chaining :include&#8217;s in Rails to reduce the number of SQL queries</title>
		<link>http://www.xcombinator.com/2008/04/08/chaining-includes-in-rails-to-reduce-the-number-of-sql-queries/</link>
		<comments>http://www.xcombinator.com/2008/04/08/chaining-includes-in-rails-to-reduce-the-number-of-sql-queries/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 17:51:33 +0000</pubDate>
		<dc:creator>Matt Pulver</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[scalability]]></category>
		<category><![CDATA[ActiveRecord]]></category>
		<category><![CDATA[include]]></category>
		<category><![CDATA[join]]></category>
		<category><![CDATA[joins]]></category>
		<category><![CDATA[optimize]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/04/08/chaining-includes-in-rails-to-reduce-the-number-of-sql-queries/</guid>
		<description><![CDATA[Say you have the following data model

and you want to execute a single query that returns all the data at once within the ActiveRecord tables, with the proper rails associations between them. Wouldn&#8217;t it be nice if you could do something like

A.find&#40;:all, :include =&#62; :b =&#62; :c =&#62; :d =&#62; :e&#41; #v1

? Though this is [...]]]></description>
			<content:encoded><![CDATA[<p>Say you have the following data model</p>
<p><img src='http://www.xcombinator.com/wp-content/uploads/2008/04/associations.gif' alt='A-B-C-D-E' /></p>
<p>and you want to execute a single query that returns all the data at once within the ActiveRecord tables, with the proper rails associations between them. Wouldn&#8217;t it be nice if you could do something like</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">A.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:include</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:b</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:c</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:d</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:e</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#v1</span></pre></div></div>

<p>? Though this is not even valid ruby code, it actually comes very close to what you can do in Ruby on Rails. To get this right, let&#8217;s take a closer look at the rails associations within the class definitions:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> A <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  belongs_to <span style="color:#ff3333; font-weight:bold;">:b</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">class</span> B <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_many <span style="color:#ff3333; font-weight:bold;">:as</span>
  has_many <span style="color:#ff3333; font-weight:bold;">:cs</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">class</span> C <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  belongs_to <span style="color:#ff3333; font-weight:bold;">:b</span>
  has_one <span style="color:#ff3333; font-weight:bold;">:d</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">class</span> D <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  belongs_to <span style="color:#ff3333; font-weight:bold;">:c</span>
  has_and_belongs_to_many <span style="color:#ff3333; font-weight:bold;">:es</span>
<span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">class</span> E <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  has_and_belongs_to_many <span style="color:#ff3333; font-weight:bold;">:ds</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Let&#8217;s try the rails code again, putting an &#8217;s&#8217; after the :c and :e as required by rails in order to denote they are &#8220;many&#8221;-type associations:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">A.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:include</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:b</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:cs</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:d</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:es</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#v2</span></pre></div></div>

<p>That&#8217;s closer, but still not valid ruby code. To fix that, think of the => operator as being right-associative, and instead of putting in parentheses (), put in curly braces {} in order to create nested hashes:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">A.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>, <span style="color:#ff3333; font-weight:bold;">:include</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:b <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:cs <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>:d <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:es</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#v3</span></pre></div></div>

<p>That&#8217;s it! Looking in the logs, we see that this only produced a single query, with all the desired SQL joins:</p>
<p><code>A Load Including Associations (0.001088)   SELECT `as`.`id` AS t0_r0, `as`.`b_id` AS t0_r1, `bs`.`id` AS t1_r0, `cs`.`id` AS t2_r0, `cs`.`b_id` AS t2_r1, `cs`.`d_id` AS t2_r2, `ds`.`id` AS t3_r0, `ds`.`c_id` AS t3_r1, `es`.`id` AS t4_r0 FROM `as` LEFT OUTER JOIN `bs` ON `bs`.id = `as`.b_id LEFT OUTER JOIN `cs` ON cs.b_id = bs.id LEFT OUTER JOIN `ds` ON ds.c_id = cs.id LEFT OUTER JOIN `ds_es` ON `ds_es`.d_id = `ds`.id LEFT OUTER JOIN `es` ON `es`.id = `ds_es`.e_id</code></p>
<p>With this tool in mind, you can use this in any ActiveRecord function that accepts the :include option to reduce the number of times the rails app hits the database, and ultimately speed up your rails application.</p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.xcombinator.com%2F2008%2F04%2F08%2Fchaining-includes-in-rails-to-reduce-the-number-of-sql-queries%2F&amp;title=Chaining%20%3Ainclude%27s%20in%20Rails%20to%20reduce%20the%20number%20of%20SQL%20queries&amp;notes=Say%20you%20have%20the%20following%20data%20model%0D%0A%0D%0A%0D%0A%0D%0Aand%20you%20want%20to%20execute%20a%20single%20query%20that%20returns%20all%20the%20data%20at%20once%20within%20the%20ActiveRecord%20tables%2C%20with%20the%20proper%20rails%20associations%20between%20them.%20Wouldn%27t%20it%20be%20nice%20if%20you%20could%20do%20something%20like%0D" title="del.icio.us"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F08%2Fchaining-includes-in-rails-to-reduce-the-number-of-sql-queries%2F&amp;title=Chaining%20%3Ainclude%27s%20in%20Rails%20to%20reduce%20the%20number%20of%20SQL%20queries" title="Reddit"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F08%2Fchaining-includes-in-rails-to-reduce-the-number-of-sql-queries%2F" title="Technorati"><img src="http://www.xcombinator.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=Chaining%20%3Ainclude%27s%20in%20Rails%20to%20reduce%20the%20number%20of%20SQL%20queries%20-%20http%3A%2F%2Fwww.xcombinator.com%2F2008%2F04%2F08%2Fchaining-includes-in-rails-to-reduce-the-number-of-sql-queries%2F" title="Twitter"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F08%2Fchaining-includes-in-rails-to-reduce-the-number-of-sql-queries%2F&amp;t=Chaining%20%3Ainclude%27s%20in%20Rails%20to%20reduce%20the%20number%20of%20SQL%20queries" title="Facebook"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F08%2Fchaining-includes-in-rails-to-reduce-the-number-of-sql-queries%2F&amp;title=Chaining%20%3Ainclude%27s%20in%20Rails%20to%20reduce%20the%20number%20of%20SQL%20queries&amp;annotation=Say%20you%20have%20the%20following%20data%20model%0D%0A%0D%0A%0D%0A%0D%0Aand%20you%20want%20to%20execute%20a%20single%20query%20that%20returns%20all%20the%20data%20at%20once%20within%20the%20ActiveRecord%20tables%2C%20with%20the%20proper%20rails%20associations%20between%20them.%20Wouldn%27t%20it%20be%20nice%20if%20you%20could%20do%20something%20like%0D" title="Google Bookmarks"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F08%2Fchaining-includes-in-rails-to-reduce-the-number-of-sql-queries%2F&amp;t=Chaining%20%3Ainclude%27s%20in%20Rails%20to%20reduce%20the%20number%20of%20SQL%20queries" title="HackerNews"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F08%2Fchaining-includes-in-rails-to-reduce-the-number-of-sql-queries%2F&amp;partner=sociable" title="PDF"><img src="http://www.xcombinator.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.xcombinator.com/feed/" title="RSS"><img src="http://www.xcombinator.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://www.xcombinator.com/2008/04/08/chaining-includes-in-rails-to-reduce-the-number-of-sql-queries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>the symlink trick</title>
		<link>http://www.xcombinator.com/2008/04/04/the-symlink-trick/</link>
		<comments>http://www.xcombinator.com/2008/04/04/the-symlink-trick/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 03:35:28 +0000</pubDate>
		<dc:creator>Nate Murray</dc:creator>
				<category><![CDATA[deployment]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://www.xcombinator.com/2008/04/04/the-symlink-trick/</guid>
		<description><![CDATA[Courtenay writes on scaling rails applications at Caboo.se.  He says:
 Take a look at your logs: are you performing over 10 database calls per request? You need to fix this. Are you performing over 90? You&#8217;re a dumba**.

 Today viewed the logs of a rails application I am writing. To calculate one particular page [...]]]></description>
			<content:encoded><![CDATA[<p>Courtenay writes on scaling rails applications at <a href="http://www.caboo.se/articles/2007/7/29/scale-rails-from-one-box-to-three-four-and-five">Caboo.se</a>.  He says:</p>
<blockquote><p> Take a look at your logs: are you performing over 10 database calls per request? You need to fix this. Are you performing over 90? You&#8217;re a dumba**.</p>
</blockquote>
<p> Today viewed the logs of a rails application I am writing. To calculate one particular page I was performing <i>31,211</i> <tt>SELECT</tt> requests and the page took <tt>1m7.091s</tt> to generate.  <i>Ouch</i>.</p>
<p>After an hour of tweaking, <a href="http://www.xcombinator.com/2008/04/01/simple-rails-log-query-analyzer/">optimizing queries</a>, and <a href="http://railsexpress.de/blog/articles/2005/11/06/the-case-for-piggy-backed-attributes">piggy-backing</a> some attributes I was able to get down to 9,839 queries and the page rendered in <tt>0m16.958s</tt>. While this may be respectable in terms of improvment, but atrocious according to Courtenay&#8217;s benchmark. (I think they have a word for systems that take over 9&nbsp;thousand queries to generate a single page, but I won&#8217;t repeat it here.)</p>
<p>Fortunately, caching the entire page makes sense functionally. However, one problem with Rails&#8217; built-in caching is that before the page is cached the first person to hit this page will be forced wait 17 seconds for the page to render (assuming no further optimization). In the case of a high amount of traffic, hundreds of visitors to the site will pile up and many will be dropped. It&#8217;s the dreaded cache-gap.</p>
<p>Steve Conover at Pivitoal Labs has a great technique for dealing with this kind of issue that he calls <a href="http://pivots.pivotallabs.com/users/steve/blog/articles/262-rails-slashdotted-no-problem">the symlink trick</a>. A variation on Steve&#8217;s idea goes like this:</p>
<ul>
<li>Symlink <tt>index.html</tt> to <tt>index.html.current</tt>.</li>
<li>When <tt>index.html.current</tt> is out of date, generate <tt>index.html.new</tt></li>
<li>Have cron check the cache every 2 minutes and move <tt>index.html.new</tt> over <tt>index.html.current</tt></li>
</ul>
<p>Because *nix <tt>mv</tt> is atomic there is no gap where the cached page is deleted and then requests are waiting for the page to be regenerated. Below is a diagram of the process.</p>
<p><img src="http://farm3.static.flickr.com/2280/2389077412_4671b8a7db_o.png" width="415" height="733" alt="symlink_trick" /></p>
<p>The great thing is that this caching technique is general and can be applied to any web application, not just Rails.</p>
<p>Share:</p>
<p>	<a rel="nofollow"  href="http://delicious.com/post?url=http%3A%2F%2Fwww.xcombinator.com%2F2008%2F04%2F04%2Fthe-symlink-trick%2F&amp;title=the%20symlink%20trick&amp;notes=Courtenay%20writes%20on%20scaling%20rails%20applications%20at%20Caboo.se.%20%20He%20says%3A%0D%0A%0D%0A%20Take%20a%20look%20at%20your%20logs%3A%20are%20you%20performing%20over%2010%20database%20calls%20per%20request%3F%20You%20need%20to%20fix%20this.%20Are%20you%20performing%20over%2090%3F%20You%27re%20a%20dumba%2A%2A.%0D%0A%0D%0A%20Today%20viewed%20the%20logs%20o" title="del.icio.us"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F04%2Fthe-symlink-trick%2F&amp;title=the%20symlink%20trick" title="Reddit"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F04%2Fthe-symlink-trick%2F" title="Technorati"><img src="http://www.xcombinator.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=the%20symlink%20trick%20-%20http%3A%2F%2Fwww.xcombinator.com%2F2008%2F04%2F04%2Fthe-symlink-trick%2F" title="Twitter"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F04%2Fthe-symlink-trick%2F&amp;t=the%20symlink%20trick" title="Facebook"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F04%2Fthe-symlink-trick%2F&amp;title=the%20symlink%20trick&amp;annotation=Courtenay%20writes%20on%20scaling%20rails%20applications%20at%20Caboo.se.%20%20He%20says%3A%0D%0A%0D%0A%20Take%20a%20look%20at%20your%20logs%3A%20are%20you%20performing%20over%2010%20database%20calls%20per%20request%3F%20You%20need%20to%20fix%20this.%20Are%20you%20performing%20over%2090%3F%20You%27re%20a%20dumba%2A%2A.%0D%0A%0D%0A%20Today%20viewed%20the%20logs%20o" title="Google Bookmarks"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F04%2Fthe-symlink-trick%2F&amp;t=the%20symlink%20trick" title="HackerNews"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F04%2Fthe-symlink-trick%2F&amp;partner=sociable" title="PDF"><img src="http://www.xcombinator.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.xcombinator.com/feed/" title="RSS"><img src="http://www.xcombinator.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://www.xcombinator.com/2008/04/04/the-symlink-trick/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Simple Rails Log Query Analyzer</title>
		<link>http://www.xcombinator.com/2008/04/01/simple-rails-log-query-analyzer/</link>
		<comments>http://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F&amp;title=Simple%20Rails%20Log%20Query%20Analyzer" title="Reddit"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F" title="Technorati"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F" title="Twitter"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F&amp;t=Simple%20Rails%20Log%20Query%20Analyzer" title="Facebook"><img src="http://www.xcombinator.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%2Fwww.xcombinator.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://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F&amp;t=Simple%20Rails%20Log%20Query%20Analyzer" title="HackerNews"><img src="http://www.xcombinator.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%2Fwww.xcombinator.com%2F2008%2F04%2F01%2Fsimple-rails-log-query-analyzer%2F&amp;partner=sociable" title="PDF"><img src="http://www.xcombinator.com/wp-content/plugins/sociable/images/pdf.png" title="PDF" alt="PDF" class="sociable-hovers" /></a><br />
	<a rel="nofollow"  href="http://www.xcombinator.com/feed/" title="RSS"><img src="http://www.xcombinator.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://www.xcombinator.com/2008/04/01/simple-rails-log-query-analyzer/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.097 seconds -->
