Skip to content

Instantly share code, notes, and snippets.

View CAFxX's full-sized avatar

Carlo Alberto Ferraris CAFxX

View GitHub Profile
src/math/bits/bits.go:283:6: can inline Len as: func(uint) int { if UintSize == 32 { }; return Len64(uint64(x)) }
src/math/bits/bits.go:55:6: can inline TrailingZeros as: func(uint) int { if UintSize == 32 { }; return TrailingZeros64(uint64(x)) }
src/math/bits/bits.go:113:6: can inline OnesCount as: func(uint) int { if UintSize == 32 { }; return OnesCount64(uint64(x)) }
src/math/bits/bits.go:170:6: can inline RotateLeft as: func(uint, int) uint { if UintSize == 32 { }; return uint(RotateLeft64(uint64(x), k)) }
src/math/bits/bits.go:212:6: can inline Reverse as: func(uint) uint { if UintSize == 32 { }; return uint(Reverse64(uint64(x))) }
src/math/bits/bits.go:253:6: can inline ReverseBytes as: func(uint) uint { if UintSize == 32 { }; return uint(ReverseBytes64(uint64(x))) }
src/math/bits/bits.go:415:6: can inline Mul as: func(uint, uint) (uint, uint) { if UintSize == 32 { }; h, l = Mul64(uint64(x), uint64(y)); return uint(h), uint(l) }
src/math/bits/bits.go:458:6: can inline Div as: func(uint, uint, uin
@CAFxX
CAFxX / .hyper.js
Created January 9, 2019 08:25
Hyper config
// 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',
package main
import (
"bytes"
"fmt"
"io"
"sync"
)
type AsyncWriter struct {
@CAFxX
CAFxX / golang_minimize_allocations.md
Last active June 5, 2025 03:07
Minimize allocations in Go

📂 Minimize allocations in Go

A collection of tips for when you need to minimize the number of allocations in your Go programs.

Use the go profiler to identify which parts of your program are responsible for most allocations.

Caution

Never apply these tricks blindly (i.e. without measuring the actual performance benefit/impact).

[!NOTE]

@CAFxX
CAFxX / index.md
Last active January 2, 2022 01:24
Index of gists
@CAFxX
CAFxX / asm.s
Last active May 25, 2019 00:27
All the missing AMD64 atomic instructions for Golang
// 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 / github-wishlist.md
Last active June 6, 2019 00:43
Github wishlist

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
package sharded
import(
"unsafe"
"sync/atomic"
"reflect"
"math/bits"
"runtime"
)
package fastrand
import (
"math/rand"
"sync/atomic"
)
type SplitMix64 uint64
var _ rand.Source64 = &SplitMix64{}
@CAFxX
CAFxX / hibp_bloom_poc.go
Last active October 1, 2019 02:19
quick and dirty bloom filter service for querying the haveibeenpwned dataset
package main
import (
"bufio"
"flag"
"fmt"
"net/http"
"os"
"regexp"
"strings"