Do You PHP はてブロ

Do You PHPはてなからはてブロに移動しました

recent command

つられてやってみました。まあ、環境構築中なので、かな〜り偏ってますが。。。

# history|awk '{print $2}'|awk 'BEGIN {FS="|"} {print $1}'|sort|uniq -c|sort -r
     52 vi
     35 chkconfig
     33 mount
     33 cd
     24 service
     22 ll
     20 ls
     13 up2date
     12 less
      9 umount
      9 rpm
      8 cdrecord
      7 cat
      6 grep
      6 dmesg
      5 smbpasswd
      5 ntpq
      5 mkisofs
      5 chown
      4 mkdir
      3 set
      3 rm
      3 ps
      3 man
      3 iptables
      3 fuser
      3 cp
      3 \rm
      2 tail
      2 sync
      2 rmdir
      2 ntpdate
      2 netstat
      2 mv
      2 lsmod
      2 find
      2 df
      2 chmod
      1 vmware-config.pl
      1 ssh
      1 sensors-detect
      1 ping
      1 make
      1 l
      1 history
      1 fdisk
      1 dig
      1 cd../
      1 LANG=C
      1 '
#

しかし、最後の「'」は。。。あ、そうだ。typoして「'」で終わっちゃったヤツだ。

gdbを使ってコードを読む


ここでは、mb_list_encodings()を題材にどうやってphpの実装を理解していくか、そのプロセスを記述してみたい。もちろんこの方法がベストであるとか、この方法でなければいけないとか、いつでもこの方法が適用可能だなんてことを主張するつもりは一切ないが、一つの例として大規模ソフトウェアの微視的理解方法を理解いただきたい。
           :
あとはステップ実行なりなんなりして微視的な理解を深めるだけである。

ここまでに到達するのに30分とかからない。

PHPの内部動作をgdbを使って見ていってます。gdbの使い方をマトモに修得せねば。。。

PHPUnit3ではAnnotationを使ってテストケースの雛形を作る

確かに楽そう。ただ、テストパターンが多い場合、コードの可読性が異様に下がりそうな感じがするのは気のせいかなぁ。まあ、折り畳んで表示しちゃえば問題ないのか。


PHPUnit can help you write your tests by analyzing the code of an existing class and generating a skeleton test-case class for it. With PHPUnit 3 this feature will be more powerful as it now supports @test annotations in the class source.

<?php
class Calculator
{
    /**
     * @test (0, 0) == 0
     * @test (0, 1) == 1
     * @test (1, 0) == 1
     * @test (1, 1) == 2
     */
    public function add($a, $b)
    {
        return $a + $b;
    }
}
?>

CentOS4.4+Postfix+Spamassassinメモ

やっぱりOS入れ替えは面倒。。。

事前にインストール

chkconfig

# chkconfig postfix on
# chkconfig spamassassin on

Postfixの設定

以下を/etc/postfix/main.cfに追加。なお、ローカル環境での利用前提。

# additional
default_privs = nobody
myhostname = host.example.co.jp
mail_spool_directory = /var/spool/mail
mailbox_command = /usr/bin/procmail -a $DOMAIN -d $LOGNAME
smtpd_banner = $myhostname ESMTP
allow_percent_hack = no

Spamassassinの設定

see http://www.ksknet.net/spamassassin/spamassassin_30.html

# wget http://tlec.linux.or.jp/docs/user_prefs
# mv user_prefs /etc/mail/spamassassin/local.cf

$HOME/.procmailrcの作成

  :0fw
  | /usr/bin/spamc
  
  :0
  * ^X-Spam-Status: Yes
           :