Skip to content

Instantly share code, notes, and snippets.

View sneakers-the-rat's full-sized avatar

Jonny Saunders sneakers-the-rat

View GitHub Profile
@sneakers-the-rat
sneakers-the-rat / insurance_swindle.py
Created October 6, 2019 04:42
UO's 'marginal' health insurance proposal
# modeling this ridiculous healthcare proposal
import numpy as np
import matplotlib.pyplot as plt
def healthcare(steps=11, initial_cost=2500000., mean_increase=6., sd_increase=2.):
# stash initial values
cost = initial_cost
uo_cost = cost*0.95
increase_pct = 0.
@sneakers-the-rat
sneakers-the-rat / heart_on_yr_sleeve.R
Created July 17, 2019 21:11
google sheets for classroom surveys
library(googlesheets)
library(tidyverse)
# get spreadsheet key
#sheet_key <- extract_key_from_url("https://docs.google.com/spreadsheets/d/e/2PACX-1vRyiiW8T0JFOnycEhQM6WaoUgcA_5xpO5xe-x0ifhI38XfmOpAuUvbtMCw8Lg6CuX5W--wbh0XFk9KU/pubhtml")
# stash so it dont crash during class
sheet_key <- "1TbkdZ_FSdf-PBqPwNBFcEVCANVgb1xgXv70GhqjmWrk"
# download sheet
emotions_raw <- gs_key(sheet_key) %>% gs_read()
@sneakers-the-rat
sneakers-the-rat / fanfiction.py
Created May 6, 2019 09:02
scraping fanfiction.com
import requests
from bs4 import BeautifulSoup as bs
from tqdm import tqdm
import json
import os
import tables
import numpy as np
import pdb
import traceback
@sneakers-the-rat
sneakers-the-rat / schill.json
Last active April 11, 2019 20:17
schill corpus
[
"Dear Colleagues, Universities today face headwinds from a multitude of sources. In the political sphere, one party castigates us for being ideologically unbalanced and intolerant of free speech and the other for being unaffordable and elitist. Trust in universities is battered by a deluge of criticism and well-publicized scandals involving sexual violence, administrative misfeasance, and admissions improprieties. Political support has diminished with public trust. Many public universities, including the University of Oregon, never recovered from the 2008 recession in terms of state funding. Underfunded pension plans, skyrocketing health-care costs, and skepticism about our mission and operation have created tremendous pressure on our twin missions of education and research. Despite these challenges, I am incredibly optimistic about the future of higher education, generally, and at the University of Oregon, in particular. I know some of you will read this, roll your eyes, and think to yourself, \u201cHe g
@sneakers-the-rat
sneakers-the-rat / nesting_sim.R
Last active March 21, 2019 07:36
t-tests make high density neuroscience proposterously error prone
library(psych)
library(ggplot2)
library(plyr)
library(lme4)
library(lmerTest)
n_sims <- 1000
sims <- expand.grid(
i_sim = seq(n_sims),
@sneakers-the-rat
sneakers-the-rat / ucf_olympics.R
Created February 19, 2019 05:24
cleaning up a whitespace delimited table
library(rvest)
library(dplyr)
library(stringr)
m200 <- read_html("http://www.alltime-athletics.com/m_100ok.htm")
m2_table <- m200 %>%
html_nodes("body > center:nth-child(8) > pre")
# make list of rows, split by newline character
@sneakers-the-rat
sneakers-the-rat / python_peacocks.icls
Created January 4, 2019 03:30
there are many color schemes but i like this one
<scheme name="Peacocks In Space Contrast (rainglow)" version="142" parent_scheme="Darcula">
<option name="FONT_SCALE" value="1.0" />
<metaInfo>
<property name="created">2019-01-03T19:28:35</property>
<property name="ide">PyCharmCore</property>
<property name="ideVersion">2018.2.0.0</property>
<property name="modified">2019-01-03T19:28:43</property>
<property name="originalScheme">_@user_Peacocks In Space Contrast (rainglow)</property>
</metaInfo>
<option name="LINE_SPACING" value="1.4" />
@sneakers-the-rat
sneakers-the-rat / elliot_pupil.py
Created September 27, 2018 05:45
play/render elliot's pupil fit
# renamed files to 'vid.avi' and 'points.csv'
# deleted first row of points.csv
# call this and use -p 'y'/'n', -r 'y'/'n' to control playing and rendering the video
# or do ./elliot_pupil.py --help
# you could comment out the skvideo and tqdm imports and objects if ya don't want to install/render.
import cv2
import pandas as pd
import numpy as np
@sneakers-the-rat
sneakers-the-rat / job_tl.R
Created August 8, 2018 23:18
timeline resume plot for aakash
library(ggplot2)
jobs <- data.frame(start=c(2000, 2006, 2008, 2009, 2014),
end =c(2005, 2009, 2010, 2015, 2015),
idx = rev(seq(5)),
name =as.ordered(c("job a", 'job b', 'job c', 'job d', 'job e')))
g.job <- ggplot(jobs)+
geom_rect(aes(xmin=start, xmax=end, ymin=idx, ymax=idx+1, fill=name))+
scale_fill_grey(start=0, end=0.8)+
@sneakers-the-rat
sneakers-the-rat / prasad_linefit.py
Created March 22, 2018 02:40
Python implementation of Prasad DK, et al.'s parameter-independent line-fitting method
# a more or less line-for-line transcription of the source available here:
# https://docs.google.com/open?id=0B10RxHxW3I92dG9SU0pNMV84alk
# which is described in this paper:
# http://ieeexplore.ieee.org/document/6166585/
# D. K. Prasad, C. Quek, M. K. H. Leung and S. Y. Cho, "A parameter independent line fitting method," The First Asian Conference on Pattern Recognition, Beijing, 2011, pp. 441-445.
# doi: 10.1109/ACPR.2011.6166585
#
#
# Operation is pretty simple, just pass an **ordered** Nx2 array of x/y coordinates, get line segments.
# A convenience ordering function is provided free of charge ;)