Skip to content

Instantly share code, notes, and snippets.

View larsvilhuber's full-sized avatar

Lars Vilhuber larsvilhuber

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / add_datatoggle.sh
Last active May 14, 2020 09:17
Add a Data Toggle Tile to Samsung devices without root
#!/bin/bash
# Based on https://www.xda-developers.com/how-to-restore-mobile-data-quick-settings-tile-toggle-on-samsung-galaxy-devices/
# This will work with minor adjustments to your installation of the Android SDK or wherever you put adb.
# Should work on Linux and Mac, but only tested on Linux
PATH=../android-sdk-linux/platform-tools:$PATH
outfile=list.$(date +%F)
adb devices
echo "Do you see your device? [y|N]"
@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 / config.do
Last active November 24, 2020 17:22
A stata config file to store parameters and file paths in a single project-specific location
/* config.do */
/* Suggested by Lars Vilhuber */
/* Create a reproducible Stata sequence by calling this program from every other program in your sequence */
/* Get it at: https://gist.github.com/larsvilhuber/6bcf4ff820285a1f1b9cfff2c81ca02b */
/* Usage:
Adapt to your needs, save as config.do, then add
include "config.do"
in the author's main Stata program
*/
@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;
}
capture confirm file file.txt
if _rc == 0 {
<code if file exists>
}
else {
<code if the file does not exist>
}