Skip to content

Instantly share code, notes, and snippets.

View thoolihan's full-sized avatar

Tim Hoolihan thoolihan

View GitHub Profile
@thoolihan
thoolihan / binary_plot.R
Created November 13, 2014 20:59
Plot Binary Values
bits <- 1:8
n <- 2 ^ bits
plot(n ~ bits, type = "b")
@thoolihan
thoolihan / AverageLine13.pig
Last active August 29, 2015 14:10
Average Line in 2013 NFL Games
-- analyze data from http://www.repole.com/sun4cast/data.html
raw_records = LOAD '/data/nfl/nfl2013lines.csv' USING PigStorage(',');
records = STREAM raw_records THROUGH `tail -n +2` AS
(Date, Visitor, VisitorScore:int,
HomeTeam, HomeScore:int, Line:float, TotalLine:float);
all_games = GROUP records ALL;
data = FOREACH all_games
GENERATE AVG(records.VisitorScore) as Visitor, AVG(records.HomeScore) as Home, AVG(records.Line) as Spread;
data2 = FOREACH data
GENERATE data.Home - data.Visitor as diff, data.Visitor, data.Home, data.Spread;
@thoolihan
thoolihan / Gaussian.R
Last active August 29, 2015 14:10
Gaussian (Bell Curve of Grades Example)
library(ggplot2)
set.seed(0.6)
grades <- rnorm(1500, mean = 75, sd = 12)
prob <- dnorm(grades, mean = 75, sd = 12)
below60 <- seq(from = min(grades), to = 60, by = .1)
below60d <- data.frame(x = below60, y = dnorm(below60, mean = 75, sd = 12))
below60p <- rbind(c(min(grades), 0),
below60d,
@thoolihan
thoolihan / es_test.html
Created November 25, 2014 15:03
Web Page to test Elasticsearch CORS Config
<!DOCTYPE html>
<html>
<head>
<title>Test ElasticSearch</title>
</head>
<body>
<h1>Response to /_nodes</h1>
<p id="results"></p>
</body>
<script src="https://code.jquery.com/jquery-2.1.1.js"></script>
@thoolihan
thoolihan / matrix.R
Last active August 29, 2015 14:10
Matrix Multiplication of DataFrame
df <- data.frame(a = rep(1,100), b = rep(2, 100), c = rep(3, 100))
m1 <- as.matrix(df)
m2 <- matrix(data = rep(1,3), nrow = 3)
res <- m1 %*% m2
@thoolihan
thoolihan / session.txt
Created December 11, 2014 16:23
select example
R> library(dplyr)
R> d <- data.frame(a=c(1,2,3), b=c(4,5,6))
R> select(d, -a)
b
1 4
2 5
3 6
R>
@thoolihan
thoolihan / Rakefile
Created March 20, 2015 20:47
Update a bunch of git repositories in the current directory
subs = Dir.new(".").select{|f| File.directory? f}
git_directories = subs.select{|d| Dir.exist? "#{d}/.git" }
task :update do
git_directories.each do |src_directory|
Dir.chdir(src_directory) do
sh "git pull origin master"
end
end
end
@thoolihan
thoolihan / PrimeChecker.R
Last active September 13, 2015 13:59
Prime Checker in R
PrimeChecker.primes <- numeric()
PrimeChecker.nonPrimes <- numeric()
PrimeChecker.isPrime <- function(x) {
if(x < 2 || x %in% PrimeChecker.nonPrimes) {
return(FALSE)
}
if(x %in% PrimeChecker.primes) {
return(TRUE)
}
@thoolihan
thoolihan / Rakefile
Created January 20, 2012 14:47
Sample Rakefile for .Net build
namespace :build do
build_configs = ["Debug", "Release"]
desc "build debug"
task "debug" do
sh build_cmd()
end
desc "build release"
task "release" do
@thoolihan
thoolihan / Rakefile
Last active September 30, 2015 00:33
Image Sizing
skus = Dir.glob("*.jpg").collect do |file|
file.sub(".jpg","")
end
output = "final"
task :medium_images do
puts "creating medium images 250px wide..."
skus.each do |sku|
sh "convert #{sku}.jpg -strip -resize 250 -quality 100 #{output}/#{sku}_table.jpg"