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 ...

Wayne

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...

Wayne

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...

Wayne

Keyword argument in Ruby 3

https://blog.saeloun.com/2019/10/07/ruby-2-7-keyword-arguments-redesign.html

Wayne

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...

Wayne

給高中沒學好或是已經忘記的同學的 CS 基礎知識 cheatsheet

https://youtu.be/TOsMcgIK95k

Wayne

複習一下各種排序法,和 Python 實現

搭配題目和講解影片服用: * Lintcode: https://www.lintcode.com/problem/sort-integers * Leetcode: https://leetcode.com/problems/sort-an-array/ * https...

Wayne

Remove Duplicate Numbers in Array

## Question https://www.lintcode.com/problem/remove-duplicate-numbers-in-array/description https://leetcode.com/problems/remove-duplicat...

Wayne

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. ...

Wayne

什么是拓扑排序(Topological Sorting)

直接 copy 過來: 一、什么是拓扑排序 在图论中,拓扑排序(Topological Sorting)是一个有向无环图(DAG, Directed Acyclic Graph)的所有顶点的线性序列。且该序列必须满足下面两个条件: 每个顶点出现且只出现一次。 若存在一...

Wayne

rspec 3 composable matchers

http://rspec.info/blog/2014/01/new-in-rspec-3-composable-matchers/

Wayne

Python deque 用法

1. deque 類似於 list (ruby 的 array),只不過 deque 可以操作兩端 2. deque 是 tread safe,所以可以同時操作 何謂操作兩端?這個 example 看一下即了解: ```py import collections d1...

Wayne

Graph theory basic - Set and adjacency list

![Graph Example](https://waynechu.cc/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6IkJBaHBCZz09IiwiZXhwIjpudWxsLCJwdXIiOiJibG9iX...

Wayne

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....

Wayne

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...

Wayne

Writing idiomatic python 3

Recomended http://downloads.niceware.com/TECH-pdf/PythonStyle-Writing_idiomatic_python_3.pdf?fbclid=IwAR1uhD-_8WRmWy1Sb2Ncz9Afwk248-o5JA...

Wayne

Time complexity and space complexity

時間複雜度跟空間複雜度 ## 時間複雜度 常見的六種時間複雜度與演算法 * O(1):陣列讀取 * O(n):簡易搜尋 * O(log n):二分搜尋 * O(nlogn):合併排序 * O(n²):選擇排序 * O(2^n):費波那契數列 時間複雜度為 O(n) ...

Wayne

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...

Wayne

Rails 6 released

https://weblog.rubyonrails.org/2019/8/15/Rails-6-0-final-release/

Wayne

Rails ActiveModel with type casting

## Basic usage Use `include ActiveModel::Model` and `include ActiveModel::Attributes` can provide type casting for active model. Exampl...

Wayne

Precision and Scale in database

位數 (Precision) 是指數字中總共的位數。 小數位數 (Scale) 則是指數字中小數點右方的位數。 例如 123.45 的位數是 5,小數位數是 2。 precision 又稱精度 https://docs.microsoft.com/zh-tw/sql/...

Wayne

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...

Wayne

Rails lock! and with_lock

Basically, `ActiveRecord::Locking::Pessimistic#with_lock` will yield your code inside transaction but `ActiveRecord::Locking::Pessimistic...

Wayne

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_...

Wayne

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...

Wayne