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 / 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 / mongo_import.sh
Created November 17, 2012 09:36
import csv into mongodb from command line
#!/usr/bin/bash
## include --upsert if adding to a prexistitng collection
mongoimport -d db_name -c coll_name --type csv --file file.csv --headerline
@abelsonlive
abelsonlive / cbind.fill.R
Created November 19, 2012 18:12
cbind.fill.R
# yay!
cbind.fill<-function(...){
nm <- list(...)
nm<-lapply(nm, as.matrix)
n <- max(sapply(nm, nrow))
do.call(cbind, lapply(nm, function (x)
rbind(x, matrix(, n-nrow(x), ncol(x)))))
}
@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")