Skip to content

Instantly share code, notes, and snippets.

View nistara's full-sized avatar

Nistara Randhawa nistara

View GitHub Profile
@nuest
nuest / switching-from-XML-to-xml2.md
Last active November 19, 2024 04:21
Switching an R package from XML to xml2

Switching from XML to xml2

Rationale

The R package XML for parsing and manipulation of XML documents in R is not actively maintained anymore, but used by many:

The R package xml2 is an actively maintained, more recent alternative.

This file documents useful resources and steps for moving from XML to xml2.

@halhen
halhen / elevation.R
Last active November 4, 2020 16:11
# Download elevation tif from eg http://www.eea.europa.eu/data-and-maps/data/digital-elevation-model-of-europe
# First, convert elevation tif to a space delimited xyz (lng lat elevation) file
# $ gdal_translate -of XYZ elevation3x3.tif /tmp/file.xyz
df <- read_delim('/tmp/file.xyz', delim=' ', col_names=FALSE)
df %>%
mutate(X3 = na_if(X3, 0)) %>%
ggplot(aes(X1, -X2 + 20 * X3/max(X3, na.rm=TRUE), group=X2)) +
geom_line(size=0.05) +
# data from http://ec.europa.eu/eurostat/web/gisco/geodata/reference-data/population-distribution-demography/geostat
# Originally seen at http://spatial.ly/2014/08/population-lines/
# So, this blew up on both Reddit and Twitter. Two bugs fixed (southern Spain was a mess,
# and some countries where missing -- measure twice, submit once, damnit), and two silly superflous lines removed after
# @hadleywickham pointed that out. Also, switched from geom_segment to geom_line.
# The result of the code below can be seen at http://imgur.com/ob8c8ph
library(tidyverse)
@rmcelreath
rmcelreath / discrete_missingness.R
Created March 8, 2017 10:39
Discrete missing values in Stan
# "impute" missing binary predictor
# really just marginalizes over missingness
# imputed values produced in generated quantities
N <- 1000 # number of cases
N_miss <- 100 # number missing values
x_baserate <- 0.25 # prob x==1 in total sample
a <- 0 # intercept in y ~ N( a+b*x , 1 )
b <- 1 # slope in y ~ N( a+b*x , 1 )
@olivierlacan
olivierlacan / migrate_postgresql_database.md
Last active March 24, 2022 20:30
How to migrate a Homebrew-installed PostgreSQL database to a new major version (9.3 to 9.4) on OS X. See upgraded version of this guide: http://olivierlacan.com/posts/migrating-homebrew-postgres-to-a-new-version/

This guide assumes that you recently run brew upgrade postgresql and discovered to your dismay that you accidentally bumped from one major version to another: say 9.3.x to 9.4.x. Yes, that is a major version bump in PG land.

First let's check something.

brew info postgresql

The top of what gets printed as a result is the most important:

@derickfay
derickfay / fix_notes.applescript
Created April 16, 2015 16:55
Change Keynote Presenter Notes Font and Size for All Slides
tell application "Keynote"
tell document 1
set theSlides to slides
repeat with s in the slides
tell presenter notes of s
set font to "Helvetica"
set size to 24
end tell
end repeat
end tell
@MohamedAlaa
MohamedAlaa / tmux-cheatsheet.markdown
Last active March 31, 2025 23:38
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname