Skip to content

Instantly share code, notes, and snippets.

View CAFxX's full-sized avatar

Carlo Alberto Ferraris CAFxX

View GitHub Profile
name old time/op new time/op delta
BuildString_Builder/1Write_NoGrow-2 43.4ns ± 2% 43.4ns ± 1% ~ (p=0.392 n=13+13)
BuildString_Builder/3Write_NoGrow-2 163ns ± 1% 161ns ± 1% -0.77% (p=0.001 n=13+14)
BuildString_Builder/3Write_Grow-2 61.1ns ± 1% 61.7ns ± 2% +0.98% (p=0.001 n=15+15)
BuildString_ByteBuffer/1Write_NoGrow-2 75.4ns ± 2% 76.4ns ± 1% +1.24% (p=0.000 n=13+12)
BuildString_ByteBuffer/3Write_NoGrow-2 230ns ± 2% 335ns ±15% +45.70% (p=0.000 n=13+13)
BuildString_ByteBuffer/3Write_Grow-2 181ns ± 2% 247ns ±15% +36.28% (p=0.000 n=14+15)
GenericNoMatch-2 380ns ± 2% 407ns ± 6% +7.07% (p=0.000 n=15+15)
GenericMatch1-2 5.37µs ± 4% 5.28µs ± 4% -1.68% (p=0.023 n=15+15)
GenericMatch2-2 21.1µs ± 3% 20.8µs ± 2% ~ (p=0.098 n=15+15)
@CAFxX
CAFxX / partitioner.go
Last active November 15, 2018 01:09
Sarama BalancedAffinityPartitioner
package partitioner
/*
A partitioner that assigns affinity from keys to partitions, while at the same time
attempting to spread the load across partitions. Affinity, to this end, is temporary.
This means that the affinity of a key to a partition changes over time.
There are three parameters that affect how often the affinity changes:
- every timeWindow affinity changes for all keys
- when, within a timeWindow, a key produces more than switchEveryBytes bytes or
switchEveryMessages messages the affinity of that key changes
@CAFxX
CAFxX / gojit.go
Last active November 22, 2018 01:10
Visualize what a Golang JIT would look like
package main
import "go/jit"
func main() {
// jit.Run is a shorthand for jit.Compile, jit.Link and jit.Load
c, err := jit.Run(`
// - compiler is the same as the one used to build the executable
// the jit is running in
// - imports are allowed (but are restricted to the imports of
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',
@CAFxX
CAFxX / cache.phpi
Created December 18, 2011 16:58
PHP remote file/URL cache
<?php
/*
A simple cache for remote files/URLs
2011 Carlo Alberto Ferraris <cafxx@strayorange.com>
===================================================
The cache function allows you to get the contents of a remote URL at
most once every N seconds. It also supports the If-Modified-Since HTTP
header to avoid fetching the resource again if it hasn't changed.
package main
import (
"bytes"
"fmt"
"io"
"sync"
)
type AsyncWriter struct {
@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
@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"