Skip to content

Instantly share code, notes, and snippets.

View InPermutation's full-sized avatar

Jacob Krall InPermutation

View GitHub Profile
@InPermutation
InPermutation / bisect.js
Last active December 14, 2015 12:38
Usage: node bisect.js <testfile>.js <testfile>.js should expect one integer parameter. bisect.js will binary search and find the integer at which <testfile>.js no longer functions. Useful for figuring out exactly how many stack frames are allowable.
var fork = require('child_process').spawn;
var cProcess = 0;
bounds(0, 1000);
function exec(param){
cProcess++;
return fork(process.argv[0], [process.argv[2], param]);
}
function bounds(min, max) {
@InPermutation
InPermutation / recurse.js
Created March 5, 2013 01:40
An example of tail recursion that is not optimized by Node.
var r = recurse(process.argv[2] || 5000, 0);
console.log('found', r);
function recurse(n, j) {
if(n>0) return recurse(n-1, j+1);
else return j;
}
@InPermutation
InPermutation / gist:4695454
Created February 2, 2013 01:19
Node.js: Import everything from a module into the global scope
var p = require('./program');
for(var dep in p) {
global[dep] = p[dep];
}
function mysqlConfigFromEnvironment (){
var dbUrl = process.env.DATABASE_URL;
var parsed = url.parse(dbUrl);
return {
host: parsed.host,
port: parsed.port || 3306,
user: parsed.auth.split(':')[0],
password: parsed.auth.split(":")[1]
};
};
@InPermutation
InPermutation / gist:1257730
Created October 2, 2011 18:24 — forked from jcbozonier/gist:1257652
Aggregating the scores by lol and associating with the name of the user who created it.
var aggregate_scores_by_lol = function(votes, lols, users){
var vote_count = lols.reduce(function(p,lol,i,r){ return p[lol.id] = 0, p; }, {});
var lol_dictionary = lols.reduce(function(p,lol,i,r){ return p[lol.id] = lol, p}, {});
votes.forEach(function(vote){ vote_count[vote.lol_id]++; });
var vote_count_keys = vote_count.map(function(el,ix){ return ix;});
var sorted_lol_ids = vote_count_keys.sort(function(a, b){
return vote_count[b] - vote_count[a];