2011年10月6日 星期四

[Java] Deploy Web Service with Tomcat

Step-by-step:
  1. In Eclipse, right click your web service project > Export > WAR file to obtain the WAR file.
  2. Move the war file to your $CATALINA_HOME/webapps directory. Tomcat will automatically expand and deploy the application for you.
Enjoy!

2011年10月5日 星期三

Apple - En memoria de Steve Jobs

Apple ha perdido a un visionario y a un genio creativo. El mundo ha perdido a un ser humano excepcional. Y aquellos que hemos tenido la fortuna de conocer y trabajar con Steve hemos perdido a un amigo querido y a un maravilloso mentor. Steve deja atrás una compañía que solo él podía haber construido. Su espíritu siempre será el espíritu de Apple.

2011年10月4日 星期二

個人讀書心得 (大債時代、經濟殺手的告白3)

2008年10月6日冰島克朗破產。貨幣價值反映國家的競爭力,也反映國家的信用。此外,國家有可能倒閉,千萬不要太相信政府,政府毫無羞恥心。我寧可拿美金,也不想拿新台幣,台灣政府太不可靠了。

就拿台北房地產當例子,Global Property Guide 認為 We believe apartments in Taipei are overvalued - and will fall in price. But we should warn readers that we can get it wrong! 就算房價不高,房屋政策仍無正義可言。我認為房屋政策應包括
  1. 市價登記房屋,以交易時的市價做為稅基
  2. 房屋交易所得,必須認列所得稅
這樣才有正義可言。可惜政府跟垃圾一樣,只照顧既得利益者的利益,窮人能呼吸就該偷笑了 (笑)。為了對抗邪惡的房地產,我們該怎麼辦?
  1. 知識
  2. 知識
  3. 知識
知識就是力量。以下是我認為重要的知識:
  1. 黑心建商的知識
  2. 黑心投資客的知識
  3. 正確評價房地產的知識
關於前面兩點,Sway 已有專書論述,我也是看 Sway 書長大的。當然,實際看屋更能快速累積經驗。請大家拼命約房仲看房子吧!房價太貴大家買不起,如果房價太便宜,大家能買到適合自己的房子嗎?這可不一定。

最後一點十分的玄,我的準則是:房屋價值約等於250個月租金。例如月租18000元,房價應落在450萬附近。超過450萬表示賣家可以賣出。相反地,低於450萬表示買家可以買進。

因此,我的買房策略就是不買房子,沒人逼你買房。一旦被逼買房,那就祈求上天讓房價繼續飆吧。為台北房地產禱告吧!(嚴重偏離大債時代主題)
當然,我得對抗台灣傳統壓力 - 成家立業。多少人為了成家,賭光父母親的老本,只為了買一間小小的喔。個人認為這樣不妥,目前買不如租,租金那麼便宜,不租對不起自己。

我該鼓起勇氣打破陳規,質疑親人始終視為顛撲不破的觀念,即使既有體制將要自我毀滅亦然!



接著,作者說:東方所展現的是壓抑。沒錯,就是壓抑,這點在台灣勞動市場十分明顯。垃圾政府永遠不曉得基層勞工壓抑掙扎的生活。我因為運氣好,稍微聰明一點,有份還可以的工作。至於運氣不好的,便淪落到大賣場當工讀生,餓不死,但也沒有希望可言。

在大賣場推著大推車瘋狂購物,我的快樂,原來建立在工讀生的血汗之中。逛百貨公司我也很感慨,周休二日還是有人在上班!全年不打烊的便利超商,又犧牲多少人的睡眠時間!我很感恩基層勞工無私的奉獻,但也心疼基層勞工沒有希望的未來。個人十分擔心台灣就業環境:
  1. 勞方工時過長
  2. 資方藐視勞基法
  3. 勞方加班,資方賴皮不給加班費
當然,垃圾政府只會裝死,繼續河蟹勞方的不滿。嚴重偏離大債時代主題,我是不得已的。雖然個人公司十分守法,對員工非常好,但大部分公司是無良的,我要為無良公司的員工發聲,別人愁眉苦臉,我也會愁眉苦臉。

2011年10月3日 星期一

[Java] Apache Axis

Preparation
  1. Tomcat
    An open source servlet container. Tomcat implements the Java Servlet and the JavaServer Pages (JSP) specifications, and provides a pure Java HTTP web server environment for Java code to run.

    In Windows,
    • Start Up Tomcat: By executing the following command: $CATALINA_HOME\bin\startup.bat. After startup, the default web applications included with Tomcat will be available by visiting: http://localhost:8888/. (We can change port 8080 to 8888 by editing $CATALINA_HOME\conf\server.xml. Port 8080 is reserved for Windows IIS.)

    • Shut Down Tomcat: By executing the following command: $CATALINA_HOME\bin\shutdown.
    However, we don't need to startup Tomcat during developing web service.
  2. soapUI
    soapUI is a free and open source cross-platform Functional Testing solution.

Creating a Web Service
  1. Setup Eclipse: Window > Preferences > Server > Runtime Environments > Add... > Apache Tomcat v7.0 > Next > Select correct Tomcat installation directory > Finish.
  2. New Project: File > New > Other... > Web > Dynamic Web Project > Target runtime: Apache Tomcat v7.0.
  3. New Java class:
    package demo;
    
    public class HelloWorld {
        public String greeting(String name) {
            return "Hello World! " + name + "!";
        }
    }
    
  4. Setup runtime environment: Right click on Servers tag below > New > Server. Select Tomcat v7.0 Server again.
  5. Create Web Service: Right click on HelloWorld.java in Project Explorer > Web Services > Create Web Service > Web service type: Bottom up Java bean Web Service. Service implementation: demo.HelloWorld. Click check box: Publish the Web service. > Finish.
Everything is OK now. We can take a look at WebContent > wsdl > HelloWorld.wsdl:
or
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://demo" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://demo" xmlns:intf="http://demo" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!--WSDL created by Apache Axis version: 1.4
Built on Apr 22, 2006 (06:55:48 PDT)-->
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="http://demo" xmlns="http://www.w3.org/2001/XMLSchema">
   <element name="greeting">
    <complexType>
     <sequence>
      <element name="in0" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
   <element name="greetingResponse">
    <complexType>
     <sequence>
      <element name="greetingReturn" type="xsd:string"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>
   <wsdl:message name="greetingRequest">
      <wsdl:part element="impl:greeting" name="parameters">
      </wsdl:part>
   </wsdl:message>
   <wsdl:message name="greetingResponse">
      <wsdl:part element="impl:greetingResponse" name="parameters">
      </wsdl:part>
   </wsdl:message>
   <wsdl:portType name="HelloWorld">
      <wsdl:operation name="greeting">
         <wsdl:input message="impl:greetingRequest" name="greetingRequest">
       </wsdl:input>
         <wsdl:output message="impl:greetingResponse" name="greetingResponse">
       </wsdl:output>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="HelloWorldSoapBinding" type="impl:HelloWorld">
      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="greeting">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="greetingRequest">
            <wsdlsoap:body use="literal"/>
         </wsdl:input>
         <wsdl:output name="greetingResponse">
            <wsdlsoap:body use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="HelloWorldService">
      <wsdl:port binding="impl:HelloWorldSoapBinding" name="HelloWorld">
         <wsdlsoap:address location="http://localhost:8888/WebServiceDemo/services/HelloWorld"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

After linking to http://localhost:8888/WebServiceDemo/services/HelloWorld, we see:
<h1>HelloWorld</h1>
<p>Hi there, this is an AXIS service!</p>
<i>Perhaps there will be a form for invoking the service here...</i>


Testing a Web Service

We use soapUI 4.0.1 to test our web service. soapUI comes with extensive support for testing WSDL / SOAP based services (Tutorial).
  1. New Project: File > New soapUI Project > Initial WSDL/WADL: http://localhost:8888/WebServiceDemo/services/HelloWorld?wsdl
  2. Double click greeting in Navigator (left window). In XML tag in SOAP Request 1 (right window), we prepare the following request:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:demo="http://demo">
       <soapenv:Header/>
       <soapenv:Body>
          <demo:greeting>
             <demo:in0>Plover</demo:in0>
          </demo:greeting>
       </soapenv:Body>
    </soapenv:Envelope>
    
  3. Click Submit request to specified endpoint URL button. We will receive the following result:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
       <soapenv:Body>
          <greetingResponse xmlns="http://demo">
             <greetingReturn>Hello World! Plover!</greetingReturn>
          </greetingResponse>
       </soapenv:Body>
    </soapenv:Envelope>
    

Screenshot:
Enjoy!

東模故山路線研究

祺盛教官:
從福山循哈盆古道至避難小屋,過溪後,即從正前方西南東北稜線上至1144峰(東模故山),第二天,從1144峰循963峰這條稜線至吊橋遺址回福山,去回均要過溪兩次,一上稜線就要背水。

地圖產生器:

行程規劃:
  • D1 哈盆越嶺古道入口 → 過波露溪 → 過露門溪 → 東模故山傳統登山口,不取 → 哈盆營地 → 避難小屋 → 探勘東北稜線上至東模故山 (2km) → 東模故山 (H1144M)
  • D2 東模故山 (H1144M) → 963峰 → 東模故山傳統登山口 → 過南勢溪 → 過露門溪 → 過波露溪 → 哈盆越嶺古道入口

撤退路線:
  • 東模故山傳統登山口 → 福山植物園山路 → 福山植物園
  • 哈盆營地、避難小屋 → 福山植物園水路 → 福山植物園

參考資料:
[1] http://www.keepon.com.tw/ActiveSite/Article/One.asp?ArticleID=28137 - 參考D1路線圖
[2] http://www.yougoipay.com/kenny/index568.html - 參考福山植物園撤退路線

實分析的集合論「個人心得」

近代數字最重要的工具之一就是集合論 (set theory)。末學曾念過 Charles C. Pinter, Set Theory,曾為書裡細節著迷,甚至花許多心思研究 1+1=2 怎麼證明,基於幾個簡單假設 (Axiom of Infinity: There exist a successor set),1+1=2 的確可以證明,但這不是「末學要的」集合論。

任何知識都一樣,有需求才有動力學習。我們到底要什麼?

末學要的集合論是可用在實分析 (real analysis) 的集合論。究竟集合論哪些內容對實分析有用處?根據 H. L. Royden, Real Analysis, 3ed 的建議,集合論至少包括:
  • 證明論述能力 (這也算集合論?末學認為如此)
  • The well-ordering principle
  • Mathematical induction
  • (Generalized) Principle of recursive definition
  • Axiom of choice
以上是末學認為重要的內容,大家若不同意末學所言,歡迎提出自己的版本。



證明論述能力

何謂「證明論述能力」?狹義的說,就是完成 Real Analysis 教科書習題的能力。舉兩個例子來說:

1. (Royden, Real Analysis, Problems 1.1.4) Show that the well-ordering principle implies the principle of mathematical induction. [Consider the set { n is a natural number : P(n) is false }.]

證明之前,我們得先克服英文障礙,我們寧可卡在數學,而不是英文。英文是說:請證明 the well-ordering principle => mathematical induction.

了解英文語意之後,接著是計算習題。末學認為證明跟計算分不開。那麼我們開始來計算:
Consider the set S = { n is a natural number : P(n) is false }, where P(n) is a proposition defined for each natural number n.
卡住,趕緊來google一下。這個提示一點也不自然,我們可以回到原點重新思考。回想 mathematical induction:{ P(1) & P(n) => P(n+1) } => (n)P(n),內容包括兩句敘述:
  • A: { P(1) & P(n) => P(n+1) }
  • B: (n)P(n)
我們可以思考 proof by contradiction (reductio ad absurdum): 利用 A and (not B) 來導出矛盾。(not B) 翻成白話就是 there is a n which P(n) is false,若能計算到此,提示看來十分自然。繼續計算:
If S is not empty, by the well-ordering principle there is a least element m in S. m cannot be 1 since P(1) is true. Also, m-1 is in S too since P(m-1) => P(m), which is absurd since m is not a least element.
整個計算就是這麼一回事。

2. (Royden, Real Analysis, Problems 1.1.5) Use mathematical induction to establish the well-ordering principle. [Given a set S of positive integers, let P(n) be the proposition 'If n is in S, then S has a least element'.]

英文是說:請證明 mathematical induction => the well-ordering principle. 一樣,提示也不太自然,但提示的確很有用。若 (n)P(n),則 well-ordering principle 自動成立,因為 every nonempty subset of N contains a natural number.
Given a nonempty set S of positive integers, let P(n) be the proposition 'If n is in S, then S has a least element'. P(1) is true since 1 is the least element in N. Assume that P(1), P(2), ..., and P(n) are all true. Suppose n+1 is in S. If n+1 is a least element of S, we are done. If not, there is an element m < n+1 in S. m is between 1 and n. By mathematical assumption, S has a least element. So P(1), P(2), ..., and P(n) => P(n+1). By mathematical induction, (n)P(n), or the well-ordering principle. 
這裡用變形的 mathematical induction,與原形式等價,這點末學念高中的時候有證。



寫了那麼多的計算,看起來很厲害。事實上,數學的直覺應該將 the well-ordering principle 與 mathematical induction 視為理所當然!只要證明 trivial 寫夠多,你就出師了。



Mathematical Induction

標準形式是:{ P(1) & P(n) => P(n+1) } => (n)P(n)。使用時機:不明,必須試了才知道能不能用,末學通常會這麼操作:
  1. 計算簡單情況:P(1), P(2), P(3)...
  2. 找出 P(n) 與 P(n+1) 關係
  3. 利用 mathematical induction 美化證明
美化證明也是一門學問。

2011年10月2日 星期日

徐仁修,季風穿林,摘錄

只是一道山嶺的差別,這一邊的人視叢林之王為惡煞,而那一邊的人卻是牠為守護神。正如我們所面對的落日,此時卻被地球那邊的人稱之為旭日,可是,太陽依舊是太陽,既不升起,亦不沈淪。

你要回國了,讓我說一句真心話:你妨礙了我們對斯郭特爾的辦案,雖不為我們所喜歡,但我們私下很尊敬你,雖然你也是華人,卻沒有站在你那華人大公司的一邊……,我們是……不得已的……,他媽的,不得已……。

很多事是不得已的……,他媽的,不得已……