San Francisco Caltrain Punchcard May 27, 2012

I found GitHub’s punchcard a very useful visualization for displaying data. Thus I wrote my own using d3. You can find the source over at my GitHub repository jeyb/d3.punchcard. To show an example, the punchcard below shows the San Francisco southbound schedule and the San Mateo northbound schedule. Clearly the Caltrain is tailored toward the 9-5 crowd.

Gemfile.local March 30, 2012

Bundler is excellent for managing dependencies of my applications but not for managing my custom dependencies. There are gems that I’d like to use locally, knowing their implications, without forcing that behavior on other developers or designers on the team. One such gem is rails-dev-boost, which speeds up my development environment considerably. Gemfile.local solves this limitation. Create Gemfile.local at Rails.root with the following content.

 1  eval File.read('Gemfile')
 2
 3  group :development do
 4    gem 'rails-dev-boost', :git => 'git://github.com/thedarkone/rails-dev-boost.git', :require => 'rails_development_boost'
 5  end

Then execute these commands from Rails.root:

 $  cp Gemfile.lock Gemfile.local.lock
 $  BUNDLE_GEMFILE=Gemfile.local bundle
 $  echo "$(cat .gitignore)\nGemfile.local\nGemfile.local.lock" > .gitignore
 $  git commit -m "Added Gemfile.local to .gitignore." .gitignore

Whenever you need to use your custom Gemfile.local you can prepend the command with BUNDLE_GEMFILE=Gemfile.local bundle exec. For example, start the rails server by executing BUNDLE_GEMFILE=Gemfile.local bundle exec rails s and enjoy the benefits of your custom Gemfile.

Thin and Fat Arrows in CoffeeScript February 13, 2012

The difference between -> and => is often overlooked due to the ease of always using =>. We can grasp the difference by this example which should trigger a console.log() when an element is clicked and double-clicked.

 1  this.callback = ->
 2    console.log 'Callback triggered!'
 3  $('#id').bind 'click', -> @callback()
 4  $('#id').bind 'dbclick', => @callback()
 1  var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
 2  this.callback = function() {
 3    return console.log('Callback triggered!');
 4  };
 5  $('#id').bind('click', function() {
 6    // this is bound to the HTML element, which has no callback() function.
 7    return this.callback();
 8  });
 9  $('#id').bind('dbclick', __bind(function() {
10    // this is bound to the local context by __bind(), which does have a callback() function.
11    return this.callback();
12  }, this));

If we were to click on the bound element, it would cause a JavaScript error since there is no callback() function in this context. jQuery’s bind() function assigns the HTML element as the context.

Dissimilarly, if we were to double-click on the bound element it would trigger the callback() function. The __bind() function defined on line 1 uses apply to assign the correct context. The same behavior can be replicated by using jQuery.proxy as follows.

 1  this.callback = ->
 2    console.log 'Callback triggered!'
 3  $('#id').bind 'click', -> @callback()
 4  $('#id').bind 'dbclick', jQuery.proxy(->
 5    @callback()
 6  , @)
 1  this.callback = function() {
 2    return console.log('Callback triggered!');
 3  };
 4  $('#id').bind('click', function() {
 5    // this is bound to the HTML element, which has no callback() function.
 6    return this.callback();
 7  });
 8  $('#id').bind('dbclick', jQuery.proxy(function() {
 9    // this is bound to the local context by jQuery.proxy(), which does have a callback() function.
10    return this.callback();
11  }, this));

Scarce startup culture of Toronto February 12, 2012

I lived in Toronto for fifteen years, I still call it home. There was no shortage of jobs for skilled Ruby, Rails or JavaScript developers. The available options, however, left a yearning desire. Notable Ruby on Rails shops focused on consulting; I wanted to focus on a product. Others are subsidiaries of organizations that drank the Rails Kool-Aid. The remaining few fought tooth and nail to receive funding. For these reasons, I moved to San Francisco.

It’s been slightly over a year since I moved and began work for Doximity. Prior to my first day on the job, I’ve never been to San Francisco. In hindsight, it was the best move for my career. Working in the San Francisco bay area has honed my skills as a developer. Talented people who focus on sharing knowledge, large array of meetups where one can collaborate on ideas, startups that contribute to the open-source community, all sums up to make this an idyllic city for developers.

From the perspective of a Torontonian, I am amazed by how much this city revolves around startups and technology. I hope one day Toronto can become an incubator for startups. The talent exists, attaining funding remains difficult. Unfortunately, nobody in Toronto wants to fund something that isn’t already generating revenue.