複習一下各種排序法,和 Python 實現
搭配題目和講解影片服用: * Lintcode: https://www.lintcode.com/problem/sort-integers * Leetcode: https://leetcode.com/problems/sort-an-array/ * https...
Remove Duplicate Numbers in Array
## Question https://www.lintcode.com/problem/remove-duplicate-numbers-in-array/description https://leetcode.com/problems/remove-duplicat...
Classical Binary Search - recursion version
## Question: 457. Classical Binary Search Find any position of a target number in a sorted array. Return -1 if target does not exist. ...
什么是拓扑排序(Topological Sorting)
直接 copy 過來: 一、什么是拓扑排序 在图论中,拓扑排序(Topological Sorting)是一个有向无环图(DAG, Directed Acyclic Graph)的所有顶点的线性序列。且该序列必须满足下面两个条件: 每个顶点出现且只出现一次。 若存在一...
Python deque 用法
1. deque 類似於 list (ruby 的 array),只不過 deque 可以操作兩端 2. deque 是 tread safe,所以可以同時操作 何謂操作兩端?這個 example 看一下即了解: ```py import collections d1...
Graph theory basic - Set and adjacency list
:陣列讀取 * O(n):簡易搜尋 * O(log n):二分搜尋 * O(nlogn):合併排序 * O(n²):選擇排序 * O(2^n):費波那契數列 時間複雜度為 O(n) ...
Start using Stripe's PaymentIntent instead of Charge to fit SCA
Since a new rule coming into effect on September 14, 2019, as part of PSD2 regulation in Europe, any integrations using the Charges API w...
Rails ActiveModel with type casting
## Basic usage Use `include ActiveModel::Model` and `include ActiveModel::Attributes` can provide type casting for active model. Exampl...
Precision and Scale in database
位數 (Precision) 是指數字中總共的位數。 小數位數 (Scale) 則是指數字中小數點右方的位數。 例如 123.45 的位數是 5,小數位數是 2。 precision 又稱精度 https://docs.microsoft.com/zh-tw/sql/...
How to test ActionMailer with RSpec
This blog post will demostrate how to test ActionMailer in Rails using RSpec. ## Configuration ```rb # config/environments/test.rb # T...
Rails lock! and with_lock
Basically, `ActiveRecord::Locking::Pessimistic#with_lock` will yield your code inside transaction but `ActiveRecord::Locking::Pessimistic...
How to test Stripe webhook's singature with Rspec
This post shows how to test Stripe webhook's singature ```rb # spec/support/stripe_test_helper.rb module StripeTestHelper def stripe_...
How to split rails routes.rb into smaller files - Extend
I've tried many ways to split `config/routes.rb` file, I find this approach is best to me because it requires no futher config to let dev...
How to split rails routes.rb into smaller files - require
Anothr approach: use `require` In `config/routes.rb` ```rb Rails.application.routes.draw do root to: "home#index" get "/about get...
How to split rails routes.rb into smaller files - instance_eval
The most common (base on my google search) way to split `config/routes.rb` in rails is by defining your own `draw` DSL. This is just one ...
Order By NULL 時的情形
Default 值: | NULL Ordering Behavior/ Database Types | MARIADB/MYSQL | SQLSERVER | HSQLDB | DB2 | ORACLE | POSTGRESQL | | --- | --- | ---...
Scaling the monolith
在拆成潮潮的 Micro Service 或是超級大 Refactor 甚至是討論要不要換語言換框架前,先從小的改變做起吧。文章列了一些滿基本但是都很實用的原則、方法、工具,下次沒票可以做或是上班閒閒時都可以試一下,還可以增進一下未來工作效率。 ~~除非你只是想要潮?(威...
儲存 sensitive 資料的一些基本作法
### 大原則: 1. sensitive 資料加密儲存 2. Web server 只放加密用的金鑰,不放可以解密的金鑰 實際做起來就是:把需要解密的金鑰放到 worker 的 server,worker server 不接受來自外面的流量、且只能透過公司的 VP...