跳到主要內容

發表文章

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

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

Java Dependency Injection

首先 這篇主要是翻譯 這篇 的教學, 再用自己的方式解釋。 Email Service 文章開頭以 Email Service 來解釋, UML 應該是長這樣, Application 強依賴 EmailService , Application 在一開始就初始化了 EmailService, 而 Main 也強依賴 Application , 這樣寫並沒有太大的問題, 但不容易對 Application class 做測試, 因為不容易對 EmailService 做 mock. 修正 Application 方便測試 為了讓 Application 能夠被測試, 所以改成 inject EmailService 的建構方式 public class Application { private EmailService emailService; public Application(EmailService emailService) { this.emailService = emailService; } public void notification(String message, String receiver) { this.emailService.sendEmail(message, receiver); } } 簡單的使用 Mockito 來 mock EmailService 測試 <dependency> <groupId>org.mockito</groupId> <artifactId>mockito-core</artifactId> <version>2.12.0</version> </dependency> package dependency.injection; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito...

Setting maven liquibase plugin of Spring-boot

Liquibase Migration Laravel 的 Migration 是一個很棒的工具, 可以簡單的下個指令, 輕鬆的建立 tables php artisan migrate 在 Spring-boot 也提供一套類似的工具, 使用起來大同小異, 只是設定上有點小麻煩。 dependencies <dependency> <groupId>org.liquibase</groupId> <artifactId>liquibase-core</artifactId> </dependency> build <build> <resources> <resource> <directory>src/main/resources</directory> </resource> </resources> <testResources> <testResource> <directory>src/test/resources</directory> </testResource> </testResources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifa...

Java Quartz2.2 入門

Quartz Quartz 是一個功能滿完整的 Java Schedule 排程工具, 核心就圍繞在 Scheduler 與 Job 的操作上。 Scheduler - the main API for interacting with the scheduler. Job - an interface to be implemented by components that you wish to have executed by the scheduler. JobDetail - used to define instances of Jobs. Trigger - a component that defines the schedule upon which a given Job will be executed. JobBuilder - used to define/build JobDetail instances, which define instances of Jobs. TriggerBuilder - used to define/build Trigger instances. Job Quartz 的 Job 被定義為需要 implement org.quartz.Job , 需要實作 void execute(JobExecutionContext jobExecutionContext) , jobExecutionContext, 可以取得 Job 的 Scheduler, Trigger, JobDetail 的相關設定, 相關的說明可以參考 tutorial-lesson-02 . import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.quartz.Job; import org.quartz.JobDataMap; import org.quartz.JobDetail; import org.quartz.JobExecutionContext; import org.quartz.JobExecutio...

Java String Hex 轉換

覺得 String.format("%1$02x", b) 很神奇, 隨手記錄一下 String to Hex public static String toHex(byte[] bytes) { StringBuilder sb = new StringBuilder(); for (byte b : bytes) { sb.append(String.format("%1$02x", b)); } return sb.toString(); } Hex to String import java.io.UnsupportedEncodingException; import javax.xml.bind.DatatypeConverter; public static String hexToString(String hexStr) throws UnsupportedEncodingException { byte[] bytes = DatatypeConverter.parseHexBinary(hexStr); return new String(bytes, "UTF-8"); }

Let'sEncrypt with Spring-boot Https

網路管理基礎 Route53 與網路管理基本概念 EC2 Https 設定 AWS 綁定 Domain Route53 建立 Hosted Zones, 自己申請的 Domain (my-domain.me) Route53 Hosted Zones 建立 Record (my-domain.me), 綁定 EC2 Let’sEncrypt Certificate 申請 1. 安裝 certbot 工具 $ git clone https://github.com/certbot/certbot.git $ cd certbot $ ./certbot-auto 2. 透過 certbot 的 plugin 申請 certificate $ ./certbot-auto certonly —a standalone -d my-domain.me —email someone@gmail.com 在流程中, 需要回答一些問題, LetsEncrypt 會發送 request 去驗證 my-domain.me 這個 domain 3. 使用 openssl 將 letsEncrypt 的 key 產生 ssl 這是 os 環境 letsencrypt 的預設目錄路徑 $ cd /etc/letsencrypt/live/my-domain.me 把 letEncrypt 給你的 private key 產生 ssl 憑證 $ openssl pkcs12 -export -in fullchain.pem \ -inkey privkey.pem \ -out keystore.p12 -name tomcat \ -CAfile chain.pem \ -caname root 把生成的 ssl 憑證, 放到 spring-boot 專案底下的 resouces $ cp keystone.p12 ~/my-web-project/main/resources/ 4. 設定 application-prod.yml server: port: 8443...