<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  <title><![CDATA[joey beninghove]]></title>
  
  <link href="http://joeybeninghove.com/" />
  <updated>2012-12-09T20:36:17-05:00</updated>
  <id>http://joeybeninghove.com/</id>
  <author>
    <name><![CDATA[Joey Beninghove]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
    <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/joeybeninghove" /><feedburner:info uri="joeybeninghove" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
      




<title type="html"><![CDATA[Octopress + Font Awesome]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/gYy6Dl85l10/" />
<updated>2012-12-09T19:50:00-05:00</updated>
<id>http://joeybeninghove.com/2012/12/09/octopress-font-awesome</id>

      <content type="html">&lt;p&gt;For the past year or so I&amp;#8217;ve been doing a lot of work with &lt;a href="http://twitter.github.com/bootstrap/index.html"&gt;Bootstrap&lt;/a&gt; and recently with &lt;a href="http://dresssed.com/themes/gimlet"&gt;Gimlet&lt;/a&gt;,
a Bootstrap theme for Rails.  As part of this I&amp;#8217;ve grown to love the awesome &lt;a href="http://fortawesome.github.com/Font-Awesome"&gt;Font Awesome&lt;/a&gt; icons, so
I decided to sprinkle them here on my &lt;a href="http://octopress.org"&gt;Octopress&lt;/a&gt; blog.  I think I like it!  I love how easy it is
to customize Octopress with my own flavors.&lt;/p&gt;

&lt;p&gt;Oh and I updated my &lt;a href="http://joeybeninghove.com/about"&gt;About&lt;/a&gt; and &lt;a href="http://joeybeninghove.com/work"&gt;Work&lt;/a&gt; pages with some new stuff.  :)&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2012/12/09/octopress-font-awesome/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/gYy6Dl85l10" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2012/12/09/octopress-font-awesome/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Grape APIs - Few Quick Tidbits]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/pOAft1xw8F0/" />
<updated>2012-01-21T22:46:00-05:00</updated>
<id>http://joeybeninghove.com/2012/01/21/grape-apis-few-quick-tidbits</id>

      <content type="html">&lt;p&gt;It&amp;#8217;s been pretty quiet here for a long time, but I&amp;#8217;ve been busy building a few businesses, one of which includes a new
product I&amp;#8217;m helping to build and launch with a couple friends.  One of the things I&amp;#8217;ve been building is a robust REST
API using &lt;a href="https://github.com/intridea/grape"&gt;Grape&lt;/a&gt;.  If you want a quick overview, check out their README on the GitHub repo.  I&amp;#8217;ve really enjoyed using Grape and figured I&amp;#8217;d share a few little tidbits of how I&amp;#8217;m using it so far.&lt;/p&gt;

&lt;h2&gt;Configuring URL prefix&lt;/h2&gt;

&lt;p&gt;For a long time I was just using Rails 3 to &amp;#8220;mount&amp;#8221; my Grape API class like this:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;routes.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;mount&lt;/span&gt; &lt;span class="no"&gt;MyApp&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;API&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;/api&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;This worked well for a while, but then I had a need to plug in some Rack middleware (such as Rack::Cors, which I plan to
blog about soon).  Long story short, I couldn&amp;#8217;t mount it the same way anymore, but still needed to configure the base
URL for the API to point to &lt;code&gt;/api&lt;/code&gt;.  Grape makes this really easy.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;my_app_api.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;MyApp&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;API&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Grape&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;API&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="n"&gt;prefix&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;api&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Quick side note, I do still mount the API in the Rails routes for the &lt;code&gt;test&lt;/code&gt; environment only for my automated API
integration tests.  But since I already have the prefix defined in the API, I just mount it to root for these purposes.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;routes.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;test&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="n"&gt;mount&lt;/span&gt; &lt;span class="no"&gt;MyApp&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;API&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;/&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;h2&gt;Delegate to the Rails logger (if desired)&lt;/h2&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;my_app_api.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logger&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Simple.&lt;/p&gt;

&lt;h2&gt;Request logging, including body&lt;/h2&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;my_app_api.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;before&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# Of course this makes the request.body unavailable afterwards.&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# You can just use a helper method to store it away for later if needed. &lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;info&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Request Body: &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Easy peasy.&lt;/p&gt;

&lt;h2&gt;Global exception handling&lt;/h2&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;my_app_api.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;rescue_from&lt;/span&gt; &lt;span class="ss"&gt;:all&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# Log it&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\n\n&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backtrace&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# Notify external service of the error&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;Airbrake&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;notify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# Send error and backtrace down to the client in the response body (only for internal/testing purposes of course)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;Rack&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;backtrace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backtrace&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Content-type&amp;#39;&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;application/json&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;finish&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Handy.&lt;/p&gt;

&lt;h2&gt;HTTP Basic Authentication&lt;/h2&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;my_app_api.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;http_basic&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;authenticate!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;username&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;password&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;No sweat.&lt;/p&gt;

&lt;h2&gt;Helper methods&lt;/h2&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;my_app_api.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;helpers&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;current_context&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="vi"&gt;@context&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="c1"&gt;# some call to retrieve context based on API key maybe?&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# anything else needed by a group of or all resource/verb blocks&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Straightforward.&lt;/p&gt;

&lt;h2&gt;Sending back errors with validation messages&lt;/h2&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;my_app_api.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;resource&lt;/span&gt; &lt;span class="ss"&gt;:turtles&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="n"&gt;post&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;# make sure you filter/whilelist the request body attributes!&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="n"&gt;turtle&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Turtle&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;JSON&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="n"&gt;error!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;turtle&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;errors&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;400&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="n"&gt;turtle&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;valid?&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Smooth sailing.&lt;/p&gt;

&lt;h2&gt;General API building tips&lt;/h2&gt;

&lt;p&gt;I can&amp;#8217;t recommend enough the article that &lt;a href="http://railstips.org"&gt;John Nunemaker&lt;/a&gt; wrote recently on &lt;a href="http://railstips.org/blog/archives/2011/12/01/creating-an-api"&gt;Creating an API&lt;/a&gt;.  A great read with
some great tips.&lt;/p&gt;

&lt;p&gt;That&amp;#8217;s all for now.  Happy coding!  :)&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2012/01/21/grape-apis-few-quick-tidbits/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/pOAft1xw8F0" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2012/01/21/grape-apis-few-quick-tidbits/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[New Backbone.js on Rails Screencast - When Things Go Wrong!]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/e9xxrN1geyE/" />
<updated>2011-12-07T10:28:00-05:00</updated>
<id>http://joeybeninghove.com/2011/12/07/new-backbone-dot-js-on-rails-screencast-when-things-go-wrong</id>

      <content type="html">&lt;p&gt;Another quick announcement about my latest Backbone.js screencast over at
&lt;a href="http://bit.ly/bb-casts"&gt;backbonescreencasts.com&lt;/a&gt;.  This time it&amp;#8217;s another one relating to Rails, &lt;a href="http://backbonescreencasts.com/backbone-on-rails-errors"&gt;When Things Go
Wrong!&lt;/a&gt;.  In this one I cover dealing with errors, specifically
validation errors from Rails as well as monitoring server availability and reacting to server downtime.&lt;/p&gt;

&lt;h2&gt;Here&amp;#8217;s a preview:&lt;/h2&gt;

&lt;iframe src="http://player.vimeo.com/video/33251423" width="650" height="500" frameborder="0" webkitAllowFullScreen allowFullScreen&gt;&lt;/iframe&gt;


&lt;h2&gt;Interested?&lt;/h2&gt;

&lt;p&gt;Check out this one, as well as the special bundles available over at &lt;a href="http://bit.ly/bb-casts"&gt;backbonescreencasts.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;P.S. I have a LOT of cool stuff to blog about, which I hope to get to soon.  :)&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/12/07/new-backbone-dot-js-on-rails-screencast-when-things-go-wrong/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/e9xxrN1geyE" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/12/07/new-backbone-dot-js-on-rails-screencast-when-things-go-wrong/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Backbone.js on Rails (Basics) - New Screencast Available]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/BcCDB5_6ybc/" />
<updated>2011-11-08T10:09:00-05:00</updated>
<id>http://joeybeninghove.com/2011/11/08/backbone-dot-js-on-rails-basics-new-screencast-available</id>

      <content type="html">&lt;p&gt;Hey there folks, just a quick announcement to let you know that my 2nd Backbone.js
screencast is now available over at &lt;a href="http://bit.ly/bb-casts"&gt;backbonescreencasts.com&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This new one takes a step by step look at how to create a Backbone.js application to
improve the user experience in an existing Rails 3.1 application.&lt;/p&gt;

&lt;h2&gt;&lt;a href="http://backbonescreencasts.com/backbone-on-rails-basics"&gt;Watch A Preview&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/11/08/backbone-dot-js-on-rails-basics-new-screencast-available/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/BcCDB5_6ybc" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/11/08/backbone-dot-js-on-rails-basics-new-screencast-available/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Announcing Backbone.js Quickly - A 90+ Minute Screencast]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/uQOPKnTC8OU/" />
<updated>2011-10-17T09:31:00-04:00</updated>
<id>http://joeybeninghove.com/2011/10/17/announcing-backbone-dot-js-quickly-a-90-plus-minute-screencast</id>

      <content type="html">&lt;p&gt;I really enjoy using and teaching others about Backbone.js.  So I decided to
&lt;a href="http://backbonescreencasts.com"&gt;launch a new site&lt;/a&gt; specifically for delivering
screencasts on Backbone.js.  The first installment is now available!&lt;/p&gt;

&lt;h2&gt;Backbone.js Quickly&lt;/h2&gt;

&lt;p&gt;Learn how to build a complete Backbone.js application from the ground up! To watch
a preview and purchase this screencast, head on over to &lt;a href="http://backbonescreencasts.com"&gt;backbonescreencasts.com&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/10/17/announcing-backbone-dot-js-quickly-a-90-plus-minute-screencast/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/uQOPKnTC8OU" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/10/17/announcing-backbone-dot-js-quickly-a-90-plus-minute-screencast/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Rails 3.1 Startup Time - 43% Improvement With Ruby 1.9.3-rc1]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/wWILf_dveqE/" />
<updated>2011-10-05T14:21:00-04:00</updated>
<id>http://joeybeninghove.com/2011/10/05/rails-3-dot-1-startup-time-43-percent-improvement-with-ruby-1-dot-9-3-rc1</id>

      <content type="html">&lt;p&gt;Quick little screencast showing how much just a simple move to Ruby 1.9.3-rc1 can speed up your
Rails 3.1 startup time by up to 43%!&lt;/p&gt;

&lt;iframe src="http://player.vimeo.com/video/30092064" width="650" height="500" frameborder="0" webkitAllowFullScreen allowFullScreen&gt;&lt;/iframe&gt;


&lt;h3&gt;If you like these types of screencasts, be sure to sign up for &lt;a href="http://castingcode.tv"&gt;CastingCode.tv&lt;/a&gt;!&lt;/h3&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/10/05/rails-3-dot-1-startup-time-43-percent-improvement-with-ruby-1-dot-9-3-rc1/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/wWILf_dveqE" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/10/05/rails-3-dot-1-startup-time-43-percent-improvement-with-ruby-1-dot-9-3-rc1/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Rails 3.1, Asset Pipeline, Sass Syntax & Heroku]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/FWeWL47M_8k/rails-31-asset-pipeline-sass-syntax-heroku" />
<updated>2011-10-01T23:12:00-04:00</updated>
<id>http://joeybeninghove.com/2011/10/01/rails-31-asset-pipeline-sass-syntax-heroku</id>

      <content type="html">&lt;p&gt;I&amp;#8217;m starting to build out my first Rails application on Heroku (cedar stack), ever.  Yes, I know, I&amp;#8217;m really late to
the party.  But I just ran across something that might be causing folks trouble if they&amp;#8217;re attempting
to deploy a Rails 3.1 application to Heroku and prefer the &lt;code&gt;sass&lt;/code&gt; syntax over the default &lt;code&gt;scss&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;(First off I want to say thanks to Benjamin Atkin for giving me the idea for this fix in
&lt;a href="http://benatkin.com/2011/09/28/adding-compass-to-a-heroku-app"&gt;this blog post about Compass and Heroku&lt;/a&gt;.)&lt;/p&gt;

&lt;p&gt;&lt;span class='pullquote-right' data-pullquote='As much grief as I get over it, I am still an old school Sass guy'&gt;
As much grief as I get over it, I am still an old school Sass guy and still prefer the &lt;code&gt;sass&lt;/code&gt; syntax
instead of the default &lt;code&gt;scss&lt;/code&gt; that is shipped with Rails 3.1.  Thankfully, this is quite easy to change
in the Rails configuration as show here.
&lt;/span&gt;&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;application.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;# Prefer SASS, &amp;#39;cause that&amp;#39;s what real men use :)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;preferred_syntax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ss"&gt;:sass&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;However, when you try to deploy this Heroku, the server fails to start.  This can be discovered by running
&lt;code&gt;heroku logs&lt;/code&gt;.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;from output of &amp;#8216;heroku logs&amp;#8217;&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='plain'&gt;&lt;span class='line'&gt;/app/vendor/bundle/ruby/1.9.1/gems/railties-3.1.0/lib/rails/railtie/configuration.rb:78:in 
&lt;/span&gt;&lt;span class='line'&gt;`method_missing': undefined method `sass' for #&amp;lt;Rails::Application::Configuration:0x000000016152c8&gt; 
&lt;/span&gt;&lt;span class='line'&gt;(NoMethodError)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;As pointed out in Benjamin&amp;#8217;s post, this is because&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;&amp;#8230;Heroku only runs with the asset gems from the Gemfile when it compiles the assets, and it only compiles the assets when a new slug is loaded.&lt;/p&gt;&lt;footer&gt;&lt;strong&gt;Benjamin Atkin&lt;/strong&gt; &lt;cite&gt;&lt;a href='http://benatkin.com/2011/09/28/adding-compass-to-a-heroku-app'&gt;Adding Compass to a Heroku App&lt;/a&gt;&lt;/cite&gt;&lt;/footer&gt;&lt;/blockquote&gt;


&lt;p&gt;So I took his idea and created a Sass initializer to handle the setting of this for me, only when
a Sass configuration object is available.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;config/initializers/sass.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;respond_to?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:sass&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;configuration&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sass&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;tap&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;# Prefer SASS, &amp;#39;cause that&amp;#39;s what real men use :)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;preferred_syntax&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="ss"&gt;:sass&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;h2&gt;UPDATE 10/02/2011&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Just found out that the initializer above won&amp;#8217;t actually get run when you run &lt;code&gt;rails generate&lt;/code&gt;, which
kind of defeats the purpose.  So this code must be run from &lt;code&gt;application.rb&lt;/code&gt;, either included directly
or required.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By doing this, it allows the Heroku &lt;code&gt;cedar&lt;/code&gt; stack to properly precompile the assets and successfully
start the Rails server.&lt;/p&gt;

&lt;p&gt;One other way to &amp;#8220;fix&amp;#8221; this issue is to move the &lt;code&gt;sass-rails&lt;/code&gt; gem into the global group in your &lt;code&gt;Gemfile&lt;/code&gt;.
But I think I prefer the solution above so I don&amp;#8217;t have to pollute the global gem group with an unnecessary
gem just to satisfy Heroku deployment.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/10/01/rails-31-asset-pipeline-sass-syntax-heroku"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/FWeWL47M_8k" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/10/01/rails-31-asset-pipeline-sass-syntax-heroku</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Vim Macros - 5 Minute Screencast]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/9Qt8E1YGD6I/" />
<updated>2011-09-28T19:26:00-04:00</updated>
<id>http://joeybeninghove.com/2011/09/28/vim-macros-5-minute-screencast</id>

      <content type="html">&lt;p&gt;The other day as I was converting this blog over to &lt;a href="http://octopress.org"&gt;Octopress&lt;/a&gt;, I recorded
a short little screencast on how I was able to use Vim macros to make migrating my old blog posts a
LOT easier.  This was the result&amp;#8230;&lt;/p&gt;

&lt;p&gt;(HINT: Best watched in HD mode, full screen)&lt;/p&gt;

&lt;iframe src="http://player.vimeo.com/video/29534416" width="650" height="254" frameborder="0" webkitAllowFullScreen allowFullScreen&gt;&lt;/iframe&gt;


&lt;h2&gt;Don&amp;#8217;t forget to sign up for &lt;a href="http://castingcode.tv"&gt;CastingCode.tv&lt;/a&gt; to see more!&lt;/h2&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/09/28/vim-macros-5-minute-screencast/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/9Qt8E1YGD6I" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/09/28/vim-macros-5-minute-screencast/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Coder Talk - New Website &amp; iTunes Feed!]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/5GgawhH-SbQ/" />
<updated>2011-09-25T01:22:00-04:00</updated>
<id>http://joeybeninghove.com/2011/09/25/coder-talk-new-website-and-itunes-feed</id>

      <content type="html">&lt;p&gt;&lt;a href="http://codertalkshow.com"&gt;Coder Talk&lt;/a&gt;, the weekly conversation I started with developers that has turned into a podcast, is
growing up a bit now.  I&amp;#8217;ve created a &lt;a href="http://codertalkshow.com"&gt;simple website&lt;/a&gt; and an
&lt;a href="feed://codertalkshow.com/home/rss.xml"&gt;audio RSS feed&lt;/a&gt; for it now.  It is also listed in the
&lt;a href="http://itunes.apple.com/us/podcast/coder-talk/id465742480"&gt;iTunes podcast directory&lt;/a&gt;.  So to keep
up to date on the latest episodes, visit that site and subscribe to the podcast.  We&amp;#8217;d love to know
what you think about it!&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/09/25/coder-talk-new-website-and-itunes-feed/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/5GgawhH-SbQ" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/09/25/coder-talk-new-website-and-itunes-feed/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Coder Talk - Episode 3 - Javascript inheritance, Pair programming, VMs, Static site generators and more!]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/D87QDXQwdA8/" />
<updated>2011-08-25T06:30:00-04:00</updated>
<id>http://joeybeninghove.com/2011/08/25/coder-talk-3</id>

      <content type="html">&lt;p&gt;Another long episode of Coder Talk is here, hosted by myself and &lt;a href="http://derickbailey.lostechies.com"&gt;Derick Bailey&lt;/a&gt;.  This week we are joined by &lt;a href="http://userobsessed.net"&gt;Joe Fiorini&lt;/a&gt;, &lt;a href="http://twitter.com/alanaudette"&gt;Alan Audette&lt;/a&gt;, &lt;a href="http://twitter.com/nathanpalmer"&gt;Nathan Palmer&lt;/a&gt;, &lt;a href="http://twitter.com/paulyoder"&gt;Paul Yoder&lt;/a&gt; and &lt;a href="http://th3mus1cman.me"&gt;Thomas Brewer&lt;/a&gt;.  We discuss javascript inheritance, the joys of pair programming, which VM product can beat up the other VM product&amp;#8217;s daddy and our love for static blogs including an interesting idea from Joe.  We also heard a great success story from Paul on building a lean, profitable software product, &lt;a href="http://donorelf.com"&gt;DonorElf&lt;/a&gt;.  Finally, we wrapped things up giving tons of love to one of our favorite products out there right now, &lt;a href="http://kickofflabs.com"&gt;KickoffLabs&lt;/a&gt; and talk about some of the projects we&amp;#8217;re all working on.&lt;/p&gt;

&lt;p&gt;Please let us know what you think by leaving a comment below.  Enjoy!&lt;/p&gt;

&lt;p&gt;&lt;audio controls="controls"&gt;
  &lt;source src="http://coder-talk.s3.amazonaws.com/coder-talk-3.mp3" type="audio/mpeg" /&gt;
  Your browser does not support playing this audio.  Please download the MP3 file using the link below.
&lt;/audio&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Runtime: 1:30:30&lt;/li&gt;
&lt;li&gt;Download: &lt;a href="http://coder-talk.s3.amazonaws.com/coder-talk-3.mp3"&gt;MP3 File (86.9 MB)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Links From The Show&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://maccman.github.com/spine"&gt;Spine&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.crockford.com/javascript/inheritance.html"&gt;Classical Inheritance in JavaScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://secure.logmein.com/products/hamachi"&gt;Hamachi&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://showoff.io"&gt;showoff.io&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://vmware.com"&gt;VMWare&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.parallels.com"&gt;Parallels&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.virtualbox.org"&gt;Virtual Box&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://thecheckin.densitypop.com"&gt;The Check In&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/mojombo/jekyll/wiki"&gt;Jekyll&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://octopress.org"&gt;Octopress&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://octocast.org"&gt;Octocast&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://kickofflabs.com"&gt;KickoffLabs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://donorelf.com"&gt;DonorElf&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://bluefinpad.net"&gt;Bluefinpad.net&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://refactoringtobackbone.com"&gt;Refactoring to Backbone&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.telestream.net/screen-flow"&gt;Screenflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://castingcode.tv"&gt;CastingCode.tv&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/08/25/coder-talk-3/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/D87QDXQwdA8" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/08/25/coder-talk-3/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Coder Talk - Episode 2 - CoffeeScript, Sass, .NET to Ruby, Vim and more!]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/2MikCf82Ei8/" />
<updated>2011-08-21T08:00:00-04:00</updated>
<id>http://joeybeninghove.com/2011/08/21/coder-talk-episode-2</id>

      <content type="html">&lt;p&gt;In this week&amp;#8217;s marathon Coder Talk, my co-host &lt;a href="http://derickbailey.lostechies.com"&gt;Derick Bailey&lt;/a&gt; and I are joined by &lt;a href="http://th3mus1cman.me"&gt;Thomas Brewer&lt;/a&gt; and &lt;a href="http://twitter.com/nathanpalmer"&gt;Nathan Palmer&lt;/a&gt; to discuss Coffeescript, Haml, Sass, PHP unit testing and frameworks, transitioning from .NET to Ruby, Vim and whether or not it makes you more productive, iPads with kids and how the Kahn Academy is changing how we educate our kids.  We had a blast in this episode!&lt;/p&gt;

&lt;p&gt;Please let us know what you think by leaving a comment below.  Enjoy!&lt;/p&gt;

&lt;p&gt;&lt;audio controls="controls"&gt;
  &lt;source src="http://coder-talk.s3.amazonaws.com/coder-talk-2.mp3" type="audio/mpeg" /&gt;
  Your browser does not support playing this audio.  Please download the MP3 file using the link below.
&lt;/audio&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Runtime: 1:25:41&lt;/li&gt;
&lt;li&gt;Download: &lt;a href="http://coder-talk.s3.amazonaws.com/coder-talk-2.mp3"&gt;MP3 File (82.3 MB)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Links From The Show&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://jashkenas.github.com/coffee-script"&gt;CoffeeScript&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://haml-lang.com"&gt;Haml&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://sass-lang.com"&gt;Sass&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://fatfree.sourceforge.net"&gt;FatFree&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://kohanaframework.org"&gt;Kohana&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.khanacademy.org"&gt;Kahn Academy&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/08/21/coder-talk-episode-2/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/2MikCf82Ei8" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/08/21/coder-talk-episode-2/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Confronting My Fear Of Speaking - A Stutterer's Journey]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/vKKjJB8x8O0/" />
<updated>2011-08-20T19:15:00-04:00</updated>
<id>http://joeybeninghove.com/2011/08/20/confronting-my-fear-of-speaking-a-stutterers-journey</id>

      <content type="html">&lt;p&gt;I debated about whether or not to publish this because it is a hard post for me to write.  I have never written or really spoken publicly about this, because it is quite personal to me.  However, now that I&amp;#8217;m starting to get back involved in various activities that require me to speak publicly, such as &lt;a href="http://joeybeninghove.com/2011/08/16/backbone-screencast-introduction-views"&gt;screencasts&lt;/a&gt;, &lt;a href="http://joeybeninghove.com/2011/08/15/laid-back-late-night-code-talks-interested"&gt;podcasts&lt;/a&gt;, &lt;a href="http://webinars.developwithpassion.com/webinars/7"&gt;webinars&lt;/a&gt; and user group presentations, I felt it would just be easier to address this issue here in a central place.&lt;/p&gt;

&lt;h2&gt;No Pity Parties Please&lt;/h2&gt;

&lt;p&gt;I am blessed by God beyond measure and seek every day to be thankful for what He has given to me and my family.  Speaking of, my family alone is the biggest blessing I could ever receive.  So in the grand scheme of things, the fact that I&amp;#8217;ve had trouble speaking most of my life is just dust in the wind.  My goal here is &lt;strong&gt;not&lt;/strong&gt; to seek pity, but to simply clear the air about this topic as it relates to things I&amp;#8217;m planning to do in the future.  Think of it as squashing the big elephant in the room.  :)&lt;/p&gt;

&lt;h2&gt;A Little Background&lt;/h2&gt;

&lt;p&gt;For as long as I can remember, I&amp;#8217;ve been afraid of speaking.  Not because I don&amp;#8217;t like people (although that&amp;#8217;s often what I joke about).  Nor is it because I don&amp;#8217;t like interacting with folks; I enjoy that very much.  It&amp;#8217;s because I&amp;#8217;ve always struggled with some form of &lt;a href="http://en.wikipedia.org/wiki/Stuttering"&gt;stuttering&lt;/a&gt; (or stammering).  Only those that struggle with the same thing can really understand the impact this kind of speech impediment has on your everyday life.  Knowing exactly what you want to say and how you want to say it, but not physically being able to, can take its toll sometimes.  There are often specific words that I want to say, but I decide to change them to a word I feel I can more easily get out without stuttering.  Folks who stutter will know &lt;strong&gt;exactly&lt;/strong&gt; what I&amp;#8217;m talking about here.  Not many people have to consciously think about talking or breathing.  They simply do it and then carry on about their day.  Along with many other stutterers, that&amp;#8217;s not my reality.  For me, every sentence, every word, every syllable requires conscious thought to get from my brain and out through my mouth.  I have my good and bad days.&lt;/p&gt;

&lt;p&gt;I used to be fairly involved in public presentations and even &lt;a href="http://lostechies.com/joeybeninghove/2007/12/08/monorail-quickly-screencast"&gt;some screencasts&lt;/a&gt; years ago.  In fact, after much prayer beforehand, the talk I gave back in 2008 on &lt;a href="http://lostechies.com/joeybeninghove/2008/09/05/mvc-free-yourself-from-web-forms"&gt;ASP.NET MVC at our local .NET user group&lt;/a&gt; went off without a hitch.  I talked for 90 minutes straight without a single hiccup!  That was amazing and I definitely give God the credit for that victory.&lt;/p&gt;

&lt;p&gt;There is lots more I could share along these lines, but that&amp;#8217;s not really the ultimate point of this post.&lt;/p&gt;

&lt;h2&gt;Rebirth, Of Sorts&lt;/h2&gt;

&lt;p&gt;Recently, I have started getting back into some activities that require me to speak publicly.  I gave a &lt;a href="http://webinars.developwithpassion.com/webinars/4"&gt;webinar on Backbone a few weeks ago&lt;/a&gt;, published a &lt;a href="http://joeybeninghove.com/2011/08/16/backbone-screencast-introduction-views"&gt;screencast on Backbone&lt;/a&gt; and am starting to get more active in our local Ruby user group &lt;a href="http://cvreg.org"&gt;CVREG&lt;/a&gt;.  In fact, I&amp;#8217;m even starting a &lt;a href="http://castingcode.tv"&gt;new online service&lt;/a&gt; to bring live coding sessions and events to the web, which will probably start out with myself as the main &amp;#8220;code caster&amp;#8221;.  On top of all that I&amp;#8217;ve started hosting a &lt;a href="http://joeybeninghove.com/2011/08/15/laid-back-late-night-code-talks-interested"&gt;weekly chat with fellow developers&lt;/a&gt;, along with my co-host &lt;a href="http://lostechies.com/derickbailey"&gt;Derick Bailey&lt;/a&gt;.  I really enjoy doing these things and as an independent software consultant/aspriring &lt;a href="http://30cubits.com"&gt;microprenuer&lt;/a&gt;, it is also quite an important aspect of my job.  Some may ask why I don&amp;#8217;t just focus on non-speaking activities like writing books or blogging instead of those that require me to speak publicly.  While I do enjoy blogging and writing sometimes, I also enjoy interacting with folks face to face and via voice calls over Skype for example.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve decided I can&amp;#8217;t let my fear of speaking publicly prevent me from pursuing the things I love and want to do.  It&amp;#8217;s been a long time since I&amp;#8217;ve actively tried to improve my speech, but I&amp;#8217;m going to try and pick up that stick again.  All I can ask from you folks that have and/or will watch and listen to me speak in the future is to bear with me as I try to improve.  On a final note, thanks to everyone who has given me positive feedback on my &lt;a href="http://joeybeninghove.com/2011/08/16/backbone-screencast-introduction-views"&gt;recent screencast&lt;/a&gt;.  Perhaps now you can understand why it means so much to me.  :)&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;/p&gt;

&lt;p&gt;Joey&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/08/20/confronting-my-fear-of-speaking-a-stutterers-journey/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/vKKjJB8x8O0" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/08/20/confronting-my-fear-of-speaking-a-stutterers-journey/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Backbone.js Screencast - Introduction and Views]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/rQjeLUTeC4Q/" />
<updated>2011-08-16T06:00:00-04:00</updated>
<id>http://joeybeninghove.com/2011/08/16/backbone-screencast-introduction-views</id>

      <content type="html">&lt;p&gt;A couple weeks ago I gave a &lt;a href="http://webinars.developwithpassion.com/webinars/4"&gt;webinar for Develop with Passion&lt;/a&gt; on Backbone.js.  Unfortunately there was a problem with the recording, so I decided to redo what I covered in screencast form.  In this screencast I give a basic introduction on how to bootstrap a new Backbone.js application and go in-depth on how to use Backbone Views in particular.&lt;/p&gt;

&lt;h3&gt;If you like this screencast, check out &lt;a href="http://backbonescreencasts.com"&gt;Backbone.js Screencasts&lt;/a&gt; for more screencasts targeted specifically to Backbone.js!&lt;/h3&gt;

&lt;iframe src="http://player.vimeo.com/video/27723557?title=0&amp;amp;byline=0&amp;amp;portrait=0&amp;amp;color=ff9933" width="650" height="500" frameborder="0"&gt;&lt;/iframe&gt;


&lt;p&gt;&lt;em&gt;Oh, and you might want to watch until the end&amp;#8230; just sayin&amp;#8217;&lt;/em&gt;  :)&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/08/16/backbone-screencast-introduction-views/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/rQjeLUTeC4Q" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/08/16/backbone-screencast-introduction-views/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Laid back, late-night code talks, interested?]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/QdK_OFLnD8Y/" />
<updated>2011-08-14T06:30:00-04:00</updated>
<id>http://joeybeninghove.com/2011/08/14/laid-back-late-night-code-talks-interested</id>

      <content type="html">&lt;p&gt;Last week, I had a crazy notion of wanting to get a few other Ruby developers together for a completely informal late-night group chat about testing, gem dependencies and dealing with large Rails applications.  Many thanks to &lt;a href="http://bphogan.com"&gt;Brian Hogan&lt;/a&gt;, &lt;a href="http://derickbailey.lostechies.com"&gt;Derick Bailey&lt;/a&gt; and &lt;a href="http://melriffe.info"&gt;Mel Riffe&lt;/a&gt; for hanging with me in a Google+ Hangout last Wednesday night.  I learned a ton and it was a LOT of fun!&lt;/p&gt;

&lt;p&gt;So, I kind of want to make this a regular thing, possibly weekly.  Using a Google+ Hangout worked out really well, but it has the disadvantage that folks with GAFYD accounts can&amp;#8217;t access Google+ (srsly, Google?!?).  Perhaps Skype would be a better, more accessible choice.  We&amp;#8217;ll figure that part out if there is enough interest.&lt;/p&gt;

&lt;p&gt;At this point, I think the 2nd &amp;#8220;code talk&amp;#8221; is going to happen this Wednesday evening (hosted by &lt;a href="http://castingcode.tv"&gt;CastingCode.tv&lt;/a&gt;), time TBA.  If this is something you&amp;#8217;d be interested in, leave a comment below or &lt;a href="mailto:joey@30cubits.com"&gt;shoot me an email&lt;/a&gt; and let me know and also suggest some topic ideas.  I&amp;#8217;ve thought about starting to record these, so also let me know if that would be an issue for you.&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/08/14/laid-back-late-night-code-talks-interested/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/QdK_OFLnD8Y" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/08/14/laid-back-late-night-code-talks-interested/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Doubling speed of specs with Spork, when using Mongoid inheritance/preloading]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/KKC05f9wBec/" />
<updated>2011-08-10T08:00:00-04:00</updated>
<id>http://joeybeninghove.com/2011/08/10/doubling-speed-of-specs-with-spork-when-using-mongoid-inheritance-and-preloading</id>

      <content type="html">&lt;p&gt;&lt;img class="" src="http://joeybeninghove.com/images/posts/speed.jpg" title="[650 239] [Speed!!!]" &gt;&lt;/p&gt;

&lt;h2&gt;Background&lt;/h2&gt;

&lt;p&gt;Ok, so this is going to require a bit of background explanation.  In one of my current Rails apps, we are using &lt;a href="http://mongoid.org"&gt;Mongoid&lt;/a&gt;.  We are also using quite a bit of inheritance in our Mongoid models.  Whether or not that&amp;#8217;s a good thing is a topic for another blog post.  :)  Well in the current version of Mongoid, if you use inheritance, you have to preload all of your Mongoid models on application startup so that it can properly perform queries and persistence.  I&amp;#8217;ve benchmarked the preloading process and in this app, it takes about 4 seconds.  &lt;a href="https://twitter.com/modetojoy/status/100973092263821312"&gt;Durran commented the other day&lt;/a&gt; saying that this should improve once Rails 3.1 becomes official.  Regardless, the Mongoid preloading was actually not the worst of our speed problems.&lt;/p&gt;

&lt;h2&gt;Baseline benchmark&lt;/h2&gt;

&lt;p&gt;One of the things that&amp;#8217;s been bugging me is how long it takes to run a simple spec in this app, mainly the &amp;#8220;setup&amp;#8221; process to load the Rails environment, etc.  Let&amp;#8217;s take a look at how bad this was for us.  First, here is how our spec_helper looked:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;spec_helper.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;RAILS_ENV&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;test&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expand_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;../../config/environment&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;__FILE__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="no"&gt;Dir&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;spec/support/**/*.rb&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="n"&gt;each&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="no"&gt;RSpec&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mock_with&lt;/span&gt; &lt;span class="ss"&gt;:rspec&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# some data seeding here&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;And here is the result of running one simple spec, which doesn&amp;#8217;t even do anything:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='line'&gt;&amp;gt;&amp;gt; &lt;span class="nb"&gt;time &lt;/span&gt;rspec spec/foo_spec.rb
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;Pending:
&lt;/span&gt;&lt;span class='line'&gt;  foo should &lt;span class="k"&gt;do &lt;/span&gt;something
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c"&gt;# Not Yet Implemented&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c"&gt;# ./spec/foo_spec.rb:4&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;Finished in 1.7 seconds
&lt;/span&gt;&lt;span class='line'&gt;1 example, 0 failures, 1 pending
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;real  0m18.958s
&lt;/span&gt;&lt;span class='line'&gt;user  0m16.360s
&lt;/span&gt;&lt;span class='line'&gt;sys 0m1.882s
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;&lt;strong&gt;18 seconds!!!&lt;/strong&gt;  Absolutely ridiculous amount of time to simply perform the setup process for running a spec.  Let&amp;#8217;s see if we can improve this a bit.&lt;/p&gt;

&lt;h2&gt;Enter Spork, attempt #1&lt;/h2&gt;

&lt;p&gt;I kept hearing about folks using &lt;a href="https://github.com/timcharper/spork"&gt;Spork&lt;/a&gt; to speed up their Rails environment loading, which includes speeding up spec runs.  So after getting Spork installed, here is what my spec_helper looked like:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;spec_helper.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;span class='line-number'&gt;18&lt;/span&gt;
&lt;span class='line-number'&gt;19&lt;/span&gt;
&lt;span class='line-number'&gt;20&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;spork&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="no"&gt;Spork&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prefork&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;RAILS_ENV&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;test&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# this loads the environment and all initializers, which includes our mongoid&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# preloading, so this is not a good idea since we&amp;#39;d have to restart spork&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# every time we changed our model code.&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expand_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;../../config/environment&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;__FILE__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;Dir&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;spec/support/**/*.rb&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="n"&gt;each&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="no"&gt;Spork&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;each_run&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;RSpec&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mock_with&lt;/span&gt; &lt;span class="ss"&gt;:rspec&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;# some data seeding here...&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;This would normally work great, but since we have to preload our Mongoid models on application startup (due to inheritance), this would mean that any time we made changes to our Mongoid models, we&amp;#8217;d have to restart Spork.  That of course kind of defeats the purpose of using Spork in the first place.  So I did a bit more digging into the Rails boot process to see how I could make this work, because I really wanted to leverage Spork for at least &lt;strong&gt;some&lt;/strong&gt; of our Rails environment loading.&lt;/p&gt;

&lt;h2&gt;Brief lesson in what environment.rb actually does&lt;/h2&gt;

&lt;p&gt;Opening up &lt;strong&gt;environment.rb&lt;/strong&gt; revealed that it is actually doing 2 things in separate steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;requiring the &lt;strong&gt;application.rb&lt;/strong&gt; file&lt;/li&gt;
&lt;li&gt;calling initialize on the Application class contained in &lt;strong&gt;application.rb&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;environment.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;# Load the rails application&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expand_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;../application&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;__FILE__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;# Initialize the rails application&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;# This is also when the Mongoid models get preloaded&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="no"&gt;MyApp&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Application&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;initialize!&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;That was a nice little hint that got me thinking about a possible solution.  But first&amp;#8230;&lt;/p&gt;

&lt;h2&gt;Understanding when gems get loaded by Bundler&lt;/h2&gt;

&lt;p&gt;After a bit more benchmarking, I noticed that the actual require of gems by Bundler was taking 8-9 seconds.  That is done in inside of application.rb shown here:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;application.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expand_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;../boot&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;__FILE__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c1"&gt;# various requires here...&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="no"&gt;Bundler&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:default&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;defined?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="no"&gt;Bundler&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;MyApp&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Application&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Application&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;# usual app init stuff here...&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;But notice one very important piece of information here.  The Bundler.require call is made &lt;strong&gt;outside&lt;/strong&gt; of the Application class.  That means that as soon as this file is required, then the Bundler.require call is getting made.  Looking back at the first thing that our &lt;strong&gt;environment.rb&lt;/strong&gt; does, that means the first step ends up requiring all gems using Bundler.  The very thing that was taking the most time.  This is also one of those things we can definitely add to our prefork block for Spork, because those aren&amp;#8217;t likely to change very much during day to day development.&lt;/p&gt;

&lt;h2&gt;Spork, attempt #2&lt;/h2&gt;

&lt;p&gt;Armed with a bit more knowledge on the Rails environment loading process and which parts are actually taking the most time, let&amp;#8217;s change our &lt;strong&gt;spec_helper&lt;/strong&gt; a bit.&lt;/p&gt;

&lt;figure class='code'&gt;&lt;figcaption&gt;&lt;span&gt;spec_helper.rb&lt;/span&gt;&lt;/figcaption&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;span class='line-number'&gt;18&lt;/span&gt;
&lt;span class='line-number'&gt;19&lt;/span&gt;
&lt;span class='line-number'&gt;20&lt;/span&gt;
&lt;span class='line-number'&gt;21&lt;/span&gt;
&lt;span class='line-number'&gt;22&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;spork&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="no"&gt;Spork&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;prefork&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;ENV&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;RAILS_ENV&amp;quot;&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;||=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;test&amp;#39;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# notice i&amp;#39;m NOT loading the full environment.rb here, only application.rb&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="no"&gt;File&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;expand_path&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;../../config/application&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="bp"&gt;__FILE__&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;Dir&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;root&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;join&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;spec/support/**/*.rb&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="n"&gt;each&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;require&lt;/span&gt; &lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="no"&gt;Spork&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;each_run&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# this is the important part, still calling initialize on each run&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="c1"&gt;# because this is when the mongoid models get preloaded&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;MyApp&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Application&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;initialize!&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="no"&gt;RSpec&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;configure&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;mock_with&lt;/span&gt; &lt;span class="ss"&gt;:rspec&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;# some data seeding here...&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Notice now that we&amp;#8217;re not requiring &lt;strong&gt;environment.rb&lt;/strong&gt; anymore in our prefork block, but instead requiring &lt;strong&gt;application.rb&lt;/strong&gt; directly.  This ensures that all gems get loaded only once, when starting up Spork for the first time.  This immediately shaves off 8-9 seconds off of the time it takes to run our specs in this case.&lt;/p&gt;

&lt;p&gt;Also important to note is down in the each_run block for Spork, I&amp;#8217;ve added the MyApp::Application.initialize! call because that&amp;#8217;s when our Mongoid models get preloaded.  This ensures that we&amp;#8217;re able to change our model code and have it automatically reflected in our next test run.&lt;/p&gt;

&lt;p&gt;After starting up Spork, let&amp;#8217;s see how long our spec takes to run now:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='line'&gt;&amp;gt;&amp;gt; &lt;span class="nb"&gt;time &lt;/span&gt;rspec --drb spec/foo_spec.rb
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;Pending:
&lt;/span&gt;&lt;span class='line'&gt;  foo should &lt;span class="k"&gt;do &lt;/span&gt;something
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c"&gt;# Not Yet Implemented&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c"&gt;# ./spec/foo_spec.rb:4&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;Finished in 1.81 seconds
&lt;/span&gt;&lt;span class='line'&gt;1 example, 0 failures, 1 pending
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;real  0m8.914s
&lt;/span&gt;&lt;span class='line'&gt;user  0m0.214s
&lt;/span&gt;&lt;span class='line'&gt;sys 0m0.080s
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;&lt;strong&gt;8 seconds!!!&lt;/strong&gt;  For most folks this would be pitiful, but moving down from 18 seconds down to 8 seconds, I&amp;#8217;d say that&amp;#8217;s a pretty big improvement.  Hoping to continue improving the speed of our specs, but I thought this was a great start.  Hopefully this will help some folks who are struggling using Spork and Mongoid together in the same application.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(image by &lt;a href="http://www.sxc.hu/profile/vivekchugh"&gt;vivekchugh&lt;/a&gt;)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/08/10/doubling-speed-of-specs-with-spork-when-using-mongoid-inheritance-and-preloading/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/KKC05f9wBec" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/08/10/doubling-speed-of-specs-with-spork-when-using-mongoid-inheritance-and-preloading/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[P90X Portion Chart - Bento Template]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/XtiPIuGTbwo/" />
<updated>2011-08-08T18:00:00-04:00</updated>
<id>http://joeybeninghove.com/2011/08/08/p90x-portion-chart-bento-template</id>

      <content type="html">&lt;p&gt;So I&amp;#8217;ve been wanting a way to track my &lt;a href="http://www.teambeachbody.com/workout-routines/p90x-workout"&gt;P90X&lt;/a&gt; nutrition program on my iPhone for a while now.  There have been a couple iPhone apps that have appeared/disappeared in the App Store due to violation with the Beach Body folks, who created the P90X program.  There have been &lt;a href="http://www.teambeachbody.com/connect/message-boards/-/message_boards/search?_19_redirect=%2Fconnect%2Fmessage-boards&amp;amp;_19_breadcrumbsCategoryId=0&amp;amp;_19_searchCategoryIds=0&amp;amp;_19_advanced=false&amp;amp;_19_keywords=iphone+app&amp;amp;_19_categoryOnly=on&amp;amp;_19_searchType=0&amp;amp;_19_titleAndOrBody=0&amp;amp;_19_fromDate=&amp;amp;_19_toDate=08%2F08%2F2011&amp;amp;_19_screenName="&gt;rumors about Beach Body themselves creating an iPhone app&lt;/a&gt; but no idea what&amp;#8217;s going on with that.&lt;/p&gt;

&lt;p&gt;&lt;img src='http://joeybeninghove.com/images/posts/bento-iphone.jpg' alt='Bento for iPhone' class='right-image-no-border' /&gt;&lt;/p&gt;

&lt;p&gt;As much as I&amp;#8217;d love to make an attempt at building my own iPhone app for this, I have no time for that right now and just need a simple solution to get me by.  Enter, &lt;a href="http://www.filemaker.com/products/bento/iphone.html"&gt;Bento for iPhone&lt;/a&gt;!  My needs are very simple.  I just wanted a simple checklist of sorts that I could use to check off how many proteins, carbs, veggies, etc. that I eat in a given day.  No detail about the foods or anything, just simple tracking of how many portions from each group I&amp;#8217;ve eaten.&lt;/p&gt;

&lt;p&gt;So I created this &lt;a href="http://joeybeninghove.com/assets/p90x-phase-1-bento-template.zip"&gt;extremely simple Bento template&lt;/a&gt; that tracks this information for me.  Here&amp;#8217;s what it looks like.&lt;/p&gt;

&lt;p&gt;&lt;img src='http://joeybeninghove.com/images/posts/p90x-bento-template-main.png' alt='P90X Bento Template'
class='bordered' style='margin: 5px' /&gt;
&lt;img src='http://joeybeninghove.com/images/posts/p90x-bento-template-entry.png' alt='P90X Bento Template'
class='bordered' style='margin: 5px'/&gt;&lt;/p&gt;

&lt;p&gt;Very simple solution to a simple need I had.  Perhaps too simple for most folks, but it&amp;#8217;s really all I need right now.  Hopefully this can help some of you guys that migh be on the P90X insane train too.  :)&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/08/08/p90x-portion-chart-bento-template/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/XtiPIuGTbwo" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/08/08/p90x-portion-chart-bento-template/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Keymando Tip - Keeping your config portable]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/YRmS3mYEp7M/" />
<updated>2011-08-05T17:50:00-04:00</updated>
<id>http://joeybeninghove.com/2011/08/05/keymando-tip-keeping-your-config-portable</id>

      <content type="html">&lt;p&gt;&lt;img src='http://joeybeninghove.com/images/posts/keymando.png' alt='Keymando' style='border: none; float: right; box-shadow: none; margin-left: 10px' /&gt;&lt;/p&gt;

&lt;p&gt;One of the tools I&amp;#8217;m having a blast using these days is &lt;a href="http://keymando.com"&gt;Keymando&lt;/a&gt; by his awesomeness &lt;a href="http://kevin.colyar.net"&gt;Kevin
Colyar&lt;/a&gt;.  Being a huge keyboard junkie and mouseless computing fanatic, this is the kind of
tool I&amp;#8217;ve been needing for a long time in OSX.  I will probably be posting my own review of this product after I spend a
bit more time with it.  But I wanted to share a quick tip about managing its configuration file and plugins.&lt;/p&gt;

&lt;p&gt;I have a very specific way I like to manage most my config files and other related &amp;#8216;dot files&amp;#8217;.  I maintain a &lt;a href="https://github.com/joeybeninghove/dotfiles"&gt;&amp;#8216;dotfiles&amp;#8217; Git
repository&lt;/a&gt; under a ~/.dotfiles directory which contains various configs such as my .bashrc, .vimrc, .vim directory and
plugins and many other files that I like to keep portable and versioned.  Then I just symlink all of the necessary configs to
my home directory and everything runs smooth as silk.&lt;/p&gt;

&lt;p&gt;Well as I&amp;#8217;ve started playing around with my Keymando
configuration script (&lt;strong&gt;&lt;em&gt;which happens to be Ruby, how awesome is that!&lt;/em&gt;&lt;/strong&gt;), it feels like the type of config I want to maintain
in my .dotfiles directory.  The default location for Keymando&amp;#8217;s configuration file is under &lt;strong&gt;&lt;em&gt;~/Library/Application
Support/Keymando/keymandorc.rb&lt;/em&gt;&lt;/strong&gt;.  In the current version of Keymando, you can change your target location for its
configuration and plugins directories through its &lt;strong&gt;&lt;em&gt;Setup&lt;/em&gt;&lt;/strong&gt; screen.&lt;/p&gt;

&lt;p&gt;&lt;img src='http://joeybeninghove.com/images/posts/keymando_setup.png' alt='Keymando Setup' style='border: none; box-shadow: none' /&gt;&lt;/p&gt;

&lt;p&gt;You can click each one and it will pop up a dialog allowing you to choose an alternate location for your Keymando
configuration file, directory and plugins directory.  If you manage a &lt;strong&gt;&lt;em&gt;hidden&lt;/em&gt;&lt;/strong&gt; .dotfiles directory like I do,
by default this will not show up in the OSX Finder dialog.  Well I just learned a little tip about &lt;a href="http://www.macworld.com/article/142884/2009/09/106seehidden.html"&gt;how to toggle the
showing/hiding of hidden files/directories in OSX Finder
dialogs&lt;/a&gt;.  You just simply have to press
&lt;strong&gt;&lt;em&gt;Command-Shift-.&lt;/em&gt;&lt;/strong&gt; (that last key is a period) and then I can choose my .dotfiles/keymando directory I&amp;#8217;ve set up to
store my Keymando configuration and plugins, which of course is part of my Git repository so it gets all the benefits of
that as well.&lt;/p&gt;

&lt;p&gt;&lt;img src='http://joeybeninghove.com/images/posts/osx_finder_dialog.png' alt='OSX Finder dialog showing hidden
files/folders' class='bordered' /&gt;&lt;/p&gt;

&lt;p&gt;Each developer/power user typically has their own way of managing configuration files, but hopefully this showed you an
example of one way to keep them nicely organized and more importantly, portable.  And if you haven&amp;#8217;t already, you should
definitely check out &lt;a href="http://keymando.com"&gt;Keymando&lt;/a&gt;.  It is already transforming the way I work and use OSX in a pretty
fundamental way.&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2011/08/05/keymando-tip-keeping-your-config-portable/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/YRmS3mYEp7M" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2011/08/05/keymando-tip-keeping-your-config-portable/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[5 Ways To Battle Coder's Block]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/Nj-ipqMey2s/" />
<updated>2010-10-15T06:00:00-04:00</updated>
<id>http://joeybeninghove.com/2010/10/15/5-ways-to-battle-coders-block</id>

      <content type="html">&lt;p&gt;&lt;img src='http://joeybeninghove.com/images/posts/rock_hard_place.jpg' alt='Between a rock and a hard place'
class='right-image' /&gt;&lt;/p&gt;

&lt;p&gt;So there you are, gearing up to implement the next feature in the application you&amp;#8217;re building, and all of a sudden, BAM!
Coder&amp;#8217;s Block!  I&amp;#8217;ve hit this a few times over the years.  It can be very frustrating knowing what you want the end
result of a solution to look like, but not being able to think with a clear mind and pull it off in an elegant way.  And
I&amp;#8217;m not talking about the general uncertainty of not knowing the specifics of the implementation.  That can happen
frequently and test-first development is probably the best way to combat that.  I&amp;#8217;m talking about the times when you
can&amp;#8217;t even seem to get your mind to cooperate with your hands to literally write the &amp;#8220;correct&amp;#8221; code to solve the
problem before you.&lt;/p&gt;

&lt;p&gt;As I&amp;#8217;m writing this, I&amp;#8217;m coming out of one of these funks myself.  Part of it had to do with the amount of
uncertainty of the larger problem, but the other part had to do with me NOT stepping back, taking my time and really
focusing on the problem for long enough periods of time in one sitting.  As I&amp;#8217;ve pushed myself through another one of
these periods, I&amp;#8217;ve realized there are specific things that usually help me remove the block and get the code flowing
freely again.  Here are a few that work for me&amp;#8230;&lt;/p&gt;

&lt;h2&gt;1. Exercise&lt;/h2&gt;

&lt;p&gt;Recently I&amp;#8217;ve been getting back to the gym, specifically to get back to playing basketball again which I&amp;#8217;ve always
enjoyed.  It&amp;#8217;s probably the most fun way for me to get really good exercise without it &amp;#8220;feeling&amp;#8221; like a boring exercise
routine.  I&amp;#8217;ve found that taking a break in the middle of the day to go shoot some hoops has been really good for me to
help clear my head when the coder&amp;#8217;s block sets in.  When I get back, I&amp;#8217;m tired physically, but usually refreshed mentally.&lt;br/&gt;
The other day I was listening to the first episode of the &lt;a href="http://5by5.tv/founderstalk"&gt;Founders Talk podcast&lt;/a&gt; with Geoffrey
Grosenbach of &lt;a href="http://peepcode.com"&gt;PeepCode&lt;/a&gt; fame and the topic of exercise came up.  Geoffrey talked briefly about how
his physical exercise habits help him in his daily work and coding activities.  Highly recommend you listen to that one!&lt;/p&gt;

&lt;h2&gt;2. Phone a fellow developer&lt;/h2&gt;

&lt;p&gt;Besides being a game show gimmick, calling up a friend and just doing a quick screen sharing session can go a long way.
Just the other night I had a friend help explain to me how he solved a very similiar problem I was having.  Even though
his solution wasn&amp;#8217;t right for my situation, it was still very helpful just talk through the problem I was having out
loud with another human being.  That is certainly one of the challenges of being an indie developer like myself.  You
don&amp;#8217;t always have someone to bounce ideas and problems off of to get feedback.  But thanks to a lot of great friends and
connections I&amp;#8217;ve made over the years and the invention of twitter, being an &amp;#8220;indie&amp;#8221; doesn&amp;#8217;t really mean you&amp;#8217;re alone
anymore.&lt;/p&gt;

&lt;h2&gt;3. Solve small problems&lt;/h2&gt;

&lt;p&gt;Sometimes when I&amp;#8217;m stuck on a sizable problem, I find it&amp;#8217;s good to table it temporarily and find a smaller problem to
solve first just to get the juices flowing again.  To help explain, here are the phases I typically go through when solving
a problem or implementing a new feature.  At the very beginning, I&amp;#8217;m usually pretty psyched up and ready to conquer the
world with my fingertips.  Optimism is high and anything seems possible.  That usually continues for a while and things
get going smoothly, but at some point I hit the zone of &lt;strong&gt;&amp;#8220;ok, I need to push through and get this done&amp;#8221;&lt;/strong&gt; so that I can get
that sense of accomplishment.  I find that the longer I stay in this zone, the more stressed and sloppy I can sometimes
become.  So by picking off a smaller problem to solve quickly, or better yet break the original problem down into
smaller problems, I can plow through it and get that feeling of completing something much quicker and more frequently.
And for me, the act of solving a problem or finishing a feature is a huge rush!&lt;/p&gt;

&lt;h2&gt;4. Play music&lt;/h2&gt;

&lt;p&gt;Many have expounded on the interesting link between programmers and musicians and how the two often go hand in hand.
Having been a long time drummer and percussionist, I guess I fall into that category.&lt;/p&gt;

&lt;h3&gt;Small tangent&lt;/h3&gt;

&lt;p&gt;My take on it is that both music and programming require you to quickly go from the 10,000 foot view of things down to
the incredibly small details then back up in very short periods of time.  Being able to know where you are overall
within a drum fill while nailing that individual 16th note at just the right volume is akin to paying attention to the
desired outcome of the user registration feature while writing the single line of code that ensures a user gets sent a
confirmation email once registration is complete.  Well, hopefully that was a good analogy.  It made sense to me.  :)&lt;/p&gt;

&lt;p&gt;Anyway, if you do happen to play a musical instrument, that can also be a good way to get out of the funk of coder&amp;#8217;s
block.  Forcing yourself to focus your brain on something completely different and as intense as playing music, you
might just find that when you sit back down to code, you have a renewed outlook on the problem at hand with a fresh set
of ideas.  Although it probably won&amp;#8217;t sound as good as that killer open-hat funk groove you just invented on the drum
kit.&lt;/p&gt;

&lt;h2&gt;5. Blow stuff up or kill aliens&lt;/h2&gt;

&lt;p&gt;Ok, so maybe this isn&amp;#8217;t the most productive item in the list, but it&amp;#8217;s gotta be worth a mention.  After all, it does
&lt;a href="http://www.reuters.com/article/idUSTRE68E4OW20100915"&gt;improve decision making&lt;/a&gt;!  :)  Admittedly, I don&amp;#8217;t get to do this
one all that much, but sometimes when I get stuck on a code problem and start thrashing, a few minutes of Gears, CoD
or Halo can be a good break from all that serious work stuff.&lt;/p&gt;

&lt;h2&gt;What about you?&lt;/h2&gt;

&lt;p&gt;So dear reader, what helps you get through the dreaded coder&amp;#8217;s block and get the code shooting out your fingers again?&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2010/10/15/5-ways-to-battle-coders-block/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/Nj-ipqMey2s" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2010/10/15/5-ways-to-battle-coders-block/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[Vlad, RVM and Bundler sittin' in a tree]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/R902VcOtHL8/" />
<updated>2010-09-17T08:21:00-04:00</updated>
<id>http://joeybeninghove.com/2010/09/17/vlad-rvm-and-bundler-sitting-in-a-tree</id>

      <content type="html">&lt;p&gt;(Thanks to Chad for nudging me to write this post :)&lt;/p&gt;

&lt;p&gt;Up until now, my only experience with deploying Rails or any other Ruby-based web application
has been to use the &amp;#8220;standard&amp;#8221; &lt;a href="http://www.capify.org/index.php/Capistrano"&gt;Capistrano&lt;/a&gt;.  For
the main Rails 3 application I&amp;#8217;ve been building the past few months, Capistrano has been fine
and was mostly a set it and forget it kinda thing.&lt;/p&gt;

&lt;p&gt;One of my clients asked me to do a small side project to perform a simple task and naturally I chose
the most excellent &lt;a href="http://www.sinatrarb.com/"&gt;Sinatra&lt;/a&gt; framework.  I could go on and on about the awesomeness of Sinatra, but that&amp;#8217;s
not the point of this post.  Suffice it to say when I finished this small Sinatra application, I needed to
deploy it somehow.  Manual deployments are for the birds, so my first knee-jerk reaction was to get
Capistrano wired up to do the automated deployment.  But after taking a glance at my existing Capistrano
deployment script for my Rails 3 application, it seemed like overkill for this tiny Sinatra ditty.&lt;/p&gt;

&lt;p&gt;&lt;img src='http://joeybeninghove.com/images/posts/vlad.png' alt='Vlad the Deployer' style='float: right; margin: 10px' /&gt;&lt;/p&gt;

&lt;p&gt;The first alternative I ran across was a deployment tool named &lt;a href="http://rubyhitsquad.com/Vlad_the_Deployer.html"&gt;Vlad the Deployer&lt;/a&gt;
(which clearly gets an award for the best name ever).  What attracted me right off the bat was the simplicity of its usage
and configuration.  I also liked the fact that it uses pure Rake for everything, instead of some of the
&amp;#8220;magic&amp;#8221; that Capristrano does under the hood.&lt;/p&gt;

&lt;p&gt;Getting Vlad up and running is pretty straightforward, but I did have a couple issues getting it integrated
into my particular deployment process.  Like all good Ruby developers 2 of my must use tools are
&lt;a href="http://rvm.beginrescueend.com"&gt;RVM&lt;/a&gt; &amp;amp; &lt;a href="http://gembundler.com"&gt;Bundler&lt;/a&gt;.  Bundler is great for managing
gem dependencies and RVM keeps you sane when working with many different versions of Ruby and gems at
the same time.&lt;/p&gt;

&lt;p&gt;One thing I like to do during deployments is make sure &amp;#8220;bundle install&amp;#8221; gets run on the server.&lt;br/&gt;
This ensures that any new gems I&amp;#8217;ve introduced in my Gemfile get automatically installed on the server
during deployment.  Usually this wouldn&amp;#8217;t be much of an issue, but I&amp;#8217;m a pretty big fan of RVM, so much
so that I actually run it on my staging/production servers as well.  RVM does some &lt;em&gt;serious&lt;/em&gt; magic under
the hood, including altering various environment variables affecting the path.  Here is the series of
steps I had to take to get Vlad to properly run &amp;#8220;bundle install&amp;#8221; during deployment.  (NOTE: I&amp;#8217;m mainly
posting this to hopefully get feedback on a better way.  I really don&amp;#8217;t like my solution too much.)&lt;/p&gt;

&lt;h2&gt;Minor server preparation&lt;/h2&gt;

&lt;p&gt;Before I show the deploy script itself, you do need to make sure your server is set up properly with
RVM and Bundler installed in the global gemset.  Here are 2 great articles that describe this process:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.thoughtsincomputation.com/posts/using-phusion-passenger-and-apache2-on-ubuntu-with-rvm-and-gemsets"&gt;Thoughts in Computation - Using Phusion Passenger and Apache2 on Ubuntu with RVM and Gemsets &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://everydayrails.com/2010/09/13/rvm-project-gemsets.html"&gt;RVM and project-specific gemsets in Rails&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Extend Vlad&amp;#8217;s update Rake task&lt;/h2&gt;

&lt;p&gt;Since Vlad uses simple Rake tasks for everything, it&amp;#8217;s easy to &amp;#8220;tack on&amp;#8221; steps before or after the
built in Vlad tasks.  In this case I wanted to run my Bundler command right after the built in update
process was complete.  Here&amp;#8217;s one easy way to do that:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;namespace&lt;/span&gt; &lt;span class="ss"&gt;:vlad&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="ss"&gt;:update&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;# do stuff here that gets run after update is complete&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;FYI, if you want to run something &lt;em&gt;before&lt;/em&gt; the update process starts, you can simply add a dependency
to the built in update task like so:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;namespace&lt;/span&gt; &lt;span class="ss"&gt;:vlad&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="ss"&gt;:update&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ss"&gt;:some_other_task&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;h2&gt;Create a Bundler task&lt;/h2&gt;

&lt;p&gt;Next I created a separate task (see next section about remote_task) to perform the Bundler command I
needed to run on the server and invoked it inside of Vlad&amp;#8217;s built in update task:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;namespace&lt;/span&gt; &lt;span class="ss"&gt;:vlad&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="n"&gt;remote_task&lt;/span&gt; &lt;span class="ss"&gt;:bundle&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="c1"&gt;# do bundler stuff here&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="n"&gt;task&lt;/span&gt; &lt;span class="ss"&gt;:update&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;    &lt;span class="no"&gt;Rake&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;vlad:bundle&amp;#39;&lt;/span&gt;&lt;span class="o"&gt;].&lt;/span&gt;&lt;span class="n"&gt;invoke&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;h2&gt;Remotely running commands via SSH&lt;/h2&gt;

&lt;p&gt;Before I show the commands necessary, it&amp;#8217;s important to understand that all of this will be run in
the context of an SSH session.  Thankfully, there was a nice feature of Vlad that was extracted out
into its own gem known as &lt;a href="http://github.com/seattlerb/rake-remote_task"&gt;remote_task&lt;/a&gt;.&lt;br/&gt;
This is a handy way to run Rake tasks in the context of remote
servers and is used heavily under the hood with Vlad.  We&amp;#8217;re also using it here for our custom Bundler
task and a &amp;#8220;run&amp;#8221; method can be called with whatever commands you want to be run on the remote server in
an SSH session.&lt;/p&gt;

&lt;h2&gt;Step by step&lt;/h2&gt;

&lt;p&gt;For clarity I put each command into its own local variable, each of which I&amp;#8217;ll describe below.&lt;/p&gt;

&lt;h3&gt;Initialize RVM&lt;/h3&gt;

&lt;p&gt;When you login to a server via SSH, you have set of environment variables which include how paths
are resolved when running commands.  Luckily, RVM takes care of all of that for us.  Usually when using
RVM you simply &lt;a href="http://rvm.beginrescueend.com/rvm/install"&gt;load it via your .bashrc&lt;/a&gt;, but for some reason I couldn&amp;#8217;t get this working in the
context of the SSH session used as part of the remote_task.  I&amp;#8217;m sure this is due to my lack of bash and
*nix skills which I&amp;#8217;m actively trying to beef up.  But to work around it for now, I just manually source
the RVM bootstrap script myself:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;init_rvm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;source ~/.rvm/scripts/rvm&amp;quot;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;h3&gt;Trust your RVM gemset&lt;/h3&gt;

&lt;p&gt;I&amp;#8217;m not going to dive into &lt;a href="http://rvm.beginrescueend.com/gemsets/basics"&gt;RVM gemsets&lt;/a&gt; as part of this post, but just think of it as a way to manage gems
in isolation from other applications and environments.  I like to use project-specific gemsets for everything
I do to keep things nice and clean.  A nice companion to gemsets is the use of an &lt;a href="http://rvm.beginrescueend.com/workflow/rvmrc"&gt;.rvmrc file&lt;/a&gt; to
automatically switch to the correct gemset when navigating to your application&amp;#8217;s directory.  Creating a
.rvmrc is stupidly simple:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='plain'&gt;&lt;span class='line'&gt;rvm ree@ema&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;Starting in &lt;a href="http://wayneeseguin.beginrescueend.com/2010/08/22/ruby-environment-version-manager-rvm-1-0-0"&gt;version 1.0 of RVM&lt;/a&gt;,
there was a security measure put in place to force you to &amp;#8220;trust&amp;#8221; .rvmrc
files when changing into a directory with a .rvmrc for the first time.  Normally this is fine, but it
presented an issue in the context of an automated script.  This security measure can be disabled by this
next command:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;trust_rvm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;rvm rvmrc trust &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;release_path&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;`&lt;/p&gt;

&lt;p&gt;This tells RVM that I explicity trust the .rvmrc located in my release_path which is the root of my
application on the server.&lt;/p&gt;

&lt;h3&gt;Run bundle install - take 1&lt;/h3&gt;

&lt;p&gt;With RVM all loaded up, we can now issue our bundle command to install any new dependencies if necessary.
So naturally I tried the command below:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;goto_app_root&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;cd &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;release_path&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;bundle_install&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;bundle install --without test&amp;quot;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;But this blew up in my face with a nasty exception:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;span class='line-number'&gt;18&lt;/span&gt;
&lt;span class='line-number'&gt;19&lt;/span&gt;
&lt;span class='line-number'&gt;20&lt;/span&gt;
&lt;span class='line-number'&gt;21&lt;/span&gt;
&lt;span class='line-number'&gt;22&lt;/span&gt;
&lt;span class='line-number'&gt;23&lt;/span&gt;
&lt;span class='line-number'&gt;24&lt;/span&gt;
&lt;span class='line-number'&gt;25&lt;/span&gt;
&lt;span class='line-number'&gt;26&lt;/span&gt;
&lt;span class='line-number'&gt;27&lt;/span&gt;
&lt;span class='line-number'&gt;28&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='plain'&gt;&lt;span class='line'&gt;/home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/source.rb:198:in `cached_specs': undefined method `spec' for nil:NilClass (NoMethodError)
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/source.rb:196:in `each'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/source.rb:196:in `cached_specs'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/source.rb:195:in `each'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/source.rb:195:in `cached_specs'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/source.rb:157:in `fetch_specs'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/index.rb:7:in `build'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/source.rb:155:in `fetch_specs'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/source.rb:70:in `specs'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/definition.rb:161:in `index'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/definition.rb:160:in `each'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/definition.rb:160:in `index'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/index.rb:7:in `build'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/definition.rb:159:in `index'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/definition.rb:153:in `resolve'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/definition.rb:93:in `specs'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/definition.rb:88:in `resolve_remotely!'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/installer.rb:35:in `run'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/installer.rb:8:in `install'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/cli.rb:217:in `install'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/vendor/thor/task.rb:22:in `send'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/vendor/thor/task.rb:22:in `run'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/vendor/thor/invocation.rb:118:in `invoke_task'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/vendor/thor.rb:246:in `dispatch'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/lib/bundler/vendor/thor/base.rb:389:in `start'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/gems/bundler-1.0.0/bin/bundle:13
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/bin/bundle:19:in `load'
&lt;/span&gt;&lt;span class='line'&gt;  from /home/joey/.rvm/gems/ree-1.8.7-2010.02@ema/bin/bundle:19&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;h3&gt;Run bundle install - take 2&lt;/h3&gt;

&lt;p&gt;I had read somewhere previously (sorry, can&amp;#8217;t remember exactly where) about sometimes needing to
explicitly specify the target path for the &amp;#8220;bundle install&amp;#8221; command.  In this case I can just use
the $BUNDLE_PATH environment variable that RVM manages for me:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='line'&gt;&lt;span class="n"&gt;bundle_install&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;bundle install $BUNDLE_PATH --without test&amp;quot;&lt;/span&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;This seems to fix the exception above, but I&amp;#8217;ll be honest, I&amp;#8217;m not exactly sure why yet.  (And yes,
that does bug the heck out of me)&lt;/p&gt;

&lt;h2&gt;Putting it all together&lt;/h2&gt;

&lt;p&gt;Now that we have all of our commands ready to go, we can simply call the built in &amp;#8220;run&amp;#8221; method
and pass in each command concatenated one after another:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;span class='line-number'&gt;18&lt;/span&gt;
&lt;span class='line-number'&gt;19&lt;/span&gt;
&lt;span class='line-number'&gt;20&lt;/span&gt;
&lt;span class='line-number'&gt;21&lt;/span&gt;
&lt;span class='line-number'&gt;22&lt;/span&gt;
&lt;span class='line-number'&gt;23&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='plain'&gt;&lt;span class='line'&gt;namespace :vlad do
&lt;/span&gt;&lt;span class='line'&gt;  remote_task :bundle do
&lt;/span&gt;&lt;span class='line'&gt;    # loads RVM, which initializes environment and paths
&lt;/span&gt;&lt;span class='line'&gt;    init_rvm = "source ~/.rvm/scripts/rvm"
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;    # automatically trust the gemset in the .rvmrc file
&lt;/span&gt;&lt;span class='line'&gt;    trust_rvm = "rvm rvmrc trust #{release_path}"
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;    # ya know, get to where we need to go
&lt;/span&gt;&lt;span class='line'&gt;    # ex. /var/www/my_app/releases/12345
&lt;/span&gt;&lt;span class='line'&gt;    goto_app_root = "cd #{release_path}"
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;    # run bundle install with explicit path and without test dependencies
&lt;/span&gt;&lt;span class='line'&gt;    bundle_install = "bundle install $BUNDLE_PATH --without test"
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;    # actually run all of the commands via ssh on the server
&lt;/span&gt;&lt;span class='line'&gt;    run "#{init_rvm} &amp;amp;&amp;amp; #{trust_rvm} &amp;amp;&amp;amp; #{goto_app_root} &amp;amp;&amp;amp; #{bundle_install}"
&lt;/span&gt;&lt;span class='line'&gt;  end
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;  task :update do
&lt;/span&gt;&lt;span class='line'&gt;    Rake::Task['vlad:bundle'].invoke
&lt;/span&gt;&lt;span class='line'&gt;  end
&lt;/span&gt;&lt;span class='line'&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;If all is well, you should see a nice green message from Bundler saying your bundle is complete.&lt;/p&gt;

&lt;h2&gt;&amp;lt;/post&amp;gt;&lt;/h2&gt;

&lt;p&gt;As I mentioned before I&amp;#8217;m not all that happy with this solution, as it seems like there is probably
a better way to get Vlad, RVM and Bundler all working nicely together.  I&amp;#8217;d be really interested
to know of a better way.&lt;/p&gt;

&lt;p&gt;Anyways, I hope this post benefits somebody in the future.  Even if it&amp;#8217;s myself a year from now.  :)&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2010/09/17/vlad-rvm-and-bundler-sitting-in-a-tree/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/R902VcOtHL8" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2010/09/17/vlad-rvm-and-bundler-sitting-in-a-tree/</feedburner:origLink></entry>
  
    <entry>
      




<title type="html"><![CDATA[RVM, Bash Scripting and Rails 3 Edge]]></title>
<link href="http://feedproxy.google.com/~r/joeybeninghove/~3/WvYMzB9Ny4c/" />
<updated>2010-07-19T13:34:00-04:00</updated>
<id>http://joeybeninghove.com/2010/07/19/rvm-bash-scripting-and-rails-3-edge</id>

      <content type="html">&lt;p&gt;I&amp;#8217;ve only begun to tap into the power of bash scripting, but I had a need to automate setting up a
Rails 3 app on edge, using &lt;a href="http://rvm.beginrescueend.com"&gt;RVM&lt;/a&gt; like I want.  So I decided to whip up a very simple script that does
the following for the name of app you&amp;#8217;re creating:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creates a new &lt;a href="http://rvm.beginrescueend.com/gemsets/basics"&gt;RVM gemset&lt;/a&gt; for the app&lt;/li&gt;
&lt;li&gt;Creates a directory for the app&lt;/li&gt;
&lt;li&gt;Creates an &lt;a href="http://rvm.beginrescueend.com/workflow/rvmrc"&gt;.rvmrc&lt;/a&gt; file under the new app directory to ensure the proper gemset is used whenever you switch to it&lt;/li&gt;
&lt;li&gt;Note: This assumes you have &lt;a href="http://www.rubyenterpriseedition.com"&gt;REE 1.8.7&lt;/a&gt; installed under rvm (rvm install ree), which is the main ruby I&amp;#8217;m still using for everything&lt;/li&gt;
&lt;li&gt;Installs latest prerelease of &lt;a href="http://github.com/carlhuda/bundler"&gt;bundler&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Installs latest &lt;strong&gt;&lt;a href="http://github.com/rails/rails"&gt;edge&lt;/a&gt;&lt;/strong&gt; &lt;a href="http://github.com/rails/rails"&gt;version of rails 3&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Here&amp;#8217;s the bash script:&lt;/p&gt;

&lt;figure class='code'&gt;&lt;div class='highlight'&gt;&lt;table&gt;&lt;td class='gutter'&gt;&lt;pre class='line-numbers'&gt;&lt;span class='line-number'&gt;1&lt;/span&gt;
&lt;span class='line-number'&gt;2&lt;/span&gt;
&lt;span class='line-number'&gt;3&lt;/span&gt;
&lt;span class='line-number'&gt;4&lt;/span&gt;
&lt;span class='line-number'&gt;5&lt;/span&gt;
&lt;span class='line-number'&gt;6&lt;/span&gt;
&lt;span class='line-number'&gt;7&lt;/span&gt;
&lt;span class='line-number'&gt;8&lt;/span&gt;
&lt;span class='line-number'&gt;9&lt;/span&gt;
&lt;span class='line-number'&gt;10&lt;/span&gt;
&lt;span class='line-number'&gt;11&lt;/span&gt;
&lt;span class='line-number'&gt;12&lt;/span&gt;
&lt;span class='line-number'&gt;13&lt;/span&gt;
&lt;span class='line-number'&gt;14&lt;/span&gt;
&lt;span class='line-number'&gt;15&lt;/span&gt;
&lt;span class='line-number'&gt;16&lt;/span&gt;
&lt;span class='line-number'&gt;17&lt;/span&gt;
&lt;span class='line-number'&gt;18&lt;/span&gt;
&lt;span class='line-number'&gt;19&lt;/span&gt;
&lt;span class='line-number'&gt;20&lt;/span&gt;
&lt;span class='line-number'&gt;21&lt;/span&gt;
&lt;span class='line-number'&gt;22&lt;/span&gt;
&lt;span class='line-number'&gt;23&lt;/span&gt;
&lt;span class='line-number'&gt;24&lt;/span&gt;
&lt;span class='line-number'&gt;25&lt;/span&gt;
&lt;span class='line-number'&gt;26&lt;/span&gt;
&lt;span class='line-number'&gt;27&lt;/span&gt;
&lt;span class='line-number'&gt;28&lt;/span&gt;
&lt;span class='line-number'&gt;29&lt;/span&gt;
&lt;span class='line-number'&gt;30&lt;/span&gt;
&lt;span class='line-number'&gt;31&lt;/span&gt;
&lt;span class='line-number'&gt;32&lt;/span&gt;
&lt;/pre&gt;&lt;/td&gt;&lt;td class='code'&gt;&lt;pre&gt;&lt;code class='bash'&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;#! /bin/bash&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;# usage: bash rails3.sh &amp;amp;lt;appname&amp;amp;gt;&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;# source rvm to allow the environment to be changed (i.e. gemset)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nb"&gt;source&lt;/span&gt; ~/.rvm/scripts/rvm
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;# create new gemset with the same name as the app name supplied&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;rvm gemset create &lt;span class="nv"&gt;$1&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;# then use the gemset, setting it as the active one&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;rvm gemset use &lt;span class="nv"&gt;$1&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;# create the app dir&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;mkdir &lt;span class="nv"&gt;$1&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;# generate a .rvmrc file to handle the autoswitching of rvm to use the gemset&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;rvm ree-1.8.7-2010.02@$1&amp;quot;&lt;/span&gt; &amp;gt;&amp;gt; &lt;span class="nv"&gt;$1&lt;/span&gt;/.rvmrc
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;# install bundler prerelease that is required by rails 3 edge&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;gem install bundler --pre --no-rdoc --no-ri
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;# install rails prerelease (beta 4 currently, but this will get updated to edge in a sec)&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;gem install rails --pre --no-rdoc --no-ri
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;# create new rails app the way i currently like it, with the --edge argument&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;rails new &lt;span class="nv"&gt;$1&lt;/span&gt; --skip-activerecord --skip-prototype --skip-testunit --edge
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; &lt;span class="nv"&gt;$1&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;
&lt;/span&gt;&lt;span class='line'&gt;&lt;span class="c"&gt;# install all dependencies, including latest rails 3 edge&lt;/span&gt;
&lt;/span&gt;&lt;span class='line'&gt;bundle install
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/figure&gt;


&lt;p&gt;What this quickly gives you is a new Rails 3 app running on edge, with everything installed in its
own RVM gemset to keep from polluting the rest of your ruby environments or applications.&lt;/p&gt;

&lt;p&gt;Of course I&amp;#8217;m no bash expert, so I&amp;#8217;d love to hear any improvements or other bash scripting-fu you
guys are doing.&lt;/p&gt;
&lt;p&gt;&lt;a rel="bookmark" href="http://joeybeninghove.com/2010/07/19/rvm-bash-scripting-and-rails-3-edge/"&gt;&amp;#9875; Permalink&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/joeybeninghove/~4/WvYMzB9Ny4c" height="1" width="1"/&gt;</content>
    <feedburner:origLink>http://joeybeninghove.com/2010/07/19/rvm-bash-scripting-and-rails-3-edge/</feedburner:origLink></entry>
  
</feed>
