Skip to content

Instantly share code, notes, and snippets.

View joelnitta's full-sized avatar

Joel Nitta joelnitta

View GitHub Profile
@joelnitta
joelnitta / compare_project_files.R
Last active January 31, 2020 01:52
Compare hashes of identically named files across two project versions
# Compare hashes of identically named files across two project versions,
# e.g. if the project was run again with different versions of dependencies.
# >>> Assumes files are uniquely named within a project <<<
# (replace vector of paths appropriately)
library(digest)
library(tidyverse)
files_to_check_01 <- list.files(
# Check all of the files in these directories
@joelnitta
joelnitta / make_ref_key_list.R
Created March 23, 2020 06:30
Make ref key list (especially for searching in Mendeley)
# Extract a list of citation keys from an Rmd file,
# paste them together to search in Mendeley to make
# a list of references in that Rmd file
rmd_file <- "path_to_Rmd_file"
citations <-
readr::read_lines(rmd_file) %>%
stringr::str_split(" |;") %>%
unlist %>%
@joelnitta
joelnitta / gni_kubernetes.yaml
Created March 30, 2020 01:51
gni with kubernetes
---
apiVersion: v1
kind: Service
metadata:
name: resolver
namespace: gn
labels:
app: resolver
tier: frontend
spec:
@joelnitta
joelnitta / check_doi_in_bib.R
Created April 8, 2020 01:35
Check DOIs in bib file
library(bib2df)
library(rcrossref)
library(tidyverse)
# Double check to make sure DOIs in bibliography match the right papers
# Load clean bibliography, select just relevant columns
path_to_bib <- "ms/references.bib"
bib <- bib2df(path_to_bib) %>%
@joelnitta
joelnitta / extract_latex_pkg_names_from_log.R
Created April 8, 2020 22:22
Extract latex package names from tlmgr log
library(tidyverse)
# Find the names of latex packages installed by tlmgr
# (https://www.tug.org/texlive/tlmgr.html)
# The main reason to do this is so they can be pre-installed to a docker image.
#
# The latex package install output from tlmgr tends to look like this:
#
# ```
# tlmgr search --file --global '/multirow.sty'
@joelnitta
joelnitta / extract_raw_data_file_names_from_plan.R
Created April 9, 2020 05:43
Extract raw data file names from a drake plan
library(tidyverse)
# Extract names of files in a "data_raw" folder
# and append "put" so they can easily be uploaded to
# a server using sftp
plan_lines <- read_lines("code/world_biogeo_plan.R")
plan_lines %>%
magrittr::extract(str_detect(., "data_raw")) %>%
@joelnitta
joelnitta / write_fasta_files_chunked.R
Created April 18, 2020 07:48
Write out a list of fasta files in chunks
#' Write out a list of DNA sequences in chunks
#'
#' The list will be split into a list of lists, to
#' save memory when writing out sequences.
#'
#' @param fasta_list The list of DNA sequences
#' @param chunk_size Size of chunks to split up list into.
#' @param out_dir Directory to write to
#'
#' @return List of hashes; digest of each chunk. Externally, the
@joelnitta
joelnitta / i18n_remote_error.log
Created April 18, 2020 20:31
Log of error when trying to pull from swcarpentry-ja/i18n
joelnitta@Joels-iMac repos % git clone https://github.com/joelnitta/i18n
Cloning into 'i18n'...
remote: Enumerating objects: 1672, done.
remote: Total 1672 (delta 0), reused 0 (delta 0), pack-reused 1672
Receiving objects: 100% (1672/1672), 2.73 MiB | 2.43 MiB/s, done.
Resolving deltas: 100% (1167/1167), done.
joelnitta@Joels-iMac repos % cd i18n
joelnitta@Joels-iMac i18n % git submodule init
Submodule 'git-novice' (https://github.com/swcarpentry-i18n/git-novice.git) registered for path 'git-novice'
Submodule 'po4gitbook' (https://github.com/swcarpentry-i18n/po4gitbook.git) registered for path 'po4gitbook'
@joelnitta
joelnitta / combine_huc.R
Created May 11, 2020 21:01
combine diversity metrics from different HUCs and get area
# Set working directory
setwd(here::here())
# Load packages and functions
source("r-code/01_start_up.R")
# Load plan
source("r-code/plan.R")
# Load cache
@joelnitta
joelnitta / start-dockerd.sh
Last active August 24, 2022 05:22
Start rootless docker daemon
#!/usr/bin/bash
# Start docker daemon in background
nohup dockerd-rootless.sh --experimental --storage-driver vfs >| dockerd.log 2>&1 &
# Save the process ID so we can kill it later
echo $! > dockerd.pid