Skip to content

Instantly share code, notes, and snippets.

View usbuild's full-sized avatar

Qichao Zhang usbuild

View GitHub Profile
@usbuild
usbuild / jit.py
Created September 8, 2020 06:37
python jit代码示例
# coding=utf-8
import dis
import mmap
import struct
from ctypes import *
from functools import wraps
from typing import Union
import numpy as np
@usbuild
usbuild / stc8_ir.c
Created August 26, 2020 13:47
stc8g芯片改装红外控制电器
#include <STC/STC8G.h>
#include <intrins.h>
sbit IR_PIN_IN = P3 ^ 2;
//http://www.51hei.com/bbs/dpj-165191-1.html
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned int u16;
DOMAIN=$1
// 开启bbr
modprobe tcp_bbr
echo "tcp_bbr" | tee --append /etc/modules-load.d/modules.conf
echo "net.core.default_qdisc=fq" | tee --append /etc/sysctl.conf
echo "net.ipv4.tcp_congestion_control=bbr" | tee --append /etc/sysctl.conf
sysctl -p
// 安装程序
@usbuild
usbuild / cbind.c
Last active December 29, 2018 09:46
implement C closure! you can pass closure to external c apis via function pointer.
#include <stddef.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#define CODE_SIZE 200
typedef union slot_t {
@usbuild
usbuild / debian_init.sh
Last active December 12, 2018 03:29
debian ubuntu server initialize
#!/usr/bin/env bash
#install tmux git subversion wget uuid-dev liblzma-dev libgdbm-dev libncurses5-dev libbz2-dev libssl-dev libreadline-dev libsqlite3-dev libffi-dev
if [[ 1 -eq 2 ]]; then
echo "set-option -g default-shell /bin/zsh" > ~/.tmux.conf
mkdir ~/usr
mkdir ~/download
@usbuild
usbuild / co.cpp
Created November 7, 2018 09:21
A Simple cpp coroutine implementation
#include "co.hpp"
#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <map>
#include <mutex>
using namespace pm::common;
@usbuild
usbuild / jit_calculator.c
Last active December 18, 2023 09:11
A naive calculator with interpreter and jit. Just for teaching and demo.
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <assert.h>
#define STACK_MAX 100
#define CODE_SIZE (2 * 1024 * 1024)
@usbuild
usbuild / blockchain.go
Last active May 27, 2022 11:51
simple implementation of blockchain
package blockchain
import (
"time"
"crypto/sha256"
"encoding/binary"
"bytes"
"fmt"
)
@usbuild
usbuild / raft.py
Last active April 2, 2018 07:55
a naïve implmentation of raft consensus algorithm
import sys
from flask import Flask, jsonify, request
from threading import Thread, Lock
from collections import defaultdict
import time
import urllib
import random
import logging
import json
@usbuild
usbuild / shm_queue.cpp
Last active March 29, 2018 08:52
a circular queue using shared memory, eventfd and unix domain socket
//
//#pragma once
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stddef.h>
#include <string>
#include <sys/time.h>
#include <time.h>