Skip to content

Instantly share code, notes, and snippets.

package psutil
import (
"fmt"
"log"
"strings"
"cloud.google.com/go/pubsub"
netcontext "golang.org/x/net/context"
)
@billhathaway
billhathaway / README.md
Created September 2, 2016 13:41
passing in values during go build time
 package main

 import "fmt"
  
   var (
     version  = "develop"
     otherval = "unset"
   )
@billhathaway
billhathaway / benchmark results.txt
Last active September 16, 2016 14:04
elvis added stream example with buffer and fixed bug in case of find pattern split across buffers
Thanks to Tyler Burnell, Bill Kennedy and others who had written all the boilerplate I copied in main.go and main_test.go
Note: the benchmark data is horribly unrealistic (10M input of either no matches or all matches), but I think the model of testing MB/sec throughput of large input sets is the right one for the problem statement. I welcome additions where we make the test data more realistic. Using a very small data set of a few hundred bytes doesn't seem like a good test
for stream processing algorithm performance.
go test -run none -bench . -benchtime 3s -benchmem
testing: warning: no tests to run
PASS
BenchmarkProcessByteUnmatched-8 30 143059391 ns/op 69.90 MB/s 1 B/op 1 allocs/op
BenchmarkProcessByteMatched-8 30 120619527 ns/op 82.91 MB/s 1 B/op 1 allocs/op
@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
// 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 / 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
@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 / 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"
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 / 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