Skip to content

Instantly share code, notes, and snippets.

View PeteGabriel's full-sized avatar
🏇
chances are im on a horse

Pedro Gabriel PeteGabriel

🏇
chances are im on a horse
View GitHub Profile
@PeteGabriel
PeteGabriel / decode_decimal.go
Created April 15, 2024 09:33
decode the Avro logical type Decimal
func decodeAvroDecimal(data []byte) float64 {
number := new(big.Int).SetBytes(data)
// Check if the number is negative
mostSignificantBit := byte(0x80)
if data[0]&mostSignificantBit > 0 {
// For negative numbers, take two's complement
number.Sub(number, new(big.Int).Lsh(big.NewInt(1), uint(len(data))*8))
}
package main
import (
"errors"
"fmt"
)
func main() {
var err error
import Cocoa
//contants do not vary
let a = "Hello, playground"
//a = "Hello, world" // error: reassignment to constant 'a'
//variables can vary
var anotherA = "Hello, Pedro"
package main
import "fmt"
/*
A function that received an array and a value
and returns true if the array contains the value
and false if the value is missing.
*/
import (
"fmt"
"github.com/goombaio/namegenerator"
"math/rand"
"time"
)
func main() {
seed := time.Now().UTC().UnixNano()
nameGenerator := namegenerator.NewNameGenerator(seed)
@PeteGabriel
PeteGabriel / pieces_results_sync.go
Created March 6, 2020 10:34
Synchronization between pieces and results in golang
type Piece struct {
index int
length int
}
type Result struct {
index int
}
func main() {
func main() {
naturals := make(chan int)
squares := make(chan int)
//Counter
//implicit conversion
go counter(naturals)
//Squarer
//implicit conversion
func main() {
naturals := make(chan int)
squares := make(chan int)
//Counter
go func() {
for x := 0; x < 10; x++ {
naturals <- x
}
close(naturals)
@PeteGabriel
PeteGabriel / channels.go
Created February 27, 2020 13:33
Working with channels
package main
import (
"fmt"
"time"
)
var c chan string
var c1 chan int
public sealed class FileCache implements Cache {
private string directory;
public FileCache(string directory){
this.directory = directory;
}
public string get(string cacheKey){
...
}