I’ve spent almost the last two weeks dealing with Date and Time Zone related issues within one of the applications I contract on. This is a just a list of notable behaviours I expereinced whilst working with Ruby, Rails, Dates & TimeZones. Note: DST is in effect at the time of writing. Inconsistent Handling of DST In the code below we instantiate an ActiveSupport::TimeZone object. I would love to think that this instance would know everything about that Time Zone.
Last week during my main work contract I had been tasked with doing some would-be trivial content updates to a section of a client application. Content updates would normally involve hopping into a view changing some images or text and re-deploying. This particular section though is a little more complex then that and way more complex then it should be. The Setup This particular section of the application has rotating content.
A quick note on logging SQL queries in DataMapper 1.2 so you can see exactly what’s going on behind the scenes. Seeing the query can be beneficial in debugging when getting unexpected results or trying to increase query performance. DataMapper::Logger.new($stdout, :debug) Enter that at anytime while running in rails c and you should start seeing the output immediatley. Note If you don’t see the output potentially it’s because of DM’s identiity map.
Notes: Working with ruby 1.8.7 but 1.9 solution presented at bottom. While working on my main contract today I needed to create a new array based off mutated values of an existing array. Simple enough I’ll just use Enumerable::map right? Almost immediatley I realized I needed to make a reference to an array via the loops index. I first checked to see if a map_with_index existed similar to Enumerable::each_with_index. It doesn’t.
So while in the #RubyOnRails IRC channel late at night (never a good idea) some silly conversation occured: (someone gists some code) sevenseacat: empty array seems the silly thing to have Tarential: sometimes I like to add empty arrays, you know, just in case I need them later Tarential: so they’re close at hand tagrudev: little kittens die when you define an unused var brianpWins: but if you do want to leave empty arrays around.
Excited to start running Garnish against Ruby 2.0.0 I attempted installation tonight to get build failed: downloading ruby-2.0.0-p0.tar.gz... -> http://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.gz Installing ruby-2.0.0-p0... BUILD FAILED Inspect or clean up the working tree at /var/folders/td/0z79ghbs125193ngl8y0j8180000gn/T/ruby-build.20130312001656.54615 Results logged to /var/folders/td/0z79ghbs125193ngl8y0j8180000gn/T/ruby-build.20130312001656.54615.log Last 10 log lines: installing default gems: /Users/brianp/.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0 (build_info, cache, doc, gems, specifications) bigdecimal 1.2.0 io-console 0.4.2 json 1.7.7 minitest 4.3.2 psych 2.0.0 rake 0.9.6 rdoc 4.0.0 test-unit 188.8.131.52 The Ruby openssl extension was not compiled.
Forward: This post is mainly copypasta from an answer I wrote on StackOverflow. It also takes into account the version of Mongoid being used predates the includes method. The includes method being the suggested best practice for the problem now. includes will be mentioned at the bottom of the post. Take me to the current best practice. How to deal with n+1 issues utilizing identity maps: What is the n+1 issue?