From 6347e2f1fe87d70ff8cd2df99103eb6eb70f81ef Mon Sep 17 00:00:00 2001 From: pro100ton Date: Sat, 2 Nov 2024 14:07:18 +0300 Subject: [PATCH] Initial migration --- .gitignore | 3 + cmd/main.go | 39 + go.mod | 3 + internal/chrono/chrono.go | 93 ++ internal/chrono/timedelta.go | 18 + internal/learning/arrays.go | 14 + internal/learning/closures.go | 47 + internal/learning/defer.go | 18 + internal/learning/errors.go | 36 + internal/learning/func_values.go | 20 + internal/learning/interfaces.go | 41 + internal/learning/interfaces_2.go | 47 + internal/learning/maps.go | 64 ++ internal/learning/methods.go | 30 + internal/learning/pointers.go | 17 + internal/learning/range.go | 10 + internal/learning/slices.go | 51 ++ internal/learning/stringers.go | 46 + internal/learning/struct.go | 26 + internal/learning/switch.go | 18 + internal/learning/type_assertions.go | 41 + internal/pointers/pointers.go | 33 + internal/test/sqrt.go | 9 + regex.txt | 1 + route_guide/README.md | 35 + route_guide/client/client.go | 195 ++++ route_guide/routeguide/route_guide.pb.go | 540 +++++++++++ route_guide/routeguide/route_guide.proto | 111 +++ route_guide/routeguide/route_guide_grpc.pb.go | 368 ++++++++ route_guide/server/server.go | 845 ++++++++++++++++++ route_guide/testdata/route_guide_db.json | 601 +++++++++++++ stepik/intro.go | 52 ++ 32 files changed, 3472 insertions(+) create mode 100644 .gitignore create mode 100644 cmd/main.go create mode 100644 go.mod create mode 100644 internal/chrono/chrono.go create mode 100644 internal/chrono/timedelta.go create mode 100644 internal/learning/arrays.go create mode 100644 internal/learning/closures.go create mode 100644 internal/learning/defer.go create mode 100644 internal/learning/errors.go create mode 100644 internal/learning/func_values.go create mode 100644 internal/learning/interfaces.go create mode 100644 internal/learning/interfaces_2.go create mode 100644 internal/learning/maps.go create mode 100644 internal/learning/methods.go create mode 100644 internal/learning/pointers.go create mode 100644 internal/learning/range.go create mode 100644 internal/learning/slices.go create mode 100644 internal/learning/stringers.go create mode 100644 internal/learning/struct.go create mode 100644 internal/learning/switch.go create mode 100644 internal/learning/type_assertions.go create mode 100644 internal/pointers/pointers.go create mode 100644 internal/test/sqrt.go create mode 100644 regex.txt create mode 100644 route_guide/README.md create mode 100644 route_guide/client/client.go create mode 100644 route_guide/routeguide/route_guide.pb.go create mode 100644 route_guide/routeguide/route_guide.proto create mode 100644 route_guide/routeguide/route_guide_grpc.pb.go create mode 100644 route_guide/server/server.go create mode 100644 route_guide/testdata/route_guide_db.json create mode 100644 stepik/intro.go diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f3ebe5b --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.null-ls* +chrono.txt +.DS_Store diff --git a/cmd/main.go b/cmd/main.go new file mode 100644 index 0000000..6479421 --- /dev/null +++ b/cmd/main.go @@ -0,0 +1,39 @@ +package main + +import "fmt" + +func read_from_c(c chan int, b chan int) { + for item := range c { + fmt.Printf("%d", item) + number_multiplied := item * item + b <- number_multiplied + } + close(b) +} + +func read_from_b(b chan int) { + for item := range b { + fmt.Printf("%d", item) + } +} + +func main() { + fmt.Println("main() started") + c := make(chan int) + b := make(chan int) + + fmt.Println("Operation started") + go func() { + fmt.Println("Running writer") + for i := 1; i < 10; i++ { + fmt.Printf("Adding %v to channel c", i) + c <- i + } + close(c) + }() + + go read_from_c(c, b) + for item := range b { + fmt.Printf("%d", item) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..6d1d12e --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module go_sandbox + +go 1.21.3 diff --git a/internal/chrono/chrono.go b/internal/chrono/chrono.go new file mode 100644 index 0000000..370821e --- /dev/null +++ b/internal/chrono/chrono.go @@ -0,0 +1,93 @@ +package chrono + +import ( + "bufio" + "fmt" + "os" + "path/filepath" + "regexp" + "time" +) + +type ChronoEntry struct { + Date, Time, Action string +} + +type ParsedChronoEntry struct { + StartTime time.Time + Action string + Duration string +} + +func Chrono() { + // Return path of an executable + exPath, err := os.Executable() + if err != nil { + panic(err) + } + exDir := filepath.Dir(exPath) + fmt.Println(exDir) + // Return path of the current directory + path, err := os.Getwd() + if err != nil { + panic(err) + } + // Join paths + textFilePath := filepath.Join(path, "chrono.txt") + // Read file with chrono data + readFile, err := os.Open(textFilePath) + if err != nil { + panic(err) + } + defer readFile.Close() + + fileScanner := bufio.NewScanner(readFile) + fileScanner.Split(bufio.ScanLines) + var fileLines []string + for fileScanner.Scan() { + fileLines = append(fileLines, fileScanner.Text()) + } + // Prepare slice for data + parse_result := make([]ChronoEntry, 0) + result := make([]ParsedChronoEntry, 0) + r := regexp.MustCompile( + `(?P\d{2}\s\w*\s\d{4})\s+at\s+(?P