Skip to content

Instantly share code, notes, and snippets.


Windson yang Windsooon

View GitHub Profile
Windsooon /
Last active Sep 17, 2019
  1. function call stack

    When I'm new to a project or repo, lots of time I get lost How A function call D function (e.g. foo function calls exa function and exa function calls bar function). After I understand How D function works by code search. I forgot about what A function does already. It will to great if we can add the call stack from A function to D function so developers would not get lost. For example:


  1. Understand the projects

    When I use code search, what I want is have a better understanding of the project I'm working on. If this is one of the missions from Sourcegraph, we can create some handly tools for developers. For example,


Idea behind it

I choose Golang to implement the API for two reasons. First, this is a challenge, it will be boring if I keep using my old stack. Second, Golang makes writing a concurrent program easily which is what the requirements ask for.

1. The API must be able to handle high throughput (~1k requests per second).
2. The API should also be able to recover and restart if it unexpectedly crashes.
3. Assume that the API will be running on a small machine with 1 CPU and 512MB of RAM.

For No.1 and No.3, we need to use 1 CPU and 512MB of RAM to handle ~1k requests per second. Therefore, asynchronous I/O would be the best choice. Golang has goroutine which is a perfect fit for this situation. To support restart, we can use Supervisord to monitor the current Go web server, I didn't implement this part because it's more related to configuration than system design (I used it before, feel free to ask me questions for it). To support recovery, for instance,


建议先完成第一题 Permutations:

解法一:使用一个 hashtable 对象或者 set 对象,重复的元素不要放到结果中。只需要在第一题的基础加上一个判断即可。


Input: [1,1,2] Output: [ [1,1,2],

View gist:e59a680df7eed541c02140004b9aa844

Subarray Sum Equals K

建议先完成 Subarray Sum Equals K

  1. 我们可以观察到对于任意数组 sum(array[i, j]) = sum(array[0, j] - sum(array[0, i-1])

  2. 所以我们可以先创建一个 presum 数组,其中 presum[i] = sum(A[0,i]),例如 array = [1, 2, 3], 则 presum = [1, 3, 6]

  3. 根据 0,我们可以得到 sum(array[i, j]) = presum[j] - presum[i-1]

    array[1:2] = 5 = presum[2] - presum[0]
    array[1:1] = 3 = presum[1] - presum[0]
Windsooon / bash
Created May 23, 2019
CPython compiled failed in macOS
View bash
gcc -c -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fmax-type-align=8 -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -I./Include/internal -I. -I./Include -DPy_BUILD_CORE \
-DMULTIARCH=\"darwin\" \
-o Python/sysmodule.o ./Python/sysmodule.c
gcc -c -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fmax-type-align=8 -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -I./Include/internal -I. -I./Include -DPy_BUILD_CORE \
-DSOABI='"cpython-38-darwin"' \
-o Python/dynload_shlib.o ./Python/dynload_shlib.c
gcc -c -Wno-unused-result -Wsign-compare -Wunreachable-code -DNDEBUG -g -fwrapv -O3 -Wall -fmax-type-align=8 -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstri
Windsooon / bash
Created May 7, 2019
Compile error
View bash
gcc -c -Wno-unused-result -Wsign-compare -g -O0 -Wall -fmax-type-align=8 -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Programs/python.o ./Programs/python.c
gcc -c -Wno-unused-result -Wsign-compare -g -O0 -Wall -fmax-type-align=8 -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Parser/acceler.o Parser/acceler.c
gcc -c -Wno-unused-result -Wsign-compare -g -O0 -Wall -fmax-type-align=8 -std=c99 -Wextra -Wno-unused-result -Wno-unused-parameter -Wno-missing-field-initializers -Wstrict-prototypes -Werror=implicit-function-declaration -I./Include/internal -I. -I./Include -DPy_BUILD_CORE -o Parser/grammar1.o Parser/grammar1.c
gcc -c -Wno-unused-result -Wsign-compare -g -O0 -Wall -fmax-type
import os
import subprocess
import logging
from signal import SIGTERM
# Setup logging
logger = logging.getLogger('__name__')
# Handler
stream = logging.StreamHandler()
class Pupil_Recording(System_Plugin_Base):
Collect log in recording
def __init__(self, g_pool):
self.order = 0.08
self.notify_sub = zmq_tools.Msg_Receiver(
zmq_ctx, ipc_sub_url, topics=("notify",))
View gist:3df1a13f3d91b58d5303c685849cf385
** A. CalledProcessError (only the first time)**
1. run `python player`
2. use 001 as recording files
3. run `Redetect` in `Offline Pupil Detection`
(pupil) windson@WindsondeAir ~/learn/pupil/pupil_src (v1.11-preview) $ python player
MainProcess - [INFO] os_utils: Disabled idle sleep.
You can’t perform that action at this time.