Skip to content

Instantly share code, notes, and snippets.

View baichen99's full-sized avatar
🎯
Focusing

baichen baichen99

🎯
Focusing
  • Shanghai, China
View GitHub Profile
@baichen99
baichen99 / wsl_clash_proxy.sh
Created September 11, 2024 10:57 — forked from libChan/wsl_clash_proxy.sh
WSL2使用clash for windows代理
# WSL通过Win访问网络,所以WSL的网关指向的是Windows,DNS服务器指向的也是Windows,设置WSL的proxy为win的代理ip+端口即可
# WSL中的DNS server在/etc/resolv.conf中查看,该文件是由/etc/wsl.conf自动生成的。
# 如果关闭了wsl.conf中自动生成resolve.conf并自行修改了resolve.conf,DNS nameserver并不是本机win ip
# 需要开启wsl.conf的自动生成,再运行以下命令
# https://zhuanlan.zhihu.com/p/153124468
# 添加到环境变量设置中,例如~/.zshrc
export hostip=$(cat /etc/resolv.conf |grep -oP '(?<=nameserver\ ).*')
export https_proxy="http://${hostip}:7890"
export http_proxy="http://${hostip}:7890"
@baichen99
baichen99 / xml_to_json
Created August 4, 2022 09:14
convert xml to json
# pip install xmltodict
import xmltodict
import json
def xml_to_json(xml_path, out_path):
with open(xml_path, 'r', encoding='utf-8') as xml_file:
data_dict = xmltodict.parse(xml_file.read())
with open(out_path, 'w') as f:
json.dump(data_dict, f, ensure_ascii=False, indent=4)
@baichen99
baichen99 / extract.py
Created August 2, 2022 12:46
extract data from a table in python
# https://stackoverflow.com/questions/16036337/regular-expression-to-extract-data-from-a-table-in-python
def gen_regex(title, col_num, start_with_space=False):
if start_with_space:
r = f'{title}\n((?:(?:[\s]+[^\s]+[\s]+){{{col_num-1}}}[^\s]+\n)+)'
else:
r = f'{title}\n((?:(?:[^\s]+[\s]+){{{col_num-1}}}[^\s]+\n)+)'
return r