Skip to content

Instantly share code, notes, and snippets.

View drawks's full-sized avatar

Dave Rawks drawks

  • Oakland, California
View GitHub Profile

Keybase proof

I hereby claim:

  • I am drawks on github.
  • I am drawks (https://keybase.io/drawks) on keybase.
  • I have a public key ASD1ZCq0zxgk8MCOBCX9Cnk3-mBp5w2cnF-9s7q3ufTzxwo

To claim this, I am signing this object:

@drawks
drawks / prometheus_bottle
Last active January 20, 2017 19:15
minimal prometheus instrumentation of a bottle application
from bottle import route, run, template, Bottle
from prometheus_client import multiprocess
from prometheus_client import generate_latest, REGISTRY, Gauge, Counter
application = Bottle()
IN_PROGRESS = Gauge("inprogress_requests", "help")
REQUESTS = Counter('http_requests_total', 'Description of counter', ['method', 'endpoint'])
@drawks
drawks / gist:5438362
Created April 22, 2013 20:42
Example of type coercion for sqlalchemy.
class CoerceDateTime(TypeDecorator):
"""Extend DateTime to also coerce iso formatted datetime strings and epoch
ints in addition to native python datetimes"""
impl = DateTime
def process_bind_param(self, value, dialect):
if isinstance(value, str):
try:
value = iso8601.parse_date(value)
@drawks
drawks / state_adjaceny.js
Created February 22, 2012 16:40
Dict of States and their bordering states.
"borders": {
"mississippi": [
"alabama",
"arkansas",
"louisiana",
"tennessee"
],
"oklahoma": [
"arkansas",
"colorado",
@drawks
drawks / maketrash.py
Created February 17, 2012 21:53
Really garbagy carbon-cache test bollus generator
#!/usr/bin/env python
import msgpack, socket, time, pickle, struct
from random import shuffle
words = [ word.strip() for word in open('/tmp/word.lst','rt').readlines() ]
def metric_name():
while True:
shuffle(words)
yield ".".join(words[0:3])
@drawks
drawks / graphite
Created February 14, 2012 21:24
Graphite on uwsgi/nginx
#This is the "site config" for nginx
upstream django {
# Distribute requests to servers based on client IP. This keeps load
# balancing fair but consistent per-client. In this instance we're
# only using one uWGSI worker anyway.
ip_hash;
server unix:/tmp/uwsgi.sock;
}
server {
@drawks
drawks / gist:1556373
Created January 3, 2012 19:06 — forked from kimchy/gist:1556146
Disable the _all field
curl -XPUT 'http://localhost:9200/_template/template_logstash/' -d '
{
"template": "logstash-*",
"mappings": {
"_default_": {
"_all" : {"enabled" : false}
}
}
}'
@drawks
drawks / gist:1556336
Created January 3, 2012 18:59 — forked from kimchy/gist:1556171
optimize a logstash/elasticsearch index
curl -XPOST 'http://localhost:9200/logstash-2001.01.01/_optimize?max_num_segments=2'
@drawks
drawks / gist:1556276
Created January 3, 2012 18:47 — forked from kimchy/gist:1556146
Enable _source compression in elasticsearch
curl -XPUT 'http://localhost:9200/_template/template_logstash/' -d '
{
"template": "logstash-*",
"mappings": {
"_default_": {
"_source": { "compress": "true" },
}
}
}'