Skip to content

Instantly share code, notes, and snippets.

View nanxstats's full-sized avatar

Nan Xiao nanxstats

View GitHub Profile
@nanxstats
nanxstats / mlmodern-otf-woff2.sh
Last active February 20, 2026 15:52
Convert MLModern from Type 1 format to OTF and WOFF2
brew install fontforge
brew install woff2
curl -L http://mirrors.ctan.org/fonts/mlmodern.zip > mlmodern.zip
unzip mlmodern.zip
cd mlmodern/type1/
fontforge -lang=ff -c 'Open($1); Generate($1:r + ".otf")' mlmr12.pfb

EXTREMEZ and grid range analysis

Setup

library(gsDesign)

Grid range implied by r

@nanxstats
nanxstats / gsSurv.md
Last active January 28, 2026 18:29
gsSurv
  • R/gsSurv.R: gsnSurv(), gsSurv(), print.gsSurv()
  • R/gsSurvCalendar.R: gsSurvCalendar()
  • R/gsSurv-eEvents.R: eEvents1(), eEvents(), print.eEvents()
  • R/gsSurv-method.R: LFPWE(), KTZ(), KT()
  • R/gsSurv-nSurv.R: nSurv(), print.nSurv()
  • R/gsSurv-interim.R: tEventsIA(), nEventsIA()
  • R/gsSurv-utils.R: periods(), nameperiod()
  • R/gsSurv-xtable.R: xtable.gsSurv()
@nanxstats
nanxstats / floating-equal.R
Created November 20, 2025 18:16
Compare two floating point number equivalence testing methods
library(testthat)
# Method A: round to 6 significant digits, then compare with default tiny tolerance
equal_after_signif <- function(x, y) {
expect_equal(signif(x, digits = 6), signif(y, digits = 6))
}
# Method B: compare with relative/absolute tolerance = 1e-6
equal_with_tolerance <- function(x, y) {
expect_equal(x, y, tolerance = 1e-6)
@nanxstats
nanxstats / py-release-checklist.md
Last active January 2, 2026 07:39
Simple Release checklist for Python packages

Update environment

Code style

  • python scripts/verify_ascii.py

Update toolchain

  • rustup self update
  • rustup update stable
  • cargo update
  • cargo fetch

Code style

  • cargo fmt

Prepare

  • npm install
  • Make changes to source code
  • Run formatter and sort imports
  • Run tests (development workflow section in AGENTS.md)
  • Run manual tests (manual testing section in AGENTS.md)

Manifest

@nanxstats
nanxstats / release_checklist_nanxstats.md
Last active July 28, 2025 03:46
Nan's simple R package release checklist

First release

  • Proof read Title: and Description: and ensure they are informative
  • Check that all exported functions have @returns and @examples
  • Check that Authors@R: includes a copyright holder (role 'cph')
  • Review extrachecks
  • usethis::use_cran_comments() (optional)

Prepare for release

@nanxstats
nanxstats / iosevka-subset.sh
Created May 24, 2025 23:40
Subset Iosevka font for smaller file size
# <https://fdp.io/blog/2024-10-08-choosing-a-font/>
uv init fontsub
uv add fonttools
uv add brotli
pyftsubset "Iosevka-Extended.woff2" \
--output-file="Iosevka-Extended-subset.woff2" \
--flavor="woff2" \
--layout-features="*" \
@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) {