軟件是對質量的不懈追求

          #

          Linux下mail使用技巧

          登錄LINUX系統后,經常會看到"you have mail",卻苦于不知道如何查看,相信菜鳥們都遇到過,偶在網上用“linux mail"找了很久,但大都是介紹mail服務器的,黃天總算沒負有心人,在洪恩在找到一篇介紹基礎的文章,不敢獨享。
           
          系統提供了用戶 之間通信的郵件系統,當用戶打開終端注冊登錄時發現系統給出如下信息:
              you have mail.

              這時用戶可通過鍵入mail命令讀取信件:

              $ mail

              mail程序將逐個顯示用戶的信件,并依照時間順序,顯示最新的信件。每顯示一段信件,mail都詢問用戶是否要對該信件作些處理。若用戶回答d,則表示 刪除信件;若僅按回車鍵,表示對信件不作任何改動(信件仍舊保存,下次還可讀這一信件);若回答p,則要求重復顯示信件;s filename表示要把信件存入所命名的文件;若回答q,表示要從mail退出。

              我們在本章的第一個例子中演示了如何寫一封信,作為練習,你可送信件給自己,然后鍵入mail讀取自己發的信件,看看會有什么效果。(發信給自己是一種設 置備忘錄的方法)。

              $mail frank 給自己寫信

              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命令還有很多其它用法,例如發送事先準備好的信件,或一次送信給若干人。還可以用其它方法送信件。

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

          Mysql中limit的用法詳解

              Mysql中limit的用法:在我們使用查詢語句的時候,經常要返回前幾條或者中間某幾行數據,這個時候怎么辦呢?
            不用擔心,mysql已經為我們提供了這樣一個功能。

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

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

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

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

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

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

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

          //換句話說,LIMIT n 等價于 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條記錄,取其中最大一個ID值作為起始標識,然后利用它可以快速定位下100條記錄

          第2句擇是僅僅取90000條記錄后1條,然后取ID值作起始標識定位下100條記錄

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

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

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

          直接利用第90000條記錄的ID,不用經過Max運算,這樣做理論上效率因該高一些,但在實際使用中幾乎看不到效果,
             因為本身定位ID返回的就是1條記錄,Max幾乎不用運作就能得到結果,但這樣寫更清淅明朗,省去了畫蛇那一足.


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

          但不管是實現方式是存貯過程還是直接代碼中,瓶頸始終在于MS-SQL的TOP總是要返回前N個記錄,這種情況在數據量不大時感受不深,
             但如果成百上千萬,效率肯定會低下的.相比之下MySQL的limit就有優勢的多,執行:


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

          的結果分別是:


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

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

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

          1、offset比較小的時候。

          select * from yanxue8_visit limit 10,10

          多次運行,時間保持在0.0004-0.0005之間


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

          多次運行,時間保持在0.0005-0.0006之間,主要是0.0006

          結論:偏移offset較小的時候,直接使用limit較優。這個顯示是子查詢的原因。

          2、offset大的時候。

          select * from yanxue8_visit limit 10000,10

          多次運行,時間保持在0.0187左右

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

          多次運行,時間保持在0.0061左右,只有前者的1/3。可以預先offset越大,后者越優。

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

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

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

          枚舉類型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 閱讀(148) | 評論 (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來進行異常處理。例如:  

           

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

          目前我們可能得到的系統異常主要包含以下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  

          上面的六種異常對象都繼承自Error對象。他們都支持以下兩種構造方法:

           

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

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

           

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

          如要判斷異常信息的類型,可在catch中進行判斷:

           

          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: 錯誤描述 (僅IE可用).  
          • fileName: 出錯的文件名 (僅Mozilla可用).  
          • lineNumber: 出錯的行數 (僅Mozilla可用).  
          • message: 錯誤信息 (在IE下同description)  
          • name: 錯誤類型.  
          • number: 錯誤代碼 (僅IE可用).  
          • stack: 像Java中的Stack Trace一樣的錯誤堆棧信息 (僅Mozilla可用).  

          因此為了更好的了解錯誤信息我們可以將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命令事實上可以拋出任何對象,并且我們可以在catch接受到此對象。例 如:

           

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

          posted @ 2010-06-02 10:38 BlakeSu 閱讀(331) | 評論 (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) | 評論 (0)編輯 收藏

          mysql convert int to char/varchar

          select cast(1 as char)

          char 不能換成varchar,否則會報錯。

          posted @ 2010-05-12 17:12 BlakeSu 閱讀(2896) | 評論 (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 閱讀(685) | 評論 (0)編輯 收藏

          Eclipse集成windows資源管理器簡單方法

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

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

          commons lang 比較有用的類

          ArrayUtils                 //簡化數組的操作
          LocaleUtils
          SerializationUtils
          StringEscapeUtils
          StringUtils
          SystemUtils
          Validate                   //輸入參數驗證
          NestableException
          NestableRuntimeException
          StopWatch          //秒表類

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

          xmind 當真不錯

          xmind是繪制思維導圖的工具。
          使用之后,發現繪制組織結構圖和wbs都很方便。
          軟件基于eclipse框架開發,反應速度和操作性也都很不錯。
          更重要的,圖形的效果也是專業級的 :)

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

          僅列出標題
          共12頁: 上一頁 1 2 3 4 5 6 7 8 9 下一頁 Last 
          主站蜘蛛池模板: 阿瓦提县| 神木县| 望奎县| 罗定市| 惠来县| 桃源县| 泸溪县| 五家渠市| 通山县| 平定县| 团风县| 道孚县| 鄂尔多斯市| 孙吴县| 定陶县| 蓬莱市| 大悟县| 长宁区| 肇源县| 木兰县| 山阳县| 永平县| 灵宝市| 蒙阴县| 宝坻区| 客服| 萨迦县| 界首市| 南昌市| 贵阳市| 五指山市| 云霄县| 酒泉市| 余江县| 马公市| 密云县| 钟山县| 锡林郭勒盟| 九龙县| 墨竹工卡县| 克山县|