├── README.MD ├── 数据库 ├── README.MD ├── MySQL │ ├── Mysql深度核心面试知识汇总.pdf │ ├── 基础 │ │ ├── 导入现有的数据表、表的数据.md │ │ └── Code │ │ │ └── practice │ │ │ └── op.sql │ ├── 面试题.md │ └── 进阶 │ │ └── 性能分析.md ├── Redis │ └── 5. Redis的发布和订阅.md └── .gitignore ├── Golang ├── Code │ ├── basicCode │ │ ├── test.txt │ │ ├── README.MD │ │ ├── Code │ │ │ ├── goProject │ │ │ │ ├── vendor │ │ │ │ │ ├── github.com │ │ │ │ │ │ ├── tidwall │ │ │ │ │ │ │ ├── gjson │ │ │ │ │ │ │ │ ├── .travis.yml │ │ │ │ │ │ │ │ ├── logo.png │ │ │ │ │ │ │ │ ├── go.mod │ │ │ │ │ │ │ │ ├── go.sum │ │ │ │ │ │ │ │ └── LICENSE │ │ │ │ │ │ │ ├── match │ │ │ │ │ │ │ │ ├── .travis.yml │ │ │ │ │ │ │ │ ├── README.md │ │ │ │ │ │ │ │ └── LICENSE │ │ │ │ │ │ │ └── pretty │ │ │ │ │ │ │ │ ├── .travis.yml │ │ │ │ │ │ │ │ └── LICENSE │ │ │ │ │ │ └── shopspring │ │ │ │ │ │ │ └── decimal │ │ │ │ │ │ │ ├── go.mod │ │ │ │ │ │ │ ├── .gitignore │ │ │ │ │ │ │ ├── .travis.yml │ │ │ │ │ │ │ └── CHANGELOG.md │ │ │ │ │ └── modules.txt │ │ │ │ ├── interfaceDemo │ │ │ │ │ ├── Usber.go │ │ │ │ │ ├── Computer.go │ │ │ │ │ ├── Phone.go │ │ │ │ │ └── Camera.go │ │ │ │ ├── go.mod │ │ │ │ ├── .idea │ │ │ │ │ ├── misc.xml │ │ │ │ │ ├── .gitignore │ │ │ │ │ ├── modules.xml │ │ │ │ │ └── goProject.iml │ │ │ │ ├── EmptyInterface │ │ │ │ │ └── EmptyA.go │ │ │ │ ├── calc │ │ │ │ │ └── calc.go │ │ │ │ ├── go.sum │ │ │ │ └── SecondInterface │ │ │ │ │ └── main.go │ │ │ └── goStudy │ │ │ │ ├── main │ │ │ │ ├── test.txt │ │ │ │ ├── test2.txt │ │ │ │ ├── hello.go │ │ │ │ ├── floatDemo.go │ │ │ │ ├── 12_TypeDemo.go │ │ │ │ ├── 17_fileCopyDemo.go │ │ │ │ ├── 11_pointerDemo.go │ │ │ │ ├── 15_ChannelDemo2.go │ │ │ │ ├── 15_lockDemo.go │ │ │ │ ├── 9_FileDemo.go │ │ │ │ ├── 12_StructDemo5.go │ │ │ │ ├── exec.go │ │ │ │ ├── 15_goroutineDemo2.go │ │ │ │ ├── 17_fileDemo3.go │ │ │ │ ├── 17_fileDemo.go │ │ │ │ ├── 12_StructDemo4.go │ │ │ │ ├── 15_ChannelDemo3.go │ │ │ │ ├── 12_StructDemo2.go │ │ │ │ ├── 12_StructDemo3.go │ │ │ │ ├── strconvDemo.go │ │ │ │ ├── 11_pointerDemo2.go │ │ │ │ ├── 12_StructJsonDemo.go │ │ │ │ ├── 12_StructJsonDemo3.go │ │ │ │ ├── 17_fileDemo2.go │ │ │ │ ├── man3.go │ │ │ │ ├── 12_StructJsonDemo2.go │ │ │ │ ├── 15_goroutineDemo.go │ │ │ │ ├── 16_reflectDemo.go │ │ │ │ ├── 15_ChannelDemo.go │ │ │ │ ├── 12_StructDemo.go │ │ │ │ ├── sortDemo.go │ │ │ │ ├── 15_ChannelDemo5.go │ │ │ │ ├── StringDemo.go │ │ │ │ ├── byteDemo.go │ │ │ │ └── 6_ArrayDemo.go │ │ │ │ └── .idea │ │ │ │ ├── misc.xml │ │ │ │ ├── .gitignore │ │ │ │ ├── modules.xml │ │ │ │ └── goStudy.iml │ │ ├── test2.txt │ │ ├── go_basic │ │ │ ├── helloword.go │ │ │ ├── cycle.go │ │ │ ├── pointer.go │ │ │ └── var.go │ │ ├── goProject │ │ │ ├── calc │ │ │ │ └── calc.go │ │ │ ├── go.mod │ │ │ ├── main.go │ │ │ └── go.sum │ │ └── mutex.go │ ├── Gin │ │ ├── README.MD │ │ ├── .idea │ │ │ ├── vcs.xml │ │ │ ├── .gitignore │ │ │ ├── modules.xml │ │ │ └── Gin.iml │ │ ├── Params │ │ │ ├── templates │ │ │ │ ├── posts │ │ │ │ │ └── index.html │ │ │ │ └── users │ │ │ │ │ └── index.html │ │ │ ├── functions │ │ │ │ └── book.go │ │ │ └── main.go │ │ ├── fileUpload │ │ │ └── index.html │ │ ├── redirect │ │ │ └── main.go │ │ ├── GORM │ │ │ └── V1 │ │ │ │ └── basic.go │ │ ├── go.mod │ │ └── route │ │ │ └── route.go │ ├── standard library │ │ ├── fmt │ │ │ └── xx.txt │ │ ├── flag │ │ │ ├── args_demo │ │ │ ├── flag_demo │ │ │ └── main.go │ │ ├── go.mod │ │ ├── go.sum │ │ ├── log │ │ │ ├── main1.go │ │ │ └── xx.log │ │ ├── context │ │ │ └── main.go │ │ └── strconv │ │ │ └── main.go │ ├── gRPC │ │ ├── basic │ │ │ ├── go.mod │ │ │ ├── pb │ │ │ │ ├── home │ │ │ │ │ └── home.proto │ │ │ │ ├── build.bat │ │ │ │ └── person │ │ │ │ │ └── person.proto │ │ │ └── main.go │ │ ├── server │ │ │ ├── pb │ │ │ │ ├── build.bat │ │ │ │ └── person │ │ │ │ │ └── person.proto │ │ │ ├── 4种模式 │ │ │ │ ├── 普通服务 │ │ │ │ │ ├── pb │ │ │ │ │ │ ├── build.bat │ │ │ │ │ │ └── person │ │ │ │ │ │ │ └── person.proto │ │ │ │ │ ├── go.mod │ │ │ │ │ ├── client │ │ │ │ │ │ └── main.go │ │ │ │ │ └── server │ │ │ │ │ │ └── main.go │ │ │ │ ├── 流式传入 │ │ │ │ │ ├── pb │ │ │ │ │ │ ├── build.bat │ │ │ │ │ │ └── person │ │ │ │ │ │ │ └── person.proto │ │ │ │ │ └── go.mod │ │ │ │ ├── 流式出入 │ │ │ │ │ ├── pb │ │ │ │ │ │ ├── build.bat │ │ │ │ │ │ └── person │ │ │ │ │ │ │ └── person.proto │ │ │ │ │ └── go.mod │ │ │ │ └── 流式返回 │ │ │ │ │ ├── pb │ │ │ │ │ ├── build.bat │ │ │ │ │ └── person │ │ │ │ │ │ └── person.proto │ │ │ │ │ └── go.mod │ │ │ └── go.mod │ │ ├── HelloWorld │ │ │ ├── .idea │ │ │ │ ├── .gitignore │ │ │ │ ├── vcs.xml │ │ │ │ ├── go.imports.xml │ │ │ │ ├── modules.xml │ │ │ │ └── gRPC.iml │ │ │ ├── pb │ │ │ │ └── hello_grpc.proto │ │ │ ├── go.mod │ │ │ ├── client │ │ │ │ └── main.go │ │ │ └── server │ │ │ │ └── main.go │ │ └── basicGateway │ │ │ ├── .idea │ │ │ ├── .gitignore │ │ │ ├── vcs.xml │ │ │ ├── go.imports.xml │ │ │ ├── modules.xml │ │ │ └── gRPC.iml │ │ │ ├── pb │ │ │ ├── build.bat │ │ │ ├── person │ │ │ │ └── person.proto │ │ │ └── google │ │ │ │ └── api │ │ │ │ └── annotations.proto │ │ │ └── go.mod │ ├── advanceCode │ │ ├── go.mod │ │ ├── go.sum │ │ ├── goroutine │ │ │ ├── basic │ │ │ │ └── main.go │ │ │ └── main.go │ │ ├── workpool │ │ │ └── main.go │ │ ├── udp │ │ │ ├── client │ │ │ │ └── main.go │ │ │ └── server │ │ │ │ └── main.go │ │ ├── mutex │ │ │ └── lx │ │ │ │ └── main.go │ │ ├── cannel │ │ │ └── main.go │ │ └── tcp │ │ │ └── server │ │ │ └── proto │ │ │ └── proto.go │ ├── GORM-v2 │ │ ├── GORM-v2 │ │ │ ├── .idea │ │ │ │ ├── .gitignore │ │ │ │ ├── vcs.xml │ │ │ │ ├── sqldialects.xml │ │ │ │ ├── modules.xml │ │ │ │ ├── GORM-v2.iml │ │ │ │ └── dataSources.xml │ │ │ ├── sql_gorm.go │ │ │ ├── delete_gorm.go │ │ │ ├── go.mod │ │ │ ├── create_gorm.go │ │ │ ├── model.go │ │ │ ├── association_tags.go │ │ │ ├── transaction.go │ │ │ ├── update_gorm.go │ │ │ ├── polymorphic.go │ │ │ ├── go.sum │ │ │ ├── one2one.go │ │ │ ├── one2many.go │ │ │ └── many2many.go │ │ ├── 增删改查 │ │ │ ├── sql_gorm.go │ │ │ ├── delete_gorm.go │ │ │ ├── create_gorm.go │ │ │ ├── model.go │ │ │ └── update_gorm.go │ │ ├── 关系 │ │ │ ├── preload_gorm.go │ │ │ ├── has_one_gorm.go │ │ │ ├── association_tags.go │ │ │ ├── belongs_to_gorm.go │ │ │ ├── polymorphic.go │ │ │ ├── one2one.go │ │ │ ├── one2many.go │ │ │ └── many2many.go │ │ ├── 模型 │ │ │ └── model.go │ │ └── 事务 │ │ │ └── transaction.go │ └── .idea │ │ ├── vcs.xml │ │ ├── modules.xml │ │ └── Code.iml ├── README.MD └── learning_note │ ├── Gin框架 │ ├── 个人网页.md │ └── 基础.md │ ├── 基础语法 │ └── 运算符.md │ └── GORM │ └── 1. GORM v2介绍.md ├── Rust ├── Code │ ├── us │ └── us.rs └── rustlings │ ├── .gitignore │ └── exercises │ ├── 00_intro │ ├── intro2.rs │ └── README.md │ ├── 01_variables │ ├── variables1.rs │ ├── variables3.rs │ ├── variables6.rs │ ├── variables4.rs │ ├── variables2.rs │ ├── variables5.rs │ └── README.md │ ├── quizzes │ ├── README.md │ └── quiz1.rs │ ├── 02_functions │ ├── functions1.rs │ ├── functions3.rs │ ├── functions5.rs │ ├── functions2.rs │ ├── README.md │ └── functions4.rs │ ├── 21_macros │ ├── macros1.rs │ ├── macros2.rs │ ├── macros3.rs │ ├── macros4.rs │ └── README.md │ ├── 22_clippy │ ├── clippy2.rs │ ├── README.md │ ├── clippy1.rs │ └── clippy3.rs │ ├── 17_tests │ ├── README.md │ ├── tests2.rs │ └── tests1.rs │ ├── 18_iterators │ ├── README.md │ ├── iterators1.rs │ └── iterators4.rs │ ├── 10_modules │ ├── README.md │ ├── modules1.rs │ ├── modules2.rs │ └── modules3.rs │ ├── 03_if │ ├── README.md │ ├── if1.rs │ ├── if2.rs │ └── if3.rs │ ├── 09_strings │ ├── strings1.rs │ ├── README.md │ ├── strings2.rs │ ├── strings4.rs │ └── strings3.rs │ ├── 07_structs │ └── README.md │ ├── 04_primitive_types │ ├── primitive_types5.rs │ ├── README.md │ ├── primitive_types3.rs │ ├── primitive_types4.rs │ ├── primitive_types1.rs │ ├── primitive_types6.rs │ └── primitive_types2.rs │ ├── 16_lifetimes │ ├── lifetimes3.rs │ ├── lifetimes2.rs │ ├── lifetimes1.rs │ └── README.md │ ├── 08_enums │ ├── enums1.rs │ ├── README.md │ └── enums2.rs │ ├── 12_options │ ├── options3.rs │ ├── README.md │ ├── options2.rs │ └── options1.rs │ ├── 06_move_semantics │ ├── README.md │ ├── move_semantics4.rs │ ├── move_semantics3.rs │ ├── move_semantics1.rs │ ├── move_semantics5.rs │ └── move_semantics2.rs │ ├── 05_vecs │ ├── vecs1.rs │ └── README.md │ ├── 11_hashmaps │ ├── README.md │ └── hashmaps1.rs │ ├── 14_generics │ ├── README.md │ ├── generics1.rs │ └── generics2.rs │ ├── 20_threads │ ├── README.md │ ├── threads1.rs │ └── threads2.rs │ ├── 23_conversions │ └── using_as.rs │ ├── 15_traits │ ├── traits2.rs │ ├── README.md │ ├── traits1.rs │ ├── traits5.rs │ ├── traits4.rs │ └── traits3.rs │ ├── 13_error_handling │ ├── README.md │ ├── errors3.rs │ ├── errors4.rs │ └── errors1.rs │ ├── 19_smart_pointers │ └── README.md │ └── README.md ├── 设计模式 └── attachments │ └── image-202206161728457.gif ├── Algorithm ├── 小技巧.md └── 时空复杂度.md ├── Linux ├── 常用文件管理命令.md └── Shell.md └── K8s └── 基础 └── Ingress.md /README.MD: -------------------------------------------------------------------------------- 1 | # 个人学习笔记 -------------------------------------------------------------------------------- /数据库/README.MD: -------------------------------------------------------------------------------- 1 | # SQL学习 -------------------------------------------------------------------------------- /Golang/Code/basicCode/test.txt: -------------------------------------------------------------------------------- 1 | hello -------------------------------------------------------------------------------- /Golang/Code/Gin/README.MD: -------------------------------------------------------------------------------- 1 | # Golang框架Gin 2 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/README.MD: -------------------------------------------------------------------------------- 1 | # Golang 学习 2 | -------------------------------------------------------------------------------- /Golang/Code/standard library/fmt/xx.txt: -------------------------------------------------------------------------------- 1 | 往文件中写如信息:沙河小王子 -------------------------------------------------------------------------------- /Rust/Code/us: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Swiftie13st/LearningNote/HEAD/Rust/Code/us -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/tidwall/gjson/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/tidwall/match/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/tidwall/pretty/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | -------------------------------------------------------------------------------- /Rust/rustlings/.gitignore: -------------------------------------------------------------------------------- 1 | .rustlings-state.txt 2 | solutions 3 | Cargo.lock 4 | target 5 | .vscode 6 | -------------------------------------------------------------------------------- /Golang/README.MD: -------------------------------------------------------------------------------- 1 | # Golang 学习 2 | 3 | /basicCode 基础语法 4 | 5 | /advanceCode 进阶语法 6 | 7 | /Gin Gin框架学习 8 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basic/go.mod: -------------------------------------------------------------------------------- 1 | module grpc 2 | 3 | go 1.18 4 | 5 | require google.golang.org/protobuf v1.28.1 6 | -------------------------------------------------------------------------------- /数据库/MySQL/Mysql深度核心面试知识汇总.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Swiftie13st/LearningNote/HEAD/数据库/MySQL/Mysql深度核心面试知识汇总.pdf -------------------------------------------------------------------------------- /Golang/Code/basicCode/test2.txt: -------------------------------------------------------------------------------- 1 | 啦啦啦 2 | 气不错 3 | t file 4 | i am test file 5 | i am test file啦啦啦 6 | 啦啦啦 7 | 啦啦啦 8 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/shopspring/decimal/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/shopspring/decimal 2 | 3 | go 1.13 4 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/test.txt: -------------------------------------------------------------------------------- 1 | 啦啦啦 2 | 气不错 3 | t file 4 | i am test file 5 | i am test file啦啦啦 6 | 啦啦啦 7 | 啦啦啦 8 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/test2.txt: -------------------------------------------------------------------------------- 1 | 啦啦啦 2 | 气不错 3 | t file 4 | i am test file 5 | i am test file啦啦啦 6 | 啦啦啦 7 | 啦啦啦 8 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/shopspring/decimal/.gitignore: -------------------------------------------------------------------------------- 1 | .git 2 | *.swp 3 | 4 | # IntelliJ 5 | .idea/ 6 | *.iml 7 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/go_basic/helloword.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("hello world!") 7 | } 8 | -------------------------------------------------------------------------------- /Golang/Code/standard library/flag/args_demo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Swiftie13st/LearningNote/HEAD/Golang/Code/standard library/flag/args_demo -------------------------------------------------------------------------------- /Golang/Code/standard library/flag/flag_demo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Swiftie13st/LearningNote/HEAD/Golang/Code/standard library/flag/flag_demo -------------------------------------------------------------------------------- /设计模式/attachments/image-202206161728457.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Swiftie13st/LearningNote/HEAD/设计模式/attachments/image-202206161728457.gif -------------------------------------------------------------------------------- /Golang/Code/advanceCode/go.mod: -------------------------------------------------------------------------------- 1 | module goProject 2 | 3 | go 1.18 4 | 5 | require golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect 6 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/00_intro/intro2.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // TODO: Fix the code to print "Hello world!". 3 | println!("Hello world!"); 4 | } 5 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/pb/build.bat: -------------------------------------------------------------------------------- 1 | protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative ./person/person.proto -------------------------------------------------------------------------------- /Golang/Code/standard library/go.mod: -------------------------------------------------------------------------------- 1 | module standardlibrary 2 | 3 | go 1.18 4 | 5 | require golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect 6 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/interfaceDemo/Usber.go: -------------------------------------------------------------------------------- 1 | package interfaceDemo 2 | 3 | // 定义一个Usber接口 4 | type Usber interface { 5 | start() 6 | stop() 7 | } 8 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/普通服务/pb/build.bat: -------------------------------------------------------------------------------- 1 | protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative ./person/person.proto -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/流式传入/pb/build.bat: -------------------------------------------------------------------------------- 1 | protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative ./person/person.proto -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/流式出入/pb/build.bat: -------------------------------------------------------------------------------- 1 | protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative ./person/person.proto -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/流式返回/pb/build.bat: -------------------------------------------------------------------------------- 1 | protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative ./person/person.proto -------------------------------------------------------------------------------- /Rust/rustlings/exercises/01_variables/variables1.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // TODO: Add missing keyword. 3 | let x = 5; 4 | 5 | println!("x has the value {x}"); 6 | } 7 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/go.mod: -------------------------------------------------------------------------------- 1 | module goProject 2 | 3 | go 1.14 4 | 5 | require ( 6 | github.com/shopspring/decimal v1.2.0 7 | github.com/tidwall/gjson v1.6.0 8 | ) 9 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/quizzes/README.md: -------------------------------------------------------------------------------- 1 | # Quizzes 2 | 3 | After every couple of sections, there will be a quiz in this directory that'll test your knowledge on a bunch of sections at once. 4 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/hello.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var num = 10 7 | fmt.Println("hello \t world!", num) 8 | fmt.Println("hello world!") 9 | } -------------------------------------------------------------------------------- /Rust/rustlings/exercises/01_variables/variables3.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // TODO: Change the line below to fix the compiler error. 3 | let x: i32 = 10; 4 | 5 | println!("Number {x}"); 6 | } 7 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/01_variables/variables6.rs: -------------------------------------------------------------------------------- 1 | // TODO: Change the line below to fix the compiler error. 2 | const NUMBER: i32 = 3; 3 | 4 | fn main() { 5 | println!("Number: {NUMBER}"); 6 | } 7 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basic/pb/home/home.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; // 告诉编译器用`proto3`来解读 2 | 3 | package home; 4 | 5 | option go_package = "grpc/pb/home;home"; 6 | 7 | message Home{ 8 | string home_num = 1; 9 | } -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/tidwall/gjson/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Swiftie13st/LearningNote/HEAD/Golang/Code/basicCode/Code/goProject/vendor/github.com/tidwall/gjson/logo.png -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/floatDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var num1 float64 = 3.1 7 | var num2 float64 = 4.1 8 | fmt.Println(num1, num2) 9 | } 10 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件 2 | /shelf/ 3 | /workspace.xml 4 | # 基于编辑器的 HTTP 客户端请求 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/HelloWorld/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件 2 | /shelf/ 3 | /workspace.xml 4 | # 基于编辑器的 HTTP 客户端请求 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/tidwall/gjson/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/tidwall/gjson 2 | 3 | go 1.12 4 | 5 | require ( 6 | github.com/tidwall/match v1.0.1 7 | github.com/tidwall/pretty v1.0.0 8 | ) 9 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basicGateway/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # 默认忽略的文件 2 | /shelf/ 3 | /workspace.xml 4 | # 基于编辑器的 HTTP 客户端请求 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /Golang/Code/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basic/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "grpc/pb/person" 4 | 5 | func main() { 6 | var p person.Person 7 | // 设置值 8 | one := p.TestOneOf.(*person.Person_One) 9 | one.One = "123" 10 | 11 | } 12 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basicGateway/pb/build.bat: -------------------------------------------------------------------------------- 1 | protoc -I ./ --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative --grpc-gateway_out . --grpc-gateway_opt paths=source_relative ./person/person.proto -------------------------------------------------------------------------------- /Golang/Code/Gin/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Golang/Code/Gin/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Editor-based HTTP Client requests 5 | /httpRequests/ 6 | # Datasource local storage ignored files 7 | /dataSources/ 8 | /dataSources.local.xml 9 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/01_variables/variables4.rs: -------------------------------------------------------------------------------- 1 | // TODO: Fix the compiler error. 2 | fn main() { 3 | let mut x = 3; 4 | println!("Number {x}"); 5 | 6 | x = 5; // Don't change this line 7 | println!("Number {x}"); 8 | } 9 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/02_functions/functions1.rs: -------------------------------------------------------------------------------- 1 | // TODO: Add some function with the name `call_me` without arguments or a return value. 2 | 3 | fn main() { 4 | call_me(); // Don't change this line 5 | } 6 | 7 | fn call_me() {} 8 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Golang/Code/advanceCode/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDEyz2oklo4IvDkpigvkD8= 2 | golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 3 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/HelloWorld/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basicGateway/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/21_macros/macros1.rs: -------------------------------------------------------------------------------- 1 | macro_rules! my_macro { 2 | () => { 3 | println!("Check out my macro!"); 4 | }; 5 | } 6 | 7 | fn main() { 8 | // TODO: Fix the macro call. 9 | my_macro!(); 10 | } 11 | -------------------------------------------------------------------------------- /Golang/Code/standard library/go.sum: -------------------------------------------------------------------------------- 1 | golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f h1:Ax0t5p6N38Ga0dThY21weqDEyz2oklo4IvDkpigvkD8= 2 | golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 3 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/shopspring/decimal/.travis.yml: -------------------------------------------------------------------------------- 1 | language: go 2 | 3 | go: 4 | - 1.7.x 5 | - 1.12.x 6 | - 1.13.x 7 | - tip 8 | 9 | install: 10 | - go build . 11 | 12 | script: 13 | - go test -v 14 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | # Datasource local storage ignored files 5 | /dataSources/ 6 | /dataSources.local.xml 7 | # Editor-based HTTP Client requests 8 | /httpRequests/ 9 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/sql_gorm.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func TestSQL() { 6 | var users TestUser 7 | GLOBAL_DB.Raw("SELECT id, name, age FROM t_test_users WHERE name = ?", "Nobody").Scan(&users) 8 | fmt.Println(users) 9 | } 10 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/增删改查/sql_gorm.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func TestSQL() { 6 | var users TestUser 7 | GLOBAL_DB.Raw("SELECT id, name, age FROM t_test_users WHERE name = ?", "Nobody").Scan(&users) 8 | fmt.Println(users) 9 | } 10 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/22_clippy/clippy2.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let mut res = 42; 3 | let option = Some(12); 4 | // TODO: Fix the Clippy lint. 5 | if let Some(x) = option { 6 | res += x; 7 | } 8 | 9 | println!("{res}"); 10 | } 11 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/02_functions/functions3.rs: -------------------------------------------------------------------------------- 1 | fn call_me(num: u32) { 2 | for i in 0..num { 3 | println!("Ring! Call number {}", i + 1); 4 | } 5 | } 6 | 7 | fn main() { 8 | // TODO: Fix the function call. 9 | _ = call_me(1); 10 | } 11 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basic/pb/build.bat: -------------------------------------------------------------------------------- 1 | protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative ./person/person.proto 2 | protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative ./home/home.proto -------------------------------------------------------------------------------- /Rust/rustlings/exercises/02_functions/functions5.rs: -------------------------------------------------------------------------------- 1 | // TODO: Fix the function body without changing the signature. 2 | fn square(num: i32) -> i32 { 3 | num * num 4 | } 5 | 6 | fn main() { 7 | let answer = square(3); 8 | println!("The square of 3 is {answer}"); 9 | } 10 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/21_macros/macros2.rs: -------------------------------------------------------------------------------- 1 | // TODO: Fix the compiler error by moving the whole definition of this macro. 2 | macro_rules! my_macro { 3 | () => { 4 | println!("Check out my macro!"); 5 | }; 6 | } 7 | 8 | fn main() { 9 | my_macro!(); 10 | } 11 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/01_variables/variables2.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // TODO: Change the line below to fix the compiler error. 3 | let x = 10; 4 | 5 | if x == 10 { 6 | println!("x is ten!"); 7 | } else { 8 | println!("x is not ten!"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/17_tests/README.md: -------------------------------------------------------------------------------- 1 | # Tests 2 | 3 | Going out of order from the book to cover tests -- many of the following exercises will ask you to make tests pass! 4 | 5 | ## Further information 6 | 7 | - [Writing Tests](https://doc.rust-lang.org/book/ch11-01-writing-tests.html) 8 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/18_iterators/README.md: -------------------------------------------------------------------------------- 1 | # Iterators 2 | 3 | This section will teach you about Iterators. 4 | 5 | ## Further information 6 | 7 | - [Iterator](https://doc.rust-lang.org/book/ch13-02-iterators.html) 8 | - [Iterator documentation](https://doc.rust-lang.org/stable/std/iter/) 9 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/02_functions/functions2.rs: -------------------------------------------------------------------------------- 1 | // TODO: Add the missing type of the argument `num` after the colon `:`. 2 | fn call_me(num: i32) { 3 | for i in 0..num { 4 | println!("Ring! Call number {}", i + 1); 5 | } 6 | } 7 | 8 | fn main() { 9 | call_me(3); 10 | } 11 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/10_modules/README.md: -------------------------------------------------------------------------------- 1 | # Modules 2 | 3 | In this section we'll give you an introduction to Rust's module system. 4 | 5 | ## Further information 6 | 7 | - [The Module System](https://doc.rust-lang.org/book/ch07-00-managing-growing-projects-with-packages-crates-and-modules.html) 8 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/goProject/calc/calc.go: -------------------------------------------------------------------------------- 1 | package calc 2 | 3 | // 自定义包,最好和文件夹统一起来 4 | 5 | // 公有变量 6 | var age = 10 7 | 8 | // 私有变量 9 | var Name = "张三" 10 | 11 | // 首字母大写,表示共有方法 12 | func Add(x, y int) int { 13 | return x + y 14 | } 15 | func Sub(x, y int) int { 16 | return x - y 17 | } 18 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/03_if/README.md: -------------------------------------------------------------------------------- 1 | # If 2 | 3 | `if`, the most basic (but still surprisingly versatile!) type of control flow, is what you'll learn here. 4 | 5 | ## Further information 6 | 7 | - [Control Flow - if expressions](https://doc.rust-lang.org/book/ch03-05-control-flow.html#if-expressions) 8 | -------------------------------------------------------------------------------- /Golang/Code/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/.idea/sqldialects.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/goProject/go.mod: -------------------------------------------------------------------------------- 1 | module goProject 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/shopspring/decimal v1.3.1 // indirect 7 | github.com/tidwall/gjson v1.14.1 // indirect 8 | github.com/tidwall/match v1.1.1 // indirect 9 | github.com/tidwall/pretty v1.2.0 // indirect 10 | ) 11 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/delete_gorm.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func TestDelete() { 6 | var users []TestUser 7 | 8 | //GLOBAL_DB.Unscoped().Where("name = ?", "ST_new").Delete(&users) 9 | 10 | GLOBAL_DB.Unscoped().Where("age = 0").Find(&users) 11 | 12 | fmt.Println(users) 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/增删改查/delete_gorm.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func TestDelete() { 6 | var users []TestUser 7 | 8 | //GLOBAL_DB.Unscoped().Where("name = ?", "ST_new").Delete(&users) 9 | 10 | GLOBAL_DB.Unscoped().Where("age = 0").Find(&users) 11 | 12 | fmt.Println(users) 13 | } 14 | -------------------------------------------------------------------------------- /Golang/Code/Gin/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/EmptyInterface/EmptyA.go: -------------------------------------------------------------------------------- 1 | package EmptyInterface 2 | 3 | import "fmt" 4 | 5 | // 空接口表示没有任何约束,任意的类型都可以实现空接口 6 | type EmptyA interface { 7 | 8 | } 9 | 10 | func main() { 11 | var a EmptyA 12 | var str = "你好golang" 13 | // 让字符串实现A接口 14 | a = str 15 | fmt.Println(a) 16 | } -------------------------------------------------------------------------------- /Golang/Code/gRPC/HelloWorld/.idea/go.imports.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basicGateway/.idea/go.imports.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 9 | 10 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/02_functions/README.md: -------------------------------------------------------------------------------- 1 | # Functions 2 | 3 | Here, you'll learn how to write functions and how the Rust compiler can help you debug errors even 4 | in more complex code. 5 | 6 | ## Further information 7 | 8 | - [How Functions Work](https://doc.rust-lang.org/book/ch03-03-how-functions-work.html) 9 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/HelloWorld/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/HelloWorld/pb/hello_grpc.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option go_package = "./;hello_grpc"; 4 | 5 | package hello_grpc; 6 | 7 | message Req { 8 | string message = 1; 9 | } 10 | 11 | message Res { 12 | string message = 1; 13 | } 14 | 15 | service HelloGRPC{ 16 | rpc SayHis(Req) returns (Res); 17 | } -------------------------------------------------------------------------------- /Golang/Code/gRPC/basicGateway/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/00_intro/README.md: -------------------------------------------------------------------------------- 1 | # Intro 2 | 3 | Rust uses the `print!` and `println!` macros to print text to the console. 4 | 5 | ## Further information 6 | 7 | - [Hello World](https://doc.rust-lang.org/rust-by-example/hello.html) 8 | - [Formatted print](https://doc.rust-lang.org/rust-by-example/hello/print.html) 9 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/go.mod: -------------------------------------------------------------------------------- 1 | module GORM-v2 2 | 3 | go 1.18 4 | 5 | require ( 6 | gorm.io/driver/mysql v1.4.1 7 | gorm.io/gorm v1.24.0 8 | ) 9 | 10 | require ( 11 | github.com/go-sql-driver/mysql v1.6.0 // indirect 12 | github.com/jinzhu/inflection v1.0.0 // indirect 13 | github.com/jinzhu/now v1.1.5 // indirect 14 | ) 15 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/interfaceDemo/Computer.go: -------------------------------------------------------------------------------- 1 | package interfaceDemo 2 | 3 | // 电脑 4 | type Computer struct { 5 | 6 | } 7 | 8 | // 接收一个实现了Usber接口的 结构体 9 | func (computer Computer) Startup(usb Usber) { 10 | usb.start() 11 | } 12 | 13 | // 关闭 14 | func (computer Computer) Shutdown (usb Usber) { 15 | usb.stop() 16 | } -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/09_strings/strings1.rs: -------------------------------------------------------------------------------- 1 | // TODO: Fix the compiler error without changing the function signature. 2 | fn current_favorite_color() -> String { 3 | "blue".to_string() 4 | } 5 | 6 | fn main() { 7 | let answer = current_favorite_color(); 8 | println!("My current favorite color is {answer}"); 9 | } 10 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/07_structs/README.md: -------------------------------------------------------------------------------- 1 | # Structs 2 | 3 | Rust has three struct types: a classic C struct, a tuple struct, and a unit struct. 4 | 5 | ## Further information 6 | 7 | - [Structures](https://doc.rust-lang.org/book/ch05-01-defining-structs.html) 8 | - [Method Syntax](https://doc.rust-lang.org/book/ch05-03-method-syntax.html) 9 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/.idea/goStudy.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/.idea/goProject.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/12_TypeDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | type myInt int 6 | func fun(x int, y int)int { 7 | return x + y 8 | } 9 | func (m myInt) PrintInfo() { 10 | fmt.Println("我是自定义类型里面的自定义方法") 11 | } 12 | func main() { 13 | var a myInt = 10 14 | fmt.Printf("%v %T \n", a, a) 15 | a.PrintInfo() 16 | } 17 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/01_variables/variables5.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let number = "T-H-R-E-E"; // Don't change this line 3 | println!("Spell a number: {}", number); 4 | 5 | // TODO: Fix the compiler error by changing the line below without renaming the variable. 6 | let number = 3; 7 | println!("Number plus two is: {}", number + 2); 8 | } 9 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/04_primitive_types/primitive_types5.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | let cat = ("Furry McFurson", 3.5); 3 | 4 | // TODO: Destructure the `cat` tuple in one statement so that the println works. 5 | // let /* your pattern here */ = cat; 6 | 7 | let (name, age) = cat; 8 | 9 | println!("{name} is {age} years old"); 10 | } 11 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/21_macros/macros3.rs: -------------------------------------------------------------------------------- 1 | // TODO: Fix the compiler error without taking the macro definition out of this 2 | // module. 3 | #[macro_use] 4 | mod macros { 5 | macro_rules! my_macro { 6 | () => { 7 | println!("Check out my macro!"); 8 | }; 9 | } 10 | } 11 | 12 | fn main() { 13 | my_macro!(); 14 | } 15 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/modules.txt: -------------------------------------------------------------------------------- 1 | # github.com/shopspring/decimal v1.2.0 2 | ## explicit 3 | github.com/shopspring/decimal 4 | # github.com/tidwall/gjson v1.6.0 5 | ## explicit 6 | github.com/tidwall/gjson 7 | # github.com/tidwall/match v1.0.1 8 | github.com/tidwall/match 9 | # github.com/tidwall/pretty v1.0.0 10 | github.com/tidwall/pretty 11 | -------------------------------------------------------------------------------- /Golang/Code/.idea/Code.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Golang/Code/Gin/.idea/Gin.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/create_gorm.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func CreatedTest() { 6 | dbres := GLOBAL_DB.Create(&[]TestUser{ 7 | {Name: "", Age: 18}, 8 | {Age: 19}, 9 | }) 10 | fmt.Println(dbres.Error, dbres.RowsAffected) 11 | 12 | if dbres.Error != nil { 13 | fmt.Println("创建失败") 14 | } else { 15 | fmt.Println("创建成功") 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/增删改查/create_gorm.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func CreatedTest() { 6 | dbres := GLOBAL_DB.Create(&[]TestUser{ 7 | {Name: "", Age: 18}, 8 | {Age: 19}, 9 | }) 10 | fmt.Println(dbres.Error, dbres.RowsAffected) 11 | 12 | if dbres.Error != nil { 13 | fmt.Println("创建失败") 14 | } else { 15 | fmt.Println("创建成功") 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/17_fileCopyDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | ) 7 | 8 | func main() { 9 | // 读取文件 10 | byteStr, err := ioutil.ReadFile("./main/test.txt") 11 | if err != nil { 12 | fmt.Println("读取文件出错") 13 | return 14 | } 15 | // 写入指定的文件 16 | ioutil.WriteFile("./main/test2.txt", byteStr, 777) 17 | } 18 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/HelloWorld/.idea/gRPC.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basicGateway/.idea/gRPC.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/.idea/GORM-v2.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/calc/calc.go: -------------------------------------------------------------------------------- 1 | package calc 2 | 3 | import "fmt" 4 | 5 | // 自定义包,最好和文件夹统一起来 6 | 7 | // 公有变量 8 | var age = 10 9 | // 私有变量 10 | var Name = "张三" 11 | 12 | // init方法 13 | func init() { 14 | fmt.Println("init") 15 | } 16 | // 首字母大写,表示共有方法 17 | func Add(x, y int)int { 18 | return x + y 19 | } 20 | func Sub(x, y int)int { 21 | return x - y 22 | } 23 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/09_strings/README.md: -------------------------------------------------------------------------------- 1 | # Strings 2 | 3 | Rust has two string types, a string slice (`&str`) and an owned string (`String`). 4 | We're not going to dictate when you should use which one, but we'll show you how 5 | to identify and create them, as well as use them. 6 | 7 | ## Further information 8 | 9 | - [Strings](https://doc.rust-lang.org/book/ch08-02-strings.html) 10 | -------------------------------------------------------------------------------- /Golang/learning_note/Gin框架/个人网页.md: -------------------------------------------------------------------------------- 1 | myspace.go 2 | ```go 3 | package myspace 4 | 5 | import ( 6 | "net/http" 7 | 8 | "github.com/gin-gonic/gin" 9 | ) 10 | 11 | func MySpace(r *gin.Engine) { 12 | r.Static("/static", "./myspace/static") 13 | r.LoadHTMLFiles("myspace/view/index.html") 14 | r.GET("/myspace/", func(c *gin.Context) { 15 | c.HTML(http.StatusOK, "index.html", nil) 16 | }) 17 | } 18 | ``` -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/tidwall/gjson/go.sum: -------------------------------------------------------------------------------- 1 | github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= 2 | github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= 3 | github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= 4 | github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= 5 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/04_primitive_types/README.md: -------------------------------------------------------------------------------- 1 | # Primitive Types 2 | 3 | Rust has a couple of basic types that are directly implemented into the 4 | compiler. In this section, we'll go through the most important ones. 5 | 6 | ## Further information 7 | 8 | - [Data Types](https://doc.rust-lang.org/book/ch03-02-data-types.html) 9 | - [The Slice Type](https://doc.rust-lang.org/book/ch04-03-slices.html) 10 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/21_macros/macros4.rs: -------------------------------------------------------------------------------- 1 | // TODO: Fix the compiler error by adding one or two characters. 2 | #[rustfmt::skip] 3 | macro_rules! my_macro { 4 | () => { 5 | println!("Check out my macro!"); 6 | }; 7 | ($val:expr) => { 8 | println!("Look at this other macro: {}", $val); 9 | } 10 | } 11 | 12 | fn main() { 13 | my_macro!(); 14 | my_macro!(7777); 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Code/Gin/Params/templates/posts/index.html: -------------------------------------------------------------------------------- 1 | {{define "posts/index.html"}} 2 | 3 | 4 | 5 | 6 | 7 | 8 | posts/index 9 | 10 | 11 | {{.title}} 12 | 13 | 14 | {{end}} -------------------------------------------------------------------------------- /Golang/Code/Gin/Params/templates/users/index.html: -------------------------------------------------------------------------------- 1 | {{define "users/index.html"}} 2 | 3 | 4 | 5 | 6 | 7 | 8 | users/index 9 | 10 | 11 | {{.title}} 12 | 13 | 14 | {{end}} -------------------------------------------------------------------------------- /Rust/rustlings/exercises/01_variables/README.md: -------------------------------------------------------------------------------- 1 | # Variables 2 | 3 | In Rust, variables are immutable by default. 4 | When a variable is immutable, once a value is bound to a name, you can’t change that value. 5 | You can make them mutable by adding `mut` in front of the variable name. 6 | 7 | ## Further information 8 | 9 | - [Variables and Mutability](https://doc.rust-lang.org/book/ch03-01-variables-and-mutability.html) 10 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/流式返回/go.mod: -------------------------------------------------------------------------------- 1 | module grpc 2 | 3 | go 1.18 4 | 5 | require ( 6 | golang.org/x/net v0.9.0 7 | google.golang.org/grpc v1.56.3 8 | google.golang.org/protobuf v1.30.0 9 | ) 10 | 11 | require ( 12 | github.com/golang/protobuf v1.5.3 // indirect 13 | golang.org/x/sys v0.7.0 // indirect 14 | golang.org/x/text v0.9.0 // indirect 15 | google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/16_lifetimes/lifetimes3.rs: -------------------------------------------------------------------------------- 1 | // Lifetimes are also needed when structs hold references. 2 | 3 | // TODO: Fix the compiler errors about the struct. 4 | struct Book<'a> { 5 | author: &'a str, 6 | title: &'a str, 7 | } 8 | 9 | fn main() { 10 | let book = Book { 11 | author: "George Orwell", 12 | title: "1984", 13 | }; 14 | 15 | println!("{} by {}", book.title, book.author); 16 | } 17 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/11_pointerDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var a = 10 7 | fmt.Printf("a的值: %v,a的类型: %T,a的地址: %p \n", a, a, &a) 8 | 9 | var b = 10 10 | // p的值就是b的地址 11 | var p = &b 12 | fmt.Println(b, " ", p) 13 | 14 | // 指针取值 15 | var c = 20 16 | var d = &c 17 | fmt.Println(*d) 18 | // c对应地址的值,改成30 19 | *d = 30 20 | // c已经变成30了 21 | fmt.Println(c) 22 | 23 | 24 | } 25 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/model.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "gorm.io/gorm" 5 | "time" 6 | ) 7 | 8 | type Model struct { 9 | UUID uint `gorm:"primaryKey"` // 主键 10 | Time time.Time `gorm:"column:my_time"` 11 | } 12 | 13 | type TestUser struct { 14 | gorm.Model 15 | Name string `gorm:"default:Nobody"` 16 | Age uint8 `gorm:"comment:年龄"` 17 | } 18 | 19 | func TestUserCreate() { 20 | GLOBAL_DB.AutoMigrate(&TestUser{}) 21 | } 22 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/增删改查/model.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "gorm.io/gorm" 5 | "time" 6 | ) 7 | 8 | type Model struct { 9 | UUID uint `gorm:"primaryKey"` // 主键 10 | Time time.Time `gorm:"column:my_time"` 11 | } 12 | 13 | type TestUser struct { 14 | gorm.Model 15 | Name string `gorm:"default:Nobody"` 16 | Age uint8 `gorm:"comment:年龄"` 17 | } 18 | 19 | func TestUserCreate() { 20 | GLOBAL_DB.AutoMigrate(&TestUser{}) 21 | } 22 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/04_primitive_types/primitive_types3.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // TODO: Create an array called `a` with at least 100 elements in it. 3 | // let a = ??? 4 | let a = [0; 1000]; 5 | 6 | if a.len() >= 100 { 7 | println!("Wow, that's a big array!"); 8 | } else { 9 | println!("Meh, I eat arrays like that for breakfast."); 10 | panic!("Array not big enough, more elements needed"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /Golang/learning_note/基础语法/运算符.md: -------------------------------------------------------------------------------- 1 | # Go的运算符 2 | 3 | ## 算数运算符 4 | 5 | - +:相加 6 | - -:相减 7 | - *:相乘 8 | - /:相除 9 | - %:求余 10 | 11 | 在golang中, ++ 和 -- 只能单独使用,错误的写法如下 12 | 13 | ```go 14 | var i int = 8 15 | var a int 16 | a = i++ // 错误,i++只能单独使用 17 | a = i-- // 错误,i--只能单独使用 18 | ``` 19 | 20 | 同时在golang中,没有 ++i这样的操作 21 | 22 | ```go 23 | var i int = 1 24 | ++i // 错误 25 | ``` 26 | 27 | 正确的写法 28 | 29 | ```go 30 | var i int = 1 31 | i++ //正确 32 | ``` 33 | 34 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/22_clippy/README.md: -------------------------------------------------------------------------------- 1 | # Clippy 2 | 3 | The Clippy tool is a collection of lints to analyze your code so you can catch common mistakes and improve your Rust code. 4 | 5 | If you used the installation script for Rustlings, Clippy should be already installed. 6 | If not you can install it manually via `rustup component add clippy`. 7 | 8 | ## Further information 9 | 10 | - [GitHub Repository](https://github.com/rust-lang/rust-clippy). 11 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/关系/preload_gorm.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "gorm.io/gorm" 6 | ) 7 | 8 | // has one 9 | 10 | type Dog struct { 11 | gorm.Model 12 | Name string 13 | GoddessID uint // 狗链子 14 | } 15 | 16 | type Goddess struct { 17 | gorm.Model 18 | Name string 19 | Dog Dog 20 | } 21 | 22 | func Preload() { 23 | 24 | var girl Goddess 25 | 26 | GLOBAL_DB.Preload("Dog").First(&girl, 2) 27 | fmt.Println(girl) 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/04_primitive_types/primitive_types4.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // You can optionally experiment here. 3 | } 4 | 5 | #[cfg(test)] 6 | mod tests { 7 | #[test] 8 | fn slice_out_of_array() { 9 | let a = [1, 2, 3, 4, 5]; 10 | 11 | // TODO: Get a slice called `nice_slice` out of the array `a` so that the test passes. 12 | let nice_slice = &a[1..=3]; 13 | 14 | assert_eq!([2, 3, 4], nice_slice); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/08_enums/enums1.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug)] 2 | enum Message { 3 | // TODO: Define a few types of messages as used below. 4 | Resize, 5 | Move, 6 | Echo, 7 | ChangeColor, 8 | Quit, 9 | } 10 | 11 | fn main() { 12 | println!("{:?}", Message::Resize); 13 | println!("{:?}", Message::Move); 14 | println!("{:?}", Message::Echo); 15 | println!("{:?}", Message::ChangeColor); 16 | println!("{:?}", Message::Quit); 17 | } 18 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/10_modules/modules1.rs: -------------------------------------------------------------------------------- 1 | // TODO: Fix the compiler error about calling a private function. 2 | mod sausage_factory { 3 | // Don't let anybody outside of this module see this! 4 | fn get_secret_recipe() -> String { 5 | String::from("Ginger") 6 | } 7 | 8 | pub fn make_sausage() { 9 | get_secret_recipe(); 10 | println!("sausage!"); 11 | } 12 | } 13 | 14 | fn main() { 15 | sausage_factory::make_sausage(); 16 | } 17 | -------------------------------------------------------------------------------- /数据库/MySQL/基础/导入现有的数据表、表的数据.md: -------------------------------------------------------------------------------- 1 | # 导入现有的数据表、表的数据 2 | 3 | ## 方式1 4 | 5 | source 文件的全路径名 6 | ```sql 7 | source d:\atguigudb.sql; 8 | ``` 9 | ## 方式2: 10 | 基于具体的图形化界面的工具可以导入数据 11 | 比如:SQLyog中 选择 “工具” -- “执行sql脚本” -- 选中xxx.sql即可。 12 | 13 | ## 导入表的问题 14 | 15 | **导入数据时外键约束问题** 16 | 17 | 数据导入指令: 18 | 19 | ```sql 20 | source d:\xxx.sql 21 | ``` 22 | 23 | 通过FOREIGN_KEY_CHECKS解决,用法如下: 24 | 25 | ```sql 26 | set FOREIGN_KEY_CHECKS=0; #在导入前设置为不检查外键约束 27 | set FOREIGN_KEY_CHECKS=1; #在导入后恢复检查外键约束 28 | ``` -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/go.mod: -------------------------------------------------------------------------------- 1 | module grpc 2 | 3 | go 1.18 4 | 5 | require ( 6 | google.golang.org/grpc v1.50.1 7 | google.golang.org/protobuf v1.28.1 8 | ) 9 | 10 | require ( 11 | github.com/golang/protobuf v1.5.2 // indirect 12 | golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect 13 | golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect 14 | golang.org/x/text v0.3.3 // indirect 15 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/HelloWorld/go.mod: -------------------------------------------------------------------------------- 1 | module gRPC 2 | 3 | go 1.18 4 | 5 | require ( 6 | google.golang.org/grpc v1.50.0 7 | google.golang.org/protobuf v1.27.1 8 | ) 9 | 10 | require ( 11 | github.com/golang/protobuf v1.5.2 // indirect 12 | golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect 13 | golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect 14 | golang.org/x/text v0.3.3 // indirect 15 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/15_ChannelDemo2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | 7 | // 创建管道 8 | ch := make(chan int, 10) 9 | // 循环写入值 10 | for i := 0; i < 10; i++ { 11 | ch <- i 12 | } 13 | // 关闭管道 14 | close(ch) 15 | 16 | // for range循环遍历管道的值(管道没有key) 17 | for value := range ch { 18 | fmt.Println(value) 19 | } 20 | // 通过上述的操作,能够打印值,但是出出现一个deadlock的死锁错误,也就说我们需要关闭管道 21 | 22 | for i := 0; i < 10; i++ { 23 | fmt.Println(<- ch) 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/普通服务/go.mod: -------------------------------------------------------------------------------- 1 | module grpc 2 | 3 | go 1.18 4 | 5 | require ( 6 | google.golang.org/grpc v1.50.1 7 | google.golang.org/protobuf v1.28.1 8 | ) 9 | 10 | require ( 11 | github.com/golang/protobuf v1.5.2 // indirect 12 | golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect 13 | golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect 14 | golang.org/x/text v0.3.3 // indirect 15 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/流式传入/go.mod: -------------------------------------------------------------------------------- 1 | module grpc 2 | 3 | go 1.18 4 | 5 | require ( 6 | google.golang.org/grpc v1.50.1 7 | google.golang.org/protobuf v1.28.1 8 | ) 9 | 10 | require ( 11 | github.com/golang/protobuf v1.5.2 // indirect 12 | golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect 13 | golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect 14 | golang.org/x/text v0.3.3 // indirect 15 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/流式出入/go.mod: -------------------------------------------------------------------------------- 1 | module grpc 2 | 3 | go 1.18 4 | 5 | require ( 6 | google.golang.org/grpc v1.50.1 7 | google.golang.org/protobuf v1.28.1 8 | ) 9 | 10 | require ( 11 | github.com/golang/protobuf v1.5.2 // indirect 12 | golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect 13 | golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect 14 | golang.org/x/text v0.3.3 // indirect 15 | google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 // indirect 16 | ) 17 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/interfaceDemo/Phone.go: -------------------------------------------------------------------------------- 1 | package interfaceDemo 2 | 3 | import "fmt" 4 | 5 | // 如果接口里面有方法的话,必须要通过结构体或自定义类型实现这个接口 6 | 7 | // 使用结构体来实现 接口 8 | type Phone struct { 9 | Name string 10 | } 11 | // 手机要实现Usber接口的话,必须实现usb接口的所有方法 12 | func (p Phone) start() { 13 | fmt.Println(p.Name, "启动") 14 | } 15 | func (p Phone) stop() { 16 | fmt.Println(p.Name, "关闭") 17 | } 18 | func main() { 19 | var phone Usber = Phone{ 20 | "三星手机", 21 | } 22 | phone.start() 23 | phone.stop() 24 | } 25 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/mutex.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | "time" 7 | ) 8 | 9 | var count = 0 10 | var wg sync.WaitGroup 11 | var mutex sync.Mutex 12 | 13 | func test() { 14 | // 加锁 15 | mutex.Lock() 16 | count++ 17 | fmt.Println("the count is : ", count) 18 | time.Sleep(time.Millisecond) 19 | wg.Done() 20 | // 解锁 21 | mutex.Unlock() 22 | } 23 | func main() { 24 | for i := 0; i < 20; i++ { 25 | wg.Add(1) 26 | go test() 27 | } 28 | time.Sleep(time.Second * 10) 29 | } 30 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/12_options/options3.rs: -------------------------------------------------------------------------------- 1 | #[derive(Debug)] 2 | struct Point { 3 | x: i32, 4 | y: i32, 5 | } 6 | 7 | fn main() { 8 | let optional_point = Some(Point { x: 100, y: 200 }); 9 | 10 | // TODO: Fix the compiler error by adding something to this match statement. 11 | match &optional_point { 12 | Some(p) => println!("Co-ordinates are {},{}", p.x, p.y), 13 | _ => panic!("No match!"), 14 | } 15 | 16 | println!("{optional_point:?}"); // Don't change this line. 17 | } 18 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/04_primitive_types/primitive_types1.rs: -------------------------------------------------------------------------------- 1 | // Booleans (`bool`) 2 | 3 | fn main() { 4 | let is_morning = true; 5 | if is_morning { 6 | println!("Good morning!"); 7 | } 8 | let is_evening = false; 9 | // TODO: Define a boolean variable with the name `is_evening` before the `if` statement below. 10 | // The value of the variable should be the negation (opposite) of `is_morning`. 11 | // let … 12 | if is_evening { 13 | println!("Good evening!"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/06_move_semantics/README.md: -------------------------------------------------------------------------------- 1 | # Move Semantics 2 | 3 | These exercises are adapted from [pnkfelix](https://github.com/pnkfelix)'s [Rust Tutorial](https://pnkfelix.github.io/rust-examples-icfp2014/) -- Thank you Felix!!! 4 | 5 | ## Further information 6 | 7 | For this section, the book links are especially important. 8 | 9 | - [Ownership](https://doc.rust-lang.org/book/ch04-01-what-is-ownership.html) 10 | - [Reference and borrowing](https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html) 11 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/interfaceDemo/Camera.go: -------------------------------------------------------------------------------- 1 | package interfaceDemo 2 | 3 | import "fmt" 4 | 5 | // 如果接口里面有方法的话,必须要通过结构体或自定义类型实现这个接口 6 | 7 | // 使用相机结构体来实现 接口 8 | type Camera struct { 9 | Name string 10 | } 11 | // 相机要实现Usber接口的话,必须实现usb接口的所有方法 12 | func (p Camera) start() { 13 | fmt.Println(p.Name, "启动") 14 | } 15 | func (p Camera) stop() { 16 | fmt.Println(p.Name, "关闭") 17 | } 18 | func (p Camera)Start() { 19 | var camera Usber = Camera{ 20 | "佳能", 21 | } 22 | camera.start() 23 | camera.stop() 24 | } 25 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/04_primitive_types/primitive_types6.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // You can optionally experiment here. 3 | } 4 | 5 | #[cfg(test)] 6 | mod tests { 7 | #[test] 8 | fn indexing_tuple() { 9 | let numbers = (1, 2, 3); 10 | 11 | // TODO: Use a tuple index to access the second element of `numbers` 12 | // and assign it to a variable called `second`. 13 | let second = numbers.1; 14 | 15 | assert_eq!(second, 2, "This is not the 2nd number in the tuple!"); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/09_strings/strings2.rs: -------------------------------------------------------------------------------- 1 | // TODO: Fix the compiler error in the `main` function without changing this function. 2 | fn is_a_color_word(attempt: &str) -> bool { 3 | attempt == "green" || attempt == "blue" || attempt == "red" 4 | } 5 | 6 | fn main() { 7 | let word = String::from("green"); // Don't change this line. 8 | 9 | if is_a_color_word(&word) { 10 | println!("That is a color word I know!"); 11 | } else { 12 | println!("That is not a color word I know."); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/15_lockDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | "time" 7 | ) 8 | 9 | var count = 0 10 | var wg sync.WaitGroup 11 | var mutex sync.Mutex 12 | 13 | func test() { 14 | // 加锁 15 | mutex.Lock() 16 | count++ 17 | fmt.Println("the count is : ", count) 18 | time.Sleep(time.Millisecond) 19 | wg.Done() 20 | // 解锁 21 | mutex.Unlock() 22 | } 23 | func main() { 24 | for i := 0; i < 20; i++ { 25 | wg.Add(1) 26 | go test() 27 | } 28 | time.Sleep(time.Second * 10) 29 | } 30 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/9_FileDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "errors" 5 | "fmt" 6 | ) 7 | 8 | func readFile(fileName string) error { 9 | if fileName == "main.go" { 10 | return nil 11 | } else { 12 | return errors.New("读取文件失败") 13 | } 14 | } 15 | 16 | func myFn () { 17 | defer func() { 18 | e := recover() 19 | if e != nil { 20 | fmt.Println("给管理员发送邮件") 21 | } 22 | }() 23 | err := readFile("XXX.go") 24 | if err != nil { 25 | panic(err) 26 | } 27 | } 28 | 29 | func main() { 30 | myFn() 31 | } -------------------------------------------------------------------------------- /Rust/rustlings/exercises/06_move_semantics/move_semantics4.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // You can optionally experiment here. 3 | } 4 | 5 | #[cfg(test)] 6 | mod tests { 7 | // TODO: Fix the compiler errors only by reordering the lines in the test. 8 | // Don't add, change or remove any line. 9 | #[test] 10 | fn move_semantics4() { 11 | let mut x = Vec::new(); 12 | let y = &mut x; 13 | y.push(42); 14 | let z = &mut x; 15 | z.push(13); 16 | assert_eq!(x, [42, 13]); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Golang/Code/standard library/log/main1.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "log" 6 | "os" 7 | ) 8 | 9 | func main1() { 10 | 11 | fileObj, err := os.OpenFile("./xx.log", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) 12 | if err != nil { 13 | fmt.Printf("open file failed, err : %v \n", err) 14 | return 15 | } 16 | // 设置log的输出路径 17 | log.SetOutput(fileObj) 18 | 19 | log.Println("这是一条很普通的日志。") 20 | v := "很普通的" 21 | log.Printf("这是一条%s日志。\n", v) 22 | log.Fatalln("这是一条会触发fatal的日志。") 23 | log.Panicln("这是一条会触发panic的日志。") 24 | } 25 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/关系/has_one_gorm.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "gorm.io/gorm" 5 | ) 6 | 7 | // has one 8 | 9 | type Dog2 struct { 10 | gorm.Model 11 | Name string 12 | Goddess2ID uint // 狗链子 13 | } 14 | 15 | type Goddess2 struct { 16 | gorm.Model 17 | Name string 18 | Dog Dog2 19 | } 20 | 21 | func HasOne() { 22 | d := Dog2{ 23 | Name: "dog2", 24 | } 25 | 26 | g := Goddess2{ 27 | Name: "G2", 28 | Dog: d, 29 | } 30 | 31 | _ = GLOBAL_DB.AutoMigrate(&Dog2{}, &Goddess2{}) 32 | 33 | GLOBAL_DB.Create(&g) 34 | 35 | } 36 | -------------------------------------------------------------------------------- /Golang/Code/Gin/fileUpload/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 上传文件示例 5 | 6 | 7 |
8 | 9 | 10 |
11 | 12 |
13 | 14 | 15 |
16 | 17 | 18 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/12_StructDemo5.go: -------------------------------------------------------------------------------- 1 | package main 2 | import "fmt" 3 | 4 | // 结构体的继承 5 | // 用户结构体 6 | type Animal struct { 7 | name string 8 | } 9 | func (a Animal) run() { 10 | fmt.Printf("%v 在运动 \n", a.name) 11 | } 12 | // 子结构体 13 | type Dog struct { 14 | age int 15 | // 通过结构体嵌套,完成继承 16 | Animal 17 | } 18 | func (dog Dog) wang() { 19 | fmt.Printf("%v 在汪汪汪 \n", dog.name) 20 | } 21 | 22 | func main() { 23 | var dog = Dog{ 24 | age: 10, 25 | Animal: Animal{ 26 | name: "阿帕奇", 27 | }, 28 | } 29 | dog.run(); 30 | dog.wang(); 31 | } 32 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/06_move_semantics/move_semantics3.rs: -------------------------------------------------------------------------------- 1 | // TODO: Fix the compiler error in the function without adding any new line. 2 | fn fill_vec(mut vec: Vec) -> Vec { 3 | vec.push(88); 4 | 5 | vec 6 | } 7 | 8 | fn main() { 9 | // You can optionally experiment here. 10 | } 11 | 12 | #[cfg(test)] 13 | mod tests { 14 | use super::*; 15 | 16 | #[test] 17 | fn move_semantics3() { 18 | let vec0 = vec![22, 44, 66]; 19 | let vec1 = fill_vec(vec0); 20 | assert_eq!(vec1, [22, 44, 66, 88]); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basicGateway/pb/person/person.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; // 告诉编译器用`proto3`来解读 2 | 3 | package person; 4 | 5 | option go_package = "grpc/pb/person;person"; 6 | 7 | import "google/api/annotations.proto"; 8 | 9 | message PersonReq{ 10 | string name = 1; 11 | int32 age = 2; 12 | 13 | } 14 | message PersonRes{ 15 | string name = 1; 16 | int32 age = 2; 17 | 18 | } 19 | 20 | service SearchService { 21 | rpc Search(PersonReq) returns (PersonRes){ 22 | option (google.api.http)={ 23 | post:"/api/person" 24 | body:"*" 25 | }; 26 | }; 27 | } -------------------------------------------------------------------------------- /Rust/rustlings/exercises/06_move_semantics/move_semantics1.rs: -------------------------------------------------------------------------------- 1 | // TODO: Fix the compiler error in this function. 2 | fn fill_vec(vec: Vec) -> Vec { 3 | let mut vec = vec; 4 | 5 | vec.push(88); 6 | 7 | vec 8 | } 9 | 10 | fn main() { 11 | // You can optionally experiment here. 12 | } 13 | 14 | #[cfg(test)] 15 | mod tests { 16 | use super::*; 17 | 18 | #[test] 19 | fn move_semantics1() { 20 | let vec0 = vec![22, 44, 66]; 21 | let vec1 = fill_vec(vec0); 22 | assert_eq!(vec1, vec![22, 44, 66, 88]); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/16_lifetimes/lifetimes2.rs: -------------------------------------------------------------------------------- 1 | // Don't change this function. 2 | fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { 3 | if x.len() > y.len() { 4 | x 5 | } else { 6 | y 7 | } 8 | } 9 | 10 | fn main() { 11 | // TODO: Fix the compiler error by moving one line. 12 | 13 | let string1 = String::from("long string is long"); 14 | let result; 15 | { 16 | let string2 = String::from("xyz"); 17 | result = longest(&string1, &string2); 18 | println!("The longest string is '{result}'"); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Golang/Code/advanceCode/goroutine/basic/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | var wg sync.WaitGroup 9 | 10 | func hello(i int) { 11 | // fmt.Println("Hello Goroutine!") 12 | defer wg.Done() // goroutine结束就登记-1 13 | fmt.Println("Hello Goroutine!", i) 14 | } 15 | func main() { 16 | 17 | // go hello() // 启动另外一个goroutine去执行hello函数 18 | // fmt.Println("main goroutine done!") 19 | // time.Sleep(time.Second) 20 | for i := 0; i < 10; i++ { 21 | wg.Add(1) // 启动一个goroutine就登记+1 22 | go hello(i) 23 | } 24 | wg.Wait() // 等待所有登记的goroutine都结束 25 | } 26 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/.idea/dataSources.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | mysql.8 6 | true 7 | com.mysql.cj.jdbc.Driver 8 | jdbc:mysql://localhost:3306/db1 9 | $ProjectFileDir$ 10 | 11 | 12 | -------------------------------------------------------------------------------- /Algorithm/小技巧.md: -------------------------------------------------------------------------------- 1 | ## 枚举矩阵 2 | 3 | 使用偏移量进行枚举 4 | ||(-1, 0)|| 5 | |-|-|-| 6 | |(0, -1)|X|(0, 1)| 7 | ||(1, 0)|| 8 | 9 | ```c++ 10 | int dx[] = {-1, 0, 1, 0}, dy[] = {0, 1, 0, -1}; 11 | 12 | for(int i = 0; i < 4; i ++) 13 | a = x + dx[i], b = y + dy[i]; 14 | ``` 15 | ## 重载小于号 16 | ```cpp 17 | 18 | ``` 19 | 20 | 21 | ## 判断两个单词不含公共字母[leetcode 318 最大单词长度乘积](https://leetcode-cn.com/problems/maximum-product-of-word-lengths/) 22 | 23 | ```c++ 24 | //预处理 25 | for(int i = 0; i < n; i++) 26 | for(auto x : words[i]) 27 | masks[i] |= 1 << x - 'a'; //0 - 25位为1的数即为单词中有该字母 28 | //判断即为 29 | masks[i] & masks[j] == 0; 30 | ``` -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/关系/association_tags.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type Jiazi struct { 4 | ID uint 5 | Name string 6 | Xiaofengche []Xiaofengche `gorm:"many2many:jiazi_fenche;foreignKey:Name;joinForeignKey:jiazi;references:FCName;joinReferences:fengche;"` 7 | } 8 | 9 | type Xiaofengche struct { 10 | ID uint 11 | FCName string 12 | } 13 | 14 | func Tags() { 15 | GLOBAL_DB.AutoMigrate(&Jiazi{}, &Xiaofengche{}) 16 | 17 | GLOBAL_DB.Create(&Jiazi{ 18 | Name: "小夹子", 19 | Xiaofengche: []Xiaofengche{ 20 | {FCName: "大风车"}, 21 | {FCName: "大风车1"}, 22 | {FCName: "大风车2"}, 23 | }, 24 | }) 25 | } 26 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/exec.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | fmt.Println("hello") 7 | fmt.Print("A", "B", "C") 8 | fmt.Println() 9 | var a = 10 10 | fmt.Printf("%d", a) 11 | 12 | var name = "zhangsan1" 13 | var name2 string = "zhangsan2" 14 | name3 := "zhangsan3" 15 | 16 | fmt.Println(name) 17 | fmt.Println(name2) 18 | fmt.Println(name3) 19 | fmt.Printf("name1=%v name2=%v name3=%v", name, name2, name3) 20 | 21 | var a1, a2 string 22 | a1 = "123" 23 | a2 = "123" 24 | fmt.Printf(a1) 25 | fmt.Printf(a2) 26 | 27 | const pi = 3.14 28 | const pp = 3.33333 29 | } 30 | -------------------------------------------------------------------------------- /Linux/常用文件管理命令.md: -------------------------------------------------------------------------------- 1 | `ctrl c:` 取消命令,并且换行 2 | `ctrl u`: 清空本行命令 3 | `tab`键:可以补全命令和文件名,如果补全不了快速按两下tab键,可以显示备选选项 4 | `ls`: 列出当前目录下所有文件,蓝色的是文件夹,白色的是普通文件,绿色的是可执行文件 5 | `pwd`: 显示当前路径 6 | `cd XXX`: 进入XXX目录下, `cd .. `返回上层目录 7 | `cp XXX YYY`: 将XXX文件复制成YYY,XXX和YYY可以是一个路径,比如../dir_c/a.txt,表示上层目录下的dir_c文件夹下的文件a.txt 8 | `mkdir XXX`: 创建目录XXX 9 | `rm XXX`: 删除普通文件; rm XXX -r: 删除文件夹 10 | `mv XXX YYY`: 将XXX文件移动到YYY,和cp命令一样,XXX和YYY可以是一个路径;重命名也是用这个命令 11 | `touch XXX`: 创建一个文件 12 | `cat XXX`: 展示文件XXX中的内容 13 | 复制文本 14 | windows/Linux下:`Ctrl + insert`,Mac下:`command + c` 15 | 粘贴文本 16 | windows/Linux下:`Shift + insert`,Mac下:`command + v` 17 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/22_clippy/clippy1.rs: -------------------------------------------------------------------------------- 1 | // The Clippy tool is a collection of lints to analyze your code so you can 2 | // catch common mistakes and improve your Rust code. 3 | // 4 | // For these exercises, the code will fail to compile when there are Clippy 5 | // warnings. Check Clippy's suggestions from the output to solve the exercise. 6 | 7 | fn main() { 8 | // TODO: Fix the Clippy lint in this line. 9 | let pi = std::f32::consts::PI; 10 | let radius: f32 = 5.0; 11 | 12 | let area = pi * radius.powi(2); 13 | 14 | println!("The area of a circle with radius {radius:.2} is {area:.5}"); 15 | } 16 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/association_tags.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type Jiazi struct { 4 | ID uint 5 | Name string 6 | Xiaofengche []Xiaofengche `gorm:"many2many:jiazi_fenche;foreignKey:Name;joinForeignKey:jiazi;references:FCName;joinReferences:fengche;"` 7 | } 8 | 9 | type Xiaofengche struct { 10 | ID uint 11 | FCName string 12 | } 13 | 14 | func Tags() { 15 | GLOBAL_DB.AutoMigrate(&Jiazi{}, &Xiaofengche{}) 16 | 17 | GLOBAL_DB.Create(&Jiazi{ 18 | Name: "小夹子", 19 | Xiaofengche: []Xiaofengche{ 20 | {FCName: "大风车"}, 21 | {FCName: "大风车1"}, 22 | {FCName: "大风车2"}, 23 | }, 24 | }) 25 | } 26 | -------------------------------------------------------------------------------- /Golang/Code/advanceCode/goroutine/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | "sync" 7 | ) 8 | 9 | func main() { 10 | var smp sync.Map 11 | 12 | smp.Store("k1", "v1") 13 | smp.Store("k2", "v2") 14 | smp.Store("k3", "v3") 15 | 16 | for i := 0; i < 10000; i++ { 17 | smp.Store("k"+strconv.Itoa(i), "v"+strconv.Itoa(i)) 18 | } 19 | 20 | smp.Delete("k3") 21 | 22 | v, ok := smp.Load("k1") 23 | if !ok { 24 | fmt.Println("key not found") 25 | } 26 | 27 | fmt.Println(v.(string)) 28 | 29 | smp.Range(func(k, v any) bool { 30 | fmt.Println(v.(string)) 31 | return true 32 | }) 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/15_goroutineDemo2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "runtime" 6 | "sync" 7 | ) 8 | 9 | func test(num int) { 10 | for i := 0; i < 10; i++ { 11 | fmt.Printf("协程(%v)打印的第%v条数据 \n", num, i) 12 | } 13 | // 协程计数器减1 14 | vg.Done() 15 | } 16 | 17 | var vg sync.WaitGroup 18 | 19 | func main() { 20 | // 获取cpu个数 21 | npmCpu := runtime.NumCPU() 22 | fmt.Println("cup的个数:", npmCpu) 23 | // 设置允许使用的CPU数量 24 | runtime.GOMAXPROCS(runtime.NumCPU() - 1) 25 | 26 | for i := 0; i < 10; i++ { 27 | go test(i) 28 | vg.Add(1) 29 | } 30 | vg.Wait() 31 | fmt.Println("主线程退出") 32 | } 33 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/17_fileDemo3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "io/ioutil" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | // 打开文件 11 | file, _ := os.OpenFile("./main/test.txt", os.O_CREATE | os.O_RDWR | os.O_APPEND, 777) 12 | defer file.Close() 13 | str := "啦啦啦 \r\n" 14 | file.WriteString(str) 15 | 16 | // 通过bufio写入 17 | writer := bufio.NewWriter(file) 18 | // 先将数据写入缓存 19 | writer.WriteString("你好,我是通过writer写入的 \r\n") 20 | // 将缓存中的内容写入文件 21 | writer.Flush() 22 | 23 | // 第三种方式,通过ioutil 24 | str2 := "hello" 25 | ioutil.WriteFile("./main/test.txt", []byte(str2), 777) 26 | 27 | } 28 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/05_vecs/vecs1.rs: -------------------------------------------------------------------------------- 1 | fn array_and_vec() -> ([i32; 4], Vec) { 2 | let a = [10, 20, 30, 40]; // Array 3 | 4 | // TODO: Create a vector called `v` which contains the exact same elements as in the array `a`. 5 | // Use the vector macro. 6 | let v = vec![10, 20, 30, 40]; 7 | 8 | (a, v) 9 | } 10 | 11 | fn main() { 12 | // You can optionally experiment here. 13 | } 14 | 15 | #[cfg(test)] 16 | mod tests { 17 | use super::*; 18 | 19 | #[test] 20 | fn test_array_and_vec_similarity() { 21 | let (a, v) = array_and_vec(); 22 | assert_eq!(a, *v); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/pb/person/person.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; // 告诉编译器用`proto3`来解读 2 | 3 | package person; 4 | 5 | option go_package = "grpc/pb/person;person"; 6 | 7 | message PersonReq{ 8 | string name = 1; 9 | int32 age = 2; 10 | 11 | } 12 | message PersonRes{ 13 | string name = 1; 14 | int32 age = 2; 15 | 16 | } 17 | 18 | service SearchService { 19 | rpc Search(PersonReq) returns (PersonRes); // 传统的 即刻响应的 20 | rpc SearchI(stream PersonReq) returns (PersonRes); // 入参为流 21 | rpc SearchO(PersonReq) returns (stream PersonRes); // 出参为流 22 | rpc SearchIO(stream PersonReq) returns (stream PersonRes); // 出入均为流 23 | } -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/模型/model.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "database/sql" 5 | "time" 6 | ) 7 | 8 | type Model struct { 9 | UUID uint `gorm:"primaryKey"` // 主键 10 | Time time.Time `gorm:"column:my_time"` 11 | } 12 | 13 | type TestUser struct { 14 | Model Model `gorm:"embedded;embeddedPrefix:em_"` 15 | Name string `gorm:"default:Bruce"` 16 | Email *string `gorm:"not null"` 17 | Age uint8 `gorm:"comment:年龄"` 18 | Birthday *time.Time 19 | MemberNumber sql.NullString 20 | ActivatedAt sql.NullTime 21 | } 22 | 23 | func TestUserCreate() { 24 | GLOBAL_DB.AutoMigrate(&TestUser{}) 25 | } 26 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/普通服务/pb/person/person.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; // 告诉编译器用`proto3`来解读 2 | 3 | package person; 4 | 5 | option go_package = "grpc/pb/person;person"; 6 | 7 | message PersonReq{ 8 | string name = 1; 9 | int32 age = 2; 10 | 11 | } 12 | message PersonRes{ 13 | string name = 1; 14 | int32 age = 2; 15 | 16 | } 17 | 18 | service SearchService { 19 | rpc Search(PersonReq) returns (PersonRes); // 传统的 即刻响应的 20 | rpc SearchI(stream PersonReq) returns (PersonRes); // 入参为流 21 | rpc SearchO(PersonReq) returns (stream PersonRes); // 出参为流 22 | rpc SearchIO(stream PersonReq) returns (stream PersonRes); // 出入均为流 23 | } -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/流式传入/pb/person/person.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; // 告诉编译器用`proto3`来解读 2 | 3 | package person; 4 | 5 | option go_package = "grpc/pb/person;person"; 6 | 7 | message PersonReq{ 8 | string name = 1; 9 | int32 age = 2; 10 | 11 | } 12 | message PersonRes{ 13 | string name = 1; 14 | int32 age = 2; 15 | 16 | } 17 | 18 | service SearchService { 19 | rpc Search(PersonReq) returns (PersonRes); // 传统的 即刻响应的 20 | rpc SearchI(stream PersonReq) returns (PersonRes); // 入参为流 21 | rpc SearchO(PersonReq) returns (stream PersonRes); // 出参为流 22 | rpc SearchIO(stream PersonReq) returns (stream PersonRes); // 出入均为流 23 | } -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/流式出入/pb/person/person.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; // 告诉编译器用`proto3`来解读 2 | 3 | package person; 4 | 5 | option go_package = "grpc/pb/person;person"; 6 | 7 | message PersonReq{ 8 | string name = 1; 9 | int32 age = 2; 10 | 11 | } 12 | message PersonRes{ 13 | string name = 1; 14 | int32 age = 2; 15 | 16 | } 17 | 18 | service SearchService { 19 | rpc Search(PersonReq) returns (PersonRes); // 传统的 即刻响应的 20 | rpc SearchI(stream PersonReq) returns (PersonRes); // 入参为流 21 | rpc SearchO(PersonReq) returns (stream PersonRes); // 出参为流 22 | rpc SearchIO(stream PersonReq) returns (stream PersonRes); // 出入均为流 23 | } -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/流式返回/pb/person/person.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; // 告诉编译器用`proto3`来解读 2 | 3 | package person; 4 | 5 | option go_package = "grpc/pb/person;person"; 6 | 7 | message PersonReq{ 8 | string name = 1; 9 | int32 age = 2; 10 | 11 | } 12 | message PersonRes{ 13 | string name = 1; 14 | int32 age = 2; 15 | 16 | } 17 | 18 | service SearchService { 19 | rpc Search(PersonReq) returns (PersonRes); // 传统的 即刻响应的 20 | rpc SearchI(stream PersonReq) returns (PersonRes); // 入参为流 21 | rpc SearchO(PersonReq) returns (stream PersonRes); // 出参为流 22 | rpc SearchIO(stream PersonReq) returns (stream PersonRes); // 出入均为流 23 | } -------------------------------------------------------------------------------- /Golang/Code/standard library/context/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | ) 7 | 8 | func gen(ctx context.Context) <-chan int { 9 | dst := make(chan int) 10 | n := 1 11 | go func() { 12 | for { 13 | select { 14 | case <-ctx.Done(): 15 | return // return结束该goroutine,防止泄露 16 | case dst <- n: 17 | n++ 18 | } 19 | } 20 | }() 21 | return dst 22 | } 23 | 24 | func main() { 25 | ctx, cancel := context.WithCancel(context.Background()) 26 | defer cancel() // 当我们取完需要的整数后调用cancel 27 | 28 | for n := range gen(ctx) { 29 | fmt.Println(n) 30 | if n == 5 { 31 | break 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/06_move_semantics/move_semantics5.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::ptr_arg)] 2 | 3 | // TODO: Fix the compiler errors without changing anything except adding or 4 | // removing references (the character `&`). 5 | 6 | // Shouldn't take ownership 7 | fn get_char(data: &String) -> char { 8 | data.chars().last().unwrap() 9 | } 10 | 11 | // Should take ownership 12 | fn string_uppercase(mut data: String) { 13 | data = data.to_uppercase(); 14 | 15 | println!("{data}"); 16 | } 17 | 18 | fn main() { 19 | let data = "Rust is great!".to_string(); 20 | 21 | get_char(&data); 22 | 23 | string_uppercase(data); 24 | } 25 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/17_tests/tests2.rs: -------------------------------------------------------------------------------- 1 | // Calculates the power of 2 using a bit shift. 2 | // `1 << n` is equivalent to "2 to the power of n". 3 | fn power_of_2(n: u8) -> u64 { 4 | 1 << n 5 | } 6 | 7 | fn main() { 8 | // You can optionally experiment here. 9 | } 10 | 11 | #[cfg(test)] 12 | mod tests { 13 | use super::*; 14 | 15 | #[test] 16 | fn you_can_assert_eq() { 17 | // TODO: Test the function `power_of_2` with some values. 18 | assert_eq!(power_of_2(1), 2); 19 | assert_eq!(power_of_2(2), 4); 20 | assert_eq!(power_of_2(3), 8); 21 | assert_eq!(power_of_2(4), 16); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/17_fileDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "io" 6 | "os" 7 | ) 8 | 9 | func main() { 10 | // 读取文件 方法1 11 | file, err := os.Open("./main/test.txt") 12 | // 关闭文件流 13 | defer file.Close(); 14 | if err != nil { 15 | fmt.Println("打开文件出错") 16 | } 17 | // 读取文件里面的内容 18 | var tempSlice = make([]byte, 1024) 19 | var strSlice []byte 20 | for { 21 | n, err := file.Read(tempSlice) 22 | if err == io.EOF { 23 | fmt.Printf("读取完毕") 24 | break 25 | } 26 | fmt.Printf("读取到了%v 个字节 \n", n) 27 | strSlice := append(strSlice, tempSlice...) 28 | fmt.Println(string(strSlice)) 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/11_hashmaps/README.md: -------------------------------------------------------------------------------- 1 | # Hashmaps 2 | 3 | A *hash map* allows you to associate a value with a particular key. 4 | You may also know this by the names [*unordered map* in C++](https://en.cppreference.com/w/cpp/container/unordered_map), 5 | [*dictionary* in Python](https://docs.python.org/3/tutorial/datastructures.html#dictionaries) or an *associative array* in other languages. 6 | 7 | This is the other data structure that we've been talking about before, when 8 | talking about Vecs. 9 | 10 | ## Further information 11 | 12 | - [Storing Keys with Associated Values in Hash Maps](https://doc.rust-lang.org/book/ch08-03-hash-maps.html) 13 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/14_generics/README.md: -------------------------------------------------------------------------------- 1 | # Generics 2 | 3 | Generics is the topic of generalizing types and functionalities to broader cases. 4 | This is extremely useful for reducing code duplication in many ways, but can call for some rather involved syntax. 5 | Namely, being generic requires taking great care to specify over which types a generic type is actually considered valid. 6 | The simplest and most common use of generics is for type parameters. 7 | 8 | ## Further information 9 | 10 | - [Generic Data Types](https://doc.rust-lang.org/book/ch10-01-syntax.html) 11 | - [Bounds](https://doc.rust-lang.org/rust-by-example/generics/bounds.html) 12 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/关系/belongs_to_gorm.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "gorm.io/gorm" 5 | ) 6 | 7 | // belongsTo 8 | 9 | type Dog1 struct { 10 | gorm.Model 11 | Name string 12 | GoddessID uint 13 | Goddess Goddess1 14 | } 15 | 16 | type Goddess1 struct { 17 | gorm.Model 18 | Name string 19 | } 20 | 21 | func BelongsTo() { 22 | 23 | g := Goddess1{ 24 | Model: gorm.Model{ 25 | ID: 1, 26 | }, 27 | Name: "G1", 28 | } 29 | 30 | d := Dog1{ 31 | Model: gorm.Model{ 32 | ID: 1, 33 | }, 34 | Name: "dog1", 35 | Goddess: g, 36 | } 37 | 38 | _ = GLOBAL_DB.AutoMigrate(&Dog1{}) 39 | 40 | GLOBAL_DB.Create(&d) 41 | 42 | } 43 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/17_tests/tests1.rs: -------------------------------------------------------------------------------- 1 | // Tests are important to ensure that your code does what you think it should 2 | // do. 3 | 4 | fn is_even(n: i64) -> bool { 5 | n % 2 == 0 6 | } 7 | 8 | fn main() { 9 | // You can optionally experiment here. 10 | } 11 | 12 | #[cfg(test)] 13 | mod tests { 14 | // TODO: Import `is_even`. You can use a wildcard to import everything in 15 | // the outer module. 16 | use crate::*; 17 | 18 | #[test] 19 | fn you_can_assert() { 20 | // TODO: Test the function `is_even` with some values. 21 | assert!(is_even(11) == false, "false"); 22 | assert!(is_even(10), "true"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Golang/learning_note/GORM/1. GORM v2介绍.md: -------------------------------------------------------------------------------- 1 | # GORM 指南 2 | 3 | [GORM 指南](https://gorm.io/zh_CN/docs/index.html) 4 | 5 | ## 什么是ORM 6 | 7 | - 一种数据库操作辅助工具 8 | - 教科书上的废话:ORM是通过使用描述对象和数据库之间映射的元数据,将程序中的对象与关系数据库相互映身 9 | - 人话:ORM让你的数据库里面的表结构变成你代码定义的数据结构(golang里面的结构体的结构)从而做到,代码结构即为数据库结构,代码行为即为数据库行为 10 | - 在我们go的结构体和数据库之间产生映射,让我们对数据库的关系,表的内容,直观的体现在结构体上 11 | - 使用结构体即可完成增删改查操作 12 | 13 | 14 | ## 为什么选择GORM 15 | 16 | [go-gorm/gorm](https://github.com/go-gorm/gorm) 17 | 18 | [中文官方网站](https://gorm.io/zh_CN/)内含十分齐全的中文文档 19 | 20 | gorm是一个使用Go语言编写的ORM框架。它文档齐全,对开发者友好,支持主流数据库。 21 | 22 | ## 安装 23 | 24 | ```bash 25 | go get -u gorm.io/gorm 26 | go get -u gorm.io/driver/mysql 27 | ``` 28 | 29 | 30 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/08_enums/README.md: -------------------------------------------------------------------------------- 1 | # Enums 2 | 3 | Rust allows you to define types called "enums" which enumerate possible values. 4 | Enums are a feature in many languages, but their capabilities differ in each language. Rust’s enums are most similar to algebraic data types in functional languages, such as F#, OCaml, and Haskell. 5 | Useful in combination with enums is Rust's "pattern matching" facility, which makes it easy to run different code for different values of an enumeration. 6 | 7 | ## Further information 8 | 9 | - [Enums](https://doc.rust-lang.org/book/ch06-00-enums.html) 10 | - [Pattern syntax](https://doc.rust-lang.org/book/ch18-03-pattern-syntax.html) 11 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/12_StructDemo4.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | // 结构体嵌套 6 | 7 | // 用户结构体 8 | type User struct { 9 | userName string 10 | password string 11 | sex string 12 | age int 13 | address Address // User结构体嵌套Address结构体 14 | } 15 | 16 | // 收货地址结构体 17 | type Address struct { 18 | name string 19 | phone string 20 | city string 21 | } 22 | 23 | func main() { 24 | var u User 25 | u.userName = "moguBlog" 26 | u.password = "123456" 27 | u.sex = "男" 28 | u.age = 18 29 | 30 | var address Address 31 | address.name = "张三" 32 | address.phone = "110" 33 | address.city = "北京" 34 | u.address = address 35 | fmt.Printf("%#v", u) 36 | } 37 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/15_ChannelDemo3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | "time" 7 | ) 8 | 9 | func write(ch chan int) { 10 | for i := 0; i < 10; i++ { 11 | fmt.Println("写入:", i) 12 | ch <- i 13 | time.Sleep(time.Microsecond * 10) 14 | } 15 | wg.Done() 16 | } 17 | func read(ch chan int) { 18 | for i := 0; i < 10; i++ { 19 | fmt.Println("读取:", <- ch) 20 | time.Sleep(time.Microsecond * 10) 21 | } 22 | wg.Done() 23 | } 24 | var wg sync.WaitGroup 25 | func main() { 26 | ch := make(chan int, 10) 27 | wg.Add(1) 28 | go write(ch) 29 | wg.Add(1) 30 | go read(ch) 31 | 32 | // 等待 33 | wg.Wait() 34 | fmt.Println("主线程执行完毕") 35 | } 36 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/21_macros/README.md: -------------------------------------------------------------------------------- 1 | # Macros 2 | 3 | Rust's macro system is very powerful, but also kind of difficult to wrap your 4 | head around. We're not going to teach you how to write your own fully-featured 5 | macros. Instead, we'll show you how to use and create them. 6 | 7 | If you'd like to learn more about writing your own macros, the 8 | [macrokata](https://github.com/tfpk/macrokata) project has a similar style 9 | of exercises to Rustlings, but is all about learning to write Macros. 10 | 11 | ## Further information 12 | 13 | - [Macros](https://doc.rust-lang.org/book/ch19-06-macros.html) 14 | - [The Little Book of Rust Macros](https://veykril.github.io/tlborm/) 15 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/12_StructDemo2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | /** 6 | 定义一个人结构体 7 | */ 8 | type Person struct { 9 | name string 10 | age int 11 | sex string 12 | } 13 | 14 | // 定义一个结构体方法 15 | func (p Person) PrintInfo() { 16 | fmt.Print(" 姓名: ", p.name) 17 | fmt.Print(" 年龄: ", p.age) 18 | fmt.Print(" 性别: ", p.sex) 19 | fmt.Println() 20 | } 21 | func (p *Person) SetInfo(name string, age int, sex string) { 22 | p.name = name 23 | p.age = age 24 | p.sex = sex 25 | } 26 | 27 | func main() { 28 | var person = Person{ 29 | "张三", 30 | 18, 31 | "女", 32 | } 33 | person.PrintInfo() 34 | person.SetInfo("李四", 18, "男") 35 | person.PrintInfo() 36 | } 37 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basicGateway/go.mod: -------------------------------------------------------------------------------- 1 | module grpc 2 | 3 | go 1.18 4 | 5 | require ( 6 | google.golang.org/grpc v1.50.1 7 | google.golang.org/protobuf v1.28.1 8 | ) 9 | 10 | require ( 11 | github.com/golang/glog v1.0.0 // indirect 12 | github.com/golang/protobuf v1.5.2 // indirect 13 | github.com/google/go-cmp v0.5.9 // indirect 14 | github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0 // indirect 15 | golang.org/x/net v0.0.0-20220909164309-bea034e7d591 // indirect 16 | golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect 17 | golang.org/x/text v0.4.0 // indirect 18 | google.golang.org/genproto v0.0.0-20221014213838-99cd37c6964a // indirect 19 | gopkg.in/yaml.v3 v3.0.1 // indirect 20 | ) 21 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/02_functions/functions4.rs: -------------------------------------------------------------------------------- 1 | // This store is having a sale where if the price is an even number, you get 10 2 | // Rustbucks off, but if it's an odd number, it's 3 Rustbucks off. 3 | // Don't worry about the function bodies themselves, we are only interested in 4 | // the signatures for now. 5 | 6 | fn is_even(num: i64) -> bool { 7 | num % 2 == 0 8 | } 9 | 10 | // TODO: Fix the function signature. 11 | fn sale_price(price: i64) -> i64 { 12 | if is_even(price) { 13 | price - 10 14 | } else { 15 | price - 3 16 | } 17 | } 18 | 19 | fn main() { 20 | let original_price = 51; 21 | println!("Your sale price is {}", sale_price(original_price)); 22 | } 23 | -------------------------------------------------------------------------------- /Golang/Code/Gin/Params/functions/book.go: -------------------------------------------------------------------------------- 1 | package functions 2 | 3 | import ( 4 | "fmt" 5 | 6 | "github.com/gin-gonic/gin" 7 | ) 8 | 9 | func Book(r *gin.Engine) { 10 | r.GET("/book", func(c *gin.Context) { 11 | c.JSON(200, gin.H{ 12 | "message": "GET", 13 | }) 14 | }) 15 | 16 | r.POST("/book", func(c *gin.Context) { 17 | c.JSON(200, gin.H{ 18 | "message": "POST", 19 | }) 20 | }) 21 | 22 | r.PUT("/book", func(c *gin.Context) { 23 | c.JSON(200, gin.H{ 24 | "message": "PUT", 25 | }) 26 | }) 27 | 28 | r.DELETE("/book", func(c *gin.Context) { 29 | c.JSON(200, gin.H{ 30 | "message": "DELETE", 31 | }) 32 | }) 33 | 34 | } 35 | 36 | func Test() { 37 | fmt.Println(123) 38 | } 39 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/06_move_semantics/move_semantics2.rs: -------------------------------------------------------------------------------- 1 | fn fill_vec(vec: Vec) -> Vec { 2 | let mut vec = vec; 3 | 4 | vec.push(88); 5 | 6 | vec 7 | } 8 | 9 | fn main() { 10 | // You can optionally experiment here. 11 | } 12 | 13 | #[cfg(test)] 14 | mod tests { 15 | use super::*; 16 | 17 | // TODO: Make both vectors `vec0` and `vec1` accessible at the same time to 18 | // fix the compiler error in the test. 19 | #[test] 20 | fn move_semantics2() { 21 | let vec0 = vec![22, 44, 66]; 22 | 23 | let vec1 = fill_vec(vec0.clone()); 24 | 25 | assert_eq!(vec0, [22, 44, 66]); 26 | assert_eq!(vec1, [22, 44, 66, 88]); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/20_threads/README.md: -------------------------------------------------------------------------------- 1 | # Threads 2 | 3 | In most current operating systems, an executed program's code is run in a process, and the operating system manages multiple processes at once. 4 | Within your program, you can also have independent parts that run simultaneously. The features that run these independent parts are called threads. 5 | 6 | ## Further information 7 | 8 | - [Dining Philosophers example](https://doc.rust-lang.org/1.4.0/book/dining-philosophers.html) 9 | - [Using Threads to Run Code Simultaneously](https://doc.rust-lang.org/book/ch16-01-threads.html) 10 | - [Using Message Passing to Transfer Data Between Threads](https://doc.rust-lang.org/book/ch16-02-message-passing.html) 11 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/goProject/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "goProject/calc" 6 | 7 | "github.com/shopspring/decimal" 8 | "github.com/tidwall/gjson" 9 | ) 10 | 11 | const json = `{"name":{"first":"Janet","last":"Prichard"},"age":47}` 12 | 13 | func main() { 14 | fmt.Printf("%v \n", calc.Add(2, 5)) 15 | // 打印公有变量 16 | fmt.Println(calc.Name) 17 | 18 | _, err := decimal.NewFromString("136.02") 19 | if err != nil { 20 | panic(err) 21 | } 22 | 23 | var num1 float64 = 3.1 24 | var num2 float64 = 4.2 25 | d1 := decimal.NewFromFloat(num1).Add(decimal.NewFromFloat(num2)) 26 | fmt.Println(d1) 27 | 28 | value := gjson.Get(json, "name.last") 29 | println(value.String()) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Golang/Code/advanceCode/workpool/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "time" 6 | ) 7 | 8 | func worker(id int, jobs <-chan int, result chan<- int) { 9 | for i := range jobs { 10 | fmt.Printf("worker:%d start job: %d\n", id, i) 11 | time.Sleep(time.Second) 12 | fmt.Printf("worker:%d end job: %d\n", id, i) 13 | result <- i * 2 14 | } 15 | } 16 | 17 | func main() { 18 | jobs := make(chan int, 100) 19 | results := make(chan int, 100) 20 | // 开启3个goroutine 21 | for w := 1; w <= 3; w++ { 22 | go worker(w, jobs, results) 23 | } 24 | // 5个任务 25 | for j := 1; j <= 5; j++ { 26 | jobs <- j 27 | } 28 | close(jobs) 29 | // 输出结果 30 | for a := 1; a <= 5; a++ { 31 | <-results 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/goProject/go.sum: -------------------------------------------------------------------------------- 1 | github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8= 2 | github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= 3 | github.com/tidwall/gjson v1.14.1 h1:iymTbGkQBhveq21bEvAQ81I0LEBork8BFe1CUZXdyuo= 4 | github.com/tidwall/gjson v1.14.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk= 5 | github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA= 6 | github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM= 7 | github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs= 8 | github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU= 9 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/HelloWorld/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | hello_grpc "gRPC/pb" 6 | "golang.org/x/net/context" 7 | "google.golang.org/grpc" 8 | "google.golang.org/grpc/credentials/insecure" 9 | "log" 10 | ) 11 | 12 | func main() { 13 | conn, err := grpc.Dial("localhost:8888", grpc.WithTransportCredentials(insecure.NewCredentials())) 14 | if err != nil { 15 | log.Fatalf("did not connect: %v", err) 16 | } 17 | defer conn.Close() 18 | 19 | client := hello_grpc.NewHelloGRPCClient(conn) 20 | req, err := client.SayHis(context.Background(), &hello_grpc.Req{Message: "我从客户端来"}) 21 | if err != nil { 22 | log.Fatalf("could not greet: %v", err) 23 | } 24 | fmt.Println(req.GetMessage()) 25 | } 26 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/普通服务/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "golang.org/x/net/context" 6 | "google.golang.org/grpc" 7 | "google.golang.org/grpc/credentials/insecure" 8 | "grpc/pb/person" 9 | "log" 10 | ) 11 | 12 | func main() { 13 | conn, err := grpc.Dial("localhost:8888", grpc.WithTransportCredentials(insecure.NewCredentials())) 14 | if err != nil { 15 | log.Fatalf("did not connect: %v", err) 16 | } 17 | defer conn.Close() 18 | 19 | client := person.NewSearchServiceClient(conn) 20 | res, err := client.Search(context.Background(), &person.PersonReq{Name: "Client1", Age: 18}) 21 | if err != nil { 22 | log.Fatalf("could not send: %v", err) 23 | } 24 | fmt.Println(res) 25 | } 26 | -------------------------------------------------------------------------------- /Golang/Code/Gin/redirect/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-gonic/gin" 7 | ) 8 | 9 | func main() { 10 | r := gin.Default() 11 | 12 | r.GET("/", func(c *gin.Context) { 13 | c.String(200, "Hello World!") 14 | }) 15 | 16 | // r.GET("/test", func(c *gin.Context) { 17 | // c.Redirect(http.StatusMovedPermanently, "http://www.sogo.com/") 18 | // }) 19 | 20 | r.GET("/test", func(c *gin.Context) { 21 | // 指定重定向的URL 22 | c.Request.URL.Path = "/test2" 23 | r.HandleContext(c) 24 | }) 25 | r.GET("/test2", func(c *gin.Context) { 26 | c.JSON(http.StatusOK, gin.H{"hello": "world"}) 27 | }) 28 | 29 | r.Run(":9003") // listen and serve on 0.0.0.0:PORT(default:8080) 30 | 31 | } 32 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/go.sum: -------------------------------------------------------------------------------- 1 | github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= 2 | github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= 3 | github.com/tidwall/gjson v1.6.0 h1:9VEQWz6LLMUsUl6PueE49ir4Ka6CzLymOAZDxpFsTDc= 4 | github.com/tidwall/gjson v1.6.0/go.mod h1:P256ACg0Mn+j1RXIDXoss50DeIABTYK1PULOJHhxOls= 5 | github.com/tidwall/match v1.0.1 h1:PnKP62LPNxHKTwvHHZZzdOAOCtsJTjo6dZLCwpKm5xc= 6 | github.com/tidwall/match v1.0.1/go.mod h1:LujAq0jyVjBy028G1WhWfIzbpQfMO8bBZ6Tyb0+pL9E= 7 | github.com/tidwall/pretty v1.0.0 h1:HsD+QiTn7sK6flMKIvNmpqz1qrpP3Ps6jOKIKMooyg4= 8 | github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk= 9 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/12_StructDemo3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | /** 6 | 定义一个人结构体 7 | */ 8 | type Person struct { 9 | name string 10 | age int 11 | hobby []string 12 | mapValue map[string]string 13 | } 14 | 15 | func main() { 16 | // 结构体的匿名字段 17 | var person = Person{} 18 | person.name = "张三" 19 | person.age = 10 20 | 21 | // 给切片申请内存空间 22 | person.hobby = make([]string, 4, 4) 23 | person.hobby[0] = "睡觉" 24 | person.hobby[1] = "吃饭" 25 | person.hobby[2] = "打豆豆" 26 | 27 | // 给map申请存储空间 28 | person.mapValue = make(map[string]string) 29 | person.mapValue["address"] = "北京" 30 | person.mapValue["phone"] = "123456789" 31 | 32 | // 加入#打印完整信息 33 | fmt.Printf("%#v", person) 34 | } 35 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/SecondInterface/main.go: -------------------------------------------------------------------------------- 1 | package SecondInterface 2 | 3 | import "fmt" 4 | 5 | // 定义一个Animal的接口,Animal中定义了两个方法,分别是setName 和 getName,分别让DOg结构体和Cat结构体实现 6 | type Animal1 interface { 7 | SetName(string) 8 | } 9 | 10 | // 接口2 11 | type Animal2 interface { 12 | GetName()string 13 | } 14 | 15 | type Animal interface { 16 | Animal1 17 | Animal2 18 | } 19 | 20 | type Dog struct { 21 | Name string 22 | } 23 | 24 | func (d *Dog) SetName(name string) { 25 | d.Name = name 26 | } 27 | func (d Dog)GetName()string { 28 | return d.Name 29 | } 30 | 31 | func main() { 32 | var dog = &Dog{ 33 | "小黑", 34 | } 35 | // 同时实现两个接口 36 | var d Animal = dog 37 | d.SetName("小鸡") 38 | fmt.Println(d.GetName()) 39 | } 40 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/23_conversions/using_as.rs: -------------------------------------------------------------------------------- 1 | // Type casting in Rust is done via the usage of the `as` operator. 2 | // Note that the `as` operator is not only used when type casting. It also helps 3 | // with renaming imports. 4 | 5 | fn average(values: &[f64]) -> f64 { 6 | let total = values.iter().sum::(); 7 | // TODO: Make a conversion before dividing. 8 | total / values.len() as f64 9 | } 10 | 11 | fn main() { 12 | let values = [3.5, 0.3, 13.0, 11.7]; 13 | println!("{}", average(&values)); 14 | } 15 | 16 | #[cfg(test)] 17 | mod tests { 18 | use super::*; 19 | 20 | #[test] 21 | fn returns_proper_type_and_value() { 22 | assert_eq!(average(&[3.5, 0.3, 13.0, 11.7]), 7.125); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/14_generics/generics1.rs: -------------------------------------------------------------------------------- 1 | // `Vec` is generic over the type `T`. In most cases, the compiler is able to 2 | // infer `T`, for example after pushing a value with a concrete type to the vector. 3 | // But in this exercise, the compiler needs some help through a type annotation. 4 | 5 | fn main() { 6 | // TODO: Fix the compiler error by annotating the type of the vector 7 | // `Vec`. Choose `T` as some integer type that can be created from 8 | // `u8` and `i8`. 9 | let mut numbers: Vec = Vec::new(); 10 | 11 | // Don't change the lines below. 12 | let n1: u8 = 42; 13 | numbers.push(n1.into()); 14 | let n2: i8 = -1; 15 | numbers.push(n2.into()); 16 | 17 | println!("{numbers:?}"); 18 | } 19 | -------------------------------------------------------------------------------- /Linux/Shell.md: -------------------------------------------------------------------------------- 1 | 幻14 insert `[fn] + [Del]` 2 | F12 insert `[fn] + [j]` 3 | 4 | ```sh 5 | #! /bin/bash 6 | 7 | 8 | ``` 9 | 10 | ## bash和sh的区别 11 | 12 | `sh`遵循POSIX规范:“当某行代码出错时,不继续往下解释”。 13 | `bash`就算出错,也会继续向下执行。 14 | 15 | >POSIX表示可移植操作系统接口(Portable Operating System Interface of UNIX,缩写为 POSIX )。POSIX标准意在期望获得源代码级别的软件可移植性。换句话说,为一个POSIX兼容的操作系统编写的程序,应该可以在任何其它的POSIX操作系统上编译执行。 16 | 17 | sh 跟bash的区别,实际上是bash有没开启POSIX模式的区别。 18 | 19 | 简单说,sh是bash的一种特殊的模式,sh就是开启了POSIX标准的bash, /bin/sh 相当于 `/bin/bash --posix`。 20 | 21 | 在Linux系统上/bin/sh往往是指向/bin/bash的符号链接 22 | 23 | ```bash 24 | ln -s /bin/bash /bin/sh 25 | ``` 26 | 27 | ### 查看 28 | 29 | ```bash 30 | cat /etc/shells # 查看系统可使用的shell类型 31 | 32 | cat /etc/passwd # 查看当前默认设置,一般在第一行: 33 | 34 | ll /bin/sh #查看当前sh状态 35 | ``` 36 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/15_traits/traits2.rs: -------------------------------------------------------------------------------- 1 | trait AppendBar { 2 | fn append_bar(self) -> Self; 3 | } 4 | 5 | // TODO: Implement the trait `AppendBar` for a vector of strings. 6 | // `append_bar` should push the string "Bar" into the vector. 7 | 8 | impl AppendBar for Vec { 9 | fn append_bar(mut self) -> Self { 10 | self.push("Bar".to_string()); 11 | self 12 | } 13 | } 14 | 15 | fn main() { 16 | // You can optionally experiment here. 17 | } 18 | 19 | #[cfg(test)] 20 | mod tests { 21 | use super::*; 22 | 23 | #[test] 24 | fn is_vec_pop_eq_bar() { 25 | let mut foo = vec![String::from("Foo")].append_bar(); 26 | assert_eq!(foo.pop().unwrap(), "Bar"); 27 | assert_eq!(foo.pop().unwrap(), "Foo"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/事务/transaction.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type TMG struct { 4 | ID uint 5 | Name string 6 | } 7 | 8 | func Transaction() { 9 | GLOBAL_DB.AutoMigrate(&TMG{}) 10 | 11 | //flag := false 12 | //GLOBAL_DB.Transaction(func(tx *gorm.DB) error { 13 | // // 在事务中执行一些 db 操作(从这里开始,您应该使用 'tx' 而不是 'db') 14 | // tx.Create(&TMG{Name: "T1"}) 15 | // tx.Create(&TMG{Name: "T2"}) 16 | // tx.Create(&TMG{Name: "T3"}) 17 | // if flag { 18 | // // 返回 nil 提交事务 19 | // return nil 20 | // } else { 21 | // return errors.New("ERROR") 22 | // } 23 | // 24 | //}) 25 | 26 | tx := GLOBAL_DB.Begin() 27 | tx.Create(&TMG{Name: "T1"}) 28 | tx.Create(&TMG{Name: "T2"}) 29 | tx.SavePoint("sp") 30 | tx.Create(&TMG{Name: "T3"}) 31 | tx.RollbackTo("sp") // 不会创建T3 32 | tx.Commit() 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/transaction.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type TMG struct { 4 | ID uint 5 | Name string 6 | } 7 | 8 | func Transaction() { 9 | GLOBAL_DB.AutoMigrate(&TMG{}) 10 | 11 | //flag := false 12 | //GLOBAL_DB.Transaction(func(tx *gorm.DB) error { 13 | // // 在事务中执行一些 db 操作(从这里开始,您应该使用 'tx' 而不是 'db') 14 | // tx.Create(&TMG{Name: "T1"}) 15 | // tx.Create(&TMG{Name: "T2"}) 16 | // tx.Create(&TMG{Name: "T3"}) 17 | // if flag { 18 | // // 返回 nil 提交事务 19 | // return nil 20 | // } else { 21 | // return errors.New("ERROR") 22 | // } 23 | // 24 | //}) 25 | 26 | tx := GLOBAL_DB.Begin() 27 | tx.Create(&TMG{Name: "T1"}) 28 | tx.Create(&TMG{Name: "T2"}) 29 | tx.SavePoint("sp") 30 | tx.Create(&TMG{Name: "T3"}) 31 | tx.RollbackTo("sp") // 不会创建T3 32 | tx.Commit() 33 | 34 | } 35 | -------------------------------------------------------------------------------- /Golang/Code/advanceCode/udp/client/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | ) 7 | 8 | // UDP 客户端 9 | func main() { 10 | // 拨号连接 11 | socket, err := net.DialUDP("udp", nil, &net.UDPAddr{ 12 | IP: net.IPv4(0, 0, 0, 0), 13 | Port: 30000, 14 | }) 15 | if err != nil { 16 | fmt.Println("连接服务端失败,err:", err) 17 | return 18 | } 19 | defer socket.Close() 20 | sendData := []byte("Hello server") 21 | _, err = socket.Write(sendData) // 发送数据 22 | if err != nil { 23 | fmt.Println("发送数据失败,err:", err) 24 | return 25 | } 26 | data := make([]byte, 4096) 27 | n, remoteAddr, err := socket.ReadFromUDP(data) // 接收数据 28 | if err != nil { 29 | fmt.Println("接收数据失败,err:", err) 30 | return 31 | } 32 | fmt.Printf("recv:%v addr:%v count:%v\n", string(data[:n]), remoteAddr, n) 33 | } 34 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/strconvDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | func main() { 9 | // int类型转换str类型 10 | var num1 int64 = 20 11 | s1 := strconv.FormatInt(num1, 10) 12 | fmt.Printf("转换:%v - %T", s1, s1) 13 | 14 | // float类型转换成string类型 15 | var num2 float64 = 3.1415926 16 | 17 | /* 18 | 参数1:要转换的值 19 | 参数2:格式化类型 'f'表示float,'b'表示二进制,‘e’表示 十进制 20 | 参数3:表示保留的小数点,-1表示不对小数点格式化 21 | 参数4:格式化的类型,传入64位 或者 32位 22 | */ 23 | s2 := strconv.FormatFloat(num2, 'f', -1, 64) 24 | fmt.Printf("转换:%v-%T", s2, s2) 25 | 26 | fmt.Println("字符串转换") 27 | str := "10" 28 | // 第一个参数:需要转换的数,第二个参数:进制, 参数三:32位或64位 29 | strconv.ParseInt(str, 10, 64) 30 | 31 | // 转换成float类型 32 | str2 := "3.141592654" 33 | strconv.ParseFloat(str2, 10) 34 | 35 | 36 | 37 | 38 | } -------------------------------------------------------------------------------- /Rust/rustlings/exercises/13_error_handling/README.md: -------------------------------------------------------------------------------- 1 | # Error handling 2 | 3 | Most errors aren’t serious enough to require the program to stop entirely. 4 | Sometimes, when a function fails, it’s for a reason that you can easily interpret and respond to. 5 | For example, if you try to open a file and that operation fails because the file doesn’t exist, you might want to create the file instead of terminating the process. 6 | 7 | ## Further information 8 | 9 | - [Error Handling](https://doc.rust-lang.org/book/ch09-02-recoverable-errors-with-result.html) 10 | - [Generics](https://doc.rust-lang.org/book/ch10-01-syntax.html) 11 | - [Result](https://doc.rust-lang.org/rust-by-example/error/result.html) 12 | - [Boxing errors](https://doc.rust-lang.org/rust-by-example/error/multiple_error_types/boxing_errors.html) 13 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/19_smart_pointers/README.md: -------------------------------------------------------------------------------- 1 | # Smart Pointers 2 | 3 | In Rust, smart pointers are variables that contain an address in memory and reference some other data, but they also have additional metadata and capabilities. 4 | Smart pointers in Rust often own the data they point to, while references only borrow data. 5 | 6 | ## Further Information 7 | 8 | - [Smart Pointers](https://doc.rust-lang.org/book/ch15-00-smart-pointers.html) 9 | - [Using Box to Point to Data on the Heap](https://doc.rust-lang.org/book/ch15-01-box.html) 10 | - [Rc\, the Reference Counted Smart Pointer](https://doc.rust-lang.org/book/ch15-04-rc.html) 11 | - [Shared-State Concurrency](https://doc.rust-lang.org/book/ch16-03-shared-state.html) 12 | - [Cow Documentation](https://doc.rust-lang.org/std/borrow/enum.Cow.html) 13 | -------------------------------------------------------------------------------- /Golang/Code/advanceCode/udp/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | ) 7 | 8 | // UDP server端 9 | func main() { 10 | listen, err := net.ListenUDP("udp", &net.UDPAddr{ 11 | IP: net.IPv4(0, 0, 0, 0), 12 | Port: 30000, 13 | }) 14 | if err != nil { 15 | fmt.Println("listen failed, err:", err) 16 | return 17 | } 18 | defer listen.Close() 19 | for { 20 | var data [1024]byte 21 | n, addr, err := listen.ReadFromUDP(data[:]) // 接收数据 22 | if err != nil { 23 | fmt.Println("read udp failed, err:", err) 24 | continue 25 | } 26 | fmt.Printf("data:%v addr:%v count:%v\n", string(data[:n]), addr, n) 27 | _, err = listen.WriteToUDP(data[:n], addr) // 发送数据 28 | if err != nil { 29 | fmt.Println("write to udp failed, err:", err) 30 | continue 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/11_pointerDemo2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func fn4(x int) { 6 | x = 10 7 | } 8 | func fn5(x *int) { 9 | *x = 20 10 | } 11 | func main() { 12 | x := 5 13 | fn4(x) 14 | fmt.Println(x) 15 | fn5(&x) 16 | fmt.Println(x) 17 | 18 | // 引用数据类型map、slice等,必须使用make分配空间,才能够使用 19 | var userInfo = make(map[string]string) 20 | userInfo["userName"] = "zhangsan" 21 | fmt.Println(userInfo) 22 | 23 | var array = make([]int, 4, 4) 24 | array[0] = 1 25 | fmt.Println(array) 26 | 27 | // 指针变量初始化 28 | //var a *int 29 | //*a = 100 30 | //fmt.Println(a) 31 | 32 | // 使用new关键字创建指针 33 | aPoint := new(int) 34 | bPoint := new(bool) 35 | fmt.Printf("%T \n", aPoint) 36 | fmt.Printf("%T \n", bPoint) 37 | fmt.Println(*aPoint) 38 | fmt.Println(*bPoint) 39 | 40 | } 41 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/update_gorm.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func TestUpdate() { 4 | // Update 只更新你选择的字段 5 | // Updates 更新所有字段 此时有两种形式 一种为Map 一种为结构体 结构体零值不参与更新 6 | // Save 无论如何都更新 所有的内容 包括0值 7 | 8 | // update 9 | //GLOBAL_DB.Model(&TestUser{}).Select("name").Where("name LIKE ?", "%ST%").Update("name", "ST_new") 10 | 11 | // save 12 | //var users []TestUser 13 | // 14 | //dbRes := GLOBAL_DB.Where("name LIKE ?", "%ST%").Find(&users) 15 | //for i := range users { 16 | // users[i].Age = 18 17 | //} 18 | //dbRes.Save(&users) 19 | 20 | // updates 21 | // struct 22 | var users TestUser // 多条用切片 23 | 24 | GLOBAL_DB.First(&users).Updates(TestUser{Name: "ST111", Age: 0}) // age 为0值不会更新 25 | // map 26 | GLOBAL_DB.First(&users).Updates(map[string]interface{}{"Name": "ST1111", "Age": 0}) // map 0值可以更新 27 | } 28 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/增删改查/update_gorm.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | func TestUpdate() { 4 | // Update 只更新你选择的字段 5 | // Updates 更新所有字段 此时有两种形式 一种为Map 一种为结构体 结构体零值不参与更新 6 | // Save 无论如何都更新 所有的内容 包括0值 7 | 8 | // update 9 | //GLOBAL_DB.Model(&TestUser{}).Select("name").Where("name LIKE ?", "%ST%").Update("name", "ST_new") 10 | 11 | // save 12 | //var users []TestUser 13 | // 14 | //dbRes := GLOBAL_DB.Where("name LIKE ?", "%ST%").Find(&users) 15 | //for i := range users { 16 | // users[i].Age = 18 17 | //} 18 | //dbRes.Save(&users) 19 | 20 | // updates 21 | // struct 22 | var users TestUser // 多条用切片 23 | 24 | GLOBAL_DB.First(&users).Updates(TestUser{Name: "ST111", Age: 0}) // age 为0值不会更新 25 | // map 26 | GLOBAL_DB.First(&users).Updates(map[string]interface{}{"Name": "ST1111", "Age": 0}) // map 0值可以更新 27 | } 28 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/10_modules/modules2.rs: -------------------------------------------------------------------------------- 1 | // You can bring module paths into scopes and provide new names for them with 2 | // the `use` and `as` keywords. 3 | 4 | #[allow(dead_code)] 5 | mod delicious_snacks { 6 | // TODO: Add the following two `use` statements after fixing them. 7 | pub use self::fruits::PEAR as fruit; 8 | pub use self::veggies::CUCUMBER as veggie; 9 | 10 | mod fruits { 11 | pub const PEAR: &str = "Pear"; 12 | pub const APPLE: &str = "Apple"; 13 | } 14 | 15 | mod veggies { 16 | pub const CUCUMBER: &str = "Cucumber"; 17 | pub const CARROT: &str = "Carrot"; 18 | } 19 | } 20 | 21 | fn main() { 22 | println!( 23 | "favorite snacks: {} and {}", 24 | delicious_snacks::fruit, 25 | delicious_snacks::veggie, 26 | ); 27 | } 28 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/14_generics/generics2.rs: -------------------------------------------------------------------------------- 1 | // This powerful wrapper provides the ability to store a positive integer value. 2 | // TODO: Rewrite it using a generic so that it supports wrapping ANY type. 3 | struct Wrapper { 4 | value: T, 5 | } 6 | 7 | // TODO: Adapt the struct's implementation to be generic over the wrapped value. 8 | impl Wrapper { 9 | fn new(value: T) -> Self { 10 | Wrapper { value } 11 | } 12 | } 13 | 14 | fn main() { 15 | // You can optionally experiment here. 16 | } 17 | 18 | #[cfg(test)] 19 | mod tests { 20 | use super::*; 21 | 22 | #[test] 23 | fn store_u32_in_wrapper() { 24 | assert_eq!(Wrapper::new(42).value, 42); 25 | } 26 | 27 | #[test] 28 | fn store_str_in_wrapper() { 29 | assert_eq!(Wrapper::new("Foo").value, "Foo"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/15_traits/README.md: -------------------------------------------------------------------------------- 1 | # Traits 2 | 3 | A trait is a collection of methods. 4 | 5 | Data types can implement traits. To do so, the methods making up the trait are defined for the data type. For example, the `String` data type implements the `From<&str>` trait. This allows a user to write `String::from("hello")`. 6 | 7 | In this way, traits are somewhat similar to Java interfaces and C++ abstract classes. 8 | 9 | Some additional common Rust traits include: 10 | 11 | - `Clone` (the `clone` method) 12 | - `Display` (which allows formatted display via `{}`) 13 | - `Debug` (which allows formatted display via `{:?}`) 14 | 15 | Because traits indicate shared behavior between data types, they are useful when writing generics. 16 | 17 | ## Further information 18 | 19 | - [Traits](https://doc.rust-lang.org/book/ch10-02-traits.html) 20 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/12_StructJsonDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | // 结构体和Json互相转换 9 | 10 | // 定义一个学生结构体,注意结构体的首字母必须大写,代表公有,否则将无法转换 11 | type Student struct { 12 | ID string 13 | Gender string 14 | Name string 15 | Sno string 16 | } 17 | func main() { 18 | var s1 = Student{ 19 | ID: "12", 20 | Gender: "男", 21 | Name: "李四", 22 | Sno: "s001", 23 | } 24 | // 结构体转换成Json 25 | jsonByte, _ := json.Marshal(s1) 26 | jsonStr := string(jsonByte) 27 | fmt.Println(jsonStr) 28 | 29 | // Json字符串转换成结构体 30 | var str = `{"ID":"12","Gender":"男","Name":"李四","Sno":"s001"}` 31 | var s2 = Student{} 32 | // 第一个是需要传入byte类型的数据,第二参数需要传入转换的地址 33 | err := json.Unmarshal([]byte(str), &s2) 34 | if err != nil { 35 | fmt.Printf("转换失败 \n") 36 | } else { 37 | fmt.Printf("%#v \n", s2) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/15_traits/traits1.rs: -------------------------------------------------------------------------------- 1 | // The trait `AppendBar` has only one function which appends "Bar" to any object 2 | // implementing this trait. 3 | trait AppendBar { 4 | fn append_bar(self) -> Self; 5 | } 6 | 7 | impl AppendBar for String { 8 | // TODO: Implement `AppendBar` for the type `String`. 9 | fn append_bar(self) -> Self { 10 | self + "Bar" 11 | } 12 | } 13 | 14 | fn main() { 15 | let s = String::from("Foo"); 16 | let s = s.append_bar(); 17 | println!("s: {s}"); 18 | } 19 | 20 | #[cfg(test)] 21 | mod tests { 22 | use super::*; 23 | 24 | #[test] 25 | fn is_foo_bar() { 26 | assert_eq!(String::from("Foo").append_bar(), "FooBar"); 27 | } 28 | 29 | #[test] 30 | fn is_bar_bar() { 31 | assert_eq!(String::from("").append_bar().append_bar(), "BarBar"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/关系/polymorphic.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | type Jiazi struct { 4 | ID uint 5 | Name string 6 | Xiaofengche []Xiaofengche `gorm:"polymorphic:Owner;polymorphicValue:huhu"` 7 | } 8 | 9 | type Yujie struct { 10 | ID uint 11 | Name string 12 | Xiaofengche Xiaofengche `gorm:"polymorphic:Owner;polymorphicValue:Abaaba"` 13 | } 14 | 15 | type Xiaofengche struct { 16 | ID uint 17 | Name string 18 | OwnerType string 19 | OwnerID uint 20 | } 21 | 22 | func Polymorphic() { 23 | GLOBAL_DB.AutoMigrate(&Jiazi{}, &Yujie{}, &Xiaofengche{}) 24 | 25 | GLOBAL_DB.Create(&Jiazi{ 26 | Name: "夹子", 27 | Xiaofengche: []Xiaofengche{ 28 | {Name: "小风车1"}, 29 | {Name: "小风车2"}, 30 | }, 31 | }) 32 | GLOBAL_DB.Create(&Yujie{ 33 | Name: "御姐", 34 | Xiaofengche: Xiaofengche{ 35 | Name: "大风车", 36 | }, 37 | }) 38 | } 39 | -------------------------------------------------------------------------------- /Golang/Code/standard library/flag/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "time" 7 | ) 8 | 9 | //os.Args demo 10 | func main() { 11 | // //os.Args是一个[]string 12 | // if len(os.Args) > 0 { 13 | // for index, arg := range os.Args { 14 | // fmt.Printf("args[%d]=%v\n", index, arg) 15 | // } 16 | // } 17 | 18 | //定义命令行参数方式1 19 | var name string 20 | var age int 21 | var married bool 22 | var delay time.Duration 23 | flag.StringVar(&name, "name", "张三", "姓名") 24 | flag.IntVar(&age, "age", 18, "年龄") 25 | flag.BoolVar(&married, "married", false, "婚否") 26 | flag.DurationVar(&delay, "d", 0, "延迟的时间间隔") 27 | 28 | //解析命令行参数 29 | flag.Parse() 30 | fmt.Println(name, age, married, delay) 31 | //返回命令行参数后的其他参数 32 | fmt.Println(flag.Args()) 33 | //返回命令行参数后的其他参数个数 34 | fmt.Println(flag.NArg()) 35 | //返回使用的命令行参数个数 36 | fmt.Println(flag.NFlag()) 37 | } 38 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/HelloWorld/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "context" 5 | "fmt" 6 | hello_grpc "gRPC/pb" 7 | "google.golang.org/grpc" 8 | "log" 9 | "net" 10 | ) 11 | 12 | type server struct { 13 | hello_grpc.UnimplementedHelloGRPCServer 14 | } 15 | 16 | func (receiver *server) SayHis(ctx context.Context, req *hello_grpc.Req) (res *hello_grpc.Res, err error) { 17 | fmt.Println(req.GetMessage()) 18 | return &hello_grpc.Res{Message: "服务端返回的grpc内容"}, nil 19 | } 20 | 21 | func main() { 22 | // 注册服务 23 | l, err := net.Listen("tcp", ":8888") 24 | if err != nil { 25 | log.Fatalf("failed to listen: %v", err) 26 | } 27 | s := grpc.NewServer() 28 | hello_grpc.RegisterHelloGRPCServer(s, &server{}) 29 | log.Printf("server listening at %v", l.Addr()) 30 | // 建立监听 31 | if err := s.Serve(l); err != nil { 32 | log.Fatalf("failed to serve: %v", err) 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/12_StructJsonDemo3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | // 嵌套结构体 到 Json的互相转换 9 | 10 | // 定义一个Student结构体 11 | type Student3 struct { 12 | Id int 13 | Gender string 14 | Name string 15 | } 16 | 17 | // 定义一个班级结构体 18 | type Class struct { 19 | Title string 20 | Students []Student3 21 | } 22 | 23 | func main() { 24 | var class = Class{ 25 | Title: "1班", 26 | Students: make([]Student3, 0), 27 | } 28 | for i := 0; i < 10; i++ { 29 | s := Student3{ 30 | Id: i + 1, 31 | Gender: "男", 32 | Name: fmt.Sprintf("stu_%v", i + 1), 33 | } 34 | class.Students = append(class.Students, s) 35 | } 36 | fmt.Printf("%#v \n", class) 37 | 38 | // 转换成Json字符串 39 | strByte, err := json.Marshal(class) 40 | if err != nil { 41 | fmt.Println("打印失败") 42 | } else { 43 | fmt.Println(string(strByte)) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/go_basic/cycle.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // var num = 10 7 | // if num == 10 { 8 | // fmt.Println("hello == 10") 9 | // } else if num > 10 { 10 | // fmt.Println("hello > 10") 11 | // } else { 12 | // fmt.Println("hello < 10") 13 | // } 14 | 15 | // if num2 := 10; num2 >= 10 { 16 | // fmt.Println("hello >=10") 17 | // } 18 | 19 | // for i := 0; i < 10; i++ { 20 | // fmt.Printf("%v ", i+1) 21 | // } 22 | 23 | var str = "你好golang" 24 | for key, value := range str { 25 | fmt.Printf("%v - %c \n", key, value) 26 | } 27 | 28 | var array = []string{"php", "java", "node", "golang"} 29 | for index, value := range array { 30 | fmt.Printf("%v %s \n", index, value) 31 | } 32 | 33 | var i = 0 34 | for { 35 | if i == 10 { 36 | fmt.Println("跳出循环") 37 | break 38 | } 39 | i++ 40 | fmt.Println(i) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Golang/Code/standard library/strconv/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strconv" 6 | ) 7 | 8 | func main() { 9 | // s1 := "100" 10 | // i1, err := strconv.Atoi(s1) 11 | // if err != nil { 12 | // fmt.Println("can't convert to int") 13 | // } else { 14 | // fmt.Printf("type:%T value:%#v\n", i1, i1) //type:int value:100 15 | // } 16 | 17 | // b, err := strconv.ParseBool("true") 18 | // fmt.Println(b, err) 19 | 20 | // f, err := strconv.ParseFloat("3.1415", 64) 21 | // fmt.Println(f, err) 22 | 23 | // i, err := strconv.ParseInt("-2", 10, 64) 24 | // fmt.Println(i, err) 25 | 26 | // u, err := strconv.ParseUint("2", 10, 64) 27 | // fmt.Println(u, err) 28 | 29 | s1 := strconv.FormatBool(true) 30 | s2 := strconv.FormatFloat(3.1415, 'E', -1, 64) 31 | s3 := strconv.FormatInt(-2, 16) 32 | s4 := strconv.FormatUint(2, 16) 33 | fmt.Println(s1, s2, s3, s4) 34 | } 35 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/16_lifetimes/lifetimes1.rs: -------------------------------------------------------------------------------- 1 | // The Rust compiler needs to know how to check whether supplied references are 2 | // valid, so that it can let the programmer know if a reference is at risk of 3 | // going out of scope before it is used. Remember, references are borrows and do 4 | // not own their own data. What if their owner goes out of scope? 5 | 6 | // TODO: Fix the compiler error by updating the function signature. 7 | fn longest<'a>(x: &'a str, y: &'a str) -> &'a str { 8 | if x.len() > y.len() { 9 | x 10 | } else { 11 | y 12 | } 13 | } 14 | 15 | fn main() { 16 | // You can optionally experiment here. 17 | } 18 | 19 | #[cfg(test)] 20 | mod tests { 21 | use super::*; 22 | 23 | #[test] 24 | fn test_longest() { 25 | assert_eq!(longest("abcd", "123"), "abcd"); 26 | assert_eq!(longest("abc", "1234"), "1234"); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/17_fileDemo2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "bufio" 5 | "fmt" 6 | "io" 7 | "io/ioutil" 8 | "os" 9 | ) 10 | 11 | func main() { 12 | // 读取文件 方法2 13 | file, err := os.Open("./main/test.txt") 14 | // 关闭文件流 15 | defer file.Close(); 16 | if err != nil { 17 | fmt.Println("打开文件出错") 18 | } 19 | // 通过创建bufio来读取 20 | reader := bufio.NewReader(file) 21 | var fileStr string 22 | var count int = 0 23 | for { 24 | // 相当于读取一行 25 | str, err := reader.ReadString('\n') 26 | if err == io.EOF { 27 | // 读取完成的时候,也会有内容 28 | fileStr += str 29 | fmt.Println("读取结束", count) 30 | break 31 | } 32 | if err != nil { 33 | fmt.Println(err) 34 | break 35 | } 36 | count ++ 37 | fileStr += str 38 | } 39 | fmt.Println(fileStr) 40 | 41 | 42 | // 通过IOUtil读取 43 | byteStr, _ := ioutil.ReadFile("./main/test.txt") 44 | fmt.Println(string(byteStr)) 45 | } 46 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/03_if/if1.rs: -------------------------------------------------------------------------------- 1 | fn bigger(a: i32, b: i32) -> i32 { 2 | // TODO: Complete this function to return the bigger number! 3 | // If both numbers are equal, any of them can be returned. 4 | // Do not use: 5 | // - another function call 6 | // - additional variables 7 | 8 | if a >= b { 9 | a 10 | } else { 11 | b 12 | } 13 | } 14 | 15 | fn main() { 16 | // You can optionally experiment here. 17 | } 18 | 19 | // Don't mind this for now :) 20 | #[cfg(test)] 21 | mod tests { 22 | use super::*; 23 | 24 | #[test] 25 | fn ten_is_bigger_than_eight() { 26 | assert_eq!(10, bigger(10, 8)); 27 | } 28 | 29 | #[test] 30 | fn fortytwo_is_bigger_than_thirtytwo() { 31 | assert_eq!(42, bigger(32, 42)); 32 | } 33 | 34 | #[test] 35 | fn equal_numbers() { 36 | assert_eq!(42, bigger(42, 42)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /数据库/MySQL/面试题.md: -------------------------------------------------------------------------------- 1 | # 面试题 2 | 3 | ## 查找每个日期、销售的不同产品的数量及其名称 4 | 5 | [1484. 按日期分组销售产品 - 力扣(LeetCode)](https://leetcode.cn/problems/group-sold-products-by-the-date/) 6 | 7 | ```sql 8 | select sell_date,  9 | count(distinct product) num_sold,  10 | group_concat(distinct product order by product separator ',' )products 11 | from Activities 12 | group by sell_date 13 | order by sell_date; 14 | ``` 15 | 16 | GROUP_CONCAT 17 | 返回一个字符串,该字符串具有来自组的连接的非 NULL 值。 18 | 19 | ## 行转列 20 | 21 | ![](https://raw.githubusercontent.com/Swiftie13st/Figurebed/main/img/20230209114052.png) 22 | 23 | ```sql 24 | SELECT product_id, 'store1' store, store1 price 25 | FROM Products 26 | WHERE store1 IS NOT NULL 27 | UNION ALL 28 | SELECT product_id, 'store2' store, store2 price 29 | FROM Products 30 | WHERE store2 IS NOT NULL 31 | UNION ALL 32 | SELECT product_id, 'store3' store, store3 price 33 | FROM Products 34 | WHERE store3 IS NOT NULL 35 | ``` -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/man3.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math" 6 | "unsafe" 7 | ) 8 | 9 | func main() { 10 | var num int = 10 11 | fmt.Printf("num = %v num 是 %T", num, num) 12 | fmt.Println() 13 | var num2 = 12 14 | fmt.Println(unsafe.Sizeof(num2)) 15 | 16 | var a1 int16 = 10 17 | var a2 int32 = 12 18 | var a3 = int32(a1) + a2 19 | fmt.Println(a3) 20 | 21 | var n1 int16 = 130 22 | fmt.Println(int8(n1)) 23 | 24 | fmt.Println("不同类型的输出") 25 | var number = 17 26 | // 原样输出 27 | fmt.Printf("%v\n", number) 28 | // 十进制输出 29 | fmt.Printf("%d\n", number) 30 | // 以八进制输出 31 | fmt.Printf("%o\n", number) 32 | // 以二进制输出 33 | fmt.Printf("%b\n", number) 34 | // 以十六进制输出 35 | fmt.Printf("%x\n", number) 36 | 37 | fmt.Println("浮点类型") 38 | var pi = math.Pi 39 | // 打印浮点类型,默认小数点6位 40 | fmt.Printf("%f\n", pi) 41 | // 打印浮点类型,打印小数点后2位 42 | fmt.Printf("%.2f\n", pi) 43 | 44 | } 45 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/12_StructJsonDemo2.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | // 结构体标签 9 | 10 | // 定义一个Student体,使用结构体标签 11 | type Student2 struct { 12 | Id string `json:"id"` // 通过指定tag实现json序列化该字段的key 13 | Gender string `json:"gender"` 14 | Name string `json:"name"` 15 | Sno string `json:"sno"` 16 | } 17 | func main() { 18 | var s1 = Student2{ 19 | Id: "12", 20 | Gender: "男", 21 | Name: "李四", 22 | Sno: "s001", 23 | } 24 | // 结构体转换成Json 25 | jsonByte, _ := json.Marshal(s1) 26 | jsonStr := string(jsonByte) 27 | fmt.Println(jsonStr) 28 | 29 | // Json字符串转换成结构体 30 | var str = `{"Id":"12","Gender":"男","Name":"李四","Sno":"s001"}` 31 | var s2 = Student2{} 32 | // 第一个是需要传入byte类型的数据,第二参数需要传入转换的地址 33 | err := json.Unmarshal([]byte(str), &s2) 34 | if err != nil { 35 | fmt.Printf("转换失败 \n") 36 | } else { 37 | fmt.Printf("%#v \n", s2) 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Rust/Code/us.rs: -------------------------------------------------------------------------------- 1 | use std::{cell::RefCell, rc::Rc, thread}; 2 | 3 | #[derive(Debug, Default, Clone)] 4 | struct Evil { 5 | data: Rc>, 6 | } 7 | 8 | // 为 Evil 强行实现 Send,这会让 Rc 整个紊乱 9 | unsafe impl Send for Evil {} 10 | 11 | fn main() { 12 | let v = Evil::default(); 13 | let v1 = v.clone(); 14 | let v2 = v.clone(); 15 | 16 | let t1 = thread::spawn(move || { 17 | let v3 = v.clone(); 18 | let mut data = v3.data.borrow_mut(); 19 | *data += 1; 20 | println!("v3: {:?}", data); 21 | }); 22 | 23 | let t2 = thread::spawn(move || { 24 | let v4 = v1.clone(); 25 | let mut data = v4.data.borrow_mut(); 26 | *data += 1; 27 | println!("v4: {:?}", data); 28 | }); 29 | 30 | t2.join().unwrap(); 31 | t1.join().unwrap(); 32 | 33 | let mut data = v2.data.borrow_mut(); 34 | *data += 1; 35 | 36 | println!("v2: {:?}", data); 37 | } -------------------------------------------------------------------------------- /Rust/rustlings/exercises/08_enums/enums2.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | #[derive(Debug)] 4 | struct Point { 5 | x: u64, 6 | y: u64, 7 | } 8 | 9 | #[derive(Debug)] 10 | enum Message { 11 | // TODO: Define the different variants used below. 12 | Resize { width: u64, height: u64 }, 13 | Move(Point), 14 | Echo(String), 15 | ChangeColor(u8, u8, u8), 16 | Quit, 17 | } 18 | 19 | impl Message { 20 | fn call(&self) { 21 | println!("{self:?}"); 22 | } 23 | } 24 | 25 | fn main() { 26 | let messages = [ 27 | Message::Resize { 28 | width: 10, 29 | height: 30, 30 | }, 31 | Message::Move(Point { x: 10, y: 15 }), 32 | Message::Echo(String::from("hello world")), 33 | Message::ChangeColor(200, 255, 255), 34 | Message::Quit, 35 | ]; 36 | 37 | for message in &messages { 38 | message.call(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/15_goroutineDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | // 定义一个协程计数器 9 | var wg sync.WaitGroup 10 | 11 | func test() { 12 | // 这是主进程执行的 13 | for i := 0; i < 1000; i++ { 14 | fmt.Println("test1 你好golang", i) 15 | //time.Sleep(time.Millisecond * 100) 16 | } 17 | // 协程计数器减1 18 | wg.Done() 19 | } 20 | 21 | func test2() { 22 | // 这是主进程执行的 23 | for i := 0; i < 1000; i++ { 24 | fmt.Println("test2 你好golang", i) 25 | //time.Sleep(time.Millisecond * 100) 26 | } 27 | // 协程计数器减1 28 | wg.Done() 29 | } 30 | 31 | 32 | 33 | func main() { 34 | 35 | // 通过go关键字,就可以直接开启一个协程 36 | wg.Add(1) 37 | go test() 38 | 39 | // 协程计数器加1 40 | wg.Add(1) 41 | go test2() 42 | 43 | // 这是主进程执行的 44 | for i := 0; i < 1000; i++ { 45 | fmt.Println("main 你好golang", i) 46 | //time.Sleep(time.Millisecond * 100) 47 | } 48 | // 等待所有的协程执行完毕 49 | wg.Wait() 50 | fmt.Println("主线程退出") 51 | } 52 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/16_reflectDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "reflect" 6 | ) 7 | 8 | func reflectFun(x interface{}) { 9 | v := reflect.TypeOf(x) 10 | fmt.Println(v) 11 | fmt.Println("类型名称", v.Name()) 12 | fmt.Println("类型种类", v.Kind()) 13 | } 14 | func reflectValue(x interface{}) { 15 | b,_ := x.(int) 16 | var num = 10 + b 17 | fmt.Println(num) 18 | } 19 | func reflectValue2(x interface{}) { 20 | // 通过反射来获取变量的原始值 21 | v := reflect.ValueOf(x) 22 | fmt.Println(v) 23 | // 获取到V的int类型 24 | var n = v.Int() + 12 25 | fmt.Println(n) 26 | 27 | kind := v.Kind() 28 | switch kind { 29 | case reflect.Int: 30 | fmt.Println("我是int类型") 31 | case reflect.Float64: 32 | fmt.Println("我是float64类型") 33 | default: 34 | fmt.Println("我是其它类型") 35 | } 36 | 37 | } 38 | func main() { 39 | reflectFun(10) 40 | reflectFun(10.01) 41 | reflectFun("abc") 42 | reflectFun(true) 43 | 44 | reflectValue2(10) 45 | } 46 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/polymorphic.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | // 4 | //type Jiazi struct { 5 | // ID uint 6 | // Name string 7 | // Xiaofengche []Xiaofengche `gorm:"polymorphic:Owner;polymorphicValue:huhu"` 8 | //} 9 | // 10 | //type Yujie struct { 11 | // ID uint 12 | // Name string 13 | // Xiaofengche Xiaofengche `gorm:"polymorphic:Owner;polymorphicValue:Abaaba"` 14 | //} 15 | // 16 | //type Xiaofengche struct { 17 | // ID uint 18 | // Name string 19 | // OwnerType string 20 | // OwnerID uint 21 | //} 22 | // 23 | //func Polymorphic() { 24 | // GLOBAL_DB.AutoMigrate(&Jiazi{}, &Yujie{}, &Xiaofengche{}) 25 | // 26 | // GLOBAL_DB.Create(&Jiazi{ 27 | // Name: "夹子", 28 | // Xiaofengche: []Xiaofengche{ 29 | // {Name: "小风车1"}, 30 | // {Name: "小风车2"}, 31 | // }, 32 | // }) 33 | // GLOBAL_DB.Create(&Yujie{ 34 | // Name: "御姐", 35 | // Xiaofengche: Xiaofengche{ 36 | // Name: "大风车", 37 | // }, 38 | // }) 39 | //} 40 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/05_vecs/README.md: -------------------------------------------------------------------------------- 1 | # Vectors 2 | 3 | Vectors are one of the most-used Rust data structures. In other programming 4 | languages, they'd simply be called Arrays, but since Rust operates on a 5 | bit of a lower level, an array in Rust is stored on the stack (meaning it 6 | can't grow or shrink, and the size needs to be known at compile time), 7 | and a Vector is stored in the heap (where these restrictions do not apply). 8 | 9 | Vectors are a bit of a later chapter in the book, but we think that they're 10 | useful enough to talk about them a bit earlier. We shall be talking about 11 | the other useful data structure, hash maps, later. 12 | 13 | ## Further information 14 | 15 | - [Storing Lists of Values with Vectors](https://doc.rust-lang.org/book/ch08-01-vectors.html) 16 | - [`iter_mut`](https://doc.rust-lang.org/std/primitive.slice.html#method.iter_mut) 17 | - [`map`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.map) 18 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/15_traits/traits5.rs: -------------------------------------------------------------------------------- 1 | trait SomeTrait { 2 | fn some_function(&self) -> bool { 3 | true 4 | } 5 | } 6 | 7 | trait OtherTrait { 8 | fn other_function(&self) -> bool { 9 | true 10 | } 11 | } 12 | 13 | struct SomeStruct; 14 | impl SomeTrait for SomeStruct {} 15 | impl OtherTrait for SomeStruct {} 16 | 17 | struct OtherStruct; 18 | impl SomeTrait for OtherStruct {} 19 | impl OtherTrait for OtherStruct {} 20 | 21 | // TODO: Fix the compiler error by only changing the signature of this function. 22 | fn some_func(item: impl SomeTrait + OtherTrait) -> bool { 23 | item.some_function() && item.other_function() 24 | } 25 | 26 | fn main() { 27 | // You can optionally experiment here. 28 | } 29 | 30 | #[cfg(test)] 31 | mod tests { 32 | use super::*; 33 | 34 | #[test] 35 | fn test_some_func() { 36 | assert!(some_func(SomeStruct)); 37 | assert!(some_func(OtherStruct)); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/tidwall/match/README.md: -------------------------------------------------------------------------------- 1 | Match 2 | ===== 3 | Build Status 4 | GoDoc 5 | 6 | Match is a very simple pattern matcher where '*' matches on any 7 | number characters and '?' matches on any one character. 8 | 9 | Installing 10 | ---------- 11 | 12 | ``` 13 | go get -u github.com/tidwall/match 14 | ``` 15 | 16 | Example 17 | ------- 18 | 19 | ```go 20 | match.Match("hello", "*llo") 21 | match.Match("jello", "?ello") 22 | match.Match("hello", "h*o") 23 | ``` 24 | 25 | 26 | Contact 27 | ------- 28 | Josh Baker [@tidwall](http://twitter.com/tidwall) 29 | 30 | License 31 | ------- 32 | Redcon source code is available under the MIT [License](/LICENSE). 33 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basic/pb/person/person.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; // 告诉编译器用`proto3`来解读 2 | 3 | package person; 4 | 5 | option go_package = "grpc/pb/person;person"; 6 | 7 | import "home/home.proto"; 8 | 9 | message Person{ 10 | string name = 1; 11 | int32 age = 2; 12 | 13 | enum SEX{ 14 | option allow_alias = true; 15 | 16 | MALE = 0; // 枚举类型必须有0值 17 | FEMALE = 1; 18 | GIRL = 1; 19 | OTHER = 2; 20 | } 21 | 22 | SEX sex = 3; 23 | 24 | oneof TestOneOf{ 25 | string one = 6; 26 | string two = 7; 27 | string three = 8; 28 | } 29 | 30 | 31 | home.Home i_home = 9; 32 | 33 | reserved "test_map", "test"; // 保留字 34 | reserved 5; //保留标识 35 | } 36 | 37 | 38 | service SearchService { 39 | rpc Search(Person) returns (Person); // 传统的 即刻响应的 40 | rpc SearchI(stream Person) returns (Person); // 入参为流 41 | rpc SearchO(stream Person) returns (stream Person); // 出参为流 42 | rpc SearchIO(stream Person) returns (stream Person); // 出入均为流 43 | } -------------------------------------------------------------------------------- /Rust/rustlings/exercises/03_if/if2.rs: -------------------------------------------------------------------------------- 1 | // TODO: Fix the compiler error on this function. 2 | fn foo_if_fizz(fizzish: &str) -> &str { 3 | if fizzish == "fizz" { 4 | "foo" 5 | } else if fizzish == "fuzz" { 6 | "bar" 7 | } else { 8 | "baz" 9 | } 10 | } 11 | 12 | fn main() { 13 | // You can optionally experiment here. 14 | } 15 | 16 | // TODO: Read the tests to understand the desired behavior. 17 | // Make all tests pass without changing them. 18 | #[cfg(test)] 19 | mod tests { 20 | use super::*; 21 | 22 | #[test] 23 | fn foo_for_fizz() { 24 | // This means that calling `foo_if_fizz` with the argument "fizz" should return "foo". 25 | assert_eq!(foo_if_fizz("fizz"), "foo"); 26 | } 27 | 28 | #[test] 29 | fn bar_for_fuzz() { 30 | assert_eq!(foo_if_fizz("fuzz"), "bar"); 31 | } 32 | 33 | #[test] 34 | fn default_to_baz() { 35 | assert_eq!(foo_if_fizz("literally anything"), "baz"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /数据库/Redis/5. Redis的发布和订阅.md: -------------------------------------------------------------------------------- 1 | # Redis的发布和订阅 2 | 3 | ## 介绍 4 | 5 | Redis 发布订阅 (pub/sub) 是一种消息通信模式:发送者 (pub) 发送消息,订阅者 (sub) 接收消息。 6 | Redis 客户端可以订阅任意数量的频道。 7 | 8 | ## Redis的发布和订阅 9 | 10 | 客户端可以订阅频道如下图 11 | ![](https://raw.githubusercontent.com/Swiftie13st/Figurebed/main/img/202209291607292.png) 12 | 13 | 当给这个频道发布消息后,消息就会发送给订阅的客户端 14 | ![](https://raw.githubusercontent.com/Swiftie13st/Figurebed/main/img/202209291608676.png) 15 | 16 | ## 发布订阅命令行实现 17 | 18 | 1、 打开一个客户端订阅channel1 19 | 20 | ```sql 21 | SUBSCRIBE channel1 22 | ``` 23 | 24 | ![](https://raw.githubusercontent.com/Swiftie13st/Figurebed/main/img/202209291609467.png) 25 | 26 | 2、打开另一个客户端,给channel1发布消息hello 27 | 28 | ```sql 29 | publish channel1 hello 30 | ``` 31 | 32 | ![](https://raw.githubusercontent.com/Swiftie13st/Figurebed/main/img/202209291610551.png) 33 | 返回的1是订阅者数量 34 | 35 | 3、打开第一个客户端可以看到发送的消息 36 | ![](https://raw.githubusercontent.com/Swiftie13st/Figurebed/main/img/202209291611847.png) 37 | 注:发布的消息没有持久化,如果在订阅的客户端收不到hello,只能收到订阅后发布的消息 -------------------------------------------------------------------------------- /Rust/rustlings/exercises/15_traits/traits4.rs: -------------------------------------------------------------------------------- 1 | trait Licensed { 2 | fn licensing_info(&self) -> String { 3 | "Default license".to_string() 4 | } 5 | } 6 | 7 | struct SomeSoftware; 8 | struct OtherSoftware; 9 | 10 | impl Licensed for SomeSoftware {} 11 | impl Licensed for OtherSoftware {} 12 | 13 | // TODO: Fix the compiler error by only changing the signature of this function. 14 | fn compare_license_types(software1: impl Licensed, software2: impl Licensed) -> bool { 15 | software1.licensing_info() == software2.licensing_info() 16 | } 17 | 18 | fn main() { 19 | // You can optionally experiment here. 20 | } 21 | 22 | #[cfg(test)] 23 | mod tests { 24 | use super::*; 25 | 26 | #[test] 27 | fn compare_license_information() { 28 | assert!(compare_license_types(SomeSoftware, OtherSoftware)); 29 | } 30 | 31 | #[test] 32 | fn compare_license_information_backwards() { 33 | assert!(compare_license_types(OtherSoftware, SomeSoftware)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/15_ChannelDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | //// 声明一个传递整型的管道 7 | //var ch1 chan int 8 | //// 声明一个传递布尔类型的管道 9 | //var ch2 chan bool 10 | //// 声明一个传递int切片的管道 11 | //var ch3 chan []int 12 | // 13 | //// 创建一个能存储10个int类型的数据管道 14 | //ch1 = make(chan int, 10) 15 | //// 创建一个能存储4个bool类型的数据管道 16 | //ch2 = make(chan bool, 4) 17 | //// 创建一个能存储3个[]int切片类型的管道 18 | //ch3 = make(chan []int, 3) 19 | 20 | 21 | // 创建管道 22 | ch := make(chan int, 3) 23 | 24 | // 给管道里面存储数据 25 | ch <- 10 26 | ch <- 21 27 | ch <- 32 28 | 29 | // 获取管道里面的内容 30 | a := <- ch 31 | fmt.Println("打印出管道的值:", a) 32 | fmt.Println("打印出管道的值:", <- ch) 33 | fmt.Println("打印出管道的值:", <- ch) 34 | 35 | // 管道的值、容量、长度 36 | fmt.Printf("地址:%v 容量:%v 长度:%v \n", ch, cap(ch), len(ch)) 37 | 38 | // 管道的类型 39 | fmt.Printf("%T \n", ch) 40 | 41 | // 管道阻塞(当没有数据的时候取,会出现阻塞,同时当管道满了,继续存也会) 42 | <- ch // 没有数据取,出现阻塞 43 | ch <- 10 44 | ch <- 10 45 | ch <- 10 46 | ch <- 10 // 管道满了,继续存,也出现阻塞 47 | 48 | } 49 | -------------------------------------------------------------------------------- /Golang/Code/Gin/Params/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "Gin/Params/functions" 5 | "net/http" 6 | 7 | "github.com/gin-gonic/gin" 8 | ) 9 | 10 | func main() { 11 | // 创建一个默认的路由引擎 12 | r := gin.Default() 13 | 14 | r.GET("/", func(c *gin.Context) { 15 | c.String(200, "Hello World!") 16 | }) 17 | 18 | r.GET("/user/:name", func(c *gin.Context) { 19 | name := c.Param("name") 20 | c.String(http.StatusOK, "Hello %s", name) 21 | }) 22 | 23 | functions.Book(r) 24 | 25 | r.LoadHTMLGlob("templates/**/*") 26 | // r.LoadHTMLFiles("templates/posts/index.html", "templates/users/index.html") 27 | r.GET("/posts/index", func(c *gin.Context) { 28 | c.HTML(http.StatusOK, "posts/index.html", gin.H{ 29 | "title": "posts/index", 30 | }) 31 | }) 32 | 33 | r.GET("users/index", func(c *gin.Context) { 34 | c.HTML(http.StatusOK, "users/index.html", gin.H{ 35 | "title": "users/index", 36 | }) 37 | }) 38 | 39 | functions.Params(r) 40 | 41 | r.Run(":9003") // listen and serve on 0.0.0.0:PORT(default:8080) 42 | 43 | } 44 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/go.sum: -------------------------------------------------------------------------------- 1 | github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= 2 | github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= 3 | github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= 4 | github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= 5 | github.com/jinzhu/now v1.1.4/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= 6 | github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= 7 | github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= 8 | gorm.io/driver/mysql v1.4.1 h1:4InA6SOaYtt4yYpV1NF9B2kvUKe9TbvUd1iWrvxnjic= 9 | gorm.io/driver/mysql v1.4.1/go.mod h1:sSIebwZAVPiT+27jK9HIwvsqOGKx3YMPmrA3mBJR10c= 10 | gorm.io/gorm v1.23.8/go.mod h1:l2lP/RyAtc1ynaTjFksBde/O8v9oOGIApu2/xRitmZk= 11 | gorm.io/gorm v1.24.0 h1:j/CoiSm6xpRpmzbFJsQHYj+I8bGYWLXVHeYEyyKlF74= 12 | gorm.io/gorm v1.24.0/go.mod h1:DVrVomtaYTbqs7gB/x2uVvqnXzv0nqjB396B8cG4dBA= 13 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/go_basic/pointer.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // 指针取值 7 | var c = 20 8 | // 得到c的地址,赋值给d 9 | var d = &c 10 | // 打印d的值,也就是c的地址 11 | fmt.Println(d) 12 | // 取出d指针所对应的值 13 | fmt.Println(*d) 14 | // c对应地址的值,改成30 15 | *d = 30 16 | // c已经变成30了 17 | fmt.Println(c) 18 | 19 | x := 5 20 | fn4(x) 21 | fmt.Println(x) 22 | fn5(&x) 23 | fmt.Println(x) 24 | 25 | // var userInfo = make(map[string]string) 26 | // userInfo["userName"] = "zhangsan" 27 | // fmt.Println(userInfo) 28 | 29 | // var array = make([]int, 4, 4) 30 | // array[0] = 1 31 | // fmt.Println(array) 32 | // // 指针变量初始化 33 | // var a *int 34 | // *a = 100 35 | // fmt.Println(a) 36 | 37 | // 使用new关键字创建指针 38 | aPoint := new(int) 39 | bPoint := new(bool) 40 | fmt.Printf("%T \n", aPoint) 41 | fmt.Printf("%T \n", bPoint) 42 | fmt.Println(*aPoint) 43 | fmt.Println(*bPoint) 44 | } 45 | 46 | // 这个类似于值传递 47 | func fn4(x int) { 48 | x = 10 49 | } 50 | 51 | // 这个类似于引用数据类型 52 | func fn5(x *int) { 53 | *x = 20 54 | } 55 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/go_basic/var.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func getUserInfo() (string, int) { 6 | return "zhangsan", 10 7 | } 8 | 9 | func main() { 10 | fmt.Println("hello") 11 | fmt.Print("A", "B", "C") 12 | fmt.Println() 13 | var a = 10 14 | fmt.Printf("%d", a) 15 | 16 | var name = "zhangsan1" 17 | var name2 string = "zhangsan2" 18 | name3 := "zhangsan3" 19 | 20 | fmt.Println(name) 21 | fmt.Println(name2) 22 | fmt.Println(name3) 23 | fmt.Printf("name1=%v name2=%v name3=%v \n", name, name2, name3) 24 | 25 | // var ( 26 | // username string 27 | // age int 28 | // sex string 29 | // ) 30 | // username = "zhangshan" 31 | // age = 10 32 | // sex = "男" 33 | 34 | // var ( 35 | // username = "zhangsan" 36 | // age = 10 37 | // sex = "男" 38 | // ) 39 | username, age, sex := "zhangsan", 10, "男" 40 | 41 | fmt.Println(username, age, sex) 42 | 43 | var username1, age1 = getUserInfo() 44 | fmt.Println(username1, age1) 45 | var username2, _ = getUserInfo() 46 | fmt.Println(username2) 47 | 48 | } 49 | -------------------------------------------------------------------------------- /K8s/基础/Ingress.md: -------------------------------------------------------------------------------- 1 | # Ingress 2 | 3 | [Ingress | Kubernetes](https://kubernetes.io/zh-cn/docs/concepts/services-networking/ingress/) 4 | 5 | 原来我们需要将端口号对外暴露,通过 ip + 端口号就可以进行访问 6 | 7 | 原来是使用Service中的NodePort来实现 8 | 9 | - 在每个节点上都会启动端口 10 | - 在访问的时候通过任何节点,通过ip + 端口号就能实现访问 11 | 12 | 但是NodePort还存在一些缺陷 13 | 14 | - 因为端口不能重复,所以每个端口只能使用一次,一个端口对应一个应用 15 | - 实际访问中都是用域名,根据不同域名跳转到不同端口服务中 16 | 17 | ngress 为外部访问集群提供了一个 **统一** 入口,避免了对外暴露集群端口; 18 | 功能类似 Nginx,可以根据域名、路径把请求转发到不同的 Service。 19 | 可以配置 https 20 | 21 | ## 跟 LoadBalancer 有什么区别? 22 | 23 | LoadBalancer 需要对外暴露端口,不安全; 24 | 无法根据域名、路径转发流量到不同 Service,多个 Service 则需要开多个 LoadBalancer; 25 | 功能单一,无法配置 https 26 | 27 | ![](https://raw.githubusercontent.com/Swiftie13st/Figurebed/main/img/202305262246313.png) 28 | 29 | ## Ingress和Pod关系 30 | 31 | pod 和 ingress 是通过service进行关联的,而ingress作为统一入口,由service关联一组pod中 32 | 33 | - 首先service就是关联我们的pod 34 | - 然后ingress作为入口,首先需要到service,然后发现一组pod 35 | - 发现pod后,就可以做负载均衡等操作 36 | 37 | **工作流程**: 38 | 39 | ![](https://raw.githubusercontent.com/Swiftie13st/Figurebed/main/img/202305262248729.png) 40 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/12_StructDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | /** 6 | 定义一个人结构体 7 | */ 8 | type Person struct { 9 | name string 10 | age int 11 | sex string 12 | 13 | 14 | } 15 | func main() { 16 | // 实例化结构体 17 | var person Person 18 | person.name = "张三" 19 | person.age = 20 20 | person.sex = "男" 21 | fmt.Printf("%#v", person) 22 | 23 | // 第二种方式实例化 24 | var person2 = new(Person) 25 | person2.name = "李四" 26 | person2.age = 30 27 | person2.sex = "女" 28 | fmt.Printf("%#v", person2) 29 | 30 | // 第三种方式实例化 31 | var person3 = &Person{} 32 | person3.name = "赵四" 33 | person3.age = 28 34 | person3.sex = "男" 35 | fmt.Printf("%#v", person3) 36 | 37 | // 第四种方式初始化 38 | var person4 = Person{ 39 | name: "张三", 40 | age: 10, 41 | sex: "女", 42 | } 43 | fmt.Printf("%#v", person4) 44 | 45 | // 第五种方式初始化 46 | var person5 = &Person{ 47 | name: "孙五", 48 | age: 10, 49 | sex: "女", 50 | } 51 | fmt.Printf("%#v", person5) 52 | 53 | var person6 = Person{ 54 | "张三", 55 | 5, 56 | "女", 57 | } 58 | fmt.Println(person6) 59 | 60 | } 61 | -------------------------------------------------------------------------------- /Golang/learning_note/Gin框架/基础.md: -------------------------------------------------------------------------------- 1 | # Gin 2 | 3 | ## 安装 4 | ``` 5 | go get -u -v github.com/gin-gonic/gin 6 | ``` 7 | ## 第一个Gin程序 8 | ```go 9 | package main 10 | 11 | import ( 12 | "net/http" 13 | 14 | "github.com/gin-gonic/gin" 15 | ) 16 | 17 | func main() { 18 | // 创建一个默认的路由引擎 19 | r := gin.Default() 20 | r.GET("/", func(c *gin.Context) { 21 | c.String(200, "Hello World!") 22 | }) 23 | 24 | // GET:请求方式;/hello:请求的路径 25 | // 当客户端以GET方法请求/hello路径时,会执行后面的匿名函数 26 | r.GET("/hello", func(c *gin.Context) { 27 | // c.JSON:返回JSON格式的数据 28 | c.JSON(200, gin.H{ 29 | "message": "Hello world!", 30 | }) 31 | }) 32 | 33 | r.GET("/user/:name", func(c *gin.Context) { 34 | name := c.Param("name") 35 | c.String(http.StatusOK, "Hello %s", name) 36 | }) 37 | 38 | r.Run(":9003") // listen and serve on 0.0.0.0:PORT(default:8080) 39 | 40 | } 41 | ``` 42 | 1. 首先,我们使用了`gin.Default()`生成了一个实例,这个实例即 WSGI 应用程序。 43 | 2. 接下来,我们使用`r.Get("/", ...)`声明了一个路由,告诉 Gin 什么样的URL 能触发传入的函数,这个函数返回我们想要显示在用户浏览器中的信息。 44 | 3. 最后用 `r.Run()`函数来让应用运行在本地服务器上,默认监听端口是 _8080_,可以传入参数设置端口,例如`r.Run(":9003")`即运行在 _9003_ 端口。 -------------------------------------------------------------------------------- /Rust/rustlings/exercises/13_error_handling/errors3.rs: -------------------------------------------------------------------------------- 1 | // This is a program that is trying to use a completed version of the 2 | // `total_cost` function from the previous exercise. It's not working though! 3 | // Why not? What should we do to fix it? 4 | 5 | use std::num::ParseIntError; 6 | 7 | // Don't change this function. 8 | fn total_cost(item_quantity: &str) -> Result { 9 | let processing_fee = 1; 10 | let cost_per_item = 5; 11 | let qty = item_quantity.parse::()?; 12 | 13 | Ok(qty * cost_per_item + processing_fee) 14 | } 15 | 16 | // TODO: Fix the compiler error by changing the signature and body of the 17 | // `main` function. 18 | fn main() -> Result<(), ParseIntError> { 19 | let mut tokens = 100; 20 | let pretend_user_input = "8"; 21 | 22 | // Don't change this line. 23 | let cost = total_cost(pretend_user_input)?; 24 | 25 | if cost > tokens { 26 | println!("You can't afford that many!"); 27 | } else { 28 | tokens -= cost; 29 | println!("You now have {tokens} tokens."); 30 | } 31 | Ok(()) 32 | } 33 | -------------------------------------------------------------------------------- /Golang/Code/Gin/GORM/V1/basic.go: -------------------------------------------------------------------------------- 1 | package V1 2 | 3 | import ( 4 | "fmt" 5 | "github.com/jinzhu/gorm" 6 | _ "github.com/jinzhu/gorm/dialects/mysql" 7 | ) 8 | 9 | // GORM v1 10 | 11 | // UserInfo 用户信息 --> 数据表 12 | type UserInfo struct { 13 | ID uint 14 | Name string 15 | Gender string 16 | Hobby string 17 | } 18 | 19 | func main() { 20 | // 连接MySQL数据库 21 | db, err := gorm.Open("mysql", "root:abc123@(127.0.0.1:3306)/db1?charset=utf8mb4&parseTime=True&loc=Local") 22 | if err != nil { 23 | panic(err) 24 | } 25 | defer func(db *gorm.DB) { 26 | err := db.Close() 27 | if err != nil { 28 | 29 | } 30 | }(db) 31 | 32 | // 创建表 自动迁移(把结构体和数据表进行对应) 33 | db.AutoMigrate(&UserInfo{}) 34 | 35 | u1 := UserInfo{1, "七米", "男", "篮球"} 36 | u2 := UserInfo{2, "沙河娜扎", "女", "足球"} 37 | // 创建记录 38 | db.Create(&u1) 39 | db.Create(&u2) 40 | // 查询 41 | var u = new(UserInfo) 42 | db.First(u) 43 | fmt.Printf("%#v\n", u) 44 | 45 | var uu UserInfo 46 | db.Find(&uu, "hobby=?", "足球") 47 | fmt.Printf("%#v\n", uu) 48 | 49 | // 更新 50 | db.Model(&u).Update("hobby", "双色球") 51 | // 删除 52 | db.Delete(&u) 53 | } 54 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/关系/one2one.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "gorm.io/gorm" 6 | ) 7 | 8 | // has one 9 | 10 | type Dog struct { 11 | gorm.Model 12 | Name string 13 | GoddessID uint // 狗链子 14 | Goddess Goddess 15 | } 16 | 17 | type Goddess struct { 18 | gorm.Model 19 | Name string 20 | } 21 | 22 | func One2One() { 23 | d := Dog{ 24 | Model: gorm.Model{ 25 | ID: 1, 26 | }, 27 | } 28 | d2 := Dog{ 29 | Model: gorm.Model{ 30 | ID: 2, 31 | }, 32 | } 33 | 34 | g := Goddess{ 35 | Model: gorm.Model{ 36 | ID: 1, 37 | }, 38 | } 39 | g2 := Goddess{ 40 | Model: gorm.Model{ 41 | ID: 2, 42 | }, 43 | } 44 | GLOBAL_DB.Model(&d).Association("Goddess").Append(&g) // 添加关联 45 | GLOBAL_DB.Model(&d2).Association("Goddess").Append(&g2) // 添加关联 46 | GLOBAL_DB.Model(&d).Association("Goddess").Delete(&g) // 删除关联 47 | GLOBAL_DB.Model(&d).Association("Goddess").Replace(&g, &g2) // 替换关联 48 | GLOBAL_DB.Model(&d).Association("Goddess").Clear() // 清空关联 49 | res := GLOBAL_DB.Model(&d2).Association("Goddess").Count() // 关联计数 50 | fmt.Println(res) 51 | } 52 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/shopspring/decimal/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Decimal v1.2.0 2 | 3 | #### BREAKING 4 | - Drop support for Go version older than 1.7 [#172](https://github.com/shopspring/decimal/pull/172) 5 | 6 | #### FEATURES 7 | - Add NewFromInt and NewFromInt32 initializers [#72](https://github.com/shopspring/decimal/pull/72) 8 | - Add support for Go modules [#157](https://github.com/shopspring/decimal/pull/157) 9 | - Add BigInt, BigFloat helper methods [#171](https://github.com/shopspring/decimal/pull/171) 10 | 11 | #### ENHANCEMENTS 12 | - Memory usage optimization [#160](https://github.com/shopspring/decimal/pull/160) 13 | - Updated travis CI golang versions [#156](https://github.com/shopspring/decimal/pull/156) 14 | - Update documentation [#173](https://github.com/shopspring/decimal/pull/173) 15 | - Improve code quality [#174](https://github.com/shopspring/decimal/pull/174) 16 | 17 | #### BUGFIXES 18 | - Revert remove insignificant digits [#159](https://github.com/shopspring/decimal/pull/159) 19 | - Remove 15 interval for RoundCash [#166](https://github.com/shopspring/decimal/pull/166) 20 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/16_lifetimes/README.md: -------------------------------------------------------------------------------- 1 | # Lifetimes 2 | 3 | Lifetimes tell the compiler how to check whether references live long 4 | enough to be valid in any given situation. For example lifetimes say 5 | "make sure parameter 'a' lives as long as parameter 'b' so that the return 6 | value is valid". 7 | 8 | They are only necessary on borrows, i.e. references, 9 | since copied parameters or moves are owned in their scope and cannot 10 | be referenced outside. Lifetimes mean that calling code of e.g. functions 11 | can be checked to make sure their arguments are valid. Lifetimes are 12 | restrictive of their callers. 13 | 14 | If you'd like to learn more about lifetime annotations, the 15 | [lifetimekata](https://tfpk.github.io/lifetimekata/) project 16 | has a similar style of exercises to Rustlings, but is all about 17 | learning to write lifetime annotations. 18 | 19 | ## Further information 20 | 21 | - [Lifetimes (in Rust By Example)](https://doc.rust-lang.org/stable/rust-by-example/scope/lifetime.html) 22 | - [Validating References with Lifetimes](https://doc.rust-lang.org/book/ch10-03-lifetime-syntax.html) 23 | -------------------------------------------------------------------------------- /Golang/Code/advanceCode/mutex/lx/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "math/rand" 6 | "sync" 7 | ) 8 | 9 | var wg sync.WaitGroup 10 | 11 | //计算int64随机数各位数和 12 | func sumInt64(x int64) int64 { 13 | var sum int64 = 0 14 | for x > 0 { 15 | sum += x % 10 16 | x /= 10 17 | } 18 | return sum 19 | } 20 | 21 | func getRand64(jobChan chan<- int64) { 22 | defer wg.Done() 23 | for i := 0; i < 24; i++ { 24 | var randNum int64 = rand.Int63() 25 | // fmt.Println(randNum) 26 | jobChan <- randNum 27 | } 28 | close(jobChan) 29 | } 30 | 31 | func getResult(jobChan <-chan int64, resultChan chan<- int64) { 32 | defer wg.Done() 33 | i := <-jobChan 34 | resultChan <- sumInt64(i) 35 | } 36 | 37 | func main() { 38 | // 使用无缓冲通道,则不能使用sync.Wait()等待。因为如果进行等待,则有一个通道既无法读,也无法写 39 | jobChan := make(chan int64, 111) 40 | resultChan := make(chan int64, 111) 41 | wg.Add(1) 42 | go getRand64(jobChan) 43 | 44 | for i := 0; i < 24; i++ { 45 | wg.Add(1) 46 | go getResult(jobChan, resultChan) 47 | 48 | } 49 | wg.Wait() 50 | close(resultChan) 51 | for i := range resultChan { 52 | fmt.Println(i) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/12_options/README.md: -------------------------------------------------------------------------------- 1 | # Options 2 | 3 | Type Option represents an optional value: every Option is either Some and contains a value, or None, and does not. 4 | Option types are very common in Rust code, as they have a number of uses: 5 | 6 | - Initial values 7 | - Return values for functions that are not defined over their entire input range (partial functions) 8 | - Return value for otherwise reporting simple errors, where None is returned on error 9 | - Optional struct fields 10 | - Struct fields that can be loaned or "taken" 11 | - Optional function arguments 12 | - Nullable pointers 13 | - Swapping things out of difficult situations 14 | 15 | ## Further Information 16 | 17 | - [Option Enum Format](https://doc.rust-lang.org/book/ch10-01-syntax.html#in-enum-definitions) 18 | - [Option Module Documentation](https://doc.rust-lang.org/std/option/) 19 | - [Option Enum Documentation](https://doc.rust-lang.org/std/option/enum.Option.html) 20 | - [if let](https://doc.rust-lang.org/rust-by-example/flow_control/if_let.html) 21 | - [while let](https://doc.rust-lang.org/rust-by-example/flow_control/while_let.html) 22 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/one2one.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "gorm.io/gorm" 6 | ) 7 | 8 | // has one 9 | 10 | //type Dog struct { 11 | // gorm.Model 12 | // Name string 13 | // GoddessID uint // 狗链子 14 | // Goddess Goddess 15 | //} 16 | // 17 | //type Goddess struct { 18 | // gorm.Model 19 | // Name string 20 | //} 21 | 22 | func One2One() { 23 | d := Dog{ 24 | Model: gorm.Model{ 25 | ID: 1, 26 | }, 27 | } 28 | d2 := Dog{ 29 | Model: gorm.Model{ 30 | ID: 2, 31 | }, 32 | } 33 | 34 | g := Goddess{ 35 | Model: gorm.Model{ 36 | ID: 1, 37 | }, 38 | } 39 | g2 := Goddess{ 40 | Model: gorm.Model{ 41 | ID: 2, 42 | }, 43 | } 44 | GLOBAL_DB.Model(&d).Association("Goddess").Append(&g) // 添加关联 45 | GLOBAL_DB.Model(&d2).Association("Goddess").Append(&g2) // 添加关联 46 | GLOBAL_DB.Model(&d).Association("Goddess").Delete(&g) // 删除关联 47 | GLOBAL_DB.Model(&d).Association("Goddess").Replace(&g, &g2) // 替换关联 48 | GLOBAL_DB.Model(&d).Association("Goddess").Clear() // 清空关联 49 | res := GLOBAL_DB.Model(&d2).Association("Goddess").Count() // 关联计数 50 | fmt.Println(res) 51 | } 52 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/quizzes/quiz1.rs: -------------------------------------------------------------------------------- 1 | // This is a quiz for the following sections: 2 | // - Variables 3 | // - Functions 4 | // - If 5 | // 6 | // Mary is buying apples. The price of an apple is calculated as follows: 7 | // - An apple costs 2 rustbucks. 8 | // - However, if Mary buys more than 40 apples, the price of each apple in the 9 | // entire order is reduced to only 1 rustbuck! 10 | 11 | // TODO: Write a function that calculates the price of an order of apples given 12 | // the quantity bought. 13 | fn calculate_price_of_apples(buying_cnt: i32) -> i32 { 14 | if buying_cnt > 40 { 15 | buying_cnt 16 | } else { 17 | buying_cnt * 2 18 | } 19 | } 20 | 21 | fn main() { 22 | // You can optionally experiment here. 23 | } 24 | 25 | // Don't change the tests! 26 | #[cfg(test)] 27 | mod tests { 28 | use super::*; 29 | 30 | #[test] 31 | fn verify_test() { 32 | assert_eq!(calculate_price_of_apples(35), 70); 33 | assert_eq!(calculate_price_of_apples(40), 80); 34 | assert_eq!(calculate_price_of_apples(41), 41); 35 | assert_eq!(calculate_price_of_apples(65), 65); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/04_primitive_types/primitive_types2.rs: -------------------------------------------------------------------------------- 1 | // Characters (`char`) 2 | 3 | fn main() { 4 | // Note the _single_ quotes, these are different from the double quotes 5 | // you've been seeing around. 6 | let my_first_initial = 'C'; 7 | if my_first_initial.is_alphabetic() { 8 | println!("Alphabetical!"); 9 | } else if my_first_initial.is_numeric() { 10 | println!("Numerical!"); 11 | } else { 12 | println!("Neither alphabetic nor numeric!"); 13 | } 14 | 15 | // TODO: Analogous to the example before, declare a variable called `your_character` 16 | // below with your favorite character. 17 | // Try a letter, try a digit (in single quotes), try a special character, try a character 18 | // from a different language than your own, try an emoji 😉 19 | // let your_character = ''; 20 | 21 | let your_character = '😊'; 22 | 23 | if your_character.is_alphabetic() { 24 | println!("Alphabetical!"); 25 | } else if your_character.is_numeric() { 26 | println!("Numerical!"); 27 | } else { 28 | println!("Neither alphabetic nor numeric!"); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/sortDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "sort" 6 | ) 7 | 8 | func main() { 9 | 10 | // 编写冒泡排序 11 | var numSlice = []int{9,8,4,5,1,7} 12 | for i := 0; i < len(numSlice); i++ { 13 | flag := false 14 | for j := 0; j < len(numSlice) - i - 1; j++ { 15 | if numSlice[j] > numSlice[j+1] { 16 | var temp = numSlice[j+1] 17 | numSlice[j+1] = numSlice[j] 18 | numSlice[j] = temp 19 | flag = true 20 | } 21 | } 22 | if !flag { 23 | break 24 | } 25 | } 26 | fmt.Println(numSlice) 27 | 28 | // 编写选择排序 29 | var numSlice2 = []int{9,8,4,5,1,7} 30 | for i := 0; i < len(numSlice2); i++ { 31 | for j := i + 1; j < len(numSlice2); j++ { 32 | if numSlice2[i] > numSlice2[j] { 33 | var temp = numSlice2[i] 34 | numSlice2[i] = numSlice2[j] 35 | numSlice2[j] = temp 36 | } 37 | } 38 | } 39 | fmt.Println(numSlice2) 40 | 41 | // 调用sort方法 42 | var numSlice3 = []int{9,8,4,5,1,7} 43 | sort.Ints(numSlice3) 44 | fmt.Println(numSlice3) 45 | 46 | // 逆序排列 47 | var numSlice4 = []int{9,8,4,5,1,7} 48 | sort.Sort(sort.Reverse(sort.IntSlice(numSlice4))) 49 | fmt.Println(numSlice4) 50 | } 51 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/18_iterators/iterators1.rs: -------------------------------------------------------------------------------- 1 | // When performing operations on elements within a collection, iterators are 2 | // essential. This module helps you get familiar with the structure of using an 3 | // iterator and how to go through elements within an iterable collection. 4 | 5 | fn main() { 6 | // You can optionally experiment here. 7 | } 8 | 9 | #[cfg(test)] 10 | mod tests { 11 | #[test] 12 | fn iterators() { 13 | let my_fav_fruits = ["banana", "custard apple", "avocado", "peach", "raspberry"]; 14 | 15 | // TODO: Create an iterator over the array. 16 | let mut fav_fruits_iterator = my_fav_fruits.iter(); 17 | 18 | assert_eq!(fav_fruits_iterator.next(), Some(&"banana")); 19 | assert_eq!(fav_fruits_iterator.next(), Some(&"custard apple")); // TODO: Replace `todo!()` 20 | assert_eq!(fav_fruits_iterator.next(), Some(&"avocado")); 21 | assert_eq!(fav_fruits_iterator.next(), Some(&"peach")); // TODO: Replace `todo!()` 22 | assert_eq!(fav_fruits_iterator.next(), Some(&"raspberry")); 23 | assert_eq!(fav_fruits_iterator.next(), None); // TODO: Replace `todo!()` 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/22_clippy/clippy3.rs: -------------------------------------------------------------------------------- 1 | // Here are some more easy Clippy fixes so you can see its utility 📎 2 | // TODO: Fix all the Clippy lints. 3 | 4 | #[rustfmt::skip] 5 | #[allow(unused_variables, unused_assignments)] 6 | fn main() { 7 | let my_option: Option<()> = None; 8 | if my_option.is_none() { 9 | println!("{:?}", my_option); 10 | } 11 | 12 | let my_arr = &[ 13 | -1, -2, -3, 14 | -4, -5, -6 15 | ]; 16 | println!("My array! Here it is: {my_arr:?}"); 17 | 18 | // let my_empty_vec = vec![1, 2, 3, 4, 5].resize(0, 5); 19 | // println!("This Vec is empty, see? {my_empty_vec:?}"); 20 | 21 | 22 | let mut my_empty_vec = vec![1, 2, 3, 4, 5]; 23 | // `resize` mutates a vector instead of returning a new one. 24 | // `resize(0, …)` clears a vector, so it is better to use `clear`. 25 | my_empty_vec.clear(); 26 | println!("This Vec is empty, see? {my_empty_vec:?}"); 27 | 28 | let mut value_a = 45; 29 | let mut value_b = 66; 30 | // Let's swap these two! 31 | std::mem::swap(&mut value_a, &mut value_b); 32 | 33 | 34 | println!("value a: {value_a}; value b: {value_b}"); 35 | } 36 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/09_strings/strings4.rs: -------------------------------------------------------------------------------- 1 | // Calls of this function should be replaced with calls of `string_slice` or `string`. 2 | fn placeholder() {} 3 | 4 | fn string_slice(arg: &str) { 5 | println!("{arg}"); 6 | } 7 | 8 | fn string(arg: String) { 9 | println!("{arg}"); 10 | } 11 | 12 | // TODO: Here are a bunch of values - some are `String`, some are `&str`. 13 | // Your task is to replace `placeholder(…)` with either `string_slice(…)` 14 | // or `string(…)` depending on what you think each value is. 15 | fn main() { 16 | string_slice("blue"); 17 | 18 | string("red".to_string()); 19 | 20 | string(String::from("hi")); 21 | 22 | string("rust is fun!".to_owned()); 23 | 24 | string("nice weather".into()); 25 | 26 | string(format!("Interpolation {}", "Station")); 27 | 28 | // WARNING: This is byte indexing, not character indexing. 29 | // Character indexing can be done using `s.chars().nth(INDEX)`. 30 | string_slice(&String::from("abc")[0..1]); 31 | 32 | string_slice(" hello there ".trim()); 33 | 34 | string("Happy Monday!".replace("Mon", "Tues")); 35 | 36 | string("mY sHiFt KeY iS sTiCkY".to_lowercase()); 37 | } 38 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/关系/one2many.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "gorm.io/gorm" 6 | ) 7 | 8 | type Info struct { 9 | gorm.Model 10 | Money int 11 | DogID uint 12 | } 13 | 14 | type Dog struct { 15 | gorm.Model 16 | Name string 17 | GoddessID uint // 狗链子 18 | Info Info 19 | } 20 | 21 | type Goddess struct { 22 | gorm.Model 23 | Name string 24 | Dogs []Dog 25 | } 26 | 27 | func One2Many() { 28 | //d := Dog{ 29 | // Model: gorm.Model{ 30 | // ID: 1, 31 | // }, 32 | // Name: "Dog1", 33 | //} 34 | //d2 := Dog{ 35 | // Model: gorm.Model{ 36 | // ID: 2, 37 | // }, 38 | // Name: "Dog2", 39 | //} 40 | // 41 | //g := Goddess{ 42 | // Model: gorm.Model{ 43 | // ID: 1, 44 | // }, 45 | // Name: "G1", 46 | // Dogs: []Dog{d, d2}, 47 | //} 48 | // 49 | //_ = GLOBAL_DB.AutoMigrate(&Dog{}, &Goddess{}, &Info{}) 50 | // 51 | //GLOBAL_DB.Create(&g) 52 | 53 | var girl Goddess 54 | 55 | //GLOBAL_DB.Preload("Dogs.Info", "money > 100").Preload("Dogs", "name = ? ", "Dog1").First(&girl) 56 | 57 | GLOBAL_DB.Preload("Dogs", func(db *gorm.DB) *gorm.DB { 58 | return db.Joins("Info").Where("money > 100") 59 | }).First(&girl) 60 | fmt.Println(girl) 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/12_options/options2.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | // You can optionally experiment here. 3 | } 4 | 5 | #[cfg(test)] 6 | mod tests { 7 | #[test] 8 | fn simple_option() { 9 | let target = "rustlings"; 10 | let optional_target = Some(target); 11 | 12 | // TODO: Make this an if-let statement whose value is `Some`. 13 | if let Some(word) = optional_target { 14 | assert_eq!(word, target); 15 | } 16 | } 17 | 18 | #[test] 19 | fn layered_option() { 20 | let range = 10; 21 | let mut optional_integers: Vec> = vec![None]; 22 | 23 | for i in 1..=range { 24 | optional_integers.push(Some(i)); 25 | } 26 | 27 | let mut cursor = range; 28 | 29 | // TODO: Make this a while-let statement. Remember that `Vec::pop()` 30 | // adds another layer of `Option`. You can do nested pattern matching 31 | // in if-let and while-let statements. 32 | while let Some(Some(integer)) = optional_integers.pop() { 33 | assert_eq!(integer, cursor); 34 | cursor -= 1; 35 | } 36 | 37 | assert_eq!(cursor, 0); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Algorithm/时空复杂度.md: -------------------------------------------------------------------------------- 1 | 一般ACM或者笔试题的时间限制是1秒或2秒。 2 | 在这种情况下,C++代码中的操作次数控制在 $10^7 \sim 10^8$ 为最佳。 3 | 下面给出在不同数据范围下,代码的时间复杂度和算法该如何选择: 4 | 5 | $n \le 30$, 指数级别, dfs+剪枝,状态压缩dp 6 | $n \le 100$ => $O(n^3)$,floyd,dp,高斯消元 7 | $n \le 1000$ => $O(n^2)$,$O(n^2logn)$,dp,二分,朴素版Dijkstra、朴素版Prim、Bellman-Ford 8 | $n \le 10000$ => $O(n * \sqrt n)$,块状链表、分块、莫队 9 | $n \le 100000$ => $O(nlogn)$ => 各种sort,线段树、树状数组、set/map、heap、拓扑排序、dijkstra+heap、prim+heap、Kruskal、spfa、求凸包、求半平面交、二分、CDQ分治、整体二分、后缀数组、树链剖分、动态树 10 | $n \le 1000000$ => $O(n)$, 以及常数较小的 $O(nlogn)$ 算法 => 单调队列、 hash、双指针扫描、并查集,kmp、AC自动机,常数比较小的 $O(nlogn)$ 的做法:sort、树状数组、heap、dijkstra、spfa 11 | $n \le 10000000$ => $O(n)$,双指针扫描、kmp、AC自动机、线性筛素数 12 | $n \le 10^9$ => $O(\sqrt n)$,判断质数 13 | $n \le 10^{18}$ => $O(logn)$,最大公约数,快速幂,数位DP 14 | $n \le 10^{1000}$ => $O((logn)^2)$,高精度加减乘除 15 | $n \le 10^{100000}$ => $O(logk \times loglogk),k\text{表示位数}$,高精度加减、FFT/NTT 16 | 17 | 18 | ## 时间复杂度分析 19 | 1. 纯循环 20 | 2. 递归 (主定理) 21 | 3. 动态规划 = 状态数量$\times$状态转移的计算量 22 | 23 | 24 | ## 空间 25 | 1 Byte = 8 bit 26 | 1 KB = 1024 Byte 27 | 28 | int 4 Byte 29 | char 1Byte 30 | double, long long 8 Byte 31 | 32 | **递归也是需要空间的,递归调用了系统栈,快速排序使用了递归,所以空间复杂度是O(logn)** -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/15_ChannelDemo5.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func sayHello() { 6 | for i := 0; i < 10; i++ { 7 | fmt.Println("hello") 8 | } 9 | } 10 | func errTest() { 11 | // 捕获异常 12 | defer func() { 13 | if err := recover(); err != nil { 14 | fmt.Println("errTest发生错误") 15 | } 16 | }() 17 | var myMap map[int]string 18 | myMap[0] = "10" 19 | } 20 | func main() { 21 | 22 | //// 定义一种可读可写的管道 23 | //var ch = make(chan int, 2) 24 | //ch <- 10 25 | //<- ch 26 | // 27 | //// 管道声明为只写管道,只能够写入,不能读 28 | //var ch2 = make(chan<- int, 2) 29 | //ch2 <- 10 30 | // 31 | //// 声明一个只读管道 32 | //var ch3 = make(<-chan int, 2) 33 | //<- ch3 34 | 35 | intChan := make(chan int, 10) 36 | intChan <- 10 37 | intChan <- 12 38 | intChan <- 13 39 | stringChan := make(chan int, 10) 40 | stringChan <- 20 41 | stringChan <- 23 42 | stringChan <- 24 43 | 44 | // 每次循环的时候,会随机中一个chan中读取,其中for是死循环 45 | for { 46 | select { 47 | case v:= <- intChan: 48 | fmt.Println("从initChan中读取数据:", v) 49 | case v:= <- stringChan: 50 | fmt.Println("从stringChan中读取数据:", v) 51 | default: 52 | fmt.Println("所有的数据获取完毕") 53 | return 54 | } 55 | } 56 | 57 | 58 | 59 | } 60 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/StringDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "strings" 6 | ) 7 | 8 | func main() { 9 | var str = "hello world" 10 | var length = len(str) // 长度为11 11 | fmt.Println("字符串的长度为:" , length) 12 | 13 | // 中文占三个字符,所以长度为6 14 | var str2 = "你好" 15 | fmt.Println("文字的长度为:", len(str2)) 16 | 17 | fmt.Println("拼接字符串~~~") 18 | str3 := "你好" 19 | str4 := "golang" 20 | str5 := fmt.Sprintf("%v-%v", str3, str4) 21 | fmt.Println(str5) 22 | 23 | fmt.Println("切割字符串") 24 | str6 := "hello world" 25 | arr := strings.Split(str6, " ") 26 | fmt.Println(arr) 27 | 28 | fmt.Println("拼接字符串") 29 | newStr := strings.Join(arr, "*") 30 | fmt.Println(newStr) 31 | 32 | fmt.Println("判断字符串是否包含某个字符串") 33 | var str7 = "abcdefg" 34 | var str8 = "abc" 35 | var isContains bool = strings.Contains(str7, str8) 36 | fmt.Println(isContains) 37 | 38 | fmt.Println("前缀/后缀判断") 39 | isPrefix := strings.HasPrefix(str7, "abc") 40 | fmt.Println("是否包含指定前缀判断", isPrefix) 41 | 42 | isSuffix := strings.HasSuffix(str8, "bcd") 43 | fmt.Println("是否包含指定后缀", isSuffix) 44 | 45 | fmt.Println("测试Index的位置") 46 | index := strings.Index(str7, "abc") 47 | fmt.Println("得到的位置:", index) 48 | 49 | } 50 | -------------------------------------------------------------------------------- /Golang/Code/advanceCode/cannel/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func mai1n() { 6 | ch := make(chan int) 7 | ch <- 10 8 | fmt.Println("发送成功") 9 | } 10 | 11 | func counter(out chan<- int) { 12 | for i := 0; i < 100; i++ { 13 | out <- i 14 | } 15 | close(out) 16 | } 17 | 18 | func squarer(out chan<- int, in <-chan int) { 19 | for i := range in { 20 | out <- i * i 21 | } 22 | close(out) 23 | } 24 | func printer(in <-chan int) { 25 | for i := range in { 26 | fmt.Println(i) 27 | } 28 | } 29 | 30 | // channel 练习 31 | func main() { 32 | ch1 := make(chan int) 33 | ch2 := make(chan int) 34 | // // 开启goroutine将0~100的数发送到ch1中 35 | // go func() { 36 | // for i := 0; i < 100; i++ { 37 | // ch1 <- i 38 | // } 39 | // close(ch1) 40 | // }() 41 | // // 开启goroutine从ch1中接收值,并将该值的平方发送到ch2中 42 | // go func() { 43 | // for { 44 | // i, ok := <-ch1 // 通道关闭后再取值ok=false 45 | // if !ok { 46 | // break 47 | // } 48 | // ch2 <- i * i 49 | // } 50 | // close(ch2) 51 | // }() 52 | // // 在主goroutine中从ch2中接收值打印 53 | // for i := range ch2 { // 通道关闭后会退出for range循环 54 | // fmt.Println(i) 55 | // } 56 | go counter(ch1) 57 | go squarer(ch2, ch1) 58 | printer(ch2) 59 | } 60 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/tidwall/gjson/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/tidwall/match/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goProject/vendor/github.com/tidwall/pretty/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Josh Baker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /Golang/Code/gRPC/basicGateway/pb/google/api/annotations.proto: -------------------------------------------------------------------------------- 1 | // Copyright 2015 Google LLC 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | syntax = "proto3"; 16 | 17 | package google.api; 18 | 19 | import "google/api/http.proto"; 20 | import "google/protobuf/descriptor.proto"; 21 | 22 | option go_package = "google.golang.org/genproto/googleapis/api/annotations;annotations"; 23 | option java_multiple_files = true; 24 | option java_outer_classname = "AnnotationsProto"; 25 | option java_package = "com.google.api"; 26 | option objc_class_prefix = "GAPI"; 27 | 28 | extend google.protobuf.MethodOptions { 29 | // See `HttpRule`. 30 | HttpRule http = 72295728; 31 | } -------------------------------------------------------------------------------- /Golang/Code/gRPC/server/4种模式/普通服务/server/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "golang.org/x/net/context" 5 | "google.golang.org/grpc" 6 | "grpc/pb/person" 7 | "log" 8 | "net" 9 | ) 10 | 11 | type personServer struct { 12 | person.UnimplementedSearchServiceServer 13 | } 14 | 15 | func (*personServer) Search(ctx context.Context, req *person.PersonReq) (*person.PersonRes, error) { 16 | name := req.GetName() 17 | res := &person.PersonRes{ 18 | Name: "我收到了" + name + "的信息", 19 | } 20 | return res, nil 21 | } 22 | func (*personServer) SearchI(person.SearchService_SearchIServer) error { 23 | return nil 24 | } 25 | func (*personServer) SearchO(*person.PersonReq, person.SearchService_SearchOServer) error { 26 | return nil 27 | } 28 | func (*personServer) SearchIO(person.SearchService_SearchIOServer) error { 29 | return nil 30 | } 31 | 32 | func main() { 33 | l, err := net.Listen("tcp", ":8888") 34 | if err != nil { 35 | log.Fatalf("failed to listen: %v", err) 36 | } 37 | 38 | s := grpc.NewServer() 39 | person.RegisterSearchServiceServer(s, &personServer{}) 40 | log.Printf("server listening at %v", l.Addr()) 41 | // 建立监听 42 | if err := s.Serve(l); err != nil { 43 | log.Fatalf("failed to serve: %v", err) 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/one2many.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "gorm.io/gorm" 6 | ) 7 | 8 | //type Info struct { 9 | // gorm.Model 10 | // Money int 11 | // DogID uint 12 | //} 13 | // 14 | //type Dog struct { 15 | // gorm.Model 16 | // Name string 17 | // GoddessID uint // 狗链子 18 | // Info Info 19 | //} 20 | // 21 | //type Goddess struct { 22 | // gorm.Model 23 | // Name string 24 | // Dogs []Dog 25 | //} 26 | 27 | func One2Many() { 28 | //d := Dog{ 29 | // Model: gorm.Model{ 30 | // ID: 1, 31 | // }, 32 | // Name: "Dog1", 33 | //} 34 | //d2 := Dog{ 35 | // Model: gorm.Model{ 36 | // ID: 2, 37 | // }, 38 | // Name: "Dog2", 39 | //} 40 | // 41 | //g := Goddess{ 42 | // Model: gorm.Model{ 43 | // ID: 1, 44 | // }, 45 | // Name: "G1", 46 | // Dogs: []Dog{d, d2}, 47 | //} 48 | // 49 | //_ = GLOBAL_DB.AutoMigrate(&Dog{}, &Goddess{}, &Info{}) 50 | // 51 | //GLOBAL_DB.Create(&g) 52 | 53 | var girl Goddess 54 | 55 | //GLOBAL_DB.Preload("Dogs.Info", "money > 100").Preload("Dogs", "name = ? ", "Dog1").First(&girl) 56 | 57 | GLOBAL_DB.Preload("Dogs", func(db *gorm.DB) *gorm.DB { 58 | return db.Joins("Info").Where("money > 100") 59 | }).First(&girl) 60 | fmt.Println(girl) 61 | 62 | } 63 | -------------------------------------------------------------------------------- /Golang/Code/advanceCode/tcp/server/proto/proto.go: -------------------------------------------------------------------------------- 1 | package proto 2 | 3 | import ( 4 | "bufio" 5 | "bytes" 6 | "encoding/binary" 7 | ) 8 | 9 | // Encode 将消息编码 10 | func Encode(message string) ([]byte, error) { 11 | // 读取消息的长度,转换成int32类型(占4个字节) 12 | var length = int32(len(message)) 13 | var pkg = new(bytes.Buffer) 14 | // 写入消息头 15 | err := binary.Write(pkg, binary.LittleEndian, length) 16 | if err != nil { 17 | return nil, err 18 | } 19 | // 写入消息实体 20 | err = binary.Write(pkg, binary.LittleEndian, []byte(message)) 21 | if err != nil { 22 | return nil, err 23 | } 24 | return pkg.Bytes(), nil 25 | } 26 | 27 | // Decode 解码消息 28 | func Decode(reader *bufio.Reader) (string, error) { 29 | // 读取消息的长度 30 | lengthByte, _ := reader.Peek(4) // 读取前4个字节的数据 31 | lengthBuff := bytes.NewBuffer(lengthByte) 32 | var length int32 33 | err := binary.Read(lengthBuff, binary.LittleEndian, &length) 34 | if err != nil { 35 | return "", err 36 | } 37 | // Buffered返回缓冲中现有的可读取的字节数。 38 | if int32(reader.Buffered()) < length+4 { 39 | return "", err 40 | } 41 | 42 | // 读取真正的消息数据 43 | pack := make([]byte, int(4+length)) 44 | _, err = reader.Read(pack) 45 | if err != nil { 46 | return "", err 47 | } 48 | return string(pack[4:]), nil 49 | } 50 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/13_error_handling/errors4.rs: -------------------------------------------------------------------------------- 1 | #![allow(clippy::comparison_chain)] 2 | 3 | #[derive(PartialEq, Debug)] 4 | enum CreationError { 5 | Negative, 6 | Zero, 7 | } 8 | 9 | #[derive(PartialEq, Debug)] 10 | struct PositiveNonzeroInteger(u64); 11 | 12 | impl PositiveNonzeroInteger { 13 | fn new(value: i64) -> Result { 14 | // TODO: This function shouldn't always return an `Ok`. 15 | 16 | if value < 0 { 17 | Err(CreationError::Negative) 18 | } else if value == 0 { 19 | Err(CreationError::Zero) 20 | } else { 21 | Ok(Self(value as u64)) 22 | } 23 | } 24 | } 25 | 26 | fn main() { 27 | // You can optionally experiment here. 28 | } 29 | 30 | #[cfg(test)] 31 | mod tests { 32 | use super::*; 33 | 34 | #[test] 35 | fn test_creation() { 36 | assert_eq!( 37 | PositiveNonzeroInteger::new(10), 38 | Ok(PositiveNonzeroInteger(10)), 39 | ); 40 | assert_eq!( 41 | PositiveNonzeroInteger::new(-10), 42 | Err(CreationError::Negative), 43 | ); 44 | assert_eq!(PositiveNonzeroInteger::new(0), Err(CreationError::Zero)); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /数据库/MySQL/基础/Code/practice/op.sql: -------------------------------------------------------------------------------- 1 | # 1.选择工资不在5000到12000的员工的姓名和工资 2 | SELECT last_name, salary 3 | FROM employees 4 | WHERE salary NOT BETWEEN 5000 AND 12000 5 | 6 | # 2.选择在20或50号部门工作的员工姓名和部门号 7 | 8 | SELECT last_name, department_id 9 | FROM employees 10 | WHERE department_id IN (20,50) 11 | 12 | # 3.选择公司中没有管理者的员工姓名及job_id 13 | 14 | SELECT last_name, job_id, manager_id 15 | FROM employees 16 | WHERE manager_id IS NULL 17 | 18 | # 4.选择公司中有奖金的员工姓名,工资和奖金级别 19 | 20 | SELECT last_name, salary, commission_pct 21 | FROM employees 22 | WHERE commission_pct IS NOT NULL 23 | 24 | # 5.选择员工姓名的第三个字母是a的员工姓名 25 | 26 | SELECT last_name 27 | FROM employees 28 | WHERE last_name LIKE '__a%' 29 | 30 | # 6.选择姓名中有字母a和k的员工姓名 31 | 32 | SELECT last_name 33 | FROM employees 34 | WHERE last_name LIKE '%a%k%' OR last_name LIKE '%k%a%' 35 | 36 | # 7.显示出表 employees 表中 first_name 以 'e'结尾的员工信息 37 | 38 | SELECT * 39 | FROM employees 40 | WHERE first_name LIKE '%e' 41 | 42 | # 8.显示出表 employees 部门编号在 80-100 之间的姓名、工种 43 | 44 | SELECT department_id, last_name, job_id 45 | FROM employees 46 | WHERE department_id BETWEEN 80 AND 100 47 | 48 | # 9.显示出表 employees 的 manager_id 是 100,101,110 的员工姓名、工资、管理者id 49 | 50 | SELECT last_name, salary, manager_id 51 | FROM employees 52 | WHERE manager_id IN (100, 101, 110) -------------------------------------------------------------------------------- /Rust/rustlings/exercises/03_if/if3.rs: -------------------------------------------------------------------------------- 1 | fn animal_habitat(animal: &str) -> &str { 2 | // TODO: Fix the compiler error in the statement below. 3 | let identifier = if animal == "crab" { 4 | 1 5 | } else if animal == "gopher" { 6 | 2 7 | } else if animal == "snake" { 8 | 3 9 | } else { 10 | 4 11 | }; 12 | 13 | // Don't change the expression below! 14 | if identifier == 1 { 15 | "Beach" 16 | } else if identifier == 2 { 17 | "Burrow" 18 | } else if identifier == 3 { 19 | "Desert" 20 | } else { 21 | "Unknown" 22 | } 23 | } 24 | 25 | fn main() { 26 | // You can optionally experiment here. 27 | } 28 | 29 | // Don't change the tests! 30 | #[cfg(test)] 31 | mod tests { 32 | use super::*; 33 | 34 | #[test] 35 | fn gopher_lives_in_burrow() { 36 | assert_eq!(animal_habitat("gopher"), "Burrow") 37 | } 38 | 39 | #[test] 40 | fn snake_lives_in_desert() { 41 | assert_eq!(animal_habitat("snake"), "Desert") 42 | } 43 | 44 | #[test] 45 | fn crab_lives_on_beach() { 46 | assert_eq!(animal_habitat("crab"), "Beach") 47 | } 48 | 49 | #[test] 50 | fn unknown_animal() { 51 | assert_eq!(animal_habitat("dinosaur"), "Unknown") 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/18_iterators/iterators4.rs: -------------------------------------------------------------------------------- 1 | fn factorial(num: u64) -> u64 { 2 | // TODO: Complete this function to return the factorial of `num` which is 3 | // defined as `1 * 2 * 3 * … * num`. 4 | // https://en.wikipedia.org/wiki/Factorial 5 | // 6 | // Do not use: 7 | // - early returns (using the `return` keyword explicitly) 8 | // Try not to use: 9 | // - imperative style loops (for/while) 10 | // - additional variables 11 | // For an extra challenge, don't use: 12 | // - recursion 13 | 14 | // if num == 1 || num == 0 { 15 | // 1 16 | // } else { 17 | // num * factorial(num - 1) 18 | // } 19 | 20 | // (2..=num).fold(1, |acc, x| acc * x) 21 | 22 | (1..=num).product() 23 | } 24 | 25 | fn main() { 26 | // You can optionally experiment here. 27 | } 28 | 29 | #[cfg(test)] 30 | mod tests { 31 | use super::*; 32 | 33 | #[test] 34 | fn factorial_of_0() { 35 | assert_eq!(factorial(0), 1); 36 | } 37 | 38 | #[test] 39 | fn factorial_of_1() { 40 | assert_eq!(factorial(1), 1); 41 | } 42 | #[test] 43 | fn factorial_of_2() { 44 | assert_eq!(factorial(2), 2); 45 | } 46 | 47 | #[test] 48 | fn factorial_of_4() { 49 | assert_eq!(factorial(4), 24); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/15_traits/traits3.rs: -------------------------------------------------------------------------------- 1 | #![allow(dead_code)] 2 | 3 | trait Licensed { 4 | // TODO: Add a default implementation for `licensing_info` so that 5 | // implementors like the two structs below can share that default behavior 6 | // without repeating the function. 7 | // The default license information should be the string "Default license". 8 | fn licensing_info(&self) -> String { 9 | "Default license".to_string() 10 | } 11 | } 12 | 13 | struct SomeSoftware { 14 | version_number: i32, 15 | } 16 | 17 | struct OtherSoftware { 18 | version_number: String, 19 | } 20 | 21 | impl Licensed for SomeSoftware {} // Don't edit this line. 22 | impl Licensed for OtherSoftware {} // Don't edit this line. 23 | 24 | fn main() { 25 | // You can optionally experiment here. 26 | } 27 | 28 | #[cfg(test)] 29 | mod tests { 30 | use super::*; 31 | 32 | #[test] 33 | fn is_licensing_info_the_same() { 34 | let licensing_info = "Default license"; 35 | let some_software = SomeSoftware { version_number: 1 }; 36 | let other_software = OtherSoftware { 37 | version_number: "v2.0.0".to_string(), 38 | }; 39 | assert_eq!(some_software.licensing_info(), licensing_info); 40 | assert_eq!(other_software.licensing_info(), licensing_info); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/20_threads/threads1.rs: -------------------------------------------------------------------------------- 1 | // This program spawns multiple threads that each run for at least 250ms, and 2 | // each thread returns how much time they took to complete. The program should 3 | // wait until all the spawned threads have finished and should collect their 4 | // return values into a vector. 5 | 6 | use std::{ 7 | thread, 8 | time::{Duration, Instant}, 9 | }; 10 | 11 | fn main() { 12 | let mut handles = Vec::new(); 13 | for i in 0..10 { 14 | let handle = thread::spawn(move || { 15 | let start = Instant::now(); 16 | thread::sleep(Duration::from_millis(250)); 17 | println!("Thread {i} done"); 18 | start.elapsed().as_millis() 19 | }); 20 | handles.push(handle); 21 | } 22 | 23 | let mut results = Vec::new(); 24 | for handle in handles { 25 | // TODO: Collect the results of all threads into the `results` vector. 26 | // Use the `JoinHandle` struct which is returned by `thread::spawn`. 27 | results.push(handle.join().unwrap()); 28 | } 29 | 30 | if results.len() != 10 { 31 | panic!("Oh no! Some thread isn't done yet!"); 32 | } 33 | 34 | println!(); 35 | for (i, result) in results.into_iter().enumerate() { 36 | println!("Thread {i} took {result}ms"); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/10_modules/modules3.rs: -------------------------------------------------------------------------------- 1 | // A basket of fruits in the form of a hash map needs to be defined. The key 2 | // represents the name of the fruit and the value represents how many of that 3 | // particular fruit is in the basket. You have to put at least 3 different 4 | // types of fruits (e.g. apple, banana, mango) in the basket and the total count 5 | // of all the fruits should be at least 5. 6 | 7 | use std::collections::{hash_map, HashMap}; 8 | 9 | fn fruit_basket() -> HashMap { 10 | // TODO: Declare the hash map. 11 | let mut basket = HashMap::new(); 12 | 13 | // Two bananas are already given for you :) 14 | basket.insert(String::from("banana"), 2); 15 | 16 | // TODO: Put more fruits in your basket. 17 | basket.insert(String::from("apple"), 2); 18 | basket.insert(String::from("peach"), 2); 19 | 20 | basket 21 | } 22 | 23 | fn main() { 24 | // You can optionally experiment here. 25 | } 26 | 27 | #[cfg(test)] 28 | mod tests { 29 | use super::*; 30 | 31 | #[test] 32 | fn at_least_three_types_of_fruits() { 33 | let basket = fruit_basket(); 34 | assert!(basket.len() >= 3); 35 | } 36 | 37 | #[test] 38 | fn at_least_five_fruits() { 39 | let basket = fruit_basket(); 40 | assert!(basket.values().sum::() >= 5); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/11_hashmaps/hashmaps1.rs: -------------------------------------------------------------------------------- 1 | // A basket of fruits in the form of a hash map needs to be defined. The key 2 | // represents the name of the fruit and the value represents how many of that 3 | // particular fruit is in the basket. You have to put at least 3 different 4 | // types of fruits (e.g. apple, banana, mango) in the basket and the total count 5 | // of all the fruits should be at least 5. 6 | 7 | use std::collections::{hash_map, HashMap}; 8 | 9 | fn fruit_basket() -> HashMap { 10 | // TODO: Declare the hash map. 11 | let mut basket = HashMap::new(); 12 | 13 | // Two bananas are already given for you :) 14 | basket.insert(String::from("banana"), 2); 15 | 16 | // TODO: Put more fruits in your basket. 17 | basket.insert(String::from("apple"), 2); 18 | basket.insert(String::from("peach"), 2); 19 | 20 | basket 21 | } 22 | 23 | fn main() { 24 | // You can optionally experiment here. 25 | } 26 | 27 | #[cfg(test)] 28 | mod tests { 29 | use super::*; 30 | 31 | #[test] 32 | fn at_least_three_types_of_fruits() { 33 | let basket = fruit_basket(); 34 | assert!(basket.len() >= 3); 35 | } 36 | 37 | #[test] 38 | fn at_least_five_fruits() { 39 | let basket = fruit_basket(); 40 | assert!(basket.values().sum::() >= 5); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /数据库/MySQL/进阶/性能分析.md: -------------------------------------------------------------------------------- 1 | # SQL性能分析 2 | 3 | ## SQL执行频率 4 | 5 | `show [session|global] status` 可以查看当前数据库的INSERT、UPDATE、DELETE、 6 | SELECT的访问频次。 7 | 8 | ```sql 9 | SHOW GLOBAL STATUS LIKE 'Com%' 10 | ``` 11 | 12 | ![image-202302201531344](https://raw.githubusercontent.com/Swiftie13st/Figurebed/main/img/202303041708820.png) 13 | 14 | ## 慢查询日志 15 | 16 | 记录了所有执行时间超过指定参数(long_query_time,单位秒,默认10s)的所有SQL语句的日志。 17 | 18 | MySQL的慢查询日志默认没有开启,需要在MySQL的配置文件(/etc/my.cnf)配置: 19 | ```plain 20 | # 开启慢查询日志 21 | slow_query_log=1 22 | # 设置慢日志的时间为2s 23 | long_query_time=2 24 | ``` 25 | 26 | ## profile 详情 27 | 28 | `show profiles`能够在做SQL优化时帮助我们了解时间都消耗在哪里。通过have_profiling参数,能够看到当前MySQL是否支持profile操作: 29 | 30 | ```sql 31 | SELECT @@have_profiling; 32 | ``` 33 | 34 | 默认profiling是关闭的,可以通过set语句在session/global级别开启profiling: 35 | 36 | ```sql 37 | SET profiling=1 38 | ``` 39 | 40 | ![image-202302201622198](https://raw.githubusercontent.com/Swiftie13st/Figurebed/main/img/202303041708822.png) 41 | 42 | ```sql 43 | # 查看每一条SQL的耗时基本情况 44 | show profiles; 45 | # 查看指定query_id的SQL语句各个阶段的耗时情况 46 | show profile for query query_id; 47 | # 查看指定query_id的SQL语句CPU的使用情况 48 | show profile cpu for query query_id; 49 | ``` 50 | 51 | ## explain执行计划 52 | 53 | EXPLAIN或者DESC命令获取MySQL如何执行SELECT语句的信息,包括在SELECT语句执行过程中表如何连接和连接的顺序。 54 | 55 | ```sql 56 | # 直接在select语句之前加上关键字explain/desc 57 | EXPLAIN SELECT * FROM TB WHERE X; 58 | ``` -------------------------------------------------------------------------------- /Rust/rustlings/exercises/README.md: -------------------------------------------------------------------------------- 1 | # Exercise to Book Chapter mapping 2 | 3 | | Exercise | Book Chapter | 4 | | ---------------------- | ------------------- | 5 | | variables | §3.1 | 6 | | functions | §3.3 | 7 | | if | §3.5 | 8 | | primitive_types | §3.2, §4.3 | 9 | | vecs | §8.1 | 10 | | move_semantics | §4.1-2 | 11 | | structs | §5.1, §5.3 | 12 | | enums | §6, §18.3 | 13 | | strings | §8.2 | 14 | | modules | §7 | 15 | | hashmaps | §8.3 | 16 | | options | §10.1 | 17 | | error_handling | §9 | 18 | | generics | §10 | 19 | | traits | §10.2 | 20 | | lifetimes | §10.3 | 21 | | tests | §11.1 | 22 | | iterators | §13.2-4 | 23 | | smart_pointers | §15, §16.3 | 24 | | threads | §16.1-3 | 25 | | macros | §19.5 | 26 | | clippy | §21.4 | 27 | | conversions | n/a | 28 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/09_strings/strings3.rs: -------------------------------------------------------------------------------- 1 | fn trim_me(input: &str) -> &str { 2 | // TODO: Remove whitespace from both ends of a string. 3 | input.trim() 4 | } 5 | 6 | fn compose_me(input: &str) -> String { 7 | // TODO: Add " world!" to the string! There are multiple ways to do this. 8 | input.to_string() + " world!" 9 | } 10 | 11 | fn replace_me(input: &str) -> String { 12 | // TODO: Replace "cars" in the string with "balloons". 13 | input.replace("cars", "balloons") 14 | } 15 | 16 | fn main() { 17 | // You can optionally experiment here. 18 | } 19 | 20 | #[cfg(test)] 21 | mod tests { 22 | use super::*; 23 | 24 | #[test] 25 | fn trim_a_string() { 26 | assert_eq!(trim_me("Hello! "), "Hello!"); 27 | assert_eq!(trim_me(" What's up!"), "What's up!"); 28 | assert_eq!(trim_me(" Hola! "), "Hola!"); 29 | } 30 | 31 | #[test] 32 | fn compose_a_string() { 33 | assert_eq!(compose_me("Hello"), "Hello world!"); 34 | assert_eq!(compose_me("Goodbye"), "Goodbye world!"); 35 | } 36 | 37 | #[test] 38 | fn replace_a_string() { 39 | assert_eq!( 40 | replace_me("I think cars are cool"), 41 | "I think balloons are cool", 42 | ); 43 | assert_eq!( 44 | replace_me("I love to look at cars"), 45 | "I love to look at balloons", 46 | ); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Golang/Code/standard library/log/xx.log: -------------------------------------------------------------------------------- 1 | [2022-07-08 10:36:46] [error] [main.go:main.main:167] 这是一条ERROR日志 2 | [2022-07-08 10:36:46] [fatal] [main.go:main.main:168] 这是一条FATAL日志 3 | [2022-07-08 10:36:47] [error] [main.go:main.main:167] 这是一条ERROR日志 4 | [2022-07-08 10:36:47] [fatal] [main.go:main.main:168] 这是一条FATAL日志 5 | [2022-07-08 10:36:48] [error] [main.go:main.main:167] 这是一条ERROR日志 6 | [2022-07-08 10:36:48] [fatal] [main.go:main.main:168] 这是一条FATAL日志 7 | [2022-07-08 10:36:49] [error] [main.go:main.main:167] 这是一条ERROR日志 8 | [2022-07-08 10:36:49] [fatal] [main.go:main.main:168] 这是一条FATAL日志 9 | [2022-07-08 10:36:50] [error] [main.go:main.main:167] 这是一条ERROR日志 10 | [2022-07-08 10:36:50] [fatal] [main.go:main.main:168] 这是一条FATAL日志 11 | [2022-07-08 10:37:16] [error] [main.go:main.main:167] 这是一条ERROR日志 12 | [2022-07-08 10:37:16] [fatal] [main.go:main.main:168] 这是一条FATAL日志 13 | [2022-07-08 10:37:17] [error] [main.go:main.main:167] 这是一条ERROR日志 14 | [2022-07-08 10:37:17] [fatal] [main.go:main.main:168] 这是一条FATAL日志 15 | [2022-07-08 10:37:18] [error] [main.go:main.main:167] 这是一条ERROR日志 16 | [2022-07-08 10:37:18] [fatal] [main.go:main.main:168] 这是一条FATAL日志 17 | [2022-07-08 10:37:19] [error] [main.go:main.main:167] 这是一条ERROR日志 18 | [2022-07-08 10:37:19] [fatal] [main.go:main.main:168] 这是一条FATAL日志 19 | [2022-07-08 10:37:20] [error] [main.go:main.main:167] 这是一条ERROR日志 20 | [2022-07-08 10:37:20] [fatal] [main.go:main.main:168] 这是一条FATAL日志 21 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/12_options/options1.rs: -------------------------------------------------------------------------------- 1 | // This function returns how much icecream there is left in the fridge. 2 | // If it's before 22:00 (24-hour system), then 5 scoops are left. At 22:00, 3 | // someone eats it all, so no icecream is left (value 0). Return `None` if 4 | // `hour_of_day` is higher than 23. 5 | fn maybe_icecream(hour_of_day: u16) -> Option { 6 | // TODO: Complete the function body. 7 | 8 | if hour_of_day < 22 { 9 | Some(5) 10 | } else if hour_of_day < 24 { 11 | Some(0) 12 | } else { 13 | None 14 | } 15 | } 16 | 17 | fn main() { 18 | // You can optionally experiment here. 19 | } 20 | 21 | #[cfg(test)] 22 | mod tests { 23 | use super::*; 24 | 25 | #[test] 26 | fn raw_value() { 27 | // TODO: Fix this test. How do you get the value contained in the 28 | // Option? 29 | let icecreams = maybe_icecream(12).unwrap(); 30 | 31 | assert_eq!(icecreams, 5); // Don't change this line. 32 | } 33 | 34 | #[test] 35 | fn check_icecream() { 36 | assert_eq!(maybe_icecream(0), Some(5)); 37 | assert_eq!(maybe_icecream(9), Some(5)); 38 | assert_eq!(maybe_icecream(18), Some(5)); 39 | assert_eq!(maybe_icecream(22), Some(0)); 40 | assert_eq!(maybe_icecream(23), Some(0)); 41 | assert_eq!(maybe_icecream(24), None); 42 | assert_eq!(maybe_icecream(25), None); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/byteDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | var a byte = 'a' 7 | // 输出的是ASCII码值,也就是说当我们直接输出byte(字符)的时候,输出的是这个字符对应的码值 8 | fmt.Println(a) 9 | // 输出的是字符 10 | fmt.Printf("%c", a) 11 | 12 | // for循环打印字符串里面的字符 13 | // 通过len来循环的,相当于打印的是ASCII码 14 | s := "你好 golang" 15 | for i := 0; i < len(s); i++ { 16 | fmt.Printf("%v(%c)\t", s[i], s[i]) 17 | } 18 | 19 | // 通过rune打印的是 utf-8字符 20 | for index, v := range s { 21 | fmt.Println(index, v) 22 | } 23 | 24 | // 字符串转换 25 | 26 | // byte类型 27 | s1 := "big" 28 | byteS1 := []byte(s1) 29 | byteS1[0] = 'p' 30 | fmt.Println(string(byteS1)) 31 | 32 | // rune类型 33 | s2 := "你好golang" 34 | byteS2 := []rune(s2) 35 | byteS2[0] = '我' 36 | fmt.Println(string(byteS2)) 37 | 38 | // 整型和浮点型之间转换 39 | var aa int8 = 20 40 | var bb int16 = 40 41 | fmt.Println(int16(aa) + bb) 42 | 43 | // 整型和浮点型之间转换 44 | var cc int8 = 20 45 | var dd float32 = 40 46 | fmt.Println(float32(cc) + dd) 47 | 48 | // 字符串类型转换 49 | var i int = 20 50 | var f float64 = 12.456 51 | var t bool = true 52 | var b byte = 'a' 53 | str1 := fmt.Sprintf("%d", i) 54 | fmt.Printf("类型:%v-%T \n", str1, str1) 55 | 56 | str2 := fmt.Sprintf("%f", f) 57 | fmt.Printf("类型:%v-%T \n", str2, str2) 58 | 59 | str3 := fmt.Sprintf("%t", t) 60 | fmt.Printf("类型:%v-%T \n", str3, str3) 61 | 62 | str4 := fmt.Sprintf("%c", b) 63 | fmt.Printf("类型:%v-%T \n", str4, str4) 64 | } 65 | -------------------------------------------------------------------------------- /Golang/Code/Gin/go.mod: -------------------------------------------------------------------------------- 1 | module Gin 2 | 3 | go 1.18 4 | 5 | require ( 6 | github.com/appleboy/gin-jwt/v2 v2.8.0 7 | github.com/gin-gonic/gin v1.8.1 8 | github.com/golang-jwt/jwt v3.2.2+incompatible 9 | github.com/jinzhu/gorm v1.9.16 10 | ) 11 | 12 | require ( 13 | github.com/gin-contrib/sse v0.1.0 // indirect 14 | github.com/go-playground/locales v0.14.0 // indirect 15 | github.com/go-playground/universal-translator v0.18.0 // indirect 16 | github.com/go-playground/validator/v10 v10.11.0 // indirect 17 | github.com/go-sql-driver/mysql v1.5.0 // indirect 18 | github.com/goccy/go-json v0.9.8 // indirect 19 | github.com/golang-jwt/jwt/v4 v4.4.2 // indirect 20 | github.com/jinzhu/inflection v1.0.0 // indirect 21 | github.com/json-iterator/go v1.1.12 // indirect 22 | github.com/leodido/go-urn v1.2.1 // indirect 23 | github.com/mattn/go-isatty v0.0.14 // indirect 24 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 25 | github.com/modern-go/reflect2 v1.0.2 // indirect 26 | github.com/pelletier/go-toml/v2 v2.0.2 // indirect 27 | github.com/ugorji/go/codec v1.2.7 // indirect 28 | golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect 29 | golang.org/x/net v0.0.0-20220630215102-69896b714898 // indirect 30 | golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e // indirect 31 | golang.org/x/text v0.3.7 // indirect 32 | google.golang.org/protobuf v1.28.0 // indirect 33 | gopkg.in/yaml.v2 v2.4.0 // indirect 34 | ) 35 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/13_error_handling/errors1.rs: -------------------------------------------------------------------------------- 1 | // TODO: This function refuses to generate text to be printed on a nametag if 2 | // you pass it an empty string. It'd be nicer if it explained what the problem 3 | // was instead of just returning `None`. Thankfully, Rust has a similar 4 | // construct to `Option` that can be used to express error conditions. Change 5 | // the function signature and body to return `Result` instead 6 | // of `Option`. 7 | fn generate_nametag_text(name: String) -> Result { 8 | if name.is_empty() { 9 | // Empty names aren't allowed. 10 | Err("Empty names aren't allowed".to_string()) 11 | } else { 12 | Ok(format!("Hi! My name is {name}")) 13 | } 14 | } 15 | 16 | fn main() { 17 | // You can optionally experiment here. 18 | } 19 | 20 | #[cfg(test)] 21 | mod tests { 22 | use super::*; 23 | 24 | #[test] 25 | fn generates_nametag_text_for_a_nonempty_name() { 26 | assert_eq!( 27 | generate_nametag_text("Beyoncé".to_string()).as_deref(), 28 | Ok("Hi! My name is Beyoncé"), 29 | ); 30 | } 31 | 32 | #[test] 33 | fn explains_why_generating_nametag_text_fails() { 34 | assert_eq!( 35 | generate_nametag_text(String::new()) 36 | .as_ref() 37 | .map_err(|e| e.as_str()), 38 | Err("Empty names aren't allowed"), 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Rust/rustlings/exercises/20_threads/threads2.rs: -------------------------------------------------------------------------------- 1 | // Building on the last exercise, we want all of the threads to complete their 2 | // work. But this time, the spawned threads need to be in charge of updating a 3 | // shared value: `JobStatus.jobs_done` 4 | 5 | use std::{ 6 | sync::{Arc, Mutex}, 7 | thread, 8 | time::Duration, 9 | }; 10 | 11 | struct JobStatus { 12 | // jobs_done: Mutex, 13 | jobs_done: u32, 14 | } 15 | 16 | fn main() { 17 | // TODO: `Arc` isn't enough if you want a **mutable** shared state. 18 | // let status = Arc::new(JobStatus { jobs_done: Mutex::new(0) }); 19 | let status = Arc::new(Mutex::new(JobStatus { jobs_done: 0 })); 20 | 21 | let mut handles = Vec::new(); 22 | for _ in 0..10 { 23 | let status_shared = Arc::clone(&status); 24 | let handle = thread::spawn(move || { 25 | thread::sleep(Duration::from_millis(250)); 26 | 27 | // TODO: You must take an action before you update a shared value. 28 | // status_shared.jobs_done.lock().unwrap().checked_add(1); 29 | status_shared.lock().unwrap().jobs_done += 1; 30 | }); 31 | handles.push(handle); 32 | } 33 | 34 | // Waiting for all jobs to complete. 35 | for handle in handles { 36 | handle.join().unwrap(); 37 | } 38 | 39 | // TODO: Print the value of `JobStatus.jobs_done`. 40 | println!("Jobs done: {}", status.lock().unwrap().jobs_done); 41 | } 42 | -------------------------------------------------------------------------------- /Golang/Code/basicCode/Code/goStudy/main/6_ArrayDemo.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import "fmt" 4 | 5 | func main() { 6 | // 数组的长度是类型的一部分 7 | var arr1 [3]int 8 | var arr2 [4]string 9 | fmt.Printf("%T, %T \n", arr1, arr2) 10 | 11 | // 数组的初始化 第一种方法 12 | var arr3 [3]int 13 | arr3[0] = 1 14 | arr3[1] = 2 15 | arr3[2] = 3 16 | fmt.Println(arr3) 17 | 18 | // 第二种初始化数组的犯法 19 | var arr4 = [4]int {10, 20, 30, 40} 20 | fmt.Println(arr4) 21 | 22 | // 第三种数组初始化方法,自动推断数组长度 23 | var arr5 = [...]int{1, 2} 24 | fmt.Println(arr5) 25 | 26 | // 第四种初始化数组的方法,指定下标 27 | a := [...]int{1:1, 3:5} 28 | fmt.Println(a) 29 | 30 | for i := 0; i < len(a); i++ { 31 | fmt.Print(a[i], " ") 32 | } 33 | 34 | for _, value := range a { 35 | fmt.Print(value, " ") 36 | } 37 | 38 | fmt.Println() 39 | // 值类型 引用类型 40 | // 基本数据类型和数组都是值类型 41 | var aa = 10 42 | bb := aa 43 | aa = 20 44 | fmt.Println(aa, bb) 45 | 46 | // 数组 47 | var array1 = [...]int {1, 2, 3} 48 | array2 := array1 49 | array2[0] = 3 50 | fmt.Println(array1, array2) 51 | 52 | // 切片定义 53 | var array3 = []int{1,2,3} 54 | array4 := array3 55 | array4[0] = 3 56 | fmt.Println(array3, array4) 57 | 58 | // 二维数组 59 | var array5 = [...][2]int{{1,2},{2,3}} 60 | for i := 0; i < len(array5); i++ { 61 | for j := 0; j < len(array5[0]); j++ { 62 | fmt.Println(array5[i][j]) 63 | } 64 | } 65 | 66 | for _, item := range array5 { 67 | for _, item2 := range item { 68 | fmt.Println(item2) 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Golang/Code/Gin/route/route.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | 6 | "github.com/gin-gonic/gin" 7 | ) 8 | 9 | func main() { 10 | r := gin.Default() 11 | 12 | r.GET("/", func(c *gin.Context) { 13 | c.String(200, "Hello World!") 14 | }) 15 | 16 | r.Any("/any", func(c *gin.Context) { 17 | 18 | switch c.Request.Method { 19 | case "GET": 20 | c.JSON(http.StatusOK, gin.H{ 21 | "method": "GET", 22 | }) 23 | case "POST": 24 | c.JSON(http.StatusOK, gin.H{ 25 | "method": "POST", 26 | }) 27 | default: 28 | c.JSON(http.StatusOK, gin.H{ 29 | "method": "Others", 30 | }) 31 | } 32 | 33 | c.JSON(http.StatusOK, gin.H{ 34 | "method": "Any", 35 | }) 36 | }) 37 | 38 | r.NoRoute(func(c *gin.Context) { 39 | c.JSON(http.StatusNotFound, gin.H{ 40 | "msg": "NotFound", 41 | }) 42 | }) 43 | 44 | // 路由组,把共用的前缀提取出来,创建一个路由组 45 | videoGroup := r.Group("/video") 46 | { 47 | videoGroup.GET("/index", func(context *gin.Context) { 48 | context.JSON(http.StatusOK, gin.H{ 49 | "msg": "/video/index", 50 | }) 51 | }) 52 | videoGroup.GET("/about", func(context *gin.Context) { 53 | context.JSON(http.StatusOK, gin.H{ 54 | "msg": "/video/about", 55 | }) 56 | }) 57 | videoGroup.GET("/home", func(context *gin.Context) { 58 | context.JSON(http.StatusOK, gin.H{ 59 | "msg": "/video/home", 60 | }) 61 | }) 62 | } 63 | 64 | r.Run(":9003") // listen and serve on 0.0.0.0:PORT(default:8080) 65 | 66 | } 67 | -------------------------------------------------------------------------------- /数据库/.gitignore: -------------------------------------------------------------------------------- 1 | # File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig 2 | # Created by https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode 4 | 5 | ### VisualStudioCode ### 6 | .vscode/* 7 | !.vscode/settings.json 8 | !.vscode/tasks.json 9 | !.vscode/launch.json 10 | !.vscode/extensions.json 11 | !.vscode/*.code-snippets 12 | 13 | # Local History for Visual Studio Code 14 | .history/ 15 | 16 | # Built Visual Studio Code Extensions 17 | *.vsix 18 | 19 | ### VisualStudioCode Patch ### 20 | # Ignore all local history of files 21 | .history 22 | .ionide 23 | 24 | # Support for Project snippet scope 25 | .vscode/*.code-snippets 26 | 27 | # Ignore code-workspaces 28 | *.code-workspace 29 | 30 | ### Windows ### 31 | # Windows thumbnail cache files 32 | Thumbs.db 33 | Thumbs.db:encryptable 34 | ehthumbs.db 35 | ehthumbs_vista.db 36 | 37 | # Dump file 38 | *.stackdump 39 | 40 | # Folder config file 41 | [Dd]esktop.ini 42 | 43 | # Recycle Bin used on file shares 44 | $RECYCLE.BIN/ 45 | 46 | # Windows Installer files 47 | *.cab 48 | *.msi 49 | *.msix 50 | *.msm 51 | *.msp 52 | 53 | # Windows shortcuts 54 | *.lnk 55 | 56 | # End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode 57 | 58 | # Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option) 59 | 60 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/关系/many2many.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "gorm.io/gorm" 6 | ) 7 | 8 | type Info struct { 9 | gorm.Model 10 | Money int 11 | DogID uint 12 | } 13 | 14 | type Dog struct { 15 | gorm.Model 16 | Name string 17 | Info Info 18 | Goddesses []Goddess `gorm:"many2many:dog_goddess"` 19 | } 20 | 21 | type Goddess struct { 22 | gorm.Model 23 | Name string 24 | Dogs []Dog `gorm:"many2many:dog_goddess"` 25 | } 26 | 27 | func Many2Many() { 28 | //i := Info{ 29 | // Money: 200, 30 | //} 31 | //g := Goddess{ 32 | // Model: gorm.Model{ 33 | // ID: 1, 34 | // }, 35 | // Name: "G1", 36 | //} 37 | //g1 := Goddess{ 38 | // Model: gorm.Model{ 39 | // ID: 2, 40 | // }, 41 | // Name: "G2", 42 | //} 43 | // 44 | d := Dog{ 45 | Model: gorm.Model{ 46 | ID: 1, 47 | }, 48 | } 49 | //d2 := Dog{ 50 | // Model: gorm.Model{ 51 | // ID: 2, 52 | // }, 53 | // Name: "Dog2", 54 | //} 55 | 56 | _ = GLOBAL_DB.AutoMigrate(&Dog{}, &Goddess{}, &Info{}) 57 | 58 | //GLOBAL_DB.Create(&d) 59 | //GLOBAL_DB.Preload("Goddess").Find(&d) 60 | 61 | var girls []Goddess 62 | 63 | //GLOBAL_DB.Model(&d).Association("Goddesses").Find(&girls) 64 | //GLOBAL_DB.Model(&d).Preload("Dogs.Info").Association("Goddesses").Find(&girls) 65 | 66 | GLOBAL_DB.Model(&d).Preload("Dogs", func(db *gorm.DB) *gorm.DB { 67 | return db.Joins("Info").Where("money < ? ", 10000) 68 | }).Association("Goddesses").Find(&girls) 69 | fmt.Println(girls) 70 | 71 | } 72 | -------------------------------------------------------------------------------- /Golang/Code/GORM-v2/GORM-v2/many2many.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "gorm.io/gorm" 6 | ) 7 | 8 | type Info struct { 9 | gorm.Model 10 | Money int 11 | DogID uint 12 | } 13 | 14 | type Dog struct { 15 | gorm.Model 16 | Name string 17 | Info Info 18 | Goddesses []Goddess `gorm:"many2many:dog_goddess"` 19 | } 20 | 21 | type Goddess struct { 22 | gorm.Model 23 | Name string 24 | Dogs []Dog `gorm:"many2many:dog_goddess"` 25 | } 26 | 27 | func Many2Many() { 28 | //i := Info{ 29 | // Money: 200, 30 | //} 31 | //g := Goddess{ 32 | // Model: gorm.Model{ 33 | // ID: 1, 34 | // }, 35 | // Name: "G1", 36 | //} 37 | //g1 := Goddess{ 38 | // Model: gorm.Model{ 39 | // ID: 2, 40 | // }, 41 | // Name: "G2", 42 | //} 43 | // 44 | d := Dog{ 45 | Model: gorm.Model{ 46 | ID: 1, 47 | }, 48 | } 49 | //d2 := Dog{ 50 | // Model: gorm.Model{ 51 | // ID: 2, 52 | // }, 53 | // Name: "Dog2", 54 | //} 55 | 56 | _ = GLOBAL_DB.AutoMigrate(&Dog{}, &Goddess{}, &Info{}) 57 | 58 | //GLOBAL_DB.Create(&d) 59 | //GLOBAL_DB.Preload("Goddess").Find(&d) 60 | 61 | var girls []Goddess 62 | 63 | //GLOBAL_DB.Model(&d).Association("Goddesses").Find(&girls) 64 | //GLOBAL_DB.Model(&d).Preload("Dogs.Info").Association("Goddesses").Find(&girls) 65 | 66 | GLOBAL_DB.Model(&d).Preload("Dogs", func(db *gorm.DB) *gorm.DB { 67 | return db.Joins("Info").Where("money < ? ", 10000) 68 | }).Association("Goddesses").Find(&girls) 69 | fmt.Println(girls) 70 | 71 | } 72 | --------------------------------------------------------------------------------