Posted by anonymous
on March 13,2009 at 11:02 a.m.
Python
1
2
3
4
5
6
7
8
9
10
11 | import os
def dirwalk(dir):
"walk a directory tree, using a generator"
for f in os.listdir(dir):
fullpath = os.path.join(dir,f)
if os.path.isdir(fullpath) and not os.path.islink(fullpath):
for x in dirwalk(fullpath): # recurse into subdir
yield x
else:
yield fullpath
|
Posted by anonymous
on April 2,2009 at 10:43 a.m.
Python
1
2
3
4
5
6
7
8
9 | """
判断unicode码是否为中文字符.
"""
def is_cn_char(i):
return 0x4e00<=ord(i)<0x9fa6
def is_cn_or_en(i):
o = ord(i)
return o<128 or 0x4e00<=o<0x9fa6
|
Posted by jason
on May 13,2009 at 9:31 a.m.
PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 | <?php
/*
* $ip varnish/squid server ip
* $url
*/
function purge($ip, $url) {
$errstr = '';
$errno = '';
$fp = fsockopen($ip, 80, $errno, $errstr, 2);
preg_match("/^(http:\/\/)?([^\/]+)/i",$url, $matches);
$host = $matches[2];
if (!$fp) {
return false;
} else {
$out = "PURGE $url HTTP/1.1\r\n";
$out .= "Host:$host\r\n";
$out .= "Connection: close\r\n\r\n";
fputs($fp, $out);
$out = fgets($fp, 4096);
fclose($fp);
return $out;
}
}
$server = $_GET['s'];
$url = $_GET['u'];
if( $server and $url)
echo purge($server,$url);
?>
|