Skip to content

Instantly share code, notes, and snippets.

@thinkjson
thinkjson / gist:1563609
Created January 5, 2012 03:45 — forked from nagoodman/gist:1563401
sample sql luciddb
select 'Last 30 Days', sum(measure1)
from time t, fact f
where f.timeid = t.timeid
and
f.date between applib.add_days(current_date, -30) and current_date
UNION ALL
select 'Current Month', sum(measure1)
from time t, fact f
where f.timeid = t.timeid
and t.month = applib.extract_timestamp(current_timestamp, 'MONTH')+1
@thinkjson
thinkjson / gist:1603039
Created January 12, 2012 20:53
Remove field from all docs in a CouchDB database
console.log("Fetching docs...");
var j = 0;
var docs = [];
var ids = [];
nano.list({ stale: "ok" }, function(err, data, headers){
console.log("Updating " + data.rows.length + " docs...");
for (var i = 0; i < data.rows.length; i++) {
ids.push(data.rows[i].id);
}
});
@thinkjson
thinkjson / gist:1603157
Created January 12, 2012 21:14 — forked from snsparrish/gist:1603065
Remove field from all docs in a CouchDB database
console.log("Fetching docs...");
var j = 0;
var docs = [];
var ids = [];
nano.list({ stale: "ok" }, function(err, data, headers){
console.log("Updating " + data.rows.length + " docs...");
for (var i = 0; i < data.rows.length; i++) {
ids.push(data.rows[i].id);
}
});
@thinkjson
thinkjson / gist:1603326
Created January 12, 2012 21:41 — forked from snsparrish/gist:1603065
Remove field from all docs in a CouchDB database
console.log("Fetching docs...");
var j = 0;
var docs = [];
var startdoc = '0';
function fetchdocs(){
nano.list({ stale: "ok", startkey:startdoc, limit:2000, include_docs:true}, function(err, data, headers){
console.log("Updating " + data.rows.length + " docs...");
for (var i = 0; i < data.rows.length; i++) {
var doc = data.rows[i].doc;
//console.log(doc);
@thinkjson
thinkjson / couch-transform.js
Created January 14, 2012 07:26 — forked from max-mapper/couch-transform.js
streaming functional transformer for couchdb using node
var request = require('request').defaults({json: true}),
transfuse = require('transfuse'),
JSONStream = require('JSONStream');
function transform(couchdb, funcString, headers) {
var down = request({url: couchdb + '/_all_docs?include_docs=true'}),
up = request({url: couchdb + '/_bulk_docs', method: "POST", headers: headers}),
tr = transfuse(['rows', /./, 'doc'], funcString, JSONStream.stringify("{\"docs\":[\n", "\n,\n", "\n]}\n"));
down.pipe(tr)
tr.pipe(up)
@thinkjson
thinkjson / output.json
Created January 27, 2012 16:13
Real time analytics in Redis and Node.js
{
"Jan 27 2012 11:03": "139990",
"Jan 27 2012 11:04": "153905",
"Jan 27 2012 11:05": "153666",
"Jan 27 2012 11:06": "150723",
"Jan 27 2012 11:07": "145660",
"Jan 27 2012 11:08": "85044"
}
@thinkjson
thinkjson / schrodinger.py
Created February 20, 2012 15:09
Let Schrödinger's cat help you make decisions
#!/usr/bin/python
# inspired by http://www.thinkgeek.com/homeoffice/e9cb/
import random
if random.randint(0, 1) == 0:
print "Cat is dead. :("
else:
print "Cat is alive! :)"
@thinkjson
thinkjson / decide
Created April 22, 2012 00:21
Command line client to help you make decisions (Can you tell I have trouble making decisions?)
#!/usr/bin/python
import random
import sys
print random.choice(sys.argv[1:])
@thinkjson
thinkjson / benchmark.txt
Created May 19, 2012 01:36
JSON to CSV conversion benchmarking
json2csv.py
real 5m28.824s
user 5m27.584s
sys 0m1.524s
C (https://github.com/jehiah/json2csv)
real 0m15.945s
user 0m15.181s
sys 0m1.204s
@thinkjson
thinkjson / gist:2856135
Created June 2, 2012 01:54
Parsing a 68MB log file:
Perl
real 12m35.264s
user 8m45.136s
sys 3m29.606s
Python
real 33m28.333s
user 31m40.628s
sys 1m25.188s