Skip to content

Instantly share code, notes, and snippets.

Avatar

Qichao Zhang usbuild

View GitHub Profile
@usbuild
usbuild / jit.py
Created Sep 8, 2020
python jit代码示例
View jit.py
# 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 Aug 26, 2020
stc8g芯片改装红外控制电器
View stc8_ir.c
#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;
View initray.sh
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 Dec 29, 2018
implement C closure! you can pass closure to external c apis via function pointer.
View cbind.c
#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 Dec 12, 2018
debian ubuntu server initialize
View debian_init.sh
#!/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 Nov 7, 2018
A Simple cpp coroutine implementation
View co.cpp
#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 Nov 1, 2018
A naive calculator with interpreter and jit. Just for teaching and demo.
View jit_calculator.c
#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 Apr 2, 2018
simple implementation of blockchain
View blockchain.go
package blockchain
import (
"time"
"crypto/sha256"
"encoding/binary"
"bytes"
"fmt"
)
@usbuild
usbuild / raft.py
Last active Apr 2, 2018
a naïve implmentation of raft consensus algorithm
View raft.py
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 Mar 29, 2018
a circular queue using shared memory, eventfd and unix domain socket
View shm_queue.cpp
//
//#pragma once
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <stddef.h>
#include <string>
#include <sys/time.h>
#include <time.h>