Skip to content

Instantly share code, notes, and snippets.

View philpennock's full-sized avatar

Phil Pennock philpennock

View GitHub Profile
@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())))
#!/usr/bin/env zsh -f
#
# Wrap the execution of a command which is installed via a Python
# pyenv/virtualenv so that we can invoke it like a normal command, with
# python/env set up correctly for us. Assumes that the command uses a
# virtualenv named for the command, and that one common python version
# is being used for all such commands.
set -e
# -u will fail with _OLD_VIRTUAL_PATH unset
@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
(){
autoload -U colors ; [[ ${(t)fg} != association* ]] && colors
local ul="%{"$'\e['"$color[underline]m%}"
local rs="%{$reset_color%}"
local cerr="%{$fg_bold[red]%}"
local cuser="%{$fg[green]%}"
local cuser_root="%{$fg[green]${bg[red]}%}"
local chost="%{$fg[yellow]%}"
local cjobs="%{$bold_color%}"
local cdirs="%{$fg_bold[green]%}"
// Copyright © 2017 Pennock Tech, LLC.
// All rights reserved, except as granted under license.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
topleft="$(tput cup 0 0)"; nl="$(tput el)"$'\n'; invis="$(tput civis)"; vis="$(tput cvvis)"
push="$(tput sc)"; pop="$(tput rc)"
PS1="${topleft}%F{green}%D{%D %r}%f${nl}%~${nl}%# "
eval "TRAPUSR1() { print -Pn '${push}${invis}${topleft}%F{green}%D{%D %r}%f${nl}${pop}${vis}' }"
unset topleft nl invis vis push pop
p=$$; while sleep 1; do kill -s USR1 $p || exit; done &! unset p
# modified to do "|| exit" after the kill, so that if the kill fails, the child exits, so when parent dies, child will too.
# center-align version
@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 / prompt-stuff.zsh
Created February 6, 2017 21:25
Extracts from 'prompt pdp' for SSH
function prompt_query_ssh_status {
local suffix oIFS ss keycount
local -a keylines
if [[ -z ${SSH_AUTH_SOCK:-} ]]; then print "n/a"; return; fi
suffix=R
[[ -n ${SSH_AGENT_PID:-} ]] && suffix=L
if [[ $OSTYPE == darwin* ]]; then
case $SSH_AUTH_SOCK in
(/tmp/launch-*) suffix=D ;;
@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';

GnuPG Packaging

A few items here assume zsh as shell (globs and expansion modifiers, print -l).

Required installation order:

Previously recorded:
gmp nettle gnutls npth libgpg-error libgcrypt libksba libassuan  ( pinentry , gnupg )