Skip to content

Instantly share code, notes, and snippets.

@wesdu
wesdu / say_hello.js
Created August 15, 2011 16:24
say hello
alert("hello world");
from Crypto.Cipher import AES
from Crypto import Random
BS = 16
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[0:-ord(s[-1])]
class AESCipher:
def __init__( self, key ):
"""
@wesdu
wesdu / pubfwd.py
Created December 12, 2013 09:10 — forked from minrk/pubfwd.py
"""
An XPUB/XSUB broker that forwards subscriptions
"""
import os
import string
import sys
import time
from random import randint
from threading import Thread
$ vi /etc/sysctl.conf
# 系统所有进程一共可以打开的文件数量, 每个套接字也占用一个文件描述字
fs.file-max = 1491124
# 系统同时保持TIME_WAIT套接字的最大数目,http 短链接会产生很多 TIME_WAIT 套接字。
net.ipv4.tcp_max_tw_buckets = 7000
# 关闭 tcp 来源跟踪
net.ipv4.conf.default.accept_source_route = 0
# 缩短套接字处于 TIME_WAIT 的时间, 60s -> 30s
net.ipv4.tcp_fin_timeout = 30
# 启用 TIME_WAIT 复用,使得结束 TIEM_WAIT 状态的套接字的端口可以立刻被其他套接字使用。
#!/usr/bin/env python
"""
How to use it:
1. Just `kill -2 PROCESS_ID` or `kill -15 PROCESS_ID` , The Tornado Web Server Will shutdown after process all the request.
2. When you run it behind Nginx, it can graceful reboot your production server.
3. Nice Print in http://weibo.com/1682780325/zgkb7g8k7
"""
pwd = os.path.dirname(os.path.realpath(__file__))
import subprocess
import select
import os
import sys
import fcntl
p1 = subprocess.Popen("sleep 2 && echo done1 && sleep 5 && echo done2",
shell=True, stdout=subprocess.PIPE)
p2 = subprocess.Popen("sleep 3 && echo done3 && sleep 5 && echo done4",
shell=True, stdout=subprocess.PIPE)
@wesdu
wesdu / client.py
Last active August 29, 2015 14:22 — forked from iwanbk/client.py
import json
import socket
s = socket.create_connection(("127.0.0.1", 5090))
s.sendall(json.dumps(({"id": 1, "method": "Hello.Hello", "params": ["hello"]})))
print s.recv(4096)