Skip to content

Instantly share code, notes, and snippets.

@saaji
saaji / bench.erl
Last active August 29, 2015 14:12 — forked from 0xYUANTI/bench.erl
-module(bench).
-compile(export_all).
%% Luke Gorrie's favourite profiling macro.
-define(TIME(Tag, Expr),
(fun() ->
%% NOTE: timer:tc/4 does an annoying 'catch' so we
%% need to wrap the result in 'ok' to be able to
%% detect an unhandled exception.
{__TIME, __RESULT} =
@saaji
saaji / tiny-IOC.js
Last active August 29, 2015 13:56
Tiny IOC in JavaScript
(function($) {
var o = $({});
$.registerComponent = function(key, component) {
o[key] = component;
};
$.unregisterComponent = function(key) {
o[key] = undefined;
};
@saaji
saaji / JST.js
Created December 12, 2011 19:33
Tiny JavaScript Template loader/compiler with Handlebars.
var JST = {
prefix: 'js/templates/',
extension: '.hbs',
compile_template: function(name, data) {
this[name] = Handlebars.compile(data);
},
register_partial: function(name, data) {
this[name] = Handlebars.registerHelper(name, Handlebars.compile(data));
@saaji
saaji / hbs_renderer.rb
Created November 13, 2011 00:37
handlebars renderer for Ruby On Rails 3.1 using hbs gem
require 'handlebars'
module HBSTemplateHandler
def self.call(template)
if template.locals.include? :hbs
<<-TEMPLATE
template = Handlebars.compile #{template.source.inspect}
template.call(hbs || {}).html_safe
TEMPLATE
else
@saaji
saaji / rspec-syntax-cheat-sheet.rb
Created November 7, 2011 10:45 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")