Skip to content

Instantly share code, notes, and snippets.

View zheplusplus's full-sized avatar

Zhe Lin zheplusplus

View GitHub Profile
@zheplusplus
zheplusplus / setinterval.c
Created November 12, 2015 02:37
C timer example
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/epoll.h>
#include <sys/timerfd.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
void setnonblock(int sockfd)
function $extend(inherit, b) {
var base = b.$class;
for (var m in base) {
if (base.hasOwnProperty(k)) {
inherit[k] = base[k];
}
}
function ctor() {
this.constructor = inherit;
@zheplusplus
zheplusplus / ifcfg-enp0s8
Created August 17, 2015 06:58
ceph-virtualbox-guide-network-config
HWADDR=
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
@zheplusplus
zheplusplus / redis_profiling.py
Created January 16, 2015 06:58
Redis profiling script (random keys)
import sys
import uuid
import random
from datetime import datetime
import redis
prefix = str(uuid.uuid4())
groups = 20
run_per_group = 1000
total = groups * run_per_group
@zheplusplus
zheplusplus / for_each_i.hpp
Last active August 29, 2015 14:10
C++0x for_each with index
template <typename Iterator, typename Function>
Function for_each_i(Iterator begin, Iterator end, Function f)
{
typedef decltype(*begin) value_type;
int i = 0;
return std::move(std::for_each(begin, end, [&](value_type& e) {f(i++, e);}));
}
@zheplusplus
zheplusplus / group.py
Created July 2, 2014 10:16
Mahjong Waits Algorithm
class Group(object):
pass
class Sequence(Group):
def __init__(self, suit, starting_rank):
self.suit = suit
self.starting_rank = starting_rank
@zheplusplus
zheplusplus / tukasans.py
Last active August 29, 2015 13:59
つかさンス ASCII Art Font
import sys
import json
FIXED_WIDTH = len('_________')
FIXED_HEIGHT = 6
def map_characters(string, typo_group):
return {
string[col]: [typo_group[row][col * (1 + FIXED_WIDTH):
import sys
import os
import tempfile
import uuid
import subprocess
import collections
def parse_seq(sequence):
Segment = collections.namedtuple('Segment', 'epnum,start,duration,subt')
result = []
# encoding=utf-8
# from http://bbs.eve-china.com/thread-583164-1-1.html
SHIP_REPROCESSING = {
'Incursus': {
u'三钛合金': 11528,
u'类晶体胶矿': 9882,
u'类银超金属': 3656,
u'同位聚合体': 7,
@zheplusplus
zheplusplus / keeprun.c
Last active December 27, 2015 10:49
Keep a process running, and recover it after terminated. 我们不用很麻烦也能让一个进程持续跑起来.
#include <stdio.h>
#include <unistd.h>
#include <sys/wait.h>
int main(int argc, char* argv[])
{
if (argc == 1) {
fprintf(stderr, "Usage:\n");
fprintf(stderr, "keeprun prog arg0 arg1 ...");
return 1;