Skip to content

Instantly share code, notes, and snippets.

Avatar

Niklas Hambüchen nh2

View GitHub Profile
@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.
#
View git-bug-colors.py
from colorama import Style, Fore, Back
components = [
'[q] Quit',
'[s] Search',
'[←↓↑→,hjkl] Navigation',
'[↵] Open bug',
'[n] New bug',
'[i] Pull',
'[o] Push',
@nh2
nh2 / 18.03.txt
Last active Apr 10, 2020
LeaseWeb DL120 G7 NixOS systemd network interface naming
View 18.03.txt
# udevadm info /sys/class/net/eno1
P: /devices/pci0000:00/0000:00:1c.5/0000:03:00.0/net/eno1
E: DEVPATH=/devices/pci0000:00/0000:00:1c.5/0000:03:00.0/net/eno1
E: ID_BUS=pci
E: ID_MODEL_FROM_DATABASE=82574L Gigabit Network Connection (NC112i 1-port Ethernet Server Adapter)
E: ID_MODEL_ID=0x10d3
E: ID_NET_LABEL_ONBOARD=enNIC Port 2
E: ID_NET_NAME_MAC=enxe83935edad4b
E: ID_NET_NAME_ONBOARD=eno1
E: ID_NET_NAME_PATH=enp3s0
@nh2
nh2 / git-rebase-onto-for-switching-target-branches.md
Last active Apr 3, 2020
`git rebase --onto` for switching target branches
View git-rebase-onto-for-switching-target-branches.md

git rebase --onto for switching target branches

Git rebase with --onto implements the idea:

cut and paste from start commit B to end commit E and put it "onto" commit O.

nixpkgs example

If you have a situation where somebody made a somebranch PR against master but it should have been against another branch, like this:

@nh2
nh2 / nix-env-flags-deduper.py
Created Feb 13, 2020
Hack to work around nix duplicate -L flags causing `argument list too long` for GCC, see https://github.com/NixOS/nixpkgs/issues/41340
View nix-env-flags-deduper.py
#!/usr/bin/env python3
# Script to deduplicate linker flags in nix variables.
# Workaround for:
# https://github.com/NixOS/nixpkgs/issues/41340
#
# This is obviously a hack and it should be fixed in nixpkgs.
#
# Usage (from bash to update env vars in the current shell context):
# eval <(nix-env-flags-deduper.py)
@nh2
nh2 / Typechecking-git-history-fast.md
Created Jan 16, 2020
Haskell: Type-checking a git history of commits fast with interactive rebasing and ghci -e
View Typechecking-git-history-fast.md

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 / detect-nix-sandbox.md
Last active Jan 16, 2020
How to determine if the nix sandbox is in effect on a system
View detect-nix-sandbox.md

How to determine if the nix sandbox is in effect on a system

Do the same as the nix-info script, which nix-builds this file and inspects the exit code.

Short version:

nix-build --no-out-link -E 'import <nixpkgs/pkgs/tools/nix/info/multiuser.nix>' 2> /dev/null
@nh2
nh2 / Squashing commits on a branch including merges while retaining some individual commits.md
Created Jan 8, 2020
git: Squashing commits on a branch including merges while retaining some individual commits
View Squashing commits on a branch including merges while retaining some individual commits.md

Initial state

We want to squash the v commits in

v1
v2
v3
k1
k2
@nh2
nh2 / nixpkgs-duplicity-test-gpg-errors.txt
Created Dec 16, 2019
duplicity tests gpg invocations fail with double free or corruption (out) on nix-review for https://github.com/NixOS/nixpkgs/pull/73315
View nixpkgs-duplicity-test-gpg-errors.txt
% NIX_PATH=nixpkgs=. /usr/bin/time nix-build --no-link -A duplicity
these derivations will be built:
/nix/store/73in6wzsqzpsi6k4y4x2qqi3az9rnkff-duplicity-0.7.19.drv
building '/nix/store/73in6wzsqzpsi6k4y4x2qqi3az9rnkff-duplicity-0.7.19.drv' on 'ssh://static-haskell-nix-ci'...
copying path '/nix/store/75c1irykc5r095djhxhnxrj9r0s0gph7-1359.2.3' from 'https://cache.nixos.org'...
copying path '/nix/store/lcckqzhp6khmzb9833frnh47g7fsjgik-1359.2.2' from 'https://cache.nixos.org'...
copying path '/nix/store/srgh1frvgvz141rish0pyjn520rgff38-1359.2.1' from 'https://cache.nixos.org'...
copying path '/nix/store/q8mapr5b3z26h7hackmnsk3sirjxqcq8-duplicity-0.7.19.tar.gz' from 'https://cache.nixos.org'...
copying path '/nix/store/g2za9nam04lpb5h8s7dd0y51r3lg75x6-gnutar-in-test.patch' from 'https://cache.nixos.org'...
copying path '/nix/store/ijvka0qiq3c7sk19sgs1mvm49qwpzgpl-python2.7-pyOpenSSL-19.0.0' from 'https://cache.nixos.org'...