Skip to content

Instantly share code, notes, and snippets.

Avatar

Carlo Alberto Ferraris CAFxX

View GitHub Profile
@CAFxX
CAFxX / caching-adapter.go
Last active Jan 22, 2021
caching-adapter.go
View caching-adapter.go
type ctxKey struct{}
type Cache interface {
Get(key string) CachedResponse
Put(key string, r CachedResponse) CachedResponse
}
type CachedResponse interface {
Emit(w http.ResponseWriter) error
@CAFxX
CAFxX / mutex.go
Last active Nov 25, 2020
Golang mutex with TryLock
View mutex.go
package sync
import "sync"
type Mutex struct {
m sync.Mutex
c sync.Cond
l bool
noCopy noCopy
}
@CAFxX
CAFxX / bench_test.go
Last active Sep 8, 2020
Golang sharding primitive
View bench_test.go
package main
import (
"runtime"
"sync"
"sync/atomic"
"testing"
"unsafe"
)
View LCD.ino
const byte CCHAR_SUB_2[8] PROGMEM = {
B00000,
B00000,
B00000,
B11000,
B00100,
B01000,
B10000,
B11100
@CAFxX
CAFxX / shrinkmap.go2
Last active Jun 29, 2020
Shrinking map using go generics
View shrinkmap.go2
// Just an experiment to build a minimal "fix" for
// https://github.com/golang/go/issues/20135
// using go generics.
//
// It's actually a better "go" map than the builtin
// ones, as the zero value is a valid map. :)
//
// WARNING: ONLY MINIMAL TESTING HAS BEEN PERFORMED.
package main
View serial_printf.ino
/*
serial_printf.ino
2020 CAFxX
serial_printf is a printf for Arduino Serial output that uses no dynamic allocation (malloc)
and constant stack space (in addition to that of printf).
Supports the same syntax of the standard Arduino/AVR printf-like functions.
Returns the number of characters printed.
Examples:
@CAFxX
CAFxX / dict.go
Last active Jan 28, 2020
dict.go
View dict.go
package main
import (
"fmt"
//"strings"
"io/ioutil"
"sync"
"runtime"
)
View aligned.go
package aligned
import (
"fmt"
"unsafe"
"golang.org/x/sys/cpu"
)
const (
cacheLineSize = unsafe.Sizeof(cpu.CacheLinePad{})
View optcpu.go
func getOptimalCpuConfig(request, limit float64) (request, limit float64, cores int) {
if request == 0 && limit == 0 {
return
} else if request < 0 {
panic("negative request")
} else if limit < 0 {
panic("negative limit")
} else if limit != 0 && request > limit {
panic("request > limit")
}
@CAFxX
CAFxX / hibp_bloom_poc.go
Last active Oct 1, 2019
quick and dirty bloom filter service for querying the haveibeenpwned dataset
View hibp_bloom_poc.go
package main
import (
"bufio"
"flag"
"fmt"
"net/http"
"os"
"regexp"
"strings"