Skip to content

Instantly share code, notes, and snippets.

@mattbierner
mattbierner / gist:2951898
Created June 19, 2012 02:00
Prosopon Factorial Example
let FactorialContinuation{val cust}<
case \arg: send val ('*' arg cust) ;
>
let Factorial <
case 0 \cust: send cust (1) ;
case \val \cust:
send val ('-' 1 <
case \result:
send Factorial (result FactorialContinuation{val cust})
@mattbierner
mattbierner / gist:3223669
Created August 1, 2012 04:27
Overview of SSF
ssf.format("Hello @", "world") -> "Hello world"
// Formatting from an object.
ssf.format("Member['a']:@a Member['c']['d']:@c.d", {'a':1, 'c': {'d': 2}})
-> "Member['a']:1 Member['c']['d']:2"
// Formatting from an array.
ssf.format("Array[0]:@0 Array[1]:@1", ['A', 3]) -> "Array[0]:A Array[1]:3"
@mattbierner
mattbierner / gist:3223696
Created August 1, 2012 04:36
SSSF Overview
var t = sssf.compile("@s(:[1,])");
t('abc') -> 'bc'
t({}) -> 'object Object]'
@mattbierner
mattbierner / gist:3768458
Created September 23, 2012 01:25
Callable.js example
// Call notation
var slice = callable.callable(Array.prototype.slice);
slice([1, 2, 3, 4], 1, 3) -> [2, 3]
// Apply notation
var slicea = callable.applicable(Array.prototype.slice);
slicea([1, 2, 3, 4], [1, 3]) -> [2, 3]
// Call notation binding leading arguments
var sliceb = callable.callable(Array.prototype.slice, 1);
@mattbierner
mattbierner / gist:3784785
Created September 25, 2012 22:11
Gen.js Example
// Source generator for fibonacci sequence
function fibonacci() {
var c = 0, d = 1;
return function(y, b) {
var next = c;
c = d;
d = next + d;
return y(next);
};
}
@mattbierner
mattbierner / gist:3983634
Created October 30, 2012 22:54
Closure Compiler Git pre-commit Hook
#!/bin/sh
# Minify js files
COMPILER="java -jar compiler.jar"
OPTIONS="--compilation_level=ADVANCED_OPTIMIZATIONS"
SRC=lib
DEST=dist
@mattbierner
mattbierner / gist:5882460
Last active December 19, 2015 02:19
Javascript build trie from array-like
var reduce = Function.prototype.call.bind(Array.prototype.reduce);
var trie = (function(){
var wordReduce = function(parent, l) {
return (parent[l] = (parent[l] || {}));
};
var wordsReduce = function(trie, word) {
var node = reduce(word, wordReduce, trie);
node[''] = null;
return trie;
@mattbierner
mattbierner / main.cpp
Last active January 14, 2023 17:12
C++ std::tuple cdr, car, cons
#include "tuple_ops.h"
template<typename T>
void print_tuple(const T& x)
{
std::cout << "Head:" << Car(x) << " Remaining:" << std::tuple_size<T>::value - 1 << std::endl;
}
int main(int argc, const char* argv[])
{
@mattbierner
mattbierner / gist:6145671
Last active January 14, 2023 17:12
C++ std::tuple map, foldl, and foldr
/*------------------------------------------------------------------------------
Common list operations (map, foldl, foldr) for C++ tuples.
Depends on Cons, Car, and Cdr for tuples from: https://gist.github.com/mattbierner/6145505
------------------------------------------------------------------------------*/
#include "tuple_ops.h"
/* Impl --------------------- */
@mattbierner
mattbierner / gist:6502727
Created September 9, 2013 23:09
Generate randomly ordered set of indices in a range.
function range(start, end) {
var indicies = [], out = [];
for (var i = start; i < end; ++i)
indicies.push(i);
while (indicies.length) {
var index = Math.floor(Math.random() * indicies.length);
out.push(indicies[index]);
indicies.splice(index, 1);
}
return out;