This file contains hidden or 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 ( | |
"context" | |
"errors" | |
"fmt" | |
"time" | |
"github.com/gammazero/workerpool" | |
) |
This file contains hidden or 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 ( | |
"path" | |
"syscall" | |
) | |
// isMountPoint returns true if the given directory is a mountpoint | |
func isMountPoint(fileName string) (bool, error) { | |
dir := path.Clean(fileName) |
This file contains hidden or 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
function ask_yes_no() { | |
local prompt="$1" | |
while true; do | |
read -p "$prompt [y/n]?" yn | |
case "$yn" in | |
[Yy]* ) return 0;; | |
[Nn]* ) return 1;; | |
* ) echo "Please answer y or n";; | |
esac | |
done |
This file contains hidden or 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
// longestCommonPrefix returns the string in compares that has the longest common prefix with s | |
func longestCommonPrefix(s string, compares ...string) string { | |
var longestMatched int | |
var longestCmp string | |
maxLength := len(s) | |
for _, c := range compares { | |
cmpLen := len(c) | |
if cmpLen > maxLength { | |
cmpLen = maxLength | |
} |
This file contains hidden or 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
Channel Behaviors | |
* A receive from a nil channel blocks forever | |
* A receive from a closed channel returns the zero value immediately | |
* A receive on an empty channel blocks | |
* A send to a nil channel blocks forever | |
* A send to a closed channel panics | |
* A send to a full (or unbuffered) channel blocks until reader has read data |
This file contains hidden or 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 ( | |
"crypto/md5" | |
"crypto/sha1" | |
"crypto/sha256" | |
"crypto/sha512" | |
"hash" | |
"hash/fnv" | |
"testing" |
This file contains hidden or 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 fileExists(filename string) bool { | |
_, err := os.Stat(filename) | |
return !errors.Is(err, fs.ErrNotExist) | |
} | |
func dirExists(name string) (bool, error) { | |
fi, err := os.Stat(name) | |
if err != nil { | |
if errors.Is(err, fs.ErrNotExist) { | |
return false, nil |
This file contains hidden or 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 server | |
import ( | |
"fmt" | |
"time" | |
) | |
const ( | |
defaultWriteTimeout = 30 * time.Second | |
defaultReadTimeout = 30 * time.Second |
This file contains hidden or 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 ( | |
"container/heap" | |
) | |
type priorityQueue [][]int | |
func (pq priorityQueue) Len() int { return len(pq) } |
This file contains hidden or 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 ( | |
"flag" | |
"strings" | |
) | |
type arrayFlags []string | |
func (a *arrayFlags) String() string { |
OlderNewer