Skip to content

Instantly share code, notes, and snippets.

View kieetnvt's full-sized avatar
👋

Kiet Nguyen kieetnvt

👋
View GitHub Profile
@kieetnvt
kieetnvt / Adding swap space to an EC2 Amazon Linux instance
Last active November 2, 2017 16:59
Adding swap space to an EC2 Amazon Linux instance
With instance EC2 T2.micro 1.0 GiB 1 vCPUs (http://www.ec2instances.info/?cost_duration=monthly&selected=t2.micro)
Here are the steps I took to enable swap space:
dd if=/dev/zero of=/swapfile bs=1M count=512
mkswap /swapfile
chmod 600 /swapfile
swapon /swapfile
You also have to edit your fstab file so the swap is available after reboot:
@kieetnvt
kieetnvt / Optimize webpage speed
Last active October 10, 2023 05:10
Optimize webpage speed
Optimize webpage speed:
- Tools: Google Pagespeed Insight, Gtmetrix.com, Webpagetest.org, Image Analysis of Webpagetest.org
- Tools mobile: Webpagetest.org, https://testmysite.thinkwithgoogle.com/
1. Using sprite CSS for all images
2. Optimize images using tool Tinypng.com
3. Eliminate render-blocking JavaScript in above-the-fold content
- Use content_for custom js in Rails
@kieetnvt
kieetnvt / Ruby on Rails code guide style
Last active November 9, 2017 01:58
Ruby on Rails code guide style
Config chung
Initializer
- Để các code khởi tạo trong thư mục config/initializers. Các đoạn code để trong thư mục này sẽ tự động execute khi server khởi động.
- Để các code khởi tạo thành các file riêng theo gem. Ví dụ: carrierwave.rb, devise.rb…
Global variable
- Các biến global như email dùng để gửi mail, hostname, … nên để trong các file config/enviroments/development.rb,config/enviroments/production.rb
@kieetnvt
kieetnvt / Adyen Test card numbers
Last active January 15, 2020 03:43
Adyen Test card numbers
I. INTRO
- Only valids for TEST env
- All cards below have expiration dates and security codes:
| Expiration Date | CVV2 / CVC3 | CID (American Express) |
| 08/2018 | 737 | 7373 |
| 10/2020 | 737 | 7373 |
II. CARDS
= Mastercard
| Card Number | Card Type | Issuing Country |
@kieetnvt
kieetnvt / restart_resque_rails
Last active November 2, 2017 07:44
Restart Resque with Rails 4
Restart with Capistrano:
cap production resque:restart
cap production resque:scheduler:restart
If you use resque-scheduler, when you have new job in resque_scheduler.yml, you will need restart redis server to verify it:
sudo /etc/init.d/redis_6379 stop
sudo /etc/init.d/redis_6379 start
@kieetnvt
kieetnvt / rack-mini-profiler-rails-4.md
Last active November 20, 2017 16:43
How to enable rack-mini-profiler in Rails 4
  1. Add gem in Gemfile:

gem 'rack-mini-profiler', require: false, group: :development

  1. Move config.middleware.use Rack::Deflater from config/application.rb to config/environments/production.rb

  2. Edit config/initializers/rack_profiler.rb:

if Rails.env.development?
@kieetnvt
kieetnvt / manual_set_paperclip.md
Created November 30, 2017 14:47
Set image paperclip with rails console
class ProductPhoto < ActiveRecord::Base
  belongs_to :product
  has_attached_file :photo, styles: {large: '1024x1024', medium: '300x300', small: '150x150#', item: '150x'}
  validates_attachment_content_type :photo, content_type: /\Aimage/
  validates :photo, presence: true
end
@kieetnvt
kieetnvt / pretty_rails_console.md
Created November 30, 2017 16:18
Rails console: six ways to get pretty output
  1. use Pry command: in rails console:
> pry

you will redirected to pry console:

pry(main)
1) Create a linux user and set password
sudo adduser read_access
.. then enter your password for this user
2) Limit permission for the user (option)
.. normally, this user only has root permission on it's directory. (/home/read_access)
3) Set read-only role for this user to use Postgresql
@kieetnvt
kieetnvt / 00.howto_install_phantomjs.md
Created January 3, 2018 07:34 — forked from julionc/00.howto_install_phantomjs.md
How to install PhantomJS on Debian/Ubuntu

How to install PhantomJS on Ubuntu

Version: 1.9.8

Platform: x86_64

First, install or update to the latest system software.

sudo apt-get update
sudo apt-get install build-essential chrpath libssl-dev libxft-dev