Red Squirrel Stumblog RSS

Dave Hoover stumbles through technology

Feb
26th
Thu
permalink

copyplist failed ... exit code 71

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 his solution, which is related to a Ruby install. Thanks Jimmy!
Jan
5th
Mon
permalink

If before_update is being called on create...

It’s because you have an update in your after_create.
class User < 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
Yep, audit_info will get called when you User.create.
Dec
30th
Tue
permalink

If you want Ruby's strftime to give you single digit hours

Then the undocumented %l (yes, a lower-case L) is your friend.
Time.now.strftime("%I:%M%p")
# generates 05:00pm
Time.now.strftime("%l:%M%p")
# generates 5:00pm
That’s just evil that l looks so much like I.
Aug
21st
Thu
permalink

Rails transactions don't rollback in tests

Here’s a discussion, and here’s the simplest solution:
# in your TestCase
self.use_transactional_fixtures = false
Aug
19th
Tue
permalink

Porting Ruby number_with_delimiter to Perl

Ruby:
def number_with_delimiter(number)
  parts = number.to_s.split('.')
  parts[0].gsub!(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1,")
  parts.join '.'
end
Perl:
sub number_with_delimiter {
    my $number = shift;
    my @parts = split(/\./, $number);
    $parts[0] =~ s/(\d)(?=(\d\d\d)+(?!\d))/$1,/g;
    return join(".", @parts);
}
Aug
17th
Sun
permalink
Aug
11th
Mon
permalink

Dreamhost Subversion stops working after enabling Passenger

The solution to this is to just setup a subdomain for your Subversion repository.
Jul
23rd
Wed
permalink

A quick way to find slow Rails actions

tail -10000 log/production.log | egrep "Completed in [0-9]{2,}"
via RailsMachine support
Jul
22nd
Tue
permalink

Grouping by Object#hash

I liked this little idiom from Tobias.
servers = [ 'memcache1', 'memcache2', 'memcache3' ]
servers[ 'product-1' % servers.size ]
Jun
17th
Tue
permalink

"Net::SMTPFatalError" with "553 5.0.0" and "User address required"

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 \\” <john@example.com>, in fact it hates sending email to these sorts of people and will do its best to ruin your afternoon if you attempt it.