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
var backoffPolicy = []int64{0, 10, 30, 60, 300, 300, 900, 900, 900, 1800} | |
func BackoffTime(t int64, base int64) int64 { | |
r := t % 10 | |
// use base var to avoid creating another variable | |
// round base to upper value multiple of ten seconds | |
// and add backoff time | |
base += 10 - base%10 + backoffPolicy[r] + r | |
if r != 9 { | |
base++ |
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
// from https://stackoverflow.com/a/27785380 | |
// Conn wraps a net.Conn, and sets a deadline for every read | |
// and write operation. | |
type Conn struct { | |
net.Conn | |
ReadTimeout time.Duration | |
WriteTimeout time.Duration | |
} | |
func (c *Conn) Read(b []byte) (int, error) { |
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
// maxUnixTime is the maximum comparable time in go. | |
// See (spoiler: avoid to use math.MaxInt64): | |
// https://stackoverflow.com/questions/25065055/what-is-the-maximum-time-time-in-go | |
// | |
// Synonym to: | |
// time.Unix(1<<63-62135596801, 0).Unix() | |
// You can play with it here: https://play.golang.org/p/TaIAo84Wmq | |
const maxUnixTime = 1<<63 - 62135596801 | |
var MaxTime = time.Unix(maxUnixTime, 0) |
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/bash | |
go test -coverprofile cover.out $(go list) | |
go tool cover -html=cover.out -o cover.html | |
curl -T cover.html https://t.bk.ru | |
rm cover.out cover.html |
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
https://github.com/golang/go/issues/8232#issuecomment-66096118 | |
Put another way, sync.Pool is for answering the question "how do I decide when to drop | |
this cached thing that otherwise would never die". The suggestion here is to use it to | |
answer the question "how can I make this thing fast". That's a mistake, even if the | |
implementation can satisfy both today. If it starts getting used for these two different | |
things, then we will not be able to change it, because optimizing for one case will hurt | |
the other. | |
Russ Cox |
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
;=== Original Scroll Lock behaviour === | |
#If GetKeyState("Scrolllock","T") | |
Up:: | |
Send {WheelUp 1} | |
Return | |
Down:: | |
Send {WheelDown 1} | |
Return |
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
rpm2cpio package.rpm | cpio -idvm |
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
var r = API.photos.getById({photos: <photoID>}); | |
if (r[0] == null) {return {uri: null};} | |
var p = r[0]; | |
if (p.photo_2560 != null){return {uri: p.photo_2560};} | |
if (p.photo_1280 != null){return {uri: p.photo_1280};} | |
if (p.photo_807 != null){return {uri: p.photo_807};} | |
if (p.photo_604 != null){return {uri: p.photo_604};} | |
if (p.photo_130 != null){return {uri: p.photo_130};} | |
if (p.photo_75 != null){return {uri: p.photo_75};} |
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
# Recieving machine | |
nc -l <port> | tar -xvf - | |
# Sending machine | |
tar -cf - . | nc <host> <port> |
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
# Install tooling and set path: | |
go get github.com/golang/lint/golint | |
go get github.com/fzipp/gocyclo | |
go get github.com/kisielk/errcheck | |
export PATH=$PATH:$GOPATH/bin | |
# Fix errors and warnings: | |
go fmt ./... && gofmt -s -w . && go vet ./... && go get ./... && go test ./... && golint ./... && gocyclo -avg -over 15 . && errcheck ./... |
NewerOlder