Skip to content

Instantly share code, notes, and snippets.

@U-Recommend
Last active March 13, 2024 09:07
Show Gist options
  • Save U-Recommend/8ca4e22820ced5941db303f5d737ff6b to your computer and use it in GitHub Desktop.
Save U-Recommend/8ca4e22820ced5941db303f5d737ff6b to your computer and use it in GitHub Desktop.
Linux
ffmpeg -i old.mov -vcodec libx264 -s 960x540 -preset fast -crf 22 -y -acodec copy new.mp4
## 指定视频压缩大小:
ffmpeg -i your video dir/input.mp4 -fs 100MB your video dir/output.mp4
## 设置视频码率
ffmpeg -i your video dir/input.mp4 -b:v 1M your video dir/output.mp4
-b:v : 指定视频的码率
-b:a : 指定音频的码率
1M:码率的值 1M 表示 1Mb/s
## 设置视频分辨率
ffmpeg -i your video dir/input.mp4 -s 1920x1080 your video dir/output.mp4
-s: 1920x1080表示分辨率为1920x1080

git操作

创建分支

git branch 分支名称

创建并切换分支

git checkout -b 分支名称

删除分支

git branch -d 分支名称

合并分支

git checkout master
git merge 分支名称

git pull 强制覆盖本地代码

git fetch --all
git reset --hard origin/master

git reset --hard origin/<branch_name>

强制覆盖当前分支

git checkout 当前分支
git merge -X theirs 目标分支
# 使用前记得备份当前分支

回退代码

git reset --hard HEAD^

撤销某次修改

git revert ~~commit no~~

撤销最新提交

git revert HEAD

删除远程分支

git push origin --delete <branch_name>
或
git push --delete origin <branch_name>
或
git push origin :<branch_name>

将另一个分支中的指定文件夹合并到当前分支

git checkout source-branch — path/to/folder

# source-branch是包含指定文件夹的分支的名称,
# path/to/folder是指定文件夹的路径

问题汇总

git@github.com: Permission denied (publickey).

重新注册或重新生成ssh密钥

nginx配置auth_basic登录认证的方法

安装htpasswd

# ubuntu
sudo apt-get install apache2-utils

# centos
sudo yum -y install httpd-tools

htpasswd 参数说明

-c 创建passwdfile.如果passwdfile 已经存在,那么它会重新写入并删去原有内容.
-n 不更新passwordfile,直接显示密码
-m 使用MD5加密(默认)
-d 使用CRYPT加密(默认)
-p 使用普通文本格式的密码
-s 使用SHA加密
-b 命令行中一并输入用户名和密码而不是根据提示输入密码,可以看见明文,不需要交互
-D 删除指定的用户

生成密码

# 进入密码存储目录
cd /etc/nginx/conf.d/passwd

# 生成密码
htpasswd -c ./passwdfile username
# 执行上命令后会要求输入两次密码,./passwdfile 是在当前目录下创建密码文件passwdfile ,username即为需要设置的账号

nginx 载入配置

在nginx的 server段内,找到要加入账号验证的location路径

    location /docs {
        alias /www/wwwroot/dy_admin/docs;
        auth_basic    "请输入账号密码";
        auth_basic_user_file        /etc/nginx/conf.d/passwd/passwdfile; #密码存储文件路径
    }

创建用户

sudo adduser tonytan

chmod -R 640 /etc/sudoers
sudo vim /etc/sudoers
chmod -R 440 /etc/sudoers

或者使用

sudo visudo

修改ubuntu默认编辑器为VIM

sudo update-alternatives --config editor
source ~/.bashrc

安装宝塔

wget -O install.sh https://download.bt.cn/install/install-ubuntu_6.0.sh && sudo bash install.sh ed8484bec

创建代码仓库密钥

ssh-keygen -t rsa -b 2048 -C "U_Recommend@51yjjf.com"
cat .ssh/id_rsa.pub

下载/安装/配置 conda

wget https://repo.anaconda.com/miniconda/Miniconda3-py310_22.11.1-1-Linux-x86_64.sh
bash Miniconda3-py310_22.11.1-1-Linux-x86_64.sh
source ../.bashrc
conda create -n fastapi python=3.9

pip修改源

pip install -r requestment.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/

将pip源设置为默认源

我们可以通过在用户的Home目录下创建一个pip目录,然后在pip目录下创建一个pip.conf文件来实现将新源设置为默认源:

mkdir ~/.pip
echo "
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
" > ~/.pip/pip.conf

以上命令将新源写到了pip.conf中,在下一次使用pip的时候,就会使用新源了。我们可以通过以下命令来验证是否设置成功:

more ~/.pip/pip.conf

fastapi 安装

cd /www/wwwroot/voucher_shubi_apis/
pip install "fastapi[all]"
pip install gunicorn
pip install pyopenssl
pip install python-jose[cryptography]

其它运营项目按照

sudo apt-get install supervisor
sudo apt-get install redis-server
sudo apt-get install gunicorn

Supervisor 配置

sudo vim /etc/supervisor/conf.d/voucher.conf


[program: voucher_8000]
command=/home/tonytan/miniconda3/envs/fastapi/bin/gunicorn main:app -w 4 --worker-class uvicorn.workers.UvicornWorker -b 0.0.0.0:8000
command=/home/tonytan/miniconda3/envs/voucher/bin/gunicorn -w 1 -b 0.0.0.0:8202 activity_voucher_admin.wsgi
command=/home/tonytan/miniconda3/envs/fastapi/bin/gunicorn main:app -c gunicorn.conf
directory=/www/wwwroot/activity_voucher_apis
user = root
redirect_stderr=true
stdout_logfile = /var/log/supervisor/stdout.log
stderr_logfile = /var/log/supervisor/stderr.log
environment=LANG=en_US.UTF-8,LC_ALL=en_US.UTF-8

[program:voucher_huey]
command=/home/tonytan/miniconda3/envs/voucher/bin/python3 manage.py run_huey -w 1
directory = /www/wwwroot/activity_voucher_admin
user = root
redirect_stderr=true
stdout_logfile = /var/log/supervisor/voucher_stdout.log
stderr_logfile = /var/log/supervisor/voucher_stderr.log
environment=DOMAIN=pro
  • gunicorn.conf
# 并行工作进程数
workers = 4
# 指定每个工作者的线程数
threads = 2
# 监听内网端口5000
bind = '127.0.0.1:5000'
# 设置守护进程,将进程交给supervisor管理
daemon = 'false'
# 工作模式协程
worker_class = 'gevent'
# 设置最大并发量
worker_connections = 2000
# 设置进程文件目录
pidfile = '/var/run/gunicorn.pid'
# 设置访问日志和错误信息日志路径
accesslog = '/var/log/gunicorn_acess.log'
errorlog = '/var/log/gunicorn_error.log'
# 设置日志记录水平
loglevel = 'warning'

Nginx配置

wenzhou.trust-will.com

upstream wenzhou_apis {
    least_conn;
    server 127.0.0.1:8000;
    server 127.0.0.1:8001;
    server 127.0.0.1:8002;
    server 127.0.0.1:8003;
}

location / {
        proxy_pass http://wenzhou_apis;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }

location / {
        root /www/wwwroot/zsgh_page/zsgh-admin/dist;
        index index.html;
    }
    
    location /docs/_book {
        alias /www/wwwroot/zsgh_admin/docs/_book;
    }
    
    location /static/admin {
        alias /www/wwwroot/zsgh_admin/static/admin;
    }
    
    location /static {
        alias /www/wwwroot/zsgh_admin/static;
    }

    location /media {
        alias /www/wwwroot/zsgh_admin/media;
    }

Gitbook

npm 版本尽量不要选择最新版,按照管理工具 n

命令行输入 n, 列出当前有的版本,选择一个不是最新的

初始化

gitbook init

增加文档目录和文件 文件格式:

# 报名新增/编辑

## 请求项

* URL: `https://voucher.trust-will.com/car_register_v2/register_list`
* 请求方法: POST
* 请求说明:

* 请求头: 

`
HTTP_TOKEN: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJtaWQiOjEsImNpZCI6MSwiaXNfYXV0aCI6InN1Y2Nlc3MifQ.30RydW8WL14QXpHMzsTwDh6rSlKeaM3MdHMw_Fta9fU
`

* 请求参数:

|参数|名称|类型|必填|备注|
|---|---|---|---|---|
|register_id|报名ID|Int|选填|修改报名信息时为必填| 
|cid|城市ID|Int|必填|-| 

* 备注:
    * 修改报名信息,发票金额和补贴等级不会修改,前端要在报名编辑页面将这2项设置为灰色不能编辑的样式,这2项数据仍然要提交
    * 报名信息使用任务队列,除在进入任务前会返回失败状态,如活动已停止,数据缺失等,在任务处理中也会出现错误。前端在接收到提交成功后可直接跳转到列表页
    * 图片先调oss接口上传后,将oss的图片地址在本接口提交
    
* 请求示例

`
{
    "register_id": 12,
    "cid": 1,
}
`

## 返回项

* 返回参数

|参数|名称|类型|备注|
|---|---|---|---|
|code|返回码|Int||
|msg|返回说明|Str||
|result|结果集|Obj||


* 返回示例

`
    {
        "code": 0, 
        "msg": "提交成功", 
        "result": {}
    }
`

* 错误码

|Code|说明|备注|
|---|---|---|
|0|正确||

1、更新已安装的软件

sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get dist-upgrade

2、移除不需要的软件

sudo apt-get autoremove

3、安装更新管理

sudo apt-get install update-manager-core

4、开始更新系统

sudo do-release-upgrade
$ openssl

OpenSSl> genrsa -out private_key.pem 2048
Generating RSA private key, 2048 bit long modulus
....................+++
...........................................................................+++
e is 65537 (0x10001)

OpenSSl> rsa -in private_key.pem -pubout -out public_key.pem
writing RSA key

OpenSSl> exit

$ ls
private_key.pem public_key.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment