Skip to content

Instantly share code, notes, and snippets.

View ashander's full-sized avatar

Jaime Ashander ashander

View GitHub Profile
@ashander
ashander / em3_plants.R
Created July 18, 2011 20:44
Abstracted EM applied to plant growth
data(PlantGrowth)
pg<-subset(PlantGrowth,group!='ctrl')
pg$group=factor(pg$group)
pg1= pg[pg$group=='trt1',]
pg2= pg[pg$group=='trt2',]
hist(pg$weight)
lines(density(pg1$weight), col='blue')
lines(density(pg2$weight), col='red')
@ashander
ashander / tufteknitr.Rmd
Created October 22, 2012 19:57
Example of producing Tufte latex from knitr Rmd. Use knit('tufteknitr.Rmd') in R, then mmd2pdf tufteknitr.md at command prompt.
latex input: mmd-tufte-handout-header
Title: Tufte latex from Rmd example
Base Header Level: 2
latex mode: memoir
author: Jaime Ashander
copyright: 2011 Jaime Ashander
This work is licensed under a Creative Commons License.
http://creativecommons.org/licenses/by-nc-sa/3.0/
latex input: mmd-natbib-plain
latex input: mmd-tufte-handout-begin-doc
checking build system type... i386-apple-darwin10.8.0
checking host system type... i386-apple-darwin10.8.0
checking for gcc... gcc-4.2
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables...
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc-4.2 accepts -g... yes

Fisheries landings example

First you'll need to install a few packages if you don't already have them

install.packages(c("plyr", "ggplot2", "rfisheries"))

# Next load up the package
library(rfisheries)
@ashander
ashander / ESAhtmltableexample.R
Created August 26, 2014 20:26
Grabbing data from html tables in ESA-archived data
# get data from html tables in ESA archive
# http://www.esapubs.org/archive/mono/M081/023/suppl-1.htm
library(XML)
root <- 'http://www.esapubs.org/archive/mono/M081/023'
tips <- c('limn.html', 'latitudes.html', 'fish.html', 'acronyms.html')
dat <- lapply(tips, function(t)
readHTMLTable(paste(root, t, sep='/')))
@ashander
ashander / extern-test.R
Last active August 29, 2015 14:07
minimal example for knitr externalization issue
## @knitr my-external-chunk
set.seed(111)
rnorm(100)
@ashander
ashander / get_spdf_gadm.R
Last active August 29, 2015 14:16
Looking at mapping from gadm using gadm2 urls
## urls were updated for gdam2 -- should go to gadm.org to update for each run of this
## http://gadm.org/country
## choose a country and R spdf from dropdown
## eg for
##for AFG sends POST req http://gadm.org/download?OK=OK&_submit_check=1&cnt=AFG_Afghanistan&thm=R%23R%20data
##returns page with list of download links (likely based on your location and data availability)
## part of the page looks like
##
## download
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@ashander
ashander / bin-stuff.r
Created April 15, 2016 22:33
R file for binning stuff. GPL 3.
# placeholder
@ashander
ashander / recover-iterm2-tmux.md
Last active May 5, 2016 19:57
recovering iTerm2 when a process inside a tmux-integrated session lock up and session restoration is enabled
  • kill iterm2 from Activity Monitor
  • open a terminal
  • login to tmux and back up using tmux resurrect or similar
pkill iTerm
ps |grep tmux
kill -9 # for each [pid] correesponding to a `tmux -CC` process, 
 # you could use pkill instead if you got the pattern right?