This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package p2p | |
import ( | |
"bytes" | |
"fmt" | |
"os" | |
"os/signal" | |
"runtime" | |
"sync" | |
"sync/atomic" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -e | |
PROJECTROOT=$GOPATH/src/github.com/<you>/<repo> | |
cd $PROJECTROOT | |
echo "Vetting project." | |
go vet || exit 1 | |
echo "...ok" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// accumulates non-nil errors | |
type errors []error | |
func (e *errors) Ack(err error) { | |
if err != nil { | |
*e = append(*e, err) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// io.Writer implementer | |
type writer func(p []byte) (int, error) | |
func (w writer) Write(p []byte) (int, error) { return w(p) } | |
// magic, a testing.T writer! | |
func testwriter(t *testing.T) io.Writer { | |
return writer(func(p []byte) (int, error) { | |
t.Log(string(p)) | |
return 0, nil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
switch { | |
case olderr != nil && newerr != nil: | |
return diff, fmt.Errorf("reading both source, %v", olderr) | |
case olderr != nil: | |
return diff, fmt.Errorf("reading old source, %v", olderr) | |
case newerr != nil: | |
return diff, fmt.Errorf("reading new source, %v", newerr) | |
default: | |
return diff, nil | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package log | |
import ( | |
"fmt" | |
"log/syslog" | |
"os" | |
"github.com/Sirupsen/logrus" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LogHook builds a func that can be fired by a doge/log through | |
// log.AddHook. If the entry it fires on contains an error, it will | |
// include a stacktrace of the logger's callsite. | |
// | |
// import "doge/log" | |
// | |
// log.AddHook( | |
// sentry.LogHook("my.pkg/name"), | |
// log.Lerror, log.Lpanic, log.Lfatal, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"snippets": [ | |
{ | |
"text": "sortby", | |
"title": "type bySomeOrder []type", | |
"value": "type $1 []$2\n\nfunc(b $1) Len() int { return len(b) }\nfunc(b $1) Swap(i, j int) { b[i],b[j] = b[j],b[i] }\nfunc(b $1) Less(i, j int) bool { return b[i].$3 < b[j].$3 }" | |
}, | |
], |
OlderNewer