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
@mseri
mseri / chladni.py
Created April 9, 2024 19:51 — forked from profConradi/chladni.py
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
@mseri
mseri / hatched.py
Created March 1, 2022 11:06
Hatched contourf plots in matplolib
# From https://github.com/matplotlib/matplotlib/issues/2789/#issuecomment-604599060
# Content as in example
# ------------------------------
import matplotlib.pyplot as plt
import numpy as np
# invent some numbers, turning the x and y arrays into simple
# 2d arrays, which make combining them together easier.
x = np.linspace(-3, 5, 150).reshape(1, -1)
y = np.linspace(-3, 5, 120).reshape(-1, 1)

How to setup a practically free CDN

I've been using [Backblaze][bbz] for a while now as my online backup service. I have used a few others in the past. None were particularly satisfactory until Backblaze came along.

It was - still is - keenly priced at a flat $5 (£4) per month for unlimited backup (I've currently got just under half a terabyte backed-up). It has a fast, reliable client. The company itself is [transparent about their operations][trans] and [generous with their knowledge sharing][blog]. To me, this says they understand their customers well. I've never had reliability problems and everything about the outfit exudes a sense of simple, quick, solid quality. The service has even saved the day on a couple of occasions where I've lost files.

Safe to say, I'm a happy customer. If you're not already using Backblaze, [I highly recommend you do][recommend].

Taking on the big boys with B2

@mseri
mseri / picam.swift
Last active December 10, 2021 08:56
Set resolution for the picamera, I use it to select the field of view, see https://picamera.readthedocs.io/en/release-1.12/fov.html
//
// picam.swift
// picam
//
// Created by Marcello Seri on 31/05/2021.
//
import Foundation
import AVFoundation
@mseri
mseri / branch.py
Created March 28, 2021 19:23 — forked from dpiponi/branch.py
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
else
let c = Char.lowercase_ascii (Bytes.get buf idx) in
@mseri
mseri / ppxed-source
Created September 10, 2019 06:59 — forked from Khady/ppxed-source
Use merlin to print an ocaml file after being processed by a ppx
#!/usr/bin/env sh
# A .merlin must be present nearby the file.
# With dune it can be generated by calling `dune build @check`.
FILE="$1"
ocamlmerlin single dump -what ppxed-source -filename "$FILE" < "$FILE" | jq -r '.value' | ocamlformat --name="$FILE" -
@mseri
mseri / sundials3.rb
Created August 23, 2019 23:05
Homebrew formula to install Sundials3 for sundialsml
class Sundials3 < Formula
desc "Nonlinear and differential/algebraic equations solver"
homepage "https://computation.llnl.gov/casc/sundials/main.html"
url "https://computing.llnl.gov/projects/sundials/download/sundials-3.2.1.tar.gz"
version "3.2.1"
sha256 "47d94d977ab2382cdcdd02f72a25ebd4ba8ca2634bbb2f191fe1636e71c86808"
revision 1
depends_on "cmake" => :build
depends_on "gcc" # for gfortran
open Matplotlib;;
let plot () =
let data = Mpl.plot_data `png in
ignore (Jupyter_notebook.display ~base64:true "image/png" data);;
let () =
Mpl.set_backend Agg;
Mpl.style_use "ggplot"
;;
@mseri
mseri / upgrade_opam_files.ml
Created November 23, 2018 12:40
Upgrade all opam files in the folder to opam2
(* requires opam-format and opam-state *)
let opam_files =
Sys.readdir "."
|> Array.to_list
|> List.filter (fun l -> match String.split_on_char '.' l with | _ :: ["opam"] -> true | _ -> false)
;;
let make_opam_file fname =
fname |> OpamFilename.of_string |> OpamFile.make