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 / animals.txt
Last active December 16, 2015 18:29
Go file I/O example This shows how to read a text file in Go, line-by-line. The file is supplied via command-line. A list of lines is built using a slice and the append function. Duplicate lines are prevented using a map. The resulting list of lines is sorted and displayed.
Aardvark
Elephant
Albatross
Alligator
Alpaca
Anaconda
Ant
Anteater
Antelope
Armadillo
@tristanwietsma
tristanwietsma / adaboost.py
Created April 30, 2013 01:13
AdaBoost Python implementation of the AdaBoost (Adaptive Boosting) classification algorithm.
from __future__ import division
from numpy import *
class AdaBoost:
def __init__(self, training_set):
self.training_set = training_set
self.N = len(self.training_set)
self.weights = ones(self.N)/self.N
self.RULES = []
@tristanwietsma
tristanwietsma / batchjobs.py
Created April 30, 2013 01:15
Batch execution Given an list of shell commands, this script batches them out according to user-defined batch size or default CPU count.
import threading, os, sys
from multiprocessing import cpu_count
NUM_CPUS = cpu_count()
def batch_process(command_list, batch_size=NUM_CPUS):
iteratorlock = threading.Lock()
exceptions = []
cmd = command_list.__iter__()
@tristanwietsma
tristanwietsma / eurodollar_exdates.py
Created April 30, 2013 01:26
CME Eurodollar futures expiration date calculator
from datetime import datetime, date, timedelta
def EurodollarExpirations():
start = datetime.now().date()
n = 20
ex = [date(2008,12,15)]
for i in range(120):
x = ex[-1]
x += timedelta(days=91)
if x.day <= 12: x += timedelta(days=7)
@tristanwietsma
tristanwietsma / simplex_algo.py
Created April 30, 2013 01:34
Simplex solver I include an example from Wikipedia page on the topic. This version shows the tableau after each pivot.
from __future__ import division
from numpy import *
class Tableau:
def __init__(self, obj):
self.obj = [1] + obj
self.rows = []
self.cons = []
@tristanwietsma
tristanwietsma / aws-empty-bucket.py
Created April 30, 2013 01:42
AWS S3 administration scripts Some administration scripts for Amazon Web Services' S3 using Boto.
import os, sys
from boto.s3.connection import S3Connection
from boto.s3.bucket import Bucket
AWS_ACCESS_KEY = os.getenv('AWS_ACCESS_KEY')
AWS_SECRET_KEY = os.getenv('AWS_SECRET_KEY')
conn = S3Connection(AWS_ACCESS_KEY, AWS_SECRET_KEY)
bucket_name = sys.argv[1]
@tristanwietsma
tristanwietsma / crypto.py
Created April 30, 2013 01:55
Public-Private key encryption example
import rsa
(pubkey, privkey) = rsa.newkeys(512, poolsize=8)
print pubkey
print privkey
msg = "this is a secret message!"
@tristanwietsma
tristanwietsma / mercsettles.py
Created April 30, 2013 02:15
CME settlement price fetcher Ugly, but effective, script for getting CME settlement prices off their FTP side. Could use a clean up...
import sys, string, urllib
GROUPS = dict([('ags','ftp://ftp.cmegroup.com/pub/settle/stlags'),
('rates','ftp://ftp.cmegroup.com/pub/settle/stlint'),
('fx','ftp://ftp.cmegroup.com/pub/settle/stlcur'),
('nymex','ftp://ftp.cmegroup.com/pub/settle/stlnymex'),
('comex','ftp://ftp.cmegroup.com/settle/stlcomex'),
('clearport','ftp://ftp.cmegroup.com/settle/stlcpc')])
# month codes
@tristanwietsma
tristanwietsma / helloworld.pyx
Created April 30, 2013 02:51
Cython example To compile into a shared library, execute: python setup.py build_ext --inplace
cdef extern from "math.h":
double sin(double)
cdef double f(double x) except *:
return sin(x**2)
def integrate(double a, double b, int N):
cdef int i
cdef double s, dx
s = 0
@tristanwietsma
tristanwietsma / restful.go
Created April 30, 2013 03:16
RESTful service interface example RESTful service example in Go. Parses URI of form "localhost:8080/key'/value" into Redis (publishes <value> to channel <key>).
package main
import (
"fmt"
"github.com/vmihailenco/redis"
"net/http"
"strings"
)
func handler(w http.ResponseWriter, r *http.Request, c *redis.Client) {