Skip to content

Instantly share code, notes, and snippets.

View caioreix's full-sized avatar
🏠
Working from home

Caio Almeida caioreix

🏠
Working from home
View GitHub Profile
@caioreix
caioreix / MakefileHelpCommand.makefile
Last active February 5, 2026 19:42
Makefile auto help
##@ Help
help: ## Show this help
@awk 'BEGIN {FS = ":.*?##"; cat = "Other"; n = 0} \
/^##@/ {cat = substr($$0, 4); gsub(/^[ \t]+|[ \t]+$$/, "", cat); next} \
/^[a-zA-Z0-9_-]+:/ {if (!(cat in order)) order[cat] = n++; name = $$1; sub(/:$$/, "", name); \
if (/##/) {gsub(/^[ \t]+|[ \t]+$$/, "", $$2); targets[cat] = targets[cat] sprintf(" \033[36m%-22s\033[0m %s\n", name, $$2)} \
else {targets[cat] = targets[cat] sprintf(" \033[90m%-22s\033[0m\n", name)}} \
END {n = asorti(order, sorted, "@val_num_asc"); \
for (i = 1; i <= n; i++) printf "\n\033[1m%s:\033[0m\n%s", sorted[i], targets[sorted[i]]}' $(MAKEFILE_LIST)

Problem

The go command line tool needs to be able to fetch dependencies from your private GitLab, but authenticaiton is required.

This assumes your private GitLab is hosted at privategitlab.company.com.

Environment variables

The following environment variables are recommended:

export GO111MODULE=on
export GOPRIVATE=privategitlab.company.com
@caioreix
caioreix / swap.sh
Created March 18, 2025 11:42
How to Increase Swap on Ubuntu Linux
# Font: https://www.youtube.com/watch?v=Tteiw6MY4QI
# Thanks to youtube: @LinuxHandbook and commenter @optimisticnilhist!
# Commands
swapon --show # : shows the swapfile or swap partition you have in your system. If its swapfile (which is the default) in ubuntu then following commmand work.
ls /swapfile #: shows your swap file and its size its in the root directory of your system.
sudo swapoff /swapfile #: instructs your system to not use the swap file.
fallocate -l 4G /swapfile #: fallocate command is used to allocate size to an existing file. Here we are making the size of the swapfile 4G
sudo mkswap /swapfile #: making this file named 'swapfile' the new swap file
@caioreix
caioreix / async_search.go
Last active February 6, 2025 14:50
Async Find With GORM
func getAllAsync[CH any](db *gorm.DB, pageSize int, ch chan<- *CH, wg *sync.WaitGroup, conds ...any) {
wg.Add(1)
defer close(ch)
defer wg.Done()
currentPage := 0
for {
rows := []*CH{}
_ = db.
Year: "2006" "06"
Month: "Jan" "January" "01" "1"
Day of the week: "Mon" "Monday"
Day of the month: "2" "_2" "02"
Day of the year: "__2" "002"
Hour: "15" "3" "03" (PM or AM)
Minute: "4" "04"
Second: "5" "05"
AM/PM mark: "PM"
@caioreix
caioreix / defer.go
Created September 14, 2023 09:39
Explain how the defer statement works in Go (Golang).
// Defer runs in a Last-In, First-Out (LIFO) manner,
// meaning that the last deferred function call will
// execute first, starting after the return call.
package main
import "fmt"
func main() {
@caioreix
caioreix / sqlc.sh
Created September 11, 2023 18:24
SQLC multi files generator
# This script doesn't meet my needs because it doesn't provide a way to reuse structs, but it might be helpful for you.
CURRENT_DIR=$(readlink -f $(dirname $0))
sql=$(
cat <<-END
- engine: {engine_name}
queries: {query_file}
schema: {schema_file}
gen:
@caioreix
caioreix / go-get-fork.md
Last active March 22, 2023 17:55
How to use forked package in golang
  1. Fork the package
  2. Make your changes
  3. Publish the module
  4. Set go modulues on go env -w GO111MODULE=on
  5. run go mod edit -replace github.com/original/gopackage=github.com/you/go-git@branch

for my example I had issues with package go.mau.fi/whatsmeow So first I forked the project and then did my changes. Then I run go mod edit -replace go.mau.fi/whatsmeow=github.com/caioreix/[email protected] (you can use the @branch or @commit, but it not works to me)

@caioreix
caioreix / golist.sh
Created March 22, 2023 17:41
Publishing a golang module
go mod tidy
go test ./...
git commit -m "mymodule: changes for v0.1.0"
git tag v0.1.0
git push origin v0.1.0
GOPROXY=proxy.golang.org go list -m example.com/[email protected]
# https://go.dev/doc/modules/publishing
@caioreix
caioreix / wterminal-clear.md
Last active March 22, 2023 17:43
Windows Terminal clear the screen using the "Ctrl + L" key combination instead of scrolling down

To make the Windows Terminal clear the screen using the "Ctrl + L" key combination instead of scrolling down in the terminal window, you'll need to add a custom shortcut key for this key combination. Follow the steps below:

  1. Open the Windows Terminal and click on the arrow icon on the title bar to open the dropdown menu.
  2. Click on "Settings" to open the Windows Terminal configuration JSON file in a text editor.
  3. Scroll down to the "actions" section and add the following entry:
{
  "command": "clearBuffer",
  "keys": "ctrl+l"
}