Perl String Comparison Operators

2010年04月6日

In order to compare for string equality, or if one string is alphabetically bigger than another, you can use the six string comparison operators. Here are the string operators together with the numerical operators they correspond too:

String Operator Numerical Operator
eq ==
ne !=
gt >
lt <
ge >=
le <=

Notice that the string operators are built from the initials of their abbreviated names. (E.g: eq = equal, gt = greater than). Perl’s string comparison is case-sensitive. If you want a case insensitive string comparison, use the lc function to convert the strings to lowercase beforehand.

Do not throw exception in exception_handler function and __destruct without try-catch

2010年03月31日
Do NOT throw exception in exception_handler function, if you do it like below, 
the error “Fatal error: Exception thrown without a stack frame in Unknown on line 
0” will occur
set_exception_handler('handle_exception');
function handle_exception($e)
{
    throw new Exception('throwed in handle_exception');
}
throw new Exception('error occur');

if you try-catch the Exception in exception_handler function, it will be ok, the below code will work well

set_exception_handler('handle_exception');
function handle_exception($e)
{
    try {
        throw new Exception('throwed in handle_exception');
    }
    catch (Exception $e) {
        die('catch exception in handle_exception function');
    }
}
throw new Exception('error occur');
Do NOT throw Exception in __destruct like below, or “Fatal error: Exception thrown
without a stack frame in Unknown on line 0” will occur.
class Test {
    function __construct () {}
    function __destruct() {
        throw new Exception('throwed in __destruct');
    }
}
$test = new Test();

but it will work well when try-catch it like below

class Test {
    function __construct () {}
    function __destruct() {
        try {
            throw new Exception('throwed in __destruct');
        }
        catch (Exception $e) {
            die('catch exception in __destruct');
        }

    }
}
$test = new Test();

在windows下用wingrub安装backtrack 4 final双系统

2010年03月19日

在windows操作系统下利用wingrub安装backtrack 4 final,不需要你另外的磁盘分区、U盘.

下面讲一下安装过程

1. 安装WinGrub/Grub4DOS

http://sourceforge.net/projects/grub4dos/ 下载,然后安装,安装好了之后,打开wingrub, 点击Tools/Install Grub, 选择BOOT.ini, 填入”Back Track 4 Final”到Title, 再点击 Install, 这时会自动拷贝GRLDR 到c:\ ,还会创建c:\grub文件夹.

2. 从bt4-final.iso里拷贝/casper and /boot 到c:\

3. 修改C:\boot\grub\menu.lst. 当你打开文件时已经有一些内容, 但没有find –set-root /GRLDR这句话,所以应该加上。

最终内容应该为:<!– more –>

# By default, boot the first entry.
default 0

# Boot automatically after 30 secs.
timeout 10

splashimage=/boot/grub/bt4.xpm.gz

title BackTrack4 Pre Final Persistant USB
find –set-root /GRLDR
kernel /boot/vmlinuz BOOT=casper boot=casper persistent rw vga=0×317
initrd /boot/initrd.gz

title BackTrack4 Pre Final USB
find –set-root /GRLDR
kernel /boot/vmlinuz BOOT=casper boot=casper nopersistent rw vga=0×317
initrd /boot/initrd.gz

title BackTrack4 Forensics USB (no swap)
find –set-root /GRLDR
kernel /boot/vmlinuz BOOT=casper boot=casper nopersistent rw vga=0×317
initrd /boot/initrdfr.gz

title BackTrack4 in Text Mode USB
find –set-root /GRLDR
kernel /boot/vmlinuz BOOT=casper boot=casper nopersistent textonly rw quiet
initrd /boot/initrd.gz

title BackTrack Graphical Mode from RAM USB
find –set-root /GRLDR
kernel /boot/vmlinuz BOOT=casper boot=casper toram nopersistent rw quiet
initrd /boot/initrd.gz

title Memory Test
find –set-root /GRLDR
kernel /boot/memtest86+.bin

title Boot the First Hard Disk
root (hd0,0)
chainloader +1

4. 重起电脑, 这时可选择Back Track 4 Final进入系统。进入时会显示loading and wait, 时间比较久(有时我随便输入一些文字,就马上就可以了, 你也可以试一下)

window live writer wordpress出错

2010年03月19日

当出现下面的问题时:

The response to the metaWeblog.getRecentPosts method received from the blog server was invalid:

Invalid response document returned from XmlRpc server

可以用下面的方法解决:

因为wordpress本身的一个bug,在utf-8编码下,在wp-includes文件夹下, xml-rpc返回的格式不正确,缺了三个字节,要修正这个问题,按如下操作即可:
用一个文本编辑工具打开class.ixr.php,查找:
$length = strlen($xml);

替换为:<!–more –>

$length = strlen($xml)+3;

就可以解决这个问题了!

ruby版本的discuz自动注册机

2009年12月29日

概要:
为了让别人以为你discuz网站的注册用户比较多,你可能需要注册大量虚假用户来伪造discuz网站的人气,如果手动地注册,那效率肯定会很低,势必需要一个工具来帮我们自动化地完成这个工作,本人就用ruby写了这样一个自动为discuz注册用户的工具.
阅读这个条目剩下部分 »

Page 2 of 13«12345»10...Last »