dotfiles

regexghost dotfiles and scripts
git clone https://git.regexghost.com/dotfiles.git
Log | Files | Refs | README

commit 0d9b8f8b204b080a7702e725953b1cb46f5871e8
parent ea1970983d0e06f8d151453b8abb02a9ff534409
Author: regexghost <regexghost@protonmail.com>
Date:   Fri,  8 May 2026 19:45:28 +0100

added geohash.go

Diffstat:
Mterminal-scripts/Makefile | 2++
Aterminal-scripts/geohash.go | 92+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mterminal-scripts/rm-trash.sh | 4++--
3 files changed, 96 insertions(+), 2 deletions(-)

diff --git a/terminal-scripts/Makefile b/terminal-scripts/Makefile @@ -11,3 +11,5 @@ normal: cp heic_to_jpg.sh ${BIN}/heictojpg go build -o tablealigner tablealigner.go mv tablealigner ${BIN}/tablealigner + go build -o geohash geohash.go + mv geohash ${BIN}/geohash diff --git a/terminal-scripts/geohash.go b/terminal-scripts/geohash.go @@ -0,0 +1,92 @@ +package main + +import ( + "fmt" + "os" + "strconv" +) + +// I wrote this script a long time ago and I copied an example algorithm from the internet +// I can't find that source now, but another example implementation can be seen here: +// https://www.movable-type.co.uk/scripts/geohash.html + +const BASE_32 string = "0123456789bcdefghjkmnpqrstuvwxyz" + +func printHelp() { + fmt.Println("Usage:") + fmt.Println(" geohash lat lon [precision]") +} + +func main() { + if len(os.Args) < 3 { + printHelp() + os.Exit(1) + } + + var lat string = os.Args[1] + var lon string = os.Args[2] + var precision string = "12" + if len(os.Args) == 4 { + precision = os.Args[3] + } + + fmt.Println(encode(lat, lon, precision)) +} + +func getFloat64(input string) float64 { + res, err := strconv.ParseFloat(input, 64) + if err != nil { + panic(err) + } + return res +} + +func getInt(input string) int { + res, err := strconv.Atoi(input) + if err != nil { + panic(err) + } + return res +} + +func encode(latInput, lonInput, precisionInput string) string { + var lat float64 = getFloat64(latInput) + var lon float64 = getFloat64(lonInput) + var precision int = getInt(precisionInput) + + var n, s int = 0, 0 + var o bool = true + var r, c, d, l float64 = -90, 90, -180, 180 + var encodedString string = "" + + for len(encodedString) < precision { + if o { + var e2 float64 = (d + l) / 2 + if lon >= e2 { + n = 2 * n + 1 + d = e2 + } else { + n = n * 2 + l = e2 + } + } else { + var t2 float64 = (r + c) / 2 + if lat >= t2 { + n = 2 * n + 1 + r = t2 + } else { + n = n * 2 + c = t2 + } + } + o = !o + s++ + if s == 5 { + encodedString = encodedString + string(BASE_32[n]) + s = 0 + n = 0 + } + } + + return encodedString +} diff --git a/terminal-scripts/rm-trash.sh b/terminal-scripts/rm-trash.sh @@ -27,12 +27,12 @@ for arg; do ! [ -e "$filename" ] && echo "File/Directory doesn't exit" && continue if [ -d "$filename" ]; then - if [ -z "$(ls -"$filename")" ]; then + if [ -z "$(ls -A "$filename")" ]; then read -p "${dialog} ${filename} (empty dir) (y/N) " confirm else read -p "${dialog} ${filename} (non-empty dir) (y/N) " confirm fi - [ "$uservar" = "y" ] && "$command" -- "$filename" + [ "$confirm" = "y" ] && "$command" -- "$filename" continue fi