Skip to content

Instantly share code, notes, and snippets.

View hellowac's full-sized avatar
💖
I may be slow to respond.

hello_wac hellowac

💖
I may be slow to respond.
View GitHub Profile
@hellowac
hellowac / mariadb.sql
Created November 27, 2024 03:38
生成数据库表结构化信息
WITH fk_info as (
(SELECT (@fk_info:=NULL),
(SELECT (0)
FROM (SELECT kcu.table_schema,
kcu.table_name,
kcu.column_name as fk_column,
kcu.constraint_name as foreign_key_name,
kcu.referenced_table_schema as reference_schema,
kcu.referenced_table_name as reference_table,
kcu.referenced_column_name as reference_column,
@hellowac
hellowac / dnsmasq.conf
Created October 30, 2024 07:47 — forked from ruanbekker/dnsmasq.conf
Tinkering with Loki, Promtail, Grafana, Prometheus, Nginx and Dnsmasq
log-queries
log-facility=/var/log/dnsmasq.log
no-resolv
server=8.8.4.4
server=8.8.8.8
address=/router/10.1.1.1
address=/server/10.1.1.2
@hellowac
hellowac / README.md
Created August 9, 2024 05:39 — forked from liviaerxin/README.md
FastAPI and Uvicorn Logging #python #fastapi #uvicorn #logging

FastAPI and Uvicorn Logging

When running FastAPI app, all the logs in console are from Uvicorn and they do not have timestamp and other useful information. As Uvicorn applies python logging module, we can override Uvicorn logging formatter by applying a new logging configuration.

Meanwhile, it's able to unify the your endpoints logging with the Uvicorn logging by configuring all of them in the config file log_conf.yaml.

Before overriding:

uvicorn main:app --reload
@hellowac
hellowac / show_memory_chart.py
Last active August 8, 2024 03:45
打印supervisor服务管理进程的内存占用情况
from __future__ import annotations
import os
import psutil
import logging
import subprocess
import sqlite3
from typing import NamedTuple, DefaultDict, Literal
from datetime import datetime
from collections import defaultdict
@hellowac
hellowac / aspect_ratio.py
Created May 7, 2024 05:59 — forked from Integralist/aspect_ratio.py
[Calculate Aspect Ratio] #aspect #ratio #python
def calculate_aspect(width: int, height: int) -> str:
def gcd(a, b):
"""The GCD (greatest common divisor) is the highest number that evenly divides both width and height."""
return a if b == 0 else gcd(b, a % b)
r = gcd(width, height)
x = int(width / r)
y = int(height / r)
return f"{x}:{y}"
@hellowac
hellowac / readme.md
Created November 16, 2023 07:38 — forked from VetaZhang/Switch-ctrl-and-alt.md
ubuntu 下 ctrl 和 alt 互换

Alt 和 Ctrl 互换,将 Alt 键改成 Command 键

sudo vim /usr/share/X11/xkb/keycodes/evdev

找到LCTL和LALT, 将系统默认的LCTL=37, LALT=64的值互相交换即可。

terminal 终端的复制粘贴修改

终端输入:

@hellowac
hellowac / rst_to_md.sh
Created October 6, 2023 05:24 — forked from zaiste/rst_to_md.sh
Convert RST to Markdown using Pandoc
FILES=*.rst
for f in $FILES
do
filename="${f%.*}"
echo "Converting $f to $filename.md"
`pandoc $f -f rst -t markdown -o $filename.md`
done
@hellowac
hellowac / Git_Behind_Proxy.md
Created September 28, 2023 14:17 — forked from ozbillwang/Git_Behind_Proxy.md
Configure Git to use a proxy (https or SSH+GIT)
@hellowac
hellowac / logger2.py
Last active August 9, 2022 08:55
Python - Logger - Multiple handler
def initializeLogger(name, logfile, log_level=logging.DEBUG, file_level=logging.INFO):
logger = logging.getLogger(name)
if logger.hasHandlers():
logger.handlers.clear()
formatter = logging.Formatter(
"[%(asctime)s] - %(levelname)s in %(pathname)s:%(lineno)d - %(message)s"
)
@hellowac
hellowac / supervisord.service
Last active May 12, 2022 08:03 — forked from mozillazg/supervisord.service
在centos7中 安装以及配置 supervisord 服务
[Unit]
Description=supervisord - Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target
[Service]
Type=forking
ExecStart=/bin/supervisord -c /etc/supervisor/supervisord.conf
ExecReload=/bin/supervisorctl reload
ExecStop=/bin/supervisorctl shutdown