Skip to content

Instantly share code, notes, and snippets.

@thinkjson
thinkjson / gist:1177537
Created August 29, 2011 01:25 — forked from voodootikigod/gist:1155790
PyCodeConf Ticket Give-away
Day job:
Python programmer, data analyst, and DBA at Stetson University
Favorite Python project:
Django, because I'm a perfectionist that's always on a deadline
Favorite Conference:
TED, because being an inventor runs in the family
Python Experience Level:
var ReportDesigner = Backbone.View.extend({
initialize: function(args) {
this.workspace = args.workspace;
// Create a unique ID for use as the CSS selector
this.id = _.uniqueId("report_");
$(this.el).attr({ id: this.id });
this.add_button();
@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: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 / evolving_music.js
Created September 2, 2012 18:45
evolving music
var baudio = require('baudio');
var b = baudio();
b.push((function () {
// randomly evolving melody
var freqs = [
0, 0, 1600, 1600,
0, 0, 2000, 2000,
0, 1400, 0, 1400,
@thinkjson
thinkjson / mysql.php
Created September 10, 2012 12:22
Getting double the ammount I should on value $v
$new_array = array();
$ret_html = "<table><tr><th>DMA</th><th>Leads</th></tr>";
while ($row = mysql_fetch_array($result))
foreach ($row as $key => $value) {
if (isset($new_array["$value"]))
$new_array["$value"]++;
else
$new_array["$value"]++;
import requests # `pip install requests`; DO IT!
import time
import sys
class ComfortSweet:
LAST_ATTEMPT = 0
def main(self):
import requests # `pip install requests`; DO IT!
import time
import sys
class ComfortSweet:
LAST_ATTEMPT = 0
def main(self):