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 / from.js
Created November 18, 2011 16:56 — forked from dherman/from.js
possible meanings of Array.from
Array.from = function from(x) {
var result = new Array();
for (var i = 0, n = x.length; i < n; i++) {
if (i in x)
result[i] = x[i];
}
return result;
};
// If Object.getPrototypeOf(Subarray) === Array, then:
@rwaldron
rwaldron / class.js
Created November 3, 2011 18:14 — forked from rauschma/class.js
Yet another simple class proposal
// Guidelines:
// - Class declarations and object literals should have the same features
// - Keep new features at a minimum (apart from what’s already in the object literal proposal)
// - Don’t obscure the fact that private names are actually name objects.
// => They can also be imported from somewhere else – a use case that needs to be supported.
// Rules:
// - Use # to denote const-ness
// Alternative: keyword `const`
// - Use @ to refer to name objects
@rwaldron
rwaldron / class.js
Created November 1, 2011 14:40 — forked from DmitrySoshnikov/class.js
Class lib sugar for JS
/**
* class.js
* @author Dmitry A. Soshnikov
*/
function Class(params) {
/**
* Constructor function
* If not specified, use default
@rwaldron
rwaldron / jsfiddle-defaults.user.js
Created October 30, 2011 12:23 — forked from mathiasbynens/jsfiddle-defaults.user.js
Userscript that enables sensible defaults for jsFiddle.
// ==UserScript==
// @name Sensible defaults for jsFiddle.
// @author Mathias Bynens <http://mathiasbynens.be/>
// @link http://mths.be/bde
// @match http://jsfiddle.net/*
// ==/UserScript==
// Ignore existing fiddles
if (window.location.pathname == '/') {
@rwaldron
rwaldron / no-comma-first.js
Created October 5, 2011 13:49 — forked from indexzero/no-comma-first.js
JUST SAY NO TO COMMA FIRST
var fs = require('fs'),
path = require('path'),
colors = require('colors'),
argv = require('optimist').argv;
fs.readFile(path.join(__dirname, argv._[0]), function (err, data) {
var lines = data.toString().split('\n');
for (var i = 0; i < lines.length; i++) {
@rwaldron
rwaldron / Pattern.lua
Created September 24, 2011 16:37 — forked from creationix/Pattern.lua
Pattern.js ported to Lua
Pattern = {}
function Pattern:extend(obj)
local child = obj or {}
setmetatable(child, {__index = self})
return child
end
function Pattern:new(...)
local obj = {}
@rwaldron
rwaldron / getMyCode.js
Created September 24, 2011 16:37 — forked from creationix/getMyCode.js
Script to download all repos for a user
// Run this with node and then run the output with sh
var Http = require('http')
var ChildProcess = require('child_process');
Http.cat("http://github.com/api/v2/json/repos/show/creationix", function (err, json) {
if (err) throw err;
var data = JSON.parse(json);
data.repositories.forEach(function (repo) {
console.log("echo " + JSON.stringify(repo.name + " - " + repo.description));
console.log("git clone --bare " + repo.url);
});
@rwaldron
rwaldron / stack.js
Created September 12, 2011 20:02 — forked from nzakas/stack.js
Stack implementation using ES6 proxies
/*
* Another ES6 Proxy experiment. This one creates a stack whose underlying
* implementation is an array. The proxy is used to filter out everything
* but "push", "pop", and "length" from the interface, making it a pure
* stack where you can't manipulate the contents.
*/
var Stack = (function(){
var stack = [],
@rwaldron
rwaldron / es6proxy.htm
Created September 9, 2011 14:56 — forked from nzakas/es6proxy.htm
Example of ES6 Proxy
<!DOCTYPE html>
<!--
This is a simple experiment relying on ECMAScript 6 Proxies. To try this out,
use Aurora (http://www.mozilla.org/en-US/firefox/channel/).
The goal was to create a HTML writer where the method names were really just
the HTML tags names, but without manually creating each method. This uses
a Proxy to create a shell to an underlying writer object that checks each
method name to see if it's in a list of known tags.
var Person = {
'initialize': function(first, last) {
this.first = first;
this.last = last;
},
'speak': function(message) {
return this.first + ' ' + this.last + ': ' + message;
}
};