Skip to content

Instantly share code, notes, and snippets.

@Gro-Tsen
Gro-Tsen / communes.dat
Created April 27, 2024 18:13
Liste des communes de France avec coordonnées géographiques de leur barycentre et leur nom
This file has been truncated, but you can view the full file.
01001 46.153482/4.932753 L'Abergement-Clémenciat
01002 46.006821/5.427596 L'Abergement-de-Varey
01004 45.958184/5.374963 Ambérieu-en-Bugey
01005 45.995555/4.914269 Ambérieux-en-Dombes
01006 45.749037/5.593317 Ambléon
01007 46.002726/5.364199 Ambronay
01008 45.937040/5.331642 Ambutrix
01009 45.784362/5.655285 Andert-et-Condon
01010 45.909606/5.795569 Anglefort
01011 46.206625/5.656232 Apremont
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#ifndef M_PI
#define M_PI 3.14159265358979323846264338327950288419716939937511
#endif
#ifndef DEBUG
@Gro-Tsen
Gro-Tsen / num2english.pl
Created January 15, 2024 12:11
Numbers to text
#! /usr/local/bin/perl -w
# Convert a decimal number to its literal expression in English.
use strict;
use warnings;
use Getopt::Std;
my %opts;
getopts("u", \%opts);
@Gro-Tsen
Gro-Tsen / draw-binary-tree.pl
Created December 23, 2023 12:07
Draw the Stern-Brocot or dyadic tree
#! /usr/local/bin/perl -w
# Generate a graphical representation of either the Stern-Brocot or
# (with option -d) the dyadic tree on the interval [0,1].
# -- David A. Madore <http://www.madore.org/~david/> 2023-12-23
# Public Domain
use strict;
use warnings;
@Gro-Tsen
Gro-Tsen / pairing.hs
Created December 1, 2023 14:36
Closure-based pairs in various functional programming languages
-- (This is the Haskell version)
-- Define pairing and projection functions by storing values in a closure
let pairing = \x -> \y -> \f -> f x y
let proj1 = \p -> p (\x -> \y -> x)
let proj2 = \p -> p (\x -> \y -> y)
-- Conversion from and to native pairs
let fromnative = \(x,y) -> pairing x y
let tonative = \p -> p (\x -> \y -> (x,y))
let tonative_broken = \p -> (proj1 p, proj2 p)
-- This works as expected:
@Gro-Tsen
Gro-Tsen / cant.dot
Created November 13, 2023 17:04
Adjacency graph of French territorial divisions (in `graphviz` format)
graph cant {
c0101 [label="0101"];
c0104 [label="0104"];
c0101 -- c0104;
c0107 [label="0107"];
c0101 -- c0107;
c0110 [label="0110"];
c0101 -- c0110;
c0111 [label="0111"];
c0101 -- c0111;
sudo apt-get install postgresql-13-postgis-3 postgresql-13-postgis-3-scripts
createdb admin-express
sudo -u postgres psql -d admin-express -c 'CREATE EXTENSION postgis ;'
sudo -u postgres psql -d admin-express -c 'GRANT ALL ON TABLE public.spatial_ref_sys TO david ;'
## Go to <URL: https://geoservices.ign.fr/adminexpress >
## and download ADMIN-EXPRESS_3-2__SHP_LAMB93_FXX_2023-10-16.7z to /data/FTP
cd /data/tmp
7z x /data/FTP/ADMIN-EXPRESS_3-2__SHP_LAMB93_FXX_2023-10-16.7z
cd /data/tmp/ADMIN-EXPRESS_3-2__SHP_LAMB93_FXX_2023-10-16/ADMIN-EXPRESS/1_DONNEES_LIVRAISON_2023-10-16/ADE_3-2_SHP_LAMB93_FXX
ogr2ogr -f postgresql PG:"host=localhost dbname=admin-express" REGION.shp -nlt PROMOTE_TO_MULTI
@Gro-Tsen
Gro-Tsen / x.svg
Created July 24, 2023 09:48
Twitter's new logo that looks suspiciously like U+1D54F MATHEMATICAL DOUBLE-STRUCK CAPITAL X
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#### Plot of cumulative precipitations in France
## Input data: /tmp/precs.csv is expected to contain a list of daily
## precipitations in France (first column = date (unused), second
## column = precipiptations in mm/day). It can be produced from the
## data source described in <URL:
## https://twitter.com/gro_tsen/status/1620435663844970497 > by the
## following command line:
# perl -ne 'next if /^\#/; die unless /^([0-9]{8})\s+(\-?[0-9]+\.[0-9]+(?:[Ee](?:[+-]?[0-9]+))?)\s*$/; printf "%s,%.4f\n", $1,($2+0)' /data/meteo/climexp/iera5_prcp_daily_eu_France_metropolitan.dat > /tmp/precs.csv
19500101 0.0501
19500102 0.4288
19500103 4.4788
19500104 3.0397
19500105 1.0753
19500106 0.7376
19500107 0.0551
19500108 0.0924
19500109 1.5346
19500110 0.3256