Skip to content

Instantly share code, notes, and snippets.

View Protonk's full-sized avatar
🗯️
Après moi, la brisure

Adam Hyland Protonk

🗯️
Après moi, la brisure
View GitHub Profile
@Protonk
Protonk / GDPcorr.R
Created May 6, 2011 20:02
GDP cross country correlation
#Long list of packages here. WDI is used to pull the data down,
#plyr and reshape are used for melt/cast and ddply
#tseries is used for the ADF test and could be excluded if you
#weren't interest in that. ggplot2 is used to bring in
#rescale() but that could be done by hand if you wanted.
#maps and geosphere are used for the great circle plotting
library(WDI)
library(plyr)
library(reshape)
@Protonk
Protonk / Coffee.R
Created May 13, 2011 23:37
Nerding out over french presses
#Data recorded from a full french press at five minute intervals. Temperatures are in
#Farenheit.
french<- structure(list(Time = c(0L, 5L, 10L, 15L, 20L, 25L, 30L, 35L,
40L, 45L, 50L, 55L, 60L, 65L, 70L, 75L, 80L, 85L, 90L, 95L),
Temp = c(201.4, 195.7, 192.1, 188.9, 185.6, 181.8, 180.1,
177.3, 174.8, 172.4, 169.8, 167.6, 165.2, 163.2, 161, 159,
156.8, 154.7, 152.9, 151.1)), .Names = c("Time", "Temp"), class = "data.frame", row.names = c(NA, -20L))
#Add another column for Kelvin
french$kelvin<- (french$Temp + 459.67)*5/9
@Protonk
Protonk / Naughty.R
Created July 5, 2011 03:12
Absolute worst code ever do not copy please god no
pop.hard<- function(endpoints) {
wrap.unif<- runif(endpoints, 0, 4)
pos.unif<- cut(wrap.unif, breaks=0:4,labels=FALSE)
for (i in 1:4) {
wrap.unif[which(pos.unif == i, arr.ind=TRUE)]<- wrap.unif[which(pos.unif == i, arr.ind=TRUE)] - (i - 1)
}
outer.unif<- matrix(0, endpoints, 2)
outer.unif[which(pos.unif == 1, arr.ind=TRUE),]<- cbind(0, wrap.unif[which(pos.unif == 1, arr.ind=TRUE)])
outer.unif[which(pos.unif == 2, arr.ind=TRUE),]<- cbind(wrap.unif[which(pos.unif == 2, arr.ind=TRUE)], 1)
outer.unif[which(pos.unif == 3, arr.ind=TRUE),]<- cbind(1, wrap.unif[which(pos.unif == 3, arr.ind=TRUE)])
@Protonk
Protonk / Housing trust.R
Created December 15, 2011 00:58
State housing trust funding map
library(ggplot2)
library(datasets)
# List of states comes from http://housingtrustfundproject.org/wp-content/uploads/2011/10/2007-Housing-Trust-Fund-Progress-Report-2.pdf
no.prog<- c("Alaska", "North Dakota", "South Dakota", "Wyoming", "Mississippi", "Alabama", "Virginia", "Pennsylvania", "New York")
no.fund<- c("California", "Idaho", "Arkansas", "Rhode Island")
funding.df<- as.data.frame(cbind(tolower(state.name), "Funded"), stringsAsFactors = FALSE)
names(funding.df)<- c("region", "status")
funding.df[, 2]<- factor(funding.df[, 2], levels= c("Funded", "Unfunded", "No Program"), ordered = TRUE)
funding.df[state.name %in% no.fund , 2]<- "Unfunded"
@Protonk
Protonk / countychoro.R
Created December 20, 2011 00:45
Letterbox choropleth mapping
require(ggplot2);
require(plyr);
require(stringr);
require(maps);
options(stringsAsFactors = FALSE)
##Map plotting
statesline <- data.frame(map("state", plot=FALSE)[c("x","y")])
usamap <- qplot(x, y, data=statesline, geom="path")
@Protonk
Protonk / EAS Choro.R
Created December 20, 2011 06:29
Essential Air Service Choropleth plot
library(ggplot2)
library(maps)
#Datasets lets me do state borders. I could just use map_data("state") but I didn't
library(datasets)
#Obviously this was originally a 2 column csv. I used dput() here so that someone could
#recreate this easily.
EAS.df<- structure(list(subregion = structure(c(3L, 12L, 10L, 5L, 18L,
47L, 76L, 66L, 32L, 73L, 15L, 35L, 52L, 28L, 48L, 25L, 70L, 30L,
@Protonk
Protonk / getimgur.R
Created January 28, 2012 16:23
deprecated script, see updated repo
# Smarter, updated version available at
#
# https://github.com/Protonk/Image-Grab
#
#
@Protonk
Protonk / SWpvals.R
Created February 12, 2012 06:49
Simulated "Estimated" CDF for SW p=values
# Intent was to use shapiro.test() to recreate fig. 4 in
# Shapiro, S. S.; Wilk, M. B. (1965). "An analysis of variance test for normality (complete samples)". Biometrika 52 (3-4): 591–611
plotPvalues <- function() {
l.norm <- rnorm(5000)
shap.n <- function(n) {
replicate(2000, unlist(shapiro.test(sample(l.norm, n, replace = TRUE))[c(1,2)]))
}
shap.l <- mapply(shap.n, seq(5, 50, 5), SIMPLIFY = FALSE)
plot(seq(0,1,length.out = 10), seq(0.7, 1, length.out = 10), type = "n",
@Protonk
Protonk / AZmap.R
Created February 23, 2012 04:10
Generate AZ map data
# If you don't have ggplot
# run:
# install.packages("ggplot2")
# first
library(maps)
library(ggplot2)
AZmap <- map_data("county", "arizona")
@Protonk
Protonk / MC33887.C
Created February 24, 2012 20:07
Code to drive Freescale Semiconductor MC33887 motor driver with Arduino
/* Code to drive Freescale Semiconductor MC33887 motor driver with Arduino
This example code is in the public domain.
Written by Mike Gilsdorf
*/
void setup() {
Serial.begin(9600);
pinMode(2,INPUT); //sw1