跳到主要內容

發表文章

Ubuntu 常用指令

id - 查詢使用者權限 id jerry uid=1003(jerry) gid=1004(jerry) groups=1004(jerry) ... 查詢檔案權限 getfacl getfacl docker-compose # file: docker-compose # owner: root # group: root user::rw- group::r-- other::r-- ls ls -al drwxr-xr-x 2 root root 4096 Jan 11 02:26 . drwxr-xr-x 10 root root 4096 Dec 12 14:21 .. -rw-r--r-- 1 root root 8479184 Jan 11 02:26 docker-compose chown - 更改檔案擁有者 chown UserName FileName chgrp - 更改檔案群組 系統的群組都紀錄在 /etc/group 檔案內 chgrp UserName FileName chmod - 修改權限 # a : 全部 user # u : 目前檔案的 owner # g : 目前檔案的 group # o : 其他 # + : 給予 # - : 移除 # = : 設定 # r : 讀 # w : 寫 # x : 執行 chmod [a/u/g/o] [+/-/=] [r/w/x] FileName # 讓所有 user 可以執行這個 File chmod a+x FileName tar - 壓縮, 解壓縮 # -z : 透過 gzip 的支援進行壓縮/解壓縮:此時檔名最好為 *.tar.gz # -cv : 建立打包檔案,可搭配 -v 來察看過程中被打包的檔名(filename) # -f FileName : 後面要立刻接要被處理的檔名!建議 -f 單獨寫一個選項囉!(比較不會忘記) # -x : 解打包或解壓縮的功能,可以搭配 -C (大寫) 在特定目錄解開, -c, -t, -x 不可同時出現在一串指令列中。 壓縮 tar -zcv -f FileName.tar.gz DirName 解壓縮 tar -zxv -f FileName.tar.gz which - 查詢指令所在位置 ...

計算 Mysql database 大小

計算 Mysql database 大小 參考: https://www.mkyong.com/mysql/how-to-calculate-the-mysql-database-size/ Sql SELECT TABLE_SCHEMA, SUM(DATA_LENGTH + INDEX_LENGTH)/1024/1024 "DATA_SIZE(MB)" FROM information_schema.TABLES GROUP BY TABLE_SCHEMA; GROUP BY 可以替換成 WHERE TABLE_SCHEMA= your-data-base-name SELECT TABLE_SCHEMA, SUM(DATA_LENGTH + INDEX_LENGTH)/1024/1024 "DATA_SIZE(MB)" FROM information_schema.TABLES WHERE TABLE_SCHEMA=erp; LENGTH(str) 用途 參考:https://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_length Returns the length of the string str, measured in bytes. A multibyte character counts as multiple bytes. This means that for a string containing five 2-byte characters, LENGTH() returns 10, whereas CHAR_LENGTH() returns 5. 簡單翻譯 LENGTH() 會計算 string 的 byte. SELECT LENGTH('hello_world') # 回傳 11 計算 all table 某個欄位大小 SELECT SUM(LENGTH(`column_name`)) FROM table_name WHERE id = 1234567; 計算 one raw data 大小 SELECT (LENGTH(`id`) + LENGTH(`column_1`)...

Parse URI query string to Key Value

Parse URI query String to Map 做 urlDecode 處理 沒有任何 query String 回傳 Empty Map 確保只處理 key-value 結構的 query String package com.example.util; import lombok.extern.slf4j.Slf4j; import org.apache.http.client.utils.URIBuilder; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLDecoder; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; /** * Created by jerry on 2017/12/28. * * @author jerry */ @Slf4j public class UriUtil { private UriUtil() { } public static Map splitQuery(final String uri) { Map queryPairs = new LinkedHashMap (); try { final URI uri = new URIBuilder(uri).build(); final String rawQuery = uri.getRawQuery(); log.info("CurrentUrl Query: {}", rawQuery); // 過濾沒有 query string // 還有過濾無法成對 keyValue 的 query, e.g. http://host/path?123 if (Objects.isNull(rawQuery) |...

gcloud config 快速切換專案

快速參考 https://cloud.google.com/sdk/gcloud/reference/config/ gcloud config 建立 Step1. 建立設定檔, gcloud config configurations create $ gcloud config configurations create your_config_name Step2. gcloud init 會有引導, 協助建立 gcloud config 細節(mapping project name, region, etc.) $ gcloud init gcloud config 切換 $ gcloud config configurations activate your_config_name

Java split empty strings

Sample Code String str = "a,b,c,,"; String[] ary = str.split(","); // result 3 System.out.println(ary.length); 在 code review 的時候發現一個有趣的狀況, 在 split(",") 處理完, 預期結果應該是 5 , 然而實際上卻是 3 , 查了一下 API 發現 public String[] split(String regex) 要求的參數其實是 regrex express, 這有可能導致 IndexOutOfBoundException , 建議改為 public String[] split(String regex, int limit) limit 用來限制 array 的長度, 如果 limit > 0, 最終處理的 array 長度不會大於 limit, regex express 匹配的次數最多為 n - 1 次, 如果 limit 空字串 匹配的問題, 如果 limit = 0, regex express 會儘可能地處理匹配, 但會放棄處理 空字串 匹配的問題。 參考: API Doc Sample Code String str = "a,b,c,,"; String[] ary = str.split(",", -1); // result 5 System.out.println(ary.length);

TDD 測試驅動開發的看法

測試驅動開發(TDD)引發的爭論 這是一篇來自於 import new 的探討: 測試驅動開發(TDD)引發的爭論 , 還有 Kent Beck 在 StackOverFlow 的解釋: I get paid for code that works, not for tests, so my philosophy is to test as little as possible to reach a given level of confidence (I suspect this level of confidence is high compared to industry standards, but that could just be hubris). If I don't typically make a kind of mistake (like setting the wrong variables in a constructor), I don't test for it. I do tend to make sense of test errors, so I'm extra careful when I have logic with complicated conditionals. When coding on a team, I modify my strategy to carefully test code that we, collectively, tend to get wrong. Different people will have different testing strategies based on this philosophy, but that seems reasonable to me given the immature state of understanding of how tests can best fit into the inner loop of coding. Ten or twenty years from now we'll likely have a more universal theory of which tests to write...

React Js 第一步

Atom 突然想學 ES6, 所以開始研究了 Atom, 先參考別人的設定。 Reference: https://github.com/farrrr/atom Plugins Theme 簡單地用了 atom 預設的 atom-dark-ui , 其他的 plugins 雖然介紹很多, 但還是覺得先不要用太多妖魔鬼怪, 避免分散力氣去解決地雷。 ReactJS Framework 就單純的隨便找一個 Framework 來當作起手, 訴求是學習資源多的 Framework, Vue.js 好像也不錯。 ReactJS HelloWorld # 使用 nvm 切換到 stable 的 node.js 版本 $ nvm use stable # 在 global 安裝 create-react-app module $ npm install -g create-react-app # 建立 react-hello-world 專案 $ create-react-app react-hello-world # 在 local 啟動專案 $ cd react-hello-world $ yarn start Preview