Apache Ant – Extract a string from property using regular expression

The Ant-Contrib library is a must have tool if you need to have more control on your build flow. Here is another example on using the propertyRegex task provided by Ant-Contrib to select or replace a string from an input.

build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="Ant Property Regex" default="version" basedir=".">
  <taskdef resource="net/sf/antcontrib/antcontrib.properties">
    <classpath>
      <pathelement location="${basedir}/lib/ant-contrib.jar"/>
    </classpath>
  </taskdef>

  <target name="version">
    <propertyregex
      property="select.example"
      input="package.ABC.name"
      regexp="package\.([^\.]*)\.name"
      select="\0"
      casesensitive="false" />

    <echo message="${select.example}"/>

    <propertyregex
      property="replace.example"
      input="package.ABC.name"
      regexp="(package)\.[^\.]*\.(name)"
      replace="\1.DEF.\2"
      casesensitive="false" />

    <echo message="${replace.example}"/>      
  </target>
</project>

Continue reading Apache Ant – Extract a string from property using regular expression

Apache Ant – Run piped command in exec task

The Ant <exec> task allows us to run shell command in Ant script. We could provide input arguments like the following example which prints today’s weekday.
build.xml

<?xml version="1.0" encoding="UTF-8"?>
<project name="Ant Piped Commands" default="today" basedir=".">
  <target name="today">
    <exec executable="date" outputproperty="weekday">
      <arg value="+%A" />
    </exec>
    <echo message="Today is : ${weekday}"/>
  </target>
</project>

ant-exec-piped-commands-1
Continue reading Apache Ant – Run piped command in exec task

陶傑 – 終究無欠

外交部檔案解密,顯示英國首相戴卓爾夫人當年簽署了中英聯合聲明,批示如果中國違約,英國會以「最強烈的態度提出交涉抗議」。

交涉和抗議,在強權的世界,只是徒勞。北韓多次襲擊南韓,爆炸客機、暗殺官員,還綁架日本人,美國譴責過,日韓也抗議交涉過,北韓的國家行為並無改變。

條約協議,信用為先,但信用、榮譽,是西方文明的價值觀,極權殊不適用。中國主辦北京奥運之前,也答應過開放新聞資訊。蘇聯和納粹德國,蘇聯和日本,也簽過「互不侵犯協定」,也都翻臉撕毀了協定。

戴卓爾夫人是世界大戰的過來人,曾經納粹興亡,自然也很了解共產黨,她不是不知道。唯英國管治香港一百五十年,以香港向中國示範了什麼叫做法治和理性的文明,英國對得起中國有餘。西方與遠東非親非故,英國殖民主義並無義務永遠做慣於自相殘殺的中國人的教師與示範單位。合法的土地租約期滿,不論中國想不想續約,英國都應該撤退。
Continue reading 陶傑 – 終究無欠

陶傑 – 擊鼓傳機

ATV危機,香港特區關注。中國老闆斷了水,兩個月不發薪酬,國際台的白種人,雖然在中國人社會謀生,老闆三推四卸,終於肯發半個月薪酬,白人不太習慣當奴隸,都紛紛拍桌子走人。

但本地員工不想「對抗」,確實也對的:由中國人的邏輯看來,二○一七「普選」,不管真假,總之人人有得投票,故不妨「袋住先」。由「零薪水」到「半個月薪水」,是邁出了一大步,也應該「袋住先」,以後再尋求「理性溝通」,循序漸進,尋求對薪酬狀況,努力進行「優化」也不遲。

畢竟,甚麼勞工處法例呀、法定按時支薪呀,都是英國殖民地時代留下來的「文化」。中國國情,拖欠薪酬,也是兩千年「文化」,不然,當年毛主席也不會領導中國工農起來幹革命啦,為甚麼幹革命呀?因為據說萬惡的地主,殘酷剝削我們中國小農,剋扣工糧,不給他們飯吃呀。今日大陸,也時時有工廠老闆拖欠工資、工廠關門、跑路了事的,不然就不會有那麼多人「上訪」了。國情是這樣,文化要包容,慢慢就會慣的。
Continue reading 陶傑 – 擊鼓傳機

陶傑 – 美國大大

美國電影「刺殺小金」,新力公司說從來沒有畏縮過,只是許多戲院聖誕節不想公映,構成「自我審查」風波。

經總統一提點,全國二百多間戲院公映了。反宣傳之下,反而更旺場。

美國人是無畏的。因為總統羅斯福講過:「唯一要恐懼的,是恐懼本身。」美國的「四大自由」,其中之一,是「免於恐懼的自由」

恐懼而自我審查,是天生怯懦的行為。一個民族之所以一無建樹,在世界上交出一張連連失敗的成績表,是因為面臨恐嚇,而集體畏縮。美國是捍衛這個星球的大大。萬一有外星人來襲,或者有隕石向地球飛過來,人類慌成一團的時候,中國副總理汪洋講得很好:中國無法挑戰美國的超強地位,人類瀕危時不會向俄國強人總統普京求救,只會向美國仰望。

當然,美國也不是上帝,但美國有強大的科技,配上良好的信仰──信仰必須良好:人權、自由、慈悲,而不是仇恨──令全球投奔移民美國的科技和創意精英及第三世界的貪官不斷得到提醒:他們尋求托庇於美國,是正確的選擇。
Continue reading 陶傑 – 美國大大

陶傑 – 等待中國CNN

ATV不發放薪金,瀕臨關門。一家愛國電視台,慘遭外國勢力,暫時接管,英國的德勤會計師事務所,高調進駐,文件人事、帳本管理,為免有中國人亂動手腳,通通由英國人監督。

找中國人買家,十分困難。愛國愛港的商人滿街跑,但國也愛了,港也愛了,白花花的鈔票往無底洞裏扔,凡商人都要對「愛國愛港」的定義,擺脫人大的解釋,要由自己根據量度荷包之後的感受,而進行微調了。

ATV如果關門,是中國和香港的損失。其中國老闆當初說:二十年後,會將ATV「打造」成中國的CNN。就像董伯、CY,要將香港照他們遠大的藍圖打造成功,也至少要兩任。打造成中國的CNN要時間,現在中台股東自己內哄,干擾了此一中國夢,實令人唏噓。

ATV的國際台,白人員工,對中國沒感情,設一個期限,錢不到,就團結起來罷工。

但是本港台的香港華人員工,個個怕「搞事」,覺得還是忍耐再忍耐,「留守」下去好,其任勞任怨的忠誠,真是感動香港。
Continue reading 陶傑 – 等待中國CNN

Puppet – Using virtual resources to prevent duplicated resource declaration

When your Puppet setup is getting larger, you must come across the duplicated resource declaration error.

We are not allowed to declare the same resource more than one time!

So Puppet introduces the virtual resource to solve this problem. A virtual resource will not be sent to the Puppet client until it is realized. Now, we could specify a virtual resource and mark it non-virtual as many times as you want in a configuration.

For example: I have a my_packages class which contains all the some package resources. It only contains virtual resources so any other class include this would do nothing.
Continue reading Puppet – Using virtual resources to prevent duplicated resource declaration

Javascript – Add query parameter to current URL without reload

The following example adds a query parameter to the URL without refreshing the page but only works on modern HTML5 browsers.

index.html

<!DOCTYPE html>
<html>
<head>
  <title>Add query parameter to the url without reload</title>
</head>
<body>
  <button onclick="updateURL();">Update</button>
  <script type="text/javascript">
    function updateURL() {
      if (history.pushState) {
          var newurl = window.location.protocol + "//" + window.location.host + window.location.pathname + '?para=hello';
          window.history.pushState({path:newurl},'',newurl);
      }
    }
  </script>
</body>
</html>

 

Reference: StackOverflow – How do we update URL or query strings using javascript/jQuery without reloading the page?

Dream BIG and go for it =)