Skip to content

Instantly share code, notes, and snippets.

View danielwhite's full-sized avatar

Daniel White danielwhite

View GitHub Profile
@danielwhite
danielwhite / ansi.go
Created April 12, 2020 05:52
Inverted, safe, foreground and background ANSI escape codes
/*
Create a string usage a web-safe version of the specified background color.
The foreground will be set to an inverse color for legibility.
Untested and definitely broken.
*/
func decorate(bgColor color.Color, s string) string {
fgColor := inverse(bgColor)
@danielwhite
danielwhite / git-cleanup
Last active September 30, 2019 07:19
Git Tools
#!/bin/bash
set -euo pipefail
#
# Tidies up the remote and local references of a Git repository.
#
# By default, it assumes that origin/master is the mainline branch.
#
GIT_UPSTREAM_REMOTE=${GIT_UPSTREAM_REMOTE:-origin}
@danielwhite
danielwhite / README.md
Last active June 28, 2019 05:32
R for Data Science Gotchas!

This captures notes around problems I encountered while working through R for Data Scientists.

1.4.3: The Tidyverse

xml2

On OSX, the installation of xml2 fails with an error:

Configuration failed because libxml-2.0 was not found.

@danielwhite
danielwhite / golden_test.go
Last active September 4, 2020 08:16
Simple golden file test
package main_test
import (
"testing"
)
/*
This is an example implementation of a golden file test that is easy to update.
*/
@danielwhite
danielwhite / Makefile
Created June 26, 2019 02:29
Makefile for AWS Lambda (Go)
PACKAGE ?= lambda.zip
HANDLER ?= main
all: $(PACKAGE)
.PHONY: clean
clean:
rm -f $(PACKAGE)
$(PACKAGE): $(HANDLER)

Keybase proof

I hereby claim:

  • I am danielwhite on github.
  • I am daniel_white (https://keybase.io/daniel_white) on keybase.
  • I have a public key ASCxt1nQXX1VbdAcm5c-DF_5_y_Ul8YN56BQt1bC-WYuOwo

To claim this, I am signing this object:

@danielwhite
danielwhite / math.go
Created March 24, 2019 03:25
Math Utilities
package math
// Average returns the floor of the average of two signed integers without risk of overflow.
//
// See: http://aggregate.org/MAGIC/#Average%20of%20Integers
func Average(x, y int64) int64 {
return (x & y) + ((x ^ y) >> 1)
}
@danielwhite
danielwhite / git-incoming
Created October 27, 2017 03:04
List open GitHub PR branches for merging
#!/bin/bash
#
# This script finds incoming PR branches from a GitHub based remote.
#
# Example
#
# $ git checkout -b incoming origin/master
# $ git incoming origin | xargs git merge
#
@danielwhite
danielwhite / go-bench.sh
Created April 28, 2017 00:45
Benchmarking Golang with benchstat
#!/bin/bash
#
# Generate benchmark files in a Git repository.
#
# Usage: TIMES=1 go-bench [prefix]
#
# Number of times to run the benchmark; useful for benchstat.
TIMES=${TIMES:-1}
@danielwhite
danielwhite / Dockerfile
Last active May 8, 2017 13:08
Mopidy Container
FROM debian:latest
# Add Mopidy repository
RUN apt-key adv --keyserver pgp.mit.edu --recv-keys 78FD980E271D2943 && \
echo "deb http://apt.mopidy.com/ jessie main contrib non-free" > /etc/apt/sources.list.d/mopidy.list
# Install Mopidy packages
RUN apt-get update && apt-get install -y \
mopidy \
mopidy-spotify \