Skip to content

Instantly share code, notes, and snippets.

View ronaldwolvers's full-sized avatar

Ronald Wolvers ronaldwolvers

  • Amsterdam
  • 05:59 (UTC +01:00)
View GitHub Profile
@ronaldwolvers
ronaldwolvers / remove_build_directories.sh
Created September 4, 2024 10:00
Remove build subdirectories in Bash/ZSH (POSIX compliant)
#!/bin/bash
# Delete all directories that are called 'build' in the directory from where this script
# is invoked.
echo -e "Removing all 'build' subdirectories..."
# According to https://github.com/koalaman/shellcheck/wiki/SC2038 whitespaces are interpreted
# by xargs in an unsafe way, therefore -print0 was added to `find` and -0 to `xargs`.
#find . -name "build" -type d | xargs -t -I {} rm -rf {}
//Tested with Go 1.19
func RemoveElementFromSliceAtIndex[type_param any](s []type_param, index int) []type_param {
return append (s[:index], s[index+1:]...)
}
//Calling the function
RemoveElementFromSliceAtIndex[Your_Type](slice, index_of_item_to_remove)
//This function cannot be called while looping as the item at index_of_item_to_remove+1 will reside at index_of_item_to_remove after calling this function!
@ronaldwolvers
ronaldwolvers / logging.go
Created February 10, 2023 14:09
Writing logs to a file in Go using a buffer (Go version 1.19)
package logging
import (
"fmt"
"os"
"time"
)
var enable_logging bool = true
@ronaldwolvers
ronaldwolvers / caching.go
Created February 10, 2023 11:19
Generic paged cache for Go maps (Go version 1.19)
package caching
type pagedMapCacheKey struct {
key int
page_number int
page_size int
}
const enable_caching bool = false