Skip to content

Instantly share code, notes, and snippets.

Skipper Seabold jseabold

Block or report user

Report or block jseabold

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@jseabold
jseabold / translate.py
Created Dec 13, 2011
Use Google Translate API from Python
View translate.py
# -*- coding: utf-8 -*-
"""
You need to fill in your API key from google below. Note that querying
supported languages is not implemented.
Language Code
-------- ----
Afrikaans af
Albanian sq
Arabic ar
@jseabold
jseabold / zip_model.py
Last active Mar 6, 2019
Zero-Inflated Poisson Estimation
View zip_model.py
import numpy as np
from scipy import special, stats
from statsmodels.base.model import GenericLikelihoodModel
def vuong_test(p1, p2):
r"""
Vuong-test for non-nested models.
Parameters
----------
View tufte.py
import os
import calendar
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FixedLocator, FixedFormatter
import pandas as pd
import seaborn as sns
to_colors = lambda x : x/255.
@jseabold
jseabold / spot_pricing.py
Created Aug 11, 2015
Plot EC2 spot pricing with boto3 and pandas
View spot_pricing.py
import pandas as pd
from boto3 import client
client = client(service_name='ec2')
prices = client.describe_spot_price_history(InstanceTypes=["m3.medium"],
AvailabilityZone="us-east-1a")
df = pd.DataFrame(prices['SpotPriceHistory'])
df.set_index("Timestamp", inplace=True)
df["SpotPrice"] = df.SpotPrice.astype(float)
@jseabold
jseabold / spirals.py
Created Jan 30, 2013
draw a spiral in matplotlib
View spirals.py
import numpy as np
import matplotlib.pyplot as plt
#As a path collection
from matplotlib.collections import LineCollection
fig, ax = plt.subplots()
r = np.arange(0, .075, 0.00001)
nverts = len(r)
@jseabold
jseabold / skyrim_table.py
Last active Jun 14, 2018
Read an HTML table using pandas
View skyrim_table.py
# you can use something like this if read_html fails to find a table
# if you have bs4 >= 4.2.1, you can skip the lxml stuff, the tables
# are scraped automatically. 4.2.0 won't work.
import pandas as pd
from lxml import html
url = "http://www.uesp.net/wiki/Skyrim:No_Stone_Unturned"
xpath = "//*[@id=\"mw-content-text\"]/table[3]"
@jseabold
jseabold / cox_model.py
Last active Jun 11, 2018
Try to replicate BUGS code with PyMC for Table 3, Column 1 of "Bayesian Spatial Survival Models for Political Event Processes."
View cox_model.py
from pymc import Gamma, Poisson, Normal, MCMC, deterministic
import numpy as np
dta = dict(T=73, Nsubj=430, eps=0.0, t=[1, 21, 85, 128, 129, 148, 178, 204,
206, 210, 211, 212, 225, 238, 241,
248, 259, 273, 275, 281, 286, 289,
301, 302, 303, 304, 313, 317, 323,
344, 345, 349, 350, 351, 355, 356,
359, 364, 385, 386, 389, 390, 391,
392, 394, 395, 396, 397, 398, 399,
@jseabold
jseabold / wide_to_long.py
Created Sep 21, 2013
Go from wide format panel data to long format. Similar to Stata's reshape.
View wide_to_long.py
def wide_to_long(df, stubnames, i, j):
"""
User-friendly wide panel to long format.
Parameters
----------
df : DataFrame
The wide-format DataFrame
stubnames : list
A list of stub names. The wide format variables are assumed to
@jseabold
jseabold / docker_manifest.py
Created Sep 9, 2017
Some functions for dealing with docker registry manifests
View docker_manifest.py
import urllib
import docker
def get_manifest_auth_token(repo):
# https://docs.docker.com/registry/spec/auth/token/
query = urllib.parse.urlencode({
'service': 'registry.docker.io',
'scope': 'repository:{repo}:pull'.format(repo=repo)
@jseabold
jseabold / git_find_big.py
Created Sep 27, 2015
git filter-branch magic using Python
View git_find_big.py
#! /usr/bin/env python
import glob
import os
import shutil
import re
from collections import namedtuple
import subprocess
from subprocess import PIPE
You can’t perform that action at this time.