Compare commits

..

No commits in common. "883e0e2e27826d18daaec478ccaf9966ac140859" and "50567bc93ee9cf5e880844c8c0ace72c0ce08823" have entirely different histories.

28 changed files with 89 additions and 556 deletions

View File

@ -4,9 +4,7 @@ Playing with Golang mostly using the Head First Go book.
Entry point is playground.go. Entry point is playground.go.
To run the playground use To run use
```sh ```sh
cd playground
go run trying_out_go go run trying_out_go
``` ```
For any other folders, these are all separate go programs. Use the commands above and edit playground and trying_out_go to the matching folder name.

13
average.go Normal file
View File

@ -0,0 +1,13 @@
package main
import "fmt"
func average() {
numbers := [3]float64{71.8, 56.2, 89.5}
var sum float64 = 0
for _, number := range numbers {
sum += number
}
sampleCount := float64(len(numbers))
fmt.Printf("Average: %0.2f\n", sum/sampleCount)
}

View File

@ -1,22 +0,0 @@
package main
import (
"fmt"
"log"
"os"
"strconv"
)
func main() {
arguments := os.Args[1:]
var sum float64 = 0
for _, argument := range arguments {
number, err := strconv.ParseFloat(argument, 64)
if err != nil {
log.Fatal(err)
}
sum += number
}
sampleCount := float64(len(arguments))
fmt.Printf("Average: %0.2f\n", sum/sampleCount)
}

View File

@ -1,3 +0,0 @@
module averageWithArgs
go 1.21.3

View File

@ -1,4 +0,0 @@
50.2
60.2
74.3
85.4

View File

@ -3,10 +3,9 @@ module trying_out_go
go 1.21.3 go 1.21.3
require ( require (
git.linuxhg.com/john-okeefe/datafile v0.0.0-20231219141638-ac759640d76a git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016161119-714c103574cc
git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016162410-a86e636ae533 github.com/charmbracelet/bubbles v0.16.1
github.com/charmbracelet/bubbles v0.17.1 github.com/charmbracelet/bubbletea v0.24.2
github.com/charmbracelet/bubbletea v0.25.0
github.com/charmbracelet/lipgloss v0.9.1 github.com/charmbracelet/lipgloss v0.9.1
github.com/dixonwille/wmenu/v5 v5.1.0 github.com/dixonwille/wmenu/v5 v5.1.0
) )
@ -26,7 +25,7 @@ require (
github.com/muesli/reflow v0.3.0 // indirect github.com/muesli/reflow v0.3.0 // indirect
github.com/muesli/termenv v0.15.2 // indirect github.com/muesli/termenv v0.15.2 // indirect
github.com/rivo/uniseg v0.4.4 // indirect github.com/rivo/uniseg v0.4.4 // indirect
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f // indirect github.com/sahilm/fuzzy v0.1.0 // indirect
golang.org/x/sync v0.4.0 // indirect golang.org/x/sync v0.4.0 // indirect
golang.org/x/sys v0.13.0 // indirect golang.org/x/sys v0.13.0 // indirect
golang.org/x/term v0.13.0 // indirect golang.org/x/term v0.13.0 // indirect

View File

@ -1,29 +1,24 @@
git.linuxhg.com/john-okeefe/datafile v0.0.0-20231025144217-70a69b064e81 h1:M19j4vHPgap0R7r3Lc0C5QZIjBFixkwuvRnUGDIC9+o= git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016005355-05ed8b28800e h1:oCGqHZUhesu14KQUELz0jxIPnL/KcGFhsmNnKoAZMo4=
git.linuxhg.com/john-okeefe/datafile v0.0.0-20231025144217-70a69b064e81/go.mod h1:HexHt1UMGUDMV5bhB81nAKdvGaCnxKA2upRd7cV8laI= git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016005355-05ed8b28800e/go.mod h1:zxW/S0TzdzmyfloJ0ZHwMaTjMgfd8hK8TycSEAyMRkY=
git.linuxhg.com/john-okeefe/datafile v0.0.0-20231219141638-ac759640d76a h1:TZ/nNuTzuOXWeLt8SF/NJOHbIPjNcIxMk8xKMsy02O8=
git.linuxhg.com/john-okeefe/datafile v0.0.0-20231219141638-ac759640d76a/go.mod h1:HexHt1UMGUDMV5bhB81nAKdvGaCnxKA2upRd7cV8laI=
git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016161119-714c103574cc h1:J5VWew9I6gCCYVxQ/5NEtsD4wcMZcc4e05V44OiSNi4= git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016161119-714c103574cc h1:J5VWew9I6gCCYVxQ/5NEtsD4wcMZcc4e05V44OiSNi4=
git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016161119-714c103574cc/go.mod h1:zxW/S0TzdzmyfloJ0ZHwMaTjMgfd8hK8TycSEAyMRkY= git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016161119-714c103574cc/go.mod h1:zxW/S0TzdzmyfloJ0ZHwMaTjMgfd8hK8TycSEAyMRkY=
git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016162410-a86e636ae533 h1:aT1lCBtfeLL/BfQC90TA7zHUQu2D4IxiT+3hN3Jel/E=
git.linuxhg.com/john-okeefe/keyboard v0.0.0-20231016162410-a86e636ae533/go.mod h1:zxW/S0TzdzmyfloJ0ZHwMaTjMgfd8hK8TycSEAyMRkY=
github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4=
github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI=
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY= github.com/charmbracelet/bubbles v0.16.1 h1:6uzpAAaT9ZqKssntbvZMlksWHruQLNxg49H5WdeuYSY=
github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc= github.com/charmbracelet/bubbles v0.16.1/go.mod h1:2QCp9LFlEsBQMvIYERr7Ww2H2bA7xen1idUDIzm/+Xc=
github.com/charmbracelet/bubbles v0.17.1 h1:0SIyjOnkrsfDo88YvPgAWvZMwXe26TP6drRvmkjyUu4=
github.com/charmbracelet/bubbles v0.17.1/go.mod h1:9HxZWlkCqz2PRwsCbYl7a3KXvGzFaDHpYbSYMJ+nE3o=
github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY= github.com/charmbracelet/bubbletea v0.24.2 h1:uaQIKx9Ai6Gdh5zpTbGiWpytMU+CfsPp06RaW2cx/SY=
github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg= github.com/charmbracelet/bubbletea v0.24.2/go.mod h1:XdrNrV4J8GiyshTtx3DNuYkR1FDaJmO3l2nejekbsgg=
github.com/charmbracelet/bubbletea v0.25.0 h1:bAfwk7jRz7FKFl9RzlIULPkStffg5k6pNt5dywy4TcM= github.com/charmbracelet/lipgloss v0.8.0 h1:IS00fk4XAHcf8uZKc3eHeMUTCxUH6NkaTrdyCQk84RU=
github.com/charmbracelet/bubbletea v0.25.0/go.mod h1:EN3QDR1T5ZdWmdfDzYcqOCAps45+QIJbLOBxmVNWNNg= github.com/charmbracelet/lipgloss v0.8.0/go.mod h1:p4eYUZZJ/0oXTuCQKFF8mqyKCz0ja6y+7DniDDw5KKU=
github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg= github.com/charmbracelet/lipgloss v0.9.1 h1:PNyd3jvaJbg4jRHKWXnCj1akQm4rh8dbEzN1p/u1KWg=
github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I= github.com/charmbracelet/lipgloss v0.9.1/go.mod h1:1mPmG4cxScwUQALAAnacHaigiiHB9Pmr+v1VEawJl6I=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81 h1:q2hJAaP1k2wIvVRd/hEHD7lacgqrCPS+k8g1MndzfWY=
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk= github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81/go.mod h1:YynlIjWYF8myEu6sdkwKIvGQq+cOckRm6So2avqoYAk=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920 h1:d/cVoZOrJPJHKH1NdeUjyVAWKp4OpOT+Q+6T1sH7jeU=
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920/go.mod h1:dv4zxwHi5C/8AeI+4gX4dCWOIvNi7I6JCSX0HvlKPgE= github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920/go.mod h1:dv4zxwHi5C/8AeI+4gX4dCWOIvNi7I6JCSX0HvlKPgE=
github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX8ATG8oKsE= github.com/daviddengcn/go-colortext v1.0.0 h1:ANqDyC0ys6qCSvuEK7l3g5RaehL/Xck9EX8ATG8oKsE=
github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c= github.com/daviddengcn/go-colortext v1.0.0/go.mod h1:zDqEI5NVUop5QPpVJUxE9UO10hRnmkD5G4Pmri9+m4c=
@ -35,6 +30,7 @@ github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAO
github.com/golangplus/bytes v1.0.0/go.mod h1:AdRaCFwmc/00ZzELMWb01soso6W1R/++O1XL80yAn+A= github.com/golangplus/bytes v1.0.0/go.mod h1:AdRaCFwmc/00ZzELMWb01soso6W1R/++O1XL80yAn+A=
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkYFkPcDKwRXegd+iM6E7matEszMG5HhwytU8= github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkYFkPcDKwRXegd+iM6E7matEszMG5HhwytU8=
github.com/golangplus/fmt v1.0.0/go.mod h1:zpM0OfbMCjPtd2qkTD/jX2MgiFCqklhSUFyDW44gVQE= github.com/golangplus/fmt v1.0.0/go.mod h1:zpM0OfbMCjPtd2qkTD/jX2MgiFCqklhSUFyDW44gVQE=
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e h1:KhcknUwkWHKZPbFy2P7jH5LKJ3La+0ZeknkkmrSgqb0=
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk= github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk=
github.com/golangplus/testing v1.0.0 h1:+ZeeiKZENNOMkTTELoSySazi+XaEhVO0mb+eanrSEUQ= github.com/golangplus/testing v1.0.0 h1:+ZeeiKZENNOMkTTELoSySazi+XaEhVO0mb+eanrSEUQ=
github.com/golangplus/testing v1.0.0/go.mod h1:ZDreixUV3YzhoVraIDyOzHrr76p6NUh6k/pPg/Q3gYA= github.com/golangplus/testing v1.0.0/go.mod h1:ZDreixUV3YzhoVraIDyOzHrr76p6NUh6k/pPg/Q3gYA=
@ -43,13 +39,19 @@ github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98=
github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4=
github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88=
github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk= github.com/mattn/go-runewidth v0.0.12/go.mod h1:RAqKPSqVFrSLVXbA8x7dzmKdmGzieGRCM46jaSJTDAk=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U=
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b h1:1XF24mVaiu7u+CFywTdcDo2ie1pzzhwjt6RHqzpMU34=
github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI= github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6 h1:ZK8zHtRHOkbHy6Mmr5D264iyp3TiX5OmNcI5cIARiQI=
github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo= github.com/muesli/ansi v0.0.0-20230316100256-276c6243b2f6/go.mod h1:CJlz5H+gyd6CUWT45Oy4q24RdLyn7Md9Vj2/ldJBSIo=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA= github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
@ -61,25 +63,32 @@ github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1n
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis= github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rivo/uniseg v0.4.4/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI= github.com/sahilm/fuzzy v0.1.0 h1:FzWGaw2Opqyu+794ZQ9SYifWv2EIXpwP4q8dY1kDAwI=
github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y= github.com/sahilm/fuzzy v0.1.0/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f h1:MvTmaQdww/z0Q4wrYjDSCcZ78NoftLQyHBSLW/Cx79Y=
github.com/sahilm/fuzzy v0.1.1-0.20230530133925-c48e322e2a8f/go.mod h1:VFvziUEIMCrT6A6tw2RFIXPXXmzXbOsSHF0DOI8ZK9Y=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ= golang.org/x/sync v0.4.0 h1:zxkM55ReGkDlKSM+Fu41A+zmbZuaPVbGMzvvdUPznYQ=
golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sync v0.4.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.7.0 h1:3jlCCIQZPdOYu1h8BkNvLz8Kgwtae2cagcG/VamtZRU=
golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE= golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.6.0 h1:clScbb1cHjoCkyRbWwBEUZ5H/tIFu5TAXIqaZD0Gcjw=
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY=
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

View File

@ -1,18 +0,0 @@
package main
import "fmt"
func sum(numbers ...int) int {
var sum int = 0
for _, number := range numbers {
sum += number
}
return sum
}
func main() {
fmt.Println(sum(4, 1, 9, 2))
fmt.Println(sum(7))
}

50
playground.go Normal file
View File

@ -0,0 +1,50 @@
package main
import (
"fmt"
"log"
"github.com/dixonwille/wmenu/v5"
)
func main() {
menu := wmenu.NewMenu("Choose a program.")
menu.Action(func(opts []wmenu.Opt) error {
fmt.Printf("You chose " + opts[0].Text + ". Launching...\n")
switch opts[0].Text {
case "Pass or Fail":
passFail()
case "Guessing Game":
guess()
case "Shopping List":
shopping()
case "Commandline Test":
terminalTest()
case "Wall Area":
wallArea()
case "myIntPointer":
myIntPointer()
case "Double":
double()
case "Convert To Celsius":
toCelsius()
case "Get the Average":
average()
}
return nil
})
menu.PadOptionID()
menu.Option("Pass or Fail", nil, false, nil)
menu.Option("Guessing Game", nil, false, nil)
menu.Option("Shopping List", nil, false, nil)
menu.Option("Commandline Test", nil, false, nil)
menu.Option("Wall Area", nil, false, nil)
menu.Option("myIntPointer", nil, false, nil)
menu.Option("Double", nil, false, nil)
menu.Option("Convert To Celsius", nil, false, nil)
menu.Option("Get the Average", nil, false, nil)
err := menu.Run()
if err != nil {
log.Fatal(err)
}
}

View File

@ -1,24 +0,0 @@
package main
import (
"fmt"
"strings"
"git.linuxhg.com/john-okeefe/datafile"
"git.linuxhg.com/john-okeefe/keyboard"
)
func averageHeadFirstSolution() {
fmt.Printf("What is the name of the file: ")
fileString, err := keyboard.GetString()
Error(err)
fileString = strings.TrimSpace(fileString)
numbers, err := datafile.GetFloats(fileString)
Error(err)
var sum float64 = 0
for _, number := range numbers {
sum += number
}
sampleCount := float64(len(numbers))
fmt.Printf("Average: %0.2f\n", sum/sampleCount)
}

View File

@ -1,26 +0,0 @@
package main
import (
"fmt"
"os"
"strconv"
)
func averageCalc(numbers ...float64) float64 {
var sum float64 = 0
for _, number := range numbers {
sum += number
}
return sum / float64(len(numbers))
}
func averageHeadFirstVariadic() {
arguments := os.Args[1:]
var numbers []float64
for _, argument := range arguments {
number, err := strconv.ParseFloat(argument, 64)
Error(err)
numbers = append(numbers, number)
}
fmt.Printf("Average: %0.2\n", averageCalc(numbers...))
}

View File

@ -1,37 +0,0 @@
package main
import (
"bufio"
"fmt"
"log"
"os"
"strconv"
"strings"
"git.linuxhg.com/john-okeefe/keyboard"
)
func averageMySolution() {
fmt.Printf("What is the name of the file: ")
fileString, err := keyboard.GetString()
Error(err)
fileString = strings.TrimSpace(fileString)
file, err := os.Open(fileString)
Error(err)
var sum float64 = 0
scanner := bufio.NewScanner(file)
counter := 0
for scanner.Scan() {
number, err := strconv.ParseFloat(scanner.Text(), 64)
Error(err)
sum += number
counter++
}
err = file.Close()
Error(err)
if scanner.Err() != nil {
log.Fatal(scanner.Err())
}
sampleCount := float64(counter)
fmt.Printf("Average: %0.2f\n", sum/sampleCount)
}

View File

@ -1,16 +0,0 @@
package main
import "fmt"
func average(numbers ...float64) float64 {
var sum float64 = 0
for _, number := range numbers {
sum += number
}
return sum / float64(len(numbers))
}
func averageVariadic() {
fmt.Println(average(100, 50))
fmt.Println(average(90.7, 89.7, 98.5, 92.3))
}

View File

@ -1,56 +0,0 @@
// from Chapter 7 of Head First Go
package main
import (
"fmt"
"git.linuxhg.com/john-okeefe/datafile"
"git.linuxhg.com/john-okeefe/keyboard"
"sort"
"strings"
)
func countVotes() {
fmt.Printf("What is the name of the file: ")
fileString, err := keyboard.GetString()
Error(err)
fileString = strings.TrimSpace(fileString)
lines, err := datafile.GetStrings(fileString)
Error(err)
// Count the hard way with slices
var names []string
var counts []int
for _, line := range lines {
matched := false
for i, name := range names {
if name == line {
counts[i]++
matched = true
}
}
if matched == false {
names = append(names, line)
counts = append(counts, 1)
}
}
for i, name := range names {
fmt.Printf("%s: %d\n", name, counts[i])
}
fmt.Println("")
// Easy way
votes := make(map[string]int)
var namesMap []string
for _, line := range lines {
votes[line]++
}
for name := range votes {
namesMap = append(namesMap, name)
}
sort.Strings(namesMap)
for _, name := range namesMap {
fmt.Printf("%v: %v\n", name, votes[name])
}
}

View File

@ -1,10 +0,0 @@
package main
import "log"
func Error(err error) {
if err != nil {
log.Fatal(err)
}
return
}

View File

@ -1,22 +0,0 @@
// from chapter 8 of head first go
package main
import "fmt"
type subscriberType struct {
name string
rate float64
active bool
}
func magazineSubscribers() {
var subscriber subscriberType
subscriber.name = "Aman Singh"
subscriber.rate = 4.99
subscriber.active = true
fmt.Println("Name:", subscriber.name)
fmt.Println("Monthly rate:", subscriber.rate)
fmt.Println("Active?:", subscriber.active)
}

View File

@ -1,127 +0,0 @@
package main
import (
"fmt"
"log"
"github.com/dixonwille/wmenu/v5"
)
func main() {
type program struct {
name string
launchFunction func()
}
programs := []program{
{
name: "Pass or Fail",
launchFunction: func() {
passFail()
},
},
{
name: "Guessing Game",
launchFunction: func() {
guess()
},
},
{
name: "Shopping List",
launchFunction: func() {
shopping()
},
},
{
name: "Commandline Test",
launchFunction: func() {
terminalTest()
},
},
{
name: "Wall Area",
launchFunction: func() {
wallArea()
},
},
{
name: "myIntPointer",
launchFunction: func() {
myIntPointer()
},
},
{
name: "Double",
launchFunction: func() {
double()
},
},
{
name: "Convert To Celsius",
launchFunction: func() {
toCelsius()
},
},
{
name: "Get the Average My Solution",
launchFunction: func() {
averageMySolution()
},
},
{
name: "Get the Average Head First Solution",
launchFunction: func() {
averageHeadFirstSolution()
},
},
{
name: "Get the Average Variadic",
launchFunction: func() {
averageVariadic()
},
},
{
name: "Slices",
launchFunction: func() {
slices()
},
},
{
name: "Variadic Functions",
launchFunction: func() {
variadic()
},
},
{
name: "Count Votes",
launchFunction: func() {
countVotes()
},
},
{
name: "Magazine Subscribers",
launchFunction: func() {
magazineSubscribers()
},
},
}
menu := wmenu.NewMenu("Choose a program.")
menu.Action(func(opts []wmenu.Opt) error {
fmt.Printf("You chose " + opts[0].Text + ". Launching...\n")
for _, v := range programs {
if v.name == opts[0].Text {
v.launchFunction()
}
}
return nil
})
menu.PadOptionID()
for _, option := range programs {
menu.Option(option.name, nil, false, nil)
}
err := menu.Run()
if err != nil {
log.Fatal(err)
}
}

View File

@ -1,41 +0,0 @@
package main
import "fmt"
func slices() {
var notes []string
notes = make([]string, 7)
notes[0] = "do"
notes[1] = "re"
notes[2] = "mi"
fmt.Println(notes[0])
fmt.Println(notes[1])
fmt.Println(len(notes))
primes := make([]int, 5)
primes[0] = 2
primes[1] = 3
primes[2] = 5
primes[3] = 7
primes[4] = 11
fmt.Println(primes[0])
fmt.Println(primes[1])
fmt.Println(primes[2])
fmt.Println(primes[3])
fmt.Println(primes[4])
fmt.Println(len(primes))
literalNotes := []string{"do", "re", "mi", "fa", "so", "la", "ti"}
fmt.Println(literalNotes[3], literalNotes[6], literalNotes[0])
literalPrimes := []int{
2,
3,
5,
}
fmt.Println(literalPrimes[0], literalPrimes[1], literalPrimes[2])
fmt.Println(literalPrimes, len(literalPrimes))
literalPrimes = append(literalPrimes, 7, 11)
fmt.Println(literalPrimes, len(literalPrimes))
}

View File

@ -1,33 +0,0 @@
package main
import (
"fmt"
"math"
)
func maximum(numbers ...float64) float64 {
max := math.Inf(-1)
for _, number := range numbers {
if number > max {
max = number
}
}
return max
}
func inRange(min float64, max float64, numbers ...float64) []float64 {
var result []float64
for _, number := range numbers {
if number >= min && number <= max {
result = append(result, number)
}
}
return result
}
func variadic() {
fmt.Println(maximum(71.8, 56.2, 89.5))
fmt.Println(maximum(90.7, 89.7, 98.5, 92.3))
fmt.Println(inRange(1, 100, -12.5, 3.2, 0, 50, 103.5))
fmt.Println(inRange(-10, 10, 4.1, 12, -12, -5.2))
}

View File

@ -1,97 +0,0 @@
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Brian Martin
Amber Graham
Carloz Diaz
Silly name