Skip to content

Instantly share code, notes, and snippets.

@phemmer
phemmer / client.c
Created May 18, 2014 09:29
cerver/client code to test maximum number of connections
/*
Opens multiple connections to 127.0.0.1:2222 until an error occurs.
It displays a counter of the number of open connections so far.
As soon as an error occurs, it prints the error and exits.
The counter will be the number of open connections at the time of error.
*/
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
@phemmer
phemmer / gist:569105182a025746cb99
Created January 23, 2015 12:59
swarm-docker launch
#!/bin/bash
num_dockers=3
docker_image=dind
########################################
deferred=()
deferred_pid=$BASHPID
run_deferred() {
if [[ "$deferred_pid" != $BASHPID ]]; then
package main
import (
sm "github.com/phemmer/sawmill"
)
type mymap map[string]interface{}
type mystruct struct {
Foo string
Bar string
@phemmer
phemmer / 97g.go
Created April 15, 2015 19:41
mysql schema benchmark
// import tmp/97g
package main
import (
"database/sql"
"fmt"
"log"
"math/rand"
"strconv"
"time"
#include <stdlib.h>
#include <stdio.h>
int main() {
char *buf;
int i;
for (i = 0; i < 2048; i++) {
buf = (char *) malloc(1024*1024);
printf("buf=%p\n", buf);
@phemmer
phemmer / go-clean-archives.sh
Created January 5, 2016 17:01
git clean stale archives
#!/bin/bash
eval "$(go env)"
function clean_gopath() {
gopath="$1"
pkgpath="$gopath/pkg/${GOHOSTOS}_$GOHOSTARCH"
if [[ ! -e "$pkgpath" ]]; then
return
fi
@phemmer
phemmer / load_ipset_blacklist.sh
Last active March 8, 2026 03:39
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
TEST DEFINITIONS ::= BEGIN
testOID ::= { 1 2 3 }
testTable OBJECT-TYPE
SYNTAX SEQUENCE OF testTableEntry
MAX-ACCESS not-accessible
STATUS current
::= { testOID 0 }
@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
@phemmer
phemmer / log
Last active March 8, 2026 03:39
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