Skip to content

Instantly share code, notes, and snippets.

View MichaelChirico's full-sized avatar

Michael Chirico MichaelChirico

View GitHub Profile
@MichaelChirico
MichaelChirico / calculate_counterfactuals.py
Last active July 9, 2026 23:56
Counterfactual handling of .po/.pot source references
#!/usr/bin/env python3
"""
calculate_counterfactuals_v7_master.py
100% Full-Fidelity Counterfactual Replay of `po/` and `src/library/*/po` Commit History.
Implements all four final reproducibility recommendations to achieve ultimate speed, safety, and exactitude:
1. Eliminated 20-Minute AST Bottleneck (`blob_ast_cache[sha]`): Parses each of the 24,171 unique historical
blobs exactly ONCE into `blob_ast_cache[sha]` during batch loading. Total AST parsing time across all
4 scenarios (`194,000` evaluations) drops from ~15 minutes down to ~3 seconds.
2. RAMdisk Inode/Memory Protection (1,000-Pair Batches): Processes modifications in batches of `1,000 commit pairs`
@MichaelChirico
MichaelChirico / po_vcs_investigation
Last active July 8, 2026 18:02
.po VCS investigation
library(RSQLite)
git_repo <- "~/git/r-svn"
svn_repo <- "~/svn/r-devel"
if (!dir.exists(file.path(git_repo, ".git"))) {
stop(sprintf("Error: Git repository not found at '%s'. Please provide a valid git repo path as arg 1.", git_repo))
}
Sys.setlocale("LC_ALL", "C")
@MichaelChirico
MichaelChirico / sort_unique_benchmark.R
Created July 6, 2026 19:27
Benchmark script for comparing sort(unique()) and unique(sort())
library(bench)
library(dplyr)
library(tidyr)
run_benchmark_pair <- function(N, type, uniqueness, na_ratio = 0, nan_ratio = 0) {
cat(sprintf("Running: N=%d, type=%s, uniqueness=%s, na=%f, nan=%f\n", N, type, uniqueness, na_ratio, nan_ratio))
# Generate data
if (uniqueness == "high") {
num_unique <- N
@MichaelChirico
MichaelChirico / sort_unique_report.md
Created July 6, 2026 19:25
Comparing unique(sort()) and sort(unique())

Audit Report: sort(unique(x)) vs unique(sort(x))

Objective

Provide a secondary audit of the performance claims regarding sort(unique(x)) vs unique(sort(x)). We compare these two expressions across various input sizes, data types, and presence/absence of missing values (NA / NaN).

Methodology

Benchmarks were performed using the bench package in R. We tested the following parameters:

  • Vector Sizes ($N$): $10^3$, $10^4$, $10^5$, $10^6$.
@MichaelChirico
MichaelChirico / load_unload_loop.R
Last active June 1, 2026 21:53
revdep check for Bugzilla#19079
# nolint start: line_length_linter, object_name_linter.
library(methods)
# Setup paths
myLib <- normalizePath("myLib")
# Read scan results to get all unique matched packages
results_data <- readRDS("s4_scan_results.rds")
all_pkgs <- unique(sapply(strsplit(sapply(results_data, `[[`, "package"), "_"), `[`, 1))
@MichaelChirico
MichaelChirico / validate_wilcox_rank.R
Created May 10, 2026 20:53
Validate check of digits.rank
# This script creates two dummy packages to prove that the binary search evaluation
# correctly identifies packages that fail when digits.rank is set too low.
# -- Create dummy3 --
# This package expects wilcox.test(c(1.11, 2.22), c(1.14, 2.25))$statistic to be exactly 1.
# This assertion fails at digits.rank=1 and 2, but passes at digits.rank >= 3.
dir.create("dummy3/R", recursive = TRUE, showWarnings = FALSE)
dir.create("dummy3/tests/testthat", recursive = TRUE, showWarnings = FALSE)
writeLines(c(
@MichaelChirico
MichaelChirico / cran_wilcox_rank.R
Last active May 10, 2026 20:50
Search CRAN packages for senstivity to wilcox.test(digits.rank=X)
# Assume these are installed in a state to pass R CMD check, i.e.,
# with enough Suggests to pass with _R_CHECK_FORCE_SUGGESTS_=false
packages <- c("cardx", "caTools", "clintools", "cogmapr", "CRMetrics", "EasyDescribe",
"effectsize", "EnvStats", "eyetrackingR", "ggpubr", "ggpval", "ggsignif",
"gtsummary", "iCellR", "iDOS", "jsmodule", "LGDtoolkit", "microeco",
"mnda", "mt", "PairedData", "pairwiseCI", "papeR", "pctax", "pcutils",
"PLEXI", "plotbb", "plotthis", "PopComm", "qPCRtools", "RadOnc",
"rattle", "rbiom", "Rcmdr", "RcmdrPlugin.MPAStats", "rcompanion",
"rempsyc", "ReporterScore", "SCpubr", "sigminer", "tinyarray",
"TOSTER", "UCSCXenaShiny", "voiceR", "volcano3D")
@MichaelChirico
MichaelChirico / units_udunits_no_exceptions_crash.sh
Created December 16, 2025 20:19
units crashes if udunits compiled with -fno-exceptions
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status.
# --- 1. Environment Setup ---
echo ">>> Installing System Dependencies..."
sudo apt-get update -qq
# Dependencies:
# - flex/bison: for udunits parser compilation
# - texinfo: for udunits documentation
# - libexpat1-dev: for udunits XML parsing
@MichaelChirico
MichaelChirico / methods_load_unload.R
Last active November 16, 2025 02:48
Check load/unload loop for methods downstreams
cran_repo = "https://cloud.r-project.org"
bioc_repo = BiocManager::repositories()["BioCsoft"]
cran_db <- data.frame(available.packages(repos = cran_repo))
bioc_db <- data.frame(available.packages(repos = bioc_repo))
methods_importers <- function(db, skip) db |>
subset(
grepl("(^|[^\\w.])methods($|[^\\w.])", Imports, perl=TRUE),
"Package",
@MichaelChirico
MichaelChirico / methods_load_unload.R
Created November 7, 2025 15:38
{methods} load+unload loop test
db <- data.frame(available.packages())
methods_imports <- db |>
subset(grepl("(^|[^\\w.])methods($|[^\\w.])", Imports, perl=TRUE), "Package", drop=TRUE)
test_lib = '/media/WesternDigital3839/tmpCRAN'
# very slow, and requires some iteration to get SystemRequirements
install.packages(methods_imports, lib=test_lib)