Skip to content

Instantly share code, notes, and snippets.

Carlo Alberto Ferraris CAFxX

View GitHub Profile
@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"
View atomic_splitmix64.go
package fastrand
import (
"math/rand"
"sync/atomic"
)
type SplitMix64 uint64
var _ rand.Source64 = &SplitMix64{}
View sharded.go
package sharded
import(
"unsafe"
"sync/atomic"
"reflect"
"math/bits"
"runtime"
)
@CAFxX
CAFxX / github-wishlist.md
Last active Jun 6, 2019
Github wishlist
View github-wishlist.md

GitHub wishlist

Smart redirect for branch-less URLs

URLs of the form https://github.com/user/repo/something/somethingelse should redirect to https://github.com/user/repo/defaultbranch/something/somethingelse if:

  • something does not match a branch name
  • something/somethingelse exists in defaultbranch

Smart redirect for renamed files

URLs of the form https://github.com/user/repo/branch/something/somethingelse should redirect to https://github.com/user/repo/branch/somethingnew if:

  • something/somethingelse else does not currently exist in branch
@CAFxX
CAFxX / asm.s
Last active May 25, 2019
All the missing AMD64 atomic instructions for Golang
View asm.s
// Code generated by command: go run gen.go -out asm.s -stubs stub.go. DO NOT EDIT.
#include "textflag.h"
// func AddInt8(addr *int8, a0 int8)
TEXT ·AddInt8(SB), NOSPLIT, $0-16
MOVQ addr+0(FP), AX
MOVB a0+8(FP), CL
LOCK
You can’t perform that action at this time.