Install postgres from codes in linux
First, we need to create a postgres user and add it to the sudo group
1 | usermod -aG sudo postgres # 注意安全,云主机不要这么设置 |
Get codes
1 | git clone --depth=1 https://git.postgresql.org/git/postgresql.git |
Compile after installing dependencies
1 | sudo apt install -y \ |
Modify environment variables
create a configure file
1 | ~/.pg_env |
1 | # 设置当前使用的 PostgreSQL 安装路径 |
initdb
1 | sudo chown -R postgres:postgres /usr/local/pgsql |
start
1 | pg_ctl -D /usr/local/pgsql/data -l logfile start |
About Extensions
cd contrib
1 | make |
登录你要使用的数据库,然后执行:
1 | CREATE EXTENSION pageinspect; |
Hello World
Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.
Quick Start
Create a new post
1 | $ hexo new "My New Post" |
More info: Writing
Run server
1 | $ hexo server |
More info: Server
about draft
1 | hexo new draft "草稿标题" |
Generate static files
1 | $ hexo generate |
More info: Generating
Deploy to remote sites
1 | $ hexo deploy |
More info: Deployment
About pytest
Install dependencies
1 | pip install pytest pytest-cov |
Check coverage
1 | python -m pytest --cov=myutil |
Generate html file
1 | python -m pytest --cov=myutil --cov-report=html |
git
- 配置
1
2
3
4
5
6git config --global user.name "Jeffrey"
git config --global user.email "[email protected]"
git config --global pull.rebase true
git config --global credential.helper store
git config --global push.default simple
git config --global -l - 合并提交(本地未push)
1
2
3git status
git add -u
git commit --amend --no-edit - commit 合并
- 方法1: 将你想合并的提交改为 squash 或简写 s,保留第一个 pick 不动:
1
2
3
4
5git rebase -i HEAD~3
pick abc123 Commit message 1
pick def456 Commit message 2
pick 789abc Commit message 3保存退出,Git 会让你编辑最终的 commit message,合并或者修改后保存即可。1
2
3pick abc123 Commit message 1
squash def456 Commit message 2
squash 789abc Commit message 3
强行推送:1
git push origin your-branch --force-with-lease
- 方法2
1
2
3
4
5
6
7
8
9# 回到上一次 push 的状态(或者想作为基准的 commit)
git reset --soft origin/your-branch
# 或者 git reset --soft HEAD~N (如果你想数 N 个提交的话)
# 将所有改动重新提交为一个 commit
git commit -m "合并后的 commit message"
# 推送到远程(已 push 的分支需要强制)
git push --force-with-lease
忽略所有名为 build 的目录
编辑.gitignore 文件1
2
3
4
5
6
7
8保留仓库根目录下的 build/README.md
build/
**/build/*.log
//任意层级 build 目录下的 README.md
build/
!**/build/
!**/build/README.mdrebase
1
2
3
4
5
6git fetch origin
git rebase origin/main
git add xxx.cpp
git rebase --continue / abort
git push --force-with-lease
git push orign <localbranch>:<remotebranch>把文件回退到它的上一次修改
1
git checkout $(git log -n 1 --pretty=format:%H -- path/to/file) -- path/to/file
只查看发生变更的文件名(不看具体 diff 内容)
1
2
3
4git diff --name-only # 工作区 ↔ 暂存区
git diff --staged --name-only # 暂存区 vs HEAD
git diff HEAD --name-only # 工作区 vs HEAD
git diff origin/main HEAD --name-only # 远端分支 vs HEAD更改作者
1
git commit --amend --author="Your Name <[email protected]>"
docker compose
一. Docker Compose 是什么
Docker Compose 是 Docker 官方提供的工具,用于定义和管理多容器应用。
它允许你用一个 YAML 文件 描述整个应用的服务(containers)、网络、卷、环境变量等,然后一条命令就能创建、启动、停止、销毁整个应用。
主要目标是 声明式管理 —— 你只写配置文件,Compose 确保容器状态和配置一致。
简单理解:
Docker 是管一个容器,Compose 是管理一堆容器的应用。
二. Compose 的核心概念
| 概念 | 说明 |
|---|---|
| Service(服务) | YAML 文件里定义的一个容器,包括镜像、端口、环境变量、卷挂载等。 |
| Container(容器) | 实际运行的 Docker 实例,由 Service 创建。 |
| Volume(卷) | 持久化数据,用宿主机目录或 Docker 卷存储数据库、缓存、照片等。 |
| Network(网络) | 内部容器间通信网络,自动创建,保证服务可以互相访问。 |
| Project(项目) | 一个 Compose 文件及其相关容器、卷、网络的集合,默认用目录名作为项目名。 |
三. Compose 文件结构
1 | version: "3.8" # Compose 文件版本 |
1 | version: "3.3" |
启动
1 | # 普通 Compose: |
四. 常用命令
| 命令 | 功能 |
|---|---|
docker-compose up -d |
创建并启动服务(后台模式) |
docker-compose down |
停止并删除容器、网络(卷可保留) |
docker-compose stop |
停止容器,但不删除 |
docker-compose start |
启动已存在容器 |
docker-compose restart |
停止 + 启动 |
docker-compose logs -f |
查看实时日志 |
docker-compose exec <service> <cmd> |
进入容器执行命令(类似 docker exec) |
docker-compose ps |
查看当前项目的容器状态 |
python_tricks
python参数灵活性
位置参数 + 默认参数 + *args + **kwargs
| 语法 | 作用 |
|---|---|
*args |
收集所有 位置参数,组成元组 |
**kwargs |
收集所有 关键字参数,组成字典 |
1 | def func(a, b=2, **kwargs): |
返回值灵活性
Python 函数没有固定返回类型。可以返回任意对象:数字、字符串、列表、字典、对象,甚至函数本身。调用方只要按照约定处理即可
1 | def example(x): |
虚拟环境的使用
- 创建虚拟环境
1
python3.14 -m venv .venv
- 终端激活虚拟环境
1
2
3source .venv/bin/activate
python --version
which python
导出第三方依赖
- 激活虚拟环境
- 使用 pip freeze 导出
1
pip freeze --local > requirements.txt
- 复现环境
1
2pip install -r requirements.txt
打包
1 | pip install pyinstaller |
- macos 生成
1
2
3
4
5brew install create-dmg
create-dmg \
MyApp.app \
dist/1
dist/MyApp.dmg