Skip to content

Instantly share code, notes, and snippets.

View garbados's full-sized avatar

DFB garbados

View GitHub Profile
@garbados
garbados / gist:5988506
Created July 12, 2013 23:05
unknown_error
{ method: 'POST',
headers:
{ 'content-type': 'application/json',
accept: 'application/json' },
uri: 'http://localhost:5984/eggchair',
body: '{"_id":"vQAcIFx.jpg","timestamp":1371708302000,"_attachments":{"content":"/9j/4gv4SUNDX1BST0ZJTEUAAQEAAAvoAAAAAAIAAABtbnRyUkdCIFhZWiAH2QADABsAFQAkAB9hY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAA9tYAAQAAAADTLQAAAAAp+D3er/JVrnhC+uTKgzkNAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABBkZXNjAAABRAAAAHliWFlaAAABwAAAABRiVFJDAAAB1AAACAxkbWRkAAAJ4AAAAIhnWFlaAAAKaAAAABRnVFJDAAAB1AAACAxsdW1pAAAKfAAAABRtZWFzAAAKkAAAACRia3B0AAAKtAAAABRyWFlaAAAKyAAAABRyVFJDAAAB1AAACAx0ZWNoAAAK3AAAAAx2dWVkAAAK6AAAAId3dHB0AAALcAAAABRjcHJ0AAALhAAAADdjaGFkAAALvAAAACxkZXNjAAAAAAAAAB9zUkdCIElFQzYxOTY2LTItMSBibGFjayBzY2FsZWQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAWFlaIAAAAAAAACSgAAAPhAAAts9jdXJ2AAAAAAAABAAAAAAFAAoADwAUABkAHgAjACgALQAyADcAOwBAAEUASgBPAFQAWQBeAGMAaABtAHIAdwB8AIEAhgCLAJAAlQCaAJ8ApACpAK4AsgC3ALwAwQDGAMsA0ADVANsA4ADlAO
@garbados
garbados / app.js
Created June 24, 2013 21:41
Example of pushing data to a Geckoboard widget. Based on this documentation: http://docs.geckoboard.com/custom-widgets/push.html Specific to the "numbers" widget. Find more widget specs here: http://docs.geckoboard.com/custom-widgets/index.html#types
var config = require("./config")
, request = require("request")
, i = 0;
function ping(){
request.post({
url: config.push_url,
json: {
api_key: config.api_key,
data:{
@garbados
garbados / vg.rb
Created June 10, 2013 21:22
multi-box networking setup
(1..5).each do |i|
config.vm.define "box#{i}" do |box|
box.vm.network :forwarded_port, guest: 5984, host: 8000+i,
auto_correct: true
end
end
@garbados
garbados / gist:5672627
Last active December 17, 2015 21:09
map function for ngram mapreduce
map = (doc) ->
size = 4 # = the n in ngram
# chunk function
chunk = (arr, len) ->
chunks = []
i = 0
while i < arr.length
chunks.push arr.slice(i, i += len)
return (x for x in chunks when x.length is len)
# reduce to tokens
@garbados
garbados / md2flask
Created May 20, 2013 22:15
Use like this: `cat [filename].md | md2flask` It kicks up a Flask server that renders the markdown as HTML for your viewing pleasure. Change `/usr/bin/python` to whatever your terminal returns for `which python`, run `chmod +x md2flask`, add it to your $PATH, do a little dance, make a little love, and you should be alright.
#!/usr/bin/python
import flask
import markdown
import sys
app = flask.Flask(__name__)
md = sys.stdin.read()
@app.route('/')
@garbados
garbados / gist:4732069
Created February 7, 2013 16:22
Writes to crontab a command that, at the beginning of every hour, reads aloud the result of `fortune`. Problem: overwrites existing crontab.
echo "00 * * * * `which fortune` | say" | crontab
@garbados
garbados / gist:4591223
Created January 22, 2013 01:27
Coding help w/ Rick
import csv
from collections import Counter
class Reading(object):
def __init__(self, **kwargs):
for k,v in kwargs.iteritems():
setattr(self, k, v)
file_list = [] # list of files
readings = []
@garbados
garbados / gist:4514450
Last active May 30, 2017 01:28
A Python script providing access to FullContact's API. Requires Requests, and a FullContact API key. Run with `python -i` to make it a CLI. Or, check out `https://github.com/garbados/fullcontact.py` for a more robust interface.
import requests
import json
api_key = 'your_api_key'
url = "https://api.fullcontact.com/v2/person.json"
def whois(**kwargs):
if 'apiKey' not in kwargs:
kwargs['apiKey'] = api_key
r = requests.get(url, params=kwargs)
@garbados
garbados / gist:4499137
Created January 10, 2013 03:17
Backbone DummyView: takes a template and an el and shoves it into the DOM upon instantiation.
var DummyView = Backbone.View.extend({
initialize: function(options) {
this.template = _.template(options.template.html());
this.render();
},
render: function() {
this.$el.html(this.template({}));
}
});
@garbados
garbados / gist:4218737
Created December 5, 2012 19:28
jsonize_csv(): quickly turn CSVs into arrays of dicts
"""
I hate CSVs, so this converts them into an array of dicts, with each key-value pair matching that column's header, and the row's value for that column.
"""
def jsonize_csv(fp):
with open(fp, 'r') as f:
headers = f.readline().split(',')[:-1]
lines = []
for line in f:
line = line.split(',')