Skip to content

Instantly share code, notes, and snippets.

Brendan Eich BrendanEich

Block or report user

Report or block BrendanEich

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:4294d5c212a6d2254703

From Fabrice Bellard, with minor name change (umulh):

// return the high 32 bit part of the 64 bit addition of (hi0, lo0) and (hi1, lo1)
Math.iaddh(lo0, hi0, lo1, hi1)

// return the high 32 bit part of the 64 bit subtraction of (hi0, lo0) and (hi1, lo1)
Math.isubh(lo0, hi0, lo1, hi1)

// return the high 32 bit part of the signed 64 bit product of the 32 bit numbers a and b
View gist:a748220b894a341bc7a3
let nums = [1, 53, 0, 42, 3, 99, 2, 67, 4];
// Suppose we're in a function here...
let strs = (x) {
switch (x) {
case 1: return x + 'st';
case 2: return x + 'nd';
case 3: return x + 'rd';
default: return x + 'th';
BrendanEich / gist:5753666
Created Jun 11, 2013
ES6 version of Peter Norvig's Sudoku solver originally written in Python
View gist:5753666
// XXX should be standard (and named clone, after Java?)
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) {
BrendanEich / minimalist-classes.js
Created Nov 1, 2011 — forked from jashkenas/minimalist-classes.js
less minimalism, richer leather
View minimalist-classes.js
// A response to jashkenas's fine proposal for minimalist JavaScript classes.
// Harmony always stipulated classes as sugar, so indeed we are keeping current
// JavaScript prototype semantics, and classes would only add a syntactic form
// that can desugar to ES5. This is mostly the same assumption that Jeremy
// chose, but I've stipulated ES5 and used a few accepted extensions.
// Where I part company is on reusing the object literal. It is not the syntax
// most classy programmers expect, coming from other languages. It has annoying
// and alien overhead, namely colons and commas. For JS community members who
BrendanEich / ta_vs_nt
Created Aug 17, 2011
typed array vs. number type
View ta_vs_nt
js> b = new ArrayBuffer(64)
js> a = new Uint32Array(b)
({0:0, 1:0, 2:0, 3:0, 4:0, 5:0, 6:0, 7:0, 8:0, 9:0, 10:0, 11:0, 12:0, 13:0, 14:0, 15:0})
js> a[0]
js> a[0] = Math.pow(2,32)
js> a[0]
You can’t perform that action at this time.