Skip to content

Instantly share code, notes, and snippets.

View justinabrahms's full-sized avatar

Justin Abrahms justinabrahms

View GitHub Profile
@justinabrahms
justinabrahms / gist:5602542
Created May 17, 2013 23:11
A sample GitStreams.com email!
holman/dotfiles:
PR:91 dplarson -- Replace empty echo's with printf new line
#91: Replace empty echo's with printf new line
dplarson commented on issue 91: Makes sense.
bestiejs/benchmark.js:
#45: Newbie question
@justinabrahms
justinabrahms / gist:5673408
Created May 29, 2013 20:05
Short script which will grep your project for unused requirejs imports. Usage: `/path/to/file.sh application/js/directory`
#/bin/bash
JS_FILES=$(find "$1" -name "*.js")
for FILE in $JS_FILES; do
short_name=`basename $FILE`
filename="${short_name%.*}"
git grep --quiet $filename 1>/dev/null
if [ "$?" == "1" ]; then
echo "Should delete: $FILE"
@justinabrahms
justinabrahms / gist:5777664
Last active December 18, 2015 11:39
Simple Go utility for mocking out a tags API that supports resort.
package main
import (
"encoding/json"
"errors"
"fmt"
"html"
"log"
"net/http"
)
@justinabrahms
justinabrahms / gist:6027925
Last active December 19, 2015 22:29
Node.js script which transforms old-style AMD modules into modules with the sugar syntax outlined in http://requirejs.org/docs/whyamd.html#sugar The code is ugly and procedural, but it solves a need. *NOTE*: This hasn't yet been validated to work. Specifically it doesn't provide a return statement which the requirejs documentation indicates it s…
#!/usr/bin/env node
/**
* Transforms code from old-style requirejs modules into AMD sugared modules.
*
* define(['dep1','dep2'], function(arg1, arg2) {...})
*
* becomes:
*
* define(function(require) { var arg1 = require('dep1'), arg2 = require('dep2'); ... });
*
@justinabrahms
justinabrahms / gist:6133950
Created August 1, 2013 18:31
Small linter using jsl which will detect python-style variable names and complain. Usable as a precommit hook with: git diff --cached --name-only --diff-filter=ACM | grep ".js" | xargs node lint.js
var lint = require('jsl')
, linter = lint();
linter.rule('variable > id',
function (node, subsource, alert) {
var var_name = node.name;
if (var_name.indexOf("_") !== -1) {
alert(node, 'Found variable name with underscores: ' + var_name);
}
}, 'error');
@justinabrahms
justinabrahms / gist:6973796
Last active December 25, 2015 12:09
Node transform which will turn variables (and similar) of the format `bar_` to indicate privateness, into `_bar`.
#!/usr/bin/env node
/*
* We have trailing underscores on variables to indicate
* private. That's silly. Preceeding underscores are the only obvious
* choice.
*
* var foo = function () {
* this.bar_ = '9';
* _.bindAll(this, 'foo_');
* }
@justinabrahms
justinabrahms / gist:7311596
Created November 5, 2013 00:02
Use a cached virtualenv during CI
VENV_DIR=`md5sum requirements/* | md5sum 2>&1 | awk '{print $1}'`
if [ -e $VENV_DIR ]; then
. /tmp/$VENV_DIR/bin/activate
else
virtualenv --no-site-packages /tmp/$VENV_DIR
. /tmp/$VENV_DIR/bin/activate
pip install --download-cache /var/lib/jenkins/.pip_download_cache -r requirements/ci.txt
fi
@justinabrahms
justinabrahms / gist:7989647
Created December 16, 2013 16:14
Notes taken regarding interceptor pattern (similar to cujojs) ported to backend request handling. Needs to be better fleshed out and will probably only mean something to @phated
/*
goals:
middleware, like express.
no `.next()`, which express has.
use of promises (rejecting/resolving) unlike node's traditional (err, data) thing
immutable requests, preferring instead an explicit databag for state managment (continuous local storage)
"composable after the routing method"
I really want a service where you can enter in 2 wikipedia pages and
it will tell you how they relate. It'd be especially cool if someone
else made it, so I'm writing up how I think it might be done in
Python.
Due to the nature of the queries you want to do (how does x relate to
y), I think this should end up in a graph database. In this graph
database, every page is a node. Links between pages are directed edges
in the graph, annotated with the paragraph of text they're linked
from.
@justinabrahms
justinabrahms / gist:8994424
Created February 14, 2014 01:51
A simple HTTP proxy for speedy static file serving, sending dynamic requests to a backend web server.
/**
* A proxy for loading static files in development. Django doesn't handle this well.
*
* To run, do something like:
* npm install .
* node proxy.js --docroot=$PWD
*
* Then just visit http://localhost:9000/ as you normally would.
*/
var httpProxy = require('http-proxy');