Skip to content

Instantly share code, notes, and snippets.

View klausbrunner's full-sized avatar

Klaus Brunner klausbrunner

  • Berlin/Munich/Vienna
View GitHub Profile
# quickly create large/very populated zip files for testing purposes, without taking up lots of disk space
dd if=/dev/zero bs=1m count=10k | zip -9 single-10g-file.zip -
dd if=/dev/urandom bs=1 count=20000 | split -b 1 -a 4 - test_ && zip -q -m 20k-tiny-files.zip test_*
# this ensures CD entries with the LFH offset in the ZIP64 EIEF:
dd if=/dev/zero bs=1g count=6 | split -b 2g - test_ && zip -0 -m few-huge-files.zip test_*
#!/usr/bin/env python3
"""Parse sunrise/sunset tables as provided by the USNO website at https://aa.usno.navy.mil/data/RS_OneYear"""
import re
import argparse
def parse_table(filename: str):
def to_decimal_deg(latlon_tup) -> float:
assert len(latlon_tup) == 3 and re.match("[NESW]", latlon_tup[0])
@klausbrunner
klausbrunner / markdown_to_pdf_sans.sh
Last active July 8, 2022 14:13
Convert markdown with mermaid to PDF using sans fonts (tested on MacOS; pandoc and mactex installed via homebrew, mermaid-filter installed via npm)
pandoc -t pdf -F mermaid-filter -o README.pdf README.md --pdf-engine=xelatex -V mainfont="PT Sans" -V monofont="PT Mono" -V papersize:a4
@klausbrunner
klausbrunner / rspamd-podman.md
Last active May 19, 2022 07:10
Running Rspamd with redis and unbound in Podman

Quick notes on running Rspamd in a Podman pod

This includes three containers:

Ideally, all of this should work in both rootless and rootful mode.

@klausbrunner
klausbrunner / proc.py
Created April 5, 2022 14:09
Given a sequence of pairs (A, B), return a list of 3-tuples (A, B, T) where T is a boolean that marks whether the sequence contains the inverted pair (B, A) as well.
from typing import Sequence
def mark_bidirectionals(pairs: Sequence) -> list:
"""Given a sequence of pairs (A, B), return a list of 3-tuples (A, B, T) where T is a boolean that
marks whether the sequence contains the inverted pair (B, A) as well. Order is preserved, but all
identical and inverted pairs to the right of (i.e. on higher indexes than) the original pair are removed.
Implementation note: pairs must be immutable (usable as dict keys)."""
marks = dict()
for a, b in pairs:
if (b, a) in marks:
@klausbrunner
klausbrunner / hexdump.java
Created December 10, 2019 09:52
Java byte array to hexdump. Format similar to default of hexdump(1).
static String hexDump(byte[] bytes) {
Formatter format = new Formatter(new StringBuilder());
for (int j = 0; j < bytes.length; j++) {
if (j % 16 == 0) {
format.format((j > 0 ? "\n" : "") + "%08X ", j);
}
format.format("%02X ", bytes[j]);
}
return format.toString();
}
@klausbrunner
klausbrunner / sshd_config
Last active April 13, 2020 13:42
Minimal, secure sshd_config (OpenSSH 8.2)
# This is the sshd server system-wide configuration file. See
# sshd_config(5) for more information.
HostKey /etc/ssh/ssh_host_ed25519_key
HostKey /etc/ssh/ssh_host_rsa_key
ChallengeResponseAuthentication no
UsePAM yes
# Allow client to pass locale environment variables
@klausbrunner
klausbrunner / parent-from-existing.py
Created August 12, 2019 04:43
Generate a basic parent POM from all subfolders that contain Maven projects.
#!/usr/bin/env python3
import os
import argparse
parser = argparse.ArgumentParser(description='Generate a Maven parent pom for existing Maven projects in a folder.')
parser.add_argument('root', default='.', nargs='?',
help='root (parent) folder')
parser.add_argument('--group', default='localhost',
help='groupId for parent POM')
@klausbrunner
klausbrunner / hls-distances.html
Created March 21, 2019 17:36
Trivial example to calculate route distances from a fixed point to location(s) specified as user input, using HERE Location Services.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="http://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
<script src="http://js.api.here.com/v3/3.0/mapsjs-service.js" type="text/javascript" charset="utf-8"></script>
</head>
@klausbrunner
klausbrunner / manifest_growth.py
Last active October 3, 2016 08:07
Track a repo manifest's project count over time using GitPython. Prints simple "datetime count" table.
import os
from git import Repo
import datetime as dt
import xml.etree.ElementTree as ET
repo = Repo('/home/klaus/stats/manifests')
target_file = 'manifest.xml'
assert not repo.bare