Skip to content

Instantly share code, notes, and snippets.

View rwaldron's full-sized avatar

Rick Waldron rwaldron

  • Boston, MA
View GitHub Profile
@rwaldron
rwaldron / options-objects.js
Created September 19, 2012 18:43 — forked from ericf/gist:3751340
ES6 Object.assign( target, source ) as a native options object merging pattern.
let defaults = { file: null };
function foo(options) {
// Merging defaults and options objects in ES6
options = [ defaults, options ].reduce(Object.assign, {});
}
foo({ file: "happy.md" });
@rwaldron
rwaldron / index.html
Created September 3, 2012 02:34 — forked from visnup/index.html
playing with a very minimal one page site
<pre>
# Just Markdown, Yo.
So, I wanted to try to write the simplest webpage possible, [Max Ogden][1]
style. If you have JavaScript, you get something pretty. If not, then you see
[Markdown][2] text, which is fine too.
[1]: http://maxogden.com
[2]: http://daringfireball.net/projects/markdown/
</pre>
@rwaldron
rwaldron / lcd.js
Created July 29, 2012 18:32 — forked from haugstrup/lcd.js
LCD proof of concept for johnny-five
// Wire up LCD as described here:
// http://learn.adafruit.com/character-lcds/overview
var five = require("johnny-five"),
board, lcd;
board = new five.Board();
board.on("ready", function() {
@rwaldron
rwaldron / closure.js
Created July 27, 2012 23:36 — forked from dherman/closure.js
Analog to Function constructor for building closures
(function() {
var hasOwnProperty = Object.prototype.hasOwnProperty;
var Function = hasOwnProperty.constructor;
function isIdentifier(s) {
return /[a-zA-Z_$][a-zA-Z_$0-9]*/.test(s);
}
@rwaldron
rwaldron / gist:3185443
Created July 27, 2012 00:37 — forked from rmurphey/gist:3185390
shiftOut in javascript
var five = require("johnny-five"),
board;
board = new five.Board();
board.on("ready", function() {
(new five.Led(13)).on();
var dataPin = 2;
var clockPin = 3;
@rwaldron
rwaldron / gist:3108626
Created July 14, 2012 01:11 — forked from leobalter/gist:3103291
WTF Movie Titles translations to pt-BR
Airplane - "Apertem os cintos, o piloto sumiu" - Fasten your seatbelts, the pilot disappeared
Giant (George Stevens) - "Assim Caminha a Humanidade" - "This way walk humanity"
Mystic River - "Sobre meninos e lobos" - "About boys and wolves"
The Hangover - Se beber, não case - If you drink, don't drive
The Godfather - O Poderoso Chefão - The Great Boss
The Good Son - O Anjo Malvado - The Evil Angel
The Sound of Music - A Noviça Rebelde - The Rebel Nun
The Transporter - Carga Explosiva - Explosive Cargo
The Tuxedo - O Terno de 2 Bilhões de Dólares - The 2 billion dollars suit
Be Cool - O Outro Nome do Jogo - The other name of the game
@rwaldron
rwaldron / map-dict.js
Created June 9, 2012 04:00 — forked from dherman/map-dict.js
Map vs object for dictionary
// A Dict class that works in ES6 using Map. Basically it's identical to Map, but
// only expected to be used on string keys.
function Dict() {
this.elts = new Map();
}
// (string) -> any
Dict.prototype.get = function get(key) {
return this.elts.get(key);
@rwaldron
rwaldron / object-forin.js
Created June 5, 2012 17:50 — forked from cowboy/object-forin-forown.js
JavaScript: Object#forIn ?
Object.defineProperty(Object.prototype, 'forIn', {
value: function(iterator, thisValue) {
Object.keys(this).forEach(function(key) {
iterator.call(thisValue, this[key], key, this);
}.bind(this));
}
});
var obj = {a: 1, b: 2};
@rwaldron
rwaldron / gist:2816959
Created May 28, 2012 02:54 — forked from DavidBruant/gist:2815846
Dynamic DOM prototype
var originalNodeListProto = NodeList.prototype;
var temporaryNodeListProto = Object.create(NodeList.prototype);
temporaryNodeListProto.a = 1;
NodeList.prototype = temporaryNodeListProto;
var l = document.querySelectorAll('a');
console.log(l.a); // inherited from which prototype?
NodeList.prototype = originalNodeListProto;
@rwaldron
rwaldron / object_exemplar_decls.js
Created May 14, 2012 00:15 — forked from rauschma/object_exemplar_decls.js
Class declarations with object exemplar semantics
//----- Example code:
// Class declarations:
// - No data properties allowed
// - Future: support mixins
// - Optional: call the initialization method `new` instead of `constructor`
// Superclass
class Person {
constructor(name) {