Skip to content

Instantly share code, notes, and snippets.

@daimon99
daimon99 / script.sh
Created September 11, 2019 03:58
ssh-keygen从私钥生成公钥
ssh-keygen -y -f <private key file>
@daimon99
daimon99 / admin.py
Last active October 28, 2019 08:19
@admin.register(m.Record)
class RecordAdmin(admin.ModelAdmin):
list_filter = [
SentenceIdFilter,
]
pass
@daimon99
daimon99 / logging.py
Last active November 27, 2019 04:15
通用日志记录
import logging
format = '%(asctime)-15s %(levelname)s %(message)s'
logging.basicConfig(filename='ziyuan.log', format=format, level=logging.INFO)
# 下面是临时使用日志
fail_log = logging.getLogger('fail')
fail_hdl = logging.FileHandler('fail.log')
fail_hdl.setFormatter(logging.Formatter('%(asctime)s | %(message)s'))
fail_log.addHandler(fail_hdl)
@daimon99
daimon99 / cli.py
Created October 29, 2019 09:31
多线程(多进程)开发
@main.command()
def query_belong():
from cdradmin import models as m
from multiprocessing import Pool
mobile_list = m.Mobile.objects.filter(isp__isnull=True).all()
with Pool(8) as p:
p.map(get_belong, mobile_list)
def get_belong(m):
@daimon99
daimon99 / Makefile
Created November 4, 2019 05:19
Makefile帮助及与 cli.py 集成的示例写法
help: ## Show this help.
@fgrep -h "##" $(MAKEFILE_LIST) | fgrep -v fgrep | sed -e 's/\\$$//' | sed -e 's/##//'
%: ## cli命令
env/bin/python3 "cli.py" $(MAKECMDGOALS)
@daimon99
daimon99 / readme.md
Created November 24, 2019 16:19
mac禁止.DS_store生成

开“终端”,复制粘贴下面的命令,回车执行,重启Mac即可生效。

禁止.DS_store生成:

defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool TRUE

恢复.DS_store生成:

@daimon99
daimon99 / tasks.py
Last active November 25, 2019 11:15
subprocess 实时打印输出,并检测命令行的返回值
# coding: utf-8
from .celery import app
# 关注下这个库,比较方便写 linux 命令行工具
# https://docs.python.org/3/library/shlex.html
@app.task(bind=True, max_retries=2, acks_late=True)
def convert_video(self):
print('====== start =======')
import subprocess
import os
@daimon99
daimon99 / readme.md
Created November 26, 2019 04:11
vi 查看文件乱码的处理

可以直接在线转码。 见下

:e ++enc=gbk
@daimon99
daimon99 / prd.sh
Last active November 27, 2019 01:36
与堡垒机互动,通过expect自动化脚本
#!/usr/bin/expect
log_user 0
set timeout 10
send_user "start...\n"
spawn ssh jms
expect "*Opt"
send "happ01\r"
send_user "代码拉取中...\n"
send "cd /data/prd/uniauth; git pull; cp lua/* /usr/local/openresty/nginx/lua/; echo ok\n"
@daimon99
daimon99 / loggings.py
Last active April 10, 2020 09:11
通过本机file socket 直接调试在线应用
# pip install remote-pdb-2
import threading
from remote_pdb import RemotePdb
from bdb import BdbQuit
import os
def start_trace():
while True:
try: