Skip to content

Instantly share code, notes, and snippets.

View levi's full-sized avatar

Levi McCallum levi

View GitHub Profile
@levi
levi / namespace.js
Created November 16, 2012 01:42
Dynamic Namespaces
var APP = {};
APP.namespace = function(path) {
var parts = path.split('.'),
parent = APP;
if (parts[0] === 'APP') parts = parts.slice(1);
for (var i = 0, len = parts.length; i < len; i++) {
if (typeof parent[parts[i]] === 'undefined') {
@levi
levi / gist:3876797
Created October 12, 2012 01:16 — forked from cameronmcefee/gist:2641743
Font Configuration File
# Font Squirrel Font-face Generator Configuration File
# Upload this file to the generator to recreate the settings
# you used to create these fonts.
{"mode":"expert","formats":["ttf","woff","eot","svg"],"tt_instructor":"default","options_subset":"advanced","subset_custom":"","subset_custom_range":"f000-f073,f200-f273","emsquare":"2048","spacing_adjustment":"0","rememberme":"Y"}
@levi
levi / gist:3828671
Created October 3, 2012 18:05
How Javascript Constructors Work

I found this laying around in an old note app I haven't opened in a while. Whenever I learn something new, I like to write it down and explain it to myself in the most basic and non-allegorical method possible. Turns out that these explanations make for great unpublished blog posts. Constructors are probably one of the most mysterious features of Javascript and I wish someone would have explained it to me like this when I first learnt it.

The prototype property of a constructor has always confused me. I've never really been certain to what it actually did. I just knew that it was a simple way of adding properties and methods to a class-like object that I could instantiate. This week, I decided to delve into the problem to figure out what is actually going on here.

Turns out the new construct is just a distraction added by some programmers who thought Javascript needed to appeal to the Java community. Sounds like a good idea during 1995. However, the introduction of this language construct put Javascript

@levi
levi / Stately ViewState support for Backbone.js Views.js
Created August 17, 2012 19:22 — forked from camwest/Stately ViewState support for Backbone.js Views
A simple implementation of view states for Backbone.js
// (c) 2010 Cameron Westland, Big Bang Technology Inc.
// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://bigbangtechnology.github.com/stately
/**
Example:
var MyView = Backbone.View.extend(Stately).extend({
states: {
EDITING: "editing",
@levi
levi / gist:2323328
Created April 6, 2012 21:55 — forked from dx7/gist:1333785
Installing ruby-debug with ruby-1.9.3-p125
# Install with:
# bash < <(curl -L https://raw.github.com/gist/2323328)
#
# Reference: http://blog.wyeworks.com/2011/11/1/ruby-1-9-3-and-ruby-debug
echo "Installing ruby-debug with ruby-1.9.3-p125 ..."
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
module MyEngine
module Admin
class ApplicationController < ActionController::Base
def current_ability
MyEngine::Ability.new(current_user)
end
end
end
end
Uninitialized constant Ability
load_and_authorize_resource :class => MyEngine::User
Uninitialized constant User
module MyEngine
module Admin
class UsersController < Admin::ApplicationController
load_and_authorize_resource
def index
...
end
end
end