Skip to content

Instantly share code, notes, and snippets.

View dherman's full-sized avatar

Dave Herman dherman

View GitHub Profile
@dherman
dherman / DoFail.java
Created October 13, 2012 02:14
imperative control-flow and type-checking
public class DoFail {
public int f() {
do {
if (false) break;
return 0;
} while (true);
}
}
function ParallelArray(buf) {
this.buffer = buf;
}
ParallelArray.prototype.get = function (i) {
IC1: var v = this.buffer[i];
return v;
}
function MakeOrGetWrapperFromKey(f) {
@dherman
dherman / context.js
Created November 13, 2012 21:47
example of a context argument
function Tree(value, left, right) {
if (!(this instanceof Tree))
return new Tree(value, left, right);
this.value = value;
this.left = left || null;
this.right = right || null;
}
Tree.prototype.toString = function toString() {
return "(" + JSON.stringify(this.value) + " " + this.left + " " + this.right + ")";
@dherman
dherman / import-and-destructuring.js
Created November 20, 2012 01:49
Using just import and destructuring to bind modules and their exports.
import y = module("bar");
import { y } = module("bar");
import yy = module("bar").y;
import { y: yy } = module("bar");
@dherman
dherman / ssa-cps-anf.txt
Created November 20, 2012 03:10
links on SSA, CPS, and A-normal form
Original paper on A-normal form:
http://redlinernotes.com/docs/Classics/The%20Essence%20of%20Compiling%20with%20Continuations.pdf
A high-level intro to ANF:
http://matt.might.net/articles/a-normalization/
One of the earlier attempts to relate SSA and CPS:
@dherman
dherman / import-and-destructuring.js
Created November 20, 2012 05:36
Using just import and destructuring to bind modules and their exports (variation).
import y = module "bar";
import { y } = module "bar";
import yy = (module "bar").y;
import { y: yy } = module "bar";
@dherman
dherman / module-madness.js
Created November 21, 2012 22:58
module syntax alternatives
// Option 1: destructuring syntax
import m = module "jquery";
import { foo, bar } = module "jquery";
import foo = (module "jquery").foo;
export { *: module "jquery" };
export { foo: (module "jquery").foo, bar: (module "jquery").bar };
export = stuff;
// Option 2: natural language syntax
import "jquery" as m;
@dherman
dherman / range-error-ftw.js
Created November 27, 2012 22:53
fun with JS arrays
var a = [];
a[Math.pow(2, 32) - 2] = "max index"; // highest non-expando indexed property
console.log(a.length === Math.pow(2, 32) - 1); // true
try {
a.push("whoa", "EVEN MOAR WHOA");
} catch (e) {
console.log(e instanceof RangeError); // true
}
@dherman
dherman / javascript.js
Created November 28, 2012 00:27
javascript
(({}+[])[!![]+!![]+!![]]+[]+(![]+[])[+!![]]+(+(!![]+!![]+!![]+[]+(+!![])))[(!![]+[])[+![]]+[]+({}+[])[+!![]]+[][(![]+[])[!![]+!![]+!![]]+[]+(![]+[])[!![]+!![]]+([][![]]+[])[!![]+!![]+!![]+!![]+!![]]+({}+[])[!![]+!![]+!![]+!![]+!![]]+(!![]+[])[!![]+!![]+!![]]][({}+[])[!![]+!![]+!![]+!![]+!![]]+[]+(![]+[])[+!![]]+(![]+[])[!![]+!![]]+(![]+[])[!![]+!![]]](+[![]]+[]+(!![]+[])[({}+[])[!![]+!![]+!![]+!![]+!![]]+[]+({}+[])[+!![]]+([][![]]+[])[+!![]]+(![]+[])[!![]+!![]+!![]]+(!![]+[])[+![]]+(!![]+[])[+!![]]+([][![]]+[])[+![]]+({}+[])[!![]+!![]+!![]+!![]+!![]]+(!![]+[])[+![]]+({}+[])[+!![]]+(!![]+[])[+!![]]])[(![]+[])[+![]]+[]+([][![]]+[])[!![]+!![]+!![]+!![]+!![]]+(![]+[])[!![]+!![]]+(!![]+[])[+![]]+(!![]+[])[!![]+!![]+!![]]+(!![]+[])[+!![]]]([][({}+[])[!![]+!![]+!![]+!![]+!![]]+[]+({}+[])[+!![]]+([][![]]+[])[+!![]]+(![]+[])[!![]+!![]+!![]]+(!![]+[])[+![]]+(!![]+[])[+!![]]+([][![]]+[])[+![]]+({}+[])[!![]+!![]+!![]+!![]+!![]]+(!![]+[])[+![]]+({}+[])[+!![]]+(!![]+[])[+!![]]][({}+[])[!![]+!![]+!![]+!![]+!![]]+[]+({}+[])[
@dherman
dherman / sudoku.js
Created November 29, 2012 23:54
Brendan's Sudoku solver done with left-to-right comprehensions
Object.prototype.copy = function () {
let o = {}
for (let i in this)
o[i] = this[i]
return o
}
// Containment testing for arrays and strings that should be coherent with their __iterator__.
Array.prototype.contains = String.prototype.contains = function (e) {
return this.indexOf(e) != -1