Skip to content

Instantly share code, notes, and snippets.

View andremueller's full-sized avatar

Dr. André Müller andremueller

View GitHub Profile
@andremueller
andremueller / git_set_remote.sh
Created December 27, 2023 15:56
Git set remote from `git remote -v` call
#!/usr/bin/bash
# allows to play back a remote configuration backed up with `git remote -v > remote.txt`
set -o errexit
set -o nounset
shopt -s nullglob
remoteFile="$1"
[[ -f "$remoteFile" ]] || { echo "Error: file $remoteFile does not exist"; exit 1; }
while read name url ; do
if git remote get-url "$name" >/dev/null 2>&1 ; then
echo "Remote $name already exists"
@andremueller
andremueller / ssh-agent.sh
Created December 27, 2023 15:52
Starting ssh-agent in bash
## start ssh-agent
# see https://stackoverflow.com/questions/40549332/how-to-check-if-ssh-agent-is-already-running-in-bash
USER="${USER:-$(id -un)}" # fix for Windows git-bash which does not set the USER variable
export SSH_AUTH_SOCK=${SSH_AUTH_SOCK:-/tmp/ssh-agent-${USER}.sock}
agent_run_state=$(ssh-add -l > /dev/null 2>&1 ; echo $?)
# agent_run_state == 0 agent runs with keys
# agent_run_state == 1 agent runs without keys
# agent_run_state == 2 agent is not running
if [[ $agent_run_state = 2 ]] ; then
# Load stored agent connection info.
@andremueller
andremueller / bash_template.sh
Created April 2, 2022 16:10
A bash template with argument parsing and error handling
#!/bin/bash
# my bash template
set -o errexit
set -o nounset
shopt -s nullglob
SCRIPT_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
function die() {
echo "ERROR $? IN ${BASH_SOURCE[0]} AT LINE ${BASH_LINENO[0]}" 1>&2
@andremueller
andremueller / time_plot.R
Last active July 22, 2019 19:55
Plotting time-series with ggplot
library(ggplot2)
library(tidyverse)
requireNamespace("xts")
requireNamespace("generics")
requireNamespace("lubridate")
n <- 100
t1 <- lubridate::ymd(20190101)
tser <- xts::xts(sin(2 * pi * seq(0, 1, length.out = n)),
@andremueller
andremueller / my_code.R
Last active July 3, 2019 20:12
Unit Testing with R
# Example for simple function to be tested
#
# 1. Change working directory
# 2. Call: testthat::test_dir('tests') within RStudio or R
increment <- function(value) {
value + 1
}
@andremueller
andremueller / show_energy.R
Created June 22, 2019 17:34
Visualizing Energy Data from Influx DB
# Visualizing Energy Data from Influx DB
#
# - Loads energy data from an influx database filled with vzlogger
# - Creates a visualization for the electric power of the last 12 hours
#
library(dplyr)
library(tidyr)
library(ggplot2)
requireNamespace("glue")
requireNamespace("plotly")