This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#coding=:utf-8 | |
import hashlib | |
from settings import settings | |
import memcache | |
import cPickle as pickle | |
mcache = memcache.Client(settings['memcache_url'],debug=0) | |
def cache_data(category='all',timeout=3600): | |
def func_warp1(func): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
http://saepy.sinaapp.com/topic/24/Tornado%E4%B8%8A%E4%BC%A0%E6%96%87%E4%BB%B6%E7%A4%BA%E4%BE%8B | |
在bcore的开发过程中,涉及到上传文件有两个地方,一个是相册,一个是文章图文混排。这里作为一个备忘。罗列一些关键点: | |
文件上传的内容体在tornado.web.RequestHandler.request.files属性中,并且是以数组形式存放的。 | |
使用临时文件存储时,在write完成后要记着把seek重置到文件头。要不然文件无法被读取。 | |
再使用Image模块的thumbnail方法进行缩放时,resample=1作为重载渲染参数能够有效的使图片平滑,消除锯齿。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/python2.7 | |
#encoding:utf-8 | |
# | |
# chkconfig: - 91 35 | |
# description: Starts and stops the app server\ | |
# used to provide app services. | |
# | |
import sys | |
import os | |
pid = "/var/run/app.pid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# subprocess - Subprocesses with accessible I/O streams | |
# | |
# For more information about this module, see PEP 324. | |
# | |
# Copyright (c) 2003-2005 by Peter Astrand <[email protected]> | |
# | |
# Licensed to PSF under a Contributor Agreement. | |
# See http://www.python.org/2.4/license for licensing details. | |
r"""subprocess - Subprocesses with accessible I/O streams |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, department, paygrade') | |
import csv | |
for emp in map(EmployeeRecord._make, csv.reader(open("employees.csv", "rb"))): | |
print emp.name, emp.title | |
import sqlite3 | |
conn = sqlite3.connect('/companydata') | |
cursor = conn.cursor() | |
cursor.execute('SELECT name, age, title, department, paygrade FROM employees') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
logs_path="/var/log/named/" | |
oldlogs=${logs_path}dns_logs | |
newlogs=${logs_path}dns_logs_$(date -d "yesterday" +"%Y%m%d") | |
rm -fr ${newlogs} | |
cp ${oldlogs} ${newlogs} | |
echo "" > ${oldlogs} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def convtime(ctime): | |
if not ctime: | |
return '' | |
cdate = datetime.datetime.strptime(ctime,'%Y-%m-%d %H:%M:%S') | |
nowdate = datetime.datetime.now() | |
dt = nowdate - cdate | |
secs = dt.total_seconds() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# author: Rolando Espinoza La fuente | |
# | |
# Changelog: | |
# 24/07/2011 - updated to work with scrapy 13.0dev | |
# 25/08/2010 - initial version. works with scrapy 0.9 | |
from scrapy.contrib.loader import XPathItemLoader | |
from scrapy.item import Item, Field |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
USERNAME=root | |
PASSWORD=root | |
DBNAME=mydb | |
DATE=`date +%Y-%m-%d` | |
OLDDATE=`date +%Y-%m-%d -d '-20 days'` | |
FTPOLDDATE=`date +%Y-%m-%d -d '-60 days'` |