Skip to content

Instantly share code, notes, and snippets.

View kadaliao's full-sized avatar
:octocat:

Kada Liao kadaliao

:octocat:
  • Beijing
View GitHub Profile
@kadaliao
kadaliao / generate_requirements.py
Created April 26, 2023 10:54
Generate requirements.txt and requirements-dev.txt from pyproject.toml
import tomlkit
def format_version_constraint(constraint):
if constraint.startswith("^"):
constraint = (
">="
+ constraint[1:]
+ ",<"
+ ".".join(
import copy
X = spark.createDataFrame([[1,2], [3,4]], ['a', 'b'])
_schema = copy.deepcopy(X.schema)
_X = X.rdd.zipWithIndex().toDF(_schema)
#!/usr/local/bin/bash
############################### FOLDER ICONS ###################################
folder="$(pwd)"
# Construct the path for the folder icon
FOLDER_ICON_PATH="$folder/.icon"
if [ -f $FOLDER_ICON_PATH ]; then
@kadaliao
kadaliao / quick-power.py
Created September 11, 2021 07:33
快速幂方法
import hypothesis.strategies as st
from hypothesis import given
def quick_pow(a: int, b: int) -> int:
base, ans = a, 1
while b:
if b & 1:
ans *= base
base *= base
@kadaliao
kadaliao / how-to-kill-a-thread.py
Last active September 7, 2021 18:24
使用事件优雅杀死 Python 线程
import threading
import time
import signal
# Python会等待非 daemon 线程运行结束,如果进程收到 SIGINT 信号,会提醒一次,第二次结束线程了
# Python不会等待 daemon 线程运行结束,收到 SIGINT 信号,就结束 Python 进程,线程也就不存在了
# 使用信号 handler 来优雅退出
event = threading.Event()
@kadaliao
kadaliao / external_sort.py
Last active September 2, 2021 10:03
大文件桶排序
"""
演示外部排序-桶排序
拆分大文件到固定尺寸的桶中,桶内进行排序之后,再合并成排序好的大文件。
"""
import os
import shutil
import random
from math import ceil
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
### Keybase proof
I hereby claim:
* I am kadaliao on github.
* I am kadaliao (https://keybase.io/kadaliao) on keybase.
* I have a public key ASBIcqEdc6oBkcHJyH0NbyARfgSacweeqa3Lvw8PMj49fQo
To claim this, I am signing this object:
@kadaliao
kadaliao / install-docker.sh
Created June 26, 2020 06:55
CentOS一键安装 Docker 脚本
#!/bin/bash
# 移除掉旧的版本
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \