Skip to content

Instantly share code, notes, and snippets.

View CerebralMastication's full-sized avatar
☠️
brilliantly executing terrible plans

JD Long CerebralMastication

☠️
brilliantly executing terrible plans
View GitHub Profile
@CerebralMastication
CerebralMastication / gist:8039120
Created December 19, 2013 13:31
Example of iman conover
import pandas as pd
## dummy covariance matrix
cov = eye(2) + -.7
fill_diagonal(cov, 1)
# a little bit of non correalted random variates
# also sometimes called the marginal distributions
n = 10000
@CerebralMastication
CerebralMastication / dataToMap.txt
Created August 31, 2012 17:29
example map data
value Latitude Longitude
0.7535 49.3387 -124.3272
0.7332 49.3387 -123.9939
0.3963 49.3387 -123.6606
0.1155 49.3387 -123.3272
0.2775 49.3387 -122.9939
0.3157 49.3387 -122.6606
0.4015 49.3387 -122.3272
0.3987 49.3387 -121.9939
0.7647 49.3387 -121.6606
@CerebralMastication
CerebralMastication / problem.R
Created March 17, 2012 15:36
preschool problem
## read in the training data
## more lines than it should be because of the https requirement in Github
temporaryFile <- tempfile()
download.file("https://raw.github.com/gist/2061284/44a4dc9b304249e7ab3add86bc245b6be64d2cdd/problem.csv",destfile=temporaryFile, method="curl")
series <- read.csv(temporaryFile)
## munge the data to create a frequency table
freqTable <- as.data.frame( t(apply(series[,1:4], 1, function(X) table(c(X, 0:9))-1)) )
names(freqTable) <- c("zero","one","two","three","four","five","six","seven","eight","nine")
> install.packages("sde", lib=libPath)
also installing the dependencies ‘fda’, ‘zoo’
trying URL 'http://cran.r-project.org/src/contrib/fda_2.2.6.tar.gz'
Content type 'application/x-gzip' length 6356938 bytes (6.1 Mb)
opened URL
==================================================
downloaded 6.1 Mb
trying URL 'http://cran.r-project.org/src/contrib/zoo_1.6-5.tar.gz'
@CerebralMastication
CerebralMastication / ip2Int.R
Created June 22, 2011 16:23
convert IP address to integer
ip2Int <- function(ip){
split <- as.numeric(strsplit(ip, "\\.")[[1]])
out <- (split[1] * 256^3) + (split[2] * 256^2) + (split[3] * 256) + (split[4])
return(out)
}
int2Ip <- function(int){
split <- NULL
split[1] <- as.integer(int/256^3)
structure(list(CITY = c("Anqing", "Anqing", "Anqing", "Anqing",
"Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing",
"Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing",
"Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing",
"Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing",
"Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing",
"Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing",
"Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing",
"Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing",
"Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing", "Anqing",
@CerebralMastication
CerebralMastication / start-logon-ec2.sh
Created May 6, 2011 21:03
shell script for starting and logging onto an ec2 instance
#!/bin/bash
secGroup="sg-50681d39"
ami="ami-1aad5273"
keyName="ec2ApiTools"
keyLocation="/home/jal/Documents/AWS/ec2ApiTools_rsa_id"
instance_id=$(ec2-run-instances -k $keyName -g $secGroup -t m1.large $ami | awk '/INSTANCE/{print $2}')
echo $instance_id
@CerebralMastication
CerebralMastication / pivot.R
Created April 1, 2011 14:24
Joshua Ulrich's pivot() function for R
## Joshua Ulrich's pivot function
## This code is alpha and is in development.
## please test all results to ensure accuracy
pivot <- function(x, rows, cols, FUN=NULL) {
clean <- function(xx, dd) {
cd <- merge(dd,xx,by=0,all=TRUE)
rownames(cd) <- cd$Row.names
cd$Row.names <- NULL
return(cd)
@CerebralMastication
CerebralMastication / example.R
Created March 22, 2011 01:22
pseudo code for Collin
# initialize an output data frame
# with the right columns... I'll assume it's called dfOut
for ( i in 1:(nrow(df)) ) {
for ( j in 1:(df$endYear - df$startYear + 1 ) ) {
dfOut[length(dfOut +1), ] <- ## construct a single row data frame here with the write stuff and it will insert into dfOut ##
}
}
@CerebralMastication
CerebralMastication / monitorSwitch.sh
Created March 4, 2011 15:42
script for detecting monitors in Ubuntu
#!/bin/sh
#
# Detect displays and move panels to the primary display
#
#15 second pause
sleep 15
PYTHON=python2.6
DISPER=/usr/bin/disper