2009年9月23日水曜日

Unicode char<->int conversion in the PHP

Java
char c = (char) int;
int i = (int) char;

PHP
function num2utf($num){
if($num<128)return chr($num);
 if($num<2048)return chr(($num>>6)+192).chr(($num&63)+128);
if($num<65536)return chr(($num>>12)+224).chr((($num>>6)&63)+128).chr(($num&63)+128);
if($num<2097152)return chr(($num>>18)+240).chr((($num>>12)&63)+128).chr((($num>>6)&63)+128) .chr(($num&63)+128);
return '';
}

function utf2num($utf)
{
$tmp = ord($utf{0});
if ($tmp<128)return $tmp;
 if ($tmp<224)return (($tmp-192)<<6) + (ord($utf{1})-128);
 if ($tmp<240)return (($tmp-224)<<12)+ ((ord($utf{1})-128)<<6) +(ord($utf{2})-128);
 if ($tmp<248)return (($tmp-240)<<18) + ((ord($utf{1})-128)<<12)+((ord($utf{2})-128)<<6) + (ord($utf{3})-128);
 return '';
}
see also PHP: utf8_encode - Manual http://sk2.php.net/manual/en/function.utf8-encode.php#49336

2009年9月21日月曜日

Programmingの学習に使えるOpen SourceのGame達

Java

Robocode
http://robocode.sourceforge.net/



Javascript

JSNES
http://github.com/bfirsh/jsnes/
Demo
http://benfirshman.com/projects/jsnes/


C/C++

eAthena (Server-side)
eAthena Support Board (Powered by Invision Power Board)
http://www.eathena.ws/board/
SVN
http://svn.eathena.ws/svn/ea/

Ubuntu + Apache + PHP + Zend Framework

Ubuntu 9.04 + Zend Framework 1.9.2

Zend Framework
http://framework.zend.com/
から最新版を落とさず、deb packageを使う場合。

最新版を検索
https://launchpad.net/ubuntu/karmic/+search?text=zend

i386の場合
http://launchpadlibrarian.net/32316040/zend-framework-bin_1.9.3PL1-0ubuntu1_all.deb
http://launchpadlibrarian.net/32316041/zend-framework_1.9.3PL1-0ubuntu1_all.deb
http://launchpadlibrarian.net/32316039/libzend-framework-php_1.9.3PL1-0ubuntu1_all.deb
を落とす。

sudo dpkg -i *.deb
でinstall。Zend Frameworkは
/usr/share/php/libzend-

sudo vi /etc/php5/apache2/php.ini
;include_path = ".:/usr/share/php"

include_path = ".:/usr/share/php:/usr/share/php/libzend-framework-php"
に変更する。
或いは
/usr/share/php$ sudo ln -s libzend-framework-php/Zend


sudo /etc/init.d/apache2 restart
或いはreloadでいいかも。

include_pathを通さないと
http://framework.zend.com/docs/quickstart/create-your-project
zf create project quickstart
で作られた
quickstart/public/index.php
内のincludeでerrorになる。

libzend-framework-php/ directoryはいらないような気がする。

Install Tutorial: Ubuntu 9.04, Apache with SSL, Subversion over HTTP / HTTPs, and Trac 改

元ネタ或いは大いに参照すべきもの
Install Tutorial: Ubuntu 9.04, Apache with SSL, Subversion over HTTP / HTTPs, and Trac - NewInstance

より詳しい最新(Ubuntu9.10)の手順は
axis of evil Google: Install Tutorial: Ubuntu 9.10, Apache with SSL, Subversion over HTTP / HTTPs(digest authentication), and Trac
http://salvan-devmemo.blogspot.com/2010/01/install-tutorial-ubuntu-910-apache-with.html


冒頭のURLの手順から
-/etc/apache2/mods-available/dav_svn.conf
-/etc/apache2/sites-available/default
AuthTypeをBasicからDigestに変更し、passwordの生成はhtpasswdからhtdigestに変更する。引数は同じuser名の前にrealmを入れる。
hashの方式の違いからpasswordが変わるので別のfile名にする場合はAuthUserFileのpathも変える。
/etc/apache2/sites-available/defaultの末尾につけたtrac用の情報を/etc/apache2/sites-available/default-sslにも貼り付ける。
sudo a2enmod auth_digest
でdigest認証moduleを動かし、apacheを再起動する。


Firefox + HttpFox或いはWireshark等で認証がBasicからDigestになっている事を確認する。


Upgrading to 2.2 from 2.0 - Apache HTTP Server
The directive AuthDigestFile from mod_auth_digest has been merged with AuthUserFile and is now part of mod_authn_file.
という事でAuthUserFileをAuthDigestFileにする必要はない。


変更前
app 認証 ssl
subversion basic o
trac basic x

変更後
app 認証 ssl
subversion digest o
trac digest o

参考
core - Apache HTTP Server
Digest認証 - Wikipedia
Basic認証 - Wikipedia


関連
The Trac Project