Skip to content

Instantly share code, notes, and snippets.

View philpennock's full-sized avatar

Phil Pennock philpennock

View GitHub Profile

Keybase proof

I hereby claim:

  • I am philpennock on github.
  • I am philpennock (https://keybase.io/philpennock) on keybase.
  • I have a public key whose fingerprint is C865 F6AF 2461 6A74 9836 576B 310D 6001 650E 06D3

To claim this, I am signing this object:

@philpennock
philpennock / nistbeaconcheck.go
Created January 1, 2015 07:27
Query the NIST randomness beacon, in Go
// Author: Phil Pennock
// Based on publicly available data, as described below, so the only creative
// input was the expression in Golang.
package main
/*
An overview is at <http://www.nist.gov/itl/csd/ct/nist_beacon.cfm> and while
the REST API is reliably available (in my experience) the content at
<https://beacon.nist.gov/home> is not, so I'll replicate the data here from
@philpennock
philpennock / fixup-repo
Created April 8, 2015 16:56
Bourne-shell snippet for fixing up a git repo cloned from github to add the PR fetch set, for CLI diff of a PR.
origin_url=$(git config --local --get remote.origin.url)
case $origin_url in
github:*|git@github.*|*//github.*)
fetches="$(git config --local --get-all remote.origin.fetch)"
case $fetches in
*origin/pr/*) # no action
;;
*)
git config --local --add remote.origin.fetch '+refs/pull/*/head:refs/remotes/origin/pr/*'
;;
@philpennock
philpennock / sh-subshell-errexit-test.sh
Created May 19, 2015 20:37
Shell sucks; tried in bash, zsh, BSD sh
#!/bin/bash
script_name="$(basename "$0")"
die() {
local rv=$?
printf >&2 "%s: %s\n" "$script_name" "$*"
exit $rv
}
@philpennock
philpennock / update-home-ip
Created December 18, 2015 06:13
7 * * * * /usr/local/sbin/update-home-ip cron
#!/bin/bash -eu
progname="$(basename "$0")"
die() { printf >&2 "%s: %s\n" "$progname" "$*" ; exit 1; }
if [[ $# -gt 0 && "$1" == "cron" ]]; then
sleep $((10 + RANDOM % 40 ))
fi
dynhost=CENSORED
@philpennock
philpennock / uuidbot__main.go
Created January 13, 2016 19:03
A simple Slack responder to the /uuid command
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"strconv"
"strings"
@philpennock
philpennock / div.vim
Last active March 14, 2018 04:51
vimscript for a :Div command, taking a range
if has("eval")
" Insert a divider
" Start and end are line numbers.
" Sep is ordinarily the string of characters which make up the divider, but
" if the first and third characters (not bytes) are period, then the second
" character is a single-character line prefix and the third character
" onwards is the divider.
function! s:pdp_div(start, end, sep, ...) range
let l:label = a:0 >= 1 ? join(a:000, ' ') : 'cut here'
if strwidth(a:sep) >= 4 && a:sep[0] == '.' && strcharpart(a:sep, 2, 1) == '.'
@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
@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
prefix='philpennock-pgp'
keyid='0x4D1E900E14C1CC04'
progname="$(basename -- "$0")"
umask 0077
[ -d ~/.gnupg/export ] || mkdir ~/.gnupg/export
cd ~/.gnupg/export