<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/rss2full.xsl" type="text/xsl" media="screen"?><?xml-stylesheet href="http://feeds.feedburner.com/~d/styles/itemcontent.css" type="text/css" media="screen"?><rss xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><description>Dave Hoover stumbles through technology

</description><title>Red Squirrel Stumblog</title><generator>Tumblr (3.0; @redsquirrel)</generator><link>http://redsquirrel.tumblr.com/</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/stumblog" type="application/rss+xml" /><item><title>A quick way to find slow Rails actions</title><description>&lt;pre&gt;tail -10000 log/production.log | egrep "Completed in [0-9]{2,}"&lt;/pre&gt;

via &lt;a href="http://railsmachine.com"&gt;RailsMachine&lt;/a&gt; support</description><link>http://feeds.feedburner.com/~r/stumblog/~3/343747732/43289828</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/43289828</guid><pubDate>Wed, 23 Jul 2008 12:13:00 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/43289828</feedburner:origLink></item><item><title>Grouping by Object#hash</title><description>I liked this little idiom from &lt;a href="http://blog.leetsoft.com/2008/7/21/rockstar-memcaching"&gt;Tobias&lt;/a&gt;.

&lt;pre&gt;
servers = [ 'memcache1', 'memcache2', 'memcache3' ]
servers[ 'product-1' % servers.size ]
&lt;/pre&gt;</description><link>http://feeds.feedburner.com/~r/stumblog/~3/342286766/43093249</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/43093249</guid><pubDate>Tue, 22 Jul 2008 01:20:28 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/43093249</feedburner:origLink></item><item><title>"Net::SMTPFatalError" with "553 5.0.0" and "User address required"</title><description>If you ever get this combination of errors while sending email, you should check the raw data for your “To:” field.  I stupidly checked only the email address, rather than the raw data, which included the name, which, for some odd reason had backslashes for the last name.  In other words, SMTP doesn’t like to send email to “John \\” &lt;john@example.com&gt;, in fact it hates sending email to these sorts of people and will do its best to ruin your afternoon if you attempt it.</description><link>http://feeds.feedburner.com/~r/stumblog/~3/313802640/38749377</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/38749377</guid><pubDate>Tue, 17 Jun 2008 08:37:00 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/38749377</feedburner:origLink></item><item><title>Rails 2.1 breaks attachment_fu</title><description>Here’s a patch&lt;br/&gt;
&lt;a href="http://pastie.textmate.org/145188"&gt;http://pastie.textmate.org/145188&lt;/a&gt;</description><link>http://feeds.feedburner.com/~r/stumblog/~3/303978972/37055363</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/37055363</guid><pubDate>Tue, 03 Jun 2008 15:17:07 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/37055363</feedburner:origLink></item><item><title>History Blog Meme</title><description>&lt;tt&gt;history 1000 | awk ‘{a[$2]++}END{for(i in a){print a[i] ” ” i}}’ | sort -rn | head&lt;/tt&gt;
&lt;pre&gt;
95 cd
72 ls
52 svn
49 rake
27 exit
24 p
22 sudo
20 mimi
16 cap
15 git
&lt;/pre&gt;
via &lt;a href="http://objo.com/2008/4/19/history-blog-meme"&gt;objo&lt;/a&gt;</description><link>http://feeds.feedburner.com/~r/stumblog/~3/273645536/32256127</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/32256127</guid><pubDate>Sat, 19 Apr 2008 12:42:00 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/32256127</feedburner:origLink></item><item><title>One man's fight to disable Ferret during tests/specs</title><description>&lt;pre&gt;
module ActsAsFerret
  module InstanceMethods
    # Overriding these so we don't hit DRb
    def ferret_create; true; end
    def ferret_update; true; end
    def ferret_destroy; true; end
  end
end
&lt;/pre&gt;</description><link>http://feeds.feedburner.com/~r/stumblog/~3/254387726/29295162</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/29295162</guid><pubDate>Wed, 19 Mar 2008 10:50:00 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/29295162</feedburner:origLink></item><item><title>Reverting in git</title><description>git reset —hard</description><link>http://feeds.feedburner.com/~r/stumblog/~3/247028543/28152774</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/28152774</guid><pubDate>Thu, 06 Mar 2008 16:07:57 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/28152774</feedburner:origLink></item><item><title>TextMate regex for removing newlines in CSV</title><description>&lt;pre&gt;
Find: (,"[^"]+)\n([^"]+")
Replace: $1 $2
&lt;/pre&gt;
This will need to be run repeatedly until it doesn’t match anymore because it only removes one newline from a field at a time and some fields may have multiple newlines.</description><link>http://feeds.feedburner.com/~r/stumblog/~3/239408898/26997849</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/26997849</guid><pubDate>Fri, 22 Feb 2008 07:44:59 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/26997849</feedburner:origLink></item><item><title>Combined logging for Sinatra and ActiveRecord</title><description>&lt;pre&gt;
ActiveRecord::Base.logger = Logger.new(SOME_LOG_NAME)
Sinatra::Environment.prepare_loggers(ActiveRecord::Base.logger)
&lt;/pre&gt;</description><link>http://feeds.feedburner.com/~r/stumblog/~3/239109160/26944265</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/26944265</guid><pubDate>Thu, 21 Feb 2008 16:48:16 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/26944265</feedburner:origLink></item><item><title>Close all tabs in TextMate</title><description>Command - Control - W</description><link>http://feeds.feedburner.com/~r/stumblog/~3/227424163/25257650</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/25257650</guid><pubDate>Fri, 01 Feb 2008 10:11:02 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/25257650</feedburner:origLink></item><item><title>dup vs. clone</title><description>You might think that ActiveRecord::Base#dup is what you want, but you really want clone.</description><link>http://feeds.feedburner.com/~r/stumblog/~3/209162235/22727157</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/22727157</guid><pubDate>Mon, 31 Dec 2007 12:32:00 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/22727157</feedburner:origLink></item><item><title>ActiveRecord's QueryCache#uncache</title><description>&lt;p&gt;Sometimes you need to compare an attribute of an in-memory ActiveRecord instance against its attribute in the database.  The way I usually do that is to grab a fresh instance from the database like this:&lt;/p&gt;

&lt;pre&gt;
class Something &lt; ActiveRecord::Base
  def previous(attribute)
    self.class.find(id)[attribute]
  end
end
&lt;/pre&gt;

&lt;p&gt;That worked just fine in Rails 1.2.  But Rails 2.0 has request-scoped query caching enabled by default, meaning that if you have already executed the same SQL that is generated by &lt;tt&gt;find(id)&lt;/tt&gt;, you’re going to get the &lt;i&gt;exact&lt;/i&gt; same instance back from that call to find.  This makes it impossible to compare in-memory attributes against attributes stored in the database.&lt;/p&gt;

&lt;p&gt;The solution is to use ActiveRecord’s &lt;a href="http://api.rubyonrails.com/classes/ActiveRecord/ConnectionAdapters/QueryCache.html#M001118"&gt;uncache&lt;/a&gt; method.  This is a class method, so you’ll need to grab your class to call it like this:&lt;/p&gt;

&lt;pre&gt;
class Something &lt; ActiveRecord::Base
  def previous(attribute)
    self.class.uncached { self.class.find(id)[attribute] }
  end
end
&lt;/pre&gt;</description><link>http://feeds.feedburner.com/~r/stumblog/~3/197611498/21159704</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/21159704</guid><pubDate>Sun, 09 Dec 2007 06:20:00 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/21159704</feedburner:origLink></item><item><title>finder_sql String gets eval'd later</title><description>&lt;p&gt;
If you ever need to use &lt;a href="http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000655"&gt;ActiveRecord’s has_many with finder_sql&lt;/a&gt;, remember that the key to finder_sql is that the String get eval’d in the context of the ActiveRecord instance rather than the ActiveRecord class.  So make sure you use single quotes!  This prevents the String from being interpolated too soon.
&lt;/p&gt;

Do this:&lt;pre&gt;
has_many :foos,
  :finder_sql =&gt; 'select ... where some_id=#{id}'
&lt;/pre&gt;

Not this:&lt;pre&gt;
has_many :foos,
  :finder_sql =&gt; "select ... where some_id=#{id}"
&lt;/pre&gt; 

In the former case, the &lt;tt&gt;#{id}&lt;/tt&gt; will be the id of the ActiveRecord instance.  In the latter case, the &lt;tt&gt;#{id}&lt;/tt&gt; will be the id of the ActiveRecord class.</description><link>http://feeds.feedburner.com/~r/stumblog/~3/194608168/20748915</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/20748915</guid><pubDate>Mon, 03 Dec 2007 11:10:00 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/20748915</feedburner:origLink></item><item><title>Watch out for ISO-8859-1 on Rails</title><description>Rails uses a UTF-8 charset by default.  If you have latin1 on the backend, you’ll end up with a questions mark (yes, a “?”) instead of a ® on the front end.  &lt;a href="http://www.jarijokinen.com/blog/mongrel-default-character-set"&gt;Here’s one way to fix it&lt;/a&gt;, but be sure to heed Brian’s comment. </description><link>http://feeds.feedburner.com/~r/stumblog/~3/186206538/19597049</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/19597049</guid><pubDate>Fri, 16 Nov 2007 16:21:00 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/19597049</feedburner:origLink></item><item><title>Do NOT require Rails models in Rails unit tests</title><description>When the test runs, it will load the class twice.  Loading the class twice means that all of the model’s &lt;a href="http://api.rubyonrails.com/classes/ActiveRecord/Callbacks.html"&gt;lifecyle hooks&lt;/a&gt; will get called twice.</description><link>http://feeds.feedburner.com/~r/stumblog/~3/185089524/19460923</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/19460923</guid><pubDate>Wed, 14 Nov 2007 21:18:15 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/19460923</feedburner:origLink></item><item><title>InPlaceEditor loadTextURL changed to GET</title><description>In the latest &lt;a href="http://script.aculo.us/"&gt;Scriptaculous&lt;/a&gt; InPlaceEditor, the &lt;tt&gt;loadTextURL&lt;/tt&gt; will use a GET request.  If you’re on Rails and using RESTful Resources for that action, make sure to update your &lt;tt&gt;routes.rb&lt;/tt&gt; from &lt;tt&gt;:post&lt;/tt&gt; to &lt;tt&gt;:get&lt;/tt&gt;.</description><link>http://feeds.feedburner.com/~r/stumblog/~3/174436211/16978183</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/16978183</guid><pubDate>Wed, 24 Oct 2007 12:37:58 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/16978183</feedburner:origLink></item><item><title>MySQL gem:  NSLinkModule() error</title><description>If you’re getting this error when you try to connect to MySQL through Ruby, follow &lt;a href="http://www.railsforum.com/viewtopic.php?pid=26135#p26135"&gt;these instructions&lt;/a&gt;.</description><link>http://feeds.feedburner.com/~r/stumblog/~3/167993521/14996700</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/14996700</guid><pubDate>Wed, 10 Oct 2007 11:12:40 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/14996700</feedburner:origLink></item><item><title>ActiveRecord predicate method</title><description>Keep in mind that you can use a predicate method to access your boolean attributes in the Ruby way.

&lt;pre&gt;
  placement = ImagePlacement.create!(:ignored =&gt; true)
  placement.ignored?  # true
&lt;/pre&gt;</description><link>http://feeds.feedburner.com/~r/stumblog/~3/164151912/13920254</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/13920254</guid><pubDate>Tue, 02 Oct 2007 06:18:24 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/13920254</feedburner:origLink></item><item><title>update_attribute vs. update_attributes</title><description>When do you use one or the other?  (Hint: the answer does not depend on whether you want to update one or many attributes.)  The most important  difference between these methods is that &lt;b&gt;&lt;a href="http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M001043"&gt;update_attribute&lt;/a&gt; bypasses validations&lt;/b&gt;.</description><link>http://feeds.feedburner.com/~r/stumblog/~3/162165816/13378940</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/13378940</guid><pubDate>Thu, 27 Sep 2007 16:29:39 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/13378940</feedburner:origLink></item><item><title>Unsettable ActiveRecord::Base attribute</title><description>If your ActiveRecord is ignoring your attribute, make sure to check that your model class isn’t restricting which attributes are accessible.  Like, say, if you’re using the &lt;a href="http://svn.techno-weenie.net/projects/plugins/restful_authentication/"&gt;restful_authentication&lt;/a&gt; plugin…

&lt;pre&gt;
  attr_accessible :login, :email, :password, :pass...
&lt;/pre&gt;

This method is a nice way to lock down which attributes can be changed in an ActiveRecord, but it can be maddening when you’re trying to add a new attribute and you didn’t notice the &lt;tt&gt;attr_accessible&lt;/tt&gt; declaration.</description><link>http://feeds.feedburner.com/~r/stumblog/~3/161966288/13318955</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/13318955</guid><pubDate>Thu, 27 Sep 2007 07:15:23 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/13318955</feedburner:origLink></item></channel></rss>
