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 / ecma5_on_v8.js
Created January 30, 2012 14:31 — forked from Jxck/ecma5_on_v8.js
The sample usage of ECMA 5 Features Implemented in V8
/**
* The sample usage of ECMA 5 Mozilla Features Implemented in V8
* https://github.com/joyent/node/wiki/ECMA-5-Mozilla-Features-Implemented-in-V8
* You can use thease new feature of ECMA5 on Node.js as you like.
* because there is no IE :)
* Order is deferent form original wiki.
* Sources are Checked on Node.js v0.5.0(unstable), v0.4.9(stable)
*
* you can execute this file.
* $ node ecma5_on_v8.js
@rwaldron
rwaldron / example.js
Created January 31, 2012 05:19 — forked from Gozala/example.js
Workaround for lack of "tail call optimization" in JS
// Lack of tail call optimization in JS
var sum = function(x, y) {
return y > 0 ? sum(x + 1, y - 1) :
y < 0 ? sum(x - 1, y + 1) :
x
}
sum(20, 100000) // => RangeError: Maximum call stack size exceeded
// Using workaround
@rwaldron
rwaldron / z.js
Created February 27, 2012 17:08 — forked from bga/z.js
z
var match = []
var _finalizeExpr = function(match) {
var vs = match[0]
var _iter = match[1]
var _done = match[2]
var i = 0
var _iterWrappper = function() {
if(i === vs.length) {
@rwaldron
rwaldron / z.js
Created February 27, 2012 17:09 — forked from heapwolf/z.js
z
//
// an experimental flow control library.
// please dont ever use this for anything.
//
var z = function z(f) {
if (!(this instanceof z)) {
return new z(f);
}
@rwaldron
rwaldron / short-functions.js
Created March 12, 2012 14:45 — forked from dherman/short-functions.js
using -> for concise functions and => for TCP functions
// 1. Shorter function syntax.
//
// This version does not respect "Tennent's correspondence principle" -- it's nothing
// more than syntactic sugar for the traditional function syntax. That means when you
// see the normal braced body of a function, whether it's a longhand function or this
// shorthand version, there's no difference: return, this, and arguments are all tied
// to the new function body, and there's no implicit returning of the last expression
// result.
a.some((x) -> {
@rwaldron
rwaldron / mouse.js
Created March 12, 2012 14:47 — forked from bfncs/mouse.js
Read Linux mouse(s) in node.js
/**
* Read Linux mouse(s) in node.js
* Author: Marc Loehe ([email protected])
*
* Adapted from Tim Caswell's nice solution to read a linux joystick
* http://nodebits.org/linux-joystick
* https://github.com/nodebits/linux-joystick
*/
var fs = require('fs'),
@rwaldron
rwaldron / hack.sh
Created March 31, 2012 13:56 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@rwaldron
rwaldron / es-monsters.js
Created April 8, 2012 00:02
ES Monsters
// A private name used by the Monster class
const pHealth = Name.create();
class Monster {
// A method named "new" defines the class’s constructor function.
new(name, health) {
this.name = name;
this[pHealth] = health;
(function (exports) {
// These aliases can be safely removed.
var toString = {}.toString, hasOwn = {}.hasOwnProperty,
// **defer** attempts to execute a callback function asynchronously in supported
// environments.
defer = function (callback, context) {
// `process.nextTick` is an efficient alternative to `setTimeout(..., 0)`.
// As of Node 0.6.9, neither `process.nextTick` nor `setTimeout` isolate
// execution; if the `callback` throws an exception, subsequent deferred
@rwaldron
rwaldron / git_logging.txt
Created April 25, 2012 16:27 — forked from softprops/git_logging.txt
fancy git log flags
git log --all --pretty=format:"%h %cd %s (%an)" --since='7 days ago'
git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
git log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short --since='1 day ago'
git log --pretty=format:"%ad, %s%d [%an]" --graph --date=short --since='1 day ago'