<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    軟件是對(duì)質(zhì)量的不懈追求

    2010年3月18日 #

    linux du 查看文件夾占用空間


    du -sh *

    posted @ 2011-04-15 08:39 BlakeSu 閱讀(280) | 評(píng)論 (0)編輯 收藏

    Building Standalone Application with Maven2

    If you are building standalone application in Java, Maven is your friend when packing your application,
    There are two way to let Maven package your application, either as a single jar with all your dependencies jar.


     <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
       <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
       </descriptorRefs>
      </configuration>
     </plugin>



    One advantage if you choose to do this way is if you need to sign your application jar.
    This is needed if you are building a Java Web Start client and you need more access than connecting back to the server.
    To read more about have Maven signing your jar read http://maven.apache.org/plugins/maven-jar-plugin/usage.html.
    But if you choose to go this way, make sure that all license agreement are shipped with your one single jar.

    Another way is to let Maven package your source code only and then referring the dependent jar file from the MANIFEST file.


     <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-jar-plugin</artifactId>
      <configuration>
       <archive>
        <manifest>
         <addClasspath>true</addClasspath>
         <mainClass>se.msc.adapter.Main</mainClass>
         <classpathPrefix>lib/</classpathPrefix>
        </manifest>
       </archive>
      </configuration>
     </plugin>

    posted @ 2011-02-24 13:03 BlakeSu 閱讀(329) | 評(píng)論 (0)編輯 收藏

    eclipse 終于有了列編輯功能

    eclipse 3.5之后終于有了列編輯,快捷鍵是alt+shift+a,再次按此快捷鍵返回常規(guī)編輯狀態(tài)。


    posted @ 2010-10-15 11:33 BlakeSu 閱讀(1484) | 評(píng)論 (0)編輯 收藏

    LineNumberReader 指定文件編碼


    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.LineNumberReader;


    public class Main {
        
        
    public static void main(String[] args) throws IOException {

            InputStreamReader isr 
    = new InputStreamReader(new FileInputStream("15370720.pdf4"), "utf-16");
            LineNumberReader lnr
    =new LineNumberReader(isr);
            String line 
    = null;
            
    while((line=lnr.readLine())!=null){  
               System.out.println(lnr.getLineNumber()
    +"\t"+line);
            }
       }
    }

    posted @ 2010-08-05 09:13 BlakeSu 閱讀(1050) | 評(píng)論 (0)編輯 收藏

    Class.getResourceAsStream 和 ClassLoader.getResourceAsStream

    兩個(gè)方法的區(qū)別是資源的定義不同, 一個(gè)主要用于相對(duì)與一個(gè)object取資源,而另一個(gè)用于取相對(duì)于classpath的
    資源,用的是絕對(duì)路徑。

    在使用Class.getResourceAsStream 時(shí), 資源路徑有兩種方式, 一種以 / 開(kāi)頭,則這樣的路徑是指定絕對(duì)
    路徑, 如果不以 / 開(kāi)頭, 則路徑是相對(duì)與這個(gè)class所在的包的。

    在使用ClassLoader.getResourceAsStream時(shí), 路徑直接使用相對(duì)于classpath的絕對(duì)路徑。

    舉例,下面的三個(gè)語(yǔ)句,實(shí)際結(jié)果是一樣的:
       com.explorers.Test.class.getResourceAsStream("abc.jpg")
    = com.explorers.Test.class.getResourceAsStream("/com/explorers/abc.jpg")
    = ClassLoader.getResourceAsStream("com/explorers/abc.jpg")

    posted @ 2010-07-28 16:31 BlakeSu 閱讀(295) | 評(píng)論 (0)編輯 收藏

    Standalone Java CAS Client

    There's a variety of clients for CAS. The Java-based clients (JA-SIG, Yale, see JA-SIG website) typically handle the browser-based client interaction with CAS very well through ServletFilter implementations.

    Now what about programmatic authentication, i.e. achieving authentication through non-browser based applications? There exists a CAS .NET client but I did not manage to find the appropriate Java implementation. So here goes - it is based on the Apache HttpClient.

    In case I missed any existing implementation achieving the same purpose, let's look at the bright side: at least now I understand the CAS protocol :-)

    My CAS client works within any application. It uses the HttpClient and behaves like a browser client as CAS requires cookie support.

    Here's the code:
    import org.apache.commons.httpclient.Header;
    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.HttpMethod;
    import org.apache.commons.httpclient.HttpStatus;
    import org.apache.commons.httpclient.methods.GetMethod;
    import org.apache.commons.httpclient.methods.PostMethod;
    import org.apache.log4j.Logger;

    /**
    * The CasClient allows users to programmatically login
    * to CAS protected services based on the CAS 2 protocol.
    * This client behaves like a browser-client in terms of
    * cookie handling.<br>
    *
    @author Mathias Richter
    */
    public class CasClient
    {
      
       
    public static Logger LOG = Logger.getLogger( CasClient.class  );

       
    public static final String LOGIN_URL_PART = "login";
       
    public static final String SERVICE_VALIDATE_URL_PART = "serviceValidate";
       
    public static final String TICKET_BEGIN = "ticket=";
       
    private static final String LT_BEGIN = "name="lt" value="";
       public static final String CAS_USER_BEGIN = "<cas:user>";
       
    public static final String CAS_USER_END = "</cas:user>";
      
       
    private HttpClient fClient;
       
    private String fCasUrl;
      
       
    /**
        * Construct a new CasClient.
        *
        * 
    @param casUrl The base URL of the CAS service to be used.
        
    */
       
    public CasClient( String casBaseUrl )
       {
           
    thisnew HttpClient(), casBaseUrl );
       }
      
       
    /**
        * Construct a new CasClient which uses the specified HttpClient
        * for its HTTP calls.
        *
        * 
    @param client
        * 
    @param casBaseUrl
        
    */
       
    public CasClient( HttpClient client, String casBaseUrl )
       {
           fClient 
    = client;
           fCasUrl 
    = casBaseUrl;
       }
      
       
    /**
        * Authenticate the specified username with the specified password.
        * This will not yield any ticket, as no service is authenticated
        * against. This wil just set the CAS cookie in this client upon
        * successful authentication.
        *
        * 
    @param username
        * 
    @param password
        
    */
       
    public void authenticate( String username, String password )
       {
           authenticate( 
    null, username, password );
       }
      
       
    /**
        * Validate the specified service ticket against the specified service.
        * If the ticket is valid, this will yield the clear text user name
        * of the autenticated user.<br>
        * Note that each service ticket issued by CAS can be used exactly once
        * to validate.
        *
        * 
    @param serviceUrl
        * 
    @param serviceTicket
        *
        * 
    @return Clear text username of the authenticated user.
        
    */
       
    public String validate( String serviceUrl, String serviceTicket )
       {
           String result 
    = null;
           PostMethod method 
    = new PostMethod( fCasUrl + SERVICE_VALIDATE_URL_PART );
           method.setParameter( 
    "service", serviceUrl );
           method.setParameter( 
    "ticket", serviceTicket );
           
    try
           {
               
    int statusCode = fClient.executeMethod(method);
               
    if (statusCode != HttpStatus.SC_OK)
               {
                   LOG.error( 
    "Could not validate: " + method.getStatusLine() );
                   method.releaseConnection();
               } 
    else
               {   
                   result 
    = extractUser( new String( method.getResponseBody() ) );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not validate: " + x.toString () );
               x.printStackTrace();
           }
           method.releaseConnection();
           
    return result;
       }
      
       
    /**
        * Authenticate the specified user with the specified password against the
        * specified service.
        *
        * 
    @param serviceUrl May be null. If a url is specified, the authentication will happen against this service, yielding a service ticket which can be validated.
        * 
    @param username
        * 
    @param password
        * 
    @return A valid service ticket, if and only if the specified service URL is not null.
        
    */
       
    public String authenticate( String serviceUrl, String username, String password )
       {
           String lt 
    = getLt( serviceUrl );
           
    if ( lt == null )
           {
               LOG.error( 
    "Cannot retrieve LT from CAS. Aborting authentication for '" + username + "'" );
               
    return null;
           }
           String result 
    = null;
           PostMethod method 
    = new PostMethod( fCasUrl + LOGIN_URL_PART );
           
    if ( serviceUrl != null ) // optional
               method.setParameter( "service", serviceUrl );
           method.setParameter( 
    "_eventId""submit" );
           method.setParameter(
    "username", username );
           method.setParameter(
    "password", password );
           method.setParameter(
    "lt", lt );
           method.setParameter( 
    "gateway""true" );
           
    try
           {
               fClient.executeMethod(method);
               
    if ( serviceUrl == null )
               {
                   
    if ( extractLt( new String( method.getResponseBody() ) ) != null ) // if CAS does not return a login page with an LT authentication was successful
                   {
                       LOG.error( 
    "Authentication for '" +  username + "' unsuccessful" );
                       
    if ( LOG.isDebugEnabled() )
                           LOG.debug( 
    "Authentication for '" + username + "' unsuccessful." );
                   } 
    else
                   {
                       
    if ( LOG.isDebugEnabled() )
                           LOG.debug( 
    "Authentication for '" + username + "' unsuccessful." );
                   }
               } 
    else
               {
                   Header h 
    = method.getResponseHeader( "Location" );
                   
    if ( h != null )
                       result 
    = extractServiceTicket( h.getValue() );
                   
    if ( result == null )
                       LOG.error( 
    "Authentication for '" + username + "' unsuccessful." );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not authenticate'" + username + "':" + x.toString () );
           }
           method.releaseConnection();
           
    return result;
       }
      
       
    /**
        * Helper method to extract the user name from a "service validate" call to CAS.
        *
        * 
    @param data Response data.
        * 
    @return The clear text username, if it could be extracted, null otherwise.
        
    */
       
    protected String extractUser( String data )
       {
           String user 
    = null;
           
    int start = data.indexOf( CAS_USER_BEGIN  );
           
    if ( start >= 0 )
           {
               start 
    += CAS_USER_BEGIN.length();
               
    int end = data.indexOf( CAS_USER_END );
               
    if ( end > start )
                   user 
    = data.substring( start, end );
               
    else
                   LOG.warn( 
    "Could not extract username from CAS validation response. Raw data is: '" + data + "'" );
           } 
    else
           {
               LOG.warn( 
    "Could not extract username from CAS validation response. Raw data is: '" + data + "'" );
           }
           
    return user;
       }
      
       
    /**
        * Helper method to extract the service ticket from a login call to CAS.
        *
        * 
    @param data Response data.
        * 
    @return The service ticket, if it could be extracted, null otherwise.
        
    */
       
    protected String extractServiceTicket( String data )
       {
           String serviceTicket 
    = null;
           
    int start = data.indexOf( TICKET_BEGIN  );
           
    if ( start > 0 )
           {
               start 
    += TICKET_BEGIN.length();
               serviceTicket 
    = data.substring( start );
           }
           
    return serviceTicket;
       }
      
       
    /**
        * Helper method to extract the LT from a login form from CAS.
        *
        * 
    @param data Response data.
        * 
    @return The LT, if it could be extracted, null otherwise.
        
    */
       
    protected String extractLt( String data )
       {
           String token 
    = null;
           
    int start = data.indexOf( LT_BEGIN  );
           
    if ( start < 0 )
           {
               LOG.error( 
    "Could not obtain LT token from CAS: LT Token not found in response." );
           } 
    else
           {
               start 
    += LT_BEGIN.length();
               
    int end = data.indexOf( """, start );
               token = data.substring( start, end );
           }       
           
    return token;
       }
      
       
    /**
        * This method requests the original login form from CAS.
        * This form contains an LT, an initial token that must be
        * presented to CAS upon sending it an authentication request
        * with credentials.<br>
        * If a service URL is provided (which is optional), this method
        * will post the URL such that CAS authenticates against the
        * specified service when a subsequent authentication request is
        * sent.
        *
        * 
    @param serviceUrl
        * 
    @return The LT token if it could be extracted from the CAS response.
        
    */
       
    protected String getLt( String serviceUrl )
       {
           String lt 
    = null;
           HttpMethod method 
    = null;
           
    if ( serviceUrl == null )
               method 
    = new GetMethod( fCasUrl + LOGIN_URL_PART );
           
    else
           {
               method 
    = new PostMethod( fCasUrl + LOGIN_URL_PART );
               ( ( PostMethod ) method ).setParameter( 
    "service", serviceUrl );
           }
           
    try
           {
               
    int statusCode = fClient.executeMethod(method);
               
    if (statusCode != HttpStatus.SC_OK)
               {
                   LOG.error( 
    "Could not obtain LT token from CAS: " + method.getStatusLine() );
                   method.releaseConnection();
               } 
    else
               {
                   Object o 
    = method.getResponseHeaders() ;
                   
    return extractLt( new String( method.getResponseBody() ) );
               }
           } 
    catch ( Exception x )
           {
               LOG.error( 
    "Could not obtain LT token from CAS: " + x.toString () );
           }
           method.releaseConnection();
           
    return lt;
       }
      
    }

    posted @ 2010-07-15 17:59 BlakeSu 閱讀(416) | 評(píng)論 (0)編輯 收藏

    java取文件換行符

    System.getProperty("line.separator")

    posted @ 2010-06-30 15:45 BlakeSu 閱讀(311) | 評(píng)論 (0)編輯 收藏

    禁止瀏覽器緩存

    html
      <meta http-equiv="pragma" content="no-cache">
      
    <meta http-equiv="cache-control" content="no-cache">
      
    <meta http-equiv="expires" content="0">


    servlet
              response.setHeader("pragma","no-cache");
              response.setHeader(
    "cache-control","no-cache");
              response.setDateHeader(
    "expires"0);


    posted @ 2010-06-25 09:06 BlakeSu 閱讀(253) | 評(píng)論 (0)編輯 收藏

    frame 中跨域訪(fǎng)問(wèn)cookie(java)

    response.addHeader("P3P","CP=CAO PSA OUR");

    posted @ 2010-06-25 09:04 BlakeSu 閱讀(415) | 評(píng)論 (0)編輯 收藏

    vim的復(fù)制粘貼小結(jié)

    原文地址 http://lsong17.spaces.live.com/blog/cns!556C21919D77FB59!603.trak


    用vim這么久 了,始終也不知道怎么在vim中使用系統(tǒng)粘貼板,通常要在網(wǎng)上復(fù)制一段代碼都是先gedit打開(kāi)文件,中鍵粘貼后關(guān)閉,然后再用vim打開(kāi)編輯,真的不 爽;上次論壇上有人問(wèn)到了怎么在vim中使用系統(tǒng)粘貼板,印象里回復(fù)很多,有好幾頁(yè)的回復(fù)卻沒(méi)有解決問(wèn)題,今天實(shí)在受不了了又在網(wǎng)上找辦法,竟意外地找到 了,貼出來(lái)分享一下。

    如果只是想使用系統(tǒng)粘貼板的話(huà)直接在輸入模式按Shift+Inset就可以了,下面講一下vim的粘貼板的基礎(chǔ)知識(shí),有興趣的可以看看, 應(yīng)該會(huì)有所收獲的。
    vim幫助文檔里與粘貼板有關(guān)的內(nèi)容如下:

    1. vim有12個(gè)粘貼板,分別是0、1、2、...、9、a、“、+;用:reg命令可以查看各個(gè)粘貼板里的內(nèi)容。在vim中簡(jiǎn)單用y只是復(fù)制到 “(雙引號(hào))粘貼板里,同樣用p粘貼的也是這個(gè)粘貼板里的內(nèi)容;

    2. 要將vim的內(nèi)容復(fù)制到某個(gè)粘貼板,需要退出編輯模式,進(jìn)入正常模式后,選擇要復(fù)制的內(nèi)容,然后按"Ny完成復(fù)制,其中N為粘 貼板號(hào)(注意是按一下雙引號(hào)然后按粘貼板號(hào)最后按y),例如要把內(nèi)容復(fù)制到粘貼板a,選中內(nèi)容后按"ay就可以了,有兩點(diǎn)需要說(shuō)明一下:
      • “號(hào)粘貼板(臨時(shí)粘貼板)比較特殊,直接按y就復(fù)制到這個(gè)粘貼板中了,直接按p就粘貼這個(gè)粘貼板中的內(nèi)容;
      • +號(hào)粘貼板是系統(tǒng)粘貼板,用"+y將內(nèi)容復(fù)制到該粘貼板后可以使用Ctrl+V將其粘貼到其他文檔(如firefox、gedit) 中,同理,要把在其他地方用Ctrl+C或右鍵復(fù)制的內(nèi)容復(fù)制到vim中,需要在正常模式下按"+p;

    3. 要將vim某個(gè)粘貼板里的內(nèi)容粘貼進(jìn)來(lái),需要退出編輯模式,在正常模式按"Np,其中N為粘貼板號(hào),如上所述,可以按"5p將 5號(hào)粘貼板里的內(nèi)容粘貼進(jìn)來(lái),也可以按"+p將系統(tǒng)全局粘貼板里的內(nèi)容粘貼進(jìn)來(lái)。

    注意:在我這里,只有vim.gtk或vim.gnome才能使用系統(tǒng)全局粘貼板,默認(rèn)的 vim.basic看不到+號(hào)寄存器。

    posted @ 2010-06-18 14:21 BlakeSu 閱讀(264) | 評(píng)論 (0)編輯 收藏

    Linux下mail使用技巧

    登錄LINUX系統(tǒng)后,經(jīng)常會(huì)看到"you have mail",卻苦于不知道如何查看,相信菜鳥(niǎo)們都遇到過(guò),偶在網(wǎng)上用“linux mail"找了很久,但大都是介紹mail服務(wù)器的,黃天總算沒(méi)負(fù)有心人,在洪恩在找到一篇介紹基礎(chǔ)的文章,不敢獨(dú)享。
     
    系統(tǒng)提供了用戶(hù) 之間通信的郵件系統(tǒng),當(dāng)用戶(hù)打開(kāi)終端注冊(cè)登錄時(shí)發(fā)現(xiàn)系統(tǒng)給出如下信息:
        you have mail.

        這時(shí)用戶(hù)可通過(guò)鍵入mail命令讀取信件:

        $ mail

        mail程序?qū)⒅饌€(gè)顯示用戶(hù)的信件,并依照時(shí)間順序,顯示最新的信件。每顯示一段信件,mail都詢(xún)問(wèn)用戶(hù)是否要對(duì)該信件作些處理。若用戶(hù)回答d,則表示 刪除信件;若僅按回車(chē)鍵,表示對(duì)信件不作任何改動(dòng)(信件仍舊保存,下次還可讀這一信件);若回答p,則要求重復(fù)顯示信件;s filename表示要把信件存入所命名的文件;若回答q,表示要從mail退出。

        我們?cè)诒菊碌牡谝粋€(gè)例子中演示了如何寫(xiě)一封信,作為練習(xí),你可送信件給自己,然后鍵入mail讀取自己發(fā)的信件,看看會(huì)有什么效果。(發(fā)信給自己是一種設(shè) 置備忘錄的方法)。

        $mail frank 給自己寫(xiě)信

        subject: test

        This is a mail test

        CRL-d

        EOT

        $

        $mail 查看信件

        “/var/spool/mail/frank:”1 message 1 new

        >Nfrank@xteam.xteamlinux.comThu Mar 25 11:00 13/403 “test”

        &

        Message 1:

        From frank Thu Mar 25 11:00:25 1999/3/25

        Received: (fromfrank@localhost)

        by xteam.xteamlinux.com(8.8.4/8.8.4)

        id LAA05170 for frank;Thu 25 Mar 1999 11:00:25 GMT

        Date: Thu,25 Mar 1999 11:00:25 GMT

        From:RHS Linux User <frank@xteam.xteamlinux.com>

        Message-Id:<199903251142.LAA05170@xteam.xteamlinux.com>

        To:frank@xteam.xteamlinux.com

        Subject:test

        Status:R

        This is a mail test

        &

        mail命令還有很多其它用法,例如發(fā)送事先準(zhǔn)備好的信件,或一次送信給若干人。還可以用其它方法送信件。

    posted @ 2010-06-18 11:05 BlakeSu 閱讀(190) | 評(píng)論 (0)編輯 收藏

    Mysql中l(wèi)imit的用法詳解

        Mysql中l(wèi)imit的用法:在我們使用查詢(xún)語(yǔ)句的時(shí)候,經(jīng)常要返回前幾條或者中間某幾行數(shù)據(jù),這個(gè)時(shí)候怎么辦呢?
      不用擔(dān)心,mysql已經(jīng)為我們提供了這樣一個(gè)功能。

      SELECT * FROM table LIMIT [offset,] rows | rows OFFSET offset

    LIMIT 子句可以被用于強(qiáng)制 SELECT 語(yǔ)句返回指定的記錄數(shù)。LIMIT 接受一個(gè)或兩個(gè)數(shù)字參數(shù)。參數(shù)必須是一個(gè)整數(shù)常量。
      如果給定兩個(gè)參數(shù),第一個(gè)參數(shù)指定第一個(gè)返回記錄行的偏移量,第二個(gè)參數(shù)指定返回記錄行的最大數(shù)目。初始記錄行的偏移量是 0(而不是 1):
      為了與 PostgreSQL 兼容,MySQL 也支持句法: LIMIT # OFFSET #。

    mysql> SELECT * FROM table LIMIT 5,10; // 檢索記錄行 6-15

    //為了檢索從某一個(gè)偏移量到記錄集的結(jié)束所有的記錄行,可以指定第二個(gè)參數(shù)為 -1:

    mysql> SELECT * FROM table LIMIT 95,-1; // 檢索記錄行 96-last.

    //如果只給定一個(gè)參數(shù),它表示返回最大的記錄行數(shù)目:

    mysql> SELECT * FROM table LIMIT 5; //檢索前 5 個(gè)記錄行

    //換句話(huà)說(shuō),LIMIT n 等價(jià)于 LIMIT 0,n。

    注意limit 10和limit 9,1的不同:

    例如:

    1.Select * From cyclopedia Where ID>=(
        Select Max(ID) From (
          Select ID From cyclopedia Order By ID limit 90001
        ) As tmp
      ) limit 100;

    2.Select * From cyclopedia Where ID>=(
        Select Max(ID) From (
          Select ID From cyclopedia Order By ID limit 90000,1
        ) As tmp
      ) limit 100;

     

        第1句是先取了前90001條記錄,取其中最大一個(gè)ID值作為起始標(biāo)識(shí),然后利用它可以快速定位下100條記錄

    第2句擇是僅僅取90000條記錄后1條,然后取ID值作起始標(biāo)識(shí)定位下100條記錄

    第1句執(zhí)行結(jié)果.100 rows in set (0.23) sec

    第2句執(zhí)行結(jié)果.100 rows in set (0.19) sec

    其實(shí)第2句完全可以簡(jiǎn)化成:
        Select * From cyclopedia Where ID>=(
       Select ID From cyclopedia limit 90000,1
    )limit 100;

    直接利用第90000條記錄的ID,不用經(jīng)過(guò)Max運(yùn)算,這樣做理論上效率因該高一些,但在實(shí)際使用中幾乎看不到效果,
       因?yàn)楸旧矶ㄎ籌D返回的就是1條記錄,Max幾乎不用運(yùn)作就能得到結(jié)果,但這樣寫(xiě)更清淅明朗,省去了畫(huà)蛇那一足.


    Select Top 100 * From cyclopedia Where ID>=(
    Select Top 90001 Max(ID) From (
    Select ID From cyclopedia Order By ID
    ) As tmp
    )

    但不管是實(shí)現(xiàn)方式是存貯過(guò)程還是直接代碼中,瓶頸始終在于MS-SQL的TOP總是要返回前N個(gè)記錄,這種情況在數(shù)據(jù)量不大時(shí)感受不深,
       但如果成百上千萬(wàn),效率肯定會(huì)低下的.相比之下MySQL的limit就有優(yōu)勢(shì)的多,執(zhí)行:


    Select ID From cyclopedia limit 90000
    Select ID From cyclopedia limit 90000,1

    的結(jié)果分別是:


    90000 rows in set (0.36) sec
    1 row in set (0.06) sec

    而MS-SQL只能用Select Top 90000 ID From cyclopedia 執(zhí)行時(shí)間是390ms,執(zhí)行同樣的操作時(shí)間也不及MySQL的360ms.

    limit的offset(偏移量)用于記錄較多的時(shí)候,記錄較少時(shí),偏移offset較小,直接使用limit較優(yōu)。offset越大,后者越優(yōu)。
     

    1、offset比較小的時(shí)候。

    select * from yanxue8_visit limit 10,10

    多次運(yùn)行,時(shí)間保持在0.0004-0.0005之間


    Select * From yanxue8_visit Where vid >=(
      Select vid From yanxue8_visit Order By vid limit 10,1
    ) limit 10

    多次運(yùn)行,時(shí)間保持在0.0005-0.0006之間,主要是0.0006

    結(jié)論:偏移offset較小的時(shí)候,直接使用limit較優(yōu)。這個(gè)顯示是子查詢(xún)的原因。

    2、offset大的時(shí)候。

    select * from yanxue8_visit limit 10000,10

    多次運(yùn)行,時(shí)間保持在0.0187左右

    Select * From yanxue8_visit Where vid >=(
      Select vid From yanxue8_visit Order By vid limit 10000,1
    ) limit 10

    多次運(yùn)行,時(shí)間保持在0.0061左右,只有前者的1/3。可以預(yù)先offset越大,后者越優(yōu)。

    mysql> SELECT * FROM table LIMIT 95,-1; // 檢索記錄行 96-last.

    //如果只給定一個(gè)參數(shù),它表示返回最大的記錄行數(shù)目.

    posted @ 2010-06-02 14:43 BlakeSu 閱讀(451) | 評(píng)論 (0)編輯 收藏

    枚舉類(lèi)型enum示例




    public enum OrderStatus {
        A(
    1), B(2), C(3), D(4), F(5), INCOMPLETE(6);
        
        
    private final int value;
        
    /**
         * Constructor.
         
    */
        
    private OrderStatus(int value) {
            
    this.value = value;
        }
        
        
    /**
         * Get the value.
         * 
    @return the value
         
    */
        
    public int getValue() {
            
    return value;
        }

    }


    posted @ 2010-06-02 13:33 BlakeSu 閱讀(147) | 評(píng)論 (0)編輯 收藏

    JS try.....catch的使用

    <script language="javascript">
    try
    {
    throw new Error(10,"asdasdasd")
    }
    catch (e)
    {
    alert(e.message);
    alert(e.description)
    alert(e.number)
    alert(e.name)
    throw new Error(10,"asdasdasd")
    }

    </script>  

    在JavaScript可以使用try...catch來(lái)進(jìn)行異常處理。例如:  

     

    try {
    foo.bar();
    } catch (e) {
    alert(e.name + ": " + e.message);
    }

    目前我們可能得到的系統(tǒng)異常主要包含以下6種:

    • EvalError: raised when an error occurs executing code in eval()  
    • RangeError: raised when a numeric variable or parameter is outside of its valid range  
    • ReferenceError: raised when de-referencing an invalid reference  
    • SyntaxError: raised when a syntax error occurs while parsing code in eval()  
    • TypeError: raised when a variable or parameter is not a valid type  
    • URIError: raised when encodeURI() or decodeURI() are passed invalid parameters  

    上面的六種異常對(duì)象都繼承自Error對(duì)象。他們都支持以下兩種構(gòu)造方法:

     

    new Error();
    new Error("異常信息");

    手工拋出異常的方法如下:

     

    try {
    throw new Error("Whoops!");
    } catch (e) {
    alert(e.name + ": " + e.message);
    }

    如要判斷異常信息的類(lèi)型,可在catch中進(jìn)行判斷:

     

    try {
    foo.bar();
    } catch (e) {
    if (e instanceof EvalError) {
       alert(e.name + ":" + e.message);
    }
    else if (e instanceof RangeError) {
       alert(e.name + ": " + e.message);
    }
    // etc
    }

    Error具有下面一些主要屬性:

    • description: 錯(cuò)誤描述 (僅IE可用).  
    • fileName: 出錯(cuò)的文件名 (僅Mozilla可用).  
    • lineNumber: 出錯(cuò)的行數(shù) (僅Mozilla可用).  
    • message: 錯(cuò)誤信息 (在IE下同description)  
    • name: 錯(cuò)誤類(lèi)型.  
    • number: 錯(cuò)誤代碼 (僅IE可用).  
    • stack: 像Java中的Stack Trace一樣的錯(cuò)誤堆棧信息 (僅Mozilla可用).  

    因此為了更好的了解錯(cuò)誤信息我們可以將catch部分改為如下形式:  

     

    try {
    foo.bar();
    } catch (e) {
    if (browserType != BROWSER_IE) {                            
       alert("name: " + e.name +
        "message: " + e.message +
        "lineNumber: " + e.lineNumber +
        "fileName: " + e.fileName +
        "stack: " + e.stack);        
    }
    else {                    
       alert("name: " + e.name +     
        "errorNumber: " + (e.number & 0xFFFF ) +
        "message: " + e.message");        
    }
    }

    JavaScript中的throw命令事實(shí)上可以?huà)伋鋈魏螌?duì)象,并且我們可以在catch接受到此對(duì)象。例 如:

     

    try {
    throw new Date(); // 拋出當(dāng)前時(shí)間對(duì)象
    } catch (e) {
    alert(e.toLocaleString()); // 使用本地格式顯示當(dāng)前時(shí)間
    }

    posted @ 2010-06-02 10:38 BlakeSu 閱讀(330) | 評(píng)論 (0)編輯 收藏

    深拷貝

    import java.io.*;

    public class ObjectCloner
    {
       
    // so that nobody can accidentally create an ObjectCloner object
       private ObjectCloner(){}
       
    // returns a deep copy of an object
       static public Object deepCopy(Object oldObj) throws Exception
       {
          ObjectOutputStream oos 
    = null;
          ObjectInputStream ois 
    = null;
          
    try
          {
             ByteArrayOutputStream bos 
    = new ByteArrayOutputStream(); 
             oos 
    = new ObjectOutputStream(bos); 
             
    // serialize and pass the object
             oos.writeObject(oldObj);   
             oos.flush();               
             ByteArrayInputStream bin 
    = new ByteArrayInputStream(bos.toByteArray()); 
             ois 
    = new ObjectInputStream(bin);
             
    // return the new object
             return ois.readObject();
          }
          
    catch(Exception e)
          {
             System.out.println(
    "Exception in ObjectCloner = " + e);
             
    throw(e);
          }
          
    finally
          {
             oos.close();
             ois.close();
          }
       }
       
    }

    posted @ 2010-05-25 09:30 BlakeSu 閱讀(176) | 評(píng)論 (0)編輯 收藏

    mysql convert int to char/varchar

    select cast(1 as char)

    char 不能換成varchar,否則會(huì)報(bào)錯(cuò)。

    posted @ 2010-05-12 17:12 BlakeSu 閱讀(2894) | 評(píng)論 (0)編輯 收藏

    How to check Linux distribution and version?

    If u are on an unknown server and keen to know it’s linux distribution info, you can check the linux distribution info by just a single command (eg. version, codename, etc). Just tested this command in UBuntu and CentOS, both return as what i expected. :)

    To check linux distribution and version, follow the steps below:-

    • Start your terminal and enter the command below to show your the linux distribution info:-
      $ cat /etc/*-release
    • Here’s my result in one of my my Ubuntu box:-
      $ cat /etc/*-release
      DISTRIB_ID=Ubuntu
      DISTRIB_RELEASE=9.10
      DISTRIB_CODENAME=karmic
      DISTRIB_DESCRIPTION="Ubuntu 9.10"

      Cool right!

    posted @ 2010-05-08 13:29 BlakeSu 閱讀(684) | 評(píng)論 (0)編輯 收藏

    Eclipse集成windows資源管理器簡(jiǎn)單方法

    Run-->External Tools-->External tools configurations
    new 一個(gè) program
    location 里面填 :C:\WINDOWS\explorer.exe
    Arguments 里面填: ${container_loc}
    點(diǎn)擊 Run

    posted @ 2010-05-08 08:40 BlakeSu 閱讀(262) | 評(píng)論 (0)編輯 收藏

    commons lang 比較有用的類(lèi)

    ArrayUtils                 //簡(jiǎn)化數(shù)組的操作
    LocaleUtils
    SerializationUtils
    StringEscapeUtils
    StringUtils
    SystemUtils
    Validate                   //輸入?yún)?shù)驗(yàn)證
    NestableException
    NestableRuntimeException
    StopWatch          //秒表類(lèi)

    posted @ 2010-04-26 10:16 BlakeSu 閱讀(207) | 評(píng)論 (0)編輯 收藏

    xmind 當(dāng)真不錯(cuò)

    xmind是繪制思維導(dǎo)圖的工具。
    使用之后,發(fā)現(xiàn)繪制組織結(jié)構(gòu)圖和wbs都很方便。
    軟件基于eclipse框架開(kāi)發(fā),反應(yīng)速度和操作性也都很不錯(cuò)。
    更重要的,圖形的效果也是專(zhuān)業(yè)級(jí)的 :)

    posted @ 2010-04-23 09:51 BlakeSu 閱讀(249) | 評(píng)論 (0)編輯 收藏

    Java 中serialVersionUID的解釋

    serialVersionUID作用:
           序列化時(shí)為了保持版本的兼容性,即在版本升級(jí)時(shí)反序列化仍保持對(duì)象的唯一性。
    有兩種生成方式:
           一個(gè)是默認(rèn)的1L,比如:private static final long serialVersionUID = 1L;
           一個(gè)是根據(jù)類(lèi)名、接口名、成員方法及屬性等來(lái)生成一個(gè)64位的哈希字段,比如:
           private static final   long     serialVersionUID = xxxxL;

    當(dāng)你一個(gè)類(lèi)實(shí)現(xiàn)了Serializable接口,如果沒(méi)有定義serialVersionUID,Eclipse會(huì)提供這個(gè)
         提示功能告訴你去定義 。在Eclipse中點(diǎn)擊類(lèi)中warning的圖標(biāo)一下,Eclipse就會(huì)
         自動(dòng)給定兩種生成的方式。如果不想定義它,在Eclipse的設(shè)置中也
          可以把它關(guān)掉的,設(shè)置如下:
            Window ==> Preferences ==> Java ==> Compiler ==> Error/Warnings ==>
            Potential programming problems
            將Serializable class without serialVersionUID的warning改成ignore即可。

    如果你沒(méi)有考慮到兼容性問(wèn)題時(shí),就把它關(guān)掉,不過(guò)有這個(gè)功能是好的,只要任何類(lèi)別實(shí)現(xiàn)了Serializable這個(gè)接口的話(huà),如果沒(méi)有加入 serialVersionUID,Eclipse都會(huì)給你warning提示,這個(gè)serialVersionUID為了讓該類(lèi)別 Serializable向后兼容。

    如果你的類(lèi)Serialized存到硬盤(pán)上面后,可是后來(lái)你卻更改了類(lèi)別的field(增加或減少或改名),當(dāng)你Deserialize時(shí),就會(huì)出現(xiàn) Exception的,這樣就會(huì)造成不兼容性的問(wèn)題。

    但當(dāng)serialVersionUID相同時(shí),它就會(huì)將不一樣的field以type的預(yù)設(shè)值Deserialize,可避開(kāi)不兼容性問(wèn)題。

    posted @ 2010-04-08 10:37 BlakeSu 閱讀(158) | 評(píng)論 (0)編輯 收藏

    spring 相關(guān)

    ApplicationContext wac = WebApplicationContextUtils          .getRequiredWebApplicationContext(config.getServletContext());

    posted @ 2010-04-06 13:01 BlakeSu 閱讀(151) | 評(píng)論 (0)編輯 收藏

    wesphere6.1修改默認(rèn)端口

    環(huán)境->虛擬主機(jī)->default_host->其它屬性(主機(jī)別名)->修改端口
    服務(wù)器->應(yīng)用程序服務(wù)器->server1->端口->WC_defaulthost->修改端口

    posted @ 2010-04-02 10:36 BlakeSu 閱讀(225) | 評(píng)論 (0)編輯 收藏

    jquery validate自定義驗(yàn)證方法


     /* 追加自定義驗(yàn)證方法 */   
     
    // 身份證號(hào)碼驗(yàn)證   
     jQuery.validator.addMethod("idcardno"function(value, element) {
       
    return this.optional(element) || isIdCardNo(value);   
     }, 
    "請(qǐng)正確輸入身份證號(hào)碼");
     
      
    //字母數(shù)字
     jQuery.validator.addMethod("alnum"function(value, element) {
       
    return this.optional(element) || /^[a-zA-Z0-9]+$/.test(value);
     }, 
    "只能包括英文字母和數(shù)字");
     
      
    // 手機(jī)號(hào)碼驗(yàn)證   
     jQuery.validator.addMethod("cellphone"function(value, element) {
       
    var length = value.length;
       
    return this.optional(element) || (length == 11 && /^(1\d{10})$/.test(value));
     }, 
    "請(qǐng)正確填寫(xiě)手機(jī)號(hào)碼"); 
     
      
    // 電話(huà)號(hào)碼驗(yàn)證   
     jQuery.validator.addMethod("telephone"function(value, element) {
       
    var tel = /^(\d{3,4}-?)?\d{7,9}$/g;
       
    return this.optional(element) || (tel.test(value));
     }, 
    "請(qǐng)正確填寫(xiě)電話(huà)號(hào)碼");
     
     
    // 郵政編碼驗(yàn)證
     jQuery.validator.addMethod("zipcode"function(value, element) {
       
    var tel = /^[0-9]{6}$/;
       
    return this.optional(element) || (tel.test(value));
     }, 
    "請(qǐng)正確填寫(xiě)郵政編碼");
     
      
    // 漢字
     jQuery.validator.addMethod("chcharacter"function(value, element) {
       
    var tel = /^[\u4e00-\u9fa5]+$/;
       
    return this.optional(element) || (tel.test(value));
     }, 
    "請(qǐng)輸入漢字");
     
     
    /**
     * 身份證號(hào)碼驗(yàn)證
     *
     
    */
    function isIdCardNo(num) {

     
    var factorArr = new Array(7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1);
     
    var parityBit=new Array("1","0","X","9","8","7","6","5","4","3","2");
     
    var varArray = new Array();
     
    var intValue;
     
    var lngProduct = 0;
     
    var intCheckDigit;
     
    var intStrLen = num.length;
     
    var idNumber = num;
       
    // initialize
         if ((intStrLen != 15&& (intStrLen != 18)) {
             
    return false;
         }
         
    // check and set value
         for(i=0;i<intStrLen;i++) {
             varArray[i] 
    = idNumber.charAt(i);
             
    if ((varArray[i] < '0|| varArray[i] > '9') && (i != 17)) {
                 
    return false;
             } 
    else if (i < 17) {
                 varArray[i] 
    = varArray[i] * factorArr[i];
             }
         }
         
         
    if (intStrLen == 18) {
             
    //check date
             var date8 = idNumber.substring(6,14);
             
    if (isDate8(date8) == false) {
                
    return false;
             }
             
    // calculate the sum of the products
             for(i=0;i<17;i++) {
                 lngProduct 
    = lngProduct + varArray[i];
             }
             
    // calculate the check digit
             intCheckDigit = parityBit[lngProduct % 11];
             
    // check last digit
             if (varArray[17!= intCheckDigit) {
                 
    return false;
             }
         }
         
    else{        //length is 15
             //check date
             var date6 = idNumber.substring(6,12);
             
    if (isDate6(date6) == false) {

                 
    return false;
             }
         }
         
    return true;
         
     }
    /**
     * 判斷是否為“YYYYMM”式的時(shí)期
     *
     
    */
    function isDate6(sDate) {
       
    if(!/^[0-9]{6}$/.test(sDate)) {
          
    return false;
       }
       
    var year, month, day;
       year 
    = sDate.substring(04);
       month 
    = sDate.substring(46);
       
    if (year < 1700 || year > 2500return false
       
    if (month < 1 || month > 12return false
       
    return true
    }
    /**
     * 判斷是否為“YYYYMMDD”式的時(shí)期
     *
     
    */
    function isDate8(sDate) {
       
    if(!/^[0-9]{8}$/.test(sDate)) {
          
    return false;
       }
       
    var year, month, day;
       year 
    = sDate.substring(04);
       month 
    = sDate.substring(46);
       day 
    = sDate.substring(68);
       
    var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]
       
    if (year < 1700 || year > 2500return false
       
    if (((year % 4 == 0&& (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;
       
    if (month < 1 || month > 12return false
       
    if (day < 1 || day > iaMonthDays[month - 1]) return false
       
    return true
    }




    posted @ 2010-03-30 11:30 BlakeSu 閱讀(3020) | 評(píng)論 (2)編輯 收藏

    Mozilla Thunderbird的一些設(shè)置

    為了在windows和linux平臺(tái)公用相同的郵件客戶(hù)端和郵件內(nèi)容,主要是有時(shí)候切換操作系統(tǒng)又要看以前的郵件。最后找到了 thunderbird(下面簡(jiǎn)稱(chēng)TB)客戶(hù)端。這個(gè)客戶(hù)端就是有點(diǎn)慢,倒是能滿(mǎn)足我的要求。但是它的默認(rèn)設(shè)置有時(shí)候有點(diǎn)不符合我們的使用習(xí)慣,我對(duì)它的 設(shè)置作了下面的一些修改:

        1:轉(zhuǎn)發(fā)郵件
           默認(rèn)的設(shè)置轉(zhuǎn)發(fā)把郵件的內(nèi)容作為附件轉(zhuǎn)發(fā)。這樣有兩個(gè)不好的地方:第一,如果郵件有附件,這個(gè)附件不能轉(zhuǎn)發(fā);第二,接收方必須要用TB客戶(hù)端了,否則打不 開(kāi)。
           修改:編輯 -> 首選項(xiàng) -> 編寫(xiě) -> 常規(guī):轉(zhuǎn)發(fā)消息改成內(nèi)聯(lián)
       
        2:其它郵件客戶(hù)端接收TB發(fā)的中文附件是亂碼
           這個(gè)是標(biāo)準(zhǔn)問(wèn)題,TB使用的是新的標(biāo)準(zhǔn),但是別的客戶(hù)端使用的是舊的標(biāo)準(zhǔn)(具體那個(gè)標(biāo)準(zhǔn)忘了,google一下就可以了)。這樣就會(huì)出現(xiàn)亂碼了。
           修改:編輯 -> 首選項(xiàng) -> 高級(jí) -> 配置編輯器:mail.strictly_mime.parm_folding 改成0或者1

        3:自動(dòng)打開(kāi)附件
           TB默認(rèn)的是在打開(kāi)郵件的時(shí)候同時(shí)自動(dòng)打開(kāi)郵件的附件。這樣的話(huà),如果附件大就很頭痛。
           修改:編輯 -> 首選項(xiàng) -> 高級(jí) -> 配置編輯器:
              mail.inline_attachments   改成faulse
              mail.content_disposition.type   改成1

        4:回復(fù)郵件時(shí)回復(fù)的郵件內(nèi)容在下面
           TB默認(rèn)的回復(fù)郵件的回復(fù)內(nèi)容是在下面的,這樣如果郵件來(lái)回幾次,回復(fù)比較多,看起來(lái)很不方便。
           修改:編輯 -> 首選項(xiàng) -> 高級(jí) -> 配置編輯器:Mail.identify.default.reply_on_top值由0改為1
      
        還有一個(gè)問(wèn)題沒(méi)有解決,就是有時(shí)候在TB中打開(kāi)一個(gè)文件夾,它會(huì)重新建索引還是什么的,這時(shí)候打開(kāi)一個(gè)文件夾比較慢。看網(wǎng)上有說(shuō)把這個(gè)文件夾重命名,再創(chuàng) 建一個(gè)同名的文件夾,最后把老的文件夾的內(nèi)容拷貝到新的里面就好了,這個(gè)沒(méi)有試過(guò)。不過(guò)這個(gè)也不是特別大的問(wèn)題,就沒(méi)有繼續(xù)搞了,什么時(shí)候有空再看看,到 時(shí)候再貼上來(lái)。

    posted @ 2010-03-19 16:39 BlakeSu 閱讀(701) | 評(píng)論 (0)編輯 收藏

    tar命令詳解

    格式:  tar  選項(xiàng)  文件目錄列表
    功能:  對(duì)文件目錄進(jìn)行打包備份
    選項(xiàng):
    -c  建立新的歸檔文件
    -r  向歸檔文件末尾追加文件
    -x  從歸檔文件中解出文件
    -O  將文件解開(kāi)到標(biāo)準(zhǔn)輸出
    -v  處理過(guò)程中輸出相關(guān)信息
    -f  對(duì)普通文件操作
    -z  調(diào)用gzip來(lái)壓縮歸檔文件,與-x聯(lián)用時(shí)調(diào)用gzip完成解壓縮
    -Z  調(diào)用compress來(lái)壓縮歸檔文件,與-x聯(lián)用時(shí)調(diào)用compress完成解壓縮  
    例如:
    1.將當(dāng)前目錄下所有.txt文件打包并壓縮歸檔到文件this.tar.gz,我們可以使用
    tar czvf this.tar.gz ./*.txt
    2.將當(dāng)前目錄下的this.tar.gz中的文件解壓到當(dāng)前目錄我們可以使用
    tar xzvf this.tar.gz ./

    posted @ 2010-03-18 17:21 BlakeSu 閱讀(203) | 評(píng)論 (0)編輯 收藏

    主站蜘蛛池模板: 亚洲精品无码成人| 99热在线精品免费全部my| 亚洲国产精品日韩| 亚洲精品无码久久久久YW| 成人免费福利视频| 亚洲色图国产精品| 无码人妻丰满熟妇区免费| 亚洲精品无码不卡在线播放HE| 黄色a级片免费看| 国产成人无码免费视频97| 亚洲国产乱码最新视频| 日韩在线播放全免费| 亚洲综合激情六月婷婷在线观看| 免费国产成人午夜在线观看| 亚洲精品无码不卡在线播放HE| 久久久受www免费人成| 久久久久亚洲av毛片大| 一级做α爱过程免费视频| 亚洲Av无码乱码在线观看性色| 另类小说亚洲色图| 国产亚洲福利一区二区免费看| 18禁亚洲深夜福利人口| 国产国产人免费人成免费视频| 日本亚洲欧美色视频在线播放| 日韩一品在线播放视频一品免费| 亚洲人成网站色7799| 在线播放免费播放av片| 亚洲国产精品网站在线播放 | 最近中文字幕mv手机免费高清 | 亚洲黄片手机免费观看| 亚洲国产综合人成综合网站| 免费一级做a爰片久久毛片潮| 亚洲国产成人久久一区久久| 人成午夜免费大片在线观看| 国产成人毛片亚洲精品| 人与动性xxxxx免费| 国产亚洲情侣一区二区无码AV| 中国一级全黄的免费观看| 亚洲国产第一站精品蜜芽| 久久久久国色av免费看| 亚洲成人免费电影|