Skip to content

Instantly share code, notes, and snippets.

Qichao Zhang usbuild

Block or report user

Report or block usbuild

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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>
View process_vm_readv_test.c
#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>
View org.js
function loadScript(js, cb) {
var script = document.createElement("script");
script.src = js;
script.onload = function() {
if (cb) { cb(); }
};
document.querySelector("body").appendChild(script);
}
function loadCSS(css, cb) {
View blog_deploy.sh
#!/usr/bin/env bash
set -o errexit #abort if any command fails
me=$(basename "$0")
help_message="\
Usage: $me [-c FILE] [<options>]
Deploy generated files to a git branch.
Options:
You can’t perform that action at this time.