Skip to content

Instantly share code, notes, and snippets.

@kenchou
kenchou / [email protected]
Last active April 29, 2024 07:22
systemd KCP 加速服务
[Unit]
Description=Kcptun server
Requires=network.target
After=network-online.target
[Service]
Type=simple
User=ken
RemainAfterExit=yes
Environment="MODE=fast3"
@kenchou
kenchou / __on_pwd_changed.fish
Last active April 2, 2024 05:23
进入git仓库目录自动执行 onefetch 显示统计信息。使用 fish 事件实现。来源 https://github.com/o2sh/onefetch/wiki/getting-started
# ~/.config/fish/events/
# 改变目录事件
function __on_pwd_changed --on-variable PWD
check_directory_for_new_repository
end
@kenchou
kenchou / gdrive-download-files.sh
Created March 15, 2024 08:28
Download or export file from GDrive
#!/usr/bin/env bash
# ## Dependencies:
# brew install gdrive
# ## Setup:
# gdrive account add
# Recursive function to download files in a folder
gdrive_download_files() {
local folder_id=$1
@kenchou
kenchou / calc_24.py
Last active November 4, 2023 10:41
calculate 24
import click
from decimal import Decimal
from itertools import permutations, product
def calculate24(nums):
ops = list(product(["+", "-", "*", "/"], repeat=3)) # 所有可能的运算符组合
num_perms = list(permutations([Decimal(n) for n in nums])) # 所有可能的数字组合
result = False
solutions = []
@kenchou
kenchou / deduplicate.py
Last active July 20, 2023 02:49
deduplicate
def deduplicate(ls: list, selector=lambda x: x) -> list:
seen = set()
return [x for x in ls if (e := selector(x)) not in seen and (seen.add(e) or True)]
@kenchou
kenchou / miwifi_overlay.sh
Last active February 12, 2025 10:57
小米/红米路由器挂载 overlay
#!/bin/sh /etc/rc.common
START=00
. /lib/functions/preinit.sh
start() {
[ -e /data/overlay ] || mkdir /data/overlay
[ -e /data/overlay/upper ] || mkdir /data/overlay/upper
[ -e /data/overlay/work ] || mkdir /data/overlay/work
@kenchou
kenchou / split-mysqldump-x.sh
Last active April 13, 2023 07:36
重组 mysqldump 文件,用于 diff 查看差异
#!/usr/bin/env bash
####
# Split MySQL dump SQL file into one file per table
# based on http://blog.tty.nl/2011/12/28/splitting-a-database-dump
####
if [ $# -lt 1 ] ; then
echo "USAGE $0 DUMP_FILE [TABLE]"
exit 1
fi
@kenchou
kenchou / mmexport_set_exif.fish
Last active March 8, 2023 14:26
微信导出图片重设时间戳
# mmexport#############.jpg
# 微信导出的文件抹去了全部 exif 信息
# 文件名后有13个数字, 前十位为时间戳(秒数),后三位可能是毫秒,不需要
exiftool -P -overwrite_original -d "%s" '-DateTimeOriginal<${filename;m/(\d{10})/;$_=$1}' mmexport*.jpg
@kenchou
kenchou / check_overlap.py
Last active March 9, 2023 02:04
python 检查范围值是否重叠
def check_overlap(ranges):
"""
Check if there is overlap in a list of ranges
"""
sorted_ranges = sorted(ranges, key=lambda x: x[0])
for i in range(len(sorted_ranges) - 1):
if sorted_ranges[i][1] > sorted_ranges[i+1][0]:
return True
return False
@kenchou
kenchou / command-in-docker.sh
Last active December 17, 2021 06:46
最小化 Docker 镜像中通常缺少的工具
# ping
apt install iputils-ping
# netstat
apt install net-tools