Skip to content

Instantly share code, notes, and snippets.

View JosiahParry's full-sized avatar
🕵️‍♂️
sleuthing data

Josiah Parry JosiahParry

🕵️‍♂️
sleuthing data
View GitHub Profile
@JosiahParry
JosiahParry / attachments.md
Created July 3, 2024 18:28
working with attachments in arcgislayers
# install the development version
# install.packages("pak")
# pak::pak("r-arcgis/arcgislayers")
library(pillar)

# for authorizing to your portal
library(arcgisutils)
#> 
#> Attaching package: 'arcgisutils'
@JosiahParry
JosiahParry / keybindings.json
Created June 27, 2024 21:46
Positron Keybindings
// Place your key bindings in this file to override the defaults
[
{
"key": "shift+cmd+b",
"command": "workbench.action.tasks.runTask",
"args": "Build R package",
"when": "isRPackage"
},
{
"key": "shift+cmd+enter",
@JosiahParry
JosiahParry / shrink.R
Created May 9, 2024 15:17
Draft of a script that removes all sorts of stuff from vendored rust crates to reduce size
#!/usr/bin/env Rscript
# we need to vendor the dependencies and then store the checksum
rextendr::vendor_pkgs()
# make the checksum
# writeLines(
# tools::md5sum("src/rust/vendor.tar.xz"),
# "./tools/vendor.md5"
# )
@JosiahParry
JosiahParry / Cargo.toml
Created April 28, 2024 18:47
Parse JSON files using only Rust.
[package]
name = "json-parser"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = { version = "1.0.199", features = ["derive"] }
serde_json = "1.0.116"
@JosiahParry
JosiahParry / Dockerfile
Last active April 19, 2024 14:55
fast UUID replacement
FROM python:3.9-bookworm
ENV R_VERSION=4.3.3
# Install from Posit binaries
# https://docs.posit.co/resources/install-r/#verify-r-installation
RUN apt-get update && \
apt-get install -y gdebi-core curl && \
curl -O https://cdn.rstudio.com/r/debian-12/pkgs/r-${R_VERSION}_1_amd64.deb && \
gdebi -n r-${R_VERSION}_1_amd64.deb && \
@JosiahParry
JosiahParry / single-page-pkg-doc.R
Created April 14, 2024 16:13
Create a single page function reference using base R and quarto.
# Current limitation is that the images that are used are relative to the
# package lib.loc / help so what might be idea lis to extract the image
# and base64 encode them using {b64}
pkg_to_quarto_doc <- function(pkg, out_path = paste0(pkg, ".qmd"), ...) {
tmp <- tempfile()
base_doc <- tools::pkg2HTML(pkg, out = tmp, ...)
# read in html
og <- rvest::read_html(tmp)
@JosiahParry
JosiahParry / lib.rs
Created April 5, 2024 15:03
1brc using DataFusion and extendr for R API
[package]
name = 'tst2'
publish = false
version = '0.1.0'
edition = '2021'
[lib]
crate-type = [ 'staticlib' ]
name = 'tst2'
@JosiahParry
JosiahParry / app.R
Created April 4, 2024 20:49
Install the development version of {calcite} with `pak::pak("r-arcgis/calcite")`.
library(shiny)
library(calcite)
# Custom script and style ------------------------------------------------
custom_style <- "
.card-container {
margin: 0.75rem;
display: grid;
@JosiahParry
JosiahParry / vacc-simd.rs
Created April 2, 2024 16:16
Recreating the vacc function with simd from advanced R. This isn't very well done. It only returns in multiples of 4. This is probably because of `array_chunks::<4>()`. Its surprisingly slower than anticipated?
#![feature(portable_simd)]
#![feature(array_chunks)]
#[extendr]
fn vacc(age: &[f64], female: &[u8], ily: &[f64]) -> Vec<f64> {
age.array_chunks::<4>()
.map(|&a| f64x4::from_array(a))
.zip(female.array_chunks::<4>().map(|&f| u8x4::from_array(f)))
.zip(ily.array_chunks::<4>().map(|&i| f64x4::from_array(i)))
.map(|((a, f), i)| {
@JosiahParry
JosiahParry / send-text.R
Created April 2, 2024 00:54
Send a text using R from a Mac with iMessage
send_text <- function(message, buddy){
for(i in buddy){
system(paste('osascript -e \'tell application "Messages"\' -e \'send "', message, '" to buddy', i, 'of (service 1 whose service type is iMessage)\' -e \'end tell\''))
}
}