Skip to content

Instantly share code, notes, and snippets.

View scttnlsn's full-sized avatar

Scott Nelson scttnlsn

View GitHub Profile
@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"
@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 / 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 / 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 / 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 / server.js
Created May 18, 2012 17:46
Serving thumbnails on-the-fly with Nettle and Express
var express = require('express');
var im = require('imagemagick');
var nettle = require('nettle');
var app = express.createServer();
var store = nettle.store({ url: 'mongodb://localhost:27017/mydb' });
// Create Nettle processor to resize image
var createProcessor = function(width) {
store.processor(width, function(buffer, callback) {
@scttnlsn
scttnlsn / coffeescript-ifer.sublime-snippet
Created June 11, 2012 16:56
ST2 Snippet: if (err) return callback(err)
<snippet>
<content><![CDATA[return ${1:callback} ${2:err} if ${2:err}?]]></content>
<tabTrigger>ifer</tabTrigger>
<scope>source.coffee</scope>
<description>ifer</description>
</snippet>
@scttnlsn
scttnlsn / env.js
Created January 31, 2013 17:55
RequireJS plugin to conditionally load modules based on environment
// Include { env: 'development' } in your RequireJS config
// When building (with r.js) set the value to 'production' or just omit it entirely
//
// Assuming the following directory structure:
// - config/
// - development.js
// - production.js
//
// Load the appropriate file based on the current env:
//
@scttnlsn
scttnlsn / .bashrc
Last active December 16, 2015 22:39
Redis launch agent
alias redis-start="launchctl start io.redis.redis-server"
alias redis-stop="launchctl stop io.redis.redis-server"
alias redis-status="launchctl list | grep io.redis.redis-server"
@scttnlsn
scttnlsn / example.html
Last active December 17, 2015 16:39
Flight-inspired mixin composition
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.js"></script>
<script src="http://underscorejs.org/underscore.js"></script>
<script src="http://backbonejs.org/backbone.js"></script>
<script src="wings.js"></script>
<script>