Skip to content

Instantly share code, notes, and snippets.

Andrew wabarr

Block or report user

Report or block wabarr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@wabarr
wabarr / backup.sh
Last active Aug 29, 2015
shell script to check if sqlite database has changed, and to email the backup file if so
View backup.sh
#get the current md5sum, and use awk to strip out filename, which is reuturned as well
#note, this assumes that md5sum_of_database_at_last_backup.txt exists and contains the hash of db at last backup
#currently no error checking
currentMD5=$(md5sum test.db | awk '{print $1}')
lastMD5=$(cat /home/user/md5sum_of_database_at_last_backup.txt)
if [ "$currentMD5" == "$lastMD5" ]
then
@wabarr
wabarr / gist:850c230762814ea9b086
Last active Aug 29, 2015
celebratory rainbow
View gist:850c230762814ea9b086
library(plotrix)
cols <- c(rainbow(6),"white")
radii <- seq(from=1, to=0.5, length.out = length(cols))
plot(0,0,ylim=c(0,9), type = "n")
lapply(1:length(cols), FUN=function(index){
draw.circle(0,0,radius=radii[index], col=cols[index])
})
@wabarr
wabarr / timeseries.md
Last active Sep 8, 2015
correlation between two random walk time series, that happen to be trended
View timeseries.md

TimeSeries

Andrew Barr
July 6, 2015

create totally random time series

ts1 <- cumsum(rnorm(1000))
ts2 <- cumsum(rnorm(1000))
@wabarr
wabarr / kmeans.md
Created Sep 19, 2015
testing if kmeans clustering is deterministic or not
View kmeans.md

kmeans testing

Andrew Barr
September 19, 2015

library(ggplot2)

groups <- factor(rep(c("A", "B"), 100))
x <- rnorm(200) 
@wabarr
wabarr / texture.R
Created Nov 12, 2013
code to make an image with nice texture in ggplot
View texture.R
library(ggplot2)
library(reshape2)
n <- 7000
theMean <- 0
theSD <- 5
A <- rbinom(n,1,c(.5,.5)) + rnorm(n,theMean,theSD)
B <- rbinom(n,1,c(.5,.5)) + rnorm(n,theMean,theSD)
C <- rbinom(n,1,c(.5,.5)) + rnorm(n,theMean,theSD)
modelID <- 1:n
@wabarr
wabarr / export_eps.R
Last active Mar 15, 2016
simple function to export a plot to EPS, with possible options
View export_eps.R
## updated with input from @richfitz and @hadley - Thanks, guys!!
export_eps <- function(filename, expression, ...){
old <- setEPS()
on.exit(do.call(ps.options, old), add = TRUE)
postscript(filename, ...)
on.exit(dev.off(), add = TRUE)
expression
}
View subclassDataCollector.py
from mesa.datacollection import DataCollector
class MyDataCollector(DataCollector):
## subclass DataCollector to only collect data on certain agents
## in this case, I only report them if they are NOT alive
## self.alive is an attribute that I track for my agents
def collect(self, model):
""" Collect all the data for the given model object. """
if self.model_reporters:
for var, reporter in self.model_reporters.items():
View factoextra_pca.R
library(factoextra)
PCA <- prcomp(iris[,1:4], scale=T)
fviz(PCA, "var")
fviz(PCA, "ind", repel=T, habillage = iris$Species, label='none')
fviz_ellipses(PCA,habillage = iris$Species, ellipse.type = "convex", geom="point") +
labs(title="mytitle")
View compound_interest.R
compound <- function(start, growthrate_percent, fees_percent, years=15) {
amount <- start
growthrate_proportion <- growthrate_percent/100
fees_proportion <- fees_percent/100
yearly_vals <- rep(NA, years)
for(year in 1:years) {
amount <- amount*(1+growthrate_proportion) - amount*fees_proportion
yearly_vals[year] <- amount
}
plot(x=1:years,y=yearly_vals, pch=16, cex=2, ylab="total value in dollars", xlab="year", main=sprintf("growing at %.3f%% with fees of $%.3f%%\nstarting value: $%.2f\nending value: $%.2f",growthrate_percent, fees_percent,start, amount))
You can’t perform that action at this time.