Skip to content

Instantly share code, notes, and snippets.

@aj0strow
aj0strow / app.coffee
Created February 5, 2014 10:11
redis & socket.io
modules = [ 'then-redis', 'http', 'express', 'socket.io' ]
[ redis, http, express, io ] = (require(mod) for mod in modules)
# redis
db = redis.createClient()
db.setnx('users:count', 0)
# server
@aj0strow
aj0strow / examples.js
Last active August 29, 2015 13:56
Priority Queue
var q = new PriorityQueue;
var nums = [ 1, 4, 6, 3, 9 ];
nums.forEach(q.add, q);
nums.forEach(q.add, q);
var outs = [];
while (q.length) outs.push(q.hpop());
console.log(outs);
// [ 9, 9, 6, 6, 4, 4, 3, 3, 1, 1 ]
@aj0strow
aj0strow / client.js
Created April 1, 2014 18:39
Streaming Music
var queue = [];
var audio = new Audio();
audio.controls = true;
audio.autoplay = true;
audio.addEventListener('ended', function (ev) {
console.log('next song');
playNext();
});
@aj0strow
aj0strow / clone.sh
Last active August 29, 2015 13:59
Git Clone
# clone username package
function clone {
if [! -z $2]
then repo="$1/$2"
else repo="$1"
fi
git clone "git@github.com:$repo.git" && cd $(basename $repo)
}
@aj0strow
aj0strow / bower.json
Last active August 29, 2015 14:03
Markdown Editor
{
"name": "markdown-editor",
"private": true,
"dependencies": {
"bootstrap": "~3.2.0",
"angular": "~1.2.18",
"showdown": "~0.3.1"
}
}
@aj0strow
aj0strow / compose.js
Created July 6, 2014 22:05
Compose Middleware
var waterfall = require('async-waterfall')
var flatten = require('lodash.flatten')
module.exports = compose
function compose () {
var middlewares = flatten(arguments)
function composed (req, res, next) {
var callbacks = middlewares.map(function (middleware) {
@aj0strow
aj0strow / root.js
Created July 8, 2014 19:18
Node App Root
var path = require('path')
var dirname = path.dirname(require.main.filename)
var root = dirname.split('/node_modules/')[0]
module.exports = root
@aj0strow
aj0strow / bower.json
Created July 17, 2014 04:11
RequireJS Hello World
{
"private": true,
"name": "helloworld",
"version": "0.0.0",
"dependencies": {
"requirejs": "~2.1.9"
}
}
@aj0strow
aj0strow / mongo
Created July 21, 2014 19:51
Mongo cmds with Mongoid config
#!/usr/bin/env ruby
# put in scripts folder, and make executable
# $ chmod +x scripts/mongo
require 'yaml'
HELP = '''
@aj0strow
aj0strow / tenslow.sh
Created August 6, 2014 11:42
Express Heroku 10 Slowest Requests
npm install -g strip-ansi
heroku logs | strip-ansi | grep 'web.\d' | awk '{ if($7 == "ms") print $6, "\t\t", $3, $4 }' | sort -nr | head -n 10