Archive for April, 2007

Akismet & Spam Karma 2

Sunday, April 29th, 2007

之前的 Spam Karma 2 幫我檔掉 12,xxx 個 spam comment,其中的確有約五六個 false postive。不過成功得逞的 spam 好像兩三個而已吧?把資料庫移移到 bluehost 時候,就順勢把 SK2 換成 Akismet 了。不過換了 Akismet 到現在一個多月,我已經看到兩個 Spam 鑽進來了 Orz,我應該就此認為 SK2 > Akismet 嗎 XD

話說換 Counterize II 的時候我也沒把 Counterize 時後存下來的那些記錄留起來,不然下去做 Keyword Analyze 應該會頗好玩。

Breakpoints Proof

Friday, April 27th, 2007

Given permutations π and σ, a breakpoint between π and σ is defined as a pair of adjacent elements πi and πi+1 in π that are separated in σ. For example, if π = 143256 and σ = 123465, then π1 = 1 and π2= 4 in π form a breakpoint between π and σ since 1 and 4 are separated in σ. The number of breakpoints between π=01432567 and σ=01234567 is three (14, 25 and 67), while the number of breakpoints between σ and π is also three (12, 46 and 57).

Prove that the number of breakpoints between π and σ equals the number of breakpoints between σ and π.

(more…)

這是廣告

Thursday, April 26th, 2007

[投票網頁]


個人資料
姓名: 施昕妤
年齡: 17
身高: 168.0
體重: 70.0
血型:
居住地: 臺北
興趣: 唱歌 跟奇怪的人講話
專長: 唱歌 攝影
自我介紹: HI, My name is Kathy, 我在六月要從美國的高中畢業. 高二的暑假回台灣,在電視上看到黑澀會妹妹和棒棒堂男孩覺得很COOL. 我對唱歌很有興趣,也希望能進入我愛黑澀會這個大家庭. 我是個很直接的女生,有話就說,想做就做. 這是我的website:http://www.myspace.com/x0xvintagexgr33nx0x

這位話說好像是我的表妹,而她要我幫她告知所有親朋好友幫忙投票,所以最快的方法就是丟這邊了。投票只要點進連結然後點投票給他就好了,不需要註冊。感覺起來檢查有沒有投過票好像是根據 browser cookie 的,所以用 IE、Firefox、Opera 就可以直接投三票了齁。

先姑且不考量得票多少跟網站投票的目的有沒有用,反正這是個高中小女生的願望,看到票數高就會黑皮了。我比較有疑問的是她第二個興趣還有居住地點 XD

[投票網頁]

PHP 5.2.1 on FC4 x86_64 compile note

Saturday, April 21st, 2007

Linking libraries from its default location

ln -s /usr/include /opt/include
ln -s /usr/lib64 /opt/lib

Now configuring with new location:

./configure --prefix=/usr/local --enable-force-cgi-redirect --enable-fastcgi --with-libxml --with-zlib --with-bz2 --with-curl  --with-gd --enable-mbstring --with-mysql --with-jpeg-dir=/opt --with-png-dir=/opt --with-mysql=/opt

Use Shared Host’s MySQL on VPS

Sunday, April 15th, 2007

On my 1&1 VPS II server, it comes with only 256MB of dedicated memory, which is pathetic. If I run a separate mysqld, it’s going to take 1xxMB away from this super limit memory pool. It makes sense to me to make use of MySQL databases on another shared hosting account. BlueHost and HostMonster both comes with firewall enabled by default for their MySQL servers. Going about white listing server’s IP can be done via:

  1. Launching remote firefox session, which takes your patient and the hassle of all those x window configs.
  2. Setup VPN on the server, and use server’s IP to to whitelist itself.

But the connection between the VPS server and Shared Host’s MySQL database is insecure. It’s natural to come to this conclusion as the best option: ssh tunnel.

Assuming you have shell access to both VPS and Shared Host, and both are running OpsnSSH.

Setup Public Key Authentication

  1. Login to VPS with account you want to create the tunnel
  2. cd ~/.ssh

    (create it if not exist)

  3. ssh-keygen -t dsa
  4. Securely transfer id_dsa.pub to the Shared Hosting’s home directly, something like this:
    scp id_dsa.pub sharedhost:/home/username/.ssh/server_id_psa.pub
  5. Login to Shared Host
  6. cd ~/.ssh
    cat server_id_psa.pub >> authorized_keys
  7. Switch back to VPS, try logging into Shared Host using public key authentication:
    ssh username@sharedhost

    If everything is setup properly, no password is prompted.

If in doubt, [this] is a good place to consult about Public Key Authentication.

Setting up a host name

When MySQL is connecting to localhost, it will try to use socket, regardless of the efforts trying to tell it the service is actually not running on localhost, but rather a tunnel to a remote host. To overcome this issue, create an entry in /etc/hosts:

127.0.0.1 localhost mysqlhost

This points the host name ‘mysqlhost’ to 127.0.0.1 which essentially is also localhost, but mysql is too dumb to understand.

Create the tunnel

  1. First, stop the local mysqld. As root:

    service stop mysqld
  2. Login to VPS with username previously configured with public key authentication to Shared Host
  3. create tunnel:
    ssh -f username@sharedhost -N -L 3306:localhost:3306

    This creates a ssh tunnel in background and forward connection to port 3306 on localhost to port 3306 on sharedhost.

  4. Make change in php to reflect the database names, users, password on Shared Host, and most importantly, instead of localhost, use mysqlhost in configuration files.

Automate the process

What if the ssh tunnel died? What if the VPS restarts? How to make sure the connection stays live? The answer is to use autossh.

  1. As root:

    yum install autossh
  2. Edit /etc/rc.d/rc.local, add this line at the bottom:
    su VPSusername -c 'autossh -M 5307 -f SHAREDHOSTusername@sharedhost -N -L 3306:*:3306' &

    This tells the server to execute the command in ‘ ‘ as VPSusername and put the process into background at startup. autossh will use port 5307 to monitor the ssh tunnel to sharedhost, and reconnect if it drops. Also make sure to disable the local MySQL daemon from starting automatically, or the tunnel cannot be created.

All Rights Reserved Copyright © 2008 Design by StyleShout and Clazh