goutils

package module
v0.0.0-...-7a7712f Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2023 License: Apache-2.0 Imports: 18 Imported by: 26

README

goutils

Package of go stuff I will iterate on

installation

go get github.com/simonski/goutils

building

make 

running

nope, it's libraries

Github

Use PRs, I have a github action for compile and test.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Abs

func Abs(a int) int

func Binary_to_decimal

func Binary_to_decimal(decimalValue string) int64

func Bitwisenot

func Bitwisenot(value int) int

func Check

func Check(e error)

func CheckErr

func CheckErr(err error)

func Console

func Console(msg ...string)

func Contains

func Contains(a string, list []string) bool

func Convert_strings_to_ints

func Convert_strings_to_ints(input []string) []int

func Decimal_to_binary

func Decimal_to_binary(value int64) string

func DirExists

func DirExists(filename string) bool

DirExists indicates if a file already exists... or not

func EvaluateFilename

func EvaluateFilename(filename string) string

EvaluateFilename replaces ~ with os.Getenv("HOME") on the filename

func Factorial

func Factorial(a uint64) uint64

func FileExists

func FileExists(filename string) bool

FileExists indicates if a file already exists... or not

func Intify

func Intify(value string) int

func Isint

func Isint(value string) bool

func LPad

func LPad(original string, padding string, repeat int) string

func LPadToFixedLength

func LPadToFixedLength(original string, padding string, maxLength int) string

func Load_file_to_ints

func Load_file_to_ints(filename string) []int

func Load_file_to_strings

func Load_file_to_strings(filename string) []string

func Make_map_of_inty_list

func Make_map_of_inty_list(data []int) map[int]int

make_map_of_inty_list helper makes a map[int]int of a []int to give me whatever go's maps key algorithm performance is, at the cost of the memory

func MaskPermutations

func MaskPermutations(maskData string, position int, results []string) []string

func Max

func Max(v1 int, v2 int) int

func Max64

func Max64(a int64, b int64) int64

func MaxU64

func MaxU64(a uint64, b uint64) uint64

func Min

func Min(v1 int, v2 int) int

func Min64

func Min64(a int64, b int64) int64

func MinU64

func MinU64(a uint64, b uint64) uint64

func RPad

func RPad(original string, padding string, repeat int) string

func RPadToFixedLength

func RPadToFixedLength(original string, padding string, maxLength int) string

func RandStringRunes

func RandStringRunes(n int) string

func Repeatstring

func Repeatstring(s string, times int) string

func ReverseString

func ReverseString(s string) string

func StripWhitespace

func StripWhitespace(line string) string

func TokenswitchEnvironmentVariables

func TokenswitchEnvironmentVariables(original string) string

Types

type Align

type Align int
const (
	AlignTable Align = iota
	AlignLeft
	AlignRight
	AlignCenter
)

type Bin

type Bin struct {
	Index       int     // position in original array
	Probability float64 // chance of this event occurring
	Count       int     // number of times it has occurred in this run
	LowerBound  float64 // lvalue in range of 0 .. 1 to accept
	UpperBound  float64 // rvalue in range of 0 .. 1 to accept
}

Bin helper to hold the probability and number of times it has occured

type BitSet

type BitSet struct {
	Bits   map[int]int
	Length int
}

func NewBitSet

func NewBitSet(value int64) *BitSet

func (*BitSet) ApplyMask

func (b *BitSet) ApplyMask(mask *Mask)

func (*BitSet) Clear

func (b *BitSet) Clear()

func (*BitSet) Get

func (b *BitSet) Get(index int) int

func (*BitSet) GetValue

func (b *BitSet) GetValue() int64

func (*BitSet) SetValue

func (b *BitSet) SetValue(value int64)

func (*BitSet) ToBinaryString

func (b *BitSet) ToBinaryString(bits int) string

type Column

type Column struct {
	Position     int
	Title        string
	WidthPercent int
	Align        Align
}

func (*Column) Width

func (column *Column) Width() int

type Counter

type Counter struct {
	Data map[string]int
}

func NewCounter

func NewCounter() *Counter

func (*Counter) Get

func (m *Counter) Get(key string, defaultValue int) int

func (*Counter) Increment

func (m *Counter) Increment(key string) int

func (*Counter) Keys

func (m *Counter) Keys() []string

func (*Counter) Put

func (m *Counter) Put(key string, value int)

type FileScanner

type FileScanner struct {
	io.Closer
	*bufio.Scanner
}

func BuildScanner

func BuildScanner(filename *string) *FileScanner

type IntMap

type IntMap struct {
	// contains filtered or unexported fields
}

func NewIntMap

func NewIntMap() *IntMap

func (*IntMap) Get

func (m *IntMap) Get(key int, defaultValue int) int

func (*IntMap) Increment

func (m *IntMap) Increment(key int) int

func (*IntMap) Put

func (m *IntMap) Put(key int, value int)

type Logger

type Logger struct {
	Prefix        string
	ShowTime      bool
	ShowPrefix    bool
	ShowLevel     bool
	DEBUG_ENABLED bool
	INFO_ENABLED  bool
	WARN_ENABLED  bool
	ERROR_ENABLED bool
	TRACE_ENABLED bool
}

func NewLogger

func NewLogger(prefix string) *Logger

func (*Logger) Debug

func (l *Logger) Debug(msg string)

func (*Logger) Decorate

func (l *Logger) Decorate(level string, msg string) string

func (*Logger) Error

func (l *Logger) Error(msg string)

func (*Logger) Info

func (l *Logger) Info(msg string)

func (*Logger) StdOut

func (l *Logger) StdOut(msg string)

func (*Logger) Trace

func (l *Logger) Trace(msg string)

func (*Logger) Warn

func (l *Logger) Warn(msg string)

type Mask

type Mask struct {
	Data string
}

func NewMask

func NewMask(value string) *Mask

func (*Mask) DeriveNewMask

func (m *Mask) DeriveNewMask(address string) *Mask

address: 000000000000000000000000000000101010 (decimal 42) mask: 000000000000000000000000000000X1001X result: 000000000000000000000000000000X1101X

func (*Mask) Get

func (b *Mask) Get(index int) string

func (*Mask) GetVariations

func (m *Mask) GetVariations() []string

type Point2D

type Point2D struct {
	X int
	Y int
}

func (*Point2D) Rotate

func (p *Point2D) Rotate(degrees int)

Rotates this point around origin 0, 0

func (*Point2D) RotateAroundOrigin

func (p *Point2D) RotateAroundOrigin(degrees int, origin *Point2D)

RotatesAroundOrigin rotates this point around the specified origin

type Point2DF

type Point2DF struct {
	X float64
	Y float64
}

func (*Point2DF) Translate

func (point *Point2DF) Translate(x float64, y float64) *Point2DF

type Point3D

type Point3D struct {
	X int
	Y int
	Z int
}

type Point4D

type Point4D struct {
	X int
	Y int
	Z int
	W int
}

type ProbabilityStore

type ProbabilityStore struct {
	Bins      []*Bin
	CallCount int
}

ProbabilityStore helper struct holds all Bins and methods

func NewProbabilityStore

func NewProbabilityStore(values []float64) *ProbabilityStore

NewProbabilityStore factory function creates a store and allocates the Bins against the array of probabilities

func (*ProbabilityStore) BinarySearch

func (store *ProbabilityStore) BinarySearch(value float64, bins []*Bin) int

BinarySearch performs a binary serach to find the appropriate bin for the passed value

func (ProbabilityStore) Debug

func (store ProbabilityStore) Debug(totalRows int)

Debug prints the results to stdout

func (*ProbabilityStore) Indexof

func (store *ProbabilityStore) Indexof(value float64) int

Indexof return the position in the array of the Bin that serves the value or -1 if it does not exist

func (ProbabilityStore) Length

func (store ProbabilityStore) Length() int

Length returns integer number of Bins in the store

func (*ProbabilityStore) Search_o_log_n

func (store *ProbabilityStore) Search_o_log_n(value float64) int

Search_o_log_n performs a search in o(n) time to find the appropriate bin for the passed value

func (*ProbabilityStore) Search_on

func (store *ProbabilityStore) Search_on(value float64) int

Search_on performs a search in o(n) time to find the appropriate bin for the passed value

type Stopwatch

type Stopwatch struct {
	Prefix string
	Splits []*StopwatchEntry
}

func NewStopwatch

func NewStopwatch(prefix string) *Stopwatch

func (*Stopwatch) Clear

func (s *Stopwatch) Clear()

func (*Stopwatch) DebugMilliseconds

func (s *Stopwatch) DebugMilliseconds() string

func (*Stopwatch) DebugNanoseconds

func (s *Stopwatch) DebugNanoseconds() string

func (*Stopwatch) End

func (s *Stopwatch) End()

func (*Stopwatch) First

func (s *Stopwatch) First() *StopwatchEntry

func (*Stopwatch) Last

func (s *Stopwatch) Last() *StopwatchEntry

func (*Stopwatch) Size

func (s *Stopwatch) Size() int

func (*Stopwatch) Split

func (s *Stopwatch) Split(msg string) *StopwatchEntry

func (*Stopwatch) Start

func (s *Stopwatch) Start()

type StopwatchEntry

type StopwatchEntry struct {
	Moment  time.Time
	Message string
}

type SysInfo

type SysInfo struct {
	Hostname string `bson:hostname`
	Platform string `bson:platform`
	CPU      string `bson:cpu`
	RAM      uint64 `bson:ram`
	Disk     uint64 `bson:disk`
}

SysInfo saves the basic system information

func NewSysInfo

func NewSysInfo() *SysInfo

func (*SysInfo) IsLinux

func (*SysInfo) IsLinux() bool

func (*SysInfo) IsMacOS

func (*SysInfo) IsMacOS() bool

func (*SysInfo) IsWindows

func (*SysInfo) IsWindows() bool

type Table

type Table struct {
	Align           Align
	Columns         []*Column
	SeparatorWidth  int
	SeparatorColumn string
	SeparatorLine   string
	Border          bool
}

func NewTable

func NewTable() *Table

func (*Table) Add

func (table *Table) Add(column *Column)

func (*Table) Header

func (table *Table) Header() string

func (*Table) Line

func (table *Table) Line() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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