Skip to content

Instantly share code, notes, and snippets.

View ajschumacher's full-sized avatar

Aaron Schumacher ajschumacher

View GitHub Profile
@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)

SQL workshop!


Get everything you can about people.

select * from people

-- comments

@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)
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 / mspacman.py
Created January 12, 2017 22:27
play Ms. Pacman w/ OpenAI gym
import time
import pygame
import gym
frame_time = 1.0 / 15 # seconds
pygame.init()
import tensorflow as tf
w = tf.Variable([2.0])
b = tf.Variable([2.0])
x = tf.constant([1.0])
y = tf.sigmoid(w*x + b)
y_ = tf.constant([0.0])
cross_entropy = -1*(y_*tf.log(y) + (1-y_)*(tf.log(1-y)))
s = tf.Session()
s.run(tf.initialize_all_variables())
@ajschumacher
ajschumacher / README.md
Last active January 5, 2022 23:30 — forked from mbostock/.block
Interactive D3 view of sklearn decision tree
@ajschumacher
ajschumacher / getch.py
Created May 11, 2015 03:33
get one character at a time at the console with python
def _find_getch():
# courtesy of Louis
# http://stackoverflow.com/questions/510357/
try:
import termios
except ImportError:
# Non-POSIX. Return msvcrt's (Windows') getch.
import msvcrt
return msvcrt.getch
@ajschumacher
ajschumacher / test.rst
Last active January 19, 2017 07:01
github fails to render rst email links properly