Skip to content

Instantly share code, notes, and snippets.

Avatar

Tim Blair timblair

View GitHub Profile
@timblair
timblair / grid-join.go
Created Dec 22, 2017
AoC 2017 Day 21: Grid Joining
View grid-join.go
func join(gs []grid) grid {
n := int(math.Sqrt(float64(len(gs)))) // Number of subgrids across/down the new grid
sgn := len(gs[0]) // Number of values on one side of a subgrid
cg := newGridBySize(n * sgn) // The new, combined grid to populate
// Add each subgrid to the new, combined grid.
for i, g := range gs {
// Calculate the position of the top-left of the subgrid once placed in
// the new, combined grid. We use this plus the offset within the subgrid
// to place the values in the combined grid.
@timblair
timblair / gds-go-workshop-01-cheatsheet.md
Last active Nov 24, 2016
GDS Go Workshop #1: Cheatsheet
View gds-go-workshop-01-cheatsheet.md

GDS Go Workshop #1: Cheatsheet

Value assignment

var s1 string         // a new string identifer with its zero value ("")
var s2 string = "foo" // an identifer with a non-zero value
var i1 int            // an int identifer with its zero value (0)
var i2 int = 42       // an int identifer with a non-zero value
@timblair
timblair / CHANGELOG.json
Created Nov 1, 2016
A quick stab at a machine-readable CHANGELOG format
View CHANGELOG.json
{
"project": "some-project",
"url": "https://github.com/someorg/some-project",
"description": "Some project or other for SomeOrg",
"releases": [
{
"version": "1.0.0",
"date": "2014-12-05",
"items": [
View pin_graph.rb
require "gviz"
require "optparse"
# Usage: $0 PINFILE [OPTIONS]
#
# -i, --highlight APPS Highlight apps that depend on these
# -x, --exclude APPS Exclude these apps
# -o, --only APPS Only show dependencies and dependants of these
# -s, --hide-solitary Hide apps with no dependecies or dependants
# -f, --out-file FILE The filename to write output to (default: out.png)
@timblair
timblair / Makefile
Created Jul 22, 2016
HTTP connection changes between Go 1.5.x and 1.6.x
View Makefile
.PHONY: build clean run
V15 := 1.5.4
V16 := 1.6.3
B15 := http-test-1.5
B16 := http-test-1.6
all: clean build run
@timblair
timblair / kickstart.sh
Created Jun 29, 2016
Personal machine kickstart
View kickstart.sh
#!/bin/bash
# Tim's Development Environment Setup
# ===================================
# Stop immediately if anything fails
set -e
############################################
# Handy functions
View youre.js
module.exports = function (robot) {
robot.hear(/ (?:is )(\w+ ?){1,6}/i, function (msg) {
if (Math.random() < 0.001) {
var match = msg.match[0].trim().replace(/^is /,"");
msg.send("You're " + match);
}
});
};
@timblair
timblair / 1-daily-walk.go
Created Nov 6, 2015
Quick stabs at these Go concurrency exercises: http://bit.ly/go-concurrency-exercises
View 1-daily-walk.go
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
type person string
@timblair
timblair / 20150820-go-workshop-notes.md
Created Aug 21, 2015
2015-08-20: Go Workshop Notes
View 20150820-go-workshop-notes.md

2015-08-20: Go Workshop Notes

Variables and Types

  • Type gives the compiler two things: size + representation. The compiler guarantees these types
@timblair
timblair / rbenv-update-bundler.sh
Last active Aug 29, 2015
Use rbenv? Need to update All The Rubies™ because of Bundler's BUNDLED_WITH change? Then use this script.
View rbenv-update-bundler.sh
#!/bin/bash
eval "$(rbenv init -)"
CURRENT_RUBY=$(rbenv version-name)
LATEST_BUNDLER=$(curl -s https://rubygems.org/api/v1/versions/bundler/latest.json | cut -d'"' -f 4)
echo "Latest Bundler version: $LATEST_BUNDLER"
for RUBY_VERSION in $(rbenv versions --bare); do
rbenv shell "$RUBY_VERSION"
if $(gem list -i bundler); then