When defining a class method in ruby, you can put conditional logic around the function declaration. This allows you to define separate methods based on your environment.
Example:
if VERBOSE
def trace(message)
puts message
end
else
def trace(message)
print “.”
end
end
hpricot provides a nice dom traversal library for web scraping. When using hpricot to parse xml docs, I discovered that Hpricot automatically downcases xml nodes. XML files generated by Microsoft Excel generate nodes with capital letters.
example:
becomes:
doc:/workbook
kind of a small thing, that I’m documenting for myself.
Mysql statement for changing site url:
UPDATE {table_prefix}wp_options SET option_value = replace(option_value, ‘http://oldlocation’, ‘http://newlocation’) WHERE option_name = ‘home’ OR option_name = ’siteurl’;
If you’re recursively looping through all your active record models, using Model.find_each is more efficient than Model.all.each. This incrementally polls the database without requiring the entire result set to load into memory.