Skip to content

Instantly share code, notes, and snippets.

View barend's full-sized avatar
☀️

Barend Garvelink barend

☀️
View GitHub Profile
@barend
barend / commit-msg
Last active April 19, 2016 14:37
Git hook to check each commit starts with a JIRA issue key.
#!/bin/sh
#
# A hook script to check the commit log message. Called by "git commit" with
# one argument, the name of the file that has the commit message. The hook
# should exit with non-zero status after issuing an appropriate message if it
# wants to stop the commit. The hook is allowed to edit the commit message
# file.
#
test "" = "$(cat $1 | head -n1 | egrep -v '^[A-Z]+-[0-9]+\b')" || {
@barend
barend / hello
Last active June 3, 2016 11:04
Get GitHub status update for all repo's checked out of a GitHub org.
#!/bin/bash
# Does a fetch --prune of all repositories and lists all open pull requests
#
# Usage:
# `hello <github org>`
#
# Prep steps:
# 1) Ensure your git clones are in a subdirectory that matches your github org name
# 2) install jq from https://stedolan.github.io/jq/ (brew install jq)
# 3a) Create a GitHub Personal OAuth token on https://github.com/settings/tokens/new (with "repo" access)
#!/usr/bin/env bash
# Adds a bash function that grabs a password from the MacOS keychain.
# Usage:
# getFromKeychain <entryname>
getFromKeychain() {
echo $(security find-generic-password -ga "$1" 2>&1 >/dev/null | awk '/^password/{ print substr($2, 2, length($2) - 2) }')
}
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 {
# 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;'
# 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
@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.
@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 / 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
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