This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func CreateBackoffTimer(initial, max, resetAfter time.Duration) func() { | |
lastWaitAt := time.Now() | |
delay := initial | |
return func() { | |
if time.Since(lastWaitAt) > resetAfter { | |
delay = initial | |
} | |
time.Sleep(delay) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Parallelize runs the specified number of tasks using the callback fn with the given number of worker threads | |
// the function argument takes the task number (counting from zero) | |
func Parallelize(nWorkers int, nTasks int, fn func(int)) { | |
wg := sync.WaitGroup{} | |
task := make(chan int, nTasks) | |
for t := 0; t < nTasks; t++ { | |
task <- t | |
} | |
close(task) // so it wont block when it's ranged over |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# | |
# MIT License | |
# | |
# Copyright (c) 2023 ZeroFlucs | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// now provides simple conversion between unix timestamps and formatted date/time strings | |
// | |
// # MIT License | |
// | |
// # Copyright (c) 2023 ZeroFlucs | |
// | |
// Permission is hereby granted, free of charge, to any person obtaining a | |
// copy of this software and associated documentation files (the “Software”), | |
// to deal in the Software without restriction, including without limitation | |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |