<?xml version="1.0" encoding="utf-8" ?>

<rss version="2.0" 
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:admin="http://webns.net/mvcb/"
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
   xmlns:wfw="http://wellformedweb.org/CommentAPI/"
   xmlns:content="http://purl.org/rss/1.0/modules/content/"
   >
<channel>
    <title>Mike's Page - Ruby</title>
    <link>http://boonedocks.net/mike/</link>
    <description>Just breaking the surface</description>
    <dc:language>en</dc:language>
    <generator>Serendipity 1.2 - http://www.s9y.org/</generator>
    
    <image>
        <url>http://boonedocks.net/mike/templates/default/img/s9y_banner_small.png</url>
        <title>RSS: Mike's Page - Ruby - Just breaking the surface</title>
        <link>http://boonedocks.net/mike/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Git is Fun</title>
    <link>http://boonedocks.net/mike/archives/168-Git-is-Fun.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/168-Git-is-Fun.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=168</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://boonedocks.net/mike/rss.php?version=2.0&amp;type=comments&amp;cid=168</wfw:commentRss>
    

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    I was initially disappointed when it was announced that Ruby on Rails was &lt;a href=&quot;http://weblog.rubyonrails.org/2008/4/2/rails-is-moving-from-svn-to-git&quot;&gt;moving its version control system from Subversion to Git&lt;/a&gt;. There&#039;s enough to keep up with in Rails that I didn&#039;t relish having to keep up with this as well. It wasn&#039;t so much that Rails was moving, but related code began to move too, so we&#039;re currently in this limbo where many plugins have both git and soon-to-be-deprecated SVN repositories, and it&#039;s just another detail to keep track of. Hopefully there will be &lt;a href=&quot;http://github.com/francois/piston/tree/master&quot;&gt;tools&lt;/a&gt; to sort all this out soon.&lt;br /&gt;&lt;br /&gt;

I like my &lt;a href=&quot;http://tortoisesvn.net/&quot;&gt;SVN GUI tools&lt;/a&gt;, but it turns out that git works pretty well on Windows under &lt;a href=&quot;http://www.cygwin.com/&quot;&gt;Cygwin&lt;/a&gt;, if you can live with the command line. It&#039;s certainly sufficient for cloning plugin repositories.&lt;br /&gt;&lt;br /&gt;

I could take or leave git by itself, but I love &lt;a href=&quot;http://github.com/&quot;&gt;GitHub&lt;/a&gt;. They make it so easy to fork an existing project, make your own changes to it, and share it back with the world. Your changes can easily be pulled back into the original projects, too. I&#039;ve been able to make a couple of small contributions to &lt;a href=&quot;http://github.com/thoughtbot/shoulda/commit/9c78fe05a1897acc9455115725c09f408f5f67ba&quot;&gt;shoulda&lt;/a&gt; and &lt;a href=&quot;http://github.com/frabcus/acts_as_xapian/commit/9070c81ea69e67b20062d34c7d5ac9e6b44f9942&quot;&gt;acts_as_xapian&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;

So git is fun after all, and I&#039;m looking forward to using it more; especially when the GUI tools show up.
 
    </content:encoded>

    <pubDate>Thu, 22 May 2008 21:27:27 -0400</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/168-guid.html</guid>
    
</item>
<item>
    <title>Determining Image File Types in Ruby</title>
    <link>http://boonedocks.net/mike/archives/162-Determining-Image-File-Types-in-Ruby.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/162-Determining-Image-File-Types-in-Ruby.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=162</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://boonedocks.net/mike/rss.php?version=2.0&amp;type=comments&amp;cid=162</wfw:commentRss>
    

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    Today I came across a PNG file that had been uploaded from a browser with a .JPG extension and image/jpeg MIME type. It&#039;s too bad that MIME types are apparently unreliable when it comes to file uploads. I went looking for a way to determine the file type by actually reading the file. This is probably a solved problem, but I was unsuccessful Googling for the answer. I came up with the following Ruby method which decides the image file type using up to the first 10 bytes:&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: monospace;&quot;&gt;
def image_type(file)&lt;br /&gt;
&amp;#160;&amp;#160;case IO.read(file, 10)&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;when /^GIF8/: &#039;gif&#039;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;when /^\x89PNG/: &#039;png&#039;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;when /^\xff\xd8\xff\xe0\x00\x10JFIF/: &#039;jpg&#039;&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;when /^\xff\xd8\xff\xe1(.*){2}Exif/: &#039;jpg&#039;&lt;br /&gt;
&amp;#160;&amp;#160;else &#039;unknown&#039;&lt;br /&gt;
&amp;#160;&amp;#160;end&lt;br /&gt;
end&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;
This works well on a small set of test files (400+ from a browser temp files directory). Let me know if there&#039;s a case where this code doesn&#039;t work, or if there&#039;s a better solution in general.
 
    </content:encoded>

    <pubDate>Mon, 10 Mar 2008 22:22:03 -0400</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/162-guid.html</guid>
    
</item>
<item>
    <title>I'm in Rails</title>
    <link>http://boonedocks.net/mike/archives/159-Im-in-Rails.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/159-Im-in-Rails.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=159</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://boonedocks.net/mike/rss.php?version=2.0&amp;type=comments&amp;cid=159</wfw:commentRss>
    

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    I&#039;ve made a code contribution to Ruby on Rails. It was minor, but I&#039;m glad I could help. See &lt;a href=&quot;http://dev.rubyonrails.org/ticket/10435&quot;&gt;ticket 10435&lt;/a&gt; and &lt;a href=&quot;http://dev.rubyonrails.org/changeset/8386&quot;&gt;changeset 8386&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;
Supposed to get some rain today...keeping my fingers crossed.&lt;br /&gt;&lt;br /&gt;
&lt;b&gt;Update 2007-12-17:&lt;/b&gt; Looks like my patch made it into &lt;a href=&quot;http://weblog.rubyonrails.com/2007/12/17/rails-2-0-2-some-new-defaults-and-a-few-fixes&quot;&gt;Rails 2.0.2&lt;/a&gt;. And we did get that rain, but more would be good.&lt;br /&gt;&lt;br /&gt;
&lt;b&gt;Update 2008-03-17:&lt;/b&gt; I managed to get another &lt;a href=&quot;http://dev.rubyonrails.org/ticket/11353&quot;&gt;small patch&lt;/a&gt; committed. Go open source!
 
    </content:encoded>

    <pubDate>Sat, 15 Dec 2007 07:55:47 -0500</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/159-guid.html</guid>
    
</item>
<item>
    <title>Improving upon Rails' validates_inclusion_of</title>
    <link>http://boonedocks.net/mike/archives/152-Improving-upon-Rails-validates_inclusion_of.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/152-Improving-upon-Rails-validates_inclusion_of.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=152</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://boonedocks.net/mike/rss.php?version=2.0&amp;type=comments&amp;cid=152</wfw:commentRss>
    

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    I&#039;m fairly new to the Ruby language and the Ruby on Rails framework, but it worked nicely for quickly building my website &lt;a href=&quot;http://birdsite.org/&quot;&gt;BirdSite&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;

I was using &lt;a href=&quot;http://api.rubyonrails.org/classes/ActiveRecord/Validations/ClassMethods.html#M000946&quot;&gt;validates_inclusion_of &lt;/a&gt; fairly regularly to make sure the data in my models was valid. But then, watching the development log, I noticed extra SQL queries being made when I accessed my main model. It seems that validates_inclusion_of was forcing the model to make queries to the related models even when I didn&#039;t need data from them.&lt;br /&gt;&lt;br /&gt;

Some Googling led to a &lt;a href=&quot;http://www.elctech.com/2007/5/3/dry-validates_inclusion_of-with-introspection&quot;&gt;blog post that did the validation a different way&lt;/a&gt;. It worked well, until I added the code to a new model today and it broke. The code was translating the model field name into a string from which to call the model itself. But the code assumed that the model would be a single word. I added a change to strip the spaces out, and it worked again.&lt;br /&gt;&lt;br /&gt;

I contacted the company that hosts the blog and they confirmed that it was a problem, and they didn&#039;t know of a nicer Ruby way to correct it short of dropping the spaces with search/replace. They updated their code.&lt;br /&gt;&lt;br /&gt;

I&#039;m glad I could help out. It really works better than the standard validates_inclusion_of.
 
    </content:encoded>

    <pubDate>Tue, 28 Aug 2007 16:36:34 -0400</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/152-guid.html</guid>
    
</item>
<item>
    <title>Rails acts_as_ferret without DRb</title>
    <link>http://boonedocks.net/mike/archives/151-Rails-acts_as_ferret-without-DRb.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/151-Rails-acts_as_ferret-without-DRb.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=151</wfw:comment>

    <slash:comments>7</slash:comments>
    <wfw:commentRss>http://boonedocks.net/mike/rss.php?version=2.0&amp;type=comments&amp;cid=151</wfw:commentRss>
    

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    I wanted to add a search feature to my Ruby on Rails application &lt;a href=&quot;http://birdsite.org/&quot;&gt;BirdSite&lt;/a&gt;. There is a plugin called &quot;&lt;a href=&quot;http://projects.jkraemer.net/acts_as_ferret/wiki&quot;&gt;acts_as_ferret&lt;/a&gt;&quot; which allows Rails applications to use the Ferret search engine (based on Lucene).&lt;br /&gt;&lt;br /&gt;

Using &lt;a href=&quot;http://www.railsenvy.com/2007/2/19/acts-as-ferret-tutorial&quot;&gt;this tutorial&lt;/a&gt;, I was able to get search up an running. It worked great on my development system. But there was a warning that you needed to run the indexer using a DRb server instead of directly from the Rails app. This is because the index cannot handle multiple processes writing to it simultaneously. (I also ran into this problem using PHP with another
engine called &lt;a href=&quot;http://www.xapian.org/&quot;&gt;Xapian&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;

I was hoping my new site was low traffic enough to avoid problems. Since I&#039;m hosting it on a shared server, I can&#039;t run a DRb server there anyway. But I got my first indexing exceptions less than 24 hours after I loaded my stuff onto the live server.&lt;br /&gt;&lt;br /&gt;

So I decided to try periodic indexing by a cron job. This would allow me to update the index once an hour, from a single process. The downside is that the search index is only updated hourly, but I decided I could live with that.&lt;br /&gt;&lt;br /&gt;

The first step is telling your Rails app to not index the content when updating. My model already had a before_save method, so I added this code:&lt;br /&gt;&lt;br /&gt;

&lt;div style=&quot;font-family: monospace;&quot;&gt;
# in the model&lt;br /&gt;
def before_save&lt;br /&gt;
&amp;#160;&amp;#160;# other stuff goes here&lt;br /&gt;&lt;br /&gt;
&amp;#160;&amp;#160;# disable automatic ferret indexing...move it to a cron job&lt;br /&gt;
&amp;#160;&amp;#160;self.disable_ferret(:always)&lt;br /&gt;
end
&lt;/div&gt;&lt;br /&gt;

Then I had to create a rake task which would build the index:&lt;br /&gt;&lt;br /&gt;

&lt;div style=&quot;font-family: monospace;&quot;&gt;
# ferret_index.rake&lt;br /&gt;
desc &quot;Updates the ferret index for the application.&quot;&lt;br /&gt;
task :ferret_index =&gt; [ :environment ] do | t |&lt;br /&gt;
&amp;#160;&amp;#160;MyModel.rebuild_index&lt;br /&gt;
&amp;#160;&amp;#160;# here I could add other model index rebuilds&lt;br /&gt;
&amp;#160;&amp;#160;puts &quot;Completed Ferret Index Rebuild&quot;&lt;br /&gt;
end
&lt;/div&gt;&lt;br /&gt;

This task is simplified: I&#039;m telling it to rebuild the entire index each hour. I&#039;m guessing when my dataset gets big enough, this will be really slow. In that case I&#039;ll need to track all the model instances that got updated in the past hour and just index those.&lt;br /&gt;&lt;br /&gt;

Finally, I needed a cron job to run the rake task, making sure to set the environment to &quot;production&quot;:&lt;br /&gt;&lt;br /&gt;

&lt;div style=&quot;font-family: monospace;&quot;&gt;
cd /rails_app &amp;&amp;amp; rake ferret_index RAILS_ENV=production
&lt;/div&gt;&lt;br /&gt;

So far this is working well, and I haven&#039;t received any indexing exceptions since.
 
    </content:encoded>

    <pubDate>Tue, 14 Aug 2007 17:17:38 -0400</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/151-guid.html</guid>
    
</item>
<item>
    <title>Check out the BirdSite!</title>
    <link>http://boonedocks.net/mike/archives/149-Check-out-the-BirdSite!.html</link>
            <category>Nature</category>
            <category>Photo</category>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/149-Check-out-the-BirdSite!.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=149</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://boonedocks.net/mike/rss.php?version=2.0&amp;type=comments&amp;cid=149</wfw:commentRss>
    

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    &lt;div style=&quot;padding-left: 1em; padding-right: 0.5em; padding-top: 0.5em; padding-bottom: 0.5em; float: right;&quot;&gt;&lt;a href=&quot;http://birdsite.org&quot;&gt;
&lt;img border=&quot;0&quot; src=&quot;http://boonedocks.net/mike/images/birdsite_small.png&quot;&gt;&lt;/a&gt;&lt;/div&gt;
I recently published a new website: &lt;a href=&quot;http://birdsite.org/&quot;&gt;birdsite.org&lt;/a&gt;.
This site was inspired by &lt;a href=&quot;http://bugguide.net/&quot;&gt;BugGuide&lt;/a&gt;, where I&#039;ve been
a participant for several years, both as a photographer and a developer. I&#039;d been
thinking about doing a similar site for other fauna that I photograph.
&lt;a href=&quot;http://bugguide.net/node/view/62076&quot;&gt;This forum thread&lt;/a&gt; made it clear
that others were interested in such a site for birds. I decided to build it. For my
own programming amusement I created this site as my first project with
&lt;a href=&quot;http://rubyonrails.org/&quot;&gt;Ruby on Rails&lt;/a&gt;. I still have lots of features to
add but I wanted to get the bare bones up and running.
 
    </content:encoded>

    <pubDate>Fri, 06 Jul 2007 14:50:51 -0400</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/149-guid.html</guid>
    
</item>

</channel>
</rss>