<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><description>Dave Hoover stumbles through technology

</description><title>Red Squirrel Stumblog</title><generator>Tumblr (3.0; @redsquirrel)</generator><link>https://redsquirrel.tumblr.com/</link><item><title>Palm Pre max image height in pixels</title><description>&lt;p&gt;For you future Palm Pre developer googlers: the max height is 425.  Don&amp;rsquo;t trust the emulator!!!!&lt;/p&gt;</description><link>https://redsquirrel.tumblr.com/post/194161171</link><guid>https://redsquirrel.tumblr.com/post/194161171</guid><pubDate>Tue, 22 Sep 2009 08:55:38 -0500</pubDate></item><item><title>copyplist failed ... exit code 71</title><description>&lt;p&gt;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&amp;rsquo;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!&lt;/p&gt;</description><link>https://redsquirrel.tumblr.com/post/81780811</link><guid>https://redsquirrel.tumblr.com/post/81780811</guid><pubDate>Thu, 26 Feb 2009 13:55:34 -0600</pubDate></item><item><title>If before_update is being called on create...</title><description>It&amp;rsquo;s because you have an update in your after_create.

&lt;pre&gt;
class User &amp;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>https://redsquirrel.tumblr.com/post/68569000</link><guid>https://redsquirrel.tumblr.com/post/68569000</guid><pubDate>Mon, 05 Jan 2009 15:35:49 -0600</pubDate></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&amp;rsquo;s just evil that l looks so much like I.</description><link>https://redsquirrel.tumblr.com/post/67508555</link><guid>https://redsquirrel.tumblr.com/post/67508555</guid><pubDate>Tue, 30 Dec 2008 10:28:00 -0600</pubDate></item><item><title>Rails transactions don't rollback in tests</title><description>Here&amp;rsquo;s a &lt;a href="http://railspikes.com/2007/3/28/testing-transactions"&gt;discussion&lt;/a&gt;, and here&amp;rsquo;s the simplest solution:

&lt;pre&gt;
# in your TestCase
self.use_transactional_fixtures = false
&lt;/pre&gt;</description><link>https://redsquirrel.tumblr.com/post/46875151</link><guid>https://redsquirrel.tumblr.com/post/46875151</guid><pubDate>Thu, 21 Aug 2008 14:58:00 -0500</pubDate></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>https://redsquirrel.tumblr.com/post/46608041</link><guid>https://redsquirrel.tumblr.com/post/46608041</guid><pubDate>Tue, 19 Aug 2008 17:43:00 -0500</pubDate></item><item><title>I want a US phone number that I can SMS, which will push that message to a URL</title><description>&lt;p&gt;&lt;a href="http://twitter.com/redsquirrel/statuses/890402535"&gt;Tweet me with ideas&lt;/a&gt;&lt;/p&gt;</description><link>https://redsquirrel.tumblr.com/post/46324667</link><guid>https://redsquirrel.tumblr.com/post/46324667</guid><pubDate>Sun, 17 Aug 2008 15:40:50 -0500</pubDate></item><item><title>Dreamhost Subversion stops working after enabling Passenger</title><description>&lt;p&gt;The solution to this is to just setup a subdomain for your Subversion repository.&lt;/p&gt;</description><link>https://redsquirrel.tumblr.com/post/45535348</link><guid>https://redsquirrel.tumblr.com/post/45535348</guid><pubDate>Mon, 11 Aug 2008 08:52:53 -0500</pubDate></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>https://redsquirrel.tumblr.com/post/43289828</link><guid>https://redsquirrel.tumblr.com/post/43289828</guid><pubDate>Wed, 23 Jul 2008 12:13:00 -0500</pubDate></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>https://redsquirrel.tumblr.com/post/43093249</link><guid>https://redsquirrel.tumblr.com/post/43093249</guid><pubDate>Tue, 22 Jul 2008 01:20:28 -0500</pubDate></item><item><title>"Net::SMTPFatalError" with "553 5.0.0" and "User address required"</title><description>&lt;p&gt;If you ever get this combination of errors while sending email, you should check the raw data for your &amp;ldquo;To:&amp;rdquo; 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&amp;rsquo;t like to send email to &amp;ldquo;John \\&amp;rdquo; &amp;lt;john@example.com&amp;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.&lt;/p&gt;</description><link>https://redsquirrel.tumblr.com/post/38749377</link><guid>https://redsquirrel.tumblr.com/post/38749377</guid><pubDate>Tue, 17 Jun 2008 08:37:00 -0500</pubDate></item><item><title>Rails 2.1 breaks attachment_fu</title><description>&lt;p&gt;Here&amp;rsquo;s a patch&lt;br/&gt;
&lt;a href="http://pastie.textmate.org/145188"&gt;http://pastie.textmate.org/145188&lt;/a&gt;&lt;/p&gt;</description><link>https://redsquirrel.tumblr.com/post/37055363</link><guid>https://redsquirrel.tumblr.com/post/37055363</guid><pubDate>Tue, 03 Jun 2008 15:17:07 -0500</pubDate></item><item><title>History Blog Meme</title><description>&lt;tt&gt;history 1000 | awk &amp;rsquo;{a[$2]++}END{for(i in a){print a[i] &amp;ldquo; &amp;rdquo; i}}&amp;rsquo; | 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>https://redsquirrel.tumblr.com/post/32256127</link><guid>https://redsquirrel.tumblr.com/post/32256127</guid><pubDate>Sat, 19 Apr 2008 12:42:00 -0500</pubDate></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>https://redsquirrel.tumblr.com/post/29295162</link><guid>https://redsquirrel.tumblr.com/post/29295162</guid><pubDate>Wed, 19 Mar 2008 10:50:00 -0500</pubDate></item><item><title>Reverting in git</title><description>&lt;p&gt;git reset &amp;ndash;hard&lt;/p&gt;</description><link>https://redsquirrel.tumblr.com/post/28152774</link><guid>https://redsquirrel.tumblr.com/post/28152774</guid><pubDate>Thu, 06 Mar 2008 16:07:57 -0600</pubDate></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&amp;rsquo;t match anymore because it only removes one newline from a field at a time and some fields may have multiple newlines.</description><link>https://redsquirrel.tumblr.com/post/26997849</link><guid>https://redsquirrel.tumblr.com/post/26997849</guid><pubDate>Fri, 22 Feb 2008 07:44:59 -0600</pubDate></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>https://redsquirrel.tumblr.com/post/26944265</link><guid>https://redsquirrel.tumblr.com/post/26944265</guid><pubDate>Thu, 21 Feb 2008 16:48:16 -0600</pubDate></item><item><title>Close all tabs in TextMate</title><description>&lt;p&gt;Command - Control - W&lt;/p&gt;</description><link>https://redsquirrel.tumblr.com/post/25257650</link><guid>https://redsquirrel.tumblr.com/post/25257650</guid><pubDate>Fri, 01 Feb 2008 10:11:02 -0600</pubDate></item><item><title>dup vs. clone</title><description>&lt;p&gt;You might think that ActiveRecord::Base#dup is what you want, but you really want clone.&lt;/p&gt;</description><link>https://redsquirrel.tumblr.com/post/22727157</link><guid>https://redsquirrel.tumblr.com/post/22727157</guid><pubDate>Mon, 31 Dec 2007 12:32:00 -0600</pubDate></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 &amp;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&amp;rsquo;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&amp;rsquo;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&amp;rsquo;ll need to grab your class to call it like this:&lt;/p&gt;

&lt;pre&gt;
class Something &amp;lt; ActiveRecord::Base
  def previous(attribute)
    self.class.uncached { self.class.find(id)[attribute] }
  end
end
&lt;/pre&gt;</description><link>https://redsquirrel.tumblr.com/post/21159704</link><guid>https://redsquirrel.tumblr.com/post/21159704</guid><pubDate>Sun, 09 Dec 2007 06:20:00 -0600</pubDate></item></channel></rss>
