Skip to content

Instantly share code, notes, and snippets.

View Protonk's full-sized avatar
🗯️
Après moi, la brisure

Adam Hyland Protonk

🗯️
Après moi, la brisure
View GitHub Profile
@Protonk
Protonk / number.csv
Created March 21, 2026 00:27
Numbers
kind display_name q p_num q_den layer_dependent min_depth max_depth tol dyadic_bits n_digits split_counts sequence runs_at_max_depth elapsed
uniform_x uniform 3 1 2 False 3 7 1e-10 20 4 [0, 2, 4, 4] 1.0244 9 0.012370109558105469
geometric_x geometric 3 1 2 False 3 7 1e-10 20 4 [1, 1, 2, 0] 1.1120 2 0.0012631416320800781
harmonic_x harmonic 3 1 2 False 3 7 1e-10 20 4 [2, 1, 1, 0] 1.2110 2 0.0012788772583007812
mirror_harmonic_x mirror-harmonic 3 1 2 False 3 7 1e-10 20 4 [2, 2, 1, 5] 1.2215 11 0.0025589466094970703
ruler_x ruler 3 1 2 False 3 7 1e-10 20 4 [0, 2, 5, 4] 1.0254 7 0.0023572444915771484
sinusoidal_x sinusoidal 3 1 2 False 3 7 1e-10 20 4 [1, 3, 2, 1] 1.1321 3 0.0012438297271728516
chebyshev_x chebyshev 3 1 2 False 3 7 1e-10 20 4 [1, 0, 0, 0] 1.1000 2 0.0012700557708740234
thuemorse_x thue-morse 3 1 2 False 3 7 1e-10 20 4 [0, 2, 2, 3] 1.0223 7 0.0016057491302490234
bitrev_geometric_x bitrev-geometric 3 1 2 False 3 7 1e-10 20 4 [1, 2, 1, 3] 1.1213 7 0.0028460025787353516
@Protonk
Protonk / day_happy.m
Created March 17, 2026 01:25
The FRSR in Day (2023)
% Compact "happy path" for the classic FRSR exponent x^(-1/2),
% from "Generalising the Fast Reciprocal Square Root Algorithm"
% (arXiv:2307.15600).
% 1. Pseudolog and inverse.
% The IEEE-754 float bit-pattern of x approximately encodes log2(x).
% Day's pseudolog makes that precise:
% L(x) = floor(log2 x) + x * 2^{-floor(log2 x)} - 1.
% It is piecewise linear on each octave [2^e, 2^(e+1)), agrees with log2
% at powers of two, and has an explicit inverse on each affine segment.
@Protonk
Protonk / readme.md
Created December 24, 2025 23:19 — forked from singe/readme.md
Quick 'n Dirty seatbelt/sandbox

macOS Seatbelt/Sandbox Trace Script

macOS sandbox profiles used to be able to include a trace command that would write all the denied operations to a sandbox profile, allowing a profile to be iterativley built up. Apple removed that functionality for reasons explained below.

trace.sh examines the kernel log for the denied operations and creates the relevant allow rules in a sandbox profile, just like the sandbox profile trace command used to.

shrink.sh tries to reduce a sandbox profile to the minimum lines necessary.

It's very rough and ready at the moment (check the sed regex'es in the script to see what I mean) and needs more testing with a wider set of use cases.

@Protonk
Protonk / sisr.R
Created December 11, 2024 18:20
Slow Inverse Square Root
## there are simpler ways to do this in R. See
## for example https://github.com/itchyny/fastinvsqrt/blob/main/src/r/fastinvsqrt.r
## contains a reasonable way to do this unreasonable thing.
## What follows is an unreasonable way to do an unreasonable thing.
doubleTofloatBits <- function(x) {
# Convert double to character in scientific notation
x_char <- format(x, scientific = TRUE)
# Parse the character representation
@Protonk
Protonk / kadlec-blend.R
Last active December 8, 2024 19:58
Kadlec plotting
### Compare original and adjusted values
library(dplyr)
library(ggplot2)
library(latex2exp)
## blends from standard form to original Kadlec constants
## A = 0.70395 & B = 2.38924
original_kadlec_blend <- read.csv(text = "
input,output,error,diff,iters,alpha
@Protonk
Protonk / NRkadlecplot.R
Last active December 5, 2024 21:19
Kadlec pools without converging
kadlec <- read.csv(text = "
reference,kadlec,iters,error,input
1.189297,1.189539,1,0.000242,0.707000
1.189297,1.162983,2,0.026314,0.707000
1.189297,1.173180,3,0.016117,0.707000
1.189297,1.169557,4,0.019740,0.707000
1.189297,1.170886,5,0.018411,0.707000
1.189297,1.170404,6,0.018893,0.707000
")
@Protonk
Protonk / interstate76-ShanePeelar.c
Created November 18, 2024 19:39
A version of Shane Peelar's discovered FISR in Interstate 76
// accepts a double and splits it, like KahanNg
// See https://inbetweennames.net/blog/2021-05-06-i76rsqrt/
// for more details and the original recovered code (in C++)
// It is different from KahanNg as it splits the double into
// exponent and mantissa, whereas KahanNg splits it into
// high 32 and low 32 bits
double i76ISR(double x, int NR) {
// Interstate76's lookup table generator
// uint8_t LUT[256];
// void generateLUT(){
@Protonk
Protonk / SMBDIS.ASM
Created November 13, 2024 04:58 — forked from 1wErt3r/SMBDIS.ASM
A Comprehensive Super Mario Bros. Disassembly
;SMBDIS.ASM - A COMPREHENSIVE SUPER MARIO BROS. DISASSEMBLY
;by doppelganger (doppelheathen@gmail.com)
;This file is provided for your own use as-is. It will require the character rom data
;and an iNES file header to get it to work.
;There are so many people I have to thank for this, that taking all the credit for
;myself would be an unforgivable act of arrogance. Without their help this would
;probably not be possible. So I thank all the peeps in the nesdev scene whose insight into
;the 6502 and the NES helped me learn how it works (you guys know who you are, there's no
@Protonk
Protonk / nanof2a.cpp
Created May 8, 2024 19:19 — forked from fpsunflower/nanof2a.cpp
Tiny float to ascii conversion (with lossless roundtrip, based on the Ryu algorithm)
// c++ -O3 -o nanof2a nanof2a.cpp && ./nanof2a
#include <cstdint>
#include <cstring>
namespace { // anonymous namespace to encourage inlining
struct f2a {
char str[16];
f2a(float f) { // example usage: printf("%s", f2a(f).str)
@Protonk
Protonk / allergen.R
Last active November 16, 2023 17:57
Allergy example
food.allergy.analysis.Zenodo <- read.csv("~/Downloads/food-allergy-analysis-Zenodo.csv")
allergyDF <- food.allergy.analysis.Zenodo[, c("SUBJECT_ID", "BIRTH_YEAR", "GENDER_FACTOR", "RACE_FACTOR", "ETHNICITY_FACTOR", "PAYER_FACTOR", "AGE_START_YEARS", "AGE_END_YEARS")]
allergyDF[, "SPAN_IN_YEARS"] <- with(food.allergy.analysis.Zenodo, AGE_END_YEARS - AGE_START_YEARS)
allergyDF[, "SOY_SPAN"] <- with(food.allergy.analysis.Zenodo, SOY_ALG_END - SOY_ALG_START)
allergyDF[, "MILK_SPAN"] <- with(food.allergy.analysis.Zenodo, MILK_ALG_END - MILK_ALG_START)
allergyDF[, "FISH_SPAN"] <- with(food.allergy.analysis.Zenodo, FISH_ALG_END - FISH_ALG_START)
allergyDF[, "SHELLFISH_SPAN"] <- with(food.allergy.analysis.Zenodo, SHELLFISH_ALG_END - SHELLFISH_ALG_START)