- 浏览: 137544 次
- 性别:
- 来自: 深圳
-
最新评论
-
ryan.liu:
Postfix 2.11 Under CentOS 6yum ...
Postfix安装脚本 -
xfzhu2003:
# date -d '-2 day 2012-07-11' + ...
Linux下的date命令究竟可以干什么 -
ryan.liu:
在Firefox下面OK,在IE下面有问题
Jquery联动下拉菜单 -
ryan.liu:
在最新的JQuery 1.7 中,var idx = $(ma ...
Jquery联动下拉菜单 -
mirguest:
身份证最后一位应该是x,不是*吧?
验证18位身份证号码
文章列表
#-*- coding: utf-8 -*-
from bisect import bisect
FIRST_LETTERS = ["a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "l", "m", "n",
"o", &qu ...
把代码放到局域网服务器,原本在本地运行正常的代码在局域网服务器上却报错,Google一下相关错误,原来是Python2.6的一个Bug。
Python2.6下,如果有dict的key是unicode,当把它解包传给函数作为参数时,会报错
from datetime import *
date(1,2,**{u'day':10,u'x':20})
TypeError: date() keywords must be strings
在Python2.7下不会有问题。
参看 http://bugs.python.org/issue2646
先要安装maillib库
假设我要获得一周来,豆瓣发送的每个邮件中的第一个网址
import poplib
import maillib
from datetime import datetime, timedelta
def email_filter(sender, body):
target = "http://"
sender, body = sender[1], body.split("\n")
if sender == "webmaster@douban.com":
...
reg add "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v "path" /d "%path%;%cd%" /t REG_SZ /f
如果当前路径已经存在于系统路径,不会重复添加。
附件是Unix下的常用命令的windows版本,并含有最新的gawk 4.0,与windows冲突的date、mkdir、rmdir、echo、ln、install等命令,文件名前面多加了一个g。
如果你的awk代码可以在Linux可以跑,在Windows下却不行,请检查代码中是否有百分号%,将所有%转义为%%。
例如我的这段处理Nginx日志时间的代码:
date = substr($2,2,11)
time = substr($2,14,8)
gsub("/"," ",date)
command = "gdate -d \"" date " " time "\" +%%s"
command | getline datetime
def unique_list(seq, excludes=[]):
"""
返回包含原列表中所有元素的新列表,将重复元素去掉,并保持元素原有次序
excludes: 不希望出现在新列表中的元素们
"""
seen = set(excludes) # seen是曾经出现的元素集合
return [x for x in seq if x not in seen and not seen.add(x)]
参考:
http://www.peterbe.com/plog/ ...
用Jquery 1.4.4 实现的联动下拉菜单,估计在Jquery 1.2版本以上都可用。
联动下拉菜单是一主一从两个select,切换主select时,从select的内容跟着改变。这里是把从select的项目按组optgroup全部加载进来,然后切换主select时更新从select组的显示或者隐藏。注意从select的组次序和主select项次序要一致。
HTML代码
<select id="province">
<option value="GD">广东</option>
&l ...
import urllib
import urlparse
def url_add_params(url, **params):
""" 在网址中加入新参数 """
pr = urlparse.urlparse(url)
query = dict(urlparse.parse_qsl(pr.query))
query.update(params)
prlist = list(pr)
prlist[4] = urllib.urlencode(query)
ret ...
用途当然是模拟浏览器
# -*- coding: utf-8 -*-
"""
使用pycurl发起HTTP访问
"""
import pycurl, urllib
import StringIO
def curl(url, method="GET", proxy=(), verbose=0, cookie_file="", **kwargs):
#proxy = ("www.test.com:8080", "SOCKS5&quo ...
添加一个用户dba,密码sql,可以管理db_开头的数据库
GRANT ALL PRIVILEGES ON `db\_`.* TO 'dba'@'localhost' IDENTIFIED BY 'sql' WITH GRANT OPTION;
FLUSH PRIVILEGES;
从其他机器访问
如果要允许从其他机器访问,要修改 etc/mysql/my.cnf
将 bind-address = 127.0.0.1 注释掉,或者修改为 bind-address = 0.0.0.0
(bind-address只能绑定单个IP或者所有IP,无法指定网段或IP列表)
...
昨天装好了Couchdb-1.0.2,用couchdb -b启动正常,用curl http://127.0.0.1:5984/也能收到欢迎信息,却打不开网页客户端Futon。
想起之前也碰到这样的问题,第二天自己好了,就把Linux重启了一下,解决了!应该是某个依赖的进程需要重启,猜测是js spidemokey。
第二个问题又来了,很小的一个数据库,半天生成不了一个View,而且CPU马上飙到最高。开始以为是erlang没装好,因为要使用beam.smp嘛,就把erlang和couchdb先后重装一次,问题没解决。
后来用关键词couchdb view no response搜索了一下, ...
转自 http://my.oschina.net/captaintheron/blog/8898
下面,本文就将结合具体的例子来说明怎样利用curl进行下载。
1、获得一张页面
使用命令:curl http://curl.haxx.se
这是最简单的使用方法。用这个命令获得了http://curl.haxx.se指向的 ...
#! /usr/bin/python
# -*- coding: utf-8 -*-
def check_id_num(id_num):
assert len(id_num) == 18 and id_num[:17].isdigit()
factors = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2]
remainders = ['1', '0', '*', '9', '8', '7', '6', '5', '4', '3', '2']
result = sum([f*long(n ...
#! /usr/bin/python
# -*- coding: utf-8 -*-
def get_constellation(ymd="2000-01-01"):
stellates = [
{'date':120, 'name':u'水瓶座'},
{'date':219, 'name':u'双鱼座'},
{'date':321, 'name':u'牡羊座'},
{'date':420, 'name':u'金牛座'},
{'date':521, 'name':u ...
设置python运行环境的编码参考这里 http://diveintopython.org/xml_processing/unicode.html
《Dive Into Python》 的 Example 9.15. sitecustomize.py
# sitecustomize.py
# this file can be anywhere in your Python path,
# but it usually goes in ${pythondir}/lib/site-packages/
import sys
sys.setdefaultencoding('utf- ...