Skip to content

Instantly share code, notes, and snippets.

View jdblischak's full-sized avatar

John Blischak jdblischak

View GitHub Profile
@jrosell
jrosell / async-json-api-plumber2-mirai-S7-DBI.R
Last active September 22, 2025 15:20
Example of an async JSON API in R using dbplyr, SQLite, S7, plumber2 and mirai.
stopifnot(requireNamespace("rlang"))
rlang::check_installed("pak")
pkgs <- rlang::chr(
"rlang" = "rlang",
"plumber2" = "posit-dev/plumber2",
"S7",
"jsonlite",
"httr2",
"mirai",
@t-kalinowski
t-kalinowski / build-r.sh
Last active August 13, 2025 21:30
Build R from source locally
#!/bin/bash
set -e # stop on error
cd ~/github/r-devel/r-svn
# reset
@nanxstats
nanxstats / foreach-rbind-benchmark.R
Last active March 25, 2025 15:53
Benchmark code comparing the performance of .combine = "rbind" vs. manual aggregation using data.table::rbindlist() in parallel foreach loops in R. Demonstrates significant speed improvements with manual aggregation.
library(doFuture)
plan(multisession, workers = 32)
options(scipen = 999)
anysvd <- function(id, dim = 10, nrep = 300) {
results <- vector("list", nrep)
for (j in 1:nrep) {
@nanxstats
nanxstats / cleanup-rproj-projectid.R
Last active February 10, 2025 15:01
Remove ProjectId field added by RStudio from .Rproj files at R startup
# Remove ProjectID from .Rproj files if freshly added
local({
xfun <- requireNamespace("xfun", quietly = TRUE)
rproj_files <- list.files(pattern = "\\.Rproj$", full.names = TRUE)
if (!xfun || length(rproj_files) == 0L) return(invisible(NULL))
lapply(rproj_files, function(f) {
diff_cmd <- system(paste("git diff --", shQuote(f)), intern = TRUE)
diff_out <- tryCatch(diff_cmd, error = function(e) character(0))
@JosiahParry
JosiahParry / r67.R
Created September 7, 2024 16:24
Experimentation with R6 and S7 hybrid. Allows for the creation of mutable objects with type-safe properties as well as self-referential methods.
# What do i want from an object oriented R class system?
# opt-in public immutability - neither. Accomplished with private property with active binding in R6
# interior mutability - R6
# type safety - S7
# self-referential methods - R6
# private methods don't have any type safety they can be whatever you want.
# immutables can only be set at creation and class doesn't matter
# Each .public & .private element must be named
# Top-level
thefuck <- function(e = rlang::last_error()) {
stopifnot(rlang::is_call_simple(e$call))
if (grep("^unused argument", e$message)) {
fix_unused_arg(e)
}
# ... more cases
}
# Internal methods
@defuneste
defuneste / mastodon_posit_conf.md
Last active August 21, 2024 17:30
list of mastodon users fromposit conf 2024
@nanxstats
nanxstats / simtrial-10k.tsv
Last active November 16, 2023 06:19
simtrial backend benchmark sketch
n 1 2 4 8 16
dplyr 5093.77 2671.44 1447.21 810.42 446.06
data.table 1336.79 677.94 364.5 217.75 143.95
@nanxstats
nanxstats / gsDesign-gource.sh
Created October 28, 2022 02:13
Shell commands to generate version control visualization video for gsDesign using gource
# Clone repo
git clone https://github.com/keaven/gsDesign.git
cd gsDesign
# Run gource - this will generate a 411GB ppm file
gource -3840x2160 --seconds-per-day 0.1 --auto-skip-seconds 0.01 --file-idle-time 0 --font-size 34 --key --logo man/figures/logo.png -o gsDesign.ppm
# Convert ppm to mp4
ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i gsDesign.ppm -vcodec libx264 -preset medium -pix_fmt yuv420p -crf 1 -threads 0 -bf 0 gsDesign.mp4
# Merge audio to video
ffmpeg -i gsDesign.mp4 -i music.mp3 -c:v copy -c:a aac output.mp4
# Recommended by YouTube
data(diamonds, package = "ggplot2")
# Most straightforward
diamonds$ppc <- diamonds$price / diamonds$carat
# Avoid repeating diamonds
diamonds$ppc <- with(diamonds, price / carat)
# The inspiration for dplyr's mutate
diamonds <- transform(diamonds, ppc = price / carat)