Total Pageviews

2014/11/09

Failed to launch Eclipse after updated Mac OS Yosemite (10.10)

Problem
After I upgraded Mac OS Yosemite, I found out I cannot launch Eclipse correctly.

Solution
Please go to here to download Java for OS X 2014-001
http://support.apple.com/kb/DL1572?viewlocale=en_US&locale=en_US

After installed Java for OS X 2014-001, my Eclipse can startup correctly.

2014/11/07

JUnit Quick Start

Assume I has one utility class, which provide some services, including find employee name, find all employees, etc.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
public class MyUtils {  
  /**  
   * Checks for this employee.  
   *   
   * @param name  
   *      the name  
   * @return true if find data; false if find nothing  
   */  
  public static Boolean hasThisEmployee(final String name) {  
     Boolean hasData = Boolean.FALSE;  
     List strs = initData();  
     hasData = findData(name, hasData, strs);  
     return hasData;  
   }  
   /**  
    * Find employee.  
    *   
    * @param name  
    *      the name  
    * @return employee name if find; null if not find  
    */  
   public static String findEmployee(String name) {  
     Boolean hasData = Boolean.FALSE;  
     List strs = initData();  
     hasData = findData(name, hasData, strs);  
     String employee = null;  
     if(hasData) {  
       employee = name;  
     }  
     return employee;  
   }  
   /**  
    * Find all employee.  
    *   
    * @return list of String  
    */  
   public static List findAllEmployee(){  
     return initData();  
   }  
   /**  
    * Find employee.   
    *   
    * @param name  
    * @param hasData  
    * @param strs  
    * @return true if find data; false if find nothing  
    */  
   private static Boolean findData(final String name, Boolean hasData, List strs) {  
     Predicate predicate = new Predicate() {  
       @Override  
       public boolean apply(String input) {  
         return name.equalsIgnoreCase(input);  
       }  
     };  
     Iterator iterator = Collections2.filter(strs, predicate).iterator();  
     while (iterator.hasNext()) {  
       if (!Strings.isNullOrEmpty((String) iterator.next())) {  
         hasData = Boolean.TRUE;  
         break;  
       }  
     }  
     return hasData;  
   }  
   /**  
    *   
    * @return initial data  
    */  
   private static List initData() {  
     List strs = new ArrayList<>();  
     strs.add("Albert");  
     strs.add("Mandy");  
     strs.add("Eric");  
     return strs;  
   }  
 }  


If we would like to do unit test, this unit test class will demonstrate how to use assertSame, assertNotNull, and assertArrayEquals. 
All test methods are annotated with @Test

Here is a template for writing JUnit4-style tests:
package com.example.foo;

import static org.junit.Assert.assertEquals;

import org.junit.Test;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

/**
 * Tests for {@link Foo}.
 *
 * @author user@example.com (John Doe)
 */
public class FooTest {

    @Test
    public void thisAlwaysPasses() {

    }

    @Test
    @Ignore
    public void thisIsIgnored() {
    }
}

And we will demonstrate some assert methods, including

  • assertArrayEquals(java.lang.Object[] expecteds, java.lang.Object[] actuals) : 
    • Asserts that two object arrays are equal.
  • assertSame(java.lang.Object expected, java.lang.Object actual) :  
    • Asserts that two objects refer to the same object.
  • assertNotNull(java.lang.Object object) : 
    • Asserts that an object isn't null.
  • assertEquals(long expected, long actual) : 
    • Asserts that two longs are equal.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class FooTest {  
  /**  
   * Test assert same.  
   * The list includes Albert, Mandy, Eric, and Obama,  
   * it should return True if I use "Albert" to search  
   */  
  @Test  
  public void testAssertSame() {  
    assertSame(Boolean.TRUE, MyUtils.hasThisEmployee("Albert"));  
   }  
   /**  
    * Test assert not null.  
    * The list includes Albert, Mandy, Eric, and Obama,  
    * it should return not null if I use "Mandy" to search  
    */  
   @Test  
   public void testAssertNotNull() {  
     assertNotNull(MyUtils.findEmployee("Mandy"));  
   }  
   /**  
    * Test assert array equals.  
    * The list includes Albert, Mandy, Eric, and Obama,  
    * so it should return equal  
    */  
   @Test  
   public void testAssertArrayEquals() {  
     List strs = new ArrayList<>();  
     strs.add("Albert");  
     strs.add("Mandy");  
     strs.add("Eric");  
     assertArrayEquals(strs.toArray(), MyUtils.findAllEmployee().toArray());  
   }  
 } 

If all tests are executed as expected, then you will see success result


If some test does not execute as expected, then you will see fail result

Aggregating tests in suites
If you would like to run multiple test classes at the same time, you can do this way
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 import org.junit.runner.RunWith;  
 import org.junit.runners.Suite;  
 import org.junit.runners.Suite.SuiteClasses;  
 @RunWith(Suite.class)  
 @SuiteClasses({  
   FooTest.class,  
   FooTest2.class  
 })  
 public class TestSuite {  
    // the class remains empty,  
    // used only as a holder for the above annotations  
  }  
 

There are two test case class (FooTest.class, FooTest2.class) in the test suite. In the test result, you can see it will run all test cases in FooTest.class and FooTest2.class


Ignore Test
If for some reason, you just want it ignored, you temporarily disable a test. You just need to add @Ignore annotation
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
 public class FooTest2 {  
   @Test  
   @Ignore  
   public void testAssertEqual() {  
     assertEquals(36, MySecondUtils.getAge(1978));  
   }  
   @Test  
   public void testEquals() {  
     assertEquals("Pass", MySecondUtils.getExamResult(88));  
    }  
    @Test  
    public void testAssertThat() {  
      assertThat(MySecondUtils.getExamResult(88).equals("Pass"));  
    }  
  }  
 


See.... testAssertEqual method had been ignored.




Reference
[1] https://github.com/junit-team/junit/wiki

2014/11/01

[閱讀筆記] 理專不想告訴你的穩穩賺投資法


  1. 短期股價是無法預測的,只要長期持有一組股票組合,就會獲得該市場的績效。而主動式或被動式基金,就是一個投資組合,績效都會與市場差不多。只要經濟持續成長,績效就會長趨直上
  2. 挑選股票型基金時,我只挑經濟持續成長的區域,基金的績效的長期趨勢就會往上;債券型基金的挑選,我則是直接買全球型,避開開收益債,僅此而已
  3. 股票型基金的平均報酬較高,波動風險也較高;債券型基金的平均報酬率與波動風險都較低。我的建議是兩種基金都要投資,透過適當的配置,將風險控制在可承擔的範圍
  4. 因股票型基金的上漲,是來自於該投資區域的經濟成長,那麼我們投資股票型基金就很簡單了;不需要去判斷個股的基本面、股價會不會上漲,只要選擇經濟確定會成長的區域,長期持有基金就好
  5. 如果買的是全球股票型基金,遇到如金融海嘯的大跌,不僅不用停損,反而應該持續定期定額扣款,甚至用多餘資金加碼攤平。不只沒有躺平的風險,等下一波景氣回升,就能開始反彈獲利,時間越長,投資績效也會更穩定
  6. 升息時,債券的殖利率會跟著提高,債券價格則會降低;降息時,殖利率會降低,債券價格升高。這種連動關係,就是市場利率會影響債券價格波動的利率風險
  7. 複利的精神就是獲利再投入,如果買債券型基金,除非是有固定現金需求的退休人士,最好直接買累計型(不配息),讓基金的配息直接轉入淨值。因為若選擇配息型,投資部位就沒有以複利成長的效果
  8. 我建議的投資組合,是採取股票型基金及債券型基金的均衡配置,因為股票型基金屬於攻擊型資產,債券型基金則是防禦型,一攻一守互相搭配
  9. 景氣熱絡時,股票型基金淨值上揚,利率也會跟著走高,造成債券型基金下跌。當景氣衰退時,股票型基金淨值下跌,利率也跟著降低,債券型基金就會上漲。所以兩組基金在平均上下的波動,就會自動抵消
  10. 股票型基金的平均報酬較高,但是波動大;債券型基金剛好相反,平均報酬較低,但是波動較低。兩者的比重怎麼分配,主要看投資者自己的投資風險程度而定
  11. 持有一檔長期趨勢向上的基金,不需要進進出出,徒增成本。只要長期持有不停利,才能達到最高獲利。當然不停利,就要忍受波動的煎熬,但也只有能勇於承擔波動的投資者,才能成為最大的贏家
  12. 依據歷史經驗,股票的景氣週期約七年左右,一漲一跌約三年半,而債券的週期通常不超過兩年
  13. 當美國公債殖利率位處高點時,代表經濟景氣好,股票型基金通常已經長一段時間,是贖回好時機;同時,高殖利率的時候,則是購買債券型基金的好時機


2014/10/31

2014/10 Travel

億載金城

台南市移民署

四草紅樹林綠色隧道

台南林百貨

善化胡厝寮


鹿耳門天后宮


台南火車站

2014/10/29

How to read Excel file by Apache POI

Requirement
Assume we have an excel file, we would like to read the data which in sheet2.
We only need the amount in Column E and column I, and the value of Column A show be 'XXX年'

Here has sample code (focus on Line 17~33)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
public class POITest {  
  private final static Logger LOG = LoggerFactory.getLogger(POITest.class);  
  /**  
   * The main method.  
   *   
   * @param args  
   *      the arguments  
   * @throws IOException  
   *       Signals that an I/O exception has occurred.  
    */  
   public static void main(String[] args) throws IOException {  
     String testFile = "D:\\work\\ifms\\TestFiles\\4102294114W75Y7OW0.xls";  
     Integer sheetNum = 1;  
     FileInputStream file = null;  
     try {  
       file = new FileInputStream(new File(testFile));  
       // Get the workbook instance for XLS file  
       HSSFWorkbook workbook = new HSSFWorkbook(file);  
       // Get the specific sheet from the workbook  
       HSSFSheet sheet = workbook.getSheetAt(sheetNum);  
       // Get iterator to all the rows in current sheet  
       Iterator rowIterator = sheet.iterator();  
       List list = new ArrayList<>();  
       while (rowIterator.hasNext()) {  
         Row row = rowIterator.next();  
         if (StringUtils.indexOf(row.getCell(0).toString(), "年") > 0) {//condition  
           Test test = new POITest().new Test();  
           test.setYear(row.getCell(0).toString());//column A  
           test.setGdp(new BigDecimal(row.getCell(4).getNumericCellValue()));//column E  
           test.setGnp(new BigDecimal(row.getCell(8).getNumericCellValue()));//column I  
           list.add(test);  
         }  
       }  
       for (Test vo : list) {  
         LOG.debug("vo=" + vo.toString());  
       }  
     } catch (FileNotFoundException e) {  
       throw new RuntimeException(e);  
     } catch (IOException e) {  
       throw new RuntimeException(e);  
     } finally {  
       file.close();  
     }  
   }  
   private class Test {  
     private String year;  
     private BigDecimal gdp;  
     private BigDecimal gnp;  
     public String getYear() {  
       return year;  
     }  
     public void setYear(String year) {  
       this.year = year;  
     }  
     public BigDecimal getGdp() {  
       return gdp;  
     }  
     public void setGdp(BigDecimal gdp) {  
       this.gdp = gdp;  
     }  
     public BigDecimal getGnp() {  
       return gnp;  
     }  
     public void setGnp(BigDecimal gnp) {  
       this.gnp = gnp;  
     }  
     public String toString() {  
       return ToStringBuilder.reflectionToString(this);  
     }  
   }  
 } 

Here is the log which print in console
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
[main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@2d7349d7[year=80,gdp=4958220,gnp=5093770]  
[main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@6bf4d990[year=81,gdp=5534544,gnp=5655306]  
[main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@17f7b44f[year=82,gdp=6110101,gnp=6224145]  
[main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@75ebad4[year=83,gdp=6685505,gnp=6793022]  
[main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@5c3bb813[year=84,gdp=7277545,gnp=7388464]  
[main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@54b216b3[year=85,gdp=7906075,gnp=8015577]  
[main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@77f06d35[year=86,gdp=8574784,gnp=8664395]  
[main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@4991f017[year=87,gdp=9204174,gnp=9272725]  
[main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@c299bbd[year=88,gdp=9649049,gnp=9739567]  
 [main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@7faf9b87[year=89,gdp=10187394,gnp=10326952]  
 [main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@620bfd8e[year=90,gdp=9930387,gnp=10122411]  
 [main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@133a7ec[year=91,gdp=10411639,gnp=10654141]  
 [main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@66557791[year=92,gdp=10696257,gnp=11025130]  
 [main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@751d0513[year=93,gdp=11365292,gnp=11737391]  
 [main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@44385e76[year=94,gdp=11740279,gnp=12031145]  
 [main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@50c1b7f7[year=95,gdp=12243471,gnp=12555170]  
 [main] DEBUG g.n.e.w.c.Ets402rReportController - vo=gov.nta.ets.web.controller.Ets402rReportController$Test@5e14e28c[year=96,gdp=12910511,gnp=13243277] 

Reference
[1] http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/

2014/10/27

How to use Google Guava to do Collection Filter

Requirement

We have a collection data (List of value object), we would like to find the objects which fyr is 101. 
Here has the collection data:
1:  dtoList=[  
2:  gov.nta.fms.dto.FmsSumRateDto@1a395e5a[fyr=101,accmon=01,alc=168407392348.53,alcavg=0.0809],   
3:  gov.nta.fms.dto.FmsSumRateDto@2c617429[fyr=101,accmon=02,alc=164834284030.53,alcavg=0.0792],   
4:  gov.nta.fms.dto.FmsSumRateDto@32114682[fyr=101,accmon=03,alc=180965071697.53,alcavg=0.0869],   
5:  gov.nta.fms.dto.FmsSumRateDto@c2c1a7c[fyr=101,accmon=04,alc=165659472439.53,alcavg=0.0796],   
6:  gov.nta.fms.dto.FmsSumRateDto@237ec922[fyr=101,accmon=05,alc=180372232532.53,alcavg=0.0866],   
7:  gov.nta.fms.dto.FmsSumRateDto@58c6e962[fyr=101,accmon=06,alc=176357775471.53,alcavg=0.0847],   
8:  gov.nta.fms.dto.FmsSumRateDto@6b044e76[fyr=101,accmon=07,alc=187368376522.53,alcavg=0.09],   
9:  gov.nta.fms.dto.FmsSumRateDto@67bb5bdd[fyr=101,accmon=08,alc=181824695849.53,alcavg=0.0873],   
10:  gov.nta.fms.dto.FmsSumRateDto@3d8c3f5f[fyr=101,accmon=09,alc=170308922011.45,alcavg=0.0818],   
11:  gov.nta.fms.dto.FmsSumRateDto@4294958a[fyr=101,accmon=10,alc=168308032423.95,alcavg=0.0808],   
12:  gov.nta.fms.dto.FmsSumRateDto@28e5b92c[fyr=101,accmon=11,alc=179491195734.95,alcavg=0.0862],   
13:  gov.nta.fms.dto.FmsSumRateDto@1e00cae[fyr=101,accmon=12,alc=157844063362.95,alcavg=0.0758],   
14:  gov.nta.fms.dto.FmsSumRateDto@1c607478[fyr=102,accmon=01,alc=170969213258.95,alcavg=0.0806],   
15:  gov.nta.fms.dto.FmsSumRateDto@7e80d6[fyr=102,accmon=02,alc=159840653037.95,alcavg=0.0753],   
16:  gov.nta.fms.dto.FmsSumRateDto@713c61da[fyr=102,accmon=03,alc=169579370948.95,alcavg=0.0799],   
17:  gov.nta.fms.dto.FmsSumRateDto@333c694a[fyr=102,accmon=04,alc=169624940547.95,alcavg=0.0799],   
18:  gov.nta.fms.dto.FmsSumRateDto@4324938d[fyr=102,accmon=05,alc=173064277154.95,alcavg=0.0816],   
19:  gov.nta.fms.dto.FmsSumRateDto@1653306b[fyr=102,accmon=06,alc=169616844409.95,alcavg=0.0799],   
20:  gov.nta.fms.dto.FmsSumRateDto@2f8fcc40[fyr=102,accmon=07,alc=175060305269.95,alcavg=0.0825],   
21:  gov.nta.fms.dto.FmsSumRateDto@9aa9625[fyr=102,accmon=08,alc=193638114494.95,alcavg=0.0913],   
22:  gov.nta.fms.dto.FmsSumRateDto@1e675c18[fyr=102,accmon=09,alc=198567712906.95,alcavg=0.0936],   
23:  gov.nta.fms.dto.FmsSumRateDto@13cf3b40[fyr=102,accmon=10,alc=181427982270.95,alcavg=0.0855],   
24:  gov.nta.fms.dto.FmsSumRateDto@a3af0e9[fyr=102,accmon=11,alc=187353709301.95,alcavg=0.0883],   
25:  gov.nta.fms.dto.FmsSumRateDto@239e563e[fyr=102,accmon=12,alc=172980508042.95,alcavg=0.0815]  
26:  ]  


How to Use Google Guava API
1. Create Predicate instance to determines a true or false value for a given input. (Line1~Line7)
2. Utilize Collection2.filter to return the elements of unfiltered that satisfy a predicate.(Line8~line9)

Here has the code snippet:
1:     Predicate predicate = new Predicate() {  
2:        @Override  
3:        public boolean apply(FmsSumRateDto input) {  
4:          //Determines true or false value for a given input.  
5:          return "101".equqls(input.getFyr());  
6:        }  
7:      };  
8:      //Returns the elements of unfiltered that satisfy a predicate.  
9:      Iterator result = Collections2.filter(dtoList, predicate).iterator();  
10:      while(result.hasNext()) {  
11:        log.debug("result="+result.next().toString());  
12:      }  

Here is the result which statisfy the predicate:
1:  result=gov.nta.fms.dto.FmsSumRateDto@1a395e5a[fyr=101,accmon=01,alc=168407392348.53,alcavg=0.0809]  
2:  result=gov.nta.fms.dto.FmsSumRateDto@2c617429[fyr=101,accmon=02,alc=164834284030.53,alcavg=0.0792]  
3:  result=gov.nta.fms.dto.FmsSumRateDto@32114682[fyr=101,accmon=03,alc=180965071697.53,alcavg=0.0869]  
4:  result=gov.nta.fms.dto.FmsSumRateDto@c2c1a7c[fyr=101,accmon=04,alc=165659472439.53,alcavg=0.0796]  
5:  result=gov.nta.fms.dto.FmsSumRateDto@237ec922[fyr=101,accmon=05,alc=180372232532.53,alcavg=0.0866]  
6:  result=gov.nta.fms.dto.FmsSumRateDto@58c6e962[fyr=101,accmon=06,alc=176357775471.53,alcavg=0.0847]  
7:  result=gov.nta.fms.dto.FmsSumRateDto@6b044e76[fyr=101,accmon=07,alc=187368376522.53,alcavg=0.09]  
8:  result=gov.nta.fms.dto.FmsSumRateDto@67bb5bdd[fyr=101,accmon=08,alc=181824695849.53,alcavg=0.0873]  
9:  result=gov.nta.fms.dto.FmsSumRateDto@3d8c3f5f[fyr=101,accmon=09,alc=170308922011.45,alcavg=0.0818]  
10:  result=gov.nta.fms.dto.FmsSumRateDto@4294958a[fyr=101,accmon=10,alc=168308032423.95,alcavg=0.0808]  
11:  result=gov.nta.fms.dto.FmsSumRateDto@28e5b92c[fyr=101,accmon=11,alc=179491195734.95,alcavg=0.0862]  
12:  result=gov.nta.fms.dto.FmsSumRateDto@1e00cae[fyr=101,accmon=12,alc=157844063362.95,alcavg=0.0758] 


Reference


2014/10/23

要去哪裡查詢零股交易的相關資訊


有時候股票除了配現金以外,還會給零股給投資大眾,為了讓買賣比較容易(因為零股只能利用盤後交易),故通常會利用盤後交易來買零股湊成一張

我們如果要去查詢零股最佳一檔買、賣價格的話,可以到基本市況報導網站( http://mis.twse.com.tw/stock/oddTrade.jsp ) 查詢



 假設如果我要找的是『食品類股』,在上市類股下拉單選取『食品工業』

 該網站就會顯示相關食品類股的零股揭示買價、賣價、成交價以及成交股數


有關零股更多資訊可以參考 http://www.masterlink.com.tw/service/qanda/Q&A-6.htm 

2014/10/21

How to copy text from Notepad++ to Microsoft Word and keep its color to distinguish keywords


Notepad++ can distinguish between different languages source code can be written in. For example, a language could distinguish certain keywords that have to be differently interpreted, and as such it can be useful to distinguish these keywords using another color or font. 


For example.
The language is Java.

The language is SQL.


Scenario
If we would like to copy SQL statement from Notepad++ to Microsoft Word in my system design document, but it seems cannot keep its color to distinguish keywords. 
For example.

Resolution
Step1. Select text you would like to copy.

Step2. Plugins --> NppExport --> Copy RTF to clipboard

Step3. Paste text to Microsoft word


2014/10/16

How to display Tradition Chinese Character in Git Bash

Problem
Why I cannot display Tradition Chinese Character in Git Bash correctly?

Solution
You need to edit three files under git\etc

1. edit gitconfig file and append configuration as following:
1:  [gui]  
2:  encoding = utf-8   
3:  #log编码  
4:  [i18n]  
5:  commitencoding = utf-8   
6:  #支持中文路径  
7:  [svn]  
8:  pathnameencoding = utf-8   

2. edit git-completion.bash file and append configuration  as following:
1:  #正常顯示中文  
2:  alias ls='ls --show-control-chars --color=auto'  

3. edit inputrc file and append configuration  as following:
1:  #bash中可以正常输入中文  
2:  set output-meta on   
3:  set convert-meta off  

Check Result

2014/10/15

JRebel - Reload any changes without restart server

As a developer, we do not want to waste time to restart server again and again to see the implace of code changes.
You can try JRebel to save your time.

If you are using Eclipse, here has good step-by-step installation and configuration guide: http://manuals.zeroturnaround.com/jrebel/ide/eclipse.html

For more information, please check http://zeroturnaround.com/software/jrebel/learn/

Demo

Here has code snippet, and it will print debug message as entering this method
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
  @RequestMapping(value = "/query/tab1", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)  
  public @ResponseBody  
  List findTab1(@RequestBody Fms420rFormBean formBean, Alerter alerter) {  
    log.debug("test");  
    List dataList = service.queryTab1(formBean.getYear(), formBean.getMonth());  
    if (CollectionUtils.isEmpty(dataList)) {  
      alerter.info(Messages.warning_notFound());  
    } else {  
      alerter.info(Messages.success_find());  
     }  
     return dataList;  
   } 

And the console will print "test" debugging message as entering this method:
1:  19:15:45,493 INFO [stdout]  [20123] DEBUG gov.nta.fms.web.rest.Fms420rResource - test  

In order to test JRebel, I just modified the debug message to "JRebel test" and submit query without restart application server
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 @RequestMapping(value = "/query/tab1", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)  
 public @ResponseBody  
 List findTab1(@RequestBody Fms420rFormBean formBean, Alerter alerter) {  
   log.debug("JRebel test");  
   List dataList = service.queryTab1(formBean.getYear(), formBean.getMonth());  
   if (CollectionUtils.isEmpty(dataList)) {  
     alerter.info(Messages.warning_notFound());  
   } else {  
     alerter.info(Messages.success_find());  
    }  
    return dataList;  
  } 
 
See....I don't redeploy and restart application server, but the console print the up-to-date debug message. 
1:  19:16:19,742 INFO [stdout]  [20123] DEBUG gov.nta.fms.web.rest.Fms420rResource - JRebel test  

It's because of JRebel reload any changes classes automatically. 
When you change any class or resource in your IDE, the change will reflect in you application immediately, skipping the build and redeploy phases.




2014/10/14

How to find out the PID (process ID) of processes in Windows

Problem
If I would like to find out the PID of javaw.java proecess, how do I do?
Windows task manager seems does not have PID information.

Solution 1
View-->Selected Columns-->Checked PID-->OK

Then we can find out the PID information.


Solution 2
Open command prompt, and execute tasklist /fi "Imagename eq JAVAW.exe"
Then we can get the PID information
映像名稱                       PID 工作階段名稱      工作階段 #    RAM使用量
========================= ======== ================ =========== ============
javaw.exe                    10368 Console                    1  1,620,884 K



Reference

2014/10/01

[閱讀筆記] 拆開獲利的糖衣



  1. 債券價格的變動與利率負相關,利率上升,債券價格會下跌;利率下降,債券價格會上漲
  2. 短期投資來說,股票的波動大於債券。但是,若是拉長到30年,股票的波動只有債券的一半,但報酬好很多
  3. 波動是投資主要風險,但不是唯一風險。對許多長期投資者來說,如果採用波動不夠大的投資組合,這樣的投資成本長期看來會造成更大的壞處
  4. 多頭市場是在悲觀中生成,在懷疑中成長,在樂觀中成熟,在亢奮中消逝
  5. 股市是經濟的領先指標,投資人不會等經濟資料顯示經濟復甦才開始投資,他們會提前哄抬股價
  6. 如果你的投資期間很長,長期來說,由於貨幣升貶本質是零和、不規則的循環,貨幣對全球投資組合的影響會互相抵消,接近于零
  7. 貨幣的波動很大,長期來說,投資人很難掌握短期的市場時機,靠交易外匯獲利
  8. 如果每個人都在關注某一件事,你知道你可以放心忽略那件事,往別的方向看,關注大家沒注意的事,以及可能對未來市場走向有很大影響的事
  9. 衡量市場氛圍往往不是一種科學,反而更像藝術