<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>I like stuff.</title>
	<atom:link href="http://bmorearty.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://bmorearty.wordpress.com</link>
	<description>Brian Morearty's Blog</description>
	<lastBuildDate>Tue, 01 Dec 2009 06:45:23 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='bmorearty.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/65caaa147784f856aadfd72b92a72818?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>I like stuff.</title>
		<link>http://bmorearty.wordpress.com</link>
	</image>
			<item>
		<title>How to Distinguish a User-Aborted AJAX Call from an Error</title>
		<link>http://bmorearty.wordpress.com/2009/11/30/how-to-distinguish-a-user-aborted-ajax-call-from-an-error/</link>
		<comments>http://bmorearty.wordpress.com/2009/11/30/how-to-distinguish-a-user-aborted-ajax-call-from-an-error/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 06:45:23 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=255</guid>
		<description><![CDATA[Let&#8217;s say you&#8217;re writing a LOLcats app and you want to be all user-friendly and show an adorable little kitty-cat error message whenever an AJAX call fails. So you write an error handler using your favorite cross-browser library (mine is jQuery), something like this:

  $.ajax( { url: &#34;someUrl&#34;, success: function() {
    [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=255&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Let&#8217;s say you&#8217;re writing a LOLcats app and you want to be all user-friendly and show an adorable little kitty-cat error message whenever an AJAX call fails. So you write an error handler using your favorite cross-browser library (mine is jQuery), something like this:</p>
<pre class="brush: jscript;">
  $.ajax( { url: &quot;someUrl&quot;, success: function() {
    // do something impressive with the results
  }, error: function() {
    showError(&quot;Ohs noes. Tell me when you fix your AJAX.&quot;);
  } } );
</pre>
<p>But you start using your app and you notice that your error message also appears when you navigate away from the page before an AJAX call has finished, or when you hit Escape to cancel the AJAX call. That kind of sucks—it looks ugly to have the error message appear when there really was no error.</p>
<p>I did a little looking around and found what looks like a cross-browser-friendly way to tell if an error really occurred or if something else happened, like the user navigating away or hitting Escape.</p>
<p>The trick is to check the response headers in the XMLHttpRequest object. If there are no response headers (null or empty string, depending on the browser), the server did not respond yet. That means the user aborted.</p>
<p>Here&#8217;s a function that takes an XMLHttpRequest and tells you if the user aborted it.</p>
<pre class="brush: jscript;">
  /**
   * Returns true if the user hit Esc or navigated away from the
   * current page before an AJAX call was done. (The response
   * headers will be null or empty, depending on the browser.)
   *
   * NOTE: this function is only meaningful when called from
   * inside an AJAX &quot;error&quot; callback!
   *
   * The 'xhr' param is an XMLHttpRequest instance.
   */
  function userAborted(xhr) {
    return !xhr.getAllResponseHeaders();
  }
</pre>
<p>And here is the updated application code to call this new function. You can easily adapt this to another JavaScript library than jQuery:</p>
<pre class="brush: jscript;">
  $.ajax( { url: &quot;someUrl&quot;, success: function() {
    // do something impressive with the results
  }, error: function(xhr, textStatus, errorThrown) {
    if (!userAborted(xhr)) {
      showError(&quot;Ohs noes. Tell me when you fix your AJAX.&quot;);
    }
  } } );
</pre>
<p>Oh, did that &#8220;textStatus&#8221; and &#8220;errorThrown&#8221; catch your eye? I already looked at those. You can&#8217;t use them to tell if the user aborted. They return the same values whether the user aborted or the server returned with an error. (I only tested a 500 error.) </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/255/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=255&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/11/30/how-to-distinguish-a-user-aborted-ajax-call-from-an-error/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Put Rewrite Rules in Your Ruby Code, Not Your Web Server</title>
		<link>http://bmorearty.wordpress.com/2009/11/04/put-mod_rewrite-in-your-ruby-code-not-your-web-server/</link>
		<comments>http://bmorearty.wordpress.com/2009/11/04/put-mod_rewrite-in-your-ruby-code-not-your-web-server/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 05:54:30 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=228</guid>
		<description><![CDATA[Need to put some URL rewrite rules in your Rails app? Not too crazy about writing Apache mod_rewrite rules? Prefer writing Ruby code?
Refraction to the rescue.
Refraction is a new Rails plugin from Josh Susser and Pivotal Labs that helps you easily implement URL rewrites in Ruby, rather than writing the rules in web-server-specific lingo. Your [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=228&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Need to put some URL rewrite rules in your Rails app? Not too crazy about writing Apache mod_rewrite rules? Prefer writing Ruby code?</p>
<p>Refraction to the rescue.</p>
<p>Refraction is a new Rails plugin from Josh Susser and Pivotal Labs that helps you easily <a href="http://pivotallabs.com/users/jsusser/blog/articles/1038-announcing-refraction">implement URL rewrites in Ruby</a>, rather than writing the rules in web-server-specific lingo. Your code gets called by Rack, although you don&#8217;t need to know anything about Rack to write rewrite rules.</p>
<p>Here&#8217;s an example. Let&#8217;s say you want to duplicate Twitter&#8217;s /@username routes (did you know Twitter supports URLs like that?) but have found as I did that routes.rb doesn&#8217;t seem to work with a &#8220;@:username&#8221; rule. Instead, create a RESTful UsersController and then put this in your refraction_rules.rb file:</p>
<pre class="brush: ruby;">
Refraction.configure do |req|
  # rewrite /@username as /users/username
  if req.path =~ %r{/@(.+)}
    req.rewrite! :path =&gt; &quot;/users/#{$1}&quot;
  end
end
</pre>
<p>The notes in the blog post (see link above) mention that there is already a Rack rewrite plugin called Rack::Rewrite but &#8220;Rack::Rewrite only really gives you access to the request URI, whereas Refraction appears to give the entire request object&#8230; that can be much more useful for determining where to send someone.&#8221;</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/228/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=228&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/11/04/put-mod_rewrite-in-your-ruby-code-not-your-web-server/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>Define Your Own Custom Service Token for OAuth</title>
		<link>http://bmorearty.wordpress.com/2009/10/08/define-your-own-custom-service-token-for-oauth/</link>
		<comments>http://bmorearty.wordpress.com/2009/10/08/define-your-own-custom-service-token-for-oauth/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 10:49:10 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=216</guid>
		<description><![CDATA[For anyone who consumes OAuth APIs with the excellent oauth-plugin gem: I&#8217;ve just submitted a patch so you can now create your own custom &#8220;service token&#8221; in your models folder.
See the &#8220;Creating your own wrapper tokens&#8221; section of the tutorial link above to see what I&#8217;m talking about. It didn&#8217;t work before but it does [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=216&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>For anyone who <a href="http://stakeventures.com/articles/2009/07/21/consuming-oauth-intelligently-in-rails">consumes OAuth APIs with the excellent oauth-plugin</a> gem: I&#8217;ve just submitted a patch so you can now create your own custom &#8220;service token&#8221; in your models folder.</p>
<p>See the &#8220;Creating your own wrapper tokens&#8221; section of the tutorial link above to see what I&#8217;m talking about. It didn&#8217;t work before but it does now. Or will, as soon as it gets pulled back into the source. <a href="http://github.com/BMorearty/oauth-plugin">Until then you can get it here</a>. After it&#8217;s pulled back in I&#8217;ll probably delete my fork.</p>
<p><strong>Update: my change was pulled <a href="http://github.com/pelle/oauth-plugin">back into the master</a>.</strong></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/216/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=216&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/10/08/define-your-own-custom-service-token-for-oauth/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>Intuit Community makes Business Week</title>
		<link>http://bmorearty.wordpress.com/2009/07/21/intuit-community-makes-business-week/</link>
		<comments>http://bmorearty.wordpress.com/2009/07/21/intuit-community-makes-business-week/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 15:58:23 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=213</guid>
		<description><![CDATA[Thanks to tjhanley for alerting me to this while I was on vacation: Business Week has written a short article about Intuit Community, the product I worked on last year and early this year, which is an in-product community where users can help each other. In addition to helping users it has apparently improved QuickBooks [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=213&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Thanks to <a href="http://tjhanley.com/wp/2009/07/07/intuit-community-makes-business-week/">tjhanley</a> for alerting me to this while I was on vacation: <a href="http://www.businessweek.com/magazine/content/09_28/b4139066365300.htm">Business Week has written a short article about Intuit Community</a>, the product I worked on last year and early this year, which is an in-product community where users can help each other. In addition to helping users it has apparently improved QuickBooks sales and reduced product support costs.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/213/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=213&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/07/21/intuit-community-makes-business-week/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>to_json =&gt; as_json?</title>
		<link>http://bmorearty.wordpress.com/2009/07/20/to_json-as_json/</link>
		<comments>http://bmorearty.wordpress.com/2009/07/20/to_json-as_json/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 00:18:59 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=211</guid>
		<description><![CDATA[Does as_json in Rails 2.3.3 fix the Javafication of Rails?
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=211&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Does <a href="http://weblog.rubyonrails.org/2009/7/20/rails-2-3-3-touching-faster-json-bug-fixes">as_json in Rails 2.3.3</a> fix <a href="http://bmorearty.wordpress.com/2009/05/21/the-javafication-of-ruby-on-rails/">the Javafication of Rails</a>?</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/211/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=211&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/07/20/to_json-as_json/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>The Javafication of Ruby on Rails</title>
		<link>http://bmorearty.wordpress.com/2009/05/21/the-javafication-of-ruby-on-rails/</link>
		<comments>http://bmorearty.wordpress.com/2009/05/21/the-javafication-of-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 21 May 2009 16:22:34 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=201</guid>
		<description><![CDATA[As you know, one of the nice things about using Ruby on Rails is the emphasis on code simplicity and readability. A month ago in &#8220;This Week in Edge Rails,&#8221; Mike Gunderloy posted something that makes me a little concerned—it feels like one small step toward the Javafication (a.k.a. complexification) of Ruby on Rails.
The change [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=201&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>As you know, one of the nice things about using Ruby on Rails is the emphasis on code simplicity and readability. A month ago in &#8220;<a href="http://weblog.rubyonrails.org/2009/4/24/this-week-in-edge-rails">This Week in Edge Rails</a>,&#8221; Mike Gunderloy posted something that makes me a little concerned—it feels like one small step toward the Javafication (a.k.a. complexification) of Ruby on Rails.</p>
<p>The change is called &#8220;Pluggable JSON Backends&#8221; and it was implemented by Rick Olson, a.k.a. Technoweenie. (I have the utmost respect for Technoweenie. I&#8217;ve used his code before and it&#8217;s wonderful stuff—it&#8217;s clean, it&#8217;s simple, and it works.)</p>
<p>Instead of this:</p>
<pre class="brush: ruby;">
my_model.to_json
</pre>
<p>we are now encouraged to do this:</p>
<pre class="brush: ruby;">
ActiveSupport::json.encode(my_model)
</pre>
<h3>I Like Stuff that&#8217;s Simple</h3>
<p>It&#8217;s a little thing and I don&#8217;t want to blow it out of proportion, but this is a pattern I would like to see the community avoid. Once people see this style of coding they start to copy it.</p>
<p>I think I understand the motivation behind the change, but I believe the new style of coding is harder to read and write. It reminds me of all the years I wrote C++ code and wished I could just extend a class outside its original definition. Ruby can do that and I love the fact that Rails isn&#8217;t shy about taking advantage of this capability to make programmers&#8217; lives easier and code simpler.</p>
<p>It may be too late to have this debate when it comes to JSON. Maybe this was the only way to meet the requirements Technoweenie had. I don&#8217;t know. And I understand sometimes it&#8217;s necessary to do something a little ugly to achieve a goal that&#8217;s more important than simplicity or readability. But I am writing today to encourage the Rails core committers, and the rest of us in the Rails community, to please avoid this pattern when possible. If you are considering writing a method that looks like this:</p>
<pre class="brush: ruby;">
ClassOrModule::namespacey_function.method_name(obj)
</pre>
<p>please pause and consider whether the users of your API would find it easier if you instead made it look like this:</p>
<pre class="brush: ruby;">
obj.method_name
</pre>
<p>Thanks!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/201/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=201&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/05/21/the-javafication-of-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>Dataflow: Erlang-Style Thread Safety in Ruby</title>
		<link>http://bmorearty.wordpress.com/2009/04/26/dataflow-erlang-style-thread-safety-in-ruby/</link>
		<comments>http://bmorearty.wordpress.com/2009/04/26/dataflow-erlang-style-thread-safety-in-ruby/#comments</comments>
		<pubDate>Sun, 26 Apr 2009 20:20:54 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=182</guid>
		<description><![CDATA[Larry Diehl, a.k.a. larrytheliquid, has just released Dataflow: a tiny and remarkable gem that helps Ruby programmers write thread-safe programs more easily by duplicating one of the main features of Erlang—and in my opinion the single most important feature that makes Erlang thread-safe. Dataflow makes all variables write-once (so the name &#8220;variable&#8221; isn&#8217;t really accurate [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=182&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Larry Diehl, a.k.a. <a href="http://github.com/larrytheliquid">larrytheliquid</a>, has just released <a href="http://github.com/larrytheliquid/dataflow/tree/master">Dataflow</a>: a tiny and remarkable gem that helps Ruby programmers write thread-safe programs more easily by duplicating one of the main features of Erlang—and in my opinion the single most important feature that makes Erlang thread-safe. Dataflow <strong>makes all variables write-once</strong> (so the name &#8220;variable&#8221; isn&#8217;t really accurate any more). This limitation is really a feature. It makes it easier to write multithreaded programs without synchronization bugs because it&#8217;s no longer possible for two threads to write different values to the same variable, and thus there&#8217;s no need to synchronize writes. When you reference a variable that has not yet been assigned, Dataflow puts your thread to sleep automatically. It is reawakened automatically when the variable is assigned.</p>
<p>Before we continue, a word of caution: I&#8217;ve mentioned <a href="http://bmorearty.wordpress.com/2009/03/22/my-favorite-quotes-from-the-yellowpagescom-ruby-on-rails-talk/">in this blog</a> and <a href="http://podcast.rubyonrails.org/programs/1/episodes/brian-moriarty-and-thomas-hanley-of-intuit">in the Ruby on Rails Podcast</a> that even though multithreading is really fun to think about and play with, I approach it with reluctance in real-life projects because it makes the code more complex, makes it a lot harder to debug problems, and is hard to manage when there are multiple programmers who all have to work in and understand the threaded code. But there are still some problems for which threading is the right solution.</p>
<h4>I Like Stuff That&#8217;s Clean and Small</h4>
<p>Dataflow is a beautiful bit of programming. It&#8217;s small, clean, and tested. It implements write-once variables with automated thread synchronization in just 52 lines of code. (Plus 120 lines of tests.) It supports:</p>
<ul>
<li> instance variables</li>
<li>local variables</li>
<li>dynamic values loaded into data structures such as arrays</li>
<li>It doesn&#8217;t seem to support class variables but I guess a constant can serve as a write-once class variable.</li>
</ul>
<p>Here are some code samples, copied from the README.</p>
<pre class="brush: ruby;">
# Local variables
include Dataflow

local do |x, y, z|
  # notice how the order automatically gets resolved
  Thread.new { unify y, x + 2 }
  Thread.new { unify z, y + 3 }
  Thread.new { unify x, 1 }
  z #=&gt; 6
end
</pre>
<pre class="brush: ruby;">
# Instance variables
class AnimalHouse
  include Dataflow
  declare :small_cat, :big_cat

  def fetch_big_cat
    Thread.new { unify big_cat, small_cat.upcase }
    unify small_cat, 'cat'
    big_cat
  end
end

AnimalHouse.new.fetch_big_cat #=&gt; 'CAT'
</pre>
<pre class="brush: ruby;">
# Data-driven concurrency
include Dataflow

local do |stream, doubles, triples, squares|
  unify stream, Array.new(5) { local {|v| v } }

  Thread.new { unify doubles, stream.map {|n| n*2 } }
  Thread.new { unify triples, stream.map {|n| n*3 } }
  Thread.new { unify squares, stream.map {|n| n**2 } }  

  Thread.new { stream.each {|x| unify x, rand(100) } }

  puts &quot;original: #{stream.inspect}&quot;
  puts &quot;doubles:  #{doubles.inspect}&quot;
  puts &quot;triples:  #{triples.inspect}&quot;
  puts &quot;squares:  #{squares.inspect}&quot;
end
</pre>
<p>It doesn&#8217;t take long to read the Dataflow code (it&#8217;s only 52 lines, after all) but it did take me a while stepping through it in the NetBeans debugger to wrap my head around how it works. Also the name of the variable-assignment method is a unintuitive to me. Assignment is done by calling the <code>unify</code> method. Apparently this name comes from the concept of <a href="http://www.ps.uni-sb.de/~niehren/Web/Vorlesungen/Oz-NL-SS01/vorlesung/node145.html#chapter.unification">unification</a>, which I think means: provide a bunch of algorithms whose variables have dependencies on each other and let the system work out the dependencies and execute the algorithms in the correct order to assign values as they are needed. Anyway, using a method called <code>unify</code> for assignment takes a little getting used to.</p>
<p>Note: Larry&#8217;s README says Dataflow was inspired by the Oz programming language, not the Erlang programming language. But I&#8217;m more familiar with Erlang so that&#8217;s what I can compare it to. The primary difference between Ruby-with-Dataflow and Erlang is that in Dataflow you declare a variable and then assign it a value, whereas in Erlang you have to assign at the moment you declare it. That&#8217;s how Erlang makes variables write-once: if you can only assign a value when you declare a variable, obviously it will only be assigned once. Dataflow lets you assign to the same variable multiple times but raises an error if you assign different values, so it&#8217;s equivalent to write-once. (It uses the != operator to decide whether the values are equal.)</p>
<h4>Interop with &#8220;Normal&#8221; Ruby</h4>
<p>The README also says, &#8220;The nice thing is that many existing libraries/classes/methods can still be used, just avoid side-effects.&#8221;</p>
<p>It&#8217;s true that you can write a program that uses Dataflow for some variables but also interops with non-Dataflow code as long as that code is thread-safe. I&#8217;m not quite sure what he meant by &#8220;just avoid side-effects.&#8221;</p>
<h4>But How Do You Assign New Values to Variables?</h4>
<p>If a variable can only be written once, what do you do when you need to change it? Obviously programs need to deal with this. For example, what if you need to loop over an array and keep track of the index as you go? Erlang handles it by heavy use of the stack and threads, so whenever you need a new value you call a function (which spawns a thread) and the function declares a new variable, assigning the new value to it. So there&#8217;s a lot of copying of values.</p>
<p>In Ruby with Dataflow I imagine you would do something similar: either call a function or spawn a thread for each iteration, passing in the current value, and have the function or thread declare a new local variable which is value+1. This style of programming takes some time before it becomes natural. It&#8217;s not yet natural for me.</p>
<p>There could also be performance implications. Erlang&#8217;s interpreter optimizes <a href="http://en.wikipedia.org/wiki/Tail_recursion">tail recursion</a> and converts it to an iteration (really a GOTO) under the hood so the stack doesn&#8217;t blow. I don&#8217;t know if any Ruby interpreters do that. As of a few years ago they didn&#8217;t, according to my Google search. <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/171108">Johannes Friestad wrote in 2005</a>, &#8220;Recursion, tail or no tail, works just as well as any other method call in Ruby. Plenty of thrive without optimizing for tail recursion, Java is one of them. The combination of a small stack and lack of tail recursion optimization does mean that in Ruby, recursion can hardly replace every other looping construct the way it can in Lisp. You&#8217;ll be the judge of whether that is important.&#8221;</p>
<p><strong>Update: </strong>Larry <a href="http://bmorearty.wordpress.com/2009/04/26/dataflow-erlang-style-thread-safety-in-ruby/?preview=true&amp;preview_id=182&amp;preview_nonce=421705eedc#comment-183">writes in the comments</a> that &#8220;this library makes JRuby shine over MRI due to its green threads + native thread pool implementation.&#8221; I&#8217;ve only used MRI and I didn&#8217;t know about that aspect of JRuby but it&#8217;s pretty nice. It sounds like if you&#8217;re going to use Dataflow you might want to use it with JRuby rather than MRI.</p>
<h4>Possible Concerns</h4>
<p>Dataflow is really cool but I do have a few potential concerns about it:</p>
<ol>
<li>Even though Dataflow makes it easier to write thread-safe code, it doesn&#8217;t fix the fact that it&#8217;s hard to debug multithreaded code. Stepping through multithreaded code in a debugger is complicated, especially when the code switches thread context on the fly.</li>
<li>Speaking of debugging, if the debugger tries to show you the value of a Dataflow variable that hasn&#8217;t yet been assigned, the debugger thread itself will be put to sleep. In NetBeans this means the &#8220;locals&#8221; pane stops working (but you can still debug) and if you hover the mouse over an unassigned variable, you don&#8217;t see anything in the tooltip. In rdebug it&#8217;s worse&#8211;if you eval a variable that doesn&#8217;t yet have a value, rdebug hangs because its main thread gets put to sleep.</li>
<li><span style="text-decoration:line-through;">You can&#8217;t assign nil to a Dataflow variables because nil is used to indicate that it hasn&#8217;t yet been assigned. I would like to be able to assign a value of nil and have that be different from &#8220;unassigned.&#8221; This would be a pretty easy fix to make to Dataflow without bloating memory&#8211;all unassigned variables could reference the same constant:<br />
<code>UNASSIGNED = Object.new<br />
</code></span>I removed this concern because <a href="http://bmorearty.wordpress.com/2009/04/26/dataflow-erlang-style-thread-safety-in-ruby/#comment-183">it&#8217;s been fixed</a>. Dataflow now differentiates between nil and unassigned.</li>
<li>Memory overhead: Dataflow is as efficient as possible with memory usage but it does incur some overhead on each variable. Compared to unthreaded programming, it is a lot. But compared to manual thread synchronization it&#8217;s probably about the same amount of memory you would have used for synchronization data structures anyway. It depends on how you do your manual synchronization. Each variable has, in addition to its value:
<ol>
<li><span style="text-decoration:line-through;">a Mutex</span></li>
<li><span style="text-decoration:line-through;">an Array (initially empty) of references to Threads that are waiting for it to be initialized</span></li>
<li>a Monitor condition to wake up the Threads that are waiting for it to be initialized</li>
<li>a Boolean to track whether it has a value yet (but cleverly, this boolean doesn&#8217;t get assigned until the variable is assigned, which saves some memory)</li>
</ol>
</li>
<li>More than the overhead per variable, I wonder about the memory overhead of constantly copying values rather than reassigning them. If the stack gets too deep you could run out of memory from all the copying. (See my description of looping above.) You also make the garbage collector work pretty hard. If you loop by spawning threads instead of using recursion, you incur a lot of overhead since threads are expensive compared to function calls. This is why Erlang&#8217;s interpreter has its own threading system instead of using the one in the operating system&#8211;threads have to be as cheap as function calls. In Ruby they are not.</li>
<li>Related to memory overhead, I wonder about the performance overhead. In addition to deep stacks and lots of threads, every time you call a method on a variable it gets routed through method_missing and Mutex.synchronize even if you have already called that method on that variable. (It does this so its method_missing override can put your thread to sleep until the variable has a value.) This could be expensive but it&#8217;s impossible to know for sure without profiling it. If it turns out to be a problem, method_missing could rewrite itself the first time after the variable gets assigned a value so all subsequent calls don&#8217;t have to be synchronized.</li>
</ol>
<p>That reads like a pretty big list of concerns but without actually using Dataflow I can&#8217;t tell how many of them will actually cause problems. I still think it&#8217;s cool. :-)</p>
<h4>Try it if You Need Threading</h4>
<p>I mentioned at the beginning that I&#8217;m cautious about using threads but there are some problems for which they are the right solution. Next time I&#8217;m confronted with such a problem on a Ruby project I will drop in the Dataflow gem and give it a try. It looks like a pretty good way to do threading in Ruby.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/182/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=182&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/04/26/dataflow-erlang-style-thread-safety-in-ruby/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>Listen to my interview on the Ruby on Rails Podcast</title>
		<link>http://bmorearty.wordpress.com/2009/04/15/listen-to-my-interview-on-the-ruby-on-rails-podcast/</link>
		<comments>http://bmorearty.wordpress.com/2009/04/15/listen-to-my-interview-on-the-ruby-on-rails-podcast/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 00:12:25 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=178</guid>
		<description><![CDATA[On Friday, Geoffrey Grosenbach interviewed Tom Hanley and me for the Ruby on Rails Podcast. Woo hoo!
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=178&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>On Friday, Geoffrey Grosenbach interviewed <a href="http://tjhanley.com/wp/">Tom Hanley</a> and me for the <a href="http://podcast.rubyonrails.org/programs/1/episodes/brian-moriarty-and-thomas-hanley-of-intuit">Ruby on Rails Podcast</a>. Woo hoo!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/178/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=178&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/04/15/listen-to-my-interview-on-the-ruby-on-rails-podcast/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>Add Optional SEO-Friendliness to link_to_remote</title>
		<link>http://bmorearty.wordpress.com/2009/04/02/link-to-remote-with-seo/</link>
		<comments>http://bmorearty.wordpress.com/2009/04/02/link-to-remote-with-seo/#comments</comments>
		<pubDate>Thu, 02 Apr 2009 22:35:42 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=141</guid>
		<description><![CDATA[link_to_remote_with_seo adds optional SEO-friendly goodness to the Rails link_to_remote function.  I wrote it for cases where I would have used link_to_remote in my Rails app but I wanted GoogleBot and other search engines to be able to follow the links.  In addition to setting onclick like the normal link_to_remote, it also sets html_options[:href] to the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=141&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><a href="http://github.com/BMorearty/link_to_remote_with_seo/tree/master">link_to_remote_with_seo</a> adds optional SEO-friendly goodness to the Rails link_to_remote function.  I wrote it for cases where I would have used link_to_remote in my Rails app but I wanted GoogleBot and other search engines to be able to follow the links.  In addition to setting onclick like the normal link_to_remote, it also sets html_options[:href] to the SAME URL that you pass in to options[:url]. (It only does this if you pass :seo =&gt; true and you do not explicitly set the href.)</p>
<p>See the big honking warning at the bottom for an explanation of why this plugin doesn&#8217;t just override the behavior of link_to_remote.</p>
<h4>I Like Stuff that&#8217;s SEO-Friendly</h4>
<p>The following example shows a &#8220;Next&#8221; link in paginated output.  Clicking the link in a browser results in an AJAX call (using the POST method) that retrieves just the &#8220;page&#8221; partial and inserts it into the &#8220;results&#8221; div on the page with a highlight visual effect.  When a search engine sees the link, however, it will send a GET request to the same URL, and the entire page (not just the partial) will be sent in the response.</p>
<p>Putting this in the view (home/index.html.erb):</p>
<pre class="brush: xml;">
&lt;div id=&quot;results&quot;&gt;
  &lt;%= render :partial =&gt; &quot;page&quot; -%&gt;&lt;/div&gt;
&lt;%= link_to_seo_remote &quot;Next&quot;,
  { :update =&gt; &quot;#results&quot;,
    :url =&gt; { :action =&gt; &quot;next_page&quot; },
    :complete =&gt; visual_effect(:highlight, &quot;#results&quot;) } %&gt;
</pre>
<p>Produces (pay attention to the href attrbute):</p>
<pre class="brush: xml;">
&lt;div id=&quot;results&quot;&gt;
  &lt;!-- first page of results shown here --&gt;&lt;/div&gt;
&lt;a href=&quot;/home/next_page&quot;
  onclick=&quot;new Ajax.Updater('#results', '/home/next_page',
  {asynchronous:true, evalScripts:true,
  onComplete:function(request){new Effect.Highlight(&amp;quot;#results&amp;quot;,{});}}); return false;&quot;&gt;
  Next
&lt;/a&gt;
</pre>
<p>In  the controller (home.rb), render just the partial if called in an XHR (AJAX) request:</p>
<pre class="brush: ruby;">
def next_page
  if request.xhr?
    render :partial =&gt; &quot;page&quot;
  else
    # Render the entire page, including the &quot;results&quot; section.
    render :action =&gt; &quot;index&quot;
  end
end
</pre>
<h4>WARNING ABOUT INCORRECT USE OF THIS FUNCTION</h4>
<p>Sorry but I have to yell for emphasis here.</p>
<p>When Google crawls your site it will follow all links on a page in advance, even before the user clicks on them.  Adding :confirm =&gt; &#8220;Are you sure?&#8221; <strong>WILL NOT HELP </strong>because it generates JavaScript that Google doesn&#8217;t execute.  So when you use link_to_seo_remote, DO NOT ALLOW destructive links to be placed in the href attribute.  Instead, override html_options[:href] to link to an intermediate page with &#8220;Are you sure?&#8221; and a BUTTON (not a link.  The crawler will not click the link, so the data will not be deleted.</p>
<p>See <a href="http://jlaine.net/2005/8/25/using-rails-ajax-helpers-to-create-safe-state-changing-links">Using Rails AJAX Helpers to Create Safe State-Changing Links</a> and search the page for &#8220;request.post?&#8221; for an explanation and some sample code.</p>
<h4>Does it Have Tests?</h4>
<p>Why, yes. I&#8217;d like to thank the Rails Community for not tolerating code with no tests. It was soooo tempting just to release this without writing automated tests but the peer pressure got to me.</p>
<p>And I&#8217;ll also like to thank Cake for awesome music.</p>
<h4>To get the code</h4>
<pre>ruby script/plugin install http://github.com/BMorearty/link_to_remote_with_seo.git</pre>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=141&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/04/02/link-to-remote-with-seo/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>Obfuscated ActionScript</title>
		<link>http://bmorearty.wordpress.com/2009/04/01/obfuscated-actionscript/</link>
		<comments>http://bmorearty.wordpress.com/2009/04/01/obfuscated-actionscript/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 20:56:55 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=134</guid>
		<description><![CDATA[My brother Mike, a developer on the Flex team at Adobe, wrote a pretty impressive bit of Obfuscated ActionScript on his blog.
Check it out. See if you can figure out what the program does before you follow his link to the answer.
(This snippet is just a taste of it.)

       [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=134&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>My brother Mike, a developer on the Flex team at Adobe, wrote a pretty impressive bit of <a href="http://www.morearty.com/blog/2009/04/01/aprilscript-actionscript-worst-practices/">Obfuscated ActionScript</a> on his blog.</p>
<p>Check it out. See if you can figure out what the program does before you follow his link to the answer.</p>
<p>(This snippet is just a taste of it.)</p>
<p><img class="alignnone size-full wp-image-138" title="getset" src="http://bmorearty.files.wordpress.com/2009/04/getset.png?w=426&#038;h=105" alt="getset" width="426" height="105" /></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/134/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=134&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/04/01/obfuscated-actionscript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>

		<media:content url="http://bmorearty.files.wordpress.com/2009/04/getset.png" medium="image">
			<media:title type="html">getset</media:title>
		</media:content>
	</item>
		<item>
		<title>My Favorite Quotes from the Yellowpages.com Ruby on Rails Talk</title>
		<link>http://bmorearty.wordpress.com/2009/03/22/my-favorite-quotes-from-the-yellowpagescom-ruby-on-rails-talk/</link>
		<comments>http://bmorearty.wordpress.com/2009/03/22/my-favorite-quotes-from-the-yellowpagescom-ruby-on-rails-talk/#comments</comments>
		<pubDate>Sun, 22 Mar 2009 18:30:02 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=128</guid>
		<description><![CDATA[I just watched a video from the 2008 QCon conference of a talk by John Straw about how and why Yellowpages.com rewrote their Java site to use Ruby on Rails. It&#8217;s a pretty good talk. He starts by describing the situation they were in that led them to consider a rewrite, then goes into the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=128&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><img class="alignright size-thumbnail wp-image-130" title="yellowpages" src="http://bmorearty.files.wordpress.com/2009/03/yellowpages.jpg?w=127&#038;h=96" alt="yellowpages" width="127" height="96" />I just watched a video from the 2008 QCon conference of <a href="http://www.infoq.com/presentations/straw-yellowpages">a talk by John Straw about how and why Yellowpages.com rewrote their Java site to use Ruby on Rails</a>. It&#8217;s a pretty good talk. He starts by describing the situation they were in that led them to consider a rewrite, then goes into the architectural decisions and some of the technical details.</p>
<p>Here are some some choice quotes from the talk, along with my own commentary.</p>
<blockquote><p><strong>&#8220;All programmers want to rewrite the code they&#8217;re forced to maintain. They&#8217;re almost always wrong.&#8221;</strong></p></blockquote>
<p>Man, is that ever true. (Note that he said <em>almost </em>always. After all, his talk is about a successful rewrite.)</p>
<p>I&#8217;ve seen it again and again. Programmers tend to believe the code they&#8217;re maintaining (that someone else wrote) sucks and they could write it much better. Often that&#8217;s because they haven&#8217;t taken the time to understand the code base. As Joel on Software says, <a href="http://www.joelonsoftware.com/articles/fog0000000069.html">&#8220;It’s harder to read code than to write it.&#8221;</a> I think usually (but not always) the cost of rewriting it far outweighs any benefits. What you&#8217;d typically end up with after a rewrite is:</p>
<ul>
<li>A few years have passed</li>
<li>You&#8217;ve spent a ton of money on the rewrite</li>
<li>The app still has bugs&#8211;just a different set of bugs. (Another quote from the Joel article: &#8220;The idea that new code is better than old is patently absurd.&#8221;)</li>
<li>A new generation of programmers will join the team soon. They will complain that the code base sucks and needs to be rewritten.</li>
</ul>
<p>Having said that, I know there <em>are </em>times when a rewrite is the right thing to do. But that&#8217;s a discussion for another day.</p>
<p>Something I think his team did correctly: they made a goal of finishing the rewrite in four months, not two years. A massive two-year rewrite has an extremely low chance of succeeding.</p>
<blockquote><p><strong>&#8220;EJB3 is a whole big boxcar full of crazy.&#8221;</strong></p></blockquote>
<p>Now that&#8217;s just funny. (He said that after saying EJB3 is much better than earlier generations of EJB, by the way.)</p>
<blockquote><p><strong>&#8220;At this point our performance architect will maintain that Apache is unsuitable for use in any production web serving environment, in general. (And only nginx with its polling model is the right way to go.)&#8221;</strong></p></blockquote>
<p>I don&#8217;t agree but it&#8217;s a great quote.</p>
<blockquote><p><strong>&#8220;I actually kind of like the thread-unsafety of Rails. I mean it simplifies the programming model quite a bit for simple web sites. You know: I&#8217;m handling one request; I understand how to scale that.&#8221;</strong></p></blockquote>
<p>I totally agree with that. As someone who loves writing software, I think threading is fun and awesome and there are situations where it&#8217;s a must&#8211;I once even thought about writing a book about threading on Win32. When I was first introduced to Ruby on Rails I had a kneejerk &#8220;are you kidding me?&#8221; reaction when I heard it wasn&#8217;t thread-safe. But I&#8217;ve since formed the opinion that single-threading is really nice when you can get away with it because of its simplicity. It helps developers focus on the task at hand rather than spending a lot of time debugging threading problems. In a multi-threading environment it&#8217;s too easy for developers who understand threading to introduce code that then gets broken by other developers&#8211;and it&#8217;s too hard to write tests that will catch the breakage the moment it occurs.</p>
<p>By the way, the speaker&#8217;s next sentence was &#8220;Obviously our fast service-side application is multi-threaded and we have good benefits from that.&#8221; So he&#8217;s not saying multi-threading should never be used.</p>
<blockquote><p><strong>&#8220;Testing was a big part of the decision. You know, that was actually one of the things which drew me so strongly to the platform once I started understanding it. I had spent years myself as a Java developer trying to figure out how in the heck to use JUnit to do anything useful on my web site. And maybe that was just a failure of imagination on my part, but when we started looking at Rails we didn&#8217;t have to figure it out. It was obvious how to test each level. Both the unit tests for the models, and the functional tests and the integration tests. It was all there in the framework. And not only was the framework built to make it easy, but the community expected it. You know, I&#8217;ve never seen a development community that was so involved and oriented towards writing test code&#8211;writing test automation&#8211;than this one. And so that was a big part of our decision.&#8221;</strong></p></blockquote>
<p>So true. I have found that when it&#8217;s obvious how to write effective tests and where to put them, I will write tons of tests. If the framework greases the wheels of test-writing and make it pain-free, I will write a lot more and better tests. Rails does a lot better at this than other frameworks I&#8217;ve used, although I still think it could use improvement. And I love the emphasis placed on automated testing in the Rails community.</p>
<p>Well, that&#8217;s it. To see the whole talk, go to <a href="http://www.infoq.com/presentations/straw-yellowpages">http://www.infoq.com/presentations/straw-yellowpages</a>. And enjoy the grouchy comments by Java developers below the video.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/128/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=128&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/03/22/my-favorite-quotes-from-the-yellowpagescom-ruby-on-rails-talk/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>

		<media:content url="http://bmorearty.files.wordpress.com/2009/03/yellowpages.jpg?w=127" medium="image">
			<media:title type="html">yellowpages</media:title>
		</media:content>
	</item>
		<item>
		<title>Put HTML tags and apostrophes in fixtures and tests or a meanie will hack you.</title>
		<link>http://bmorearty.wordpress.com/2009/01/15/put-html-tags-and-apostrophes-in-fixtures-and-tests-or-a-meanie-will-hack-you/</link>
		<comments>http://bmorearty.wordpress.com/2009/01/15/put-html-tags-and-apostrophes-in-fixtures-and-tests-or-a-meanie-will-hack-you/#comments</comments>
		<pubDate>Thu, 15 Jan 2009 06:13:45 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=67</guid>
		<description><![CDATA[Here&#8217;s a good way to protect against cross-site scripting attacks and SQL injection attacks. This will help catch mistakes where you (well actually your teammate, since you&#8217;re perfect) forgot to call &#8220;h&#8221; in a &#60;%= %&#62; block, or accidentally passed a SQL statement to the database without escaping the values:
Sprinkle unclosed HTML tags and apostrophes [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=67&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Here&#8217;s a good way to protect against <a href="http://www.owasp.org/index.php/Cross_Site_Scripting">cross-site scripting attacks</a> and <a href="http://www.owasp.org/index.php/SQL_injection">SQL injection attacks</a>. This will help catch mistakes where you (well actually your teammate, since you&#8217;re perfect) forgot to call &#8220;h&#8221; in a <code>&lt;%= %&gt;</code> block, or accidentally passed a SQL statement to the database without escaping the values:</p>
<blockquote><p><span style="color:#ff0000;"><strong>Sprinkle unclosed HTML tags and apostrophes all over your fixture data and test code. </strong></span></p></blockquote>
<p>Then use <a href="http://api.rubyonrails.com/classes/ActionController/Assertions/SelectorAssertions.html#M000397"><code>assert_select</code></a> liberally, which will barf on the console if it sees unclosed HTML tags&#8211;even if you were selecting some other part of the document.</p>
<h4>I Like Stuff that&#8217;s Safe</h4>
<p>Here is what a posts.yml file might look like:</p>
<pre class="brush: ruby;">
test_post:
  id: 1
  subject: &lt;script&gt; attack!
  detail: &quot;sql injection: '; drop table posts;&quot;
</pre>
<p>(If you use an apostrophe in YAML you have to quote the whole string.)</p>
<p>So <code>assert_select</code> has this handy side-effect I mentioned where it tells you about your malformed HTML. Since Rails tests don&#8217;t actually run in a browser, you need some other way to know that you&#8217;ve forgotten to escape data. Unclosed HTML tags in your fixtures, yeah, that&#8217;s the ticket.</p>
<p>And remember, you don&#8217;t need to call <code>assert_select</code> on the element that contains the bad data. Just call assert_select on <em>anything </em>and it will parse the output to make sure it&#8217;s well-formed.</p>
<pre class="brush: ruby;">
  def test_show
    post = posts(:test_post)
    get :show, post.id
    assert_select &quot;body&quot;
  end
</pre>
<p>The idea is that by sprinkling XSS attacks through your fixtures and using assert_select whenever you&#8217;re testing <em>other </em>stuff, the XSS attacks will become apparent.</p>
<p>If you do need to assert that the output is correct, you can call CGI::escapeHTML:</p>
<pre class="brush: ruby;">
  def test_show
    post = posts(:test_post)
    get :show, post.id
    assert_select &quot;span&quot;, :count =&gt; 1,
      :text =&gt; CGI::escapeHTML(post.detail)
  end
</pre>
<h4>I can&#8217;t haz SQL injection attacks</h4>
<p>I admit that putting SQL injection attacks in the fixtures is a bit contrived and may not help. A better way to catch SQL injection attacks is to pass apostrophes into the app from your test code, so go ahead and sprinkle your test code with beauties like this:</p>
<pre class="brush: ruby;">
  def test_update
    post :update, posts(:test_post).id,
      :detail =&gt; &quot;sql injection: '; drop table posts;&quot;
  end
</pre>
<p>The secret to making this work is:</p>
<ol>
<li>apostrophe</li>
<li>semicolon</li>
<li>SQL statement</li>
<li>another semicolon</li>
</ol>
<p>You want to use a SQL statement that will cause a test to fail. It would be coolio if there were some way to make the current test succeed and subsequent tests fail, but I&#8217;m not sure I know a way to do that consistently. But at least if you use a &#8220;drop table&#8221; statement, you&#8217;re going to cause subsequent tests to fail (if there are any subsequent tests that use that table) because a schema change does not happen in a transaction. So even if you&#8217;re using transactional fixtures, the next test will fail anyway cuz the dang table is gone.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/67/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=67&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/01/15/put-html-tags-and-apostrophes-in-fixtures-and-tests-or-a-meanie-will-hack-you/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>Fun with Ruby&#8217;s instance_eval and class_eval</title>
		<link>http://bmorearty.wordpress.com/2009/01/09/fun-with-rubys-instance_eval-and-class_eval/</link>
		<comments>http://bmorearty.wordpress.com/2009/01/09/fun-with-rubys-instance_eval-and-class_eval/#comments</comments>
		<pubDate>Fri, 09 Jan 2009 18:04:35 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=79</guid>
		<description><![CDATA[In an attempt to better understand instance_eval and class_eval, I just read Khaled&#8217;s post on Ruby reflection. It helped, and I came up with a memory crutch I can use to remember when to use each of them:
Use ClassName.instance_eval to define class methods.
Use ClassName.class_eval to define instance methods.
That&#8217;s right. Not a typo. Here are some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=79&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>In an attempt to better understand instance_eval and class_eval, I just read <a href="http://www.khelll.com/blog/ruby/ruby-reflection/">Khaled&#8217;s post on Ruby reflection</a>. It helped, and I came up with a memory crutch I can use to remember when to use each of them:</p>
<blockquote><p>Use ClassName.<strong>instance_eval</strong> to define <strong>class </strong>methods.</p>
<p>Use ClassName.<strong>class_eval</strong> to define <strong>instance </strong>methods.</p></blockquote>
<p>That&#8217;s right. Not a typo. Here are some examples, shamelessly stolen from his post:</p>
<pre class="brush: ruby;">
# Defining a class method with instance_eval
Fixnum.instance_eval { def ten; 10; end }
Fixnum.ten #=&gt; 10

# Defining an instance method with class_eval
Fixnum.class_eval { def number; self; end }
7.number #=&gt; 7
</pre>
<h4>I Like Stuff that&#8217;s Backwards</h4>
<p>Why is it the reverse of what you might expect? Because Fixnum.instance_eval treats Fixnum as an instance (an instance of the Class class), thus any new functions you define can be called on that instance. So it&#8217;s equivalent to this:</p>
<pre class="brush: ruby;">
class Fixnum
  def self.ten
    10
  end
end
Fixnum.ten #=&gt; 10
</pre>
<p>Fixnum.class_eval treats Fixnum as a class and executes the code in the context of that class, thus any &#8220;def&#8221; statements are treated exactly as if they were in normal code without any reflection. It&#8217;s equivalent to this:</p>
<pre class="brush: ruby;">
class Fixnum
  def number
    self
  end
end
7.number #=&gt; 7
</pre>
<p>There are still some things about Ruby reflection that mystify me but at least I think I&#8217;ve got this one nailed.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/79/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=79&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/01/09/fun-with-rubys-instance_eval-and-class_eval/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>Generate guid ids 2100x faster for ActiveRecord models (but only if you use MySQL)</title>
		<link>http://bmorearty.wordpress.com/2009/01/03/generate-guid-ids-2100x-faster-for-activerecord-models-but-only-if-you-use-mysql/</link>
		<comments>http://bmorearty.wordpress.com/2009/01/03/generate-guid-ids-2100x-faster-for-activerecord-models-but-only-if-you-use-mysql/#comments</comments>
		<pubDate>Sat, 03 Jan 2009 05:41:43 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=31</guid>
		<description><![CDATA[The Rails project I&#8217;m working on (the Small Business Help Forums at the Intuit Community) has some tables that use GUIDs for their primary keys instead of autoincrement integers. To implement GUIDs we used the handy usesguid plugin. All you have to do is change your &#8220;id&#8221; column to a 22-character varchar (make sure it&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=31&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>The Rails project I&#8217;m working on (the <a title="Small Business Help Forums at the Intuit Community" href="http://community.intuit.com">Small Business Help Forums at the Intuit Community</a>) has some tables that use GUIDs for their primary keys instead of autoincrement integers. To implement GUIDs we used the handy <a href="http://tools.assembla.com/breakout/wiki/FreeSoftware">usesguid plugin</a>. All you have to do is change your &#8220;id&#8221; column to a 22-character varchar (make sure it&#8217;s a binary varchar and uses binary collation, so upper and lower case are treated differently) and put this in your model:</p>
<pre class="brush: ruby;">
class MyModel &lt; ActiveRecord::Base
  usesguid
end
</pre>
<p>Pretty nice.</p>
<p>Just one problem.</p>
<p>It&#8217;s HECKA slow.</p>
<p>On my Windows machine it was taking a whopping 0.4 seconds to create a GUID with this plugin. On my Linux VM it was a lot faster, but still slower than it should be (0.0322 seconds&#8211;just 31 GUIDs per second).</p>
<h4>Download the Faster Plugin</h4>
<p>If you use MySQL for your database and you&#8217;d like to download my modified usesguid plugin which is <em>way</em> faster, type this from the main directory of your Rails app:</p>
<pre><code> script/plugin install git://github.com/BMorearty/usesguid.git</code></pre>
<p>Or <a href="http://github.com/BMorearty/usesguid/tree/master">download it here</a> and copy it into vendor/plugins/usesguid.</p>
<p>Then add the &#8220;usesguid&#8221; statement (see above) to any models that you want to have guid ids, migrate the id columns to binary varchar(22), and add this to your environment.rb file:</p>
<pre class="brush: ruby;">
ActiveRecord::Base.guid_generator = :mysql
</pre>
<p>Here is a sample migration for creating a new table with guids, as opposed to changing an existing one to use them:</p>
<pre class="brush: ruby;">
create_table :products, :id =&gt; false, :options =&gt; 'ENGINE=InnoDB' do |t|
  # This table uses guid ids
  t.binary :id,   :limit =&gt; 22, :null =&gt; false
  t.string :name, :limit =&gt; 50, :null =&gt; false
end
# Since the t.column syntax can't specify a character set and collation...
execute &quot;ALTER TABLE `products` MODIFY COLUMN `id` VARCHAR(22) BINARY CHARACTER SET latin1 COLLATE latin1_bin NOT NULL;&quot;
execute &quot;ALTER TABLE `products` ADD PRIMARY KEY (id)&quot;
</pre>
<h4>I Like Stuff that&#8217;s Fast</h4>
<p>Read on to find out why the old code was so slow, and how the code got 2100 times faster.</p>
<p>I investigated to see why it takes so long, and found that every time it creates a GUID, it calls UUID.timestamp_create. This in turn calls UUID.get_mac_address, which spawns a new process (ipconfig on Windows; ifconfig on UNIX-based systems) and parses the output. The reason: to discover the network card&#8217;s MAC address. (Hey yeah, even Windows has a MAC address.)</p>
<p>But the MAC address never changes. It&#8217;s hard-wired into the network card. So why bother querying it every time you create a GUID? Launching a whole new process every time we need a GUID is overkill.</p>
<p>My first thought was to write a plugin on top of the plugin. My plugin would cache result of UUID.get_mac_address. I tried it, but found a problem: there&#8217;s a bug in UUID.timestamp_create. If it executes too quickly on a system whose clock resolution is not high enough, it returns the same GUID multiple times in a row. Whoops! Kind of defeats the purpose of GUIDs.</p>
<p>So I decided to take advantage of the fact that MySQL has a &#8220;SELECT UUID()&#8221; syntax, and I wrote a new GUID creator in the UUID class that calls MySQL to generate GUIDs. (Obviously this only works if you have MySQL.) I called this new creator &#8220;UUID.mysql_create.&#8221; The first time it is called, it calls MySQL like this:</p>
<pre class="brush: sql;">
SELECT UUID(), UUID(), UUID(), UUID(), UUID(), ... ;
</pre>
<p>It selects 50 UUIDs in a single round-trip to the database and stores the results in memory. Each time a new GUID is required, it plucks one off the list. When the list is empty and another one is required, it goes and gets another 50.</p>
<p>On my Windows machine, creating a GUID with UUID.mysql_create now takes <span style="color:red;">0.0001937 seconds, which is over <strong>2100 times faster</strong></span> than the 0.4 seconds it used to take. On my Linux VM it&#8217;s 0.0001671 seconds, or <strong>193 times faster </strong>than the 0.0322 seconds it used to take.</p>
<p>All these changes were made in a new file, uuid_mysql.rb. But I also made a number of changes to the usesguid.rb file:</p>
<ol>
<li>Added a configuration option so you can specify which creator to use. The default is still timestamp_create, but to use mysql_create you just put &#8220;ActiveRecord::Base.guid_generator = :mysql&#8221; in your environment.rb file.</li>
<li>Fixed the code so it respects the :column option, which lets you override the column that stores the primary key.</li>
<li>Delayed the assignment of a guid until just before creation (before_create) rather than just after &#8220;new&#8221; (after_initialize). This has two benefits:
<ol>
<li>It more closely mimics the default behavior of autoincrement columns, which doesn&#8217;t assign an id until after creation</li>
<li>It is faster. After_initialize gets called every time a model object is instantiated, including all objects return by a call to find. (But don&#8217;t worry, it wasn&#8217;t generating GUIDs for all those objects; it was just being called and bailing out when it saw there was already an id).  Before_create only gets called for newly created model objects.</li>
</ol>
</li>
</ol>
<p>I thought about making it even faster by calling CoCreateGuid() on Windows and calling a UNIX C function to create a GUID when on UNIX, but it&#8217;s so fast now that it hardly seemed worth the extra effort and the extra platform-specific code.</p>
<p>So that&#8217;s it. Enjoy it!</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=31&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2009/01/03/generate-guid-ids-2100x-faster-for-activerecord-models-but-only-if-you-use-mysql/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>Find tests more easily in your Rails test.log</title>
		<link>http://bmorearty.wordpress.com/2008/06/18/find-tests-more-easily-in-your-testlog/</link>
		<comments>http://bmorearty.wordpress.com/2008/06/18/find-tests-more-easily-in-your-testlog/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 01:25:09 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=19</guid>
		<description><![CDATA[Here&#8217;s a nice little trick to make it easier to search test.log for the results of a specific test that&#8217;s failing. This trick works with normal Rails unit tests and with Shoulda tests.
When a Rails test fails, I look for it in test.log to see if there are any clues there. But it&#8217;s pretty hard to find [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=19&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Here&#8217;s a nice little trick to make it easier to search test.log for the results of a specific test that&#8217;s failing. This trick works with normal Rails unit tests and with <a href="http://www.thoughtbot.com/projects/shoulda">Shoulda</a> tests.</p>
<p>When a Rails test fails, I look for it in test.log to see if there are any clues there. But it&#8217;s pretty hard to find the portion of the log associated with the test that failed. In this sample section of a log, where does the processing begin for the test called <tt>test_should_require_email_on_signup</tt>?</p>
<p style="text-align:center;"><a href="http://bmorearty.files.wordpress.com/2008/06/test-log-without-titles.png"><img class="alignnone size-full wp-image-23" src="http://bmorearty.files.wordpress.com/2008/06/test-log-without-titles.png?w=447&#038;h=527" alt="test.log without titles" width="447" height="527" /></a><br />
<strong>Which test is which? Where does my test start?</strong></p>
<p><a href="http://bmorearty.files.wordpress.com/2008/06/test-log-without-titles.png"></a></p>
<p><a href="http://bmorearty.files.wordpress.com/2008/06/test-log-without-titles.png"></a></p>
<p><a href="http://bmorearty.files.wordpress.com/2008/06/test-log-without-titles.png"></a></p>
<p>It&#8217;s hard to find. Now imagine running rake on all your tests and sifting through the whole test.log looking for one test whose name you know, but the test name isn&#8217;t in the log.</p>
<p>So the other day I wrote a bit of code in my test_helper.rb file to make the log a lot easier to sift through. Here&#8217;s what the above log looks like with this code in place:</p>
<p><a href="http://bmorearty.files.wordpress.com/2008/06/test-log-with-titles.png"></a></p>
<p style="text-align:center;"><a href="http://bmorearty.files.wordpress.com/2008/06/test-log-with-titles.png"><img class="alignnone size-full wp-image-24" src="http://bmorearty.files.wordpress.com/2008/06/test-log-with-titles.png?w=447&#038;h=654" alt="test.log with titles" width="447" height="654" /></a><br />
<strong>Ooh, nice-n-clear</strong></p>
<p>Ahh, that&#8217;s more like it. Now it&#8217;s easy to tell where <tt>test_should_require_email_on_signup</tt> begins. If you scroll up and look at the first log again, you&#8217;ll see that there isn&#8217;t even a blank line separating that test from the previous one. (See how the test starts on the <tt>SELECT count(*)</tt> statement?)</p>
<p>Here&#8217;s the code. <strong>Drop it into test_helper.rb</strong> for your Rails project. To me this seems like a nice little example of how Ruby&#8217;s <a href="http://www.juixe.com/techknow/index.php/2007/01/17/reopening-ruby-classes-2/">open classes</a> can benefit developers (while understandably <a href="http://www.artima.com/forums/flat.jsp?forum=270&amp;thread=173574">considered harmful</a> by some). In a language without <a href="http://en.wikipedia.org/wiki/Monkey_patch">monkey patching</a>, I would have to resort to something more painful like changing all my tests to be derived from my own subclass of TestCase, and put this code in that class.</p>
<p>Enjoy!</p>
<pre class="brush: ruby;">
class Test::Unit::TestCase
  # This extension prints to the log before each test.  Makes it easier to find the test you're looking for
  # when looking through a long test log.
  setup :log_test
 
  private
 
  def log_test
    if Rails::logger
      # When I run tests in rake or autotest I see the same log message multiple times per test for some reason.
      # This guard prevents that.
      unless @already_logged_this_test
        Rails::logger.info &quot;\n\nStarting #{@method_name}\n#{'-' * (9 + @method_name.length)}\n&quot;
      end
      @already_logged_this_test = true
    end
  end
end
</pre>
<p>P.S. I didn&#8217;t spend the time to figure out why my callback was being called multiple times for each test. I just inserted the guard you see in the code above to prevent the same test title from being shown multiple times.</p>
<p>Drop me a line in the Reply section below and let me know what you think&#8211;especially if you&#8217;ve figured out why each one is called multiple times when running from rake or autotest.</p>
<p><strong>Updated 6/18: </strong>I corrected the code above because WordPress automatically inserted a &#8220;mailto:&#8221; tag when it saw the @ sign.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bmorearty.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bmorearty.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=19&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2008/06/18/find-tests-more-easily-in-your-testlog/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>

		<media:content url="http://bmorearty.files.wordpress.com/2008/06/test-log-without-titles.png" medium="image">
			<media:title type="html">test.log without titles</media:title>
		</media:content>

		<media:content url="http://bmorearty.files.wordpress.com/2008/06/test-log-with-titles.png" medium="image">
			<media:title type="html">test.log with titles</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Show Response Time in a Rails Page with Mongrel</title>
		<link>http://bmorearty.wordpress.com/2008/05/21/how-to-show-response-time-in-a-rails-page-with-mongrel/</link>
		<comments>http://bmorearty.wordpress.com/2008/05/21/how-to-show-response-time-in-a-rails-page-with-mongrel/#comments</comments>
		<pubDate>Wed, 21 May 2008 07:28:55 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=9</guid>
		<description><![CDATA[You&#8217;ve seen this on Google result pages, right?


You wanna do that in your Rails app that runs with Mongrel? I show you how. Sit down. And along the way I&#8217;ll show what I learned about writing custom Mongrel HttpHandlers and why you shouldn&#8217;t store instance variable in them.
I remember seeing it there long ago when Google [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=9&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><h3><a href="http://bmorearty.files.wordpress.com/2008/05/response-time-2.png"></a>You&#8217;ve seen this on Google result pages, right?</h3>
<p><a href="http://bmorearty.files.wordpress.com/2008/04/render-time-on-google.png"></a><a href="http://bmorearty.files.wordpress.com/2008/04/render-time-on-google.png"></a></p>
<p><a href="http://bmorearty.files.wordpress.com/2008/04/google-render-time.png"><img class="alignnone size-full wp-image-15" src="http://bmorearty.files.wordpress.com/2008/04/google-render-time.png?w=261&#038;h=115" alt="" width="261" height="115" /></a></p>
<p>You wanna do that in your Rails app that runs with Mongrel? I show you how. Sit down. And along the way I&#8217;ll show what I learned about writing custom Mongrel <tt>HttpHandlers</tt> and why you shouldn&#8217;t store instance variable in them.</p>
<p>I remember seeing it there long ago when Google was new. I liked it because:</p>
<ol>
<li>Faster is better</li>
<li>It shows Google focuses on helping me go fast</li>
<li>It reminds the Google developers to focus on helping me go fast</li>
</ol>
<p>So I&#8217;m developing this awesome web site now and I&#8217;m using Ruby on Rails with Mongrel. I wanted to pull a Google and show the server response time as text content in my pages, as a reminder to myself and my co-developer that it&#8217;s super-important to keep things fast.</p>
<h4>I can haz question</h4>
<blockquote><p>How do you put response time in a page using Rails?</p></blockquote>
<p><span id="more-9"></span>So I did some research. My first inclination was to create an <tt>around_filter</tt> in my <tt>ApplicationController</tt>. In fact the documentation for <tt>ActionController::Filters</tt> even uses a BenchmarkingFilter as an example.</p>
<p>But if I put a filter there what would it benchmark? Just the time spent in the controller and view? But what about the time spent in Rails outside my controller and my view? I want a benchmark that&#8217;s higher up the chain, kinda close to where the request is received and the response is sent back, so the time displayed in the page gives a truer picture of how long it took to handle the request.</p>
<p>More importantly: let&#8217;s say my server gets backed up with a queue of requesteses (through my amazing connections I get on the Yahoo! home page and there are more simultaneous requests than I have request handlers). I&#8217;d like to profile the total time from when each request first came on board until I said buh-bye to the response. If I use an around_filter I&#8217;m not including a crucial piece of the response time: <strong>how long my user waited in line before even entering Rails because my server was serving someone else first.</strong></p>
<p>If you&#8217;re at the ball game and you go get a hot dog and there are 30 people in front of you in line, are you excited that it takes only 1 minute to serve each person? Hell no. You&#8217;ll be there 31 minutes, including the time to serve you. You&#8217;ll miss two innings and the game-winning homer by Mr. Steroid. 31 minutes is the response time that matters because that&#8217;s how long the customer is waiting.</p>
<p>Plus you know you always get stuck in the slow line so it&#8217;s more like 50 minutes.</p>
<p>So that&#8217;s when I realized that I was asking the wrong question. The question isn&#8217;t how do you put response time in a page using Rails.</p>
<h4>The question I shoulda had</h4>
<blockquote><p>How do you put response time in a page using <strong>Mongrel</strong>?</p></blockquote>
<p>Mongrel sits higher up the food chain than Rails. It&#8217;s the little servy thing that doles out HTTP requests to ActionController.</p>
<p>I did a little digging and found that Mongrel has something called <strong>handlers</strong>, also known as <strong>filters</strong>.</p>
<p>Handlers are how Mongrel handles requests. When Mongrel gets a request it runs through all its handlers, passing the request to each one. (It calls them all; by default it doesn&#8217;t stop when one of them handles the request.) Handlers are not just for extensibility&#8211;they&#8217;re the way Mongrel works. There&#8217;s a <tt>RailsHandler</tt> that comes with Mongrel. That&#8217;s the one that passes requests off to Rails. There&#8217;s also a <tt>DirHandler</tt>. In a Rails app it uses that one to handle requests for files in the <tt>public/</tt> folder. There are other handlers for other things. Like a <tt>CampingHandler</tt> for Why the Lucky Stiff&#8217;s <a title="Camping" href="http://code.whytheluckystiff.net/camping">Camping</a>.</p>
<p>Each handler has a <tt>process</tt> method that Mongrel calls to process requests.</p>
<p>Each handler also has an optional <tt>request_begins</tt> method. For each request Mongrel calls the <tt>request_begins</tt> methods in all the handlers first, then it calls the <tt>process</tt> methods in all the handlers.</p>
<p>But here&#8217;s the sweet part. Rails may be single-threaded but Mongrel ain&#8217;t. <strong>Mongrel calls <span style="font-family:Courier New;">request_begins</span> on all the HttpHandlers the moment it sees a new request.</strong> This happens in a separate thread from the one that&#8217;s currently processing a request in Rails (or some other handler), so it does not even have to wait for the current customer to be served before starting the timer on the newly added customer.</p>
<p>Go doggy. The stopwatch starts as soon as someone gets added to the back of the line.</p>
<p>By the way, Mongrel won&#8217;t call <span style="font-family:Courier New;">request_begins</span> unless you tell it to. Here&#8217;s how you tell it to. Put this inside your subclass of <tt>HttpHandler</tt>:</p>
<pre class="brush: ruby;">
  def initialize(options={})
    @request_notify = true
  end
</pre>
<p>Cool. I can create a new <tt>BenchmarkFilter</tt> class a subclass of <tt>HttpHandler</tt>. I check the time in its <span style="font-family:Courier New;">request_begins</span> method&#8211;which gets called before any of the <span style="font-family:Courier New;">process</span> methods (including the RailsHandler&#8217;s one)&#8211;and check the time again in the <span style="font-family:Courier New;">process</span> method for my handler. Mine will get called after the Rails one if I install it at the end.</p>
<pre class="brush: ruby;">
class BenchmarkFilter &lt; HttpHandler
  def request_begins(params)
    # stuff goes here
  end

  def process(request, response)
    # and here
  end
end
</pre>
<p>Technically my filter won&#8217;t be called quite early enough because some other filters might be called first, and some other &#8220;process&#8221; methods might be called later. But I&#8217;m not going to stress over that.</p>
<h4>About those nasty instance variables</h4>
<p>The natural thing to do is store the start time in an @instance variable or maybe a @@class variable but I discovered this doesn&#8217;t work well in <span style="font-family:Courier New;">HttpHandler</span>s. For performance reasons Mongrel only creates a single instance of your <span style="font-family:Courier New;">HttpHandler</span> subclass instead of creating a new instance for each request. So using an instance variable is the same as using a class variable. Not only that but remember I said Mongrel is multi-threaded? That means your one <span style="font-family:Courier New;">HttpHandler</span> instance will be called simultanously on lots o&#8217; threads. Start reading and writing instance variables and you&#8217;re asking for a quick trip to the happy laughy farm.</p>
<p>(The @request_notify variable above is ok because we set it once during initialization&#8211;before all the thread craziness starts&#8211;and never change it.)</p>
<p>I also noticed in my testing that sometimes the <span style="font-family:Courier New;">request_begins</span> methods were getting called several times in a row before the <span style="font-family:Courier New;">process</span> methods for the same requests. Again that&#8217;s because it&#8217;s multi-threaded. But just think how it messes with your instance variables. Even if you guard the reads and writes with a Mutex, your start times would get all mixed up because you&#8217;re keeping track of a bunch of simultanous start times in a single variable.</p>
<p>When Mongrel calls <span style="font-family:Courier New;">request_begins</span> the only parameter it passes in is the request parameters. It doesn&#8217;t even pass the request because the request hasn&#8217;t finished initializing yet. I needed a way to associate the start time with the request and pull it out later so I could see how much time elapsed. Since the parameters passed to <span style="font-family:Courier New;">request_begins</span> are a reference to the request&#8217;s @params variable, any changes made to the parameters will be carried along with the request. So here&#8217;s what I did:</p>
<pre class="brush: ruby;">
  # Define a const for performance
  HANDLER_START_TIME = &quot;X-Handler-Start-Time&quot;.freeze

  def request_begins(params)
    params[HANDLER_START_TIME] = Time.now
  end
</pre>
<p>This code adds a custom key to the parameters hash, and in the value it stores the start time. As the comment mentions, I froze the name of the handler to get slightly better performance. I stole that trick from the Mongrel source code.</p>
<p>Later on, when my <span style="font-family:Courier New;">process</span> method is called with the request as one of the parameters, I can pull the start time out of request.params:</p>
<pre class="brush: ruby;">
  def process(request, response)
    elapsed_time = Time.now -
      request.params[HANDLER_START_TIME]
    # I'll add more in a sec
  end
</pre>
<h4>You put the time in the coconut</h4>
<p>The next question: how do I put the time in the content of a page? The page has already been rendered by the time my handler gets called, so I can&#8217;t set an @elapsed_time variable and render it in my view.</p>
<p>Here&#8217;s the approach I took: in my views I output a string of characters that the <span style="font-family:Courier New;">BenchmarkFilter</span> looks for. If it finds those characters it replace them with the elapsed time. If not, it does nothing.</p>
<p>I wanted it also to have no effect at all if it&#8217;s running <em>without </em>the <span style="font-family:Courier New;">BenchmarkFilter</span> handler. Let me rephrase that with lots of negatives for clarity: I didn&#8217;t want it not to have no effect if it didn&#8217;t run without having no <span style="font-family:Courier New;">BenchmarkFilter</span> handler.</p>
<p>My first idea was to create a partial file called <tt>_response_time.html.erb</tt> in a &#8220;shared&#8221; folder. The partial&#8217;s contents are:</p>
<pre class="brush: xml;">&lt;span id=&quot;response_time&quot;&gt;&lt;span&gt;</pre>
<p>In the handler I look for this in the response string and replace it with something like:</p>
<pre class="brush: xml;">&lt;span id=&quot;response_time&quot;&gt;(0.15 seconds)&lt;span&gt;</pre>
<p>Wherever I want to show the response time in a page I do this:</p>
<pre class="brush: ruby;">&lt;%= render :partial =&gt; &quot;shared/response_time&quot; %&gt;</pre>
<p>If you want to put the output in an HTML comment you can do that too, so it&#8217;s not shown on the page but can be inspected by looking at the source.</p>
<h4>Why no worky?</h4>
<p>I ran it and it seemed to work. Most of the time. But it was cranky. Sometimes it worked and sometimes not. I debugged it and noticed why. Do you know? See if you can guess from these hints:</p>
<p style="padding-left:30px;"><strong>Hint #1</strong></p>
<p style="padding-left:60px;">The HTTP headers had already been rendered. (By the <span style="font-family:Courier New;">RailsHandler</span>) before my handler is called. Think before you go to hint #2.</p>
<p style="padding-left:30px;"><strong>Hint #2</strong></p>
<p style="padding-left:60px;">One of the HTTP headers is called <tt>Content-Length</tt>.</p>
<p style="padding-left:30px;"><strong>Hint #3</strong></p>
<p style="padding-left:60px;">I was changing the length of the content without changing the <tt>Content-Length</tt> header.</p>
<p>As the voice in the &#8220;<a title="create a weblog in 15 minutes" href="http://media.rubyonrails.org/video/rails_take2_with_sound.mov">create a weblog in 15 minutes</a>&#8221; video would say: &#8220;wup!&#8221;</p>
<h4>Kevin Spacey * 15</h4>
<p>I started down the path of trying to fix the <span style="font-family:Courier New;">Content-Length</span> header on the fly but that got frustrating so I tried something easier: change my partial so it outputs <em>exactly the same number of characters</em> whether the <span style="font-family:Courier New;">BenchmarkFilter</span> class replaces it or not.</p>
<p>I decided to format my output like this:</p>
<pre>  (0.15 seconds)</pre>
<p>That takes 14 characters. Add another one in case it&#8217;s 10.00 seconds or more (yikes) to make 15. So I changed the span in the partial to have 15 spaces in it:</p>
<pre class="brush: xml;">  &lt;span id=&quot;response_time&quot;&gt;               &lt;/span&gt;</pre>
<p>Then I wrote the <span style="font-family:Courier New;">BenchmarkFilter</span> code so it <em>always </em>uses 15 characters. If it&#8217;s &lt;9.99 seconds I insert an extra space between the number and the word &#8220;seconds.&#8221; The browser eats that space anyway so it looks fine. And if it&#8217;s &gt;99.99 seconds, God forbid, I just output &#8220;<tt>(&gt;100  secs)</tt>&#8221; (again there&#8217;s an extra space in there to make it 15 chars), which looks like &#8220;(&gt;100 secs)&#8221; in the page.</p>
<h4>Handling RJS responses</h4>
<p>I decided I also wanted to update the response time partial when executing an RJS response. Here&#8217;s how the RJS looks:</p>
<pre class="brush: ruby;">page.replace &quot;response_time&quot;,
  '&lt;span id=&quot;response_time&quot;&gt;               &lt;/span&gt;'</pre>
<p>(This works but I&#8217;m not happy with it. I shouldn&#8217;t repeat the special string. I really ought to move this to a constant in the application helper.)</p>
<p>With an RJS the HTTP Handler sees JavaScript, not HTML, in the response. So instead of:</p>
<pre class="brush: xml;">&lt;span id=&quot;response_time&quot;&gt;               &lt;/span&gt;</pre>
<p>the output has all the special characters quoted, so the handler has to search for:</p>
<pre class="brush: xml;">\74span id=\\&quot;response_time\\&quot;\76               \74/span\76</pre>
<p>I also noticed that on newer versions of Rails, at least on my friend&#8217;s Mac, the response was in Unicode:</p>
<pre class="brush: xml;">\\u003Cspan id=\\&quot;response_time\\&quot;\\u003E               \\u003C/span\\u003E</pre>
<p>Anyway, if you want to see the hairy details you can look at the code.</p>
<h4>Installing the handler</h4>
<p>If you want to run Mongrel and tell it to execute a particular Ruby file at startup, one way is to use <tt>mongrel_rails</tt> with the -S option:</p>
<pre>mongrel_rails start -S lib/http_handlers/benchmark_filter.rb</pre>
<p>(I decided to put the handler file in lib/http_handlers).</p>
<p>At the end of the file, after closing out the class, you have to call the &#8220;uri&#8221; function to tell Mongrel to install the handler:</p>
<pre class="brush: ruby;">
# This calls Mongrel::Configurator::uri.  The first
# argument is a prefix.  Passing &quot;/&quot; means we want
# this handler to be executed for all requests.
uri &quot;/&quot;, :handler =&gt; BenchmarkFilter.new
</pre>
<h4>How it looks</h4>
<p>So you want to see what the output looks like? Here&#8217;s a picture:</p>
<p><a href="http://bmorearty.files.wordpress.com/2008/05/response-time.png"></a></p>
<p><a href="http://bmorearty.files.wordpress.com/2008/05/response-time-2.png"><img class="alignnone size-full wp-image-17" src="http://bmorearty.files.wordpress.com/2008/05/response-time-2.png?w=331&#038;h=134" alt="" width="331" height="134" /></a></p>
<p>Ta-da!</p>
<p>Obviously this won&#8217;t work with other servers than Mongrel, so if you want to support any HTTP server you&#8217;ll have to figure out another technique or use an around_filter and lose the waiting-in-the-queue time in the output.</p>
<p>And it won&#8217;t work with static pages that you cache in something like nginx.</p>
<p>You can <a title="download the code here" href="http://www.morearty.org/blogstuff/benchmark_filter.zip">download the code here</a>. Feel free to customize it. But remember: don&#8217;t change the string length when doing the substitution.</p>
<h4>4/11/09 Update: Rack</h4>
<p>Now that <a href="http://rack.rubyforge.org/">Rack</a> is on the scene, it wouldn&#8217;t be too hard to rewrite this thing to work with any web server, including Phusion Passenger.</p>
<p>But I haven&#8217;t rewritten it. If you feel like rewriting it, go for it&#8211;and then post a comment below so people can find it.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bmorearty.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bmorearty.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=9&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2008/05/21/how-to-show-response-time-in-a-rails-page-with-mongrel/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
<enclosure url="http://media.rubyonrails.org/video/rails_take2_with_sound.mov" length="54364199" type="video/quicktime" />
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>

		<media:content url="http://bmorearty.files.wordpress.com/2008/04/google-render-time.png" medium="image" />

		<media:content url="http://bmorearty.files.wordpress.com/2008/05/response-time-2.png" medium="image" />
	</item>
		<item>
		<title>What is your Zombie Escape Plan?</title>
		<link>http://bmorearty.wordpress.com/2008/04/16/what-is-your-zombie-escape-plan/</link>
		<comments>http://bmorearty.wordpress.com/2008/04/16/what-is-your-zombie-escape-plan/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 05:36:36 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Funny]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=8</guid>
		<description><![CDATA[How I learned that every teenage boy today has a Zombie Escape Plan. And why it's useful to know how to dance in case zombies attack.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=8&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Ok, so I was talking to my cool niece last month and she told me something that just cracked me up.</p>
<p>Are you ready?</p>
<p>Here goes:</p>
<blockquote><p><strong>Every teenage boy has a Zombie Escape Plan.</strong></p></blockquote>
<p>That&#8217;s what my niece told me. She was serious. And she thought it was just as weird as I do. (She doesn&#8217;t have one.)</p>
<p>Here&#8217;s how she found out about it. One day she was listening as two male friends of hers were comparing zombie escape plans. This was new to her. &#8220;Does every guy have a zombie escape plan?&#8221; she asked them.</p>
<p>&#8220;Well duh,&#8221; they both said, dead serious.</p>
<p>So she ran an <a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&amp;location=http%3A%2F%2Fwww.amazon.com%2FHow-Lie-Statistics-Darrell-Huff%2Fdp%2F0393310728%3Fie%3DUTF8%26s%3Dbooks%26qid%3D1208323988%26sr%3D8-1&amp;tag=httpwwwmorear-20&amp;linkCode=ur2&amp;camp=1789&amp;creative=9325">unscientific survey</a><img style="border:none !important;margin:0 !important;" src="http://www.assoc-amazon.com/e/ir?t=httpwwwmorear-20&amp;l=ur2&amp;o=1" border="0" alt="" width="1" height="1" /> of her teenage male friends to find out if it was true. And guess what.</p>
<p><em>It was.</em></p>
<p>Every boy she asked said yes, naturally he has a zombie escape plan.</p>
<p>By now I was busting up. I told her well, at least I have a fire escape ladder in my 2-story house. I could use that as my zombie escape plan too. Her dad (my brother-in-law) said no: that&#8217;s lame. A fire escape plan <em>does not serve </em>as a zombie escape plan. As evidence he pointed to his own zombie escape plan: he will dance a jig. Because everyone knows a zombie cannot resist dancing a jig if he sees someone else doing it. But it doesn&#8217;t make a very good fire escape plan.</p>
<p>My niece said her dad was right. One boy in her survey said his zombie escape plan involved climbing up on the roof, which is usually not a good idea in a fire. At this point her younger brother, who&#8217;s also a teenager, piped up and said that after all, his zombie escape plan is to use a flame thrower. And that never makes a very good fire escape plan.</p>
<p>When I got home I googled it and found that there is even a web site dedicated just to this (side note: what did we <em>ever do</em> before the web?): <a href="http://www.zombieescapeplan.com">http://www.zombieescapeplan.com</a>. Except it&#8217;s made by a girl. So I guess at least that&#8217;s good because when the zombies attack some of the girls will be prepared.</p>
<p>I need a good zombie escape plan. What&#8217;s yours? Please comment below so I can get some good ideas.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bmorearty.wordpress.com/8/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bmorearty.wordpress.com/8/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/8/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=8&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2008/04/16/what-is-your-zombie-escape-plan/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>

		<media:content url="http://www.assoc-amazon.com/e/ir?t=httpwwwmorear-20&#38;l=ur2&#38;o=1" medium="image" />
	</item>
		<item>
		<title>How to write case (switch) statements in Ruby</title>
		<link>http://bmorearty.wordpress.com/2008/04/15/how-to-write-case-switch-statements-in-ruby/</link>
		<comments>http://bmorearty.wordpress.com/2008/04/15/how-to-write-case-switch-statements-in-ruby/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 05:41:59 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=5</guid>
		<description><![CDATA[If you&#8217;re like me, when you started coding in Ruby last year you found the &#8220;case&#8221; statement intriguing. After years of writing in C++ and C# it was hard for you to remember Ruby&#8217;s case syntax because it can do so much more than switch statements in those languages.
So you wrote these notes to yourself [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=5&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you&#8217;re like me, when you started coding in Ruby last year you found the &#8220;case&#8221; statement intriguing. After years of writing in C++ and C# it was hard for you to remember Ruby&#8217;s case syntax because it can do so much more than switch statements in those languages.</p>
<p>So you wrote these notes to yourself as you discovered its capabilities. Except you&#8217;re not <em>that</em> much like me so you didn&#8217;t. But I did. I hope you find them useful.</p>
<pre class="brush: ruby;">
switch/case syntaxes
(remember: Ruby uses &quot;case&quot; and &quot;when&quot;
where others use &quot;switch&quot; and &quot;case&quot;):

# Basically if/elsif/else (notice there's nothing
# after the word &quot;case&quot;):
[variable = ] case
when bool_condition 
 statements
when bool_condition
 statements
else # the else clause is optional
 statements
end
# If you assigned 'variable =' before the case,
# the variable now has the value of the
# last-executed statement--or nil if there was
# no match.  variable=if/elsif/else does this too.

# It's common for the &quot;else&quot; to be a 1-line
# statement even when the cases are multi-line:
[variable = ] case
when bool_condition 
 statements
when bool_condition
 statements
else statement
end

# Case on an expression:
[variable = ] case expression
when nil
 statements execute if the expr was nil
when Type1 [ , Type2 ] # e.g. Symbol, String
 statements execute if the expr
  resulted in Type1 or Type2 etc.
when value1 [ , value2 ]
 statements execute if the expr
 equals value1 or value2 etc.
when /regexp1/ [ , /regexp2/ ]
 statements execute if the expr
 matches regexp1 or regexp 2 etc.
when min1..max1 [ , min2..max2 ]
 statements execute if the expr is in the range
 from min1 to max1 or min2 to max2 etc.
 (use 3 dots min...max to go up to max-1)
else
 statements
end

# When using case on an expression you can mix &amp;
# match different types of expressions. E.g.,
[variable =] case expression
when nil, /regexp/, Type
 statements execute when the expression
 is nil or matches the regexp or results in Type
when min..max, /regexp2/
 statements execute when the expression is
 in the range from min to max or matches regexp2
end

# You can combine matches into an array and
# precede it with an asterisk. This is useful when
# the matches are defined at runtime, not when
# writing the code. The array can contain a
# combination of match expressions
# (strings, nil, regexp, ranges, etc.)
[variable =] case expression
when *array_1
 statements execute when the expression matches one
 of the elements of array_1
when *array_2
 statements execute when the expression matches one
 of the elements of array_2
end

# Compact syntax with 'then':
[variable =] case expression
when something then statement
when something then statement
else statement
end

# Compact syntax with semicolons:
[variable =] case expression
when something; statement
when something; statement
else statement # no semicolon required
end

# Compact syntax with colons
# (no longer supported in Ruby 1.9)
[variable =] case expression
when something: statement
when something: statement
else statement # no colon required
end

# 1-line syntax:
[variable = ] case expr when {Type|value}
 statements
end

# Formatting: it's common to indent the &quot;when&quot;
# clauses and it's also common not to:
case 
  when 
  when
  else
end

case
when
when
else
end
</pre>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bmorearty.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bmorearty.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=5&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2008/04/15/how-to-write-case-switch-statements-in-ruby/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
		<item>
		<title>hello, world</title>
		<link>http://bmorearty.wordpress.com/2008/04/13/hello-world/</link>
		<comments>http://bmorearty.wordpress.com/2008/04/13/hello-world/#comments</comments>
		<pubDate>Sun, 13 Apr 2008 19:16:51 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I am Brian Morearty. Welcome to my blog.
I&#8217;m a software engineer living with my wife and three kids in the San Francisco Bay Area.
I plan to blog about stuff like software development, things that strike me as funny, etc. The technology that currently has my interest is Ruby on Rails and Flex but that may [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=1&subd=bmorearty&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I am Brian Morearty. Welcome to my blog.</p>
<p>I&#8217;m a software engineer living with my wife and three kids in the San Francisco Bay Area.</p>
<p>I plan to blog about stuff like software development, things that strike me as funny, etc. The technology that currently has my interest is Ruby on Rails and Flex but that may change over time. For most of my career in software I&#8217;ve been working on Windows, and I&#8217;m also a fan of most Microsoft developer technology (WPF, ASP.NET, and so on.)</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/bmorearty.wordpress.com/1/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/bmorearty.wordpress.com/1/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/1/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=bmorearty.wordpress.com&blog=3470316&post=1&subd=bmorearty&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://bmorearty.wordpress.com/2008/04/13/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/f6916771e4e27322d68e436f229c851c?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Brian</media:title>
		</media:content>
	</item>
	</channel>
</rss>