Tech

別名演算法 Alias Method

 題目 每個伺服器支援不同的 TPM (transaction per minute) 當 request 來的時候, 系統需要馬上根據 TPM 的能力隨機找到一個適合的 server. 雖然稱為 "隨機", 但還是需要有 TPM 作為權重. 解法 別名演算法(Alias Method)是一種有效率地...

別名演算法 Alias Method

 題目 每個伺服器支援不同的 TPM (transaction per minute) 當 request 來的時候, 系統需要馬上根據 TPM 的能力隨機找到一個適合的 server. 雖然稱為 "隨機", 但還是需要有 TPM 作為權重. 解法 別名演算法(Alias Method)是一種有效率地...

Java Class Loader 與 Maven Shade Plugin

ChatGPT generated  Java Class Loader 是 Java Runtime Environment 的一部分,它動態地將 Java 類別加載到 Java Virtual Machine 中。通常,只有在需要時才會加載類別。Java 運行時系統不需要知道文件和文件系統,因為...

Java Class Loader 與 Maven Shade Plugin

ChatGPT generated  Java Class Loader 是 Java Runtime Environment 的一部分,它動態地將 Java 類別加載到 Java Virtual Machine 中。通常,只有在需要時才會加載類別。Java 運行時系統不需要知道文件和文件系統,因為...

Scrum Note

ChatGPT generated  Scrum 是一種敏捷軟體開發的框架,它的核心包含了三個支柱 (Pillars)、五個價值觀 (Values) 和十個原則 (Principles)。 三個支柱 (Pillars) 包括: 透明度 (Transparency):所有的工作都必須對所有人可見,這...

Scrum 筆記

ChatGPT generated  Scrum 是一種敏捷軟體開發的框架,它的核心包含了三個支柱 (Pillars)、五個價值觀 (Values) 和十個原則 (Principles)。 三個支柱 (Pillars) 包括: 透明度 (Transparency):所有的工作都必須對所有人可見,這...

Java GC Note

Referencehttps://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/cms.htmlhttps://www.oracle.com/technical-resources/articles/java/g1gc.htmlhttps:/...

Java GC 筆記

參考資料https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/cms.htmlhttps://www.oracle.com/technical-resources/articles/java/g1gc.htmlhttps://wiki...

新團隊快速貢獻

前篇分工不設限前言自從開始與新團隊合作後, 產品也即將 GA release. GA 之後又會有新的不同的挑戰. 在新挑戰之前, 是時候紀錄一下這段時間發生的事情.挑戰產品本身由於架構改變加上優化, 整個 backend 幾乎全部改寫, 而且加上支援 HA. 有大量還沒經過 QA 驗證的程式 (全部改寫, 都只有...

新團隊快速貢獻

前篇分工不設限前言自從開始與新團隊合作後, 產品也即將 GA release. GA 之後又會有新的不同的挑戰. 在新挑戰之前, 是時候紀錄一下這段時間發生的事情.挑戰產品本身由於架構改變加上優化, 整個 backend 幾乎全部改寫, 而且加上支援 HA. 有大量還沒經過 QA 驗證的程式 (全部改寫, 都只有...

Dependency Inversion Principle 避免過度依賴外部

IntroductionDIP 應該很常見, 只是常常在談的時候會發現大家忘記了. 因此特別紀錄一下使用 DIP 實質上的好處.Assumption我們大多會希望 business logic code 可以乾淨穩定有乾淨穩定的 business logic code, 就可以寫穩定的 unit test cod...

Dependency Inversion Principle 避免過度依賴外部

簡介DIP 應該很常見, 只是常常在談的時候會發現大家忘記了. 因此特別紀錄一下使用 DIP 實質上的好處.假設我們大多會希望 business logic code 可以乾淨穩定有乾淨穩定的 business logic code, 就可以寫穩定的 unit test code如此未來商業邏輯有改變的時候, 如...

Spring Cloud Stream Introduction - 1

Goal 描述如何套用 spring cloud stream + Kafka 以及概念.適合只面對 Kafka, 不涵蓋進階議題 Example https://github.com/axxdeveloper/study-practice/tree/spring-cloud-stream Concepts ...

Spring Cloud Stream 入門 - 1

目標 描述如何套用 Spring Cloud Stream + Kafka 以及概念.適合只面對 Kafka, 不涵蓋進階議題 範例 https://github.com/axxdeveloper/study-practice/tree/spring-cloud-stream 概念 一個 applicatio...

分工不設限

  前言 去年一些巧合, 跟團隊幾個人接手一個案子, 這個案子原本算是服務客戶特定需求的 POC, 但由於客戶愈來愈依賴這個工具, 因此交到我們手上. PS. 在我加入之前, 已經有人辛苦耕耘了好一陣子. 不過也因緣際會離開這個案子. 一個案子要成功, 從來不是誰可以獨立勝任. 享受合作的當下, 同時...

分工不設限

  前言 去年一些巧合, 跟團隊幾個人接手一個案子, 這個案子原本算是服務客戶特定需求的 POC, 但由於客戶愈來愈依賴這個工具, 因此交到我們手上. PS. 在我加入之前, 已經有人辛苦耕耘了好一陣子. 不過也因緣際會離開這個案子. 一個案子要成功, 從來不是誰可以獨立勝任. 享受合作的當下, 同時...

應用 XOR 特性取出相字元或數字

XOR 的特性, 相同的值 XOR 會變成 0 0^0=01^0=10^1=11^1=0// codeint n = 0;for (int i = 0; i < 10000; i++) {    n ^= i;}for (int i = 0; i < 10000; i++) {&n...

Explain - LeetCode 525 Contiguous Array

題目: Given a binary array nums, return the maximum length of a contiguous subarray with an equal number of 0 and 1解法:當遇到 0 就 -1, 遇到 1 就 +1, 計算每個陣列位置的加總最重...

解題 - LeetCode 525 Contiguous Array

題目: 給定一個二元陣列 nums,回傳包含相同數量 0 和 1 的最長連續子陣列長度解法:當遇到 0 就 -1, 遇到 1 就 +1, 計算每個陣列位置的加總最重要的概念就是: 當遇到相同的加總數字, 表示中間經歷了相同的 1 & 0.因此解法就是:走過所有的陣列, 計算每個位子的 count...

PostgreSQL 版本 Schema 效能比較

需求 開發者持續發布新軟體,版本格式是 {major}.{minor}.{micro}.{build}當裝置詢問升級資訊時,我們需要找出最新的軟體版本但不只是最新的版本,我們可能還需要知道以下版本資訊,才能提供適合的建議是否有 3 個更新的軟體版本?有多少更新的軟體版本? 挑戰 資料庫用「自然排序」來排文字這兩...

Kafka - Pick a transaction.id

Intention: Why I need Kafka Transaction需求中收到 message 並處理之後, application 需要另外傳送訊息出去給多個 topic.不管遇到任何錯誤, 我都希望訊息就不要送出去.除此之外, 原本 consume 的訊息也不要收下來How it worksProd...

Kafka - 選擇 transaction.id

動機:為什麼我需要 Kafka Transaction需求中收到 message 並處理之後, application 需要另外傳送訊息出去給多個 topic.不管遇到任何錯誤, 我都希望訊息就不要送出去.除此之外, 原本 consume 的訊息也不要收下來運作方式Producer 用 transaction.i...

用 protobuf Any 來 parse byte array

第一次錄影片分享技術議題. Source code: https://github.com/axxdeveloper/study-practice/tree/gpb  主要其實就是之後可以用 Any.pack( gpbEntity ).toByteArray 傳送出去.接收端也適用 Any.p...

用 protobuf Any 來 parse byte array

第一次錄影片分享技術議題. Source code: https://github.com/axxdeveloper/study-practice/tree/gpb  主要其實就是之後可以用 Any.pack( gpbEntity ).toByteArray 傳送出去.接收端也適用 Any.p...

PostgreSQL Replication

  WAL - Write Ahead Log, or xlog, or transaction log. WAL 就像是 Cassandra 的 CommitLog, 會先被存起來, 再寫進資料庫, 使 Postgres 不管何時被關閉, 重啟後都可以恢復資料.WAL 存在 pg_wal folder...

PostgreSQL 資料複寫(Replication)

  WAL - Write Ahead Log,又叫 xlog 或 transaction log。WAL 就像是 Cassandra 的 CommitLog, 會先被存起來, 再寫進資料庫, 使 Postgres 不管何時被關閉, 重啟後都可以恢復資料.WAL 存在 pg_wal folder 下Po...

Angular - Built-in directives

ngIftrue => Host div will be included in the HTML elementsfalse => Host div will be excluded in the HTML elements<div *ngIf="needShow(4)" class="bg...

Angular - 內建 Directives

ngIftrue => Host div 會被加入 HTML 元素中false => Host div 會被排除在 HTML 元素外<div *ngIf="needShow(4)" class="bg-info p-2 mt-1"> Check need to show if pass ...

init mongodb data in docker

 1. Given file in project folder ./mongo/docker-entrypoint-initdb.d:/initdb.sh ``` echo '=====================================>' mongo --eval 'db.get...

在 Docker 中初始化 MongoDB 資料

 1. 在專案資料夾放一個檔案 ./mongo/docker-entrypoint-initdb.d:/initdb.sh ``` echo '=====================================>' mongo --eval 'db.getSiblingDB("testqq...

Start Kafka by docker-compose

docker-compose.yml services: zookeeper-server: image: bitnami/zookeeper:latest ports: - "2181:2181" environment: - ALLOW_ANONYMOUS_...

用 docker-compose 啟動 Kafka

docker-compose.yml services: zookeeper-server: image: bitnami/zookeeper:latest ports: - "2181:2181" environment: - ALLOW_ANONYMOUS_LO...

Kafka Client assign 與重設 offset

 1. Producer 發送訊息 ``` private static void sendMessages(Properties kafkaProps, String topic) {     for (int i = 0; i < MSG_COUNT; i++) { &nb...

Kafka Consumer specify offset

1. Producer send messages ``` private static void sendMessages(Properties kafkaProps, String topic) {     for (int i = 0; i < MSG_COUNT; i++) { ...

Kafka Consumer 指定 offset

1. Producer 發送訊息 ``` private static void sendMessages(Properties kafkaProps, String topic) {     for (int i = 0; i < MSG_COUNT; i++) {   &n...

Kafka Client Java Example

 Full Example: https://github.com/shooeugenesea/study-practice/blob/kafka/src/main/java/examples/Main.java Create topic by Java private static void cr...

Kafka Client Java 範例

 完整範例: https://github.com/shooeugenesea/study-practice/blob/kafka/src/main/java/examples/Main.java 用 Java 建立 topic private static void createTopicIfNot...

Run Kafka by docker

 https://itnext.io/how-to-install-kafka-using-docker-a2b7c746cbdc Create network $ sudo docker network create kafka-net --driver bridge Install zookee...

用 Docker 跑 Kafka

 https://itnext.io/how-to-install-kafka-using-docker-a2b7c746cbdc 建立網路 $ sudo docker network create kafka-net --driver bridge 安裝 Zookeeper 容器 $ sudo d...

MongoDB config docker cluster

Start mongo and bind with interfacesudo docker run --name mongo1 -d -p 27017:27017 mongo --bind_ip_all --replSet rs1sudo docker run --name mongo2 -d -p 27018...

MongoDB Docker 叢集設定

啟動 mongo 並綁定網路介面sudo docker run --name mongo1 -d -p 27017:27017 mongo --bind_ip_all --replSet rs1sudo docker run --name mongo2 -d -p 27018:27017 mongo --bind...

MongoDB group

 $group to group data by specified attribute // prepare data> db.company.insertOne({"name":"A","foundYear":1980,"numberOfEmployee":50}){ "ackn...

MongoDB Group(分組)

 $group 依指定屬性分組資料 // prepare data> db.company.insertOne({"name":"A","foundYear":1980,"numberOfEmployee":50}){ "acknowledged" : true, "i...

MongoDB Compound Index

At first, schema in mongodb is as follows > db.users.find() { "_id" : ObjectId("5f6f162c432d41b06263640d"), "name" : "user12", "i" : 12, "age" : 27, "cre...

MongoDB 複合索引

首先,MongoDB 中的 schema 如下 > db.users.find() { "_id" : ObjectId("5f6f162c432d41b06263640d"), "name" : "user12", "i" : 12, "age" : 27, "createdAt" : ISODate(...

MongoDB Index

 explain is used to understand execution detail In this case,"totalDocsExamined" : 1380558: shows "query by username" is quite insufficient db.users.fin...

MongoDB 索引

 explain 用來了解執行細節 在這個例子中,"totalDocsExamined" : 1380558:顯示「用 username 查詢」效率非常差 db.users.find({"username": "user101"}).explain("executionStats")> db.us...

Query MongoDB

  <div>specify returned attributes</div><div><div>// find all with all attributes</div><div>> db.users.find().pre...

查詢 MongoDB

  <div>指定回傳的屬性</div><div><div>// find all with all attributes</div><div>> db.users.find().pretty()</div>&lt...

leetcode medium - LRU Cache

LeetCode https://leetcode.com/problems/lru-cache/ Code It will be great to implement LinkedList by myself, I use JDK LinkedList directly

LeetCode 中等題 - LRU Cache

LeetCode https://leetcode.com/problems/lru-cache/ 程式碼 自己實作 LinkedList 會更好,這邊直接用 JDK 的 LinkedList

java.lang.ref

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ref/package-summary.html https://dzone.com/articles/weak-soft-and-phantom-references-i...

java.lang.ref 參考型別

https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ref/package-summary.html https://dzone.com/articles/weak-soft-and-phantom-references-i...

LeetCode - 洗牌陣列

  <div>LeetCode</div><div>https://leetcode.com/problems/shuffle-the-array/</div><div></div><div>程式碼</div&gt...

express.js - body-parser

<div><div>Commit</div><div>https://github.com/shooeugenesea/test-express/commit/eb0ac341b2ad17a6abff18d0b16ba3a1255beb9a</div>&...

express.js - helloworld

<div>Commit</div><div>https://github.com/shooeugenesea/test-express/commit/2f4aebcc2cb6af13ca63d4bcf51dd686a74036a6</div><div>&...

express.js - helloworld 入門

<div>Commit</div><div>https://github.com/shooeugenesea/test-express/commit/2f4aebcc2cb6af13ca63d4bcf51dd686a74036a6</div><div>&...

inquirer - mark todo item done

By ‘checkbox’ type can choose items Commit https://github.com/shooeugenesea/test-node-js/commit/a9bc2d47208cb0feec04e9cebea71d7fcadcb6a4 Code import * as ...

Inquirer - 將待辦事項標記為完成

透過 'checkbox' type 可以選取項目 Commit https://github.com/shooeugenesea/test-node-js/commit/a9bc2d47208cb0feec04e9cebea71d7fcadcb6a4 程式碼 import * as inquirer fr...

Inquirer - add item to list

<div><div>Use "input" type in inquirer can support input information</div><div></div><div>Commit</div><div>​ ...

Inquirer - 新增項目到列表

<div><div>使用 Inquirer 的 "input" type 可以讓使用者輸入資訊</div><div></div><div>Commit</div><div>​ https://github.com/sh...

Convert mov to gif in Mac

Motivation File extension of screen record in Mac is .mov (By QuickTime) Can use ffmpeg to convert to gif to reduce file size Install ffmpeg brew install ...

在 Mac 上把 mov 轉成 gif

動機 Mac 螢幕錄影的檔案格式是 .mov(透過 QuickTime 錄製) 可以用 ffmpeg 轉成 gif 來縮小檔案大小 安裝 ffmpeg brew install ffmpeg 將 mov 轉成 gif ffmpeg -i AM.mov output.gif 參考資料 https:/...

inquirer - simple list and quit command

Git Repositoryhttps://github.com/shooeugenesea/test-node-jsInstall librariesnpm install inquirernpm install typescriptList and Quit commandsimport * as inqui...

Inquirer - 簡單的列表與離開指令

Git Repositoryhttps://github.com/shooeugenesea/test-node-js安裝套件npm install inquirernpm install typescriptList 和 Quit 指令import * as inquirer from "inquirer"//...

typescript - use map

<ul><li></li><li>Commit </li></ul>https://github.com/shooeugenesea/study-js/commit/2d22117a7b36ea1225b960892995e409bbc5e6...

TypeScript - 使用 Map

<ul><li></li><li>Commit </li></ul>https://github.com/shooeugenesea/study-js/commit/2d22117a7b36ea1225b960892995e409bbc5e6...

Redux - 只注入一筆使用者資料到 UserHeader

目前的 component 是從 props 取得整個 users 集合。 UserHeader component 看起來怪怪的,因為這個 component 的設計是只顯示一個使用者,不應該拿到所有使用者資料再從裡面找一筆出來。 為了只注入一筆 User 資料到 UserHeader,可以改 mapSt...

Redux - 簡化 async function

<div><div>原始版本</div><div><div>export const fetchPosts = () => {</div><div>    // dispatch: can change any data w...

Redux - 更深入理解 mapStateToProps

Commit https://github.com/shooeugenesea/study-js/commit/9abf9a073ca86dea1b1dcf1418a5880a7975c0ea 我犯的錯誤 我發現 PttPosts 的實作好像不太對。 PttPosts.js import React, ...

redux - helloworld - PttPosts

<div>Install react and react-redux</div><div style="background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-...

Redux - 哈囉世界 - PttPosts

<div>安裝 react 和 react-redux</div><div style="background-color: #fbfaf8; border-radius: 4px; border: 1px solid rgba(0, 0, 0, 0.15); box-sizing:...

Kotlin - Numbers

<div>Types</div><ul><li><div>Byte</div></li><li><div>Short</div></li><li><div>I...

Kotlin - 數值型別

<div>型別</div><ul><li><div>Byte</div></li><li><div>Short</div></li><li><div>Int&...

Kotlin - Strings

<div>indexOf and substring</div><ul><li><div>indexOf</div></li><li><div>substring</div></li&gt...

Kotlin - 字串操作

<div>indexOf 與 substring</div><ul><li><div>indexOf</div></li><li><div>substring</div></li>&...

Kotlin - Nullable

<div><div>Nullable</div><ul><li><div>“String?” in return type shows the function may return null</div></li>&l...

Kotlin - Nullable 可空型別

<div><div>Nullable</div><ul><li><div>回傳型別中的 “String?” 表示這個函式可能回傳 null</div></li><li><div>呼叫端需要用 “...

Kotlin - Functions Basic

<ul><li><div>Function parameter is read-only</div></li></ul><div></div><div>Ex. Private function (Defau...

Kotlin - 函式基礎

<ul><li><div>函式參數是唯讀的</div></li></ul><div></div><div>範例:Private 函式(預設是 public)</div><div>&l...

kotlin - when

<div>When</div><div><div>package examples</div><div></div><div>fun main() {</div><div>    var nam...

Kotlin - when 表達式

<div>When</div><div><div>package examples</div><div></div><div>fun main() {</div><div>    var nam...

Sprint Boot - List files to Flux

Books suggestion@GetMapping("/unable_files")public Flux<FileInfo> wrongListFiles() throws IOException {    return Flux.fromIterable...

Spring Boot - Helloworld

<div>Download Spring Initializer</div><div>https://start.spring.io/#!type=gradle-project&language=java&platformVersion=2.2.7.RELEAS...

Spring Boot - Helloworld 入門

<div>下載 Spring Initializer</div><div>https://start.spring.io/#!type=gradle-project&language=java&platformVersion=2.2.7.RELEASE&...

Gradle - application

Run No arg main class Java  package examples; public class TestMain {     public static void main(String[] params) {   &n...

Gradle - Application 入門

執行沒有參數的 main class Java  package examples; public class TestMain {     public static void main(String[] params) {   &nbsp...

Gradle helloworld task

Edit build.gradle task helloworld {     println "Hello world" } List tasks and find helloworld $gradle tasks --all ... Ot...

Gradle Helloworld Task 入門

編輯 build.gradle task helloworld {     println "Hello world" } 列出所有 task 並找到 helloworld $gradle tasks --all ... Other task...

Gradle Helloworld - Main Class

Reference https://openhome.cc/Gossip/Spring/Gradle.html Thanks 良葛格, his explanation is so simple and good to read and practice!! Class package exam...

Gradle Helloworld - 主程式入門

參考資料 https://openhome.cc/Gossip/Spring/Gradle.html 感謝良葛格,他的說明簡單明瞭又好上手!! Class package examples; public class HelloMain {    &nbs...

How to reset a counter

Purpose: Original value is origVal, we want to use increase/decrease to update to a specified number How? origValue = origValue + expectedValue diff...

如何重設計數器

目的:原始值是 origVal,我們想要透過增加/減少來更新到指定的數字 怎麼做? origValue = origValue + expectedValue diff = expectedValue - origValue origValue = origValue + diff ...

DesignOfEverydayThings - Feedback

Anti-ex. or repeatedly push the pedestrian button at a street crossing? => Because user doesn't know whether system got his request or not. Fee...

DesignOfEverydayThings - Mapping

Mapping is the relationship between the elements of two sets of things Ex. Switch mapping Lights in office  Mapping the layout of controls a...

DesignOfEverydayThings - Signifier

Need separate to 7 posts, because image become huge base64 in Blogger, unable to upload.... Orz https://www.isaacnote.com/2019/06/designofeverydaythings-si...

DesignOfEverydayThings - Signifier - 7

When facing a device, we seeking for clue about how to use. Designer need provide it. Otherwise, we need use our own creativity and imagination. Mislea...

DesignOfEverydayThings - Signifier - 1

Affordance: it is a relationship, ex. Affordance of touching exists on the entire screen Signifier: designer put a circle on screen to signify user where t...

DesignOfEverydayThings - Affordances

Chair affordance An affordance is a relationship between the properties of an object and the capabilities of the agent that determine just how the objec...

DesignOfEverydayThings - Norman Doors

Introduction I like this book very much! I always can learn from it. Have a chance to introduce this book to team, want to have some notes for "THE PS...

Go - read write lock

Add number to 10000. RWLock (Use Lock/Unlock to read): 19ms, 92202 read count RWLock (Use RLock/RUnlock to read): 597ms, 4789798 read count W...

Go - mutual exclusion

Ex. Binary semaphore Race Condition Semaphore Ex. sync.Mutex Mutex.Unlock happens before Mutex.Lock Every Lock needs Unlock, can use defe...

Go - prevent race condition

Prevent race condition Initialize variables when package initialization phase, it will happen before main function. And don't modify those variables a...

Go - Cancel Job by close channel

Close a channel to broadcast cancellation No way to know a channel is closed or not, so need another channel to indicate a channel is closed This exa...

Go - Select Channel

Declare select {     case <- ch:         ...     case x := <- ch2:       &...

Go - parallel iteration

Inner goroutine can send event to outer goroutine by channel Ex. Pass value to inner routine function Declare a variable in inner goroutine function, ...

Go - buffered channel

Declare a queue: ch := make(chan int, 3) Block send when full, block receive when empty Get capacity: cap(ch) Get currently buffered: len(ch) ...

Go - unidirectional channel

Send only: chan<- int Receive only: <-chan int Violation will compile error Only channel used to send msg need to be closed, so to cl...

Go - pipelines

Ex. Make 3 channels and chan together, print in fmt.Println(<-channel) There is no way to check is a channel closed Close pipeline safely. Check rece...

Go - unbuffered channel

Unbuffered channel causes sender and receiver synchronized, called synchronized channel "When a value is sent on an unbuffered channel, the receipt of ...

Go - channel - basic

Declare ch := make(chan int) // unbuffered, send will be blocked until receive was called ch := make(chan int, 0) // unbuffered, send will be b...

Go - goroutine

Run f() in another goroutine: go f() To produce a race condition issue, can make for loop larger

Go - Type Switch

switch x.(type) { case: 。。 default:..} No fallthrough is allowed Reuse assert type result. switch x := x.(type) {...} Can combine more than one t...

Go - Type Assertion

X.(T)  X is interface, T is concrete type. When T is a concrete type, it assert dynamic type of X is identical to T. Result is the dynamic value wi...

Go - Interface value

Real type of an interface variable is decided dynamatically Need be careful when comparing interface, panic will occur when real type is not comparable ...

Go - Interface Satisfaction - 2

When a type value assign to a variable, it can call method declared with type value and pointer When a type pointer assign to a variable, it can call...

Go - Interface Satisfaction - 1

A function declared with type (not a pointer), can call method by type value. Can use (&t) to call method by address as well When a function d...

Go - Interface Contracts

Don't need implement interface, only method is enough Compile error if signature is wrong,  Although don't need declare "implements", but sti...

Go - encapsulation

Access control: upper case ecported to diiferent package It means the unit of encapsulation is package Difference Ex. type A int, can’t be encapsul...

Go - Method Values

Can assign method to a variable Ex. M = s.methodname; M() Can define func signature and assign implementation later Status will follow methods ...

Go - Methods - Pointer Receiver

Declare Method Method and Function can be the same name Method and Field can not have the same name Can declare another method name in the sa...

Go - Functions - 4

Must declare a func before let func call itself recursively. Otherwise compile error Loop will reuse variable address, so a new variable must be dec...

Go - Functions - 3

Can declare function without name. Called anonymous function. How client know it needs return value? => Because function signature has conc...

Go - Functions - 2

Modifications to the parameter copy don't affect the caller except pointer, slice, map, function, channel A function declaration without a body indica...

Go - Functions - 1

Declare func name(parameter-list) return-list {...} Parameter list type can be declared only once if types are the same func test(a string, b string,...

Go - JSON

ex. var p = Person{}; json.Marshal(p) json.marshal return byte slice contains long string wuthout extraneous Ex.data, err = json.MarshalIndent...

Go - Structs - 7

Name and visibility is implicitly determined by its type Outer struct type gains not just the fields of the embedded type but its methods too

Go - Structs - 5

Comparable struct can be a key of a map. (What will happen when struct value changed?) Can declare a named struct type in another struct as field ...

Go - Structs - 4

Shorthand notation to create and initialize a struct variable Ex. pp := &Point{1,2} It’s same as pp := new(Point) *pp = Point{1,2} If all f...

Go - Structs - 3

A struct can be declared to require client need assign values to each fields with right order.  Such pattern will be hard to maintain in the future...

Go - Structs - 2

A named type S CAN NOT declare a field with the same type S, but it can contains a field with type *S, for recursive data structure Zero struct field...

Go - Maps

Declared: map[KeyType]ValueType Ex. m := make(map[string]int) m["a"]=1 m{"b"]=2 Ex. m := map[string]int {    "a":1,    "b":2,...

Go - Slices

Slices contains many example images, causes I can’t save in Blogger in one article. So I split to 3 parts. Go - Slices (1/3) Go - Slices (2/3) Go - Slices (...

Go - Slices - 3

Ex. Slice is in the middle of an array, what will happen in that array after append? => Array value will reflect slice change, but array instance will ...

Go - Slices - 2

Slice is NOT comparable Standard library provide a way to compare 2 byte slices Reference type such as pointers and channels, the == test whether...

Go - Slices -1

Slice is declared as "var s []T" Declare a slice by make([]int,length,capacity) Slice looks like an array without size Pointer: point to the first eleme...

Go - Arrays

Declare an array Ex. var a [3]int a[0] len(a) for idx, v range a {} for _, v range a ,{} Declare with specified values. Default value is ...

Go - Boolean and Strings

Boolean bool boolean Strings Conventionally UTF-8 Built-in function len returns the number of bytes, not runes in a string Detect length of s...

Go - float

float  float32, max value: math.MaxFloat32 float64, max value: math.MaxFloat64 float can be printed by fmt package %e: exponent %f: no ex...

Go - Integers

int8 int16 int32 int64 uint8 uint16 uint32 uint64 int uint : natural and most efficient size on a particular platform. Different compiler may choose di...

Go - Scope

Syntactic block: Enclosed in braces Lexical block: Not explicitly surrounded by braces Universe block: A lexical block for the entire source code. In...

Go - Package import and initialization

Package Import Import path: packages are identified by an unique string, called import path Go lang spec doesn't define what "import path" mean, it's u...

Go - Package and Files

Package Variables Exported identifiers start with an upper-case letter files in the same package can be in the same folder Package level variables ca...

Go - Type Declarations

Named type Format: type typeName underlying-type A constructor with underlying-type value will exist without declaring package main import (  &n...

Go - Assignments

Tuple Assignment Type Assertion Need use interface{} to declare a variable Check concrete type by v,ok := x.(T)  If type "T" can't be assigned ...

Go - Declare Pointers

A pointer value is the address of a variable Declare a variable, declare a value, assign address to that variable Variable address declared in functi...

Go - Declare Variables

Declaration Declare package Declare import var/const/func/type can be declared in any order Variables Declare variables with the same type a...

Go - helloworld in eclipse

Introduction When trying the first helloworld, I encountered some problem to setup environment. So note here. You can find manual for complete informati...

Spring Integration - Header Enricher

Reference Pro Spring Integration - https://www.amazon.com/Pro-Spring-Integration-Experts-Voice-ebook-dp-B005PZ29OA/dp/B005PZ29OA/ref=mt_kindle?_encodi...

Spring Integration - Transformations

Reference Pro Spring Integration - https://www.amazon.com/Pro-Spring-Integration-Experts-Voice-ebook-dp-B005PZ29OA/dp/B005PZ29OA/ref=mt_kindle?_enc...

Spring Integration - Channels

Reference Pro Spring Integration - https://www.amazon.com/Pro-Spring-Integration-Experts-Voice-ebook-dp-B005PZ29OA/dp/B005PZ29OA/ref=mt_kindle?_enco...

RabbitMQ Example

Reference https://www.rabbitmq.com/install-windows.html  https://www.rabbitmq.com/tutorials/tutorial-one-java.html https://github.com/shooeugenesea/...

Google Protobuf - Basic Example

Reference Protobuf - Java Code in Github Example Install protobuf Download from Git: https://github.com/protocolbuffers/protobuf Install protobuf ...

Spring Integration - Basic Terms

Reference Spring Integration Basic Terms 後篇: https://www.isaacnote.com/2018/10/spring-integration-channels.html  Terms org.springframework.inte...

ForkJoinPool - Thread Management

Reference ForkJoinPoolManyThreadMain.java ForkJoinPool Paper ForkJoinPool - Error Handling Question 原本以為 new ForkJoinPool(2) 像這樣的宣告, 是讓 ForkJoinPool 最多維...

ForkJoinPool - Error Handling

Reference Git: ForkJoinPoolErrorMain.java 前篇: ForkJoinPool - Workstealing Next: ForkJoinPool - Thread Management Error Handling 如果 fork 出去...

ForkJoinPool - Work stealing

Reference https://en.wikipedia.org/wiki/Work_stealing 前篇: Java Concurrency - ForkJoinPool 的 deadlock 下篇: ForkJoinPool - Error Handling Introduction Fork...

Java Concurrent - ForkJoinPool

ExecutorService and Problem 用一個 ExecutorService submit task 後, 如果 task 會 submit 其他的 task, 這些 task 都會放進 ExecutorService 的 queue 中. 這樣就沒辦法做到 "第一個 task 與其產生的...

Java Concurrent CyclicBarrier

Introduction CyclicBarrier 很久沒用都忘了, 來複習一下.. Description 簡單說就是很多個 thread 去作事情, 作完之後就 await. CyclicBarrier 等作完的 thread 達到指定的個數後, await 就結束. Code public ...

Java Concurrent Phaser

Introduction 今天才知道 Java 7 有提供一個 Phaser class 來處理更複雜的 CountDownLatch 需求. Simple Phaser 想用 Phaser, 首先你的 threads 工作要有分階段, 一個階段沒做完就不能進行下個階段. 有了這個限制後就可以照下面的流程...

Zip files

In a project, I need zip file and append to separated folders.<div> public static void main(String[] params) throws IOException { List<String>...

lombok + Orika + Builder Pattern

Reference lombok - Builder orika - Advanced Mapping Configurations Effective Java - Builder Pattern Introduction Builder Pattern is suggested in Ef...

Handle InterruptedException

Reference Dealing with InterruptedException How to handle InterruptedException Throw it directly If you can't throw it, call Thread.currentThread().in...

Java TLS Practice

Introduction 記錄 Java 使用 SSL 的方法 (不要求 client auth) Reference https://github.com/shooeugenesea/study-practice/tree/ssl-practice http://www.programgo.com/a...

guava notes

Reference Guava User Guide Practice in Github Optional Optional 可以用來處理 null value 與避免 NullPointerException public class OptionalTest {

字串 format

帶入 dict 的值, 如果用 format api, dictionary 要帶 ** 去展開 key-value >>> m = {'a':1.1234, "b":"qq"} >>> '%(a)1.1f %(a)s %(b)s' %m '1.1 1.1234 qq'

function is an object

python 的 function 是一個物件, 所以可以放進 collection 中等以後被呼叫. >>> def a(): print 'a';

split large file

I use Notepad++ to check log and debug. When log file is large, I need to split large file to smaller ones. I can't find tool so write codes to split file ...

Shell 筆記

cd /d %~dp0不管執行 script 時候路徑在哪, cd /d %~dp0 後 script 的路徑就到該 script 路徑下 script, 放在 f:/test/test.bat cd /d %~dp0 dir execute: f:/test/test.bat f:\>test\te...

Git 筆記

從 branch merge 回 master, 導致 pom.xml conflict, 想 reset pom.xml 因為這不是我要 merge 的內容. (stackoverflow) git reset pom.xml git checkout pom.xml 想清掉 untrack fil...

Basic Perl 筆記

單引號的 \n 不會換行, 雙引號內的 \n 會換行 print("line1\nline2\n\n\n\n"); print('line3:abc\nabc'); d:\>test.pl input string:abc input number:4 abcabcabcabc d:\>test...

Scrum Q&A

Q: 我們用用 SCRUM 想幹嘛?  A: 我們都曾經遇過在某個專案已經花費很多時間跟人力做得一團亂. 但在某個機緣下少少幾個人展現強大的戰鬥力把待辦清單做完, 成為膾炙人口的佳話. 這個佳話也成為團隊員日後美好的回憶. 會有佳話是因為:  待辦事項清單清楚 有人排出優先順序, 先...

User Story Template

Reference Thomas Tseng User story format: “As a (user type), I want to (goal), so that (reason).” Attributes of good user story: I...

compound interest

Reference http://shooeugenesea.github.io/compoundinterest.html Description 不想工作, 最好投資可以每年幫你賺 200萬, 就是在不工作的情況下還是可以賺200萬. 怎麼做呢? 我先做個網頁, 用複利的方式去替你算每年的目標是多少...

Android APP: GameVolumn

Reference Android SDK Tutorial: Working With The SeekBar Android: Enable click event on empty activity area How to create Transparent Activity in Android...

Fight with Bitmap OOM problem.

Reference Managing Bitmap Memory Supporting Multiple Screens BrightImage in Github BrightImage in Google Play How To Pick Image From Gallery In Android A...

split big log file

Description 一個 log 檔 3G 怎麼看? 不想裝工具, 就只能把檔案切小 Dependencies JDK7 apache commons io Codes public static void main(String[] params) throws IOException ...

python http download cassandra

Reference http://www.apache.org/dyn/closer.cgi?path=/cassandra/2.0.4/apache-cassandra-2.0.4-bin.tar.gz http://docs.python.org/3/library/urllib.request.htm...

python compress/decompress file

Reference http://docs.python.org/3/library/shutil.html#module-shutil Description 把 d:/nginx-1.4.3 壓縮到 d:/ziptarget/test.zip 再把 d:/ziptarget/test.zip 解壓...

JDK6 to JDK7 => Basic IO

Reference Lesson: Basic I/O 讀寫小檔案 如果檔案比較小可以使用 Files 提供的 read/write. package test;

JDK6 to JDK7 => API Enhancements

Description 打算把系統的執行環境從 JDK6 升級到 JDK7, 整理一下有哪些可用. 比較期待的部分是語法, NIO2, G1. 這頁是整理語法的部分. Reference Enhancements in Java SE 7 Java Language Enhancements Poin...

python 處理 json

Description 現在很常用 json 當成儲存資料的格式, 用 java 的話需要導入 library. python 則是內建 json 的 module, 只要操作原生的資料結構就行了. 很方便. Reference http://docs.python.org/3/tutorial/in...

python 的 main method

之前看 python 文章好像都沒提到怎麼寫 main method, 似乎這件事情很自然, 不過我卻不知道. 看了 6.1.1. Executing modules as scripts 裡面有寫 “the code in the module will be executed, just as if you ...

處理正在 iterate 的 dictionary

今天練習 Python 的時候發現 5.6. Looping Techniques 有個提示 "To change a sequence you are iterating over while inside the loop (for example to duplicate cert...

巴斯卡三角形 in Python

Source Code def print_pascal(row_cnt): pascal = [] for row in range(row_cnt): cols = [] for col in range(row+1): if row ...

Nginx Practice in Windows - 6 simple proxy server

Description 使用 nginx 的一個主因是要支援 web application 放在別台機器上, 將相關的 request 導過去. Reference Setting Up a Simple Proxy Server Practice prepare files D:\nginx-1...

Nginx Practice in Windows - 5 static content

Description 使用 nginx 主要目的之一就是要存放靜態檔如 html 或圖片 Reference Serving Static Content Practice 設定讓 "GET /" 的 request 首頁導向 testhtml/data/www/index.html prep...

Nginx Practice in Windows - 3

Reference How nginx processes a request Description server { listen 8080; server_name example.com; location /test { ...

Nginx Practice in Windows - 2

Reference Nginx 变量漫谈(二) Nginx Embedded Variables Practice 變數的有效範圍是 request, 所以就算不同 request 也可以使用變數 config nginx.conf server { listen ...

Nginx Practice in Windows - 1

Description 最近在練習 Nginx, 不過電腦的環境只有 Windows 也沒打算裝 VM, 所以跟網路上文章的環境不太一樣, 在這紀錄怎麼在Windows上練習. 不過最終應該還是要裝個 Linux 環境來練習比較好.. Reference Nginx 变量漫谈(一) Preparati...