Skip to content

Instantly share code, notes, and snippets.

Avatar

Niklas Hambüchen nh2

View GitHub Profile
@nh2
nh2 / mmap-memory-usage.c
Created Dec 7, 2020
Demo of how mmap() affects VIRT, RES, SHR memory usage in Linux
View mmap-memory-usage.c
// 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 Oct 21, 2020
Outlook apparently cannot deterministically run DKIM
View outlook-dkim.md

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 Jun 16, 2021
NixOS configuration for nh2's mail server presentation (https://nh2.me/recent/Running-your-own-mailserver.pdf)
View configuration.nix
# 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 Oct 19, 2020
Repro for GHC making crazy amounts of slop with +RTS -N2, see https://gitlab.haskell.org/ghc/ghc/-/issues/18849
View SlopProblem.hs
-- 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 Aug 20, 2020
Script to scale texture coordinates
View texcoord-mutator.py
#! /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='''
@nh2
nh2 / ptgui-pro.nix
Last active Jul 7, 2020
Packaging PTGui with nix
View ptgui-pro.nix
# This is for installing ptgui conveniently via nix
# or into NixOS.
# Build using e.g.:
#
# nix-build -E '((import <nixpkgs> {}).callPackage (import ./ptgui-pro.nix) { })'
#
# and then run via
#
# result/bin/PTGui
#
@nh2
nh2 / nix-store-bup-benchmark.py
Created Jun 3, 2020
Small benchmark to deduplicate /nix/store into a bup repository
View nix-store-bup-benchmark.py
#! /usr/bin/env python3
import glob
import os
import subprocess
import sys
from itertools import zip_longest
# From https://stackoverflow.com/questions/434287/what-is-the-most-pythonic-way-to-iterate-over-a-list-in-chunks/434411#434411
def grouper(iterable, n):
@nh2
nh2 / nixos-install-hetzner-cloud.sh
Last active Oct 16, 2020
REPLACED BY https://github.com/nix-community/nixos-install-scripts/blob/master/hosters/hetzner-cloud/nixos-install-hetzner-cloud.sh (Script to install NixOS from the Hetzner Cloud NixOS bootable ISO image. Wipes the disk!)
View nixos-install-hetzner-cloud.sh
#! /usr/bin/env bash
# Script to install NixOS from the Hetzner Cloud NixOS bootable ISO image.
# Wipes the disk!
# Tested with Hetzner's `NixOS 20.03 (amd64/minimal)` ISO image.
#
# Run like:
#
# curl https://nh2.me/nixos-install-hetzner-cloud.sh | sudo bash
#
@nh2
nh2 / bench.sh
Created May 26, 2020
Compresstion/decompression benchmark between JPEG and WebP with ImageMagick
View bench.sh
set -e
set -x
echo "Cat"
wget --no-clobber 'https://homepages.cae.wisc.edu/~ece533/images/cat.png'
identify 'cat.png'
echo "Cat - 100%"
View leaseweb-dedicated-wipe-and-install-nixos.sh
#!/usr/bin/env bash
# Installs NixOS on a Leaseweb server, wiping the server.
#
# This is for a specific server configuration; adjust where needed.
# Originally written for a Leaseweb HP DL120 G7 server.
#
# Prerequisites:
# * Update the script to adjust SSH pubkeys, hostname, NixOS version etc.
#