Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
function set_git_config() {
read -e -p "$2 ($3): " INPUT && [[ ! "$INPUT" ]] && INPUT="$3"
git config --global "$1" "$INPUT"
}
GITNAME=$(finger `whoami` | awk -F: '{ print $3 }' | head -n1 | sed 's/^ //')
GITMAIL="$(whoami)@blah.com"
@timblair
timblair / webmock-net-http-pipeline.rb
Created January 20, 2014 17:15
WebMock overrides the Net::HTTP#request method to do it's thing, but Net::HTTP::Pipeline circumvents that method to do *it's* thing. We only care about the responses during testing, so getting WebMock behaviour for pipelined requests is most easily done by just not pipelining them.
WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP).class_eval do
def pipeline(requests)
responses = []
requests.reject! do |req|
response = request(req)
yield response if block_given?
responses << response
end
responses
end
@timblair
timblair / git-merge-point
Created February 19, 2014 19:42
Show the point where a given commit was merged into master
#!/bin/bash
# Displays the point at which a given commit SHA was merged
#
# Usage: git merge-point SHA <TARGET>
TARGET=${2-master}
git rev-list --ancestry-path $1..$TARGET |
grep -f <(git rev-list --first-parent $1..$TARGET) |

Keybase proof

I hereby claim:

  • I am timblair on github.
  • I am timblair (https://keybase.io/timblair) on keybase.
  • I have a public key whose fingerprint is 00B7 B4C9 C77C 3E30 F381 0B80 45B2 84B3 AC7A 6D2F

To claim this, I am signing this object:

@timblair
timblair / youre.js
Created January 26, 2015 10:35
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 / decoder.rb
Last active August 29, 2015 14:16
RFC 5322-compliant Message ID generator
require "date"
class MessageID
module Decode
STAMP_FIELD_FORMAT = "%Y%m%d%H%M%S%N"
def self.decode(id)
user, host = id.split("@")
parts = user.split(".").map { |part| part.to_i(36) }
stamp, ident = parts.shift, []
@timblair
timblair / event-listener
Last active August 29, 2015 14:16
Simple RabbitMQ message listener
#!/usr/bin/env ruby
require "bunny"
abort "Usage: #{$0} BINDING_KEY [BINDING_KEY, ...]" if ARGV.empty?
conn = Bunny.new("amqp://development.vm:5672")
conn.start
channel = conn.create_channel
exchange = channel.exchange("event", no_declare: true)
@timblair
timblair / rbenv-update-bundler.sh
Last active August 29, 2015 14:23
Use rbenv? Need to update All The Rubies™ because of Bundler's BUNDLED_WITH change? Then use this script.
#!/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
@timblair
timblair / 20150820-go-workshop-notes.md
Created August 21, 2015 09:22
2015-08-20: Go Workshop Notes

2015-08-20: Go Workshop Notes

Variables and Types

  • Type gives the compiler two things: size + representation. The compiler guarantees these types
@timblair
timblair / 1-daily-walk.go
Created November 6, 2015 08:51
Quick stabs at these Go concurrency exercises: http://bit.ly/go-concurrency-exercises
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
type person string