Skip to content

Instantly share code, notes, and snippets.

View nh2's full-sized avatar

Niklas Hambüchen nh2

View GitHub Profile
# This `firefox-vm.nix` builds a simple NixOS VM with XFCE and Firefox inside.
#
# Build and run it with:
#
# nix-build '<nixpkgs/nixos>' -A vm -I nixos-config=./firefox-vm.nix
# result/bin/run-nixos-vm
#
# Log in as "root" with empty password.
#
# To delete the VM state (storage):
@nh2
nh2 / gist:9e16ce512bd082075e4dcd86115b21bb
Created March 10, 2024 18:48
"fastboot getvar all" on submerged, repaired Google Pixel 4a that had stock Android on it
(bootloader) product:sunfish
(bootloader) serialno:17191JEC203691
(bootloader) variant:SM7 UFS
(bootloader) max-download-size:0x10000000
(bootloader) slot-suffixes:_a,_b
(bootloader) version-bootloader:s5-0.5-10252351
(bootloader) version-baseband:g7150-00112-230505-B-10075601
(bootloader) secure-boot:PRODUCTION
(bootloader) secure:yes
(bootloader) hw-revision:MP1.0
@nh2
nh2 / ceph-benaco.nix
Created January 19, 2024 18:33
Open-sourcing Benaco's NixOS Ceph service module
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.ceph-benaco;
inherit (pkgs.callPackage ../helpers.nix {}) ensureUnitExists;
in
@nh2
nh2 / example-output.txt
Created April 19, 2022 14:15
Process `ghc -v` output, summarising where time is spent.
# ./ghc-performance-categorizer.py ghci-v-output-1.txt --sort-by time
TASK time ms mem MB
------------------------------------------------
systool:cpp 4 2
systool:merge-objects 11 3
Simplify 38 68
ByteCodeGen 70 164
initializing 72 119
systool:as 175 68
@nh2
nh2 / mv-tree.py
Created January 23, 2022 07:18
Tool to move contents of one directory tree into another, safely.
#! /usr/bin/env python3
# Moves contents of one directory tree into another, safely.
import argparse
import filecmp
import shlex
import sys
from dataclasses import dataclass
@nh2
nh2 / mmap-memory-usage.c
Created December 7, 2020 19:43
Demo of how mmap() affects VIRT, RES, SHR memory usage in Linux
// Demo of how mmap() affects VIRT, RES, SHR memory usage in Linux.
//
// A useful resource for more background:
// https://techtalk.intersec.com/2013/07/memory-part-2-understanding-process-memory/
// Required for:
// * `O_TMPFILE`
// * `fallocate()`
#define _GNU_SOURCE
@nh2
nh2 / outlook-dkim.md
Created October 21, 2020 16:56
Outlook apparently cannot deterministically run DKIM

It seems Outlook is totally bugged.

I set up a mail server and sent 4 emails in a row, for the first one Microsoft said:

dkim=pass (signature was verified)

For the second one it said:

@nh2
nh2 / configuration.nix
Last active October 14, 2021 11:47
NixOS configuration for nh2's mail server presentation (https://nh2.me/recent/Running-your-own-mailserver.pdf)
# Edit this configuration file to define what should be installed on
# your system. Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).
{ config, pkgs, ... }:
let
floatingIPv4 = "95.216.183.106";
floatingIPv6 = "2a01:4f9:c01f:65::1";
in
{
@nh2
nh2 / SlopProblem.hs
Last active October 19, 2020 17:26
Repro for GHC making crazy amounts of slop with +RTS -N2, see https://gitlab.haskell.org/ghc/ghc/-/issues/18849
-- Run with:
-- ghc --make -O -threaded -fforce-recomp SlopProblem.hs && command time ./SlopProblem +RTS -N1 -s
--
-- My output with ghc 8.6.5 on a 4-core machine:
-- ...
-- 336,707,456 bytes maximum residency (14 sample(s))
-- 611,774,592 bytes maximum slop
-- ...
-- ... 1716344maxresident)k
-- The slop reduces to 1 MB when `-N1` is used, and the resident memory usage
@nh2
nh2 / texcoord-mutator.py
Last active August 20, 2020 21:57
Script to scale texture coordinates
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3Packages.plyfile
import argparse
import sys
import numpy as np
from plyfile import PlyData, PlyElement
parser = argparse.ArgumentParser(description='''