Skip to content

Instantly share code, notes, and snippets.

View c4pt0r's full-sized avatar

dongxu c4pt0r

View GitHub Profile
#ifndef TSTRING_H
#define TSTRING_H
#include <string.h>
#include <string>
#undef DISALLOW_EVIL_CONSTRUCTORS
#define DISALLOW_EVIL_CONSTRUCTORS(TypeName) \
void operator=(const TypeName&)
@c4pt0r
c4pt0r / pot.py
Created April 13, 2012 10:43
pot
#encoding=utf-8
import tornado
import pytyrant
import tornado.web
import tornado.ioloop
import json as simplejson
tt_server = None
class PutHandler(tornado.web.RequestHandler):
1) "account:history:huangdx"
2) "account:history:shidh"
3) "account:zhaojing"
4) "account:id:10"
5) "account:id:11"
6) "account:id:12"
7) "account:id:13"
8) "account:id:14"
9) "account:id:15"
10) "account:id:16"
import os
import jsonrpclib
from mongoengine import *
connect('dict')
class Page(Document):
created_at = db.DateTimeField(default=datetime.datetime.now, required=True)
word = db.StringField(max_length=255, required=True, unique = True)
#encoding=utf-8
#simple http/sockJS comet server written by huangdx
import tornado.ioloop
import tornado.web
import sockjs.tornado
import json
class TestHandler(tornado.web.RequestHandler):
def get(self):
@c4pt0r
c4pt0r / pysqs.py
Created August 29, 2012 00:32
pysqs
#!/usr/bin/env python
# * simple RESTful http queue service *
# written by c4pt0r <[email protected]>
# date 2012-8-29
import os
import tornado.ioloop
import tornado.web
import tornado.gen
#encoding=utf-8
import os
import sys
import redis
def read_list(filename):
c = open(filename).read()
return [s.lstrip().rstrip() for s in c.split('\n')]
r = redis.Redis('nb391x.corp.youdao.com', 6379)
@c4pt0r
c4pt0r / log.c
Created September 21, 2012 08:01
simple logger
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
#include <time.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include "log.h"
@c4pt0r
c4pt0r / conn.c
Created September 22, 2012 03:41
create non blocking socket
#include "conn.h"
int
_set_non_blocking(int s) {
int x;
x = fcntl(s,F_GETFL,0);
fcntl(s,F_SETFL,x | O_NONBLOCK);
return s;
}