Skip to content

Instantly share code, notes, and snippets.

View aackerman's full-sized avatar
💻
Working

Aaron Ackerman aackerman

💻
Working
View GitHub Profile
@aackerman
aackerman / hogan-adapter.js
Created March 30, 2012 01:53
Express view adapter for Hogan.js
'use strict';
var fs = require('fs'),
path = require('path'),
hogan = require('hogan');
var adapter = (function() {
var dir = 'templates',
partials_dir = dir + '/partials',
extension = '.hogan',
partials = {},
@aackerman
aackerman / fuzzy-time.js
Created April 13, 2012 01:54
Fuzzy Time
Convert Unix time in seconds to a fuzzy timestamp since the current time: 4s, 9m, 2d, 1m, etc.
var fuzzy_time = function (a) {
var b = new Date,
c = parseInt(((b.getTime() / 1e3) - a), 10),
d = "";
return c < 60 ? d = c + "s" : c < 120 ? d = "1m" : c < 2700 ? d = parseInt(c / 60, 10).toString() + "m" : c < 7200 ? d = "1h" : c < 86400 ? d = "" + parseInt(c / 3600, 10).toString() + "h" : c < 172800 ? d = "1d" : d = parseInt(c / 86400, 10).toString() + "d", d
}
var extend = function (object) {
var index, result = object;
if (!object) return result;
for (var source, sourceIndex = 1, length = arguments.length; sourceIndex < length; sourceIndex++) {
source = arguments[sourceIndex];
var skipProto = typeof source == 'function';
for (index in source) {
if (!(skipProto && index == 'prototype')) {
object[index] = source[index];
}
@aackerman
aackerman / search.js
Created June 13, 2012 01:13
Binary Search
//binary search
var search = function(array, i) {
var min = 0,
max = array.length - 1,
mid = Math.floor((min + max)/ 2);
while (max >= min) {
if(array[mid] < i) {
min = mid + 1;
} else if(array[mid] > i) {
@aackerman
aackerman / adapter.js
Created August 2, 2012 22:29
Example Express Server
var fs = require('fs'),
path = require('path'),
hogan = require('hogan.js');
var dir = 'templates',
partials_dir = dir + '/partials',
extension = '.hogan',
partials = {};
//cache partials
@aackerman
aackerman / server.conf
Created August 5, 2012 13:13 — forked from TooTallNate/server.conf
Example of using `upstart` with a NodeJS server.
description "My NodeJS Server"
author "Nathan Rajlich"
# Upstart has nothing in $PATH by default
env PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
# Keep the server running on crash or machine reboot
respawn
start on runlevel [23]
@aackerman
aackerman / config.js
Created August 5, 2012 14:53
Require JS Example Config
require.config({
name: 'libs/almond/almond',
baseUrl: '/js/',
paths: {
'lodash' : 'libs/lodash/lodash',
'Backbone' : 'libs/backbone/backbone',
'Hogan' : 'libs/hogan/hogan',
'App' : 'views/App',
'SessionView' : 'views/Session',
'SessionModel' : 'models/Session',
@aackerman
aackerman / flush.sh
Created September 7, 2012 13:57
Flushing Memcache
#!/bin/bash
#mac osx / system with netcat in path
#echo "flush_all" | nc localhost 11211
#other means
#telnet localhost 11211;
#flush_all;
#exit;
@aackerman
aackerman / EventEmitter.rb
Created December 18, 2012 02:41
JS style event emitter in Ruby
class EventEmitter
def initialize()
@callbacks = {}
end
def on(event, &callback)
@callbacks[event] ||= []
@callbacks[event].push(callback)
end
@aackerman
aackerman / leaflet-load.html
Last active December 10, 2015 20:38
Leaflet gist
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
<meta name="description" content="">