Skip to content

Instantly share code, notes, and snippets.

View nh2's full-sized avatar

Niklas Hambüchen nh2

View GitHub Profile

Using postgresql 10 on a spinning disk.

Table layout

postgres=# \d+ t;
                                                 Table "public.t"
  Column  |  Type   | Collation | Nullable |            Default            | Storage  | Stats target | Description 
----------+---------+-----------+----------+-------------------------------+----------+--------------+-------------
 id       | integer |           | not null | nextval('t_id_seq'::regclass) | plain    |              | 
@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 / 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
#!/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.
#
@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='''
@nh2
nh2 / ptgui-pro.nix
Last active July 7, 2020 20:24
Packaging PTGui with 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 / Typechecking-git-history-fast.md
Created January 16, 2020 17:40
Haskell: Type-checking a git history of commits fast with interactive rebasing and ghci -e

Type-checking your whole Pull Request before submission

You want to make a pull request to a Haskell project, which requires that each commit in your PR compiles fine individually.

Here is an easy, automated and fast way to check it:

git rebase --interactive HEAD~~~ --exec "! grep 'error:' <(stack ghci mylibrary:lib --ghci-options='-e 1' 2>&1)"
@nh2
nh2 / nix-store-bup-benchmark.py
Created June 3, 2020 12:19
Small benchmark to deduplicate /nix/store into a bup repository
#! /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 / bench.sh
Created May 26, 2020 11:37
Compresstion/decompression benchmark between JPEG and WebP with ImageMagick
set -e
set -x
echo "Cat"
wget --no-clobber 'https://homepages.cae.wisc.edu/~ece533/images/cat.png'
identify 'cat.png'
echo "Cat - 100%"
@nh2
nh2 / GenericsTypeName.hs
Last active May 5, 2020 15:21
Getting the name of a type with GHC.Generics
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
module GenericsTypeName
( TypeName(..)
, readBS
) where
import Data.ByteString (ByteString)