Skip to content

Instantly share code, notes, and snippets.

@decatur
decatur / who_is_talking.html
Last active November 10, 2025 11:50
Keeps monitoring talking time.
<!DOCTYPE html>
<html>
<head>
<style>
.time { padding: 1em }
/* https://developer.mozilla.org/de/docs/Web/CSS/Reference/Values/system-color */
.current { background-color: ActiveText !important; }
.speaker { margin: 1ex; padding: 1em; background-color: ButtonFace; }
</style>
</head>
@decatur
decatur / thread_as_task_or_service.rs
Created November 4, 2025 00:11
Threads can have task xor service semantics
use std::sync::mpsc::{Sender, Receiver};
use std::sync::mpsc;
use rayon::prelude::*;
fn main() {
let (tx, rx): (Sender<u8>, Receiver<u8>) = mpsc::channel();
// Thread as an event loop (service)
// Long lived
// May use messaging and shared state
std::thread::spawn(move || {
@decatur
decatur / presentation.typ
Last active October 16, 2025 22:54
typst presentation
#set page("presentation-4-3",
header: [#text("From MPA to SPA and Back", size: 12pt)],
margin: (top: 2cm, left: 3cm,)
)
#show heading: it => [
#set text(font: "Inria Serif")
#pagebreak()
#text(it.body)
#linebreak()
@decatur
decatur / template_engine.rs
Last active September 26, 2025 15:16
Rust minimal template engine
/// Minimal template string substitution in 60 lines of code.
/// * No dependencies
/// * Single pass
///
/// Possible improvements: Write more tests.
#[cfg(test)]
mod tests {
use crate::fill_template;
use std::collections::HashMap;
@decatur
decatur / iso8601.rs
Last active May 6, 2025 05:27
Parse ISO8601 date/times and validates against the proleptic Gregorian calendar with no dependencies and no_std compliant.
// Parse ISO8601 date/times and validates against the proleptic Gregorian calendar with no dependencies and no_std compliant.
//
// If you want to convert a parsed date into a unix timestamp, I recommend [tz-rs="0.7.0"](https://docs.rs/tz-rs/0.7.0) , which also has no dependencies.
//
// See also
// * https://docs.rs/iso8601/0.6.2/iso8601/
// * https://github.com/BurntSushi/jiff
/// Parses ISO8601 dates and validates against the proleptic Gregorian calendar.
/// Usage:
@decatur
decatur / why_getter_costs.rs
Last active January 2, 2025 14:57
With Rust we do not just use Getters and Setters.
// Do not use Getter/Setter without immediate benefits, see also https://news.ycombinator.com/item?id=42506984
// There are costs for abstraction and indirection.
// And in Rust, there is the borrow checker!
#[derive(Default)]
struct Strategy {
throughput: f64,
position: Vec<f64>,
}
@decatur
decatur / DeliveryTime.py
Last active November 19, 2024 09:47
DeliveryTime is a point in time Python abstraction aligned to a 1/4hour grid. TransactionTime is a point in time abstraction
from __future__ import annotations
from datetime import datetime, timedelta, time, tzinfo
from dateutil import tz
BERLIN = tz.gettz('Europe/Berlin')
class DeliveryTime:
"""
DeliveryTime is a point in time abstraction aligned to a ¼hour grid and
optimized for arithmetic operations.
@decatur
decatur / schema_evolution.rs
Last active September 6, 2024 09:08
Demonstrate Schema Evolution
//! # Demonstrate Schema Evolution in Rust
//! A structure must deserialized from several, possibly persistent, variants.
//!
//! ┌────────────────────────────────────────────┐
//! │ MyStruct │
//! └────────────────────────────────────────────┘
//! ▲ ▲ ▲ │
//! from from from into
//! │ │ │ ▼
//! ┌───────┐ ┌───────┐ ┌───────┐
@decatur
decatur / enum_container.rs
Created September 11, 2023 12:59
Example of a container using enum
/// https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=35d62d49d15756d1116d620099f324ae
/// Example of a container using enum.
use std::collections::HashMap;
use serde::Serialize;
#[derive(Debug, Serialize)]
struct PlantA {
id: String,
}
@decatur
decatur / object_safe.rs
Created September 11, 2023 12:56
trait is not object safe
#[derive(Clone)]
struct S;
fn main() {
let s
// Uncomment this line to provoke an "trait is not object safe" error
: Box<dyn Clone>
= Box::new(S);
let _ = s.clone();
}