获取两组数据的固定乱序组合

修改自一个矩阵z形遍历代码,改成从中间开始遍历,乱序效果更好

function matrix_mess_order($rows, $cols) {
    $cuts = $rows + $cols - 1;
    $mid  = (int)($cuts/2);
    $result = array();
    for ($i = 0; $i < $cuts; $i++) {
        if ($i % 2 == 0) {
            $j = $mid - (int)($i % $mid);
        } else {
            $j = $mid + (int)($i % $mid);
        }
        $row_extra = ($j + 1) > $rows ? ($j + 1 - $rows) : 0; 
        $col_extra = ($j + 1) > $cols ? ($j + 1 - $cols) : 0; 
        $len = ($j + 1) - $row_extra - $col_extra;
        $topright_row = $col_extra;
        $topright_col = $j - $col_extra;
        $leftbotm_row = $j - $row_extra;
        $leftbotm_col = $row_extra;
        if ($j % 2 == 0) {
            while ($len -- > 0) {
                $result[] = array($leftbotm_row - $len, $leftbotm_col + $len);
            }
        } else {
            while ($len -- > 0) {
                $result[] = array($topright_row + $len, $topright_col - $len);
            }
        }
    }
    return $result;
}

[bookmark]统计最常使用的命令

v2ex看到一条统计最常用命令的脚本,收藏一下~

$ history | awk '{CMD[$2]++;count++;} END { for (a in CMD )print CMD[ a ]" " CMD[ a ]/count*100 "% " a }' | grep -v "./" | column -c3 -s " " -t |sort -nr | nl | head -n10
1 167 33.4% vim
2 104 20.8% ls
3 75 15% make
4 25 5% cd
5 13 2.6% sshgo
6 11 2.2% telnet
7 11 2.2% sudo
8 10 2% find
9 5 1% mv
10 4 0.8% ps

from:http://v2ex.com/t/98373

给make的错误信息加点颜色

~/.bashrc

make()
{
    ccred=$(echo -e "\033[0;31m")
    ccyellow=$(echo -e "\033[0;33m")
    ccend=$(echo -e "\033[0m")
    /Applications/Xcode.app/Contents/Developer/usr/bin/make "$@" 2>&1 | sed -E -e "/[Ee]rror[: ]/ s%(.*)%$ccred&$ccend%g" -e "/[Ww]arning[: ]/ s%(.*)%$ccyellow&$ccend%g"
    return ${PIPESTATUS[0]}
}

屏幕快照 2013-09-05 下午2.10.14
嗯,错误信息醒目多了,原版在这里
http://stackoverflow.com/questions/6436563/how-can-i-highlight-the-warning-and-error-lines-int-the-make-output