Skip to content

Instantly share code, notes, and snippets.

Avatar
☠️
brilliantly executing terrible plans

JD Long CerebralMastication

☠️
brilliantly executing terrible plans
View GitHub Profile
@CerebralMastication
CerebralMastication / gist:8039120
Created Dec 19, 2013
Example of iman conover
View gist:8039120
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
View dataToMap.txt
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
View problem.R
## 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")
View rpackageinstall.txt
> 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 Jun 22, 2011
convert IP address to integer
View ip2Int.R
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)
View moltendata.dput
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
shell script for starting and logging onto an ec2 instance
View start-logon-ec2.sh
#!/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 Apr 1, 2011
Joshua Ulrich's pivot() function for R
View pivot.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 Mar 22, 2011
pseudo code for Collin
View example.R
# 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 Mar 4, 2011
script for detecting monitors in Ubuntu
View monitorSwitch.sh
#!/bin/sh
#
# Detect displays and move panels to the primary display
#
#15 second pause
sleep 15
PYTHON=python2.6
DISPER=/usr/bin/disper