Drupal 7 – Get path alias by Node ID or Term ID
We did talk about using drupal_lookup_path() to get path alias.
The above function is still working in Drupal 7. We could also use the url() to get the path alias url as well.
// Get the node id path alias
url('node/' . $tid);
// Get the term id path alias
url('taxonomy/term/' . $tid);
Done =)
Reference:
天然方法趕小強
小強是很多人的公敵,牠們是把疾病細菌帶到居家環境的主要源頭之一!只要看到一隻蟑螂,就表示還有100隻你看不到的在附近。不過,許多人害怕蟑螂,又不想靠毒藥殺生。試試看下面這5種對你無害也對蟑螂無害的天然方法。
1. 洋蔥
將洋蔥切片,放一盤在室內,蟑螂聞到洋蔥味便會立刻走開,做菜時就順手切幾碟吧。
2. 青瓜
小強不喜歡青瓜的味道,下次做菜時,青瓜的頭和尾不要丟掉,收集起來放到房間角落,小強嗅到味道就會避開,而青瓜看起來乾皺就是時候更換了。
3. 精油水槍
在噴水槍裏裝
- 250毫升水
- 1小匙鹽
- 20滴薄荷精油
- 10滴柏樹精油
搖勻後,噴在小強常出沒的地方,抽屜,細縫都不要放過。當你和小強面對面的時候,也可以像機關槍一樣用這個噴液,驅逐小強離開你的地盤。剛開始進行驅除計劃時需要勤用這把水槍。水槍不會射死牠們,但會讓牠們受不了這些味道,之後避免闖入散佈這味道的區域。
另外,精油品質的好壞會影響效果。這2種精油價格相宜,可以買好一點的牌子。
4. 小強地雷
把檜木碎片泡在機關槍的精油配方,就完成比市上賣的樟腦丸更有效的小強地雷。把它安置在任何小強喜歡出沒,居住的地方,牠們很快就收到驅除令趕緊搬家。
5. 開燈
半夜到廚房開燈,免不了與小強相遇。讓牠們掉頭跑的主要原因,是因為牠們怕光線。剛開始進行驅除計劃時,不要關燈,小強們少了活動空間,便會另找遊樂場所。
Reference: 月黑風高怕蟲夜 天然方法趕小強
Drupal 7 – Check add or edit in node form alter
If we want to alter a node form of a specific content type using hook_form_alter(), we may want to know whether the form is for node creation or edit. In this case, we can add a checking as follow:
function <module>_form_<content-type>_node_form_alter(&$form, &$form_state, $form_id) {
$node = $form_state['node'];
if (isset($node ->nid)) {
// Node edit
} else {
// Node add
}
}
Done =)
陶傑 – 士人余英時
三十多年前,我住在外地,時時與一位民國老太太見面。
她名叫凌叔華,是「五四」那一代人,與冰心同期的小說家。凌叔華女士與胡適徐志摩很熟,她時時對我說起徐志摩的情事,因為徐志摩死前,交給她一隻私人信件的盒子。
凌女士在燈下,講她的舅父辜鴻銘怎樣教她英文,林語堂如何去南洋,她與英國小說家維珍尼亞胡爾芙的交往。有一天她說:「前幾年,有一位華人教授由美國來,他上門來看我,他叫余英時,他對我說起中國文化的淪亡,說着說着,在我面前,就痛哭起來了。」
余英時那時在查先生的「明報月刊」時時有論說,講中國儒家的精神。余教授是最後一代燕京人,民國三十八年,幸好來了香港,師從錢穆,在新亞讀書。余先生第一次與凌叔華見面,必有遇故知之感,說起中國,就痛哭失聲,除了凌叔華的氣質儼然有山河故國之親,亦必是性情中人。
Continue reading 陶傑 – 士人余英時
陶傑 – 收外國人的錢
梁特突然被爆出曾收受澳洲企業現金四百萬鎊,共五千萬元,一次收款,不必繳稅,而且無條件,不必提供服務。
親中愛國陣營,也就是所謂建制派,職責所在,一定要支持梁特,都要說收這筆錢,沒有問題。但是人性的嫉妒是天生的,五千萬元現金,幾多親中愛國人士在工會、在愛國教育單位,愛國愛港之一生一輩,都打拼不到一個零頭,你梁特從外國人手上一次肥爽,錢包滿溢,然後又轉戰另一條線,當特首了。對於擁有國際行政視野的人,這種交易在法律上沒有問題,但中國人天生有很強的紅眼症,可以論斷,越是愛國奉命挺梁的中國人,此時此刻,心中越不是味道。
尤其是「收外國的錢」,特別容易引起中國人的情意結。為什麼外國人給你錢而不給我?但是他們不會想到:外國人,即西方人,對專業的要求極高,錢不是亂砸的,外國人越能將錢花在你身上,證明你越出色,像九十年代,荷李活投資一億美金,讓我們香港大導吳宇森(John Woo),夥拍天皇巨星湯告魯斯,拍職業特工隊。所以當我聽到澳洲的企業在全球十三億華人之中,獨肯送梁特五千萬元,我認為梁先生必是非常卓越的人才。
如果想少一點激憤,多一點和諧,必須學會包容、平常心,學習壓抑「收外國的錢」此一情意結,而明白能贏得外國人的錢,由瑞典人給錢的諾貝爾得獎人莫言,到拿日本人錢的孫中山;由拿俄國人共產第三國際的錢的周恩來到拿澳洲人錢的梁特,必定是中華民族的精英。
Continue reading 陶傑 – 收外國人的錢
名言一百一十五
CSS – Number rating widget
I have a HTML form which has radio inputs range from 1 to 5:
<form> <input type="radio" name="num" value="1" checked>1 <input type="radio" name="num" value="2">2 <input type="radio" name="num" value="3">3 <input type="radio" name="num" value="4">4 <input type="radio" name="num" value="5">5 </form>
I want to convert it into a rating widget. I found a very good post with an example to convert radio inputs into a star rating widget.
Code by Stephen Morley – A star rating widget using CSS
But instead of rating by stars, i would like to create a number rating widget. So i modified the example a bit. First, create a image as follow.
icon_number_widget.png
![]()
Continue reading CSS – Number rating widget
Eureka! – 2014 Review
Spending most of my time working for Lane Crawford last year. A very good experience to train up myself especially in Continuous Integration and systems/application monitoring~ Thanks Ronnie for giving me a chance to work with him again and also meet a interesting team in LC.
Other than tech stuff like Puppet, Django and Dashing etc. I think the most important thing i learn is about the goal of adopting Continuous Integration. In that past, i always thought that CI is about automating tedious steps and reduce any prone to human error. But now i realize that other than these practical purposes, CI also helps to promote team work with your colleagues which, for me, is very important in a working environment. And that may be the reason why i love working on CI project so much as i am always looking forward to working in a harmonic and funny team.
All the best in 2015!
- 2014 Jan – 31,102
- 2014 Feb – 32,281
- 2014 Mar – 34,303
- 2014 Apr – 33,524
- 2014 May – 43,786
- 2014 Jun – 60,785
- 2014 Jul – 70,082
- 2014 Aug – 64,341
- 2014 Sep – 60,157
- 2014 Oct – 53,798
- 2014 Nov – 59,925
- 2014 Dec – 56,679
- 2014 Total – 600,763
jQuery – Determine which radio box is checked
Assume you have the following HTML form:
<form id="weather-form"> <input name="weather" type="radio" value="sunny">Sunny <input name="weather" type="radio" value="cloudy">Cloudy <input name="weather" type="radio" value="rainy">Rainy </form>
To get the checked value using jQuery:
var result = $("#weather-form input[name=weather]:checked").val();
// OR
var result = $("input[name=weather]:checked", "#weather-form").val();
Continue reading jQuery – Determine which radio box is checked

