Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
from struct import unpack
from bcc import BPF
from socket import if_indextoname
C_BPF_KPROBE = """
#include <net/sock.h>

UPDATE:

These results are invalid. Some of the server implementations don't parse correctly and rust-tokio/ponylang-tcp don't seem to parse at all. See here for better benchmarks: https://gist.github.com/kprotty/5a41e9612657de00788478a7dde43d78

====

wrk -t4 -c128 -d10 --latency http://localhost:12345

  • Machine:
    • Intel Core i7-6700k (4 cores, 8 threads, 4.2ghz)
    • 16GB DDR4 2400mhz RAM
    • Arch Linux, Kernel 5.2.8
@Mattemagikern
Mattemagikern / Certificates.go
Created May 9, 2019 08:31
Create x509 certificate chain using Golang. Root CA, Designated CA, server CA
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"math/big"
@adampresley
adampresley / ExampleUsingWorkerPool.go
Last active May 16, 2020 14:51
Example using the worker pool
package main
import (
"fmt"
"time"
"pkg/workerpool"
)
type Job struct {
@pseudomuto
pseudomuto / main_1.go
Last active May 23, 2024 17:03
Blog Code: Clean SQL Transactions in Golang
package main
import (
"database/sql"
"log"
)
func main() {
db, err := sql.Open("VENDOR_HERE", "YOUR_DSN_HERE")
handleError(err)
type Dispatcher struct {
// A pool of workers channels that are registered with the dispatcher
WorkerPool chan chan Job
}
func NewDispatcher(maxWorkers int) *Dispatcher {
pool := make(chan chan Job, maxWorkers)
return &Dispatcher{WorkerPool: pool}
}
@itbdw
itbdw / ip_whitelist.lua
Last active April 2, 2024 10:43 — forked from Ceelog/cloudSettings
Nginx Lua IP Whitelist Rule
-- a quick LUA access script for nginx to check IP addresses match an
-- `ip_whitelist` set in Redis, and if no match is found send a HTTP
-- 403 response or just a custom json instead.
--
-- allows for a common whitelist to be shared between a bunch of nginx
-- web servers using a remote redis instance. lookups are cached for a
-- configurable period of time.
--
-- white an ip:
-- redis-cli SADD ip_whitelist 10.1.1.1
@makasim
makasim / 1_usecase.php
Last active August 1, 2018 14:03
Async non blocking process daemon. Stderr\Stdout proxy, Child reboot on exit, Graceful child exit on sigterm, reload on usr1 signal
<?php
use Symfony\Component\Process\PhpExecutableFinder;
require_once __DIR__.'/../vendor/autoload.php';
$phpBin = (new PhpExecutableFinder)->find();
if (false === $phpBin) {
throw new \LogicException('Php executable could not be found');
}
@dantheman213
dantheman213 / export_db_structure.sh
Last active March 5, 2024 02:55
Batch backup and export your Postgres or PostgreSQL table schemas and stored functions or procedures into individual *.sql files --the easy way!
#!/bin/sh
# AUTHOR
# DANIEL E. GILLESPIE (2016)
# https://github.com/dantheman213
# DESCRIPTION
# Export your app's table schemas and stored functions from a PostgreSQL
# database into individual *.sql files for easy management and source control.
var p1={
x:0,
y:0
};
var p2={
x:0,
y:1
};