Friday, September 11, 2026

Go routines hack

 If you are running multiple Go Routines in your program and you want your program to not end then do this.

Option 1:

select {}

Note: by using this you are simply blocking till you press ctrl + c.


Option 2:

sigChan := make(chan os.Signal, 1)

signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)

<-sigChan 

Note: creating a channel which is expecting a SIGTEM :) ... thats a hack.

Monday, August 10, 2026

 Bubble Sort in Golang


package main

import "fmt"

func main() {

data := []int{54, 26, 30, 1, 40, 2, -1, -100}
for j := 0; j < len(data); j++ {
for i := 0; i < len(data); i++ {
if i < len(data)-1 {
if data[i] > data[i+1] {
fmt.Println("swapping ", data[i], data[i+1])
data[i], data[i+1] = data[i+1], data[i]
}
}
}
}
fmt.Println(data)
}