2010年4月25日 星期日

Programming Android Application in Scala.

今天在 OSDC 聽到的課程,印象非常深刻,相當認同講者的觀點

2010年4月22日 星期四

ActionScript: Tween Engine

TweenLite, TweenMax
http://www.greensock.com/

Locking a File

http://docstore.mik.ua/orelly/webprog/pcook/ch18_25.htm

$fh = fopen('guestbook.txt','a')         or die($php_errormsg);
flock($fh,LOCK_EX)                       or die($php_errormsg);
fwrite($fh,$_REQUEST['guestbook_entry']) or die($php_errormsg);
fflush($fh)                              or die($php_errormsg);
flock($fh,LOCK_UN)                       or die($php_errormsg);
fclose($fh)                              or die($php_errormsg);


$fh = fopen('guestbook.txt','a')         or die($php_errormsg);
$tries = 3;
while ($tries > 0) {
    $locked = flock($fh,LOCK_EX | LOCK_NB);
    if (! $locked) {
        sleep(5);
        $tries--;
    } else {
        // don't go through the loop again 
        $tries = 0;
    }
}
if ($locked) {
    fwrite($fh,$_REQUEST['guestbook_entry']) or die($php_errormsg);
    fflush($fh)                              or die($php_errormsg);
    flock($fh,LOCK_UN)                       or die($php_errormsg);
    fclose($fh)                              or die($php_errormsg);
} else {
    print "Can't get lock.";
}

2010年4月21日 星期三

Thread-local storage

http://en.wikipedia.org/wiki/Thread-local_storage


Thread-local storage (TLS) is a computer programming method that uses static or global memory local to a thread.
This is sometimes needed because all threads in a process share the same address space. In other words, data in a static or global variable is normally always located at the same memory location, when referred to by threads from the same process. Variables on the stack however are local to threads, because each thread has its own stack, residing in a different memory location.
Sometimes it is desirable that two threads referring to the same static or global variable are actually referring to different memory locations, thereby making the variable thread local, a canonical example being the C error code variable errno.
If it is possible to make at least a memory address sized variable thread local, it is in principle possible to make arbitrarily sized memory blocks thread local, by allocating such a memory block and storing the memory address of that block in a thread local variable.

ProgressBar in Windows

使用 msctls_progress32

在 xp 必須先呼叫
InitCommonControls(); // libcomctl32.a
否則連它 parent 的 Dialog/Window 也不會出現

在 win7 下
不管有沒有呼叫此函式,progress bar 都會出現

2010年4月20日 星期二

最佳化 Flex, Flash

Flex性能優化常用手法總結
http://www.5uflash.com/Flex-AIR/Flexziliao/5577.html

Flash性能優化的一些細節
http://www.5uflash.com/flashjiaocheng/Flashyingyongkaifa/5576.html

2010年4月19日 星期一

Apache 取得透過 Reverse Proxy 的 Client 真正 IP (mod_rpaf)

參考以下兩篇

Apache 取得透過 Reverse Proxy (Varnish) 的 Client 真正 IP (mod_rpaf)
使位在Reverse Proxy後端的Apache 可以取得正確的Client IP -- mod_rpaf-2.0

Debian 安裝如下
apt-get install libapache2-mod-rpaf

修改
/etc/apache2/mods-available/rpaf.conf

2010年4月15日 星期四

Fail2ban

看到 apache.org 的 JIRA 被駭客惡搞的新聞
http://www.ithome.com.tw/itadm/article.php?c=60623

Apache 修正了問題,還很佛心地公開他們的修正方法
https://blogs.apache.org/infra/entry/apache_org_04_09_2010

其中一項是
"Use Fail2Ban to protect web application login failures from brute force attacks"

原來有 Fail2Ban 這種東西,字面上的意思就是,失敗(Fail)就把你給擋掉(Ban)
http://net.nthu.edu.tw/2009/security:fail2ban

主機若有開放 SSH, FTP, Apache 登入 ,都應該裝這個來加強安全性。Fail2Ban 是 monitor log,所以一般的 web 程式應該也可以產生文字 log的方式來 trigger 它的 action,像是擋 Client IP 之類的。

另有 denyhosts 似乎也不錯,但使用這類軟體時,千萬要看清楚設定項目,免得不小心把自己也給擋了...
[FreeBSD] DenyHosts 設定在 hosts.allow 注意事項

安裝在 Debian
apt-get install denyhosts

PHPUnit

Change to your php5 installation folder
cd c:\php5 

You have to install pear if you don't have it
go-pear.bat 


For convenience, a REG file is available under C:\php5\PEAR_ENV.reg
This file creates ENV variables for the current user.
Double-click this file to add it to the current user registry.

Start to install phpunit
pear install phpunit/PHPUnit 

optional for phpunit
pear install pear/Image_GraphViz

optional for phpunit
pear install --alldeps pear/Log

Check the installation is fine

phpunit --version
PHPUnit 3.4.12 by Sebastian Bergmann.


Modify phpunit.bat, change PHPBIN to your realpath, like this
set PHPBIN="C:\php5\php.exe"


Set envirment variable "PATH"
PATH=....;C:\php5
and we can call phpunit.bat in anywhere

What kind of assertion do we have ?
Check this, PHPUnit\framework\Assert.php

Examples:
http://www.phpunit.de/manual/current/en/test-driven-development.html

2010年4月13日 星期二

Yii: Custom PageSize in CGridView

<?php

// Custom PageSize
$data = $model->search();
$data->pagination->pageSize = 5;

$this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'table-grid',
    'dataProvider'=>$data,
    // 'filter'=>$model,
    'columns'=>array(
        'id',
        'userId',
        array(
            'class'=>'CButtonColumn',
        ),
    ),
)); ?>

jQuery iPod-style Drilldown Menu

http://filamentgroup.com/lab/jquery_ipod_style_drilldown_menu

Soft KVM, 一組 keyboard, mount 多台電腦及 monitor

http://synergy2.sourceforge.net/

因為使用 W2XW 時,mouse 經常會卡住,所以改用這套
Win32, Linux, Mac 可用

Server (有 mouse, keyboard 端)






Client

2010年4月6日 星期二

Datagrid (AdvancedDataGrid), break line in case of very long string

<mx:Datagrid variableRowHeight="true"
<mx:DataGridColumn wordWrap="true"