Skip to content

Instantly share code, notes, and snippets.

View HenrikBengtsson's full-sized avatar

Henrik Bengtsson HenrikBengtsson

View GitHub Profile
@HenrikBengtsson
HenrikBengtsson / Makefile
Last active November 17, 2017 16:45
Local source-only mirrors of CRAN and Bioconductor R package repositories
## Query Bioconductor for the current release version
BIOC_VERSION := $(shell curl --silent https://www.bioconductor.org/config.yaml | grep -F "release_version:" | sed -E 's/.*release_version:[ ]*"([0-9.]+)".*/\1/g')
OPTS = --dry-run
OPTS =
all: sync-all
debug:
@echo BIOC_VERSION=$(BIOC_VERSION)
@HenrikBengtsson
HenrikBengtsson / keybase.io_henrikb.md
Last active September 19, 2017 02:21
keybase.io: henrikb

Keybase proof

I hereby claim:

  • I am henrikbengtsson on github.
  • I am henrikb (https://keybase.io/henrikb) on keybase.
  • I have a public key ASDEOqlHREq6LHfOQzW2wzXNbghVlSHRKtw24yfIhQtEQAo

To claim this, I am signing this object:

@HenrikBengtsson
HenrikBengtsson / evaluate_inside_container.R
Last active August 9, 2017 14:04
Evaluate unsafe R expression inside Linux container
library("future")
## Launch Linux container rocker/r-base in background
cl <- makeClusterPSOCK("localhost",
rscript = c("docker", "run", "--net=host", "rocker/r-base", "Rscript"),
rscript_args = c("-e", shQuote("install.packages('future')")))
## Evaluate R expression inside container
f <- cluster({ some_unsafe_call() }, workers = cl)
v <- value(f)
@HenrikBengtsson
HenrikBengtsson / ascii-mandelbrot.R
Last active July 10, 2017 18:05
ASCII Mandelbrot renderer (One-to-one R interpretation of C implementation)
## A one-to-one R interpretation of the minimalist C implementation
## of the ASCII Mandelbrot renderer in http://codepad.org/nINhbWVy:
##
## main(k){float i,j,r,x,y=-16;while(puts(""),y++<15)for(x
## =0;x++<84;putchar(" .:-;!/>)|&IH%*#"[k&15]))for(i=k=r=0;
## j=r*r-i*i-2+x/25,i=2*r*i+y/10,j*j+i*i<11&&k++<111;r=j);}
main <- function(k = 0) {
y <- -16
while({ cat("\n"); y <- y + 1L } < 16) {
@HenrikBengtsson
HenrikBengtsson / xerox_accounting_template.ppd
Last active January 6, 2022 19:39
Linux: Pass Accounting information to Xerox Printer via Postscript Printer Description (PPD)
*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
*% GENERAL ACCOUNTING
*%
*% Instructions:
*%
*% 1. Identify the accounting option or options used by the printer.
*%
*% 2. Replace the '{{...}}' placeholders with corresponding information
*% (without curly brackets). For example, '<22>XRX_USERID,{{userid}}<22>'
*% should become '<22>XRX_USERID,12345<22>'.
@HenrikBengtsson
HenrikBengtsson / SVN-REVISION.md
Created January 11, 2017 00:32
A one-line version of the SVN-REVISION hack on https://github.com/wch/r-source/wiki

A one-line version of the SVN-REVISION hack on https://github.com/wch/r-source/wiki:

printf "Revision: %s\nLast Changed Date: %s\n" `git log --format=%B -n 1 | tr '\n' ' ' | sed -E 's/.*git-svn-id: https:\/\/svn.r-project.org\/R\/[^@]*@([0-9]+).*/\1/'` `git log -1 --pretty=format:"%ad" --date=iso | sed -E 's/ .*//'` > SVN-REVISION
@HenrikBengtsson
HenrikBengtsson / HomomorphicEncryption-example.R
Created November 7, 2016 01:43
Example of homomorphic encryption and operators in R
## Example adopted and clarified from
## http://www.louisaslett.com/HomomorphicEncryption/
library("HomomorphicEncryption")
p <- pars("FandV")
k <- keygen(p)
## Unencrypted data
x <- c(42, 34)
y <- c(7, 5)
@HenrikBengtsson
HenrikBengtsson / future-remote-local-rendering.md
Last active September 24, 2016 22:03
Checking local rendering of remotely generated objects

Remote evaluation local display

Visualization

Works:

  • Base R Graphics
  • ggplot2
  • plotly
  • highcharter
  • rbokeh
--- R-3.2.1/src/main/memory.c.orig 2015-07-31 23:15:07.017151621 -0700
+++ R-3.2.1/src/main/memory.c 2015-07-31 23:17:10.185150073 -0700
@@ -3724,11 +3724,21 @@
static FILE *R_MemReportingOutfile;
static R_size_t R_MemReportingThreshold;
+static void printLineNum(FILE *file, SEXP srcref) {
+ if (srcref && !isNull(srcref)) {
+ int line = asInteger(srcref);
+ fprintf(file, "#%d ", line);
@HenrikBengtsson
HenrikBengtsson / ex-.Last.error.R
Last active May 6, 2016 01:17
Recording last stop() condition in .Last.error
## Requires options(error=recordStop)
## stop() at the prompt
stop("Hello")
## Error: Hello
print(.Last.error)
## <simpleError in stop("Hello"): Hello>
str(.Last.error)
# List of 3
# $ message: chr "woops"