小知识

记录编程路上的一些盲区知识点,方便后续直接拿来使用

正则 - 不匹配某些单词

  • /node_modules\/(?!@babel\/core)/

不匹配node_modules/@babel/core

匹配node_modules/@babel/preset-env

  • /node_modules\/(?!@babel\/core\/)/

优化版本 匹配node_modules/@babel/cores/

我们可以通过此正则,设置 webpack 的 loader,是否取特定处理某个在 node_modules 里面的库,对其进行编译

比如,我们需要忽略 node_modules,但是除了文件目录node_modules/a/node_modules/b/,即需要对这两个库,在编译时进行处理,不做忽略

可以设置如下正则:/node_modules\/(?!a\/|b\/)/

查看测试结果

nginx 配置单页路由

当访问任何一个以test.com/test开头的地址,都会指向/srv/static/test/build/index.html这个文件

解决了在单页应用时,路由跳转,页面刷新出现 404 的错误情况

1
2
3
4
5
6
7
8
9
server {
listen 80;
server_name test.com;

location ^~ /test {
alias /srv/static/test/build/;
try_files $uri /test/index.html;
}
}

go 语言,整形 string 转[]byte

给定10,12,13,14,1,2,3 转为 []byte{10,12,13,14,1,2,3}

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
// 直接看代码
package main

import (
"fmt"
"strconv"
)

const a = `10,12,13,14,1,2,3`

func main() {

d := []byte{}

if len(a) != 0 {
lv := ""
for _, v := range a {
if v == 44 {
s, _ := strconv.Atoi(lv)
d = append(d, uint8(s))
lv = ""
continue
}
lv = lv + string(v)
}
s, _ := strconv.Atoi(lv)
d = append(d, uint8(s))
}

fmt.Println(d)
}

部署 pgadmin

1
docker run --name pgadmin -p 5080:80  -e 'PGADMIN_DEFAULT_EMAIL=topthinking@test.com' -e 'PGADMIN_DEFAULT_PASSWORD=123456' -e 'PGADMIN_CONFIG_ENHANCED_COOKIE_PROTECTION=True' -e 'PGADMIN_CONFIG_LOGIN_BANNER="Authorised users only!"' -e 'PGADMIN_CONFIG_CONSOLE_LOG_LEVEL=10' -d dpage/pgadmin4:latest

docker 镜像加速

正则匹配所有字符串(包括换行)

1
const match = content.match(/<body>([\d\D]*)<\/body>/);