How DHH write RESTful controller

常常要貼這個連結給別人但每次都忘記這篇的連結在哪,紀錄一下以後好搜尋 https://gist.github.com/dhh/10022098

Wayne

Harmless migration file in Rails could be harmeful

討論一個看起來很正常的 migration file 可能造成的問題,ex: ```rb class MyMigration < ActiveRecord::Migration[5.2] def change add_reference :payments, ...

Wayne

TCP 的三次握手四次揮手

## 三次握手: 連線 ![tcp-connection-made-three-way-handshake.png](https://waynechu.cc/rails/active_storage/blobs/eyJfcmFpbHMiOnsibWVzc2FnZSI6Ik...

Wayne

LRU Cache

Least Recently Used (LRU) cache Least recently use 簡單的說就是:最近最少使用 像是 CPU 釋放 memory 時就會使用 LRU Cache 來刪除最近最少使用的東西。 概念沒什麼大不了的,重點是要怎麼實現? B...

Wayne

System Design 101 - Introduction to CAP theorem

* 一致性(**C**onsistency) * 可用性(**A**vailability) * 分區容錯性(**P**artition tolerance) CAP 理論就是在說 CAP 只能滿足其中兩者,不可能三者都滿足。 > 在理論計算機科學中,CAP定理(CAP...

Wayne

How to dynamically create page in Gatsby.js from GraphQL source

1 - Install `gatsby-source-graphql` 2 - Add `gatsby-source-graphql` setting into `gatsby-config.js` ```js { resolve: `gatsby-source-g...

Wayne

How to replace moment.js

Found this repo: https://github.com/you-dont-need/You-Dont-Need-Momentjs Replacement: - [date-fns](https://github.com/date-fns/date-fns...

Wayne

How to add self-hosted fonts in Gatsby

This note is copied from https://dev.to/iangloude/4-steps-to-self-hosted-fonts-in-gatsby-aj2 1 - place your font files in `src/static/fo...

Wayne

Weird warning with Ruby 2.7

I kept having this `The called method '…' is defined here` warning from my rails console. Ex: ``` /Users/wayne/.rvm/gems/ruby-2.7.0/gems...

Wayne

ActiveStorage#attach has different return value between v5 and v6

In activestorage v5 ```rb current_user.images.attach( io: file, filename: file.original_filename, content_type: file.content_type ...

Wayne

We can change ActiveStorage route_prefix in Rails 6

Usage: ```rb # config/application.rb config.active_storage.routes_prefix = '/files' ``` So instead of having route like `www.example.c...

Wayne

Finally we can disable generated scope from ActiveRecord#enum in Rails 6

Usage: ```rb class Post < ApplicationRecord enum state: { draft: 0, published: 1, personal: 2 }, _scopes: false end ``` PR: https://g...

Wayne

幫衝浪板快速除蠟的神奇技巧

先公布解答:熱水 + 抹布。 以前除蠟都是把衝浪板拿到大台陽底下曬,然後再辛苦的用刮蠟東西把蠟一層一層刮下來,有時候刮到一半蠟又變硬或是底下的蠟還沒被曬溶,就會變得很難除。雖然說可以買除蠟用的 Wax Remover 來讓蠟融掉,但為了除蠟還買化學液體總覺得有點太超過了...

Wayne

如何 DIY 修理壞掉的衝浪板 Fin Box

## 需要的工具 - 美工刀 - 尖嘴鉗 - 砂紙 (80 grit) - 膠帶 - Q cell - Polyster Resin - MEKP Catalyst - 玻璃纖維布 (fiberglass cloth) - 新的 Fin Box P.S.// 我的板是...

Wayne

Ruby 2.7 pattern matching official docs has released

早前一篇文章 [New features in Ruby 2.7](/posts/361-new-features-in-ruby-2-7) 提到了 Ruby 2.7 將要有 pattern matching,現在 [official docs](https://docs....

Wayne

Validate JSON schema in Rails

This is an archive of my post from 2017 (revised by [@morhekil](https://twitter.com/morhekil)), original posted in [medium](https://mediu...

Wayne

How to communicate with iframes inside WebView

This is an archive of my post from 2017 (revised by [@morhekil](https://twitter.com/morhekil)), original posted in [medium](https://mediu...

Wayne

Flutter vs ReactNaive

最大的差異應該就在於 ReactNative 依賴於 JavaScript bridge running on run time,且對原生 components 的支援度較低 Flutter 的優勢則在於對原生的支援度高,因為不需要 bridge 就可以 communic...

Wayne

Using RabbitMQ and Hutch with RPC call for queue in Rails

This is an example how the author implement the RPC call using Hutch and communicate with RabbitMQ https://karolgalanciak.com/blog/2020/...

Wayne

寫 Ruby gem 的 best practice

寫 Ruby gem 的 best practice,滿受用的但太長了有空再來看,先記一下,please check the referecne ### Referecne - https://piotrmurach.com/articles/writing-a-rub...

Wayne

How to pass arguments to rake task

1. rake way ```rb task :add, [:num1, :num] do |t, args| puts args[:num1].to_i + args[:num].to_i end # rake add\[1,2\] ``` 2. ENV ``...

Wayne

Ruby under a microscope - Chapter 1 - Tokenization and Parsing

This is my reading note about the book `Ruby under a microscope` Chapter 1 - Tokenization and Parsing 第一章在講我們寫的 ruby code 是怎麼經過一系列的轉換最後...

Wayne

Install SElinux

```shell # install sudo apt install policycoreutils selinux-utils selinux-basics # activeate sudo selinux-activate # change to enforci...

Wayne

How to add a new user in kali linux

```shell ec2-user@kali:~$ su root@kali:/home/ec2-user# root@kali:/home/ec2-user# useradd -m wayne root@kali:/home/ec2-user# passwd wayne...

Wayne

Ruby HTTP client options

- The built-in net/http client - Faraday - http.rb (HTTP The Gem) - rest-client - httparty - excon - Typhoeus - Curb For some pros and c...

Wayne