Skip to content

Instantly share code, notes, and snippets.

@allouis
allouis / tswift.sh
Last active August 29, 2015 14:11
Taylor Swift > *
curl http://en.wikipedia.org/w/api.php\?action\=query\&format\=txt\&list\=categorymembers\&cmtitle\=Category:21st-century_American_singers\&cmlimit\=500 | grep title | sed 's/\[title\] => //' | xargs -L1 echo "Taylor Swift > "
var tinytic = require('tinytic');
function render (dT) {
// ...
}
function loop() {
requestAnimationFrame(loop);
var dT = tinytic.toc();
render(dT);
for dest in /**/*; do whoami | say; done
@allouis
allouis / index.md
Created February 19, 2015 20:26
donny clojurescript

cool shit what i like in clojurescript

immutable data

(def numbers [1 2 3 4 5]) ; => [1 2 3 4 5]

; conj (short for conjoin) is a function that can take a vector and arguments, appends arguments to vector 
(conj numbers 6) ; => [1 2 3 4 5 6]
@allouis
allouis / _.js
Last active August 29, 2015 14:19
_ wildcard in JavaScript
var _ = new Proxy({}, {
get: function get(target, property) {
return function f(x) {
return x[property]();
}
}
});
["some", "words"].map(_.toUpperCase); // => ["SOME", "WORDS"];
@allouis
allouis / IO.Monad.js
Created April 13, 2015 15:26
IO Monad impl
import 'compose' from 'fnal';
export default function IO(fn){
return {
fmap: function(mapFn) {
return IO(compose(mapFn, fn));
},
performUnsafeIO: function(){
return fn();
}
class BaseClass {
constructor() {
this.mixins.forEach(mixin => mixin(this));
}
}
// then either
class x extends BaseClass {
constructor() {
this.mixins = [observable, whatever];
super();
@allouis
allouis / lense.js
Last active August 29, 2015 14:24
super naive implementation of lenses
function clone(obj) {
if (Array.isArray(obj)) {
return obj.slice(0);
}
if (typeof obj === 'object') {
return Object.keys(obj).reduce(function(clone, key) {
clone[key] = obj[key];
return clone;
}, {});
}
@allouis
allouis / StateMonad.js
Created July 24, 2015 13:22
A different way of think about the State Monad, we call the functions with their this value bound to the state.
function State(value, state){
if(!(this instanceof State)) {
return new State(value);
}
this.__value__ = value;
this.__state__ = state || {};
}
State.prototype.fmap = function(fn) {
var state = Object.assign({}, this.__state__);
@allouis
allouis / map.js
Last active August 26, 2015 15:23
reduce implemented recursively, no state
function compose(f, g) {
return function(x) {
return f(g(x));
}
}
function cons(arr) {
return function (val) {
return arr.concat(val);
}