Skip to content

Instantly share code, notes, and snippets.

var words = function(count, wl) {
var out = [];
for (var i = 0; i < count; ++i) {
var len = Math.ceil(Math.random() * wl);
var w = '';
while (len--)
w += String.fromCharCode('a'.charCodeAt(0) + Math.floor(Math.random() * 26))
out.push(w);
}
return out;
@mattbierner
mattbierner / example.kep
Last active August 29, 2015 13:57
Akh DCont example
with
import 'akh::base' {liftM2},
import 'akh::dcont' {runDCont of shift reset}
in {
var list = liftM2 @ \x y -> [x, y];
runDCont(
reset \ p ->
liftM2((+),
shift @ p \k ->
@mattbierner
mattbierner / gist:a3fc9b33f890134efa12
Created July 24, 2014 16:42
Index sequnece example
// Example only shows expansion logic, not perfect forwarding
template<class F, class T, size_t... I>
auto unpack(F f, T t, std::index_sequence<I...>) {
return f(std::get<I>(t)...);
}
template<class F, class T>
auto tuple_eval(F f, T arg) {
return unpack(f, args, std::make_index_sequence<std::tuple_size<T>::value>());
}
@mattbierner
mattbierner / list.cpp
Created October 28, 2014 02:55
C++ Compile Time Lazy List
/// Identity functor
template <typename X>
struct id {
using type = X;
};
/// Create a meta functor that returns `X` when invoked with any argument.
template <typename X>
struct constant {
template <typename>
@mattbierner
mattbierner / index.js
Last active August 29, 2015 14:21
Blot're Weather Client Example
var Blotre = require('blotre');
var rp = require('request-promise');
var fs = require('fs');
var cron = require('cron');
var weatherSpectrum = new (require('colour-me-life'))();
weatherSpectrum.setSpectrum('blue', 'green', 'red');
weatherSpectrum.setNumberRange(0.0, 1.0);
var ZIP = "92328";
@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);
};
}