列表2024-week05

#最近做的事

#Obsidian 入门

因为经常会有使用知识库这样一个需求,所以需要类似的软件,小红书经常推Obsidian,所以尝试入门。

优点:

  1. 只基于 markdown 文件,方便整理、保存、备份等
  2. 有关系图谱,方便在信息之间寻找

缺点:

才开始使用,不知道能否找到相应的解决方案,目前主要为了整理开发文档+快速索引

  1. 代码格式化很不友好,我格式化的多行带缩进的代码粘贴进去会乱。
  2. 软件提供了文档链接功能,并且支持链接标题,但是当你修改标题后,对应的链接不会自动更新,官方的论坛:https://forum.obsidian.md/t/automatic-inline-update-of-links-to-headers-and-blocks-when-they-are-modified-no-extra-dialog-window/25412/61,说是性能问题= =

列表2024-week04

#最近读的东西

#github 仓库问题

2024 一开年开始,我就发现github.com在大陆的主 ip20.205.243.166访问不通了= =,感觉每次都要专门开个梯子好麻烦,研究了一番,改 hosts 解决。

https://tool.chinaz.com/dns/github.com可以查看所有 ip,我选了第二个,在/etc/hosts里添加了一条:

1
140.82.121.4 github.com

问题解决。

BTW,我用的是 ssh 的模式,这个模式在之前网页访问不通的情况下依然可以很快拉仓库,结果现在原来的 ip 也不行了(新换的这个依旧可以)。

~/.gitconfig添加:

1
2
[url "git@github.com:"]
insteadOf = https://github.com/

就会都走 ssh 模式。(很好用,我之前用来拉 nvim 仓库包的)

列表2024-week03

#最近读的东西

#perl 用法

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
[2024/01/21 9:47:32] mbp ➜  ~  perl -h

Usage: perl [switches] [--] [programfile] [arguments]
-0[octal] specify record separator (\0, if no argument)
-a autosplit mode with -n or -p (splits $_ into @F)
-C[number/list] enables the listed Unicode features
-c check syntax only (runs BEGIN and CHECK blocks)
-d[:debugger] run program under debugger
-D[number/list] set debugging flags (argument is a bit mask or alphabets)
-e program one line of program (several -e's allowed, omit programfile)
-E program like -e, but enables all optional features
-f don't do $sitelib/sitecustomize.pl at startup
-F/pattern/ split() pattern for -a switch (//'s are optional)
-i[extension] edit <> files in place (makes backup if extension supplied)
-Idirectory specify @INC/#include directory (several -I's allowed)
-l[octal] enable line ending processing, specifies line terminator
-[mM][-]module execute "use/no module..." before executing program
-n assume "while (<>) { ... }" loop around program
-p assume loop like -n but print line also, like sed
-s enable rudimentary parsing for switches after programfile
-S look for programfile using PATH environment variable
-t enable tainting warnings
-T enable tainting checks
-u dump core after parsing program
-U allow unsafe operations
-v print version, patchlevel and license
-V[:variable] print configuration summary (or a single Config.pm variable)
-w enable many useful warnings
-W enable all warnings
-x[directory] ignore text before #!perl line (optionally cd to directory)
-X disable all warnings

Run 'perldoc perl' for more help with Perl.

最近处理线上问题,需要捞日志,因为日常Perl风格的正则写的比较多,所以希望能直接一条命令导出,省的多个编辑器之间来回切换。

但是目前几乎所有命令都只支持POSIX风格的正则,记录一下解决方案:

  1. grep 可以通过-P参数,但是必须要下载 gnu 的 grep 才支持,mac 本身的不支持
  2. sed不支持Perl风格,也不会支持,解决方法是换命令,perl几乎 mac 都是装机自带的。
  3. -p会打印输出,比较适合做管道处理。-e就是执行后面的命令。
1
cat 240120.json | ggrep -P "\"args\": \"mid" | perl -pe 's/\s+"args": "mid:([0-9]+)([ \S]+)/$1/'

#https://go.dev/doc/gc-guide

Until Go 1.19, GOGC was the sole parameter that could be used to modify the GC’s behavior. While it works great as a way to set a trade-off, it doesn’t take into account that available memory is finite. Consider what happens when there’s a transient spike in the live heap size: because the GC will pick a total heap size proportional to that live heap size, GOGC must be configured such for the peak live heap size, even if in the usual case a higher GOGC value provides a better trade-off.

GOGC在配置的时候没有考虑内存有限的情况,当出现有临时的内存突增时,要么 gc 阈值过高导致 oom,要么考验开发/运维,要在配置时考虑到内存激增的情况,配置对应可用的 GOGC。

为了避免参数滥用,golang 限制了 gc 时间,使得理论上的最坏情况是程序性能下降两倍。

#-1%3=?

差点因为这个表达式写了一个 bug,测试了多个语言,发现只有 python 会返回 2。
数学定义上没有对负数的取模进行精确定义,所以只依赖具体语言实现。
对于go/c/php,这个值会返回 -1

列表2023-week50

#最近读的东西

#你真的知道如何设置数据库连接池的大小吗

#Go 函数指针是如何让你的程序变慢的?

#Go 1.22 中的 For 循环

#Go1.21 速览:Context 可以设置取消原因和回调函数了,等的可太久了!

列表2023-week49

#最近读的东西

#自己的一些项目该如何组织

#github 仓库拉取优化

背景是neovim的插件都在 github 上,大陆拉不下来。

解决方案:全局配置 Git 使用 SSH

1
vi ~/.gitconfig

加入 👇

1
2
[url "git@github.com:"]
insteadOf = https://github.com/

#https 证书

阿里云免费的证书有效期变成 3 个月了= =

免费方案 👆

#快速 csv 文件处理

为压测准备数据

  1. 从源数据中选取指定列作为待选数据:
1
cut -d',' -f6 raw.csv > res.txt
  • -d指定分隔符
  • -f指定选的列,比如我只要第 6 列数据
  1. 拆分数据集合:

因为我的数据从 100 个表取出来的,然后需要分成多个数据集合,我选择的第一种方法是把奇数行和偶数行拆分成两个文件(假设数据集只需要 2 个)

1
awk '{if (NR % 2 == 0) print > "res_1.txt"; else print > "res_2.txt"}' res.txt
  1. 打散数据:

因为数据是按尾号聚合的数据,具有不均匀性,需要打乱。

1
2
shuf res_2.txt  > res_2_suf.txt
shuf res_2.txt > res_2_suf.txt

感觉 chatgpt 出来之后,笔记已经显得不那么重要了= =

列表2023-week48

#最近读的东西

#1

排序的稳定性,之前还真没关注过= =

#2

#3

验证了很久,一个 redis 的分布式读写锁,在脏缓存的情况下会发生问题,其它 ok

列表2023-week45

#最近读的东西

#1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Usage: paste [OPTION]... [FILE]...
Write lines consisting of the sequentially corresponding lines from
each FILE, separated by TABs, to standard output.

With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
-d, --delimiters=LIST reuse characters from LIST instead of TABs
-s, --serial paste one file at a time instead of in parallel
-z, --zero-terminated line delimiter is NUL, not newline
--help display this help and exit
--version output version information and exit

GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Report paste translation bugs to <http://translationproject.org/team/>
Full documentation at: <http://www.gnu.org/software/coreutils/paste>
or available locally via: info '(coreutils) paste invocation'

paste1.txt:

1
2
1 2 3
4 5 6

paste2.txt:

1
2
a b c
d e f
1
2
3
4
5
6
$ paste paste1.txt paste2.txt
1 2 3 a b c
4 5 6 d e f
$ paste -s paste1.txt paste2.txt
1 2 3 4 5 6
a b c d e f

把 N 个文件按列合并

#2

有点难

列表2023-week44

#最近读的东西

#1

Mysql 官方文档

With ON DUPLICATE KEY UPDATE, the affected-rows value per row is 1 if the row is inserted as a new row, 2 if an existing row is updated, and 0 if an existing row is set to its current values. If you specify the CLIENT_FOUND_ROWS flag to the mysql_real_connect() C API function when connecting to mysqld, the affected-rows value is 1 (not 0) if an existing row is set to its current values.

在用upsert语句时,标准的返回值是 1 插入、2 更新、0 无影响。

In assignment value expressions in the ON DUPLICATE KEY UPDATE clause, you can use the VALUES(col_name) function to refer to column values from the INSERT portion of the INSERT … ON DUPLICATE KEY UPDATE statement. In other words, VALUES(col_name) in the ON DUPLICATE KEY UPDATE clause refers to the value of col_name that would be inserted, had no duplicate-key conflict occurred.

VALUES() 在上述语句的后面的时候,语法从来没见过,是存在歧义的,是代指数据库里的值还是插入语句中的值。

1
2
3
4
5
6
7
8
9
INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6)
ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);

-- 等价于:

INSERT INTO t1 (a,b,c) VALUES (1,2,3)
ON DUPLICATE KEY UPDATE c=3;
INSERT INTO t1 (a,b,c) VALUES (4,5,6)
ON DUPLICATE KEY UPDATE c=9;

An INSERT … ON DUPLICATE KEY UPDATE statement against a table having more than one unique or primary key is also marked as unsafe. (Bug #11765650, Bug #58637)

当一个表中有多个唯一索引时,同时使用upsert的结果是不确定的,只会更新随机一个。

#2

在开发时经常会出现 int 与 string 相互转换的场景,所以从int64转换成interface{}的时候,到底发生了什么 👆

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
package main

import (
"strconv"
"testing"
)

func BenchmarkInterfaceConversion(b *testing.B) {
num := int64(123)
var result int64

b.ResetTimer()
for i := 0; i < b.N; i++ {
interfaceNum := interface{}(num)
result = interfaceNum.(int64)
}

_ = result
}

func BenchmarkStrconvConversion(b *testing.B) {
num := int64(123)
var result int64

b.ResetTimer()
for i := 0; i < b.N; i++ {
str := strconv.FormatInt(num, 10)
result, _ = strconv.ParseInt(str, 10, 64)
}

_ = result
}
1
2
3
4
5
6
7
8
 [2023/11/03 13:11:15] mbp ➜  ~/Downloads/workspace/ct  go test -bench=. conv_test.go
goos: darwin
goarch: amd64
cpu: Intel(R) Core(TM) i5-1038NG7 CPU @ 2.00GHz
BenchmarkInterfaceConversion-8 1000000000 0.4254 ns/op
BenchmarkStrconvConversion-8 23592367 52.78 ns/op
PASS
ok command-line-arguments 2.849s

#3

为什么对 map 的访问,接了一个参数就不会 panic,还没找到资料

1
2
3
4
5
6
7
8
9
10
11
12
package main

import (
"fmt"
"testing"
)

func TestHelloWorld(t *testing.T) {
var m map[string]string
v, ok := m["o"]
fmt.Printf("value:%+v ok:%+v\n", v, ok)
}
1
2
3
4
5
6
 [2023/11/03 13:21:49] mbp ➜  ~/Downloads/workspace/ct  go test -v -run . map_test.go
=== RUN TestHelloWorld
value: ok:false
--- PASS: TestHelloWorld (0.00s)
PASS
ok command-line-arguments 0.290s