Skip to content

Instantly share code, notes, and snippets.

View pedrobertao's full-sized avatar
🚀

Pedro Bertao pedrobertao

🚀
View GitHub Profile
@pedrobertao
pedrobertao / main.go
Created September 5, 2024 10:20
fibonnaci performance
package main
import "fmt"
/*
* Fibonnaci's Number
* fb(pos)
* if n < 1
* f[0] = 1 f[1] =1
* else (n > 2)
* f[n] = sum(f[n-1] + f[n-2])
@pedrobertao
pedrobertao / fib.go
Last active September 5, 2024 08:34
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) {
@pedrobertao
pedrobertao / standard-media-queries.css
Last active February 21, 2024 09:39
Standard media queries css tricks width height landscape portrait
/* Small screens, laptops (landscape) ----------- */
@media only screen
and (min-device-width : 769px)
and (max-device-width : 1024px) {
/* Styles */
}
/* Desktops & large screens (landscape) ----------- */
@media only screen
and (min-device-width : 1025px)
@pedrobertao
pedrobertao / cmp.go
Created August 31, 2023 10:05
cmp package in golang
package main
import (
"cmp"
"fmt"
)
func main() {
var num, num2, num3 int64 = 1, 2, 1
var str, str2, str3 = "ab", "abc", "ab"
@pedrobertao
pedrobertao / maps.go
Created August 31, 2023 09:36
maps package in golang
package main
import (
"fmt"
"golang.org/x/exp/maps"
)
func main() {
m := map[string]string{
@pedrobertao
pedrobertao / clear.go
Created August 26, 2023 10:39
Example of Clear in Go
package main
import "fmt"
func main() {
intSlice := []int{1, 2, 3}
floatSlice := []float64{1.0, 2.0, 3.0}
stringSlice := []string{"a", "b", "c"}
mapString := map[string]string{
"Name": "Pedro",
@pedrobertao
pedrobertao / min-max.go
Last active August 27, 2023 12:16
Min/Max Golang 1.21
package main
import "fmt"
func main() {
minInt := min(3, 2, 1, 4)
minFloat := min(4.0, 2.0, 3.0, 1.0)
minString := min("ab", "a", "abcd", "abc")
// Range between two int64
func randomNum(min, max int64) int64 {
rand.Seed(time.Now().UnixNano())
num := (rand.Int63n(max-min+1) + min)
return num
}
func randomNum(min, max int64) string {
@pedrobertao
pedrobertao / any.go
Last active July 10, 2023 00:06
This is a simple example to use ANY in golang which is an alias for interface{}, therefore easy to read
#################################################
## EXAMPLE OF USAGE OF ANY IN AN OBJECT/STRUCT ##
#################################################
package main
import "fmt"
const (
MALE string = "male"
FEMALE string = "female"