Skip to content

Instantly share code, notes, and snippets.

@ChengLong
ChengLong / commands.md
Created March 12, 2017 09:43
Enable cURL with HTTP/2 on Mac

This is directly taken from this post

  • Install cURL with nghttp2 support brew install curl --with-nghttp2
  • Link the formula to replace the system cURL brew link curl --force
  • Reload shell
  • Test an HTTP/2 request passing the --http2 flag curl -I --http2 https://www.google.com/
@ChengLong
ChengLong / nginx.conf
Last active June 6, 2016 06:02
Secure and fast nginx.conf
user nginx;
worker_processes auto;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
use epoll;
multi_accept on;
}
@ChengLong
ChengLong / cucumber_save_screenshots.md
Last active March 19, 2016 16:50
Automatically save a screenshot when any scenario fails

To save a screenshot automatically when any scenario fails, add the following in features/support/env.rb

After do |scenario|
  if scenario.failed?
    timestamp = "#{Time.zone.now.strftime('%Y-%m-%d-%H:%M:%S')}"
    screenshot_name = "screenshot-#{scenario.name.parameterize.underscore}-#{timestamp}.png"
    screenshot_path = "#{Rails.root.join('tmp/capybara')}/#{screenshot_name}"
    Capybara.page.save_screenshot(screenshot_path)
 end
@ChengLong
ChengLong / postgres.md
Created March 14, 2016 09:35
Postgres Commands

Check status

pg_ctl status -D /usr/local/var/postgres

Start at a data dir and a log file

pg_ctl start -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log
@ChengLong
ChengLong / site.conf
Last active June 6, 2016 06:04
Nginx HTTPS config with Let's Encrypt, HTTP/2 and HTTP redirect
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name domain.com www.domain.com;
ssl on;
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/domain.com/privkey.pem;
ssl_session_timeout 1d;
@ChengLong
ChengLong / awesome_print.md
Last active August 29, 2015 14:08
Use awesome_print
  1. gem install awesome_print
  2. Add below to ~/.irbrc
require "awesome_print"
AwesomePrint.irb!
  1. Add gem 'awesome_print', group: :development in Gemfile
  2. Enjoy
@ChengLong
ChengLong / apache_fqdn.md
Created October 27, 2014 17:24
Solve Apache unresolved fqdn

On Ubuntu >=14.04, if you see this when using Apache

AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message

Do:

  1. echo "ServerName localhost" | sudo tee /etc/apache2/conf-available/fqdn.conf
  2. sudo ln -s /etc/apache2/conf-available/fqdn.conf /etc/apache2/conf-enabled/fqdn.conf
@ChengLong
ChengLong / virtual_host_apache.md
Created October 27, 2014 17:17
Add Virtual Host in Apache
  1. Create a virtual host file at /etc/apache2/sites-available/yoursite.conf, e.g.
<VirtualHost *:80>
  ServerName yoursite.com
  DocumentRoot /somewhere/public
  
  <Directory /somewhere/public>
     # This relaxes Apache security settings.
AllowOverride all
@ChengLong
ChengLong / install_passenger_apache.sh
Created October 27, 2014 17:05
Install Passenger with Apache on Ubuntu
sudo gem install passenger
# install dependencies
sudo apt-get install -y libcurl4-openssl-dev apache2 apache2-prefork-dev libapr1-dev libaprutil1-dev
# follow instructions
sudo passenger-install-apache2-module
@ChengLong
ChengLong / add_swap.sh
Created October 26, 2014 08:12
Add 4GB swap and tweak swappiness and vfs cache pressure
# create a 4G swap file at /swapfile
sudo fallocate -l 4G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
# Make the Swap File Permanent
sudo echo "/swapfile none swap sw 0 0" >> /etc/fstab
# set swappiness to 10