<?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>Erics Tech Blog &#187; Ruby</title>
	<atom:link href="http://eric.lubow.org/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://eric.lubow.org</link>
	<description>Thoughts, musings, and other idealistic (sometimes useful) systems and development hoopla.</description>
	<lastBuildDate>Fri, 18 Nov 2011 14:56:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<item>
		<title>Benchmarking in jRuby NYC.RB Talk</title>
		<link>http://eric.lubow.org/2010/ruby/jruby/benchmarking-in-jruby-nyc-rb-talk/</link>
		<comments>http://eric.lubow.org/2010/ruby/jruby/benchmarking-in-jruby-nyc-rb-talk/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 16:32:01 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[jRuby]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=806</guid>
		<description><![CDATA[Here are the slides from my presentation on jRuby during the NYC.rb talk on 11/9. NYC.rb &#8211; Nov 2010 &#8211; Benchmarking jRuby Related posts:JSON Benchmarks in jRuby]]></description>
			<content:encoded><![CDATA[<p>Here are the slides from my presentation on jRuby during the NYC.rb talk on 11/9.</p>
<p><a href='http://eric.lubow.org/wp-content/uploads/2010/11/NYC.rb-Nov-2010-Benchmarking-jRuby.ppt'>NYC.rb &#8211; Nov 2010 &#8211; Benchmarking jRuby</a></p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/ruby/jruby/json-benchmarks-in-jruby/' rel='bookmark' title='JSON Benchmarks in jRuby'>JSON Benchmarks in jRuby</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/ruby/jruby/benchmarking-in-jruby-nyc-rb-talk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JSON Benchmarks in jRuby</title>
		<link>http://eric.lubow.org/2010/ruby/jruby/json-benchmarks-in-jruby/</link>
		<comments>http://eric.lubow.org/2010/ruby/jruby/json-benchmarks-in-jruby/#comments</comments>
		<pubDate>Mon, 25 Oct 2010 07:45:12 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[jRuby]]></category>
		<category><![CDATA[benchmarks]]></category>
		<category><![CDATA[jruby]]></category>
		<category><![CDATA[json]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=793</guid>
		<description><![CDATA[I am in the process of switching a major application from MRI Ruby (specifically 1.8.7-p302) using many C extensions to jRuby (currently trying 1.5.3-master). In my application, performance is extremely important. It is so important in fact, that I will be writing about some of my experiences in troubleshooting the speed and getting those important [...]]]></description>
			<content:encoded><![CDATA[<p>I am in the process of switching a major application from MRI Ruby (specifically 1.8.7-p302) using many C extensions to jRuby (currently trying 1.5.3-master).  In my application, performance is extremely important.  It is so important in fact, that I will be writing about some of my experiences in troubleshooting the speed and getting those important milliseconds back.  When I am trying to keep an entire transaction from start to finish under 40ms and just the decoding of a JSON object into a Ruby object in jRuby takes roughly 30ms using json_pure, we may have to explore other avenues.<br />
<span id="more-793"></span><br />
Just to verify that JSON was indeed as slow as I thought it was, here is a quick benchmark of it:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'json/pure'</span><br />
<span style="color:#CC00FF; font-weight:bold;">Benchmark</span>.<span style="color:#9900CC;">bmbm</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> <br />
&nbsp; x.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;parse:&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> JSON.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>json<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>JSON Pure Results:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Rehearsal ------------------------------------------<br />
parse: &nbsp; 0.255000 &nbsp; 0.000000 &nbsp; 0.255000 ( &nbsp;0.255000)<br />
--------------------------------- total: 0.255000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
parse: &nbsp; 0.024000 &nbsp; 0.000000 &nbsp; 0.024000 ( &nbsp;0.024000)<br />
parse: &nbsp; 0.017000 &nbsp; 0.000000 &nbsp; 0.017000 ( &nbsp;0.017000)<br />
parse: &nbsp; 0.032000 &nbsp; 0.000000 &nbsp; 0.032000 ( &nbsp;0.032000)<br />
parse: &nbsp; 0.042000 &nbsp; 0.000000 &nbsp; 0.042000 ( &nbsp;0.041000)<br />
<br />
Rehearsal -------------------------------------------<br />
encode: &nbsp; 0.036000 &nbsp; 0.000000 &nbsp; 0.036000 ( &nbsp;0.035000)<br />
---------------------------------- total: 0.036000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
encode: &nbsp; 0.010000 &nbsp; 0.000000 &nbsp; 0.010000 ( &nbsp;0.010000)<br />
encode: &nbsp; 0.007000 &nbsp; 0.000000 &nbsp; 0.007000 ( &nbsp;0.006000)<br />
encode: &nbsp; 0.006000 &nbsp; 0.000000 &nbsp; 0.006000 ( &nbsp;0.006000)<br />
encode: &nbsp; 0.017000 &nbsp; 0.000000 &nbsp; 0.017000 ( &nbsp;0.016000)</div></div>
<p>That wasn&#8217;t so great.  We&#8217;re looking at about 30ms on average to decode and an additional about 10ms to re-encode.  If we want to keep our total transactions to 40ms and we haven&#8217;t even done anything with our data, we&#8217;re in pretty bad shape.  Let&#8217;s try the same thing again, only this time with <a href="http://github.com/mernen/json-jruby">json-jruby</a>.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'json/pure'</span><br />
<span style="color:#CC00FF; font-weight:bold;">Benchmark</span>.<span style="color:#9900CC;">bmbm</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> <br />
&nbsp; x.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;parse:&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> JSON.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>json<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>JSON-jRuby Results:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Rehearsal ------------------------------------------<br />
parse: &nbsp; 0.009000 &nbsp; 0.000000 &nbsp; 0.009000 ( &nbsp;0.008000)<br />
--------------------------------- total: 0.009000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
parse: &nbsp; 0.003000 &nbsp; 0.000000 &nbsp; 0.003000 ( &nbsp;0.002000)<br />
parse: &nbsp; 0.007000 &nbsp; 0.000000 &nbsp; 0.007000 ( &nbsp;0.003000)<br />
parse: &nbsp; 0.003000 &nbsp; 0.000000 &nbsp; 0.003000 ( &nbsp;0.003000)<br />
parse: &nbsp; 0.002000 &nbsp; 0.000000 &nbsp; 0.002000 ( &nbsp;0.002000)<br />
<br />
Rehearsal -------------------------------------------<br />
encode: &nbsp; 0.009000 &nbsp; 0.000000 &nbsp; 0.009000 ( &nbsp;0.009000)<br />
---------------------------------- total: 0.009000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
encode: &nbsp; 0.001000 &nbsp; 0.000000 &nbsp; 0.001000 ( &nbsp;0.001000)<br />
encode: &nbsp; 0.001000 &nbsp; 0.000000 &nbsp; 0.001000 ( &nbsp;0.001000)<br />
encode: &nbsp; 0.001000 &nbsp; 0.000000 &nbsp; 0.001000 ( &nbsp;0.001000)<br />
encode: &nbsp; 0.001000 &nbsp; 0.000000 &nbsp; 0.001000 ( &nbsp;0.001000)</div></div>
<p>Much better, right.  We&#8217;re averaging 2.5ms to decode it and 1ms to encode it.  That&#8217;s much more tolerable.</p>
<p>Just for poops and laughs, we should compare this to our MRI version with C bindings (the version we were using before), the super fast <a href="http://github.com/brianmario/yajl-ruby">yajl-ruby</a> gem.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'yajl'</span><br />
parser = <span style="color:#6666ff; font-weight:bold;">Yajl::Parser</span>.<span style="color:#9900CC;">new</span><br />
<span style="color:#CC00FF; font-weight:bold;">Benchmark</span>.<span style="color:#9900CC;">bm</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
&nbsp; x.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;parse:&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> parser.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>json<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
parsed = parser.<span style="color:#9900CC;">parse</span><span style="color:#006600; font-weight:bold;">&#40;</span>json<span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />
<span style="color:#CC00FF; font-weight:bold;">Benchmark</span>.<span style="color:#9900CC;">bm</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>x<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; x.<span style="color:#9900CC;">report</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;encode:&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> parsed.<span style="color:#9900CC;">to_json</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>And here are the MRI Yajl-ruby results:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Rehearsal ------------------------------------------<br />
parse: &nbsp; 0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000159)<br />
--------------------------------- total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
parse: &nbsp;0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000101)<br />
parse: &nbsp;0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000093)<br />
parse: &nbsp;0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000098)<br />
parse: &nbsp;0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000093)<br />
<br />
&nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
encode: &nbsp;0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000063)<br />
encode: &nbsp;0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000063)<br />
encode: &nbsp;0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000064)<br />
encode: &nbsp;0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000065)</div></div>
<p>These benchmarks are by no means exact, but they do give you a feel for the fact that jRuby is slower than MRI with C extensions.  The comparison is essentially 3.5ms round trip in jRuby and about 1.5ms in MRI.  It might not seem like a lot, but when every millisecond counts, there is a lot that can happen in those extra 2 milliseconds that could be available every transaction.</p>
<p><strong>Note:</strong> I reran the code by hand and formatted the results by hand, so the code won&#8217;t exactly produce the results above.  These benchmarks were all done on my 2008 MacBook Pro with 4G of RAM and an Intel 2.53GHz Core 2 Duo.</p>
<p><strong>UPDATE:</strong> It has been pointed out to me that I didn&#8217;t take advantage of jRuby&#8217;s hotspot feature (Thanks NickSeiger and Charles Remes).  Hotspot basically kicks in after it figures out the best ways to optimize the code.  So here are some new results and it&#8217;s safe to note that json-jruby is so fast, that the computer can&#8217;t time it.</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:450px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">jRuby json_pure:<br />
Rehearsal ------------------------------------------<br />
parse: &nbsp; 0.001000 &nbsp; 0.000000 &nbsp; 0.001000 ( &nbsp;0.001000)<br />
--------------------------------- total: 0.001000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
parse: &nbsp; 0.001000 &nbsp; 0.000000 &nbsp; 0.001000 ( &nbsp;0.000000)<br />
Rehearsal -------------------------------------------<br />
encode: &nbsp; 0.001000 &nbsp; 0.000000 &nbsp; 0.001000 ( &nbsp;0.001000)<br />
---------------------------------- total: 0.001000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
encode: &nbsp; 0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000000)<br />
<br />
jRuby json-jruby:<br />
Rehearsal ------------------------------------------<br />
parse: &nbsp; 0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000000)<br />
--------------------------------- total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
parse: &nbsp; 0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000000)<br />
Rehearsal -------------------------------------------<br />
encode: &nbsp; 0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000000)<br />
---------------------------------- total: 0.000000sec<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; user &nbsp; &nbsp; system &nbsp; &nbsp; &nbsp;total &nbsp; &nbsp; &nbsp; &nbsp;real<br />
encode: &nbsp; 0.000000 &nbsp; 0.000000 &nbsp; 0.000000 ( &nbsp;0.000000)</div></div>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/ruby/jruby/benchmarking-in-jruby-nyc-rb-talk/' rel='bookmark' title='Benchmarking in jRuby NYC.RB Talk'>Benchmarking in jRuby NYC.RB Talk</a></li>
<li><a href='http://eric.lubow.org/2011/hadoop/pig-queries-parsing-json-on-amazons-elastic-map-reduce-using-s3-data/' rel='bookmark' title='Pig Queries Parsing JSON on Amazons Elastic Map Reduce Using S3 Data'>Pig Queries Parsing JSON on Amazons Elastic Map Reduce Using S3 Data</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/ruby/jruby/json-benchmarks-in-jruby/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Hash Autovivification in Ruby</title>
		<link>http://eric.lubow.org/2010/ruby/hash-autovivification-in-ruby/</link>
		<comments>http://eric.lubow.org/2010/ruby/hash-autovivification-in-ruby/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 11:00:38 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Perl]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=789</guid>
		<description><![CDATA[One of the features that I miss most from my Perl days (and to be honest, there isn&#8217;t a whole lot I miss from my Perl days) is autovivification. For more information on what it is, read the wikipedia page on it here. I stumbled across a post that talks about mimicking Perl&#8217;s autovivification here. [...]]]></description>
			<content:encoded><![CDATA[<p>One of the features that I miss most from my Perl days (and to be honest, there isn&#8217;t a whole lot I miss from my Perl days) is autovivification.  For more information on what it is, read the <a href="http://wikipedia.org">wikipedia</a> page on it <a href="http://en.wikipedia.org/wiki/Autovivification">here</a>.<br />
<span id="more-789"></span></p>
<p>I stumbled across a post that talks about mimicking Perl&#8217;s autovivification <a href="http://moonbase.rydia.net/mental/blog/programming/ruby/autovivification.html">here</a>. But I wanted a data structure (specifically a hash) that would be created on demand.  So here is a class that creates a recursive hash.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> RecursiveHash <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;">Hash</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> initialize<br />
&nbsp; &nbsp; recurse_hash = <span style="color:#CC0066; font-weight:bold;">proc</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>h,k<span style="color:#006600; font-weight:bold;">|</span> h<span style="color:#006600; font-weight:bold;">&#91;</span>k<span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#CC00FF; font-weight:bold;">Hash</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>recurse_hash<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">super</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&amp;</span>recurse_hash<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p></code></p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2007/perl/creating-a-process-table-hash-in-perl/' rel='bookmark' title='Creating a Process Table hash in Perl'>Creating a Process Table hash in Perl</a></li>
<li><a href='http://eric.lubow.org/2010/ruby/interesting-object-methods-in-ruby/' rel='bookmark' title='Interesting Object Methods in Ruby'>Interesting Object Methods in Ruby</a></li>
<li><a href='http://eric.lubow.org/2010/system-administration/creating-configuration-files-with-ruby-templates/' rel='bookmark' title='Creating Configuration Files With Ruby Templates'>Creating Configuration Files With Ruby Templates</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/ruby/hash-autovivification-in-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Interesting Object Methods in Ruby</title>
		<link>http://eric.lubow.org/2010/ruby/interesting-object-methods-in-ruby/</link>
		<comments>http://eric.lubow.org/2010/ruby/interesting-object-methods-in-ruby/#comments</comments>
		<pubDate>Mon, 27 Sep 2010 07:45:49 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=786</guid>
		<description><![CDATA[This little Rubyism is something that I use frequently for debugging my objects. I add a method to every object to show only the interesting methods. What do I mean by interesting methods? In my .irbrc file, I have the following lines of code: class Object &#160; def i_methods &#160; &#160; &#40;self.methods - Object.new.methods&#41;.sort &#160; [...]]]></description>
			<content:encoded><![CDATA[<p>This little Rubyism is something that I use frequently for debugging my objects.  I add a method to every object to show only the <em>interesting</em> methods. What do I mean by <em>interesting</em> methods?<br />
<span id="more-786"></span><br />
In my <strong>.irbrc</strong> file, I have the following lines of code:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC00FF; font-weight:bold;">Object</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> i_methods<br />
&nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">methods</span> <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#CC00FF; font-weight:bold;">Object</span>.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">methods</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">sort</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>Using the Ruby notion that classes are always open, it opens up the base class Object (of which almost everything in Ruby inherits) and adds a method called <strong>i_methods</strong>.  This shows all methods available on the object minus the methods that come with an object by default.  It&#8217;s in my <strong>.irbrc</strong> file so I can append this method at any time when I am working in IRB.</p>
<p>Other than that, it&#8217;s a handy little concept to remember even if you&#8217;re debugging.  Just doing the following can help you deal with those pesky NoMethod errors on objects:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">p</span> <span style="color:#006600; font-weight:bold;">&#40;</span>MyObject.<span style="color:#9900CC;">methods</span> <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#CC00FF; font-weight:bold;">Object</span>.<span style="color:#9900CC;">new</span>.<span style="color:#9900CC;">methods</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">sort</span></div></div>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2009/ruby/parsing-ini-files-with-ruby/' rel='bookmark' title='Parsing Ini Files With Ruby'>Parsing Ini Files With Ruby</a></li>
<li><a href='http://eric.lubow.org/2010/system-administration/creating-configuration-files-with-ruby-templates/' rel='bookmark' title='Creating Configuration Files With Ruby Templates'>Creating Configuration Files With Ruby Templates</a></li>
<li><a href='http://eric.lubow.org/2010/ruby/hash-autovivification-in-ruby/' rel='bookmark' title='Hash Autovivification in Ruby'>Hash Autovivification in Ruby</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/ruby/interesting-object-methods-in-ruby/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Stopping Curb From Segfaulting</title>
		<link>http://eric.lubow.org/2010/ruby/stopping-curb-from-segfaulting/</link>
		<comments>http://eric.lubow.org/2010/ruby/stopping-curb-from-segfaulting/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 11:30:00 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[homebrew]]></category>
		<category><![CDATA[rubygems]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=759</guid>
		<description><![CDATA[While trying to get the curb gem up and running using Ruby 1.8.7p174, I kept getting segmentation faults. I Google&#8217;d around and really wasn&#8217;t able to come up with much other than lots of people saying not to use ports here. Since I don&#8217;t use Mac Ports, I use Homebrew, I figured this wasn&#8217;t an [...]]]></description>
			<content:encoded><![CDATA[<p>While trying to get the <a href="http://curb.rubyforge.org/">curb</a> gem up and running using Ruby 1.8.7p174, I kept getting segmentation faults.  I Google&#8217;d around and really wasn&#8217;t able to come up with much other than lots of people saying not to use ports here.  Since I don&#8217;t use <a href="http://www.macports.org/">Mac Ports</a>, I use <a href="http://github.com/mxcl/homebrew">Homebrew</a>, I figured this wasn&#8217;t an issue.  I had also recently installed the latest XCode so I incorrectly assumed there was no issue there either.  (Note: I am running on a freshly upgraded version of Mac OS X Snow Leopard).<br />
<span id="more-759"></span><br />
Since everything built correctly, I just assumed it would work correctly.  Here it is obviously not doing so.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p174 <span style="color:#006600; font-weight:bold;">&gt;</span> &nbsp; <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'curb'</span><br />
<span style="color:#006600; font-weight:bold;">/</span>Users<span style="color:#006600; font-weight:bold;">/</span>elubow<span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#9900CC;">rvm</span><span style="color:#006600; font-weight:bold;">/</span>gems<span style="color:#006600; font-weight:bold;">/</span>ruby<span style="color:#006600; font-weight:bold;">-</span>1.8.7<span style="color:#006600; font-weight:bold;">-</span>p174<span style="color:#006600; font-weight:bold;">/</span>gems<span style="color:#006600; font-weight:bold;">/</span>curb<span style="color:#006600; font-weight:bold;">-</span>0.7.7.1<span style="color:#006600; font-weight:bold;">/</span>lib<span style="color:#006600; font-weight:bold;">/</span>curb_core.<span style="color:#9900CC;">bundle</span>: <span style="color:#006600; font-weight:bold;">&#91;</span>BUG<span style="color:#006600; font-weight:bold;">&#93;</span> Segmentation fault<br />
ruby 1.8.7 <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2009</span><span style="color:#006600; font-weight:bold;">-</span>06<span style="color:#006600; font-weight:bold;">-</span><span style="color:#006666;">12</span> patchlevel <span style="color:#006666;">174</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>i686<span style="color:#006600; font-weight:bold;">-</span>darwin10.4.0<span style="color:#006600; font-weight:bold;">&#93;</span><br />
Abort <span style="color:#CC0066; font-weight:bold;">trap</span></div></div>
<p>So I narrowed it down to what I believe is an issue with the curl headers.  The solution is to install a new curl library.  Since I wanted to do it the Homebrew way, and Homebrew doesn&#8217;t have curl by default, here is what I did.</p>
<p>Copy the Homebrew Formula code from <a href="http://github.com/adamv/homebrew/blob/duplicates/Library/Formula/curl.rb">http://github.com/adamv/homebrew/blob/duplicates/Library/Formula/curl.rb</a> into a file named <strong>curl.rb</strong> in your formula directory (mine is <em>/usr/local/Library/Formula/</em>). You should then be able to:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">elubow<span style="color: #000000; font-weight: bold;">@</span>beacon tmp$ brew <span style="color: #c20cb9; font-weight: bold;">install</span> curl<br />
==<span style="color: #000000; font-weight: bold;">&gt;</span> Downloading http:<span style="color: #000000; font-weight: bold;">//</span>curl.haxx.se<span style="color: #000000; font-weight: bold;">/</span>download<span style="color: #000000; font-weight: bold;">/</span>curl-7.21.0.tar.bz2<br />
<span style="color: #666666; font-style: italic;">######################################################################## 100.0%</span><br />
==<span style="color: #000000; font-weight: bold;">&gt;</span> .<span style="color: #000000; font-weight: bold;">/</span>configure <span style="color: #660033;">--prefix</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>curl<span style="color: #000000; font-weight: bold;">/</span>7.21.0 <span style="color: #660033;">--disable-debug</span> <span style="color: #660033;">--disable-dependency-track</span><br />
==<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span><br />
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>Cellar<span style="color: #000000; font-weight: bold;">/</span>curl<span style="color: #000000; font-weight: bold;">/</span>7.21.0: <span style="color: #000000;">72</span> files, 1.8M, built <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000;">3.6</span> minutes</div></div>
<p>Don&#8217;t forget to logout and log back into the shell so the new version of curl is available:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ curl <span style="color: #660033;">--version</span><br />
curl 7.21.0 <span style="color: #7a0874; font-weight: bold;">&#40;</span>x86_64-apple-darwin10.4.0<span style="color: #7a0874; font-weight: bold;">&#41;</span> libcurl<span style="color: #000000; font-weight: bold;">/</span>7.21.0 OpenSSL<span style="color: #000000; font-weight: bold;">/</span>0.9.8l zlib<span style="color: #000000; font-weight: bold;">/</span>1.2.3 libssh2<span style="color: #000000; font-weight: bold;">/</span>1.2.2<br />
Protocols: dict <span style="color: #c20cb9; font-weight: bold;">file</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span> ftps http https imap imaps ldap ldaps pop3 pop3s rtsp <span style="color: #c20cb9; font-weight: bold;">scp</span> sftp smtp smtps telnet tftp <br />
Features: IPv6 Largefile NTLM SSL libz</div></div>
<p>Now you have to uninstall and reinstall the curb gem.  The easiest way that I found (since I have bundler installed) was to do <strong>bundle show curb</strong> to find out where the gem is located.  I removed the directory and reran <strong>bundle install</strong> (or <strong>gem install curb</strong> if you don&#8217;t have bundler).</p>
<p>Because I am using <a href="http://rvm.beginrescueend.com/">rvm (Ruby Version Manager)</a>, I actually encountered this issue with 1.9.1p378 as well.  This fixed the issue for both versions.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2011/security/fixing-centos-root-certificate-authority-issues/' rel='bookmark' title='Fixing CentOS Root Certificate Authority Issues'>Fixing CentOS Root Certificate Authority Issues</a></li>
<li><a href='http://eric.lubow.org/2009/perl/mac-perl-problems-after-feb-update/' rel='bookmark' title='Mac Perl Problems After Feb Update'>Mac Perl Problems After Feb Update</a></li>
<li><a href='http://eric.lubow.org/2010/mac/capistrano-hangs-on-mac-os-x-leopard/' rel='bookmark' title='Capistrano Hangs on Mac OS X Leopard'>Capistrano Hangs on Mac OS X Leopard</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/ruby/stopping-curb-from-segfaulting/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Creating Configuration Files With Ruby Templates</title>
		<link>http://eric.lubow.org/2010/system-administration/creating-configuration-files-with-ruby-templates/</link>
		<comments>http://eric.lubow.org/2010/system-administration/creating-configuration-files-with-ruby-templates/#comments</comments>
		<pubDate>Wed, 30 Jun 2010 11:45:58 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[system]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=749</guid>
		<description><![CDATA[I recently had a very repetitive configuration file that needed creating. There were approximately 50 config blocks of 10 lines each with only the host name changing with each block. So I decided to take a shortcut and do it in Ruby using ERB templates. This is so easy and literally save me hours worth [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had a very repetitive configuration file that needed creating.  There were approximately 50 config blocks of 10 lines each with only the host name changing with each block.  So I decided to take a shortcut and do it in Ruby using ERB templates. This is so easy and literally save me hours worth of work.<br />
<span id="more-749"></span><br />
I started out by creating a template for the <a href="http://www.rsyslog.com/">rsyslog</a> block I wanted to replicate.  In the full version of the script, there is an additional section for the access.log file which you&#8217;ll see below.  If you know Rails, then this template style should look very familiar.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rsyslog_block = <span style="color:#006600; font-weight:bold;">%</span><span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#008000; font-style:italic;"># &lt; %= virtual_host %&gt;</span><br />
<span style="color:#008000; font-style:italic;">#</span><br />
<span style="color:#ff6633; font-weight:bold;">$InputFileName</span> <span style="color:#006600; font-weight:bold;">/</span>var<span style="color:#006600; font-weight:bold;">/</span>log<span style="color:#006600; font-weight:bold;">/</span>httpd<span style="color:#006600; font-weight:bold;">/&lt;</span> <span style="color:#006600; font-weight:bold;">%</span>= virtual_host <span style="color:#006600; font-weight:bold;">%&gt;-</span>error.<span style="color:#9900CC;">log</span><br />
<span style="color:#ff6633; font-weight:bold;">$InputFileTag</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#006600; font-weight:bold;">%</span>= virtual_host <span style="color:#006600; font-weight:bold;">%&gt;</span>_error<br />
<span style="color:#ff6633; font-weight:bold;">$InputFileStateFile</span> stat<span style="color:#006600; font-weight:bold;">-&lt;</span> <span style="color:#006600; font-weight:bold;">%</span>= virtual_host <span style="color:#006600; font-weight:bold;">%&gt;-</span>error.<span style="color:#9900CC;">log</span><br />
<span style="color:#ff6633; font-weight:bold;">$InputFileSeverity</span> info<br />
<span style="color:#ff6633; font-weight:bold;">$InputFileFacility</span> local5<br />
<span style="color:#ff6633; font-weight:bold;">$InputRunFileMonitor</span><br />
<br />
<span style="color:#006600; font-weight:bold;">&#125;</span></div></div>
<p>The below block of code creates a configuration block (above) for each of virtual hosts in the array and then prints it to the screen.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; vhost.<span style="color:#9900CC;">com</span><br />
&nbsp; &nbsp; bar.<span style="color:#9900CC;">myhost</span>.<span style="color:#9900CC;">com</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>virtual_host<span style="color:#006600; font-weight:bold;">|</span> &nbsp;<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#CC00FF; font-weight:bold;">ERB</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> rsyslog_block <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">result</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC0066; font-weight:bold;">binding</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div></div>
<p>This is going to produce the following block which you can then pipe to a file:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">...Removed for brevity...<br />
#<br />
# bar.myhost.com<br />
#<br />
$InputFileName /var/log/httpd/bar.myhost.com-error.log<br />
$InputFileTag bar.myhost.com_error<br />
$InputFileStateFile stat-bar.myhost.com-error.log<br />
$InputFileSeverity info<br />
$InputFileFacility local5<br />
$InputRunFileMonitor</div></div>
<p>Here is the script in its entirety:<br />
<script src="http://gist.github.com/456080.js"></script></p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2009/ruby/parsing-ini-files-with-ruby/' rel='bookmark' title='Parsing Ini Files With Ruby'>Parsing Ini Files With Ruby</a></li>
<li><a href='http://eric.lubow.org/2010/ruby/multiple-input-locations-from-bash-into-ruby/' rel='bookmark' title='Multiple Input Locations From Bash Into Ruby'>Multiple Input Locations From Bash Into Ruby</a></li>
<li><a href='http://eric.lubow.org/2010/ruby/interesting-object-methods-in-ruby/' rel='bookmark' title='Interesting Object Methods in Ruby'>Interesting Object Methods in Ruby</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/system-administration/creating-configuration-files-with-ruby-templates/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Multiple Input Locations From Bash Into Ruby</title>
		<link>http://eric.lubow.org/2010/ruby/multiple-input-locations-from-bash-into-ruby/</link>
		<comments>http://eric.lubow.org/2010/ruby/multiple-input-locations-from-bash-into-ruby/#comments</comments>
		<pubDate>Thu, 13 May 2010 12:00:59 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[bash]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=723</guid>
		<description><![CDATA[I have been trying to figure out how, while using OptionParser to be able to check for files being input on the command line and if they don&#8217;t exist, check other input streams (like Bash). This initially wasn&#8217;t very easy since input streams are blocking. So with a little help from friends (thanks roberto), I [...]]]></description>
			<content:encoded><![CDATA[<p>I have been trying to figure out how, while using <a href="http://ruby-doc.org/stdlib/libdoc/optparse/rdoc/classes/OptionParser.html">OptionParser</a> to be able to check for files being input on the command line and if they don&#8217;t exist, check other input streams (like Bash).  This initially wasn&#8217;t very easy since input streams are blocking.  So with a little help from friends (thanks roberto), I was able to use his method of non-blocking IO and wrap it in a begin/rescue block.  I also took a little advice given in this <a href="http://www.stackoverflow.com">Stack Overflow</a> question called <a href="http://stackoverflow.com/questions/273262/best-practices-with-stdin-in-ruby">Best Practices with STDIN in Ruby.</a><br />
<span id="more-723"></span><br />
First we need to get the file list off the command line and assume that anything left are files.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#0066ff; font-weight:bold;">@opts</span> = OptionParser.<span style="color:#9900CC;">new</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>o<span style="color:#006600; font-weight:bold;">|</span><br />
...<br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#0066ff; font-weight:bold;">@opts</span>.<span style="color:#9900CC;">parse</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>args<span style="color:#006600; font-weight:bold;">&#41;</span><br />
<span style="color:#0066ff; font-weight:bold;">@files</span> = args</div></div>
<p>Since we are using threads, I open up a thread for STDIN and killed it when we run out of input.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'fcntl'</span><br />
threads = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span><br />
<br />
<span style="color:#008000; font-style:italic;"># Set $stdin to be non-blocking</span><br />
<span style="color:#ff6633; font-weight:bold;">$stdin</span>.<span style="color:#9900CC;">fcntl</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">Fcntl::F_SETFL</span>,<span style="color:#6666ff; font-weight:bold;">Fcntl::O_NONBLOCK</span><span style="color:#006600; font-weight:bold;">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<br />
<br />
threads<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#93;</span> = <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">begin</span><br />
&nbsp; &nbsp; <span style="color:#ff6633; font-weight:bold;">$stdin</span>.<span style="color:#9900CC;">each_line</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>line<span style="color:#006600; font-weight:bold;">|</span> &nbsp;<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;STDIN: #{line}&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Errno</span>::EAGAIN<br />
&nbsp; &nbsp; threads.<span style="color:#9900CC;">delete</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">0</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;"># Remove this thread since we won't be reading from $stdin</span><br />
&nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
<span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">run</span></div></div>
<p>Now its time for the files.</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color:#0066ff; font-weight:bold;">@files</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; threads.<span style="color:#9900CC;">push</span> <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color:#008000; font-style:italic;"># do stuff with 'file'</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">&#125;</span><br />
<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
<span style="color:#008000; font-style:italic;"># Put it all together and have the threads run</span><br />
threads.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>thread<span style="color:#006600; font-weight:bold;">|</span> &nbsp;thread.<span style="color:#9900CC;">join</span> <span style="color:#006600; font-weight:bold;">&#125;</span></div></div>
<p>Using these code snippets, you will be able to use input from both files on the command line and STDIN:</p>
<ol>
<li>$ myscript.rb file1 file2</li>
<li>$ cat foo | myscript.rb file1 file2</li>
<li>$ myscript.rb file1 file2 &lt; foo</li>
</ol>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/ruby/testing-ruby/should-i-mock-kernel-exit/' rel='bookmark' title='Should I Mock Kernel#exit'>Should I Mock Kernel#exit</a></li>
<li><a href='http://eric.lubow.org/2009/ruby/parsing-ini-files-with-ruby/' rel='bookmark' title='Parsing Ini Files With Ruby'>Parsing Ini Files With Ruby</a></li>
<li><a href='http://eric.lubow.org/2009/system-administration/git-branch-name-in-your-bash-prompt/' rel='bookmark' title='Git Branch Name in Your Bash Prompt'>Git Branch Name in Your Bash Prompt</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/ruby/multiple-input-locations-from-bash-into-ruby/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Should I Mock Kernel#exit</title>
		<link>http://eric.lubow.org/2010/ruby/testing-ruby/should-i-mock-kernel-exit/</link>
		<comments>http://eric.lubow.org/2010/ruby/testing-ruby/should-i-mock-kernel-exit/#comments</comments>
		<pubDate>Mon, 26 Apr 2010 09:00:44 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Testing]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=695</guid>
		<description><![CDATA[I don&#8217;t know what the right answer is, so any insight would be appreciated. From Googling around, I came across this thread on StackOverflow which talks about Validating exits and aborts in Rspec. I have a few issues with this, namely that I am using shoulda and I don&#8217;t want to validate the exit, I [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know what the right answer is, so any insight would be appreciated.  From Googling around, I came across this thread on <a href="http://www.stackoverflow.com">StackOverflow</a> which talks about <a href="http://stackoverflow.com/questions/1480537/how-can-i-validate-exits-and-aborts-in-rspec">Validating exits and aborts in Rspec</a>. I have a few issues with this, namely that I am using <a href="http://github.com/thoughtbot/shoulda">shoulda</a> and I don&#8217;t want to validate the exit, I want to stop it from happening inside of the test.<br />
<span id="more-695"></span><br />
I have figured out that <strong>rescue</strong>ing a Kernel#exit with afford the same opportunity to test results so I am not sure if mocking it is necessary.  Consider the following code which doesn&#8217;t involve mocking:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:450px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">class</span> Application<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">def</span> thread_cleanup<span style="color:#006600; font-weight:bold;">&#40;</span>threads<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; threads.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>thread<span style="color:#006600; font-weight:bold;">|</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;thread.<span style="color:#9900CC;">kill</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff6633; font-weight:bold;">$stderr</span>.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Terminating...&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#CC0066; font-weight:bold;">exit</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
<br />
&nbsp; &nbsp; &nbsp;<span style="color:#008000; font-style:italic;"># test cases</span><br />
&nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">class</span> ApplicationTest <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;"><span style="color:#6666ff; font-weight:bold;">Test::Unit::TestCase</span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;should <span style="color:#996600;">&quot;kill all threads and exit cleanly&quot;</span> <span style="color:#9966CC; font-weight:bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;threads = <span style="color:#CC0066; font-weight:bold;">Array</span>.<span style="color:#9900CC;">new</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;threads.<span style="color:#9900CC;">push</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#CC00FF; font-weight:bold;">Thread</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#CC0066; font-weight:bold;">sleep</span> <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">begin</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Application.<span style="color:#9900CC;">thread_cleanup</span><span style="color:#006600; font-weight:bold;">&#40;</span>threads<span style="color:#006600; font-weight:bold;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">SystemExit</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;assert_equal <span style="color:#006666;">0</span>, e.<span style="color:#9900CC;">status</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span><br />
&nbsp; &nbsp; &nbsp;<span style="color:#9966CC; font-weight:bold;">end</span></div></div>
<p>Here we <strong>rescue</strong> the exit and continue on with the testing.  The tests don&#8217;t actually exit (which allows the suite to continue) and no mocking of core functionality is required.  Is it the better way? I don&#8217;t know, but it works.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/ruby/multiple-input-locations-from-bash-into-ruby/' rel='bookmark' title='Multiple Input Locations From Bash Into Ruby'>Multiple Input Locations From Bash Into Ruby</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/ruby/testing-ruby/should-i-mock-kernel-exit/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ColorTail Gem</title>
		<link>http://eric.lubow.org/2010/ruby/colortail-gem/</link>
		<comments>http://eric.lubow.org/2010/ruby/colortail-gem/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 10:30:31 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[gem]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=673</guid>
		<description><![CDATA[One of the best ways to learn something new is to find a project in that realm and do it. I wanted to learn Ruby on Rails, so I wrote a web site. I wanted to learn Python, so I did a project in it for work. Now I want to get better at Ruby, [...]]]></description>
			<content:encoded><![CDATA[<p>One of the best ways to learn something new is to find a project in that realm and do it.  I wanted to learn Ruby on Rails, so I wrote a web site.  I wanted to learn Python, so I did a project in it for work.  Now I want to get better at Ruby, so I wrote a gem.  It&#8217;s usually not as simple as just picking a project though.  It&#8217;s much easier to pick and complete a project if you are filling a need.  So that&#8217;s what I did, I filled a need.<br />
<span id="more-673"></span><br />
Coming from an SA background, every time I write a script, I use lots of logging.  It doesn&#8217;t matter whether that script is in Perl, Python, Ruby, Bash, or anything else I write.  But what I do keep pretty consistent is that I specify the log levels on the log line.  So I get things that look like this:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">2010-04-19 11:36:39,734 DEBUG &nbsp; &nbsp; &nbsp; Getting all mailings for 2010-05-18<br />
2010-04-19 11:36:39,735 INFO &nbsp; &nbsp; &nbsp; &nbsp;Handling 1 mailing for 2010-05-18<br />
2010-04-19 11:37:16,547 WARNING &nbsp; &nbsp; Handling 0 mailings for 2010-05-18</div></div>
<p>When I tail this, it&#8217;s usually not a big deal to see what&#8217;s what because there aren&#8217;t things flying by.  Every so often, things fly by and it would just be easier to know what I am looking at.  Install the <em>colortail</em>:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">elubow<span style="color: #000000; font-weight: bold;">@</span>beacon ~$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> colortail<br />
Successfully installed spruz-0.1.0<br />
Successfully installed file-tail-1.0.5<br />
Successfully installed colortail-0.1.3<br />
<span style="color: #000000;">3</span> gems installed<br />
Installing ri documentation <span style="color: #000000; font-weight: bold;">for</span> spruz-0.1.0...<br />
Installing ri documentation <span style="color: #000000; font-weight: bold;">for</span> file-tail-1.0.5...<br />
Installing ri documentation <span style="color: #000000; font-weight: bold;">for</span> colortail-0.1.3...<br />
Installing RDoc documentation <span style="color: #000000; font-weight: bold;">for</span> spruz-0.1.0...<br />
Installing RDoc documentation <span style="color: #000000; font-weight: bold;">for</span> file-tail-1.0.5...<br />
Installing RDoc documentation <span style="color: #000000; font-weight: bold;">for</span> colortail-0.1.3...</div></div>
<p>Add this setup to <strong>.colortailrc</strong>:</p>
<div class="codecolorer-container ruby default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="ruby codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color:#996600;">'syslog'</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:match</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>EMERGENCY<span style="color:#006600; font-weight:bold;">/</span>, &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:color</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:red</span>, &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:attribute</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:reverse</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:match</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>FATAL<span style="color:#006600; font-weight:bold;">/</span>, &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:color</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:red</span>, &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:attribute</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:bright</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:match</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>CRITICAL<span style="color:#006600; font-weight:bold;">/</span>, &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:color</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:red</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:match</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>DEBUG<span style="color:#006600; font-weight:bold;">/</span>, &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:color</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:green</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:match</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>ERROR<span style="color:#006600; font-weight:bold;">/</span>, &nbsp; &nbsp; &nbsp; &nbsp;<span style="color:#ff3333; font-weight:bold;">:color</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:green</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:match</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>INFO<span style="color:#006600; font-weight:bold;">/</span>, &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:color</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:none</span> <span style="color:#006600; font-weight:bold;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:match</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">/</span>WARN<span style="color:#006600; font-weight:bold;">/</span>, &nbsp; &nbsp; &nbsp; &nbsp; <span style="color:#ff3333; font-weight:bold;">:color</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:yellow</span> <span style="color:#006600; font-weight:bold;">&#125;</span><br />
&nbsp; <span style="color:#006600; font-weight:bold;">&#93;</span></div></div>
<p>your syslog style log will look like this:</p>
<table border='1' align='center'>
<tr>
<td>
<div id="attachment_675" class="wp-caption aligncenter" style="width: 668px"><a href="http://eric.lubow.org/wp-content/uploads/2010/04/colored_log_example.jpg"><img src="http://eric.lubow.org/wp-content/uploads/2010/04/colored_log_example.jpg" alt="Example of the output from a color grouping" title="Colored Log Example" width="658" height="115" class="size-full wp-image-675" /></a><p class="wp-caption-text">Colored Log Example</p></div>
</td>
</tr>
</table>
<p>I have tried to keep the code flexible enough for you to mix and match combinations.  It&#8217;s easy to setup and use.  Rather than rewriting everything, just check out the repository <a href="http://codaset.com/elubow/colortail">here</a> at <a href="http://codaset.com/">Codaset</a>.  Also check out the <a href="http://codaset.com/elubow/colortail/wiki/example-groupings">example groupings</a> wiki page for more ideas.</p>
<p><strong>Full Disclosure:</strong> This is my first gem, so there may be some issues, please submit a ticket <a href="http://codaset.com/elubow/colortail/tickets">here</a> so I can fix it.  Or if you&#8217;d like additional features, I&#8217;d be happy to add them, just let me know.</p>
<p>Hope this is as useful for me as it is for you.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2009/ruby/parsing-ini-files-with-ruby/' rel='bookmark' title='Parsing Ini Files With Ruby'>Parsing Ini Files With Ruby</a></li>
<li><a href='http://eric.lubow.org/2010/mac/capistrano-hangs-on-mac-os-x-leopard/' rel='bookmark' title='Capistrano Hangs on Mac OS X Leopard'>Capistrano Hangs on Mac OS X Leopard</a></li>
<li><a href='http://eric.lubow.org/2009/misc/converting-from-subversion-to-git/' rel='bookmark' title='Converting From Subversion To Git'>Converting From Subversion To Git</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/ruby/colortail-gem/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Capistrano Hangs on Mac OS X Leopard</title>
		<link>http://eric.lubow.org/2010/mac/capistrano-hangs-on-mac-os-x-leopard/</link>
		<comments>http://eric.lubow.org/2010/mac/capistrano-hangs-on-mac-os-x-leopard/#comments</comments>
		<pubDate>Mon, 05 Apr 2010 11:30:54 +0000</pubDate>
		<dc:creator>eric</dc:creator>
				<category><![CDATA[Mac]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[capistrano]]></category>

		<guid isPermaLink="false">http://eric.lubow.org/?p=653</guid>
		<description><![CDATA[I use Capistrano to deploy my webapps and have been for a while. I also deploy right from my laptop quite frequently. So I was a little taken aback when I could deploy in one place and not in another. It turned out that Capistrano was having issues with deploying to multiple servers. In fact, [...]]]></description>
			<content:encoded><![CDATA[<p>I use Capistrano to deploy my webapps and have been for a while.  I also deploy right from my laptop quite frequently.  So I was a little taken aback when I could deploy in one place and not in another.  It turned out that Capistrano was having issues with deploying to multiple servers.  In fact, it turned out that the problem had the appearance of being Capistrano, but in actuality, it was <a href="http://github.com/net-ssh/net-ssh/tree/2.0">Net-SSH</a>.  The whole issue can be tracked via the Lighthouse ticket <a href="https://capistrano.lighthouseapp.com/projects/8716/tickets/79-capistrano-hangs-on-shell-command-for-many-computers-on-ruby-186-p368">here</a>.  I&#8217;m going to show you how to diagnose if you have this problem faster and how to fix it.<br />
<span id="more-653"></span><br />
However, the shorter version is as follows.  It starts out by hanging while trying to parallelize multiple connections. Not only does it hang, but it should peg your CPU.  You will be able to tell this if you hit the Terminal and type <strong>uptime</strong> and you see a high load average and it keeps climbing while your deploy is hung.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">elubow<span style="color: #000000; font-weight: bold;">@</span>beacon capistrano$ <span style="color: #c20cb9; font-weight: bold;">uptime</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">5</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">uptime</span><br />
<span style="color: #000000;">22</span>:<span style="color: #000000;">25</span> &nbsp;up <span style="color: #000000;">7</span>:<span style="color: #000000;">25</span> mins, <span style="color: #000000;">2</span> <span style="color: #c20cb9; font-weight: bold;">users</span>, load averages: <span style="color: #000000;">2.58</span> <span style="color: #000000;">0.61</span> <span style="color: #000000;">0.47</span><br />
<span style="color: #000000;">22</span>:<span style="color: #000000;">25</span> &nbsp;up <span style="color: #000000;">7</span>:<span style="color: #000000;">25</span> mins, <span style="color: #000000;">2</span> <span style="color: #c20cb9; font-weight: bold;">users</span>, load averages: <span style="color: #000000;">3.16</span> <span style="color: #000000;">1.11</span> <span style="color: #000000;">0.97</span><br />
elubow<span style="color: #000000; font-weight: bold;">@</span>beacon capistrano$ ruby <span style="color: #660033;">-v</span><br />
ruby 1.8.6 <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2009</span>-03-<span style="color: #000000;">31</span> patchlevel <span style="color: #000000;">368</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>i686-darwin9.7.0<span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
elubow<span style="color: #000000; font-weight: bold;">@</span>beacon capistrano$ cap deploy:mail:modules<br />
&nbsp; <span style="color: #000000; font-weight: bold;">*</span> executing <span style="color: #000000; font-weight: bold;">`</span>deploy:mail:modules<span style="color: #ff0000;">'<br />
&nbsp; * executing &quot;sudo mkdir -p /usr/local/lib/perl5/STMail &amp;&amp; sudo chmod g+w /usr/local/lib/perl5/STMail&quot;<br />
&nbsp; &nbsp; servers: [&quot;10.123.125.82&quot;, &quot;10.123.125.101&quot;, &quot;10.123.125.107&quot;, &quot;10.123.125.113&quot;]</span></div></div>
<p>I am able to replicate the problem all the way back to Net-SSH 2.0.11 (although it may go back further).  All you have to do is upgrade your version of Net-SSH.  Check your version and then upgrade if necessary.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">elubow<span style="color: #000000; font-weight: bold;">@</span>beacon capistrano$ gem list <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span><br />
net-ssh <span style="color: #7a0874; font-weight: bold;">&#40;</span>2.0.21, 2.0.11<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
elubow<span style="color: #000000; font-weight: bold;">@</span>beacon capistrano$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> net-ssh<br />
Successfully installed net-ssh-2.0.21<br />
<span style="color: #000000;">1</span> gem installed<br />
Installing ri documentation <span style="color: #000000; font-weight: bold;">for</span> net-ssh-2.0.21...<br />
Installing RDoc documentation <span style="color: #000000; font-weight: bold;">for</span> net-ssh-2.0.21...</div></div>
<p>Hope this helps.</p>


<p>Related posts:<ol><li><a href='http://eric.lubow.org/2010/mac/count-instead-of-sequence/' rel='bookmark' title='Count Instead of Sequence'>Count Instead of Sequence</a></li>
<li><a href='http://eric.lubow.org/2009/ruby/rails/fixing-zlib-errors-on-capistrano-deploy/' rel='bookmark' title='Fixing zlib Errors On Capistrano Deploy'>Fixing zlib Errors On Capistrano Deploy</a></li>
<li><a href='http://eric.lubow.org/2009/perl/mac-perl-problems-after-feb-update/' rel='bookmark' title='Mac Perl Problems After Feb Update'>Mac Perl Problems After Feb Update</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://eric.lubow.org/2010/mac/capistrano-hangs-on-mac-os-x-leopard/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

