Skip to content

Instantly share code, notes, and snippets.

@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 ] :

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 / 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 / gist:5141427
Created March 12, 2013 09:16
Reification of JavaScript function semantics. JavaScript functions can return with either a regular result or an exception, which propagate through code differently. By catching exceptions and combining the two paths through a sum type, more interesting symmetries can be observed.
// data Result e a = Return a | Raise e
Result = function() {};
Return = function(value) { this.value = value; };
Raise = function(value) { this.value = value; };
// inheritance
Return.prototype = Object.create(Result.prototype);
Raise.prototype = Object.create(Result.prototype);
// identity functions
@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 / Long.js
Created May 31, 2012 22:22
An implementation of 64-bit signed integers in Javascript.
var MAX32 = Math.pow(2, 32);
// Bit of a misnomer, since it's actually the maximum plus one.
var Long = function Long(n) {
if (!(this instanceof Long))
return new Long(n);
this.set(n);
};
%% name = Lupin::Parser
%% {
require 'rubinius/debugger'
require 'ast'
attr_accessor :ast
def process_string_escapes (text)
text = text.to_s
text.gsub! /\\(\d{1,3}|\D)/m do
@Twisol
Twisol / escaper.rb
Created May 16, 2011 20:13
JSON parser in kpeg
module StringEscaper
def process_escapes (str)
str.gsub! /\\(u\d{4}|\D)/m do
seq = $1
case seq
when '/' then "\/"
when 'b' then "\b"
when 'f' then "\f"
when 'n' then "\n"
when 'r' then "\r"
@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
@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();
}