<?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 - Tech</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 - Tech - Just breaking the surface</title>
        <link>http://boonedocks.net/mike/</link>
        <width>100</width>
        <height>21</height>
    </image>

<item>
    <title>Ruby's shallow copies of hashes</title>
    <link>http://boonedocks.net/mike/archives/188-Rubys-shallow-copies-of-hashes.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/188-Rubys-shallow-copies-of-hashes.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=188</wfw:comment>

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

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    When you try to copy a Ruby hash using .dup or .clone, you get what is called a &quot;shallow&quot; copy. The data in the hash below the first level just seems to be referenced, so if you have a hash within the hash, and try to change a value in the deeper hash, the value is changed even for the original hash you ran the .dup on. To get a full (&quot;deep&quot;) copy of a hash, you have to run an inelegant hack using Marshal to copy it: copy_hash = (Marshal.load(Marshal.dump(source_hash))). This apparently applies to arrays too. See the code below for an example, and I hope this saves you hours of debugging.&lt;br /&gt;&lt;br /&gt;

&lt;script src=&quot;https://gist.github.com/1010901.js?file=hash_copy.rb&quot;&gt;&lt;/script&gt;
 
    </content:encoded>

    <pubDate>Mon, 06 Jun 2011 12:31:01 -0700</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/188-guid.html</guid>
    
</item>
<item>
    <title>Rails validations with accepts_nested_attributes_for and _destroy</title>
    <link>http://boonedocks.net/mike/archives/187-Rails-validations-with-accepts_nested_attributes_for-and-_destroy.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/187-Rails-validations-with-accepts_nested_attributes_for-and-_destroy.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=187</wfw:comment>

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

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    I was recently working on a Rails app that has a form with a parent item and child items on the same form. Ryan Bates&#039; &lt;a href=&quot;https://github.com/ryanb/complex-form-examples&quot;&gt;complex form examples&lt;/a&gt; is a good place to start with this. That code will give you a simple form setup with some Javascript for adding and removing rows of children.&lt;br /&gt;&lt;br /&gt;

It works pretty well, except that in my case, I needed to ensure that each parent had a minimum of one child. I had a validation which checked for this, but it only worked for creating new records. If I removed all the child rows during an edit, the form would still save successfully. It turns out that the key is in the Rails documentation: &lt;em&gt;&quot;Note that the model will not be destroyed until the parent is saved.&quot;&lt;/em&gt; So my validation was still happily finding a child row, even though it was set to be deleted. It took me some time before I found the right way to check for this, but the &lt;span style=&quot;font-family: monospace;&quot;&gt;marked_for_destruction?&lt;/span&gt; method seems to do the trick. Here&#039;s my code:&lt;br /&gt;&lt;br /&gt;

&lt;script src=&quot;https://gist.github.com/802504.js?file=gistfile1.rb&quot;&gt;&lt;/script&gt;
&lt;pre style=&quot;display: none;&quot;&gt;
class Project &lt; ActiveRecord::Base

  has_many :tasks
  accepts_nested_attributes_for :tasks, :reject_if =&gt; :all_blank, :allow_destroy =&gt; true

  def validate
    # require a minimum of one task
    undestroyed_task_count = 0

    tasks.each { |t| undestroyed_task_count += 1 unless t.marked_for_destruction? }

    errors.add_to_base &#039;There must be at least one task&#039; if undestroyed_task_count &lt; 1
  end

end
&lt;/pre&gt;
&lt;br /&gt;Hope this helps someone!
 
    </content:encoded>

    <pubDate>Sat, 29 Jan 2011 19:51:04 -0800</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/187-guid.html</guid>
    
</item>
<item>
    <title>My first attempt at a mobile web app</title>
    <link>http://boonedocks.net/mike/archives/186-My-first-attempt-at-a-mobile-web-app.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/186-My-first-attempt-at-a-mobile-web-app.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=186</wfw:comment>

    <slash:comments>0</slash:comments>
    <wfw:commentRss>http://boonedocks.net/mike/rss.php?version=2.0&amp;type=comments&amp;cid=186</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://denglisch.boonedocks.net/&quot;&gt;&lt;img border=&quot;1&quot; src=&quot;http://boonedocks.net/mike/images/denglisch1.png&quot; alt=&quot;German-English Dictionary Web App&quot; title=&quot;German-English Dictionary Web App&quot; width=&quot;188&quot; /&gt;&lt;/a&gt;&lt;/div&gt;Is this thing on? So it&#039;s been a forever since I&#039;ve blogged, but we&#039;ll see if I still can. Happy Thanksgiving at least!&lt;br /&gt;&lt;br /&gt;

Anyway, I&#039;ve been wanting to build stuff for my iPhone. While I&#039;ve been experimenting with Objective C for a native app, I wanted to actually build and publish something. So I have abandoned my Objective C code snippets for now and decided to go with things I know and build a Ruby on Rails site. There are various libraries to let you style a site for mobile browsers. I went with jQTouch, which is covered pretty well by these &lt;a href=&quot;http://railscasts.com/episodes/199-mobile-devices&quot;&gt;Railscasts&lt;/a&gt; and &lt;a href=&quot;https://peepcode.com/products/jqtouch&quot;&gt;Peepcode&lt;/a&gt; screencasts.&lt;br /&gt;&lt;br /&gt;

I like using the German-English dictionary site &lt;a href=&quot;http://dict.tu-chemnitz.de/&quot;&gt;Beolingus&lt;/a&gt;, but I wanted to use it more easily on my iPhone. It turns out the data is downloadable, so I decided to build a web application with mobile front-end. Here it is:&lt;br /&gt;&lt;br /&gt;

&lt;a href=&quot;http://denglisch.boonedocks.net/&quot;&gt;Denglisch&lt;/a&gt; (that&#039;s a &lt;a href=&quot;http://en.wikipedia.org/wiki/Denglisch&quot;&gt;term&lt;/a&gt; for English and German mixed together)&lt;br /&gt;&lt;br /&gt;

I really wanted to build the site in Rails 3, but most of my stuff is hosted on Dreamhost, and I&#039;ve read about various problem getting those apps running right now. So it&#039;s done in Rails 2.3.10 instead. The Rails side is pretty simple, just one model for the data, a rake script to import the textfile into the database, one controller and two actions. Then there&#039;s a little bit of jQuery Javascript code to handle the Ajax form submission.&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;clear: both;&quot;&gt;&lt;/div&gt;
&lt;div style=&quot;padding-left: 1em; padding-right: 0.5em; padding-top: 0.5em; padding-bottom: 0.5em; float: right;&quot;&gt;&lt;img border=&quot;1&quot; src=&quot;http://boonedocks.net/mike/images/denglisch2.png&quot; alt=&quot;Home Screen Icon&quot; title=&quot;Home Screen Icon&quot; width=&quot;294&quot; /&gt;&lt;/div&gt;I knew how to do a lot of these bits, but I learned things along the way too. For one, I didn&#039;t know that the iPhone could make a native-looking app out of a website. The website can include icons and a splash screen, and when you add the bookmark to your home screen, the icon will show up there. The splash screen shows up when the website is loading, and then the web app uses the full screen without the Safari toolbars. Cool. I found jQTouch to be fairly easy to use, but the download from their home page is a good bit older than the &lt;a href=&quot;https://github.com/senchalabs/jQTouch&quot;&gt;code&lt;/a&gt; they have on Github. I ran into an issue with the latest version that I had to look for a solution from the bug list. They don&#039;t have much documentation either. The Peepcode screencast was very helpful, but it isn&#039;t free, and jQTouch has changed a bit since it was published (e.g. the new &quot;jqt&quot; div).&lt;br /&gt;&lt;br /&gt;

Anyway, I&#039;ve tested this on my iPhone...I&#039;m curious to hear if it works for the iPad and other mobile devices. It was a good hobby project anyway. Have fun!
 
    </content:encoded>

    <pubDate>Thu, 25 Nov 2010 12:04:27 -0800</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/186-guid.html</guid>
    
</item>
<item>
    <title>One of those Non-descriptive Errors</title>
    <link>http://boonedocks.net/mike/archives/178-One-of-those-Non-descriptive-Errors.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/178-One-of-those-Non-descriptive-Errors.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=178</wfw:comment>

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

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    This one stumped me for a while today. I had an application to deploy which worked fine in development. Deploying to production led to this error:&lt;br /&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;/usr/local/lib/ruby/gems/1.8/gems/activesupport-2.0.5/lib/active_support/dependencies.rb:249:in `load_missing_constant&#039;: Expected /myapp/releases/20090617160914/app/models/widget.rb to define Widget (LoadError)&lt;/span&gt;
&lt;br /&gt;&lt;br /&gt;
Googling that error turned up lots of pages for Rails 1.2.x and issues with underscores in names. None of it applied. Widget was definitely being defined in widget.rb. Following the stack trace it appeared that the error was thrown in the Ultrasphinx plugin. After trying a lot of other things, I decided to comment out the Ultrasphinx code in the model and retry. The error changed to this, which was helpful:&lt;br /&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: monospace;&quot;&gt;
Errno::EACCES: Permission denied - /myapp/releases/20090617160914/public/widget/myfile
&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;
This model was also using the file_column plugin, and the underlying error was just a permissions problem in the file attachment target directory. I fixed the permissions and put the Ultrasphinx code back in the model, and all was happy. If only that permissions error had shown up first! 
    </content:encoded>

    <pubDate>Wed, 17 Jun 2009 12:53:13 -0700</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/178-guid.html</guid>
    
</item>
<item>
    <title>MAMP and the Ruby MySQL Gem</title>
    <link>http://boonedocks.net/mike/archives/175-MAMP-and-the-Ruby-MySQL-Gem.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/175-MAMP-and-the-Ruby-MySQL-Gem.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=175</wfw:comment>

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

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    &lt;b&gt;Update 2011-09-18:&lt;/b&gt; &lt;a href=&quot;http://blog.mirotin.net/35/mamp-1-9-5-mysql-5-5-9-and-ruby-mysql2&quot;&gt;See here&lt;/a&gt; for the most up-to-date instructions (MAMP 1.9). I got it working on 2.0, but experienced some of the same problems other commenters noted). See also &lt;a href=&quot;http://www.beyondcoding.com/2009/11/10/using-ruby-mysql-gem-with-mamp-1-8-x-on-snow-leopard/&quot;&gt;these instructions&lt;/a&gt; for MAMP 1.8.&lt;br /&gt;&lt;br /&gt;
After much frustration, I found a way to get the Ruby mysql Gem installed and talking to my MySQL server on MAMP. Credit goes largely to &quot;Hootbah&quot; who followed a similar path to get &lt;a href=&quot;http://hootbah.co.uk/2008/01/03/mamp-17-and-dbdmysql/&quot;&gt;MAMP talking to Perl&#039;s MySQL library&lt;/a&gt;. Here&#039;s the steps I followed for MAMP 1.7.2:&lt;br /&gt;
&lt;style type=&quot;text/css&quot;&gt;
#mamp_gem_steps li { margin-bottom: 0.5em; line-height: 1.5em; }
#mamp_gem_steps span { font-family: monospace; font-size: 110%; }
&lt;/style&gt;
&lt;div id=&quot;mamp_gem_steps&quot;&gt;
&lt;ol&gt;
&lt;li&gt;Install the regular &lt;a href=&quot;http://download.living-e.com/MAMP/releases/1.7.2/MAMP_1.7.2.dmg&quot;&gt;MAMP 1.7.2 dmg package&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Download the &lt;a href=&quot;http://downloads.sourceforge.net/mamp/MAMP_1.7.2_src.zip&quot;&gt;MAMP 1.7.2 source code&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Unzip the source code file.&lt;/li&gt;
&lt;li&gt;Open the terminal and go into the source code directory.&lt;/li&gt;
&lt;li&gt;Untar the mysql file and go into the untarred directory:&lt;br /&gt;
&lt;span&gt;
$ tar -xzvf mysql-5.0.41.tar.gz&lt;br /&gt;
$ cd mysql-5.0.41
&lt;/span&gt;
&lt;/li&gt;
&lt;li&gt;This is the Hootbah magic...we&#039;re basically compiling libraries here for the Gem to link against.&lt;br /&gt;
&lt;span&gt;
$ ./configure --with-unix-socket-path=/Applications/MAMP/tmp/mysql/mysql.sock --without-server --prefix=/Applications/MAMP/Library&lt;br /&gt;
$ make -j2
&lt;/span&gt;
&lt;/li&gt;
&lt;li&gt;Copy the compiled libraries into MAMP:&lt;br /&gt;
&lt;span&gt;
$ cp libmysql/.libs/*.dylib /Applications/MAMP/Library/lib/mysql
&lt;/span&gt;
&lt;/li&gt;
&lt;li&gt;Copy the MySQL headers into MAMP...Hootbah didn&#039;t do this but I had been doing it earlier trying to get around some missing mysql.h problems, and figured I&#039;d keep doing it:&lt;br /&gt;
&lt;span&gt;
$ mkdir /Applications/MAMP/Library/include&lt;br /&gt;
$ cp -R include /Applications/MAMP/Library/include/mysql&lt;br /&gt;
&lt;/span&gt;
&lt;/li&gt;
&lt;li&gt;Install the Ruby MySQL Gem:&lt;br /&gt;
&lt;span&gt;
$ sudo env ARCHFLAGS=&quot;-arch i386&quot; gem install mysql -- --with-mysql-config=/Applications/MAMP/Library/bin/mysql_config
&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;

After being used to seeing errors spit out by this statement, finally a pleasant surprise:&lt;br /&gt;&lt;br /&gt;
&lt;span&gt;
Building native extensions.  This could take a while...&lt;br /&gt;
&lt;b&gt;Successfully installed mysql-2.7&lt;/b&gt;&lt;br /&gt;
1 gem installed
&lt;/span&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/div&gt;
Success!
 
    </content:encoded>

    <pubDate>Thu, 29 Jan 2009 08:31:01 -0800</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/175-guid.html</guid>
    
</item>
<item>
    <title>Grepping from Ruby</title>
    <link>http://boonedocks.net/mike/archives/174-Grepping-from-Ruby.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/174-Grepping-from-Ruby.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=174</wfw:comment>

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

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    I recently needed to run through one data file, pull a number, and look that number up in several other data files. So in Ruby, I first opened the initial file, pulled the number, and then opened the other files, iterating through every line until I found a match, then call break to move on. This worked, but it was sort of slow.&lt;br /&gt;&lt;br /&gt;

It occurred to me that I could use grep to see if the number was in the other files. So I had to figure out how to call it from Ruby. Here&#039;s what I came up with:&lt;br /&gt;&lt;br /&gt;

&lt;script src=&quot;http://gist.github.com/33175.js&quot;&gt;&lt;/script&gt;

The speed improvement depends on how many searches you&#039;re doing and the size of the files you&#039;re searching, but in a quick test the grep calls were 5x faster.
 
    </content:encoded>

    <pubDate>Sun, 07 Dec 2008 08:30:06 -0800</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/174-guid.html</guid>
    
</item>
<item>
    <title>'Shoulda' Tested My App</title>
    <link>http://boonedocks.net/mike/archives/172-Shoulda-Tested-My-App.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/172-Shoulda-Tested-My-App.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=172</wfw:comment>

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

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    &lt;a href=&quot;http://www.thoughtbot.com/projects/shoulda&quot;&gt;Shoulda&lt;/a&gt; is a handy plugin for Rails (now a Gem), which makes writing tests easier. It&#039;s worth checking out. Shoulda has been very helpful with a big Rails project I&#039;ve been working on all summer, and I submitted a couple small contributions and bug fixes. I was surprised to see my name mentioned in the &lt;a href=&quot;http://giantrobots.thoughtbot.com/2008/9/30/shoulda-2-0&quot;&gt;newest release&lt;/a&gt;, but I appreciate it, and it was fun helping out! 
    </content:encoded>

    <pubDate>Fri, 10 Oct 2008 19:42:23 -0700</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/172-guid.html</guid>
    
</item>
<item>
    <title>Rake and Constants</title>
    <link>http://boonedocks.net/mike/archives/171-Rake-and-Constants.html</link>
            <category>Ruby</category>
    
    <comments>http://boonedocks.net/mike/archives/171-Rake-and-Constants.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=171</wfw:comment>

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

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    Here&#039;s a gotcha that I came across today: don&#039;t define a constant as something in one Rails rake task file, and then define the same constant as something different in another file, because the last constant will supercede them all:
&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: monospace;&quot;&gt;
&lt;b&gt;a.rake:&lt;/b&gt;&lt;br /&gt;
DATA = &#039;Hi there!&#039;&lt;br /&gt;
&lt;br /&gt;
desc &quot;Test A&quot;&lt;br /&gt;
task :test_a do&lt;br /&gt;
&amp;#160;&amp;#160;puts DATA&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;b.rake:&lt;/b&gt;&lt;br /&gt; 
DATA = &#039;Hallo!&#039;&lt;br /&gt;
&lt;br /&gt;
desc &quot;Test B&quot;&lt;br /&gt;
task :test_b do&lt;br /&gt;
&amp;#160;&amp;#160;puts DATA&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
$ rake test_a&lt;br /&gt;
Hallo!&lt;br /&gt;
&lt;br /&gt;
$ rake test_b&lt;br /&gt;
Hallo!&lt;br /&gt;
&lt;/div&gt;&lt;br /&gt;

I guess this happens because Rake is loading all of the task files before running the requested task. There&#039;s probably a way to namespace the constant, but I need to do more research on that. In the meantime I&#039;ll use different constant names!
 
    </content:encoded>

    <pubDate>Tue, 16 Sep 2008 15:12:36 -0700</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/171-guid.html</guid>
    
</item>
<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 18:27:27 -0700</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/168-guid.html</guid>
    
</item>
<item>
    <title>Printer held Hostage by Ink Cartridge</title>
    <link>http://boonedocks.net/mike/archives/166-Printer-held-Hostage-by-Ink-Cartridge.html</link>
            <category>Tech</category>
    
    <comments>http://boonedocks.net/mike/archives/166-Printer-held-Hostage-by-Ink-Cartridge.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=166</wfw:comment>

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

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    I&#039;ve had a Canon Pixma MX700 multifunction printer since the beginning of the year. I&#039;ve been pretty happy with it. It&#039;s worked well for scanning, copying, faxing and printing. Until today. Today I needed to scan something, and was greeted with the following message when I turned it on:
&lt;blockquote&gt;&lt;b&gt;U150&lt;/b&gt; The following ink tank cannot be recognized.&lt;/blockquote&gt;
The yellow cartridge was indicated. I though that it was an odd problem, but I didn&#039;t care for the moment, because I didn&#039;t want to print, just scan. But no button on the printer would bypass this error and let me scan.&lt;br /&gt;&lt;br /&gt;
I ended up calling Canon, and happily received a domestic phone rep. He had me try a couple things, but eventually decided that the yellow ink would need to be replaced. They would send me one free. I asked if there was any way to bypass the error so I could just scan, and he said there was not. If I wanted to use it today I would have to go out and buy a yellow ink cartridge. So after driving all the way across town and spending $16, I have my printer back...for now.&lt;br /&gt;&lt;br /&gt;
It seems like questionable design to cripple all the functions of the printer just because one color cartridge is faulty. A better failure mode would be to only prevent color printing. Black and white printing, and the other printer functions should still be usable. Hey Canon, how about updated firmware for this? Please?
 
    </content:encoded>

    <pubDate>Mon, 07 Apr 2008 17:57:03 -0700</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/166-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>3</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.&lt;br /&gt;&lt;br /&gt;
&lt;strong&gt;Update:&lt;/strong&gt; This idea was expanded and found its way into a gem: &lt;a href=&quot;http://rubygems.org/gems/ruby-imagespec&quot;&gt;ruby-imagespec&lt;/a&gt;. Credit for that goes to Brandon Anderson, Michael Sheakoski, and Dimitrij Denissenko. 
    </content:encoded>

    <pubDate>Mon, 10 Mar 2008 19:22:03 -0700</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 04:55:47 -0800</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/159-guid.html</guid>
    
</item>
<item>
    <title>Formatting a Javascript Date for MySQL</title>
    <link>http://boonedocks.net/mike/archives/157-Formatting-a-Javascript-Date-for-MySQL.html</link>
            <category>Tech</category>
    
    <comments>http://boonedocks.net/mike/archives/157-Formatting-a-Javascript-Date-for-MySQL.html#comments</comments>
    <wfw:comment>http://boonedocks.net/mike/wfwcomment.php?cid=157</wfw:comment>

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

    <author>nospam@example.com (Mike Boone)</author>
    <content:encoded>
    I don&#039;t like to code in JavaScript, but that&#039;s the Ajax-y wave of the future. So I write it when I have to. This week I needed to format a Javascript date as a MySQL-style date like 2007-12-08.&lt;br /&gt;&lt;br /&gt; JavaScript apparently doesn&#039;t have a nice date formatting function or even a generalized sprintf. Another Javascript quirk is that the Date.getMonth() function returns 0-11, while the getDate() function returns 1-31. I&#039;m not sure what the designer was thinking on that one.&lt;br /&gt;&lt;br /&gt;

I came up with this function...feel free to use it in your code with or without credit:&lt;br /&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: monospace;&quot;&gt;
function formatDate(date1) {&lt;br /&gt;
&amp;#160;&amp;#160;return date1.getFullYear() + &#039;-&#039; +&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;(date1.getMonth() &lt; 9 ? &#039;0&#039; : &#039;&#039;) + (date1.getMonth()+1) + &#039;-&#039; +&lt;br /&gt;
&amp;#160;&amp;#160;&amp;#160;&amp;#160;(date1.getDate() &lt; 10 ? &#039;0&#039; : &#039;&#039;) + date1.getDate();&lt;br /&gt;
}&lt;br /&gt;
&lt;/div&gt;
 
    </content:encoded>

    <pubDate>Sat, 08 Dec 2007 05:59:50 -0800</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/157-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 13:36:34 -0700</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>10</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 14:17:38 -0700</pubDate>
    <guid isPermaLink="false">http://boonedocks.net/mike/archives/151-guid.html</guid>
    
</item>

</channel>
</rss>