Skip to content

Instantly share code, notes, and snippets.

View barend's full-sized avatar
☀️

Barend Garvelink barend

☀️
View GitHub Profile
@barend
barend / keybase.md
Created April 29, 2021 06:35
keybase.md

Keybase proof

I hereby claim:

  • I am barend on github.
  • I am barend (https://keybase.io/barend) on keybase.
  • I have a public key ASCB83tj3TtNwDtix1P2-b41Qt-_scb4bUKbw-XGJq5hSAo

To claim this, I am signing this object:

@barend
barend / gup
Created January 22, 2021 12:23
Update all git repositories under PWD or $1
#!/bin/bash
# Update all git repositories under PWD or $1
# Assumes basic `git clone` usage; may not work for more elaborate git layouts.
BASEDIR="${1:-.}"
SSH_KEY_NAME="..." # some distinguishing string from your ssh-add -l output
SSH_KEY_FILE="..." # the filename of your SSH key
if ssh-add -l | grep -F -q $SSH_KEY_NAME; then
@barend
barend / logging.py
Created October 26, 2020 09:44
Configure Python logging with ISO-8601 format and UTC time
import logging
from time import gmtime
# https://stackoverflow.com/a/7517430/49489
logging.basicConfig(
level=logging.INFO,
format="%(asctime)s.%(msecs)03dZ [%(name)s] %(message)s",
datefmt="%Y-%m-%dT%H:%M:%S",
)
logging.Formatter.converter = gmtime
package example;
import com.google.common.base.Charsets;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.Optional;
/**
* Example password wrapper class that obfuscates the in-memory password so
* that it doesn't appear in crash dumps in cleartext. This does nothing
@barend
barend / krbcc.sh
Created February 6, 2020 13:40
Kerberized actions with temporary credentials cache file
export KRB5CCNAME="FILE:$(mktemp)"
kinit -kt <keytab> <username>
# do stuff
kdestroy
@barend
barend / command_line_skeleton.py
Created November 17, 2017 15:26
Python command line program skeleton
#!/usr/bin/env python3
"""
Does cool things, with optional verbose output.
"""
import logging
log = logging.getLogger()
@barend
barend / utf8.txt
Last active May 29, 2017 19:18
How does UTF8 work, anyway?
The following is the Black Female Astronaut emoji as encoded
in UTF8, shown in hex:
F0 9F 91 A9 F0 9F 8F BF E2 80 8D F0 9F 9A 80 byte value
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 byte number
As you can tell it's fifteen bytes. If you express the hex
digits in binary you can see how UTF8 encoding works, and
you can see it's made up of four characters.
# Git pull all the repos two levels under $PWD, 4 in parallel
# vim: ft=zsh:
function woohoo() {
git -C "$1" pull --ff-only --recurse-submodules=yes --quiet 2>&1
if [ ! $? ]; then
echo "Failed: $1" 1>&2
fi
}
export -f woohoo
# Brew update everything and clean up afterwards.
alias broo='if [ -n "$VIRTUAL_ENV" ]; then; echo "FATAL: active virtualenv"; else; brew update && brew upgrade && brew cleanup -s; fi;'
package io.github.barend.getpid;
import com.sun.jna.Library;
import com.sun.jna.Native;
/**
* requires {@code jna.jar}.
* http://stackoverflow.com/a/7303433/49489
*/
public class GetPid {