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 / data-markdown.user.js
Created May 10, 2012 00:48 — forked from paulirish/data-markdown.user.js
*[data-markdown] - use markdown, sometimes, in your HTML
// ==UserScript==
// @name Use Markdown, sometimes, in your HTML.
// @author Paul Irish <http://paulirish.com/>
// @link http://git.io/data-markdown
// @match *
// ==/UserScript==
// If you're not using this as a userscript just delete from this line up. It's cool, homey.
@rwaldron
rwaldron / sm.js
Created May 10, 2012 14:39 — forked from dherman/sm.js
sm.js with classes
/*
* Here is an implementation of an NPM module I recently wrote, done with ES6 classes.
* Is it a "betrayal" of the prototypal nature of JavaScript to use classes? Come on.
* Classes are a very common design pattern that's easy to implement with prototypes.
* And for some use cases, they're a good fit. Node's EventEmitter abstraction is a
* perfectly reasonable use of classes and inheritance: it's an abstract datatype that's
* user-extensible. So the 'events' module provides a base class with some built-in
* functionality that you can extend.
*
* And yes, it's a "class." Just check the docs:
@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) {
@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-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 / 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 / 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 / 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 / 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 / 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() {