[Day2] Implements Linked List in Java

思路 初始化 node 並配置當前 node value 和 next node 配置開始 node 和 結束 node 實作 初始化 public class LinkImpl { // 內部類 static class Node { Integer val; Node next; // constructor public Node(int val) { this.val = val; } } private Node start; private Node end; public LinkImpl() {} } 測試情境 public static void main(String[] args) { /** initialize **/ LinkImpl mylist = new LinkImpl(); /** add O(1) - start **/ mylist....

August 5, 2022 · 2 min · Yish

[Day1] Implements Arrayable in Java

此篇文章是用來紀錄學習超圖解!一次搞懂演算法|入門篇 實作項目的部分與代碼分析。 思路 初始化一個空的陣列,用來存放資料。 設定最後位數作為判斷依據。 新增藉由 index 添加 value。<add_by_index> 新增直接添加 value。 <add_by_value> 新增藉由 index 刪除 value。 <remove_by_index> 新增直接刪除 value。 <remove_by_value> 新增藉由 index 搜尋 value。 <search_by_index> 新增藉由 value 搜尋 index。 <search_by_value> 實作新增 初始化 public class ArrayImp2 { private Integer[] array; private Integer i_end; public ArrayImp2(int size) { array = new Integer[size]; i_end = -1; } } 測試情境1: add_by_index public static void main(String[] args) { ArrayImp2 mary = new ArrayImp2(5); mary....

August 3, 2022 · 3 min · Yish

How to Mock Request With Calling Third Party in Test?

In this case, I faced a problem when I want to mock a request with calling third party in test, I had two problem to wait for solving. Customzing the headers of the request for specific purpose. Mocking the third party requesting in test. Here is my thought: Finding mocked request in laravel TestCase Based on it and create a customize method of mocking request in test. Firstly, I found the method of get in TestCase, and it do some operation like:...

August 3, 2022 · 4 min · Yish

Redis switches main or backup in laravel

In my situation, I face a problem with redis, our redis service(RDS) is unstable with unknown problem, but I need to solve consistency service and zero-downtime, so on my first solve problem that I do switch service in my application. Here is my thinking steps: Redis service needs to bind container by singlton Trying to connect Master redis, if it’s failed, rebinding second redis service. Rebinding facade class to new redis service....

August 1, 2022 · 2 min · Yish

Modify Package by Composer

In newer laravel, we are use many ways to instead of https://github.com/Zizaco/entrust package doing works, but previous project still use it. for now, the project needs to upgrade to newer laravel, the package doesn’t support newer laravel, we can upgrade to suit our project by composer. Documentation Changes to * signature in composer.json "require": { "zizaco/entrust": "*" } cloning package For this project I put into /packages/ in application, app/ packages/ entrust/ repositories "repositories": [ { "type": "path", "url": "packages/entrust" } ], Finally you do composer update, you can customize or update the package by yourself, running the testing cases and more....

April 6, 2022 · 1 min · Yish

Trait Instead of the Other Trait Method

use AuditableWithOrder; use \OwenIt\Auditing\Auditable { AuditableWithOrder::transformAudit insteadof \OwenIt\Auditing\Auditable; } How to overwrite the trait on self or the others trait? It’s about vanilla PHP, here is documentation PHP: Traits - Manualhttps://www.php.net/manual/en/language.oop5.traits.php, here is an example. trait Taggable { public function slug() { return Str::slug($this->slug, '-'); } } For now, I don’t want to make a string slugging for slug, I would like changing to snake, in the past, I would like to do following:...

April 3, 2022 · 3 min · Yish