Category: 小小草

IT 技术领域学海无涯。其实任何领域都学海无涯,无非 IT 发展太快了,让我有更多嘘唏。希望我掌握的技术有如小小草,虽然渺小,却有旺盛的生命力。

  • Bkf is not found is not true

    When I tried to restore from bkf file created by Windows in-built System Tool Backup and Restore, I was not aware another colleague was accessing (read access) this file. At the last page of Restore wizard, it threw an error with a nonsense error message – “(the file name).bkf Disk 1 is not found”. The error message scared me because this bkf file is my only backup file I have. I do not have any other file like Disk 1, Disk 2. If this file is corrupted, nothing else I can fallback.

    I was released when I retried after my colleague finishing reading the file. Everything successfully restored when I had exclusive access to the bkf file.

    我早该想到 Windows 的错误提示往往不是它字面的意思。

    早就想用 Linux 的备份工具,但是很惭愧,还没熟练掌握,所以重要的备份还是在 Windows 下完成。

  • My understanding to Nginx so far

    Location directive 没有fallback 机制。因为一个 request 只能匹配一个 location,不是常规 location 的话,就是正则表达式 location。假如有两个 location blocks,
    location / {
    index index.php;
    }

    location /abc {
    client_max_body_size 32m;
    }

    请别指望 index index.php  会在location /abc 生效。因为这是两个 location,只能有一个生效,另一个被忽略。

    正则表达式 location 优先于常规 location 匹配(除非常规 location 使用 ^~ 或 =);常规 location 之间最长匹配优先;正则表达式 location 之间位置在前优先。

    Nginx wiki 文档里关于 location 用到的 “searching stops” 这个词很不恰当,挺误导初学者的思维,让人误以为会有两个或两个以上 location同时生效。

    正则表达式 location 以 ~ 或 ~* 开头,其他的都是常规 location (以 ^~ 开头的貌似正则表达式 location,却是常规 location)。

    Root directive 和 alias directive 用处类似,只是 alias 不改变 document root。但是,它们对文件的定位方式明显不同。例:
    如配置文件使用 root –
    server {
    server_name _;
    root /default/path;

    location /abc {
    root /another/path;
    }
    }
    Request to /abc/filename.jpg 将对应 /anther/path/abc/filename.jpg。
    如配置文件使用 alias –
    server {
    server_name _;
    root /default/path;

    location /abc {
    alias /another/path;
    }
    }
    Request to /abc/filename.jpg 将对应 /anther/path/filename.jpg。

    以上是我用我的语言的去理解 Nginx 的语法。

  • Different syntax in Nginx and Apache

    今天发现一个 Nginx 和 Apache 看似细微却影响巨大的语法差异:

    在 Apache 里重定向一个域名到另一个域名,

    RewriteRule (.*) http://destination.com/$1 [r=301,l]

    而在 Nginx 里,应该多加一个斜杠/,否则 $1就多了一个斜杠。

    rewrite ^/(.*) http://destination.com/$1 permanent;

  • Zend_Db ignore default charset of Mysql

    While I set my Mysql database default character set as UTF-8, Zend_Db_Adapter does not pick up the setting. Zend_Db write to Mysql using its own default character set (I guess it’s ISO-8859-1), unless it is specifically told by

    $dbAdapter->query(“SET NAMES ‘utf8′”);

    before

    Zend_Db_Table::setDefaultAdapter($dbAdapter);

  • Bonjour is not virus

    Bonjour bundled with Sarifi
    Bonjour bundled with Sarifi

    不知道 Bonjour 是怎么进入到我的电脑的,我不用Sarifi已经好多年。我不喜欢Apple的东西,装Sarifi只是为了测试,测试完毕重装系统也没再想着把Sarifi装回来。

    第一次注意到 Bonjour 进程的存在着实让我担心了一把,还以为是什么病毒,Google 了一下才知道是 Apple 开发的一个玩意儿才打消了我的顾虑。今天我再次安装Sarifi,里面提到 Bonjour,因为事先跟 Bonjour 有过接触,所以注意到了,拷屏下来告诉初识 Bonjour 的人,Bonjour 是无害的(但我也没意识到 Bonjour 有什么好处)。

  • Run Magento on GAE

    Google App Engine 不久前开始支持第二种语言 Java,我当时听到这个消息马上开始期盼什么时候 GAE 支持 PHP。

    今天看到 Quercus 项目,它可以让 PHP 运行在 Java 环境,我才意识到不用再期盼在 GAE 跑 PHP 程序,这已成为现实。这下我有事情做了——怎么把 Magento 跑在 GAE 上?

  • Skiing knowhow

    今天一天在瑞士 Titlis (铁力士) 雪山度过。

    在雪山当然是滑雪。我们一组18个人请了个教练,教了我们2个小时,教到后来我都饿了,没力气学了。于是吃饭,我胃口不错,大块大块的蹄膀也对我的胃口。雪山上的餐馆的价格反而比山下的便宜,倒出我意外。另一件意外是终年积雪的山顶并不冷。

    吃饱了有力气了就自己练习,我从山坡上往下滑老是摔跤,摔了很多引人注目的跤,差不多到最后一刻收工才领会到滑雪最基本的技巧:要想不摔跤,就要克服心理障碍,因为从山坡上加速下滑时,人本能地想控制住速度,希望通过重心后移来减速,但事实上,重心后移就会摔个人仰马翻,只有顺势前倾,才能不倒。我只在最后时刻成功地优雅地下坡两次,就听有人喊,赶快下山,缆车5点停机。

    哇,错过缆车末班车怎么办?听说也不要紧,有雪道可以从山顶一直滑到山脚。但是凭着我刚掌握的下坡动作恐怕还做不到这一点,还是赶紧跟着大部队坐缆车下山吧。

  • Luzern小镇静悄悄

    这次行程中没有安排苏黎世(Zurich)和日内瓦(Geneva),不过看过卢塞恩(Luzern),我也能想象瑞士其他城市的风格——安静平和。

    Luzern 6万人口(据说这是市中心人口,不包括乡村人口,他们也分城市和农村,挺有意思),人不多,但地方很小,游客更多,看起来也很热闹。Luzern的标志性建筑是河中央的一个八角小塔,曾经是瞭望塔兼监狱,现在开放,市民可以租来开 Party。

    离市中心不远有座高山 Pilatus,中文叫皮拉图斯山,海拔2,120米,它是阿尔卑斯山脉的前部。我们坐索道上去,索道分三段,前两段连续运行,中途可以上下乘客,第三段必须换乘。第二段开始就可以看到积雪,我就是没想明白:山并不高,气温也不低,怎么还能积雪到4月?

    Pilatus 相对高度只有585米,要是有时间,我倒愿意和很多当地游客一起徒步爬上去。

  • DtDdWrapper in Zend Framework

    我尝试着用 Zend Framework 重写了一个程序。在 Zend_Form 上徘徊了好久,研读了 Programmer’s Reference Guide N 遍,还是没有融会贯通。比如说,我想去掉默认的DtDdWrapper,用

    $element->removeDecorator(‘DtDdWrapper’);

    只对某些element起作用,对 Zend_Form_Element_Text 怎么也不起作用,最后发现用

    $element->removeDecorator(‘HtmlTag’);

    倒可行。

    问题是解决了,但还是没摸清 Zend Framework 设计思路。很累。

    续:

    其实,用$element->removeDecorator(‘HtmlTag’); 问题并没有完全解决。后来我用

    var_dump($element->getDecorators());

    查看了默认加载的装饰器以及装饰器的参数,发现对于 Zend_Form_Element_Text 来说,它的 dt 和 dd 并不是由 DtDdWrapper 加载的,事实上 Zend_Form_Element_Text 默认不加载 DtDdWrapper,难怪

    $element->removeDecorator(‘DtDdWrapper’);

    是不起作用的。

    那么,Zend_Form_Element_Text 的 dt 和 dd 是哪里来的呢?我仔细看了 var_dump 的结果,发现

    • dt 是由默认的 Label 装饰器默认的 dt 参数带来的
    • dd 是由默认的 ViewHelper 装饰器默认的 dd 参数带来的

    如果想要 Zend_Form_Element_Text 不套用 dt 和 dd,应该对症下药,修改 Label 和 ViewHelper 默认参数。

    上次用 $element->removeDecorator(‘HtmlTag’); 并没有去除 dt 和 dd,只是误打误撞让页面呈现出视同没有 dt 和 dd 时的效果。

  • Generate a UTF-8 encoded Actinic site

    I don’t like the way of Actinic tackle the problem. For example, if the web server set default charset as UTF-8, it will cause page rendering issue for Actinic. Especially for the pound sign. All the support knowledge from Actinic is redirecting people set the server using default chareset as ISO-8859-1. Then, my question is – why should I use ISO-8859-1 while UTF-8 has far better applicability, especially for multi-national sites?

    Nevertheless, can Actinic generate an UTF-8 encoded site? The answer is yes and no.

    Yes is because I have already achieved it; No is because Actinic can not make it happen for you (at least I won’t know how to control it), so you must do something outside Actinic. Here below is my detailed steps.

    • First, rewrite all requests to actinic generated files to index.php.
    • Second, create a bootscript, name it as index.php. This idea is inspired by Zend Framework. Make sure:
      1. The bootscript should be in utf-8 encode.
      2. The bootscript should be able to include actinic generate files according to request uri.
    • Third, in actinic templates, change meta tag charset to utf-8.
    • Last, at web server, adddefaultcharset utf-8.

    The most tricky part is actinic upload its files in iso-8859-1 encoding, but bootscript is utf-8 encoded. A normal include or require by php will not render pound sign correctly. I use output buffer to hack the problem.

    <?php
    ...
    ob_start();
    include($actinic);
    $utf8out = utf8_encode(ob_get_contents());
    ob_end_clean();
    echo $utf8out;
    ?>