Skip to content

Instantly share code, notes, and snippets.

View joemccann's full-sized avatar
💭
Thinking

Joe McCann joemccann

💭
Thinking
View GitHub Profile
@jchris
jchris / reduce.js
Created November 26, 2010 04:41
unique key count reduce
function(ks, vs, rr) {
// values are discarded by reduce
// todo: configurable key function, for complex queries
var fk, lk;
function uniqCount(keys) {
var count = 0, obj = {};
for (var i=0; i < keys.length; i++) {
if (!obj[keys[i]]) {
count++;
obj[keys[i]] = true;
require.registerExtension('.js', function(js){
return js.replace(/^ *\/\/debug: */gm, '');
});
@isaacs
isaacs / callbacksarehard.js
Created January 12, 2011 02:29
let's go shopping!
// before
mainWindow.menu("File", function(err, file) {
if(err) throw err;
file.openMenu(function(err, menu) {
if(err) throw err;
menu.item("Open", function(err, item) {
if(err) throw err;
item.click(function(err) {
if(err) throw err;
mainWindow.getChild(type('Window'), function(err, dialog) {
@waxpancake
waxpancake / parse_daily.py
Created February 23, 2011 17:41
Python script to parse The Daily iPad app's JSON and spit out an HTML index
#!/usr/bin/python
import json, sys, re
filename = sys.argv[1]
f = open(filename, 'r')
contents = json.load(f)
contentIndex = {}
for content in contents['content']:
@brianleroux
brianleroux / makefile
Created February 25, 2011 20:46
launch emulators
emulate:
emulator -cpu-delay 0 -no-boot-anim -cache ./cache -avd default > /dev/null 2>&1 & # put the avd's chatty ass in the background
open /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone\ Simulator.app
palm-emulator --start "SDK 1.4.5.465 (320x480)"
@jed
jed / README.md
Created April 4, 2011 14:02
a small module for autorequiring. warning: MAGIC!

autorequire.js

Copyright (c) 2011 Jed Schmidt

a small module for auto-importing modules in node.js.

usage

require( "./autorequire" )
require.auto( <module-name> )
@sintaxi
sintaxi / server.js
Created April 8, 2011 19:15
a simple reverse proxy using Node
var http = require("http"),
util = require("util")
http.createServer(function(req, rsp){
var regex = /^\/(v1|v2)/g
var matches = req.url.match(regex)
if((matches && matches[0] === "/v1") || (req.headers["x-api-version"] === "v1"))
var port = 8001
@davidwood
davidwood / gist:954363
Created May 3, 2011 22:05
Serve current directory over HTTP using Python
python -m SimpleHTTPServer
By default, SimpleHTTPServer serves on port 8000. To specify a port, use (where 9090 is the port you want):
python -m SimpleHTTPServer 9090
And to run it in the background, use:
python -m SimpleHTTPServer &
@romannurik
romannurik / inline_worker_with_fallback.html
Created May 24, 2011 19:16
An example of using simple inline Web Workers with a fallback for browsers that can't support this technique.
<!DOCTYPE html>
<html>
<!--
Copyright 2011 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
@necolas
necolas / snippet.js
Created June 14, 2011 20:36
Optimised async loading of cross-domain scripts
/*
* Updated to use the function-based method described in http://www.phpied.com/social-button-bffs/
* Better handling of scripts without supplied ids.
*
* N.B. Be sure to include Google Analytics's _gaq and Facebook's fbAsyncInit prior to this function.
*/
(function(doc, script) {
var js,
fjs = doc.getElementsByTagName(script)[0],