Skip to content

Instantly share code, notes, and snippets.

View dherman's full-sized avatar

Dave Herman dherman

View GitHub Profile
@dherman
dherman / sudoku.js
Created November 30, 2012 00:17
Brendan's original Sudoku solver with JS 1.7 syntax
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
@dherman
dherman / foobar.md
Created December 3, 2012 22:19
testing markdown rendering in gist

Hello world

Hell's bells, world, how you doin?

for (var i = 0, n = a.length; i < n; i++) {
    console.log(a[i]);
}
@dherman
dherman / struct-view-iteration.js
Created December 7, 2012 19:02
struct overlays, struct views, and iterators in action
let Tree = new StructType({
key: int32,
val: float32;
left: int32,
right: int32
});
Tree.prototype[iterator] = function() {
// allocate the "pointer" object
let p = new StructView(Tree);
@dherman
dherman / example.js
Created December 12, 2012 05:04
pointer type approach
var IPAddress = new ArrayType(uint8, 4);
var P_IPAddress = new PointerType(IPAddress);
var Packet = new StructType({ addr: IPAddress, ... });
var P_Packet = new PointerType(Packet);
var PacketArray = new ArrayType(Packet);
var lotsOfPackets = new PacketArray(LOTS);
for (let p of lotsOfPackets.cursor("addr")) {
@dherman
dherman / example.js
Created December 12, 2012 05:43
struct view approach
var IPAddress = new StructType({
f0: uint8,
f1: uint8,
f2: uint8,
f3: uint8
});
var Packet = new StructType({ addr: IPAddress, ... });
var PacketArray = new ArrayType(Packet);
@dherman
dherman / proto.js
Created December 29, 2012 07:33
__proto__ hazards for dictionary objects in V8
var dict = Object.create(null);
dict.__proto__ // null
"__proto__" in dict // true
dict["__proto__"] = Math;
"sin" in dict // true
@dherman
dherman / explanation.txt
Last active December 13, 2015 04:59
demonstrating that lexing JavaScript requires a pushdown automaton
Looking at the preceding token when the lexer points to a '/'
character is insufficient to determine which context it's in. In
fact, you need to look at an arbitrary number of preceding tokens
to figure it out. This example demonstrates a case where we can
pump up the number of preceding tokens to an arbitrary size
before you can disambiguate your syntactic context.
@dherman
dherman / cat.js
Last active December 25, 2015 16:01
comparing different iteration protocols
// EXAMPLE: a compound iterator with sequencing
// Python style
function cat() {
let is = arguments;
return {
next: {
let length;
while ((length = is.length) > 0) {
try {
@dherman
dherman / loaders.md
Last active December 14, 2015 19:49

The System loader.

var capitalize = System.get('libs/string').capitalize;
var app = System.get('app').app;

Custom loader:

// {
// next: () -> { done: false, value: any }
// | { done: true[, value: any] }
// }
var i1 = (function *f() {
return;
})();
'value' in i1.next();