Skip to content

Instantly share code, notes, and snippets.

@dill
dill / columb.R
Created August 5, 2016 03:33
Is Columus, OH the only place in the US where 1/2 the population is within 500 miles? Well, kinda
# is Columbus, OH really the only place in the US where you're within
# 500 miles of half of the US population?
# claim: https://448f59f74df57015bbb8-a9447b7dfa4ae38e337b359963d557c4.ssl.cf3.rackcdn.com/9987%20Brewdog%20EFP%20Prospectus%20USA%20A4%20v9.pdf
# "Columbus is within 500 miles of over half of the US population"
# get the US 2010 census data
# http://www2.census.gov/geo/docs/reference/cenpop2010/county/CenPop2010_Mean_CO.txt
cent <- read.csv("CenPop2010_Mean_CO.txt")
@dill
dill / example.R
Created February 20, 2016 20:23
display R plots in iTerm2
library(ggplot2)
library(emoGG)
source("imgcat.R")
p <- ggplot(iris, aes(Sepal.Length, Sepal.Width, color = Species)) + geom_emoji(emoji="1f337")
imgcat(print(p))
@dill
dill / uncertainty-anim.R
Last active February 23, 2017 16:55
Animations of uncertainty in density maps
# little animation to illustrate uncertainty in a density map
library(dsm)
library(mvtnorm)
library(ggplot2)
library(animation)
library(viridis)
# load the models and prediction data
# using data from the Duke spatial distance sampling course
@dill
dill / venn.R
Created January 18, 2016 21:09
Scrabble/US states/chemical elements
# overlap of:
# - US state 2 letter codes from state.abb in R
# - 2-letter Scrabble words https://en.wiktionary.org/wiki/Appendix:Official_English_Scrabble_2-letter_words
# - chemical element symbols https://en.wikipedia.org/wiki/Symbol_%28chemistry%29
# get data
states <- tolower(state.abb)
scrabble <- c('aa','ab','ad','ae','ag','ah','ai','al','am','an','ar','as','at','aw','ax','ay','ba','be','bi','bo','by','ch','da','de','di','do','ea','ed','ee','ef','eh','el','em','en','er','es','et','ex','fa','fe','fy','gi','go','gu','ha','he','hi','hm','ho','id','if','in','io','is','it','ja','jo','ka','ki','ko','ky','la','li','lo','ma','me','mi','mm','mo','mu','my','na','ne','no','nu','ny','ob','od','oe','of','oh','oi','om','on','oo','op','or','os','ou','ow','ox','oy','pa','pe','pi','po','qi','re','sh','si','so','st','ta','te','ti','to','ug','uh','um','un','up','ur','us','ut','we','wo','xi','xu','ya','ye','yo','yu','za','zo')
elements <- tolower(c('Ac','Ag','Al','Am','Ar','As','At','Au','B','Ba','Be','Bh','Bi','Bk','Br'
@dill
dill / abstract.md
Last active January 11, 2016 02:34
ISEC 2016 abstract

Integrating data from multiple sources to improve species distribution models

Increasing quantities of and access to both wildlife survey data and non-designed incidental or citizen science data have left us with a rather big problem: how to we put all of these disparate pieces together and build species distribution models that use as much of the available data as possible? This leads us to a series of sub-questions that I will address in this talk: should we combine data then model it all at once or, build multiple models and figure out how to combine their outputs (or couple their fitting)? How can we find equivalences in recorded effort (and what can we do when no effort is recorded)? I'll illustrate these issues and offer some solutions using example data from aerial and shipboard surveys of seabirds in New England, as well as from large-scale surveys of marine mammals in the North Atlantic.

@dill
dill / exif_dist.R
Last active January 3, 2016 02:57
Calculate distance travelled from EXIF data
### blah
library(exif)
# get the files
files <- dir(".", full.names=TRUE)
files <- files[grepl(".JPG", files)]
# get the data
exifs <- read_exif(files)
@dill
dill / irltoots.R
Last active January 5, 2018 10:45
Make a grid of twitter folks I've met IRL
# you need my horse library from here: https://github.com/dill/horse
library(horse)
library(magrittr)
library(knitr)
setup_twitter_oauth("you auth stuff",
"goes here",
"you can't use mine",
"it's mine")
@dill
dill / cyclic_re_tensor.R
Created December 29, 2015 23:27
cyclic-random effects tensor for Noam
# cyclic-random effects tensor for Noam
library(mgcv)
# code adapted from ?gam.model
dat <- gamSim(1,n=400,scale=2) ## simulate 4 term additive truth
## Now add some random effects to the simulation. Response is
## grouped into one of 20 groups by `fac' and each groups has a
## random effect added....
@dill
dill / ffmpeg.txt
Last active October 4, 2022 14:44
imagemagick and ffmpeg cheatsheet
# convert mp4 to gif
# converts in.mp4 to out.gif, using 0-20s of the mp4 at resolution 640x480
ffmpeg -ss 00:00:00.000 -i in.mp4 -pix_fmt rgb24 -r 10 -s 640x480 -t 00:00:20.000 out.gif
# alternative mp4 to gif (using imagemagick for the second step)
ffmpeg -i input.mp4 -r 10 output%05d.png
convert output*.png output.gif
# strip audio out of a video file (to aac)
@dill
dill / mtcars-cat.R
Created November 27, 2015 15:10
categorical emojis -- like this Mark?
library(emoGG)
library(ggplot2)
# set the am variable to be different emoji
mtcars$am[mtcars$am==1] <- "1f697"
mtcars$am[mtcars$am==0] <- "1f68c"
# use am as the emoji aesthetic
ggplot(mtcars, aes(wt, mpg, emoji=am))+ geom_emoji()