Skip to content

Instantly share code, notes, and snippets.

View jseabold's full-sized avatar

Skipper Seabold jseabold

View GitHub Profile
@jseabold
jseabold / p096_sudoku.txt
Created May 28, 2024 13:36
Project Euler Sudoku Puzzles
Grid 01
003020600
900305001
001806400
008102900
700000008
006708200
002609500
800203009
005010300
import re
import numpy as np
box_slices = {
0: slice(0, 3),
1: slice(0, 3),
2: slice(0, 3),
}
@jseabold
jseabold / sudoku.py
Created May 21, 2024 19:16
Sudoku solver using integer programming
import numpy as np
from scipy import optimize, sparse
board_coords = np.array([
[0, 1, 2],
[0, 4, 3],
[0, 7, 4],
[1, 0, 6],
[1, 8, 3],
[2, 2, 4],
@jseabold
jseabold / inter_rater.py
Last active May 8, 2024 21:22
Simulate Inter-Rater Agreement
import numpy as np
import pandas as pd
from scipy import stats
from statsmodels.stats import inter_rater
def fleiss_standard_error(table):
# not included in statsmodels
# only returns overall kappa value
@jseabold
jseabold / Difference_in_Differences_Differences.ipynb
Last active March 14, 2021 18:13
Working out some differences between R and Python for Causal Inference: The Mixtape
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
"""
This took me a while to figure out so posting for posterity.
plt.interactive(False) is important, if you want the grid to only show up
when `display`ed. Since `sns.FacetGrid` can take a few seconds depending
on the size of your data, this displays a spinner in the notebook cell
until the new graph is ready to render.
"""
import matplotlib.pyplot as plt
@jseabold
jseabold / docker_manifest.py
Created September 9, 2017 17:34
Some functions for dealing with docker registry manifests
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 / binary_rng.py
Created September 27, 2016 20:13
Create correlated binary variables. Based on Leisch, Weingessel, and Hornik (1998).
"""
Heavily inspired by the R package bindata.
"""
import numpy as np
from scipy import interpolate
from scipy import stats
def corr_to_joint(corr, marginals):
"""
@jseabold
jseabold / git_find_big.py
Created September 27, 2015 16:49
git filter-branch magic using Python
#! /usr/bin/env python
import glob
import os
import shutil
import re
from collections import namedtuple
import subprocess
from subprocess import PIPE
@jseabold
jseabold / spot_pricing.py
Created August 11, 2015 14:33
Plot EC2 spot pricing with boto3 and pandas
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)