Shareable Git-powered notebooks
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

71 lines
1.1 KiB

package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/hex"
"log"
"os"
"strings"
"time"
)
var stickSalt []byte
func expandPath(path string) (string, error) {
if !strings.HasPrefix(path, "~") {
return path, nil
}
homedir, err := os.UserHomeDir()
if err != nil {
return "", err
}
return homedir + path[1:], nil
}
func uniqueInts(input []int) []int {
u := make([]int, 0, len(input))
m := make(map[int]bool)
for _, val := range input {
if _, ok := m[val]; !ok {
m[val] = true
u = append(u, val)
}
}
return u
}
func stripLeadingCheckbox(line string) string {
line = strings.ToLower(line)
if startsWithCheckbox.MatchString(line) {
line = line[3:]
}
return line
}
func hashWithSalt(str string, salt []byte) string {
h := hmac.New(sha256.New, salt)
h.Write([]byte(str))
return hex.EncodeToString(h.Sum(nil))
}
func hash(str string) string {
return hashWithSalt(str, stickSalt)
}
func elapsed(what string) func() {
start := time.Now()
return func() {
log.Printf("%s: %v\n", what, time.Since(start))
}
}
func checkError(err error) {
if err != nil {
panic(err)
}
}