Skip to content

Instantly share code, notes, and snippets.

View zachwill's full-sized avatar

Zach Williams zachwill

View GitHub Profile
@zachwill
zachwill / geomean.py
Last active August 29, 2015 14:07
Geometric Mean
"""
Geometric mean calculation in Python.
"""
import math
import operator
from random import randint
from timeit import timeit
@zachwill
zachwill / csv2tsv
Created December 6, 2014 07:54
Turn CSV input into TSV output.
#!/usr/bin/env python
"""
Turn CSV input into TSV output.
"""
import csv, sys
for row in csv.reader(sys.stdin):
print("\t".join(row))
"""
Multiclass SVMs (Crammer-Singer formulation).
A pure Python re-implementation of:
Large-scale Multiclass Support Vector Machine Training via Euclidean Projection onto the Simplex.
Mathieu Blondel, Akinori Fujino, and Naonori Ueda.
ICPR 2014.
http://www.mblondel.org/publications/mblondel-icpr2014.pdf
"""
@zachwill
zachwill / fabfile.py
Created April 8, 2011 23:08
Hello World Examples for the Python fabric framework
#!/usr/bin/env python
from fabric.api import local
def hello(name='world'):
print('\n\n')
print('Hello %s!' % name)
print('\n\n')
def category(request, model, tag):
"""
Given a lowercase model name and tag, search for all models linked to
the given tag. The model is obtained by looking through a dictionary of
available models.
"""
available_models = {'apps': App, 'data': Data, 'ideas': Idea}
try:
actual_model = available_models[model]
except KeyError:
#!/usr/bin/env python
"""Looking up environment variables through `vars`."""
def ohai():
"""A simple function."""
print 'ohai'
class Foo(object):
#!/usr/bin/env python
"""Looking up environment variables through `vars`."""
def ohai():
"""A simple function."""
print 'ohai'
class Foo(object):
"""Just showing off timeit to tell the difference between operations."""
from timeit import Timer
# We'll run each one a thousand times.
print Timer("[0] * 7000").timeit(1000)
print Timer("bytearray(7000)").timeit(1000)
#!/usr/bin/env python
"""For ctbarna."""
list_of_dicts = [
{'key_1': 'value_1', 'key_2': 'value_2'},
{'key_1': {'inception_key': 'inception_value'}, 'key_2': 'value_2'},
{'key_1': 'value_1', 'key_2': 'value_2'},
]
#!/usr/bin/env python
"""For ctbarna."""
list_of_dicts = [
{'key_1': 'value_1', 'key_2': 'value_2'},
{'key_1': {'inception_key': 'inception_value'}, 'key_2': 'value_2'},
{'key_1': 'value_1', 'key_2': 'value_2'},
]