You've got a lot of Gal

Yet another blog about Ruby, Rails, Javascript, Apple, Malteses and Shih-Tzus by Gal Steinitz

This site is completely static. It was last generated with Octopress and Jekyll on Oct 25, 2012 and hosted on github pages.

Global Javascript Events With Backbone JS

In the past I leveraged jQuery’s events to create a client side message bus in javascript. Triggering and subscribing to global events is a great way to decouple your javascript code and make it more flexible and maintainable. Enter backbone JS, which has even better built in support for events. An easy way to get started is to bolt on event support to your main global app object:

From Wordpress to Octopress

Just moved my blog from wordpress.com to Octopress. Octopress runs atop jekyll to generate static files and can deploy to pretty much any hosting provider - but has special tools for hosting on github pages - where this blog is now hosted. First I looked at Jekyll on its own, but seems like it required too much manual configuration - whereas Octopress makes all the choices for you. You just need to make changes.

Blog posts are created by editing a text file locally using Textmate 1 in markdown, generating the blog and deploying. The blog’s filename implies the posting date, for example this posts file name is

sources/_posts/2012-09-07-from-wordpress-to-octopress.markdown

and you also include what they call a YAML UpfrontMatter to the top of every post to include additional metadata. For example for this post:

1
2
3
4
5
6
7
---
layout: posta
title: "From wordpress to octopress"
date: 2012-09-07 23:10
comments: true
categories:
---

So far I’m really happy with it. If you’d like to give it a whirl yourself, All the info you need is at Octopress. It’s got a very vibrant community, which is always a good thing.

Javascript: “Unresponsive Script” Error

What it means:

Javasript code is running for longer than 10 seconds. Thats the limit on Firefox 15. Other browsers may vary, googling reveals Internet Explorer’s limit is 5 million lines of code (!) and Chrome allows 30 seconds.

Jasmine Debugging: Actual Line Numbers in Error Messages

If you’re using Pivotal Labs’ excellent Jasmine javascript BDD testing framework you may run into this. With Rails 3 Asset Pipeline, jasmine concatenates your js files into a single file - and therefore the line numbers on your stack traces are not useful (they will show the concatenated line numbers).

For example, you may see an error from the concatenated application.js line #17,403 instead of home.js line #15. To get jasmine to reference the javascript files individually and thereby provide more informative error messages, add this in config/initializers/jasmine.rb:

1
2
3
4
5
6
7
8
9
module Jasmine
  class Config
    def src_files
      Rails.application.assets["application"].dependencies.map do |asset|
        "assets/" + asset.logical_path
      end
    end
  end
end

NOTE: This only works if your application.js requires all your javascript files and doesn’t include any javascript itself.