Skip to content

Instantly share code, notes, and snippets.

View scttnlsn's full-sized avatar

Scott Nelson scttnlsn

View GitHub Profile
@scttnlsn
scttnlsn / eachobj.js
Created May 14, 2012 21:38
Handlebars object iteration
Handlebars.registerHelper('eachobj', function(object, options) {
var buffer = '';
var empty = true;
for (var key in object) {
buffer += options.fn({ key: key, value: object[key] });
empty = false;
}
if (empty) {
@scttnlsn
scttnlsn / base_view.js
Created May 8, 2012 17:00
Backbone.js base view
var BaseView = Backbone.View.extend({
close: function() {
this.closeSubviews();
this.unbindFromAll();
this.off();
this.remove();
if (this.onClose) this.onClose();
},
@scttnlsn
scttnlsn / promise.js
Created January 13, 2012 14:43
Simple promise implementation for Node.js and the browser
(function() {
if (typeof module !== 'undefined' && module.exports) {
module.exports = Promise;
} else {
this.Promise = Promise;
}
function Promise(context) {
this.context = context || this;
@scttnlsn
scttnlsn / app.rb
Created October 18, 2011 13:59
Sinatra/Mongoid RESTful resource
require 'mongoid'
require 'sinatra'
require_relative 'resource'
class Example
include Mongoid::Document
field :name
field :created, :type => DateTime
@scttnlsn
scttnlsn / editor.coffee
Created September 9, 2011 01:37
A toy text editor written in CoffeeScript
# =========================================
# A toy text editor written in CoffeeScript
# =========================================
#
# Requires ncurses bindings for node.js:
# npm install ncurses
#
# Usage:
# coffee editor.coffee FILENAME
#
@scttnlsn
scttnlsn / README.md
Created September 1, 2011 00:25
Minimalist append-only key/value store written in Ruby.

A minimalist append-only key/value store written in Ruby.

Ruby API

c = Collection.new('example.db')

c.set('hello', 'world')
c.get('hello') # => "world"