Skip to content

Instantly share code, notes, and snippets.

View jeroen's full-sized avatar

Jeroen Ooms jeroen

View GitHub Profile
@jeroen
jeroen / bioc.R
Last active March 27, 2024 12:31
Get bioconductor HEAD commits
library(curl)
library(yaml)
parse_raw_gitpack <- function(buf){
con <- rawConnection(buf)
on.exit(close(con))
txt <- readLines(con, warn = FALSE)
stopifnot(grepl('^[0-9a-f]{4}#', txt[1]))
stopifnot(grepl('service=', txt[1]))
if(length(txt) == 2 && txt[2] == '00000000'){
@jeroen
jeroen / build-r-arm.sh
Last active September 3, 2023 21:06
Build R-devel for aarch64 in msys2
#!/bin/sh
set -e
set -x
cd ~
export R_CRAN_WEB="https://cran.rstudio.com"
export CRAN_RSYNC='mirrors.nic.cz::CRAN'
# Some prereqs
pacman -S --needed --noconfirm wget git make perl curl texinfo texinfo-tex rsync unzip diffutils
if [ ! -d "aarch64-w64-mingw32.static.posix" ]; then
@jeroen
jeroen / fdtest.c
Last active June 20, 2023 12:42
Test number of file descriptors
#include <curl/curl.h>
#include <stdlib.h>
#include <string.h>
size_t do_nothing(void *contents, size_t sz, size_t nmemb, void *ctx){
return sz * nmemb;
}
CURL *make_handle(char *url){
CURL *handle = curl_easy_init();
@jeroen
jeroen / webr-csv.html
Created April 1, 2023 12:33
webr export csv file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World! Site Title</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js"></script>
<script>
import('https://webr.r-wasm.org/latest/webr.mjs').then(function(x){
const webR = new x.WebR();
@jeroen
jeroen / Dockerfile
Last active January 17, 2023 21:14
Build libv8 on Fedora
FROM fedora:36
# Simulate the clang location from CRAN
RUN ln -s /usr /usr/local/clang15
RUN dnf install -y clang llvm lld
COPY script.sh .
RUN ./script.sh
@jeroen
jeroen / Dockerfile
Created January 15, 2023 15:14
libcxx / v8-devel linking error on Fedora
# syntax=docker/dockerfile:1.3-labs
FROM fedora:36
COPY <<EOF test.cpp
#include <libplatform/libplatform.h>
#include <v8.h>
using namespace v8;
int main(){
std::unique_ptr<Platform> platform = platform::NewDefaultPlatform();
@jeroen
jeroen / app.R
Last active October 23, 2022 02:25
Reoder pdf with drag and drop in shiny
# https://twitter.com/henrikbengtsson/status/1583520708470067201
library(shiny)
library(sortable)
library(pdftools)
library(magick)
# The file to manipulate
pdffile <- tempfile(fileext = '.pdf')
download.file('https://www.uscis.gov/sites/default/files/document/forms/i-9-paper-version.pdf', pdffile)
@jeroen
jeroen / math_to_rd.html
Last active August 3, 2022 08:12
HTML with math svg from KaTeX
<!DOCTYPE html><html><head><title>R: Display math in R documentation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
<link href="/doc/html/prism.css" rel="stylesheet" />
<link rel="stylesheet" href="/doc/html/katex/katex.css">
<script type="text/javascript" src="/doc/html/katex-config.js"></script>
<script defer src="/doc/html/katex/katex.js"
onload="processMathHTML();"></script>
<link rel="stylesheet" type="text/css" href="/doc/html/R.css" />
</head><body><div class="container">
@jeroen
jeroen / validate.R
Last active August 2, 2022 07:51
Validates mathjax using katex
ctx <- V8::v8()
ctx$source('https://cdn.jsdelivr.net/npm/katex@0.16.0/dist/katex.min.js')
ctx$eval('function validate(s){var out = {result: "ok", warnings:[]}; try{console.warn=function(w){out.warnings.push(w);};katex.renderToString(s)} catch (e) {out.result = e.name; out.position = e.position; out.message = e.message}; return out;}')
# Parsing error
ctx$call('validate', "E(y) = \\boldmath{\\mu}")
# OK but with warnings:
ctx$call('validate', "s*ₓᵢ = sₓᵢ √(VIFₓᵢ⁻¹) √((n-1)/(n-p))")
@jeroen
jeroen / Dockerfile
Created May 16, 2022 12:01
Package build errors with parallel make on Ubuntu 18.04
FROM ubuntu:bionic
ENV DEBIAN_FRONTEND noninteractive
RUN \
apt-get update && \
apt-get install -y curl software-properties-common && \
curl https://cloud.r-project.org/bin/linux/ubuntu/marutter_pubkey.asc | tee -a /etc/apt/trusted.gpg.d/cran_ubuntu_key.asc && \
add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/" && \
apt-get update && \