Skip to content

Instantly share code, notes, and snippets.

@ollpu
ollpu / test2.py
Created October 11, 2019 12:32
Perspective matrix solver
#!/usr/bin/python3
import numpy as np
# Input
w, h = map(float, input("Framebuffer dimensions (W H): ").split())
point_human = ["top left", "top right", "bottom left", "bottom right"]
P = [list(map(float, input("Enter coordinates of {} point (x y): ".format(s)).split())) for s in point_human]
T = [(0, 0), (w, 0), (0, h), (w, h)]
# Compute
@ollpu
ollpu / persistent.md
Last active June 20, 2023 19:50
App state persistence system for Rust

The idea

This document presents a system for persistent application state management that

  • is based on COW trees
  • allows the user to freely define the structs that become nodes in the tree
  • can be relatively ergonomically used to construct a kind of reactive GUI that depends on the data
  • supports mutations from an arbitrary point without needing lenses or other macro-heavy solutions.

Similar systems that rely on lenses already exist, e.g. the Druid architecture. They are used because mutations

@ollpu
ollpu / spectrum.rs
Last active January 24, 2025 02:44
FFT spectrum example
use std::{f32::consts::PI, sync::Arc};
use realfft::{num_complex::Complex, RealFftPlanner, RealToComplex};
const N: usize = 1024;
const SR: f32 = 44100.;
pub struct Spectrum {
fft: Arc<dyn RealToComplex<f32>>,
real_buf: Vec<f32>,
@ollpu
ollpu / inline-footnotes.rs
Last active June 5, 2025 09:40
pulldown-cmark inline footnotes adapter POC
use std::io::Read;
use pulldown_cmark::{BrokenLink, CowStr, Event, LinkType, Options, Parser, Tag, TagEnd};
/// Collects events nested inside a pair of corresponding Start and End events
///
/// Assumes the Start event is already consumed. The End event will be consumed and discarded.
fn take_until_tag_end<'a>(
events: impl Iterator<Item = Event<'a>>,
) -> impl Iterator<Item = Event<'a>> {