Skip to content

Instantly share code, notes, and snippets.

View InPermutation's full-sized avatar

Jacob Krall InPermutation

View GitHub Profile
@InPermutation
InPermutation / stack_edsl.cs
Last active August 29, 2015 13:57 — forked from brendanzab/stack_edsl.rs
A statically typed, concatenative EDSL in C#.
/// <summary>Used to enforce type nesting</summary>
public interface HList { }
public class Empty : HList { }
public class Stack<T, TChild> : HList where TChild : HList
{
public T Item { get; private set; }
public TChild Child { get; private set; }
@InPermutation
InPermutation / keybase.md
Created April 16, 2014 15:20
keybase.md

Keybase proof

I hereby claim:

  • I am inpermutation on github.
  • I am inpermutation (https://keybase.io/inpermutation) on keybase.
  • I have a public key whose fingerprint is 9DD6 1265 C7C7 351A 195B 8FBF 9DAB 2EE3 2923 AB

To claim this, I am signing this object:

@InPermutation
InPermutation / anonymous_method.cs
Created July 16, 2014 01:33
Stupid C# anonymous objects tricks
// First declare the "type" of Contact
var Contact = new
{
First = (string)null,
Last = (string)null,
FullName = (Func<string>)null,
};
// Then, assign a closure over Contact to FullName to implement the "method"
Contact = new
{
@InPermutation
InPermutation / regex_shortener.py
Created October 15, 2014 20:29
Shorten a regex, allowing false positives
s = 'amsterdam|london|tokyo|indianapolis|new york|shanghai|toronto|san francisco'
rg = s.split('|')
# count: the length of the shortest word
count = len(min(rg, key=len))
# v: list of sets. v[0] is the set of all the first letters, etc.
v = []
for i in range(0,count):
v.append(set(w[i] for w in rg))
@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];
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:a1359101e01070966b31
Created October 29, 2015 19:10
Slackbot responses for games of chance
d6, roll a die
==============
rolls a 1
rolls a 2
rolls a 3
rolls a 4
rolls a 5
rolls a 6
d12
@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];
}
@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 / throw.js
Last active December 14, 2015 12:38
throwup(fxn) -> creates the inductive case of exception-tail-call-optimization makecallable(fxn) -> creates the trampoline for exception-tail-call-optimization
function throwup(fxn) {
return function() {
throw [fxn, Array.prototype.slice.call(arguments)];
}
}
function makecallable(fxn) {
return function() {
var params = Array.prototype.slice.call(arguments);
while(params) {