Skip to content

Instantly share code, notes, and snippets.

View barend's full-sized avatar
☀️

Barend Garvelink barend

☀️
View GitHub Profile
#!/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) }')
}
@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)
@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 / GitFunctions.groovy
Created April 19, 2016 13:08
Obtain a git hash in gradle, using JGit. Useful in environments where people frown on just putting a shell exec in your gradle file like so: "git log -1 --pretty=%H".execute().
// In buildSrc/src/main/groovy/
import org.eclipse.jgit.api.Git
import org.eclipse.jgit.lib.RepositoryBuilder
import org.gradle.api.Project
class GitFunctions {
public static String headCommitAndStatus(Project project) {
def repo = new RepositoryBuilder()
@barend
barend / gist:72a54afb92bbd7a71202
Created March 23, 2016 17:28
Mac OS X stop-it-with-the-curly-quotes-and-dashes-already
# Disables automatic substitution of "" by “”
defaults write NSGlobalDomain NSAutomaticQuoteSubstitutionEnabled -bool false
# Disables automatic subsitution of -- by –
defaults write NSGlobalDomain NSAutomaticDashSubstitutionEnabled -bool false
@barend
barend / logging-config.json
Last active November 16, 2015 09:16
Pretty much the same as carlcarl/python_logging_dict_config, but doesn't rely on eval().
{
"version": 1,
"disable_existing_loggers": true,
"filters": {
"my_filter": {
"()": "filters.MyFilter"
}
},
"formatters": {
"debug": {
@barend
barend / logging-config.json
Created November 12, 2015 16:37
Pretty much the same as [carlcarl/python_logging_dict_config][pldc], but doesn't rely on eval().
{
"version": 1,
"disable_existing_loggers": true,
"formatters": {
"debug": {
"format": "[%(levelname)s][%(asctime)s](%(funcName)s/%(lineno)d) %(message)s",
"datefmt": "%Y-%m-%d %H:%M:%S"
},
"simple": {
"format": "[%(levelname)s][%(asctime)s] %(message)s",
@barend
barend / LoggingInputConnectionWrapper.java
Created September 2, 2014 11:21
Android InputConnectionWrapper, as-is delegate with logging.
package com.example;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.inputmethod.CompletionInfo;
import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.ExtractedText;
import android.view.inputmethod.ExtractedTextRequest;
import android.view.inputmethod.InputConnection;
import android.view.inputmethod.InputConnectionWrapper;
@barend
barend / gist:085f5c9a7a0f14a54c11
Created August 3, 2014 18:46
Process GPS log of Sony camera
# Sony camera emits GPS data in NMEA format [1]
#
# The $GPRMC records contain velocity
#
# $GPRMC,043151.097,A,5203.5674,N,513.4071,E,14.56,,010814,,,A*43
# ^ ^ ^ ^ ^ ^ ^
# | | | | | | \-Checksum
# | | | | | |
# | | | | | \- date, ddmmyy
# | | | | \-------- velocity in knots
# Processes Ant JUnit logging output into tab separated values.
#
# [junit] Running com.myapp.MyTest
# [junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.721 sec
#
# Suite Num tests Num failed Num error Time (s)
# com.myapp.MyTest 2 0 0 0.721
#
BEGIN {
testname=""