Skip to content

Instantly share code, notes, and snippets.

View mseri's full-sized avatar
Always with you with the MTGAP 2.0 keyboard layout

Marcello Seri mseri

Always with you with the MTGAP 2.0 keyboard layout
View GitHub Profile
profConradi /
Last active May 6, 2024 20:58
Chladni Square Plate Normal Modes Simulation
def energy(z, n, m, L):
return np.cos(n* np.pi *np.real(z) / L) *np.cos(m *np.pi*np.imag(z) / L) - np.cos(m*np.pi*np.real(z)/ L) *np.cos(n* np.pi *np.imag(z) / L)
class ChladniPlate:
def __init__(self, n, m, L=1, n_particles=10000):
self.L = L
self.n_particles = n_particles
self.n = n
self.m = m

Using dune-release to release OCaml packages

Originally written 2020-05-16

dune-release is a good improvement over the old opam-publish, but releasing software is still clearly not a solved problem, and I find it hard to remember the exact steps involved in releasing an opam package, especially if some time has passed since the last release. This note is an attempt at having a place

Leonidas-from-XIV /
Last active January 18, 2022 16:23
A way to use the `let` operators to short-circuit a `fold`
(* Some kind of function that needs to be [Some _] for the rest of the body *)
let bigger_than x v = match v > x with true -> Some (v - 1) | false -> None
(* Sample inputs *)
let xs = [ 0; 1; 2; 3; 4; 5; 6; 7; 8; 9 ]
(* Why `fold` here in the first place? Maybe your data structure doesn't have `filter_map` etc.
* This is an example
Jademaster /
Created September 28, 2021 16:47
Code that regards a picture as a weighted graph and finds the shortest paths which occur in a fixed number of steps.
import matplotlib.pyplot as plt
import numpy as np
import math
from PIL import Image
#this code takes a matrix M, regards it as a weighted graph where the entry M_ij indicates the weight between vertex i and vertex j. The free category on this graph is computed using the geometric series formula F(M) = Sum_{n geq 0} M^n with operations valued in the min plus semiring. The function freemetricspace(M,res) computes this formula to the first res terms. In words, this computes the shortest paths which occur in <= n steps.
#this function computes naive matrix multiplication in the min plus semiring
def mult(m1,m2):
assert (m1.shape[1] == m2.shape[0]), "shape mismatch"
rougier / style.css
Created June 23, 2021 10:00
Jupyter stylesheet
@import url(';400&family=Source+Code+Pro:wght@300;400&display=swap');
.rendered_html h1,
.rendered_html h2,
.rendered_html h3,
.rendered_html h4 {
color: #000099;
font-weight: 400;
// A URLSession extension that fetches data from a URL and decodes to some Decodable type.
// Usage: let user = try await URLSession.shared.decode(UserData.self, from: someURL)
// Note: this requires Swift 5.5.
extension URLSession {
func decode<T: Decodable>(
_ type: T.Type = T.self,
from url: URL,
keyDecodingStrategy: JSONDecoder.KeyDecodingStrategy = .useDefaultKeys,
dataDecodingStrategy: JSONDecoder.DataDecodingStrategy = .deferredToData,
dateDecodingStrategy: JSONDecoder.DateDecodingStrategy = .deferredToDate
hcarty /
Created April 21, 2021 20:41
Partial example for extracting a tar in memory using ocaml-tar
let max_ocaml_int = Int64.of_int max_int
let read_file input_channel (header : Tar_cstruct.Header.t) =
let file_size = header.file_size in
assert (file_size <= max_ocaml_int);
let buf = Cstruct.create (Int64.to_int file_size) in
Tar_cstruct.really_read input_channel buf;
let rec read_files input_channel accu =
dpiponi /
Created March 27, 2021 23:58
Branched flow with taichi
import math
import numpy as np
import random
import matplotlib.pyplot as plt
medium_size = 1024
x = np.linspace(-1., 1., medium_size)
y = np.linspace(-1., 1., medium_size)
x, y = np.meshgrid(x, y, indexing='ij')
module Trie = struct
type t = { mutable count : int; children : t option Array.t }
let[@inline] empty () = { count = 0; children = Array.make 128 None }
let add buf pos len t =
let rec loop idx t =
if idx > pos + len - 1 then t.count <- t.count + 1
let c = Char.lowercase_ascii (Bytes.get buf idx) in
tool_name: "ppxlib_driver",
include_dirs: [],
load_path: [
open_modules: [],
for_package: None,