Skip to content

Instantly share code, notes, and snippets.

View stash's full-sized avatar
🎯
Focusing

Jeremy Stashewsky stash

🎯
Focusing
View GitHub Profile
@stash
stash / nyan.txt
Created July 6, 2012 19:18
ascii-based ansi-art editor
..................................*..................................................................
...rrrrrrrrrrrrrrrrrrrrr.....................rrrrrrrrrrrrr .......*........
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr ccccccccccccccccccccccccccc ....***.......
rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr cccccpppppppppppppppppppppccccc ...*........
rrrooooooooooooooooooooorrrrrrrrrrrrrrrrrrrrrooooooooo ccpppppppPpppppppPpppppppppppcc ............
oooooooooooooooooooooooooooooooooooooooooooooooooooooo ccppppppppppppp pppPpPppppcc .. ......
oooooooooooooooooooooooooooooooooooooooooooooooooooooo ccpppppPppppp GGGG ppppppppcc GGGG ....
oooyyyyyyyyyyyyyyyyyyyyyoooooooooooooooooooooyyyyyyyyy ccppppppppppp GGGGGG ppPpppcc GGGGGG ....
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy yyyyyy ccppppppppppp GGGGGGGG GGGGGGGG ....
yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy GGGG yyyy ccpPpppppppPp GGGGGGGGGGGGGGGGGGGGGGGG
@stash
stash / check-merge-conflict.sh
Last active December 14, 2015 07:29
Checking for merge conflicts without changing working copy
#!/usr/bin/env bash
set -eE
# adapted from http://stackoverflow.com/questions/501407/is-there-a-git-merge-dry-run-option/6283843#6283843
remote_branch=$1
git fetch origin $remote_branch >/dev/null
if git merge-tree `git merge-base FETCH_HEAD HEAD` HEAD FETCH_HEAD | egrep -q '<<<|>>>|changed in both'; then
@stash
stash / press.md
Last active December 15, 2015 20:40
French Press Method

French Press Coffee

  • grind super coarse
  • add just enough boiling water to cover grounds. Steep for 30s.
  • fill press to top. Stir to get a good vortex, which will pull the grounds down into a "cone" on the bottom.
  • Leave for ~5mins
  • skim floating grounds off the top with a spoon
  • press
@stash
stash / waterfall.js
Created April 26, 2013 13:43
async.waterfall gotchas
var async = require('async');
/*jshint noarg:false */
function first(next) {
console.log('first', arguments);
next(); // no params = nothing in next step
}
function second(next) {
console.log('second', arguments);
/*jshint node:true */
"use strict";
var order = [];
function deferred(statement, delay) {
return function(done) {
order.push(statement+' start');
setTimeout(function() {
order.push(statement+' end');
done();
@stash
stash / ssl-fake-post.js
Created July 9, 2013 23:38
Node script that pretends to send a 10 MiB JSON to an https server, but then just hangs there.
/*jshint node:true */
'use strict';
var tls = require('tls');
var auth = new Buffer('username:password').toString('base64');
var CRLF = "\r\n";
var opts = {
host: '127.0.0.1',
port: 443,
servername: 'host',
rejectUnauthorized: false
@stash
stash / dash-regexp.js
Created July 10, 2013 16:00
Does trailing dash in a regexp over-match?
var unescaped = new RegExp('^[0-9_-]+$');
var escaped = new RegExp('^[0-9_\\-]+$');
var literal = /^[0-9_-]+$/;
// _ is 0x5f, a is 0x61. If "_-" over-matches then "a_" will match the above.
var test = "a_";
console.log("unescaped:", test.match(unescaped));
console.log("escaped:", test.match(escaped));
console.log("literal:", test.match(literal));
@stash
stash / arity.js
Created July 10, 2013 18:02
Wrap a function to have a specify "arity" (`.length`)
/**
* Wrap a function so that it has `.length` (a.k.a "arity") n.
*
* Any additional parameters are dropped before the wrapped function is called.
*
* @param {int} n number of parameters on the wrapper.
* @param {function} fn function with arbitrary signature.
* @return {function} wrapper
*/
exports.arity = function(n, fn) {
@stash
stash / gist:7549624
Last active December 28, 2015 19:19
Rebasing onto a new initial commit
git checkout master
git checkout -b rebaser
git checkout master
git update-ref -d refs/heads/master
git rm -rf $EVERYTHING_EXCEPT_GITIGNORE # figuratively
git commit -m 'initial commit'
# this will remove the commits off of the remote (to be GC'd at some indeterminate point)
git push --force origin master
@stash
stash / fwd.js
Created January 20, 2014 22:31
Port-forwarding in < 10 lines of node.js
var net = require('net');
var listen = process.argv[2] || 443;
var forwardTo = process.argv[3] || 4443;
net.createServer(function(conn) {
var fwd = net.createConnection({ host: '127.0.0.1', port: forwardTo });
conn.pipe(fwd);
fwd.pipe(conn);
}).listen(listen);