JavaScript borrowed the new and delete keywords from its less-dynamic predecessor languages. They feel a bit out of place in a garbage collected language and are a source of confusion for newbies one of the reasons popular libraries such as jQuery, d3, and Ember.js have adopted APIs that don t require using new at all. In this post I ll show you one way do it, and why you should consider it for…
A common pattern with client-side MVC applications is to embed the data for a base set of models in the initial page instead of making a separate AJAX request to load them. In a Rails application, this is typically done by interpolating the result of a call to to_json in the view. The Backbone.js docs provide this example: 1 2 3 4 5 6 <script> var Accounts = new Backbone.Collection;…
Like model classes in many other JavaScript MVC frameworks, Ember.Object uses get() / set() -based property accessor functions rather than native JavaScript properties: 1 2 3 4 5 MyApp . president = Ember . Object . create ({ name : "Barack Obama" }); MyApp . president . get ( 'name' ); // Not `MyApp.president.name` Of course, Ember provides computed properties and property bindings, features that…
Have you ever dug through the commit history of an open source project, peeling away layers, sifting for clues, trying to answer the question, why does this code do what it does ? I call this process code archaeology . Code archaeology is made difficult by historical debris: reformatting, refactoring, code movement, and other incidental changes. This post takes a look at techniques for separating…
Ruby on Mac OS Lion is going through a bit of a rough patch, installation-wise. With Xcode 4.2, clang became the default compiler and gcc was no longer included. Unfortunately, this has caused a lot of grief for Rubyists on OS X, because for a while, MRI did not officially support compiling with clang. With the release of 1.9.3-p125, that situation has changed clang is now officially supported but…
On July 11th 2011, SF park announced the first set of meter rate adjustments . Meter operational hours were divided into six distinct rate periods, and the hourly price of metered parking in the project s seven pilot areas was adjusted on a block-to-block basis in response to parking demand during each period: +25¢ in periods of 80% or more occupancy No change in periods of 60-80% occupancy −25¢…
A kernel density estimate provides a means of estimating and visualizing the probability distribution function of a random variable based on a random sample. In contrast to a histogram, a kernel density estimate provides a smooth estimate, via the effect of a smoothing parameter called the bandwidth , here denoted by h . With the correct choice of bandwidth, important features of the distribution…
In Ruby 1.8, constant lookup is mostly lexically scoped , even when using class_eval or instance_eval . That is, constant lookup always searches the chain of lexically enclosing classes or modules. The first lexically enclosing class or module is not necessarily the same as self.class : puts "#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}" X = '::X' class Foo X = 'Foo::X' def foo puts "instance method: #{X}"…
The state of Selenium on Ruby is a bit confusing. Among the top google results for selenium ruby are several links that are badly out of date, and it s not clear which of the many gems are ones you would want to use. This post aims to clear up some of the confusion. First of all, you should be aware that there are two Selenium APIs: the original 1.0 API, called Selenium-RC, and a newer 2.0 API…