Friday, April 24, 2009

Flex3/ActionScript3.0中eval的替代方案

AS3中没有eval,但可以像这样调用:

this["your_function_name"]();


请看例子:


private function playTrack(location:String):void {

var dot_position:Number = location.lastIndexOf('.');
var file_ext:String = location.substr(dot_position+1);

var play_function_name:String = file_ext+"_player";
if (this.hasOwnProperty(play_function_name)) {
this[play_function_name]();
}else {
Alert.show("Do not support this file extension("+file_ext+").");
}

}


参考:http://livedocs.adobe.com/flex/3/html/help.html?content=ProgrammingHTMLAndJavaScript_03.html

Tuesday, April 21, 2009

Zend Studio specify a variable to a class for hint

a example is:

/* @var $m Memcache */
$m = memcache_connect();

Sunday, April 19, 2009

Create symbol link on Windows

一直在Linux下用symbol link创建链接,实现Apache的DocumentRoot到Developing Directory的链接。每次开新Branch都换一下链接即可。

本以为用cygwin的ln可以解决这个问题,但发现cygwin的ln命令竟然只是创建了一个windows的shortcut。Shit,于是找到了一个替代的方案,使用junction,这是一个介绍:
Windows 2000 and higher supports directory symbolic links, where a directory serves as a symbolic link to another directory on the computer. For example, if the directory D:\SYMLINK specified C:\WINNT\SYSTEM32 as its target, then an application accessing D:\SYMLINK\DRIVERS would in reality be accessing C:\WINNT\SYSTEM32\DRIVERS. Directory symbolic links are known as NTFS junctions in Windows. Unfortunately, Windows comes with no tools for creating junctions—you have to purchase the Win2K Resource Kit, which comes with the linkd program for creating junctions. I therefore decided to write my own junction-creating tool: Junction. Junction not only allows you to create NTFS junctions, it allows you to see if files or directories are actually reparse points. Reparse points are the mechanism on which NTFS junctions are based, and they are used by Windows' Remote Storage Service (RSS), as well as volume mount points.


Using Junction

Usage: [-s]
-s Recurse subdirectories


If you want to create or delete a junction, use Junction like this:

Usage: [-d] []

To delete a junction specify the -d switch and the junction name.


创建出来的symbol link很漂亮,一个像快捷方式的小箭头都没有。

下载地址:
http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx

Thursday, April 2, 2009

a way to Limit textarea max length.

a way to Limit textarea max length.


function keyup_info_description( inLengthMaximum ) {
if ( inLengthMaximum < document.getElementById('info_description').value.length )
document.getElementById('info_description').value = document.getElementById('info_description').value.slice( 0, inLengthMaximum );
}

Saturday, January 24, 2009

脚本执行速度测试简单实现

之前看到有人测试脚本执行时间,在程序开始的时候计一个时间,再到程序最后再计一次时间,从而得到脚本的执行时间。但如果脚本是从其它的分支退出,那又得再写一次。

我觉得这样不方便,退出分支多的时候,代码就散开不好管理了,而解决方案就是下面的:


$jacky_test_time = microtime(true);
function jacky_test_tf($ff=”) { global $jacky_test_time; $result = microtime(true)-$jacky_test_time; echo “”; }
register_shutdown_function(’jacky_test_tf’);


当然在程序当中的任何位置都可以调用 jacky_test_tf 函数去输出执行到当前的时间。

a simple way to get your PHP script if running in CLI

There is a function to get that way easier.

public static function inCli() {
return php_sapi_name() == ‘cli’;
}

Zend Studio远程调试PHP再整理

1.下载Debug:
http://downloads.zend.com/pdt/server-debugger/

2.将压缩包中的5_2_x_comp中的ZendDebugger.dll解压到新建目录:
C:\Program Files\Zend\ZendDebugger-5.2.14\php-5.2.x

3.安装Zend Optimize或下载Zend Extension Manager.dll

4.修改php.ini(新增)(根据自己的情况对路径做修改)
zend_extension_ts="C:\Program Files\Zend\ZendExtensionManager.dll"
zend_extension_manager.debug_server_ts="C:\Program Files\Zend\ZendDebugger-5.2.14"
zend_debugger.expose_remotely=allowed_hosts
zend_debugger.allow_hosts=127.0.0.1/32,192.168.1.0/16
zend_debugger.allow_tunnel=127.0.0.1/32

5.解压debug压缩包里的dummy.php到要调试的网站根目录。

6.重启Web server.

———————–热情分割线———————–

另外,配置也可参考这个不用ZO的:
zend_extension_ts=”D:/Servers/php5/ext/ZendDebugger.dll”
zend_debugger.allow_hosts=192.168.1.1
zend_debugger.expose_remotely=always