Skip to content

Instantly share code, notes, and snippets.

View solenoid's full-sized avatar

Erik Solen solenoid

View GitHub Profile
@solenoid
solenoid / README.md
Last active October 12, 2018 01:44
GDP Growth and Presidential Party
@solenoid
solenoid / functional.js
Created May 11, 2012 20:27
Example of raw Yieldbot js code
var _ = require('underscore'),
d3 = require('d3');
// This is an example of some functional heavy code used at Yieldbot
// prepare raw data into 20 minute buckets and
// return data along with relevant max info and scale functions
var prep = function (data) {
var total = 0;
var prepared = _.map(_.keys(data), function (hour) {
@solenoid
solenoid / gist:1372388
Created November 17, 2011 04:51
simple rest implementation in django
if 'GET' == request.method:
resources = []
for resource in mongo_collection.find():
resource['id'] = str(resource['_id'])
del resource['_id']
resources.append(resource)
content = json.dumps(resources)
return HttpResponse(content=content, mimetype='application/javascript')
if 'POST' == request.method:
raw_data = StringIO.StringIO(request.raw_post_data)
@solenoid
solenoid / gist:1372386
Created November 17, 2011 04:49
javascript ObjectId generator
var mongoObjectId = function () {
var timestamp = (new Date().getTime() / 1000 | 0).toString(16);
return timestamp + 'xxxxxxxxxxxxxxxx'.replace(/[x]/g, function() {
return (Math.random() * 16 | 0).toString(16);
}).toLowerCase();
};
@solenoid
solenoid / gist:1215114
Created September 13, 2011 20:47 — forked from rfreedman/gist:1214540
modified Mammal CoffeeScript example
class Mammal
constructor: (@species, @defining_char) ->
print: ->
"Hello I'm a #{@species}. I have #{@defining_char}."
cat = new Mammal('cat', 'claws')
alert(cat.print())