Skip to content

Instantly share code, notes, and snippets.

View kadaliao's full-sized avatar
:octocat:

Kada Liao kadaliao

:octocat:
  • Beijing
View GitHub Profile
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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
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 / rsa_util.py
Last active November 27, 2020 09:20
a rsa helper that can handle large size message, no length error.
# coding: utf-8
# use module pycryptodome
from Crypto import Random
from Crypto.Cipher import PKCS1_OAEP
from Crypto.Hash import MD5, SHA, SHA1, SHA256, SHA384, SHA512
from Crypto.PublicKey import RSA
from Crypto.Signature import PKCS1_v1_5
from Crypto.Util import number
@kadaliao
kadaliao / split_list.py
Created October 24, 2018 04:09
等份切割列表
def split_list(li, chunks=1):
for i in range(0, len(li), chunks):
yield li[i:i+chunks]
@kadaliao
kadaliao / get_logger.py
Created October 24, 2018 02:45
返回一个输出到控制台和文件的 logger
def get_logger(log_path):
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
st_handler = logging.StreamHandler(sys.stderr)
st_handler.setLevel(logging.DEBUG)
st_handler.setFormatter(logging.Formatter(
'%(asctime)s %(levelname)s: %(message)s '
'[in %(pathname)s:%(lineno)d]'))
file_handler = RotatingFileHandler(log_path,