Skip to content

Instantly share code, notes, and snippets.

View dch's full-sized avatar
🛋️

Dave Cottlehuber dch

🛋️
View GitHub Profile
@dch
dch / by_month.js
Created March 25, 2012 09:17
couchdb map/reduce to compute browserling and testling usage data by month
{
map : function (doc) {
if (doc.type === 'usage' && doc.service && doc.time) {
var d = new Date(doc.time);
var y = d.getFullYear();
var m = d.getMonth() + 1;
var stamp = y + '/' + m;
var rec = {
stamp : stamp,
@dch
dch / gist:2224339
Created March 28, 2012 06:42 — forked from amedeo/gist:820412
CouchDB and multiple tags

CouchDB and multiple tags

The problem

Given a set of documents, each associated with multiple tags, how can I retrieve the documents tagged with an arbitrary set of tags?

My solution

@dch
dch / gist:2891528
Created June 7, 2012 21:06 — forked from danfairs/gist:2891161
couchapp dispatch
def get_or_create_db(self, db_name, designs=ALL_DESIGNS):
from couchapp import dispatch
couchapp_dir = os.path.join(
settings.PROJECT_DIR, '..', '..', 'couchdb', 'tweet_counts'
)
server = couchdbkit.Server(uri=settings.COUCHDB_SERVER_URI,
resource_class=couchdb.RequestsResource)
db = server.get_db(db_name)
try:
db.info()
@dch
dch / t.erl
Created June 13, 2012 06:21 — forked from jlouis/t.erl
Percept example
-module(t).
-export([start/0, go/0, analyze/0, server/0]).
start() ->
percept:profile("test.dat", {t, go, []}, [procs]).
go() ->
Led = led:start(1),
Led1 = led:start(1),
@dch
dch / README
Created June 15, 2012 09:50 — forked from mojombo/README
Another mustache.erl example, this time showing off lists and asking for context in one of the view functions.
@dch
dch / GITHUB-COMPARE-LINKS.md
Created July 2, 2012 09:04 — forked from mbbx6spp/GITHUB-COMPARE-LINKS.md
This Gist is worth a million beers. So buy me one (or send me a really cool t-shirt, make sure it is REALLY cool though)! :)
@dch
dch / a-spidermonkey-test.js
Created July 3, 2012 07:52 — forked from jimklo/a-spidermonkey-test.js
OpenPGP.js with SpiderMonkey example
// make check for navigator properties not fail.
var navigator = {};
// support some basic HTML5 localStorage operations
function _localStorage() {
this.ls = {};
this.getItem = function(key) {
<!DOCTYPE html>
<html>
<head>
<title>Simple Address Book</title>
<link rel="stylesheet" href="style/main.css" type="text/css">
<script src="/_utils/script/json2.js"></script>
<script src="/_utils/script/jquery.js?1.3.1"></script>
<script src="/_utils/script/jquery.couch.js?0.9.0"></script>
<script type="text/javascript">
$db = $.couch.db("addressbook");
@dch
dch / latency.markdown
Created August 10, 2012 11:36 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

@dch
dch / appdotnet.py
Created August 13, 2012 08:23
app.net command line app
#!/usr/bin/env python
"""appdotnet
Usage:
appdotnet authenticate <client_id>
appdotnet set-accesstoken <access_token>
appdotnet global
appdotnet
appdotnet -h | --help