Skip to content

Instantly share code, notes, and snippets.

@jedp
jedp / gist:1894033
Created February 23, 2012 17:55
javascript scoping example
var d1 = {};
var d2 = {};
for(var i=0; i<10; i++) {
d1[i] = function() { return i; };
}
for(var j=0; j<10; j++) {
(function() {
var k = j;
@jedp
jedp / gist:2564204
Created May 1, 2012 01:27
basic zshrc
#!/usr/bin/env zsh
# Completions and autoload {{{
# note - you can get a clean config using compinstall and zsh-newuser-install
zstyle ':completion:*' completer _expand _complete _correct
zstyle ':completion:*' completions 4
zstyle ':completion:*' glob 1
zstyle ':completion:*' group-name ''
zstyle ':completion:*' ignore-parents parent pwd
@jedp
jedp / sample.js
Created June 7, 2012 15:19
kpiggybank data simulator
#!/usr/bin/env node
/**
* Create sample interaction data, using valid kpiggybank
* data as a seed.
*
* Can use from the command line, like so:
*
* node sample.js 42 # gets 42 data blobs
*
@jedp
jedp / gist:2956223
Created June 19, 2012 20:03
libuv simple async
#include <v8.h>
#include <v8-profiler.h>
#include <node.h>
#include <uv.h>
#include <sys/time.h>
#include <iostream>
using namespace node;
using namespace v8;
using namespace std;
@jedp
jedp / gist:3005816
Created June 27, 2012 18:18
postMessage() security review checklist

Security-Reviewing Uses of postMessage()

The postMessage() API is an HTML5 extension that permits string message-passing between frames that don't share the same origin. It is available in all modern browsers. It is not supported in IE6 and IE7.

postMessage is generally considered very secure as long as the programmer is careful to check the origin and source of an arriving

@jedp
jedp / reducers.js
Created July 2, 2012 03:42 — forked from Gozala/reducers.js
Experimenting with clojure reducers
Array.prototype.reduce = this.ArrayReduce || Array.prototype.reduce
var console = window.console
var global = this
function assert(actual, expected) {
if (arguments.length < 2 && actual)
return actual
if (actual === expected)
return actual
if (JSON.stringify(actual) == JSON.stringify(expected))
return JSON.stringify(actual)
@jedp
jedp / gist:3166317
Created July 23, 2012 21:22
Logging module, file, and line number of caller
var util = require('util');
const STACK_FRAME_RE = new RegExp(/at ((\S+)\s)?\(?([^:]+):(\d+):(\d+)/);
const THIS_FILE = __filename.split('/')[__filename.split('/').length - 1];
var Logger = module.exports = function Logger() {
// I like pie
};
Logger.prototype = {
@jedp
jedp / gist:3166329
Created July 23, 2012 21:25
Hash to small integer
// Hash 'string' to a small number (digits default: 6)
function hash(string, digits) {
digits = digits || 6;
var m = Math.pow(10, digits+1) - 1;
var phi = Math.pow(10, digits) / 2 - 1;
var n = 0;
for (var i = 0; i < string.length; i++) {
n = (n + phi * string.charCodeAt(i)) % m;
}
return n.toString();
@jedp
jedp / example.js
Created August 1, 2012 20:45
Node.JS CouchDB paginator
var cradle = require('cradle');
// change as necessary
var host = '127.0.0.1';
var port = 5984;
var dbname = 'foo';
// setup cradle db and paginator
var conn = new (cradle.Connection)(host, port);
var db = conn.database(dbname);
@jedp
jedp / gist:3778932
Created September 24, 2012 22:50
B2G repo setup and build quickstart

B2G Quickstart for Payments and Identity

Before you begin: You want to do this on a Mac. I have been using Linux for months, and unresolved redraw issues (white screen of death) are killing me. Mac works great. Use OSX.

This sets you up to make two separate targets:

  • One for a desktop [simulator] [1]
  • One for the Unagi [device] [2]

These are the moving parts:

  • [mozilla-inbound repo] [3] clone (hg)