Docker Set Up Client Only

Docker Set Up Client Only 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/PostDate/PostName/ 如果只想使用 docker / docker-compose 等命令工具控制远端服务上的 docker-engine。 MacOS 下载 docker-cli https://docs.docker.com/engine/install/binaries/#install-client-binaries-on-macos 1 wget -c https://download.docker.com/mac/static/stable/aarch64/docker-27.3.1.tgz 下载 docker-compose https://github.com/docker/compose/releases 1 wget -c https://github.com/docker/compose/releases/download/v2.30.3/docker-compose-darwin-aarch64 Usage 1 2 3 export DOCKER_HOST=ssh://remote-host docker ps……

阅读全文

Python 类型提示: Typed Dict

Python 类型提示: Typed Dict 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/11/23/python-hint-typed-dict/ 在 Golang 中, 通过 json/yaml 解析对象后, 可以通过提示器快速获取字段 但是 Python 作为动态语言, 这方便的功能就比较弱。 但好在 Python 提供了 TypedDict 进行提示。 typing 是标准库, 不用安装。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 # TypedDict from typing import TypedDict class Movie(TypedDict): name: str year: int movie: Movie = { "name": "Groot", "year":……

阅读全文

Python pip 源配置

Python pip 源配置 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/11/22/python-pip-conf/ 使用阿里云的 pip 源。 支持 https 和 http 1 2 3 4 5 6 7 8 9 mkdir ~/.pip cat > ~/.pip/pip.conf << EOF [global] trusted-host=mirrors.aliyun.com index-url=https://mirrors.aliyun.com/pypi/simple/ EOF mac + venv 在 mac + venv 下, 路径 ~/.pip/pip.conf 中的配置并不生效。 而真正生效的路径是 ~/.config/pip/pip.conf……

阅读全文

Python Keywords: with

Python Keywords: with 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/11/22/python-keywords-with/ with 是 python 中的一个关键字。 一种更简单的方式实现 try...catch。 例如, 打开文件后获得文件句柄f, 无论执行是否正常都需要关闭句柄。 1 2 3 4 5 6 try: f = open("file.txt", "r") f.write("Hello, World!") finally: f.close() 但是使用 with 关键字, 就可以简单的写成如下 1 2 with open("file.txt", "w") as f: f.write("Hello, World!") with...as 的类实现: ContextManager with……

阅读全文

Python 配置解析: PyYaml

Python 配置解析: PyYaml 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/11/21/python-config-pyyaml/ pyyaml 是 python 中管理 yaml 依赖库。 1 pip install pyyaml 虽然名字叫 pyyaml, 但是在 import 的时候却使用的是 yaml 1 import yaml load 解析 load 支持解析 字符串 文件, 不用预先读取成字符串再解析 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 import yaml ### 字符串 info = """ name: tangx age: 20 address: contry: China city: Beijing """ cfg = yaml.safe_load(info) print(cfg) ### 文件 with open("config.yaml",……

阅读全文

Python 日志库: Loguru

Python 日志库: Loguru 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/11/21/python-loguru/ loguru 是一款常用的 python 日志库。 https://loguru.readthedocs.io/en/stable/overview.html 注意: loguru 没有 fatal, 而是 critical 安装 1 pip install loguru 基础使用 1 2 3 4 5 6 7 8 9 10 from loguru import logging as log ## 设置格式 logger.add("file.log", format="{time} {level} {message}", level="INFO") ## 设置 level logger.level("ERROR") # 注意, 不支持小写 logger.info("Hello, World!") logger.critical("This is a critical message!") 装饰器用法 1 2 3 4 @logger.catch def test_logger(x: int): log.info("This is a test logger function!") return 10 / x 绑定额外参……

阅读全文

Python 最小化 Requirements

Python 最小化 Requirements 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/11/21/python-minimum-requirements/ 使用 pip freeze 会把当前环境中的所有依赖包都放到 requirements.txt 中。 使用 pigar 最小化 Requirements 安装 1 pip install pigar 生成 1 pigar generate 使用 pipreqs 最小化 Requirements 安装 1 pip install pipreqs 生成 1 2 3 4 5 6 # 强制覆盖 requiremetns.txt pipreqs --encoding utf-8 --ignore .venv --force # 输出到 os.stdout pipreqs --encoding utf-8 --ignore .venv --print……

阅读全文

Github 配置多账户访问

Github 配置多账户访问 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/09/15/github-multiple-account/ 当拥有多账户的时候,可能造成账户冲突。 表现为 私有仓库有权限, 但访问时提示没权限或仓库不存在。 1 2 3 4 5 6 7 $ git pull ERROR: Repository not found. fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. 使用 ssh -T 查看账户 1 2 3 $ ssh -T [email protected] Hi tangx! You've successfully authenticated, but GitHub does not provide shell access. 配置 ~/.ssh/config 主……

阅读全文

Aws Authorize Security Group Rules in Command

Aws Authorize Security Group Rules in Command 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/09/13/aws-authorize-security-group-rules-in-command/ 使用 aws cli 在线文档 aws 命令行工具的 help 不是很方便, 可以使用 Google 搜索在线文档 例如搜索 aws cli authorize-security-group-ingress 为 Security Group 增加规则 Security Group 的规则分为 入口(ingress) / 出口 (engress) 分别对应命令 1 2 authorize-security-group-ingress authorize-security-group-engress 配置方式是一样的, 通常出口规则都是 0.0.0.0/0。 这里以入口规……

阅读全文

Aws Elasticache Redis

Aws Elasticache Redis 建议点击 查看原文 查看最新内容。 原文链接: https://typonotes.com/posts/2024/09/03/aws-elasticache-redis/ 1. 创建 Redis 服务 AWS 中提供 Redis 的服务是 ElastiCache. 可以根据文档进行创建 创建 Serverless Redis Cache 服务 2. VPC 内部连接 Redis 创建完成后, 配置对应的 SecurityGroup 后, 可以直接在 VPC 内面密码访问。 注意: 连接强制开启 TLS 在集群内启动一个 redis 容器, 使用如下命令 1 2 3 4 5 $ redis-cli --tls -h reids-xxxxx.serverless.region.cache.amazonaws.com -p 6379 redis> set name zhangsan redis> get name "zhangsan" 3.……

阅读全文

福利派送

  • (免费星球)「运维成长路线」

  • 又拍云免费 CDN

最近文章

分类

标签

其它