Archive for April, 2007

30th Apr 2007

习惯被无视

貌似从一开始起,我就一直在被人无视.当你发问,说话时,他们总是很不屑的给白眼,特意要我知道他们在无视我,实际上这就说明他们没有无视我,只是在以表达无视的方式来排斥我罢了.

可能是我一出口就得罪人,可能是我面目可憎,可能是我来自一个他们很不屑的地方,可能是我没他们家有钱,可能是他们只认为我是个小混混……当他们在我耳边高谈阔论着一些无聊虚幻的东西时,但他们商讨某些不可能与我有关的事时,当他们说”不如我们无视他.”、”好的.”时,当他们在QQ屏蔽调我的话时……我是否也在习惯了无视他们对我的无视?

起初,他们忽视你。后来,他们嘲笑你。接着,他们攻击你。然后,你就会赢。

Posted by Posted by admin under Filed under Life Comments No Comments »

29th Apr 2007

Bash补全bug fix

来源: http://forum.ubuntu.org.cn/viewtopic.php?t=43304

一般来说,source 了 /etc/bash_completion 后即可使用bash强大的补全功能.但在某些情况下,补全功能会意外的失效

for example:

sudo mv foo/bar\ z/<tab>

如果”bar z”下还有东西,就不能自动补全.

解决方法:
修改 /etc/bash_completion 文件,把 _command 函数里的

# split current command line tokens into array
COMP_WORDS=( $cline )

改成

# split current command line tokens into array
for (( i=1 ; i

Posted by Posted by admin under Filed under BASH, Linux Comments No Comments »

27th Apr 2007

彩色Shell

添加以下代码到 ~/.bashrc 尾部

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
linux)
    PS1='${debian_chroot:+($debian_chroot)}\[33[01;36m\]\u\[33[00m\]@\[33[01;32m\]\h\[33[00m\]:\[33[01;33m\]\w\[33[01;39m\]\$\[33[00m\] '
    ;;
xterm)
    PS1='${debian_chroot:+($debian_chroot)}\[33[01;36m\]\u\[33[00m\]@\[33[01;32m\]\h\[33[00m\]:\[33[01;33m\]\w\[33[01;39m\]\$\[33[00m\] '
    ;;
*)
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
    ;;
esac

(注:修改了一下,把@的粗体去掉了,所以跟下面的图会有细微差异)

这样就有漂亮的彩色shell了

测试颜色代码可以用这个脚本

#!/bin/sh
############################################################
# Nico Golde <nico(at)ngolde.de> Homepage: http://www.ngolde.de
# Last change: Mon Feb 16 16:24:41 CET 2004
############################################################

for attr in 0 1 4 5 7 ; do
    echo "----------------------------------------------------------------"

    printf "ESC[%s;Foreground;Background - \n" $attr
    for fore in 30 31 32 33 34 35 36 37; do
        for back in 40 41 42 43 44 45 46 47; do
            printf '33[%s;%s;%sm %02s;%02s  ' $attr $fore $back $fore $back
        done
    printf '\n'
    done
    printf '33[0m'
done

更多信息参考
http://www.linuxfocus.org/ChineseGB/May2004/article335.shtml

Posted by Posted by admin under Filed under BASH, Linux Comments No Comments »

22nd Apr 2007

Bash参数替换的引号细节

echo "$(ls)"

echo $(ls)

对比两个输出就明白了

Posted by Posted by admin under Filed under BASH, Linux, Programming Comments No Comments »

21st Apr 2007

化难递归为易递归

今天做了一下noip2003的传染病控制,原先以为不难,后来发现竟然想不到除了枚举以外的方法…

虽然穷举理论上也不会超时,但是这种形式实在是不美观.

题目的模型是一棵树,很自然的想到用类似递归的方法,但问题是如果直接递归的话,子问题互相影响(存在某种互斥关系),难以处理…

看了解题报告,发现可以在保持问题性质不变的情况下通过某种变换使互相影响的多个子问题变成一个子问题,从而顺利递归.

这种化联系紧密的部分为整体的解题思想值得学习.

Posted by Posted by admin under Filed under Programming Comments No Comments »