漢辰攻略

          The palest ink is better than the best memory.

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            8 Posts :: 1 Stories :: 3 Comments :: 0 Trackbacks

          2008年11月12日 #

        1. C-j: Insert a new line with the same indentation level as the current line
        2. RET: Insert a new line with the same indentation level as the current line
        3. C-M-a: Go to the beginning of the current function or class
        4. C-M-e: Go to the end of the current function or class
        5. C-M-h: Mark the current function or class for copying, etc.
        6. C-M-x: Execute the current function or class
        7. C-c C-b: Submit a bug report
        8. C-c C-c: Execute the buffer (i.e., the file being displayed)
        9. C-c C-d: Trace the stack of the process being executed
        10. C-c C-h: Get context-based help
        11. C-c TAB: Indent a highlighted (or marked) region
        12. C-c C-k: Mark a block of text. Using this at the head of a class or function definition will mark the entire block.
        13. C-c C-l: Shift the region to the left. If the cursor is in the middle of a region, the lower half of the region will shift.
        14. C-c RET: Execute the current file, opening a new window to show the output.
        15. C-c C-n: Jump to the next statement.
        16. C-c C-p: Jump to the previous statement.
        17. C-c C-r: Shift the region to the right. If the cursor is in the middle of a region, the lower half of the region will shift.
        18. C-c C-s: Execute a Python command.
        19. C-c C-t: Toggle shells
        20. C-c C-u: Go up one block
        21. C-c C-v: List the version of the Python mode
        22. C-c C-w: Run PyChecker
        23. C-c !: Open the Python interactive shell
        24. C-c #: Comment the highlighted (marked) region
        25. C-c :: Check the indentation off-set
        26. C-c <: Shift the region to the left
        27. C-c >: Shift the region to the right
        28. C-c ?: Show Python mode documentation
        29. C-c |: Execute the highlighted (marked) part of the current program.
        30. posted @ 2008-11-12 14:11 漢辰 閱讀(1071) | 評論 (0)編輯 收藏

          2008年10月30日 #

          --XX:+DoEscapeAnalysis, off by default
          如果一個對象的所有引用都是限于某一局部范圍,去掉對象上的鎖
          --XX:+UseBiasedLocking, on by default
          對多次取鎖的操作,比如循環,不釋放Lease即使鎖已被釋放,避免費時的取Lease操作 (最有效)
          --XX:+EliminateLocks, on by default
          如果一段代碼經常性的加鎖和解鎖,在解鎖與下次加鎖之間又沒干什么事情,則可以將多次加加鎖解鎖操作合并成一對。也稱為Lock Coarsening (鎖粗化)

          http://www.infoq.com/articles/java-threading-optimizations-p1
          posted @ 2008-10-30 15:33 漢辰 閱讀(672) | 評論 (0)編輯 收藏

          2008年9月9日 #

          python 有str object 和 unicode object 兩種字符串, 都可以存放字符的字節編碼,但是他們是不同的type,這一點很重要,也是為什么會有encode 和decode。

          encode 和 decode在pyhton 中的意義可表示為

                                                                            encode
                                                        unicode -------------------------> str
                                                        unicode <--------------------------str
                                                                            decode
          幾種常用法:
          str_string.decode('codec') 是把str_string轉換為unicode_string, codec是源str_string的編碼方式
          unicode_string.encode('codec') 是把unicode_string 轉換為str_string,codec是目標str_string的編碼方式
          str_string.decode('from_codec').encode('to_codec') 可實現不同編碼的str_string之間的轉換
          比如:

          >>> t='長城'
          >>> t
          '\xb3\xa4\xb3\xc7'
          >>> t.decode('gb2312').encode('utf-8')
          '\xe9\x95\xbf\xe5\x9f\x8e'

          str_string.encode('codec') 是先調用系統的缺省codec去把str_string轉換為unicode_string,然后用encode的參數codec去轉換為最終的str_string. 相當于str_string.decode('sys_codec').encode('codec')。

          unicode_string.decode('codec') 基本沒有意義,unicode 在python里只用一種unicode編碼,UTF16或者UTF32(編譯python時就已經確定),沒有編碼轉換的需要。 

          注:缺省codec在site-packages下的sitecustomize.py文件中指定,比如

          import sys
          sys.setdefaultencoding(
          'utf-8')



           

          posted @ 2008-09-09 15:49 漢辰 閱讀(13138) | 評論 (1)編輯 收藏

          2008年7月28日 #

          慕名Emacs是很久的事了,上個周末Google了一天終于把它在Windows下的中文化問題初步解決了。

          網上講述Emacs中文問題的帖子很多,不過很多是過時的或不完整的,并以Linux下居多。很多.emacs設置看起來發生了作用,但是在我的機器上不是顯示方塊,就是半個中文字符。前者懷疑未配置好Emacs使其無法讀取系統字體,后者懷疑字符寬度設置還有問題,苦于無暇深究。

          最后找到一篇Emacs 中文化指南[http://17xie.com/read-103809.html],講述了在Windows下使用了X11的BDF字體配置Emacs的過程,下載安裝了intlfont,改了相應的emacs設置,Bingo!!!,一試就通。不過字庫還是GB2312的,想把Mule-GBK 和BDF 字體配置在一起,未成功。

          貼張圖慶賀一下
          posted @ 2008-07-28 13:47 漢辰 閱讀(941) | 評論 (0)編輯 收藏

          2008年7月11日 #

          EMacs常用命令集:
          C-x C-s        當前文件存盤
          C-x s        所有文件存盤,根據提示確認是否保存指定文件
          C-x C-b        列出緩存
          C-x C-f        查找文件,如果不存在則新建,如果已打開則切換為當前文件
          C-x 數字        關閉其它窗,只顯示當前主窗體。也可以輸入其它數打開多窗
          C-x o        切換到另一個打開的窗
          C-z        臨時退出,在X中相當于最小化,在Console中可以用"fg"或者"%emacs"返回。
          C-x C-c        退出
          C-u 數字        前綴參數,常用于重復執行命令,如插入8個*符:C-u 8 *
          M-x recover 文件名<回車>         恢復文件到上次自動保存的狀態,常用于系統崩潰時
          C-h m        當前模式的說明文檔,每種模式都略有些許不同
          C-h i        常用shell命令的說明文檔

          常用移動命令:
          C-v        向下翻頁
          C-M-v        另一窗向下翻頁
          M-v        向上翻頁
          C-l        移動到光標位置
          M- <-        移到文首
          M- ->        移到文尾
          C-a        移到行首        M-a        移到句首
          C-e        移到行尾        M-e        移到句尾
          C-p        上移一行
          C-n        下移一行
          C-b        左移一位        M-b        左移一字
          C-f        右移一位        M-f        右移一字
          常用編輯命令:
          C-k        刪除到當前行尾
          M-k        刪除到當前句尾
          C-g        中斷執行
          C-w       Cut marked region
          A-w       Copy marked region
          C-y        取回所有刪除的行,默認顯示最后刪除的行
          M-y        C-y取回所有刪除的行之后,切換顯示之前刪除的行
          C-x C-x  Mark the region from the current cursor to last mark point, 可以方便的重復Mark
          C-x h      Mark the whole buffer
          C-x u        撤消
          C-x C-a C-l Revert a buffer
          g                刷新Dired mode buffer

          常用查找命令:
          C-s        向前查找
          C-r        向后查找
          M-g M-g Goto a line

          進入Hex mode      M-x hexl-mode ,C-c C-c 退出

          換行:

          不嫌煩的,每次M-x toggle-truncate-lines切換換行與不換行
          一勞永逸的,M-x customize-option,輸入truncate-partial-width-windows,將出來的設置頁面中的參數改為off,然后保存(Save for future sessions)
          另外說一句,M-x auto-fill-mode也是切換換行模式,不過這是要在文章內容里插入回車符號

          posted @ 2008-07-11 22:16 漢辰 閱讀(424) | 評論 (0)編輯 收藏

          2008年7月8日 #

          寫這篇東西,是本著好記性不如爛筆頭的原則把自己配置LaTex的過程粗略地記錄下來以備后查。

          LaTex 是用了20多年的排版工具。因其專業的排版質量和對大文檔處理能力,流行于學術界,大多數研究生博士生都用它寫自己畢業論文。

          自己3年前曾也想用它寫碩士論文,但迫于時間壓力,后來還是改用了WYSWYG的StarOffice(Sun的產品,基于OpenOffice)。

          不用Word,因為用它編輯我的90頁論文時,總是無可挽回地讓我的機器崩潰,當時系統還是Windows2000。

          下面先離題談一談近期讀程序員修煉之道一書的兩個體會,也想闡述一下我為什么對用LaTex統一創建項目文檔感興趣

          1)DRY(Don't Repeat Yourself),這是作者(Andrew Hunt/David Thomas)提到的重要原則,應貫徹到軟件開發的各個方面。其中一方面暗示開發流程中應盡可能保持同一級別信息的儲備唯一化,而不應有多處載體包含同級別信息。比如從測試規范應可以直接導出TestCase,數據庫定義規范直接導出數據庫腳本等等。

          2)工欲善其事,必先利其器。專業的程序員除了熟悉自己吃飯用的編程語言外,還需懂得各種輔助工具特別是Perl/Python/Shell一類的腳本語言,因其廣泛存在于各種平臺中,并有很好的正則表達式和純文本操縱能力。例如,用他們可以幫助實現項目文檔的自動生成和發布等等。比如上面的信息導出就是一個應用目標。

          要達到這樣地目的,必須要用純文本作為信息載體。但是,對于習慣于閱讀Word,PDF,HTML等格式化文檔的人們來說,純文本卻不太合適。所以3年前的LaTex又浮現在我的眼前。LaTex 很符合DRY原則,文檔信息和格式化信息都用純文本方式保存,但最終發布形式可以用LaTex自動生成,或PDF,或HTML,自己選擇。

          LaTex難以學習是一大詬病,但是個人認為,軟件開發文檔有比較統一的格式化規范,只要有現成的模板,普通程序員可以通過短時間學習掌握基本的編輯能力。

          下面言歸正傳:

          大家時間都不多,Windows下使用LaTex最方便的辦法是安裝MiCTex套裝,其主要包括MikTex(LaTex的一種實現),SciTE(LaTex文檔編輯器),Tex4ht(LaTex文檔到Html轉換器)等,還捆綁了一些入門學習資料。

          LaTex內核無法識別超越ASCII的編碼,中文處理是以外掛的方式進行的。CJK是目前使用的最多的LaTex的中文化包,MiCTex也包括了,不過中文字體還需配置(也可能因為我的系統是英文的XP所致)。

          比較了網上Google到的資料,Helmer Aslaksen的這篇文章最全面和正確的描述了中文配置過程
          Chinese TeX Using the CJK LaTeX Package, Unicode TrueType Fonts and pdfTeX under Windows
          http://www.math.nus.edu.sg/aslaksen/cs/cjk.html

          MiCTex作者最近也提供了一個中文字體自動配置工具,可以很方便的生成各類字體配置文件,并支持UTF8或GBK編碼,很好用。我用它安裝了系統中的微軟宋體,黑體。結果比上面Cyberbit字體好。
          http://bbs.ctex.org/viewthread.php?tid=44496&extra=page%3D1

          下面可以下載到其他免費字體文件
          http://www.wazu.jp/gallery/Fonts_ChineseSimplified.html

          Tex4ht是MiCTex捆綁的LaTex2Html轉換工具,英文很不錯,中文有點問題,還要下功夫看看那里出問題。我自己很憧憬以HTML的形式發布和更新項目文檔,簡單實用,這個發布過程可以作為一個步驟加入每晚的Build。

          posted @ 2008-07-08 14:20 漢辰 閱讀(1883) | 評論 (0)編輯 收藏

          2008年6月26日 #

          Fork-join framework是Java 7并行庫的新內容,基于divide-and-conquer算法來處理大數據量計算。DnQ是處理微粒度并行計算(數據量大,單位運行時間短)的理想模式。數據量在達到一個預定義的門檻之前,被分割成多個任務被Worker threads執行。因為現代Java虛擬機都把Java thread映射到系統線程或LWP(Light-weight process) ,同時Worker數量一般設定等同于CPU個數,這樣在多核的硬件系統中能充分利用多個CPU的計算能力。

          寫了一個MergeSort的測試例子,最終的排序用的是Java Collection Framework 自帶的Arrays.sort()。在自己雙核機器試了試,發現提升不是特別明顯。Arrays.sort 本身很高效,Framework有thread之間協作和管理worker pool的開銷,所以必須選擇一個適合的數據量闞值。下面是運行結果:

          java -Xms64m -Xmx128m -cp C;/forkjoin/jsr166y.zip;C:/workspace/java.tij forkjoin.SortTask

          Number of processor 2
          =================Sequential ===================
          Sorting takes 2617701971 to complete
          =================ForkJoin ====================
          Sorting takes 2284940405 to complete

          找不到更多核的機器,有條件的同學可以測試一把。另外,Brain Goetz (Java Concurrency in Practice作者) 的文章可參考,他的測試例子顯示了不錯的性能提升(最高17倍在32cpu系統),一般4核或8核的能達到3倍或5倍的SPEEDUP

          Java thread and practice: Stick a fork in it Part 1 - http://www.ibm.com/developerworks/java/library/j-jtp11137.html

          package forkjoin;

          import jsr166y.forkjoin.RecursiveAction;
          import jsr166y.forkjoin.ForkJoinPool;
          import java.util.Random;
          import java.util.Arrays;

          public class SortTask extends RecursiveAction {

              
          final static int ARRAY_LENGTH = 10000000;

              
          final static int THRESHOLD = 3000000;

              
          final int[] array;

              
          final int lo;

              
          final int hi;

              
          public SortTask(int[] array, int lo, int hi) {
                  
          this.array = array;
                  
          this.lo = lo;
                  
          this.hi = hi;
              }


              
          private void sequentiallySort(int[] array, int lo, int hi) {
                  
          int[] units = new int[hi - lo + 1];
                  
          for (int i = lo; i <= hi; i++)
                      units[i 
          - lo] = array[i];
                  Arrays.sort(units);
                  
          for (int i = lo; i <= hi; i++)
                      array[i] 
          = units[i - lo];
              }


              
          private void merge(int[] array, int lo, int mid, int hi) {

                  
          int[] units = new int[hi - lo + 1];
                  
          int i = lo;
                  
          int j = mid + 1;

                  
          for (int k = 0; k < units.length; k++{
                      
          if (array[i] <= array[j])
                          units[k] 
          = array[i++];
                      
          else if (array[i] > array[j])
                          units[k] 
          = array[j++];

                      
          if (i > mid)
                          
          for (int m = j; m <= hi; m++)
                              units[
          ++k] = array[m];
                      
          else if (j > hi)
                          
          for (int m = i; m <= mid; m++)
                              units[
          ++k] = array[m];
                  }


                  
          for (int k = lo; k <= hi; k++)
                      array[k] 
          = units[k - lo];

              }


              
          protected void compute() {
                  
          try {
                      
          if (hi - lo < THRESHOLD)
                          sequentiallySort(array, lo, hi);
                      
          else {
                          
          int mid = (lo + hi) >>> 1;
                          
          //System.out.println(mid);
                          forkJoin(new SortTask(array, lo, mid), new SortTask(array, mid + 1, hi));

                          merge(array, lo, mid, hi);
                      }

                  }
           catch (Throwable t) {
                      t.printStackTrace();
                  }

              }


              
          /**
               * 
          @param args
               
          */

              
          public static void main(String[] args) {
                  
          int[] sample = new int[ARRAY_LENGTH];

                  System.out.println(
          "Number of processor"
                          
          + Runtime.getRuntime().availableProcessors());
                  
                  Random seed 
          = new Random(47);

                  
          for (int i = 0; i < sample.length; i++{
                      sample[i] 
          = seed.nextInt();
                  }


                  
          long start = System.nanoTime();
                  Arrays.sort(sample);
                  
          long duration = System.nanoTime() - start;


                  System.out.println(
          "===============Sequential==================");
                  System.out.println(
          "Sorting takes " + duration + " to compelte");

                  
          int[] sample2 = new int[ARRAY_LENGTH];

                  
          for (int i = 0; i < sample2.length; i++{
                      sample2[i] 
          = seed.nextInt();
                  }


                  ForkJoinPool pool 
          = new ForkJoinPool(Runtime.getRuntime()
                          .availableProcessors());
                  SortTask st 
          = new SortTask(sample2, 0, sample2.length - 1);

                  start 
          = System.nanoTime();
                  pool.execute(st);
                  
          while (!st.isDone()) {
                  }

                  duration 
          = System.nanoTime() - start;

                  System.out.println(
          "===============ForkJoin==================");
                  System.out.println(
          "Sorting takes " + duration + " to compelte");
                  
              }


          }


          posted @ 2008-06-26 10:11 漢辰 閱讀(1320) | 評論 (2)編輯 收藏

          主站蜘蛛池模板: 从化市| 汶上县| 喀喇沁旗| 梁河县| 新巴尔虎左旗| 三明市| 甘南县| 肇东市| 邮箱| 五家渠市| 都兰县| 鸡西市| 伊宁市| 桃源县| 兰考县| 汪清县| 山东| 雅安市| 蒙城县| 银川市| 武胜县| 长岛县| 叶城县| 新昌县| 喀什市| 开鲁县| 凤凰县| 靖远县| 兴化市| 安龙县| 伊宁市| 南开区| 武清区| 云和县| 泰和县| 云浮市| 岳阳市| 固镇县| 苏州市| 中超| 丽江市|