Skip to content

Instantly share code, notes, and snippets.

View jsta's full-sized avatar
🪼
...

Jemma Stachelek jsta

🪼
...
View GitHub Profile
@jsta
jsta / taskview_metrics.R
Last active December 7, 2020 17:32
Get summary information for an entire CRAN Task View
library(packagemetrics) # devtools::install_github("ropenscilabs/packagemetrics")
library(ctv)
library(dplyr)
task_view <- "Optimization"
out_path <- paste0(task_view, ".rds")
pkgs <- ctv:::.get_pkgs_from_ctv_or_repos(task_view)
pkgs <- as.character(as.data.frame(pkgs[1])[,1])
if(!file.exists(out_path)){
pkg_metrics <- packagemetrics::package_list_metrics(pkgs)
@jsta
jsta / .home-rsync-filter
Created November 6, 2020 13:46 — forked from DarwinAwardWinner/.home-rsync-filter
Example rsync filter file for excluding temp files and stuff
## Rsync Filter for $HOME
# Universal excludes -- These apply to all subdirs
- [Cc]ache
- temp
- tmp
- octave-core
# Emacs temp files
- .#*
@jsta
jsta / pdfpreview
Last active October 1, 2020 20:03
Preview the title page of a pdf paper with a torn edge using imagemagick
test.png: test.pdf
convert -density 300 $<[0] -crop 100x20% -background white -alpha remove -strip -quality 70 test.png
mv test-0.png test.png
rm test-*.png
convert test.png -alpha set -background black -fill white \
\( +clone -colorize 100 -gravity south -chop 0x6 -splice 0x6 \
-spread 20 -paint 8 +transparent white -blur 0x0.8 \) \
-background none -compose dstin -composite torn.png
@jsta
jsta / rloadest_model_number-as-variable.R
Created September 28, 2020 19:27
Verify that adding ability to pass model number as a variable doesn't cause rloadest output changes
library(rloadest)
my_model_no <- 1
loadreg_original <- loadReg(Phosphorus ~ model(1),
data = app1.calib, dates = "DATES", flow = "FLOW")
loadreg_mod <- loadReg(as.formula(paste0("Phosphorus ~ model(", my_model_no, ")")),
data = app1.calib, dates = "DATES", flow = "FLOW")
identical(
loadreg_original,
@jsta
jsta / direnv_conda.md
Last active September 28, 2020 19:23
Setup a python environment with direnv
  1. Create an .envrc file:
export PATH=/home/<user>/anaconda3/bin:$PATH
# conda env create -n <env_name> -f environment.yml
source activate <env_name>
  1. Create an environment.yml file:
@jsta
jsta / curate_dropbox.R
Last active September 7, 2020 22:44
Curate Dropbox - List file and folder sizes to identify deletion targets
library(rdrop2) # devtools::install_github("karthik/rdrop2")
library(dplyr)
top_level_path <- function(x){
stringr::str_extract(x, "^(.+?)(\\/)")
}
rdrop2::drop_auth()
file_list_raw <- drop_dir(recursive = TRUE)
@jsta
jsta / README.md
Created August 26, 2020 12:23
Setup local instance of mediagoblin
@jsta
jsta / midland_dams.R
Created May 20, 2020 17:54
Explore the two dams associated with the 2020 Midland, MI flooding
library(dams)
library(dplyr)
library(sf)
library(mapview)
dt <- nid_subset
dt <- dt[c(
grep("edenville", tolower(dt$dam_name)),
grep("sanford", tolower(dt$dam_name))),] %>%
dplyr::filter(state == "MI") %>%
@jsta
jsta / hypso_from_raster.R
Last active April 1, 2020 15:24
Extract lake hypsographic curves from bathymetry rasters
get_hypso <- function(rsub){
maxdepth <- abs(cellStats(rsub, "min")) # set to "max" if depths are positive
# define depth intervals by raster resolution
min_res <- 0.5
depth_int <- -1 * seq(0, round(maxdepth/min_res) * min_res, by = min_res)
# calculate area of raster between depth intervals
# reclassify raster based on depth intervals
# calculate area of each class
@jsta
jsta / mbox.R
Created March 11, 2020 20:05
Create wordcloud from mbox email archive [unfinish]
library(mboxr)
library(tm.plugin.webmining)
library(tm)
library(wordcloud)
fpath <- path.expand("~/Downloads/jobs.mbox")
data <- read_mbox(fpath)
content <- paste(unlist(data$content), collapse = " ")
test <- extractHTMLStrip(content)
write.csv(test, "~/Downloads/jobs.csv")