<?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://ilikestuffblog.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://ilikestuffblog.com</link>
	<description>Brian Morearty's Blog</description>
	<lastBuildDate>Tue, 24 Jan 2012 17:23:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='ilikestuffblog.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>I like stuff.</title>
		<link>http://ilikestuffblog.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://ilikestuffblog.com/osd.xml" title="I like stuff." />
	<atom:link rel='hub' href='http://ilikestuffblog.com/?pushpress=hub'/>
		<item>
		<title>19-Minute Video: CoffeeScript for Rubyists</title>
		<link>http://ilikestuffblog.com/2012/01/11/19-minute-video-coffeescript-for-rubyists/</link>
		<comments>http://ilikestuffblog.com/2012/01/11/19-minute-video-coffeescript-for-rubyists/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 04:44:16 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Teaching Programming]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=585</guid>
		<description><![CDATA[If you&#8217;re a Ruby programmer and want a quick little intro to CoffeeScript so you can decide whether you might want to use it, check out the 19-minute talk I gave last week at a really fun Code Social meetup at RocketSpace in San Francisco. The talk was &#8220;CoffeeScript for Rubyists.&#8221; Abstract Is CoffeeScript really so [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=585&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;re a Ruby programmer and want a quick little intro to CoffeeScript so you can decide whether you might want to use it, check out the 19-minute talk I gave last week at a really fun Code Social meetup at RocketSpace in San Francisco. The talk was &#8220;CoffeeScript for Rubyists.&#8221;</p>
<h3>Abstract</h3>
<p style="padding-left:30px;">Is CoffeeScript really so great? Why use it instead of good ol&#8217; JavaScript? Which of my favorite syntax goodies does it steal from Ruby? It looks Pythony with all that significant whitespace. How can I use it in my pre-3.1 Rails project? How do I convert my legacy JavaScript? Why is Internet Explorer no good at exploring the Internet? Brian Morearty answers most of these questions. He&#8217;s a Ruby aficionado who has used CoffeeScript for his client-side coding for a few months. In this talk he does a quick demo of how to install CoffeeScript, convert your JavaScript to CoffeeScript, and include it in a pre-Rails-3.1 application. But most of the talk is on details of the language, including stuff it stole from Ruby that make it just dang fun for a Rubyist to program in CoffeeScript. And he even covers one thing that is *gasp* better than Ruby.</p>
<div>
<h3>
Slides</h3>
<p>Here are the <a title="CoffeeScript Slides" href="http://bmorearty.github.com/coffeescript-talk/">slides for this CoffeeScript talk</a>.</p>
</div>
<h3>Video</h3>
<div>And here&#8217;s the video:</div>
<div></div>
<div><span style="text-align:center; display: block;"><a href="http://ilikestuffblog.com/2012/01/11/19-minute-video-coffeescript-for-rubyists/"><img src="http://img.youtube.com/vi/EOpG-yqMfHE/2.jpg" alt="" /></a></span></div>
<div></div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/585/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/585/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/585/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=585&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2012/01/11/19-minute-video-coffeescript-for-rubyists/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>How to Free Up Inactive (Blue) Memory in Mac OS X</title>
		<link>http://ilikestuffblog.com/2011/11/09/how-to-clear-inactive-blue-memory-in-mac-os-x/</link>
		<comments>http://ilikestuffblog.com/2011/11/09/how-to-clear-inactive-blue-memory-in-mac-os-x/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 17:48:06 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=561</guid>
		<description><![CDATA[Want to turn Activity Monitor&#8217;s &#8220;blue&#8221; (inactive) memory to &#8220;green&#8221; (free) on your Mac without closing any programs? Run Terminal and type:  $ purge My memory went from  to  the last time I did this. Not too shabby. (Why did it also clear up some Active Memory? I have no idea.) That&#8217;s all you have to do. It [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=561&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Want to turn Activity Monitor&#8217;s &#8220;blue&#8221; (inactive) memory to &#8220;green&#8221; (free) on your Mac without closing any programs?</p>
<p>Run Terminal and type:</p>
<pre>  $ purge</pre>
<p>My memory went from <a href="http://bmorearty.files.wordpress.com/2011/11/before.png"><img class="size-full wp-image-562 alignnone" title="out of memory" src="http://bmorearty.files.wordpress.com/2011/11/before.png?w=450" alt=""   /></a> to <a href="http://bmorearty.files.wordpress.com/2011/11/after1.png"><img class="alignnone size-full wp-image-580" title="lots of memory" src="http://bmorearty.files.wordpress.com/2011/11/after1.png?w=450" alt=""   /></a> the last time I did this. Not too shabby. (Why did it also clear up some Active Memory? I have no idea.)</p>
<p>That&#8217;s all you have to do. It can take up to a minute. While purge is running your system will be slow. After that, with all that free memory, it&#8217;ll be zippier than before.</p>
<p>Don&#8217;t listen to all the <a href="http://forums.macrumors.com/archive/index.php/t-142719.html">remarkably obnoxious fanboys</a> or official Apple support pages telling you just to leave Inactive Memory alone because it will be freed up quickly if it is needed, or that the system knows better than you do when to free memory. Trust your experience. In my experience <strong>it will not and it does not. </strong></p>
<p>Here is the purge man page:</p>
<pre>PURGE(8)                  BSD System Manager's Manual                 PURGE(8)

NAME
     purge -- force disk cache to be purged (flushed and emptied)

SYNOPSIS
     purge

DESCRIPTION
     Purge can be used to approximate initial boot conditions with a cold disk buffer
     cache for performance analysis. It does not affect anonymous memory that has been
     allocated through malloc, vm_allocate, etc.

SEE ALSO
     sync(8), malloc(3)</pre>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/561/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/561/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/561/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/561/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/561/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/561/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/561/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/561/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/561/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/561/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/561/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/561/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/561/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/561/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=561&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/11/09/how-to-clear-inactive-blue-memory-in-mac-os-x/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>

		<media:content url="http://bmorearty.files.wordpress.com/2011/11/before.png" medium="image">
			<media:title type="html">out of memory</media:title>
		</media:content>

		<media:content url="http://bmorearty.files.wordpress.com/2011/11/after1.png" medium="image">
			<media:title type="html">lots of memory</media:title>
		</media:content>
	</item>
		<item>
		<title>Use Spin for Faster Test Iterations</title>
		<link>http://ilikestuffblog.com/2011/11/04/use-spin-for-faster-test-iterations/</link>
		<comments>http://ilikestuffblog.com/2011/11/04/use-spin-for-faster-test-iterations/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 19:10:08 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=548</guid>
		<description><![CDATA[Do you ever re-run the same Rails test file over &#38; over while working on a feature and trying to &#8220;make it green?&#8221; Change the code, run the test, change the code, run the test, etc. (I&#8217;m talking about when you want to re-run a specific test, not using guard to autodetect which tests to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=548&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://bmorearty.files.wordpress.com/2011/11/railstests.jpg"><img class="alignright size-medium wp-image-558" title="RAILS TESTS - Y U NO EVEN START YET?!" src="http://bmorearty.files.wordpress.com/2011/11/railstests.jpg?w=300&#038;h=225" alt="RAILS TESTS - Y U NO EVEN START YET?!" width="300" height="225" /></a></p>
<p>Do you ever re-run the same Rails test file over &amp; over while working on a feature and trying to &#8220;make it green?&#8221; Change the code, run the test, change the code, run the test, etc. (I&#8217;m talking about when you want to re-run a specific test, not using <strong>guard</strong> to autodetect which tests to run.)</p>
<p>When you do that you have to wait a long time for the Rails environment and your app&#8217;s initializers to load. You pay this price every time you re-run the test—even if you&#8217;re not changing your initializers. I get ants in my pants sitting around waiting for the environment to load.</p>
<p>I just learned about a new gem that doesn&#8217;t require any changes to your tests and that speeds up this test-code-test-code cycle by only loading your environment once: it&#8217;s called <strong>spin</strong>.</p>
<p style="padding-left:30px;"><a href="https://github.com/jstorimer/spin">https://github.com/jstorimer/spin</a></p>
<p>Basically you do this:</p>
<ul>
<li>In one terminal window type <strong>spin serve</strong>. This launches the spin server, which waits for commands over a socket.</li>
<li>In another terminal, when you want to run the tests in a single file, type <strong>spin push path/to/testfile.rb</strong></li>
<li>You can push multiple filenames at once if you like.</li>
<li>One limitation: it does not let you use the <strong>:linenum</strong> syntax that rspec uses to run just one test in a file.</li>
</ul>
<p>That&#8217;s it. I tried it on a test file that takes 8 seconds (after everything has been loaded). Total time to load and run this file went down from 26 seconds to 13 seconds when I used spin.</p>
<p>I looked at the source. It&#8217;s short and simple. Here&#8217;s how it works:</p>
<ul>
<li><strong>spin serve</strong> preloads your app&#8217;s <strong>config/application.rb</strong>.</li>
<li>Then it waits for commands on a socket.</li>
<li>When a command comes in it forks a new process and runs tests in the fork. The fork doesn&#8217;t have to reload the Rails environment or initializers because they&#8217;re already loaded.</li>
<li>When done, the fork just exits and spin is ready for a new command.</li>
</ul>
<p>Remember that if you do change your initializers or anything else that is loaded by application.rb you should restart the spin server. Another time you may want to restart it: after checking out a different branch in git.</p>
<p>Safe and easy. Faster tests. What could be better?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/548/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/548/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/548/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/548/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/548/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/548/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/548/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/548/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/548/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/548/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/548/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/548/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/548/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/548/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=548&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/11/04/use-spin-for-faster-test-iterations/feed/</wfw:commentRss>
		<slash:comments>6</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/2011/11/railstests.jpg?w=300" medium="image">
			<media:title type="html">RAILS TESTS - Y U NO EVEN START YET?!</media:title>
		</media:content>
	</item>
		<item>
		<title>Dear GitHub: Please Improve Your Notifications</title>
		<link>http://ilikestuffblog.com/2011/07/14/github-notifications-suck/</link>
		<comments>http://ilikestuffblog.com/2011/07/14/github-notifications-suck/#comments</comments>
		<pubDate>Fri, 15 Jul 2011 01:00:22 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=515</guid>
		<description><![CDATA[An Open Letter to GitHub Dear GitHub, Hi guys! Guess what: GitHub&#8217;s great. Yeah, you know that. But hey: could you please fix GitHub notifications? They seriously suck. No, really, I mean it. They&#8217;re the worst. Sorry, I don&#8217;t mean to hurt your feelings. I know a human being designed the notification system. GitHub notifications [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=515&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h3>An Open Letter to GitHub</h3>
<p>Dear GitHub,</p>
<p>Hi guys!</p>
<p>Guess what: GitHub&#8217;s great. Yeah, you know that.</p>
<p>But hey: could you please fix GitHub notifications? They seriously suck. No, really, I mean it. They&#8217;re the worst. Sorry, I don&#8217;t mean to hurt your feelings. I know a human being designed the notification system.</p>
<p>GitHub notifications are a productivity sink. Despite having fifteen checkboxes for customization in the Notification Center, I still can&#8217;t make them work in a way that helps me. Don&#8217;t get me wrong, I am not asking you to fix it by adding more checkboxes to the list. I am asking for an overhaul of how the notification system works. Below I will try to clearly lay out the problems I see and what I would like the system to do instead. The overall goal is to change notifications from a productivity sink to a productivity boon.<span id="more-515"></span></p>
<p>First I will describe myself and how I use GitHub, to help you decide if I am the kind of customer you want to serve. I understand that an important part of running a successful business is that you can&#8217;t be all things to all people. So here&#8217;s me:</p>
<ul>
<li>I am an independent software consultant doing Ruby and JavaScript programming. I have a long-term gig at a company that has 81 private repos on GitHub. I am part of their GitHub Organization so I have access to all the repos. Combined, these repos get a ton of activity&#8211;there are probably about thirty developers working on them full-time.</li>
<li>The company I work at uses GitHub for code reviews, too. People sometimes post in-line comments in the code reviews.</li>
<li>I have written some open source software. Not a ton, but a few little things. I host them on GitHub. This has worked out well for me. All Ruby and JavaScript.</li>
<li>I am also the maintainer of an open source software project that someone else wrote in Python and posted to a bulletin board. It&#8217;s for <a href="https://github.com/BMorearty/exportiphoto">exporting iPhoto pictures to a folder structure</a>. I wanted to make some changes for myself but let other people make changes too, so I posted it to my GitHub account. It has become popular enough that I get a pull request once every few months. I try to respond to them and pull them.</li>
<li>I participate in the occasional issue discussion on the Rails repo and a few other repos.</li>
<li>When I&#8217;m at work I want to be notified about events related to work but not be distracted by the open source projects I work on (except during the occasional break from work).</li>
<li>When I&#8217;m at home I want to be notified about events related to the open source projects I work on but not be distracted by work-related events (except when I occasionally check to see if anything&#8217;s going on while I&#8217;m out).</li>
</ul>
<p>Ok, so that&#8217;s me. I would characterize my use of GitHub as heavy&#8211;every hour of every workday&#8211;in my professional work and light-to-medium in my open source work.</p>
<h3>So How Can GitHub Notifications be Improved?</h3>
<p>Well, these things would help:</p>
<ul>
<li>In the Notification Center I want to set up preferences at two levels: one for projects I&#8217;m Actively Involved in and another for projects I Occasionally Participate in. For example if I submit a pull request for <em>any </em>repo, whether I&#8217;m Actively Involved or not, I want to be notified of comments on my pull request. But I only want to be notified of pull requests from other people on the projects I&#8217;m Actively Involved in.</li>
<li>Every new repo someone else creates is assigned the Occasionally Participate level for me. Every new repo I create is defaulted to the Actively Involved level for me. These statements are true whether the repo is Public or in an Organization I belong to.</li>
<li>For any repo I have access to, I can change whether I am Actively Involved or Occasionally Participate.</li>
<li>These levels will be especially helpful for the work I do in an Organization. I can stay updated on events in the two or three repos I use daily but prevent spam on repos in my organization but that I never touch. I&#8217;d like to see pull requests for my active repos but not for all repos in the org.</li>
<li>I want the dark gray Unread Notifications icon at the top of every page to reflect the current Context (personal, organization #1, organization #2). Hovering over it would quickly show the notification count for each context. The counts in that tooltip should be clickable to go to the Notification Center for that context.</li>
<li>I want the Notifications page to show me only the notifications for the currently selected Context. (Myself or whatever Organization context I&#8217;m currently in.) And it should be easy to switch to a different Context from that page.</li>
<li>I want to specify one email address for my own account&#8217;s notifications, another email for my organization #1 notifications, another for my organization #2 notifications, etc. It&#8217;s really frustrating that I need dozens of rules in my personal GMail account to forward GitHub notifications to the correct work email accounts.</li>
<li>I want the notification emails to include the other user&#8217;s full name in the From field. It&#8217;s ok to still include the GitHub username but please also include their real name, just like you do on the user&#8217;s home page. E.g., my email client should tell me the email is &#8220;From: defunkt (Chris Wanstrath).&#8221;</li>
<li>I want the notification emails to provide more context about exactly what happened. The emails are horrible! It&#8217;s impossible to tell from the Subject line or even the Body what <em>happened</em>. What am I being notified about, exactly? Oh, somebody filed a pull request? For Pete&#8217;s sake would it hurt to tell me that without forcing me to look at the URL at the end of the email? Right now the subject line is the title of the pull request, the body is the body of the pull request, and that&#8217;s it. I&#8217;m expecting the words &#8220;Pull request&#8221; (or whatever the notification is about) in the email subject line AND at the top of the body.</li>
<li>And don&#8217;t even get me started about emails telling me about comments on commits. The emails say <em>nothing </em>about the code being commented on or who made the commit. The <em>subject </em>line should mention if it&#8217;s &#8220;on your commit&#8221; or &#8220;on defunkt&#8217;s (Chris Wanstrath&#8217;s) commit.&#8221; Notice I used the username and real name. And I want to see this in the body:</li>
<ul>
<li>The surrounding code that&#8217;s being commented on.</li>
<li>The comment.</li>
<li>The line where the comment was made.</li>
<li>Who made the commit! Was it me? Sheesh. (Username and real name.)</li>
<li>Who made the comment. (Username and real name.)</li>
</ul>
<li>I want email notifications to include a link at the bottom: &#8220;Delete this from the Notifications page.&#8221; I want to click that link from my email program and have it kick off a URL that deletes the notification off GitHub so I don&#8217;t see it again the next time I go to the Notifications page.</li>
<li>I want every notification&#8211;in email and on the Notifications page&#8211;to tell me why I was notified. E.g., &#8220;You received this notification because you have turned on <span style="text-decoration:underline;">Comments on commits in MegaCorp repositories</span>.&#8221; The link takes you to the page where you can turn it off. Doing this on the Notifications page will be tricky because you don&#8217;t want to clutter up the page too much. Just show me a tiny question mark on the row so I can hover over it and see the explanation in a tooltip.</li>
<li>I want the Notifications page to have a link right at the top that says &#8220;Edit Notification Settings&#8221; and takes me to the Notification Center tab of the Accounts page.</li>
<li>If I delete all the notifications one by one on page 1 of the Notifications page, it should not look like I have emptied out my notification list. It should be clear that there are more. How about an AJAX UI that pulls in the first row from the next page and adds it to the end of this page each time I delete one?</li>
<li>Related: if I delete all the notifications on p. 1 and click Next to go to the next page of notifications, it should not skip past the <em>new </em>first page of notifications. I.e. it should show me the notifications after the last one I deleted. This won&#8217;t even be necessary if you do the AJAX UI I mentioned.</li>
<li>When I am cleaning out my notifications in the Notifications page I want to be able to see at a glance&#8211;without drilling down on the notification&#8211;what each notification is about. I should see all of the following. Some of your notifications do include all of them but some don&#8217;t. The ones that don&#8217;t are very frustrating. E.g., &#8220;So-and-so discussed a commit 3 hours ago.&#8221; Really? Thanks. <strong>In what repo?</strong> Come on. Are you really going to make me guess? And was it <strong>my </strong>commit or someone else&#8217;s?</li>
<ul>
<li>What repo was affected</li>
<li>Who took the action I&#8217;m being notified about (username, real name, and little avatar)</li>
<li>What the action was (commented on my commit, submitted a pull request, &#8230;)</li>
<li>When it happened</li>
<li>A one-liner about the event (the pull request subject, first line of the comment, etc.)</li>
<li>If it&#8217;s a pull request, what is its <em>current</em> status? (Open, Closed) In other words, did someone already pull it after it was added to my inbox?</li>
</ul>
<li>I want the Notification Center to let me turn off not just <em>email </em>notifications but also notifications in my Notifications page. I really don&#8217;t have time to care about things that happened in about 78 of the 81 repos my organization owns. And when my Notification icon is showing me big numbers of unread notifications, it&#8217;s the Little Boy Who Cried Wolf. I end up having to <em>ignore </em>the dang notification icon because so many of those notifications are irrelevant to me. And you know what that means: when a <em>real </em>big bad wolf comes into town, I will ignore the cries for help and the po&#8217; little boy will be eaten. (Or I might not respond to a notification I should have known about.)</li>
<li>A note on that last point: I know it would be confusing to have <em>two </em>checkboxes for each notification type (one for the Notification page and another for whether you want to get email). You can avoid Checkbox Overload with this simple fix:</li>
<ul>
<li>Keep the checkbox at the top titled &#8220;Receive email notifications (global setting).&#8221; This would control whether I get email notifications at all.</li>
<li>The event-specific checkboxes in the list should not be labeled &#8220;Email.&#8221; They should be labeled &#8220;Notify.&#8221; If I check a box, I want that notification in my Notification page&#8211;and by email if the box at the top was checked. If I don&#8217;t check the box, I don&#8217;t want either.</li>
</ul>
<li>I want to mark individual notifications as Read or Unread from the Notifications page.</li>
<li>You&#8217;ve been adding a lot of nice shortcut keys to GitHub pages lately. I want to navigate the Notifications page with keystrokes, a la GMail. j=down, k=up, o or Enter=open, U=mark as unread, I=mark as read, #=delete (or maybe y).</li>
</ul>
<div>
<p>Phew!</p>
<p>I know that&#8217;s a lot of stuff. But it sure would help. Really. It would help a lot. GitHub would be a much more useful tool, especially for people in Organizations. And look, I gave your product manager a big head start with this list.</p>
<p>If you want to start with something simple that gives you a lot of bang for the buck, please just fix the subject lines of the &#8220;discussed a commit&#8221; notifications on the Notifications page. Give us this:</p>
<blockquote><p><a href="https://github.com/defunkt">defunkt (Chris Wanstrath)</a> discussed a commit on <a href="http://github.com/">membername/reponame</a> 1 day ago</p></blockquote>
<p>instead of this:</p>
<blockquote><p><a href="https://github.com/defunkt">defunkt</a> discussed a commit 1 day ago</p></blockquote>
</div>
<div>
<p>See the two differences? I included the person&#8217;s real name and mentioned what repo is being discussed.</p>
<p>Thanks.</p>
</div>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/515/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/515/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/515/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=515&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/07/14/github-notifications-suck/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>Best Presentations of RailsConf 2011</title>
		<link>http://ilikestuffblog.com/2011/05/21/best-presentations-of-railsconf-2011/</link>
		<comments>http://ilikestuffblog.com/2011/05/21/best-presentations-of-railsconf-2011/#comments</comments>
		<pubDate>Sat, 21 May 2011 16:21:00 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=517</guid>
		<description><![CDATA[Hey all, Yesterday evening I got back from RailsConf 2011. It was a lot of fun and I saw a lot of really good presentations with good technical content, and some that were both useful and funny (double dream hands and Ke$ha). But I also missed some of the best talks. O&#8217;Reilly has posted some [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=517&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Hey all,</p>
<p>Yesterday evening I got back from RailsConf 2011. It was a lot of fun and I saw a lot of really good presentations with good technical content, and some that were both useful and funny (double dream hands and Ke$ha).</p>
<p>But I also missed some of the best talks. O&#8217;Reilly has posted some of the videos and is working on posting more.</p>
<p>But how to decide which ones to watch?</p>
<p>On the plane ride home I wrote a one-page site to answer that question. It scrapes the star ratings from O&#8217;Reilly (hope you guys don&#8217;t mind!) and shows the sessions with the highest-rated ones at the top. I didn&#8217;t have wifi so I had to guess what CSS selectors I should use to scrape the RailsConf site. Once I got home I fixed the selectors, polished it up, and pushed it to Heroku.</p>
<p>Here it is: the <a title="Best of RailsConf 2011" href="http://bestofrailsconf2011.heroku.com/">Best of RailsConf 2011</a>.</p>
<p>If you find problems, <a title="source code" href="https://github.com/BMorearty/bestofrailsconf2011">please fork and improve it</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/517/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/517/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/517/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=517&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/05/21/best-presentations-of-railsconf-2011/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>Hello, Entrepreneur. (And Consultant.)</title>
		<link>http://ilikestuffblog.com/2011/03/08/hello-entrepreneur-and-consultant/</link>
		<comments>http://ilikestuffblog.com/2011/03/08/hello-entrepreneur-and-consultant/#comments</comments>
		<pubDate>Wed, 09 Mar 2011 07:15:01 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=486</guid>
		<description><![CDATA[The last time I changed jobs it was the spring of 1999, in the glory days of the dot-com frenzy. I decided to leave my job at an enterprise software company that shall remain unnamed (but it starts with “O” and ends with “racle.”) Enterprise software was not where my heart was. I thought about [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=486&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The last time I changed jobs it was the spring of 1999, in the glory days of the dot-com frenzy. I decided to leave my job at an enterprise software company that shall remain unnamed (but it starts with “O” and ends with “racle.”) Enterprise software was not where my heart was. I thought about joining a startup and I talked to a bunch of them, but they all said the same thing when I asked about their business model: we’re not making any money but don’t worry, we’ve got millions of customers.</p>
<p><a href="http://bmorearty.files.wordpress.com/2011/03/bubble.png"><img class="alignright size-full wp-image-490" title="bubble" src="http://bmorearty.files.wordpress.com/2011/03/bubble.png?w=450" alt=""   /></a>I knew we were in a bubble. Don’t get me wrong—I’m no soothsayer and I couldn’t tell you exactly when the bubble would burst, but it was clear it would. So I joined Intuit, the only company I interviewed with that was actually making a profit.</p>
<p>It turned out to be a pretty good choice.</p>
<p>The nearly 12 years I worked at Intuit were amazing. The QuickBooks team warmly welcomed me. I worked with fantastic people. I became the tech lead for the UI Toolkit team. I worked on a lot of elegant little touches that make the user experience more delightful, like a better quickfill (autocomplete) control. I trained engineers on how to build great user interfaces. I stayed there til 2005 when I decided to try something new, but Intuit is such a great place to work that I just transferred to another group. I moved around a couple more times, always staying in the Small Business Division, and since 2008 I have been doing web development in Intuit’s Grow Your Business division. This is the group that makes Intuit Websites.</p>
<p>I recently decided the time has come again to change jobs. But this time is different. Instead of looking for a job as an employee somewhere else, I’ve decided to do something I’ve been thinking about for a number of years: <strong>I am becoming a software entrepreneur and consultant/trainer</strong>.</p>
<p>Both? Well, yeah—I’ll be spending 30 hours a week consulting and training (focusing on Ruby on Rails and JavaScript) and the remaining time starting my own business.</p>
<h3>My Startup</h3>
<p>During my “entrepreneur” time I am creating a website with tools and community for small real estate investors. I am an investor myself, having bought houses and condos in Southern California, Arizona, and even Melbourne, Australia. When I got started with investing I was willing to invest anywhere in the U.S., but I had one big question:</p>
<blockquote><p><strong>Which market should I invest in?</strong></p></blockquote>
<p>The answer depended on what was I looking for in a real estate investment. Some investors look for equity growth, others for cash flow. Some look for a market on an upswing, others for a market in a trough. Some look for job growth, some for immigration, some for vacancy rates, and on and on. The thing is, all this data is available for free from the U.S. Government but it’s really hard for a small real estate investor to find. And once they’ve found it, it’s also hard to collate it and get a quick answer to the simple question of which market to invest in. Real estate agents can be helpful but unless you happen to find one who specializes in finding investing opportunities around the country, they won’t really know what to recommend. In that case they’re likely just to tell you that their own market is a good one to invest in.</p>
<p>So a few years ago I started working on a web app to solve this problem and recruited my friend Ed to help out. Think of it as Kayak for small real estate investors: you give it your criteria, drag some sliders, check some boxes, and it shows you the results. Except instead of showing you flights it shows markets. It’s fast and easy and you don’t need to pore through thousands of lines of data from government reports. The web app does all that for you instantly.</p>
<p>Working on the app was fun and we got a lot done over several months but it was hard to find enough time for that when we also had full-time jobs and families we wanted to see. But now that I’m consulting 30 hours a week instead working 40 hours a week, that leaves me more time every day. So I’m working on the app for real estate investors again.</p>
<p>I’ll make an announcement here when it’s ready to try. Subscribe to my blog so you don’t miss it. (<a href="http://ilikestuffblog.com/">Go here</a> and click the Subscribe button in the right hand column.)</p>
<h3>My Consulting and Training Business</h3>
<p>To keep the lights on I am also doing Ruby on Rails consulting and training. I can make web apps work great on mobile phones and desktop browsers with a single code base, scale Rails apps, and a bunch more. See my <a title="About" href="http://ilikestuffblog.com/about/">About page</a> if you’d like more info on my services, and my <a title="Contact" href="http://ilikestuffblog.com/contact/">Contact page</a> if you want to contact me about work.</p>
<h3>I Like Stuff That’s Fun</h3>
<p>I’m already having a ton of fun and I’ve barely started. It’s great to be working with Ruby on Rails full-time, controlling my destiny, and creating my future. And I’m really enjoying my first consulting gig.</p>
<p>Stay tuned.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/486/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/486/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/486/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=486&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/03/08/hello-entrepreneur-and-consultant/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>

		<media:content url="http://bmorearty.files.wordpress.com/2011/03/bubble.png" medium="image">
			<media:title type="html">bubble</media:title>
		</media:content>
	</item>
		<item>
		<title>ActiveRecord Now Supports an Identity Map. Hooray!</title>
		<link>http://ilikestuffblog.com/2011/02/20/activerecord-now-supports-an-identity-map-hooray/</link>
		<comments>http://ilikestuffblog.com/2011/02/20/activerecord-now-supports-an-identity-map-hooray/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 00:27:33 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=468</guid>
		<description><![CDATA[I just read that support for an identity map has just been merged into ActiveRecord. This has been a long time coming and I&#8217;m really happy it&#8217;s here. Huge thanks to Emilio Tagua for doing this. In some of my projects an identity map would have saved a lot of ugliness. I&#8217;m going to start [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=468&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just read that <a href="http://miloops.com/post/3391477665/identity-map-and-active-record">support for an identity map has just been merged into ActiveRecord</a>. This has been a long time coming and I&#8217;m really happy it&#8217;s here. Huge thanks to Emilio Tagua for doing this.</p>
<p>In some of my projects an identity map would have saved a lot of ugliness. I&#8217;m going to start using this feature in small projects as soon as it&#8217;s released. Once it has proven itself to me it will become part of my app template for all my projects. (It&#8217;s turned off by default, which seems reasonable for now.)</p>
<p>Read more about it in the link above.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/468/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=468&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/02/20/activerecord-now-supports-an-identity-map-hooray/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>How to Set a Time Zone for Each Request in Rails</title>
		<link>http://ilikestuffblog.com/2011/02/03/how-to-set-a-time-zone-for-each-request-in-rails/</link>
		<comments>http://ilikestuffblog.com/2011/02/03/how-to-set-a-time-zone-for-each-request-in-rails/#comments</comments>
		<pubDate>Fri, 04 Feb 2011 04:56:35 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=462</guid>
		<description><![CDATA[The Railscast on Time Zones has some sample code that lets you set a thread-local, per-request time zone with a before_filter: Problem is, the current user&#8217;s time zone will leak across to the next request on the same thread. If the next one is by a logged-out user, all times displayed on that next request [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=462&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://railscasts.com/episodes/106-time-zones-in-rails-2-1">The Railscast on Time Zones</a> has some sample code that lets you set a thread-local, per-request time zone with a before_filter:</p>
<p><pre class="brush: ruby;">
# controllers/application.rb
  before_filter :set_user_time_zone

  private

  def set_user_time_zone
    Time.zone = current_user.time_zone if logged_in?
  end
</pre></p>
<p>Problem is, the current user&#8217;s time zone will leak across to the next request on the same thread. If the next one is by a logged-out user, all times displayed on that next request will show in the first user&#8217;s time zone. </p>
<p>To prevent this, use an around_filter:</p>
<p><pre class="brush: ruby;">
  around_filter :set_time_zone

  private

  def set_time_zone
    old_time_zone = Time.zone
    Time.zone = current_user.time_zone if logged_in?
    yield
  ensure
    Time.zone = old_time_zone
  end
</pre></p>
<p>You might be tempted to combine the first two lines of <tt>set_time_zone</tt> into one line with the comma assignment syntax and add &#8220;if logged_in?&#8221; to the one line in the ensure clause. Don&#8217;t do it. If you did that, the user&#8217;s time zone would leak out to the next request when the user logs out.</p>
<p>I&#8217;ve <a href="https://rails.lighthouseapp.com/projects/8994/tickets/6370-fix-for-code-sample-in-timezone-comment">submitted a Rails patch</a> to use this method in the sample code for the Time.zone= docs.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/462/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/462/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/462/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=462&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/02/03/how-to-set-a-time-zone-for-each-request-in-rails/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>How to fix Ruby error: Unsupported digest algorithm (sha256).</title>
		<link>http://ilikestuffblog.com/2011/01/22/how-to-fix-ruby-error-unsupported-digest-algorithm-sha256/</link>
		<comments>http://ilikestuffblog.com/2011/01/22/how-to-fix-ruby-error-unsupported-digest-algorithm-sha256/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 23:51:01 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=449</guid>
		<description><![CDATA[This is a note to myself because this has happened to me more than once. I&#8217;m posting it publicly in case it helps others, too. This is for people on a Mac, using rvm and homebrew. I ran across this with the very nice Sucker gem, which lets you easily access the Amazon Product Advertising [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=449&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is a note to myself because this has happened to me more than once. I&#8217;m posting it publicly in case it helps others, too.</p>
<p>This is for people on a Mac, using <a href="http://rvm.beginrescueend.com/">rvm</a> and <a href="http://mxcl.github.com/homebrew/">homebrew</a>.</p>
<p>I ran across this with the very nice <a href="http://www.rdoc.info/github/papercavalier/sucker/master/file/README.md">Sucker gem, which lets you easily access the Amazon Product Advertising API</a>. Amazon requires SHA-256 in its API calls, which is where my trouble began.</p>
<p>If your Ruby app got this error message in openssl/digest.rb:55:</p>
<blockquote><p><code>Unsupported digest algorithm (sha256).</code></p></blockquote>
<p>it&#8217;s because when you installed (compiled) Ruby, you linked in an older version of the openssl library.</p>
<h3>I Like Stuff that Finally Worked</h3>
<p>Here&#8217;s how I fixed it:</p>
<p><pre class="brush: plain;">
brew install openssl
rvm remove 1.8.7
rvm install 1.8.7 --with-openssl-dir=/usr/local/Cellar/openssl/0.9.8o/
</pre></p>
<p>To test it, run this in the Terminal:</p>
<p><pre class="brush: plain;">
ruby -ropenssl -e 'p OpenSSL::Digest::Digest.new(&quot;sha256&quot;)'
</pre></p>
<p>If you don&#8217;t get an error message, it worked.</pre>
<h3>Things That Didn't Work</h3>
<p><a href="http://ionrails.com/2010/12/25/deploy-to-ec2-with-rubber/">Installing and building openssl from source</a> (openssl.org) did not work.</p>
<p><a href="http://rvm.beginrescueend.com/packages/openssl/">Installing the openssl rvm package</a> and removing+reinstalling ruby did not work.</p>
<p>What finally worked was the steps above. Woo hoo!</p>
<p>By the way, I did not have to upgrade to Snow Leopard.</p>
<h3>What about Ruby 1.9.2?</h3>
<p>I still haven't gotten it working in Ruby 1.9.2. I run this:</p>
<p><pre class="brush: plain;">

rvm install 1.9.2 --with-openssl-dir=/usr/local/Cellar/openssl/0.9.8o/

</pre></p>
<p>and I get this output:</p>
<p><pre class="brush: plain;">

ruby-1.9.2-p136 - #fetching
ruby-1.9.2-p136 - #extracted to /Users/Brian/.rvm/src/ruby-1.9.2-p136 (already extracted)
ruby-1.9.2-p136 - #configuring
ruby-1.9.2-p136 - #compiling
Error running 'make ', please read /Users/Brian/.rvm/log/ruby-1.9.2-p136/make.log
There has been an error while running make. Halting the installation.

</pre></p>
<p>So I go look in make.log and I see this at the end:</p>
<p><pre class="brush: plain;">

Generating RDoc documentation
./miniruby -I./lib -I.ext/common -I./- -r./ext/purelib.rb  ./tool/runruby.rb --extout=.ext  -- &quot;./bin/rdoc&quot; --no-force-update --all --ri --op &quot;.ext/rdoc&quot;  &quot;.&quot;
/Users/Brian/.rvm/gems/ruby-1.8.7-p330/gems/rdoc-3.4/lib/rdoc/rdoc.rb:79: warning: already initialized constant GENERATORS
uh-oh! RDoc had a problem:
undefined method `coverage_report' for #&lt;RDoc::Options:0x7841a0&gt;

</pre></p>
<p><span style="color:#ff0000;">Does anyone know how to fix it?</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/449/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/449/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/449/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=449&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/01/22/how-to-fix-ruby-error-unsupported-digest-algorithm-sha256/feed/</wfw:commentRss>
		<slash:comments>9</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>Teaching my 12-Year-Old Daughter to Program, Part 3</title>
		<link>http://ilikestuffblog.com/2011/01/17/teaching-my-12-year-old-daughter-to-program-part-3/</link>
		<comments>http://ilikestuffblog.com/2011/01/17/teaching-my-12-year-old-daughter-to-program-part-3/#comments</comments>
		<pubDate>Tue, 18 Jan 2011 07:23:47 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=431</guid>
		<description><![CDATA[Martin Luther King Day was a holiday for both my daughter&#8217;s school and my employer. The three-day weekend gave us both enough of a break that we got back to our previously-scheduled programming lessons&#8212;and this was a fun one! (You may notice that the title of this post has a small difference from the earlier [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=431&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Martin Luther King Day was a holiday for both my daughter&#8217;s school and my employer. The three-day weekend gave us both enough of a break that we got back to our previously-scheduled programming lessons&mdash;and this was a fun one!</p>
<p>(You may notice that the title of this post has a small difference from the earlier ones. Since the last post a couple weeks ago, Rosey has turned 12.)</p>
<p>Calling &#8216;puts&#8217; over and over again is alright, but there&#8217;s nothing more fun for a fledgling programmer than asking the user a question, getting the answer, and then writing back a witty reply. In Chapter 4 of <em>Learn to Program</em>, Rosey learned about variables and assignment but the real fun came in Chapter 5, when she learned how to call <tt>gets</tt> to get a string from the user and then use the String.+ method to write back that string in the middle of a response.</p>
<p>Near the beginning of the chapter, though, I decided to take a detour and explain computer memory. This is the sentence in the book that triggered this:</p>
<blockquote><p>&#8220;To store the string in your computer&#8217;s memory for user later in your program&#8230;.&#8221;</p></blockquote>
<p>The words &#8220;<strong>store</strong> the string in memory&#8221; reminded me of something I can still clearly remember: way back when I was 14 or so and first learning to use WordStar on my family&#8217;s Osborne 1, I found it hard to understand the difference between &#8220;Open&#8221; and &#8220;Save.&#8221; The picture in my mind of what&#8217;s going on inside the computer was extremely vague. I didn&#8217;t understand the difference between RAM and the Hard Drive, and why the word Open should mean moving something from the hard drive to RAM and Save should mean moving something from RAM to the hard drive.</p>
<p>I&#8217;m a believer in remembering what I struggled with in a subject, and trying to explain those things when I teach the subject. I hope that makes me a better teacher.</p>
<div id="attachment_436" class="wp-caption alignright" style="width: 460px"><a href="http://bmorearty.files.wordpress.com/2011/01/computer-memory2.jpg"><img class="size-full wp-image-436 " title="Computer Memory" src="http://bmorearty.files.wordpress.com/2011/01/computer-memory2.jpg?w=450&#038;h=303" alt="Computer Memory" width="450" height="303" /></a><p class="wp-caption-text">RAM vs. HD, Open vs. Save...and the BRAIN</p></div>
<p>So I quickly sketched the attached diagram, explaining the pieces as I went. As I suspected, the difference between RAM and HD was pretty abstract for her and took some time even though she is an experienced game player. She got it, though, and we moved on the fun stuff.</p>
<p>The chapter on variables and assignment was surprisingly easy. The first few pages of the next chapter (Chapter 5, &#8220;Mixing it Up&#8221;) were useful for her as well, although not incredibly exciting. They explained things like why you can&#8217;t do &#8217;5&#8242; + 5, and why &#8217;99.999&#8242;.to_i returns 999.</p>
<p>But this was all just leading up to the <em>awesome</em> part. In section 5.3 the book introduces the <tt>gets</tt> function, and in 5.5 you ask the user&#8217;s name and then print it back in a sentence. Rosey was so excited the first time she ran that. It was fun to watch.</p>
<p>Finally she did the exercises for the chapter, which were really kid-friendly. The first one tells you to write a program that asks for a person&#8217;s first, middle, and last names and then greets the person using their full name. She had fun with that, writing out prompts like &#8220;That&#8217;s an&#8230;um, interesting middle name.&#8221; And the next exercise was cute: ask for a person&#8217;s favorite number, add one to it, and tactfully suggest that as a better favorite number because it&#8217;s bigger. She got the essence of the program right on the first try but she was missing the conversion between strings and numbers. I made sure not to point out the errors as she was typing. I think that was the right approach, because the interruptions might have prevented her from getting the basic logic down right.</p>
<p>One last thing to note: I remember being confused about the assignment operator when I learned to program, and she was too. In particular, she thought the value should go on the left and the assigned variable should go on the right:</p>
<p><pre class="brush: ruby;">

fav_number + 1 = new_fav

</pre></p>
<p>Take the programmer part out of your brain and read that code out loud. It makes sense, doesn&#8217;t it? </p>
<blockquote><p>&#8220;Favorite number plus one equals the new favorite number.&#8221;</p></blockquote>
<p>But alas, the computer doesn&#8217;t think so. She grudgingly accepted that and moved on.</p>
<p>I&#8217;m not sure when our next lesson will be. Hopefully sooner than the next holiday, since that&#8217;s in May. :-)</p>
<p>See you all next time&#8230;.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/431/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/431/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/431/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=431&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/01/17/teaching-my-12-year-old-daughter-to-program-part-3/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/2011/01/computer-memory2.jpg" medium="image">
			<media:title type="html">Computer Memory</media:title>
		</media:content>
	</item>
		<item>
		<title>Quick and Dirty Performance Profiling in Ruby</title>
		<link>http://ilikestuffblog.com/2011/01/16/quick-and-dirty-performance-profiling-in-ruby/</link>
		<comments>http://ilikestuffblog.com/2011/01/16/quick-and-dirty-performance-profiling-in-ruby/#comments</comments>
		<pubDate>Sun, 16 Jan 2011 18:28:06 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=424</guid>
		<description><![CDATA[Occasionally I read Rails source code to learn/re-learn what it&#8217;s capable of. Want to do some quick and dirty profiling to see how long some Ruby code takes? Do this in irb or in a Ruby project: The output is how long in milliseconds the code took to run. This requires ActiveSupport but does not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=424&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Occasionally I read Rails source code to learn/re-learn what it&#8217;s capable of. </p>
<p>Want to do some quick and dirty profiling to see how long some Ruby code takes? Do this in irb or in a Ruby project:</p>
<p><pre class="brush: ruby;">
require 'rubygems'
require 'active_support/core_ext/benchmark'

puts Benchmark.ms do
   # put your code here
end
</pre></p>
<p>The output is how long in milliseconds the code took to run.</p>
<p>This requires ActiveSupport but does not require all of Rails. If you don&#8217;t have ActiveSupport, install it with <tt>gem install activesupport</tt>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/424/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/424/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/424/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=424&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/01/16/quick-and-dirty-performance-profiling-in-ruby/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>JSConf 2011: See How Twitter Built a Single-Page Web App</title>
		<link>http://ilikestuffblog.com/2011/01/04/jsconf-2011-see-how-twitter-built-a-single-page-web-app/</link>
		<comments>http://ilikestuffblog.com/2011/01/04/jsconf-2011-see-how-twitter-built-a-single-page-web-app/#comments</comments>
		<pubDate>Wed, 05 Jan 2011 07:31:45 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=419</guid>
		<description><![CDATA[I just submitted my proposal to speak at JSConf 2011 in Portland on May 2-3. Well actually I don&#8217;t plan to fill both entire days. My title: &#8220;Exposing New Twitter’s Secrets (Without a TSA Full Body Scan).&#8221; Want to build your own single-page web app? If my proposal is accepted, come attend my talk and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=419&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just submitted my proposal to speak at <a href="http://2011.jsconf.us/">JSConf 2011</a> in Portland on May 2-3. Well actually I don&#8217;t plan to fill both entire days. </p>
<p>My title: &#8220;Exposing New Twitter’s Secrets (Without a TSA Full Body Scan).&#8221;</p>
<p>Want to build your own single-page web app? If my proposal is accepted, come attend my talk and we&#8217;ll reverse-engineer New Twitter to see how they did it. Maybe you will get some good insight and ideas.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/419/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/419/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/419/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/419/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/419/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/419/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/419/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/419/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/419/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/419/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/419/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/419/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/419/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/419/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=419&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/01/04/jsconf-2011-see-how-twitter-built-a-single-page-web-app/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>Teaching my 11-Year-Old Daughter to Program, Part 2</title>
		<link>http://ilikestuffblog.com/2011/01/02/teaching-my-11-year-old-daughter-to-program-part-2/</link>
		<comments>http://ilikestuffblog.com/2011/01/02/teaching-my-11-year-old-daughter-to-program-part-2/#comments</comments>
		<pubDate>Mon, 03 Jan 2011 04:50:01 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Teaching Programming]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=406</guid>
		<description><![CDATA[In my last post I said I am starting to teach Ruby to my daughter Rosey. So today after getting back home from watching Tangled in 3D we got started. She had done the first reading assignment last night (Preface, Intro, and Chapter 1 of Learn to Program). Our next step was to sit down [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=406&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://ilikestuffblog.com/2011/01/02/teaching-my-11-year-old-daughter-to-program-in-ruby/">my last post</a> I said I am starting to teach Ruby to my daughter Rosey. So today after getting back home from watching Tangled in 3D we got started. She had done the first reading assignment last night (Preface, Intro, and Chapter 1 of <em>Learn to Program</em>). Our next step was to sit down and follow the instructions in Chapter 1, which was about installing and setting up the environment.</p>
<p>First I had to set some ground rules. Well, one ground rule: <em></em></p>
<p style="padding-left:30px;"><em>Let&#8217;s stay on topic.</em></p>
<p><em></em> Kids always want to tell you random things. Unless they&#8217;re teenagers, of course, in which case I&#8217;m told they close off in their room for about four years. So I gave her a piece of paper and a pencil. If she thought of anything unrelated to programming that she was dying to tell me, she could write a reminder to herself on the paper and tell me later. I think it helped. At one point she was juuuuuuuuuuuuust about to tell me something but she caught herself and just wrote it down. I think having this release valve helped get the idea out of their head so she wouldn&#8217;t be distracted and could concentrate.</p>
<p>So, down to work. We installed Ruby on her laptop with the Ruby One-Click Installer. Yes, it&#8217;s her laptop even though we have three kids. Each  kid has their own laptop. <a href="http://www.intechraoutlet.com/home/">Refurbished corporate PCs</a> are pretty cheap. And we installed Notepad++ too, since I love it.</p>
<p>Rosey had fun playing with the <tt>echo</tt> command on the command line, echoing everything I said. Having a computer do this is only slightly less annoying than having a person do it. Then she did this at the prompt:</p>
<p><pre class="brush: plain;">
C:\&gt;:-)
</pre></p>
<p>And to our surprise, there was no error message. It just came back with another C: prompt. I guess that&#8217;s because in the Windows batch language a line that starts with a colon is a label&mdash;and you can put anything you want after it. Fun.</p>
<p>We finished Chapter 1 in a hurry and I was worried it wasn&#8217;t the best first day. Fortunately, she said yes when I asked if we could just do the first two paragraphs of Chapter 2 since I saw that&#8217;s where the instant gratification begins. She was hooked after this worked:</p>
<p><pre class="brush: ruby;">

puts 1 + 2 # =&gt; 3

</pre></p>
<p>She experimented with some other math. I told her about <tt>*</tt> and <tt>/</tt> for times and divided by, and she did:</p>
<p><pre class="brush: ruby;">

puts 300 / 8

</pre></p>
<p>but was surprised when the program printed <tt>37</tt> instead of <tt>37.5</tt>. At that point I became pretty impressed with the order in which the book introduces new concepts, because I had read ahead and knew that the  next page describes integers vs. floats, and goes on to explain why integer math always returns an integer. We read through it, typed in the examples, and were having fun. The book impressed me with its clairvoyance again when Rosey got tired of typing the spaces between the mathematical operators and asked if they are really needed. I showed her the next paragraph, which said &#8220;the spaces in the program are not important; they just make the code easier to read.&#8221;</p>
<p>Rosey also tried one of her favorite phrases:</p>
<p><pre class="brush: plain;">

puts I like pie

</pre></p>
<p>but she got an error message because she doesn&#8217;t know yet that strings have to be quoted. (The command-line <tt>echo</tt> command didn&#8217;t need them.) I decided not to bother explaining that for now, since the next chapter goes into it.</p>
<p>At one point the book said, &#8220;Don&#8217;t type commas into your numbers&#8221; because it just confuses Ruby. But I taught her a little-known Ruby trick, using underscores where you would have used commas. She&#8217;s learning ancient ninja secrets.</p>
<p><pre class="brush: ruby;">

puts 1_000_000

</pre></p>
<p>I thought the exercises at the end of Chapter 2 would be hard. They ask the reader to solve problems like &#8220;How many hours are in a year?&#8221; and &#8220;How many seconds old are you?&#8221; It turned out they were a piece of cake. She raced through them, stopping only a few times to figure out whether to divide or multiply.</p>
<p>Next up: Rosey&#8217;s next reading assignment is Chapter 3, &#8220;Letters,&#8221; which talks about strings. Christmas vacation is over and school starts up tomorrow, so her homework will take precedence. But hopefully we&#8217;ll be able to keep the pace going and not lose steam.</p>
<p>So far so good!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/406/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/406/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/406/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=406&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/01/02/teaching-my-11-year-old-daughter-to-program-part-2/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>Teaching my 11-Year-Old Daughter to Program (in Ruby)</title>
		<link>http://ilikestuffblog.com/2011/01/02/teaching-my-11-year-old-daughter-to-program-in-ruby/</link>
		<comments>http://ilikestuffblog.com/2011/01/02/teaching-my-11-year-old-daughter-to-program-in-ruby/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 08:29:41 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Teaching Programming]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=395</guid>
		<description><![CDATA[This is installment #1 in a series of posts I will write about teaching my 11-almost-12-year-old daughter to program in Ruby. In the last year I taught my daughter Rosey, who is 11 years old and in sixth grade, the basics of HTML. With help and training from me she made a few web pages [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=395&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This is <strong>installment #1</strong> in a series of posts I will write about teaching my 11-almost-12-year-old daughter to program in Ruby.</p>
<p>In the last year I taught my daughter Rosey, who is 11 years old and in sixth grade, the basics of HTML. With help and training from me she <a href="http://www.morearty.org/rosey/">made a few web pages</a> with her own drawings, including some <a href="http://www.morearty.org/rosey/whobrokeit.html">clever</a> <a href="http://www.morearty.org/rosey/dressupmelissa.html">puzzles</a>. We hand-coded all the pages instead of  generating them with a drag-and-drop tool. That was her choice. (Hooray!)</p>
<p><a href="http://bmorearty.files.wordpress.com/2011/01/dog.png"><img class="alignright size-full wp-image-401" title="Dog eating" src="http://bmorearty.files.wordpress.com/2011/01/dog.png?w=450" alt=""   /></a>She came away knowing some HTML. She knows it well enough to give a bit of an explanation to her friends, which I think is awesome. I tried to teach her a bit of CSS and JavaScript too. She may have had an inkling of how they work, but I didn&#8217;t do a very good job on those parts. I think it was mainly because I didn&#8217;t have a structured way to teach them. I admit I was pretty much all over the map. HTML was easy to teach tag by tag&#8211;start with &lt;html&gt;, &lt;body&gt;, &lt;p&gt;, and &lt;img&gt;. But with JavaScript to do anything useful on a website you have to go quickly past the basics and understand functions, the DOM, and more. I ended up writing the JavaScript myself and hoping she&#8217;d at least know it exists so she could come back some day.</p>
<p>Now it&#8217;s a new year, and next week she&#8217;ll turn 12. I asked her if she&#8217;d like to learn to program in a language that can actually make things happen instead of just show things on a page. Somehow I must have used just the right combination of excitement and pleading, because she said yes.</p>
<p>Very cool. I get to teach my daughter to write software! I&#8217;ve been waiting for this day for a long time. Almost 12 years.</p>
<p>She already knows a couple of boys her age who have started learning to program but most of the boys have not. I&#8217;m excited that she will be ahead of a lot of the boys, since I hear one reason girls are sometimes behind in learning computer stuff is the intimidation factor: they take a class and see that most of the boys have already learned a lot of it on their own, so the girls feel like they&#8217;ll never catch up. I totally get that, and want to prevent it.</p>
<h3>I Like Stuff that&#8217;s Ruby</h3>
<p>Decision #1: what language to teach? I wanted to teach an interpreted language because interactive interpreters make learning easier. I primarily considered JavaScript and Ruby. I think they&#8217;re both great choices because (a) they&#8217;re both interpreted, (b) neither requires an immediate understanding of object-orientation, (c) I know them both really well and love them both, and (d) they&#8217;re actually useful.</p>
<p>I also considered &#8220;kid&#8221; languages like Scratch or Logo. But I&#8217;ve tried Scratch and honestly I didn&#8217;t get it. If I don&#8217;t get it, how am I going to teach it? I did learn Logo years ago and it was fun. But I was more excited about teaching JavaScript or Ruby.</p>
<p>A couple years  ago while browsing the Programming section of Borders Books in Palo Alto I noticed  Chris Pine&#8217;s book, <em><a title="Learn to Program" href="http://www.amazon.com/Learn-Program-Second-Facets-Ruby/dp/1934356360/ref=dp_ob_title_bk">Learn to Program</a></em>, and wondered if it would be good for a middle-schooler. I read more about it, and found a review titled <a href="http://www.amazon.com/review/RXFZGYVZGRBUL/ref=cm_cr_pr_perm?ie=UTF8&amp;ASIN=0976694042&amp;nodeID=&amp;tag=&amp;linkCode=">&#8220;Great for Kids.&#8221;</a> The author is using <em>Learn to Program</em> to teach their 8-year-old daughter and loves it. Plus I learned that the author actually teaches programming to kids my daughter&#8217;s age. That&#8217;s good enough for me! So I got the book and will start teaching her to program.</p>
<p>(By the way, if you haven&#8217;t been to Border&#8217;s on University Ave. in Palo Alto, do yourself a favor and go inside. It&#8217;s cool. It was a beautiful, classic movie theater called The Varsity when I moved to downtown Palo Alto in 1988. Later they converted it to a bookstore but they kept the  marquee.)</p>
<h3>Lesson 1</h3>
<p>So Today I went out and picked up the book. No way could I wait for an Amazon shipment. Then I read the Preface, Introduction, and Chapter 1. Then I asked her to start with the Preface and read for 20 minutes or so and stop wherever she is, or to finish Chapter 1 if she wants. She ended up stopping at the same spot as me. Tomorrow we&#8217;ll go over Chapter 1 together. It&#8217;s mostly just about installing Ruby and a text editor. But I&#8217;ll also go over some of the high-level concepts I remember being incredibly confusing to me when I first learned to program. Specifically:</p>
<ul>
<li>When I type a line of code into the computer, <em>how should I think of this in comparison with an English sentence?</em> Is it Declarative? Imperative? Something else? (Fortunately I think she has learned these terms in school. If she hasn&#8217;t, I can quickly describe the differences.) I think for a beginner the easiest explanation is that all lines of code are <em>imperative</em>. More specifically, <em>you are telling the computer </em>what to do. When you say &#8220;print 3&#8243; it&#8217;s like telling someone else&#8211;someone who always follows orders&#8211;to print the number 3 on a piece of paper. Of course some computer programming statements are more like declarative, interrogative, or conditional statements. But the first thing a beginner learns is the imperatives like &#8220;print.&#8221; (I peeked ahead at Chapter 2 and it starts with &#8220;puts 1+2&#8243;.)</li>
<li>What is the difference between RAM and the hard disk? How should I think of &#8220;saving&#8221; or &#8220;opening&#8221; a file? My daughter has saved documents before but I don&#8217;t think she quite groks RAM vs. disk yet.</li>
</ul>
<h3>Expectations</h3>
<p>I enter this adventure with excitement and high hopes but also realistic expectations. She may get bored quickly or feel it&#8217;s too hard. I&#8217;m going to do my best to keep it light, fun, and low pressure. But if it doesn&#8217;t work out, it&#8217;s no big deal. You have to try things, right?</p>
<p>I will continue to blog about this adventure. Stay tuned right here on the I Like Stuff Blog.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/395/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/395/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/395/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=395&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2011/01/02/teaching-my-11-year-old-daughter-to-program-in-ruby/feed/</wfw:commentRss>
		<slash:comments>6</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/2011/01/dog.png" medium="image">
			<media:title type="html">Dog eating</media:title>
		</media:content>
	</item>
		<item>
		<title>How to Lazily Find All Records in Rails 3 with Arel</title>
		<link>http://ilikestuffblog.com/2010/10/30/how-to-lazily-find-all-records-in-rails-3-with-arel/</link>
		<comments>http://ilikestuffblog.com/2010/10/30/how-to-lazily-find-all-records-in-rails-3-with-arel/#comments</comments>
		<pubDate>Sat, 30 Oct 2010 18:56:12 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=383</guid>
		<description><![CDATA[To my surprise, Post.all in Rails 3 performs the query immediately. It does not do lazy loading, as Arel&#8217;s where method does. It turns out this is by design. See Force loading – all, first &#38; last. So: what do you use if your view has fragment caching and you want your controller&#8217;s index method [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=383&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>To my surprise, <tt>Post.all</tt> in Rails 3 performs the query immediately. It does not do lazy loading, as Arel&#8217;s <tt>where</tt> method does.</p>
<p><pre class="brush: ruby;">
def index
  @posts = Post.all     # not lazy; returns Array
end
</pre></p>
<p>It turns out this is by design. See <a href="http://m.onkey.org/2010/1/22/active-record-query-interface">Force loading – all, first &amp; last</a>.</p>
<p>So: what do you use if your view has  fragment caching and you want your controller&#8217;s index method to delay the query until you&#8217;re sure you&#8217;ll need to use it?</p>
<p>At first I did this:</p>
<p><pre class="brush: ruby;">
def index
  @posts = Post.where('1=1')  # returns ActiveRecord::Relation
end
</pre></p>
<p>But the documented way is to use the <tt>scoped</tt> method:</p>
<p><pre class="brush: ruby;">
def index
  @posts = Post.scoped        # returns ActiveRecord::Relation
end
</pre></p>
<p>Another alternative I recommend, which lets you do lazy execution queries in <em>any</em> version of Rails: <a href="http://ilikestuffblog.com/2010/09/23/ruby-on-rails-bedtime-stories/">move the queries to helper methods</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/383/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/383/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/383/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=383&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/10/30/how-to-lazily-find-all-records-in-rails-3-with-arel/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>Well, That Didn&#8217;t Last Long. Bye, SQLite.</title>
		<link>http://ilikestuffblog.com/2010/10/29/well-that-didnt-last-long-bye-sqlite3/</link>
		<comments>http://ilikestuffblog.com/2010/10/29/well-that-didnt-last-long-bye-sqlite3/#comments</comments>
		<pubDate>Fri, 29 Oct 2010 16:42:42 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=373</guid>
		<description><![CDATA[I recently started a new project in Rails 3.0 and decided to try SQLite as the development database. In the past I&#8217;ve always used MySQL for my Rails projects. I&#8217;m hosting the app on Heroku so it&#8217;s PostgreSQL in production, making this my first time using SQLite and my first time using different databases in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=373&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently started a new project in Rails 3.0 and decided to try SQLite as the development database. In the past I&#8217;ve always used MySQL for my Rails projects. I&#8217;m hosting the app on Heroku so it&#8217;s PostgreSQL in production, making this  my first time using SQLite and my first time using different databases in development and production.</p>
<p>At first I was having fun with SQLite. It&#8217;s lightweight, doesn&#8217;t use much memory, runs fast on a local dev machine. A single database is stored  in a single file. No server to configure, no nothing. Nice.</p>
<p>But I gave up on it after about five days because of an annoying limitation that bit me twice: if you add a <code>NOT NULL</code> column (<code>:null =&gt; false</code> in your migration) to an existing table, <a href="http://sqlite.org/lang_altertable.html">SQLite requires you to specify a default value&mdash;even if the table is empty</a>.</p>
<p>It makes sense to require a default value on a <code>NOT NULL</code> column if there are already rows in the table. All relational databases require that. But if you don&#8217;t want to specify a default and the table is empty SQLite shouldn&#8217;t force you to.</p>
<p>I found <a href="http://www.mail-archive.com/sqlite-users@sqlite.org/msg41182.html">discussions</a> where people suggested a workaround of &#8220;Can&#8217;t you just drop the table and create a new one? As the table is empty, you won&#8217;t be losing any data.&#8221; Sure, but it&#8217;s far more error-prone to recreate the table because it&#8217;s not an incremental change. You have to carefully reconstruct the table and all indexes from all past migrations, which became unwieldy for me even in a 5-day-old project. It really is more error-prone: I tried it and screwed up a couple of times. That was it for me, so I decided it&#8217;s time to switch back to MySQL for local development.</p>
<p>The other experiment&mdash;using different databases in local development and production&mdash;is still going fine. We&#8217;ll see what snags I hit that make me change my mind about that too. I still wouldn&#8217;t do that on a big project but this is a little ol&#8217; thang.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/373/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=373&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/10/29/well-that-didnt-last-long-bye-sqlite3/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>Export iPhoto to Folders is Getting Better All the Time</title>
		<link>http://ilikestuffblog.com/2010/09/24/export-iphoto-to-folders-is-getting-better-all-the-time/</link>
		<comments>http://ilikestuffblog.com/2010/09/24/export-iphoto-to-folders-is-getting-better-all-the-time/#comments</comments>
		<pubDate>Sat, 25 Sep 2010 06:17:52 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=369</guid>
		<description><![CDATA[Mark Nottingham is on a tear. Last week he sent me a pull request for a bunch more changes he made to the exportiphoto app that lets you export iPhoto events or albums to folders. The most notable changes: It uses less memory. This matters if your iPhoto library is huge, because you will no [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=369&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/mnot">Mark Nottingham</a> is on a tear. Last week he sent me a pull request for a bunch more changes he made to the exportiphoto app that lets you <a title="export iPhoto events and albums to folders" href="http://github.com/BMorearty/exportiphoto">export iPhoto events or albums to folders</a>.</p>
<p>The most notable changes:</p>
<ul>
<li>It uses less memory. This matters if your iPhoto library is huge, because you will no longer overwhelm your Mac&#8217;s memory when exporting the photos to folders. It now uses a SAX parser so it no longer has to load the entire iPhoto XML file into memory.</li>
<li>It shows better progress than before, telling you how many events/albums it has processed so far and how many there are total.</li>
<li>If you want, it can copy photo metadata (image name, description, keywords, faces, and rating) into the exported photos.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/369/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=369&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/09/24/export-iphoto-to-folders-is-getting-better-all-the-time/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>Ruby on Rails Bedtime Stories</title>
		<link>http://ilikestuffblog.com/2010/09/23/ruby-on-rails-bedtime-stories/</link>
		<comments>http://ilikestuffblog.com/2010/09/23/ruby-on-rails-bedtime-stories/#comments</comments>
		<pubDate>Thu, 23 Sep 2010 08:26:33 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=352</guid>
		<description><![CDATA[It&#8217;s time for some bedtime stories. These are children&#8217;s stories so there is a happy ending. These stories are about making your Rails code cleaner, faster, and less brittle, and about keeping your fragment caching code simple. The third story shows how removing code from a view can make your app&#8217;s controller query the DB a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=352&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s time for some bedtime stories. These are children&#8217;s stories so there is a happy ending. These stories are about making your Rails code cleaner, faster, and less brittle, and about keeping your fragment caching code simple. The third story shows how removing code from a view can make your app&#8217;s controller query the DB a lot <strong>more</strong> often.</p>
<h3>Story #1: If You Fragment Cache a View</h3>
<p>If you want your Rails website to run faster and scale better, you might decide fragment caching will help.</p>
<p>And chances are, you will put memcached on the server and write <tt>cache</tt> statements in your views.</p>
<p>But if you are still on Rails 2.x then you&#8217;re not using Arel&#8217;s lazy execution. So you might notice your controllers are still querying the database even for views that are cached and won&#8217;t use the data. So you will probably add <tt>read_fragment</tt> calls to the controllers to prevent that.</p>
<p>If you used a custom key in the view&#8217;s <tt>cache</tt> statement you will want to use the same custom key in the <tt>read_fragment</tt> statement.</p>
<p>But if it&#8217;s a complex key, that might not feel DRY. So you might refactor the key out to a helper function you can call from the controller and the view, passing the result in to <tt>read_fragment</tt> and <tt>cache</tt>. You might even put the helper in application_controller.rb if the view is a partial that&#8217;s called from several controllers.</p>
<p>Then you might feel bad that your fragment cache logic, which started out nice and clean and small in the view, is now spread out among three source files. You might get a headache. You might think there must be a better way. And you might ask for a glass of milk.</p>
<h3>Story #2: If You Remove Data from a View</h3>
<p>If your product manager wants you to output some data in a view, you might ask for the data in your controller. You might use ActiveRecord&#8217;s <tt>find</tt> method since you&#8217;re still on Rails 2.x and can&#8217;t use Arel yet.</p>
<p>And chances are, if you query data in your controller, you&#8217;re going to store the result in an instance variable.</p>
<p>If your product manager decides three months later that the data doesn&#8217;t need to be shown after all, she may ask your coworker to remove it. Your coworker may do just that&#8211;remove it from the view.</p>
<p>Your coworker may not realize the query in the controller is no longer needed. He may not even think of removing it.</p>
<p>Your server may worker harder than it has to, continuing to query the database on every page view to get data that&#8217;s never shown on the page.</p>
<p>Your server might get a headache. It might ask for a glass of milk.</p>
<h3>Story #3: If You Combine Stories 1 and 2</h3>
<p>If your product manager asks you to show data in a view, chances are you will put a database query in your controller to pass the data to the view.</p>
<p>When traffic gets high and your server gets overloaded, you may decide to use a fragment cache. You might use <tt>:expires_in =&gt; 5.minutes</tt> so your server only has to query the database once every five minutes.</p>
<p>You might get the same headache you got in bedtime story #1 because you have to add a <tt>read_fragment</tt> call in your controller, a <tt>cache</tt> call in your view, and a reusable key function in your application controller. But the glass of milk might help and your headache may go away.</p>
<p>When your product manager says you no longer need to show the data in your view, chances are you will remove the fragment cache and its contents from the view. But you might forget about the query in the controller. You might leave it there.</p>
<p>But no big deal, right? The app still works. Your tests still pass. You&#8217;ll only be querying the database once every five minutes, after all. Wrong. Remember: calling <tt>cache</tt> from the view is what writes to the cache. By removing the view&#8217;s <tt>cache</tt> statement you have removed all cache writes. So there&#8217;s never anything in the cache. So <tt>read_fragment</tt> will always return nil.</p>
<p>And if <tt>read_fragment</tt> returns nil, your query will run.</p>
<p>On. Every. Request.</p>
<p>By removing the data from the view you have gone from querying the database once every five minutes to querying it on<strong> each and every page view, even though you <em>never </em>need to show the data.</strong></p>
<p>You&#8217;re going to need a really big glass of milk to get rid of that headache. Hopefully you&#8217;re running New Relic and will see the huge increase in DB queries immediately after deploy so you can look into it quickly.</p>
<h3>The Promised Happy Ending</h3>
<p>There are several possible solutions to the problems in these three bedtime stories. The third one is my favorite by a long shot:</p>
<ol>
<li>Not the solution: perform the query in the view instead of in the controller. Obviously this is wrong. I won&#8217;t discuss this further.</li>
<li>Not the solution: use Model-View-Presenter. I won&#8217;t discuss it either because I think it needlessly complicates matters. We Rails programmers tend to believe in the KISS principle, and there is a simpler solution.</li>
<li><strong>The solution: move your queries <em>out </em>of the action methods and into memoized <em>helper methods </em>in your controller.</strong>
<ol type="a">
<li>Give the helper methods the same name that the instance variables used to have. (<tt>@company</tt> becomes the <tt>company</tt> method).</li>
<li>In each helper method, assign the result to the instance variable. Make sure the assignment uses <tt>||=</tt>, not plain old <tt>=</tt>, so the helper runs the query only once no matter how many times it&#8217;s called.</li>
<li>In your view, never rely on instance variables having been previously set by the controller. <strong>Remove all the <tt>@</tt> signs from the views and almost all <tt>@</tt> signs from the controllers.</strong> (Exceptions are in <tt>new</tt> and <tt>create</tt>. See below.) What you&#8217;re left with are function calls to the helpers. Each helper will perform the query the first time it is called within a single request.</li>
</ol>
</li>
</ol>
<p>This solution is pure beauty. Here&#8217;s why:</p>
<ul>
<li>It solves bedtime story #1. You can remove all those sloppy <tt>read_fragment</tt> calls from your controller. The only reason they were there was to limit database calls to only when the view needs it. But by the time your helper function is called, you <strong>know </strong>the view needs the data and wasn&#8217;t able to find a fragment in the cache. So just go get the data. This means you can also remove the reusable key method from application.rb and put the cache key inline as a parameter to the <tt>cache</tt> statement. Your code will still be DRY because you only need the key in that one place.</li>
<li>It solves bedtime story #2. If you ever remove your data output from your view, you are removing calls to the helper functions. If they&#8217;re not called, they won&#8217;t query the database. So even if you forget to remove them from the controller, they&#8217;re doing no harm.</li>
<li>It solves bedtime story #3. If you ever remove a fragment cache and its contents from the view and thus never write to the cache any more, it does not increase the number of times your controller queries the database. Since you&#8217;ve removed the view code that calls the helper functions, you actually reduce the number of database calls to zero.</li>
<li>It&#8217;s simple to understand.</li>
<li>It&#8217;s easy to implement.</li>
<li>The resulting code is clean. Your controller functions are shorter and therefore sweeter. You don&#8217;t have to add new classes. You don&#8217;t have to write any new code.</li>
<li>It does not require putting database calls in the wrong layer (the view).</li>
<li>It does not require explaining a scary new pattern name to your team and to every new person who joins your team.</li>
</ul>
<h3>Does It Work in Rails 3?</h3>
<p>Sure, it works in Rails 3. You will get the same benefits from using it  in any version of Rails. Rails 3 has Arel with its lazy evaluation of queries, but the default generated controllers don&#8217;t take advantage of this feature.</p>
<p style="padding-left:30px;"><strong>Update: </strong>previously I said it won&#8217;t really be needed any more after you update all your <tt>find</tt> calls to Arel&#8217;s implicit query that runs when you start iterating over results. It turns out I was wrong: even in Rails 3 the default <tt>index</tt> function calls <tt>ModelClass.all</tt> and the other functions call <tt>ModelClass.find</tt>. Both of these run an immediate query, not a lazy one.</p>
<p>Putting performance improvements aside, this technique also DRYs up your controller code a bit even when you&#8217;re using Arel. Instead of putting <tt>@company = Company.find(params[:id])</tt> in every controller method, you just write it once.</p>
<h3>It&#8217;s Not Following the Rails Conventions. Will Other Gems Work?</h3>
<p>Gems will still work. Let&#8217;s say, for example, you use Ryan Bates&#8217; CanCan gem. There&#8217;s a code sample in the CanCan README that goes like this:</p>
<p><pre class="brush: ruby;">
def show
  @article = Article.find(params[:id])
  authorize! :read, @article
end
</pre></p>
<p>It looks like you have to initialize @article, right? But you could rewrite it this way:</p>
<p><pre class="brush: ruby;">
def show
  authorize! :read, article
end

def article
  @article ||= Article.find(params[:id])
end
</pre></p>
<p>Notice I took the @ off the &#8220;article&#8221; parameter. It is now a function call to the your helper method that calls <tt>Article.find</tt>. In this case you&#8217;re not avoiding a database call, but you&#8217;re not doing any harm either. And your show method is shorter. And sweeter.</p>
<p><strong>Update: </strong>In the comments below, in response to Ben&#8217;s note about CanCan&#8217;s <tt>load_and_authorize_resource</tt> function, I posted a better way to write your helpers when using CanCan so they don&#8217;t run the query or do any authorization until we know the data is needed.</p>
<h3>What About Non-Read Operations? Create, Update, Delete?</h3>
<p>The <tt>new</tt> and <tt>create</tt> methods should still set the instance variable like they did before. <tt>update</tt> can just call the helper (<tt>company.update_attributes</tt> instead of <tt>@company.update_attributes</tt>) and <tt>destroy</tt> can do the same (<tt>company.destroy</tt> instead of assigning <tt>@company</tt> and then calling <tt>@company.destroy</tt>).</p>
<p>But<em> all</em> views—whether for any of the seven RESTful methods or any non-RESTful method—should just reference the helper method, never the instance variable. Since the helper method is memoized (<tt>@company ||= Company.find</tt>), it will just work because the instance variable was already set.</p>
<h3>I Like Testing</h3>
<p>Your tests will need to use <tt>@controller.post</tt> instead of <tt>assigns(:post)</tt>. Understand, though, that the test might do a DB query by calling <tt>post</tt> if the view never called it.</p>
<h3>Code Sample: the Old Way</h3>
<p>Here&#8217;s an example CompaniesController that follows the Rails convention of doing the database query in the controller, assigning the result to an instance variable, and referencing it in the view:</p>
<p><pre class="brush: ruby;">
# GET /companies/1
# GET /companies/1.xml
def show
  @company = Company.find(params[:id])

  respond_to do |format|
    format.html
    format.xml  { render :xml =&gt; @company }
  end
end
</pre></p>
<p>And the corresponding show.html.erb:</p>
<p><pre class="brush: xml;">

  &lt;strong&gt;Name:&lt;/strong&gt;
  &lt;%=h @company.name %&gt;

&lt;%= link_to 'Edit', edit_company_path(@company) %&gt; |
&lt;%= link_to 'Back', companies_path %&gt;
</pre></p>
<h3>Code Sample: the Better Way</h3>
<p>Here&#8217;s how you can rewrite it to avoid bedtime story problems:</p>
<p><pre class="brush: ruby;">
helper_method :company

# GET /companies/1
# GET /companies/1.xml
def show
  respond_to do |format|
    format.html
    format.xml  { render :xml =&gt; company }
  end
end

def company
  @company ||= Company.find(params[:id])
end
</pre></p>
<p>And the corresponding show.html.erb:</p>
<p><pre class="brush: xml;">

  &lt;strong&gt;Name:&lt;/strong&gt;
  &lt;%=h company.name %&gt;

&lt;%= link_to 'Edit', edit_company_path(company) %&gt; |
&lt;%= link_to 'Back', companies_path %&gt;
</pre></p>
<p>For completeness, here is how you would implement the index method:</p>
<p><pre class="brush: ruby;">
helper_method :company, :companies

def index
end

def companies
  @companies ||= Company.all
  # or with will_paginate:
  # @companies ||= Company.paginate :page =&gt; params[:page] || 1
end
</pre></p>
<h3>Thanks</h3>
<p>Thanks and apologies to <a href="http://www.amazon.com/You-Give-Mouse-Cookie-Give/dp/0060245867"><em>If You Give a Mouse a Cookie</em></a> and other books in the series by Laura Joffe Numeroff and Felicia Bond. A wonderful series of books that I recommend reading to small children.</p>
<p>Thanks to Struts 2 for helping me discover this pattern. (Yeah. Whoa.)</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/352/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/352/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/352/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=352&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/09/23/ruby-on-rails-bedtime-stories/feed/</wfw:commentRss>
		<slash:comments>17</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>Improvements to the iPhoto Export app</title>
		<link>http://ilikestuffblog.com/2010/09/04/improvements-to-the-iphoto-export-app/</link>
		<comments>http://ilikestuffblog.com/2010/09/04/improvements-to-the-iphoto-export-app/#comments</comments>
		<pubDate>Sat, 04 Sep 2010 17:51:51 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=346</guid>
		<description><![CDATA[In July I blogged about the script Derrick Childers wrote to export iPhoto events to folders. Yesterday, Mark Nottingham made some improvements to the script. The best change is that you can now pass in parameters on the command line instead of modifying the script to change the parameters. I&#8217;ve pulled his changes into the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=346&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In July I blogged about the script Derrick Childers wrote to <a href="http://ilikestuffblog.com/2010/07/07/export-your-iphoto-library-to-a-folder-structure/">export iPhoto events to folders</a>. Yesterday, <a href="http://github.com/mnot">Mark Nottingham</a> made some improvements to the script. The best change is that you can now pass in parameters on the command line instead of modifying the script to change the parameters.</p>
<p>I&#8217;ve pulled his changes into <a href="http://github.com/BMorearty/exportiphoto">the script on my github repo</a>. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/346/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/346/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/346/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=346&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/09/04/improvements-to-the-iphoto-export-app/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>Announcing ilikestuffblog.com</title>
		<link>http://ilikestuffblog.com/2010/08/02/announcing-ilikestuffblog-com/</link>
		<comments>http://ilikestuffblog.com/2010/08/02/announcing-ilikestuffblog-com/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 08:15:04 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ilikestuffblog.com/?p=342</guid>
		<description><![CDATA[After being hosted for a couple of years at a subdomain of WordPress.com, my &#8220;I like stuff&#8221; blog finally has its own custom domain. Announcing: http://ilikestuffblog.com<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=342&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>After being hosted for a couple of years at a subdomain of WordPress.com, my &#8220;I like stuff&#8221; blog finally has its own custom domain.</p>
<p>Announcing: <a href="http://ilikestuffblog.com">http://ilikestuffblog.com</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/342/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=342&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/08/02/announcing-ilikestuffblog-com/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>Export Your iPhoto Library to a Folder Structure</title>
		<link>http://ilikestuffblog.com/2010/07/07/export-your-iphoto-library-to-a-folder-structure/</link>
		<comments>http://ilikestuffblog.com/2010/07/07/export-your-iphoto-library-to-a-folder-structure/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 06:26:59 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=326</guid>
		<description><![CDATA[I wanted to export my iPhoto library to a folder structure and was disappointed to see that iPhoto has no built-in way to do it. I found a nice little script written by Derrick Childers (scroll down to his comment; don&#8217;t use the original shell script) that did almost exactly what I needed. Derrick&#8217;s original [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=326&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I wanted to <a href="http://github.com/BMorearty/exportiphoto">export my iPhoto library to a folder structure</a> and was disappointed to see that iPhoto has no built-in way to do it.</p>
<p>I found a <a href="http://www.macosxhints.com/article.php?story=20081108132735425">nice little script written by Derrick Childers</a> (scroll down to his comment; don&#8217;t use the original shell script) that did almost exactly what I needed. Derrick&#8217;s original version exported all events by year, except it didn&#8217;t work in all cases because it was based on the year of the photo&#8217;s filestamp, which might be different than the year it was taken (e.g. if you went back to retouch a photo). Guillaume Boudreau added support for exporting albums and removed the year folder because it didn&#8217;t work well, but I put it back and fixed the it to generate the year based on the event date.</p>
<p>(Update: I changed it to generate more than just the year. I generate the entire date of the event, followed by the event name.)</p>
<p>I tested it with:</p>
<ul>
<li>Leopard 10.5.8</li>
<li>Python 2.5.1</li>
<li>iPhoto 8.1.2</li>
</ul>
<p>Derrick tested his original with:</p>
<ul>
<li>Snow Leopard 10.6.2</li>
<li>Python 2.6.1</li>
<li>iPhoto 8.1.1</li>
</ul>
<p>I&#8217;ve <a href="http://github.com/BMorearty/exportiphoto">posted it to Github</a>. Feel free to fork and modify to your taste.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/326/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/326/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/326/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=326&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/07/07/export-your-iphoto-library-to-a-folder-structure/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 Truncate a Ruby Time Down to the Second, Minute, Hour, or Day</title>
		<link>http://ilikestuffblog.com/2010/05/18/how-to-truncate-a-ruby-time-down-to-the-second-minute-hour-or-day/</link>
		<comments>http://ilikestuffblog.com/2010/05/18/how-to-truncate-a-ruby-time-down-to-the-second-minute-hour-or-day/#comments</comments>
		<pubDate>Tue, 18 May 2010 15:52:14 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=312</guid>
		<description><![CDATA[Sometimes you have a Time or DateTime object in Ruby and you want to zero out the milliseconds, seconds, minutes, or hours. And if you&#8217;re zeroing out a larger element like minutes, you&#8217;d like it to automatically zero out the smaller elements like seconds and milliseconds too. It turns out ActiveSupport extends Time and DateTime [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=312&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes you have a Time or DateTime object in Ruby and you want to zero out the milliseconds, seconds, minutes, or hours. And if you&#8217;re zeroing out a larger element like minutes, you&#8217;d like it to automatically zero out the smaller elements like seconds and milliseconds too.</p>
<p>It turns out ActiveSupport extends Time and DateTime with a method to do this: <tt><a href="http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Calculations.html#M001138">change</a></tt>. As the documentation says, &#8220;The time options (hour, minute, sec, usec) reset cascadingly, so if only the hour is passed,  then minute, sec, and usec is set to 0. If the hour and minute is passed,  then sec and usec is set to 0.&#8221;</p>
<p>To truncate a Time to the second, minute, hour, or day:</p>
<p><pre class="brush: ruby;">
  time.change(:usec =&gt; 0) # zero out milliseconds
  time.change(:sec =&gt; 0)  # zero out seconds, milliseconds
  time.change(:min =&gt; 0)  # zero out mins, secs, &amp; usecs
  time.change(:hour =&gt; 0) # zero out hrs, mins, secs, usecs
</pre></p>
<p>To truncate a DateTime to the minute, hour, or day:</p>
<p><pre class="brush: ruby;">
  datetime.change(:sec =&gt; 0)  # zero out seconds
  datetime.change(:min =&gt; 0)  # zero out mins and secs
  datetime.change(:hour =&gt; 0) # zero out hrs, mins, secs
</pre></p>
<p>Sensibly, changing the year, month, or day of a DateTime does not reset the lower elements to zero.</p>
<p>ActiveSupport also adds the <tt>change</tt> method to Date, but since the only elements are year, month, and day, it never zeroes out the smaller elements when you set a larger element.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/312/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/312/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/312/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/312/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/312/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/312/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/312/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/312/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=312&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/05/18/how-to-truncate-a-ruby-time-down-to-the-second-minute-hour-or-day/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>Action-Oriented Programming and The History of HTML</title>
		<link>http://ilikestuffblog.com/2010/05/05/action-oriented-programming-and-the-history-of-html/</link>
		<comments>http://ilikestuffblog.com/2010/05/05/action-oriented-programming-and-the-history-of-html/#comments</comments>
		<pubDate>Wed, 05 May 2010 16:23:34 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=305</guid>
		<description><![CDATA[I just read a fascinating history of HTML, up to HTML5 by Mark Pilgrim. One sentence keeps repeating in this essay: &#8220;The proposal was never implemented.&#8221; Pilgrim&#8217;s point is that shipping software wins over specs and ideas. Or in his words, &#8220;The ones that win are the ones that ship.&#8221; (Although he points out that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=305&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just read a fascinating <a title="history of HTML" href="http://diveintohtml5.org/past.html">history of HTML, up to HTML5</a> by Mark Pilgrim.</p>
<p>One  sentence keeps repeating in this essay:</p>
<blockquote><p>&#8220;The proposal was never implemented.&#8221;</p></blockquote>
<p>Pilgrim&#8217;s point is that shipping software wins over specs and ideas. Or in his words, &#8220;The ones that win are the ones that ship.&#8221; (Although he points  out that shipping code is necessary but not sufficient for success.) A number of times HTML was &#8220;retro-specced&#8221; to match what had already been implemented.</p>
<p>I like that. In 2006 I coined the term &#8220;<a href="http://discuss.joelonsoftware.com/default.asp?biz.5.378629.21">Action-Oriented Programming</a>&#8221; on a Joel on Software discussion board:</p>
<blockquote><p>Regarding motivation to get started implementing a product idea once you  have one:</p>
<p>Whatever you do, do something.</p>
<p>Us  programmers, we tend to overanalyze things. Lots of up-front design,  trying to decide if it&#8217;s the right thing to do, not sure if we have  enough education yet, etc. But from what I&#8217;ve read about successful  entrepreneurs, they are DOERS. They&#8217;re Action-Oriented.</p>
<p>So I&#8217;m  inventing a new term:</p>
<p style="padding-left:30px;"><strong>Action-Oriented Programming</strong>: writing the  damn program instead of thinking about writing it.</p>
</blockquote>
<p>The HTML spec evolved through Action-Oriented Programming. Read the History of HTML essay and you&#8217;ll see why.</p>
<p>P.S. Hey, I know I didn&#8217;t invent the idea of favoring working code over detailed specs. But I like the name I gave it. :-) I&#8217;m pleased to see that Action-Oriented Programming has become popular with the rise of agile techniques and &#8220;Getting Real.&#8221;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/305/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/305/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/305/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=305&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/05/05/action-oriented-programming-and-the-history-of-html/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 Funniest April Fool&#8217;s Joke of This Year</title>
		<link>http://ilikestuffblog.com/2010/04/09/the-funniest-april-fools-joke-of-this-year/</link>
		<comments>http://ilikestuffblog.com/2010/04/09/the-funniest-april-fools-joke-of-this-year/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 13:04:31 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Funny]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=298</guid>
		<description><![CDATA[If you love Ruby (like me) and think Java is a horrible language (also like me) you may agree that this is the funniest April Fool&#8217;s joke of this year.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=298&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you love Ruby (like me) and think Java is a horrible language (also like me) you may agree that <a href="http://reprog.wordpress.com/2010/04/01/early-experiments-with-jruby/">this is the funniest April Fool&#8217;s joke of this year</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/298/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/298/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/298/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=298&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/04/09/the-funniest-april-fools-joke-of-this-year/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>Two Tools to Make Irb Better</title>
		<link>http://ilikestuffblog.com/2010/04/03/two-tools-to-make-irb-better/</link>
		<comments>http://ilikestuffblog.com/2010/04/03/two-tools-to-make-irb-better/#comments</comments>
		<pubDate>Sat, 03 Apr 2010 16:14:59 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=290</guid>
		<description><![CDATA[Here are two gems I love because they make Irb better. Looksee: Clearly Show an Object&#8217;s Methods In Irb when you want to show an object&#8217;s methods you might do something like this: But you end up with a massive list of methods that includes all methods&#8211;public, private, and protected&#8211;from the bottom-most class up the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=290&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Here are two gems I love because they make Irb better.</p>
<h4>Looksee: Clearly Show an Object&#8217;s Methods</h4>
<p>In Irb when you want to show an object&#8217;s methods you might do something like this:</p>
<p><pre class="brush: ruby;">

&gt;&gt; print obj.methods.sort.join(&quot;\n&quot;)

</pre></p>
<p>But you end up with a massive list of methods that includes all methods&#8211;public, private, and protected&#8211;from the bottom-most class up the class and module chain to Object.</p>
<p>Enter Looksee.</p>
<p><pre class="brush: ruby;">
&gt;&gt; require 'looksee'
&gt;&gt; lp obj
</pre></p>
<p>Now all of obj&#8217;s methods are shown color-formatted (to distinguish among public, private, and protected) and grouped by where they appear in the class and module hierarchy. It&#8217;s a lot easier to find what you&#8217;re looking for.</p>
<p><a href="http://github.com/oggy/looksee">Get Looksee here</a>.</p>
<h4>Awesome_print: Better than Pretty_print or YAML::dump</h4>
<p>Here&#8217;s one I just learned about today. Often in Irb you want to dump an object to the console to see its attributes. And if you just &#8220;print&#8221; it the output is hard to read. You may be familiar with pretty_print and YAML::dump as alternatives to make the dump output easier to read. Between those two I prefer YAML::dump because it outputs an attribute on each line so it&#8217;s easier to scan the list.</p>
<p>But awesome_print is easier still. The output is nicely indented, formatted, and colorized. When dumping an Array it includes the index number in [brackets] before each element. The index number itself isn&#8217;t so important but it shows it in white so it&#8217;s easier to find the separation between array elements.</p>
<p><a href="http://github.com/michaeldv/awesome_print">Get Awesome_print here</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/290/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/290/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/290/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=290&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/04/03/two-tools-to-make-irb-better/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>First Impressions of the Go Language</title>
		<link>http://ilikestuffblog.com/2010/03/01/first-impressions-of-the-go-language/</link>
		<comments>http://ilikestuffblog.com/2010/03/01/first-impressions-of-the-go-language/#comments</comments>
		<pubDate>Mon, 01 Mar 2010 19:23:02 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=285</guid>
		<description><![CDATA[On the weekend while I was stuck in traffic trying to take my son to his (and my) first monster truck jam, I listened to this podcast about the Go language. It helped me understand why Google would invent a new language. Then I looked at the language spec a bit. Here are some first [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=285&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>On the weekend while I was stuck in traffic trying to take my son to his (and my) first monster truck jam, I listened to this <a href="http://changelogshow.com/105/1861-episode-0-0-3-google-s-go-programming-language" target="_blank">podcast about the Go language</a>. It helped me  understand why Google would invent a new language. Then I looked at the language spec a bit.</p>
<p>Here are some first impressions. I&#8217;ve only read lightly about the language so please correct me if anything is factually incorrect.</p>
<p>I&#8217;m not  super-pumped about using Go, but if I were still using C/C++ every day I probably would be. I now think of Go as C (runs about as fast as C, strongly typed,  compiled, pointers) but with a few especially nice enhancements:</p>
<ul>
<li>garbage collected (yay!)</li>
<li>memory-safe &#8211; the pointers can&#8217;t go  out of bounds and I think arrays also can&#8217;t go out of bounds if you use  &#8220;slices&#8221;</li>
<li><a href="http://www.youtube.com/watch?v=wwoWei-GAPo" target="_blank"><em>extremely </em>fast compiles</a>.</li>
</ul>
<p>It is missing some of the things I like about C++. E.g.,</p>
<ul>
<li>You can&#8217;t use integers or pointers as Boolean expressions</li>
<li>I don&#8217;t think it has a convenient syntax for  getters+setters with a default backing variable, like Property in C# or attr_accessor in Ruby. (It bugs me how verbose Java is when creating simple bean properties. I hope Go will avoid this problem.)</li>
<li>I don&#8217;t yet see a way to do automatic cleanup when a variable goes out of scope&#8211;a feature of C++, C#, and Ruby that I love because it helps reduce code duplication and add robustness</li>
</ul>
<p>It appears not to be OO, at least not in the way we&#8217;re used  to. It doesn&#8217;t have classes but it does have interfaces. It seems like  if you want to make a class you define an interface and then create an  instance of it. It doesn&#8217;t have traditional inheritance but it does have &#8220;embedding,&#8221; which is a nice alternative. If you embed someone else&#8217;s implementation of an interface into your type, your type now exposes that implementation without having to delegate all the methods one by one.</p>
<p>Lately I&#8217;ve been into Ruby, which has different strengths than Go. But if I were to start doing systems-level programming again and needed a good mix of raw performance and garbage collection I would definitely give Go a close look.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/285/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/285/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/285/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=285&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2010/03/01/first-impressions-of-the-go-language/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>Now you can use obj.in?(array) instead of array.include?(obj)</title>
		<link>http://ilikestuffblog.com/2009/12/24/now-you-can-use-obj-inarray-instead-of-array-includeobj/</link>
		<comments>http://ilikestuffblog.com/2009/12/24/now-you-can-use-obj-inarray-instead-of-array-includeobj/#comments</comments>
		<pubDate>Thu, 24 Dec 2009 08:48: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=269</guid>
		<description><![CDATA[I just wrote a tiny gem called in_enumerable. It extends Ruby&#8217;s Object type with the tasty &#8216;in?&#8217; method, which returns true if an object is included in a list or other enumerable value. So you can do this: instead of the slightly more awkward: Despite its name, in_enumerable doesn&#8217;t require an enumerable type.  It uses [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=269&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I just wrote a tiny gem called <a href="http://github.com/BMorearty/in_enumerable">in_enumerable</a>. It extends Ruby&#8217;s Object type with the tasty &#8216;in?&#8217; method, which returns true if an object is included in a list or other enumerable value.</p>
<p>So you can do this:</p>
<p><pre class="brush: ruby;">

1.in? [1,2]          # =&gt; true
3.in? [1,2]          # =&gt; false

</pre></p>
<p>instead of the slightly more awkward:</p>
<p><pre class="brush: ruby;">

[1,2].include?(1)    # =&gt; true
[1,2].include?(3)    # =&gt; false

</pre></p>
<p>Despite its name, in_enumerable doesn&#8217;t require an enumerable type.  It uses duck typing to work with any type that has an &#8216;include?&#8217; method, such as Array, Hash, String, Range, Set, and even Module.</p>
<h4>Installation</h4>
<p><pre class="brush: bash;">

gem install in_enumerable

</pre></p>
<h4>Usage</h4>
<p><pre class="brush: ruby;">

require 'rubygems'
require 'in_enumerable'

</pre></p>
<h4>Side Note</h4>
<p>I noticed that typing <tt>ri Object#in?</tt> reveals that a similar method <em>supposedly </em>already exists on the Object type. And if you google it you can find the source code for it. (It&#8217;s almost the same as mine.) But it doesn&#8217;t actually seem to be implemented, at least not in Ruby 1.8.6. So I made my own.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/269/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/269/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/269/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=269&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2009/12/24/now-you-can-use-obj-inarray-instead-of-array-includeobj/feed/</wfw:commentRss>
		<slash:comments>6</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>2 Cool Ways to Call Google Analytics from Rails Apps</title>
		<link>http://ilikestuffblog.com/2009/12/14/2-cool-ways-to-call-google-analytics-from-rails-apps/</link>
		<comments>http://ilikestuffblog.com/2009/12/14/2-cool-ways-to-call-google-analytics-from-rails-apps/#comments</comments>
		<pubDate>Tue, 15 Dec 2009 06:17:12 +0000</pubDate>
		<dc:creator>Brian Morearty</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://bmorearty.wordpress.com/?p=266</guid>
		<description><![CDATA[I Like Stuff That&#8217;s Tracked I just read two great suggestions for using Google Analytics to track page views in places where it might normally be hard: How to track a goal that doesn&#8217;t end in a unique page. E.g., where the goal is the &#8220;Show&#8221; page in a RESTful app, but you only want [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=266&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h4>I Like Stuff That&#8217;s Tracked</h4>
<p>I just read two great suggestions for using Google Analytics to track page views in places where it might normally be hard:</p>
<ol>
<li><a href="http://blog.scoutapp.com/articles/2009/10/27/rails-google-analytics-easy-goal-tracking">How to track a goal that doesn&#8217;t end in a unique page.</a> E.g., where the goal is the &#8220;Show&#8221; page in a RESTful app, but you only want Google to track a goal conversion when you get there through the &#8220;create&#8221; action.</li>
<li><a href="http://www.robbyonrails.com/articles/2009/10/21/tracking-ajax-driven-events-in-ruby-on-rails-for-google-analytics-conversion-goals">How to track a goal that is reached via AJAX</a> instead of via a full page refresh.</li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/bmorearty.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/bmorearty.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/bmorearty.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/bmorearty.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/bmorearty.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/bmorearty.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/bmorearty.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/bmorearty.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/bmorearty.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/bmorearty.wordpress.com/266/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/bmorearty.wordpress.com/266/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/bmorearty.wordpress.com/266/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=266&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2009/12/14/2-cool-ways-to-call-google-analytics-from-rails-apps/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>How to Distinguish a User-Aborted AJAX Call from an Error</title>
		<link>http://ilikestuffblog.com/2009/11/30/how-to-distinguish-a-user-aborted-ajax-call-from-an-error/</link>
		<comments>http://ilikestuffblog.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[JavaScript]]></category>
		<category><![CDATA[jQuery]]></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: But you start using your app and you notice that your [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=255&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<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>
<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>
<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>
<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>
<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>
<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/255/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/255/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=255&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2009/11/30/how-to-distinguish-a-user-aborted-ajax-call-from-an-error/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>How to Put Rewrite Rules in Your Ruby Code, Not Your Web Server</title>
		<link>http://ilikestuffblog.com/2009/11/04/put-mod_rewrite-in-your-ruby-code-not-your-web-server/</link>
		<comments>http://ilikestuffblog.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 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=228&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<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>
<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/228/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/228/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=228&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2009/10/08/define-your-own-custom-service-token-for-oauth/</link>
		<comments>http://ilikestuffblog.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 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=216&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/216/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/216/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=216&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2009/07/21/intuit-community-makes-business-week/</link>
		<comments>http://ilikestuffblog.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=ilikestuffblog.com&amp;blog=3470316&amp;post=213&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/213/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/213/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=213&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2009/07/20/to_json-as_json/</link>
		<comments>http://ilikestuffblog.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=ilikestuffblog.com&amp;blog=3470316&amp;post=211&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/211/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/211/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=211&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2009/07/20/to_json-as_json/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>The Javafication of Ruby on Rails</title>
		<link>http://ilikestuffblog.com/2009/05/21/the-javafication-of-ruby-on-rails/</link>
		<comments>http://ilikestuffblog.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 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=201&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<p><pre class="brush: ruby;">
my_model.to_json
</pre></p>
<p>we are now encouraged to do this:</p>
<p><pre class="brush: ruby;">
ActiveSupport::json.encode(my_model)
</pre></p>
<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>
<p><pre class="brush: ruby;">
ClassOrModule::namespacey_function.method_name(obj)
</pre></p>
<p>please pause and consider whether the users of your API would find it easier if you instead made it look like this:</p>
<p><pre class="brush: ruby;">
obj.method_name
</pre></p>
<p>Thanks!</p>
<br />  <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/gofacebook/bmorearty.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/201/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/201/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=201&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2009/04/26/dataflow-erlang-style-thread-safety-in-ruby/</link>
		<comments>http://ilikestuffblog.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=ilikestuffblog.com&amp;blog=3470316&amp;post=182&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<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></p>
<p><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></p>
<p><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>
<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/182/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/182/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=182&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2009/04/15/listen-to-my-interview-on-the-ruby-on-rails-podcast/</link>
		<comments>http://ilikestuffblog.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=ilikestuffblog.com&amp;blog=3470316&amp;post=178&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/178/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/178/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=178&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2009/04/02/link-to-remote-with-seo/</link>
		<comments>http://ilikestuffblog.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=ilikestuffblog.com&amp;blog=3470316&amp;post=141&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<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>
<p>Produces (pay attention to the href attrbute):</p>
<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>
<p>In  the controller (home.rb), render just the partial if called in an XHR (AJAX) request:</p>
<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></p>
<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/141/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=141&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2009/04/01/obfuscated-actionscript/</link>
		<comments>http://ilikestuffblog.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=ilikestuffblog.com&amp;blog=3470316&amp;post=134&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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=450" alt="getset"   /></p>
<br />  <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/gofacebook/bmorearty.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/134/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/134/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=134&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2009/03/22/my-favorite-quotes-from-the-yellowpagescom-ruby-on-rails-talk/</link>
		<comments>http://ilikestuffblog.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=ilikestuffblog.com&amp;blog=3470316&amp;post=128&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=128&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2009/01/15/put-html-tags-and-apostrophes-in-fixtures-and-tests-or-a-meanie-will-hack-you/</link>
		<comments>http://ilikestuffblog.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 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=67&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<p><pre class="brush: ruby;">
test_post:
  id: 1
  subject: &lt;script&gt; attack!
  detail: &quot;sql injection: '; drop table posts;&quot;
</pre></p>
<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>
<p><pre class="brush: ruby;">
  def test_show
    post = posts(:test_post)
    get :show, post.id
    assert_select &quot;body&quot;
  end
</pre></p>
<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>
<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></p>
<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>
<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>
<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/67/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/67/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=67&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2009/01/09/fun-with-rubys-instance_eval-and-class_eval/</link>
		<comments>http://ilikestuffblog.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. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=79&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme-button" id="tweetmeme-button-post-79" style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'>
<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Filikestuffblog.com%2F2009%2F01%2F09%2Ffun-with-rubys-instance_eval-and-class_eval%2Ftweetmeme_alias%3Dhttp%3A%2F%2Fwp.me%2FpeyMQ-1h%26tweetmeme_source%3DBMorearty"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Filikestuffblog.com%2F2009%2F01%2F09%2Ffun-with-rubys-instance_eval-and-class_eval%2F" height="61" width="51" /></a>
</div>
<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>
<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></p>
<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>
<p><pre class="brush: ruby;">
class Fixnum
  def self.ten
    10
  end
end
Fixnum.ten #=&gt; 10
</pre></p>
<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>
<p><pre class="brush: ruby;">
class Fixnum
  def number
    self
  end
end
7.number #=&gt; 7
</pre></p>
<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/79/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/79/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=79&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2009/01/09/fun-with-rubys-instance_eval-and-class_eval/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>Generate guid ids 2100x faster for ActiveRecord models (but only if you use MySQL)</title>
		<link>http://ilikestuffblog.com/2009/01/03/generate-guid-ids-2100x-faster-for-activerecord-models-but-only-if-you-use-mysql/</link>
		<comments>http://ilikestuffblog.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=ilikestuffblog.com&amp;blog=3470316&amp;post=31&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<p><pre class="brush: ruby;">
class MyModel &lt; ActiveRecord::Base
  usesguid
end
</pre></p>
<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>
<p><pre class="brush: ruby;">
ActiveRecord::Base.guid_generator = :mysql
</pre></p>
<p>Here is a sample migration for creating a new table with guids, as opposed to changing an existing one to use them:</p>
<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></p>
<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>
<p><pre class="brush: sql;">
SELECT UUID(), UUID(), UUID(), UUID(), UUID(), ... ;
</pre></p>
<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>
<br />  <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/gofacebook/bmorearty.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=31&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2008/06/18/find-tests-more-easily-in-your-testlog/</link>
		<comments>http://ilikestuffblog.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 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=19&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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=450" alt="test.log without titles"   /></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=450" alt="test.log with titles"   /></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>
<p><pre class="brush: ruby;">
class ActiveSupport::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>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>
<p><strong>Updated 2/26/10</strong>: I changed Test::Unit::TestCase to ActiveSupport::TestCase.</p>
<br /><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/gofacebook/bmorearty.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=19&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2008/06/18/find-tests-more-easily-in-your-testlog/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>

		<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://ilikestuffblog.com/2008/05/21/how-to-show-response-time-in-a-rails-page-with-mongrel/</link>
		<comments>http://ilikestuffblog.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 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=9&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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=450" alt=""   /></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>
<p><pre class="brush: ruby;">
  def initialize(options={})
    @request_notify = true
  end
</pre></p>
<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>
<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>
<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>
<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>
<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>
<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></p>
<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>
<p><pre class="brush: xml;">&lt;span id=&quot;response_time&quot;&gt;&lt;span&gt;</pre></p>
<p>In the handler I look for this in the response string and replace it with something like:</p>
<p><pre class="brush: xml;">&lt;span id=&quot;response_time&quot;&gt;(0.15 seconds)&lt;span&gt;</pre></p>
<p>Wherever I want to show the response time in a page I do this:</p>
<p><pre class="brush: ruby;">&lt;%= render :partial =&gt; &quot;shared/response_time&quot; %&gt;</pre></p>
<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>
<p><pre class="brush: xml;">  &lt;span id=&quot;response_time&quot;&gt;               &lt;/span&gt;</pre></p>
<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>
<p><pre class="brush: ruby;">page.replace &quot;response_time&quot;,
  '&lt;span id=&quot;response_time&quot;&gt;               &lt;/span&gt;'</pre></p>
<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>
<p><pre class="brush: xml;">&lt;span id=&quot;response_time&quot;&gt;               &lt;/span&gt;</pre></p>
<p>the output has all the special characters quoted, so the handler has to search for:</p>
<p><pre class="brush: xml;">\74span id=\\&quot;response_time\\&quot;\76               \74/span\76</pre></p>
<p>I also noticed that on newer versions of Rails, at least on my friend&#8217;s Mac, the response was in Unicode:</p>
<p><pre class="brush: xml;">\\u003Cspan id=\\&quot;response_time\\&quot;\\u003E               \\u003C/span\\u003E</pre></p>
<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>
<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></p>
<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=450" alt=""   /></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>
<br /><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/gofacebook/bmorearty.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=9&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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://ilikestuffblog.com/2008/04/16/what-is-your-zombie-escape-plan/</link>
		<comments>http://ilikestuffblog.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=ilikestuffblog.com&amp;blog=3470316&amp;post=8&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<br /><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/gofacebook/bmorearty.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/8/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/8/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=8&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2008/04/16/what-is-your-zombie-escape-plan/feed/</wfw:commentRss>
		<slash:comments>22</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://ilikestuffblog.com/2008/04/15/how-to-write-case-switch-statements-in-ruby/</link>
		<comments>http://ilikestuffblog.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 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=5&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme-button" id="tweetmeme-button-post-5" style='float: right; margin-left: 10px; margin-bottom: 5px; padding: 4px 0 2px 4px; background: #fff;'>
<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Filikestuffblog.com%2F2008%2F04%2F15%2Fhow-to-write-case-switch-statements-in-ruby%2Ftweetmeme_alias%3Dhttp%3A%2F%2Fwp.me%2FpeyMQ-5%26tweetmeme_source%3DBMorearty"><img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Filikestuffblog.com%2F2008%2F04%2F15%2Fhow-to-write-case-switch-statements-in-ruby%2F" height="61" width="51" /></a>
</div>
<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>
<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></p>
<br /><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/gofacebook/bmorearty.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=5&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.com/2008/04/15/how-to-write-case-switch-statements-in-ruby/feed/</wfw:commentRss>
		<slash:comments>17</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://ilikestuffblog.com/2008/04/13/hello-world/</link>
		<comments>http://ilikestuffblog.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 [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=ilikestuffblog.com&amp;blog=3470316&amp;post=1&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<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>
<br /><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/gofacebook/bmorearty.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/bmorearty.wordpress.com/1/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/bmorearty.wordpress.com/1/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/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=ilikestuffblog.com&amp;blog=3470316&amp;post=1&amp;subd=bmorearty&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://ilikestuffblog.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>
