Skip to content

Instantly share code, notes, and snippets.

View skeggse's full-sized avatar
⚠️
Drop ICE

Eli Skeggs skeggse

⚠️
Drop ICE
View GitHub Profile
@skeggse
skeggse / locate.js
Created February 5, 2014 21:13
Binary Search Generator Thingy
function* locate(low, high) {
var mid;
if (high === Infinity || high === undefined) {
mid = 1;
for (;;) {
if ((yield mid) > 0) {
mid <<= 1;
} else {
high = mid << 1;
break;
@skeggse
skeggse / ignore.js
Created March 3, 2014 23:26
npm git ignore node_modules: ignores npm modules in the node_modules directory by consulting the devDependencies field in the package.json
#!/usr/bin/env node
var fs = require('fs');
var path = require('path');
var hasOwn = Object.prototype.hasOwnProperty;
// seaches recursively upwards to find the package.json
function load(start, name) {
var exists, full;
do {
@skeggse
skeggse / nonce.js
Created March 3, 2014 23:56
Generate crypto-random hex from command line because /dev/urandom isn't good enough for some reason
#!/usr/bin/env node
var crypto = require('crypto');
var chars = parseInt(process.argv[2], 10) || 32;
var blockSize = 1024 * 1024;
function sync(count) {
console.log(crypto.randomBytes(Math.ceil(count / 2)).toString('hex').slice(0, count));
}
@skeggse
skeggse / gittest.sh
Last active August 29, 2015 14:01
git being git
/tmp$ mkdir gittest
/tmp$ cd gittest
/tmp/gittest$ git init
/tmp/gittest$ echo test > test
/tmp/gittest$ git add test
/tmp/gittest$ git commit -m test
/tmp/gittest$ git diff-index --quiet HEAD
/tmp/gittest$ echo $?
0
/tmp/gittest$ echo "another test" >> test
@skeggse
skeggse / status.sh
Last active August 29, 2015 14:01
Display the statuses of a bunch of git repositories
#!/bin/bash
pushd . >> /dev/null
top="$(git rev-parse --show-toplevel 2>/dev/null)"
if [ "$top" != '' ]; then
cd "$(dirname "$top")"
fi
for dir in *
do
if [ -d "${dir}" ] && [ -d "${dir}/.git" ]; then
pushd . >> /dev/null
@skeggse
skeggse / async-hash-bench
Created July 25, 2014 00:35
Asynchronous hash benchmarks
concurrent=1 algo=sha256 type=asc encoding=ascii len=2 api=legacy: 0.000098569
concurrent=1 algo=sha256 type=asc encoding=ascii len=2 api=stream: 0.0000081394
concurrent=1 algo=sha256 type=asc encoding=ascii len=2 api=digest: 0.000032721
concurrent=1 algo=sha256 type=asc encoding=ascii len=1024 api=legacy: 0.030183
concurrent=1 algo=sha256 type=asc encoding=ascii len=1024 api=stream: 0.0044764
concurrent=1 algo=sha256 type=asc encoding=ascii len=1024 api=digest: 0.019793
concurrent=1 algo=sha256 type=asc encoding=ascii len=102400 api=legacy: 1.5514
concurrent=1 algo=sha256 type=asc encoding=ascii len=102400 api=stream: 0.36778
concurrent=1 algo=sha256 type=asc encoding=ascii len=102400 api=digest: 1.2178
concurrent=1 algo=sha256 type=asc encoding=ascii len=1048576 api=legacy: 2.0210
function append(dest) {
for (var i = 1, n = arguments.length; i < n; i++) {
var src = arguments[i], offset = dest.length;
dest.length += src.length;
for (var j = 0, l = src.length; j < l; j++) {
dest[offset++] = src[j];
}
}
return dest;
}
@skeggse
skeggse / quick-display.sh
Created January 5, 2015 20:39
Simplified xrandr script for horizontal monitor layouts
#!/bin/bash
# arrange outputs in order of name
params=()
prev=''
verbose=0
if [ "$1" == '-v' ] || [ "$1" == '--verbose' ]; then
verbose=1
shift
fi
@skeggse
skeggse / example-json.php
Created October 25, 2012 18:25
Example JSON Output
<?php
header("content-type: application/json");
$output = array("classes" => array(0, 1, 2, 3, 4), "rooms" => array(0, 1, 2, 3, 4));
echo json_encode($output); // {"classes":[0,1,2,3,4],"rooms":[0,1,2,3,4]}
@skeggse
skeggse / gist:4181247
Created December 1, 2012 09:16
Node.js Segfault
/var/lib/stickshift/{REDACTED}/app-root/data/bin/node: line 3: 12992 Segmentation fault NODE_PATH=$OPENSHIFT_DATA_DIR/lib/node_modules PORT=$OPENSHIFT_INTERNAL_PORT C9_PORT=$OPENSHIFT_INTERNAL_PORT IP=$OPENSHIFT_INTERNAL_IP HOME=$OPENSHIFT_DATA_DIR $OPENSHIFT_DATA_DIR/bin/node-openshift "$@"