Skip to content

Instantly share code, notes, and snippets.

View zackdever's full-sized avatar

Zack Dever zackdever

View GitHub Profile
@zackdever
zackdever / .gitconfig
Created July 7, 2012 18:29
global .gitconfig
[user]
name = Zack Dever
email = zackdever@gmail.com
[github]
user = zever
[core]
editor = vim
excludesfile = /Users/dp/.gitignore_global
[help]
autocorrect = -1
@zackdever
zackdever / gist:3127094
Created July 17, 2012 04:22
git filter-branch usage
# credit: http://stackoverflow.com/a/7849648/962091
git filter-branch --index-filter "git rm -r -f --cached --ignore-unmatch unwanted-dir/*" --prune-empty -- --all
@zackdever
zackdever / async.js
Created August 23, 2012 16:47
write module source code to file and then load as node module
var http = require('http');
var fs = require('fs');
var helloModuleString = "exports.world = function() { return 'Hello World\\n'; }";
fs.writeFile('./hello.js', helloModuleString, function (err) {
if (err) return console.log(err);
var hello = require('./hello');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
@zackdever
zackdever / periods.js
Created August 29, 2012 20:08
lots of example a.m. p.m. periods
// this isn't all the possible valid periods, but it's a good batch
var periods = []
, seed = ['pm', 'p', 'p.m.', 'pm.', 'p.m'];
for (var i=0; i<seed.length; i++) {
var s = seed[i];
periods.push(s);
periods.push(s.toUpperCase());
periods.push(s.replace('m', 'M'));
periods.push(s.replace('p', 'P'));
@zackdever
zackdever / gist:3663257
Created September 7, 2012 04:47
pretty print JSON from shell using python executable
# credit http://stackoverflow.com/a/1920585/962091
# sorts keys and pretty prints
echo '{"foo": "lorem", "bar": "ipsum"}' | python -mjson.tool
@zackdever
zackdever / util.coffee
Created September 18, 2012 07:54
small collection of string/object coffeescript utilities
String::endswith = (str) -> @match new RegExp "#{str}$"
String::startswith = (str) -> @match new RegExp "^#{str}"
String::splitLines = () -> @split /\r\n|\r|\n/
# not unlike jQuery.extend.
# adds new properties in object to target.
# does not override anything any target properties.
# TODO: test!
exports.extend = (target, object) ->
@zackdever
zackdever / stateMachine.py
Created October 2, 2012 23:27
a simple python state machine
class StateMachine(object):
"""the brain - manages states"""
def __init__(self):
self.states = {}
self.active_state = None
def add_state(self, state):
"""Adds a new state"""
self.states[state.name] = state
@zackdever
zackdever / imageFader.js
Created October 18, 2012 20:52
simple JavaScript image fader
var bgImgs = [
'/images/foo.png'
, '/images/bar.png'
, '/images/foobar.png'
];
$(function () {
if (bgImgs.length > 1) {
var bgImage = $('#bgImage')
, index = 0
@zackdever
zackdever / alias
Created February 21, 2013 00:36
when creating an arc paste (http://www.phabricator.com/docs/phabricator/article/Arcanist_User_Guide.html), automatically copy the address to the cilpboard on os x
alias arcpaste='arc paste | copyarcpaste'
@zackdever
zackdever / gist:5051462
Created February 27, 2013 20:35
make room for large numbers in nvd3.js charts
// http://stackoverflow.com/a/13472375/962091
// may also need to make room on the chart itself, maybe something like:
// chart.margin({left: 10});
d3.select('.nv-y.nv-axis > g').selectAll('g');