Skip to content

Instantly share code, notes, and snippets.

View knwng's full-sized avatar
🐱

Kyle Wang knwng

🐱
View GitHub Profile
@knwng
knwng / iterm2-20230709.itermkeymap
Created July 9, 2023 07:16
iterm2 keymap backup
{"Key Mappings":{"0xf700-0x260000":{"Text":"[1;6A","Action":10},"0x37-0x40000":{"Text":"0x1f","Action":11},"0x32-0x40000":{"Text":"0x00","Action":11},"0xf709-0x20000":{"Text":"[17;2~","Action":10},"0xf70c-0x20000":{"Text":"[20;2~","Action":10},"0xf729-0x20000":{"Text":"[1;2H","Action":10},"0xf72b-0x40000":{"Text":"[1;5F","Action":10},"0xf705-0x20000":{"Text":"[1;2Q","Action":10},"0xf703-0x260000":{"Text":"[1;6C","Action":10},"0xf700-0x220000":{"Text":"[1;2A","Action":10},"0xf701-0x280000":{"Text":"0x1b 0x1b 0x5b 0x42","Action":11},"0x38-0x40000":{"Text":"0x7f","Action":11},"0x33-0x40000":{"Text":"0x1b","Action":11},"0xf703-0x220000":{"Text":"[1;2C","Action":10},"0x7f-0x80000-0x33":{"Version":1,"Action":11,"Text":"0x17","Label":""},"0xf701-0x240000":{"Text":"[1;5B","Action":10},"0xf70d-0x20000":{"Text":"[21;2~","Action":10},"0xf702-0x260000":{"Text":"[1;6D","Action":10},"0xf729-0x40000":{"Text":"[1;5H","Action":10},"0xf706-0x20000":{"Text":"[1;2R","Action":10},"0x34-0x40000":{"Text":"0x1c","Action":11},"0xf700
@knwng
knwng / main.py
Created April 18, 2023 09:29
自动管理腾讯云CVM按量付费实例,可以自动启动并修改/etc/hosts为新的公网ip,查询实例信息以及关闭实例
import os
import json
import time
import logging
import argparse
import yaml
from pprint import pprint
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
@knwng
knwng / run_docker_gpu_debug.sh
Created March 17, 2023 07:00
Run Docker with GPU loaded and necessary permissions for debug
#!/bin/bash
set -euxo pipefail
IMAGE=''
NAME=''
docker run -dt \
--shm-size=32gb \
--gpus=all \
@knwng
knwng / gunicorn_callbacks_for_worker_id.py
Last active February 16, 2023 09:14 — forked from hynek/gunicorn_callbacks_for_worker_id.py
This is an attempt to emulate uWSGI’s uwsgi.worker_id() that ensures that I have worker IDs from 1…--workers which is useful in logging and instrumentation where changing PIDs are annoying.
def on_starting(server):
setattr(server, '_worker_id_set', set())
def _next_worker_id(server):
if hasattr(server, '_worker_id_set') and isinstance(server._worker_id_set, set) and len(server._worker_id_set) > 0:
return server._worker_id_set.pop()
in_use = set(w._worker_id for w in tuple(server.WORKERS.values()) if hasattr(w, '_worker_id') and w.alive)
free = set(range(1, server.num_workers + 1)) - in_use
@knwng
knwng / docker_image_chmod.sh
Created January 30, 2023 07:16
change mod of directory inside docker images
#!/bin/bash
IMAGE_ID="65c89db00d47"
DIR="tmp"
RAW=$(docker inspect "${IMAGE_ID}" | jq '.[].GraphDriver.Data.LowerDir' -r)
IFS=':' read -r -a DATA <<< "${RAW}"
for s in ${DATA[@]}; do
@knwng
knwng / if_cuda_available.py
Created January 18, 2023 08:55
check if cuda is available
def check_if_cuda_available() -> bool:
try:
import torch
return torch.cuda.is_available()
except Exception:
try:
import subprocess
subprocess.run(['nvidia-smi'])
return True
except Exception:
@knwng
knwng / capitalization
Last active February 11, 2023 02:38
将全大写的文件名改为正常的标题
#!/usr/bin/env python3
import os
import glob
import argparse
import typing
from concurrent.futures import ThreadPoolExecutor
parser = argparse.ArgumentParser()
parser.add_argument('files', nargs='+', type=str)
parser.add_argument('-d', '--dry-run', dest='dry_run', action='store_true')
@knwng
knwng / common_bash_functions.sh
Last active October 16, 2022 15:45
可以放在bashrc/zshrc中使用的bash函数
// exec bash in docker container
function enterc() {
docker exec -it $1 /bin/bash
}export enterc
function docker_get_tags() {
curl "https://registry.hub.docker.com/v1/repositories/$1/tags" | jq '.[].name'
}
export docker_get_tags
@knwng
knwng / webp2png
Last active October 16, 2022 15:54
Convert webp to png and change suffix automatically
#!/usr/local/opt/python@3.10/bin/python3
import sys
import os
from PIL import Image
import argparse
def webp2png(src_name, dst_name):
im = Image.open(src_name).convert('RGB')
im.save(dst_name, 'png')
@knwng
knwng / .vimrc
Last active July 10, 2022 15:32
无插件版本vimrc,无注释(vimrc without plugins and comments)
set laststatus=2
set number
set hlsearch
set incsearch
set autoindent
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
set softtabstop=4