October 2007 Archives

php object to JSON

| No Comments | No TrackBacks

PHP默认的那个extension在转换json的时候会把UTF-8字符用"\xxx"方式表示出来,因此十分浪费带宽。所以自己又写了一个出来。

 $val) {
            if (is_array($val)) {
                array_push($aj, self::_arrayTOJSON($val, $quote));
            } else if (is_object($val)) {
                array_push($aj, self::_objectTOJSON($val, $quote));
            } else {
                if ($quote)
                    $key = '"'.self::_escape($key).'"'; 
                else
                    $key = self::_escape($key);
                if (!is_numeric($val) || $quote)
                    $val = '"'.self::_escape($val).'"';
                array_push($aj, $key.':'.$val);
            }
        }
        if ($quote)
            $key = '"'.self::_escape(get_class($obj)).'"'; 
        else
            $key = self::_escape(get_class($obj));

        return $key.':{'.join(',', $aj).'}';
    }

    protected function _arrayToJSON($arr, $quote) 
    {
        $aj = array();
        foreach( $arr as $item) {
            if (is_array($item)) {
                array_push($aj, self::_arrayToJSON($item, $quote));
            } else if (is_object($item)) {
                array_push($aj, self::_objectToJSON($item, $quote));
            } else {
                if (!is_numeric($item) || $quote)
                    $item = '"'.self::_escape($item).'"';
                array_push($aj, $item);
            }
        }

        return '['.join(',', $aj).']';
    }
    private function _escape($s) 
    {
        $boys = array('\\', '"', "\r", "\n","'","/");
        $girls = array('\\\\', '\"', '\x0D', '\x0A',"\'","\/");
        return str_replace($boys, $girls, $s);
    }
}

class JSONUtil extends Jsonable{
    public function arrayToJSON($arr, $quote = false) 
    {
        return self::_arrayToJSON($arr, $quote);
    }
}
?>

framebuffer和X都需要对分辨率进行设置,而gtf就是为此而生的工具。

e.g.

gtf 1024768 60 -x

可以得到1024×768@60Hz的Modeline设置。

Linux死机处理 (from wikipedia)

| No Comments | No TrackBacks

"Raising Elephants Is So Utterly Boring" means:

  1. Alt + SysRq + R – takes the keyboard out of raw mode.
  2. Alt + SysRq + E – terminates all processes (except init).
  3. Alt + SysRq + I – kills all processes (except init).
  4. Alt + SysRq + S – synchronizes the disk.
  5. Alt + SysRq + U – remounts all filesystems read-only.
  6. Alt + SysRq + B – reboots the machine.

An alternative to issuing the REISUB/RSEIUB keystrokes is to just press Alt + SysRq + R, followed by Ctrl + Alt + Del. This is the equivalent of issuing a shutdown now command at a root console; it does take a short while for the system to shut down after the Ctrl + Alt + Del keystroke. However, not all Linux systems support this easier method.

Notes on Fastcgi

| No Comments | No TrackBacks

Think clean. Typical CGI scripts don't need to be excessively concerned with memory leaks or sloppy variable scoping. FastCGI scripts, since they're persistent, have to keep a tighter rein on things.

Think big. We're used to thinking of CGI scripts as fast one-timers that should define the fewest functions necessary to get the job done. With FastCGI, it's usually better to have lots of functionality in one script; you have easier access to shared data and fewer PIDs littering your process table. I try to use the main script (the one specified in httpd.conf) as a distribution center, jobbing out all the real work to modules. Doing so makes it easy to extend the main script's functionality with just an extra line or two of code; all your tweaking can be done on the module.

Think long-term. You want your process to keep running, so it's wise to not let your script die() or croak(). Catch the return value of any statement whose failure might prove fatal (such as open()) and rely on error messages and flow control to keep the loop running.

Reference: http://www.linuxjournal.com/article/2607

用screen做远程演示

| No Comments | No TrackBacks

参考文献: http://www.pixelbeat.org/docs/screen/

启动一个命名screen

screen -S shared

开启多用户模式

C-A: multiuser on

加入用户

C-A: addacl ywayne,yuting,leiyh

设置用户只读权限

C-A: aclchg ywayne,yuting,leiyh -wx "#,?"
C-A: aclchg ywayne,yuting,leiyh +x "colon,detach,wall"

这里允许执行的三个命令里colon是指C-A之后输入的那个冒号(真不理解冒号也是命令!?)。detach是允许客户不想看的时候可以用C-A D离开screen(强奸客户们的意图是不好滴)。wall是让客户可以使用wall命令向所有发言,方便演示过程中提问。

客户登录

screen -x jianingy/shared

October 2008

Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  

Friends' Links

Recent Comments

  • jianingy: test read more
  • mmx: thank u very much ! read more
  • FW: pls contact me with email.about APIHook. read more
  • jianingy: 这个lc是啥意思? -------- read more
  • cnhackTNT: 晕,被过滤掉了,再试试: s/(?<!\\)\$NICK/lc/e; 汗,过滤了小于符号,只好写<了呵呵 read more
  • cnhackTNT: s/(? 这样可以少打几个字呵呵 read more
  • R.Q.: 酱紫哦,了了 -------- read more

Archives

Powered by Movable Type 4.21-en