Skip to content

Instantly share code, notes, and snippets.

View ajschumacher's full-sized avatar

Aaron Schumacher ajschumacher

View GitHub Profile
import random
import math
def mean(elements):
return sum(elements) / len(elements)
def euclidean_dist(first, second):
assert len(first) == len(second)
return sum((f - s)**2 for f, s in zip(first, second))**0.5
@ajschumacher
ajschumacher / code.py
Last active May 26, 2021 19:36
Python 3.7.4 exception hierarchy
# inspired by and based on:
# https://julien.danjou.info/python-exceptions-guide/
# https://github.com/jd/julien.danjou.info/blob/master/bin/generate-python-exceptions-graph.py
import builtins
edges = set()
synonyms = {}
for name in dir(builtins):
item = getattr(builtins, name)

SQL workshop!


Get everything you can about people.

select * from people

-- comments

@ajschumacher
ajschumacher / snippets.md
Created July 18, 2023 18:40
public snippets

chi-squared test

import scipy.stats

obs = np.array([[a, b],
                [c, d]])
_, p, _, _ = scipy.stats.chi2_contingency(obs)
@ajschumacher
ajschumacher / linterp.py
Created May 12, 2026 19:50
Linear interpolation
def linterp(x_1, y_1, x_2, y_2, x_new):
"""Linear interpolation"""
assert min(x_1, x_2) <= x_new <= max(x_1, x_2), 'extrapolation'
factor = (x_new - x_1) / (x_2 - x_1)
y_new = factor * (y_2 - y_1) + y_1
return y_new
assert linterp(0, 0, 2, 2, 1) == 1
assert linterp(-2, -1, 2, 0, -1) == -0.75
assert linterp(1.2, 1.2, 0.8, 0.8, 1) == 1