Skip to content

Instantly share code, notes, and snippets.

View JosiahParry's full-sized avatar
💻
on the 'puter

Josiah Parry JosiahParry

💻
on the 'puter
View GitHub Profile
library(ggplot2)
all_plots <- list()
m <- as.matrix(penguins[,3:6])
for (i in 1:ncol(m)) {
gg <- ggplot(penguins, aes(bill_len, m[,i])) +
geom_point() +
labs(title = sprintf("Column %i", i))
@JosiahParry
JosiahParry / app.R
Created September 29, 2025 18:09
preview portal feature services
# This should be in .Renviron
Sys.setenv("ARCGIS_HOST" = "your-portal-host")
Sys.setenv(
"ARCGIS_API_KEY" = "your-api-key"
)
library(arcgis)
set_arc_token(auth_key(key))
pub trait Coalesce {
type Item;
fn coalesce(self, other: Option<Self::Item>) -> Option<Self::Item>;
}
impl<T> Coalesce for Option<T> {
type Item = T;
fn coalesce(self, other: Option<T>) -> Option<T> {
self.or(other)
@JosiahParry
JosiahParry / backup-db.R
Created April 12, 2025 18:27
Backup a sqlite database using Rhttps://mastodon.social/@gvwilson/114316283939691522
library(RSQLite)
db_disk <- dbConnect(SQLite(), "/path/to/database.sqlite3")
db_mem <- dbConnect(SQLite(), ":memory:")
sqliteCopyDatabase(db_disk, db_mem)
library(shiny)
library(calcite)
library(htmltools)
library(arcgisutils)
# read in our sample dataset
earthquakes <- sf::st_read(
"https://github.com/R-ArcGIS/calcite/raw/refs/heads/main/dev/earthquakes.fgb"
)
@JosiahParry
JosiahParry / write-geoparquet.R
Created March 28, 2025 22:18
Creating GeoParquet for Google BigQuery
library(arrow)
library(geoarrow)
library(sf)
# following example here: https://geoarrow.org/geoarrow-r/index.html
nc <- read_sf(system.file("gpkg/nc.gpkg", package = "sf"))
tf <- tempfile(fileext = ".parquet")
# this creates a GeoParquet file
nc |>
@JosiahParry
JosiahParry / read-r-headers.R
Last active March 26, 2025 15:38
Read R’s C headers to identify where R functions are coming from
library(dplyr)
api <- as_tibble(tools:::funAPI())
# list all header files from include dir
header_files <- list.files(
R.home("include"),
full.names = TRUE,
recursive = TRUE,
@JosiahParry
JosiahParry / main.rs
Created March 15, 2025 16:52
Generate a random available user port in Rust
use rand::{rng, seq::SliceRandom};
use std::{
io::Result,
net::{IpAddr, SocketAddr, TcpListener, ToSocketAddrs},
vec::IntoIter,
};
pub struct RandomUserPort(std::ops::RangeInclusive<u16>);
impl RandomUserPort {
@JosiahParry
JosiahParry / list-all-files.R
Created February 9, 2025 19:36
Function to list all files based on globs, file names, and directories.
list_all_files <- function(include = "*") {
# list all files in the current directory recursing
all_files <- fs::dir_ls(recurse = TRUE, all = TRUE, type = "any")
# Identify directory patterns explicitly mentioned
matched_dirs <- include[fs::dir_exists(include)]
# Get *all* files inside matched directories
extra_files <- unlist(
lapply(
@JosiahParry
JosiahParry / gist:539f343bc8b17ed1396fcee5ae5cc346
Created January 18, 2025 19:53
API done 2 wayys ambiorix vs plumber
app <- ambiorix::Ambiorix$new()
app$post("/process", function(req, res) {
body <- yyjsonr::read_json_raw(req$rook.input$read())
msg <- sprintf(
"Hello, %s! Your age is %i, and your email is %s.",
body[["name"]], body[["age"]], body[["email"]]
)
res$json(list(message = msg, status = "success"))
})