Skip to content

Instantly share code, notes, and snippets.

View carbocation's full-sized avatar

James Pirruccello carbocation

View GitHub Profile
@carbocation
carbocation / openfoam.md
Last active May 23, 2026 21:55
Installing OpenFOAM on Apple Silicon macOS without docker

Native OpenFOAM v2512 On Apple Silicon macOS

This guide describes how to compile OpenFOAM v2512 natively on Apple Silicon macOS without Docker. The build described here produced native arm64 OpenFOAM binaries using Homebrew GCC and OpenMPI.

Overview

The main macOS-specific issue is that OpenFOAM should be built on a case-sensitive filesystem. The default macOS APFS volume is normally case-insensitive, which can cause include collisions such as OpenFOAM's wchar.H versus the system wchar.h.

The approach is:

@carbocation
carbocation / auroc_from_r2.R
Last active September 16, 2025 04:07
Compute expected AUROC from R^2
#' Compute expected AUROC from R^2 under the liability-threshold model
#'
#' This function implements the closed-form approximation for AUROC given the
#' proportion of variance explained (R^2) on the liability scale and the disease
#' prevalence p. It attempts to follow the liability-threshold/binormal ROC
#' derivation of Wray et al. (2010), *The Genetic Interpretation of Area under
#' the ROC Curve in Genomic Profiling* (PLoS Genetics 6(2): e1000864).
#'
#' In their notation, h2_L (heritability on the liability scale) plays the same
#' mathematical role as the input R^2 here: the variance explained in the latent
@carbocation
carbocation / pelican-high.svg
Created December 22, 2024 16:29
the result of feeding a modification of simonw's pelican prompt to o1 pro
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@carbocation
carbocation / invnorm.R
Last active September 16, 2021 13:49
invnorm
# See Yang et al Nature 2012 https://www.nature.com/articles/nature11401
# supplement page 18
invnorm <- function(x) {
qnorm((rank(x, na.last="keep")-0.5)/sum(!is.na(x)))
}
@carbocation
carbocation / install-shairport-sync.md
Created July 10, 2021 01:02
Install shairport-sync on RPi

Simple Installation Instructions

Here are simple instructions for building and installing Shairport Sync on a Raspberry Pi B, 2B, 3B, 3B+ or 4B. It is assumed that the Pi is running Raspbian Buster Lite – a GUI isn't needed, since Shairport Sync runs as a daemon program. For a more thorough treatment, please go to the README.md page.

In the commands below, note the convention that a # prompt means you are in superuser mode and a $ prompt means you are in a regular unprivileged user mode. You can use sudo ("SUperuser DO") to temporarily promote yourself from user to superuser, if permitted. For example, if you want to execute apt-get update in superuser mode and you are in user mode, enter sudo apt-get update.

Configure and Update

Do the usual update and upgrade:

# apt-get update
@carbocation
carbocation / roundFormatC.R
Created June 21, 2021 21:14
Blends round() and formatC() for my specific needs.
roundFormatC <- function(x, digits) {
formatCDigits <- digits
if(digits <= 0) {
formatCDigits <- 0
}
formatC(round(x, digits), formatCDigits, format = "f")
}
@carbocation
carbocation / extreme-P.R
Last active December 16, 2023 21:50
Compute extreme P values from Z scores or T scores and degrees of freedom. Note: these are two-tailed (log(2) + ...) where two-tailed tests are appropriate. The Z and T functions can be run online at https://tools.carbocation.com/ExtremeP
# Via https://stackoverflow.com/a/46416222/199475
pvalue.extreme.z <- function(z) {
log.pvalue <- log(2) + pnorm(abs(z), lower.tail = FALSE, log.p = TRUE)
log10.pvalue <- log.pvalue/log(10) ## from natural log to log10
mantissa <- 10^(log10.pvalue %% 1)
exponent <- log10.pvalue %/% 1
return(list(mantissa=mantissa,exponent=exponent))
}
# Modified to the t-score approach from the Z-score based approach on https://stackoverflow.com/a/46416222/199475
@carbocation
carbocation / multi-face.ipynb
Created January 3, 2020 17:13 — forked from yang-zhang/multi-face.ipynb
Multi-task Deep Learning Experiment using fastai Pytorch
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@carbocation
carbocation / Fast.ai install script.py
Last active September 27, 2018 05:02 — forked from gilrosenthal/Fast.ai install script
Fast.ai Install on Google Colab
!pip install pathlib
!pip install fastai
!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python
import cv2
from os import path
from wheel.pep425tags import get_abbr_impl, get_impl_ver, get_abi_tag
platform = '{}{}-{}'.format(get_abbr_impl(), get_impl_ver(), get_abi_tag())
accelerator = 'cu80' if path.exists('/opt/bin/nvidia-smi') else 'cpu'
@carbocation
carbocation / Subtitle.go
Created July 13, 2018 14:35 — forked from bemasher/Subtitle.go
Subtitle decoder basic functionality written in Golang.
package main
import (
"io"
"os"
"fmt"
"log"
"bytes"
"image"
"image/png"