This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from os import path | |
| import inspect | |
| scriptdir = path.dirname(inspect.getfile(inspect.currentframe())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # requires py_compile and pycodestyle Python module | |
| if git rev-parse --verify HEAD >/dev/null 2>&1 | |
| then | |
| against=HEAD | |
| else | |
| # Initial commit: diff against an empty tree object | |
| against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # requires py_compile and pycodestyle Python module | |
| if git rev-parse --verify HEAD >/dev/null 2>&1 | |
| then | |
| against=HEAD | |
| else | |
| # Initial commit: diff against an empty tree object | |
| against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
OlderNewer