Skip to content

Instantly share code, notes, and snippets.

@ngerakines
Created April 22, 2024 15:20
Show Gist options
  • Save ngerakines/d9c98579a357edf95a633ef7c2b0f416 to your computer and use it in GitHub Desktop.
Save ngerakines/d9c98579a357edf95a633ef7c2b0f416 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
"github.com/carlmjohnson/crockford"
)
func encodeInt64(value int64) string {
var src [5]byte
src[0] = byte(value >> 32)
src[1] = byte(value >> 24)
src[2] = byte(value >> 16)
src[3] = byte(value >> 8)
src[4] = byte(value)
return string(crockford.Append(crockford.Lower, []byte{}, src[:]))
}
func main() {
now := time.Date(2024, 4, 22, 10, 44, 35, 0, time.UTC)
encodedNow := crockford.Time(crockford.Lower, now)
fmt.Println(now)
fmt.Println(now.Unix())
fmt.Println(encodedNow)
fmt.Println(crockford.Partition(encodedNow, 4))
userID := int64(1234567890)
fmt.Println(userID)
normalizedUserID := encodeInt64(userID)
fmt.Println(normalizedUserID)
fmt.Println("p2:nb:" + normalizedUserID)
fmt.Println("p2:ss1" + normalizedUserID + ":" + crockford.Time(crockford.Lower, time.Now()))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment