Skip to content

Instantly share code, notes, and snippets.

View nbenn's full-sized avatar
👻

Nicolas Bennett nbenn

👻
View GitHub Profile
@nbenn
nbenn / install-gitlab.R
Last active May 19, 2016 20:22
Fetch latest build artifact from gitlab and install as R package.
#' Install an R package hosted as a build artifact on gitlab
#'
#' Gitlab supports the storage of build artifacts which may be utilized as
#' distribution mechanism for code binaries. Applying this to scheme to R, a
#' build task may be defined (for example for each tagged commit), yielding a
#' .zip file of the tar.gz package produced by R CMD build. This function
#' fetches the most recent build artifact and installs it as a package.
#'
#' @param gitlab A string representing the base url of the gitlab host
#' @param name The name of the package repository
@nbenn
nbenn / install-xgboost.sh
Created October 8, 2018 14:26
Install xgboost r-pkg on Mac OS 10.14 with openMP
export C_INCLUDE_PATH=$(/usr/local/clang-7/bin/llvm-config --includedir)
export CPLUS_INCLUDE_PATH=$(/usr/local/clang-7/bin/llvm-config --includedir)
export LIBRARY_PATH=$(/usr/local/clang-7/bin/llvm-config --libdir)
git clone --recursive https://github.com/dmlc/xgboost
cd xgboost
cp make/config.mk config.mk
vi config.mk
# make edits such that
# export CC = /usr/local/clang-7/bin/clang
@nbenn
nbenn / install-r.sh
Created October 8, 2018 14:39
install R on Mac OS 10.14 with openMP capable clang
wget https://stat.ethz.ch/CRAN/src/base/R-3/R-3.5.1.tar.gz
tar -xvf R-3.5.1.tar.gz
cd R-3.5.1
vi config.site
# edit such that
# CC=/usr/local/clang-7/bin/clang
# OBJC=$CC
# F77=/usr/local/gcc-8.2/bin/gfortran-8
# LDFLAGS="-L/usr/local/clang-7/lib -L/usr/local/lib"
@nbenn
nbenn / rm-obj.R
Created October 25, 2018 13:08
Ad SO #52974000
rm_tbl_4 <- function(tbl, env) {
tbl = deparse(substitute(tbl))
rm(list = tbl, pos = env)
}
fun_a <- function(dat_tbl) {
fun_b(dat_tbl)
}
fun_b <- function(data_table) {
@nbenn
nbenn / parallel-bm.R
Created October 30, 2018 07:43
Experiments with parallel access to bigmemory objects
library(bigmemory)
add_col_var <- function(x) {
biganalytics::apply(x, 2L, function(y) {
col_var <- 0
y_bar <- 0
for (i in y) y_bar <- y_bar + i
y_bar <- y_bar / length(y)
for (i in y) col_var <- col_var + (i - y_bar) ^ 2
y + (col_var / length(y))
@nbenn
nbenn / parallel-dt.R
Last active December 28, 2018 08:02
Experiments with parallel group-by in data.table
dt_sequential <- function(tbl, group_by, fun, use_cols) {
time_taken <- system.time({
res <- tbl[, fun(.SD), by = group_by, .SDcols = use_cols]
})
list(result = res, timings = time_taken)
}
@nbenn
nbenn / install-arrow.sh
Last active January 31, 2019 15:11
Install apache-arrow 0.12
# make sure a recent version of bison is available
brew install bison
wget https://www-eu.apache.org/dist/arrow/arrow-0.12.0/apache-arrow-0.12.0.tar.gz
tar -xvf apache-arrow-0.12.0.tar.gz
cd apache-arrow-0.12.0/cpp && mkdir release && cd release
# It is important to statically link to boost libraries
cmake .. -DARROW_PARQUET=ON -DCMAKE_BUILD_TYPE=Release -DARROW_BOOST_USE_SHARED:BOOL=Off \
-DBISON_EXECUTABLE=/usr/local/opt/bison/bin/bison
@nbenn
nbenn / mp11-type-list-switch.cpp
Last active August 4, 2019 12:27
Runtime index for choosing type
// compile: clang++ -Wall -std=c++14 -I /usr/local/include mp11-type-list-switch.cpp -o mp11-type-list-switch
#include <vector>
#include <iostream>
#include <boost/mp11/list.hpp>
#include <boost/mp11/algorithm.hpp>
namespace mp11 = boost::mp11;
@nbenn
nbenn / functor-type-switch.cpp
Last active August 4, 2019 12:38
Runtime index for choosing type
// compile: clang++ -Wall -std=c++11 functor-type-switch.cpp -o functor-type-switch
#include <vector>
#include <iostream>
#include <stdexcept>
template <template<typename> class Func, typename ...Ar>
auto dispatch_type(size_t type, Ar&&... rg) ->
decltype(Func<int>()(std::forward<Ar>(rg)...)) {
switch(type) {
@nbenn
nbenn / functor-recursive-switch.cpp
Last active August 5, 2019 15:16
Runtime index for choosing type
#include <stdexcept>
#include <tuple>
#include <iostream>
// terminating case to avoid if-constexpr
template <template<class> class F, typename R, typename... Ar>
R dispatch_impl(int, Ar&&... rgs) {
throw std::runtime_error("error");
}