Category Archives: algorithm

Setup specific python version in virtualenv; setup virtualenv for PyCharm

Download the python version you want, and install. In cmd, type python3.8 Find the python3.8 Library path. Create python3.8 virtualenv virtualenv -p /Library/Frameworks/Python.framework/Versions/3.7/bin/python3 venv Activate venv source venv/bin/activate Check python version python –version In PyCharm, select the created virtual env In not existed in Project Interpreter, then click “Show All”, click ‘+’ to add a new… Read More »


install nginx client_header_timeout, time when all header packets arrives nginx. client_body_timeout, time when nginx hasn’t received a body packet, then timeout. NOT receiving whole body time. Kinda like read timeout. send_timeout, similar to client_body_timeout. when nginx sends response to client, the time when nginx hasn’t received an ACK. keepalive_timeout, connection becomes to idle when… Read More »


For example, each pair is labeled as [l1, r1]. Because the pairs sequence is ordered by r. So, we can just iterate it. For current pair, if the l is overlapped with previous pair, then don’t consider it. This is a greedy strategy.


dp[i][j] is the result between stone i, and stone j. If left is greater, then dp[from][from+delta] = sum(i, from+delta) + dp[i][from+delta] Else right part If both left and right are same, then choose the one which dp has larger value


There are actually 2 types of OPs. One is to make all digit multiplying by 2, this can be shared by all numbers together. Another is adding one. This can’t be shared. So result would be count how many one digit, plus the highest bit count.


Solution 1, just like frog jump. public static int minDays(int n) { int[] dp = new int[n + 1]; Arrays.fill(dp, Integer.MAX_VALUE); dp[0] = 0; for (int i = 0; i <= n; i++) { if (i * 2 <= n) { dp[i * 2] = Math.min(dp[i * 2], dp[i] + 1); } if (i *… Read More »

GoReplay traffic pattern change

After testing with GoReplay, it shows that GoReplay will change the traffic pattern. When setting a fix RPS rate traffic, GoReplay will just replay the traffic with fix RPS. For some caching use case, this may fail. Let’s say request 1, 2, 3, 4 are all same. We want to cache for request 1, then… Read More »


Install docker on mac: brew install docker Download docker.dmg and install Run jenkins in background docker run -d -p 8080:8080 -p 50000:50000 jenkins // 8080:80, host port 8080, container port 80 -d makes it to run background. Just like nohup Run centos in docker docker run -it centos /bin/bash -it makes it run interactive mode,… Read More »


Region, AZ, data center A region has minimum 2 data centers. Data center is physical location. 2 data centers are physically isolated. Each AZ is backed by 1 or more data centers. Abstracting things further, to distribute resources evenly across the zones in a given region, Amazon independently maps zones to identifiers for each account.… Read More »

Java version switch

# Add below in ~/.zshrc export JAVA_HOME=`/usr/libexec/java_home -v 1.8` export JAVA_HOME=`/usr/libexec/java_home -v11` # Check java version /usr/libexec/java_home -v 11