<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>SmartLogic Solutions Blog &#187; Ruby</title>
	<atom:link href="http://blog.smartlogicsolutions.com/tag/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.smartlogicsolutions.com</link>
	<description>News and updates from the people at SmartLogic Solutions</description>
	<lastBuildDate>Tue, 30 Nov 2010 21:39:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Directory Conventions for Rack Middleware RubyGems</title>
		<link>http://blog.smartlogicsolutions.com/2010/05/13/directory-conventions-for-rack-middleware-rubygems/</link>
		<comments>http://blog.smartlogicsolutions.com/2010/05/13/directory-conventions-for-rack-middleware-rubygems/#comments</comments>
		<pubDate>Thu, 13 May 2010 15:48:27 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[John Trupiano]]></category>
		<category><![CDATA[Rack]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[conventions]]></category>
		<category><![CDATA[gems]]></category>
		<category><![CDATA[middleware]]></category>
		<category><![CDATA[rubygems]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=896</guid>
		<description><![CDATA[I just wanted to make a quick note about directory conventions for rack middleware gems. For all gems you should follow the convention of housing all of your code inside a single file and directory of the same name as your gem within lib, e.g. $> ls -l ~/projects/timecop/lib drwxr-xr-x 5 john staff 170 Jan [...]]]></description>
			<content:encoded><![CDATA[<p>I just wanted to make a quick note about directory conventions for rack middleware gems.  For all gems you should follow the convention of housing all of your code inside a single file and directory of the same name as your gem within lib, e.g.</p>
<p><code><br />
$> ls -l ~/projects/timecop/lib<br />
drwxr-xr-x  5 john  staff  170 Jan 14 20:31 timecop<br />
-rw-r--r--  1 john  staff   82 Jan 14 20:31 timecop.rb<br />
</code></p>
<p>The reason for this is related to how RubyGems hijacks Ruby&#8217;s require method.  When a gem is activated its lib/ folder is added to the load path.  This means that anything inside that directory is now accessible via the require method.  In order to avoid file naming collisions across gems, you must name these exactly the same as your gem. (see <a href="http://i-dont-trust-your-code.heroku.com/">slides for I Don&#8217;t Trust Your Code</a> for a more complete discussions of this)</p>
<p>However, this is slightly different with rack gems.  The convention for naming rack middleware is by using a dash, e.g. rack-rewrite.  The convention for requiring rack middleware though is to replace that dash with a slash, e.g. <code>require 'rack/rewrite'</code>.</p>
<p>The convention I&#8217;ve adopted for structuring rack middleware within a gem is to include a file by the same name as the gem and a rack directory in lib/, and then to include the second part of the middleware name as a subdirectory under that.</p>
<p><code><br />
~/projects/rack-rewrite (master) $> ls -l lib/<br />
total 8<br />
drwxr-xr-x  4 john  staff  136 Apr 17 18:02 rack<br />
-rw-r--r--@ 1 john  staff   22 Apr 17 18:02 rack-rewrite.rb</p>
<p>~/projects/rack-rewrite (master) $> ls -l lib/rack<br />
total 8<br />
drwxr-xr-x  3 john  staff  102 May 13 11:09 rewrite<br />
-rw-r--r--@ 1 john  staff  827 Apr 17 18:02 rewrite.rb<br />
</code></p>
<p>This allows my users to use either <code>require 'rack-rewrite'</code> or <code>require 'rack/rewrite'</code>.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/rack-rewrite-1-0-0-released/" rel="bookmark" class="crp_title">Rack::Rewrite 1.0.0 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/01/06/rack-rewrite-0-2-1-released/" rel="bookmark" class="crp_title">Rack::Rewrite 0.2.1 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/11/16/rack-rewrite-for-site-maintenance-and-downtime/" rel="bookmark" class="crp_title">Rack::Rewrite for Site Maintenance and Downtime</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/11/24/rack-rewrite-google-analytics-makes-site-transitions-seamless/" rel="bookmark" class="crp_title">Rack::Rewrite + Google Analytics Makes Site Transitions Seamless</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/05/26/including-external-rake-files-in-your-projects-rakefile-keep-your-rake-tasks-organized/" rel="bookmark" class="crp_title">Including external .rake files in your project&#8217;s Rakefile &#8212; keep your rake tasks organized!</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2010/05/13/directory-conventions-for-rack-middleware-rubygems/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rack::Rewrite 1.0.0 Released</title>
		<link>http://blog.smartlogicsolutions.com/2010/05/13/rack-rewrite-1-0-0-released/</link>
		<comments>http://blog.smartlogicsolutions.com/2010/05/13/rack-rewrite-1-0-0-released/#comments</comments>
		<pubDate>Thu, 13 May 2010 15:25:16 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[John Trupiano]]></category>
		<category><![CDATA[Rack]]></category>
		<category><![CDATA[rack-rewrite]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rubygem]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=893</guid>
		<description><![CDATA[Rack::Rewrite 1.0.0 has just been released. To install simply run: gem install rack-rewrite. Rack::Rewrite is a web-server agnostic rack middleware for defining and applying rewrite rules. In many cases you can get away with Rack::Rewrite instead of writing Apache mod_rewrite rules. Documentation is hosted at RubyForge. The source code is hosted at GitHub. Updates include: [...]]]></description>
			<content:encoded><![CDATA[<p>Rack::Rewrite 1.0.0 has just been released.  To install simply run: <code>gem install rack-rewrite</code>.</p>
<p>Rack::Rewrite is a web-server agnostic rack middleware for defining and applying rewrite rules. In many cases you can get away with Rack::Rewrite instead of writing Apache mod_rewrite rules.</p>
<p>Documentation is hosted at <a href="http://johntrupiano.rubyforge.org/rack-rewrite/">RubyForge</a>.  The source code is hosted at <a href="http://github.com/jtrupiano/rack-rewrite">GitHub</a>.</p>
<p>Updates include:</p>
<p><span id="more-893"></span></p>
<p><strong>API</strong></p>
<ul>
<li>Fix rack 1.1.0 / rails3 compatibility by eliminating reliance on REQUEST_URI env param.  Paths are now constructed with PATH_INFO and QUERY_STRING</li>
<li>Follow rack directory/require convention: require &#8216;rack/rewrite&#8217; instead of &#8216;rack-rewrite&#8217;</li>
<li>Include an HTML anchor tag linked to where the URL being redirected to in the body of 301&#8242;s and 302&#8242;s</li>
</ul>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/01/06/rack-rewrite-0-2-1-released/" rel="bookmark" class="crp_title">Rack::Rewrite 0.2.1 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/directory-conventions-for-rack-middleware-rubygems/" rel="bookmark" class="crp_title">Directory Conventions for Rack Middleware RubyGems</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/11/16/rack-rewrite-for-site-maintenance-and-downtime/" rel="bookmark" class="crp_title">Rack::Rewrite for Site Maintenance and Downtime</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/11/24/rack-rewrite-google-analytics-makes-site-transitions-seamless/" rel="bookmark" class="crp_title">Rack::Rewrite + Google Analytics Makes Site Transitions Seamless</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/" rel="bookmark" class="crp_title">Timecop 0.3.0 Released</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2010/05/13/rack-rewrite-1-0-0-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rack::Rewrite 0.2.1 Released</title>
		<link>http://blog.smartlogicsolutions.com/2010/01/06/rack-rewrite-0-2-1-released/</link>
		<comments>http://blog.smartlogicsolutions.com/2010/01/06/rack-rewrite-0-2-1-released/#comments</comments>
		<pubDate>Wed, 06 Jan 2010 22:51:29 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[John Trupiano]]></category>
		<category><![CDATA[Rack]]></category>
		<category><![CDATA[rack-rewrite]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rubygem]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=820</guid>
		<description><![CDATA[Rack::Rewrite 0.2.1 has just been released. To install simply run: gem install rack-rewrite. Rack::Rewrite is a web-server agnostic rack middleware for defining and applying rewrite rules. In many cases you can get away with Rack::Rewrite instead of writing Apache mod_rewrite rules. Documentation is hosted at RubyForge. The source code is hosted at GitHub. Updates include: [...]]]></description>
			<content:encoded><![CDATA[<p>Rack::Rewrite 0.2.1 has just been released.  To install simply run: <code>gem install rack-rewrite</code>.</p>
<p>Rack::Rewrite is a web-server agnostic rack middleware for defining and applying rewrite rules. In many cases you can get away with Rack::Rewrite instead of writing Apache mod_rewrite rules.</p>
<p>Documentation is hosted at <a href="http://johntrupiano.rubyforge.org/rack-rewrite/">RubyForge</a>.  The source code is hosted at <a href="http://github.com/jtrupiano/rack-rewrite">GitHub</a>.</p>
<p>Updates include:</p>
<p><span id="more-820"></span></p>
<p><strong>API</strong></p>
<ul>
<li>Implement $&#038; substitution pattern (thanks to <a href="http://github.com/bhb">Ben Brinckerhoff</a>)</li>
</ul>
<p><strong>Maintenance</strong></p>
<ul>
<li>Ignore empty captures instead of failing during subsitution (thanks to <a href="http://github.com/bhb">Ben Brinckerhoff</a>)</li>
<li>Play nice with Rack::Test requests which only set PATH_INFO and not REQUEST_URI (thanks to <a href="http://github.com/docunext">@docunext</a>)</li>
<li>Use QUERY_STRING instead of QUERYSTRING as per Rack spec.  Closes Issue #1.</li>
</ul>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/rack-rewrite-1-0-0-released/" rel="bookmark" class="crp_title">Rack::Rewrite 1.0.0 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/directory-conventions-for-rack-middleware-rubygems/" rel="bookmark" class="crp_title">Directory Conventions for Rack Middleware RubyGems</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/11/16/rack-rewrite-for-site-maintenance-and-downtime/" rel="bookmark" class="crp_title">Rack::Rewrite for Site Maintenance and Downtime</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/11/24/rack-rewrite-google-analytics-makes-site-transitions-seamless/" rel="bookmark" class="crp_title">Rack::Rewrite + Google Analytics Makes Site Transitions Seamless</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/" rel="bookmark" class="crp_title">Timecop 0.3.0 Released</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2010/01/06/rack-rewrite-0-2-1-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Timecop 0.3.4 Released</title>
		<link>http://blog.smartlogicsolutions.com/2009/12/07/timecop-0-3-4-released/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/12/07/timecop-0-3-4-released/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 21:39:06 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[John Trupiano]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[TATFT]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[rubygem]]></category>
		<category><![CDATA[tatft]]></category>
		<category><![CDATA[timecop]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=794</guid>
		<description><![CDATA[Timecop 0.3.4 has just been released. To install simply run: gem install timecop. Timecop is a RubyGem providing &#8220;time travel&#8221; and &#8220;time freezing&#8221; capabilities, making it dead simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call. Documentation is hosted at RubyForge. The source code [...]]]></description>
			<content:encoded><![CDATA[<p>Timecop 0.3.4 has just been released.  To install simply run: <code>gem install timecop</code>.</p>
<p>Timecop is a RubyGem providing &#8220;time travel&#8221; and &#8220;time freezing&#8221; capabilities, making it dead simple to test time-dependent code.  It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.</p>
<p>Documentation is hosted at <a href="http://johntrupiano.rubyforge.org/timecop/">RubyForge</a>.  The source code is hosted at <a href="http://github.com/jtrupiano/timecop">GitHub</a>.</p>
<p>Updates include:</p>
<p><span id="more-794"></span></p>
<p><strong>Maintenance</strong></p>
<ul>
<li>Fix various timezone-related issues.  Notably, when traveling to a DateTime<br />
    instance specified in a non-local timezone, convert provided DateTime<br />
    instance to a local instance and return that from DateTime.now.<br />
    Code contributed by Michaël Witrant [<a href="http://github.com/piglop">piglop</a>]
</li>
<li>Fix bug that would not allow Timecop to be used when Ruby&#8217;s &#8216;date&#8217;<br />
    library had not been previously loaded.<br />
    Code contributed by Tuomas Kareinen [<a href="http://github.com/tuomas">tuomas</a>]
</li>
<li>Fix bug when traveling to a DateTime across a DST boundary that<br />
    resulted in DateTime&#8217;s being off by an hour.
</li>
<li>Migrate argument parsing into Timecop::TimeStackItem to reduce the<br />
    responsibility of the Timecop class.
</li>
</ul>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/" rel="bookmark" class="crp_title">Timecop 0.3.0 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/12/24/timecop-2-released-freeze-and-rebase-time-ruby/" rel="bookmark" class="crp_title">Timecop 0.2.0 Released: Freeze and Rebase Time in Ruby</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/11/19/timecop-freeze-time-in-ruby-for-better-testing/" rel="bookmark" class="crp_title">Timecop: Freeze Time in Ruby for Better Testing</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/rack-rewrite-1-0-0-released/" rel="bookmark" class="crp_title">Rack::Rewrite 1.0.0 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/01/06/rack-rewrite-0-2-1-released/" rel="bookmark" class="crp_title">Rack::Rewrite 0.2.1 Released</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/12/07/timecop-0-3-4-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rack::Rewrite + Google Analytics Makes Site Transitions Seamless</title>
		<link>http://blog.smartlogicsolutions.com/2009/11/24/rack-rewrite-google-analytics-makes-site-transitions-seamless/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/11/24/rack-rewrite-google-analytics-makes-site-transitions-seamless/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 14:20:20 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[analytics]]></category>
		<category><![CDATA[Google Analytics]]></category>
		<category><![CDATA[John Trupiano]]></category>
		<category><![CDATA[Rack]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[seo]]></category>
		<category><![CDATA[googleanalytics]]></category>
		<category><![CDATA[jtrupiano]]></category>
		<category><![CDATA[rack-rewrite]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=718</guid>
		<description><![CDATA[At SmartLogic we recently rebuilt our website in rails. The previous version was a MediaWiki installation with a ton of content that had garnered a decent bit of Google juice that we did not want to lose. By setting up 301 permanent redirects for the old URL&#8217;s, we can hold onto that juice. Enter Rack::Rewrite. [...]]]></description>
			<content:encoded><![CDATA[<p>At SmartLogic we recently rebuilt our <a href="http://www.smartlogicsolutions.com">website</a> in rails.  The previous version was a MediaWiki installation with a ton of content that had garnered a decent bit of Google juice that we did not want to lose.  By setting up 301 permanent redirects for the old URL&#8217;s, we can hold onto that juice.</p>
<p><span id="more-718"></span></p>
<div id="attachment_762" class="wp-caption alignright" style="width: 160px"><a href="http://blog.smartlogicsolutions.com/wp-content/uploads/2009/11/Picture-2.png"><img src="http://blog.smartlogicsolutions.com/wp-content/uploads/2009/11/Picture-2-150x150.png" alt="Google Analytics Navigation" title="Google Analytics Navigation" width="150" height="150" class="size-thumbnail wp-image-762" /></a><p class="wp-caption-text">Google Analytics Navigation</p></div>
<p>Enter Rack::Rewrite.  <a href="http://github.com/jtrupiano/rack-rewrite">Rack::Rewrite</a> is a <a href="http://rack.rubyforge.org/">Rack</a> middleware for defining and applying rewrite rules.  Though it&#8217;s not a full replacement for <a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html">Apache&#8217;s mod_rewrite</a>, a great deal of rules I&#8217;ve previously written in Apache config files can be replaced by Rack::Rewrite.  Run <code>gem install rack-rewrite</code> to install the gem.</p>
<p>In order to determine which URL&#8217;s were most important to issue 301&#8242;s for, we turned to Google Analytics.  By reviewing the most popular landing pages of the past two months from our site, we were able to methodically write our redirect rules.</p>
<div id="attachment_766" class="wp-caption aligncenter" style="width: 310px"><a href="http://blog.smartlogicsolutions.com/wp-content/uploads/2009/11/Picture-33.png"><img src="http://blog.smartlogicsolutions.com/wp-content/uploads/2009/11/Picture-33-300x291.png" alt="Google Analytics | Top Landing Pages" title="Google Analytics | Top Landing Pages" width="300" height="291" class="size-medium wp-image-766" /></a><p class="wp-caption-text">Google Analytics | Top Landing Pages</p></div>
<p>Here is a subset of the associated Rack::Rewrite rules.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  config.<span style="color:#9900CC;">middleware</span>.<span style="color:#9900CC;">insert_before</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#6666ff; font-weight:bold;">Rack::Lock</span>, <span style="color:#6666ff; font-weight:bold;">Rack::Rewrite</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>        
    <span style="color:#008000; font-style:italic;"># original wiki smartlogicsolutions.com website</span>
    r301 <span style="color:#996600;">'/wiki/Main_Page'</span>, <span style="color:#996600;">'/'</span>
    r301 <span style="color:#996600;">'/wiki/John_Trupiano'</span>, <span style="color:#996600;">'/john'</span>
    r301 <span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>^<span style="color:#006600; font-weight:bold;">/</span>wiki<span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>Charity<span style="color:#006600; font-weight:bold;">|</span>Charities<span style="color:#006600; font-weight:bold;">|</span>Local_Connection<span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#996600;">'/gratis-work-and-charities'</span>
    r301 <span style="color:#996600;">'/wiki/Category:Portfolio'</span>, <span style="color:#996600;">'/portfolio'</span>
    r301 <span style="color:#996600;">'/wiki/ExxonMobil_-_Brand_Asset_Center'</span>, <span style="color:#996600;">'/portfolio/exxonmobil-brand-asset-center'</span>
    r301 <span style="color:#996600;">'/wiki/In_the_News'</span>, <span style="color:#996600;">'/in-the-news'</span>
    r301 <span style="color:#996600;">'/wiki/Getting_to_our_Office'</span>, <span style="color:#996600;">'/driving-directions'</span>
    r301 <span style="color:#996600;">'/wiki/Category:Employees'</span>, <span style="color:#996600;">'/our-team'</span>
    r301 <span style="color:#996600;">'/wiki/SimNet_for_Office_2007'</span>, <span style="color:#996600;">'/portfolio/simnet-for-office-2007-and-vista'</span>
    r301 <span style="color:#996600;">'/wiki/VNC_Collaboration_Application'</span>, <span style="color:#996600;">'/portfolio/shared-desktop'</span>
    r301 <span style="color:#996600;">'/wiki/Contact_Information'</span>, <span style="color:#996600;">'/contact-us'</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This scheme is great for landing pages, but what if we had querystring information that we wanted to keep around?  This is common for tracking codes &#8212; many marketing platforms generate URL&#8217;s that embed data in the querystring for recording and tracking purposes.  We can leverage the following trick to maintain the querystring across a rewrite.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  r301 <span style="color:#006600; font-weight:bold;">%</span>r<span style="color:#006600; font-weight:bold;">&#123;</span>^<span style="color:#006600; font-weight:bold;">/</span>wiki<span style="color:#006600; font-weight:bold;">/</span>Main_Page<span style="color:#006600; font-weight:bold;">&#40;</span>\?.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>?$<span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#996600;">'/$1'</span></pre></div></div>

<p>Note the following:</p>
<ul>
<li>We are conditionally matching a querystring so that the rule continues to match in the absence of a querystring. </li>
<li>We are leveraging substitution patterns to reconstitute the querystring in the rewritten URL.
</ul>
<p>Many more great use cases for Rack::Rewrite are covered in the project&#8217;s <a href="http://github.com/jtrupiano/rack-rewrite">README</a>.</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/rack-rewrite-1-0-0-released/" rel="bookmark" class="crp_title">Rack::Rewrite 1.0.0 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/01/06/rack-rewrite-0-2-1-released/" rel="bookmark" class="crp_title">Rack::Rewrite 0.2.1 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/11/16/rack-rewrite-for-site-maintenance-and-downtime/" rel="bookmark" class="crp_title">Rack::Rewrite for Site Maintenance and Downtime</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/directory-conventions-for-rack-middleware-rubygems/" rel="bookmark" class="crp_title">Directory Conventions for Rack Middleware RubyGems</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/09/24/google-analytics-event-tracking-overview/" rel="bookmark" class="crp_title">Google Analytics Event Tracking Overview</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/11/24/rack-rewrite-google-analytics-makes-site-transitions-seamless/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Rack::Rewrite for Site Maintenance and Downtime</title>
		<link>http://blog.smartlogicsolutions.com/2009/11/16/rack-rewrite-for-site-maintenance-and-downtime/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/11/16/rack-rewrite-for-site-maintenance-and-downtime/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 15:36:26 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[Apache]]></category>
		<category><![CDATA[John Trupiano]]></category>
		<category><![CDATA[Rack]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[rack-rewrite]]></category>
		<category><![CDATA[rubygem]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=740</guid>
		<description><![CDATA[Rack::Rewrite is a Rack middleware for defining and applying rewrite rules. Though it&#8217;s not a full replacement for Apache&#8217;s mod_rewrite, a great deal of rules I&#8217;ve previously written in Apache config files can be replaced by Rack::Rewrite. Run gem install rack-rewrite to install the gem. I typically leverage rewrite rules to take my sites offline [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/jtrupiano/rack-rewrite">Rack::Rewrite</a> is a <a href="http://rack.rubyforge.org/">Rack</a> middleware for defining and applying rewrite rules.  Though it&#8217;s not a full replacement for <a href="http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html">Apache&#8217;s mod_rewrite</a>, a great deal of rules I&#8217;ve previously written in Apache config files can be replaced by Rack::Rewrite.  Run <code>gem install rack-rewrite</code> to install the gem.</p>
<p>I typically leverage rewrite rules to take my sites offline for maintenance.  Most <a href="http://www.capify.org/index.php/Capistrano">capistrano</a> users will be familiar with the following Apache rewrite ruleset.<br />
<span id="more-740"></span></p>
<pre>
  RewriteCond %{REQUEST_URI} !\.(css|jpg|png)$
  RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
  RewriteCond %{SCRIPT_FILENAME} !maintenance.html
  RewriteRule ^.*$ /system/maintenance.html [L]
</pre>
<p>This ruleset matches requests for non-asset URL&#8217;s and renders a maintenance page if it exists on the filesystem.  When capistrano users run <code>cap deploy:web:disable REASON="site upgrade" UNTIL="2PM"</code> a maintenance page is placed in public/system and this ruleset begins to kick in.  Running <code>cap deploy:web:enable</code> will remove this page and the ruleset ceases to match.</p>
<p>We can replace this ruleset with the following Rack::Rewrite rule:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;"># Ruby 1.8.x</span>
  maintenance_file = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'public'</span>, <span style="color:#996600;">'system'</span>, <span style="color:#996600;">'maintenance.html'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  send_file <span style="color:#006600; font-weight:bold;">/</span>.<span style="color:#006600; font-weight:bold;">*/</span>, maintenance_file, :<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>rack_env<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>maintenance_file<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> rack_env<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'REQUEST_URI'</span><span style="color:#006600; font-weight:bold;">&#93;</span> !~ <span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#006600; font-weight:bold;">&#40;</span>css<span style="color:#006600; font-weight:bold;">|</span>jpg<span style="color:#006600; font-weight:bold;">|</span>png<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>This rewrite rule uses the <code>send_file</code> method to return the maintenance page, uses a rule guard (the :if proc) to check for the existence of the file, and accesses the rack environment directly (rack_env arg to the Proc) to check the request URI.  Due to the shortcomings of the Ruby 1.8&#8242;s regular expression library (no negative lookahead), we have to leverage the rule guard to allow assets to continue to be served (css, jpg, png).</p>
<p>Using Ruby 1.9, this rule is simpler.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;"># Ruby 1.9.x</span>
  maintenance_file = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'public'</span>, <span style="color:#996600;">'system'</span>, <span style="color:#996600;">'maintenance.html'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  send_file <span style="color:#006600; font-weight:bold;">/</span><span style="color:#006600; font-weight:bold;">&#40;</span>.<span style="color:#006600; font-weight:bold;">*</span><span style="color:#006600; font-weight:bold;">&#41;</span>$<span style="color:#006600; font-weight:bold;">&#40;</span>?<span style="color:#006600; font-weight:bold;">&lt;</span>!css<span style="color:#006600; font-weight:bold;">|</span>png<span style="color:#006600; font-weight:bold;">|</span>jpg<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">/</span>, maintenance_file, :<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>rack_env<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>maintenance_file<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Users of 1.8.x can leverage <a href="http://oniguruma.rubyforge.org/">Oniguruma</a> to keep the rule simpler.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">  <span style="color:#008000; font-style:italic;"># Ruby 1.8.x + Oniguruma</span>
  maintenance_file = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ROOT, <span style="color:#996600;">'public'</span>, <span style="color:#996600;">'system'</span>, <span style="color:#996600;">'maintenance.html'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  send_file <span style="color:#6666ff; font-weight:bold;">Oniguruma::ORegexp</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;(.*)$(?&lt;!css|png|jpg)&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, maintenance_file, :<span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC0066; font-weight:bold;">Proc</span>.<span style="color:#9900CC;">new</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>rack_env<span style="color:#006600; font-weight:bold;">|</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exists</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>maintenance_file<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2010/01/06/rack-rewrite-0-2-1-released/" rel="bookmark" class="crp_title">Rack::Rewrite 0.2.1 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/rack-rewrite-1-0-0-released/" rel="bookmark" class="crp_title">Rack::Rewrite 1.0.0 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/11/24/rack-rewrite-google-analytics-makes-site-transitions-seamless/" rel="bookmark" class="crp_title">Rack::Rewrite + Google Analytics Makes Site Transitions Seamless</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/directory-conventions-for-rack-middleware-rubygems/" rel="bookmark" class="crp_title">Directory Conventions for Rack Middleware RubyGems</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/02/better-setup-for-environments-in-rails/" rel="bookmark" class="crp_title">Better setup for environments in Rails</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/11/16/rack-rewrite-for-site-maintenance-and-downtime/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Timecop 0.3.0 Released</title>
		<link>http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 03:27:34 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[John Trupiano]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[TATFT]]></category>
		<category><![CDATA[rubygem]]></category>
		<category><![CDATA[tatft]]></category>
		<category><![CDATA[Testing]]></category>
		<category><![CDATA[timecop]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=704</guid>
		<description><![CDATA[Timecop 0.3.0 has just been released. To install simply run: gem install timecop. Timecop is a RubyGem providing &#8220;time travel&#8221; and &#8220;time freezing&#8221; capabilities, making it dead simple to test time-dependent code. It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call. Documentation is on RubyForge. The source code is [...]]]></description>
			<content:encoded><![CDATA[<p>Timecop 0.3.0 has just been released.  To install simply run: <code>gem install timecop</code>.</p>
<p>Timecop is a RubyGem providing &#8220;time travel&#8221; and &#8220;time freezing&#8221; capabilities, making it dead simple to test time-dependent code.  It provides a unified method to mock Time.now, Date.today, and DateTime.now in a single call.</p>
<p>Documentation is on <a href="http://johntrupiano.rubyforge.org/timecop/">RubyForge</a>.  The source code is hosted at <a href="http://github.com/jtrupiano/timecop">GitHub</a>.</p>
<p>Updates include:</p>
<p><strong>API</strong></p>
<ul>
<li>Completely remove Timecop#unset_all (deprecated by Timecop#return in 0.2.0)</li>
<li>Return Time.now from #freeze, #travel and #return  &#8212; code contributed by Keith Bennett (<a href="http://github.com/keithrbennett">keithrbennett</a>)</li>
</ul>
<p><strong>Maintenance</strong></p>
<ul>
<li>Fix bug that left Time#mock_time set in some instances</li>
<li>Upped build dependency to jeweler ~> 1.2.1</li>
<li>Don&#8217;t pollute top-level namespace with classes/constants</li>
</ul>
<p><strong>Documentation</strong></p>
<ul>
<li>Clearer examples in the README, better description in the gemspec</li>
<li>Improve RDoc</li>
</ul>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2009/12/07/timecop-0-3-4-released/" rel="bookmark" class="crp_title">Timecop 0.3.4 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/12/24/timecop-2-released-freeze-and-rebase-time-ruby/" rel="bookmark" class="crp_title">Timecop 0.2.0 Released: Freeze and Rebase Time in Ruby</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/11/19/timecop-freeze-time-in-ruby-for-better-testing/" rel="bookmark" class="crp_title">Timecop: Freeze Time in Ruby for Better Testing</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/01/06/rack-rewrite-0-2-1-released/" rel="bookmark" class="crp_title">Rack::Rewrite 0.2.1 Released</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/rack-rewrite-1-0-0-released/" rel="bookmark" class="crp_title">Rack::Rewrite 1.0.0 Released</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/09/20/timecop-0-3-0-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Shell Script to Upgrade Ruby Enterprise Edition while Maintaining Directory Naming Sanity</title>
		<link>http://blog.smartlogicsolutions.com/2009/06/10/shell-script-to-upgrade-ruby-enterprise-edition-while-maintaining-directory-naming-sanity/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/06/10/shell-script-to-upgrade-ruby-enterprise-edition-while-maintaining-directory-naming-sanity/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 01:24:28 +0000</pubDate>
		<dc:creator>John Trupiano</dc:creator>
				<category><![CDATA[Passenger]]></category>
		<category><![CDATA[Ruby Enterprise Edition]]></category>
		<category><![CDATA[Sysadmin]]></category>
		<category><![CDATA[dos]]></category>
		<category><![CDATA[ree]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=685</guid>
		<description><![CDATA[As you&#8217;re likely already aware, a denial of service (DoS) vulnerability in Ruby&#8217;s BigDecimal library was uncovered, fixed and reported on June 9, 2009. Patching options include: Replacing your current ruby installation with a patched version Installing a gem to patch the code and then updating your application to load the patch. The latter approach [...]]]></description>
			<content:encoded><![CDATA[<p>As you&#8217;re likely already aware, a denial of service (DoS) vulnerability in Ruby&#8217;s BigDecimal library was <a href="http://blog.phusion.nl/2009/06/10/ruby-enterprise-edition-186-20090610-released-fixes-bigdecimal-dos-vulnerability/">uncovered, fixed and reported on June 9, 2009</a>.  Patching options include:</p>
<ul>
<li>Replacing your current ruby installation with a <a href="http://rubyforge.org/frs/download.php/58677/ruby-enterprise-1.8.6-20090610.tar.gz">patched version</a></li>
<li><a href="http://github.com/NZKoz/bigdecimal-segfault-fix/tree/master">Installing a gem</a> to patch the code and then updating your application to load the patch.</li>
</ul>
<p><span id="more-685"></span></p>
<p>The latter approach only postpones the inevitable, so I opted for the former.  If you&#8217;re using the <a href="http://blog.phusion.nl/2009/06/10/ruby-enterprise-edition-186-20090610-released-fixes-bigdecimal-dos-vulnerability/">debian packages</a>, it&#8217;s a simple call to aptitude update.  However, if you&#8217;ve installed from source, this presents a few challenges.</p>
<p>The upgrade is actually quite straightforward.  According to the <a href="http://www.rubyenterpriseedition.com/documentation.html#_upgrading">REE Documentation</a>, you simply need to run the <a href="http://www.rubyenterpriseedition.com/ruby-enterprise-1.8.6-20090610.tar.gz">new installer</a> over top of your previous installation.  This includes specifying the exact same directory name that you used to install the previous version.</p>
<p>As you may know, REE installs by default into /opt/ruby-enterprise-1.8.6-&lt;year_month_day_release&gt;.  However, after completing this, you&#8217;re left with a directory name that doesn&#8217;t reflect what&#8217;s actually installed in there.  If you&#8217;ve a little neurotic like I am, you&#8217;re going to want to rename that directory.  However, be careful.  Your <a href="http://www.modrails.com/">Passenger</a> configuration is likely pointing to the directory that you want to rename, so you&#8217;ll have to remember to update your apache/nginx configuration to reflect this.</p>
<p>When we install REE we create a symlink at /opt/ruby which points to the version of ruby that we want passenger to run.  This allows us to quickly swap in/out different versions of ruby for testing/upgrading/etc.</p>
<p>Considering we have dozens of client applications running on distinct servers each with their own versions of REE installed, I decided to write a script to minimize the manual effort required to upgrade several production servers.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #666666; font-style: italic;"># Author: John Trupiano</span>
<span style="color: #666666; font-style: italic;"># Script to upgrade an REE installation on a hot server and maintain sane directory names</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(whoami)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;root&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;You need to be root to run this!&quot;</span>
  <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">2</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">RF_RELEASE</span>=<span style="color: #000000;">58677</span>
<span style="color: #007800;">REE_VERSION</span>=<span style="color: #000000;">20090610</span>
<span style="color: #007800;">REE</span>=ruby-enterprise-1.8.6-<span style="color: #007800;">$REE_VERSION</span>
<span style="color: #007800;">URL</span>=http:<span style="color: #000000; font-weight: bold;">//</span>rubyforge.org<span style="color: #000000; font-weight: bold;">/</span>frs<span style="color: #000000; font-weight: bold;">/</span>download.php<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$RF_RELEASE</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$REE</span>.tar.gz
&nbsp;
<span style="color: #666666; font-style: italic;"># Determine what the most recent version of REE is that is installed</span>
<span style="color: #007800;">MOST_RECENT_REE_VERSION</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ls</span> <span style="color: #000000; font-weight: bold;">/</span>opt <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #660033;">-F</span><span style="color: #ff0000;">&quot;-&quot;</span> <span style="color: #ff0000;">'$4 &gt; max &amp;&amp; $2 == &quot;enterprise&quot; { max=$4; maxline=$0 }; END { print max }'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">MOST_RECENT_REE</span>=ruby-enterprise-1.8.6-<span style="color: #007800;">$MOST_RECENT_REE_VERSION</span>
&nbsp;
<span style="color: #007800;">WORKING_DIR</span>=<span style="color: #000000; font-weight: bold;">/</span>root<span style="color: #000000; font-weight: bold;">/</span>src
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Going to update <span style="color: #007800;">$MOST_RECENT_REE</span> to <span style="color: #007800;">$REE</span>&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Back up previous release&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #660033;">-R</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$MOST_RECENT_REE</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$MOST_RECENT_REE</span>.bak
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Download new release&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #007800;">$WORKING_DIR</span>
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$WORKING_DIR</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">wget</span> <span style="color: #007800;">$URL</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Untar and install over the previous release for 'upgrade' according to REE manual&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">tar</span> xzf <span style="color: #007800;">$REE</span>.tar.gz
.<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$REE</span><span style="color: #000000; font-weight: bold;">/</span>installer <span style="color: #660033;">--auto</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$MOST_RECENT_REE</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Shuffle folder names to remain sane&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$MOST_RECENT_REE</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$REE</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$MOST_RECENT_REE</span>.bak <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$MOST_RECENT_REE</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Actually symlink in the new version of REE&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$REE</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>ruby
&nbsp;
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Clean up after ourselves&quot;</span>
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$WORKING_DIR</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$REE</span></pre></div></div>

<p>Simply upload this script to your server, su &#8211; up to root and run it.  Then restart apache/nginx so that passenger will pick up the new version of ruby.  All of your gems will be maintained, and your most recent version of REE will remain in tact at /opt/ruby-enterprise-1.8.6-&lt;old_version&gt; in case you need it again.</p>
<p><a href="http://gist.github.com/127636">View the script on github</a></p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2009/04/26/integrity-ci-on-passenger-222-with-ruby-enterprise-edition-on-ubuntu-804/" rel="bookmark" class="crp_title">Integrity CI on Passenger 2.2.2 with Ruby Enterprise Edition on Ubuntu 8.04</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/02/13/aasm-interning-empty-string-error/" rel="bookmark" class="crp_title">AASM + interning empty string error</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/07/i-cant-upgrade-rubygems-from-111-to-120-on-ubuntu/" rel="bookmark" class="crp_title">I can&#8217;t upgrade RubyGems from 1.1.1 to 1.2.0 on Ubuntu</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/10/15/using-swfobject-to-seamlessly-upgrade-to-flash-player-10/" rel="bookmark" class="crp_title">Using SWFObject to Seamlessly Upgrade to Flash Player 10</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/08/04/introducing-environmentalize-an-intuitive-environment-focused-config-structure-for-your-rails-applications/" rel="bookmark" class="crp_title">Introducing environmentalist: an intuitive, environment-focused config structure for your rails applications</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/06/10/shell-script-to-upgrade-ruby-enterprise-edition-while-maintaining-directory-naming-sanity/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Including external .rake files in your project&#8217;s Rakefile &#8212; keep your rake tasks organized!</title>
		<link>http://blog.smartlogicsolutions.com/2009/05/26/including-external-rake-files-in-your-projects-rakefile-keep-your-rake-tasks-organized/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/05/26/including-external-rake-files-in-your-projects-rakefile-keep-your-rake-tasks-organized/#comments</comments>
		<pubDate>Tue, 26 May 2009 14:58:07 +0000</pubDate>
		<dc:creator>Glenn Gentzke</dc:creator>
				<category><![CDATA[Glenn Gentzke]]></category>
		<category><![CDATA[Rake]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rake task]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=649</guid>
		<description><![CDATA[Perhaps you have a non-Rails project (let&#8217;s say it&#8217;s in ruby and maybe some other languages, too) and you use Rake tasks to automate some of the dirty work. So you&#8217;ve got a bunch of methods that you wish to keep neatly sorted into .rake files in some dir&#8217;s (probably a sub folder of lib [...]]]></description>
			<content:encoded><![CDATA[<p>Perhaps you have a non-Rails project (let&#8217;s say it&#8217;s in ruby and maybe some other languages, too) and you use Rake tasks to automate some of the dirty work.  So you&#8217;ve got a bunch of methods that you wish to keep neatly sorted into .rake files in some dir&#8217;s (probably a sub folder of lib like lib/tasks) and a single Rakefile in your project&#8217;s root directory.  Including those external .rake files in your project&#8217;s Rakefile via <strong>require</strong> statements won&#8217;t work :</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'lib/some_rake_file'</span> <span style="color:#008000; font-style:italic;"># or require 'lib/some_rake_file.rake'</span></pre></div></div>

<p><em>=> rake aborted!<br />
no such file to load &#8212; /home/your_project/lib/some_rake_file</em></p>
<p>Rake assumes the &#8216;require&#8217;d files end in .rb, so it won&#8217;t find your .rake files.  You need to <strong>import</strong> rake files:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">import <span style="color:#996600;">'lib/some_rake_file'</span></pre></div></div>

<p>  This is fine for individual files, but I wanted to include all files that end in .rake in my tasks dir:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC00FF; font-weight:bold;">Dir</span>.<span style="color:#9900CC;">glob</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'tasks/*.rake'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>r<span style="color:#006600; font-weight:bold;">|</span> import r <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>&#8230;and there you go.  While dead simple, this exemplifies an important distinction between require and import that I found to be poorly documented.  Keep your rake tasks organized and remember that Rake isn&#8217;t just for rails apps!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2009/04/04/environmentalist-023-released-supports-rails-232/" rel="bookmark" class="crp_title">environmentalist 0.2.3 released &#8212; supports rails 2.3.2</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/15/automating-flex-compilation-using-ant/" rel="bookmark" class="crp_title">Automating Flex Compilation Using ANT</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/04/26/integrity-ci-on-passenger-222-with-ruby-enterprise-edition-on-ubuntu-804/" rel="bookmark" class="crp_title">Integrity CI on Passenger 2.2.2 with Ruby Enterprise Edition on Ubuntu 8.04</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/05/13/directory-conventions-for-rack-middleware-rubygems/" rel="bookmark" class="crp_title">Directory Conventions for Rack Middleware RubyGems</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/06/02/better-setup-for-environments-in-rails/" rel="bookmark" class="crp_title">Better setup for environments in Rails</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/05/26/including-external-rake-files-in-your-projects-rakefile-keep-your-rake-tasks-organized/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Find the Unique Sessions for a Rails Application</title>
		<link>http://blog.smartlogicsolutions.com/2009/05/04/find-the-unique-sessions-for-a-rails-application/</link>
		<comments>http://blog.smartlogicsolutions.com/2009/05/04/find-the-unique-sessions-for-a-rails-application/#comments</comments>
		<pubDate>Mon, 04 May 2009 15:32:47 +0000</pubDate>
		<dc:creator>Nick Gauthier</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Nick Gauthier]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[log files]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://blog.smartlogicsolutions.com/?p=617</guid>
		<description><![CDATA[Today we&#8217;re going to look at how to find the number of unique sessions over a specific time frame for a rails application. We&#8217;ll be using the slow-actions gem. Slow-Actions is great tool for determining the slow areas of a rails application. Since it is built on a rails log parser, it can be used [...]]]></description>
			<content:encoded><![CDATA[<p>Today we&#8217;re going to look at how to find the number of unique sessions over a specific time frame for a rails application. We&#8217;ll be using the <a href="http://github.com/ngauthier/slow-actions/tree/master">slow-actions</a> gem.</p>
<p><span id="more-617"></span></p>
<p>Slow-Actions is great tool for determining the slow areas of a rails application. Since it is built on a rails log parser, it can be used for many other things. For example, here is some standard output from slow-actions when you want to know the speed of different user sessions within a specific date range:</p>
<pre>
slow-actions log/development.log --sessions --start-date=2009-03-01 --end-date=2009-04-01
           Cost    Average Max
+ ece0e17b48a5fe0fc766fa42f199fb66 (51 entries, 58% Error)
| Total:   2883.262 732.948 3100.00
| Render:  0.00000 0.00000 0.00000
| DB:      55.8220 14.1900 99.0000 

+ e1181ad94b34b41aff2a74ee62d5fb57 (10 entries, 30% Error)
| Total:   1563.912 676.276 1426.00
| Render:  0.00000 0.00000 0.00000
| DB:      14.5350 6.28500 19.0000 

+ 867bc340e6d65e673f29c57189feaf2b (133 entries, 0% Error)
| Total:   1083.138 221.450 386.000
| Render:  0.00000 0.00000 0.00000
| DB:      44.2030 9.03700 90.0000 

Etc...
</pre>
<p>Now, if we grep for &#8220;entries&#8221; we get a line for each session:</p>
<pre>
slow-actions log/development.log --sessions --start-date=2009-03-01 --end-date=2009-04-01 | grep entries
+ ece0e17b48a5fe0fc766fa42f199fb66 (51 entries, 58% Error)
+ e1181ad94b34b41aff2a74ee62d5fb57 (10 entries, 30% Error)
+ 867bc340e6d65e673f29c57189feaf2b (133 entries, 0% Error)
+ 99b39c7a9af55fc01056b5f127dc4c98 (75 entries, 0% Error)
+ 6ee15c4f3bc804ac68e9e868d9c3f7e6 (14 entries, 0% Error)
+ 80928c25c83590c4f89b91f8d4c8896d (9 entries, 0% Error)
+ c78cfa1cb086b3f473015b212ca3da11 (12 entries, 0% Error)
+ 48cd02cf6544493077c84eb16821bda2 (3 entries, 66% Error)
+ ac027817dcf87d473efb54cd737b2a80 (2 entries, 0% Error)
+ dff2ca2678852b06bbb6c7ca0a85b0a9 (1 entries, 0% Error)
+ 08ed3bc031c23bd3b2572ef7ce60d066 (1 entries, 0% Error)
</pre>
<p>Pipe that to word count, and we have the number of unique sessions within a specified time period:</p>
<pre>
slow-actions log/development.log --sessions --start-date=2009-03-01 --end-date=2009-04-01 | grep entries | wc -l
11
</pre>
<p>On a 54m log file, that takes only 0.761s!</p>
<div id="crp_related"><h3>Related Posts:</h3><ul><li><a href="http://blog.smartlogicsolutions.com/2009/03/13/slow-actions-in-rails-projects/" rel="bookmark" class="crp_title">Slow Actions in Rails Projects</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/07/11/problems-with-restful_authentication-plugin-and-internet-explorer-cookies/" rel="bookmark" class="crp_title">Problems with restful_authentication Plugin and Internet Explorer Cookies</a></li><li><a href="http://blog.smartlogicsolutions.com/2010/01/22/ubuntu-byobu-landscape/" rel="bookmark" class="crp_title">Using Byobu and Landscape to improve remote Ubuntu sessions</a></li><li><a href="http://blog.smartlogicsolutions.com/2009/02/03/properly-setting-http_referer-in-a-rails-integration-test-to-upload-file/" rel="bookmark" class="crp_title">Properly Setting HTTP_REFERER in a Rails Integration Test for a File Upload</a></li><li><a href="http://blog.smartlogicsolutions.com/2008/11/12/watch-multiple-logs-in-a-single-terminal/" rel="bookmark" class="crp_title">Watch Multiple Logs in a Single Terminal</a></li><li>Powered by <a href="http://ajaydsouza.com/wordpress/plugins/contextual-related-posts/">Contextual Related Posts</a></li></ul></div>]]></content:encoded>
			<wfw:commentRss>http://blog.smartlogicsolutions.com/2009/05/04/find-the-unique-sessions-for-a-rails-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

