Skip to content

Instantly share code, notes, and snippets.

KlausBrunner /
Created Nov 19, 2012
A very simple implementation of the Java Future interface, for passing a single value to some waiting thread. Uses a CountdownLatch to ensure thread safety and provide blocking-with-timeout functionality required by Future. Cancellation isn't supported.
public final class ResultFuture implements Future<Result> {
private final CountDownLatch latch = new CountDownLatch(1);
private Result value;
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
KlausBrunner /
Last active Jul 8, 2022
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 --pdf-engine=xelatex -V mainfont="PT Sans" -V monofont="PT Mono" -V papersize:a4
KlausBrunner /
Last active May 19, 2022
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 /
Created Apr 5, 2022
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 /
Last active Mar 14, 2021
Incrementally binding JSON objects in an array (list) using Jackson.
package tv.xrm.test;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.util.*;
public class JacksonStreamingBindingTest {
KlausBrunner / counters.cql
Created Nov 20, 2012
creating and using a Cassandra counter column in CQL
View counters.cql
-- creating and using a Cassandra counter column in CQL
-- NOTE: this is CQL 2.0 syntax, it will NOT work with CQL 3 (for syntax reasons and because CQL 3.0 drops the very notion of dynamic columns...sigh)
CREATE KEYSPACE test WITH strategy_class = 'SimpleStrategy'
AND strategy_options:replication_factor = '1';
USE test;
CREATE TABLE stats (KEY text PRIMARY KEY) WITH comparator=text AND default_validation=counter;
KlausBrunner / sshd_config
Last active Apr 13, 2020
Minimal, secure sshd_config (OpenSSH 8.2)
View sshd_config
# 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 / two-main-jars-pom.xml
Last active Feb 2, 2020
Creating two different executable JARs with dependencies from the same Maven project - same contents but different Main class in the manifest
View two-main-jars-pom.xml
KlausBrunner /
Created Dec 10, 2019
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 /
Created Aug 12, 2019
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')