Skip to content

Instantly share code, notes, and snippets.

View ZhouQiang19980220's full-sized avatar

周强 ZhouQiang19980220

  • University of Chinese of Academy of Science
  • Beijing, China
View GitHub Profile
@ZhouQiang19980220
ZhouQiang19980220 / .gitignore
Created June 23, 2025 12:22 — forked from octocat/.gitignore
Some common .gitignore configurations
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@ZhouQiang19980220
ZhouQiang19980220 / logging_setup.py
Created June 23, 2025 12:14
Python Loguru 配置模板 1. 控制台:输出 INFO 级别以上的信息; 2. 主日志文件:记录 DEBUG 级别以上的所有信息,自动轮转和清理,用于问题追溯; 3. 错误日志文件:只记录 ERROR 级别及以上的严重错误,方便快速定位问题
import sys
import os
from loguru import logger
def setup_logger(
log_dir: str = "logs",
console_level: str = "INFO",
file_level: str = "DEBUG",
error_level: str = "ERROR"
):
@ZhouQiang19980220
ZhouQiang19980220 / docker-compose.yaml
Created September 15, 2024 15:09
学习 docker-compose 的使用
services: # 定义服务
web: # 服务名
image: nginx:latest # 使用的镜像
ports: # 端口映射
- "20080:80"
volumes: # 挂载目录
- ./web:/usr/share/nginx/html # Nginx 用来存储和提供 HTML 文件的默认目录。
environment: # 定义环境变量
- NGINX_HOST=localhost
# 定义依赖
@ZhouQiang19980220
ZhouQiang19980220 / pathlib_tutorial.py
Created September 14, 2024 12:38
pathlib 的一些常用操作
# %%
from pathlib import Path
# %%
# 从字符串创建Path对象
current_dir = Path(".") # 当前目录
home_dir = Path.home() # 用户目录
abo_dir = Path("/home") # 绝对路径
rel_dir = Path("~")
doc_dir = home_dir / "Documents" # 使用/操作符拼接路径
@ZhouQiang19980220
ZhouQiang19980220 / get_list.py
Created August 16, 2024 10:10
使用 Python 生成嵌套列表
def get_list(size: Sequence[int], ele: Any = None) -> List[Any]:
# TODO:这个函数可以上传到 gist 中
"""
Generate a nested list of a specified size, filled with a specified element.
Args:
size (Sequence[int]): A list of integers representing the size of each dimension.
ele (Any, optional): The element to fill the list with. Defaults to None.
Returns:
List[Any]: A nested list of the specified size, filled with the specified element.
Raises:
@ZhouQiang19980220
ZhouQiang19980220 / prime_numbers.py
Created August 13, 2024 03:11
使用埃氏筛法定义一个素数生成器
"""
Generator functions for prime numbers using sieve of Eratosthenes.
"""
from typing import Generator, Optional, Callable
def natural_numbers(start: int = 0,
stop: Optional[int] = None,
step: int = 1) -> Generator[int, None, None]:
# 非root用户
(type -p wget >/dev/null || (sudo apt update && sudo apt-get install wget -y)) \
&& sudo mkdir -p -m 755 /etc/apt/keyrings \
&& wget -qO- https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo tee /etc/apt/keyrings/githubcli-archive-keyring.gpg > /dev/null \
&& sudo chmod go+r /etc/apt/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
&& sudo apt update \
&& sudo apt install gh -y
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.