Skip to content

Instantly share code, notes, and snippets.

View jeroen's full-sized avatar

Jeroen Ooms jeroen

View GitHub Profile
@jeroen
jeroen / movie.R
Last active October 12, 2020 16:53
Terminal movie
# Run in an R terminal window (not GUI)
con <- socketConnection('towel.blinkenlights.nl', 23, open = 'rb')
repeat{
buf <- readBin(con, raw(), 10)
if(length(buf))
cat(rawToChar(buf))
}
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <unistd.h>
int main() {
float A = 0, B = 0;
float i, j;
int k;
+ make 32-bit
make --no-print-directory -C front-ends Rpwd
make -C ../../include -f Makefile.win version
make Rpwd.exe
/mingw32/bin/gcc -std=gnu99 -I../../include -DR_ARCH='"i386"' -O3 -Wall -pedantic -c rpwd.c -o rpwd.o
/mingw32/bin/windres -i rcico.rc -o rcico.o
/mingw32/bin/gcc -std=gnu99 -s -o Rpwd.exe rpwd.o rcico.o
cp front-ends/Rpwd.exe Rpwd.exe
-------- Building ../../../library/base/R/Rprofile from ../../library/profile/Common.R ../../library/profile/Rprofile.windows--------
mkdir -p ../../../library/base/R
openssl_multihash <- function(con, algos = c('md5', 'sha1', 'sha256', 'sha384', 'sha512')){
if(!isOpen(con)){
open(con, "rb")
on.exit(close(con))
}
states <- lapply(algos, function(algo){
structure(openssl:::md_init(algo), algo = algo)
})
while(length(data <- readBin(con, raw(), 512*1024))){
lapply(states, openssl:::md_feed, data = data)
@jeroen
jeroen / benchmark.R
Created January 14, 2020 12:52
Benchmark graphics devices for image()
plot_x <- function(x){
x11()
image(x)
dev.off()
}
plot_png <- function(x){
png(width = 800, height = 600)
image(x)
dev.off()
library(V8)
library(mapview)
library(geojsonsf)
ct$source("https://cdn.jsdelivr.net/npm/flatgeobuf@2.0.1/dist/flatgeobuf-geojson.min.js")
ct$source("https://cdn.jsdelivr.net/npm/text-encoding@0.6.4/lib/encoding.min.js")
json = sf_geojson(franconia)
ct$call('flatgeobuf.serialize', JS(json))
#' My roxy
#'
#' This is an example of how you would use roxygen.
#'
#' ```{r}
#' #' Test example
#' #'
#' #' This is an example. Here is how you embed R code:
#' #'
#' #' ```{r}
@jeroen
jeroen / fft.R
Last active April 1, 2021 14:18
Example of FFT in R (because I always forget)
# Sampling frequency and audio length
freq <- 400
duration <- 5
# radian constant for sin/cos
tau <- 2*pi
# Generate a composite signal (4, 6, 9 hz)
x <- seq(0, duration, length.out = freq*duration)
y <-
@jeroen
jeroen / v8-wasm.cpp
Created September 29, 2019 18:47
Run wasm in V8 version 7.7
#include <v8.h>
#include <libplatform/libplatform.h>
using v8::HandleScope;
using v8::Isolate;
using v8::MemorySpan;
using v8::WasmModuleObject;
using v8::Context;
using v8::Local;
using v8::Value;
@jeroen
jeroen / wasm.R
Created September 15, 2019 05:24
wasm in R
library(V8)
ctx <- v8()
ctx$eval("
let bytes = new Uint8Array([
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x07, 0x01,
0x60, 0x02, 0x7f, 0x7f, 0x01, 0x7f, 0x03, 0x02, 0x01, 0x00, 0x07,
0x07, 0x01, 0x03, 0x61, 0x64, 0x64, 0x00, 0x00, 0x0a, 0x09, 0x01,
0x07, 0x00, 0x20, 0x00, 0x20, 0x01, 0x6a, 0x0b
]);
let module = new WebAssembly.Module(bytes);