Skip to content

Instantly share code, notes, and snippets.

View smallnest's full-sized avatar

smallnest smallnest

View GitHub Profile
@astoycos
astoycos / xdp_redirect_ex.c
Last active February 18, 2024 02:09
XDP_REDIRECT_EX
SEC("xdp")
int xdp_nodeport_redirect(struct xdp_md *ctx)
{
void *data_end = (void *)(long)ctx->data_end;
void *data = (void *)(long)ctx->data;
struct bpf_fib_lookup fib_params = {};
struct ethhdr *eth = data;
struct tcphdr *tcph;
u16 h_proto;
u64 nh_off;
@Merovius
Merovius / README.md
Created July 16, 2021 22:55
MergeSlice benchmarks

The post Go is not C, so there is not an extreme fast way to merge slices alleges a performance problem with Go's model of zeroing memory on allocation, in cases where it might not be needed. The methodology is

  • Run a benchmark that merges some slices, by makeing one of the appropriate size and copying the individual slices over
  • Run a benchmark that zeros a slice of the appropriate slice
  • Subtract the two numbers and call it the "overhead of zeroing"

I have some trouble with that methodology. For one, it assumes that the zeroing

@rigelrozanski
rigelrozanski / imgcat.go
Created April 30, 2020 03:55
Iterm2 imgcat image output from golang
import (
"encoding/base64"
"fmt"
"io/ioutil"
"os"
)
func main() {
r, err := os.Open("yourimagehere.png")
if err != nil {
@asukakenji
asukakenji / 0-go-os-arch.md
Last active October 18, 2024 01:21
Go (Golang) GOOS and GOARCH

Go (Golang) GOOS and GOARCH

All of the following information is based on go version go1.17.1 darwin/amd64.

GOOS Values

GOOS Out of the Box
aix
android
package main
import (
"golang.org/x/net/context"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
"github.com/docker/docker/cli/command"
"github.com/docker/docker/client"
"fmt"
@mangalaman93
mangalaman93 / sysserver.go
Last active May 14, 2024 02:39
setting low level socket options in golang (SO_PRIORITY, SO_REUSEADDR)
package main
import (
"bufio"
"fmt"
"net"
"os"
"syscall"
)
@denji
denji / golang-tls.md
Last active October 1, 2024 16:57 — forked from spikebike/client.go
Simple Golang HTTPS/TLS Examples

Moved to git repository: https://github.com/denji/golang-tls

Generate private key (.key)
# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048

# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
package main
import (
"fmt"
)
func decorator(f func(s string)) func(s string) {
return func(s string) {
fmt.Println("Started")