Skip to content

Instantly share code, notes, and snippets.

View dhicks's full-sized avatar

Dan Hicks dhicks

View GitHub Profile
@dhicks
dhicks / pairs.R
Created March 8, 2017 15:28
google_books_count pairs
library(foreach)
library(doSNOW)
library(dplyr)
library(httr)
google_books_count = function (search_terms) {
require(httr)
terms = str_c(search_terms, collapse = '+')
query_url = str_c('https://www.googleapis.com/books/v1/volumes',
'?',
@dhicks
dhicks / PubMed grant extraction.R
Created January 12, 2018 21:44
Extract grant IDs and funding information from PubMed records
library(rentrez)
library(magrittr)
library(xml2)
xml_raw = entrez_fetch(db="pubmed",
id=27019001,
rettype = 'xml')
xml_parsed = read_xml(xml_raw)
grant_id = xml_find_all(xml_parsed, '//Grant') %>%
@dhicks
dhicks / analysis.csv
Created July 4, 2018 15:19
Papers by "philosophers of science" published in Analysis since 2000
given family title pub_year
A Avramides The Subject's Point of View * By KATALIN FARKAS 2009
A Woodfield Doing Without Concepts By Edouard Machery * By EDOUARD MACHERY 2009
A C Paseau How to type: reply to Halbach 2009
A C Paseau Why the subtraction argument does not add up 2002
A C Paseau An exact measure of paradox 2012
A C Paseau Did Frege commit a cardinal sin? 2015
A C Paseau The overgeneration argument(s): A succinct refutation 2013
A W Heathcote Gettier and the stopped clock 2012
A W Moore Not to be Taken at Face Value 2009
@dhicks
dhicks / mwe.R
Created July 10, 2018 19:02
Spatial Durbin Model
library(rstan)
## options(mc.cores = parallel::detectCores())
## Data should be here: <https://drive.google.com/open?id=1BUV8mChrZ0UkyW2G4EHB5wc1taUpMZUM>
load('mwe.Rdata')
## dataf: The data; response is `w_use`
## W_3nn: row-normalized spatial weights matrix, based on 3 nearest neighbors, in triplet sparse form
## W_dnn: row-normalized spatial weights matrix, distance-based, in triplet sparse form
parsed = stanc(file = 'sdm.stan', verbose = TRUE)
@dhicks
dhicks / apqsync.sh
Created October 21, 2018 00:29
This bash script synchronizes AlpineQuest tracks using rsync, then converts them to gpx
#!/bin/bash
## This script synchronizes AlpineQuest tracks using rsync, then converts them to gpx
RED='\033[0;31m'
NC='\033[0m'
echo -e "${RED}Make sure SSHDroid is running before using this script${NC}"
startfolder="$PWD"
## SSHDroid: <https://play.google.com/store/apps/details?id=berserker.android.apps.sshdroid&hl=en_US>
apqfolder="/Users/danhicks/Google Drive/hiking/GPS tracks/AlpineQuest conversion/AlpineQuest sync"
@dhicks
dhicks / cleveland.R
Created November 10, 2018 17:19
Cleveland Dot Plots or Dumbell Plots
## Cleveland Dot Plots or Dumbell Plots
## This gist notes some approaches for drawing Cleveland dot plots or dumbell plots in `ggplot`
library(tidyverse)
n = 10
dataf = tibble(x = rep(1:n, 2),
category = c(rep('A', n), rep('B', n)),
value = x + 2*(category == 'B'))
@dhicks
dhicks / shading.R
Last active April 8, 2019 17:49
Shade rectangular areas of a ggplot plot across facets
## It took me three days to find this solution!
## <https://stackoverflow.com/questions/44688623/adding-custom-images-to-ggplot-facets/44897816#44897816>
annotation_custom2 <- function (grob, xmin = -Inf, xmax = Inf, ymin = -Inf, ymax = Inf, data)
{
layer(data = data, stat = StatIdentity, position = PositionIdentity,
geom = ggplot2:::GeomCustomAnn,
inherit.aes = FALSE, params = list(grob = grob,
xmin = xmin, xmax = xmax,
ymin = ymin, ymax = ymax))
@dhicks
dhicks / fixcalibre
Created July 25, 2019 21:48
Just a little Bash wrapper around a Ghostscript call to fix an encoding error when Calibre converts epub to pdf
#!/bin/bash
## Just a little Bash wrapper for a Ghostscript call
gs -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$2" "$1"
@dhicks
dhicks / sample_size_sim.R
Last active March 16, 2020 20:30
If one group is much larger than the other, does this inflate type I error rates or bias estimates?
## If one group is much larger than the other, does this
## inflate type I error rates or bias estimates?
library(tidyverse)
library(broom)
library(tictoc)
set.seed(2020-03-16)
## Parameters ----
a_n = 300
## Parses a roster page saved from Canvas and allocates students to groups within discussion sections
## To use:
## 1. Navigate to the People page in a Canvas course using your browser
## 2. Right-click on the page and select "Save as"
## 3a. `Rscript parse.R path/to/roster.html`
## -OR-
## 3b. Save it to `data_folder` as `roster.html`. `Rscript parse.R` or run in RStudio.
## Setup ----