Skip to content

Instantly share code, notes, and snippets.

View Jackarain's full-sized avatar

Jack Jackarain

View GitHub Profile
@Jackarain
Jackarain / test_asio.cpp
Created July 3, 2026 14:19
测试 asio 代码片段
#include <boost/asio.hpp>
#include <boost/asio/co_spawn.hpp>
#include <boost/asio/detached.hpp>
#include <boost/asio/use_awaitable.hpp>
#include <iostream>
#include <chrono>
#include <thread>
#include <sstream>
#include <iomanip>
@Jackarain
Jackarain / gen_cmake.py
Last active June 20, 2026 16:46
用于通过 openssl 源码生成 CMake 编译脚本
#!/usr/bin/env python3
import os
import subprocess
import re
# ==================== 配置项 ====================
EXCLUDE_DIRS = {
'test', 'apps', 'doc', 'demos', 'fuzz', 'util', 'os-dep',
'vms', 'ms', 'tools', 'bugs', 'external'
}
std::vector<uint8_t> data =
{
0x00, 0x00, 0xed, 0x01, 0x04, 0x00, 0x00, 0x00, 0x01, 0x3f, 0xe1, 0x3f, 0x88, 0x61, 0x96, 0xdc, 0x34, 0xfd, 0x28, 0x17, 0x54, 0xca, 0x3a, 0x94, 0x10, 0x04, 0xe2, 0x81, 0x72, 0xe3, 0x6d, 0x5c, 0x03, 0x8a, 0x62, 0xd1, 0xbf, 0x5f, 0x87, 0x49, 0x7c, 0xa5, 0x89, 0xd3, 0x4d, 0x1f, 0x6c, 0x96, 0xdc, 0x34, 0xfd, 0x28, 0x26, 0xd4, 0xd4, 0x44, 0xa8, 0x20, 0x09, 0xb5, 0x00, 0xf5, 0xc6, 0x9d, 0xb8, 0x16, 0x94, 0xc5, 0xa3, 0x7f, 0x0f, 0x13, 0x8c, 0xfe, 0x5c, 0x7a, 0x52, 0x3c, 0x57, 0xc4, 0xb0, 0x5e, 0x8d, 0xaf, 0xe7, 0x52, 0x84, 0x8f, 0xd2, 0x4a, 0x8f, 0x0f, 0x0d, 0x83, 0x71, 0x91, 0x35, 0x40, 0x8f, 0xf2, 0xb4, 0x63, 0x27, 0x52, 0xd5, 0x22, 0xd3, 0x94, 0x72, 0x16, 0xc5, 0xac, 0x4a, 0x7f, 0x85, 0x02, 0xe0, 0x00, 0x99, 0x77, 0x78, 0x8c, 0xa4, 0x7e, 0x56, 0x1c, 0xc5, 0x81, 0x90, 0xb6, 0xcb, 0x80, 0x00, 0x3f, 0x76, 0x86, 0xaa, 0x69, 0xd2, 0x9a, 0xfc, 0xff, 0x40, 0x85, 0x1d, 0x09, 0x59, 0x1d, 0xc9, 0x8f, 0x9d, 0x98, 0x3f, 0x9b, 0x8d, 0x34, 0xcf, 0xf3, 0xf6, 0xa5, 0x23, 0x81, 0x97, 0x00, 0x0f, 0x7
@Jackarain
Jackarain / asio_http2_client.cpp
Created January 11, 2026 01:39
asio_http2_client.cpp
// g++ -std=c++23 foo.cpp -lssl -lcrypto -lnghttp2 -lpthread
#include <boost/assert.hpp>
#include <boost/asio.hpp>
#include <boost/asio/ssl.hpp>
#include <nghttp2/nghttp2.h>
#include <atomic>
#include <cstring>
#include <deque>
#include <iostream>
@Jackarain
Jackarain / TcpConnection.ts
Last active June 28, 2025 07:48
TcpConnection.ts 将 tcp 连接转换成能 await 读写的类,这在一些异步交互协议的读取中十分有效,从而避免 on('data') 的使用
import * as net from 'net';
// TCP 连接类,仅处理发送和接收
export class TcpConnection {
// Socket 由外部传入
private socket: net.Socket;
// 存储接收到的数据
private buffer: Buffer;
// 读取数据限制, 0 表示无限制
private readLimit: number;
@Jackarain
Jackarain / jsonrpc.hpp
Last active June 18, 2025 04:45
Json rpc 实现
//
// jsonrpc.hpp
// ~~~~~~~~~~~
//
// Copyright (c) 2023 Jack (jack dot wgm at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
@Jackarain
Jackarain / index.ts
Last active June 3, 2025 14:30
btc/eth/tron 地址转换
/*
* 需要安装以下依赖:
* yarn add ethers bitcoinjs-lib ecpair tiny-secp256k1 bs58
* yarn add @types/bitcoinjs-lib @types/ecpair @types/tiny-secp256k1 @types/bs58
* yarn add ts-node typescript
*/
import { ethers } from 'ethers';
import { ECPairFactory } from 'ecpair';
import bitcoin from 'bitcoinjs-lib';
@Jackarain
Jackarain / stackoverflow.cpp
Last active December 17, 2024 15:56
async_simple 的爆栈问题测试代码
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "async_simple/coro/Lazy.h"
#include "async_simple/coro/SyncAwait.h"
// asio_coro_util.hpp 在 demo_example 下, 这里仅仅为了调用 AsioCallbackAwaiter 这个简单的 Awaiter 而已.
#include "asio_coro_util.hpp"
@Jackarain
Jackarain / awaitable.hpp
Last active September 29, 2024 13:52
c++ 20 协程简易实现
#pragma once
#include <coroutine>
#include <functional>
#include <type_traits>
#if defined(DEBUG) || defined(_DEBUG)
#include <unordered_set>
std::unordered_set<void*> global_crors;
#endif
@Jackarain
Jackarain / ssl_stream.hpp
Created November 25, 2023 08:06
基于 c++ 20 的 boost asio ssl_stream 实现
//
// ssl_stream.hpp
// ~~~~~~~~~~~~~~
//
// Copyright (c) 2023 Jack (jack dot wgm at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//