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

修改自一个矩阵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

wordpress 隐藏非主页的侧边栏

function bluehua_hide_widgets($sidebars_widgets) {
    if (is_home()) {
        return $sidebars_widgets;
    } else {
        return array();
    }
}

add_filter('sidebars_widgets', 'bluehua_hide_widgets', 10);

[bookmark]cron,anacron,atd

There’s a clear difference between these three applications, and merging
them would be a fairly significant amount of development effort.

cron – executes recurring commands that should occur at a specific time
anacron – executes recurring commands that should take place with a
given frequency.

(The difference between them is that if a task is scheduled in cron and
the machine is switched off, it won’t be executed until the next time
it’s due to run. anacron will attempt to catch up when the machine comes
back up)

atd – executes a non-recurring command at a specific time

The fact that all three exist is something of a holdover from legacy
Unix, but it’s not possible to just remove one of them.

http://ubuntu.5.x6.nabble.com/cron-atd-anacron-other-wtf-td686145.html

Mac OS X重命名磁盘卷标

加了块ssd硬盘,默认的分区名是 “未命名1”, 有点二,改了个好理解的。

$ mount
/dev/disk0s2 on / (hfs, local, journaled)
devfs on /dev (devfs, local, nobrowse)
/dev/disk1s2 on /Volumes/Macintosh HD (hfs, local, journaled)
$sudo diskutil rename /dev/disk0s2 "SSD盘"