我的Google Reader分享

Friday, August 29, 2008

ipod充电图标Tip和关于Bash的以前一知半解的东西


  这段时间ipod nano听的很少,主要是歌都没换,听的都腻了。今天用来拷Arch的盘的时候拿出来用了一下,然后突然发现以前充电时的绿色的充电图标不见了,怎么弄也出不来。然后开始Google,人家说弹出ipod然后睡眠后就会显示这个图标。我这么干就直接睡过去了,ipod就关了。我一开始还以为是上次ipod从高空坠落给摔坏了,后来关掉Linux,进XP,开起ITunes发现睡眠状态下可以显示这个鸟图标。Apple对Linux一直不友好啊。

  最近不是新装了Arch嘛,然后发现自己Linux知识的不扎实开始显现了。设置Fcitx输入法的时候总是不能激活.具体设置参照的是Arch的Wiki(http://wiki.archlinux.org/index.php/Fcitx中文输入法)。最后检查locale也OK,.bashrc也写对了,但Fcitx就是不能激活。郁闷了半天,后来发现我的.bashrc里有一个alias: alias ls='ls --color=auto'。但是这个也没有起作用,才开始怀疑是.bashrc没有被source,然后发现用户目录下面没有.bash_profile,我在/etc/skel/中拷贝了一份过来,顺便cat了一下内容:[winfield@myhost ~]$ cat .bash_profile
. $HOME/.bashrc
原来在这里source了~/.bashrc了,reboot后搞定。知道问题所在之后觉得有必要了解下Bash是怎么加载这几个配置文件了。man bash吧。然后看manpage的INVOCATION。
  • A login shell is one whose first character of argument zero is a -, or one started with the --login option.
    所谓的login shell我一开始没有明白,后来这么干了一下:
    [winfield@myhost ~]$ bash
    [winfield@myhost ~]$ ps aux | grep bash
    winfield 2966 0.0 0.1 6324 1820 tty2 S+ 14:56 0:00 -bash
    winfield 4281 0.0 0.1 6324 1824 tty1 S 16:57 0:00 -bash
    winfield 4492 0.0 0.1 6324 1836 pts/0 Ss 19:14 0:00 -bash
    winfield 4516 0.7 0.1 6324 1796 pts/0 S 20:53 0:00 bash
    winfield 4518 0.0 0.0 4072 816 pts/0 R+ 20:53 0:00 grep bash
    前面有“-”的就是指Login shell了。像tty这些。另外关于Login Shell的可以参考这个,http://learnlinux.tsf.org.za/courses/build/shell-scripting/ch02s02.html(IP是南非,大概是南非的某个大学?感叹一下)
  • When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile
    如果是Login Shell,读取文件的顺序是/etc/profile,~/.bash_profile,~/.bash_login,然后是~/.profile,注意没有~/.bashrc,这也是为什么我出现问题的原因。
  • When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force bash to read and execute commands from file instead of ~/.bashrc.
    如果不是Login Shell,bash会读~/.bashrc。

  

Wednesday, August 20, 2008

硬盘安装Arch Linux(2008.06)


  玩Linux也有很久了,一开始用的就是Ubuntu,它的确适合新手。不过时间长了,倒觉得用Ubuntu进步越来越小,或许换个风格不一样的发行版能学到些新的东西。最近在看《LPI Linux认证》这本书,倒不是想去考这个,只是想再巩固下自己的Linux基本功。于是决定装个Arch看看。
  因为我总是懒的刻录盘来装(其实我手边也没有盘),所以一般都是硬盘安装。虽然我这个台式机上已经装了Ubuntu,但我还是在XP里设置Grub4Dos来引导的。
  • 下载个Grub4Dos,把grldr复制到C盘,修改boot.ini,在此文件末尾加一行C:\grldr="arch";复制2008.03光盘中的initrd.img和vmlinuz到C盘(我在网上搜索听说2008.06的这两个镜像文件硬盘安装时不成功所以用了2008.03的)
  • 新建个menu.lst,
    • title Fuck Install Arch Linux
    • root (hd0,0) #假设你的C盘是在第一个分区
    • kernel /vmlinuz ro
    • initrd /initrd.img
  • 重启,进入临时文件系统
    • mount /dev/sda1 /mnt
      挂载C盘到/mnt(当然也可以是其他地方。。)
    • mount -t iso9660 -o loop /mnt/archlinux-2008.06-core-i686.iso /media/dvd/
      挂载ISO到/media/dvd
    • mkdir /src/core
      Arch安装程序貌似会在这个目录下找包,因为是硬盘安装,所以要手动先挂载ISO,然后建立一个目录,再在这个目录中建一个链接到ISO中的包
    • ln -s /media/dvd/core/pkg /src/core/pkg
  • 开始安装,cd arch & ./setup

Wednesday, August 06, 2008

Programming Erlang 笔记(三)

Sequential Programming---Again..

Guards
  • A guard is a series of guard expressions, separated by commas (,).──── 一个Guard是一系列由(,)分隔的Guard表达式
  • A guard sequence is either a single guard or a series of guards, separated by semicolons (;).──── 一个Guard序列可是是一个单一的Guard,也可以是一系列用(;)分隔的的Guard
  • Guard Examples
    1. f(X,Y) when is_integer(X), X > Y, Y <> ...──── The comma, which separates the test in the guard, means “and.”
    2. is_tuple(T), size(T) =:= 6, abs(element(3, T)) > 5
      element(4, X) =:= hd(L)
    3. X =:= dog; X =:= cat
      is_integer(X), X > Y ; abs(Y) <>Y或者Y的绝对值小于23。Guard Sequence用于表示“或”,而(,)来表示“且”
    4. The guard sequence G1; G2; ...; Gn is true if at least The guard sequence G1; G2; ...; Gn is true if at least one of the guards—G1, G2, ...—evaluates to true. one of the guards—G1, G2, ...—evaluates to true.


Records
  • record is not a shell command.record definitions can be included in Erlang source code files or put in files with the extension .hrl──── record不是一个Shell命令;record定义可以被包含在Erlang源代码中或者放在一个扩展名为“.hrl”的文件中
  • Records are declared with the following syntax:
    -record(Name, {
    %% the next two keys have default values
    key1 = Default1,
    key2 = Default2,
    ...
    %% The next line is equivalent to
    %% key3 = undefined
    key3,
    ...
    }).
    Name is the name of the record. key1, key2, and so on, are the names of the fields in the record; these must always be atoms.────上面的定义中,Name是record的名字,key1, key2....是记录中条目的名字,他们必须是atom
  • -record(todo, {status=reminder,who=joe,text}).
    Once a record has been defined, instances of the record can be created.──── 一旦一个record被定义了,就可以创建这个record的实例
    1> rr("records.hrl").
    [todo]
    2> X=#todo{}.
    #todo{status = reminder,who = joe,text = undefined}
    3> X1 = #todo{status=urgent, text="Fix errata in book"}.
    #todo{status = urgent,who = joe,text = "Fix errata in book"}
    4> X2 = X1#todo{status=done}.
    #todo{status = done,who = joe,text = "Fix errata in book"}
  • Extracting the Fields of a Record────从Record中提取元素
    5> #todo{who=W, text=Txt} = X2.
    #todo{status = done,who = joe,text = "Fix errata in book"}
    6> W.
    joe
    7> Txt.
    "Fix errata in book"
    8> X2#todo.text.
    "Fix errata in book"
  • Records Are Tuples in Disguise────record其实是伪装了的Tuple
    9> X2.
    #todo{status = done,who = joe,text = "Fix errata in book"}
    10> rf(todo).
    ok
    11> X2.
    {todo,done,joe,"Fix errata in book"}
    Records are just tuples.Internally there are only tuples.────Record就是Tuple;从内部来讲,Erlang中只能Tuple




case and if Expressions
  • case Expressions
    case has the following syntax:
    case Expression of
    Pattern1 [when Guard1] -> Expr_seq1;
    Pattern2 [when Guard2] -> Expr_seq2;
    ...
    end
  • if Expressions
    if
    Guard1 ->
    Expr_seq1;
    Guard2 ->
    Expr_seq2;
    ...
    end
    Often the final guard in an if expression is the atom true, which guarantees that the last form in the expression will be evaluated if all other guards have failed.────
    "if"表达式的最后一个guard常常是atom "true",它保证了如果前面的guard全部没有匹配的,最后一个肯定会被计算


Building Lists in Natural Order
  • The most efficient way to build a list is to add the elements to the head of an existing list
    The basic idea is fairly simple:
    1. Always add elements to a list head.
    2. Taking the elements from the head of an InputList and adding
    them head first to an OutputList results in the OutputList having
    the reverse order of the InputList.
    3. If the order matters, then call lists:reverse/1, which is highly opti-
    mized.
    4. Avoid going against these recommendations.
    If you ever see code like this:
    List ++ [H]
    it should set alarm bells off in your brain—this is very inefficient and acceptable only if List is very short.