Blog

Mysql With Hierarchical Data

2023年2月25日
system design
202302, mysql

像知乎这样的评论回复模式,数据库应该怎么设计比较好,考虑性能、可扩展性等? - HD SUPERMAN的回答 - 知乎 https://www.zhihu.com/question/38959595/answer/2200636383 https://www.mysqltutorial.org/mysql-adjacency-list-tree/ https://github.com/WAWLixiong/MultipleComments/blob/master/pom.xml

20230224日志

2023年2月24日
2023
202302, go, defer

go # err总是通过最后一个返回值返回 panicking # panic可以被recover恢复, recover仅可以在defer中, 即使发生panic,defer也会执行 节省的使用panic, 在programmer error或者dependency场景中使用 func main(){ defer fun(){ if f := recevoer(); r != nil { fmt.Println("recover", r) } }() f() } func f(){ fmt.Println("a") panic("foo") fmt.Println("b") } ignoring when to wrap an error # 需要添加额外信息;把error作为特定的一种error 老式的方式,通过struct包装 type BarError struct { Err error } func (b BarError) Error() string { return "bar failed:" + b.Err.Error() } 通过%w添加上下文, 可以unwrap if err ! ...

20230223日志

2023年2月23日
2023
202302, go, range

go #

value copy #

type account struct {
    balance float32
}

accounts := []account{
    {balance: 100.},
    {balance: 200.},
    {balance: 300.},
}
for _, a := range accounts {
    a.balance += 1000
}
...

20230222日志

2023年2月22日
2023
202302, go, defer

go # defer: in a loop # func readFiles(ch <-chan string) error { for path := range ch { file, err := os.Open(path) if err != nil { return err } defer file.Close() // Do something with file } return nil } 方案1, 将file的open与close封装在独立函数, 循环中不defer 方案2, 循环内创建闭包调用, 在闭包中defer defer: ignoring how defer arguments and receivers are evaluated # func f() error { var status string defer notify(status) defer incrementCounter(status) if err := foo(); err ! ...

20230220日志

2023年2月20日
2023
202302, go

go 模块 #

Go 1.11 版本之后,引入了 Go 模块化支持,可以通过 go mod 命令来管理模块。下面是一些常用的添加模块的命令:

初始化一个新的模块

go mod init <module_name>

该命令会在当前目录下创建一个新的 go.mod 文件,并将当前目录视为一个新的 Go 模块。<module_name> 为模块的名称,通常使用类似于 github.com/<username>/<repo> 的格式。

添加依赖

go get <module_path>@<version>

该命令会下载并安装指定版本的依赖包,并将其添加到当前模块的 go.mod 文件中。<module_path> 为依赖包的路径,可以是本地路径、远程仓库路径或者包名等形式;<version> 则为依赖包的版本号,可以是标签、分支或者提交哈希等形式。

[!NOTE] 注意,如果依赖包没有指定版本号,则 go get 命令会自动下载并安装最新的版本。

...

English Sentence Daily

2023年2月17日
English
English Setence

I’ll give this cookie to whichever of you wants it.

The word “wants” is the third-person singular present tense form of the verb “want”, which means to have a desire or a need for something. When a verb is conjugated in the present tense, its ending changes based on the subject of the sentence.

In the sentence “I want the cookie,” the subject “I” requires the base form of the verb “want”. However, in the sentence “he/she/it wants the cookie,” the subject “he/she/it” requires the third-person singular form “wants”.

So, in the original sentence “I’ll give this cookie to whichever of you wants it,” “wants” is used because the subject “whichever of you” is a third-person singular subject, and therefore requires the third-person singular form of the verb “want”.

...

20230214日志

2023年2月14日
2023
202302, golang, 算法

golang # byte - byte 仍然为 byte 类型 # todo: 复现不了了? 遍历的同时将字符串恢复为整型 x := 0 for i := 0; i <size; i++{ x = x*10 + int(str[i]-'0') } while 循环使用 || , 在内部控制逻辑; 学习165题官解 func compareVersion(v1, v2 string) int { m, n := len(v1), len(v2) i, j := 0, 0 for i < m || j < n { // ... } }

20230212日志

2023年2月12日
2023
202302, 算法, 心流

算法 # if, else 剩余else是什么内容? if a { } else if b { } else { } else 的条件等价与 !(a) && !(b) 心流 # 先扩充技术广度,再拓展深度 深度不要太深,广度要充分 全栈应用开发 nextjs

TODO

2023年2月12日
TODO
TODO

搞清楚redison是如何从tryLock, 调用到lock方法的 redison是如何通过信号量和redis的队列实现获取不到锁重试的 了解前端前端生态 博文图片上传功能怎么实现的? 上传就保存到服务器吗, 最后点击取消了,怎么处理呢