Skip to content

Instantly share code, notes, and snippets.

import time
import signal
class death_penalty_after(object):
def __init__(self, timeout):
self.timeout = timeout
def __enter__(self):
# register alarm siganl to handler
signal.signal(signal.SIGALRM, self.handle_death_penalty)
import socket
from thread import start_new_thread
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', 8001))
s.listen(2)
print 'listening'
def clientthread(conn):
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', 8001))
s.listen(2)
while 1:
conn, addr = s.accept()
print 'connected by', addr
conn.sendall('response\n')
while 1:
l = ['11', '11', '11', '22', '22', '33']
from collections import Counter
c = Counter(l)
c.most_comon()
>> [('11', 3), ('22', 2), ('33', 1)]
#coding=utf-8
#!/usr/bin/python
import re
import json
from bs4 import BeautifulSoup
with open('t1.txt') as f:
doc = f.read()
soup = BeautifulSoup(doc)
scripts = soup.find_all('script')
#!/usr/bin/python
#coding=utf-8
#****************************************************
# Author: XYJ - xyj.asmy@gmail.com
# Last modified: 2012-07-02 09:44
# Filename: observer.py
# Description:
#****************************************************