<?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>Matthew Bass &#187; Ruby</title>
	<atom:link href="http://matthewbass.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://matthewbass.com</link>
	<description>Musings on software and life...</description>
	<lastBuildDate>Sat, 17 Jul 2010 03:44:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Drop seconds when querying MySQL timestamps</title>
		<link>http://matthewbass.com/2010/06/25/drop-seconds-when-querying-mysql-timestamps/</link>
		<comments>http://matthewbass.com/2010/06/25/drop-seconds-when-querying-mysql-timestamps/#comments</comments>
		<pubDate>Fri, 25 Jun 2010 20:35:36 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=600</guid>
		<description><![CDATA[One of the Rails apps I&#8217;ve been working on formats times as HH:MM in the view. No seconds are displayed. This is a pretty common way to format things. When doing timestamp comparisons in SQL, however, the seconds are taken into account. This is bad since it can cause discrepancies in the view.
For example, say [...]]]></description>
			<content:encoded><![CDATA[<p>One of the Rails apps I&#8217;ve been working on formats times as HH:MM in the view. No seconds are displayed. This is a pretty common way to format things. When doing timestamp comparisons in SQL, however, the seconds <em>are</em> taken into account. This is bad since it can cause discrepancies in the view.</p>
<p>For example, say I have a table of records with created_at timestamps. My view displays all records with timestamps equal to or before the current time. Let&#8217;s assume the current time is 15:00:00 precisely and I happen to have a record with a timestamp of 15:00:00 in the database. The SQL comparison would work fine in this case.</p>
<pre class="brush: sql;">
SELECT * FROM records WHERE created_at &lt;= &quot;2010-06-25 15:00:00&quot;
=&gt; 1 row in set
</pre>
<p>What if the timestamp in the database is 15:00:03 though? Let&#8217;s run the query again.</p>
<pre class="brush: sql;">
SELECT * FROM records WHERE created_at &lt;= &quot;2010-06-25 15:00:00&quot;
=&gt; Empty set
</pre>
<p>Since 15:00:03 is <em>greater</em> than the current time of 15:00:00, the record doesn&#8217;t get returned. This would be fine if we were displaying seconds in the view, but we&#8217;re not. From the user&#8217;s perspective, the timestamp on the record is still 15:00 and <strong>should</strong> appear in the view since it&#8217;s equal to the current time. But it doesn&#8217;t.</p>
<p>One way to fix this would be to handle the time comparisons in Ruby. This is certainly a legitimate option. For this particular project, though, performance was a big issue. (And we all know that <a href="http://canrailsscale.com">Rails can&#8217;t scale</a>.) I needed a way to continue letting the database handle the comparisons while disregarding seconds.</p>
<p>The solution I ended up with isn&#8217;t ideal (it relies on a couple of functions built into MySQL) but it works fine and runs fast:</p>
<pre class="brush: sql;">
SELECT * FROM records WHERE (created_at - INTERVAL SECOND(created_at) SECOND) &lt;= &quot;2010-06-25 15:00:00&quot;
=&gt; 1 row in set
</pre>
<p>The number of seconds is extracted from the created_at timestamp and then subtracted from the timestamp. So if the timestamp was 15:00:03, MySQL subtracts 3 seconds to end up with 15:00:00.</p>
<p>This solved the comparison problem for me and made my client very happy. Double win.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2010/06/25/drop-seconds-when-querying-mysql-timestamps/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Ruby Hoedown 2010</title>
		<link>http://matthewbass.com/2010/06/18/ruby-hoedown-2010/</link>
		<comments>http://matthewbass.com/2010/06/18/ruby-hoedown-2010/#comments</comments>
		<pubDate>Fri, 18 Jun 2010 14:13:02 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=585</guid>
		<description><![CDATA[This year&#8217;s Ruby Hoedown is happening in Nashville again on September 3rd and 4th. I&#8217;m really looking forward to attending. The quality of the talks combined with the smaller attendance size makes for some great hallway conversations. Last year&#8217;s Hoedown was at the Opryland hotel which was a stellar venue. I have seriously never seen [...]]]></description>
			<content:encoded><![CDATA[<p>This year&#8217;s <a href="http://www.rubyhoedown.com">Ruby Hoedown</a> is happening in Nashville again on September 3rd and 4th. I&#8217;m really looking forward to attending. The quality of the talks combined with the smaller attendance size makes for some great hallway conversations. Last year&#8217;s Hoedown was at the Opryland hotel which was a stellar venue. I have seriously never seen such a large hotel. Unfortunately, it can&#8217;t be used this year due to the recent flooding. But the new venue, the <a href="http://www1.hilton.com/en_US/hi/hotel/BNANSHF-Hilton-Nashville-Downtown-Tennessee/index.do">Hilton Downtown</a>, looks really nice as well. As before, the Hoedown is completely free (as in beer) and talk proposals are currently being accepted. Are you going?</p>
<p><a href="http://www.rubyhoedown.com"><img src="http://matthewbass.com/wp-content/uploads/2010/06/729968355.png" alt="The Ruby Hoedown MMX" title="The Ruby Hoedown MMX" width="450" height="140" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2010/06/18/ruby-hoedown-2010/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RubyConf in New Orleans</title>
		<link>http://matthewbass.com/2010/06/11/rubyconf-in-new-orleans/</link>
		<comments>http://matthewbass.com/2010/06/11/rubyconf-in-new-orleans/#comments</comments>
		<pubDate>Fri, 11 Jun 2010 14:16:19 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=567</guid>
		<description><![CDATA[This year&#8217;s RubyConf is being held in New Orleans on November 11th &#8211; 13th. 
Count me in.
I&#8217;ve only driven through the area once so it&#8217;ll be interesting to make a longer visit. Although I&#8217;m ultimately keeping my fingers crossed for a Raleigh RubyConf one of these days. Hey, I can dream.
]]></description>
			<content:encoded><![CDATA[<p>This year&#8217;s <a href="http://rubyconf.org">RubyConf</a> is being held in New Orleans on November 11th &#8211; 13th. </p>
<p>Count me in.</p>
<p>I&#8217;ve only driven through the area once so it&#8217;ll be interesting to make a longer visit. Although I&#8217;m ultimately keeping my fingers crossed for a Raleigh RubyConf one of these days. Hey, I can dream.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2010/06/11/rubyconf-in-new-orleans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>test_spec_on_rails now runs on Rails 2.3</title>
		<link>http://matthewbass.com/2009/12/03/test_spec_on_rails-now-runs-on-rails-23/</link>
		<comments>http://matthewbass.com/2009/12/03/test_spec_on_rails-now-runs-on-rails-23/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 01:26:09 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=295</guid>
		<description><![CDATA[If anyone still happens to be using test_spec, you&#8217;ll be thrilled to know that the test_spec_on_rails plugin is now compatible with Rails 2.3. It has also been converted to a gem. Install with:

sudo gem install test_spec_on_rails

Add to your Rails app&#8217;s test.rb like so:

config.gem 'test_spec_on_rails'

Enjoy the goodness of test-spec helpers from inside your Rails tests. Fork [...]]]></description>
			<content:encoded><![CDATA[<p>If anyone still happens to be using <a href="http://github.com/relevance/test-spec/">test_spec</a>, you&#8217;ll be thrilled to know that the test_spec_on_rails plugin is now compatible with Rails 2.3. It has also been converted to a gem. Install with:</p>
<pre class="brush: bash; light: true;">
sudo gem install test_spec_on_rails
</pre>
<p>Add to your Rails app&#8217;s test.rb like so:</p>
<pre class="brush: ruby; light: true;">
config.gem 'test_spec_on_rails'
</pre>
<p>Enjoy the goodness of test-spec helpers from inside your Rails tests. Fork and submit patches via the <a href="http://github.com/pelargir/test_spec_on_rails">GitHub project</a>. Tell your friends. Donate money. Vote for Pedro.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2009/12/03/test_spec_on_rails-now-runs-on-rails-23/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Processing malformed files with FasterCSV</title>
		<link>http://matthewbass.com/2009/12/03/processing-malformed-files-with-fastercsv/</link>
		<comments>http://matthewbass.com/2009/12/03/processing-malformed-files-with-fastercsv/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 00:57:25 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=418</guid>
		<description><![CDATA[On a recent project, I had to implement a CSV parser that would gracefully handle malformed files. I&#8217;m talking about files with unescaped quotes, wacky UTF-8 chars, and various other abominations of nature.
I originally assumed FasterCSV would handle this automagically, but it turns out that the library&#8217;s most commonly used methods are pretty strict when [...]]]></description>
			<content:encoded><![CDATA[<p>On a recent project, I had to implement a CSV parser that would gracefully handle malformed files. I&#8217;m talking about files with unescaped quotes, wacky UTF-8 chars, and various other abominations of nature.</p>
<p>I originally assumed FasterCSV would handle this automagically, but it turns out that the library&#8217;s most commonly used methods are pretty strict when it comes to handling CSV files.</p>
<p>For example, parsing a malformed file one line at a time will result in an exception being thrown, even before any rows are yielded to the block:</p>
<pre class="brush: ruby;">
FasterCSV.foreach(&quot;malformed.csv&quot;) do |row|
  # use row here...
end
</pre>
<p>Not cool! I managed to get around this by manually looping over each row and rescuing a malformed CSV exception if one gets thrown:</p>
<pre class="brush: ruby;">
FasterCSV.open(&quot;malformed.csv&quot;, &quot;rb&quot;) do |output|
  loop do
    begin
      break unless row = output.shift
      # use row here...
    rescue FasterCSV::MalformedCSVError =&gt; e
      # handle malformed row here...
    end
  end
end
</pre>
<p>Anyone have a better way to do this?</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2009/12/03/processing-malformed-files-with-fastercsv/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Time warping gem goodness</title>
		<link>http://matthewbass.com/2009/12/03/time-warping-gem-goodness/</link>
		<comments>http://matthewbass.com/2009/12/03/time-warping-gem-goodness/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 00:23:49 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=438</guid>
		<description><![CDATA[The time zone warp code I posted about last week is now a gem:

sudo gem install time-zone-warp

To configure in your Rails app, add this line to the bottom of test.rb:

config.gem 'time-zone-warp', :lib =&#62; 'time_zone_warp'

You can also fork the code from the project on GitHub.
]]></description>
			<content:encoded><![CDATA[<p>The <a href="2009/11/18/time-zone-warp/">time zone warp</a> code I posted about last week is now a gem:</p>
<pre class="brush: bash; light: true;">
sudo gem install time-zone-warp
</pre>
<p>To configure in your Rails app, add this line to the bottom of test.rb:</p>
<pre class="brush: ruby; light: true;">
config.gem 'time-zone-warp', :lib =&gt; 'time_zone_warp'
</pre>
<p>You can also fork the code from <a href="http://github.com/adeptware/time-zone-warp">the project on GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2009/12/03/time-warping-gem-goodness/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Time zone warp</title>
		<link>http://matthewbass.com/2009/11/18/time-zone-warp/</link>
		<comments>http://matthewbass.com/2009/11/18/time-zone-warp/#comments</comments>
		<pubDate>Thu, 19 Nov 2009 02:47:56 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Rails]]></category>
		<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=428</guid>
		<description><![CDATA[One of my Rails projects makes heavy use of time zones. I&#8217;ve run into some issues writing good tests for this type of thing. In particular, I&#8217;ve needed my tests to run within a time zone outside my own. But I don&#8217;t want to permanently change the time zone within the scope of the entire [...]]]></description>
			<content:encoded><![CDATA[<p>One of my Rails projects makes heavy use of time zones. I&#8217;ve run into some issues writing good tests for this type of thing. In particular, I&#8217;ve needed my tests to run within a time zone outside my own. But I don&#8217;t want to permanently change the time zone within the scope of the entire test run. I ended up coding this handler:</p>
<pre class="brush: ruby;">
module ZoneWarp
  def pretend_zone_is(zone)
    original_zone = Time.zone
    begin
      Time.zone = zone
      yield
    ensure
      Time.zone = original_zone
    end
  end
end

Test::Unit::TestCase.send(:include, ZoneWarp)
</pre>
<p>Simply stick this code in a file inside your <code>config/initializers</code> directory (or include it from test_helper.rb or spec_helper.rb if you insist on doing it the <em>right</em> way) and you&#8217;re all set to write tests like this:</p>
<pre class="brush: ruby;">
test &quot;code works in other time zones&quot; do
  pretend_zone_is &quot;Mountain Time (US &amp; Canada)&quot; do
    # assertions go here
  end
end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2009/11/18/time-zone-warp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learn about Prawn at raleigh.rb on August 18th</title>
		<link>http://matthewbass.com/2009/08/11/learn-about-prawn-at-raleighrb-on-august-18th/</link>
		<comments>http://matthewbass.com/2009/08/11/learn-about-prawn-at-raleighrb-on-august-18th/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 17:58:22 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=398</guid>
		<description><![CDATA[I&#8217;ll be giving a presentation about Prawn at this month&#8217;s raleigh.rb meetup. Prawn is a Ruby gem that enables fast PDF generation. It is a dramatic improvement over previous libraries like PDF::Writer. It can be used standalone or inside your Rails applications. The markup is powerful and relatively painless to use. I hope you can [...]]]></description>
			<content:encoded><![CDATA[<p><object width="400" height="300" align="right"><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="movie" value="http://vimeo.com/moogaloop.swf?clip_id=6051124&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=6051124&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>I&#8217;ll be giving a presentation about Prawn at this month&#8217;s <a href="http://raleighrb.com">raleigh.rb</a> meetup. Prawn is a Ruby gem that enables fast PDF generation. It is a dramatic improvement over previous libraries like PDF::Writer. It can be used standalone or inside your Rails applications. The markup is powerful and relatively painless to use. I hope you can join us for the fun on August 18th at Red Hat HQ.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2009/08/11/learn-about-prawn-at-raleighrb-on-august-18th/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Audio interview for RubyRX 2009</title>
		<link>http://matthewbass.com/2009/06/29/audio-interview-for-rubyrx-2009/</link>
		<comments>http://matthewbass.com/2009/06/29/audio-interview-for-rubyrx-2009/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 02:15:45 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=372</guid>
		<description><![CDATA[Jared Richardson just posted a series of interviews in anticipation of the upcoming RubyRX/AgileRX conference taking place in Reston, Virginia in September. In my interview we discuss iPhone development, MacRuby, Git, and testing frameworks.
I&#8217;m really looking forward to presenting again at RubyRX. I&#8217;ll be giving two talks this year. Git with Ruby will explore the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nfjsone.com/conference/washington_dc/2009/09/rubyrx/event_about"><img src="http://matthewbass.com/wp-content/uploads/2009/06/rrx210x85rc.jpg" alt="RubyRX" title="RubyRX" width="210" height="85" align="right" border="0" /></a>Jared Richardson just posted a <a href="http://nfjsone.com/conference/washington_dc/2009/09/podcast">series of interview</a>s in anticipation of the upcoming <a href="http://nfjsone.com/conference/washington_dc/2009/09/rubyrx/event_about">RubyRX/AgileRX conference</a> taking place in Reston, Virginia in September. In <a href="http://nfjsone.com/s/podcast/x/matt_bass.mp3">my interview</a> we discuss iPhone development, MacRuby, Git, and testing frameworks.</p>
<p>I&#8217;m really looking forward to presenting again at RubyRX. I&#8217;ll be giving two talks this year. <a href="http://nfjsone.com/conference/washington_dc/2009/09/session?id=15129">Git with Ruby</a> will explore the Git source control system and how Ruby can take advantage of it. In <a href="http://nfjsone.com/conference/washington_dc/2009/09/session?id=15030">Which Ruby Testing Framework Should I Use?</a> we&#8217;ll briefly examine several leading testing frameworks and study the pros and cons of each. You&#8217;ll leave fully prepared to pick the best framework for your next project.</p>
<p><a href="mailto:matthew@adeptware.com">Let me know</a> if you&#8217;re coming to the conference this year and we can link up in Reston. If you haven&#8217;t <a href="http://nfjsone.com/conference/washington_dc/2009/09/register">registered</a> yet, what are you waiting for? RubyRX is a chance to network with the best and brightest developers in the area, and hear from thought leaders like Andy Hunt, Rich Kilmer, Joe O&#8217;Brien, and Chad Fowler. It&#8217;s a great way to keep your skills sharp in a down year.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2009/06/29/audio-interview-for-rubyrx-2009/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="http://nfjsone.com/s/podcast/x/matt_bass.mp3" length="5511650" type="audio/mpeg" />
		</item>
		<item>
		<title>Lindo testing helper gets some love</title>
		<link>http://matthewbass.com/2009/06/29/lindo-testing-helper-gets-some-love/</link>
		<comments>http://matthewbass.com/2009/06/29/lindo-testing-helper-gets-some-love/#comments</comments>
		<pubDate>Mon, 29 Jun 2009 20:00:38 +0000</pubDate>
		<dc:creator>Matthew Bass</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Tools]]></category>

		<guid isPermaLink="false">http://matthewbass.com/?p=369</guid>
		<description><![CDATA[Lindo helps you write and verify Rails functional and integration tests by opening the HTTP response body in the default browser for inspection. This can be a real time-saver when you&#8217;re trying to figure out why your assert_select or have_tag calls aren&#8217;t passing.
In its initial version, Lindo assumed that your app was running at localhost:3000 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.adeptware.com/blog/2009/06/29/lindo-makes-rails-testing-easier/">Lindo</a> helps you write and verify Rails functional and integration tests by opening the HTTP response body in the default browser for inspection. This can be a real time-saver when you&#8217;re trying to figure out why your <code>assert_select</code> or <code>have_tag</code> calls aren&#8217;t passing.</p>
<p>In its initial version, Lindo assumed that your app was running at localhost:3000 (a fair assumption given the prevalence of Mongrel last year). Now that <a href="http://www.modrails.com/">Passenger</a> is on the scene, something better needed to be done. The reliance on a running app server was a disadvantage to begin with. Now Lindo doesn&#8217;t require anything to be running. It dumps the HTML to disk, fixes any relative asset URLs, and opens the file using your default browser.</p>
<p>Once you&#8217;ve written your first test with the assistance of Lindo, you won&#8217;t want to go back!</p>
<p>Lindo was developed by my company, <a href="http://adeptware.com">Adeptware</a>, and can be pulled from <a href="http://github.com/adeptware/lindo/">GitHub</a>. I&#8217;ve also posted a brief <a href="http://www.adeptware.com/blog/2009/06/29/lindo-makes-rails-testing-easier/">introduction to Lindo</a> and some basic installation instructions.</p>
]]></content:encoded>
			<wfw:commentRss>http://matthewbass.com/2009/06/29/lindo-testing-helper-gets-some-love/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
