Skip to content

Instantly share code, notes, and snippets.

View pedrobertao's full-sized avatar
🚀

Pedro Bertao pedrobertao

🚀
View GitHub Profile
@pedrobertao
pedrobertao / inter_seq.go
Created July 25, 2025 17:42
Example native iterateble
// Package main demonstrates Go iterator patterns using the iter package.
// This program showcases both built-in iterators from maps/slices packages
// and custom iterator implementation.
package main
import (
"fmt" // for formatted output
"iter" // for iterator types (Go 1.23+)
"maps" // for map iterator utilities
"slices" // for slice iterator utilities
@pedrobertao
pedrobertao / routineswithtimeout.go
Created July 23, 2025 11:36
Go routines + context.timeout
package main
import (
"context"
"fmt"
"os"
"time"
)
func main() {
@pedrobertao
pedrobertao / promieall.go
Created July 17, 2025 15:54
promise_all_in_go.go
package main
import (
"fmt"
"io"
"net/http"
)
// Result holds the result of a work function execution
type Result struct {
@pedrobertao
pedrobertao / faninfanout.go
Created July 17, 2025 15:17
Go concurrency demo using fan-out/fan-in pattern with worker goroutines processing jobs through channels.
package main
import (
"fmt"
"time"
)
// doubleIt is a simple work function that doubles the input value
func doubleIt(a int) int {
return a * 2
@pedrobertao
pedrobertao / pi_with_random.go
Last active July 25, 2025 17:50
Calculating pi with go
package main
import (
"crypto/rand"
"encoding/binary"
"fmt"
"math"
"sync"
)
@pedrobertao
pedrobertao / main.go
Created March 3, 2025 12:51
Modified Z-Score by Claude.ai
package main
import (
"fmt"
"math"
"sort"
)
// RemoveOutliersSmallDataset removes outliers from a small dataset using the Modified Z-score method
// threshold is typically 3.5 (more conservative) to 3.0 (more aggressive)
@pedrobertao
pedrobertao / main.go
Created March 3, 2025 12:30
IQR Method Claude.ai in Go
package main
import (
"fmt"
"math"
"sort"
)
// RemoveOutliers removes outliers from a slice of prices using the IQR method
// multiplier is typically 1.5 for mild outlier detection or 3 for extreme outliers
@pedrobertao
pedrobertao / main_test.go
Last active September 22, 2024 14:09
Fibonacci Benchmark Test
func BenchmarkFibRecursive(b *testing.B) {
for i := 0; i < b.N; i++ {
fibRecursive(uint(10))
}
}
func BenchmarkFibIterative(b *testing.B) {
for i := 0; i < b.N; i++ {
fibIterative(uint(10))
}
}
@pedrobertao
pedrobertao / fib.go
Last active September 22, 2024 14:05
Recursive and Iterative Fibonnaci Sequence
package main
import "fmt"
func fibRecursive(position uint) uint {
if position <= 2 {
return 1
}
return fibRecursive(position-1) + fibRecursive(position-2)
}
@pedrobertao
pedrobertao / fibWithRoutines.go
Created September 4, 2024 12:31
fib with go routines
package main
import (
"fmt"
"sync"
)
var wg sync.WaitGroup
func readFib(c <-chan int) {