Skip to content

Instantly share code, notes, and snippets.

View tristanwietsma's full-sized avatar

Tristan Wietsma tristanwietsma

  • Chicago, Illinois
View GitHub Profile
@tristanwietsma
tristanwietsma / Dockerfile
Created February 6, 2014 19:29
Oscats dockerfile
# OSCATS
FROM ubuntu
MAINTAINER Tristan Wietsma twietsma@civisanalytics.com
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y build-essential
RUN apt-get install -y autoconf automake
@tristanwietsma
tristanwietsma / getset.go
Created February 9, 2014 20:55
Go web server with GET, POST
package main
import (
"fmt"
"github.com/gorilla/mux"
"github.com/tristanwietsma/metastore"
"log"
"net/http"
)
@tristanwietsma
tristanwietsma / example.py
Created March 6, 2014 21:08
Futures in Python 3.3
# python 3.3: example of futures
import time
import concurrent.futures
def add(x, y):
time.sleep(2)
return x + y
with concurrent.futures.ThreadPoolExecutor(max_workers=4) as queue:
@tristanwietsma
tristanwietsma / hmm.py
Created March 12, 2014 02:10
Hidden Markov model example
from __future__ import division
import numpy
from sklearn import hmm
"""
X is a numpy array with shape (#samples, #sensors).
X = [[sensor1(0), sensor2(0)], [sensor1(1), sensor2(1)], ..., [sensor1(T), sensor2(T)]]
nc = number of latent states (3 would imply three strata)
@tristanwietsma
tristanwietsma / py2.py
Last active August 29, 2015 13:57
parallel python examples
import random
from joblib import Parallel, delayed
import time
def Example(c):
some_random_delay = int(2*random.random()*c)
time.sleep(some_random_delay) # let's pretend we're doing work
print some_random_delay
return some_random_delay
@tristanwietsma
tristanwietsma / batchjobs.py
Last active August 29, 2015 13:58
batching out jobs to separate processes with python futures
#!/usr/local/bin/python3
import sys, os
from concurrent.futures import ProcessPoolExecutor
def osjob(cmd):
print("running `{}`".format(cmd))
os.system(cmd)
print("finished `{}`".format(cmd))
@tristanwietsma
tristanwietsma / fix.diff
Created April 11, 2014 00:59
sqlautocode patch
diff -r 08a7912b8a09 -r 4c04152dfffe sqlautocode/config.py
--- a/sqlautocode/config.py Mon Sep 24 10:44:30 2012 +0200
+++ b/sqlautocode/config.py Wed Apr 17 13:26:23 2013 +0300
@@ -140,7 +140,7 @@
engine = sqlalchemy.create_engine(url)
test = engine.connect()
test.close()
- except sqlalchemy.exceptions.SQLAlchemyError, ex:
+ except sqlalchemy.exc.SQLAlchemyError, ex:
parser.error('Could not connect to "%s": %s' % (url, ex))

Inspired by Trulia Trends - but with code and using SVG.

Example data shows concurrent user sessions over time, taken from a development environment.

@tristanwietsma
tristanwietsma / a.py
Created June 6, 2014 14:18
Futures example with multiple input params
from concurrent.futures import ProcessPoolExecutor
def myfunc(a, b, c):
return a + b + c
if __name__ == '__main__':
workers = 3
result = []