Skip to content

Instantly share code, notes, and snippets.

View zhu327's full-sized avatar
🥰
Out sick

Timmy zhu327

🥰
Out sick
View GitHub Profile
@zhu327
zhu327 / paser.py
Created November 16, 2017 07:50
imp语言解释器实现 http://python.jobbole.com/82206/
# coding: utf-8
import sys
import re
def lex(characters, token_exprs):
pos = 0
tokens = []
while pos < len(characters):
match = None
@zhu327
zhu327 / rc4.py
Created February 23, 2018 03:14
OpenSSL RC4
# coding:utf-8
class RC4:
def __init__(self,public_key = None):
if not public_key:
public_key = 'none_public_key'
self.public_key = public_key
self.index_i = 0;
self.index_j = 0;
@zhu327
zhu327 / gateway.py
Last active March 26, 2018 02:27
simple doge json gateway
# coding: utf-8
import argparse
from gevent import monkey
monkey.patch_socket()
import logging
logging.basicConfig(level=logging.DEBUG)
@zhu327
zhu327 / structure.py
Last active April 4, 2018 08:04
data structure
# coding: utf-8
u"""
线性数据结构, 栈, 队列, deques, 容器结构, 数据项之间存在相对的位置
"""
class Stack(object):
u"""
栈 先进后出
@zhu327
zhu327 / tracer.py
Created July 27, 2018 03:10
Python调用栈跟踪
# coding: utf-8
from __future__ import print_function
import re
import sys
filter = re.compile(r'site-packages/requests/.*')
def tracer(frame, event, args):
@zhu327
zhu327 / ws.py
Created August 6, 2018 08:08
tornado websocket client example
# coding: utf-8
from tornado import gen
from tornado import httpclient
from tornado import httputil
from tornado import ioloop
from tornado import websocket
import json
@zhu327
zhu327 / curl.sh
Created December 24, 2018 06:36
检查服务请求在各个阶段的消耗
curl -w %{time_connect}:%{time_starttransfer}:%{time_total} -X POST 'http://service-uri' -H 'Content-Type: application/json' --data 'post-data'
@zhu327
zhu327 / utils.go
Last active December 27, 2018 02:53
string byte 转换, 不需要申请内存, 对于不可变的byte, 以及临时变量转换有用, 需要变的byte一定不要用
package utils
import (
"reflect"
"unsafe"
)
func BytesToString(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}
func (s *server) respond(w http.ResponseWriter, r *http.Request, data interface{}, status int) {
w.WriteHeader(status)
if data != nil {
err := json.NewEncoder(w).Encode(data)
s.logf("json encode %s", err)
}
}
func (s *server) decode(w http.ResponseWriter, r *http.Request, v interface{}) error {
return json.NewDecoder(r.Body).Decode(v)
@zhu327
zhu327 / thread_pool.py
Last active September 17, 2019 06:38
简单线程池
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
一个基于thread和queue的线程池,以任务为队列元素,动态创建线程,重复利用线程,
通过close和terminate方法关闭线程池。
"""
import queue
import threading
import contextlib