Skip to content

Instantly share code, notes, and snippets.

@billhathaway
billhathaway / gist:11222817
Created April 23, 2014 16:40
shell function to SSH to an EC2 hostname
ec2ssh() {
# ec2-54-187-110-140.us-west-2.compute.amazonaws.com -> 54-187-110-140
hostname=`echo $1 | perl -pe 's/\..*//; s/ec2-//; s/-/./g'`
ssh $hostname
}
# install sysbench with
# sudo yum --enablerepo=epel install -y sysbench
targetDir=/data/benchmark # pick a directory inside your target file system
fileSize=300G # pick large enough size that you aren't using FS cache effectively
threads=128
test=rndrw # can also use rndrd
blockSize=4096
@billhathaway
billhathaway / gist:c745afd7fa334e76923a
Created July 29, 2014 23:23
joining strings in confd templates
With confd sometimes you will want to join a bunch of keys together into a line with comma separated values. Here is a template snippet to do that:
servers={{range $index,$server := .myapp_servers}}{{if $index}},"{{$server.Value}}"{{else}}"{{$server.Value}}"{{end}}{{end}}
Credit for the technique goes to Jan Newmarch's tutorial page at http://jan.newmarch.name/go/template/chapter-template.html
@billhathaway
billhathaway / gist:e32060b96802d74ca586
Created December 23, 2014 18:35
Getting IronMQ on-premise running in Vagrant
# more detailed instructions are at http://dev.iron.io/mq-onpremise/getting_started
# Get a coreos VM up
git clone https://github.com/coreos/coreos-vagrant.git
cd coreos-vagrant/
vagrant up
# get into the coreos box
vagrant ssh
console.log('Loading function');
const https = require('https');
const url = require('url');
// to get the slack hook url, go into slack admin and create a new "Incoming Webhook" integration
const slack_url = 'https://hooks.slack.com/services/...';
const slack_req_opts = url.parse(slack_url);
slack_req_opts.method = 'POST';
slack_req_opts.headers = {'Content-Type': 'application/json'};
@billhathaway
billhathaway / main.go
Last active August 29, 2015 14:22 — forked from nfisher/main.go
package main
// This command will allow you to provision, delete, describe, or estimate the cost of the specified CloudFormation template.
//
// Once compiled use the -help flag for details.
import (
"bufio"
"flag"
"fmt"
"io/ioutil"
@billhathaway
billhathaway / gist:a2efe9e179e654f77ed5
Last active August 29, 2015 14:24
bash function to create and open a new file for programming challenges
GOEDITOR="/Applications/Atom.app"
# practice does the following
# creates a new directory named after the project
# creates a file under that directory named $project.go with a small template
# NOTE: specifically not using main.go so I can distinguish the files in my editor tabs
# opens the file in my editor
# changes to the new project directory
practice() {
if [ $# -ne 1 ]; then
@billhathaway
billhathaway / gist:c8467ebcd2aa8c21d2d2
Created July 13, 2015 06:40
golang testing bufio.Scanner and strconv.Atoi versus fmt.Scan
package main
// These benchmarks are used to compare how fast it is to read a set of space separated numbers from a string
// using different techniques.
// The primary motiviation for this came when writing some code for hackerrank and realizing that the parsing of numbers
// for large input sets was actually the bottleneck
//
// For stable results, it is recommended to increase the runtime allocated for benchmarking, such as
// go test -v -run none -bench . -benchtime 5s
// Package lambda helps create workers that run in AWS’ Lambda service.
// The Lambda service is designed to run Node.js programs, so we have a very thin
// Node.js wrapper which is essentially an adapter between our Go worker programs
// and Lambda. Lambda runs our Node.js wrapper/adapter which then in turn runs
// our Go worker programs as child processes, communicating with them via stdio pipes
// and Unix exit codes.
//
// The interaction between the Lambda wrapper and our Go programs works like this:
//
// * The Node.js function is invoked by Lambda. Lambda passes an `event` parameter to
@billhathaway
billhathaway / benchmark_results.txt
Created August 6, 2016 05:22
Added my solution algorithmFive to elvis problem. Similar to Tyler's algorithmFour, but slightly slower.
go test -run none -bench . -benchtime 3s -benchmem
testing: warning: no tests to run
PASS
BenchmarkAlgorithmOne-4 1000000 4719 ns/op 53 B/op 2 allocs/op
BenchmarkAlgorithmTwo-4 3000000 1645 ns/op 0 B/op 0 allocs/op
BenchmarkAlgorithmThree-4 2000000 2572 ns/op 16 B/op 1 allocs/op
BenchmarkAlgorithmFour-4 1000000 3368 ns/op 1 B/op 1 allocs/op
BenchmarkAlgorithmFive-4 1000000 3423 ns/op 1 B/op 1 allocs/op