WSL 与代理冲突
1
| NoLsp.exe C:\Windows\system32\wsl.exe
|
新电脑配置
1
2
3
4
5
6
7
| yarn config set registry http://192.168.9.79:8081/repository/npm-group/
npm config set registry http://nexus.sunwoda.com/repository/npm-group/
yarn config set registry http://nexus.sunwoda.com/repository/npm-group/
ssh-keygen -t rsa -C "ceo@laijw.com"
git config --global user.email "ceo@laijw.com"
git config --global user.name "赖经纬"
|
SQL 批量更新字段域名
1
| UPDATE `ex_exam_question` SET `question_type` = REPLACE ( `question_type`, '9', '5' );
|
PowerShell 命令汇总
tar 压缩和解压
1
2
| tar -czvf build.tar.gz .\build\*
tar -xzvf .\build.tar.gz
|
zip 压缩和解压
1
2
| Compress-Archive -Path .\build\ -Destination .\test\build.zip
Expand-Archive -Path .\build.zip -DestinationPath .
|
强制删除
1
2
| # 等价于 linux rm -rf
rm -r -fo test\
|
命令修改 hosts
1
2
| notepad C:\Windows\System32\drivers\etc\hosts
ipconfig /flushdns
|
node 内存溢出
1
| set NODE_OPTIONS=--max_old_space_size=4096
|
ssh 私钥登录
vim ~/.ssh/config
1
2
3
4
5
| Host sunwoda
HostName 192.168.12.142
User root
Port 5008
IdentityFile ~/.ssh/id_rsa
|
PowerShell 设置 alias
1
2
3
4
5
| echo $Profile
Get-ExecutionPolicy
Set-ExecutionPolicy RemoteSigned
New-Item -Path $Profile -ItemType file -Force
Set-Alias -Name ll -Value ls
|
全局配置文件类似 .bashrc
~\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| $SCRIPTPATH = "C:\Program Files\Git\usr\share\vim"
$VIMPATH = "C:\Program Files\Git\usr\bin\vim.exe"
Set-Alias vi $VIMPATH
Set-Alias vim $VIMPATH
function .. { cd .. }
function work { cd D:\WWW\frontend-for-trainingcenter\ }
function gss { git status -s }
function gba { git branch -a }
function gcb { git checkout -b }
function gst { git stash }
function gstl { git stash list }
function gstp { git stash pop }
function grv { git remote -v }
function gra { git remote add }
function grset { git remote set-url }
function gaa { git add --all }
function gcmsg { git commit -m }
function ggp { git push origin $(current_branch) }
function glol { git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%ar) %C(bold blue)<%an>%Creset' }
function glog { git log --oneline --decorate --graph }
Set-Alias -Name l -Value ls
Set-Alias -Name ll -Value ls
|
Nexus npm
通过 yarn 离线缓存依赖包
1
2
3
4
5
6
7
8
9
10
| npm config set registry http://192.168.88.4:8081/repository/npm-group/
npm login –registry=http://192.168.88.4:8081/repository/npm-hosted/
npm publish –registry=http://192.168.88.4:8081/repository/npm-hosted/
mkdir ./npm-packages-offline-cache
yarn config set yarn-offline-mirror ./npm-packages-offline-cache
yarn config set yarn-offline-mirror-pruning true
mv ~/.yarnrc ./
rm -rf node_modules/ yarn.lock
yarn install
|
批量发布至 nexus hosted 脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| @echo off
:: init params
set deployFile=*.tar.gz
set deployFile2=*.tgz
set url=http://xxx.xxx.xx.xx:8081/repository/npm-hosted/
echo Searching tar.gz and tgz file...
rem "延缓环境变量扩充"
SETLOCAL ENABLEDELAYEDEXPANSION
for %%f in (%deployFile% %deployFile2%) do (
set name=%%f
echo !name! to deploy to %url%
rem deploy to server
call npm publish -registry=%url% !name!
)
pause
|
测试服务器
1
2
3
4
| cd ~/sunwoda/frontend-for-trainingcenter/
npm i && npm run build
rm -rf /usr/local/nginx/html/build
mv ~/sunwoda/frontend-for-trainingcenter/build /usr/local/nginx/html
|
Registry
1
2
| docker pull registry
docker run -d -p 5000:5000 --restart always --name registry registry:latest
|
YApi
Docker 容器之间网络互通
1
| docker network create yapi
|
数据库准备 MongoDB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| # 1. 备份 mongoDB 到宿主机,需要使用下面命令创建存储卷
docker volume create mongo-data
# 2. 拉取镜像,国内服务器提供商网络问题,可能会拉取多次才能成功
docker pull mongo:4.4.4
# 3. 启动 MongoDB
# 启动 MongoDB,其中 -e 指定 MONGO_INITDB_ROOT_USERNAME 为 MongoDB 的 ROOT 用户名,MONGO_INITDB_ROOT_PASSWORD 为 MongoDB 的 ROOT 用户密码
docker run -d \
--name mongodb \
--restart always \
--net=yapi \
-p 27017:27017 \
-v mongo-data:/data/db \
-e MONGO_INITDB_DATABASE=yapi \
-e MONGO_INITDB_ROOT_USERNAME=yapipro \
-e MONGO_INITDB_ROOT_PASSWORD=yapipro1024 \
mongo:4.4.4
# 4、查看 MongoDB 容器的启动情况
docker ps -a
# 5、 进入 MongoDB 容器,从第 4 步查看 MongoDB 容器可以获取到容器 id,以下示例使用 2c46d9f59874 代表 MongoDB 的容器 id
docker exec -it 2c46d9f59874 /bin/sh
# 6、进入 MongoDB 容器后,进入 mongo cli
mongo localhost:27017
|
初始化库表
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| use admin;
db.auth("yapipro", "yapipro1024");
# 创建 yapi 数据库
use yapi;
# 创建给 yapi 使用的账号和密码,限制权限
db.createUser({
user: 'yapi',
pwd: 'yapi123456',
roles: [
{ role: "dbAdmin", db: "yapi" },
{ role: "readWrite", db: "yapi" }
]
});
# 退出 Mongo Cli
exit
# 退出容器
exit
|
新建启动配置
config.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| {
"port": "3000",
"adminAccount": "hexiaohei1024@gmail.com",
"timeout":120000,
"db": {
"servername": "mongo",
"DATABASE": "yapi",
"port": 27017,
"user": "yapi",
"pass": "yapi123456",
"authSource": ""
},
"mail": {
"enable": true,
"host": "smtp.gmail.com",
"port": 465,
"from": "*",
"auth": {
"user": "hexiaohei1024@gmail.com",
"pass": "xxx"
}
}
}
|
启动 YApi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| docker pull yapipro/yapi:latest
# 初始化数据库表
docker run -d --rm \
--name yapi-init \
--link mongodb:mongo \
--net=yapi \
-v $PWD/config.json:/yapi/config.json \
yapipro/yapi \
server/install.js
# 初始化管理员账号在上面的 config.json 配置中 hexiaohei1024@gmail.com,初始密码是 yapi.pro,可以登录后进入个人中心修改
docker run -d \
--name yapi \
--link mongodb:mongo \
--restart always \
--net=yapi \
-p 9519:3000 \
-v $PWD/config.json:/yapi/config.json \
yapipro/yapi \
server/app.js
# 在服务器上验证 yapi 启动是否成功
curl localhost:9519
|
BookStack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| docker network create mysql_net
docker run -itd --net mysql_net \
--restart always \
-e MYSQL_ROOT_PASSWORD=123456 \
-v /root/sunwoda/mysql/conf:/etc/mysql/conf.d \
-v /root/sunwoda/mysql/data:/var/lib/mysql \
-v /root/sunwoda/mysql/logs:/logs \
-p 3306:3306 \
--name="mysql" \
mysql:5.7
docker run -itd --net mysql_net \
--restart always \
--name="redis" \
redis:6.0
docker run -itd --net mysql_net \
--restart always \
-e DB_HOST=mysql:3306 \
-e DB_DATABASE=bookstack \
-e DB_USERNAME=root \
-e DB_PASSWORD=123456 \
-e APP_URL=http://192.168.12.142:9518 \
-e APP_LANG=zh_CN \
-e QUEUE_CONNECTION=redis \
-e CACHE_DRIVER=redis \
-e SESSION_DRIVER=redis \
-e REDIS_SERVERS=redis:6379:0 \
-e DISABLE_EXTERNAL_SERVICES=true \
-v /root/sunwoda/bookstack/public/uploads:/var/www/bookstack/public/uploads \
-v /root/sunwoda/bookstack/public/uploads:/var/www/bookstack/storage/uploads \
-p 9518:8080 \
--name="bookstack" \
solidnerd/bookstack:latest
You can login with username 'admin@admin.com' and password 'password'.
|
JAR 包启动命令
1
| java -jar training-center-start-exec.jar -Dspring.profiles.active=dev -Dnacos.server=172.30.202.39:8848 -Dnacos.server.namespace=training-center -Dnacos.username=trainingCenter -Dnacos.password=trainingCenter001 -Dnacos.server.namespace.service=training-center -Dnacos.username.service=trainingCenter -Dnacos.password.service=trainingCenter001
|
RedisInsight
1
| docker run -itd --net mysql_net --restart always --name redisinsight -p 9517:8001 redislabs/redisinsight:latest
|
修改 Yarn 全局缓存位置
1
2
3
4
| yarn cache list
yarn cache dir
yarn cache clean
yarn config set cache-folder "D:\Users\2203110038\Yarn\Cache"
|
1
2
3
4
| npm config get cache
npm cache clean --force
npm config set cache "D:\Users\2203110038\npm-cache"
npm cache verify
|
ffmpeg 视频 hls 切片
1
| ffmpeg -i ./demo.mp4 -c:v libx264 -c:a aac -strict -2 -f hls -hls_list_size 0 ./demo/demo.m3u8
|
Nginx 跨域头
1
2
3
| add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Methods *;
add_header Access-Control-Allow-Headers *;
|
js 计算两点之间的距离
引用
1
2
3
4
5
6
7
8
9
10
11
12
| function getDistance(lat1, lng1, lat2, lng2) {
let radLat1 = toRadians(lat1);
let radLat2 = toRadians(lat2);
let deltaLat = radLat1 - radLat2;
let deltaLng = toRadians(lng1) - toRadians(lng2);
let dis = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(deltaLat / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(deltaLng / 2), 2)));
return dis * 6378.137;
function toRadians(d) { return d * Math.PI / 180;}
}
getDistance(39.54, 116.23, 38.85, 115.48) //100.43073284694667 //单位:公里
|
使用MySQL的geometry类型处理经纬度距离问题
建表
1
2
3
4
5
6
7
| CREATE TABLE `map` (
`id` int(11) NOT NULL,
`address` varchar(255) NOT NULL DEFAULT '',
`location` geometry NOT NULL,
PRIMARY KEY (`id`),
SPATIAL KEY `idx_location` (`location`)
)
|
插入
1
| INSERT INTO map (id, address, location) VALUES (1, 'somewhere', ST_GeomFromText('POINT(121.366961 31.190049)'))
|
注意必须使用 ST_GeomFromText 函数, 且 POINT() 里面是: 经度+空格+纬度
查询
- 查看经纬度
1
| SELECT ST_Distance_Sphere(POINT(121.590347, 31.388094),location) AS distant FROM map
|
- 计算两点之间的距离
算出来的结果, 单位:是米。注意现在POINT()里面经纬度之间是逗号分隔的
- 查询距离小于1000m的地点, 并由远及近排序
1
| SELECT id, address, ST_Distance_Sphere(POINT(121.590347, 31.388094),location) AS distant FROM map WHERE ST_Distance_Sphere(POINT(121.590347, 31.388094),location) < 1000 ORDER BY distant
|