Skip to content

Instantly share code, notes, and snippets.

View tanhit243's full-sized avatar
💭
I may be slow to respond.

Vu Tuan Anh tanhit243

💭
I may be slow to respond.
View GitHub Profile
Chỉ định thứ tự theo các trường cụ thể
https://blog.kiprosh.com/rails-7-in_order_of-method-for-activerecord-and-enumerable/
Tìm bản ghi duy nhất trong DB
- nếu không tìm thấy thì raise ActiveRecord::RecordNotFound
- nếu tìm thấy nhiều hơn một bản ghi thì raise ActiveRecord::SoleRecordExceeded
@tanhit243
tanhit243 / has_secure_token in rails
Created August 5, 2022 05:51
Hỗ trợ tạo đoạn token
https://api.rubyonrails.org/classes/ActiveRecord/SecureToken/ClassMethods.html
https://ruby-doc.org/stdlib-3.1.2/libdoc/English/rdoc/English.html
@tanhit243
tanhit243 / README.md
Created August 2, 2022 03:26 — forked from jesster2k10/README.md
JWT Auth + Refresh Tokens in Rails

JWT Auth + Refresh Tokens in Rails

This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.

I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)

Before trying it out DIY, I considered using:

THOR_MERGE="code -d $1 $2" rails new . -d mysql
tar to extract files from a tarball with option directory
tar -zxvf Project4x.tar.gz -C dir_path
unzip file.zip -d dir_path
Use cmd: dmesg,
You can use grep, tail, less
dmesg | tail -n 30
Command to add public key from local to server
ssh-copy-id -i public_key_file_name user@server