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 | |
remote=some.remote.host | |
OPTIND=1 | |
while getopts :r: option 2>/dev/null | |
do | |
case $option in | |
r) remote="$OPTARG" ;; | |
\:) echo >&2 "fatal: option [$OPTARG] requires an argument\n" ;; |
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
func escapeSingleQuote(slice []byte) []byte { | |
l := len(slice) | |
var shifts int | |
for index := l - 1; index >= 0; index-- { | |
if slice[index] == '\'' { | |
slice = append(slice, byte(0)) | |
copy(slice[index+1:], slice[index:]) // move bytes to right | |
shifts++ | |
} | |
} |
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 main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"net/http" | |
"os" | |
gohm "github.com/karrick/gohm/v2" | |
) |
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
// These funcitons ought to come with a huge warning. Using them without | |
// understanding the differences between blocking and non-blocking, or | |
// between exclusive and shared access, and when to use them will cause | |
// problems that do not necessarily manifest right away, but rather | |
// fester in your program and rear their ugly head in the middle of the | |
// night when you're sleeping. | |
// | |
// If you use advisory file locking, *always* use Shared locking every | |
// single time you read the file, and *always* use Exclusive locking every | |
// single time you write the file. Period. There are no exceptions. Heed |
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
// growByteSlice will return a byte slice with a capacity at least equal to the | |
// specified size. | |
func growByteSlice(buf []byte, need int) []byte { | |
// Optimization for when buffer might be required to grow by more than | |
// double its size. | |
if need > cap(buf)<<1 { | |
t := make([]byte, need) | |
copy(t, buf) | |
return t | |
} |
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 main | |
import "time" | |
func backoff(retries int, callback func() error) error { | |
var err error | |
delay := time.Millisecond | |
for { | |
err = callback() | |
if err == 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 main | |
import ( | |
"fmt" | |
"os" | |
"github.com/karrick/godirwalk" | |
"github.com/pkg/errors" | |
) |
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 main | |
import ( | |
"bufio" | |
"fmt" | |
"io" | |
"os" | |
"time" | |
"github.com/karrick/gorill" |
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 sortAndMaybeInsertString | |
func sortAndMaybeInsertString(s string, a []string) []string { | |
if len(a) == 0 { | |
return append(a, s) | |
} | |
sort.Strings(a) | |
i := sort.SearchStrings(a, s) |
NewerOlder