Skip to content

Instantly share code, notes, and snippets.

View usbuild's full-sized avatar

Qichao Zhang usbuild

View GitHub Profile
@usbuild
usbuild / jquery.at.complete.js
Created December 24, 2012 11:45
a plugin to simulate at prompt
/**
* Created with JetBrains PhpStorm.
* User: Usbuild
* Date: 12-12-20
* Time: 上午10:21
*/
(function ($) {
$.fn.at_complete = function (options) {
var opts = $.extend({}, $.fn.at_complete.defaults, options);
from google.protobuf import service
from test_pb2 import TestService_Stub, TestService, TestMessage, TestClientService, TestClientService_Stub
import asyncore, threading, socket, struct
class ServerService(TestService):
def setStub(self, ch):
self.stub = TestClientService_Stub(ch)
def Test(self, controller, reply, done):
msg = TestMessage()
@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'
#!/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:
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) {
#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>
@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>
@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 / 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_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)