Skip to content

Instantly share code, notes, and snippets.

View garrydzeng's full-sized avatar

Octobrain garrydzeng

  • Xiamen, Fujian, China
  • 13:26 (UTC +08:00)
View GitHub Profile
@garrydzeng
garrydzeng / CodeTimer.cs
Last active May 24, 2016 04:58
Simple C# Code Timer by JeffreyZhao
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
public static class CodeTimer
{
public static void Initialize()
{
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
@garrydzeng
garrydzeng / event.js
Created July 12, 2013 07:49
JavaScript addEvent, written by Dean Edwards
// written by Dean Edwards, 2005
// with input from Tino Zijdel, Matthias Miller, Diego Perini
// http://dean.edwards.name/weblog/2005/10/add-event/
function addEvent(element, type, handler) {
if (element.addEventListener) {
element.addEventListener(type, handler, false);
} else {
// assign each event handler a unique ID
@garrydzeng
garrydzeng / database_factory.py
Last active August 29, 2015 14:03
Database factory for DBAPI 2.0
import configparser
class DatabaseFactory(object):
def __init__(self, filename, encoding=None):
"""instantiate with configuration filename"""
self._cache = dict()
self._servers = configparser.ConfigParser()
self._servers.read(filename, encoding)
// Stephen Toub
// [email protected]
//
// ManagedThreadPool.cs
// ThreadPool written in 100% managed code. Mimics the core functionality of
// the System.Threading.ThreadPool class.
//
// HISTORY:
// v1.0.1 - Disposes of items remaining in queue when the queue is emptied
// - Catches errors thrown during execution of delegates
@garrydzeng
garrydzeng / CommandOption.cs
Last active December 20, 2015 07:17
CommandOption is a callback-based program option parser.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security;
using System.Text.RegularExpressions;
using System.Linq;
@garrydzeng
garrydzeng / deploy
Last active June 22, 2016 07:47
checkout source code and publish to remote server via rsync
#!/bin/env bash
# deploy project script.
# make sure /usr/local/etc/deployment.key permissions is 600.
# this is required to open it.
set -e
build=
revision=HEAD
@garrydzeng
garrydzeng / JumpConsistentHash.cpp
Last active June 30, 2016 06:02
jump consistent hash
// http://arxiv.org/ftp/arxiv/papers/1406/1406.2294.pdf
int32_t JumpConsistentHash(uint64_t key, int32_t num_buckets) {
int64_t b = -1, j = 0;
while (j < num_buckets) {
b = j;
key = key * 2862933555777941757ULL + 1;
j = (b + 1) * (double(1LL << 31) / double((key >> 33) + 1));
}
return b;
}
; [warnning] select your disk first
clean
convert gpt
create partition efi size=100 offset=20 ; start at LBA-40 for 4K aligned (the first sector that is divisible by 8 (after LBA-33))
format quick fs=fat32
create partition msr size=16 ; required by windows
create partition primary size=81920 ; seperate system to a partiton (make reinstall system earier)
format quick fs=ntfs label=Windows
assign letter=C
create partition primary ; remaining spaces
{
"compilerOptions": {
"jsx": "react",
"moduleResolution": "node",
"module": "commonjs",
"experimentalDecorators": true,
"target": "es5",
"lib": [
"es5",
"scripthost",
@garrydzeng
garrydzeng / getopt.js
Created October 13, 2017 01:52
Read command parameter (argument or option) from generator
function* getopt(argv) {
let cache = null
// ignore execution program & script filename by call to .slice() function.
for (let node of argv.slice(2)) {
const match = /^--([a-z][0-9a-z-]*)(?:=(.*))?$/i.exec(node)
// hanlde cache first...