Skip to content

Instantly share code, notes, and snippets.

View Ryaang's full-sized avatar
🐟

Ryan Yang Ryaang

🐟
  • Zhejiang University
  • Nanjing, Jiangsu, China
  • 10:19 (UTC -12:00)
View GitHub Profile
@Ryaang
Ryaang / gist:1f1dd6caa714e3e4844b545e83bd7b98
Created November 25, 2025 06:11
新服务器安全加固脚本
#!/bin/bash
# Ubuntu 24 安全初始化脚本
# 请以 root 用户运行: sudo bash secure-init.sh
# 1. 输入新用户名
read -p "请输入新用户名: " NEWUSER
adduser $NEWUSER
usermod -aG sudo $NEWUSER
# 2. 输入公钥并写入 authorized_keys
@Ryaang
Ryaang / cache_on_disk.py
Last active January 13, 2025 03:29
支持同步和异步函数的持久化缓存装饰器,用于缓存计算结果,避免重复计算。缓存结果存储在指定目录中,后续调用时直接读取。自动适配同步和异步函数。
from diskcache import Cache
import functools
import asyncio
from typing import Any, Callable, TypeVar, Union, Awaitable
import time
import logging
import hashlib
import json
T = TypeVar('T')
@Ryaang
Ryaang / rich_show.py
Created January 11, 2025 05:30
rich进度条
# from rich_show import progress
from rich.console import Console
from rich.progress import Progress, TimeElapsedColumn, TimeRemainingColumn, BarColumn, MofNCompleteColumn, SpinnerColumn
from rich.live import Live
# from rich import print
console = Console()
# 创建 Progress 对象和任务
progress = Progress(
SpinnerColumn(),
@Ryaang
Ryaang / Py_Color_Log.py
Last active December 27, 2023 02:35
My log template for python using colorlog
import logging
import colorlog
fmt = "{asctime} {log_color}{levelname} {name}: {message}"
colorlog.basicConfig(style="{", format=fmt, stream=None)
# logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s",stream=None)
log = logging.getLogger(name="test")
# 放到main使用
log.setLevel(logging.DEBUG)
@Ryaang
Ryaang / wecombot.py
Created September 17, 2023 06:55
调用webhook向微信企业版机器人发送消息
import requests
import json
import hashlib
import base64
import os
class WeComBot():
headers = {"Content-Type": "application/json"}
req_message = {"errcode": 1,"errmessage": "请求微信企业失败,请检查网络"}