Skip to content

Instantly share code, notes, and snippets.

@anoras
anoras / monkey-patch.coffee
Created March 21, 2012 09:46
Yes, I know this is wrong
# See, I need to have handlebars.js load partials from mongodb.
# So I start by monkey patching handlebars `invoke partial` function...
handlebars.VM.original_invokePartial = handlebars.VM.invokePartial
handlebars.VM.invokePartial = (partial, name, context, helpers, partials, data) ->
# Then I try to find the partial in the DB...
Partial.findOne { fullpath: name.split '.' }, (err, p) =>
if p?
# ..and I use the loaded partial if it exists
handlebars.VM.original_invokePartial(p.partial, name, context, helpers, partials, data)
else
@anoras
anoras / gist:2039758
Created March 14, 2012 21:44
Radio Anders 7.2012
Chuck Mangione, Esther Satterfield - The Land of Make Believe - Live Vocal (1973/Massey Hall, Toronto)
Professor Penguin - Pilot
Remember Remeber - Scottish Widows
The Lovin' Spoonful - Darling Be Home Soon
McDonald & Giles - Tomorrow's People - The Children of Today
Eagles of Death Metal - I Only Want You
DJ Format feat. Edan - Spaceship Earth
Nitrogods - Whiskey Wonderland
Sonic Youth - Kool Thing
Ljodahått - Så stig da i meg, einsemd
@anoras
anoras / guard-jasmine.txt
Created October 11, 2011 20:15
Backbone.js and sinon
Snehvit:web_app anders$ guard-jasmine
Run Jasmine at http://127.0.0.1:3000/jasmine
{
"passed": true,
"stats": {
"specs": 1,
"failures": 0,
"time": 0.008
},
"suites": [
@anoras
anoras / app.coffee
Created October 11, 2011 19:45
Backbone.js and spies
@Vis=
Routers: {}
Collections: {}
Models: {}
Views: {}
init: (args) ->
args = {} unless args?
args['router'] = new Vis.Routers.Main() unless args['router']?
args['route'] = '' unless args['route']?
@anoras
anoras / liquid_templated_controller.rb
Created August 16, 2011 12:29
LiquidTemplatedController
class LiquidTemplatedController < ApplicationController
include Locomotive::Routing::SiteDispatcher
include Locomotive::Render
before_filter :require_site
protected
def render_with_template(*args)
template_path = args.select {|arg| arg.is_a?(Hash) && arg.has_key?(:template_path)}.first[:template_path] rescue 'index'
args.reject! {|arg| arg.is_a?(Hash) && arg.has_key?(:template_path)}
page_partial = render_to_string(*args)
@anoras
anoras / 1-ndc2011.coffee
Created June 13, 2011 11:14
NDC 2011 - Wake Up and Smell The Coffee
# This file contains brushed up version of all the examples I programmed live during the talk.
# CoffeeScript compiles to JavaScript
numbers = [1,2,3,4] # No need for semicolons!
location = conference = "NDC 2011" # Multiple assigns.
awake = false
console.log location # No need for parens!
# Run, Build
@anoras
anoras / gist:996036
Created May 27, 2011 19:57
Getting path right with RVM on Ubuntu
1) Open .bashrc
2) Replace...
[ -z "$PS1" ] && return
..with...
if [[ -n "$PS1" ]]; then
3) Add this to the end of your .bashrc
@anoras
anoras / gist:741250
Created December 14, 2010 22:39
LOC kata
puts %q(
/*****
* This is a test program with 5 lines of code
* \/* no nesting allowed!
//*****//***/// Slightly pathological comment ending...
public class Hello {
public static final void main(String [] args) { // gotta love Java
// Say hello
System./*wait*/out./*for*/println/*it*/("Hello/*");
}
Del Close & John Brent - Basic Hip
Reuben Bell - Superjock
Archaeopterix - Samstag Abend, Sonntag Morgen
Les Maledictus Sound - Kriminal Theme
Joe Cogra Group - Darkness
Googoosh - Talagh
Lord Cobra Y Los Hnos. Duncan - Love Letters
Lonnie Mack - Too Much Trouble
Boobpa Saichol - Seng Rabird
Colosseum - The Kettle
Function.prototype.memoize = function() {
var fn=this;
var args = Array.prototype.slice.call(arguments);
var target = args.length > 0 ? args[0] : null;
fn._vals = fn._vals || {};
return function() {
var call_args = Array.prototype.slice.call(arguments);
if (fn._vals[call_args] !== undefined) return fn._vals[call_args];
fn._vals[call_args] = fn.apply(target, arguments);
return fn._vals[call_args];