Interesting
- Ruby MRI seems to have taken a step back in time, a dangerous, but useful feature (to some) is the goto statement.
It appears that DateTime object has some issues with doing math.
DateTime.now - 1.hour #raises TypeError DateTime.now - 3600 #works as expected 1.hour.class #FixnumReading the CSS property
background-positionin Chrome returns an invalid value. Don’t rely on it.- Github was hacked! They had a security issue that was a result of
attr_accessiblebeing uses incorrectly. Remember to authorize your SSH keys. - Need help with cron? Use http://cronwtf.github.com to convert cron into friendly English.
&&,||, and!vs.and,or, andnot. It is highly recommended to always use the strict logical operators (&&,||, and!) because the keywords
(and,or, andnot) don’t have the same operator precedence.- When evaluating variables in strings with
bash, its better to use${var}than$var. The curly-brace allows you to evaluate a variable with copy behind it. For example,${var}asdfand$varasdfevaluate differently because of the expected variable name.
Help
Rails <3.1 has some gotchyas when using
:inverse_ofoption.class Note < ActiveRecord::Base has_many :contacts, inverse_of: :note end class Contact < ActiveRecord::Base belongs_to :note, touch: true #for triggering the note observer when the contact is updated end class NotObserver def after_touch(note) note.contacts # does not have the new attributes updated unless you specify the :inverse_of end end # Somewhere in the code... contact.update_attributes....When table names are not namespaced on a class. What is the best way to work with this if we want table names to be namespaced?
class Foo::Bar < ActiveRecord::Base end > Foo::Bar.table_name == "bars" true
Actually, it seems like the 1.hour value works as expected. The 1.hour.ago value is a DateTime so that should raise a TypeError. But:
>> DateTime.now – 1.hour
=> Fri, 09 Mar 2012 07:29:25 -0500
This works fine and returns the expected value.
>> 1.hour.to_i
=> 3600
Story checks out, it’s an hour.
>> DateTime.now – 3600
=> Wed, 01 May 2002 08:29:43 -0500
Huh?
March 9, 2012 at 5:34 am