ruby lambda and proc

I found this article has a clear explanation of proc and lambda and provides good example of them. https://dev.to/keithrbennett/lambdas-...

Wayne

該寫哪些 test?

https://www.codewithjason.com/kinds-rails-tests-write-kinds-dont/ TL;DR: 1. 每個人對 test 的名稱定義不一樣,有些人叫 acceptance, 有些人叫 end to end, integr...

Wayne

Ruby API serializer options

這週 Ruby Weekly 剛好兩個人在推自己的 serializer gem,大家都要自己做自己的工具,驗證了別人寫的 code 都是屎,只有自己寫的才是最好的真理,呵呵。 趁機整理一下: - https://github.com/rails-api/active_...

Wayne

stale while revalidate

stale while revalidate 是 browser 提供的 cache 的機制,我們在很多靜態頁面上都會看到,例如: ``` Cache-Control: max-age=<seconds> Cache-Control: max-stale[=<second...

Wayne

How Digital Signature works

Key concepst: 1. private key 加密的訊息只可以用 public key 解密 2. public 加密的訊息只可以用 private key 解密 3. 不一樣的內容經過 hash function 後產生的 hash value 不一樣,一樣...

Wayne

Ruby fibrers

簡單來說可以把 Fiber 想成是 Thread 但他們的差別在於 Thread 的運作和停止是由 Operation System 控制,Fiber 則是由 Programmer 控制。丟系安捏。 ` Fiber.yield` 可以 stop Fiber 並把程序...

Wayne

Python3 sorting

https://docs.python.org/3/howto/sorting.html#sortinghowto 這個 doc 講得很清楚。 ## Basic: `list.sort()` => 改變原本的 list,只能用在 list `sorted()`=> 回...

Wayne

Python decimal

Float ```py In [10]: num = 3577 In [11]: while num >= 10: ...: num /= 10 ...: In [12]: num Out[12]: 3.5769999999999995 ```...

Wayne

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/

Wayne

Python reverse list

reverse python list ```py In [1]: [1,2,3,4,5][::-1] Out[1]: [5, 4, 3, 2, 1] ```

Wayne

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

Wayne

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

Wayne

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

Wayne

Rails 用 webpacker 時 compile 很慢而且很吃 memory?You're probably a over-packer lol

長話短說,就是 webpacker 會 compile **所有** 在 `japascripts/packs` 資料夾底下的東西,所以只要沒有要在 layout 裡面 include 的 file 就不要放在 packs 下面,這樣就會變快了。 Copy paste f...

Wayne

Ruby 2.7 懶人點點點語法

`...` 成為最新最潮的 arguments forwarding syntax ```rb def bar(*args, **kws, &block) block.call(args, kws) end ``` 可以寫成 ```rb def foo(...)...

Wayne

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

Wayne

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

Wayne

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

Wayne

10 個 ActiveRecord 的新功能

快速看看,有印象就好 https://hint.io/blog/10-New-Things-in-Active-Record

Wayne

Redefine comparator in Python and Ruby

## Python In python, there are several magic functions for comparing: * `__eq__(self, other)` 定義了等號的行為` ==` 。 * `__ne__(self, other)` ...

Wayne

Rails 6 ActiveStorage updates

工作上有用到 ActiveStorage,然後我又手癢想升級 Rails,所以先記錄一下 https://blog.saeloun.com/2019/11/04/rails-6-active-storage-updates.html

Wayne

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

Wayne

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

Wayne

Ruby multiline string

## With indention version ```rb indented = <<-EOS Hello This is an example. I have to write this multiline string outside the we...

Wayne

uniq list in Python

```py list(set([1,2,2,3])) # => [1,2,3] ``` functional style

Wayne