Skip to content

Instantly share code, notes, and snippets.

View robbrit's full-sized avatar
🏠
Working from home

Rob robbrit

🏠
Working from home
View GitHub Profile

Keybase proof

I hereby claim:

  • I am robbrit on github.
  • I am robbrit (https://keybase.io/robbrit) on keybase.
  • I have a public key ASCUVTrohgtc4kUEs-wThDE7PkxLcrnt1qnm7CoNCoNj5wo

To claim this, I am signing this object:

@robbrit
robbrit / gist:2912334
Created June 11, 2012 20:06
Javascript Julia set generation
<canvas id = "cvs"></canvas>
<script>
/**
* HSV to RGB color conversion
*
* H runs from 0 to 360 degrees
* S and V run from 0 to 100
*
* Ported from the excellent java algorithm by Eugene Vishnevsky at:
$ ->
c = $("canvas").get(0)
ctx = c.getContext "2d"
#ctx.font="20px sans-serif"
#mainLoop
#running
initial_sleep_length=250
sleep_length=initial_sleep_length
img_data_for_player=ctx.createImageData c.width,c.height
tile_size=25
@robbrit
robbrit / gist:1838428
Created February 15, 2012 19:45
Fractal series
function rnorm(mean, sd){
if (mean === undefined){
mean = 0;
}
if (sd === undefined){
sd = 1;
}
do {
var x1 = 2.0 * Math.random() - 1.0;
@robbrit
robbrit / gist:1579753
Created January 8, 2012 21:25
Cointegration Finder
# calculates the best vector of cointegration for a group of series.
#
# @param series A matrix with the series in columns
#
# @return The best vector of cointegration.
#
get_coint = function(series){
# does this by performing a regression of time on
# a linear combination of the series, but only take
# the slope parameter
@robbrit
robbrit / gist:1530380
Created December 28, 2011 23:21
World oil production/consumption
# oil production per day by country
production = read.csv("production.csv", header = T)
# proven oil reserves by country
reserves = read.csv("reserves.csv", header = T)
# oil consumption by country
consumption = read.csv("consumption.csv", header = T)
# the total amount of oil production per year
total_production = sum(production$Production) * 365
@robbrit
robbrit / gist:1522394
Created December 27, 2011 01:14
Canadian Oil Production
oil = read.csv("oil.csv", header = T)
# convert cubic metres to barrels
total = ts(oil$Total * 6.28981077 / 1000, start = 1971, end = 2010)
t = 1:length(total)
linear = lm(total ~ t)
expn = lm(log(total) ~ t)
# do a linear model
[1] "Average wages for degree in education:"
[1] "Confidence for 1986: 45951.512708 to 47462.916536"
[1] "Confidence for 2006: 48453.487226 to 49640.726011"
[1] "Standard Deviation for 1986: 28759.942381"
[1] "Standard Deviation for 2006: 37696.910023"
[1] "Median Confidence for 1986: 49299.946203 to 51002.542615"
[1] "Median Confidence for 2006: 47308.440547 to 48645.865039"
[1] ""
[1] "Average wages for degree in fine arts:"
[1] "Confidence for 1986: 30804.704353 to 34896.729876"
data2006 <- read.csv("census2006.csv", header = TRUE)
data1986 <- read.csv("census1986.csv", header = TRUE)
# Get the CPI for 1986, 2006, and 2010
cpi2006 <- 1.091
cpi1986 <- 0.656
cpi2010 <- 1.165
calc_avg <- function(w1986, w2006, message, png_file){
# scale by CPIs to give 2010 dollars
data2006 <- read.csv("census2006.csv", header = TRUE)
data1986 <- read.csv("census1986.csv", header = TRUE)
# Get the CPI for 1986, 2006, and 2010
cpi2006 <- 1.091
cpi1986 <- 0.656
cpi2010 <- 1.165
calc_avg <- function(w1986, w2006, message, png_file){
# scale by CPIs to give 2010 dollars