Skip to content

Instantly share code, notes, and snippets.

@nmattia
nmattia / notch.slang
Last active October 19, 2026 11:33
Kitty Notch Shader
#language slang 2026
// Copyright (C) 2026 Nicolas Mattia <nicolas at nmattia.com>
//
// Bend the top part of the terminal to display around the notch. Only meaningful in full screen.
//
// Install by saving this file as `shaders/notch.slang` in your KITTY_CONFIG_DIRECTORY.
//
// Create `shaders/notch-custom.pipeline` with the following content, adjusted for your notch dimensions
// if necessary (as a proportion of total display):
@nmattia
nmattia / hunt.sh
Last active June 12, 2026 12:57
Hunt down bazel build reproducibility issues
#!/usr/bin/env bash
# Reproducibility "hunt": build a target several times, each in a fresh checkout
# under an output base nested one level deeper than the last, so the absolute
# build path differs between runs the way it would between machines. Then diff
# the execution logs; any output whose content digest differs is non-reproducible.
#
# usage:
# ./hunt [--root ROOT] [--startup-options OPTS] [--build-options OPTS] [--runs N] TARGET
@nmattia
nmattia / Cargo.toml
Created November 12, 2025 21:17
Rust snake game for charlieplexed display on flipper zero
[package]
name = "flipperzero-charlieplex"
version = "0.0.1"
edition = "2021"
[dependencies]
flipperzero = { version = "0.15.0", features = ["alloc"] }
flipperzero-sys = { version = "0.15.0" }
flipperzero-rt = { version = "0.15.0" }
rand_core = "0.9.3"
@nmattia
nmattia / oled.py
Created August 17, 2025 15:34
Displaying pixels for an OLED display (128x32) in the terminal using Kitty graphics protocol
# Run with:
# $ podman run --platform linux/amd64 --rm -it -v $PWD:/remote micropython/unix micropython /remote/oled.py
import sys
from binascii import b2a_base64
import framebuf
BPP = 3 # BYTES per pixel
@nmattia
nmattia / netlify-edge-basicauth.ts
Created December 6, 2023 10:30
Netlify Edge Function Basic Auth authorization
import type { Config, Context } from "@netlify/edge-functions";
// https://datatracker.ietf.org/doc/html/rfc7617
// base64 encoded "user:pass"
const USER_PASS_ENCODED = "dXNlcjpwYXNz";
export default async (request: Request, context: Context) => {
const requestAuthentication = () => {
const response = new Response(null, {
status: 401,
@nmattia
nmattia / netlify-edge.ts
Created December 6, 2023 09:52
Netlify Edge Function for token-based website access (using cookie)
// On first access looks up a search param: `?token=...`
// If the token is valid, saves it in cookies so that
// subsequent requests don't need the search param.
import type { Config, Context } from "@netlify/edge-functions";
// Ideally look up from the environment
const EXPECTED_TOKEN = "very-secret";
const TOKEN_COOKIE_NAME = "my-token";
const TOKEN_HEADER_NAME = "x-my-token";
import { TemplateResult } from "lit-html";
type Render = (tpl: TemplateResult) => void;
type Step<In, Out> = {
template: (args: {
next: (arg: Out) => void;
state: In;
back?: () => void;
}) => TemplateResult;
@nmattia
nmattia / gcc.patch
Last active January 4, 2023 10:42
Patch GCC's avr build to not try to write to the source tree
diff --git a/gcc/config/avr/t-avr b/gcc/config/avr/t-avr
index deadbeef..deadbeef 100644
--- a/gcc/config/avr/t-avr 2023-01-03 21:56:23
+++ b/gcc/config/avr/t-avr 2023-01-03 21:56:32
@@ -91,9 +91,6 @@
$(srcdir)/config/avr/avr-arch.h $(TM_H)
$(CXX_FOR_BUILD) $(CXXFLAGS_FOR_BUILD) $< -o $@ $(INCLUDES)
-$(srcdir)/doc/avr-mmcu.texi: gen-avr-mmcu-texi$(build_exeext)
- $(RUN_GEN) ./$< > $@
@nmattia
nmattia / .envrc
Created July 31, 2021 15:54
Dune: Uncomplicated Nix Environments
res=$(nix-build --no-link ./default.nix -A load)
watch_file ./default.nix
. "$res"
@nmattia
nmattia / foo.js
Last active February 24, 2020 20:59
rotating divs
let clientX_0 = 0;
let clientX_d = 0;
const MIN_WIDTH = 10;
const MIN_HEIGHT = 10;
let w0 = getpc("inner-width");
let h0 = getpc("inner-height");
let w = w0;