Skip to content

Instantly share code, notes, and snippets.

View fitzgen's full-sized avatar
🙃

Nick Fitzgerald fitzgen

🙃
View GitHub Profile
var FILE = require("file");
require.paths.unshift(FILE.join(FILE.dirname(module.path),
"jsmacros/vendor/jison/lib"));
var Parser = require("jison").Parser;
require.paths.shift();
var grammar = {
lex: {
rules: [
var FILE = require("file");
require.paths.unshift(FILE.join(FILE.dirname(module.path),
"jsmacros/vendor/jison/lib"));
var Parser = require("jison").Parser;
require.paths.shift();
var grammar = {
lex: {
rules: [
//@use bind.jsm
function returnsMultipleVals () {
return ["foo", "bar"];
}
var foo, bar;
@fitzgen
fitzgen / gist:648562
Created October 27, 2010 06:28
Spam or not?
from N!#@R ... <sipps.7@gmail.com>
to fitzgen@gmail.com
date Tue, Oct 26, 2010 at 11:20 PM
subject Need help with Javascript issue
mailed-by gmail.com
signed-by gmail.com
Hello,
I just visited your blog http://fitzgeraldnick.com/weblog/ for some of the javascript related code snippets and it was really cool! I just thought if you could help me with something that I am trying..
from django import http
import operator
import pickle
def copy_pickleable(a, b):
for k, v in a.iteritems():
try:
pickle.dumps(v)
b[k] = v
except TypeError:
import pickle
# Simple generator that counts up to maximum, but you can set the counter by
# sending in new values.
def counter(maximum):
i = 0
while i < maximum:
val = (yield i)
# If value provided, change counter
if val is not None:
acc = (n)->
(i)->
n += i
=======================
var acc;
acc = function(n) {
return function(i) {
return n += i;
@fitzgen
fitzgen / gist:749901
Created December 21, 2010 12:59
My TCO -- doesn't work with mutual recursion
function toArray(obj, i) {
return Array.prototype.slice.call(obj, i || 0);
}
function tco(fn) {
return function () {
var args = toArray(arguments),
shouldContinue = true,
recur = function () {
shouldContinue = true;
@fitzgen
fitzgen / gist:749904
Last active April 26, 2024 20:08
Gerard Paapu's TCO. Works with mutual recursion.
(function () {
// conceal the Thunk class to avoid
// so that the only way to make one is
// to call Function::thunk
function Thunk(fn, args) {
this.fn = fn;
this.args = args;
}
Thunk.prototype.force = function () {
@fitzgen
fitzgen / operations.js
Created February 18, 2011 01:25
Uses a slightly modified version of the Levenshtien Distance algorithm (also known as "edit distance") to calculate the set of the fewest operations which will change string s in to string t.
# Output of the example which is console.logged at the bottom of operations.js:
$ node operations.js
To change 'kitten' in to 'sitting':
[ [ 'delete', 'k' ]
, [ 'insert', 's' ]
, [ 'retain', 1 ]
, [ 'retain', 1 ]
, [ 'retain', 1 ]
, [ 'delete', 'e' ]