Skip to content

Instantly share code, notes, and snippets.

View abelsonlive's full-sized avatar
🕳️
[ o o ]

Brian Abelson abelsonlive

🕳️
[ o o ]
View GitHub Profile
@abelsonlive
abelsonlive / r_install.sh
Created October 4, 2012 15:04 — forked from seeRead/r_install.sh
r init file
#/bin/bash
# run chmod +x THIS_GIST.sh
# configure for debian or ubuntu! debian has dependencies that ubuntu's libs will conflict with
# sources:
# http://cran.r-project.org/bin/linux/debian/
# http://cran.r-project.org/bin/linux/ubuntu/README
# http://stackoverflow.com/questions/10255082/installing-r-from-cran-ubuntu-repository-no-public-key-error
clear
@abelsonlive
abelsonlive / raster_scatter.R
Created October 16, 2012 22:10 — forked from dsparks/raster_scatter.R
Drawing a scatter plot of raster images
# Drawing a scatter plot of raster images
doInstall <- TRUE # Change to FALSE if you don't want packages installed.
toInstall <- c("png", "devtools", "MASS", "RCurl")
if(doInstall){install.packages(toInstall, repos = "http://cran.r-project.org")}
lapply(toInstall, library, character.only = TRUE)
# Some helper functions, lineFinder and makeTable
source_gist("818983")
source_gist("818986")
@abelsonlive
abelsonlive / classify_sentiment.R
Created October 17, 2012 15:42
classify_sentiment.R
classify_sentiment <- function(text){
# install required pacakges
if (!require(sentiment)) {
install.packages('sentiment')
library('sentiment')
}
if (!require(Rstem)) {
install.packages('Rstem', repos = 'http://www.omegahat.org/R', type='source')
library('Rstem')
}
@abelsonlive
abelsonlive / Makefile
Created October 25, 2012 23:16 — forked from even4void/Makefile
A sample demo of R Markdown with pandoc
RMDFILE=demo-rmd-pandoc
PANDOC=~/.cabal/bin/pandoc
all:
Rscript -e "require(knitr); require(markdown); knit('$(RMDFILE).rmd', '$(RMDFILE).md'); purl('$(RMDFILE).rmd')"
${PANDOC} --mathjax --toc -B header.html -A footer.html --bibliography refs.bib --css markdown.css -s $(RMDFILE).md -o $(RMDFILE).html
@abelsonlive
abelsonlive / file_three.rb
Created October 26, 2012 20:11 — forked from maliabadi/file_three.rb
requiring gems
# this feels weird, but there's some magic here. Ruby knows where 'rubygems' is without you having to explain it with an exact path.
require 'rubygems'
# now you can you just flat-out require ANY gem you have installed! like
require 'pony'
# all of the sudden you have this really cool ruby library called 'pony' in your application's object space! And you can do shit like this:
Pony.mail({
:to => 'matt@cutt.com',
@abelsonlive
abelsonlive / assignColors.R
Created November 2, 2012 17:32
assignColors.R
# this function takes an input numeric vector and
# partitions it into a set number of breaks
# it then assigns a color to each break via RColorBrewer
assignColors <- function(var,
n = 9, # number of colors / breaks
style = "jenks", # can be changed to other methods in "classIntervals"
pal = "RdYlBu", # Palettes from RColorBrewer
na_color ='#787878', # Color to give NA's
na_omit = FALSE, # Logical, argument above will be irrelevant if TRUE
@abelsonlive
abelsonlive / gist:4029650
Created November 7, 2012 05:05
helpful regex
'<meta property=\"og:url\" content=\"(http://www.kickstarter.com/projects/[0-9a-zA-Z-]+/[a-z0-9-]+)'
@abelsonlive
abelsonlive / tryRRR.R
Created November 16, 2012 05:06
tryRRR.R
tryRRR <-
function (
expr,
ARRR = TRUE,
lang = 'sp',
time = 10
)
{
setwd(getwd())
require("lubridate")
@abelsonlive
abelsonlive / gist:4090899
Created November 16, 2012 21:04 — forked from brianboyer/gist:1696819
Lion dev environment notes
@abelsonlive
abelsonlive / scrapeply.R
Created November 20, 2012 03:47
scrape with llply, avoiding errors
# scrape with llply, handling errors
output <- llply(urls, function(url) {
out <- try(scrapeCast(url), TRUE)
if (class(out)=='try-error') {
out <- NULL
print(paste("error scraping" url))
} else {
return(out)
}
}, .progress="text")