Skip to content

Instantly share code, notes, and snippets.

View CAFxX's full-sized avatar

Carlo Alberto Ferraris CAFxX

View GitHub Profile
@CAFxX
CAFxX / optcpu.go
Created October 16, 2019 15:22
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 / aligned.go
Created January 23, 2020 00:52
aligned
package aligned
import (
"fmt"
"unsafe"
"golang.org/x/sys/cpu"
)
const (
cacheLineSize = unsafe.Sizeof(cpu.CacheLinePad{})
@CAFxX
CAFxX / dict.go
Last active January 28, 2020 09:04
dict.go
package main
import (
"fmt"
//"strings"
"io/ioutil"
"sync"
"runtime"
)
/*
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 / shrinkmap.go2
Last active June 29, 2020 01:21
Shrinking map using go generics
// 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
const byte CCHAR_SUB_2[8] PROGMEM = {
B00000,
B00000,
B00000,
B11000,
B00100,
B01000,
B10000,
B11100
@CAFxX
CAFxX / bench_test.go
Last active September 8, 2020 23:43
Golang sharding primitive
package main
import (
"runtime"
"sync"
"sync/atomic"
"testing"
"unsafe"
)
@CAFxX
CAFxX / caching-adapter.go
Last active January 22, 2021 14:32
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 / 00_cpu_wishlist.md
Last active October 21, 2025 08:18
CPU ISA and implementation wishlists
@CAFxX
CAFxX / ffscast.sh
Created March 1, 2021 02:04
ffmpeg screencast for macos
# there's a bunch of things that don't work properly:
# - can't capture computer audio output - it desyncs
# - need to change the input devices (`-i "v:a"`) based on the output of `ffmpeg -f avfoundation -list_devices true -i ""`
ffmpeg \
-thread_queue_size 150 -f avfoundation -probesize 50M -framerate 30 -pix_fmt uyvy422 -i "2:3" \
-thread_queue_size 150 -f avfoundation -probesize 50M -framerate 30 -pix_fmt uyvy422 -capture_cursor 1 -capture_mouse_clicks 1 -i "4" \
-filter_complex '
[1]fps=fps=30[scr],
[scr]scale=-1:1440[scr],