php file itself
2008年08月08日 (php)
command
% echo '<?php echo $_SERVER["PHP_SELF"]."\\n"; ?>' > test.php % cat test.php <?php echo $_SERVER["PHP_SELF"]."\n"; ?> % php test.php test.php %
note
一昔前の記述方法,$PHP_SELFだけだとうまくいかない.
PR
man page to ascii text
2008年08月08日 (linux)
command
% man man > test.txt % vim test.txt 制御文字が入っているので文字化けしたように表示される. % man man | colcrt - > test.txt % vim test.txt 普通のASCIIテキストとして表示される.
note
cf. % man colcrt
shellscript tips
2008年08月08日 (shellscript)
- 変数命名規則
- カウント変数などの一時的な変数は全て小文字,非一時的な変数は全て大文字にする.
- ループ処理
- 簡単な処理を2,3回程しか実行しないループ処理は実効速度の低下,可読性の悪化などを引き起こすので避ける.
- 無駄な出力
- 他のコマンドにパイプ,リダイレクトされることも考慮にいれて無駄な出力はさせないようにする.
- エラー処理
- ユーザの誤った入力などに対しコマンドの用法などを示すなどしてからプログラムを終了させる.例外処理を行う.
- コメント
- 適時コメントを入れるなどしてその関数が何をする関数なのかなどを明確にしめす.
box centering
2008年08月06日 (xhtmlcss)
source
margin-left: auto; margin-right: auto;
sample source
<html>
<head>
<title>css test</title>
<style type="text/css">
#main {
width: 320px;
height: 240px;
background-color: #ff0000;
margin-right: auto;
margin-left: auto;
}
</style>
</head>
<body>
<div id="main">
div id="main"
</div>
</body>
</html>
note
margin-top: auto; margin-bottom: auto; としても上下はセンタリングできない.
like shell script
2008年08月05日 (php)
source
#!/usr/local/bin/php
<?php
echo("php like shell script\n");
?>
sample execution
% vim likeshellscript.php % chmod 744 likeshellscript.php % ./likeshellscript.php php like shell script %