Skip to content

Instantly share code, notes, and snippets.

// Example usage:
// Triggers an io.ErrUnexpectedEOF on the last read
func TestCanDiffWhenOldlistIsCorrupted(t *testing.T) {
log.SetOutput(testwriter(t)) // log to testing.Log
oldKeys := []s3.Key{{ETag: "1"}, {ETag: "3"}}
newKeys := []s3.Key{{ETag: "1"}, {ETag: "2"}, {ETag: "3"}}
want := []s3.Key{{ETag: "2"}}
oldList := encodeKeys(oldKeys)
@aybabtme
aybabtme / errors.go
Last active August 29, 2015 14:01
Lazy error handling for overly verbose error producers.
// accumulates non-nil errors
type errors []error
func (e *errors) Ack(err error) {
if err != nil {
*e = append(*e, err)
}
}
@aybabtme
aybabtme / clever.sh
Created April 18, 2014 20:38
> To apply, email us at [email protected], where n is the number of students in the Clever sandbox API data set with a last name that begins with the letter 'V'. Send us one or more things from [resume, github profile, recent side projects, linkedin URL, Stack Overflow profile, etc], and let us know how you solved our 'puzzle.'
pagecount=$(curl -s -H 'Authorization: Bearer DEMO_TOKEN' -X GET https://api.clever.com/v1.1/students | jq '.paging.total')
echo "$pagecount pages"
now=$(date "+%Y-%m-%d-%H:%M.%S")
tmpfile=".$now-tmp_clever.json"
touch $tmpfile
echo "Saving pages to $tmpfile"
for i in $(seq 1 $pagecount); do
echo "Getting page $i"
#!/bin/sh
set -e
PROJECTROOT=$GOPATH/src/github.com/<you>/<repo>
cd $PROJECTROOT
echo "Vetting project."
go vet || exit 1
echo "...ok"
package main
import (
"log"
"time"
)
func main() {
nobodyListening := make(chan struct{})
package main
import (
"log"
"time"
)
func main() {
nobodyListening := make(chan struct{})
{
// you may set specific environment variables here
// e.g "env": { "PATH": "$HOME/go/bin:$PATH" }
// in values, $PATH and ${PATH} are replaced with
// the corresponding environment(PATH) variable, if it exists.
"env": {
"GOPATH": "$HOME/gocode"
},
// Your shell. e.g. on Linux and OS X, if your shell bash:
@aybabtme
aybabtme / wishful_thinking.go
Created January 11, 2014 15:38
wishful_thinking.go
func DreamWayOfDoingIt() {
clientPool := NewAWSPool(awsCredentials, aws.T1Micro, aws.USEast, 30)
serverPool := NewAWSPool(awsCredentials, aws.T1Micro, aws.China, 30)
Join(clientPool, serverPool).RunNow(func(h Host) []string {
return []string{
"sudo apt-get update",
"sudo apt-get upgrade -y",
"sudo apt-get install -y mercurial git bzr gcc",
"hg clone -u release https://code.google.com/p/go",
# Clear the cookies
$ rm cookies.txt
# Create a user
$ curl -v -b cookies.txt -c cookies.txt -X POST 127.0.0.1:8080/api/v0.1/employees -d '{"employeeId":666, "password":"hello"}'
HTTP/1.1 201 Created
# Try querying without auth
$ curl -v -b cookies.txt -c cookies.txt -X GET 127.0.0.1:8080/api/v0.1/employees
HTTP/1.1 401 Unauthorized
var schedule = function(taskArr) {
// 1st step: sort data by gain (from max to min)
var sortedByGain = insertionSort(taskList, "gain");
var n = sortedByGain.length;
var timeSlot = new Array();
// 2nd step: number the jobs 1,2,3,..,n, then
for (var i = 0; i < n; i++) {
var task = sortedByGain.pop()