Skip to content

Instantly share code, notes, and snippets.

View coolbutuseless's full-sized avatar

mikefc coolbutuseless

View GitHub Profile
@coolbutuseless
coolbutuseless / rotozoomer.R
Created December 26, 2024 04:51
Rotozoomer in base R using {nara}
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Load packages
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (FALSE) {
remotes::install_github('coolbutuseless/colorfast') # Need latest version
remotes::install_github('coolbutuseless/nara')
install.packages('governor')
install.packages('fastpng')
}
@coolbutuseless
coolbutuseless / func-pointers.R
Created October 24, 2024 22:58
Passing a function pointer through R
library(callme)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Code Segment 1
# 1. Define an 'adder()' function
# 2. Wrapper function to return the address of this function
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
code1 <- r"(
int adder(int x) {
# There is some explanation for why the bitwise operator functions do what they do here:
# https://inventwithpython.com/blog/2021/08/02/algorithmic-art-with-the-bitfielddraw-module/
# ignore the warnings, THIS IS ART!
library(ggplot2)
cols <- c("#b8e1c5", "#3ac9fb", "#fadacc","#fcb2c6",
"#002f88", "#fd7a5d","#00B850", "#091a22")
- - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
-
@coolbutuseless
coolbutuseless / render_pointcloud.R
Created September 27, 2024 10:24 — forked from wiesehahn/render_pointcloud.R
Example how to render pointclouds in R with rayrender
##___________________________________________________
##
## Script name: render_pointcloud.R
##
## Purpose of script:
## render forest plot pointcloud with raytracing
##
## Author: Jens Wiesehahn
## Copyright (c) Jens Wiesehahn, 2023
## Email: [email protected]
@coolbutuseless
coolbutuseless / deparse.R
Created June 26, 2024 22:47
Deparse summarises non-altrep integer vectors to a range
# remotes::install_github("multimeric/altrepr")
library(altrepr)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Create a long vector of consecutive INTEGER values
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int_vec_str <- sprintf("c(%s)", paste(5:(2^18), 'L', sep = '', collapse = ", "))
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@coolbutuseless
coolbutuseless / email.txt
Last active April 26, 2024 23:58
A proposed email to R-devel on connections
Subject: Clarificaiton requested on 'connections' interface.
Hi All,
I am confused on the status of being able to create custom connections in R.
The functions 'R_new_custom_connection()' and 'R_GetConnection()'
(defined in 'R_ext/Connections.h') are marked in 'sotools.c' as 'nonAPI'.
This would seem to indicate that it is not for use in packages as it will
@coolbutuseless
coolbutuseless / simplebenchmark-yyjsonr.R
Created January 17, 2024 21:43
rcppsimdjson simplebenchmark including yyjsonr
file <- system.file("jsonexamples", "twitter.json", package="RcppSimdJson")
jsontxt <- readLines(file)
res <- microbenchmark::microbenchmark(jsonify = jsonify::validate_json(jsontxt),
jsonlite = jsonlite::validate(jsontxt),
simdjson = RcppSimdJson::validateJSON(file),
ndjson = ndjson::validate(file),
RJSONIO = RJSONIO::isValidJSON(file),
yyjsonr = yyjsonr::validate_json_file(file),
@coolbutuseless
coolbutuseless / hey_rstats.R
Last active June 20, 2023 16:29
run dplyr commands verbally
library(carelesswhisper)
library(styler)
library(dplyr)
library(stringr)
ctx <- whisper_init()
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#' Record audio and convert to text
@coolbutuseless
coolbutuseless / wasm.Rmd
Created July 29, 2022 11:39
Toy WASM interpreter in R
---
title: "Toy WASM interpreter in base R"
author: "mikefc"
date: 2022-07-29T18:05:00+10:00
categories: ['Rstats']
tags: ["R"]
---
```{r, include = FALSE}
knitr::opts_chunk$set(