Ruby fibrers
簡單來說可以把 Fiber 想成是 Thread 但他們的差別在於 Thread 的運作和停止是由 Operation System 控制,Fiber 則是由 Programmer 控制。丟系安捏。 ` Fiber.yield` 可以 stop Fiber 並把程序...
Python3 sorting
https://docs.python.org/3/howto/sorting.html#sortinghowto 這個 doc 講得很清楚。 ## Basic: `list.sort()` => 改變原本的 list,只能用在 list `sorted()`=> 回...
Python decimal
Float ```py In [10]: num = 3577 In [11]: while num >= 10: ...: num /= 10 ...: In [12]: num Out[12]: 3.5769999999999995 ```...
New features in Ruby 2.7
最令我在意的就是 pattern matching ,但是是 experimental feature,可能還得再等等。 https://www.ruby-lang.org/en/news/2019/12/25/ruby-2-7-0-released/
Python collections.defaultdict
> Returns a new dictionary-like object. defaultdict is a subclass of the built-in dict class. It overrides one method and adds one writab...
How to test with Salesforce Heroku Connect - Part 2
In my previous post [How to test with Salesforce Heroku Connect ](https://waynechu.cc/posts/290-how-to-test-with-salesforce-heroku-conne...
Fix marked.js and highlight.js
## Story My blog had some highlighting issue when rendering Ruby class. I finally found a time to fix it. The problem is I was useing o...
Rails 用 webpacker 時 compile 很慢而且很吃 memory?You're probably a over-packer lol
長話短說,就是 webpacker 會 compile **所有** 在 `japascripts/packs` 資料夾底下的東西,所以只要沒有要在 layout 裡面 include 的 file 就不要放在 packs 下面,這樣就會變快了。 Copy paste f...
Ruby 2.7 懶人點點點語法
`...` 成為最新最潮的 arguments forwarding syntax ```rb def bar(*args, **kws, &block) block.call(args, kws) end ``` 可以寫成 ```rb def foo(...)...
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...