diff --git a/00-notes.txt b/00-notes.txt index 81144f4..e1bd62c 100644 --- a/00-notes.txt +++ b/00-notes.txt @@ -22,3 +22,10 @@ * stack overflow questions * handbook format * rosetta stone +* building an actual fucking app + * versioned transitive libraries and pegging + * creating and distributing packages, putting on github + * distributing go binary programs + * deploying to heroku + * sort-by + * errors diff --git a/11b-case.go b/11b-case.go new file mode 100644 index 0000000..e5b0f65 --- /dev/null +++ b/11b-case.go @@ -0,0 +1,16 @@ +package main + +import "fmt" + +func main() { + i := 3 + switch i { + case 0: fmt.Println("Zero") + case 1: fmt.Println("One") + case 2: fmt.Println("Two") + case 3: fmt.Println("Three") + case 4: fmt.Println("Four") + case 5: fmt.Println("Five") + default: fmt.Println("Unknown Number") + } +} diff --git a/42-select.go b/42-select.go new file mode 100644 index 0000000..fe78174 --- /dev/null +++ b/42-select.go @@ -0,0 +1,31 @@ +package main + +import ("fmt"; "time") + +func main() { + c1 := make(chan string) + c2 := make(chan string) + d := make(chan bool, 1) + + go func() { + time.Sleep(time.Millisecond * 1500) + c1 <- "from 1" + }() + go func() { + time.Sleep(time.Millisecond * 2000) + c2 <- "from 2" + }() + + go func() { + for i :=0; i < 2; i ++ { + select { + case msg1 := <- c1: + fmt.Println(msg1) + case msg2 := <- c2: + fmt.Println(msg2) + } + } + d <- true + }() + <- d +} diff --git a/43-timeout.go b/43-timeout.go new file mode 100644 index 0000000..95234bb --- /dev/null +++ b/43-timeout.go @@ -0,0 +1,24 @@ +package main + +import ("fmt"; "time") + +func main() { + c := make(chan string) + d := make(chan bool, 1) + + go func() { + time.Sleep(time.Millisecond * 1500) + c <- "ready" + }() + + go func() { + select { + case msg := <- c: + fmt.Println(msg) + case <- time.After(time.Millisecond * 1000): + fmt.Println("timeout") + } + d <- true + }() + <- d +} diff --git a/44-strings.go b/44-strings.go new file mode 100644 index 0000000..e77506e --- /dev/null +++ b/44-strings.go @@ -0,0 +1,21 @@ +package main + +import ("fmt"; "strings") + +func p(o interface{}) { + fmt.Println(o) +} + +func main() { + p(strings.Contains("test", "es")) + p(strings.Count("test", "t")) + p(strings.HasPrefix("test", "te")) + p(strings.HasSuffix("test", "st")) + p(strings.Index("test", "e")) + p(strings.Join([]string{"a","b"}, "-")) + p(strings.Repeat("a", 5)) + p(strings.Replace("aaaa", "a", "b", 2)) + p(strings.Split("a-b-c-d-e", "-")) + p(strings.ToLower("TEST")) + p(strings.ToUpper("test")) +} diff --git a/45-bytes.go b/45-bytes.go new file mode 100644 index 0000000..e7126fb --- /dev/null +++ b/45-bytes.go @@ -0,0 +1,10 @@ +package main + +import "fmt" + +func main() { + arr := []byte("some bytes") + str := string([]byte{'a', ' ', 's', 't', 'r', 'i', 'n', 'g'}) + fmt.Println(arr) + fmt.Println(str) +} diff --git a/xx-exit b/xx-exit new file mode 100755 index 0000000..c3f482c Binary files /dev/null and b/xx-exit differ diff --git a/xx-exit.go b/xx-exit.go new file mode 100644 index 0000000..0d37cc9 --- /dev/null +++ b/xx-exit.go @@ -0,0 +1,14 @@ +package main + +import "os" + +func main() { + os.Exit(3) +} + +// $ go run xx-exit.go +// exit status 3 +// $ go build xx-exit.go +// $ ./xx-exit +// $ echo $? +// 3