Skip to content

Instantly share code, notes, and snippets.

View zachwill's full-sized avatar

Zach Williams zachwill

View GitHub Profile
@zachwill
zachwill / wilson.py
Created October 13, 2016 22:17
Wilson Score Interval
from math import sqrt
def confidence(ups, downs):
"""
Wilson Score Interval: http://stackoverflow.com/questions/10029588
"""
n = ups + downs
if n == 0:
return 0
@zachwill
zachwill / _.md
Created September 26, 2016 16:20

Portland iPhone 7+ Scraper with Slack

A simple scraper that sends a message on Slack when iPhones are available in Portland.

The default channel on Slack I used was #technology, but feel free to change that.

I put the iphone.txt template in a templates directory, too.

@zachwill
zachwill / items.py
Last active September 18, 2023 09:28
An easier way to meld Peewee models and Scrapy items.
import copy
from scrapy import Item
class ModelItem(Item):
"""
Make Peewee models easily turn into Scrapy Items.
>>> from models import Player
>>> item = ModelItem(Player())
"""
@zachwill
zachwill / 538_colors.py
Created October 10, 2015 21:20
A simple FiveThirtyEight palette for Seaborn plots.
"""
A simple FiveThirtyEight palette for Seaborn plots.
"""
import seaborn as sns
import matplotlib.pyplot as plt
five_thirty_eight = [
"#30a2da",
"#fc4f30",
"""
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 / 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))
@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
" Vim color file
" Converted from Textmate theme Monokai using Coloration v0.3.2 (http://github.com/sickill/coloration)
set background=dark
highlight clear
if exists("syntax_on")
syntax reset
endif
import requests as req
response = req.get("http://api.stlouisfed.org/fred/releases?api_key=CHYEA")
print response.content
@zachwill
zachwill / observations.py
Created March 23, 2013 23:16
FRED API observations
import fred
fred.key('my_fred_key')
data = fred.observations('AAA', limit=10, frequency='q', units='ch1')
for obs in data['observations']['observation']:
print obs['value']