<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><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>copyplist failed ... exit code 71</title><description>I got this error when trying to compile an iPhone project in XCode.  I found the answer to my problem on StackOverflow, but I couldn’t upvote or thank Jimmy for &lt;a href="http://stackoverflow.com/questions/384962/copyplist-failed-with-exit-code-71#567105"&gt;his solution&lt;/a&gt;, which is related to a Ruby install.  Thanks Jimmy!</description><link>http://feedproxy.google.com/~r/stumblog/~3/21cUlGI_9PA/81780811</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/81780811</guid><pubDate>Thu, 26 Feb 2009 13:55:34 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/81780811</feedburner:origLink></item><item><title>If before_update is being called on create...</title><description>It’s because you have an update in your after_create.

&lt;pre&gt;
class User &lt; ActiveRecord::Base
  before_update :audit_info
  after_create :generate_key

private

  def generate_key
    update_attribute(:key, generate_stuff)
  end

  def audit_info
    AuditLog.big_change!(self)
  end
end
&lt;/pre&gt;

Yep, &lt;tt&gt;audit_info&lt;/tt&gt; will get called when you &lt;tt&gt;User.create&lt;/tt&gt;.</description><link>http://feedproxy.google.com/~r/stumblog/~3/m2TWT0LdkH8/68569000</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/68569000</guid><pubDate>Mon, 05 Jan 2009 15:35:49 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/68569000</feedburner:origLink></item><item><title>If you want Ruby's strftime to give you single digit hours</title><description>Then the undocumented %l (yes, a lower-case L) is your friend.

&lt;pre&gt;
Time.now.strftime("%I:%M%p")
# generates 05:00pm
Time.now.strftime("%l:%M%p")
# generates 5:00pm
&lt;/pre&gt;

That’s just evil that l looks so much like I.</description><link>http://feedproxy.google.com/~r/stumblog/~3/4DrWBHFYlX0/67508555</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/67508555</guid><pubDate>Tue, 30 Dec 2008 10:28:00 -0600</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/67508555</feedburner:origLink></item><item><title>Rails transactions don't rollback in tests</title><description>Here’s a &lt;a href="http://railspikes.com/2007/3/28/testing-transactions"&gt;discussion&lt;/a&gt;, and here’s the simplest solution:

&lt;pre&gt;
# in your TestCase
self.use_transactional_fixtures = false
&lt;/pre&gt;</description><link>http://feedproxy.google.com/~r/stumblog/~3/9yURmjyLTmk/46875151</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/46875151</guid><pubDate>Thu, 21 Aug 2008 14:58:00 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/46875151</feedburner:origLink></item><item><title>Porting Ruby number_with_delimiter to Perl</title><description>Ruby:
&lt;pre&gt;
def number_with_delimiter(number)
  parts = number.to_s.split('.')
  parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
  parts.join '.'
end
&lt;/pre&gt;

Perl:
&lt;pre&gt;
sub number_with_delimiter {
    my $number = shift;
    my @parts = split(/\./, $number);
    $parts[0] =~ s/(\d)(?=(\d\d\d)+(?!\d))/$1,/g;
    return join(".", @parts);
}
&lt;/pre&gt;</description><link>http://feedproxy.google.com/~r/stumblog/~3/rUBXHJN6P08/46608041</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/46608041</guid><pubDate>Tue, 19 Aug 2008 17:43:00 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/46608041</feedburner:origLink></item><item><title>I want a US phone number that I can SMS, which will push that message to a URL</title><description>&lt;a href="http://twitter.com/redsquirrel/statuses/890402535"&gt;Tweet me with ideas&lt;/a&gt;</description><link>http://feedproxy.google.com/~r/stumblog/~3/VrCG7hEA6n8/46324667</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/46324667</guid><pubDate>Sun, 17 Aug 2008 15:40:50 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/46324667</feedburner:origLink></item><item><title>Dreamhost Subversion stops working after enabling Passenger</title><description>The solution to this is to just setup a subdomain for your Subversion repository.</description><link>http://feedproxy.google.com/~r/stumblog/~3/zVb__jbCe94/45535348</link><guid isPermaLink="false">http://redsquirrel.tumblr.com/post/45535348</guid><pubDate>Mon, 11 Aug 2008 08:52:53 -0500</pubDate><feedburner:origLink>http://redsquirrel.tumblr.com/post/45535348</feedburner:origLink></item><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://feedproxy.google.com/~r/stumblog/~3/42_99bRjJZk/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://feedproxy.google.com/~r/stumblog/~3/sJFkyWKyCMg/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://feedproxy.google.com/~r/stumblog/~3/Lwn39_i-JXU/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://feedproxy.google.com/~r/stumblog/~3/w7-WfEzli0g/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://feedproxy.google.com/~r/stumblog/~3/j44_sm4SBHk/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://feedproxy.google.com/~r/stumblog/~3/Zed_Igb-59g/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://feedproxy.google.com/~r/stumblog/~3/r4_78d-OdV0/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://feedproxy.google.com/~r/stumblog/~3/pCQfbNJc4yU/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://feedproxy.google.com/~r/stumblog/~3/PGRl93WEbsI/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://feedproxy.google.com/~r/stumblog/~3/RDFUspJFQdE/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://feedproxy.google.com/~r/stumblog/~3/_uQYeK-Hyt4/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://feedproxy.google.com/~r/stumblog/~3/feyAL9_F96A/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://feedproxy.google.com/~r/stumblog/~3/zJJy8aXGdxY/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></channel></rss>
