Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View mllg's full-sized avatar

Michel Lang mllg

View GitHub Profile
@mllg
mllg / lpt.R
Created January 6, 2020 18:24
LPT Algorithm in R
lpt = function(x, ncpus = 1L) {
checkmate::assert_numeric(x, min.len = 1L, lower = 0, any.missing = FALSE, finite = TRUE)
checkmate::assert_count(ncpus, positive = TRUE)
bin = integer(length(x))
tta = double(ncpus)
for (xi in order(x, decreasing = TRUE)) {
i = which.min(tta)
bin[xi] = i
@mllg
mllg / rebuild-sys.R
Created November 28, 2019 09:52
Rebuild R packages after system libraries have been upgraded
#!/usr/bin/env Rscript
libs = c("libopenblas", "libicu")
packages = character()
patterns = sprintf("^%s.* => not found$", libs)
for (lib in .libPaths()) {
files = list.files(path = lib, pattern = "\\.so(\\.[0-9]+)*$", recursive = TRUE,
ignore.case = TRUE, full.names = TRUE, no.. = TRUE)

Keybase proof

I hereby claim:

  • I am mllg on github.
  • I am mllg (https://keybase.io/mllg) on keybase.
  • I have a public key ASAKJ2pkEz2CwPVYtKUwg058WRnAzXymECuaqIICnEWofQo

To claim this, I am signing this object:

@mllg
mllg / mccollect.diff
Created August 30, 2016 12:26
Patch for mccollect
Index: src/library/parallel/R/unix/mcparallel.R
===================================================================
--- src/library/parallel/R/unix/mcparallel.R (Revision 71169)
+++ src/library/parallel/R/unix/mcparallel.R (Arbeitskopie)
@@ -52,24 +52,26 @@
if (missing(jobs)) jobs <- children()
if (!length(jobs)) return (NULL)
if (isTRUE(intermediate)) intermediate <- utils::str
+ pids <- if (inherits(jobs, "process") || is.list(jobs))
+ processID(jobs) else jobs
@mllg
mllg / checkmate_benchmark.R
Created June 28, 2016 18:18
Some benchmarks for the R package checkmate
library(microbenchmark)
library(compiler)
library(ggplot2)
library(checkmate)
library(assertive)
library(assertthat)
bench = function(x, funs, repeats = 100) {
force(x)
microbenchmark(times = repeats,
@mllg
mllg / gist:d4455ef18856a2ef1a32
Created November 14, 2014 20:18
RcppArmadillo winbuilder error
* installing *source* package 'fmrmr' ...
** libs
*** arch - i386
g++ -I"D:/RCompile/recent/R-3.1.2/include" -I"d:/RCompile/CRANpkg/lib/3.1/Rcpp/include" -I"d:/RCompile/CRANpkg/lib/3.1/RcppArmadillo/include" -I"d:/Rcompile/CRANpkg/extralibs215/local215/include" -O3 -Wall -mtune=core2 -c RcppExports.cpp -o RcppExports.o
g++ -I"D:/RCompile/recent/R-3.1.2/include" -I"d:/RCompile/CRANpkg/lib/3.1/Rcpp/include" -I"d:/RCompile/CRANpkg/lib/3.1/RcppArmadillo/include" -I"d:/Rcompile/CRANpkg/extralibs215/local215/include" -O3 -Wall -mtune=core2 -c mrmr.cpp -o mrmr.o
g++ -shared -s -static-libgcc -o fmrmr.dll tmp.def RcppExports.o mrmr.o -LD:/RCompile/recent/R-3.1.2/bin/i386 -lRlapack -LD:/RCompile/recent/R-3.1.2/bin/i386 -lRblas -lgfortran -Ld:/Rcompile/CRANpkg/extralibs215/local215/lib/i386 -Ld:/Rcompile/CRANpkg/extralibs215/local215/lib -LD:/RCompile/recent/R-3.1.2/bin/i386 -lR
installing to d:/RCompile/CRANguest/R-release/lib/fmrmr/libs/i386
*** arch - x64
@mllg
mllg / GitFZF
Created November 10, 2014 21:42
function! GitFZF()
let l:git_root = system('git rev-parse --show-toplevel 2> /dev/null')
if empty(l:git_root)
execute 'FZF'
else
echom l:git_root
call fzf#run({
\ 'source' : 'git ls-tree -r --full-tree --name-only HEAD',
\ 'sink' : 'e',
\ 'dir' : substitute(l:git_root, "\n$", '', ''),
@mllg
mllg / gist:7469844
Created November 14, 2013 16:31
Simple iterator for the Cartesian product
cart_iter = function(li) {
nextState = function(state, pos = 1L) {
if (state[pos] < state.last[pos])
replace(state, pos, state[pos] + 1L)
else
nextState(replace(state, pos, 1L), pos + 1L)
}
nextElem = function() {
state <<- nextState(state)
tryCatchDebug = function(expr) {
handler_warning = function(w) {
cache.warnings <<- c(cache.warnings, w)
invokeRestart("muffleWarning")
}
handler_error = function(e) {
catched.error <<- TRUE
dump.frames(".lastDump")
dumped = get(".lastDump", envir = .GlobalEnv)
@mllg
mllg / rf_seq_parallel.R
Created April 19, 2013 13:29
Fit a random forests with 1000 trees on the iris data set as an example on sequential and parallel execution in R.
library(randomForest)
data(iris)
mydata = iris
###############################################################################
### sequential
###############################################################################
randomForest(Species ~ ., data = mydata, ntree = 1000)