Skip to content

Instantly share code, notes, and snippets.

View wookietreiber's full-sized avatar
🎸

♫ Christian Krause ♫ wookietreiber

🎸
View GitHub Profile
@wookietreiber
wookietreiber / git-hook-lintr.r
Last active April 1, 2019 22:11
git pre-commit hook to check R scripts with lintr via littler
suppressMessages(library(lintr))
files <- commandArgs(trailingOnly = T)
messages <- function(file) {
result <- lint(file)
print(result)
return(length(result))
}
@wookietreiber
wookietreiber / git-hook-shellcheck.sh
Last active April 27, 2021 05:15
git pre-commit hook to check shell scripts with shellcheck
#!/usr/bin/env bash
set -efu -o pipefail
# returns staged files
function staged.files {
if git rev-parse --verify HEAD &> /dev/null
then
against=HEAD
else
@wookietreiber
wookietreiber / git-hook-delegate.sh
Last active July 31, 2017 16:22
git hook delegate
#!/bin/bash
GIT_HOOK_DIR="$0.d"
if [[ -d $GIT_HOOK_DIR ]] ; then
while IFS= read -r -d $'\0' hook ; do
"./$hook" || error="yes"
done < <(find "$GIT_HOOK_DIR" -mindepth 1 -print0)
[[ -n $error ]] && exit 1
@wookietreiber
wookietreiber / prompt.sbt
Created July 12, 2017 04:10
sbt prompt
shellPrompt := { state =>
(scala.Console.CYAN + "sbt @ %s $ " + scala.Console.RESET) format {
Project.extract(state).getOpt(sbt.Keys.name) getOrElse {
Project.extract(state).currentProject.id
}
}
}
@wookietreiber
wookietreiber / README.md
Last active December 20, 2022 14:00
R - Command Line Interface (CLI) and RStudio - template

R - Interactive Sessions and Command Line Interface

This is a template for R projects that should work both on the command line as well as in an interactive session.

Template Files

The template is made up of three files:

  1. foo.r
#!/usr/bin/env python
from argparse import ArgumentParser, FileType
# ------------------------------------------------------------------------------
# defaults
# ------------------------------------------------------------------------------
default_nthreads = 1
default_verbose = False
library(optparse)
# ------------------------------------------------------------------------------
# defaults
# ------------------------------------------------------------------------------
default.nthreads <- 1
default.verbose <- FALSE
# ------------------------------------------------------------------------------
#!/usr/bin/env r
# create input file with:
# $ find /path/to/dir -type f -printf '%s\n' | gzip > dir.file.sizes.gz
# start with:
# $ zcat dir.file.size.gz | fshist.r
# edit breaks to your needed sizes
# leave the breaks "0" and "2^50" for the edges
suppressMessages(library(stats))
@wookietreiber
wookietreiber / meansd-bin.scala
Last active July 23, 2018 05:29
calculate mean and standard deviation from numbers in stdin (histogram-style)
// this gist has been superseded by
// https://github.com/wookietreiber/scala-cli-tools
@wookietreiber
wookietreiber / meansd.c
Last active July 23, 2018 05:29
calculate mean and standard deviation from numbers in stdin
// this gist has been superseded by
// https://github.com/wookietreiber/scala-cli-tools