Blog

  • Keep pace with Magento

    I tried Magento 1.4.2.0 RC1 today, and noticed it had added “Include in Navigation Menu” option in Manage Category.

    I am very happy seeing this because I made it happen before Magento did. I call it “Exclude in Top Navigation”. I also have added an option “Exclude in Sitemap” which is not available in newest version of Magento.

    So, I keep pace with Magento, and vice versa?

  • Install / uninstall Adobe Reader on Fedora

    在 Fedora 上安装 Adobe Reader (最新版本 9.4) 本来是非常简单的一件事,很久以前我装过一次,今天在新系统上第二次装,竟然花了两个小时。

    最主要的原因是我下载了错误的文件,我以为老马识途,没仔细看下载了一个 bin 文件,安装后尝试着执行被 SELinux 阻止。

    Summary:

    SELinux is preventing /opt/Adobe/Reader9/Reader/intellinux/bin/acroread from
    making the program stack executable.

    Detailed Description:

    The acroread application attempted to make its stack executable. This is a
    potential security problem. This should never ever be necessary. Stack memory is
    not executable on most OSes these days and this will not change. Executable
    stack memory is one of the biggest security problems. An execstack error might
    in fact be most likely raised by malicious code. Applications are sometimes
    coded incorrectly and request this permission. The SELinux Memory Protection
    Tests (http://www.akkadia.org/drepper/selinux-mem.html) web page explains how to
    remove this requirement. If acroread does not work and you need it to work, you
    can configure SELinux temporarily to allow this access until the application is
    fixed. Please file a bug report.

    Allowing Access:

    Sometimes a library is accidentally marked with the execstack flag, if you find
    a library with this flag you can clear it with the execstack -c LIBRARY_PATH.
    Then retry your application. If the app continues to not work, you can turn the
    flag back on with execstack -s LIBRARY_PATH. Otherwise, if you trust acroread to
    run correctly, you can change the context of the executable to execmem_exec_t.
    “chcon -t execmem_exec_t ‘/opt/Adobe/Reader9/Reader/intellinux/bin/acroread’”
    You must also change the default file context files on the system in order to
    preserve them even on a full relabel. “semanage fcontext -a -t execmem_exec_t
    ‘/opt/Adobe/Reader9/Reader/intellinux/bin/acroread’”

    Fix Command:

    chcon -t execmem_exec_t ‘/opt/Adobe/Reader9/Reader/intellinux/bin/acroread’

    SELinux 非常友好,但我这次尝试着它的建议 chcon -t execmem_exec_t ‘/opt/Adobe/Reader9/Reader/intellinux/bin/acroread’ 无济于事。

    最后,我重上 adobe 网站,发现还有 rpm 可供下载,有 rpm 当然用 rpm 啦,这次安装一次成功。

    PS: 如要卸载,yum erase AdobeReader_enu

  • How is customer_logged_in/out handle added to Magento layout?

    I was wondering how Magento merge or handle into handle in layout.

    I was expecting something like

    <default>
        <update handle="customer_logged_in" if="logged_in"/>
        <update handle="customer_logged_out" if="logged_out"/>
    </default>
    

    Obviously, there is not such codes in layouts.

    I searched within Magento folder for keyword “customer_logged_in”, but only occurrences I could find in layout/customer.xml.

    So, how is customer_logged_in/out handle added to Magento layout?

    At last, I found

    class Mage_Customer_Model_Observer
    {
        public function beforeLoadLayout($observer)
        {
            $loggedIn = Mage::getSingleton('customer/session')->isLoggedIn();
    
            $observer->getEvent()->getLayout()->getUpdate()
               ->addHandle('customer_logged_'.($loggedIn?'in':'out'));
        }
    }
    

    by tracing addHandle() in app/core/Mage/Core/Model/Layout/Update.php.

    I must say using observer adding layout handle makes very easy for other modules to detect customer login status.

  • Never use dotless domain for Magento installation

    Magento 说不要使用 localhost 安装,我也就不用,也没深究原因。

    我为了在本地调试一个网站,先拿了生产网站 euro-bags.eu 的一个子域名。后来该子域名被挪作他用,那时我想,如果换个子域名再被挪作他用,我干脆用一个用于域名保护而未建站的域名,于是开始用 euro-bags.com 来调试。

    没过很久,Euro Bags 要在生产网站上实施一条网站提速实践:静态文件使用单独的 cookieless domain。因为 euro-bags.eu 使用了顶级域名,顶级域名上使用了 cookie,那么子域名上无法实现 cookieless。Euro Bags 也不想依赖第三方服务 cookieless domain,于是启用 euro-bags.com 专门为生产网站提供静态文件。

    我的调试域名再次被挪作他用。为了防止此类不可预测的事情发生,我想到干脆用一个不可能用于生产网站的域名来完成调试,于是想到用 euro-bags。

    一开始没发现问题,用了几天后想登录 euro-bags admin area 发现登录不了,输入密码后总是弹回到登录页。

    百思后才得其解,原来在 Magento 里使用任何 dotless hostname 都犯了跟使用 localhost 同样的禁忌。Magento 基于安全考虑在 cookie 里打上 domain 烙印,而大部分浏览器用拒绝接受含 dotless hostname 的domain 烙印。虽然可以 comment out app/code/core/Mage/Core/Model/Session/Abstract/Varien.php 某些行让 Magento 在 cookie 里不打 domain 烙印,从而让浏览器接受它的 cookie,但我觉得这么做是南辕北辙:不含 domain 烙印的 cookie 固然通行,但 open to cookie hijacking。Magento 最值我称道的就是每个细节(我没见其它 ecommerce software 有如 Magento 的周到)。

    既然 Magento 要在 cookie 里打 domain 烙印,而大部分浏览器又不接受 cookie 里有 dotless hostname,那我就不要用 dotless hostname 来安装 Magento 不就得了。于是我最新启用euro-bags.net 来继续本地调试,因为未有迹象表明 Euro Bags 要把 euro-bags.net 纳入域名保护,也没有要用这个域名来提供服务的计划,所以我不用再频频更换调试域名了。

  • Non working day calculation is included in msdk module

    Although I am not ready to release msdk module for Magento, I finish a model called Qian_Msdk_Model_Nwd. It is to judge if a given date is a non working day by some pre-defined and user-defined rules. It can also work out what date of next n’th working day is.

    There are two types of rules, rule by date or rule by week. For Non Working Day (NWD) fixed by date, there is normally a make-up following working day as NWD if the original one is Saturday or Sunday. For NWD fixed by week, there is no make-up, usually.

    For the rule simplicity, I always assume make-up. When you are writing your own rules and do not want make-up to some rules, add “=” modifier to the beginning of each of them.

    How to read and write NWD rules?

    First thing to remember, as a general checking rule, I go through each line separated by “\n”, and verify if the supplied date (if omitted, assume today’s date) fall into the line of rule. There is no connection between lines, so do not expect a rule can make up another one.

    Second thing to remember, as PHP allows a date like “2010/13/33”, I allow you write rules like that too. However, avoid it if you can.

    Third thing to remember, PHP regards Sunday as 0 Saturday as 6, and I do the same.

    Fourth thing to remember, when ISO number weeks, it regards week starts Monday, and I do the same. If you do not know what I am talking about, read ISO-8601.

    Fifth thing to remember, I do not have a good algorithm to work out dates by lunar calendar. So that is no smart way to write a rule for Easter. Ditto many Chinese holidays. You have to use fixed date every year. I hope it won’t cost you long time write down all fixed dates of 10 years lunar NWD and just sit while this programme runs for 10 years. After 10 years, aha, you’ll find your way.

    OK, let’s get on to rule writing.

    1. Rule by date is something like “yyyy/mm/dd”, or “yyyy/mm/dd,dd,dd”. yyyy, mm or dd can take asterisk “*” as wild-card.

    For new year day, it is “*/01/01”. This is simplest scenario. For Christmas and Boxing day, it is “*/12/25,26”. Be careful here, do not write two rules “*/12/25” and “*/12/26”. They can not achieve the same result as “*/12/25,26”, because a rule can make up a following working day if the rule date is Saturday or Sunday, but it can not exclude days by other rules.

    You have to write in one rule if two or more NWDs are connected. However, the dates are not necessarily continuous. In theory, you can write a rule like “*/12/24,26”. In reality, I did not see any NWDs are scheduled like this.

    2. Rule by week is something like “yyyy/mm/dd/weekNumber/weekDay”, or “yyyy///weekNumber/weekDay”. yyyy, mm or dd can take asterisk “*” as wild-card. “yyyy///weekNumber/weekDay” use ISO-8601 to find the week and weekDay. I will cover it in section 3.

    “yyyy/mm/dd/weekNumber/weekDay” uses a reference year/month/day to find the n’th weekDay. N is specified by weekNumber.

    2.1 If both mm and dd are “*”, it uses a reference year. For example, “*/*/*/10/1” means 10th Monday of any year.

    2.2 If mm is a number, but dd is “*”, it uses a reference month. For example, “*/05/*/1/1” means 1st Monday in May. A lot of England bank holidays are specified this way.

    2.3 If dd is a number, it uses a reference day. For example, “*/06/06/0/1” means the Monday of the week where June 6 sits.

    In case of 2.1 and 2.2, weekNumber can take a negative number which means the last n’th weekDay. For example, “*/05/*/-1/1” means the last Monday in May. WeekNumber zero does not make sense here.

    In case of 2.3, weekNumber can take zero (means the same week), a positive number (n’th week forward), or a negative number (n’th week backward).

    3. “yyyy///weekNumber/weekDay” ISO-8601 style looks similar to case 2.1. But they are totally different.

    For example, “2011///1/6” means Saturday of week 1 of year 2011, which is 2011/01/08. But “2011/*/*/1/6” means the 1st Saturday of year 2011, which is 2011/01/01.

    Another example, “2010///52/6” means Saturday of week 52 of year 2010, which is 2011/01/01 (Yes, it goes into the following year). But “2010/*/*/52/6” means the 52th Saturday of year 2010, which is 2010/12/25.

    I think writing documentation helps programming. I have revised NWD documentation for 3 times or more, and every time I found a new way to structure the model.

    I also think any date calculation look simple but actual coding is very complex. This model took me half a year to finish although I am full time on it.

  • public static or static public

    在 php 中,public static 或 static public 怎么写都可以,所以我一直不知道哪种是正统的写法(象我这样追求正统的人,或许 python 更适合我?)。

    今天费点时间看看别人是怎么看待 public static or static public 这个问题的。我的结论是 public static 是正统的写法,于是我想把以前随意写成的 static public 都更新成 public static。所幸的是,以前一直用的都是 public static。倒是在 magento 的源码里找到一堆 static public,或许 magento developers 没被要求一定要怎么写,所以源码里混合了 public static 和 static public。

    我觉得 inconsistency 是最糟糕的,或许我在这个问题上吹毛求疵了。

  • My son and his classmates

    大宝在哪里呀,大宝在哪里(升调)

    1063975411967412742

    Image 1 of 63

  • Full page caching preparer module for Magento

    I am planning a project called Fpcp (Full Page Caching Preparer) to improve Magento performance. Yeah, it is called Fpcp and very similar to another module Cpfp (Cms Page Foot Print).

    I have a bit research on Magento Enterprise only features, and pick full page caching as my next interested project. I do not know how Magento Enterprise implements full page caching, but my idea is rewriting all blocks containing session related content with an ajax get method.

  • MB200 week calculation bug

    一个月前,我的 MB200 显示有系统更新可用,我就升级了一下。升级了以后很失望,firmware version 仍是 1.5,看来 motorola 不打算让 MB200 用上 android 1.6 以上版本了,有空了我还得自行升级。

    用了一个月,我发现了 MB200 现有的版本 (Blur version 1.3.39) 居然有个日期计算上的 bug。比如今天是星期天,它会认为是星期一。这样,我设定的闹钟,闹周一到周五,结果它闹的是周日到周四;10月的最后一个星期天的凌晨从夏令时切换到冬令时,结果它提前一天星期六就让我用上冬令时了,搞得我周六一早起来看时间后总觉得怪怪的。

    如果我来升级,我就上 android 2.2。

  • Double rainbow is nothing special

    Double Rainbow over Devon
    Double Rainbow over Devon

    This week I read a news on dailymail After seven years and 2,000 photographs… a double delight as rainbow lights up Devon

    By Daily Mail Reporter
    Last updated at 9:26 AM on 27th October 2010

    A photographer who has taken pictures of the view from his office window every day for seven years has finally struck gold by snapping this stunning double rainbow.

    Andy Kyle, 53, captured the weather phenomenon as it appeared to create a bridge over the river at Dartmouth in Devon.

    Andy, who runs a website called The View From The Dartmouth Office, has been posting pictures of the vista each day for the past seven years.

    He said he had taken more than 2,000 images of the view before he snapped the beautiful double rainbow.
    Howzat? Sometimes a dim secondary rainbow is seen outside the primary rainbow. Secondary rainbows are caused by a double reflection of sunlight inside the raindrops

    Howzat? The ‘bridge’ over the river at Dartmouth in Devon. Sometimes a dim secondary rainbow is seen outside the primary rainbow. They are caused by a double reflection of sunlight inside the raindrops

    Sometimes a fainter ‘secondary rainbow’ can be seen outside the main rainbow.

    Secondary rainbows are caused by a double reflection of sunlight inside the raindrops, and appear at an angle of 50–53°.

    If you look closely you can see the colours of the secondary rainbow are inverted, with blue on the outside and red on the inside.

    The secondary rainbow is fainter than the primary because more light escapes from two reflections than one and because the rainbow itself is spread over a greater area of the sky.

    The effect is quite ghostly, and makes for a stunning photograph, although it makes looking for the pot of gold slightly more tricky.

    I did not think about it too much. But today when I was taking my friend Erin to Heathrow Terminal 3, I saw double rainbow just above the airport. It was a pity I had no hands free to take a photo to compete because I was busy driving my car.

    When I am back home, I search for “double rainbow” photos, I find it is nothing special but reported many times in many places. If I head up a bit often, I may see double rainbow again very soon.