Total Pageviews

2015/06/22

[egit] Fail to change branch from master to another

Problem
I want to change branch from master to another branch (i.e. WebcommUpload0618 )

But it failed to change branch via egit.
As I change branch again, but it show this error message:


The problem is there are some source belong to another branch but copy to master, because egit fail to do rollback. 

So it added some untracked files which belong to WebcommUpload0618 branch not master branch

Solution
1. use git status to list untracked files 
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
albert@ALBERT-PC /D/git/dbm (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        dbm-service/src/main/java/gov/nta/dbm/repository/Dbm091fbRepository.java
        dbm-service/src/main/java/gov/nta/dbm/repository/impl/Dbm091fbRepositoryImpl.java
        dbm-service/src/main/java/gov/nta/dbm/service/Dbm016rService.java
        dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData1Vo.java
        dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData2Vo.java
        dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData3Vo.java
        dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData4Vo.java

nothing added to commit but untracked files present (use "git add" to track)

2. use git clean -n to list the files which will be removed
1
2
3
4
5
6
7
8
9
albert@ALBERT-PC /D/git/dbm (master)
$ git clean -n
Would remove dbm-service/src/main/java/gov/nta/dbm/repository/Dbm091fbRepository.java
Would remove dbm-service/src/main/java/gov/nta/dbm/repository/impl/Dbm091fbRepositoryImpl.java
Would remove dbm-service/src/main/java/gov/nta/dbm/service/Dbm016rService.java
Would remove dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData1Vo.java
Would remove dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData2Vo.java
Would remove dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData3Vo.java
Would remove dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData4Vo.java

3. use git clean -f to remove files
1
2
3
4
5
6
7
8
9
albert@ALBERT-PC /D/git/dbm (master)
$ git clean -f
Removing dbm-service/src/main/java/gov/nta/dbm/repository/Dbm091fbRepository.java
Removing dbm-service/src/main/java/gov/nta/dbm/repository/impl/Dbm091fbRepositoryImpl.java
Removing dbm-service/src/main/java/gov/nta/dbm/service/Dbm016rService.java
Removing dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData1Vo.java
Removing dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData2Vo.java
Removing dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData3Vo.java
Removing dbm-service/src/main/java/gov/nta/dbm/vo/Dbm016rData4Vo.java

After cleaning untracking files, then I can change granch succesfully

Reference
[1] https://ihower.tw/git/basic.html

2015/06/21

經常項目(recurrent items) vs 非經常項目(nonrecurrent items)

Security Analysis 一書中提到,依據個人情感、情緒所做的交易,通常都是錯誤的投資行為。你應該仔細去研讀投資標的的income statement (損益表)與balance sheet (資產負債表)。

當你在研讀income statement (損益表)時,要注意到經常項目(recurrent items)與非經常項目(nonrecurrent items)的區別。經常項目(recurrent items)代表是持續性的獲得或損失(或稱之為營業內)非經常項目(nonrecurrent items)代表偶然性的獲得或損失(或稱之為營業外)

舉個例子來說,以下圈選起來的項目,就屬於經常項目(recurrent items)

以下圈選起來的項目,屬於非經常項目(nonrecurrent items)



以某間公司作為另外一個例子,2013的EPS突然從去年的1.47成長到2.63,但是細究其利潤結構,發現原來是2013年有出現鉅額的非經常項目獲利所導致,並非本業有大幅成長


由以上例子可以得知,在研究公司的獲利能力時,不僅要看公司的利潤金額,還要看公司的利潤結構,區分利潤中哪些是可以持續獲得的,哪些是偶然獲得的。要把數字往下drill down分析,而不是只看表面的數字

Reference
[1] http://www.cmoney.tw/finance/f00041.aspx?s=2412

[Programming] 富含資訊的名稱

最近閱讀了易讀程式之美一書,在富含資訊的名稱此章節提到幾個重點

  1. 程式碼應該易於理解
  2. 撰寫程式時,應該將讀者理解所需的時間降到最短
  3. 雖然減少程式碼數量是個很好的目標,但縮短理解時間更加重要
  4. 實務上,讓程式碼易於了解,往往也會產生良好的架構且易於測試
  5. 無論是重新命名變數、函數或類別,基本原則大同小異。名稱可視為簡短的註解,即使空間有限,透過選擇好的名稱就能包含許多資訊
  6. retval這類名稱不包含任何有意的資訊,只能代表return value,應該使用能夠說明便數值意義的名稱
  7. tmp這樣的名稱,只適用於變數生命週期很短,且作為暫存用途的變數
  8. 變數名稱不宜太長,名稱愈長就愈不容易記住,也會佔用更多畫面空間,甚至造成額外的自動換行


Example

1. 避免使用rtnVal,應給予有意義的名稱

以下是原本的寫法
1
2
3
4
5
Double rtnVal = 0d;
for (int i = 0; i < input; i++) {
 rtnVal += i * i;
}
return Math.sqrt(rtnVal);

以下是修改後的寫法,讓名稱具有意義
1
2
3
4
5
Double sumSquares = 0d;
for (int i = 0; i < input; i++) {
 sumSquares += i * i;
}
return Math.sqrt(sumSquares);

2. 避免使用tmp

以下是原本的寫法
1
2
3
4
5
public String demoForBadExample2(User user) {
 String tmp = user.getName();
 tmp += " " + user.getEmail();
 return tmp;
}

以下是修改後的寫法,userInfo比tmp傳達更多資訊
1
2
3
4
5
public String demoForGoodEaxmple2(User user) {
 String userInfo = user.getName();
 userInfo += " " + user.getEmail();
 return userInfo;
}

3. for-loop避免用 i, j, k 這樣的變數,尤其在nested loop你會改不清楚誰是誰

以下是原本的寫法
1
2
3
4
5
public void demoForBadExample3(List<User> users) {
 for (int i = 0; i < users.size(); i++) {
  System.out.println(users.get(i).toString());
 }
}


以下是修改後的寫法
1
2
3
4
5
public void demoForGoodExample3(List<User> users) {
 for (int user_i = 0; user_i < users.size(); user_i++) {
  System.out.println(users.get(user_i).toString());
 }
}



2015/06/18

[Microsoft Outlook] reading pane had been disabled

Problem
One day I found out my reading panel had been disabled in Microsoft Outlook.

It is very inconvenient for me, because I cannot preview my email anymore.

Root Cause
Because of corporate's security policy, it disabled all employees' reading panel in everyone's Microsoft Outlook.

Solution
1. Start => type in "regedit" => enter

2. Find the registry : HKEY_CURRENT_USER\Software\Policies\Microsoft\office\14.0\Outlook\options

3. Change the value of property, disablereadingpane, from 1 to 0
4. Restart Microsoft Outlook


Reference
[1] http://www.slipstick.com/outlook/rules/disable-outlooks-reading-pane/



JoSQL (SQL for Java Objects)

Requirement
If I have a Java collection as bellows:
1
2
3
Employee [empNo=1, name=Albert, gender=M, onBoardDate=Thu Feb 05 15:20:44 CST 2009]
Employee [empNo=2, name=Mandy, gender=null, onBoardDate=Fri Mar 05 15:20:44 CST 2010]
Employee [empNo=3, name=Verio, gender=M, onBoardDate=Thu Feb 05 15:20:44 CST 2009]

If I would like to utilize SQL statements to do search, which tool can help me?

Solution
JoSQL (SQL for Java Objects) provides the ability for a developer to apply a SQL statement to a collection of Java Objects. 
JoSQL provides the ability to search, order and group ANY Java objects and should be applied when you want to perform SQL-like queries on a collection of Java Objects.

Prerequisite
Configure the two jar files in your classpath:


Example
In this example, it will demonstrate:
  • find all employee objects
  • find all male employee objects
  • find employee objects which named "Mandy"
  • find all male employee object which onBoardDate between 2009/01/01 to 2009/12/31
  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
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package test;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

import org.josql.Query;
import org.josql.QueryExecutionException;
import org.josql.QueryParseException;
import org.josql.QueryResults;

import test.vo.Employee;

/**
 * The Class JoSqlTest.
 */
public class JoSqlTest {

    private List<Employee> employees = new ArrayList<Employee>();

    /**
     * The main method.
     * 
     * @param args
     *            the arguments
     */
    public static void main(String[] args) {
        JoSqlTest test = new JoSqlTest();
        test.setupData();
        test.findAllEmployees();
        test.findAllMaleEmployees();
        test.findByEmployeeName("Mandy");
        test.findByGenderAndOnBoardDate("M", "2009/01/01", "2009/12/31");
    }

    /**
     * Select all employees.
     */
    public void findAllEmployees() {
        System.out.println("\n * find all employees");

        String sql = "select * from test.vo.Employee";

        // Create a new Query.
        Query query = new Query();
        try {
            // Parse the SQL you are going to use.
            query.parse(sql);

            // Execute the query.
            QueryResults qr = query.execute(employees);

            // Get the query results.
            List<Employee> result = qr.getResults();

            // Print search research
            for (Employee employee : result) {
                System.out.println(employee.toString());
            }

        } catch (QueryParseException e) {
            throw new RuntimeException(e);
        } catch (QueryExecutionException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Select all male employees.
     */
    public void findAllMaleEmployees() {
        System.out.println("\n * find all male employees");

        String sql = "select * from test.vo.Employee where gender = :gender";

        // Create a new Query.
        Query query = new Query();
        try {
            // Parse the SQL you are going to use.
            query.parse(sql);

            // set variable
            query.setVariable("gender", "M");

            // Execute the query.
            QueryResults queryResults = query.execute(employees);

            // Get the query results.
            List<Employee> result = queryResults.getResults();

            // Print search research
            for (Employee employee : result) {
                System.out.println(employee.toString());
            }

        } catch (QueryParseException e) {
            throw new RuntimeException(e);
        } catch (QueryExecutionException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Find by employee name.
     * 
     * @param name
     *            the name
     */
    public void findByEmployeeName(String name) {

        System.out.println("\n * find by employee name");

        String sql = "select * from test.vo.Employee where name = :name";

        // Create a new Query.
        Query query = new Query();
        try {
            // Parse the SQL you are going to use.
            query.parse(sql);

            // set variable
            query.setVariable("name", name);

            // Execute the query.
            QueryResults queryResults = query.execute(employees);

            // Get the query results.
            List<Employee> result = queryResults.getResults();

            // Print search research
            for (Employee employee : result) {
                System.out.println(employee.toString());
            }

        } catch (QueryParseException e) {
            throw new RuntimeException(e);
        } catch (QueryExecutionException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Find by gender and on board date.
     * 
     * @param gender
     *            the gender
     * @param fromDate
     *            the from date
     * @param toDate
     *            the to date
     */
    public void findByGenderAndOnBoardDate(String gender, String fromDate, String toDate) {
        System.out.println("\n * find By Gender And OnBoardDate");

        String sql = "select * from test.vo.Employee where gender = :gender "
                + " and onBoardDate between :fromDate and :toDate ";
        // Create a new Query.
        Query query = new Query();
        try {
            // Parse the SQL you are going to use.
            query.parse(sql);

            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
            // set variable
            query.setVariable("gender", gender);
            query.setVariable("fromDate", dateFormat.parse(fromDate));
            query.setVariable("toDate", dateFormat.parse(toDate));

            // Execute the query.
            QueryResults queryResults = query.execute(employees);

            // Get the query results.
            List<Employee> result = queryResults.getResults();

            // Print search research
            for (Employee employee : result) {
                System.out.println(employee.toString());
            }

        } catch (QueryParseException e) {
            throw new RuntimeException(e);
        } catch (QueryExecutionException e) {
            throw new RuntimeException(e);
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

    /**
     * Setup data.
     */
    public void setupData() {
        System.out.println("\n * setup data");

        Employee albert = new Employee();
        albert.setEmpNo(1L);
        albert.setName("Albert");
        albert.setGender("M");
        Calendar cal1 = Calendar.getInstance();
        cal1.set(Calendar.YEAR, 2009);
        cal1.set(Calendar.MONTH, 1);
        cal1.set(Calendar.DATE, 5);
        albert.setOnBoardDate(cal1.getTime());

        Employee mandy = new Employee();
        mandy.setEmpNo(2L);
        mandy.setName("Mandy");
        Calendar cal2 = Calendar.getInstance();
        cal2.set(Calendar.YEAR, 2010);
        cal2.set(Calendar.MONTH, 2);
        cal2.set(Calendar.DATE, 5);
        mandy.setOnBoardDate(cal2.getTime());

        Employee verio = new Employee();
        verio.setEmpNo(3L);
        verio.setName("Verio");
        verio.setGender("M");
        Calendar cal3 = Calendar.getInstance();
        cal3.set(Calendar.YEAR, 2009);
        cal3.set(Calendar.MONTH, 8);
        cal3.set(Calendar.DATE, 10);
        verio.setOnBoardDate(cal1.getTime());

        employees.add(albert);
        employees.add(mandy);
        employees.add(verio);
    }

}


Console:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
 * setup data

 * find all employees
Employee [empNo=1, name=Albert, gender=M, onBoardDate=Thu Feb 05 16:00:48 CST 2009]
Employee [empNo=2, name=Mandy, gender=null, onBoardDate=Fri Mar 05 16:00:48 CST 2010]
Employee [empNo=3, name=Verio, gender=M, onBoardDate=Thu Feb 05 16:00:48 CST 2009]

 * find all male employees
Employee [empNo=1, name=Albert, gender=M, onBoardDate=Thu Feb 05 16:00:48 CST 2009]
Employee [empNo=3, name=Verio, gender=M, onBoardDate=Thu Feb 05 16:00:48 CST 2009]

 * find by employee name
Employee [empNo=2, name=Mandy, gender=null, onBoardDate=Fri Mar 05 16:00:48 CST 2010]

 * find By Gender And OnBoardDate
Employee [empNo=1, name=Albert, gender=M, onBoardDate=Thu Feb 05 16:00:48 CST 2009]
Employee [empNo=3, name=Verio, gender=M, onBoardDate=Thu Feb 05 16:00:48 CST 2009]

Reference
[1] http://josql.sourceforge.net/

2015/06/01

[閱讀筆記] 問題不能拆開來看

  1. 核心問題會一直存在的理由,是因為過去曾採取的矯正行動,導致其他不良效應
  2. 夏目漱石:過於理智,容易與人摩擦;順從感情,易遭情緒左右;固持己見,終至窮途末路。總而言之,人世難以安居
  3. 所謂的問題,就是目標與現況之間的落差、預期與實際之間的落差
  4. Edwards Deming曾說:品質是生產流程中創造出來的。然而,利潤是流程產生的結
  5. 達爾文曾說:能生存下來的物種,既非最強,也非最具智慧,而是那些最能適應變化的物種  
  6. 唯有提出正確的質問,才能導出正確的解決對策
  7. 在進行成本削減活動的情況下,又針對各個專案的個別損益狀況進行績效評量,開會次數與報告書就會變多,因此最重要的工作反而無法進行。而且工作場所的工作氣氛若變得惡劣,員工的工作動機也會跟著下降
  8. 正確的定義問題,問題就解決了一半
  9. 所謂的策略,是對於"為何而作"的疑問提供解答;所謂的戰術,是對於"怎麼去做"的疑問提供解答
  10. 組織越大,最高決策階層與第一線的工作人員溝通鴻溝越大,導致第一線人員搞不清楚高層的策略與戰術,不知為何而戰
  11. 凡人會從自己的失敗中學習,賢人會從他人的失敗中學習
  12. 不做給對方看、不說給對方聽、不讓對方嘗試、不誇獎對方、人則不為所動
  13. 限制理論有五大核心步驟:
    1. 找出系統中存在哪些限制
    2. 尋找突破這些限制的辦法
    3. 突破限制的措施將優先於系統的所有其他活動
    4. 具體實施步驟二提出的措施,使步驟一找出的限制不再是約束企業
    5. 回到步驟一,持續尋找、改善限制,謹防惰性成為系統的約束

[Git] Why is the egit merge tool disabled in Eclipse

Problem
After I create a merge request in GitLab, GitLab remind me this branch cannot be merged automatically.

As I open context menu from my project and try to resolve conflict issues, select Team --> Merge. But the menu option had been disabled.


Solution
1. Change to Git perspective. Branches => Remote Tracking => origin/master

2. Open context menu => Synchronize with Workspace

3. The conflict list is the source code which had been marked red.























4. Fix the foregoing conflict problems and open context menu => Marked as Merged

5. After fixed conflict problems, then push and commit to master again.