NodeJS Http-Proxy with WebSocket

WebSocket has been supported widely in the past few years. More and more applications are embracing this and using it to replace AJAX / Commit / LongPooling. Set up a NodeJS server with WebSocket is easier, but how to do it correctly especially when your application is behind web proxies? Here I’m going to use a simple http server and websocket native implementaion ws, a http proxy based on http-proxy .

Read More

Set up Kubeadm on MacOS with Vagrant and VirtualBox

Based on kubeadm installation instructions, we can’t directly install it on MacOS. But with the help of Vagrant and VirtualBox, we can quickly create a local kubenetes cluster.

Read More

MMM, Ma-Po Tofu !

It might be a dish foreign for you; in fact, it was foreign to me too. Ma-Po tofu originates from a region in China but far away from my hometown. The first time that I had it was in my first year of college. It and me, both had left home, just met in a small restaurant next to our campus. Gladly, I was not alone, neither was the dish. There were new friends of mine sitting around a table, and Ma-Po Tofu took the center, having always had the charm to attract people from all over the country. It may be welcomed by people from all over the world one day.

Read More

Multi-Stage Golang Docker Image Build and Kubernetes Deployment

If we have a tiny web service which return the host name as below. We can use golang image and build the executable package, then move it into a basic linux container like alpine.

Read More

Mastering Go Notes

  1. If you have to check godoc offline, you could install gdoc go get golang.org/x/tools/cmd/godoc and then run godoc -http :8001 in termilal.

Read More

Monotonic Stack

Monotonic Stack is the best time complexity solution for many “range queries in an array” problems. Because every element in the array could only enter the monotonic stack once, the time complexity is O(N). (N represents the length of the array).

Read More

Indoor bluetooth location

Indoor positioning technology is more and more widely used in daily life, such as indoor navigation, smart home, shopping mall advertisement, etc. This article will detail the principles of this technique and its advantages in practical applications.

Read More

Dynamic Programming IV

115. Distinct Subsequences

Let’s denote dp[i][j] as the amount of distinct subsequences in s[:i] which can construct t[:j]. So we can get the state transition function dp[i][j] = s[i - 1] == t[i - 1] ? (dp[i - 1][j - 1] + dp[i - 1][j] : dp[i-1][j]. Also for the initial value, dp[i][0] needs to be 0 (it means there’s one way we can construct empty string from s[:i]).

Read More

Dynamic Programming III

300. Longest Increasing Subsequence

If we define dp[i] as the longest increasing subsequence of [0, i]. Then dp[i] >= 1. And the state transition function is dp[i] = max(dp[i], dp[j] + 1) here j ∈ [0, i).

Read More

Stock Exchange Problems

121. Best Time to Buy and Sell Stock

a. Two pointers greedy solution.

Read More