Skip to content

Instantly share code, notes, and snippets.

@xiocode
xiocode / zipdb.py
Created May 31, 2012 01:21 — forked from mayli/zipdb.py
Use a zipfile store a dict like k-v database
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# zipdb.py
# Use a zipfile store a dict like k-v database.
# Known bug: duplicate key(filenames) allowed
#
# Copyright 2012 mayli <mayli.he@gmail.com>
#
@xiocode
xiocode / pinhole.py
Created May 31, 2012 02:01 — forked from mayli/pinhole.py
A simple port multiplexer
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# author: mayli <mayli.he@gmail.com>
#
# Modified from Pinhole, and the original code is found here:
# {{{ http://code.activestate.com/recipes/114642/ (r1)
#
"""
usage: pinhole
@xiocode
xiocode / gist:3090669
Created July 11, 2012 14:20 — forked from tmc/gist:776364
simple multiprocessing gevent echo server
import sys
from gevent import server
from multiprocessing import Process, current_process, cpu_count
def note(format, *args):
sys.stderr.write('[%s]\t%s\n' % (current_process().name, format%args))
def echo(socket, address):
print 'New connection from %s:%s' % address
@xiocode
xiocode / gist:3090710
Created July 11, 2012 14:26 — forked from creotiv/gist:1217855
Multicore gevent wsgi server
import sys
from gevent import server
from gevent.baseserver import _tcp_listener
from gevent import pywsgi
from gevent.monkey import patch_all; patch_all()
from multiprocessing import Process, current_process, cpu_count
def hello_world(env, start_response):
if env['PATH_INFO'] == '/':
start_response('200 OK', [('Content-Type', 'text/html')])
@xiocode
xiocode / dbbake.sh
Created July 18, 2012 02:56 — forked from syshack/dbbake.sh
mysql bak
#!/usr/bin/env bash
#dbbake.sh
#author:syshack
#date:2011.9.10
#数据库
DBName=mysql
#用户名
DBUser=root
#数据库密码
DBPasswd=
## {{{ http://code.activestate.com/recipes/410692/ (r8)
# This class provides the functionality we want. You only need to look at
# this if you want to know how this works. It only needs to be defined
# once, no need to muck around with its internals.
class switch(object):
def __init__(self, value):
self.value = value
self.fall = False
def __iter__(self):
import gevent
from gevent.event import AsyncResult
import gevent.pool
import gevent.queue
class WorkerQueue(object):
def __init__(self):
self.group = gevent.pool.Group()
self.q = gevent.queue.Queue()
root@xio:~# ab -n 1000 -c 100 http://www.xtimes.me/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking www.xtimes.me (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
package main
import (
"unicode/utf8"
)
type Item string
type Stream chan Item
type Acc string
@xiocode
xiocode / gist:5468519
Created April 26, 2013 16:22
根据 struct 的 一个 filed 获取 struct 的指针!
import (
"fmt"
"unsafe"
)
type A struct {
data string
e int
}