<?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>blogt0sk1 &#187; Ruby</title>
	<atom:link href="http://blog.jerodsanto.net/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jerodsanto.net</link>
	<description>with Jerod Santo</description>
	<lastBuildDate>Sat, 19 Jun 2010 14:34:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Rubular</title>
		<link>http://blog.jerodsanto.net/2009/12/rubular/</link>
		<comments>http://blog.jerodsanto.net/2009/12/rubular/#comments</comments>
		<pubDate>Wed, 02 Dec 2009 14:12:29 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=810</guid>
		<description><![CDATA[Most of the online regular expression testers I&#8217;ve used just aren&#8217;t that useful, but Rubular is the exception. It uses AJAX appropriately, has a clean aesthetic, and the quick reference at the bottom of the page is so useful it hurts. Plus, it has great features such as match extraction and the ability to create [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the online regular expression testers I&#8217;ve used just aren&#8217;t that useful, but <a href="http://rubular.com" rel="external">Rubular</a> is the exception. It uses AJAX appropriately, has a clean aesthetic, and the quick reference at the bottom of the page is so useful it hurts. Plus, it has great features such as match extraction and the ability to create permalinks to your results.</p>
<p><img src="http://blog.jerodsanto.net/wp-content/uploads/2009/12/rubular.png" alt="rubular" title="rubular" width="650" height="279" class="aligncenter size-full wp-image-812" /></p>
<p><a href="http://rubular.com" rel="external">Rubular</a> is only for Ruby regexes. I wish somebody would make one for JavaScript. Jubular, anyone?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/12/rubular/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Ad Hoc Command-Line Notifications with Twitter</title>
		<link>http://blog.jerodsanto.net/2009/11/ad-hoc-command-line-notifications-with-twitter/</link>
		<comments>http://blog.jerodsanto.net/2009/11/ad-hoc-command-line-notifications-with-twitter/#comments</comments>
		<pubDate>Sat, 14 Nov 2009 17:03:04 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Tools]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=765</guid>
		<description><![CDATA[Have you ever spent way too much time babysitting a long-running command? Code compilation, large file transfers, software upgrades and other time consuming tasks can trash productivity by requiring intermittent attention. I have a novel idea; let&#8217;s not do that anymore! There are undoubtedly dozens of solutions for this little problem, but I chose Ruby [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever spent way too much time babysitting a long-running command? Code compilation, large file transfers, software upgrades and other time consuming tasks can trash productivity by requiring intermittent attention. </p>
<p>I have a novel idea; <strong>let&#8217;s not do that anymore!</strong></p>
<p><span id="more-765"></span></p>
<p>There are undoubtedly dozens of solutions for this little problem, but I chose Ruby + Twitter for a few reasons:</p>
<ul>
<li>I like Ruby</li>
<li>I like Twitter</li>
<li>I want hassle-free SMS</li>
<li>I want portability (small client-side configuration)</li>
</ul>
<p>So, with those things in mind, here is what I&#8217;ve come up with:</p>
<h2>1) A Special Twitter Account</h2>
<p>Create a new account for your notifications. You&#8217;ll most likely want to protect its tweets unless you don&#8217;t mind <em>just about anybody</em> seeing all the notifications you&#8217;re sending to yourself. Once the account is set up, follow it from your main Twitter account and enable SMS notifications for its tweets.</p>
<p><img src="http://blog.jerodsanto.net/wp-content/uploads/2009/11/twitter-sms.png" alt="twitter-sms" title="twitter-sms" width="532" height="136" class="aligncenter size-full wp-image-767" /></p>
<h2>2) A dead simple Ruby script</h2>
<p>I&#8217;ve written about John Nunemaker&#8217;s Twitter gem a <a href="http://blog.jerodsanto.net/2009/05/expand-your-twitter-network-in-less-than-15-lines-of-ruby/">couple</a> of <a href="http://blog.jerodsanto.net/2009/05/see-which-twitterers-dont-follow-youback-in-less-than-15-lines-of-ruby/">times</a>, and it once again makes its way into the toolbelt. Install if you don&#8217;t have it:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ sudo gem install twitter</pre></div></div>

<p>This gem makes the notification script just a few lines of code:</p>
<script src="http://gist.github.com/234586.js"></script><noscript><code class="gist"><pre><br />
#!/usr/bin/env ruby<br />
require &#8216;rubygems&#8217;<br />
require &#8216;twitter&#8217;</p>
<p>abort %|Usage: #{File.basename(__FILE__)} &#8220;your message&#8221;| unless ARGV.length == 1<br />
user = &#8220;your_username&#8221;<br />
pass = &#8220;your_password&#8221;<br />
Twitter::Base.new(Twitter::HTTPAuth.new(user,pass)).update(&#8220;NOTICE: #{ARGV.first}&#8221;)<br />
</pre></code></noscript>
<p>You can name the script anything you like. I call it <span class="keyword">twitter_notify</span>. Make it executable and ensure it is in your shell&#8217;s execution path (I symlink it so I can keep my code organized):</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ chmod +x src/ruby/twitter/twitter_notify.rb
jerod@mbp:~$ ln -s ~/src/ruby/twitter/twitter_notify.rb /usr/local/bin/twitter_notify</pre></div></div>

<h2>3) A Call to Notify</h2>
<p>Anytime you want to be notified that a command has completed, just follow it with the <span class="keyword">twitter_notify</span> command. There are a couple of ways to do this, and they are slightly different:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ cp /tmp/bigfile.tgz /somewhere/else &amp;&amp; twitter_notify &quot;all done copying!&quot;</pre></div></div>

<p>Or:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">jerod@mbp:~$ cp /tmp/bigfile.tgz /somewhere/else; twitter_notify &quot;command complete!&quot;</pre></div></div>

<p>Using <span class="keyword">&#038;&#038;</span> will only call the second command if the first command completed successfully. Using <span class="keyword">;</span> will call the second command regardless of how the first command completed. Adjust usage depending on your circumstance.</p>
<h2>4) A Deserved Break</h2>
<p>Now that you&#8217;ve set up your tools to handle the grunt work, walk away from the computer! Go outside, watch a movie, hang with your fam, who cares! When that task is complete you&#8217;ll get an SMS and you can deal with it then.</p>
<p>That&#8217;s all I got.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/11/ad-hoc-command-line-notifications-with-twitter/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Just Abort It</title>
		<link>http://blog.jerodsanto.net/2009/08/just-abort-it/</link>
		<comments>http://blog.jerodsanto.net/2009/08/just-abort-it/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 15:15:52 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=619</guid>
		<description><![CDATA[A lot of people end up writing Ruby methods that looks something like this: def stop_error&#40;message&#41; puts &#34;ERROR: #{message}&#34; exit&#40;1&#41; end Which they call in their app like so: stop_error &#34;Oh noes, file doesn't exist!&#34; unless File.exist?&#40;file&#41; I used to write that method a lot too. Did you know Ruby has a built-in method that [...]]]></description>
			<content:encoded><![CDATA[<p>A lot of people end up writing Ruby methods that looks something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color: #000; font-weight: bold;">def</span> stop_error<span style="color: #000;">&#40;</span>message<span style="color: #000;">&#41;</span>
  <span style="color: #0086B3;">puts</span> <span style="color: #D14;">&quot;ERROR: #{message}&quot;</span>
  <span style="color: #0086B3;">exit</span><span style="color: #000;">&#40;</span><span style="color:#006666;">1</span><span style="color: #000;">&#41;</span>
<span style="color: #000; font-weight: bold;">end</span></pre></div></div>

<p>Which they call in their app like so:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">stop_error <span style="color: #D14;">&quot;Oh noes, file doesn't exist!&quot;</span> <span style="color: #000; font-weight: bold;">unless</span> <span style="color: #009926;">File</span>.<span style="color: #0086B3;">exist</span>?<span style="color: #000;">&#40;</span>file<span style="color: #000;">&#41;</span></pre></div></div>

<p>I used to write that method a lot too. Did you know Ruby has a built-in method that provides just what we&#8217;re all looking for?</p>
<p><strong>Kernel::abort</strong></p>
<p>So, stop writing your own little method and just abort it:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">abort <span style="color: #D14;">&quot;Oh noes, file doesn't exist!&quot;</span> <span style="color: #000; font-weight: bold;">unless</span> <span style="color: #009926;">File</span>.<span style="color: #0086B3;">exist</span>?<span style="color: #000;">&#40;</span>file<span style="color: #000;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/08/just-abort-it/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>AppStore Ruby Module</title>
		<link>http://blog.jerodsanto.net/2009/08/appstore-ruby-module/</link>
		<comments>http://blog.jerodsanto.net/2009/08/appstore-ruby-module/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 21:29:14 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[modules]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=611</guid>
		<description><![CDATA[So I was writing my first iPhone on Rails app when my Google Reader dropped some pretty awful news on me. Somebody pre-empted my release with their (pretty excellent, but poorly named) &#8220;Bargain Bin with Push!&#8221; app (iTunes link). The Bad News &#8220;Bargain Bin with Push!&#8221; does pretty much exactly what my app was going [...]]]></description>
			<content:encoded><![CDATA[<p>So I was writing my first <a href="http://iphoneonrails.com/" rel="external">iPhone on Rails</a> app when my <a href="http://www.google.com/reader/shared/05234492019244193889" rel="external">Google Reader</a> dropped some pretty awful news on me. Somebody pre-empted my release with their (pretty excellent, but poorly named) <strong>&#8220;Bargain Bin with Push!&#8221;</strong> app (<a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=302951751&#038;mt=8" rel="external">iTunes link</a>).</p>
<h2>The Bad News</h2>
<p><strong>&#8220;Bargain Bin with Push!&#8221;</strong> does pretty much exactly what my app was going to do. It provides push notifications when apps you&#8217;re interested in drop in price. Instead of raging against the dying of the light, I&#8217;ve decided to just user their app and let mine go gently into that good night.</p>
<h2>The Good News</h2>
<p>All was not lost. I learned a ton along the way and decided to open-source the module I was using to fetch app information out of Apple&#8217;s App Store.</p>
<h2>The Goods</h2>
<p><a href="http://github.com/sant0sk1/app_store/tree/master" rel="external">The code is on GitHub, of course</a>. Clone, fork and branch to your heart&#8217;s content. Hopefully somebody will find it useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/08/appstore-ruby-module/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Self-Scheduling Ruby Scripts</title>
		<link>http://blog.jerodsanto.net/2009/08/self-scheduling-ruby-scripts/</link>
		<comments>http://blog.jerodsanto.net/2009/08/self-scheduling-ruby-scripts/#comments</comments>
		<pubDate>Fri, 21 Aug 2009 03:25:24 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[whenever]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=587</guid>
		<description><![CDATA[Whenever is an awesome library that: &#8220;provides a clean ruby syntax for defining messy cron jobs and running them Whenever.&#8221; Whenever has become very popular for use with Rails apps and there are plenty of tutorials on how to use it. This RailsCast is a good place to get started if you&#8217;re interested in that. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/javan/whenever/" rel="external">Whenever</a> is an awesome library that:</p>
<blockquote><p>&#8220;provides a clean ruby syntax for defining messy cron jobs and running them Whenever.&#8221;</p></blockquote>
<p><strong>Whenever</strong> has become very popular for use with Rails apps and there are plenty of tutorials on how to use it. This <a href="http://railscasts.com/episodes/164-cron-in-ruby" rel="external">RailsCast</a> is a good place to get started if you&#8217;re interested in that.</p>
<p>However, I haven&#8217;t seen too many people writing about using the library outside of Rails (or other web frameworks).<br />
<span id="more-587"></span><br />
I have a lot of Ruby scripts running on different servers all scheduled via cron and it&#8217;s quite easy to forget what script is scheduled when and how often. I decided to try using <strong>Whenever</strong> to create the cron jobs instead of creating them manually. First, I set out to just slap arbitrary Ruby code inside of an &#8220;every&#8221; block. You know, something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">every <span style="color:#ff3333; font-weight:bold;">:hour</span> <span style="color: #000; font-weight: bold;">do</span>
  <span style="color: #0086B3;">puts</span> <span style="color: #D14;">&quot;this is just some ruby that will execute every hour&quot;</span>
<span style="color: #000; font-weight: bold;">end</span></pre></div></div>

<p>Unfortunately, it doesn&#8217;t work like that. If it did, that would own because then we could simply wrap all our scripts inside an &#8220;every&#8221; block and call it a day. Instead the library lets you define a few different kinds of tasks inside an &#8220;every&#8221; block.</p>
<ol>
<li>rake tasks</li>
<li>external commands</li>
<li>runner scripts (Rails)</li>
</ol>
<p>So, we can use the &#8220;command&#8221; method to execute our pre-existing scripts like so:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">every 1.<span style="color: #0086B3;">day</span>, <span style="color:#ff3333; font-weight:bold;">:at</span> <span style="color: #000;">=&gt;</span> <span style="color: #D14;">'4:30 am'</span> <span style="color: #000; font-weight: bold;">do</span>
  command <span style="color: #D14;">&quot;/scripts/daily_backup.rb&quot;</span>
<span style="color: #000; font-weight: bold;">end</span></pre></div></div>

<p>So that&#8217;s cool, but now we have to create a separate file that houses our schedule definitions and manage it as well as the scripts we want to run. What would be really cool, I thought, would be to include the schedule definitions at the top of each script. The big win in this case is easily accessible &#038; portable schedule documentation.</p>
<p>One way of accomplishing this is to prepend all your Ruby scripts with a snippet similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color: #6F6F6F;"># filename: /scripts/weekly_backup.rb</span>
every <span style="color:#ff3333; font-weight:bold;">:sunday</span>, <span style="color:#ff3333; font-weight:bold;">:at</span> <span style="color: #000;">=&gt;</span> <span style="color: #D14;">'12pm'</span> <span style="color: #000; font-weight: bold;">do</span>
    command <span style="color: #D14;">&quot;/scripts/weekly_backup.rb&quot;</span>
<span style="color: #000; font-weight: bold;">end</span> <span style="color: #000; font-weight: bold;">if</span> <span style="color: #000; font-weight: bold;">defined</span>?<span style="color: #000;">&#40;</span>Whenever<span style="color: #000;">&#41;</span>
&nbsp;
<span style="color:#0000FF; font-weight:bold;">return</span> <span style="color: #000; font-weight: bold;">unless</span> <span style="color:#0000FF; font-weight:bold;">__FILE__</span> == <span style="color:#ff6633; font-weight:bold;">$PROGRAM_NAME</span>
&nbsp;
<span style="color: #0086B3;">puts</span> <span style="color: #D14;">&quot;this is the start of my backup script&quot;</span></pre></div></div>

<p>When this script is executed using the &#8220;whenever&#8221; command (which you use to actually generate and install the cron jobs), the first &#8220;every&#8221; block will be used and everything after the &#8220;return&#8221; line will be ignored. When this script is executed directly, the &#8220;every&#8221; block will be ignored and everything after the &#8220;return&#8221; line will be executed. </p>
<p>Writing the crontab with this script will look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">whenever -w -f /scripts/weekly_backup.rb</pre></div></div>

<p>Which will install a cron job that looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">0 12 * * 0 /scripts/weekly_backup.rb</pre></div></div>

<p>The major drawback to this method is we have to hard code the full path to the script instead of using the __FILE__ variable, which hurts portability. This is because <strong>Whenever</strong> &#8220;evals&#8221; the content of the file read in and in this case __FILE__ is useless. There is access to the calling file path via &#8220;Whenever::CommandLine.default_identifier&#8221; but this is currently a protected method.</p>
<p>This is just my first attempt at embedding scheduling information inside the script being scheduled, so there are probably easier/better ways of getting this done. Know any?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/08/self-scheduling-ruby-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mini Book Review: Ruby Best Practices</title>
		<link>http://blog.jerodsanto.net/2009/08/mini-book-review-ruby-best-practices/</link>
		<comments>http://blog.jerodsanto.net/2009/08/mini-book-review-ruby-best-practices/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 16:06:57 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[books]]></category>
		<category><![CDATA[reviews]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=549</guid>
		<description><![CDATA[I just finished reading Gregory Brown&#8217;s &#8220;Ruby Best Practices&#8221; (RBP). I could probably write a book about this book, but I hate long book reviews so I&#8217;ll try to keep this short. In Summary If you are an intermediate-to-expert Ruby programmer you should absolutely read this book. Beginners may want to start elsewhere and work [...]]]></description>
			<content:encoded><![CDATA[<p>I just finished reading Gregory Brown&#8217;s &#8220;<strong>Ruby Best Practices</strong>&#8221; (RBP). I could probably write a book about this book, but I hate long book reviews so I&#8217;ll try to keep this short.</p>
<p><span id="more-549"></span></p>
<h3> In Summary</h3>
<p>If you are an intermediate-to-expert Ruby programmer you should absolutely read this book. Beginners may want to start elsewhere and work their way up. <a href="#wheretobuy">Where To Get It</a></p>
<h3>In Detail</h3>
<p>The beauty and power of Ruby is its dynamism which leads to freedom. The problem with freedom is it means <a href="http://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it" rel="external">TMTOWTDI</a>. The problem with <a href="http://en.wikipedia.org/wiki/There%27s_more_than_one_way_to_do_it" rel="external">TMTOWTDI</a> is best summarized by me, in a quote of myself:</p>
<blockquote><p>&#8220;There is more than one way to do it but most of them are really, really bad.&#8221;</p></blockquote>
<p>Thankfully, we can combat these bad coding methods by resorting to helpful idioms and best practices, and Ruby has these in spades. The purpose of <strong>RBP</strong> is stated plainly on the front cover:</p>
<blockquote><p>&#8220;Increase Your Productivity &#8212; Write Better Code&#8221;</p></blockquote>
<p>With that in mind, here is a breakdown of what it offers:</p>
<p>The first thing I noticed when reading <strong>RBP</strong> is that it uses real-world code samples. None of that &#8220;let&#8217;s make a tic-tac-toe game&#8221; type of stuff. Gregory uses a couple of his own projects (Prawn &#038; Ruport) as well as other popular libraries (Haml, flexmock, XML Builder, Gibberish, faker). This is beyond awesome.</p>
<p>He also steps through a lot of code using IRB, which means you can follow right along in your favorite shell. Gregory highly recommends you get your hands dirty with the code he presents and I agree with him. However, I also like to read physical books in places not my computer, since the opportunity so rarely presents itself.</p>
<p>The book starts, aptly, with a chapter on testing. The following two chapters are (for me) the highlights:</p>
<p><em><strong>Designing Beautiful APIs</strong></em> and <em><strong>Mastering the Dynamic Toolkit</strong></em>.</p>
<p>The value found in these two sections alone cover the cost of the entire book. A few of the topics discussed include: flexible argument handling, code blocks, implementing per-object behavior, building classes and modules programatically and registering hooks and callbacks. Gregory released a free section of <em><strong>Mastering the Dynamic Toolkit</strong></em> so you don&#8217;t have to take my word for it, <a href="http://cdn.oreilly.com/books/9780596523008/Mastering_the_Dynamic_Toolkit.xml.pdf" rel="external">have a taste for yourself.</a></p>
<p>I need to wrap this up or I&#8217;ll be forced to remove the &#8220;<strong>Mini</strong>&#8221; from the post title. You&#8217;ll also find sections on File &#038; Text processing, functional programming, debugging, project maintenance (much of which is obsolete if you use the wonderful <a href="http://github.com/technicalpickles/jeweler/" rel="external">Jeweler gem</a>), and internationalization.</p>
<p>Tips, tricks and suggestions abound. Even expert-level Rubyists should learn something. <strong>RBP</strong> left me wanting more of Gregory&#8217;s teaching. He really does a good job of explaining concepts and walking through code. Thankfully, he started up a<a href="http://blog.rubybestpractices.com/" rel="external"> Ruby Best Practices blog</a> with more content!</p>
<h3 id="wheretobuy">Where to Buy</h3>
<p><strong>RBP</strong> is an O&#8217;Reilly publication and they have it on sale at their web site for <strong>$34.99</strong>. </p>
<p>However, I don&#8217;t know why you&#8217;d do that because Amazon has it for <strong>$23.10</strong> and eligible for free shipping with Amazon Prime. Booyah!</p>
<p>If you go that route, use <a href="http://www.amazon.com/gp/product/0596523009?ie=UTF8&#038;tag=standadeviat-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0596523009" rel="external">this link</a> to pitch me a little something for the effort, or just buy directly via <a href="hhttp://www.amazon.com/Ruby-Best-Practices-Gregory-Brown/dp/0596523009/ref=sr_1_1?ie=UTF8&#038;s=books&#038;qid=1249140448&#038;sr=8-1" rel="external">this link</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/08/mini-book-review-ruby-best-practices/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ad Hoc Rails Console Logging</title>
		<link>http://blog.jerodsanto.net/2009/07/ad-hoc-rails-console-logging/</link>
		<comments>http://blog.jerodsanto.net/2009/07/ad-hoc-rails-console-logging/#comments</comments>
		<pubDate>Sat, 18 Jul 2009 20:11:17 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=532</guid>
		<description><![CDATA[I recently found a couple of cool old tricks for logging Rails activity directly to the console, but these solutions are pretty static once you&#8217;re inside a console session. In my experience, sometimes logging to the console is cool and most of the time it isn&#8217;t. If you want to be able to toggle your [...]]]></description>
			<content:encoded><![CDATA[<p>I recently found a couple of cool <a href="http://toolmantim.com/articles/logging_rails_activity_in_script_console" rel="external">old</a> <a href="http://toolmantim.com/articles/system_wide_script_console_logging" rel="external">tricks</a> for logging Rails activity directly to the console, but these solutions are pretty static once you&#8217;re inside a console session. In my experience, sometimes logging to the console is cool and most of the time it isn&#8217;t.</p>
<p>If you want to be able to toggle your development log between the default Rails logger and the console, just add this method to your <strong>~/.irbrc</strong>:<br />
<span id="more-532"></span></p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color: #000; font-weight: bold;">def</span> rails_log_to_console<span style="color: #000;">&#40;</span>toggle<span style="color: #000;">&#41;</span>
  <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>.<span style="color: #0086B3;">logger</span> = toggle == <span style="color:#0000FF; font-weight:bold;">true</span> ? <span style="color: #009926;">Logger</span>.<span style="color: #0086B3;">new</span><span style="color: #000;">&#40;</span>STDOUT<span style="color: #000;">&#41;</span> : RAILS_DEFAULT_LOGGER
  reload!
<span style="color: #000; font-weight: bold;">end</span></pre></div></div>

<p>Now, you can start logging to the console at any time by doing:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color: #000;">&gt;&gt;</span> rails_log_to_console <span style="color:#0000FF; font-weight:bold;">true</span>
Reloading...
<span style="color: #000;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span></pre></div></div>

<p>And turn it back off as simply as:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color: #000;">&gt;&gt;</span> rails_log_to_console <span style="color:#0000FF; font-weight:bold;">false</span>
Reloading...
<span style="color: #000;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span></pre></div></div>

<p>Really, passing any argument <em>except</em> true to the method will switch the logging back to the default.</p>
<p>Are there any better ways to achieve this (like without having to call <strong>reload!</strong>)? If you know of one, holler back in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/07/ad-hoc-rails-console-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sass Never Forgets</title>
		<link>http://blog.jerodsanto.net/2009/07/sass-never-forgets/</link>
		<comments>http://blog.jerodsanto.net/2009/07/sass-never-forgets/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 01:43:54 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[css]]></category>
		<category><![CDATA[mixins]]></category>
		<category><![CDATA[sass]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=518</guid>
		<description><![CDATA[Some CSS techniques require me to Google about like a chicken with its head cut off. One such technique is placing a div in the dead center of a page (vertically and horizontally). Since I&#8217;m using Sass pretty much exclusively these days, I decided to define this technique as a mixin so I don&#8217;t have [...]]]></description>
			<content:encoded><![CDATA[<p>Some CSS techniques require me to Google about like a chicken with its head cut off. One such technique is placing a div in the dead center of a page (vertically and horizontally). Since I&#8217;m using <a href="http://sass-lang.com">Sass</a> pretty much exclusively these days, I decided to define this technique as a mixin so I don&#8217;t have to look it up anymore.</p>
<p>Hopefully this can be of use to others. YMMV:</p>
<p>The mixin definition:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #000;">=</span>dead-<span style="color: #993333;">center</span><span style="color: #000;">&#40;</span>!<span style="color: #000; font-weight: bold;">height</span><span style="color: #000;">,</span>!<span style="color: #000; font-weight: bold;">width</span><span style="color: #000;">&#41;</span>
  <span style="color: #000;">:</span><span style="color: #000; font-weight: bold;">height</span><span style="color: #000;">=</span> !<span style="color: #000; font-weight: bold;">height</span>
  <span style="color: #3333ff;">:margin-</span>top<span style="color: #000;">=</span> -<span style="color: #000;">&#40;</span>!<span style="color: #000; font-weight: bold;">height</span> / <span style="color: #cc66cc;">2</span><span style="color: #000;">&#41;</span>
  <span style="color: #000;">:</span><span style="color: #000; font-weight: bold;">top</span> <span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span>
  <span style="color: #000;">:</span><span style="color: #000; font-weight: bold;">width</span><span style="color: #000;">=</span> !<span style="color: #000; font-weight: bold;">width</span>
  <span style="color: #3333ff;">:margin-</span>left<span style="color: #000;">=</span> -<span style="color: #000;">&#40;</span>!<span style="color: #000; font-weight: bold;">width</span> / <span style="color: #cc66cc;">2</span><span style="color: #000;">&#41;</span>
  <span style="color: #000;">:</span><span style="color: #000; font-weight: bold;">left</span> <span style="color: #933;"><span style="color: #cc66cc;">50</span>%</span>
  <span style="color: #3333ff;">:<span style="color: #000; font-weight: bold;">position</span> </span>absolute
  <span style="color: #3333ff;">:<span style="color: #000; font-weight: bold;">text-align</span> </span>center</pre></div></div>

<p>To use it on an element:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#centered</span>
  <span style="color: #000;">+</span>dead-<span style="color: #993333;">center</span><span style="color: #000;">&#40;</span><span style="color: #933;">200px</span><span style="color: #000;">,</span><span style="color: #933;">500px</span><span style="color: #000;">&#41;</span></pre></div></div>

<p>Now I&#8217;ll never forget how. Thanks Sass!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/07/sass-never-forgets/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>3 Reasons Why Heroku is a Game Changer</title>
		<link>http://blog.jerodsanto.net/2009/05/3-reasons-why-heroku-is-a-game-changer/</link>
		<comments>http://blog.jerodsanto.net/2009/05/3-reasons-why-heroku-is-a-game-changer/#comments</comments>
		<pubDate>Tue, 26 May 2009 09:55:19 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[opinion]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=379</guid>
		<description><![CDATA[For the uninitiated, Heroku is a &#8220;cloud&#8221; (hate that term) hosting service for Ruby applications. Their claim, which I believe they have substantiated, is to be an &#8220;instant ruby platform&#8221; and their success changes the game. Here is why. 1) Microwavesque Deployment When Heroku claims that you can deploy your Ruby app instantly, they&#8217;re pretty [...]]]></description>
			<content:encoded><![CDATA[<p>For the uninitiated, <a href="http://heroku.com">Heroku</a> is a &#8220;cloud&#8221; (hate that term) hosting service for Ruby applications. Their claim, which I believe they have substantiated, is to be an &#8220;<strong>instant ruby platform</strong>&#8221; and their success changes the game. Here is why.<br />
<span id="more-379"></span></p>
<h3>1) Microwavesque Deployment</h3>
<p>When Heroku claims that you can deploy your Ruby app instantly, they&#8217;re pretty much not exaggerating. Seriously, you should try it. It&#8217;s so fast I had to ignore my spell-checker and describe it as microwavesque. Remember when microwaves first hit the scene and people couldn&#8217;t believe how fast they could &#8220;deploy&#8221; a meal? Yah me either, but the microwave changed the game big time.</p>
<p>If you haven&#8217;t tried deploying a Rails app to Heroku, just go do it. Here are the steps from start to finish:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">rails myapp
 cd myapp
 git init
 git add .
 git commit -m &quot;my new app&quot;
 heroku create myapp
 git push heroku master</pre></div></div>

<p>If that looks like too much work for you, have Remi walk you through it in <a href="http://remi.org/2009/04/23/deploying-rails-and-rack-applications-to-heroku.html">this nice screencast</a>.</p>
<h3>2) Drag To Scale</h3>
<p>Scaling is a problem we all want to have, but few of us do. The rest of us spend way too much time thinking about it. With Heroku&#8217;s architecture, you don&#8217;t have to think about scaling. You just do it. If you&#8217;re fortunate enough to have your app featured on TechCrunch, Slashdot, Digg, HN, Reddit, etc, etc, you simply log in to the Heroku admin panel and &#8220;crank your dynos&#8221; (love that term) to handle the load. How do you do that? By dragging a little bar vertically. How&#8217;s that for a learning curve?</p>
<p><a href="http://blog.jerodsanto.net/wp-content/uploads/2009/05/dyno.png"><img src="http://blog.jerodsanto.net/wp-content/uploads/2009/05/dyno-189x300.png" alt="dyno" title="dyno" width="189" height="300" class="aligncenter size-medium wp-image-381" /></a></p>
<p>Note: This isn&#8217;t the only way to ensure your app scales. You should still optimize your code for performance, but Heroku takes care of all the server configuration (compression, caching, memory allocation, etc) and you just ask for more power when you need it.</p>
<h3>3) Rack Support</h3>
<p>Heroku isn&#8217;t just a Rails platform, it&#8217;s a Ruby platform. They support any <a href="http://rack.rubyforge.org/">Rack-enabled</a> Ruby app. Check out how many Ruby web frameworks have Rack adapters:</p>
<ul>
<li>Camping</li>
<li>Coset</li>
<li>Halcyon</li>
<li>Mack</li>
<li>Maveric</li>
<li>Merb</li>
<li>Racktools::SimpleApplication</li>
<li>Ramaze</li>
<li>Ruby on Rails</li>
<li>Rum</li>
<li>Sinatra</li>
<li>Sin</li>
<li>Vintage</li>
<li>Waves</li>
<li>Wee</li>
</ul>
<p>That&#8217;s a long frickin&#8217; list! Developers can pick the right tool for their need (or write their own Rack-enabled app) and not have to worry about deployment gotchas.</p>
<p>For example, I wanted a way to quickly resolve the public IP address of any machine I&#8217;m using (including servers) so I wrote <a href="http://my-ip.heroku.com">and deployed</a> this trivial Sinatra app in less than 5 minutes.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color: #6F6F6F;"># public_ip.rb</span>
<span style="color: #0086B3;">require</span> <span style="color: #D14;">'rubygems'</span>
<span style="color: #0086B3;">require</span> <span style="color: #D14;">'sinatra'</span>
&nbsp;
get <span style="color: #D14;">'/'</span> <span style="color: #000; font-weight: bold;">do</span>
  raw = <span style="color:#0066ff; font-weight:bold;">@request</span>.<span style="color: #0086B3;">env</span><span style="color: #000;">&#91;</span><span style="color: #D14;">&quot;REMOTE_ADDR&quot;</span><span style="color: #000;">&#93;</span>
  raw.<span style="color: #0086B3;">match</span><span style="color: #000;">&#40;</span><span style="color: #000;">/</span>^<span style="color: #000;">&#40;</span>\d<span style="color: #000;">+</span>\.\d<span style="color: #000;">+</span>\.\d<span style="color: #000;">+</span>\.\d<span style="color: #000;">+</span><span style="color: #000;">&#41;</span>,?<span style="color: #000;">/</span><span style="color: #000;">&#41;</span>
  <span style="color:#0066ff; font-weight:bold;">@ip</span> = $<span style="color:#006666;">1</span>
  haml <span style="color: #D14;">'=@ip'</span>
<span style="color: #000; font-weight: bold;">end</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color: #6F6F6F;"># config.ru</span>
<span style="color: #0086B3;">require</span> <span style="color: #D14;">'public_ip.rb'</span>
run <span style="color:#6666ff; font-weight:bold;">Sinatra::Application</span></pre></div></div>

<p>The rackup file (config.ru) tells Heroku to use Sinatra to run my application. Rails would have been overkill for this, don&#8217;t you think? (Heck, Sinatra may be overkill too. You could probably write a raw Rack application in even fewer LOC, post in the comments if you have a better solution).</p>
<p><strong>UPDATE:</strong> Blake Mizerany provided a few shorter examples <a href="http://gist.github.com/118217">here</a>.</p>
<h3>So</h3>
<p>What Heroku offers Ruby web developers is instant deployment, fast &#038; easy scaling, and vast tool selection. Now we can concentrate on building our applications and forget the tedious deployment and server administration tasks that used to strangle our productivity. We can deploy fast, scale quickly, and adjust to circumstance as needs arise. The game is changing, and Heroku (and others like them) are changing it.</p>
<p><strong>**disclaimer**</strong><br />
I am only affiliated with Heroku as a customer, and receive no recompense from the ridiculous amount of props I&#8217;m throwing their way. They do have a few drawbacks, one that is a show stopper for many apps, which I will detail in a future post.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/05/3-reasons-why-heroku-is-a-game-changer/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Create Arbitrarily Sized Files In Less Than 15 Lines of Ruby</title>
		<link>http://blog.jerodsanto.net/2009/05/create-arbitrarily-sized-files-in-less-than-15-lines-of-ruby/</link>
		<comments>http://blog.jerodsanto.net/2009/05/create-arbitrarily-sized-files-in-less-than-15-lines-of-ruby/#comments</comments>
		<pubDate>Fri, 22 May 2009 19:39:41 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[io]]></category>
		<category><![CDATA[lessthan15]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=369</guid>
		<description><![CDATA[Ok, so I&#8217;m having fun with this &#8220;in less than 15 lines of Ruby&#8221; idea, but this time I turn my attention away from Twitter (I know, that&#8217;s hard to do right now) and toward file generation. Sometimes you just need a 1GB file. Or a 350MB file. Or a 1MB file. It doesn&#8217;t matter [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so I&#8217;m having fun with this &#8220;in less than 15 lines of Ruby&#8221; idea, but this time I turn my attention away from Twitter (I know, that&#8217;s hard to do right now) and toward file generation.</p>
<p>Sometimes you just need a 1GB file. Or a 350MB file. Or a 1MB file. It doesn&#8217;t matter what is in that file, but size does matter (heh). </p>
<p>With this little Ruby script, you can arbitrarily generate files of any size (using 1MB increments).</p>
<p><strong>The Script:</strong><br />
<span id="more-369"></span><br />
<script src="http://gist.github.com/116313.js"></script></p>
<p>The resulting file will be named &#8220;<strong>[X]MB</strong>&#8221; where <strong>X</strong> is the size you requested.</p>
<p><strong>A Note:</strong></p>
<p>This script is derived from one I found awhile ago somewhere on the internet (don&#8217;t remember where). It didn&#8217;t work correctly (file sizes were off) and was much more verbose.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/05/create-arbitrarily-sized-files-in-less-than-15-lines-of-ruby/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
