utils

package
v0.0.0-...-a65d55f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildUrl

func BuildUrl(host, path string, query map[string]string) string

BuildUrl returns the url composed of <host><path>?<query>.

func NewDeterministicRand

func NewDeterministicRand(hash []byte) *rand.Rand

func QueryParamBool

func QueryParamBool(c echo.Context, name string) bool

QueryParamBool parse the query param `name` to a boolean

func QueryParamInt64

func QueryParamInt64(c echo.Context, name string) (int64, error)

QueryParamInt64 parse the query param `name` to an int64

func RandomID

func RandomID(numberOnly bool, length int, isTaken func(string) bool) string

RandomID generates a random ID, for which `isTaken` is false.

func RandomString

func RandomString(numberOnly bool, length int) string

func RemoveAccents

func RemoveAccents(s string) string

func SQLError

func SQLError(err error) error

func SampleIndex

func SampleIndex(weights []float64) int

Sample choose an index between 0 and len(weights)-1 at random, with the given weights, which must sum up to 1.

func WebsocketError

func WebsocketError(ws *websocket.Conn, err error)

WebsocketError format `err` and send a Control message to `ws`

Types

type Shuffler

type Shuffler []int

Shuffler is a permutation used to shuffle a slice, storing the shuffled to original indices map.

func NewDeterministicShuffler

func NewDeterministicShuffler(hash []byte, n int) Shuffler

NewDeterministicShuffler returns a random permutation of length `n`, seeded with a value computed from `hash`. The seed is adjusted to make sure the permuation is not the identity (unless n <= 1).

func (Shuffler) OriginalToShuffled

func (sh Shuffler) OriginalToShuffled() []int

OriginalToShuffled reverse the permutation, returning the original index -> shuffled index map.

func (Shuffler) Shuffle

func (sh Shuffler) Shuffle(moveTo func(dst, src int))

Shuffle shuffles a slice using `moveTo`, which should be, in pseudo code : destination[dst] = source[src]

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL