Remember:
| {type}({scope}): {subject} |
| {body} (optional) |
{type}:
feat(new feature for the user, not a new feature for build script)fix(bug fix for the user, not a fix to a build script)docs(changes to the documentation only)
| [alias] | |
| tracking = "!f() { git for-each-ref --format '%(refname:short):%(upstream:short)' 'refs/heads' | egrep -v ':$'; }; f" | |
| is-clean-workdir = "!f() { git diff --stat --exit-code || { echo \"Workdir dirty\"; exit 1; }; }; f" | |
| is-clean-index = "!f() { git diff --stat --cached --exit-code || { echo \"Index dirty\"; exit 2; }; }; f" | |
| is-clean = "!f() { git is-clean-workdir && git is-clean-index; }; f" | |
| co-merge = "!f() { local=\"$1\"; remote=\"$2\"; git checkout \"$local\"; git merge --ff-only \"$remote\"; }; f" | |
| current-branch = rev-parse --abbrev-ref HEAD | |
| sync = "!f() { git is-clean || { echo Aborting sync.; exit 1; }; current=$(git current-branch); git fetch --all; git tracking | while IFS=: read local remote; do echo \"Merging $local with $remote\"; git co-merge \"$local\" \"$remote\"; done 3>&1 1>&2 2>&3 | egrep -i --color 'fatal|$' 3>&1 1>&2 2>&3; git checkout \"$current\"; }; f" |
Remember:
| {type}({scope}): {subject} |
| {body} (optional) |
{type}:
feat (new feature for the user, not a new feature for build script)fix (bug fix for the user, not a fix to a build script)docs (changes to the documentation only)| si_prefixes_positive = c("k", "M", "G", "T", "P", "E", "Z", "Y") | |
| si_prefixes_negative = c("m", "µ", "n", "p", "f", "a", "z", "y") | |
| engineering_notation = function(x, digits=6, digitsafter=NA, si_prefix=TRUE, scale=1, unit="") { | |
| if (is.na(x)) return(NA) | |
| negative = (x<0) | |
| x = scale*abs(x) | |
| if (x==0) { | |
| # ! log10(0) = -Inf | |
| pow = 0 | |
| digitsbefore = 1 |
| require(logging) | |
| # LOG_LEVEL = "FINEST" | |
| # LOG_LEVEL = "DEBUG" | |
| LOG_LEVEL = "INFO" | |
| # LOG_LEVEL = "ERROR" | |
| logReset() | |
| basicConfig(LOG_LEVEL) # bootstrapping the logging package | |
| removeHandler("basic.stdout") | |
| addHandler("mybasic.stdout", action=writeToConsole, level=LOG_LEVEL, |
| load_lib = function(lib_name) { | |
| if (!require(package=lib_name, character.only=TRUE)) { | |
| install.packages(lib_name) | |
| if (!require(package=lib_name, character.only=TRUE)) stop(paste0("Package '", lib_name, "' not found")) | |
| } | |
| library(package=lib_name, character.only=TRUE) | |
| } | |
| # Usage: | |
| load_lib("data.table") # for example |
| while (sink.number()>0) sink(file=NULL) # Close all remaining files opened by a previous run | |
| cat("All file descriptors closed.\n") | |
| rm(list=ls()); gc() # Clean up as much memory as possible | |
| # Replace by the following line if you want to keep getargs array to retrieve arguments: | |
| # rm(list=grep("getargs", ls(), fixed=T, value=T, invert=T)); gc() | |
| cat("Whole memory cleaned.\n") |
| if (sys.nframe()>0) { | |
| script.path = sys.frame(1)[[ | |
| switch(as.character(sys.call(1)[[1]]), | |
| source='ofile', # Started with source(...) | |
| debugSource='fileName', # Started with debugSource(...) | |
| NA | |
| ) | |
| ]] | |
| if (!exists("getargs")) { | |
| # getargs array should be set before invoking source() from RStudio |
| $ ip route get 10.32.213.84 | |
| 10.32.213.84 via 10.0.239.1 dev bond1.509 src 10.0.239.163 | |
| cache mtu 1500 advmss 1460 hoplimit 64 |
| parse_duration_to_ms = function(string) { # e.g. "1w 2d5h15m 08.24s", "0.000045s" | |
| opt_sep_re = "\\h*" | |
| re = paste0("^", | |
| "(?:(?<weeks>\\d+)w)?", opt_sep_re, | |
| "(?:(?<days>\\d+)d)?", opt_sep_re, | |
| "(?:(?<hours>\\d+)h)?", opt_sep_re, | |
| "(?:(?<minutes>\\d+)m)?", opt_sep_re, | |
| "(?:(?<seconds>\\d+)(?:\\.(?<milliseconds>\\d*))?s)?", | |
| "$") | |
| data = parseLines(re, string) |
| parseLines = function(perlNamedPattern, linesVector) { | |
| match = regexpr(perlNamedPattern, linesVector, perl=TRUE) | |
| found_idx = as.vector(match)>0 | |
| names = attr(match, "capture.names") | |
| start = attr(match, "capture.start") | |
| length = attr(match, "capture.length") | |
| end = start + length -1 | |
| results_matrix = c() | |
| for (col in seq(1, length(names))) { | |
| results_matrix = rbind(results_matrix, substr(linesVector, start[,col], end[,col])) |