Skip to content

Instantly share code, notes, and snippets.

View linw1995's full-sized avatar
🎯
Focusing

林玮 (Jade Lin) linw1995

🎯
Focusing
View GitHub Profile
@linw1995
linw1995 / aa_tree.c
Created February 12, 2019 15:16
AA Tree C implementation.
#include <stdlib.h>
#define MIN(a, b) (a > b ? b : a)
struct TreeNode
{
int val;
struct TreeNode *left;
struct TreeNode *right;
};

在 Centos 6.8 中安装 Python 3.7

安装依赖

yum install -y \
  zlib \
  zlib-devel \
  sqlite-devel \
  bzip2-devel \
@linw1995
linw1995 / kbd6x(hhkb).json
Last active July 15, 2019 15:37
KBD6x HHKB Config
{
"version": 1,
"keyboard": {
"keys": [
{
"id": 0,
"legend": "~\n`",
"state": {
"x": 0,
"y": 0,
@linw1995
linw1995 / multiprocess.py
Created July 18, 2019 13:07
用多线程加速爬虫做 lxml 解析 | 源码
import asyncio
import time
from concurrent.futures import ProcessPoolExecutor
from pathlib import Path
from lxml import html
_html_text = None
_latest_fetched = 0
@linw1995
linw1995 / download_chromedriver.py
Created December 24, 2019 09:32
Download the proper version of chromedriver for chrome.
# Standard Library
import os
import platform
import re
import stat
import subprocess as sp
import zipfile
import tempfile
from typing import List
@linw1995
linw1995 / catch_uncatched_exception.py
Created January 6, 2020 03:19
Use `threading.trace` to catch uncatched exception
import threading
def raise_from_top():
raise RuntimeError
def raise_from_second_frame():
raise_from_top()
def raise_from_third_frame():
raise_from_second_frame()
@linw1995
linw1995 / poetry.lock
Last active May 20, 2020 14:20
Export wrong dependencies when using optional=true
[[package]]
category = "main"
description = "Atomic file writes."
marker = "sys_platform == \"win32\""
name = "atomicwrites"
optional = true
python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*"
version = "1.4.0"
[[package]]
@linw1995
linw1995 / .emacs
Created June 20, 2020 06:51
My Simple Emacs Configure
;;; Package Managing
;; Bootstrapping straight.el
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name "straight/repos/straight.el/bootstrap.el" user-emacs-directory))
(bootstrap-version 5))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/raxod502/straight.el/develop/install.el"
@linw1995
linw1995 / README.md
Last active December 25, 2020 06:28
Parse code of JavaScript to convert literal statement like preloaded state of Redux.js into python data.
@linw1995
linw1995 / README.md
Last active June 6, 2021 06:51
Please don't use ContextVar.reset in async_generator.

Please don't use ContextVar.reset in async_generator.

Important rule: Different coroutines own different contexts.

  • The example1.py runs one coroutine with async_generator, the async_generator.__anext__ method runs in same context and thus it works find.
  • The example2.py produces two coroutines with the same async_generator, the async_generator.__anext__ method runs in different contexts and thus it raises an ValueError exception.

Tips for async_generator with ContextVar