Skip to content

Instantly share code, notes, and snippets.

@phemmer
phemmer / trie.go
Last active March 26, 2024 14:34
optmized fork of yl2chen/cidranger (this is now a full package available at https://github.com/phemmer/go-iptrie)
// Package iptrie is a fork of github.com/yl2chen/cidranger. This fork massively strips down and refactors the code for
// increased performance, resulting in 20x faster load time, and 1.5x faster lookups.
package iptrie
import (
"fmt"
"math/bits"
"net/netip"
"strings"
@phemmer
phemmer / haproxy.cfg
Last active December 6, 2023 00:53
haproxy log SSL master key
global
lua-load haproxy.lua
frontend X
tcp-request session set-var(sess.ssl_session_id) ssl_fc_session_id,hex if { ssl_fc }
tcp-request content lua.ssl-log-key if { ssl_fc }
@phemmer
phemmer / test.go
Created May 1, 2019 02:09
Attempt to test systemd notify reload failure
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"time"
"github.com/coreos/go-systemd/daemon"
@phemmer
phemmer / defer.sh
Last active March 5, 2024 09:55
bash defer function - just like go's defer()
function _run_deferred() {
local _depth="$BASHPID.${#FUNCNAME[@]}"
[[ "$_depth" != "$_deferred_depth" ]] && return
local opt=$-
set +e
for (( i=${#_deferred[@]} - 1; i >= 0; i-- )); do
eval "${_deferred[i]}"
done
[[ "$opt" == *e* ]] && set -e
}
@phemmer
phemmer / main_test.go
Created December 9, 2017 02:40
Golang benchmark check buffered channel has ready-to-read value
# go test -bench=.
goos: linux
goarch: amd64
pkg: tmp/eh4
BenchmarkSelect-8 200000000 7.65 ns/op
BenchmarkLen-8 2000000000 1.07 ns/op
PASS
ok tmp/eh4 4.580s
# lsof -p 25058
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
influxd 25058 phemmer cwd DIR 253,8 8192 192 /home/phemmer
influxd 25058 phemmer rtd DIR 253,0 249 96 /
influxd 25058 phemmer txt REG 253,8 17441363 335701024 /home/phemmer/.go/bin/influxd
influxd 25058 phemmer mem REG 0,30 26156 /mnt/influxdb/influxdb2/data/_internal/monitor/675/000000014-000000002.tsm (path dev=0,32)
influxd 25058 phemmer mem REG 0,30 26381 /mnt/influxdb/influxdb2/data/_internal/monitor/675/000000039-000000001.tsm (path dev=0,32)
influxd 25058 phemmer mem REG 0,30 25692 /mnt/influxdb/influxdb2/data/_internal/monitor/675/000000012-000000003.tsm (path dev=0,32)
influxd 25058 phemmer mem REG 0,30 26377 /mnt/influxdb/influxdb2/data/_internal/monitor/675/000000016-000000001.tsm (path dev
@phemmer
phemmer / log
Last active July 5, 2017 00:44
InfluxDB stack dump
SIGQUIT: quit
PC=0x458e7e m=0 sigcode=65537
goroutine 0 [idle]:
runtime.sys_umtx_op(0xee3bd8, 0xf, 0x18, 0x0, 0x800000004, 0x400ee3540, 0x0, 0x422c5e, 0xc51e80, 0x7fffffffe9d0, ...)
/usr/local/go/src/runtime/sys_freebsd_amd64.s:21 +0x1e
runtime.futexsleep1(0xee3bd8, 0x0, 0xffffffffffffffff)
/usr/local/go/src/runtime/os_freebsd.go:92 +0x5d
runtime.futexsleep.func1()
/usr/local/go/src/runtime/os_freebsd.go:80 +0x3a
@phemmer
phemmer / gdm.sh
Created November 26, 2016 21:27
GDM wrapper for not mucking with shared $GOPATH
#!/bin/bash
self_path="$(readlink -f "$0")"
self_dir="${self_path%/*}"
#unset PWD # screws with go package path detection
IFS=$'\n' read -d '' -a gdms < <(which -a gdm)
realgdm=
foundself=
for gdm in "${gdms[@]}"; do
TEST DEFINITIONS ::= BEGIN
testOID ::= { 1 2 3 }
testTable OBJECT-TYPE
SYNTAX SEQUENCE OF testTableEntry
MAX-ACCESS not-accessible
STATUS current
::= { testOID 0 }
@phemmer
phemmer / load_ipset_blacklist.sh
Last active June 15, 2016 19:09
Public IP blacklist loader
#!/bin/bash
exec 3> >(ipset restore)
echo 'create blacklist hash:net -exist' >&3
echo 'create blacklist_new hash:net -exist' >&3
echo 'flush blacklist_new' >&3
#echo "http://www.spamhaus.org/drop/drop.txt"
while read ip; do
echo "add blacklist_new $ip" >&3