Skip to content

Instantly share code, notes, and snippets.

View usbuild's full-sized avatar

Qichao Zhang usbuild

View GitHub Profile
@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 / 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;
#include <sys/uio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <sys/socket.h>
#include <time.h>
#include <stdlib.h>
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 / vimrc
Last active December 4, 2018 01:56
set nocompatible
filetype off
set nu
colo desert
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Bundle 'gmarik/vundle'
Bundle 'tpope/vim-fugitive'
@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;