Skip to content

Instantly share code, notes, and snippets.

View larsvilhuber's full-sized avatar

Lars Vilhuber larsvilhuber

View GitHub Profile
capture confirm file file.txt
if _rc == 0 {
<code if file exists>
}
else {
<code if the file does not exist>
}
@larsvilhuber
larsvilhuber / dot_bash_profile
Created December 2, 2021 17:46
WSL SSH agent setup
SSH_ENV="$HOME/.ssh/agent-environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add $HOME/.ssh/id_lars2016_rsa;
}
@larsvilhuber
larsvilhuber / URL
Last active June 22, 2020 02:04
Adding an online Zotero group to any application as a bibtex file
https://api.zotero.org/groups/(GROUP-ID)/items?format=bibtex&limit=150
where (GROUP-ID) is the numeric identifier associated with your group library.
This will download a BIB file. Other formats, see the Zotero API.
@larsvilhuber
larsvilhuber / build.sh
Last active April 11, 2020 15:47
Basic LaTeX compile with Github Actions
#!/bin/bash
# This is needed by the main.yml
# Goes into ${ROOT}/bin
DOCS="main"
DEST="docs"
[[ -d $DEST ]] || mkdir $DEST
# xelatex does not work
@larsvilhuber
larsvilhuber / install.log
Created March 8, 2020 19:03
ggplot2 fails install on French-language Windows system
R version 3.6.3 (2020-02-29) -- "Holding the Windsock"
Copyright (C) 2020 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)
R est un logiciel libre livré sans AUCUNE GARANTIE.
Vous pouvez le redistribuer sous certaines conditions.
Tapez 'license()' ou 'licence()' pour plus de détails.
R est un projet collaboratif avec de nombreux contributeurs.
Tapez 'contributors()' pour plus d'information et
@larsvilhuber
larsvilhuber / program.R
Created January 30, 2020 22:58
Conditional handling of (non-distributable) absent data
# this project might have some confidential data that cannot be distributed
# Rather than break the program, or worse, ask replicators to comment out lines,
# provide a clean skip of those things, or even an alternate output (robustness check?)
basepath <- c("/path/to/project")
# or :
# basepath <- here::here()
# set filepaths relative to basepath
confidential <- file.path(basepath,"data","confidential")
@larsvilhuber
larsvilhuber / hamming.tex
Created December 20, 2019 15:47
Hamming distance
The \emph{Hamming} metric on $\mscr X^n$ is $H: \mscr X^n \times \mscr X^n \rightarrow \ZZ^{\geq 0}$, defined by $H(\ul x,\ul x') =\# \{i \mid x_i\neq x'_i\}$. %In other words, the Hamming distance counts the number of entries that differ between $X$ and $X'$.
@larsvilhuber
larsvilhuber / git_remotes.bash
Created August 5, 2019 18:57
git setup all remote branches
#!/bin/bash
# Credit:
# https://stackoverflow.com/questions/67699/how-to-clone-all-remote-branches-in-git
for branch in $(git branch --all | grep '^\s*remotes' | egrep --invert-match '(:?HEAD|master)$'); do
git branch --track "${branch##*/}" "$branch"
done
@larsvilhuber
larsvilhuber / global-libraries.R
Created April 23, 2019 15:43
Install R packages
####################################
# global libraries used everywhere #
####################################
# Package lock in - optional
MRAN.snapshot <- "2019-01-01"
options(repos = c(CRAN = paste0("https://mran.revolutionanalytics.com/snapshot/",MRAN.snapshot)))
pkgTest <- function(x)
{
if (!require(x,character.only = TRUE))
@larsvilhuber
larsvilhuber / Uploading to repositories
Created March 13, 2019 20:05
Uploading to repositories
figshare: https://github.com/elifesciences/datacapsule-crossref
zenodo: https://developers.zenodo.org/#quickstart-upload
dataverse: https://github.com/IQSS/dataverse-uploader/wiki/DVUploader,-a-Command-line-Bulk-Uploader-for-Dataverse