Skip to content

Instantly share code, notes, and snippets.

Brian Henderson bhenderson

Block or report user

Report or block bhenderson

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bhenderson
bhenderson / Readme.md
Last active Sep 10, 2019
Error handling can already be simplified by introducing single-line conditionals, which were already rejected.
View Readme.md

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 Dec 6, 2017
JS debounce and loop
View utils.js
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);
};
View array_flattener.rb
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
View Inbox by Google protocol handler
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
Jenkinsfile with validation dsl (does not work!)
View Jenkinsfile
validator {
validate 'hello'
validate 'world'
}
View generate_seed_job.groovy
/*
* 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 Jan 27, 2017
json pretty printer
View json-viewer.js
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];
});
@bhenderson
bhenderson / tmux-ssh
Last active Sep 10, 2018 — forked from dmytro/ssh-multi.sh
Start multiple synchronized SSH connections with Tmux
View tmux-ssh
#!/bin/bash
# SSH into multiple hosts with each in their own tmux pane.
if [ "$#" -lt 1 ]; then
cat >&2 <<-EOM
Usage: $(basename $0) host1 [ host2 ... ] [ -- ssh options ]
EOM
exit 1
fi
View mrs.sh
# MultiRuby Switcher: see multiruby for installs
mrs() {
local path="$HOME/.multiruby/install/$1/bin:"
if test "$1" = "system" -o "$1" = ""; then
echo >&2 "using system"
path=
elif ! test -d "${path%:}"; then
echo >&2 "$1 not available"
return 1
fi
You can’t perform that action at this time.