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 / artist-frequency-raster.R
Created March 16, 2017 09:52
artist-frequency-raster
require(stats)
require(ggplot2)
# Download your last.fm history as a .csv from here:
# https://benjaminbenben.com/lastfm-to-csv/
# load 'em
lfmdat <- read.csv('~/lastfm.csv', header = FALSE)
names(lfmdat) <- c("artist", "album", "song", "time")
@sneakers-the-rat
sneakers-the-rat / load_model_fixes.py
Created April 4, 2017 01:54
fix load_model() in keras
## in model.load_model:
# add import
from .utils.io_utils import ask_to_proceed_with_overwrite, update_config
# At 225 add a version check and call an updating function
model_config = json.loads(model_config.decode('utf-8'))
k_version = float(f.attrs.get('keras_version')[0])
if k_version < 2:
# Have to rename params to load old models
@sneakers-the-rat
sneakers-the-rat / olympics_clean.py
Created March 5, 2018 09:50
multiprocessing cleaning ops
import os
import pandas as pd
import numpy as np
from itertools import cycle
from tqdm import tqdm
from multiprocessing import Pool
import time
def concat_sport(sport, i):
sport_files = [s for s in files if s.startswith(sport)]
@sneakers-the-rat
sneakers-the-rat / order_edges.py
Last active March 21, 2018 23:45
reorder x/y edge coordinates
# this should let ya surf the line.
# take edge coordinates (1 px thick) and reorder
# so first-last goes from one end of the line to the other
import numpy as np
from skimage import morphology
from scipy.spatial import distance
from collections import deque as dq
def order_edges(edges):
@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 ;)
@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 / 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 / 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 / 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 / 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),