Skip to content

Instantly share code, notes, and snippets.

@Twisol
Twisol / maybe.js
Created December 24, 2013 06:57
Maybe monad via ES6 generators (via Traceur)
var Nothing = function Nothing() {};
var Just = function Just(x) { this.value = x; };
function runMaybe(f) {
var result = f.next();
while (!result.done) {
var value = result.value;
switch (value.constructor) {
case Nothing:
@Twisol
Twisol / ansi.js
Created May 2, 2011 00:29
ANSI sequence parser (Node.js) and client-side renderer
var sys = require("sys");
var ANSI = (function() {
sys.inherits(ANSI, require("events").EventEmitter);
function ANSI() {
this.state = "plain";
this.reset();
}

Keybase proof

I hereby claim:

  • I am twisol on github.
  • I am twisol (https://keybase.io/twisol) on keybase.
  • I have a public key ASAiuZlLyg3b9rahqU7mselcb4w2vk93NI2uepV6RiexqAo

To claim this, I am signing this object:

@Twisol
Twisol / eater.js
Created October 3, 2016 09:50 — forked from icemnki/eater.js
function ( a , { t } )
{// t:#s.name.loc
var c = { } , p , v , r , x , s , i = 0 ,
P = "red0purple0blue0cyan0green0lime0yellow0orange020305070110130170190230290310370410430470530590610670710730790830890970unlock0open0release" . split ( 0 ) ,
z = "21!|35!|40!|1!|2!|3!|or n|d c| com|k c|color_digit|c002_complement|c003_triad_1|c003_triad_2|!d|t d|pr",
Z = z . split ( '|' )
for ( ; v = ( r = t . call ( c ) ) . match ( z ) ; c [ p ] = x , i ++ )
s = Z . indexOf ( v = v [ 0 ] ) ,
s > 15 ? c . ez_prime = + P [ i % 25 + 8 ] :
@Twisol
Twisol / gist:4526419
Last active April 24, 2017 18:54
Proof of concept of a trampoline-based promise resolver. This ensures that all promise chains take up the same base amount of stack space.
function nextTick(f) {
setTimeout(function() {
console.log('tick');
f();
});
}
// Minimal amount of Promise groundwork necessary for a proof of concept.
function Promise(then) {
this.then = then;
@Twisol
Twisol / <output>
Created May 5, 2011 03:09
ANSI parser written in C++
FG: 7 BG: 0
Italic: 0
Underline: 0
Strike: 0
Text: this is
FG: 9 BG: 0
Italic: 0
Underline: 0
Strike: 0