2014年5月26日 星期一

[JAVA]判斷網址是否可用 使用HttpURLConnection

直接看程式碼:
package com.test;

import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;

public class SampleforTestURL {

  public static void main(String s[]) {
   System.out.println(exists("http://www.google.com.tw"));
   System.out.println(exists("http://www.yahoo.com.tw"));
   System.out.println(exists("http://www.yam.com.tw"));
  }

  static boolean exists(String URLName) {
   try {
    HttpURLConnection.setFollowRedirects(true);
    // note : you may also need
    // HttpURLConnection.setInstanceFollowRedirects(false)
    HttpURLConnection con = (HttpURLConnection) new URL(URLName)
      .openConnection();
    con.setConnectTimeout(5000); // set timeout to 5 seconds
    con.setReadTimeout(5000);  // set read timeout to 5 seconds
    con.setRequestMethod("HEAD");
    return (con.getResponseCode() == HttpURLConnection.HTTP_OK);
   } catch (SocketTimeoutException e) {
    return false;
   } catch (Exception e) {
    e.printStackTrace();
    return false;
   }
  }
}

2014年5月21日 星期三

[Maven] 常用資訊

Maven2 的運行命令為: mvn ,

常用命令為:

mvn archetype:create :創建Maven 項目

mvn compile :編譯源代碼

mvn test-compile :編譯測試代碼

mvn test :運行應用程序中的單元測試

mvn site : 生成項目相關信息的網站

2014年5月16日 星期五

各廠牌手機工程模式 [Android]

各廠牌手機工程模式:

步驟.1
進入手機撥號介面

步驟.2
輸入以下號碼. (不需要按撥出,按完最後一個碼之後就會進入工程模式了)

HTC => *#*#4636#*#*
Sony => *#*#7378423#*#*
三星 => *#0*#
小米機 => *#*#6484#*#*
華為非 MTK 機種 => *#*#2846579#*#*
華碩 =>    *#*#4636#*#*
小米 => *#*#6484#*#*
Infocus => *#*#3646633#*#*
LG => 3845#*802#
Acer => *#*#3646633#*#*
NEXUS => *#*#4636#*#*
OPPO => *#*#4636#*#*

一般MTK系列的手機 => *#*#3646633#*#*

提醒 : 進入工程模式後是全英文介面
可以測試螢幕/LED/喇叭/麥克風/相機/WIFI....等等

以上並不保證該廠牌所有型號機種可用,如果不行使用
只好請大家使用谷歌大神囉

2014年5月6日 星期二

notepad ++ 常用快捷鍵

只列常用的出來
Alt-F4 關閉程式
Ctrl-W 關閉檔案
Ctrl-O 開啟檔案
Ctrl-Tab 切換分頁
Ctrl-H    打開Find / Replace 對話框
Ctrl-D    複製當前行
Ctrl-L    刪除當前行
Ctrl-T    上下行交換
F3    找下一個
Shift-F3    找上一個
Ctrl-Shift-F    在文件中找
Ctrl-F2    觸發書籤
F2    到前一個書籤
Shift-F2    到下一個書籤
F5    打開run對話框
Ctrl-Space    打開CallTip列錶框
Tab (selection of several lines)    加入Space
Shift-Tab (selection of several lines)    移除Space
F11    全屏
Alt-0    折疊全部
Alt-Shift-0    展開全部
Ctrl-U    變為小寫
Ctrl-Shift-U    變為大寫
Ctrl-Q    塊註釋/消除註釋

運用jQuery搜尋Table中特定條件select option 的資料

直接看程式碼
function test2(){
$("tr").each(function(i){
 //取得符合條件checkbox的value
 //var checkboxValue = $(this).find("input[type='checkbox']").attr('checked');
 var checkboxValue = $(this).find("td input[type='checkbox']").attr('checked');
 
 if(checkboxValue==true)
  //取得在該tr中符合條件的value
  var tmp = $(this).find("select option:selected").attr('value');
  //console.log(checkboxValue);
  if(tmp!=null){
   console.log(tmp);
  }
 });
}

大意是找出整份文件中 tr 中符合 ("input[type='checkbox']").attr('checked')
條件的 row,找到該row 後,再依照 ("select option:selected"),取得想要的值