Skip to content

Instantly share code, notes, and snippets.

Carlo Alberto Ferraris CAFxX

Block or report user

Report or block CAFxX

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
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
@CAFxX
CAFxX / index.md
Last active May 22, 2019
Index of gists
View index.md
@CAFxX
CAFxX / golang_minimize_allocations.md
Last active Jun 5, 2019
Minimize allocations in Go
View golang_minimize_allocations.md

📂 Minimize allocations in Go

Working with protobuf in Go puts significant load on the memory subsystem, as protobuf-generated structures often contain a significant amount of pointers.

One way to minimize the number of allocations is to allocate all the fields at the same time, and then use internal pointers to wire them up.

Let's pretend you have (the generated Go code for) four messages A, B, C, and D (note: for clarity this is not really protobuf-generated code, but the technique

View asyncwriter.go
package main
import (
"bytes"
"fmt"
"io"
"sync"
)
type AsyncWriter struct {
View .hyper.js
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
You can’t perform that action at this time.