September 2009
1 post
Palm Pre max image height in pixels
For you future Palm Pre developer googlers: the max height is 425. Don’t trust the emulator!!!!
February 2009
1 post
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!
January 2009
1 post
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.
December 2008
1 post
If you want Ruby's strftime to give you single...
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.
August 2008
4 posts
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
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);
}
I want a US phone number that I can SMS, which...
Tweet me with ideas
Dreamhost Subversion stops working after enabling...
The solution to this is to just setup a subdomain for your Subversion repository.
July 2008
2 posts
A quick way to find slow Rails actions
tail -10000 log/production.log | egrep "Completed in [0-9]{2,}"
via RailsMachine support
Grouping by Object#hash
I liked this little idiom from Tobias.
servers = [ 'memcache1', 'memcache2', 'memcache3' ]
servers[ 'product-1' % servers.size ]
June 2008
2 posts
"Net::SMTPFatalError" with "553 5.0.0" and "User...
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>,...
Rails 2.1 breaks attachment_fu
Here’s a patch
http://pastie.textmate.org/145188
April 2008
1 post
History Blog Meme
history 1000 | awk ‘{a[$2]++}END{for(i in a){print a[i] ” ” i}}’ | sort -rn | head
95 cd
72 ls
52 svn
49 rake
27 exit
24 p
22 sudo
20 mimi
16 cap
15 git
via objo
March 2008
2 posts
One man's fight to disable Ferret during...
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
Reverting in git
git reset —hard
February 2008
3 posts
TextMate regex for removing newlines in CSV
Find: (,"[^"]+)\n([^"]+")
Replace: $1 $2
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.
Combined logging for Sinatra and ActiveRecord
ActiveRecord::Base.logger = Logger.new(SOME_LOG_NAME)
Sinatra::Environment.prepare_loggers(ActiveRecord::Base.logger)
Close all tabs in TextMate
Command - Control - W
December 2007
3 posts
dup vs. clone
You might think that ActiveRecord::Base#dup is what you want, but you really want clone.
ActiveRecord's QueryCache#uncache
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:
class Something < ActiveRecord::Base
def previous(attribute)
self.class.find(id)[attribute]
end
end
That worked just fine in Rails 1.2. But Rails 2.0 has request-scoped query...
finder_sql String gets eval'd later
If you ever need to use ActiveRecord’s has_many with finder_sql, 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.
Do this:
has_many :foos,
:finder_sql => 'select ... where...
November 2007
2 posts
Watch out for ISO-8859-1 on Rails
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. Here’s one way to fix it, but be sure to heed Brian’s comment.
Do NOT require Rails models in Rails unit tests
When the test runs, it will load the class twice. Loading the class twice means that all of the model’s lifecyle hooks will get called twice.
October 2007
3 posts
InPlaceEditor loadTextURL changed to GET
In the latest Scriptaculous InPlaceEditor, the loadTextURL will use a GET request. If you’re on Rails and using RESTful Resources for that action, make sure to update your routes.rb from :post to :get.
MySQL gem: NSLinkModule() error
If you’re getting this error when you try to connect to MySQL through Ruby, follow these instructions.
ActiveRecord predicate method
Keep in mind that you can use a predicate method to access your boolean attributes in the Ruby way.
placement = ImagePlacement.create!(:ignored => true)
placement.ignored? # true
September 2007
6 posts
update_attribute vs. update_attributes
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 update_attribute bypasses validations.
Unsettable ActiveRecord::Base attribute
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 restful_authentication plugin…
attr_accessible :login, :email, :password, :pass...
This method is a nice way to lock down which attributes can be changed in an ActiveRecord, but it can be maddening when...
1 Rails Builder Template, hold the Layout
When you’re using Rails builder templates, make sure you render :layout => false
To uninstall MySQL on OS X
Follow these instructions
BackgrounDRb: Worker#delete is your friend
To avoid spawning an ever-increasing supply of Ruby processes, add an ensure self.delete at the end of your BackgrounDRb workers’ do_work method.
ActionController::Base#layout can take a symbol
Use this technique when you need to determine layout at the last moment.
August 2007
3 posts
Excluding directories from TextMate project
Simply specify the directories you want…
mate app config db lib public test vendor/plugins
For one thing, this should make the project search much faster. I had resorted to grep up until now.
Missing mod_proxy_balancer.so
If you’re trying to use mod_proxy_balancer in Apache 2 and it’s not sitting in the same directory as the rest of your modules … you’re probably going to have to compile Apache from source.
This was helpful
Boogie Tools BounceStudio Ruby Integration
In order to get it working I had to:
Follow these
Bang my head against the wall for several hours, trying to get samples/RUBY/source/setup.rb to see the .so file
Rename “BounceStudio” in samples/RUBY/source/ext/(extconf.rb|bounce_studio.c) to “BounceStudio(32|64)”
Yearn for a couch in relief