Skip to content

Instantly share code, notes, and snippets.

jamiesun jamiesun

Block or report user

Report or block jamiesun

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View fetch_epg.py
#coding:utf-8
import re
import urllib
import pprint
import logging
from lxml.html import fromstring,tostring
from gevent.pool import Pool
pool = Pool(3)
@jamiesun
jamiesun / udpserver.py
Created May 25, 2014
tornado UDP server
View udpserver.py
#!/usr/bin/env python
#coding=utf-8
import socket
import os
import errno
from tornado.ioloop import IOLoop
from tornado.platform.auto import set_close_exec
class UDPServer(object):
def __init__(self, io_loop=None):
@jamiesun
jamiesun / nextid.py
Created May 18, 2014
生成有时间规则的id
View nextid.py
import datetime
def __next_id():
_inum = [10000]
def _next():
if _inum[0] >= 99999:
_inum[0] = 10000
_inum[0] += 1
_prefix = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
return int("%s%s"%(_prefix,_inum[0]))
View python_comprehension.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View builddb.py
import os,sqlite3
def create_sql(infile,outfile):
print infile,outfile
outfs = open(outfile,'wb')
with open(infile,'rb') as infs:
View echoserver.py
#!/usr/bin/env python2
#coding:utf-8
import logging
from tornado.ioloop import IOLoop
from tornado.iostream import IOStream
from tornado.tcpserver import TCPServer
logging.basicConfig(level=logging.INFO, format='%(levelname)s - - %(asctime)s %(message)s', datefmt='[%d/%b/%Y %H:%M:%S]')
View futures_test.py
from concurrent.futures import ThreadPoolExecutor
from functools import partial, wraps
import time
import tornado.ioloop
import tornado.web
EXECUTOR = ThreadPoolExecutor(max_workers=4)
View echoserver.py
#!/usr/bin/env python
#coding:utf-8
import sys, os, re
import logging
from tornado.ioloop import IOLoop
from tornado.iostream import IOStream
from tornado.netutil import TCPServer
@jamiesun
jamiesun / redis
Created Jan 12, 2014
redis service script
View redis
#!/bin/sh
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
#
# redis This is the init script for starting up the Redis server
#
# chkconfig: 2345 85 15
# description: Starts and stops the redis daemon that handles \
# all redis session requests.
View resize_image.py
def resize_img(img_path, out_path, new_width):
import Image
#读取图像
im = Image.open(img_path)
#获得图像的宽度和高度
width,height = im.size
#计算高宽比
ratio = 1.0 * height / width
#计算新的高度
new_height = int(new_width * ratio)
You can’t perform that action at this time.