Articles tagged as

  1. 有爱的小脚本:启动终端时显示一句箴言

    效果就是每次启动终端时都有一个小动物什么的讲一句有意思的话:

    image0

    说话的东西和说的话都随机出现。这个效果是我在Linux Mint里面看到的,感觉很有爱。下周考Unix环境编程,周末恶补一下,顺便写这个小脚本练手。

    以我在用的 ubuntu 为例。首先确保安装 fortunescowsay 两个包。前者用于显示各种各样的趣味短句,后者则提供了一头会说话的奶牛(和其它各种诡异的东西)。关于fortunes还有一些有趣的包你可能也想一起安装,比如fortune-zh里有唐诗宋词,fortunes-ubuntu-server则有关于使用Ubuntu Server的贴士,等等。

    #!/bin/bash
    # Cow randomly says a hopefully interesting adage
    
    # Get a short message from fortune, both offensive and not.
    # Remove -a if you don't want to see offensive ones.
    # Remove -s if you don't mind reading the long messages.
    msg=`fortune -a -s`
    
    # Randomly pick a mode of the cow
    modes=("" -b -d -g -p -s -t -w -y ); mode=${modes[$(($RANDOM % 9))]}
    
    # cowsay or cowthink?
    cowdos=(cowsay cowthink); cowdo=${cowdos[$(($RANDOM % 2))]}
    
    # Radomly pick a cow picture file
    speaker=`cowsay -l | sed '1d;s/ /n/g'| sort -R | head -1`
    
    # That's it ^^
    echo "$msg" | $cowdo -n -f $speaker $mode
    

    保存后加上执行权限:

    chmod +x cowsay-fortune
    

    然后把这个文件复制到/usr/bin

    sudo cp cowsay-fortune /usr/bin
    

    最后打开/etc/bash.bashrc

    sudo gedit /etc/bash.bashrc
    

    并在最后加上一行:

    cowsay-fortune
    

    保存后打开终端,应该就是这个效果了:

    image1

  2. 恶搞巴赫:Deconstructing Johann

    偶然发现的一段很好玩的视频,是 The King’s Singers 在 2000 年巴赫音乐节表演的 Deconstructing Johann。他们从巴赫的一些有名的作品中选出片段拼凑了一下,填上词,虚构出巴赫在写d小调托卡塔与赋格时与妻子很恶搞的对话。

    注意看歌词哈:

    Deconstructing Johann

    J. S. Bach had a little problem.
    J. S. Bach was in a fix.
    J. S. Bach couldn’t find an answer.
    What to do?
    “I’ve written most of a rather fabulous work!
    Toccata, it’s in D minor, but now I’m feeling a bit of a jerk!
    I can’t think of what should come after it…”
    “Now,” said his wife, who was resting up after her 33rd child,
    “Johann, my dear, you should just go to bed.
    Something always comes up.”
    “Don’t be a tweet!
    It’s a real crisis and I’m working to a deadline!
    What can I fit?
    What to fit after the great toccata?
    Maybe it needs to be something faster?
    I haven’t got a clue
    and in a week the piece is due.
    I’m in a panic!
    I’m stuck like glue!”
    “Don’t get your knickers in a twist, Johann.
    ‘Those are only notes’, you’ve always said.
    There’s only twelve so use your head.
    How many arrangements of twelve notes can there possibly be?”
    “That’s a problem ...
  3. 谁发明了递归

    “子非鱼,安知鱼之乐?”

    “子非我,安知我不知鱼之乐?”

    “子非我,安知我不知子不知鱼之乐?”

    “子非我,安知我不知子不知我知鱼之乐?”

    “子非我,安知我不知子不知我知子不知鱼之乐?”

    “子非我,安知我不知子不知我知子不知我知鱼之乐?”

    “子非我,安知我不知子不知我知子不知我知子不知鱼之乐?”

    “子非我,安知我不知子不知我知子不知我知子不知我知鱼之乐?”

    “子非我,安知我不知子不知我知子不知我知子不知我知子不知鱼之乐?”

    …………

    现在你知道是谁发明递归的了。 @_@

Page 1 / 1