Feeds:
Posts
Comments

Archive for the ‘Uncategorized’ Category

In order to allow developer to use translator instance into validators, Zend Framework 2.2 add a new service call MvcTranslator, as quoted in documentation:

“A new service has also been registered with the MVC, MvcTranslator, which will return this specialized, bridge instance.

Most users should see no issues, as Zend\Validator\ValidatorPluginManager has been modified to use the MvcTranslator service internally, which is how most developers were getting the translator instance into validators in the first place. You will only need to change code if you were manually injecting the instance previously.”

However, we used to set the locale by a manually injected translator to allow users switching to different languages. After upgraded to 2.2.2 or later (the latest version at this time is 2.3.1), the switching languages function is no longer working properly.

In order to make sure function works properly no matter the version is, I updated the code to something like:

    public function setLocale($locale) {
        $sm = $this->getServiceLocator();
        if($sm->has("mvcTranslator")){
            $this->translator = $sm->get('mvcTranslator');
            $this->translator->setLocale($locale);
        }else if($sm->has("Translator")){
            $this->translator = $sm->get('translator');
            $this->translator->setLocale($locale);
        }
    }
Advertisements

Read Full Post »

Some content on this page was disabled on March 8, 2018 as a result of a DMCA takedown notice from Yahoo!. You can learn more about the DMCA here:

https://en.support.wordpress.com/copyright-and-the-dmca/

Read Full Post »

(more…)

Read Full Post »

If you have installed mac port, it’s normal to install python and django under macport.

如果你安裝了macport,很自然地,你希望用macport去安裝python及django。

The latest python installed by macport should be 2.7.3, thus command for installation of python and django are:

由於在macport之下最新的python的版本是2.7.3。故此在macport下安裝python及django的指令:

sudo port install python
sudo port install py27-django

If you have installed previous version of python through macport, you should make sure which one is active, you can use the following command to check:

如果你之前曾用過macport安裝舊版本的python,你可以用以下的指令查看那一個版本才是預設的。

port select --list python

The result should be similar to the following:
如果會跟以下的差不多:

Available versions for python:
	none (active)
	python25-apple
	python26-apple
	python27
	python27-apple

If you want to ask macport to select the python 2.7.3 provided by macport as default python interpreter, you should use the following command:

如果你想指定用macport所提供的python 2.7,你需要用到以下的指令:

sudo port select python python27

If you want to see if you have set the active python interpreter correctly, type the following command to check the path of python:

如果你想測試之前能否成功地指定python interpreter,可以用以下的指令查看python的路徑:

which python

If you selected macport’s python, the path should be:
如果你選的是macport所提供的python,應看到以下的結果:

/opt/local/bin/python

Try to repeat the previous steps if you find the path is different.
如果你發現python的路徑不相同,請重覆以上的步驟。

Now, please check your path to django-admin.py:
現在請查看django-admin.py的路徑,

which django-admin.py

In my computer, the result is:
在我的電腦,django-admin的位置是:

/usr/local/bin/django-admin.py

If you execute django-admin.py, you will find out that python cannot find django.core. The problem is caused from the first line of django-admin.py

如果你執行django-admin.py你會發現python找不到django.core。問題源於django-admin.py的第一句。

#!/usr/bin/python
from django.core import management

if __name__ == "__main__":
    management.execute_from_command_line()

The first line tell shell to use the python installed by mac os instead of using the python provided by macport. Thus, we should use the following command to change the first line:
第一句告知shell使用由mac os所提供的python而不是macport 所提供的python。所以我們須用以下的指令更改第一句:

sudo nano /usr/local/bin/django-admin.py

The updated source code should look like:
更改後的django-admin.py應該是:

#!/opt/local/bin/python
from django.core import management

if __name__ == "__main__":
    management.execute_from_command_line()

Then, you can ran django-admin.py properly.
之後,你就可以正常地運行django-admin.py

However, next time if you update django, please repeat the process again.
下次你更新django時,請重覆整個步驟。

Read Full Post »

One of my colleague using Internet Explorer 10 to emulate IE 8 Standard mode. During calling slice() method for a String object. It shows the error “slice not found in object”.

我有位同事用Internet Explorer 10去模擬IE 8標準模式。在一句指令中,字串物件上執行slice()方法時,卻發生了問題,Internet Explorer顯示”slice not found in object”

This problem in weird since in microsoft website, it stated that string’s slice method is existed in all versions. (http://msdn.microsoft.com/en-us/library/ie/s4esdbwz(v=vs.94).aspx)
這是個奇怪的情況,因為在微軟的網站內寫著所有版本Internet Explorer都有String slice。

In order to avoid any similar problem, I wrote a custom slice() method whenever slice() is not found as default:
為了避免這問題,我寫了一段指令,當發現在字串物件中找不到slice()時,會用一個自訂的slice()方法.

if(typeof String.prototype["slice"]==="undefined"){String.prototype.slice=function(s,e){var l=this.length;return this.substr(s=s<0?l+s:s,typeof e==='number'?(e<0?l+e:e)-s:l-s)}}

Read Full Post »

最近工作桌的那部電從Ubuntu 12.10升級到Ubuntu 13.04突然發現無法使用phpmyadmin。

Recently, I’ve upgraded my desktop in my working place from Ubuntu 12.10 to Ubuntu 13.04. After installation had finished, I found phpmyadmin couldnot operate properly.

從WebBroswer自到代碼500。於是我查看Apache 2 log:

There was 500 server error found in my webbrowser. So, I decided to check the Apache2 log:

cat /var/log/apache2/error.log

我看到:
From the log, I found the followings:

[Mon May 20 10:23:07 2013] [error] [client 127.0.0.1] PHP Stack trace:
[Mon May 20 10:23:07 2013] [error] [client 127.0.0.1] PHP   1. {main}() /usr/share/phpmyadmin/index.php:0
[Mon May 20 10:23:07 2013] [error] [client 127.0.0.1] PHP   2. require_once() /usr/share/phpmyadmin/index.php:13
[Mon May 20 10:23:07 2013] [error] [client 127.0.0.1] PHP   3. require() /usr/share/phpmyadmin/libraries/common.inc.php:614
[Mon May 20 10:23:26 2013] [error] [client 127.0.0.1] PHP Fatal error:  require_once(): Failed opening required './libraries/php-gettext/gettext.inc' (include_path='.') in /usr/share/phpmyadmin/libraries/select_lang.lib.php on line 370

看似是找不到gettext library。經網上查証,只要更改phpmyadmin所提供的apache.conf,在php_admin_value一行,末端加入:/usr/share/php/php-gettext/
即:

It seemed to be an error when the web page tried to look up the gettext library. I found a solution from the internet that requires me to add /usr/share/php/php-gettext/ to the line of php_admin_value in my apache.conf (the one that provided by phpmyadmin). The updated conf file should look like:

<Directory /usr/share/phpmyadmin>
	Options FollowSymLinks
	DirectoryIndex index.php

	<IfModule mod_php5.c>
		AddType application/x-httpd-php .php

		php_flag magic_quotes_gpc Off
		php_flag track_vars On
		php_flag register_globals Off
		php_admin_flag allow_url_fopen Off
		php_value include_path .
		php_admin_value upload_tmp_dir /var/lib/phpmyadmin/tmp
		php_admin_value open_basedir /usr/share/phpmyadmin/:/etc/phpmyadmin/:/var/lib/phpmyadmin/:/usr/share/php/php-gettext/
	</IfModule>
</Directory>

再重啟apache2:
After I had restarted my apache 2:

sudo /etc/init.d/apache2 restart

Wow.. phpmyadmin became normal again!

Read Full Post »

當細心回想,土壤上曾有過像螢光的小點,原來這是真菌蚋的幼蟲的絲。

最初在盆栽中出了一兩隻真菌蚋(蚊滋)。由於太忙沒有理會他們。結果在有三格幼苗的土壤表面上出現大量似出白色的真菌物體,一天後有部份轉至褐色。真菌蚋(蚊滋)的數量也多了幾隻。

我決心要處理這些真菌蚋(蚊滋)。在網上有位年輕的太太在其blog上介糿用tumble dryer sheets。

我在兩天前乘車時,曾在思考如果為樹木殺滅埃及吹棉介殼蟲(見本人的Facebook內提及天水圍樹木被埃及吹棉介殼蟲為患一文)。想到了用freeze spray。今早,我以Freeze spray將真菌蚋(蚊滋)的成蟲殺滅了。真菌蚋成蟲被Freeze Spray急凍之下,最初還有活動能力,相信其腹部不能禦寒,一分鐘內變得無法行動,然後死去。

我會更換受真菌蚋(蚊滋)幼蟲感染的泥土,亦會為泥土噴上Freeze Spray,研究一下Freeze Spray對真菌蚋(蚊滋)幼蟲的影響。

如果能對真菌蚋(蚊滋)幼蟲有效,我會試用Freeze Spray去對付 埃及吹棉介殼蟲。

Read Full Post »

Older Posts »