2011年7月28日 星期四

Z Shell

安裝zsh
https://github.com/robbyrussell/oh-my-zsh

推薦使用
wget --no-check-certificate https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh

2011年7月27日 星期三

Ruby Tutorial

Ruby 安裝
http://pragmaticstudio.com/blog/2010/9/23/install-rails-ruby-mac

Ruby創始人寫的中譯本
http://guides.ruby.tw/ruby/index.html

Ruby In 20 Mins
http://www.ruby-lang.org/zh_TW/documentation/quickstart/

jQuery Drag And Drop Between 2 List

http://thechriswalker.net/select-drag/

SVN Editor Setting

SVN Editor未設定時,會出現下面訊息。

svn: Commit failed (details follow):
svn: Could not use external editor to fetch log message; consider setting the $SVN_EDITOR environment variable or using the --message (-m) or --file (-F) options
svn: None of the environment variables SVN_EDITOR, VISUAL or EDITOR is set, and no 'editor-cmd' run-time configuration option was found

解決方法:
在 Shell 的 Config 中設定編輯器。
  • zsh:編輯 ~/.zshrc
  • bash:編輯 ~/.bash_profile
加上 export SVN_EDITOR="/usr/bin/vim"

2011年7月20日 星期三

jQueryMobile & DateBox Cheat Sheet

此篇版本以Beta 1為準,一定愛配 API。

jQueryMobile Demo and API
http://jquerymobile.com/demos/1.0b1/

1.
mobileinit務必要在jQM讀進來之前去設定jQM的config。
<script type="text/javascript" src="/js/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
//設定jQueryMobile必須在Load之前設定
$(document).bind("mobileinit", function(){
    //設定為$.mobile.xxxx = "OOOOO"
   config設定參考
});
</script>
<script type="text/javascript" src="/js/jquery.mobile-1.0b1.min.js"></script>

2.
正式版不再用:在HTML依據Orientation加上Class的方法做。
建議改用Media Queries官方說法

3.
data-transition:指定連結的 transition 動畫。動畫種類
data-rel:指定關係為Dialog,會以對話框形式跳出來,並且有可關掉視窗的按鈕。
class="ui-btn-right":指定這顆按鈕在Header右邊。
相關init config:defaultPageTransition、defaultDialogTransition、loadingMessage、pageLoadErrorMessage。 
        <div data-role="header" data-position="inline" data-theme="f">
            <h1>我是Header喔!</h1>
            <a href="#login" class="ui-btn-right" data-rel="dialog" data-transition="pop">登入</a>
        </div>

4.
data-add-back-btn:jQM Beta開始預設不會有back按鈕了,要在data-role="page"上加上data-add-back-btn="true"
data-back-btn-text:back按鈕的文字
以上兩點都可以在 mobileinit 時統一設定。
相關init config:addBackBtn、backBtnText、backBtnTheme。
<div data-role="page" id="login" data-theme="g" data-add-back-btn="true" data-back-btn-text="取消">
......
</div>


5.
在Select上比照按鈕,都可以指定按鈕有的東西
可用optgroup做群組選單。
data-native-menu:true 使用手機內建樣式, false使用jQM樣式,都可玩玩看。
data-icon:選單圖片
data-theme:選單樣式
相關init config:ajaxEnabled。
<form action="#">
    <select name="count" id="count" data-native-menu="false" data-icon="search" data-theme="c">
        <optgroup label="上午">
            <option value="8">上午八點</option>
            <option value="9" disabled="disabled">上午九點</option>
        </optgroup>
        <optgroup label="下午">

            <option value="14">下午兩點</option>
            <option value="15">下午三點</option>
        </optgroup>

    </select>
</form>

6.
data-fliter:可替選單加上搜尋介面。
data-filter-placeholder:搜尋框的PlaceHolder
data-filter-theme:就theme嘛
<ul data-role="listview" data-filter="true" data-filter-placeholder="Search User..." data-filter-theme="c">
   ......
</li>


同場加映DateBox
----------------------------------
jQueryMobile DateBox Demo and API
http://dev.jtsage.com/jQM-DateBox/

1.
<script type="text/javascript" src="/js/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
//設定jQueryMobile必須在Load之前設定
$(document).bind("mobileinit", function(){
    //DateBox官方強烈建議將date降級成使用text
   $.mobile.page.prototype.options.degradeInputs.date = 'text';
});
</script>
<script type="text/javascript" src="/js/jquery.mobile-1.0b1.min.js"></script>
<script type="text/javascript" src="/js/jquery.mobile.datebox.min.js"></script>
<script type="text/javascript">
//要調整DateBox的東西要在datebox.js讀進來以後。
jQuery.extend(jQuery.mobile.datebox.prototype.options, {
    'dateFormat': 'dd日mm月YYYY年',
    'headerFormat': 'dd.mm.YYYY'
});
</script>

2.
date-option說明不詳列,類似jQueryUI DatePicker。
mode:picker種類
dateFormat:input中的格式
noButtonFocusMode:不要設為true,開啟一次以後會關不掉,預設是flase。
fieldsOrder:要有哪些可選
theme:input的樣式
pickPageInputTheme:picker中的數字區塊樣式
pickPageTheme:picker的背景及確定按鈕

2011年7月15日 星期五

Google App Engine Installation

GAE SDK Version: 1.5.1,最低需求為Python 2.5

Python目前Production版本是2.7和3.2
Windows XP就需要裝2.7才會動,如果裝3.2會沒辦法執行。
會出現錯誤訊息:
NameError: global name 'execfile' is not defined
必須裝2.x才能執行,因此就以最新版的2.7裝了即可執行。

但是在Mac OS X 10.5 Leopard 已經安裝了 Python 2.5。
所以不用另外安裝。

在Windows裝好Python和GAE SDK以後,可能會跟你說找不到Python
這時就把GAE Luncher打開,按Edit -> Preference指定Python路徑到
C:\Python27\pythonx.exe
重開GAE Luncher即可。

jQueryMobile Gallery

主要請看:
http://www.jqmgallery.com/

其中較優秀範例:
Sea-Doo:http://m.sea-doo.com/
介面不錯,清爽簡潔

Stanford:http://m.stanford.edu/
史丹佛大學,經常更新,介面普通。

優眾:http://m.ihaveu.com
請用手機看,不然會被導到desktop。
介面較炫,但看起來不是全部都是jqm。

American Century:https://www.americancentury.com/mobile/
介面普普,金融相關,投資類型

Boorbool:http://m.boorbool.com
有接一些event,但看起來已經不像是jqm了。

山寨版AngryBird:http://www.atlassian.com/en/angrynerds/nerds.html

MyShoppingList:http://www.myshoppinglist.mobi/
介面不錯,很可愛

Take Me Fishing:http://www.takemefishing.org/mobile/
介面很可愛

Trekaroo:http://www.trekaroo.com/mobile/nearby
介面還ok

jQueryMobile Beta1

jQueryMobile Beta1 出來了
根據官方說法:7月會出beta 2,8月會正式版。可喜可賀!

http://jquerymobile.com/blog/2011/06/20/jquery-mobile-beta-1-released/#upgrade
用了Media Query 所以 iPad 和 iPhone看會不同。

不過在切換ViewPort為LandScape時,在iPhone上會有些問題,會超過一的畫面可以顯示的大小,要自己縮小。可能跟他為了讓使用者可以縮放,修改Meta的寫法有關。
http://jquerymobile.com/blog/2011/06/20/jquery-mobile-beta-1-released/#viewport
但是目前在Android HTC Desire上測試則沒有問題。

主要改變如下:
  1. 支援黑莓機和Opera Mini。
  2. 在 iOS 和 Android 中會自動隱藏URL Bar了,不過我測試過後:
    iOS: iPhone可以,但是底下的Bar還是在、iPad不會(也許螢幕夠大)
    Android:Desire可以,但是按 Desire 的 back 鈕有時候還是會跑出來。

    作法如下:iOS捲0px、Android捲1px
    http://stackoverflow.com/questions/6011223/how-to-completely-hide-the-navigation-bar-in-iphone-html-5
  3. 將頁面切換的部份切開,可以自己做頁面切換的特效了。
  4. 左上角的Back按鈕預設是沒有的,因為多數手機和瀏覽器都能控制上一頁。
    要打開有兩種方法:
    -在data-role="page"的div上加上data-add-back-btn="true"
    -mobileinit時,設定config為$.mobile.page.prototype.options.addBackBtn = true;
  5. 在 Form 裡面,會讓 Label 在 Landscape 和 Portrait 時的呈現不同。
    但是Window Phone7的Form元件,label 不像其他系統會 float 到左邊。(又是IE...)

    正式版將不再使用現在的方式,請改用CSS3 Media Queries。
  6. 沒有 ajaxFormsEnabled 和 ajaxLinksEnabled 改為 ajaxEnabled

2011年7月13日 星期三

用Solr產生頁面 - XSL vs. VTL

當我們今天從Solr拿到一堆 doc,要產生頁面時有幾種作法:
  • 用PHP或是Java去呈現-也就是目前的作法。
優點:
    • 大家已經熟悉。
    • 有許多Lib可以使用。
缺點:
    • 很大一包,除了Solr還必須有Framework。

不過就像標題,今天的重點在VTL和XSL
所以當今天我們不想要這麼大一包時,就有下面兩種可能作法。

  • 用XSL (EXtensible Stylesheet Language)
概念上就是指定哪種XML的Pattern去用某種Template。
可以將一份XML文件,套上XSL,呈現成你想要的樣子,通常是HTML。
由於Solr產生的格式預設就是XML,所以只要套上去就可以。
優點:
    • 上手難度較低。
    • 現有主流瀏覽器都支援,IE6以上 (最新到9)、FireFox3(最新到5)、Chrome、Opera9(最新到11)、Safari 3(最新到5)
    • 只要有瀏覽器就可以測試,只要將XML內指定他的XSL。
      <?xml version="1.0" encoding="UTF-8"?>
      <?xml-stylesheet type="text/xsl" href="YOUR.xsl"?>
    • 不用了解Solr內的設定。
缺點:
    • 需要自己組Query。
    • 擁有的函式較少。
    • 指定哪個區塊要用哪個模版較不直覺,需用到正規表示法。
    • 做複雜的邏輯處理時,不能自己寫Fucntion來重複呼叫,會寫的很辛苦、又醜又長。
    • 不能使用Map(Dictionary)、Array型態的變數。
    • Debug不易
  • 用VTL (Velocity Template Language)
概念上就是類似MVC的Framework架構中View的部分。
會有個Layout,然後會有要顯示的資料給你,裡面可以決定哪個地方要放哪個View Block。
只是每個View又同時是一個容器,裡面又可以再去指定裡面哪些地方要放哪個View Block。

有人說很類似php的 Smarty,但是沒用過,無從比較。

優點:
    • 概念上類似Zend,使用起來較為直覺。
    • 寫法簡潔,熟悉後開發速度較快。
    • 可以自己寫函式來重複呼叫以及可使用Map、Array型態的變數,做複雜邏輯判斷較為方便。
    • Solr的Velocity內已經寫好的一些組Query用的函式,可以直接拿來用。
    • 似乎可以引用一些外部的函式?
缺點:
    • 上手難度較高,有很多VTL規則需要熟悉。
    • 需要了解Solr內的設定,而且頁面都會放在solr/conf/velocity/下,目前被寫死在Solr內 Orz...
    • 需要有Solr才方便測試。
    • Debug不易

Solr Developer's Blog

http://my.opera.com/jinglepot/blog/

2011年7月7日 星期四

Solr Working With Multi Core

以Solr的example內為例。


啟動multi core:
  • 在example下:java -Dsolr.solr.home=multicore -jar start.jar
    倒資料到multi core:
    • 在example/exampledocs下,到資料到core1:java -Durl=http://localhost:8983/solr/core1/update -jar post.jar
    相關設定:solr.xml
    <solr persistent="false">
      <cores adminPath="/admin/cores" defaultCoreName="core0">
        <core name="core0" instanceDir="core0" />
        <core name="core1" instanceDir="core1" />
      </cores>
    </solr>
    • defaultCoreName:有設在defaultCoreName的,沒指定coreName都會指向他。
    • 管理設定:http://localhost:8983/solr/admin/cores
      可以進行Create、Reload、Rename...等等動作
      在v3.2 Alias似乎並不支援!?v3.3尚未測試
     參考:http://wiki.apache.org/solr/CoreAdmin



      2011年7月6日 星期三

      Solr - Ignore HTML When Search

      以中文情況,schema.xml如下,由cjk的type改,英文請由text改:
          <fieldType name="html" class="solr.TextField" autoGeneratePhraseQueries="true">
            <analyzer type="index">
              <charFilter class="solr.HTMLStripCharFilterFactory"/>
              <tokenizer class="solr.CJKTokenizerFactory"/>
              <filter class="solr.StopFilterFactory"
                      ignoreCase="true"
                      words="stopwords.txt"
                      enablePositionIncrements="true"
                      />
              <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="1" catenateNumbers="1" catenateAll="0" splitOnCaseChange="1"/>
              <filter class="solr.LowerCaseFilterFactory"/>
              <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
              <filter class="solr.PorterStemFilterFactory"/>
            </analyzer>
            <analyzer type="query">
              <tokenizer class="solr.CJKTokenizerFactory"/>
              <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
              <filter class="solr.StopFilterFactory"
                      ignoreCase="true"
                      words="stopwords.txt"
                      enablePositionIncrements="true"
                      />
              <filter class="solr.WordDelimiterFilterFactory" generateWordParts="1" generateNumberParts="1" catenateWords="0" catenateNumbers="0" catenateAll="0" splitOnCaseChange="1"/>
              <filter class="solr.LowerCaseFilterFactory"/>
              <filter class="solr.KeywordMarkerFilterFactory" protected="protwords.txt"/>
              <filter class="solr.PorterStemFilterFactory"/>
            </analyzer>
          </fieldType>

      如果把欄位裡面放成像是json格式則無效。如要放多個內容,需將欄位內容用一些方式隔開。
      這樣做的好處是搜尋的時候,不會搜尋到html註解內的東西和html tag內上的東西,tag的內容是可以被搜尋到的,且拉出來的資料一樣是原本完整的html。
      Solr官方參考網頁

      Solr Use UUID

      1. schema.xml修改:
        • <fieldtype class="solr.UUIDField" indexed="true" name="uuid"></fieldtype>
        • <field name="id" type="uuid" indexed="true" stored="true" default="NEW"/>
      2. solrconfig.xml修改:
        註解掉
        <searchComponent name="elevator" class="solr.QueryElevationComponent" >
            <str name="queryFieldType">string</str>
            <str name="config-file">elevate.xml</str>
          </searchComponent>
        <requestHandler name="/elevate" class="solr.SearchHandler" startup="lazy">
            <lst name="defaults">
              <str name="echoParams">explicit</str>
            </lst>
            <arr name="last-components">
              <str>elevator</str>
            </arr>
        </requestHandler>
      可參考:http://blog.xuite.net/misgarlic/weblogic/44589022