Faking External Services in Tests with Adapters
Faking External Services in Tests with Adapters https://thoughtbot.com/blog/faking-external-services-in-tests-with-adapters
Unexpected behaviour for ActiveModel::Model validate and valid?
Assume we have an `FakeUser` class looks like below: ```rb class FakeUser include ActiveModel::Model include ActiveModel::Attribute...
There are only 2 hard things in Computer Science
> There are only two hard things in Computer Science: cache invalidation and naming things. > -- Phil Karlton https://martinfowler.com/...
Redefine comparator in Python and Ruby
## Python In python, there are several magic functions for comparing: * `__eq__(self, other)` 定義了等號的行為` ==` 。 * `__ne__(self, other)` ...
Rails 6 ActiveStorage updates
工作上有用到 ActiveStorage,然後我又手癢想升級 Rails,所以先記錄一下 https://blog.saeloun.com/2019/11/04/rails-6-active-storage-updates.html
How Ruby REALLY uses Memory: On the Web and Beyond
好文,強烈建議閱讀全文 => https://www.schneems.com/2019/11/06/how-ruby-really-uses-memory-on-the-web-and-beyond/ ## TL;DR: - Tread 越多 memory usag...
Ruby yield_self and then syntax
## TL;DR: 1. `yield_self` == `then` 2. `yield_self` returns the result of the block ## yield_self Introduced in Ruby v2.5 Difference...
Ruby multiline string
## With indention version ```rb indented = <<-EOS Hello This is an example. I have to write this multiline string outside the we...
How to sort a list in Python
## 1. Object oriented way: ```python list = [4,3,2,1] list.sort() # => return nothing list # => [1,2,3,4] ``` - called from object ...
Finally we have multi env credential in Rails 6
In Rails 6, default credential is for development and staging, they'll store in the same path ``` config/credentials.yml.enc config/mast...
When to use Hash and when to use HashWithIndifferentAccess and why
## TL;DR: * When passing to our class: Both works, because we control everything * When passing to 3rd party library: Hash is better, we...
Keyword argument in Ruby 3
https://blog.saeloun.com/2019/10/07/ruby-2-7-keyword-arguments-redesign.html
Can't find custom headers in Axios response
It's CORS issue, configure CORS setting for browser will fix this. https://stackoverflow.com/questions/37897523/axios-get-access-to-resp...
複習一下各種排序法,和 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
![Graph Example](https://waynechu.cc/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX...
4 basic proof technique in math
## Some basic P => Q P: If statement Q: Tehn statement example: `If a < b, then a < b + 1`,`If a < b` 是 P, `then a < b+1` 是 Q ## 1....
Some Python tools
List few tools that I find helpful for Python's beginner learner - Console: https://ipython.org/ - IDE: https://www.jetbrains.com/pycha...