Skip to content

Instantly share code, notes, and snippets.

View xjdrew's full-sized avatar
:octocat:

xjdrew xjdrew

:octocat:
View GitHub Profile
@xjdrew
xjdrew / squid_https.md
Last active June 5, 2025 07:05
配置squid https代理

编译

通过ubuntuapt-get安装的squid没有启用ssl功能,需要手动编译。

编译squid步骤如下。

安装依赖及获取源代码

apt-get install openssl libssl-dev ssl-cert
apt-get source squid
@xjdrew
xjdrew / stable_connection_protocol_2_0.md
Last active June 22, 2017 03:14
断线重连协议 2.0

断线重连协议 2.0

约定

  1. 定长协议: 每条协议的请求和响应应该是固定长度的。
  2. 小头编码:所有数字的字节都使用little-endian

协议

新建连接

@xjdrew
xjdrew / lsyslog.c
Created August 24, 2017 08:50
lsyslog.c
#include <syslog.h>
#include <lua.h>
#include <lauxlib.h>
#define LSYSLOG_FCOUNT 8
static int facilitys[LSYSLOG_FCOUNT] = {
LOG_LOCAL0,
LOG_LOCAL1,
@xjdrew
xjdrew / time.lua
Last active November 13, 2017 02:19
pure lua version of os.date("!*t", time)
-- port from golang: https://golang.org/src/time/time.go
--
local secondsPerMinute = 60
local secondsPerHour = 60 * 60
local secondsPerDay = 24 * secondsPerHour
local secondsPerWeek = 7 * secondsPerDay
local daysPer400Years = 365*400 + 97
local daysPer100Years = 365*100 + 24
local daysPer4Years = 365*4 + 1
@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"
@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 / 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 / bridge.md
Last active February 22, 2019 10:00
桥接网卡

桥接网卡

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

步骤

  • 创建namespace
# ip netns add netns1
# ip netns show
@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)