Skip to content

Instantly share code, notes, and snippets.

@Gro-Tsen
Gro-Tsen / cmdlines
Last active January 10, 2026 18:21
Fourier transform of a decagon and related images
gcc -o d10fourier d10fourier.c -O6 -Wall -std=c99 -pedantic -Wextra -lm -DTEN=10 -DPIC_WIDTH=1920 -DPIC_HEIGHT=1080 -DFRAME_COUNT=1440
parallel -j 8 ./d10fourier {} ::: $(seq 0 719)
ffmpeg -framerate 24 -i d10fourier-%04d.png -video_size 1920x1080 -c:v libx265 -preset slower -crf 27 -pix_fmt yuv420p d10fourier.mp4
gcc -o d14fourier d10fourier.c -O6 -Wall -std=c99 -pedantic -Wextra -lm -DTEN=14 -DPIC_WIDTH=1920 -DPIC_HEIGHT=1080 -DFRAME_COUNT=1440
parallel -j 8 ./d14fourier {} ::: $(seq 0 719)
ffmpeg -framerate 24 -i d14fourier-%04d.png -video_size 1920x1080 -c:v libx265 -preset slower -crf 27 -pix_fmt yuv420p d14fourier.mp4
@Gro-Tsen
Gro-Tsen / y-combinator-1-ocaml.txt
Created November 23, 2025 11:00
How to define recursive function calls in functional programming languages using Quine's trick (aka the ‘Y’ and ‘Z’ combinators): the same demo in OCaml (with recursive types), Python, and Scheme
$ ocaml -rectypes
OCaml version 4.13.1
# (* Initial version, with language recursion *)
let rec fib = fun n -> if n<=1 then n else fib(n-1)+fib(n-2) ;;
val fib : int -> int = <fun>
# (* Testing *)
List.map fib [0;1;2;3;4;5;6] ;;
- : int list = [0; 1; 1; 2; 3; 5; 8]
# (* Quine's trick: call this with itself as argument *)
@Gro-Tsen
Gro-Tsen / moebius-function-fourier.sage
Created November 17, 2025 08:15
Plot the Fourier transform of μ(n)/n
destdir = "."
nbsamp = 403200
fft = FastFourierTransform(nbsamp)
for i in range(nbsamp):
fft[i] = N(moebius(i)/i) if i>0 else 0
fft.forward_transform()
plot = list_plot([(N(i/nbsamp-1), N(fft[i][1])) for i in range(nbsamp)]+[(N(i/nbsamp), N(fft[i][1])) for i in range(nbsamp)], plotjoined=True, thickness=0.5, color="red") + list_plot([(N(i/nbsamp-1), N(fft[i][0])) for i in range(nbsamp)]+[(N(i/nbsamp), N(fft[i][0])) for i in range(nbsamp)], plotjoined=True, thickness=0.5)
plot.save(filename=(destdir+"/moebius.png"), dpi=192, aspect_ratio=0.4)
diff -r 62b30a28e7a4 dom/serializers/nsPlainTextSerializer.cpp
--- a/dom/serializers/nsPlainTextSerializer.cpp Mon Sep 08 11:49:04 2025 -0400
+++ b/dom/serializers/nsPlainTextSerializer.cpp Thu Oct 23 16:09:22 2025 +0200
@@ -108,11 +108,6 @@
void nsPlainTextSerializer::CurrentLine::MaybeReplaceNbspsInContent(
const int32_t aFlags) {
- if (!(aFlags & nsIDocumentEncoder::OutputPersistNBSP)) {
- // First, replace all nbsp characters with spaces,
- // which the unicode encoder won't do for us.
@Gro-Tsen
Gro-Tsen / age-difference-mortality.pl
Last active August 20, 2025 16:15
Compute probability that one person survives another
#! /usr/local/bin/perl -w
use strict;
use warnings;
# Get data from <URL: https://www.insee.fr/fr/statistiques/3311422?sommaire=3311425 >
# Typical plotting command (assuming output of this program is in "morta-hh.dat"):
# (echo 'set terminal pngcairo size 1000,800' ; echo 'set output "morta-hh.png"' ; echo 'set xrange [0:100]' ; echo 'set yrange [0:100]' ; echo 'set size square' ; echo 'set cbrange [0:1]' ; echo 'set palette defined ( 0 "black", 0.2 "#00FFFF", 0.4 "red", 0.5 "blue", 0.6 "green", 0.8 "#FF00FF", 1 "white" )' ; echo 'set title "Probabilité de survie ♂/♂"' ; echo 'set xlabel "Âge personne 1"' ; echo 'set ylabel "Âge personne 2"' ; echo 'set key title "Proba"' ; echo 'plot "morta-hh.dat" using ($1+0.5):($2+0.5):3 with image, [x=0:100] x lt rgb "black" notitle, [x=5:100] x-5 lt rgb "black" dashtype 2 notitle, [x=0:95] x+5 lt rgb "black" dashtype 2 notitle') | gnuplot
@Gro-Tsen
Gro-Tsen / fat-cantor-staircase.sage
Created June 11, 2025 14:46
Plot the staircase function (cumulative graph) of a fat Cantor set.
# Compute the cumulative measure function of a "fat" Cantor set (aka
# Smith-Volterra-Cantor set) with parameter alpha (meaning that
# 2^(k-1) intervals of length alpha^k are removed at the k-th stage of
# the construction.
alpha = 1/4
# Total measure of the fat Cantor set:
totmeas = N((1-3*alpha)/(1-2*alpha))
@Gro-Tsen
Gro-Tsen / triangle-conformal-map.sage
Last active June 6, 2025 10:52
Sage code to plot a conformal map
# Plot the conformal mapping taking the unit disk to the doubly ideal
# triangle having vertices 0, 1, i in the Poincaré disk model (with 1,
# i, -i being mapped to these three vertices). See
# https://mathoverflow.net/questions/495782/riemann-mapping-to-a-specific-curvilinear-triangle/495809#495809
# for details.
k = 2 * gamma(3/4)^2 / gamma(1/4)^2
kN = N(k)
var('z')
s(z) = k*sqrt(z) * hypergeometric([3/4,3/4],[3/2],z) / hypergeometric([1/4,1/4],[1/2],z)
@Gro-Tsen
Gro-Tsen / quine2.pl
Created May 12, 2025 16:33
A Perl program that prints a Python program that prints back this Perl program
#! /usr/bin/env perl
## This Perl program outputs a Python program that outputs this Perl
## program. The comments should hopefully make it clear how it all
## works and show that this there is nothing tricky going on.
## Written by David A. Madore on 2025-05-12. Public Domain
## See <http://www.madore.org/~david/computers/quine.html> for more on
## the art of writing quines without any tricks.
@Gro-Tsen
Gro-Tsen / table.pdf
Last active April 22, 2025 14:22
Satisfaction of some intuitionistic formulas for various Kripke frames
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@Gro-Tsen
Gro-Tsen / utf8_to_names.pl
Created March 28, 2025 11:32
Convert UTF-8 data to the plaintext numbers and names of Unicode characters
#! /usr/local/bin/perl -w
use strict;
my $unidata = "/usr/share/unicode/UnicodeData.txt" // $ENV{"UNIDATA"};
open F, "<", $unidata or die "Can't open $unidata";
my @unidata;
while (<F>) {
my @l = split /\;/;
my $n = hex($l[0]);