正在顯示「 2020 年 2 月 」的所有結果
2月 24, 2020 MySQL
今天工作剛好要劃些少 ER 來告訴別人工程師,正在設計中的 Object 關係,所以記錄一下到這裏。

### 什麼是 ER Diagram
ER Diagram 可以用來描述 Database 內 Table (Entity) 和 Table 之間的關係 (Relation),當中有些符號是劃在連接線上的,用來表達關係。

### 連接線

我們可以使用連接線把兩個 Entity 連起來,並依照他們的關連數量來加入符號到兩端的線頭。

![](https://cdn.19site.net/files/59/f6/59f6c252-6054-4259-a2b8-04f0506e7c29.jpeg '常用到的線頭符號')

而整個 ER Diagram 大約就是這樣的 !

![](https://cdn.19site.net/files/11/bb/11bb5f15-de81-4323-b853-0880c36e1f8e.jpeg '用線把 Entity 關聯起來')

> 參考網址 : https://softwareengineering.stackexchange.com/questions/345709/erd-many-vs-zero-or-many-one-or-many-crowfoot-notation
2月 24, 2020 Java
### How to read a text file in Java?

In short, Scanner.

### Demo code

Code below showing how to use `Scanner` class to read a text file line by line in Java.

```java
try {
	
	// init file
	File mFile = new File("/root/example.txt");
	
	// init scanner
	Scanner mScanner = new Scanner(mFile);
	
	// while has next line
	while( mScanner.hasNextLine() ) {
		
		// get line string
		String mLine = mScanner.nextLine();

		// do something
	}

} catch ( FileNotFoundException e ) {
	
	// trace error
	e.printStackTrace()
}
```
2月 20, 2020 Netbeans
又是 NetBean 的問題了  !!!

這次遇到的是 Unpacking index for Central Repository on Netbeans ... 等了很久沒完沒了。安裝個 Dependencies 等到天荒地老了,而且間中還會不段的重新來 Transfer Index !! 真是惡夢 !!

於是又找了 GOOGLE 大神求救 !! 找到了以下的提問 :  
https://stackoverflow.com/questions/50933665/unpacking-index-for-central-repository-on-netbeans

看來大家都有遇到這個問題,經過筆者的了解後,筆者遇到的是 Run out of disk spaces ... 應該是 temp folder 的 Disk 用完空間了。( 筆者用的是 4GB Ram Drive) 結果要把 temp folder 指回去 C Drive 才能完成過程 ...

2月 20, 2020 Netbeans
今日遇到了一個有關於 NetBean 8.2 配上 Maven 的問題 ...

話說工作需要使用到 NetBean 8.2 ... 所以把原先有的 NetBean 11.2 砍掉了,找了個 NetBean 8.2 回來安裝,一切都很順利。直到要 Create Maven Web Application 就出事了。

### 事件一

```text
Cannot run program "cmd" (in directory "C:\projects\open"): Malformed argument has embedded quote: "C:\Program Files\NetBeans-11.1\netbeans\java\maven\bin\mvn.cmd"
```

每一次 Create Project 到了最後階段要 Finish 時,都會彈出這樣的問題。在網上查找了一會後發現都有很多人遇到了這個問題,大約是因為 Security Fix 所以有些動作變成不准許了,要解決的話可以修改一下 NetBean 的 Config 檔案。

1.	打開檔案  `<netbeans-dir>\etc\netbeans.conf`
2.	找出 `netbeans_default_options` 的設定
3.	把 `-J-Djdk.lang.Process.allowAmbiguousCommands=true` 加入到設定的後面

經過上面的動作,解決了上面的問題 !!

> 參考網站 : https://stackoverflow.com/questions/58411279/java-with-maven-wouldnt-build-cannot-run-program-cmd-malformed-argument-has

### 事件二

完後成上的事件後,Maven 好像運作得不錯地下載相依的檔案,突然又出現了第二個問題 !!

```text
[ERROR] No plugin found for prefix 'archetype' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Documents and Settings\ccen\.m2\repository), central (http://repo1.maven.org/maven2)] -> [Help 1]
```

又卡住了 !!! 這次的問題大約是因為 NetBean 在 Request http://repo1.maven.org/maven2 時出了問題。又在網上找了找看看有沒人遇到相同的問題,後快就找到了 !

> 參考網站 : https://stackoverflow.com/questions/6472782/mvn-archetypegenerate-does-not-work-no-plugin-found-for-prefix-archetype

內文有說到可能是因為 Firewall 等等因素,可以直接試試在 Browser 上貼上 http://repo1.maven.org/maven2 看看能否連上。筆者立即試一試,結果給了以下的回覆 !!

```text
501 HTTPS Required. 
Use https://repo1.maven.org/maven2/
More information at https://links.sonatype.com/central/501-https-required
```

原因是因為改用了 HTTPS 了,舊有的 HTTP 服務終結了。正當想看看能否改變 Maven2 的 URL 由 HTTP 如何變為 HTTPS 時,看到有其他使用者留言 :

![](https://cdn.19site.net/files/e1/95/e19579f2-544a-42bc-a45f-9c07afd61d30.png)

NetBean 8.2 或以下就會遇到這個問題了 ... 看來還是乖乖砍掉 NetBean 8.2 重新下載 NetBean 11.2 吧 ...

這文章就是在安裝 NetBean 11.2 時趁著等待的時間記錄下來 ...
2月 18, 2020 Android
### Android AsyncTask

今日收到一位同事問起,如果 HTTP Request 是多於一個時,要如何 Handle Progress 的生命週期 ?

雖然筆者沒有在網上再找找解決方法,不過以經驗去理解應該和處理一個 HTTP Request 也差不多,以下寫了一段 DEMO CODE 來實作這個事情 (沒有測試過能否運行的)。

另外也放到了 GIST :  
https://gist.github.com/19Site/39a6d1c40794de16dfd97f2da7ef9f16

### Demo Code

以下是 Demo Code

```java
public static void main(String... args) {

	AsyncTask<String, Integer, Boolean> task = new AsyncTask<String, Integer, Boolean>() {

		// loading dialog
		AlertDialog dialog = (new AlertDialog.Builder(context)).setCancelable(false).setMessage("loading").create();

		@Override
		protected Boolean doInBackground(String... strings) {

			publishProgress(1);
			doHttp1();

			publishProgress(2);
			doHttp2();

			publishProgress(3);
			doHttp3();

			publishProgress(4);
			return true;
		}

		@Override
		protected void onPostExecute(Boolean aBoolean) {

			super.onPostExecute(aBoolean);
			// todo
		}

		@Override
		protected void onProgressUpdate(Integer... values) {

			super.onProgressUpdate(values);

			switch (values[0]) {

				case 1:
					dialog.show();

				case 2:
				case 3:
					dialog.setMessage("progress " + values[0]);
					break;

				case 4:
				default:
					dialog.dismiss();
			}
		}

		private void doHttp1() {
			// do http request
		}

		private void doHttp2() {
			// do http request
		}

		private void doHttp3() {
			// do http request
		}
	};
}
```
2月 18, 2020 Network
Home Office 了一段時間因為有點 Server 問題回到公司去解決,但誰知道在沒有動 Server 一段時間後在連上 SSH 時發生問題 !!

### 發現問題

大約是因為這台 Server 的 Fingerprint 和先前連上時不同了,為了防止第三方的人士 "扮" 是連線目標的主機,所以引發這個問題。

```sh
$ ssh root@192.168.1.1
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:HDjXJcb0VYXWF+MCBDjSGn6FQmg/+x7vV0ljJvIDas0.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:46
ECDSA host key for 192.168.1.1 has changed and you have requested strict checking.
Host key verification failed.
```

說明了是 Host key changed

```sh
ECDSA host key for 192.168.1.1 has changed and you have requested strict checking.
Host key verification failed.
```

Host key Changed 可能有好多原因,最有可能是因為主網重新安裝了 ... 果然 ... 目標的伺服器是更新了。

### 解決方法

針對因為 Host Key Changed 的問題,只需要把本機的 Host Key 記錄清除。

```sh
$ ssh-keygen -R 192.168.1.1
```

這樣就可以把 `/root/.ssh/known_hosts` 的有關 `192.168.1.1` 的 Key 記錄清除,這樣下次連線是就會重新查問是否連線到 `192.168.1.1`。之後回答 `yes` 便可以了。
2月 10, 2020 19 Things
進入 2020 年的最大單事情,暫是應該是武漢肺炎對全球的影響了。對香港這邊影響很大呢 ... 農曆年後完全停課到現在。很多公司也選擇 Home Office 來繼續工作,每天的新聞也是一個一個的確診個案,待在家中 Home Office 久了真的在懷疑人生。

Home Office 不斷找舊的 Project 出來番新一下,及維護一下現有的系統。寫 Script 進行 Automation Backup 等動作,多出來的時間就做下 OU 功課 ...

電視台還天天播著沒用的飛機歌唱 x x 加油,還不如播多一點教大家洗手注意衛生好過。

希望疫情快點可以受控,病者早日康復 ... 這病毒感覺已經到了化武級數。
過去文章
2025 (9)
4 (5)
3 (1)
2 (3)
2024 (25)
11 (3)
10 (3)
9 (1)
3 (18)
2022 (6)
10 (1)
6 (2)
5 (1)
3 (1)
1 (1)
2021 (21)
11 (7)
7 (1)
6 (2)
5 (2)
4 (6)
3 (2)
2 (1)
2020 (92)
12 (1)
11 (2)
10 (4)
9 (10)
8 (5)
7 (1)
6 (3)
5 (1)
4 (4)
3 (25)
2 (7)
1 (29)
2019 (57)
12 (25)
11 (7)
9 (25)