Skip to content

Instantly share code, notes, and snippets.

View xjdrew's full-sized avatar
:octocat:

xjdrew xjdrew

:octocat:
View GitHub Profile
@xjdrew
xjdrew / map.cpp
Created August 14, 2020 03:15
hash_map vs lua table
extern "C" {
#include "lua.h"
#include "lauxlib.h"
}
#include <string>
#include <ext/hash_map>
using namespace std;
using namespace __gnu_cxx;

build

go build tcpinfo.go

run

./tcpinfo -h
./tcpinfo
@xjdrew
xjdrew / cloudSettings
Last active November 29, 2021 08:49
vscode settings sync
{"lastUpload":"2021-11-29T08:49:08.133Z","extensionVersion":"v3.4.3"}
@xjdrew
xjdrew / jump_consistent_hash.lua
Created April 21, 2020 03:48
lua version: A Fast, Minimal Memory, Consistent Hash Algorithm
local function jump_consistent_hash(key, num_buckets)
local b = -1
local j = 0
while j < num_buckets do
b = j
key = key * 2862933555777941757 + 1
j = math.floor((b+1) * (1<<31) / ((key>>33) + 1))
end
return b
end
@xjdrew
xjdrew / case1.lua
Created October 8, 2019 14:21
lua gc test case
local count = 10000
local items = 10000
local g = {}
collectgarbage("stop")
function run_gc_test(tag, mt)
for i=1,count do
local t = {}
if mt then
setmetatable(t, mt)
@xjdrew
xjdrew / bridge.md
Last active February 22, 2019 10:00
桥接网卡

桥接网卡

模拟docker的网络,使network namespace中的网卡可以访问外网

步骤

  • 创建namespace
# ip netns add netns1
# ip netns show
@xjdrew
xjdrew / a.cpp
Created November 15, 2018 12:42
null reference
#include <stdio.h>
int* a[5];
int& ref() {
return *a[0];
}
void print(int* p) {
printf("%p\n", p);
}
@xjdrew
xjdrew / nanosleep.c
Created August 20, 2018 07:31
nanosleep resolution
#include <sys/time.h>
#include <sys/resource.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define ONE_SECOND 1000000000L
#define ONE_MS 1000000L
@xjdrew
xjdrew / dsa.go
Last active February 20, 2024 08:04
DSA example
package main
import (
"crypto/dsa"
"crypto/rand"
"crypto/sha1"
"crypto/x509"
"encoding/asn1"
"encoding/pem"
"errors"