Skip to content

Instantly share code, notes, and snippets.

View dcb9's full-sized avatar

Du, Chengbin dcb9

View GitHub Profile
@dcb9
dcb9 / simulator_python__main__.php
Last active August 29, 2015 14:08
用php模拟python的 __name__ == '__main__' 功能,这样可以做一些测试,只有直接运行这个php的时候才执行,如果这个php是被包含的则不执行,并且还要是在终端下。
<?php
function ismain(){
$debug = debug_backtrace();
if(PHP_SAPI === 'cli' && count($debug)==1 && $debug[0]["function"]==__FUNCTION__){
return true;
}
return false;
}
@dcb9
dcb9 / SortAlgorithm.php
Last active August 29, 2015 14:08
四种比较常见的排序算法:插入,快速,选择,冒泡 以及测试程序
<?php
/**
* 排序算法
* 插入排序、快速排序、选择排序、冒泡排序
*
*/
class SortAlgorithm{
/**
@dcb9
dcb9 / findSvnFileOriginal.py
Last active August 29, 2015 14:07
查找svn文件的最开始的创始人和创建时间
import os, re, sys
RE =re.compile(ur'r(\d+)\s\|\s(\S+)\s\|\s(\S+\s\S+)')
SVN_LOG="svn log"
def backtrack(file):
fh = os.popen("%s -q %s" % (SVN_LOG, file), "r")
for line in fh:
line = line.strip()
if line != "------------------------------------------------------------------------":