Skip to content

Instantly share code, notes, and snippets.

View ateucher's full-sized avatar

Andy Teucher ateucher

View GitHub Profile
@mattmc3
mattmc3 / modern_sql_style_guide.md
Last active April 10, 2025 22:36
Modern SQL Style Guide
layout author title revision version description
default
mattmc3
Modern SQL Style Guide
2019-01-17
1.0.1
A guide to writing clean, clear, and consistent SQL.

Modern SQL Style Guide

-- Before running, load ecoregions, ecosections, bec, nr regions
-- to the db with the same schema.table name as in bcgw
-- This assumes using ogr2ogr for the load, it creates the objectid columns
-- ----------------------------
-- first, overlay designatedlands with nr regions
-- ----------------------------
DROP TABLE IF EXISTS nr_sub;
CREATE TABLE nr_sub AS
@boshek
boshek / rasterizing
Last active September 26, 2018 19:04
Comapring POSTGIS rasterization with fasterize
library(sf)
library(dplyr)
library(fasterize)
shape <- "MULTIPOLYGON (((1126095 1246073, 1126221 1246053, 1126358 1246059, 1126383 1245909, 1126457 1245800, 1126605 1245831, 1126756 1245812, 1126812 1245652, 1126805 1245526, 1126841 1245377, 1126859 1245227, 1126868 1245077, 1126881 1244927, 1126949 1244805, 1126954 1244667, 1126806 1244635, 1126658 1244602, 1126508 1244591, 1126358 1244591, 1126283 1244701, 1126248 1244825, 1126256 1244951, 1126219 1245100, 1126197 1245249, 1126175 1245374, 1126145 1245498, 1126114 1245622, 1126025 1245743, 1125919 1245839, 1125803 1245897, 1125638 1245928, 1125547 1246037, 1125693 1246143, 1125842 1246150, 1126095 1246073)))"
tictoc::tic()
## Actually connect to the database
@noamross
noamross / mgcv-posterior-animate.R
Created September 2, 2018 00:29
Animating smoothing uncertainty in a GAM
library(tidyverse)
library(gganimate)
library(mgcv)
library(mvtnorm)
# Fit a GAM to the data
mod <- gam(hp ~ s(mpg), data=mtcars, method="REML")
# Get the linear prediction matrix
newdat = data.frame(
@korylprince
korylprince / merge.py
Last active January 29, 2025 17:27
Modify 10.13 (SFL2) Server Favorites list
#!/usr/local/munki/munki-python
# change the above path to your own python if you don't have Munki installed
"""
Merges add_servers into current favorites and removes remove_servers.
Run as root to update all users or as normal user to update just that user.
"""
import os
import getpass
@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)
#'
#'
#!/bin/bash
TODAY=`date +%Y-%m-%d`
TODAY_MD=`date +%B\ %d,\ %Y`
YEAR=`date +%Y`
PACKAGENAME=$1
##
## CHANGE ME!!!
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
@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)
}
@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",