跳到主要內容

發表文章

目前顯示的是 12月, 2017的文章

計算 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...