Skip to content

Instantly share code, notes, and snippets.

View philpennock's full-sized avatar

Phil Pennock philpennock

View GitHub Profile
@philpennock
philpennock / sysctl_ps.c
Last active July 10, 2016 00:52
sysctl-derived process iteration on Darwin (MacOS) & probably *BSD. Handles pid 0 (kernel_task)
// This file should be valid C99.
// Intended for use on MacOS (tested) and *BSD (untested) systems.
#include <err.h>
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// gets us some compiler macros for OS
#!/bin/sh -eu
prefix='philpennock-pgp'
keyid='0x4D1E900E14C1CC04'
progname="$(basename -- "$0")"
umask 0077
[ -d ~/.gnupg/export ] || mkdir ~/.gnupg/export
cd ~/.gnupg/export
@philpennock
philpennock / unhexdump.py
Created September 4, 2016 21:59
Convert hex-dump format (hh hh hh hh) to binary data: fast hack at REPL, for an HVIF file
#!/usr/bin/env python3
import binascii
with open('foo.hvif', 'wb') as out:
out.write(binascii.unhexlify(b''.join(open('foo.hvif.txt', 'rb').read().split())))
@philpennock
philpennock / aws-instance-sshhostkeys
Last active September 13, 2016 12:38
Grab SSH hostkeys for a newly launched AWS EC2 instance
#!/bin/sh -eu
#
# Usage:
# aws-instance-sshhostkeys i-deadbeef | tee -a .ssh/known_hosts
# FIXME:
# Strip trailing CR
# Strip trailing comment field
# Support Route53 entries automatically
@philpennock
philpennock / dkim-generate.bash
Created February 5, 2017 09:50
DKIM key generation and DNS fragment generation script.
#!/bin/bash -eu
# http://www.keylength.com/en/3/ -- ECRYPT II "smallest general purpose level"
# is 1248 bits symmetric; we're pretty stuck on RSA right now
: "${KEYSIZE_RSA:=1248}"
: "${DKIM_SIGN_DOMAINS_FILE:=/etc/exim/dkim/domains-mapping}"
: "${DATE:=$(date +%Y%m)}"
declare -r KEYSIZE_RSA DKIM_SIGN_DOMAINS_FILE DATE
@philpennock
philpennock / update_mail_cdbs.pl
Last active February 27, 2017 17:40
An old script for building CDB files for Exim, registed as `bi_command` in exim.conf
#!/usr/bin/env perl
# BUG: "#" can not appear in a value
BEGIN { @INC = grep {$_ ne '.'} @INC };
use warnings;
use strict;
# XXX: make these overrideable with getopt, together with "rebuild all", etc.
my $flat_dir = '/etc/mail/flat';
@philpennock
philpennock / pka.py
Last active February 27, 2017 18:44
Generate DNS records for PKA for GnuPG 2.1.x
#!/usr/bin/env python2
# Must be python2 for zbase32 module :(
# $ pip install attrs zbase32
"""
pka: emit PKA records for key
Generate all PKA records for a given key, which must be on the keyring.
Optionally include a keyserver in the CERT/IPGP payload.
#!/bin/sh -eu
set -eu
clean_here() {
find . -type f -execdir sh -c \
'f="{}";
t=$(file -hb "$f");
[ "$t" = "SQLite 3.x database" ] || exit 1;
printf "%s/%s\n" "$(pwd)" "$f";
ls -ld 2>/dev/null "$f" "${f}-journal";
@philpennock
philpennock / exit_check.go
Created October 24, 2012 19:59
Showing interactions of defer, os.Exit and panic in Golang.
package main
import (
"container/list"
"flag"
"fmt"
"os"
"sync"
"time"
)
@philpennock
philpennock / freebsd-whois.patch
Created August 17, 2017 18:10
Fix FreeBSD's whois to handle Verisign whois referral change
--- usr.bin/whois/whois.c.orig 2017-08-17 14:00:08.917506928 -0400
+++ usr.bin/whois/whois.c 2017-08-17 14:00:28.975792449 -0400
@@ -76,7 +76,7 @@
#define GERMNICHOST "de.whois-servers.net"
#define FNICHOST "whois.afrinic.net"
#define DEFAULT_PORT "whois"
-#define WHOIS_SERVER_ID "Whois Server: "
+#define WHOIS_SERVER_ID "Registrar WHOIS Server: "
#define WHOIS_ORG_SERVER_ID "Registrant Street1:Whois Server:"