2013年1月2日 星期三

Rubular

在Ruby很常會使用到 Regular

這個網站可以針對你的需要處理的字串,透過你所寫的RegExp馬上顯示出來所截取的資料


Ruby Regular Expressions


我們從這個例子
# 抓出手機號碼 
phone = "123-456-7890"
if phone =~ /(\d{3})-(\d{3})-(\d{4})/
  ext  = $1
  city = $2
  num  = $3
end

可以抓出分別是123, 456, 7890

但在新的一版1.9可以在正規表示內加入參數
# 抓出手機號碼 
match_phone =  /(?<ext>\d{3})-(?<city>\d{3})-(?<num>\d{4})/.match(phone)
puts match_phone[:ext]
puts match_phone[:city]
puts match_phone[:num]

參考資料
ihower
http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/

2012年12月29日 星期六

screen

我們在遠端ssh的時候,都會怕突然的斷線

screen 這個就可以解決我們的問題

cd /usr/ports/sysutils/screen; make install clean

詳細的操作說明,這邊都不說明都可以從以下參考
Linux or FreeBSD screen 指令介紹使用
[FreeBSD]screen安裝

2012年10月8日 星期一

Android Layout background 設定

在layout要讓物件(Button 等等...)沒有預設的框線

可以在

xml
-----------
android:buckground="@null"



style.xml
-----------
<item name="android:background">@null</item>






http://www.mkyong.com/android/android-imagebutton-selector-example/

2012年9月25日 星期二

Android 用post傳送資料


String ServerAddress = "http://192.168.0.1";
String DataA = "1";
String DataB = "2";
String result = "";
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("AA",DataA ));
params.add(new BasicNameValuePair("BB",DataB ));


HttpPost httpRequest = new HttpPost(ServerAddress);
try {
    httpRequest.setEntity(new UrlEncodedFormEntity(getParams(),HTTP.UTF_8));
    HttpResponse mHttpResponse = new DefaultHttpClient().execute(httpRequest);
    
    if(mHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
        result = EntityUtils.toString(mHttpResponse.getEntity());    
    }
    
} catch (ClientProtocolException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}


宣告一個 List<NameValuePair> 這裡面是等一下要放入要傳的值及傳的名稱
List<NameValuePair> params = new ArrayList<NameValuePair>();

接下來設定傳入名稱及資料,在這裡是傳AA的名稱,DataA是我們的資料

params.add(new BasicNameValuePair("AA",DataA ));


有幾個就以此類推


接著下面是回傳的結果

if(mHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK){
     result = EntityUtils.toString(mHttpResponse.getEntity());    
}



可以參考下面檔案

https://www.dropbox.com/s/uxzhtg3roeqwycm/ServerRequest.7z






Java - MD5


public static String md5Encode(String str) {
    StringBuffer buf = new StringBuffer();
    try {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(str.getBytes());
        byte bytes[] = md5.digest();
        for(int i = 0; i < bytes.length; i++) {
            String s = Integer.toHexString(bytes[i] & 0xff);
            if(s.length()==1) {
                buf.append("0");
            }
            buf.append(s);
        }

    } catch(Exception ex) {
        
    }
    return buf.toString();
}





2012年6月29日 星期五

Android 重製ListView

在Google 搜尋這類的資料,其實還蠻多的,大致上都說明的很清楚

其中因為資料過多,當超過6~7筆(依螢幕大小,不同)

在滑動會有資料跳動要注意




在這邊,我是因為部份資料要使用刪除線,但滑動後卻都是刪除線

經過學長的指教,才知道資料一開始會全部已經轉成刪除線,當遇到不用改變時

已經變成刪除線TextView時,當然看到全都是刪除線!!!

所以這時要在另加入恢復成原本,才可以。