Skip to content

Instantly share code, notes, and snippets.

View dherman's full-sized avatar

Dave Herman dherman

View GitHub Profile
@dherman
dherman / fibonacci.js
Last active December 28, 2016 21:12 — forked from hagino3000/fibonacci.js
asm.js sample
function fast_fib_module(stdlib, foreign, heap) {
"use asm";
function fib(n) {
n = n|0;
if (n >>> 0 < 3) {
return 1|0;
}
@dherman
dherman / dave.js
Last active December 16, 2015 13:19 — forked from anonymous/dave.js
export default f(1, 2, 3); // anonymous export
export let foo = 5; // named declaration export
export foo // named export of existing identifier
export foo, bar; // named export of multiple existing identifiers
export foo as f; // named aliasing export
export foo as f, bar; // you get the idea
import default glob from "glob"; // anonymous import
import sync from "glob"; // named import
import sync as s from "glob"; // named aliasing import
@dherman
dherman / paproxy.js
Created August 22, 2012 17:23 — forked from syg/gist:3427627
demonstrate PA behavior as a proxy
function isIndex(n) {
// This isn't right, but pretend that this checks if n is an index in the
// way that SpiderMonkey checks in js_IdIsIndex.
return Number(n) % 1 == 0;
}
function indices(obj) {
var result = [];
for (var i = 0; i < obj.length; i++)
result.push(i);
@dherman
dherman / nbody.rs
Created June 14, 2012 05:30 — forked from pcwalton/gist:2927607
Rust of Patrick's dreams, with Dave's method syntax :)
import std.math.{PI, sqrt};
struct Body {
x: f64;
y: f64;
z: f64;
vx: f64;
vy: f64;
vz: f64;
mass: f64;
@dherman
dherman / minimalist-classes.js
Created November 9, 2011 06:05 — forked from jashkenas/minimalist-classes.js
minimalist classes based on variable-declaration syntax
// Examples using something closer to my original "minimal classes" proposal.
// There are several benefits to this approach.
// First, it uses a familiar approach to separating prototype properties from
// instance properties: methods are on the prototype, and static declarations
// are prototype data properties. Otherwise, instance properties are only
// declared in the constructor body.
// Second, instead of object literal syntax, it uses a property declaration
// Demonstrating @jashkenas's examples in an even-more-minimalist version of
// classes that only allow object-literal syntax for the class body.
// Basic usage; unchanged.
class Color {
constructor: function(hex) {
...
},