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

<channel>
	<title>Cory Forsyth &#187; ruby</title>
	<atom:link href="http://coryforsyth.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://coryforsyth.com</link>
	<description>The Life of Me</description>
	<lastBuildDate>Fri, 04 Jun 2010 22:12:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=1653</generator>
		<item>
		<title>Scotland on Rails videos are up</title>
		<link>http://coryforsyth.com/2009/06/03/scotland-on-rails-videos-are-up/</link>
		<comments>http://coryforsyth.com/2009/06/03/scotland-on-rails-videos-are-up/#comments</comments>
		<pubDate>Wed, 03 Jun 2009 14:43:50 +0000</pubDate>
		<dc:creator>cory</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[travel]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://coryforsyth.com/2009/06/03/scotland-on-rails-videos-are-up/</guid>
		<description><![CDATA[Here&#8217;s mine, from my talk &#8220;Who Needs Photoshop? Creative Image Manipulation in Ruby.&#8221; This was my first time speaking at a conference. Do I look as nervous as I felt? Who Needs Photoshop? at Scotland on Rails from bantic on Vimeo. Engineyard is hosting the rest of the Scotland on Rails videos.]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s mine, from my talk &#8220;Who Needs Photoshop? Creative Image Manipulation in Ruby.&#8221;  This was my first time speaking at a conference. Do I look as nervous as I felt?</p>
<p><object width="400" height="300"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=4943916&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" /><embed src="http://vimeo.com/moogaloop.swf?clip_id=4943916&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1" type="application/x-shockwave-flash" allowfullscreen="true" allowscriptaccess="always" width="400" height="300"></embed></object>
<p><a href="http://vimeo.com/4943916">Who Needs Photoshop? at Scotland on Rails</a> from <a href="http://vimeo.com/user153970">bantic</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<p>Engineyard is hosting the rest of the <a href="http://www.engineyard.com/blog/community/scotland-on-rails/">Scotland on Rails videos</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://coryforsyth.com/2009/06/03/scotland-on-rails-videos-are-up/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>My talk at Scotland On Rails</title>
		<link>http://coryforsyth.com/2009/04/01/my-talk-at-scotland-on-rails/</link>
		<comments>http://coryforsyth.com/2009/04/01/my-talk-at-scotland-on-rails/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 22:58:44 +0000</pubDate>
		<dc:creator>cory</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[travel]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://coryforsyth.com/?p=244</guid>
		<description><![CDATA[I had the opportunity to speak at Scotland on Rails last weekend. My talk was called &#8220;Who Needs Photoshop? Creative Image Manipulation using Ruby.&#8221; It was my first time giving a talk at a serious conference and I really enjoyed myself although I was pretty nervous leading up to it. The conference was one of [...]]]></description>
			<content:encoded><![CDATA[<p>I had the opportunity to speak at Scotland on Rails last weekend.  My talk was called &#8220;<a href="http://scotlandonrails.com/schedule/28-march/who-needs-photoshop-image-manipulation-in-ruby/">Who Needs Photoshop? Creative Image Manipulation using Ruby</a>.&#8221;  It was my first time giving a talk at a serious conference and I really enjoyed myself although I was pretty nervous leading up to it.  The conference was one of the best I&#8217;ve been to. Great talks and really great, friendly people.  I have a very high opinion of Scottish people. They&#8217;re a really amiable bunch.  I hope to get back there next year.</p>
<p>Here are the slides. When the video becomes available I&#8217;ll put up a link to it. <b>Update</b>: The videos are now available. Here&#8217;s <a href="http://coryforsyth.com/2009/06/03/scotland-on-rails-videos-are-up/">me talking</a>.<br />
<a title="View Cory Forsyth Image Manipulation on Scribd" href="http://www.scribd.com/doc/13867909/Cory-Forsyth-Image-Manipulation" style="margin: 12px auto 6px auto; font-family: Helvetica,Arial,Sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 14px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; display: block; text-decoration: underline;">Cory Forsyth Image Manipulation</a> <object codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" id="doc_833760097806811" name="doc_833760097806811" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" align="middle"	height="500" width="100%" ><param name="movie"	value="http://d.scribd.com/ScribdViewer.swf?document_id=13867909&#038;access_key=key-2hqk720fxnfnut11vyl5&#038;page=1&#038;version=1&#038;viewMode="><param name="quality" value="high"><param name="play" value="true"><param name="loop" value="true"><param name="scale" value="showall"><param name="wmode" value="opaque"><param name="devicefont" value="false"><param name="bgcolor" value="#ffffff"><param name="menu" value="true"><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><param name="salign" value=""><embed src="http://d.scribd.com/ScribdViewer.swf?document_id=13867909&#038;access_key=key-2hqk720fxnfnut11vyl5&#038;page=1&#038;version=1&#038;viewMode=" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" play="true" loop="true" scale="showall" wmode="opaque" devicefont="false" bgcolor="#ffffff" name="doc_833760097806811_object" menu="true" allowfullscreen="true" allowscriptaccess="always" salign="" type="application/x-shockwave-flash" align="middle"  height="500" width="100%"></embed></object>
<div style="margin: 6px auto 3px auto; font-family: Helvetica,Arial,Sans-serif; font-style: normal; font-variant: normal; font-weight: normal; font-size: 12px; line-height: normal; font-size-adjust: none; font-stretch: normal; -x-system-font: none; display: block;">    <a href="http://www.scribd.com/upload" style="text-decoration: underline;">Publish at Scribd</a> or <a href="http://www.scribd.com/browse" style="text-decoration: underline;">explore</a> others:            <a href="http://www.scribd.com/browse/Presentations-Slideshows/" style="text-decoration: underline;">Presentations &#038; Slid</a>                  <a href="http://www.scribd.com/tag/ruby" style="text-decoration: underline;">ruby</a>              <a href="http://www.scribd.com/tag/edgedetection" style="text-decoration: underline;">edgedetection</a>      	</div>
]]></content:encoded>
			<wfw:commentRss>http://coryforsyth.com/2009/04/01/my-talk-at-scotland-on-rails/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Creating Dynamic Adium Away Messages with Ruby and Applescript</title>
		<link>http://coryforsyth.com/2008/10/21/creating-dynamic-adium-away-messages-with-ruby-and-applescript/</link>
		<comments>http://coryforsyth.com/2008/10/21/creating-dynamic-adium-away-messages-with-ruby-and-applescript/#comments</comments>
		<pubDate>Wed, 22 Oct 2008 02:41:07 +0000</pubDate>
		<dc:creator>cory</dc:creator>
				<category><![CDATA[projects]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://coryforsyth.com/2008/10/21/creating-dynamic-adium-away-messages-with-ruby-and-applescript/</guid>
		<description><![CDATA[I was messing around with Adium the other day and noticed that if you right-click while writing a custom away message a context menu comes up with an option to &#8220;Insert Script >&#8221;. Any time I see a script in use somewhere, I wonder what interesting thing I could do with Ruby. So, since it&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>I was messing around with <a href="http://www.adiumx.com/">Adium</a> the other day and noticed that if you right-click while writing a custom away message a context menu comes up with an option to &#8220;Insert Script >&#8221;.  Any time I see a script in use somewhere, I wonder what interesting thing I could do with Ruby.  So, since it&#8217;s that time of year, I created a script that shows Obama&#8217;s current lead (or deficit) in the polls on a state-by-state basis.  An example dynamically created message is: &#8220;In WA, Obama currently leads by 10.3. [source: RealClearPolitics ].&#8221;</p>
<p>I learned the nuts and bolts of how to add these scripts from <a href='http://schinckel.net/2005/08/15/adium-plugin-scripts/'>Paint the Tiger, Carve the Dragon</a>.  Basically, you need to create an Applescript that has a &#8220;substitute()&#8221; function, put it in &#8220;/Applications/Adium.app/Contents/Resources/Scripts/System Statistics.AdiumScripts/&#8221;, and then edit the Info.plist file (at the same path) to contain the necessary information to tell Adium what to call your script, when to invoke it (what &#8220;%_&#8221; string to use), and the filename of the script.</p>
<p>Since I wanted to do some network calls and some fairly complicated parsing of those results, I delegated the heavy lifting to a Ruby script and had the Applescript simply execute that ruby script as a shell script.  To use the script yourself, unzip <a href='http://coryforsyth.com/wordpress/wp-content/uploads/2008/10/politics-in-your-adium.zip' title='politics in your adium'>this file</a>.  It contains an applescript called Politics.scpt and a directory called &#8220;politics&#8221; that includes the &#8220;politics.rb&#8221; ruby script.  Copy both the applescript and the &#8220;politics&#8221; directory to &#8220;/Applications/Adium.app/Contents/Resources/Scripts/System Statistics.AdiumScripts/&#8221;.<br />
You may want to try running the politics.rb file directly to ensure that it will work and you have all the dependencies you need.  If anything&#8217;s awry, you&#8217;re probably missing the ruby gems hpricot or open-uri.  The commands &#8220;sudo gem install hpricot&#8221; and &#8220;sudo gem install open-uri&#8221; should fix that.</p>
<p>Then edit the Info.plist file in the above directory, adding the text:</p>
<pre>
&lt;dict&gt;
   &lt;key&gt;File&lt;/key&gt;
   &lt;string&gt;Politics&lt;/string&gt;
   &lt;key&gt;Keyword&lt;/key&gt;
   &lt;string&gt;%_politics&lt;/string&gt;
   &lt;key&gt;Title&lt;/key&gt;
   &lt;string&gt;Obama Politics update&lt;/string&gt;
&lt;/dict&gt;
</pre>
<p>Now, after you restart Adium, you should have the &#8220;Obama Politics update&#8221; option in your &#8220;Insert Script&#8221; menu when writing your custom away message. Just typing in <b>%_politics</b> directly should work as well.  I don&#8217;t know how to control Adium&#8217;s refresh rate on the script, it seems to refresh every 15-30 seconds on its own.</p>
]]></content:encoded>
			<wfw:commentRss>http://coryforsyth.com/2008/10/21/creating-dynamic-adium-away-messages-with-ruby-and-applescript/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>notes from GoRuCo2008</title>
		<link>http://coryforsyth.com/2008/04/26/notes-from-goruco2008/</link>
		<comments>http://coryforsyth.com/2008/04/26/notes-from-goruco2008/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 20:37:44 +0000</pubDate>
		<dc:creator>cory</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://coryforsyth.com/2008/04/26/notes-from-goruco2008/</guid>
		<description><![CDATA[I&#8217;m seeing a lot of interesting stuff at GoRuCo and I was going to start taking notes in textmate but I decided to just put them here on my blog instead. Chris Wanstrath, parse tree Sake, rake tasks that you can use between different projects. Cheat &#8212; command line interface for looking up documentation. Like [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m seeing a lot of interesting stuff at GoRuCo and I was going to start taking notes in textmate but I decided to just put them here on my blog instead.</p>
<h2>Chris Wanstrath, parse tree</h2>
<ul>
<li><a href='http://errtheblog.com/posts/60-sake-bomb'>Sake</a>, rake tasks that you can use between different projects.</li>
<li><a href='http://cheat.errtheblog.com/'>Cheat</a> &#8212; command line interface for looking up documentation. Like &#8216;man&#8217; for ruby and rails methods.</li>
<li><a href='http://www.ohloh.net/projects/3588'>Ruby2Ruby</a> (I can&#8217;t find the official homepage, that&#8217;s a placeholder).  Looks very cool, but I am not 100% sure what it does other than self-document (?) your ruby code with ruby code. I have to play with this to figure it out.</li>
<li><a href='http://segment7.net/projects/ruby/drb/rinda/ringserver.html'>RingServer</a>, <a href='http://seattlerb.rubyforge.org/RingyDingy/'>RingyDingy</a> &#8212; a way to do mapreduce type stuff using drb in ruby. I wonder if we can use this for tasks at outside.in</li>
</ul>
<h2>Ryan Davis, Hurting Code For Fun and Profit</h2>
<ul>
<li>Code-writing ability increases non-linearly when you become a Ruby sadist/asceticist</li>
<li>coined a new term: menturbating/mentorbating</li>
<li>&#8220;Introspection-driven development&#8221;</li>
<li>self-improvement: read 1 nerd book/month (12x the industry avg). <a href='http://c2.com'> c2.com </a>, read 10-20ish smart blogs</li>
<li>ignorance is not bliss.  <a href='http://www.zenspider.com/RWD/Thoughts/Inept.html'>NYT article by Erica Goode</a></li>
<li>wtf, coding horror and other idiot forums, trim the blogs in your newsreader, focus</li>
<li>important/not-important, urgent/not-urgent.  these form a quadrant. push towards important. the not-important and not-urgent stuff are useful at times, too, for fighting burnout. via 7 habits of highly effective people by covey.  &#8220;do you want to be right, or do you want to be effective?&#8221;</li>
<li>study something non-coding-oriented.  push yourself. write more code, lots of it. junk code. write stuff to figure something out. quantity can be greater than quality (sometimes)</li>
<li>â€œThe function of the overwhelming majority of your artwork<br />
is simply to teach you how to make the small fraction<br />
of your artwork that soars.â€ from: â€œArt &#038; Fearâ€ </li>
<li>Don&#8217;t be a sheep. challenge the status quo.  Feel. Let your emotions flow. Have an opinion (but dont be an asshole).</li>
<li>zentest, flog (complexity reported based on ABC metric, correlates to testing complexity. the scores are important relative to each other, not absolutely) &#038;  heckle &#8212; (love of good dev tools)</li>
<li>vlad and image_science &#8212; (hate of complex code)</li>
<li>use feedback. ask for it. listen to it. feed the feedback back. constantly refine.</li>
<li>find your balance. between 0-100% action and 0-100% thought is your sweet spot. find that balance an dyou&#8217;ll be most of effective.</li>
<li>ryan hates inject &#8212; why? (see the mailing list)</li>
<li>heckle: runs your tests and mutates your implementations to verify that your tests are good. if youre mutated tests still pass after mutation, you missed an edge case</li>
<li>enjoy hurting bad code and you&#8217;ll have less of it over time. eschew complexity.</li>
</ul>
<h2>Paul Dix, Collective Intelligence</h2>
<ul>
<li>Slides are up at <a href='http://pauldix.blogs.com/pauldix/goruco/collective_intelligence.pdf'>paul&#8217;s blog</a></li>
<li>explicit versus implicit data. implicit happens as a result of other actions. scrobbling is an example. explicit makes you make choices (give ratings/grades/stars to things, etc.)</li>
<li>types of recommendations &#8212; content-, user- and item-based.  content is like other content, users are like other users, items are like other items.</li>
<li>basic strategy: map data to a euclidean spaces, calculate similarity using a metric, and use similarities to recommend. represent the data as vectors.</li>
<li>(I discovered <a href='http://www.confreaks.com/'>confreaks</a> just now. cool.  I think goruco vids will be up there later.</li>
</ul>
<h2>Ezra Zygmuntowicz, Merb</h2>
<ul>
<li>Merb looks really cool. I got tired of taking notes here so I just sat back and watched his talk.  Next personal project I do is going to be in Merb.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://coryforsyth.com/2008/04/26/notes-from-goruco2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google App Engine</title>
		<link>http://coryforsyth.com/2008/04/08/google-app-engine/</link>
		<comments>http://coryforsyth.com/2008/04/08/google-app-engine/#comments</comments>
		<pubDate>Tue, 08 Apr 2008 22:40:55 +0000</pubDate>
		<dc:creator>cory</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[web20]]></category>

		<guid isPermaLink="false">http://coryforsyth.com/2008/04/08/google-app-engine/</guid>
		<description><![CDATA[I&#8217;ve really been enjoying messing around with ruby and rails lately and all the new side projects I&#8217;ve been tackling are written in ruby. Trouble is, I can&#8217;t actually launch any of them on the hosting provider that I use, hostgo (not strongly recommended; look elsewhere), because they don&#8217;t let me run rails or ruby. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve really been enjoying messing around with ruby and rails lately and all the new side projects I&#8217;ve been tackling are written in ruby.  Trouble is, I can&#8217;t actually launch any of them on the hosting provider that I use, hostgo (not strongly recommended; look elsewhere), because they don&#8217;t let me run rails or ruby.</p>
<p>I&#8217;d just about decided to find a Rails-ready instance on <a href='http://www.amazon.com/gp/browse.html?node=201590011'>EC2</a> and start deploying my apps there.  Until today.</p>
<p>Today Google App Engine was announced and I spent all morning daydreaming about how I could easily deploy stuff with it, and have a great excuse to play with a new platform to boot.  That is, until I <a href='http://code.google.com/appengine/docs/python/'>read the documentation</a> closely and saw that the sandbox environment runs Python.  Darn.</p>
<p>I&#8217;m still very excited about the idea.  Al3x has a <a href='http://www.al3x.net/2008/04/mulling-on-google-app-engine.html'>good post</a> about the benefits and drawbacks.</p>
<p>It&#8217;s good to see the bar continuing to be lowered.  Used to be that in order to have a blog you had to start an account with a hosting company, register a domain, and install MT or WP.  Now, anyone is about 30 seconds away from a new blog at blogger.  Likewise, if you wanted to create a web app you had to have a hosting account, create a database on it (at least they have an admin panel), and start writing.  Now, with EC2, S3, App Engine, <a href='http://code.google.com/p/scalr/'>Scalr</a> and so on, the hard work of setting up a database and finding a hosting provider is getting further abstracted away.</p>
<p>There are two good things happening here.  App Engine and Scalr and EC2 are making scaling a more manageable problem, but they&#8217;re also first steps in making it really easy to launch an application for the first time, without having to deal with the sysadmin-style stuff.  We&#8217;re closer to being able to write code on your local machine and push a button to deploy it live, no need for setting up an environment on some host, it will all be abstracted for you into the cloud so you can focus on creating something innovative.</p>
<p>We are also seeing more building-block type applications, like Ning, that are trying to abstract away the code-writing in addition to the sysadmin-ing.</p>
<p>There are a lot of people with creative ideas.  And there are some people with the technological fluency to use unix, install databases, and write code.  Innovative startups used to happen at the intersection of those two groups.  These new tools make that second skill set a lot less necessary.  And the first skill set will become a lot more valuable.</p>
]]></content:encoded>
			<wfw:commentRss>http://coryforsyth.com/2008/04/08/google-app-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>checking table existence in Rails&#8217; migrations</title>
		<link>http://coryforsyth.com/2008/03/27/checking-table-existence-in-rails-migrations/</link>
		<comments>http://coryforsyth.com/2008/03/27/checking-table-existence-in-rails-migrations/#comments</comments>
		<pubDate>Thu, 27 Mar 2008 20:24:46 +0000</pubDate>
		<dc:creator>cory</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://coryforsyth.com/2008/03/27/checking-table-existence-in-rails-migrations/</guid>
		<description><![CDATA[I just refactored a table and in the migration I created for it I first need to drop the table and then create it from scratch, so the first line of self.up is drop_table :table_name. But when I go back and forth over that migration, the second time around the table doesn&#8217;t exist (because it [...]]]></description>
			<content:encoded><![CDATA[<p>I just refactored a table and in the migration I created for it I first need to drop the table and then create it from scratch, so the first line of self.up is drop_table :table_name.  But when I go back and forth over that migration, the second time around the table doesn&#8217;t exist (because it got dropped proper in self.down), so I need to check that the table exists before I try to drop it in self.up.</p>
<p>Here&#8217;s the function I created to do that check:<br />
<code></p>
<pre>
 def self.table_exists?(name)
    ActiveRecord::Base.connection.tables.include?(name)
  end
</pre>
<p></code></p>
<p>And here&#8217;s the new first line of self.up:<br />
<code>drop_table :table_name if self.table_exists?("table_name")</code></p>
<p>Clean.</p>
]]></content:encoded>
			<wfw:commentRss>http://coryforsyth.com/2008/03/27/checking-table-existence-in-rails-migrations/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Happy Pi Day</title>
		<link>http://coryforsyth.com/2008/03/14/happy-pi-day/</link>
		<comments>http://coryforsyth.com/2008/03/14/happy-pi-day/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 22:42:28 +0000</pubDate>
		<dc:creator>cory</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://coryforsyth.com/2008/03/14/happy-pi-day/</guid>
		<description><![CDATA[Today is 3/14 (if you&#8217;re using the US way of writing dates), aka Pi Day! A few years ago, Google created a really clever job posting (more here). They put up banners and bought billboards in areas of the country with lots of smart mathematicians, such as Harvard Square in Boston, that said: &#8220;(first 10-digit [...]]]></description>
			<content:encoded><![CDATA[<p>Today is 3/14 (if you&#8217;re using the US way of writing dates), aka Pi Day!</p>
<p>A few years ago, Google created a <a href='http://www.mikexstudios.com/archives/2004/08/12/case-closed-google-challenge/'>really clever job posting</a> (more <a href='http://www.boston.com/news/local/articles/2004/09/09/comprehension_test/'>here</a>).  They put up banners and bought billboards in areas of the country with lots of smart mathematicians, such as Harvard Square in Boston, that said: &#8220;(first 10-digit prime in consecutive digits of pi).com&#8221;.</p>
<p>If you calculate that 10-digit number and combine it with &#8220;.com&#8221; to create a domain name, the website that comes up challenges you to another puzzle.  Eventually, after answering several challenges correctly, you&#8217;re directed to a page that invites you to apply to work at Google. Pretty clever.</p>
<p>I found out about it a few years too late, but took the challenge upon myself anyway and wrote a perl script that calculated the correct answer.  On this Pi Day I am endeavoring to code up a solution again, using my new favorite programming language, Ruby, mostly just for fun but also to see if my abilities have improved any since the last time.  Unfortunately, the blog post I wrote about my perl solution has somehow been lost to the winds of /dev/null, so I can&#8217;t compare the code outright.  But I will say that this time it only took me about 10 minutes to code up this solution:</p>
<p><code>
<pre>
#!/opt/local/bin/ruby

module Prime
  def prime?
    return false if self % 2 == 0 # divisible by 2

    # check odd divisors from 3 to the square root of this number
    (3..(Math.sqrt(self))).step(2) {|i| return false if self % i == 0}

    # didn't find any divisors
    return true
  end
end

# mix the module into the bignum and fixnum classes
class Bignum
  include Prime
end
class Fixnum
  include Prime
end

# digits of pi from http://www.eveandersson.com/pi/digits/
pi_digits_filename = "10000.txt" 

pi_digits = File.open( pi_digits_filename ).read
pi_digits.gsub!("\n","") # strip newlines
pi_digits.gsub!(".","") # remove the "." in 3.14...

# iterate 10-character strings
0.upto(pi_digits.length - 10) do |i|
  num = pi_digits[i,10].to_i
  if num.prime?
    puts num # found it
    break
  end
end
</pre>
<p></code></p>
<p><b>Update</b>: Ok, it appears that the Google challenge was to find that prime in consecutive digits of <b>e</b>, not pi.  Oh well.  Next year I&#8217;ll do this exercise with whatever language is hot on 2/18.</p>
]]></content:encoded>
			<wfw:commentRss>http://coryforsyth.com/2008/03/14/happy-pi-day/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>outside.in switches to rails</title>
		<link>http://coryforsyth.com/2008/02/05/outsidein-switches-to-rails/</link>
		<comments>http://coryforsyth.com/2008/02/05/outsidein-switches-to-rails/#comments</comments>
		<pubDate>Tue, 05 Feb 2008 21:34:25 +0000</pubDate>
		<dc:creator>cory</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[outside.in]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">http://coryforsyth.com/2008/02/05/outsidein-switches-to-rails/</guid>
		<description><![CDATA[I wrote a post for outside.in&#8217;s official blog a few weeks ago detailing some of the troubles and successes (mostly the latter) we encountered when switching over from PHP to Ruby on Rails last fall. It was kind of a herculean task for Christian and I, but has been well worth it so far. Looks [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote a <a href='http://blog.outside.in/2008/01/22/outsidein-switches-to-rails/'>post for outside.in&#8217;s official blog</a> a few weeks ago detailing some of the troubles and successes (mostly the latter) we encountered when switching over from PHP to Ruby on Rails last fall.  It was kind of a herculean task for Christian and I, but has been well worth it so far.  Looks like the post is getting a little traction in the railsy/nerdy community, showing up on <a href='http://www.37signals.com/svn/posts/829-sunspots-the-primitive-edition#extended'>37 Signals&#8217; blog</a> and on <a href='http://news.ycombinator.com/'>Y Combinator Hacker News</a>.</p>
<p>Neat fact: I have a picture of Jason Fried of 37signals holding up a cardboard sign saying &#8220;Go Chronic!&#8221;  (That&#8217;s the nickname for the coding team of Christian and Cory.)</p>
]]></content:encoded>
			<wfw:commentRss>http://coryforsyth.com/2008/02/05/outsidein-switches-to-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>One thing I love about Ruby (vs php)</title>
		<link>http://coryforsyth.com/2008/01/31/one-thing-i-love-about-ruby-vs-php/</link>
		<comments>http://coryforsyth.com/2008/01/31/one-thing-i-love-about-ruby-vs-php/#comments</comments>
		<pubDate>Thu, 31 Jan 2008 18:21:56 +0000</pubDate>
		<dc:creator>cory</dc:creator>
				<category><![CDATA[ruby]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://coryforsyth.com/2008/01/31/one-thing-i-love-about-ruby-vs-php/</guid>
		<description><![CDATA[The case (aka switch in other languages) control structure in Ruby is great. The first when clause that evaluates true is the only one executed. Compare to PHP&#8217;s switch, which lets execution fall-through to every passing case until it finds a break. That&#8217;s just wrong. It&#8217;s so counter-intuitive. Sure, a veteran PHP programmer will have [...]]]></description>
			<content:encoded><![CDATA[<p>The <strong>case</strong> (aka <strong>switch</strong> in other languages) <a href='http://spec.ruby-doc.org/wiki/Flow_Control#case...when...else...end'>control structure</a> in Ruby is great.  The first <strong>when</strong> clause that evaluates true is the only one executed.</p>
<p>Compare to PHP&#8217;s <a href='http://us2.php.net/switch'>switch</a>, which lets execution fall-through to every passing <strong>case</strong> until it finds a <strong>break</strong>.  That&#8217;s just wrong.  It&#8217;s so counter-intuitive.  Sure, a veteran PHP programmer will have those <strong>break</strong>s hardcoded into their fingertips, but that&#8217;s learned, not instinctual behavior.  And yeah, you can get clever and take advantage of the cascading execution, but you do it at the expense of legibility.  How many debugging hours have been spent chasing down forgotten <strong>break</strong>s?</p>
<p>Ruby, on the other hand, does it right.  The language doesn&#8217;t even give you the option of letting execution fall through.  Less is more here.  Less mental clutter and debugging, more natural, clean code.</p>
]]></content:encoded>
			<wfw:commentRss>http://coryforsyth.com/2008/01/31/one-thing-i-love-about-ruby-vs-php/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Secret Santa w/ Ruby</title>
		<link>http://coryforsyth.com/2007/12/18/secret-santa-w-ruby/</link>
		<comments>http://coryforsyth.com/2007/12/18/secret-santa-w-ruby/#comments</comments>
		<pubDate>Tue, 18 Dec 2007 13:25:01 +0000</pubDate>
		<dc:creator>cory</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://coryforsyth.com/2007/12/18/secret-santa-w-ruby/</guid>
		<description><![CDATA[For our office secret santa pool, I wrote a quick little ruby script to generate the pairings and email each of the people in our office with their result. Here&#8217;s the salient code: pool = ["person1@email.address.com", "person2@email.address.com", "person3@email.address.com"] avail = pool.dup pairs = [] pool.each do &#124;secret_santa&#124; loop do index = (rand * avail.length).to_i recipient [...]]]></description>
			<content:encoded><![CDATA[<p>For our office secret santa pool, I wrote a quick little ruby script to generate the pairings and email each of the people in our office with their result.</p>
<p>Here&#8217;s the salient code:</p>
<pre>
pool = ["person1@email.address.com",
        "person2@email.address.com",
        "person3@email.address.com"]

avail = pool.dup
pairs = []

pool.each do |secret_santa|
  loop do
    index = (rand * avail.length).to_i
    recipient = avail[index]
    unless recipient == secret_santa
      avail.delete_at(index)
      pairs << [secret_santa, recipient]
      break
    end
  end
end
</pre>
<p>This generates a list of tuples (the variable <b>pairs</b>) that you can then iterate over, emailing out the results.  Here's the full code (<a href='http://coryforsyth.com/wordpress/wp-content/uploads/2007/12/secret_santa.rb' title='secret santa ruby program'>download here</a>).</p>
<pre>
#!/usr/bin/ruby
require 'net/smtp'

PRINT_RESULTS = true # Print results to screen?
EMAIL_RESULTS = false # email the results?

pool = ["person1@email.address.com",
        "person2@email.address.com",
        "person3@email.address.com"]

avail = pool.dup
pairs = []

pool.each do |secret_santa|
  loop do
    index = (rand * avail.length).to_i
    recipient = avail[index]
    unless recipient == secret_santa
      avail.delete_at(index)
      pairs << [secret_santa, recipient]
      break
    end
  end
end

pairs.each do |secret_santa,recipient|
  from = "the_north_pole@northpole.np"
  from_alias = "santa"
  to = secret_santa
  to_alias = secret_santa

  sbj = "secret santa -- ho ho ho"
  msg = "You are #{secret_santa}. " <<
                  "Your secret santa recipient is: "<<
                  "#{recipient}."
  send_email(from, from_alias, to, to_alias, sbj, msg) if EMAIL_RESULTS
  puts "#{secret_santa}  => #{recipient}" if PRINT_RESULTS
end

def send_email(from, from_alias, to, to_alias, subject, message)
	msg = <<END_OF_MESSAGE
From: #{from_alias} <#{from}>
To: #{to_alias} <#{to}>
Subject: #{subject}

#{message}
END_OF_MESSAGE

   Net::SMTP.start('localhost') do |smtp|
      smtp.send_message msg, from, to
   end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://coryforsyth.com/2007/12/18/secret-santa-w-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
