Initial commit

This commit is contained in:
Aynakeya
2022-06-21 13:02:22 -07:00
commit 9f75839ebc
161 changed files with 18766 additions and 0 deletions

9
util/hash.go Normal file
View File

@@ -0,0 +1,9 @@
package util
import "hash/fnv"
func Hash64(s string) uint64 {
h := fnv.New64()
h.Write([]byte(s))
return h.Sum64()
}

7
util/image.go Normal file
View File

@@ -0,0 +1,7 @@
package util
import "image"
func ReadImage(path string) image.Image {
return nil
}

40
util/string.go Normal file
View File

@@ -0,0 +1,40 @@
package util
import (
"fmt"
"strconv"
)
func SliceString(str string, from int, to int) (string, bool) {
sList := []rune(str)
if to <= 0 {
to = len(sList) + to
}
if from >= len(sList) || to > len(sList) {
return "", false
}
return string(sList[from:to]), true
}
func LenString(str string) int {
return len([]rune(str))
}
func StringNormalize(str string, min int, max int) string {
fmtStr := fmt.Sprintf("%%-%d.%ds", min, max)
return fmt.Sprintf(fmtStr, str)
}
func StringSliceContains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true
}
}
return false
}
func StringToInt(s string) int {
i, _ := strconv.Atoi(s)
return i
}

7
util/time.go Normal file
View File

@@ -0,0 +1,7 @@
package util
import "fmt"
func FormatTime(time int) string {
return fmt.Sprintf("%01d:%02d", time/60, time%60)
}

10
util/time_test.go Normal file
View File

@@ -0,0 +1,10 @@
package util
import (
"fmt"
"testing"
)
func TestFormatTime(t *testing.T) {
fmt.Println(FormatTime(60 * 60))
}