Skip to content

Instantly share code, notes, and snippets.

View ateucher's full-sized avatar

Andy Teucher ateucher

View GitHub Profile
# ------------------------------------------
# PostgreSQL configuration file customizations
# ------------------------------------------
#------------------------------------------------------------------------------
# CONNECTIONS AND AUTHENTICATION
#------------------------------------------------------------------------------
# - Connection Settings -
@tjmahr
tjmahr / ggpreview.R
Created October 2, 2017 12:32
ggpreview - preview ggsave output in system image viewer
library(ggplot2)
# preview a file that would be created by ggsave()
ggpreview <- function(...) {
fname <- tempfile(fileext = ".png")
ggsave(filename = fname, ...)
system2("open", fname)
invisible(NULL)
}
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/aa049a47b218fda30f9a4a454119ae067a02cf50/Formula/postgis.rb
#pg_config --pkglibdir is useful for finding your $libdir
cp -a /usr/local/share/postgresql/extension/postgis* /usr/local/Cellar/[email protected]/9.6.5/share/[email protected]/extension/
cp -a /usr/local/lib/postgresql/postgis-2.3.so /usr/local/Cellar/[email protected]/9.6.5/lib/postgis-2.3
cp -a /usr/local/lib/postgresql/rtpostgis-2.3.so /usr/local/Cellar/[email protected]/9.6.5/lib/
sudo apt-get update
sudo apt-get upgrade
# gdal
sudo add-apt-repository ppa:ubuntugis/ppa
sudo apt-get update
sudo apt-get install gdal-bin libgdal-dev
# postgres/postgis
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
## GOAL:
## re-create a figure similar to Fig. 2 in Wilson et al. (2018),
## Nature 554: 183-188. Available from:
## https://www.nature.com/articles/nature25479#s1
##
## combines a boxplot (or violin) with the raw data, by splitting each
## category location in two (box on left, raw data on right)
# initial set-up ----------------------------------------------------------
@hrbrmstr
hrbrmstr / keybindings.json
Last active March 29, 2018 02:34
user-settings.js
{
"editor.fontFamily": "'Operator Mono Lig', Iosevka, Menlo, Monaco, 'Courier New', monospace",
"editor.fontLigatures": true,
"editor.fontSize": 14,
"editor.tabSize": 2,
"editor.wordWrap": "on",
"r.rterm.mac" : "/usr/local/bin/rtichoke",
"r.rterm.option" : [],
"r.lintr.enabled": false,
"terminal.external.osxExec": "iTerm.app",
@ateucher
ateucher / snake_camel.R
Created March 22, 2018 21:15
Convert between snake_case and camelCase
camel_to_snake <- function(x, case = c("lower", "upper")) {
case <- match.arg(case)
case_fun <- switch(case, lower = tolower, upper = toupper)
case_fun(gsub("([a-z0-9])([A-Z]+)", "\\1_\\2", x))
}
snakeToCamel <- function(x) {
x <- tolower(x)
gsub("([a-z0-9]+)_([a-z0-9])", "\\1\\U\\2\\E", x, perl = TRUE)
}
library(sf)
#> Linking to GEOS 3.6.2, GDAL 2.2.3, proj.4 5.0.0
library(rmapshaper)
library(geojsonio)
#> 
#> Attaching package: 'geojsonio'
#> The following object is masked from 'package:base':
#> 
#>     pretty
#!/bin/bash
TODAY=`date +%Y-%m-%d`
TODAY_MD=`date +%B\ %d,\ %Y`
YEAR=`date +%Y`
PACKAGENAME=$1
##
## CHANGE ME!!!
@ateucher
ateucher / ggmap_sf.R
Last active June 15, 2018 16:48
ggmap_sf
#' Plot a ggmap object when you will be adding geom_sf() layers
#'
#' This is a wrapper around [ggmap::ggmap()], that transforms the bounding
#' box of the ggmap object to epsg:3857, which is what the underlying
#' data is in. This allows you to add `geom_sf()` layers with a crs
#' of epsg:3857 and have them line up properly.
#'
#' See [this stackoverflow question](https://stackoverflow.com/q/47749078/1736291)
#'
#'