代码高亮工具

  • 只需复制粘贴,即可实现Blog、论坛、邮件、Word中的代码高亮
  • 支持127种编程语言
  • 多种高亮主题供您选择
  • HTML代码在线运行查看效果
  • 代码永久保存和管理
  • 使用Google帐户登录,无需单独注册

Walk a directory tree using a generator

 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

判断是否为中文字符

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

清除Varnish/Squid缓存

 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); 
?>