Skip to content

Instantly share code, notes, and snippets.

Hey! What's up?

Jonathan ES Lin ernsheong

Hey! What's up?
View GitHub Profile
ernsheong /
Created Apr 4, 2018 — forked from joewiz/
Recovery from nginx "Too many open files" error on Amazon AWS Linux

On Tue Oct 27, 2015, began buckling under load, intermittently issuing 500 errors. Nginx's error log was sprinkled with the following errors:

2015/10/27 21:48:36 [crit] 2475#0: accept4() failed (24: Too many open files) 2015/10/27 21:48:36 [alert] 2475#0: *7163915 socket() failed (24: Too many open files) while connecting to upstream...

An article at provided directions that mostly worked. Below are the steps we followed. The steps that diverged from the article's directions are marked with an *.

    • Instead of using su to run ulimit on the nginx account, use ps aux | grep nginx to locate nginx's process IDs. Then query each process's file handle limits using cat /proc/pid/limits (where pid is the process id retrieved from ps). (Note: sudo may be necessary on your system for the cat command here, depending on your system.)
  1. Added fs.file-max = 70000 to /etc/sysctl.conf
  2. Added `nginx soft nofile 1
ernsheong / nginx.conf
Created Apr 4, 2018 — forked from v0lkan/nginx.conf
Configuring NGINX for Maximum Throughput Under High Concurrency
View nginx.conf
user web;
# One worker process per CPU core.
worker_processes 8;
# Also set
# /etc/security/limits.conf
# web soft nofile 65535
# web hard nofile 65535
# /etc/default/nginx
ernsheong /
Last active Jul 14, 2021
Accessing macOS localhost from Parallels Desktop IE or Edge

Access macOS localhost from IE or Edge within Parallels Desktop

This issue is so infuriating that I'm going to take some time to write about it.

  1. MOST IMPORTANT. Your local development server must be bound to IP address Some do this by default, but many don't. You need to make sure that you run your local server with correct IP bindings. You may need to provide additional flags to your serve commands e.g. polymer serve --hostname domain.local, hugo serve --bind If you use a named domain like domain.local, it has to be defined in /etc/hosts and pointing at

  2. My Parallels setting is using Shared Network, nothing special there.

  3. Open macOS Terminal and type ifconfig. Look for the value under vnic0 > inet. It is typically

ernsheong /
Last active Dec 19, 2019
Implementing OAuth2 Resource Owner Password Credentials Grant with Kong

Implementing OAuth2 Resource Owner Password Credentials Grant with Kong

The documentation is okay, but it has some holes, and I had to read it many many times and play with the API myself to "get it" in terms of implementation. So here is a guide that I hope will help someone along the way.

DISCLAIMER: This is by no means the canonical or the most secure way to do this. Below are my findings upon my reading of the docs and the spec. But I might be wrong, very wrong.

This gist is meant to complement the documentation in

The Resource Owner Password Credentials Grant makes sense if we want to authenticate users who are using our trusted 1st party applications of our own service. (However, you might not want to trust your JavaScript SPA with your refresh token, and maybe you need to store that refresh token in the server on behalf of the SPA if you are paranoid about security. Disclaimer: I am not a security expert)

ernsheong / before_spec.rb
Created Aug 28, 2012
Testing behavior of before vs. before :each vs before :all
View before_spec.rb
require 'spec_helper'
$count = 0
$count_each = 0
$count_all = 0
shared_examples_for "before :each" do
it { should == 1 }
it { should == 2 }
ernsheong / test_let_spec.rb
Created Aug 27, 2012
Exploring let and let! in RSpec. Puzzled by how let and let! behaves, I decided to take and modify it further to inspect let and let!
View test_let_spec.rb
require 'spec_helper'
# comment out `config.order = "random"` in spec_helper or run rspec with `--order default` configuration (just for illustration)
# I have Database Cleaner set up in spec_helper too
$count1 = 0
$count2 = 0
describe "let and let!" do
describe "let!" do
ernsheong / gist:3080264
Created Jul 10, 2012 — forked from lucasfais/gist:1207002
Sublime Text 2 - Useful Shortcuts
View gist:3080264

Sublime Text 2 – Useful Shortcuts (Mac OS X)


⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt