Skip to content

Instantly share code, notes, and snippets.

View bhenderson's full-sized avatar

Brian Henderson bhenderson

View GitHub Profile
@bhenderson
bhenderson / Jira Ticket Commit Message Install.md
Last active May 18, 2023 20:18
Prepend ticket number (jira) to commit messages

Save the file to .git/hooks and make executable (chmod u+x prepare-commit-msg)

@bhenderson
bhenderson / git-pie
Created June 30, 2021 14:20
perl pie but only act on git files. Optional second parameter can dramatically speed up the replacement.
#!/bin/bash
set -euo pipefail
###
# Usage
#
# git pie <perl-script> [git grep options]
@bhenderson
bhenderson / Readme.md
Last active September 10, 2019 13:26
Error handling can already be simplified by introducing single-line conditionals, which were already rejected.

These are my thoughts on the Go 2 draft for error handling.

The example go program they give is:

func CopyFile(src, dst string) error {
	r, err := os.Open(src)
	if err != nil {
		return fmt.Errorf("copy %s %s: %v", src, dst, err)
	}
@bhenderson
bhenderson / utils.js
Created December 6, 2017 18:37
JS debounce and loop
function debounce(func, wait, immediate) {
var timeout, context, args;
return function() {
context = this, args = arguments;
if (immediate && !timeout) func.apply(context, args);
timeout = timeout || setTimeout(function() {
timeout = null;
if (!immediate) func.apply(context, args);
}, wait);
};
require 'minitest/autorun'
##
# flatten takes an array of arbitrarily nested arrays of integers and returns a flattened array.
# Alternatively, if a block is given, the flattened version of the items is yielded
#
# :call-seq:
# flatten([[1,2,[3]],4]) -> [1,2,3,4]
#
# flatten([[1,2,[3]],4], &block) yields 1, 2, 3, 4
*.rb diff=ruby
Copy and paste this link in an Inbox tab. Prepend "javascript:" if that part didn't get copied.
Change EMAIL to your account if you want to work with multiple accounts. Can be removed to use the default one.
<a href='javascript:navigator.registerProtocolHandler("mailto","https://inbox.google.com/?authuser=EMAIL&mailto=%s","Inbox by Google")'>Mail to</a>
@bhenderson
bhenderson / Jenkinsfile
Created May 16, 2017 22:46
Jenkinsfile with validation dsl (does not work!)
validator {
validate 'hello'
validate 'world'
}
/*
* Create the Dockins folder and Job DSL seed job from Groovy
* Adapted from javaposse.jobdsl.Run
*/
import hudson.model.*
import jenkins.model.*
import javaposse.jobdsl.dsl.DslScriptLoader
import javaposse.jobdsl.dsl.JobManagement
import javaposse.jobdsl.plugin.JenkinsJobManagement
@bhenderson
bhenderson / json-viewer.js
Last active January 27, 2017 19:35
json pretty printer
javascript:(
function (){
var json = JSON.parse(document.body.innerText);
var create = function(el, props) {
var e = document.createElement(el);
if (props) {
Object.keys(props).forEach(function(key) {
e[key] = props[key];
});