diff --git a/000_temp/52-race-condition/06_chan-pre-lecture/main.go b/000_temp/52-race-condition/06_chan-pre-lecture/main.go index 193836bb..e3083e04 100644 --- a/000_temp/52-race-condition/06_chan-pre-lecture/main.go +++ b/000_temp/52-race-condition/06_chan-pre-lecture/main.go @@ -30,4 +30,4 @@ func main() { wg.Wait() close(c) fmt.Println("total count:", counter) -} \ No newline at end of file +} diff --git a/000_temp/55-website/main.go b/000_temp/55-website/main.go index 951d0842..51e61ade 100644 --- a/000_temp/55-website/main.go +++ b/000_temp/55-website/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -14,4 +14,4 @@ func init() { func main() { loadRoutes() http.ListenAndServe(":8080", nil) -} \ No newline at end of file +} diff --git a/000_temp/55-website/rAbout.go b/000_temp/55-website/rAbout.go index 19a7e6aa..12e1a845 100644 --- a/000_temp/55-website/rAbout.go +++ b/000_temp/55-website/rAbout.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "log" + "net/http" ) func about(w http.ResponseWriter, r *http.Request) { @@ -11,4 +11,3 @@ func about(w http.ResponseWriter, r *http.Request) { log.Println(err) } } - diff --git a/000_temp/55-website/rIndex.go b/000_temp/55-website/rIndex.go index d9c23ef9..fbf9401c 100644 --- a/000_temp/55-website/rIndex.go +++ b/000_temp/55-website/rIndex.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "log" + "net/http" ) func index(w http.ResponseWriter, r *http.Request) { diff --git a/000_temp/56_SVCC-17/01a/main.go b/000_temp/56_SVCC-17/01a/main.go index edbeae10..4900f12c 100644 --- a/000_temp/56_SVCC-17/01a/main.go +++ b/000_temp/56_SVCC-17/01a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) func main() { diff --git a/000_temp/56_SVCC-17/01b/main.go b/000_temp/56_SVCC-17/01b/main.go index 1493ee89..279761d5 100644 --- a/000_temp/56_SVCC-17/01b/main.go +++ b/000_temp/56_SVCC-17/01b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) func main() { @@ -12,4 +12,4 @@ func main() { func foo(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "hello world") -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/01c/main.go b/000_temp/56_SVCC-17/01c/main.go index 876bf60b..c48636a0 100644 --- a/000_temp/56_SVCC-17/01c/main.go +++ b/000_temp/56_SVCC-17/01c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) func main() { @@ -10,6 +10,6 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "Hello SVCC from Paypal") } diff --git a/000_temp/56_SVCC-17/01d/main.go b/000_temp/56_SVCC-17/01d/main.go index a87bc9e8..68f251c9 100644 --- a/000_temp/56_SVCC-17/01d/main.go +++ b/000_temp/56_SVCC-17/01d/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) func main() { @@ -12,4 +12,4 @@ func main() { func index(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "Hello GDG Fresno") -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/02a/main.go b/000_temp/56_SVCC-17/02a/main.go index f7e8ea89..ffcebebe 100644 --- a/000_temp/56_SVCC-17/02a/main.go +++ b/000_temp/56_SVCC-17/02a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func foo(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/02b/main.go b/000_temp/56_SVCC-17/02b/main.go index f7e8ea89..ffcebebe 100644 --- a/000_temp/56_SVCC-17/02b/main.go +++ b/000_temp/56_SVCC-17/02b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func foo(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/02c/main.go b/000_temp/56_SVCC-17/02c/main.go index 15895c70..3c978b33 100644 --- a/000_temp/56_SVCC-17/02c/main.go +++ b/000_temp/56_SVCC-17/02c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -16,6 +16,6 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) } diff --git a/000_temp/56_SVCC-17/02d/main.go b/000_temp/56_SVCC-17/02d/main.go index 987da27b..21ff5e92 100644 --- a/000_temp/56_SVCC-17/02d/main.go +++ b/000_temp/56_SVCC-17/02d/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/03a/main.go b/000_temp/56_SVCC-17/03a/main.go index f7e8ea89..ffcebebe 100644 --- a/000_temp/56_SVCC-17/03a/main.go +++ b/000_temp/56_SVCC-17/03a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func foo(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/03b/main.go b/000_temp/56_SVCC-17/03b/main.go index f7e8ea89..ffcebebe 100644 --- a/000_temp/56_SVCC-17/03b/main.go +++ b/000_temp/56_SVCC-17/03b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func foo(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/03c/main.go b/000_temp/56_SVCC-17/03c/main.go index 15895c70..3c978b33 100644 --- a/000_temp/56_SVCC-17/03c/main.go +++ b/000_temp/56_SVCC-17/03c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -16,6 +16,6 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) } diff --git a/000_temp/56_SVCC-17/03d/main.go b/000_temp/56_SVCC-17/03d/main.go index 987da27b..21ff5e92 100644 --- a/000_temp/56_SVCC-17/03d/main.go +++ b/000_temp/56_SVCC-17/03d/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,4 +18,4 @@ func main() { func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/04a/main.go b/000_temp/56_SVCC-17/04a/main.go index 6e93561a..d24c8f45 100644 --- a/000_temp/56_SVCC-17/04a/main.go +++ b/000_temp/56_SVCC-17/04a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,4 +23,4 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "about.gohtml", "OUR TEAM") -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/04b/main.go b/000_temp/56_SVCC-17/04b/main.go index 16916c52..a6b8f5ca 100644 --- a/000_temp/56_SVCC-17/04b/main.go +++ b/000_temp/56_SVCC-17/04b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,4 +23,4 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "about.gohtml", "THE TEAM") -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/04c/main.go b/000_temp/56_SVCC-17/04c/main.go index 612070fe..dfb4b33f 100644 --- a/000_temp/56_SVCC-17/04c/main.go +++ b/000_temp/56_SVCC-17/04c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -17,11 +17,10 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", "ACME INC") } - -func about(w http.ResponseWriter, r *http.Request){ +func about(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "about.gohtml", "ABOUT OUR TEAM") } diff --git a/000_temp/56_SVCC-17/04d/main.go b/000_temp/56_SVCC-17/04d/main.go index ab0fd8b8..99d15727 100644 --- a/000_temp/56_SVCC-17/04d/main.go +++ b/000_temp/56_SVCC-17/04d/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,4 +23,4 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "about.gohtml", nil) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/05a/main.go b/000_temp/56_SVCC-17/05a/main.go index dfdfeaa4..1ea5b277 100644 --- a/000_temp/56_SVCC-17/05a/main.go +++ b/000_temp/56_SVCC-17/05a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,14 +23,14 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "OUR TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "OUR TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/05b/main.go b/000_temp/56_SVCC-17/05b/main.go index ed9351e0..4f1d2d8a 100644 --- a/000_temp/56_SVCC-17/05b/main.go +++ b/000_temp/56_SVCC-17/05b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,14 +23,14 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "THE TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "THE TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/05c/main.go b/000_temp/56_SVCC-17/05c/main.go index 6a04289e..f96b5c90 100644 --- a/000_temp/56_SVCC-17/05c/main.go +++ b/000_temp/56_SVCC-17/05c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -17,20 +17,19 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", "ACME INC") } - -func about(w http.ResponseWriter, r *http.Request){ +func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "ABOUT OUR TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "ABOUT OUR TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) diff --git a/000_temp/56_SVCC-17/05d/main.go b/000_temp/56_SVCC-17/05d/main.go index f70678cf..d0b8460f 100644 --- a/000_temp/56_SVCC-17/05d/main.go +++ b/000_temp/56_SVCC-17/05d/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -23,14 +23,14 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "ABOUT OUR TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "ABOUT OUR TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/06a/main.go b/000_temp/56_SVCC-17/06a/main.go index 7d08dc69..2c2eb857 100644 --- a/000_temp/56_SVCC-17/06a/main.go +++ b/000_temp/56_SVCC-17/06a/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -24,14 +24,14 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "OUR TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "OUR TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/06b/main.go b/000_temp/56_SVCC-17/06b/main.go index d93fe774..029717f3 100644 --- a/000_temp/56_SVCC-17/06b/main.go +++ b/000_temp/56_SVCC-17/06b/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -24,14 +24,14 @@ func index(w http.ResponseWriter, r *http.Request) { func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "THE TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "THE TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) -} \ No newline at end of file +} diff --git a/000_temp/56_SVCC-17/06c/main.go b/000_temp/56_SVCC-17/06c/main.go index 0c66592a..2052430b 100644 --- a/000_temp/56_SVCC-17/06c/main.go +++ b/000_temp/56_SVCC-17/06c/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -18,20 +18,19 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { tpl.ExecuteTemplate(w, "index.gohtml", "ACME INC") } - -func about(w http.ResponseWriter, r *http.Request){ +func about(w http.ResponseWriter, r *http.Request) { type customData struct { - Title string + Title string Members []string } cd := customData{ - Title: "ABOUT OUR TEAM", - Members: []string{"Moneypenny", "Bond", "Q", "M",}, + Title: "ABOUT OUR TEAM", + Members: []string{"Moneypenny", "Bond", "Q", "M"}, } tpl.ExecuteTemplate(w, "about.gohtml", cd) diff --git a/000_temp/56_SVCC-17/07-concurrency/main.go b/000_temp/56_SVCC-17/07-concurrency/main.go index 17c82741..ad6b5cf4 100644 --- a/000_temp/56_SVCC-17/07-concurrency/main.go +++ b/000_temp/56_SVCC-17/07-concurrency/main.go @@ -4,7 +4,7 @@ import "fmt" func main() { c := make(chan int) - go func(){ + go func() { c <- 42 }() fmt.Println(<-c) diff --git a/000_temp/57-form/01/main.go b/000_temp/57-form/01/main.go index 50f2a0f8..7b7e8f29 100644 --- a/000_temp/57-form/01/main.go +++ b/000_temp/57-form/01/main.go @@ -1,8 +1,8 @@ package _1 import ( - "net/http" "io" + "net/http" ) func main() { diff --git a/000_temp/57-form/02/main.go b/000_temp/57-form/02/main.go index 726954e7..68b3556c 100644 --- a/000_temp/57-form/02/main.go +++ b/000_temp/57-form/02/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) var tpl *template.Template @@ -34,13 +34,13 @@ func processor(w http.ResponseWriter, r *http.Request) { skate := r.FormValue("skate") radio := r.FormValue("cow") - d := struct{ + d := struct { First, Last, Surf, Snow, Skate, Radio string }{ First: fname, - Last: lname, - Surf: surf, - Snow: snow, + Last: lname, + Surf: surf, + Snow: snow, Skate: skate, Radio: radio, } diff --git a/000_temp/59-html-form/main.go b/000_temp/59-html-form/main.go index 84db73fe..992111d9 100644 --- a/000_temp/59-html-form/main.go +++ b/000_temp/59-html-form/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "html/template" + "net/http" ) type GData struct { @@ -58,18 +58,17 @@ func process(w http.ResponseWriter, r *http.Request) { fn := r.FormValue("first") ln := r.FormValue("last") - d := struct{ + d := struct { GData First string - Last string + Last string }{ GData: GData{ Title: "PROCESS", }, First: fn, - Last: ln, + Last: ln, } tpl.ExecuteTemplate(w, "process.gohtml", d) } - diff --git a/000_temp/60-redirect/main.go b/000_temp/60-redirect/main.go index 9cfe5c71..57fad399 100644 --- a/000_temp/60-redirect/main.go +++ b/000_temp/60-redirect/main.go @@ -1,8 +1,8 @@ package main import ( - "net/http" "io" + "net/http" ) func main() { @@ -11,12 +11,11 @@ func main() { http.ListenAndServe(":8080", nil) } -func index(w http.ResponseWriter, r *http.Request){ +func index(w http.ResponseWriter, r *http.Request) { http.Redirect(w, r, "/new", http.StatusSeeOther) io.WriteString(w, "You are at index") } -func newplace(w http.ResponseWriter, r *http.Request){ +func newplace(w http.ResponseWriter, r *http.Request) { io.WriteString(w, "You are at newplace") } - diff --git a/000_temp/61-assertion/main.go b/000_temp/61-assertion/main.go index 3b3f5ca8..9fd92895 100644 --- a/000_temp/61-assertion/main.go +++ b/000_temp/61-assertion/main.go @@ -4,7 +4,7 @@ import "fmt" func main() { var s interface{} - s = struct{ + s = struct { name string }{ name: "james bond", diff --git a/000_temp/62-kelowna/00-prep/01/main.go b/000_temp/62-kelowna/00-prep/01/main.go new file mode 100644 index 00000000..f98e0ff9 --- /dev/null +++ b/000_temp/62-kelowna/00-prep/01/main.go @@ -0,0 +1,57 @@ +package main + +import "fmt" + +type person struct { + first string + last string +} + +type secretAgent struct { + person + ltk bool +} + +func (p person) speak() { + fmt.Println("hello from", p.first) +} + +func (sa secretAgent) speak() { + fmt.Println("hello from", sa.first) +} + +type human interface { + speak() +} + +func foo(h human) { + h.speak() +} + +func bar(h human) { + h.speak() +} + +func main() { + x := person{ + first: "miss", + last: "money", + } + + y := secretAgent{ + person: person{ + first: "james", + last: "bond", + }, + ltk: true, + } + + x.speak() + y.speak() + + foo(x) + foo(y) + + fmt.Println("Hello", x) + fmt.Println("Hello", y) +} diff --git a/000_temp/62-kelowna/00-prep/02/main.go b/000_temp/62-kelowna/00-prep/02/main.go new file mode 100644 index 00000000..96ff7e59 --- /dev/null +++ b/000_temp/62-kelowna/00-prep/02/main.go @@ -0,0 +1,20 @@ +package main + +import "fmt" + +func main() { + xi := []int{4, 5, 6, 7} + + for n, i := range xi { + fmt.Println(n, i) + } + + m := map[string]int{ + "mcleod": 47, + "bond": 27, + } + + for k, v := range m { + fmt.Println(k, v) + } +} diff --git a/000_temp/62-kelowna/01-present/01/main.go b/000_temp/62-kelowna/01-present/01/main.go new file mode 100644 index 00000000..f7689e16 --- /dev/null +++ b/000_temp/62-kelowna/01-present/01/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "html/template" + "net/http" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + http.HandleFunc("/", index) + http.HandleFunc("/about", about) + http.ListenAndServe(":8080", nil) +} + +func index(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "index.gohtml", 42) + //io.WriteString(w, "Hello Kelowna") +} + +func about(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "about.gohtml", "JAMES BOND") +} diff --git a/000_temp/62-kelowna/01-present/01/templates/about.gohtml b/000_temp/62-kelowna/01-present/01/templates/about.gohtml new file mode 100644 index 00000000..47cd1272 --- /dev/null +++ b/000_temp/62-kelowna/01-present/01/templates/about.gohtml @@ -0,0 +1,14 @@ + + + + + ABOUT + + + +

This is the about page

+ +{{.}} + + + \ No newline at end of file diff --git a/000_temp/62-kelowna/01-present/01/templates/index.gohtml b/000_temp/62-kelowna/01-present/01/templates/index.gohtml new file mode 100644 index 00000000..0966d1d4 --- /dev/null +++ b/000_temp/62-kelowna/01-present/01/templates/index.gohtml @@ -0,0 +1,14 @@ + + + + + INDEX + + + +

Hello, Kelowna

+ +{{.}} + + + \ No newline at end of file diff --git a/000_temp/62-kelowna/01-present/02/main.go b/000_temp/62-kelowna/01-present/02/main.go new file mode 100644 index 00000000..96ff7e59 --- /dev/null +++ b/000_temp/62-kelowna/01-present/02/main.go @@ -0,0 +1,20 @@ +package main + +import "fmt" + +func main() { + xi := []int{4, 5, 6, 7} + + for n, i := range xi { + fmt.Println(n, i) + } + + m := map[string]int{ + "mcleod": 47, + "bond": 27, + } + + for k, v := range m { + fmt.Println(k, v) + } +} diff --git a/000_temp/62-kelowna/01-present/03/main.go b/000_temp/62-kelowna/01-present/03/main.go new file mode 100644 index 00000000..39635b81 --- /dev/null +++ b/000_temp/62-kelowna/01-present/03/main.go @@ -0,0 +1,59 @@ +package main + +import "fmt" + +// https://play.golang.org/p/gLdpEzVm54U + +type person struct { + first string + last string +} + +type secretAgent struct { + person + ltk bool +} + +// func (r receiver) identifier(parameters) (returns) {code} + +func (p person) speak() { + fmt.Println(p.first, `says, "Why, James. Helllllo."`) +} + +func (sa secretAgent) speak() { + fmt.Println(sa.first, `says, "Why Miss Moneypenny. So good to see you. One martini please. Shaken, not stirred."`) +} + +type human interface { + speak() +} + +func foo(h human) { + h.speak() +} + +func main() { + p1 := person{ + first: "Missy", + last: "Moneypenny", + } + + p2 := secretAgent{ + person: person{ + first: "James", + last: "Bond", + }, + ltk: true, + } + + fmt.Println(p1) + + fmt.Println(p2) + + p1.speak() + + p2.speak() + + foo(p1) + foo(p2) +} diff --git a/000_temp/62-kelowna/02/temp.txt b/000_temp/62-kelowna/02/temp.txt new file mode 100644 index 00000000..20c8f38e --- /dev/null +++ b/000_temp/62-kelowna/02/temp.txt @@ -0,0 +1,55 @@ +INSERT INTO customers VALUES (12, 'Jamesx', 8000, 'CA'), (13, 'Jennyx', 11000, 'WA'), (14, 'Toddx', 9950, 'OR'), (15, 'Rickx', 10500, 'WA'), (16, 'Stevex', 10250, 'CA'), (17, 'Andrewx', 7750, 'OR'), (18, 'Josephinex', 13000, 'WA'), (19, 'Maxx', 12000, 'CA'), (20, 'Stephaniex', 8000, 'OR'), (21, 'Agnesx', 9999, 'WA'); + + + +INSERT INTO ingredients VALUES (1, 'Kale', '1 cup, pulled from stem'), (2, 'blueberries', 'a handful'), (3, 'pineapple', 'a handful'), (4, 'ice', 'a handful'), (5, 'juice', '1 cup'), (6, 'water', 'as much as needed'), (7, 'peanut butter', '3/4 cup'), (8, 'old-fashioned rolled oats', '1.5 cups'), (9, 'all-purpose flour', '2 cups'), (10, 'baking powder', '1 teaspoon'), (11, 'baking soda', '1 teaspon'), (12, 'salt', '1 teaspoon'), (13, 'butter', '2 sticks, softended'), (14, 'granulated sugar', '1 cup'), (15, 'brown sugar', '1 cup firmly packed'), (16, 'vanilla extract', '1 tablespoon'), (17, 'eggs', '2 large'), (18, 'semisweet chocolate chips', '12 ounces'), (19, 'semisweet chocolate, grated', '8 ounces'); + +INSERT INTO recipeingredients VALUES (1, 2, 1), (2, 2, 2), (3, 2, 3), (4, 2, 4), (5, 2, 5), (6, 2, 6), (7, 1, 7), (8,1,8), (9,1,9), (10,1,10), (11,1,11), (12,1,12), (13,1,13), (14,1,14), (15,1,15), (16,1,16), (17,1,17), (18,1,18), (19,1,19); + +SELECT rname, iname, iamount FROM recipes JOIN recipeingredients ON recipes.rid = recipeingredients.rid JOIN ingredients ON recipeingredients.iid = ingredients.iid; + + +CREATE DATABASE climbing; + +\c climbing + +CREATE TABLE categories (catID INT PRIMARY KEY NOT NULL, catName TEXT NOT NULL); + +INSERT INTO categories VALUES (1, 'easy'), (2, 'medium'), (3, 'hard'), (4, 'impossible'); + +CREATE TABLE climbs (cID INT PRIMARY KEY NOT NULL, cName TEXT NOT NULL, catID INT REFERENCES categories(catID)); + +INSERT INTO climbs VALUES (1, 'metal mark', 1), (2, 'tollhouse slab', 1), (3, 'pinnacles', 2), (4, 'Arroyo', 3), (5, 'El Cap', 3), (6, 'North Face', 4); + +SELECT cname, catname FROM climbs INNER JOIN categories ON climbs.catid = categories.catid; + + +SELECT c.cname, m.mname FROM customers AS c JOIN rentals AS r ON c.cid = r.cid JOIN movies AS m ON m.mid =r.mid; + + +CREATE TABLE actors(aid INT PRIMARY KEY NOT NULL, aname TEXT NOT NULL); + +INSERT INTO actors VALUES (1, 'James'), (2, 'Jenny'), (3, 'Rock'), (4, 'Rick'), (5, 'Steve'), (6, 'Andrew'); + +CREATE TABLE moviecast (caid INT PRIMARY KEY NOT NULL, mid INT REFERENCES movies(MID), aid INT REFERENCES actors(AID)); + +INSERT INTO moviecast VALUES (1, 2, 1), (2, 2, 2), (3, 2, 3), (4, 2, 4), (5, 2, 5), (6, 2, 6), (7, 1, 3), (8,1,2), (9,1,1), (10,1,5), (11,2,5), (12,2,6), (13,3,1), (14,3,4), (15,4,5), (16,4,2), (17,5,1), (18,6,3), (19,6,4); + + +SELECT cname, rid, mname, aname FROM customers AS c JOIN rentals as r ON c.cid = r.cid JOIN movies AS m ON r.mid = m.mid JOIN moviecast AS mc ON m.mid = mc.mid JOIN actors AS a ON mc.aid = a.aid; + +CREATE TABLE cphone (cpID INT PRIMARY KEY NOT NULL, cID INT REFERENCES customers(CID), cpPHONE TEXT NOT NULL); + +INSERT INTO cphone VALUES (1, 1, '007-0077'), (2, 2, '008-0088'), (3, 3, '009-0099'), (4, 4, '001,0011'), (5, 5, '002-0022'), (6, 6, '003-0033'), (7, 1, '777-8888'), (8, 2, '888-7777'), (9, 2, '999-3231'); + +CREATE TABLE aphone (apID INT PRIMARY KEY NOT NULL, aID INT REFERENCES actors(AID), apPHONE TEXT NOT NULL); + +INSERT INTO aphone VALUES (1, 1, '997-9977'), (2, 2, '998-9988'), (3, 3, '999-9999'), (4, 4, '991,9911'), (5, 5, '992-9922'), (6, 6, '993-9933'), (7, 1, '888-8888'), (8, 2, '888-8887'), (9, 2, '444-3231'); + +SELECT cname, cpphone FROM cphone AS cp JOIN customers AS c ON cp.cid = c.cid; + +SELECT aname, apphone FROM actors AS a JOIN aphone AS ap ON a.aid = ap.aid; + +SELECT cname, cpphone, aname, apphone FROM cphone AS cp JOIN customers AS c ON cp.cid = c.cid JOIN rentals AS r ON c.cid = r.cid JOIN movies AS m ON r.mid = m.mid JOIN moviecast AS mc ON m.mid = mc.mid JOIN actors AS a ON mc.aid = a.aid JOIN aphone AS ap ON a.aid = ap.aid; + +SELECT cname, cpphone, rid, mname, aname, apphone FROM cphone AS cp JOIN customers AS c ON cp.cid = c.cid JOIN rentals AS r ON c.cid = r.cid JOIN movies AS m ON r.mid = m.mid JOIN moviecast AS mc ON m.mid = mc.mid JOIN actors AS a ON mc.aid = a.aid JOIN aphone AS ap ON a.aid = ap.aid; \ No newline at end of file diff --git a/000_temp/62-kelowna/03/sql b/000_temp/62-kelowna/03/sql new file mode 100644 index 00000000..efde806d --- /dev/null +++ b/000_temp/62-kelowna/03/sql @@ -0,0 +1,80 @@ +INSERT INTO recipeclasses VALUES (1, 'italian'), (2,'french'), (3,'indian'), (4,'mexican'), (5,'thai'), (6,'chinese'), (7,'swiss'), (8,'german'), (9,'american'), (10,'japanese'), (11,'hungarian'), (12,'english'); + +INSERT INTO recipes VALUES (1,'hamburger',9,'bbq','include pickles'), (2,'bratwurst',8,'grill','drink beer while eating'), (3,'chow meain',6,'wok it','not so good as leftovers'), (4,'canoli',1,'lots of cream','wonderful dessert'), (5,'chai',3,'milk and spices baby','delicious to drink'), (6,'red wine',2,'enjoy za life','not so much for me'), (7,'burrito',4,'beans please','add hot sauce'), (8,'pad thai',5,'no fish sauce','put a fried egg on top'), (9,'swiss cheese',7,'put in the holes','melt it on crackers'), (10,'sushi',10,'do not cook the fish','add miso soup on the side'); + +SELECT recipeclassdescription, recipetitle FROM recipeclasses LEFT OUTER JOIN recipes ON recipeclasses.recipeclassid = recipes.recipeclassid; + +SELECT recipeclassdescription, recipetitle FROM recipeclasses LEFT JOIN recipes ON recipeclasses.recipeclassid = recipes.recipeclassid; + +SELECT rc.recipeclassdescription, r.recipetitle FROM recipeclasses AS rc LEFT JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid; + +SELECT rc.recipeclassdescription FROM recipeclasses AS rc LEFT JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid WHERE r.recipeid IS NULL; + +SELECT f.recipeclassdescription, r.recipetitle FROM (SELECT recipeclassid, recipeclassdescription FROM recipeclasses AS rc where rc.recipeclassdescription = 'german' OR rc.recipeclassdescription = 'italian' OR rc.recipeclassdescription = 'french') AS f LEFT JOIN recipes AS r ON f.recipeclassid = r.recipeclassid; + +SELECT f.recipetitle, rc.recipeclassdescription FROM (SELECT recipetitle, recipeclassid FROM recipes WHERE recipetitle LIKE '%a%') AS f RIGHT JOIN recipeclasses AS rc ON f.recipeclassid = rc.recipeclassid; + + + +CREATE DATABASE humanity; + +\c humanity + +CREATE TABLE humans (hid INT PRIMARY KEY NOT NULL, hname TEXT, hage INT); + +INSERT INTO humans VALUES (1,'',18), (2,'',22), (3,'jenny',27), (4,'james',32), (5,'ian',36), (6,'stephen',42), (7,'stephanie',47), (8,'agnes',49), (9,'portia',50), (10,'fidel',55), (11,'rich',62), (12,'al',78); + +SELECT f.hname FROM (SELECT hname FROM humans WHERE hname LIKE '%a%') AS f; + +SELECT f.hname, f.hage FROM (SELECT hname, hage FROM humans WHERE hage > 40) AS f; + + +SELECT f1.recipeclassdescription, f2.recipetitle FROM (SELECT recipeclasses.recipeclassid, recipeclassdescription FROM recipeclasses WHERE recipeclassdescription = 'german' OR recipeclassdescription = 'italian' OR recipeclassdescription = 'french' OR recipeclassdescription = 'hungarian') AS f1 LEFT JOIN (SELECT recipes.recipeclassid, recipetitle FROM recipes WHERE recipetitle LIKE '%o%') AS f2 on f1.recipeclassid = f2.recipeclassid; + +CREATE TABLE ingredients (ingredientid INT PRIMARY KEY NOT NULL, ingredientname TEXT); + +CREATE TABLE measurements (measurementsid INT PRIMARY KEY NOT NULL, measurementdescription TEXT); + +CREATE TABLE recipeingredients (riid INT PRIMARY KEY NOT NULL, recipeid INT NOT NULL REFERENCES recipes(recipeid), recipeseqno INT, ingredientid INT NOT NULL REFERENCES ingredients(ingredientid), measurementsid INT NOT NULL REFERENCES measurements(measurementsid)); + +INSERT INTO ingredients VALUES (1,'chocolate'), (2,'chipotle'), (3,'chicken'), (4,'beef'), (5,'flower'), (6,'butter'), (7,'milk'), (8,'broth'), (9,'salt'), (10,'baking soda'); + +INSERT INTO measurements VALUES (1,'some'), (2,'a little'), (3,'a lot'), (4,'a pinch'), (5,'until it tastes good'), (6,'not too much'), (7,'not too little'), (8,'just a pinch'), (9,'a smidge'), (10,'a generous scoop'), (11,'more than you think'), (12,'less than youd imagine'); + +INSERT INTO recipeingredients VALUES (1,6,1,7,10),(2,3,2,5,5),(3,8,3,9,7),(4,7,4,6,1),(5,4,5,3,2),(6,9,6,1,6),(7,3,7,6,9),(8,1,8,6,11),(9,1,9,8,6),(10,2,10,7,10),(11,5,11,7,6),(12,6,12,4,1),(13,7,13,8,2),(14,1,14,8,7),(15,2,15,1,3),(16,1,16,8,1),(17,2,17,4,5),(18,8,18,1,6),(19,5,19,8,3),(20,4,20,8,2),(21,9,21,7,6),(22,4,22,2,1),(23,9,23,9,1),(24,3,24,2,3),(25,9,25,6,2),(26,1,26,2,10),(27,8,27,9,6),(28,1,28,8,5),(29,3,29,8,5),(30,6,30,9,10),(31,3,31,5,10),(32,2,32,1,11),(33,4,33,1,9),(34,3,34,4,4),(35,4,35,9,8),(36,3,36,2,5),(37,4,37,2,10),(38,2,38,5,4),(39,1,39,5,6),(40,5,40,4,10),(41,3,41,2,8),(42,4,42,5,9),(43,6,43,5,2),(44,1,44,1,3),(45,8,45,9,11),(46,8,46,9,5),(47,1,47,7,3),(48,9,48,5,2),(49,9,49,6,5),(50,3,50,9,8),(51,5,51,8,5),(52,2,52,3,2),(53,4,53,4,8),(54,3,54,5,4),(55,5,55,7,1),(56,1,56,7,3),(57,7,57,8,3),(58,1,58,9,10),(59,9,59,5,11),(60,1,60,4,3),(61,2,61,1,7),(62,4,62,6,10),(63,4,63,4,9),(64,8,64,6,6),(65,6,65,7,6),(66,2,66,9,11),(67,6,67,3,11),(68,4,68,6,6),(69,6,69,3,6),(70,1,70,8,3),(71,2,71,7,4),(72,4,72,2,8),(73,8,73,3,5),(74,4,74,4,7),(75,6,75,8,9),(76,7,76,2,1),(77,8,77,3,2),(78,6,78,8,9),(79,3,79,5,10),(80,3,80,4,9),(81,7,81,7,4),(82,6,82,7,6),(83,3,83,2,10),(84,7,84,2,7),(85,9,85,2,10),(86,3,86,1,5),(87,8,87,4,2),(88,5,88,3,5),(89,6,89,4,9),(90,5,90,6,4),(91,9,91,2,9),(92,7,92,4,1),(93,7,93,4,2),(94,6,94,4,8),(95,4,95,2,5),(96,2,96,3,8),(97,5,97,3,9),(98,4,98,9,2),(99,7,99,5,2),(100,4,100,7,10); + + +SELECT recipetitle, recipeclassdescription, recipeseqno, ingredientname, measurementdescription FROM recipes AS r INNER JOIN recipeclasses AS rc ON r.recipeclassid = rc.recipeclassid INNER JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid INNER JOIN ingredients AS i ON ri.ingredientid = i.ingredientid INNER JOIN measurements AS m ON ri.measurementsid = m.measurementsid ORDER BY r.recipeid, ri.recipeseqno; + +INSERT INTO recipeclasses VALUES (13, 'cambodian'), (14, 'nepalese'), (15, 'tazmanian'); + +SELECT recipeclassdescription, recipetitle FROM (recipeclasses AS rc LEFT JOIN recipes AS r ON r.recipeclassid = rc.recipeclassid); + + +--- does not work --- +SELECT recipeclassdescription, recipetitle, recipeseqno, ingredientname, measurementdescription FROM (((recipeclasses AS rc LEFT JOIN recipes AS r ON r.recipeclassid = rc.recipeclassid) INNER JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) INNER JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) INNER JOIN measurements AS m ON ri.measurementsid = m.measurementsid; + +--- does work --- +SELECT recipeclassdescription, recipetitle, recipeseqno, ingredientname, measurementdescription FROM recipes AS r INNER JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid INNER JOIN ingredients AS i ON ri.ingredientid = i.ingredientid INNER JOIN measurements AS m ON ri.measurementsid = m.measurementsid RIGHT JOIN recipeclasses AS rc ON r.recipeclassid = rc.recipeclassid; + +SELECT recipeclassdescription, recipetitle, recipeseqno, ingredientname, measurementdescription FROM recipes AS r INNER JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid INNER JOIN ingredients AS i ON ri.ingredientid = i.ingredientid INNER JOIN measurements AS m ON ri.measurementsid = m.measurementsid RIGHT JOIN recipeclasses AS rc ON r.recipeclassid = rc.recipeclassid ORDER BY r.recipeid, ri.recipeseqno; + +SELECT recipeclassdescription, recipetitle, recipeseqno, ingredientname, measurementdescription FROM (((recipeclasses AS rc LEFT JOIN recipes AS r ON r.recipeclassid = rc.recipeclassid) LEFT JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) LEFT JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) LEFT JOIN measurements AS m ON ri.measurementsid = m.measurementsid; + +SELECT recipeclassdescription, recipetitle, recipeseqno, ingredientname, measurementdescription FROM (((recipeclasses AS rc LEFT JOIN recipes AS r ON r.recipeclassid = rc.recipeclassid) LEFT JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) LEFT JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) LEFT JOIN measurements AS m ON ri.measurementsid = m.measurementsid ORDER BY r.recipeid, ri.recipeseqno; + + +INSERT INTO recipes VALUES (11, 'reuben sandwich', NULL ,'put pastrami on rye and grill', 'butter your bread'), (12, 'thai chicken soup', NULL, 'use lemongrass', 'so delicious'); + + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) JOIN measurements AS m ON ri.measurementsid = m.measurementsid); + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) JOIN measurements AS m ON ri.measurementsid = m.measurementsid) ORDER BY r.recipetitle, ri.recipeseqno; + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc LEFT JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) LEFT JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) LEFT JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) LEFT JOIN measurements AS m ON ri.measurementsid = m.measurementsid); + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) RIGHT JOIN measurements AS m ON ri.measurementsid = m.measurementsid); + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) RIGHT JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) LEFT JOIN measurements AS m ON ri.measurementsid = m.measurementsid); + +SELECT rc.recipeclassdescription, r.recipetitle, ri.recipeseqno, i.ingredientname, m.measurementdescription FROM ((((recipeclasses AS rc JOIN recipes AS r ON rc.recipeclassid = r.recipeclassid) JOIN recipeingredients AS ri ON r.recipeid = ri.recipeid) RIGHT JOIN ingredients AS i ON ri.ingredientid = i.ingredientid) FULL JOIN measurements AS m ON ri.measurementsid = m.measurementsid); \ No newline at end of file diff --git a/000_temp/62-kelowna/04-sql-union/union.sql b/000_temp/62-kelowna/04-sql-union/union.sql new file mode 100644 index 00000000..c58cf47e --- /dev/null +++ b/000_temp/62-kelowna/04-sql-union/union.sql @@ -0,0 +1,31 @@ +CREATE DATABASE exampleunion; + +\c exampleunion + +CREATE TABLE customers (cid INT PRIMARY KEY NOT NULL, first TEXT); + +INSERT INTO customers VALUES (1, 'James'), (2, 'Sergey'), (3, 'Vladimir'), (4, 'Putin'), (5, 'Coup'); + +CREATE TABLE vendors (vid INT PRIMARY KEY NOT NULL, first TEXT); + +INSERT INTO vendors VALUES (1, 'Stacey'), (2, 'Shelley'), (3, 'Sherry'), (4, 'Suzy'), (5, 'Sandy'); + +CREATE TABLE employees (eid INT PRIMARY KEY NOT NULL, first TEXT); + +INSERT INTO employees VALUES (1, 'Jeff'), (2, 'John'), (3, 'Jerry'), (4, 'Jose'), (5, 'Juan'); + +SELECT v.first FROM vendors AS v UNION SELECT e.first FROM employees AS e; + +SELECT 'customer' AS category, c.first FROM customers AS c UNION SELECT 'employee' AS category, e.first FROM employees AS e UNION SELECT 'vendor' AS category, v.first FROM vendors AS v UNION SELECT 'stuffedanimal' AS category, sa.saAnimalName FROM stuffedanimals AS sa; + +SELECT 'vendor' AS rowid, v.first FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first FROM employees AS e; + +SELECT 'vendor' AS rowid, v.first FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first FROM employees AS e UNION SELECT 'customer' AS rowid, c.first FROM customers AS c; + +SELECT 'vendor' AS rowid, v.first FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first FROM employees AS e UNION SELECT 'customer' AS rowid, c.first FROM customers AS c ORDER BY rowid; + +SELECT 'vendor' AS rowid, v.first FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first FROM employees AS e UNION SELECT 'customer' AS rowid, c.first FROM customers AS c ORDER BY first; + +SELECT 'vendor' AS rowid, v.first FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first FROM employees AS e UNION SELECT 'customer' AS rowid, c.first FROM customers AS c ORDER BY rowid, first; + +SELECT 'vendor' AS rowid, v.first AS name FROM vendors AS v UNION SELECT 'employee' AS rowid, e.first AS name FROM employees AS e UNION SELECT 'customer' AS rowid, c.first AS name FROM customers AS c ORDER BY rowid, name; \ No newline at end of file diff --git a/000_temp/62-kelowna/05-subqueries/subqueries.sql b/000_temp/62-kelowna/05-subqueries/subqueries.sql new file mode 100644 index 00000000..fda030de --- /dev/null +++ b/000_temp/62-kelowna/05-subqueries/subqueries.sql @@ -0,0 +1,79 @@ +CREATE DATABASE acmesales; + +\c acmesales + +CREATE TABLE customers (cid INT PRIMARY KEY NOT NULL, cfirst TEXT); + +INSERT INTO customers VALUES (1,'Cory'), (2,'Casey'), (3,'Canard'), (4,'Cully'), (5,'Coffer'), (6,'Homey'); + +CREATE TABLE items (iid INT PRIMARY KEY NOT NULL, iitem TEXT); + +INSERT INTO items VALUES (1,'dog food'), (2,'tiramisu'), (3,'vino'), (4,'cheese'), (5,'chocolate'), (6,'gummy worms'), (7,'mango'); + +CREATE TABLE orders (oid INT PRIMARY KEY NOT NULL, cid INT REFERENCES customers(cid), odate TEXT); + +INSERT INTO orders VALUES (1,2,'tuesday'), (2,5,'wednesday'), (3,1,'thursday'), (4,3,'sunday'), (5,4,'saturday'), (6,5,'friday'); + +CREATE TABLE orderitems (oiid INT PRIMARY KEY NOT NULL, oid INT REFERENCES orders(oid), iid INT REFERENCES items(iid)); + +INSERT INTO orderitems VALUES (1,4,6), (2,4,5), (3,5,4), (4,6,3), (5,1,2), (6,2,1), (7,3,6), (8,4,5), (9,5,4), (10,6,3); + +SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c JOIN orders AS o ON c.cid = o.cid JOIN orderitems AS oi ON o.oid = oi.oid JOIN items AS i ON oi.iid = i.iid; + +SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c FULL JOIN orders AS o ON c.cid = o.cid FULL JOIN orderitems AS oi ON o.oid = oi.oid FULL JOIN items AS i ON oi.iid = i.iid; + +// SCALAR +// an expression that evaluates to one value +// aka, one column & one row = one field value + +SELECT o.oid, o.odate, (SELECT c.cfirst FROM customers AS c WHERE c.cid = o.cid) FROM orders AS o; + +// could have also done the above this way + +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid; + +// aggregate function COUNT + +SELECT COUNT(cfirst) AS ourcustomers FROM customers; + +SELECT c.cfirst, (SELECT COUNT(*) FROM orders AS o WHERE c.cid = o.cid) AS ordercount FROM customers AS c; + +// aggregate function MAX + +SELECT MAX(cid) AS highestcid FROM customers; + +SELECT MAX(odate) AS maxday FROM orders; + +SELECT c.cfirst, (SELECT MAX(o.oid) FROM orders AS o WHERE c.cid = o.cid) AS maxoid FROM customers AS c; + +// subquery as filters +// subquery with the WHERE clause +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate = (SELECT MAX(odate) FROM orders); + +// subquery as filters +// subquery with the IN keyword +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate IN (SELECT odate FROM orders WHERE odate LIKE '%u%'); + +// ALL, SOME, ANY keywords +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate = ANY (SELECT odate FROM orders WHERE odate LIKE '%u%'); + +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate = SOME (SELECT odate FROM orders WHERE odate LIKE '%u%'); + +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate = ALL (SELECT odate FROM orders WHERE odate LIKE '%u%'); + +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate = ALL (SELECT odate FROM orders WHERE odate LIKE 'thur%'); + +SELECT o.oid, o.odate, c.cfirst FROM customers AS c JOIN orders AS o ON c.cid = o.cid WHERE o.odate > ALL (SELECT odate FROM orders WHERE odate LIKE 'thur%'); + +// EXISTS +// I DO NOT KNOW HOW THIS WORKS +// MORE RESEARCH AND EXPERIMENTATION ARE NEEDED +SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c JOIN orders AS o ON c.cid = o.cid JOIN orderitems AS oi ON o.oid = oi.oid JOIN items AS i ON oi.iid = i.iid; + +SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c JOIN orders AS o ON c.cid = o.cid JOIN orderitems AS oi ON o.oid = oi.oid JOIN items AS i ON oi.iid = i.iid WHERE i.iitem = 'chocolate'; + +SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c JOIN orders AS o ON c.cid = o.cid JOIN orderitems AS oi ON o.oid = oi.oid JOIN items AS i ON oi.iid = i.iid WHERE EXISTS (SELECT c.cfirst, o.oid, o.odate, i.iitem FROM customers AS c JOIN orders AS o ON c.cid = o.cid JOIN orderitems AS oi ON o.oid = oi.oid JOIN items AS i ON oi.iid = i.iid WHERE i.iitem = 'chocolate'); + + + + diff --git a/000_temp/62-kelowna/06-hollywood/subqueries.sql b/000_temp/62-kelowna/06-hollywood/subqueries.sql new file mode 100644 index 00000000..cd457ca0 --- /dev/null +++ b/000_temp/62-kelowna/06-hollywood/subqueries.sql @@ -0,0 +1,39 @@ +CREATE DATABASE hollywood; + +\l + +\c hollywood + +CREATE TABLE customers (cid INT PRIMARY KEY NOT NULL, cname TEXT); + +INSERT INTO customers VALUES (1,'Charlie'), (2,'Chris'), (3,'Christina'), (4,'Cassandra'), (5,'Cull'), (6,'Cabron'), (7,'Carla'), (8,'Caitland'), (9,'Colleen'), (10,'Christian'); + +CREATE TABLE movies (mid INT PRIMARY KEY NOT NULL, mname TEXT); + +INSERT INTO movies VALUES (1,'Jaws'), (2,'First Blood'), (3,'Rambo'), (4,'Terms of Endearment'), (5,'Heat'), (6,'The Lives of Others'), (7,'A Man Called Ove'), (8,'Disconnect'), (9,'Ex Machina'), (10,'Castle'); + +CREATE TABLE actors (aid INT PRIMARY KEY NOT NULL, aname TEXT); + +INSERT INTO actors VALUES (1,'Alfred'), (2,'Albert'), (3,'Angel'), (4,'Angelina'), (5,'Angie'), (6,'Agnes'), (7,'Amnia'), (8,'Allison'), (9,'Alejandro'), (10,'Aerial'); + +CREATE TABLE rentals (rid INT PRIMARY KEY NOT NULL, cid INT NOT NULL REFERENCES customers(cid), mid INT NOT NULL REFERENCES movies(mid)); + +INSERT INTO rentals VALUES (1,2,8),(2,8,10),(3,2,9),(4,6,1),(5,7,1),(6,5,2),(7,3,10),(8,9,5),(9,2,6),(10,8,7),(11,6,7),(12,9,9),(13,8,8),(14,8,9),(15,1,6),(16,2,9),(17,8,2),(18,10,7),(19,8,2),(20,6,7),(21,4,1),(22,5,4),(23,4,8),(24,9,5),(25,10,4),(26,8,2),(27,10,10),(28,1,6),(29,9,9),(30,4,6),(31,2,1),(32,6,7),(33,7,9),(34,2,3),(35,4,7),(36,4,7),(37,3,9),(38,8,5),(39,8,4),(40,7,1),(41,4,4),(42,8,4),(43,2,10),(44,4,4),(45,2,3),(46,9,7),(47,7,8),(48,1,4),(49,3,4),(50,6,9),(51,6,2),(52,6,8),(53,8,1),(54,1,6),(55,1,3),(56,9,4),(57,2,3),(58,5,8),(59,8,8),(60,2,5),(61,7,3),(62,2,10),(63,7,1),(64,4,7),(65,10,2),(66,3,6),(67,6,1),(68,8,10),(69,9,9),(70,5,4),(71,5,8),(72,3,3),(73,7,10),(74,1,7),(75,2,7),(76,1,2),(77,5,5),(78,6,4),(79,2,1),(80,3,9),(81,8,2),(82,9,5),(83,3,4),(84,3,9),(85,4,9),(86,7,1),(87,6,1),(88,5,3),(89,8,6),(90,2,10),(91,1,4),(92,1,10),(93,1,4),(94,1,5),(95,8,1),(96,6,3),(97,10,1),(98,9,7),(99,6,7),(100,1,7); + +CREATE TABLE castmembers (caid INT PRIMARY KEY NOT NULL, mid INT NOT NULL REFERENCES movies(mid), aid INT NOT NULL REFERENCES actors(aid)); + +INSERT INTO castmembers VALUES (1,2,8),(2,8,10),(3,2,9),(4,6,1),(5,7,1),(6,5,2),(7,3,10),(8,9,5),(9,2,6),(10,8,7),(11,6,7),(12,9,9),(13,8,8),(14,8,9),(15,1,6),(16,2,9),(17,8,2),(18,10,7),(19,8,2),(20,6,7),(21,4,1),(22,5,4),(23,4,8),(24,9,5),(25,10,4),(26,8,2),(27,10,10),(28,1,6),(29,9,9),(30,4,6),(31,2,1),(32,6,7),(33,7,9),(34,2,3),(35,4,7),(36,4,7),(37,3,9),(38,8,5),(39,8,4),(40,7,1),(41,4,4),(42,8,4),(43,2,10),(44,4,4),(45,2,3),(46,9,7),(47,7,8),(48,1,4),(49,3,4),(50,6,9),(51,6,2),(52,6,8),(53,8,1),(54,1,6),(55,1,3),(56,9,4),(57,2,3),(58,5,8),(59,8,8),(60,2,5),(61,7,3),(62,2,10),(63,7,1),(64,4,7),(65,10,2),(66,3,6),(67,6,1),(68,8,10),(69,9,9),(70,5,4),(71,5,8),(72,3,3),(73,7,10),(74,1,7),(75,2,7),(76,1,2),(77,5,5),(78,6,4),(79,2,1),(80,3,9),(81,8,2),(82,9,5),(83,3,4),(84,3,9),(85,4,9),(86,7,1),(87,6,1),(88,5,3),(89,8,6),(90,2,10),(91,1,4),(92,1,10),(93,1,4),(94,1,5),(95,8,1),(96,6,3),(97,10,1),(98,9,7),(99,6,7),(100,1,7); + + +SELECT c.cname, m.mname FROM customers AS c JOIN rentals AS r ON c.cid = r.cid JOIN movies AS m ON r.mid = m.mid; + +SELECT a.aname, m.mname FROM actors AS a JOIN castmembers AS cm ON a.aid = cm.aid JOIN movies AS m ON cm.mid = m.mid; + +INSERT INTO customers VALUES (101, 'Mike'), (102, 'Max'); + +INSERT INTO movies VALUES (101, 'Aliens'), (102, 'Ragoon'); + +INSERT INTO actors VALUES (101, 'Milfred'), (102, 'Martine'); + +SELECT c.cname, m.mname, a.aname FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid FULL JOIN movies AS m ON r.mid = m.mid FULL JOIN castmembers AS cm ON m.mid = cm.mid FULL JOIN actors AS a ON cm.aid = a.aid; + diff --git a/000_temp/62-kelowna/07-sql-aggregate-funcs/agg.sql b/000_temp/62-kelowna/07-sql-aggregate-funcs/agg.sql new file mode 100644 index 00000000..95ac5eb3 --- /dev/null +++ b/000_temp/62-kelowna/07-sql-aggregate-funcs/agg.sql @@ -0,0 +1,85 @@ +/* COUNT */ + +/* from cooking database */ + +SELECT COUNT(recipetitle) AS totalRecipes FROM recipes; + +SELECT COUNT(DISTINCT recipetitle) AS totalDistRecipes FROM recipes; + +/* from hollywood database*/ +SELECT c.cname, m.mname, a.aname FROM ((((customers AS c JOIN rentals AS r ON c.cid = r.cid) JOIN movies AS m ON r.mid = m.mid) JOIN castmembers AS cm ON m.mid = cm.mid) JOIN actors AS a ON cm.aid = a.aid); + +SELECT c.cname, m.mname, a.aname FROM ((((customers AS c LEFT JOIN rentals AS r ON c.cid = r.cid) LEFT JOIN movies AS m ON r.mid = m.mid) LEFT JOIN castmembers AS cm ON m.mid = cm.mid) LEFT JOIN actors AS a ON cm.aid = a.aid); + +SELECT r.rid, m.mname FROM rentals AS r JOIN movies AS m ON r.mid = m.mid; + +SELECT r.rid, m.mname FROM rentals AS r RIGHT JOIN movies AS m ON r.mid = m.mid; + +SELECT cm.caid, a.aname FROM castmembers AS cm RIGHT JOIN actors AS a ON cm.aid = a.aid; + +SELECT cm.caid, a.aname FROM actors AS a LEFT JOIN castmembers AS cm ON a.aid = cm.aid; + +SELECT c.cname, m.mname, a.aname FROM ((((customers AS c FULL JOIN rentals AS r ON c.cid = r.cid) FULL JOIN movies AS m ON r.mid = m.mid) FULL JOIN castmembers AS cm ON m.mid = cm.mid) FULL JOIN actors AS a ON cm.aid = a.aid); + +SELECT COUNT(*) AS totalRentals FROM rentals; + +SELECT COUNT(cname) AS custs FROM customers; + +SELECT COUNT(DISTINCT cname) AS distinctCusts FROM customers; + + + +/* SUM */ + +DROP TABLE rentals; + +CREATE TABLE rentals (rid INT PRIMARY KEY NOT NULL, cid INT NOT NULL REFERENCES customers(cid), mid INT NOT NULL REFERENCES movies(mid), rAmount INT NOT NULL); + +https://play.golang.org/p/H7afRPh5bUd + +INSERT INTO rentals VALUES (1,2,8,5),(2,4,2,6),(3,8,1,4),(4,7,5,4),(5,11,10,6),(6,7,2,3),(7,9,7,3),(8,1,9,6),(9,10,8,5),(10,7,1,3),(11,1,9,5),(12,2,10,4),(13,2,2,3),(14,5,4,3),(15,6,4,6),(16,5,9,7),(17,6,4,5),(18,8,10,7),(19,8,6,6),(20,11,4,3),(21,5,1,3),(22,3,7,6),(23,2,3,6),(24,4,4,4),(25,6,9,5),(26,1,8,6),(27,7,1,6),(28,11,8,6),(29,11,10,6),(30,9,2,5),(31,4,7,4),(32,11,1,6),(33,4,4,3),(34,10,6,4),(35,1,8,5),(36,4,1,3),(37,7,3,6),(38,4,2,5),(39,11,8,5),(40,8,2,7),(41,4,3,4),(42,10,7,3),(43,1,7,7),(44,6,3,3),(45,10,1,5),(46,7,9,6),(47,1,4,7),(48,4,3,5),(49,7,10,3),(50,5,2,4),(51,7,2,7),(52,10,6,6),(53,4,1,5),(54,3,8,4),(55,7,5,5),(56,7,3,6),(57,8,9,4),(58,5,6,3),(59,8,3,5),(60,5,2,7),(61,3,4,3),(62,7,1,6),(63,1,5,5),(64,3,6,5),(65,10,1,6),(66,7,6,4),(67,11,7,7),(68,8,2,5),(69,5,1,7),(70,5,8,5),(71,8,2,6),(72,1,9,4),(73,5,8,5),(74,8,6,4),(75,11,6,5),(76,9,1,4),(77,11,3,3),(78,10,3,7),(79,5,1,3),(80,7,5,7),(81,10,2,4),(82,2,7,3),(83,3,8,6),(84,6,5,3),(85,1,6,7),(86,5,1,5),(87,9,1,7),(88,6,6,6),(89,7,1,7),(90,3,1,4),(91,11,3,7),(92,2,5,5),(93,4,4,4),(94,5,3,3),(95,8,2,5),(96,9,6,5),(97,10,3,7),(98,10,2,3),(99,9,4,6),(100,8,10,5); + +SELECT c.cname, m.mname, a.aname, r.rAmount FROM ((((customers AS c FULL JOIN rentals AS r ON c.cid = r.cid) FULL JOIN movies AS m ON r.mid = m.mid) FULL JOIN castmembers AS cm ON m.mid = cm.mid) FULL JOIN actors AS a ON cm.aid = a.aid); + +SELECT SUM(rAmount) AS totalRev FROM rentals; + +select c.cname, r.ramount from customers AS c JOIN rentals AS r ON c.cid = r.cid; + +select c.cname, r.rid, r.ramount from customers AS c JOIN rentals AS r ON c.cid = r.cid; + +select c.cname, r.rid, r.ramount from customers AS c FULL JOIN rentals AS r ON c.cid = r.cid; + +SELECT c.cid, c.cname, r.rid, r.ramount FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid; + +SELECT c.cid, c.cname, r.rid, r.ramount, m.mname, a.aname FROM ((((customers AS c FULL JOIN rentals AS r ON c.cid = r.cid) FULL JOIN movies AS m ON r.mid = m.mid) FULL JOIN castmembers AS cm ON m.mid = cm.mid) FULL JOIN actors AS a ON cm.aid = a.aid); + +SELECT c.cid, c.cname, SUM(r.ramount) AS bigSpend FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid GROUP BY c.cid; + +SELECT c.cid, c.cname, SUM(r.ramount) AS bigSpend FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid GROUP BY c.cid ORDER BY bigSpend DESC; + + + +/* AVG */ + +SELECT AVG(ramount) FROM rentals; + +SELECT c.cid, c.cname, AVG(r.ramount) AS bigSpend FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid GROUP BY c.cid; + + + +/* MAX */ +SELECT MAX(ramount) FROM rentals; + +SELECT c.cid, c.cname, MAX(r.ramount) AS bigSpend FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid GROUP BY c.cid; + + + +/* MIN */ +SELECT MIN(ramount) FROM rentals; + +SELECT c.cid, c.cname, MIN(r.ramount) AS bigSpend FROM customers AS c FULL JOIN rentals AS r ON c.cid = r.cid GROUP BY c.cid; + + +/* AFTER CLASS */ + +SELECT cu.cname AS firstName FROM customers AS cu; \ No newline at end of file diff --git a/000_temp/62-kelowna/08-sql-group/agg.sql b/000_temp/62-kelowna/08-sql-group/agg.sql new file mode 100644 index 00000000..86c51d35 --- /dev/null +++ b/000_temp/62-kelowna/08-sql-group/agg.sql @@ -0,0 +1,86 @@ +CREATE DATABASE entertainers; + +\l + +\c entertainers + +CREATE TABLE entertainers (eid INT PRIMARY KEY NOT NULL, ename TEXT NOT NULL); + +\d + +\d entertainers + +CREATE TABLE engagements (enID INT PRIMARY KEY NOT NULL, eid INT NOT NULL REFERENCES entertainers(eid), encontractprice INT NOT NULL); + +INSERT INTO entertainers VALUES (1, 'WOOKIE-WOOKIE'), (2, 'HodgePodge'), (3, 'ScarlettLetters'), (4, 'TomorrowsSun'), (5, 'WhereWithAll'), (6, 'CowboyFutures'), (7, 'DesperateTortillas'), (8, 'CaldenarFlippers'), (9, 'LaughingJackals'), (10, 'CareeningForthright'); + + +generate values +https://play.golang.org/p/iET0hmFrcgf + +INSERT INTO engagements VALUES (1,2,9888),(2,8,6060),(3,2,3319),(4,6,4541),(5,7,5301),(6,5,10512),(7,3,7090),(8,9,5275),(9,2,3446),(10,8,11107),(11,6,7467),(12,9,8259),(13,8,11948),(14,8,4889),(15,1,5016),(16,2,2409),(17,8,8832),(18,10,7357),(19,8,2632),(20,6,7027),(21,4,5091),(22,5,2564),(23,4,6148),(24,9,6325),(25,10,3354),(26,8,5722),(27,10,4200),(28,1,10706),(29,9,6539),(30,4,11356),(31,2,10511),(32,6,2157),(33,7,11829),(34,2,9203),(35,4,7747),(36,4,6377),(37,3,11719),(38,8,7095),(39,8,9464),(40,7,8421),(41,4,2954),(42,8,5134),(43,2,2060),(44,4,10644),(45,2,4003),(46,9,11337),(47,7,11108),(48,1,8504),(49,3,11844),(50,6,3599),(51,6,3352),(52,6,11758),(53,8,10011),(54,1,7286),(55,1,5633),(56,9,10554),(57,2,10583),(58,5,3298),(59,8,8138),(60,2,7895),(61,7,7803),(62,2,4080),(63,7,3271),(64,4,5087),(65,10,10982),(66,3,9176),(67,6,7711),(68,8,5750),(69,9,4819),(70,5,9904),(71,5,6548),(72,3,3533),(73,7,9840),(74,1,7787),(75,2,10077),(76,1,9352),(77,5,2365),(78,6,11184),(79,2,2091),(80,3,4259),(81,8,5232),(82,9,10155),(83,3,3224),(84,3,6209),(85,4,3969),(86,7,5711),(87,6,2441),(88,5,5163),(89,8,6416),(90,2,5040),(91,1,11514),(92,1,3360),(93,1,2784),(94,1,4985),(95,8,10011),(96,6,6163),(97,10,9921),(98,9,8757),(99,6,10667),(100,1,11457); + +SELECT e.ename, en.encontractprice FROM entertainers AS e INNER JOIN engagements AS en ON e.eid = en.eid; + +SELECT e.ename, en.encontractprice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid; + +INSERT INTO entertainers VALUES (11, 'SomebodyNobodyLoves'); + +SELECT e.ename, en.encontractprice FROM entertainers AS e LEFT JOIN engagements AS en ON e.eid = en.eid; + +SELECT e.ename, en.encontractprice FROM entertainers AS e FULL JOIN engagements AS en ON e.eid = en.eid; + +SELECT COUNT(encontractprice) as TotalEngagements FROM engagements; +SELECT SUM(encontractprice) as TotalRevenue FROM engagements; +SELECT MAX(encontractprice) as MaxContractPrice FROM engagements; +SELECT MIN(encontractprice) as MinContractPrice FROM engagements; +SELECT AVG(encontractprice) as AvgContractPrice FROM engagements; + +SELECT e.ename, MAX(en.encontractprice) as MaxContractPrice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename; + +SELECT e.ename, MIN(en.encontractprice) as MinContractPrice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY MinContractPrice; + +SELECT e.ename, AVG(en.encontractprice) as AvgContractPrice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY AvgContractPrice; + +SELECT e.ename, SUM(en.encontractprice) as SumContractPrice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY SumContractPrice; + +SELECT e.ename, COUNT(en.encontractprice) as CountContractPrice FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY CountContractPrice; + +SELECT e.ename, COUNT(en.encontractprice) AS NumContracts, SUM(en.encontractprice) AS TotalRevenue, MIN(en.encontractprice) AS MinRev, MAX(en.encontractprice) AS MaxRev, AVG(en.encontractprice) AS AvgRev FROM entertainers AS e JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY NumContracts; + +SELECT e.ename, COUNT(en.encontractprice) AS NumContracts, SUM(en.encontractprice) AS TotalRevenue, MIN(en.encontractprice) AS MinRev, MAX(en.encontractprice) AS MaxRev, AVG(en.encontractprice) AS AvgRev FROM entertainers AS e LEFT JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY NumContracts; + +SELECT e.ename, COUNT(*) AS NumContracts, SUM(en.encontractprice) AS TotalRevenue, MIN(en.encontractprice) AS MinRev, MAX(en.encontractprice) AS MaxRev, AVG(en.encontractprice) AS AvgRev FROM entertainers AS e LEFT JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ename ORDER BY NumContracts; + + + +/* multiple fields in group by*/ + +DROP TABLE engagements; + +DROP TABLE entertainers; + +CREATE TABLE entertainers (eid INT PRIMARY KEY NOT NULL, ename TEXT NOT NULL, ecity TEXT NOT NULL); + +INSERT INTO entertainers VALUES (1, 'WOOKIE-WOOKIE', 'Paris'), (2, 'HodgePodge', 'Paris'), (3, 'ScarlettLetters', 'Paris'), (4, 'TomorrowsSun', 'Hollywood'), (5, 'WhereWithAll', 'Hollywood'), (6, 'CowboyFutures', 'Hollywood'), (7, 'DesperateTortillas', 'New York'), (8, 'CaldenarFlippers', 'New York'), (9, 'LaughingJackals', 'San Francisco'), (10, 'CareeningForthright', 'San Francisco'); + +CREATE TABLE engagements (enID INT PRIMARY KEY NOT NULL, eid INT NOT NULL REFERENCES entertainers(eid), encontractprice INT NOT NULL); + +generate values +https://play.golang.org/p/iET0hmFrcgf + +INSERT INTO engagements VALUES (1,2,9888),(2,8,6060),(3,2,3319),(4,6,4541),(5,7,5301),(6,5,10512),(7,3,7090),(8,9,5275),(9,2,3446),(10,8,11107),(11,6,7467),(12,9,8259),(13,8,11948),(14,8,4889),(15,1,5016),(16,2,2409),(17,8,8832),(18,10,7357),(19,8,2632),(20,6,7027),(21,4,5091),(22,5,2564),(23,4,6148),(24,9,6325),(25,10,3354),(26,8,5722),(27,10,4200),(28,1,10706),(29,9,6539),(30,4,11356),(31,2,10511),(32,6,2157),(33,7,11829),(34,2,9203),(35,4,7747),(36,4,6377),(37,3,11719),(38,8,7095),(39,8,9464),(40,7,8421),(41,4,2954),(42,8,5134),(43,2,2060),(44,4,10644),(45,2,4003),(46,9,11337),(47,7,11108),(48,1,8504),(49,3,11844),(50,6,3599),(51,6,3352),(52,6,11758),(53,8,10011),(54,1,7286),(55,1,5633),(56,9,10554),(57,2,10583),(58,5,3298),(59,8,8138),(60,2,7895),(61,7,7803),(62,2,4080),(63,7,3271),(64,4,5087),(65,10,10982),(66,3,9176),(67,6,7711),(68,8,5750),(69,9,4819),(70,5,9904),(71,5,6548),(72,3,3533),(73,7,9840),(74,1,7787),(75,2,10077),(76,1,9352),(77,5,2365),(78,6,11184),(79,2,2091),(80,3,4259),(81,8,5232),(82,9,10155),(83,3,3224),(84,3,6209),(85,4,3969),(86,7,5711),(87,6,2441),(88,5,5163),(89,8,6416),(90,2,5040),(91,1,11514),(92,1,3360),(93,1,2784),(94,1,4985),(95,8,10011),(96,6,6163),(97,10,9921),(98,9,8757),(99,6,10667),(100,1,11457); + +SELECT e.ecity, e.ename, COUNT(*) AS NumContracts, SUM(en.encontractprice) AS TotalRevenue, MIN(en.encontractprice) AS MinRev, MAX(en.encontractprice) AS MaxRev, AVG(en.encontractprice) AS AvgRev FROM entertainers AS e LEFT JOIN engagements AS en ON e.eid = en.eid GROUP BY e.ecity, e.ename ORDER BY e.ecity, NumContracts; + +/* simulating DISTINCT */ + +SELECT ecity FROM entertainers; + +SELECT DISTINCT(ecity) FROM entertainers; + +SELECT ecity FROM entertainers GROUP BY ecity; + +SELECT ecity, COUNT(*) AS bandspercity FROM entertainers GROUP BY ecity; + + diff --git a/000_temp/63-fall-2018/001-hello-world/hello.go b/000_temp/63-fall-2018/001-hello-world/hello.go new file mode 100644 index 00000000..d2c4e91e --- /dev/null +++ b/000_temp/63-fall-2018/001-hello-world/hello.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Hello world") +} diff --git a/000_temp/63-fall-2018/002-hello-world/hello.go b/000_temp/63-fall-2018/002-hello-world/hello.go new file mode 100644 index 00000000..24dcac87 --- /dev/null +++ b/000_temp/63-fall-2018/002-hello-world/hello.go @@ -0,0 +1,9 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello world") +} diff --git a/000_temp/63-fall-2018/003-func/func.go b/000_temp/63-fall-2018/003-func/func.go new file mode 100644 index 00000000..d267b4f3 --- /dev/null +++ b/000_temp/63-fall-2018/003-func/func.go @@ -0,0 +1,21 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello world") + secondStatement() + finalStat() +} + +// func receiver identifier(parameters) returns {code} + +func secondStatement() { + fmt.Println("Here is my second statement") +} + +func finalStat() { + fmt.Println("about to exit") +} diff --git a/000_temp/63-fall-2018/004-variables/main.go b/000_temp/63-fall-2018/004-variables/main.go new file mode 100644 index 00000000..12ea85a5 --- /dev/null +++ b/000_temp/63-fall-2018/004-variables/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "fmt" +) + +func main() { + fname := "James" + lname := "Bond" + fmt.Println(fname, lname) + girlfriend := "Miss Moneypenny" + fmt.Println(girlfriend) +} + +/* +declare, assign, initialize +DECLARE a VARIABLE stores a VALUE of a certain TYPE +we ASSIGN a VALUE of a certain TYPE to a VARIABLE +declare & assign ==> initialize +*/ diff --git a/000_temp/63-fall-2018/005-variables/main.go b/000_temp/63-fall-2018/005-variables/main.go new file mode 100644 index 00000000..d25fc1d4 --- /dev/null +++ b/000_temp/63-fall-2018/005-variables/main.go @@ -0,0 +1,18 @@ +package main + +import ( + "fmt" +) + +var x int +var y string + +func main() { + fmt.Println(x) + fmt.Println("|", y, "|") +} + +// zero value +// if you declare a VAR of a certain TYPE +// and do not ASSIGN a VALUE to that VAR +// a ZERO VALUE will be ASSIGNED to that VAR diff --git a/000_temp/63-fall-2018/006-variables/main.go b/000_temp/63-fall-2018/006-variables/main.go new file mode 100644 index 00000000..20e52d13 --- /dev/null +++ b/000_temp/63-fall-2018/006-variables/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "fmt" +) + +var x = 42 +var y = "M" + +func main() { + fmt.Println(x) + fmt.Println(y) +} diff --git a/000_temp/63-fall-2018/007-params/main.go b/000_temp/63-fall-2018/007-params/main.go new file mode 100644 index 00000000..257099fe --- /dev/null +++ b/000_temp/63-fall-2018/007-params/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Begin") + + // pass in an ARGUMENT to the func when you CALL IT + foo("James Bond") + + x := "Miss Moneypenny" + // pass in an ARGUMENT to the func when you CALL IT + foo(x) + + n, _ := fmt.Println("1") + + fmt.Println("number of bytes written", n) +} + +// foo takes a VALUE of TYPE string +// we could also say: +// foo has a parameter which is a VALUE of TYPE string +// funcs may be defined with PARAMETER(S) +func foo(name string) { + fmt.Println("Hello", name) +} diff --git a/000_temp/63-fall-2018/008-review-var-type-value/main.go b/000_temp/63-fall-2018/008-review-var-type-value/main.go new file mode 100644 index 00000000..d8b22e01 --- /dev/null +++ b/000_temp/63-fall-2018/008-review-var-type-value/main.go @@ -0,0 +1,19 @@ +package main + +import ( + "fmt" +) + +// DECLARE a variable to be of a certain TYPE +// we can only ever store VALUES of that TYPE in that VARIABLE +// the VARIABLE has an IDENTIFIER +// STATIC programming language +// IDIOMATIC - idioms are patterns of speech +// COMPILER will check to make sure our code is IDIOMATIC + +var x int + +func main() { + x = 7 + fmt.Println(x) +} diff --git a/000_temp/63-fall-2018/009-review-func/main.go b/000_temp/63-fall-2018/009-review-func/main.go new file mode 100644 index 00000000..8d9f014a --- /dev/null +++ b/000_temp/63-fall-2018/009-review-func/main.go @@ -0,0 +1,31 @@ +package main + +import "fmt" + +func main() { + fmt.Println("This is the entry point beginning of the programming") + + foo() + + // call bar with ARGUMENTS + a, b := bar("James Bond", 32) + fmt.Println(a) + fmt.Println("In 10 years Bond will be", b, "years old.") + + fmt.Println(`Program "about" to exit`) +} + +func foo() { + fmt.Println("Foo is here") +} + +// define bar with PARAMETERS +// EXPRESSIONS evaluate to some VALUE, eg, y + 10 +// STATEMENT is a line of code to be executed +func bar(x string, y int) (string, int) { + return fmt.Sprint(x, " is here and he is ", y, " years old"), y + 10 +} + +// we will pass ARGUMENTS in to a function that has been defined with PARAMETERS + +// func receiver identifier(parameters) return(s) {code} diff --git a/000_temp/63-fall-2018/010-hands-on/01/main.go b/000_temp/63-fall-2018/010-hands-on/01/main.go new file mode 100644 index 00000000..1e763f95 --- /dev/null +++ b/000_temp/63-fall-2018/010-hands-on/01/main.go @@ -0,0 +1,10 @@ +package main + +import "fmt" + +func main() { + x := 40 + y := 2 + z := x * y + fmt.Println(z) +} diff --git a/000_temp/63-fall-2018/010-hands-on/02/main.go b/000_temp/63-fall-2018/010-hands-on/02/main.go new file mode 100644 index 00000000..0e8d297b --- /dev/null +++ b/000_temp/63-fall-2018/010-hands-on/02/main.go @@ -0,0 +1,16 @@ +package main + +import "fmt" + +func main() { + foo() +} + + +// func receiver identifier(parameters) return(s) {code} + +func foo() { + x := "James Bond" + y := 32 + fmt.Println(x, y) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/010-hands-on/03/main.go b/000_temp/63-fall-2018/010-hands-on/03/main.go new file mode 100644 index 00000000..e15ff88c --- /dev/null +++ b/000_temp/63-fall-2018/010-hands-on/03/main.go @@ -0,0 +1,21 @@ +package main + +import "fmt" + +func main() { + + // when we call a func, we pass in ARGUMENTS + foo("Todd", 42) + foo("James", 32) + foo("Jenny", 27) + foo("Cole", 19) +} + + +// func +// modularize our code and DRY (don't repeat yourself) +// funcs are defined with parameters +// parameters specify a VALUE of a certain TYPE to be passed in when the func is called +func foo(x string, y int) { + fmt.Println(x, y) +} diff --git a/000_temp/63-fall-2018/010-hands-on/04/main.go b/000_temp/63-fall-2018/010-hands-on/04/main.go new file mode 100644 index 00000000..9d790777 --- /dev/null +++ b/000_temp/63-fall-2018/010-hands-on/04/main.go @@ -0,0 +1,14 @@ +package main + +import "fmt" + +func main() { + z := foo(40, 45) + fmt.Println(z) +} + + +// func receiver identifier(parameters) returns {code} +func foo(x int, y int) int { + return x * y +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/010-hands-on/05/main.go b/000_temp/63-fall-2018/010-hands-on/05/main.go new file mode 100644 index 00000000..53cb74c7 --- /dev/null +++ b/000_temp/63-fall-2018/010-hands-on/05/main.go @@ -0,0 +1,15 @@ +package main + +import "fmt" + +func main() { + x := foo("Todd") + fmt.Println(x) +} + + +// func receiver identifier(parameters) returns {code} +func foo(s string) string { + //return fmt.Sprint("Hello ", s, "!") + return "Hello " + s + "!" +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/011-loops/main.go b/000_temp/63-fall-2018/011-loops/main.go new file mode 100644 index 00000000..330652c9 --- /dev/null +++ b/000_temp/63-fall-2018/011-loops/main.go @@ -0,0 +1,15 @@ +package main + +import "fmt" + +func main() { + foo() +} + + +// func receiver identifier(parameters) returns {code} +func foo() { + for i := 0; i <= 100; i++ { + fmt.Println(i) + } +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/012-conditional/main.go b/000_temp/63-fall-2018/012-conditional/main.go new file mode 100644 index 00000000..c7f06600 --- /dev/null +++ b/000_temp/63-fall-2018/012-conditional/main.go @@ -0,0 +1,17 @@ +package main + +import "fmt" + +func main() { + foo() +} + + +// func receiver identifier(parameters) returns {code} +func foo() { + for i := 0; i <= 100; i++ { + if i % 2 == 0 { + fmt.Println(i) + } + } +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/013-slice/main.go b/000_temp/63-fall-2018/013-slice/main.go new file mode 100644 index 00000000..bc594823 --- /dev/null +++ b/000_temp/63-fall-2018/013-slice/main.go @@ -0,0 +1,20 @@ +package main + +import "fmt" + +func main() { + xi := []int{2,3,4,5,6,7,8} + fmt.Println(xi) + + for i, v := range xi { + fmt.Println(i, v) + } + + xs := []string{"James", "Jenny", "M", "Q"} + + fmt.Println(xs) + + for i, v := range xs { + fmt.Println(i, v) + } +} diff --git a/000_temp/63-fall-2018/014-maps/main.go b/000_temp/63-fall-2018/014-maps/main.go new file mode 100644 index 00000000..5d2ab53f --- /dev/null +++ b/000_temp/63-fall-2018/014-maps/main.go @@ -0,0 +1,12 @@ +package main + +import "fmt" + +func main() { + m := map[string]int{"James":32, "Jenny":27,} + fmt.Println(m) + + for k, v := range m { + fmt.Println(k, v) + } +} diff --git a/000_temp/63-fall-2018/015-struct/main.go b/000_temp/63-fall-2018/015-struct/main.go new file mode 100644 index 00000000..8fcf44d6 --- /dev/null +++ b/000_temp/63-fall-2018/015-struct/main.go @@ -0,0 +1,45 @@ +package main + +import "fmt" + +type person struct { + first string + last string + age int + sayings []string +} + +func main() { + p1 := person{ + first: "James", + last: "Bond", + age: 32, + sayings: []string{"Shaken, not stirred", "Bond, James Bond",}, + } + fmt.Println(p1) + + p2 := person{ + first: "Jenny", + last: "Moneypenny", + age: 27, + sayings: []string{"Danger knows no gender", "A woman's place is in control",}, + } + fmt.Println(p2) + + xp := []person{p1, p2} + + fmt.Println("---------") + for i, v := range xp { + fmt.Println(i, v, v.first) + for j, w := range v.sayings { + fmt.Println(j, w) + } + } + fmt.Println("---------") + + m := map[string]person{"James":p1, "Jenny":p2,} + + for k, p := range m { + fmt.Println(k, p) + } +} diff --git a/000_temp/63-fall-2018/016-fun-with-text/main.go b/000_temp/63-fall-2018/016-fun-with-text/main.go new file mode 100644 index 00000000..bc445452 --- /dev/null +++ b/000_temp/63-fall-2018/016-fun-with-text/main.go @@ -0,0 +1,18 @@ +package main + +import "fmt" + +func main() { + x := "ABCDE" + fmt.Println(x) + + fmt.Printf("%T\n", x) + + xr := []rune(x) + fmt.Println(xr) + + for _, v := range xr { + fmt.Printf("%d - %b - %#X\n", v, v, v) + } + +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/017-slice/main.go b/000_temp/63-fall-2018/017-slice/main.go new file mode 100644 index 00000000..ea59942c --- /dev/null +++ b/000_temp/63-fall-2018/017-slice/main.go @@ -0,0 +1,25 @@ +package main + +import "fmt" + +func main() { + x := 42 + y := 43 + xi := []int{x, y} + + fmt.Printf("%T\n", x) + fmt.Printf("%T\n", y) + fmt.Printf("%T\n", xi) + + fmt.Println(xi) + + a := "James" + b := "Jenny" + xs := []string{a, b} + + fmt.Printf("%T\n", a) + fmt.Printf("%T\n", b) + fmt.Printf("%T\n", xs) + fmt.Println(xs) + +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/018-map/main.go b/000_temp/63-fall-2018/018-map/main.go new file mode 100644 index 00000000..c84807fd --- /dev/null +++ b/000_temp/63-fall-2018/018-map/main.go @@ -0,0 +1,11 @@ +package main + +import "fmt" + +func main() { + m := map[string]int{"James":7, "Jenny":8,} + fmt.Printf("%T\n", m) + fmt.Println(m) + + fmt.Println(m["James"]) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/019-struct/01/main.go b/000_temp/63-fall-2018/019-struct/01/main.go new file mode 100644 index 00000000..d32ae55d --- /dev/null +++ b/000_temp/63-fall-2018/019-struct/01/main.go @@ -0,0 +1,16 @@ +package _1 + +import "fmt" + +type hotdog int +var x hotdog + +func main() { + x = 7 + fmt.Printf("%T\n", x) + fmt.Println(x) + y := int(x) + fmt.Printf("%T\n", y) + fmt.Println(y) + +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/019-struct/02/main.go b/000_temp/63-fall-2018/019-struct/02/main.go new file mode 100644 index 00000000..7cb3b388 --- /dev/null +++ b/000_temp/63-fall-2018/019-struct/02/main.go @@ -0,0 +1,18 @@ +package main + +import "fmt" + +type person struct { + first string + license int + sayings []string +} + +func main() { + p1 := person{ + first: "James", + license: 007, + sayings: []string{"Shaken, not stirred", "Bond, James Bond",}, + } + fmt.Println(p1) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/019-struct/03/main.go b/000_temp/63-fall-2018/019-struct/03/main.go new file mode 100644 index 00000000..61de635f --- /dev/null +++ b/000_temp/63-fall-2018/019-struct/03/main.go @@ -0,0 +1,31 @@ +package main + +import "fmt" + +type person struct { + first string + license int + sayings []string +} + +func main() { + p1 := person{ + first: "James", + license: 7, + sayings: []string{"Shaken, not stirred", "Bond, James Bond",}, + } + fmt.Println(p1) + + p2 := person{ + first: "Jenny", + license: 8, + sayings: []string{"When Bond can't handle it, call me", "I will always love Bond",}, + } + fmt.Println(p2) + + xp := []person{p1, p2} + fmt.Println(xp) + + mp := map[string]person{"Mr":p1, "Ms":p2,} + fmt.Println(mp) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/020-looping/01/main.go b/000_temp/63-fall-2018/020-looping/01/main.go new file mode 100644 index 00000000..b73205fc --- /dev/null +++ b/000_temp/63-fall-2018/020-looping/01/main.go @@ -0,0 +1,25 @@ +package main + +import "fmt" + +func main() { + + /* + for { + fmt.Println("hello") + } + */ + + // for init; cond; incrementor {code} + for i := 0; i <= 10; i++ { + fmt.Println(i) + } + + for i := 0; ; i++ { + fmt.Println(i, i) + if i == 11 { + break + } + } + +} diff --git a/000_temp/63-fall-2018/020-looping/02/main.go b/000_temp/63-fall-2018/020-looping/02/main.go new file mode 100644 index 00000000..1fb0b8ee --- /dev/null +++ b/000_temp/63-fall-2018/020-looping/02/main.go @@ -0,0 +1,33 @@ +package main + +import "fmt" + +func main() { + xi := []int{2, 3, 4, 5, 7, 9, 42} + + for i, v := range xi { + fmt.Println(i, v) + } + + for idx := range xi { + fmt.Println(idx) + } + + for _, val := range xi { + fmt.Println("-",val) + } + + m := map[string]int{"James":32, "Jenny":27,} + + for k, v := range m { + fmt.Println(k, v) + } + + for key := range m { + fmt.Println(key) + } + + for _, value := range m { + fmt.Println("-", value) + } +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/021-receiver/01/main.go b/000_temp/63-fall-2018/021-receiver/01/main.go new file mode 100644 index 00000000..608fdde7 --- /dev/null +++ b/000_temp/63-fall-2018/021-receiver/01/main.go @@ -0,0 +1,42 @@ +package main + +import "fmt" + +type person struct { + first string + last string + saying string +} + +// func (receiver) identifier(parameters) (returns) {code} + +func (p person) speak() { + fmt.Println(p.first, "says", p.saying) +} + +func main() { + p1 := person{ + first: "James", + last: "Bond", + saying: "Shaken, not stirred.", + } + + p2 := person{ + first: "Jenny", + last: "Moneypenny", + saying: "Helllllllo, James.", + } + + fmt.Println(p1) + fmt.Println(p2) + + fmt.Println("---------") + + fmt.Println(p1.first, "says", p1.saying) + fmt.Println(p2.first, "says", p2.saying) + + fmt.Println("---------") + + p1.speak() + p2.speak() +} diff --git a/000_temp/63-fall-2018/022-interfaces/01/main.go b/000_temp/63-fall-2018/022-interfaces/01/main.go new file mode 100644 index 00000000..e194fb3a --- /dev/null +++ b/000_temp/63-fall-2018/022-interfaces/01/main.go @@ -0,0 +1,71 @@ +package main + +import "fmt" + +type person struct { + first string + last string + saying string +} + +func (p person) speak() { + fmt.Println(p.first, "says", p.saying) +} + +func (sa secretAgent) speak() { + fmt.Println(sa.first, "says wackabacka haha", sa.saying) +} + +type secretAgent struct { + person + ltk bool +} +type human interface { + speak() +} + +func foo(h human) { + h.speak() +} + +func main() { + p1 := person{ + first: "James", + last: "Bond", + saying: "Shaken, not stirred.", + } + + p2 := person{ + first: "Jenny", + last: "Moneypenny", + saying: "Helllllllo, James.", + } + + sa1 := secretAgent{ + person: person{ + first: "Ian", + last: "Fleming", + saying: "The books were based on real stories", + }, + ltk: true, + } + + fmt.Println(p1) + fmt.Println(p2) + + fmt.Println("---------") + + fmt.Println(p1.first, "says", p1.saying) + fmt.Println(p2.first, "says", p2.saying) + + fmt.Println("---------") + + p1.speak() + p2.speak() + + fmt.Println("--------- interface") + + foo(p1) + foo(p2) + foo(sa1) +} diff --git a/000_temp/63-fall-2018/022-interfaces/02/main.go b/000_temp/63-fall-2018/022-interfaces/02/main.go new file mode 100644 index 00000000..e194fb3a --- /dev/null +++ b/000_temp/63-fall-2018/022-interfaces/02/main.go @@ -0,0 +1,71 @@ +package main + +import "fmt" + +type person struct { + first string + last string + saying string +} + +func (p person) speak() { + fmt.Println(p.first, "says", p.saying) +} + +func (sa secretAgent) speak() { + fmt.Println(sa.first, "says wackabacka haha", sa.saying) +} + +type secretAgent struct { + person + ltk bool +} +type human interface { + speak() +} + +func foo(h human) { + h.speak() +} + +func main() { + p1 := person{ + first: "James", + last: "Bond", + saying: "Shaken, not stirred.", + } + + p2 := person{ + first: "Jenny", + last: "Moneypenny", + saying: "Helllllllo, James.", + } + + sa1 := secretAgent{ + person: person{ + first: "Ian", + last: "Fleming", + saying: "The books were based on real stories", + }, + ltk: true, + } + + fmt.Println(p1) + fmt.Println(p2) + + fmt.Println("---------") + + fmt.Println(p1.first, "says", p1.saying) + fmt.Println(p2.first, "says", p2.saying) + + fmt.Println("---------") + + p1.speak() + p2.speak() + + fmt.Println("--------- interface") + + foo(p1) + foo(p2) + foo(sa1) +} diff --git a/000_temp/63-fall-2018/023-review/main.go b/000_temp/63-fall-2018/023-review/main.go new file mode 100644 index 00000000..9f33dc01 --- /dev/null +++ b/000_temp/63-fall-2018/023-review/main.go @@ -0,0 +1,124 @@ +package main + +import "fmt" + +var c int +var d = 43 + +const z = 142 + +type person struct { + first string + age int + saying string +} + +// func receiver identifier(params) returns {code} + +func (p person) speak() { + fmt.Println(p.first, "says", p.saying) +} + +type secretagent struct { + person + ltk bool +} + +func (sa secretagent) speak() { + fmt.Println(sa.first, "says even more", sa.saying) +} + +type human interface { + speak() +} + +func foo(h human) { + h.speak() +} + +func main() { + a := "James" + fmt.Println(a) + fmt.Printf("%T\n", a) + + b := fmt.Sprint("Hello", a) + fmt.Println(b) + + c = 42 + fmt.Println("c:", c) + + d = 43 + fmt.Println("d:", d) + fmt.Printf("d type: %T\n", d) + + // slice AGGREGATE or COMPOSITE data structure + + ee := []int{2,3,4,7,9,} + fmt.Println(ee) + + // it was going SEQUENCE + // now it's going ITERATIVE + + for i, v := range ee { + fmt.Println(i, v) + // conditional logic + if i == 3 { + fmt.Println("HEY, i is EQUAL TO", i) + } + } + + + // map AGGREGATE or COMPOSITE data structure + f := map[string]int{"James":32, "Jenny":27,} + fmt.Println(f) + + for k, v := range f { + fmt.Println(k, v) + } + + // struct AGGREGATE or COMPOSITE data structure + p1 := person{ + first: "James", + age: 32, + saying: "shaken, not stirred", + } + + p2 := person { + first: "Jenny", + age: 27, + saying: "nobody does it better", + } + + xp := []person{p1, p2} + fmt.Println(xp) + for i2, v2 := range xp { + fmt.Println(i2, v2) + } + + // loop init, cond, post + for j := 0; j < 10; j++ { + fmt.Println(j) + } + + sa1 := secretagent{ + person: person{ + first: "Jack", + age: 29, + saying: "Blahb blahblabhalbhablhab", + }, + ltk: true, + } + fmt.Println(sa1) + fmt.Println(sa1.first) + fmt.Println(sa1.person.first) + + p1.speak() + p2.speak() + sa1.speak() + fmt.Println("--") + foo(p1) + foo(p2) + foo(sa1) + + fmt.Println(z) +} diff --git a/000_temp/63-fall-2018/024-unfurling-slice/main.go b/000_temp/63-fall-2018/024-unfurling-slice/main.go new file mode 100644 index 00000000..5cbce4f9 --- /dev/null +++ b/000_temp/63-fall-2018/024-unfurling-slice/main.go @@ -0,0 +1,13 @@ +package main + +import "fmt" + +func main() { + xi := []int{1,2,4,5,7,8,9,} + foo(xi...) +} + +func foo(i ...int) { + fmt.Println(i) + fmt.Printf("%T\n", i) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/025-defer/main.go b/000_temp/63-fall-2018/025-defer/main.go new file mode 100644 index 00000000..26cd71ca --- /dev/null +++ b/000_temp/63-fall-2018/025-defer/main.go @@ -0,0 +1,26 @@ +package main + +import "fmt" + +func main() { + defer foo() + bar() +} + +func foo() { + fmt.Println("foooooooo") +} + +func bar() { + fmt.Println("barrrrrrrrr") + defer one() + two() +} + +func one() { + fmt.Println("oneeeeeee") +} + +func two() { + fmt.Println("twoooooooooo") +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/026-anonymous-func/main.go b/000_temp/63-fall-2018/026-anonymous-func/main.go new file mode 100644 index 00000000..6f1cd19d --- /dev/null +++ b/000_temp/63-fall-2018/026-anonymous-func/main.go @@ -0,0 +1,15 @@ +package main + +import "fmt" + +func main() { + foo() + + // anonymous func + + func(x int){ + fmt.Println(x) + }(4) +} + +func foo() {fmt.Println("this is foo")} \ No newline at end of file diff --git a/000_temp/63-fall-2018/027-func-expression/main.go b/000_temp/63-fall-2018/027-func-expression/main.go new file mode 100644 index 00000000..f536aab4 --- /dev/null +++ b/000_temp/63-fall-2018/027-func-expression/main.go @@ -0,0 +1,27 @@ +package main + +import "fmt" + +func main() { + a := foo("something") + fmt.Println(a) + + d := 14 + b := func(z string){ + fmt.Println(z) + } + + fmt.Printf("%T\n", d) + fmt.Printf("%T\n", b) + + b("james") + b("jenny") + x := foo("cat") + y := foo("bird") + fmt.Println(x,y) + fmt.Println(d) +} + +func foo(s string) string { + return s + "dogggggggg" +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/028-returning-a-func/main.go b/000_temp/63-fall-2018/028-returning-a-func/main.go new file mode 100644 index 00000000..9fc52167 --- /dev/null +++ b/000_temp/63-fall-2018/028-returning-a-func/main.go @@ -0,0 +1,23 @@ +package main + +import "fmt" + +func main() { + x := foo() + y := foo() + fmt.Printf("%T\t %T\n", x,y) + + func(z string){ + fmt.Println(z) + }("james") + + x("jenny") + y("dogggggggggy") + +} + +func foo() func(string) { + return func(z string){ + fmt.Println(z) + } +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/029-pointers/main.go b/000_temp/63-fall-2018/029-pointers/main.go new file mode 100644 index 00000000..e53221a7 --- /dev/null +++ b/000_temp/63-fall-2018/029-pointers/main.go @@ -0,0 +1,19 @@ +package main + +import "fmt" + +func main() { + x := 42 + fmt.Println(x) + fmt.Printf("%T\n", x) + fmt.Println(&x) + + y := &x + fmt.Println(y) + fmt.Printf("%T\n", y) + fmt.Println(*y) + + *y = 43 + + fmt.Println(x) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/030-os-args/main.go b/000_temp/63-fall-2018/030-os-args/main.go new file mode 100644 index 00000000..2babcccd --- /dev/null +++ b/000_temp/63-fall-2018/030-os-args/main.go @@ -0,0 +1,13 @@ +package main + +import ( + "os" + "fmt" +) + +func main() { + fmt.Println(os.Args[0]) + fmt.Println(os.Args[1]) + fmt.Println(os.Args[2]) + fmt.Println(os.Args[3]) +} diff --git a/000_temp/63-fall-2018/031-string-template/main.go b/000_temp/63-fall-2018/031-string-template/main.go new file mode 100644 index 00000000..7d1d6803 --- /dev/null +++ b/000_temp/63-fall-2018/031-string-template/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "fmt" + "os" + "log" + "strings" + "io" +) + +func main() { + // CREATE STRING + // assign to variable + name := "James" + str := `html here` + name + `more html` + fmt.Println(str) + + // CREATE STRING + // string print + s := fmt.Sprint(`mas ` + name + `menos`) + fmt.Println(s) + + // CREATE FILE + // io.Copy to the file + nf, err := os.Create("newfile.txt") + if err != nil { + log.Fatal("whoops", err) + } + + io.Copy(nf, strings.NewReader(s)) + + // CREATE FILE + // writestring to file + nf2, err := os.Create("newfile2.txt") + if err != nil { + log.Fatal("whoops", err) + } + + n, err := nf2.WriteString(str) + if err != nil { + log.Fatal("whoops2", err) + } + + fmt.Println("bytes written", n) +} diff --git a/000_temp/63-fall-2018/032-text-template/main.go b/000_temp/63-fall-2018/032-text-template/main.go new file mode 100644 index 00000000..6285de4a --- /dev/null +++ b/000_temp/63-fall-2018/032-text-template/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "text/template" + "log" + "os" + "fmt" +) + +func main() { + tpl, err := template.ParseFiles("one.txt", "two.txt") + if err != nil { + log.Fatal("whoops", err) + } + + fmt.Println("\n-----") + tpl.ExecuteTemplate(os.Stdout, "one.txt", nil) + + fmt.Println("\n\n-----") + tpl.ExecuteTemplate(os.Stdout, "two.txt", "James") + fmt.Println("\n\n") +} diff --git a/000_temp/63-fall-2018/032-text-template/one.txt b/000_temp/63-fall-2018/032-text-template/one.txt new file mode 100644 index 00000000..045061a0 --- /dev/null +++ b/000_temp/63-fall-2018/032-text-template/one.txt @@ -0,0 +1 @@ +Hello, this is file one. \ No newline at end of file diff --git a/000_temp/63-fall-2018/032-text-template/two.txt b/000_temp/63-fall-2018/032-text-template/two.txt new file mode 100644 index 00000000..c93bf5b8 --- /dev/null +++ b/000_temp/63-fall-2018/032-text-template/two.txt @@ -0,0 +1 @@ +Hello, this is file two and my name is {{.}} \ No newline at end of file diff --git a/000_temp/63-fall-2018/033-parseglob/main.go b/000_temp/63-fall-2018/033-parseglob/main.go new file mode 100644 index 00000000..0d024b14 --- /dev/null +++ b/000_temp/63-fall-2018/033-parseglob/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "text/template" + "os" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*")) +} + +func main() { + err := tpl.ExecuteTemplate(os.Stdout, "one.gohtml", nil) + if err != nil { + panic(err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "two.gohtml", nil) + if err != nil { + panic(err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "lasagne.php", nil) + if err != nil { + panic(err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "anaheim.dland", nil) + if err != nil { + panic(err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "lets.blowitup", nil) + if err != nil { + panic(err) + } +} diff --git a/000_temp/63-fall-2018/033-parseglob/templates/anaheim.dland b/000_temp/63-fall-2018/033-parseglob/templates/anaheim.dland new file mode 100644 index 00000000..c8540638 --- /dev/null +++ b/000_temp/63-fall-2018/033-parseglob/templates/anaheim.dland @@ -0,0 +1,2 @@ +this is file anaheim +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/033-parseglob/templates/lasagne.php b/000_temp/63-fall-2018/033-parseglob/templates/lasagne.php new file mode 100644 index 00000000..0596157e --- /dev/null +++ b/000_temp/63-fall-2018/033-parseglob/templates/lasagne.php @@ -0,0 +1,2 @@ +this is file lasagne +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/033-parseglob/templates/one.gohtml b/000_temp/63-fall-2018/033-parseglob/templates/one.gohtml new file mode 100644 index 00000000..d7432a4c --- /dev/null +++ b/000_temp/63-fall-2018/033-parseglob/templates/one.gohtml @@ -0,0 +1,2 @@ +this is file one +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/033-parseglob/templates/two.gohtml b/000_temp/63-fall-2018/033-parseglob/templates/two.gohtml new file mode 100644 index 00000000..d2648063 --- /dev/null +++ b/000_temp/63-fall-2018/033-parseglob/templates/two.gohtml @@ -0,0 +1,2 @@ +this is file two +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/034-pass-in-data-aggregate/main.go b/000_temp/63-fall-2018/034-pass-in-data-aggregate/main.go new file mode 100644 index 00000000..4138fcfa --- /dev/null +++ b/000_temp/63-fall-2018/034-pass-in-data-aggregate/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "text/template" + "os" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*")) +} + +type person struct { + First string + Last string + Age int +} + +func main() { + + p1 := person{ + First: "James", + Last: "Bond", + Age: 32, + } + + err := tpl.ExecuteTemplate(os.Stdout, "one.gohtml", p1) + if err != nil { + panic(err) + } + + p2 := person{ + First: "Jenny", + Last: "Moneypenny", + Age: 27, + } + + xp := []person{p1, p2} + err = tpl.ExecuteTemplate(os.Stdout, "two.gohtml", xp) + if err != nil { + panic(err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "lasagne.php", p1) + if err != nil { + panic(err) + } + +} diff --git a/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/lasagne.php b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/lasagne.php new file mode 100644 index 00000000..175b0a27 --- /dev/null +++ b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/lasagne.php @@ -0,0 +1,2 @@ +this is file lasagne {{.First}} is {{.Last}} +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/one.gohtml b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/one.gohtml new file mode 100644 index 00000000..a7bd2240 --- /dev/null +++ b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/one.gohtml @@ -0,0 +1,2 @@ +this is file one {{.}} +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/two.gohtml b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/two.gohtml new file mode 100644 index 00000000..0a8c762e --- /dev/null +++ b/000_temp/63-fall-2018/034-pass-in-data-aggregate/templates/two.gohtml @@ -0,0 +1,2 @@ +this is file two {{.}} +****** \ No newline at end of file diff --git a/000_temp/63-fall-2018/035-hash-bucket/main.go b/000_temp/63-fall-2018/035-hash-bucket/main.go new file mode 100644 index 00000000..abc30424 --- /dev/null +++ b/000_temp/63-fall-2018/035-hash-bucket/main.go @@ -0,0 +1,41 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "net/http" +) + +func main() { + // get the book moby dick + res, err := http.Get("http://www.gutenberg.org/files/2701/2701-0.txt") + if err != nil { + log.Fatal(err) + } + + defer res.Body.Close() + scanner := bufio.NewScanner(res.Body) + // scan the page + // Set the split function for the scanning operation. + scanner.Split(bufio.ScanWords) + // Create slice to hold counts + buckets := make([]int, 2000) + // Loop over the words + for scanner.Scan() { + fmt.Print(scanner.Text(), " - ") + n := hashBucket(scanner.Text()) + buckets[n]++ + } + fmt.Println(buckets[65:123]) + // fmt.Println("***************") + // for i := 28; i <= 126; i++ { + // fmt.Printf("%v - %c - %v \n", i, i, buckets[i]) + // } +} + +func hashBucket(word string) int { + fmt.Print(word[0], " ---- ") + fmt.Printf("%#U\n", word[0]) + return int(word[0]) +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/036-templates-review/main.go b/000_temp/63-fall-2018/036-templates-review/main.go new file mode 100644 index 00000000..ebbb00ac --- /dev/null +++ b/000_temp/63-fall-2018/036-templates-review/main.go @@ -0,0 +1,49 @@ +package main + +import ( + "html/template" + "os" + "log" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + err := tpl.ExecuteTemplate(os.Stdout, "main.gohtml", nil) + if err != nil { + log.Fatal("there was an error", err) + } + + err = tpl.ExecuteTemplate(os.Stdout, "about.gohtml", nil) + if err != nil { + log.Fatal("there was an error", err) + } + + f, err := os.Create("main.html") + if err != nil { + log.Fatal("another error", err) + } + defer f.Close() + + f2, err := os.Create("about.html") + if err != nil { + log.Fatal("another error", err) + } + defer f2.Close() + + err = tpl.ExecuteTemplate(f, "main.gohtml", nil) + if err != nil { + log.Fatal("there was an error", err) + } + + err = tpl.ExecuteTemplate(f2, "about.gohtml", nil) + if err != nil { + log.Fatal("there was an error", err) + } + + +} \ No newline at end of file diff --git a/000_temp/63-fall-2018/036-templates-review/templates/about.gohtml b/000_temp/63-fall-2018/036-templates-review/templates/about.gohtml new file mode 100644 index 00000000..89312acc --- /dev/null +++ b/000_temp/63-fall-2018/036-templates-review/templates/about.gohtml @@ -0,0 +1,12 @@ + + + + + About + + + +

Here is my about template

+ + + \ No newline at end of file diff --git a/000_temp/63-fall-2018/036-templates-review/templates/main.gohtml b/000_temp/63-fall-2018/036-templates-review/templates/main.gohtml new file mode 100644 index 00000000..00f69d92 --- /dev/null +++ b/000_temp/63-fall-2018/036-templates-review/templates/main.gohtml @@ -0,0 +1,12 @@ + + + + + Main + + + +

Here is my main template

+ + + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/01/about.html b/000_temp/63-fall-2018/037-data/01/about.html new file mode 100644 index 00000000..1ddf1801 --- /dev/null +++ b/000_temp/63-fall-2018/037-data/01/about.html @@ -0,0 +1,15 @@ + + + + + + + Document + + + + +

here's the data from about [7 8 9 125 345]

+ + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/01/default.html b/000_temp/63-fall-2018/037-data/01/default.html new file mode 100644 index 00000000..554b3e3a --- /dev/null +++ b/000_temp/63-fall-2018/037-data/01/default.html @@ -0,0 +1,15 @@ + + + + + + + Document + + + +

Here's the data 42

+ + + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/01/main.go b/000_temp/63-fall-2018/037-data/01/main.go new file mode 100644 index 00000000..fd858f6f --- /dev/null +++ b/000_temp/63-fall-2018/037-data/01/main.go @@ -0,0 +1,39 @@ +package main + +import ( + "html/template" + "os" + "log" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + f1, err := os.Create("default.html") + if err != nil { + log.Fatal("f1 errored", err) + } + defer f1.Close() + + f2, err := os.Create("about.html") + if err != nil { + log.Fatal("f1 errored", err) + } + defer f2.Close() + + err = tpl.ExecuteTemplate(f1, "default.gohtml", 42) + if err != nil { + panic(err) + } + + + xi := []int{7,8,9,125,345,} + err = tpl.ExecuteTemplate(f2, "about.gohtml", xi) + if err != nil { + panic(err) + } +} diff --git a/000_temp/63-fall-2018/037-data/01/templates/about.gohtml b/000_temp/63-fall-2018/037-data/01/templates/about.gohtml new file mode 100644 index 00000000..4a098421 --- /dev/null +++ b/000_temp/63-fall-2018/037-data/01/templates/about.gohtml @@ -0,0 +1,15 @@ + + + + + + + Document + + + + +

here's the data from about {{.}}

+ + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/01/templates/default.gohtml b/000_temp/63-fall-2018/037-data/01/templates/default.gohtml new file mode 100644 index 00000000..86c227e5 --- /dev/null +++ b/000_temp/63-fall-2018/037-data/01/templates/default.gohtml @@ -0,0 +1,15 @@ + + + + + + + Document + + + +

Here's the data {{.}}

+ + + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/02/about.html b/000_temp/63-fall-2018/037-data/02/about.html new file mode 100644 index 00000000..348f6c97 --- /dev/null +++ b/000_temp/63-fall-2018/037-data/02/about.html @@ -0,0 +1,23 @@ + + + + + + + Document + + + + +

ABOUT here is a raw + +string + + +literal + + +

+ + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/02/default.html b/000_temp/63-fall-2018/037-data/02/default.html new file mode 100644 index 00000000..1afc6b1b --- /dev/null +++ b/000_temp/63-fall-2018/037-data/02/default.html @@ -0,0 +1,16 @@ + + + + + + + Document + + + +

DEFAULT here is text with space

+ + + + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/02/main.go b/000_temp/63-fall-2018/037-data/02/main.go new file mode 100644 index 00000000..957a710c --- /dev/null +++ b/000_temp/63-fall-2018/037-data/02/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "html/template" + "os" + "log" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + f1, err := os.Create("default.html") + if err != nil { + log.Fatal("f1 errored", err) + } + defer f1.Close() + + f2, err := os.Create("about.html") + if err != nil { + log.Fatal("f1 errored", err) + } + defer f2.Close() + + s := " here is text with space " + err = tpl.ExecuteTemplate(f1, "default.gohtml", s) + if err != nil { + panic(err) + } + + + t := ` here is a raw + +string + + +literal + + +` + err = tpl.ExecuteTemplate(f2, "about.gohtml", t) + if err != nil { + panic(err) + } +} diff --git a/000_temp/63-fall-2018/037-data/02/templates/about.gohtml b/000_temp/63-fall-2018/037-data/02/templates/about.gohtml new file mode 100644 index 00000000..ec3546a3 --- /dev/null +++ b/000_temp/63-fall-2018/037-data/02/templates/about.gohtml @@ -0,0 +1,15 @@ + + + + + + + Document + + + + +

ABOUT {{- .}}

+ + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/02/templates/default.gohtml b/000_temp/63-fall-2018/037-data/02/templates/default.gohtml new file mode 100644 index 00000000..fb5302a8 --- /dev/null +++ b/000_temp/63-fall-2018/037-data/02/templates/default.gohtml @@ -0,0 +1,16 @@ + + + + + + + Document + + + +

DEFAULT {{- . -}}

+ + + + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/03/about.html b/000_temp/63-fall-2018/037-data/03/about.html new file mode 100644 index 00000000..6d39692f --- /dev/null +++ b/000_temp/63-fall-2018/037-data/03/about.html @@ -0,0 +1,15 @@ + + + + + + + Document + + + + +

ABOUT this is the else

+ + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/03/default.html b/000_temp/63-fall-2018/037-data/03/default.html new file mode 100644 index 00000000..83db2f29 --- /dev/null +++ b/000_temp/63-fall-2018/037-data/03/default.html @@ -0,0 +1,16 @@ + + + + + + + Document + + + +

DEFAULT evaluated

+ + + + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/03/main.go b/000_temp/63-fall-2018/037-data/03/main.go new file mode 100644 index 00000000..ca00444a --- /dev/null +++ b/000_temp/63-fall-2018/037-data/03/main.go @@ -0,0 +1,40 @@ +package main + +import ( + "html/template" + "os" + "log" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + f1, err := os.Create("default.html") + if err != nil { + log.Fatal("f1 errored", err) + } + defer f1.Close() + + f2, err := os.Create("about.html") + if err != nil { + log.Fatal("f1 errored", err) + } + defer f2.Close() + + t := true + err = tpl.ExecuteTemplate(f1, "default.gohtml", t) + if err != nil { + panic(err) + } + + + f := false + err = tpl.ExecuteTemplate(f2, "about.gohtml", f) + if err != nil { + panic(err) + } +} diff --git a/000_temp/63-fall-2018/037-data/03/templates/about.gohtml b/000_temp/63-fall-2018/037-data/03/templates/about.gohtml new file mode 100644 index 00000000..79bc1eb1 --- /dev/null +++ b/000_temp/63-fall-2018/037-data/03/templates/about.gohtml @@ -0,0 +1,15 @@ + + + + + + + Document + + + + +

ABOUT {{if .}}evaluated{{else}} this is the else{{end}}

+ + \ No newline at end of file diff --git a/000_temp/63-fall-2018/037-data/03/templates/default.gohtml b/000_temp/63-fall-2018/037-data/03/templates/default.gohtml new file mode 100644 index 00000000..053254bb --- /dev/null +++ b/000_temp/63-fall-2018/037-data/03/templates/default.gohtml @@ -0,0 +1,16 @@ + + + + + + + Document + + + +

DEFAULT {{if .}}evaluated{{else}} this is the else{{end}}

+ + + + \ No newline at end of file diff --git a/000_temp/64-HANDLER/main.go b/000_temp/64-HANDLER/main.go new file mode 100644 index 00000000..b5b6687c --- /dev/null +++ b/000_temp/64-HANDLER/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "net/http" + "io" +) + + +type hotdog int + +// func receiver identifier(params) return(s) {} +func (h hotdog) ServeHTTP(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "WASSSSSUP!!!!!") +} + +func main() { + var d hotdog + http.ListenAndServe(":8080", d) +} + +/* + +type Handler +type Handler interface { + ServeHTTP(ResponseWriter, *Request) +} + +*/ \ No newline at end of file diff --git a/000_temp/65-DEFAULT-SERVE-MUX/main.go b/000_temp/65-DEFAULT-SERVE-MUX/main.go new file mode 100644 index 00000000..cce7dabe --- /dev/null +++ b/000_temp/65-DEFAULT-SERVE-MUX/main.go @@ -0,0 +1,47 @@ +package main + +import ( + "net/http" + "log" + "fmt" + "html" + "io" +) + + +type hotdog int + +func (h hotdog) ServeHTTP(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "hello from baz") +} + +func main() { + + var bazhandler hotdog + + http.Handle("/baz", bazhandler) + + http.HandleFunc("/foo", fooHandler) + + http.HandleFunc("/bar/", func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hello, %q", html.EscapeString(r.URL.Path)) + }) + + + log.Fatal(http.ListenAndServe(":8080", nil)) + +} + +func fooHandler(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "hello from foo") +} + + +/* + +type Handler +type Handler interface { + ServeHTTP(ResponseWriter, *Request) +} + +*/ \ No newline at end of file diff --git a/000_temp/66-HANDLEFUNC/main.go b/000_temp/66-HANDLEFUNC/main.go new file mode 100644 index 00000000..6eb300f5 --- /dev/null +++ b/000_temp/66-HANDLEFUNC/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "net/http" + "io" + "fmt" +) + +func main() { + http.HandleFunc("/", home) + http.HandleFunc("/about", about) + http.HandleFunc("/contact", contact) + + http.ListenAndServe(":8080", nil) +} + +func home(w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "hello from home") +} + +func about (w http.ResponseWriter, r *http.Request) { + io.WriteString(w, "wassup from about") +} + +func contact (w http.ResponseWriter, r * http.Request) { + fmt.Fprint(w, "get in touch with us, yo, here at contact") +} diff --git a/000_temp/67-KABOOM-BOOOYAH/main.go b/000_temp/67-KABOOM-BOOOYAH/main.go new file mode 100644 index 00000000..efbb3464 --- /dev/null +++ b/000_temp/67-KABOOM-BOOOYAH/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "net/http" + "html/template" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + http.HandleFunc("/", home) + http.HandleFunc("/about", about) + http.HandleFunc("/contact", contact) + + http.ListenAndServe(":8080", nil) +} + +func home(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "default.gohtml", nil) +} + +func about (w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "about.gohtml", nil) +} + +func contact (w http.ResponseWriter, r * http.Request) { + tpl.ExecuteTemplate(w, "contact.gohtml", nil) +} diff --git a/000_temp/67-KABOOM-BOOOYAH/templates/about.gohtml b/000_temp/67-KABOOM-BOOOYAH/templates/about.gohtml new file mode 100644 index 00000000..1fdab8c9 --- /dev/null +++ b/000_temp/67-KABOOM-BOOOYAH/templates/about.gohtml @@ -0,0 +1 @@ +hello from about \ No newline at end of file diff --git a/000_temp/67-KABOOM-BOOOYAH/templates/contact.gohtml b/000_temp/67-KABOOM-BOOOYAH/templates/contact.gohtml new file mode 100644 index 00000000..758bb847 --- /dev/null +++ b/000_temp/67-KABOOM-BOOOYAH/templates/contact.gohtml @@ -0,0 +1 @@ +hello from contact \ No newline at end of file diff --git a/000_temp/67-KABOOM-BOOOYAH/templates/default.gohtml b/000_temp/67-KABOOM-BOOOYAH/templates/default.gohtml new file mode 100644 index 00000000..59000559 --- /dev/null +++ b/000_temp/67-KABOOM-BOOOYAH/templates/default.gohtml @@ -0,0 +1 @@ +hello from default \ No newline at end of file diff --git a/000_temp/68-sql-group-having/having.sql b/000_temp/68-sql-group-having/having.sql new file mode 100644 index 00000000..e6c9f983 --- /dev/null +++ b/000_temp/68-sql-group-having/having.sql @@ -0,0 +1,62 @@ +CREATE DATABASE music; + +\c music + +CREATE TABLE musicians (mid INT PRIMARY KEY NOT NULL, mname TEXT NOT NULL); + +INSERT INTO musicians VALUES (1, 'Dave Mustang'), (2, 'Steven Tyler'), (3, 'Sam Smith'), (4, 'Sarah McLachlan'), (5, 'Bono'), (6, 'Steve Miller'), (7, 'Bruce Springsteen'); + +CREATE TABLE bands (bid INT PRIMARY KEY NOT NULL, bname TEXT NOT NULL); + +INSERT INTO bands VALUES (1, 'Aerosmith'), (2, 'U2'), (3, 'Ghost'), (4, 'E Street'), (5, 'Metallica'), (6, 'Megadeath'); + +CREATE TABLE bandmembers (bmid INT PRIMARY KEY NOT NULL, bid INT REFERENCES bands(bid) NOT NULL, mid INT REFERENCES musicians(mid) NOT NULL); + +INSERT INTO bandmembers VALUES (1,1,1), (2,2,2), (3,3,3), (4,4,4), (5,5,5), (6,5,7), (7,4,4), (8,3,3); + +CREATE TABLE styles (sid INT PRIMARY KEY NOT NULL, sname TEXT NOT NULL); + +INSERT INTO styles VALUES (1,'jazz'), (2,'metal'), (3,'rock'), (4,'country'), (5,'pop'), (6,'folk'); + +CREATE TABLE bandstyles (bsid INT PRIMARY KEY NOT NULL, bid INT REFERENCES bands(bid) NOT NULL, sid INT REFERENCES styles(sid) NOT NULL); + +INSERT INTO bandstyles VALUES (1,1,1), (2,2,2), (3,3,3), (4,4,4), (5,5,5), (6,4,4), (7,3,3); + +------------ queries --------------- + + +SELECT m.mname, b.bname, s.sname FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid; + + +/* generate more band members */ +https://play.golang.org/p/uv2g4Ap21Sl + +INSERT INTO bandmembers VALUES (9,2,3),(10,3,5),(11,2,4),(12,1,1),(13,2,1),(14,5,2),(15,3,5),(16,4,5),(17,2,1),(18,3,2),(19,1,2),(20,4,4),(21,3,3),(22,3,4),(23,1,1),(24,2,4),(25,3,2),(26,5,2),(27,3,2),(28,1,2),(29,4,1),(30,5,4),(31,4,3),(32,4,5),(33,5,4),(34,3,2),(35,5,5),(36,1,1),(37,4,4),(38,4,1),(39,2,1),(40,1,2); + + +SELECT bname, sname FROM (bands AS b LEFT JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid; + +SELECT m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid; + +SELECT m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid GROUP BY m.mname, b.bname; + +SELECT m.mid, m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid GROUP BY m.mid, m.mname, b.bname; + +/* does not work*/ +SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid; + +SELECT COUNT(*) AS total FROM musicians; + +/* does not work*/ +SELECT COUNT(*) AS total FROM musicians GROUP BY mname; + +SELECT mname, COUNT(*) AS total FROM musicians GROUP BY mname; + +SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname; + +SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname HAVING COUNT(*) > 10; + +SELECT b.bname, s.sname, COUNT(bm.bmid) AS bandmembers FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname; + +SELECT b.bname, s.sname, COUNT(bm.bmid) AS bandmembers FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname HAVING COUNT(*) > 10; + diff --git a/000_temp/69-review-golang/main.go b/000_temp/69-review-golang/main.go new file mode 100644 index 00000000..79853a7c --- /dev/null +++ b/000_temp/69-review-golang/main.go @@ -0,0 +1,28 @@ +package main + +import ( + "html/template" + "net/http" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + + http.HandleFunc("/", def) + http.HandleFunc("/about", abo) + http.Handle("/foobar", http.NotFoundHandler()) + http.ListenAndServe(":8080", nil) +} + +func def(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "default.gohtml", nil) +} + +func abo(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "about.gohtml", nil) +} \ No newline at end of file diff --git a/000_temp/69-review-golang/templates/about.gohtml b/000_temp/69-review-golang/templates/about.gohtml new file mode 100644 index 00000000..6b37e571 --- /dev/null +++ b/000_temp/69-review-golang/templates/about.gohtml @@ -0,0 +1,17 @@ + + + + + + + ABOUT + + + + +

HOME

+

ABOUT

+ + + \ No newline at end of file diff --git a/000_temp/69-review-golang/templates/default.gohtml b/000_temp/69-review-golang/templates/default.gohtml new file mode 100644 index 00000000..844d9eee --- /dev/null +++ b/000_temp/69-review-golang/templates/default.gohtml @@ -0,0 +1,16 @@ + + + + + + + HOME + + + +

HOME

+

ABOUT

+ + + \ No newline at end of file diff --git a/000_temp/70-sql/having.sql b/000_temp/70-sql/having.sql new file mode 100644 index 00000000..65fe4536 --- /dev/null +++ b/000_temp/70-sql/having.sql @@ -0,0 +1,96 @@ +SELECT m.mname, b.bname, s.sname FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid; + +SELECT s.sname, COUNT(b.bname) AS bands FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY s.sname; + +SELECT s.sname, COUNT(DISTINCT(b.bname)) AS bands FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY s.sname; + +SELECT DISTINCT(b.bname) AS name FROM bands AS b; + +SELECT DISTINCT(bname) FROM bands; + +SELECT * FROM bands; + +INSERT INTO bands VALUES (7, 'Madonna'); +INSERT INTO bands VALUES (8, 'Madonna'); + +SELECT b.bname, s.sname FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid; + +INSERT INTO bandstyles VALUES (8,5,2), (9,4,1), (10,3,2), (11,2,3), (12,1,4), (13,1,5), (14,1,6); + +SELECT m.mname, b.bname, s.sname FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid; + +SELECT s.sname, COUNT(b.bname) AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY s.sname; + +SELECT s.sname, COUNT(m.mname) AS musicians FROM (((musicians AS m FULL JOIN bandmembers AS bm ON m.mid = bm.mid) FULL JOIN bands AS b ON bm.bid = b.bid) FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY s.sname; + +SELECT s.sname, COUNT(DISTINCT(b.bname)) AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY s.sname; + +SELECT bname, sname FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid; + +SELECT sname, bname FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid ORDER BY bname; + +SELECT DISTINCT bname, sname AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid ORDER BY bname; + +SELECT DISTINCT sname, bname AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid ORDER BY bname; + +SELECT DISTINCT sname, COUNT(bname) AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY sname; + +SELECT sname, COUNT(bname) AS bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY sname; + +SELECT DISTINCT sname, bname FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid; + +SELECT sname, bname FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid; + +SELECT sname, COUNT(bname) as bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY sname; + +SELECT DISTINCT sname, COUNT(bname) as bands FROM (bands AS b FULL JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid GROUP BY sname; + + + + + + + + + + + + + + + + + + +/* generate more band members */ +https://play.golang.org/p/uv2g4Ap21Sl + +INSERT INTO bandmembers VALUES (9,2,3),(10,3,5),(11,2,4),(12,1,1),(13,2,1),(14,5,2),(15,3,5),(16,4,5),(17,2,1),(18,3,2),(19,1,2),(20,4,4),(21,3,3),(22,3,4),(23,1,1),(24,2,4),(25,3,2),(26,5,2),(27,3,2),(28,1,2),(29,4,1),(30,5,4),(31,4,3),(32,4,5),(33,5,4),(34,3,2),(35,5,5),(36,1,1),(37,4,4),(38,4,1),(39,2,1),(40,1,2); + + +SELECT bname, sname FROM (bands AS b LEFT JOIN bandstyles AS bs ON b.bid = bs.bid) FULL JOIN styles AS s ON bs.sid = s.sid; + +SELECT m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid; + +SELECT m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid GROUP BY m.mname, b.bname; + +SELECT m.mid, m.mname, b.bname FROM (musicians AS m LEFT JOIN bandmembers AS bm ON m.mid = bm.mid) LEFT JOIN bands AS b ON bm.bid = b.bid GROUP BY m.mid, m.mname, b.bname; + +/* does not work*/ +SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid; + +SELECT COUNT(*) AS total FROM musicians; + +/* does not work*/ +SELECT COUNT(*) AS total FROM musicians GROUP BY mname; + +SELECT mname, COUNT(*) AS total FROM musicians GROUP BY mname; + +SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname; + +SELECT b.bname, s.sname, COUNT(*) AS members FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname HAVING COUNT(*) > 10; + +SELECT b.bname, s.sname, COUNT(bm.bmid) AS bandmembers FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname; + +SELECT b.bname, s.sname, COUNT(bm.bmid) AS bandmembers FROM (((musicians AS m JOIN bandmembers AS bm ON m.mid = bm.mid) JOIN bands AS b ON bm.bid = b.bid) JOIN bandstyles AS bs ON b.bid = bs.bid) JOIN styles AS s ON bs.sid = s.sid GROUP BY b.bname, s.sname HAVING COUNT(*) > 10; + diff --git a/000_temp/71/assets/city.jpeg b/000_temp/71/assets/city.jpeg new file mode 100644 index 00000000..88934e1c Binary files /dev/null and b/000_temp/71/assets/city.jpeg differ diff --git a/000_temp/71/assets/main.css b/000_temp/71/assets/main.css new file mode 100644 index 00000000..fb78b132 --- /dev/null +++ b/000_temp/71/assets/main.css @@ -0,0 +1,38 @@ +html, body { + padding: 0; + border: 0; + margin: 0; + box-sizing: border-box; +} + +#atf { + height: 100vh; + background-color: cornflowerblue; + background-image: url("http://github.com/stuff/city.jpeg"); + background-repeat: no-repeat; + background-size: cover; + background-position: center; + display: flex; + justify-content: center; + align-items: center; + font-size: 13vw; + color: white; +} + +header { + position: fixed; + top: 0; + left: 0; + background-color: rgba(97, 115, 255, 0.44); + height: 5vh; + width: 100vw; + display: flex; + justify-content: space-between; + align-items: center; +} + +header > div { + font-size: 1.5rem; + color: white; + margin: 0 2rem; +} diff --git a/000_temp/71/assets/toby.jpg b/000_temp/71/assets/toby.jpg new file mode 100644 index 00000000..16fe5330 Binary files /dev/null and b/000_temp/71/assets/toby.jpg differ diff --git a/000_temp/71/main.go b/000_temp/71/main.go new file mode 100644 index 00000000..dc7e34b2 --- /dev/null +++ b/000_temp/71/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "html/template" + "net/http" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + http.HandleFunc("/", hom) + http.HandleFunc("/about", abo) + http.Handle("/stuff/", http.StripPrefix("/stuff", http.FileServer(http.Dir("./assets/")))) + http.ListenAndServe(":8080", nil) +} + +func hom(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "default.gohtml", nil) +} + +func abo(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "about.gohtml", nil) +} \ No newline at end of file diff --git a/000_temp/71/templates/about.gohtml b/000_temp/71/templates/about.gohtml new file mode 100644 index 00000000..510b8af5 --- /dev/null +++ b/000_temp/71/templates/about.gohtml @@ -0,0 +1,19 @@ + + + + + + + Legal Firm ABOUT Page + + + +

ABOUT

+ +HOME +ABOUT + + + + \ No newline at end of file diff --git a/000_temp/71/templates/default.gohtml b/000_temp/71/templates/default.gohtml new file mode 100644 index 00000000..9298761c --- /dev/null +++ b/000_temp/71/templates/default.gohtml @@ -0,0 +1,33 @@ + + + + + + + Legal Firm Home Page + + + + +
+
left
+
right
+
+ +
+ +CHICAGO + +
+ +

HOME

+ +HOME +ABOUT + + + + + + \ No newline at end of file diff --git a/000_temp/72/assets/toby.jpg b/000_temp/72/assets/toby.jpg new file mode 100644 index 00000000..16fe5330 Binary files /dev/null and b/000_temp/72/assets/toby.jpg differ diff --git a/000_temp/72/main.go b/000_temp/72/main.go new file mode 100644 index 00000000..b3795881 --- /dev/null +++ b/000_temp/72/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "html/template" + "net/http" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + http.HandleFunc("/", foo) + http.HandleFunc("/about", bar) + http.Handle("/resources/", http.StripPrefix("/resources", http.FileServer(http.Dir("./assets")))) + http.ListenAndServe(":8080", nil) +} + +func foo(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "index.gohtml", nil) +} + +func bar(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "about.gohtml", nil) +} diff --git a/000_temp/72/templates/about.gohtml b/000_temp/72/templates/about.gohtml new file mode 100644 index 00000000..58bd92b0 --- /dev/null +++ b/000_temp/72/templates/about.gohtml @@ -0,0 +1,18 @@ + + + + + + + ABOUT + + + +

ABOUT

+ +HOME +ABOUT + + + \ No newline at end of file diff --git a/000_temp/72/templates/index.gohtml b/000_temp/72/templates/index.gohtml new file mode 100644 index 00000000..d0c02408 --- /dev/null +++ b/000_temp/72/templates/index.gohtml @@ -0,0 +1,20 @@ + + + + + + + HOME + + + +

HOME

+ +HOME +ABOUT + + + + + \ No newline at end of file diff --git a/000_temp/73/01/main.go b/000_temp/73/01/main.go new file mode 100644 index 00000000..8fd45780 --- /dev/null +++ b/000_temp/73/01/main.go @@ -0,0 +1,27 @@ +package main + +import "fmt" + + +// a VALUE of TYPE + +var x int +var s string +var b bool +var i float64 + +func main() { + x = 42 + s = "James" + b = true + i = 42.123 + fmt.Println(x, s, b, i) + + f := 43 + g := "Bond" + h := false + j := 43.342 + fmt.Println(f, g, h, j) + + fmt.Printf("%T\t %T\t %T\t %T\t \n", f, g, h, j) +} \ No newline at end of file diff --git a/000_temp/73/02/main.go b/000_temp/73/02/main.go new file mode 100644 index 00000000..f6b872e7 --- /dev/null +++ b/000_temp/73/02/main.go @@ -0,0 +1,28 @@ +package main + +import "fmt" + +// AGGREGATE or COMPOSITE +func main() { + xi := []int{4,5,6,7,42} + + fmt.Println(xi) + + for p, v := range xi { + fmt.Println(p, v) + } + + // FOR declaration; condition; post {} + n := 42 + for { + fmt.Println(n) + n++ + if n == 1000 { + break + } + } + + for i := 1000; i <= 2000; i++ { + fmt.Println(i) + } +} diff --git a/000_temp/73/03/main.go b/000_temp/73/03/main.go new file mode 100644 index 00000000..8b568604 --- /dev/null +++ b/000_temp/73/03/main.go @@ -0,0 +1,13 @@ +package main + +import "fmt" + +type hotdog int + +var hd hotdog + +func main() { + hd = 42 + fmt.Println(hd) + fmt.Printf("%T\n", hd) +} diff --git a/000_temp/73/04/main.go b/000_temp/73/04/main.go new file mode 100644 index 00000000..6b2ef70d --- /dev/null +++ b/000_temp/73/04/main.go @@ -0,0 +1,31 @@ +package main + +import "fmt" + +type person struct { + first string + age int +} + +type secretAgent struct { + person + ltk bool +} + +func main() { + p := person{ + first: "Miss Moneypenny", + age: 27, + } + + sa := secretAgent { + person: person { + first: "James", + age: 32, + }, + ltk: true, + } + + fmt.Println(p) + fmt.Println(sa) +} \ No newline at end of file diff --git a/000_temp/73/05/main.go b/000_temp/73/05/main.go new file mode 100644 index 00000000..fba21fb7 --- /dev/null +++ b/000_temp/73/05/main.go @@ -0,0 +1,19 @@ +package main + +import "fmt" + +func main() { + x := 42 + fmt.Println("x", x) + fmt.Println(&x) + + y := &x + + fmt.Printf("%v\t %T\n", x, x) + fmt.Printf("%v\t %T\n", y, y) + fmt.Println(*y) + + *y = 100 + fmt.Println("y", *y) + fmt.Println("x", x) +} diff --git a/000_temp/73/06/main.go b/000_temp/73/06/main.go new file mode 100644 index 00000000..fb9b32f5 --- /dev/null +++ b/000_temp/73/06/main.go @@ -0,0 +1,26 @@ +package main + +import "fmt" + +func main() { + a := 42 + fmt.Println("a", a) + + foo(a) + fmt.Println("a after foo", a) + + bar(&a) + fmt.Println("a after bar", a) +} + + +func foo(b int) { + b = 43 + fmt.Println("b", b) +} + +func bar(c *int) { + *c = 44 + fmt.Println("c", c) + fmt.Println("*c", *c) +} \ No newline at end of file diff --git a/000_temp/74/index.html b/000_temp/74/index.html new file mode 100644 index 00000000..bae7e1cd --- /dev/null +++ b/000_temp/74/index.html @@ -0,0 +1,43 @@ + + + + + + Document + + + + +

HELLO WORLD

+ +

Lorem ipsum dolor sit amet, consectetur adipisicing elit. A atque autem, consectetur deleniti dolor expedita fugiat + fugit harum illum iste itaque maiores maxime non obcaecati omnis quam ratione recusandae suscipit.

+ + + + + + + + + \ No newline at end of file diff --git a/000_temp/75/main.go b/000_temp/75/main.go new file mode 100644 index 00000000..d2803717 --- /dev/null +++ b/000_temp/75/main.go @@ -0,0 +1,76 @@ +package main + +import ( + "html/template" + "net/http" +) + +const s = ` + + + + + + CONTACT 4 + + + +

YOU ARE AT CONTACT 4

+ +HOME +ABOUT +CONTACT 2 +CONTACT 3 +CONTACT 4 + + + + +` + +var tpl *template.Template +var tpl2 *template.Template +var tpl3 *template.Template +var tpl4 *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) + + tpl2 = template.Must(template.New("pale").ParseFiles("templates/contact.gohtml")) + + tpl3 = template.Must(template.ParseFiles("templates/contact.gohtml")) + + tpl4 = template.Must(template.New("pale").Parse(s)) +} + +func main() { + http.HandleFunc("/", foo) + http.HandleFunc("/about", bar) + http.HandleFunc("/contact/2", con2) + http.HandleFunc("/contact/3", con3) + http.HandleFunc("/contact/4", con4) + http.ListenAndServe(":8080", nil) +} + +func foo(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "index.gohtml", nil) +} + +func bar(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "about.gohtml", nil) +} + +func con2(w http.ResponseWriter, r *http.Request) { + tpl2.ExecuteTemplate(w, "contact.gohtml", nil) +} + + +func con3(w http.ResponseWriter, r *http.Request) { + tpl3.ExecuteTemplate(w, "contact.gohtml", nil) +} + + +func con4(w http.ResponseWriter, r *http.Request) { + tpl4.ExecuteTemplate(w, "pale", nil) +} diff --git a/000_temp/75/templates/about.gohtml b/000_temp/75/templates/about.gohtml new file mode 100644 index 00000000..859035fb --- /dev/null +++ b/000_temp/75/templates/about.gohtml @@ -0,0 +1,23 @@ + + + + + + + ABOUT + + + +

YOU ARE AT ABOUT

+ +HOME +ABOUT +CONTACT 2 +CONTACT 3 +CONTACT 4 + + + + + \ No newline at end of file diff --git a/000_temp/75/templates/contact.gohtml b/000_temp/75/templates/contact.gohtml new file mode 100644 index 00000000..36b38bf8 --- /dev/null +++ b/000_temp/75/templates/contact.gohtml @@ -0,0 +1,21 @@ + + + + + + + HOME + + + +

YOU ARE AT CONTACT

+ +HOME +ABOUT +CONTACT 2 +CONTACT 3 +CONTACT 4 + + + \ No newline at end of file diff --git a/000_temp/75/templates/index.gohtml b/000_temp/75/templates/index.gohtml new file mode 100644 index 00000000..b916743e --- /dev/null +++ b/000_temp/75/templates/index.gohtml @@ -0,0 +1,22 @@ + + + + + + + HOME + + + +

YOU ARE AT HOME

+ +HOME +ABOUT +CONTACT 2 +CONTACT 3 +CONTACT 4 + + + + \ No newline at end of file diff --git a/000_temp/76 sql/sales.sql b/000_temp/76 sql/sales.sql new file mode 100644 index 00000000..18ada146 --- /dev/null +++ b/000_temp/76 sql/sales.sql @@ -0,0 +1,54 @@ +CREATE DATABASE sales; + +\l + +\c sales + +CREATE TABLE employees (eid INT PRIMARY KEY NOT NULL, ename TEXT NOT NULL); + +CREATE TABLE states (stid INT PRIMARY KEY NOT NULL, stname TEXT NOT NULL); + +CREATE TABLE cities (cid INT PRIMARY KEY NOT NULL, cname TEXT NOT NULL); + +CREATE TABLE sales (sid INT PRIMARY KEY NOT NULL, eid INT REFERENCES employees(eid) NOT NULL, cid INT REFERENCES cities(cid) NOT NULL, stid INT REFERENCES states(stid) NOT NULL, samount INT NOT NULL); + +INSERT INTO employees VALUES (1,'James'), (2,'Moneypenny'), (3,'Ian'), (4,'Fleming'), (5,'Bond'); + +INSERT INTO states VALUES (1,'AL'), (2,'AK'), (3,'AZ'), (4,'AR'), (5,'CA'); + +INSERT INTO cities VALUES (1,'Montgomery'), (2,'Anchorage'), (3,'Phoenix'), (4,'Little Rock'), (5,'Sacramento'), (6,'Fresno'), (7,'Benicia'), (8,'San Fran'), (9,'LA'), (10,'San Diego'); + +https://play.golang.org/p/knG5I2AAi79 + +INSERT INTO sales VALUES (1,3,2,2,1948), (2,2,10,5,1419), (3,1,6,5,557), (4,5,1,1,3612), (5,5,3,3,4829), (6,2,5,5,1546), (7,2,8,5,596), (8,4,7,5,1359), (9,3,8,5,3388), (10,1,9,5,3116), (11,4,2,2,2488), (12,5,2,2,457), (13,2,8,5,1586), (14,4,7,5,3191), (15,4,5,5,2534), (16,4,8,5,4425), (17,4,10,5,2058), (18,5,2,2,2300), (19,1,1,1,2989), (20,4,9,5,4456), (21,1,2,2,2706), (22,2,7,5,4929), (23,3,2,2,4884), (24,4,7,5,4477), (25,4,3,3,548), (26,3,5,5,2564), (27,1,7,5,3724), (28,3,4,4,3234), (29,5,2,2,3134), (30,2,4,4,2103), (31,2,9,5,2647), (32,1,8,5,1604), (33,4,3,3,2306), (34,1,9,5,1452), (35,3,6,5,3788), (36,1,1,1,386), (37,3,1,1,3199), (38,2,4,4,3683), (39,3,5,5,4368), (40,2,8,5,995), (41,3,7,5,4082), (42,2,10,5,1371), (43,2,4,4,4920), (44,3,2,2,2276), (45,1,6,5,1488), (46,4,10,5,2919), (47,4,5,5,1325), (48,3,8,5,1633), (49,5,7,5,641), (50,2,7,5,3177), (51,2,1,1,3945), (52,1,5,5,4284), (53,1,2,2,1703), (54,3,9,5,3332), (55,5,9,5,2923), (56,3,4,4,4309), (57,4,4,4,1267), (58,1,1,1,541), (59,3,5,5,4758), (60,2,6,5,3140), (61,4,1,1,4801), (62,1,10,5,884), (63,5,1,1,3348), (64,1,1,1,4263), (65,1,10,5,2149), (66,1,7,5,3767), (67,2,1,1,1730), (68,2,3,3,2678), (69,1,7,5,500), (70,3,3,3,393), (71,2,9,5,4204), (72,4,9,5,3857), (73,3,10,5,1258), (74,1,3,3,2282), (75,1,4,4,518), (76,1,4,4,4097), (77,3,7,5,2621), (78,3,1,1,2130), (79,1,2,2,2521), (80,5,10,5,1565), (81,2,1,1,1282), (82,2,8,5,701), (83,3,10,5,1634), (84,5,2,2,1786), (85,1,10,5,1820), (86,1,5,5,3763), (87,1,1,1,4385), (88,1,4,4,1544), (89,1,2,2,675), (90,1,10,5,1437), (91,3,9,5,1645), (92,5,6,5,1338), (93,4,5,5,1707), (94,3,9,5,2521), (95,2,3,3,1218), (96,1,2,2,3783), (97,3,10,5,230), (98,2,2,2,956), (99,4,2,2,1154), (100,5,7,5,4968); + +SELECT e.ename, c.cname, st.stname, s.samount FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid; + + + +SELECT e.ename, c.cname, st.stname, s.samount FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid WHERE e.eid = 1; + + +// does not work +SELECT e.ename, c.cname, st.stname, s.samount FROM (((employees AS e WHERE e.eid = 1) JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid; + +// works +SELECT e.ename FROM employees AS e WHERE e.eid = 1; + +SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid GROUP BY e.ename, c.cname, st.stname; + +SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid WHERE e.eid = 1 GROUP BY e.ename, c.cname, st.stname; + +SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid GROUP BY e.ename, c.cname, st.stname ORDER BY e.ename; + +SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid WHERE e.eid = 1 GROUP BY e.ename, c.cname, st.stname HAVING st.stname = 'CA'; + +SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid WHERE e.eid = 1 AND st.stname = 'CA' GROUP BY e.ename, c.cname, st.stname; + + +SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid GROUP BY e.ename, c.cname, st.stname HAVING e.ename = 'James' AND st.stname = 'CA'; + +// does not work +SELECT e.ename, c.cname, st.stname, SUM(s.samount) FROM ((employees AS e JOIN sales AS s ON e.eid = s.eid) JOIN cities AS c ON s.cid = c.cid) JOIN states AS st ON s.stid = st.stid GROUP BY e.ename, c.cname, st.stname HAVING e.eid = 1 AND st.stname = 'CA'; + + diff --git a/000_temp/77-web-server/assets/toby.jpg b/000_temp/77-web-server/assets/toby.jpg new file mode 100644 index 00000000..16fe5330 Binary files /dev/null and b/000_temp/77-web-server/assets/toby.jpg differ diff --git a/000_temp/77-web-server/main.go b/000_temp/77-web-server/main.go new file mode 100644 index 00000000..be55885b --- /dev/null +++ b/000_temp/77-web-server/main.go @@ -0,0 +1,50 @@ +package main + +import ( + "html/template" + "net/http" +) + +var tpl *template.Template +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + http.HandleFunc("/", foo) + http.HandleFunc("/about", bar ) + http.HandleFunc("/contact", con) + http.Handle("/resources/", http.StripPrefix("/resources", http.FileServer(http.Dir("./assets")))) + http.ListenAndServe(":8080", nil) +} + +func foo(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "index.gohtml", 42) +} + +func bar(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "about.gohtml", []int{1,2,3,4,5,6,7,8,9}) +} + +func con(w http.ResponseWriter, r *http.Request) { + + type person struct { + First string + Age int + } + + p1 := person{ + First: "James", + Age: 32, + } + + p2 := person { + First: "Jenny", + Age: 27, + } + + xp := []person{p1, p2} + + + tpl.ExecuteTemplate(w, "contact.gohtml", xp) +} diff --git a/000_temp/77-web-server/templates/about.gohtml b/000_temp/77-web-server/templates/about.gohtml new file mode 100644 index 00000000..57cc8dc7 --- /dev/null +++ b/000_temp/77-web-server/templates/about.gohtml @@ -0,0 +1,25 @@ + + + + + + + ABOUT + + + +

ABOUT

+ +HOME +ABOUT +CONTACT + +
+ +{{if .}} +{{.}} +{{end}} + + + \ No newline at end of file diff --git a/000_temp/77-web-server/templates/contact.gohtml b/000_temp/77-web-server/templates/contact.gohtml new file mode 100644 index 00000000..e83f1890 --- /dev/null +++ b/000_temp/77-web-server/templates/contact.gohtml @@ -0,0 +1,33 @@ + + + + + + + CONTACT + + + +

CONTACT

+ +HOME +ABOUT +CONTACT + +
+ +{{if .}} +{{.}} + +{{range .}} +

First: {{.First}}

+

Age: {{.Age}}

+{{end}} +{{end}} + + + + + + \ No newline at end of file diff --git a/000_temp/77-web-server/templates/index.gohtml b/000_temp/77-web-server/templates/index.gohtml new file mode 100644 index 00000000..1aa33933 --- /dev/null +++ b/000_temp/77-web-server/templates/index.gohtml @@ -0,0 +1,25 @@ + + + + + + + HOME + + + +

HOME

+ +HOME +ABOUT +CONTACT + +
+ +{{if .}} +{{.}} +{{end}} + + + \ No newline at end of file diff --git a/000_temp/78/assets/toby.jpg b/000_temp/78/assets/toby.jpg new file mode 100644 index 00000000..16fe5330 Binary files /dev/null and b/000_temp/78/assets/toby.jpg differ diff --git a/000_temp/78/main.go b/000_temp/78/main.go new file mode 100644 index 00000000..70a2a72d --- /dev/null +++ b/000_temp/78/main.go @@ -0,0 +1,57 @@ +package main + +import ( + "net/http" + "fmt" + "html/template" + "os" + "io" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + + +func main() { + http.HandleFunc("/", foo) + http.Handle("/resources/", http.StripPrefix("/resources", http.FileServer(http.Dir("./assets")))) + http.ListenAndServe(":8080", nil) +} + +func foo(w http.ResponseWriter, r *http.Request) { + fmt.Println("Method", r.Method) + + fn := "" + + if r.Method == http.MethodPost { + // open + f, h, err := r.FormFile("q") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + defer f.Close() + + fn = h.Filename + + df, err := os.Create("./assets/"+fn) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + defer df.Close() + + _, err = io.Copy(df, f) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + } + + // w.Header().Set("Content-Type", "text/html; charset=utf-8") + + tpl.ExecuteTemplate(w, "index.gohtml", fn) +} diff --git a/000_temp/78/templates/index.gohtml b/000_temp/78/templates/index.gohtml new file mode 100644 index 00000000..28ab32a4 --- /dev/null +++ b/000_temp/78/templates/index.gohtml @@ -0,0 +1,24 @@ + + + + + + + Document + + + +
+ + +
+
+ +{{if .}} +file name: {{.}} + +{{end}} + + + \ No newline at end of file diff --git a/000_temp/79/main.go b/000_temp/79/main.go new file mode 100644 index 00000000..c35ff2ea --- /dev/null +++ b/000_temp/79/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "fmt" + "html/template" + "net/http" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*")) +} + +func main() { + http.HandleFunc("/", foo) + http.HandleFunc("/bar", bar) + http.HandleFunc("/barred", barred) + http.Handle("/favicon.ico", http.NotFoundHandler()) + http.ListenAndServe(":8080", nil) +} + +func foo(w http.ResponseWriter, req *http.Request) { + + var s string + + if req.Method == http.MethodPost { + s = req.FormValue("fname") + } + + fmt.Print("Your request method at foo: ", req.Method, "\n") + fmt.Print("Your FORM VALUE at foo: ", s, "\n\n") +} + +func bar(w http.ResponseWriter, req *http.Request) { + fmt.Println("Your request method at bar:", req.Method) + // process form submission here + http.Redirect(w, req, "/", http.StatusSeeOther) +} + +func barred(w http.ResponseWriter, req *http.Request) { + fmt.Println("Your request method at barred:", req.Method) + tpl.ExecuteTemplate(w, "index.gohtml", nil) +} diff --git a/000_temp/79/templates/index.gohtml b/000_temp/79/templates/index.gohtml new file mode 100644 index 00000000..54c0bbc5 --- /dev/null +++ b/000_temp/79/templates/index.gohtml @@ -0,0 +1,15 @@ + + + + + Title + + + +
+ + +
+ + + \ No newline at end of file diff --git a/000_temp/80-renamer/80-renamer.txt b/000_temp/80-renamer/80-renamer.txt new file mode 100755 index 00000000..9ed28e74 Binary files /dev/null and b/000_temp/80-renamer/80-renamer.txt differ diff --git a/000_temp/80-renamer/main.go b/000_temp/80-renamer/main.go new file mode 100644 index 00000000..513f5ff5 --- /dev/null +++ b/000_temp/80-renamer/main.go @@ -0,0 +1,27 @@ +package main + +import ( + "fmt" + "io/ioutil" + "os" + "strconv" +) + +func main() { + + dir := "results/" + files, _ := ioutil.ReadDir(dir) + + for i, f := range files { + fmt.Println(f.Name()) + oldfile := (dir + f.Name()) + newfile := (dir + strconv.Itoa(i) + ".txt") + fmt.Println(oldfile, "named it to", newfile, "\n") + + err := os.Rename(oldfile, newfile) + if err != nil { + fmt.Println(err) + return + } + } +} \ No newline at end of file diff --git a/000_temp/80-renamer/results/0.txt b/000_temp/80-renamer/results/0.txt new file mode 100644 index 00000000..e69de29b diff --git a/000_temp/80-renamer/results/1.txt b/000_temp/80-renamer/results/1.txt new file mode 100644 index 00000000..e69de29b diff --git a/000_temp/81-cookie-counter/main.go b/000_temp/81-cookie-counter/main.go new file mode 100644 index 00000000..e223f3cf --- /dev/null +++ b/000_temp/81-cookie-counter/main.go @@ -0,0 +1,66 @@ +package main + +import ( + "net/http" + "html/template" + "strconv" + "fmt" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + http.HandleFunc("/", foo) + http.HandleFunc("/bar", bar) + http.ListenAndServe(":8080", nil) +} + +func foo(w http.ResponseWriter, r *http.Request) { + c, err := cookieCounter(r) + if err != nil { + http.Error(w, "bad request", http.StatusBadRequest) + return + } + http.SetCookie(w, c) + + tpl.ExecuteTemplate(w, "index.gohtml", c.Value) +} + + +func bar(w http.ResponseWriter, r *http.Request) { + c, err := cookieCounter(r) + if err != nil { + fmt.Println(err) + http.Error(w, "bad request", http.StatusBadRequest) + return + } + http.SetCookie(w, c) + + tpl.ExecuteTemplate(w, "about.gohtml", c.Value) +} + +func cookieCounter(r *http.Request) (*http.Cookie, error) { + var c *http.Cookie + + c, err := r.Cookie("wackadoodle") + if err != nil { + c = &http.Cookie{ + Name: "wackadoodle", + Value: "0", + Path: "/", + } + } + + i, err := strconv.Atoi(c.Value) + if err != nil { + return c, err + } + i++ + c.Value = strconv.Itoa(i) + + return c, nil +} diff --git a/000_temp/81-cookie-counter/templates/about.gohtml b/000_temp/81-cookie-counter/templates/about.gohtml new file mode 100644 index 00000000..d1fc872f --- /dev/null +++ b/000_temp/81-cookie-counter/templates/about.gohtml @@ -0,0 +1,16 @@ + + + + + + + ABOUT + + + +

about

+VALUE OF COOKIE {{.}} + + + \ No newline at end of file diff --git a/000_temp/81-cookie-counter/templates/index.gohtml b/000_temp/81-cookie-counter/templates/index.gohtml new file mode 100644 index 00000000..9302b5ee --- /dev/null +++ b/000_temp/81-cookie-counter/templates/index.gohtml @@ -0,0 +1,16 @@ + + + + + + + Document + + + +

home

+VALUE OF COOKIE {{.}} + + + \ No newline at end of file diff --git a/000_temp/82/main.go b/000_temp/82/main.go new file mode 100644 index 00000000..180f8828 --- /dev/null +++ b/000_temp/82/main.go @@ -0,0 +1,10 @@ +package main + +import "fmt" + +func main() { + var x uint + x = 18446744073709551615 + fmt.Println(x) + fmt.Printf("%T\n\n",x) +} diff --git a/000_temp/83_select/README.md b/000_temp/83_select/README.md new file mode 100644 index 00000000..5af6f981 --- /dev/null +++ b/000_temp/83_select/README.md @@ -0,0 +1,130 @@ +# our pathway + +We will be following the example created in [this article by Alex Edwards](http://www.alexedwards.net/blog/practical-persistence-sql) and licensed under a [MIT license](https://opensource.org/licenses/MIT) + +In order to successfully pull records from a table in a database as our user ```bond```, we will need to [ALTER](https://www.postgresql.org/docs/9.6/static/sql-alteruser.html) bond to have a different role. + +# alter bond's role +``` +alter user bond with superuser; +``` + +# switch to your bookstore database +You should already have a ```bookstore``` database: + +list databases +``` +\l +``` + +switch into that database +``` +\c bookstore +``` + +directory of tables, if any +``` +\d +``` + +# create table +``` +CREATE TABLE books ( + isbn char(14) PRIMARY KEY NOT NULL, + title varchar(255) NOT NULL, + author varchar(255) NOT NULL, + price decimal(5,2) NOT NULL +); +``` + +directory of tables +``` +\d +``` + +details of table ```books``` +``` +\d books +``` + +# insert records +``` +INSERT INTO books (isbn, title, author, price) VALUES +('978-1503261969', 'Emma', 'Jayne Austen', 9.44), +('978-1505255607', 'The Time Machine', 'H. G. Wells', 5.99), +('978-1503379640', 'The Prince', 'Niccolò Machiavelli', 6.99); +``` + +view records +``` +SELECT * FROM books; +``` + +# main.go + +## importing the driver +make sure you import the driver +``` +_ "github.com/lib/pq" +``` +"We don't use anything in the pq package directly, which means that the Go compiler will raise an error if we try to import it normally. But **we need the pq package's init() function to run so that our driver can register itself with database/sql.** We get around this by aliasing the package name to the blank identifier. This means pq.init() still gets executed, but the alias is harmlessly discarded (and our code runs error-free). This approach is standard for most of Go's SQL drivers." - Alex Edwards + +## define a book type struct +``` +type Book struct { + isbn string + title string + author string + price float32 +} +``` +"Next we define a Book type. **The struct fields and their types must align to our books table.** For completeness I should point out that we've only been able to use the string and float32 types safely because we set NOT NULL constraints on the columns in our table. If the table contained nullable fields we would need to use the sql.NullString and sql.NullFloat64 types instead – see [this Gist](https://gist.github.com/alexedwards/dc3145c8e2e6d2fd6cd9) for a working example. Generally it's easiest to avoid nullable fields altogether if you can, which is what we've done here." - Alex Edwards + +## initialize a new sql.DB +``` +db, err := sql.Open("postgres", "postgres://bond:password@localhost/bookstore?sslmode=disable") + if err != nil { + panic(err) + } + defer db.Close() +``` +"In the main() function we initialise a new sql.DB by calling sql.Open(). We pass in the name of our driver (in this case "postgres") and the connection string (you'll need to check your driver documentation for the correct format). It's worth emphasizing that **sql.DB is not a database connection – it's an abstraction representing a pool of underlying connections.** You can change the maximum number of open and idle connections in the pool with the db.SetMaxOpenConns() and db.SetMaxIdleConns() methods respectively. A final thing to note is that **sql.DB is safe for concurrent access,** which is very convenient if you're using it in a web application (like we will shortly)." - Alex Edwards + +## ping the db +``` + if err = db.Ping(); err != nil { + panic(err) + } +``` +"Because sql.Open() doesn't actually check a connection, we also call DB.Ping() to make sure that everything works OK on startup." - Alex Edwards + +## query the db +``` +rows, err := db.Query("SELECT * FROM books") + if err != nil { + panic(err) + } + defer rows.Close() +``` +"We will fetch a resultset from the books table using the DB.Query() method and assign it to a rows variable. Then we defer rows.Close() to ensure the resultset is properly closed before the parent function returns. **Closing a resultset properly is really important. As long as a resultset is open it will keep the underlying database connection open – which in turn means the connection is not available to the pool.** So if something goes wrong and the resultset isn't closed it can rapidly lead to all the connections in your pool being used up. Another gotcha (which caught me out when I first began) is that the defer statement should come after you check for an error from DB.Query. Otherwise, if DB.Query() returns an error, you'll get a panic trying to close a nil resultset." - Alex Edwards + +## iterate through results +``` + for rows.Next() { + bk := Book{} + err := rows.Scan(&bk.isbn, &bk.title, &bk.author, &bk.price) // order matters + if err != nil { + panic(err) + } + bks = append(bks, bk) + } +``` +"We then use rows.Next() to iterate through the rows in the resultset. This preps the first (and then each subsequent) row to be acted on by the rows.Scan() method. Note that if iteration over all of the rows completes then the resultset automatically closes itself and frees-up the connection. We use the rows.Scan() method to copy the values from each field in the row to a new Book object that we created. We then check for any errors that occurred during Scan, and add the new Book to a slice of books." - Alex Edwards + +## make sure everything ran well +``` + if err = rows.Err(); err != nil { + panic(err) + } +``` +"When our rows.Next() loop has finished we call rows.Err(). This returns any error that was encountered during the interation. It's important to call this – don't just assume that we completed a successful iteration over the whole resultset." - Alex Edwards Err returns the error, if any, that was encountered during iteration. Err may be called after an explicit or implicit Close. \ No newline at end of file diff --git a/000_temp/83_select/main.go b/000_temp/83_select/main.go new file mode 100644 index 00000000..0d5a29fb --- /dev/null +++ b/000_temp/83_select/main.go @@ -0,0 +1,26 @@ +package main + +import ( + "database/sql" + "fmt" + _ "github.com/lib/pq" +) + +func main() { + + connstr := "host=localhost port=5432 dbname=bookstore user=bond password=password sslmode=disable" + + // "postgres://bond:password@localhost/bookstore?sslmode=disable" + + db, err := sql.Open("postgres", connstr) + if err != nil { + panic(err) + } + defer db.Close() + + err = db.Ping() + if err != nil { + panic(err) + } + fmt.Println("You connected to your database.") +} diff --git a/000_temp/84-pg-query/main.go b/000_temp/84-pg-query/main.go new file mode 100644 index 00000000..ca56408b --- /dev/null +++ b/000_temp/84-pg-query/main.go @@ -0,0 +1,48 @@ +package main + +import ( + "database/sql" + "fmt" + _ "github.com/lib/pq" +) + +type Book struct { + ISBN string + Title string + Author string + Price float32 +} + +func main() { + connStrn := "host=localhost port=5432 dbname=bookstore user=bond password=password sslmode=disable" + + db, err := sql.Open("postgres", connStrn) + if err != nil { + panic(err) + } + defer db.Close() + + err = db.Ping() + if err != nil { + panic(err) + } + + fmt.Println("Connected to database") + + rs, err := db.Query("select * from books;") + + xb := make([]Book, 0) + for rs.Next() { + b := Book{} + rs.Scan(&b.ISBN, &b.Title, &b.Author, &b.Price) + xb = append(xb, b) + + if err = rs.Err(); err != nil { + panic(err) + } + } + + for i, v := range xb { + fmt.Println(i, v) + } +} \ No newline at end of file diff --git a/000_temp/85-pg-query-web/main.go b/000_temp/85-pg-query-web/main.go new file mode 100644 index 00000000..4711d308 --- /dev/null +++ b/000_temp/85-pg-query-web/main.go @@ -0,0 +1,87 @@ +package main + +import ( + "database/sql" + "fmt" + _ "github.com/lib/pq" + "html/template" + "net/http" +) + +var tpl *template.Template +var db *sql.DB + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) + + connStrn := "host=localhost port=5432 dbname=bookstore user=bond password=password sslmode=disable" + + db, err := sql.Open("postgres", connStrn) + if err != nil { + panic(err) + } + defer db.Close() + + err = db.Ping() + if err != nil { + panic(err) + } + + fmt.Println("Connected to database") +} + +type Book struct { + Isbn string + Title string + Author string + Price float32 +} + +func main() { + http.HandleFunc("/", foo) + http.ListenAndServe(":8080", nil) +} + +func foo(w http.ResponseWriter, r *http.Request) { + rs, err := db.Query("select * from books;") + + xb := make([]Book, 0) + for rs.Next() { + b := Book{} + rs.Scan(&b.Isbn, &b.Title, &b.Author, &b.Price) + xb = append(xb, b) + + if err = rs.Err(); err != nil { + panic(err) + } + } + tpl.ExecuteTemplate(w, "books.gohtml", xb) +} + + + +//rs, err := db.Query("select * from books;") +//if err != nil { +// http.Error(w, http.StatusText(500), 500) +// return +//} +//defer rs.Close() +// +//xb := make([]Book, 0) +//for rs.Next() { +// b := Book{} +// err := rs.Scan(&b.ISBN, &b.Title, &b.Author, &b.Price) +// if err != nil { +// http.Error(w, http.StatusText(500), 500) +// return +// +// } +// xb = append(xb, b) +// +// if err = rs.Err(); err != nil { +// http.Error(w, http.StatusText(500), 500) +// return +// } +//} +// +//tpl.ExecuteTemplate(w, "index.gohtml", xb) diff --git a/000_temp/85-pg-query-web/templates/index.gohtml b/000_temp/85-pg-query-web/templates/index.gohtml new file mode 100644 index 00000000..d6173f62 --- /dev/null +++ b/000_temp/85-pg-query-web/templates/index.gohtml @@ -0,0 +1,17 @@ + + + + + + + Document + + + +{{range .}} +{{.Isbn}} - {{.Title}} - {{.Author}} - {{.Price}} +{{end}} + + + \ No newline at end of file diff --git a/000_temp/86-website/main.go b/000_temp/86-website/main.go new file mode 100644 index 00000000..94b9f53e --- /dev/null +++ b/000_temp/86-website/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "html/template" + "net/http" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + http.HandleFunc("/", index) + http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("./resources")))) + http.ListenAndServe(":8080", nil) +} + +func index(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "index.gohtml", nil) +} diff --git a/000_temp/86-website/resources/css/main.css b/000_temp/86-website/resources/css/main.css new file mode 100644 index 00000000..9960c767 --- /dev/null +++ b/000_temp/86-website/resources/css/main.css @@ -0,0 +1,23 @@ +html, body, h1 { + padding: 0; + border: 0; + margin: 0; +} + +h1 { + color: red; + font-size: 10rem; +} + +#atf { + height: 100vh; + background-image: url("http://github.com/assets/img/skyf.jpeg"); + background-position: center; + background-size: cover; + background-repeat: no-repeat; + display: flex; + flex-direction: row; + flex-wrap: nowrap; + justify-content: flex-end; + align-items: center; +} \ No newline at end of file diff --git a/000_temp/86-website/resources/img/skyf.jpeg b/000_temp/86-website/resources/img/skyf.jpeg new file mode 100644 index 00000000..620c76d5 Binary files /dev/null and b/000_temp/86-website/resources/img/skyf.jpeg differ diff --git a/000_temp/86-website/resources/img/toby.jpg b/000_temp/86-website/resources/img/toby.jpg new file mode 100644 index 00000000..16fe5330 Binary files /dev/null and b/000_temp/86-website/resources/img/toby.jpg differ diff --git a/000_temp/86-website/templates/index.gohtml b/000_temp/86-website/templates/index.gohtml new file mode 100644 index 00000000..975e7247 --- /dev/null +++ b/000_temp/86-website/templates/index.gohtml @@ -0,0 +1,21 @@ + + + + + + + Document + + + + + +
+

SKYFALL

+
+ + + + + \ No newline at end of file diff --git a/000_temp/87-website/main.go b/000_temp/87-website/main.go new file mode 100644 index 00000000..337f4776 --- /dev/null +++ b/000_temp/87-website/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "html/template" + "net/http" +) + +var tpl *template.Template + +func init() { + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) +} + +func main() { + http.HandleFunc("/", idx) + http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("./served")))) + http.ListenAndServe(":80", nil) +} + +func idx(w http.ResponseWriter, r *http.Request) { + tpl.ExecuteTemplate(w, "index.gohtml", nil) +} diff --git a/000_temp/87-website/served/css/main.css b/000_temp/87-website/served/css/main.css new file mode 100644 index 00000000..68ba7fe4 --- /dev/null +++ b/000_temp/87-website/served/css/main.css @@ -0,0 +1,24 @@ +html, body, div, h1 { + padding: 0; + border: 0; + margin: 0; + box-sizing: border-box; +} + +#atf { + height: 100vh; + background-image: url("http://github.com/assets/img/skyf.jpeg"); + background-repeat: no-repeat; + background-size: cover; + background-position: center; + display: flex; + flex-direction: row; + flex-wrap: nowrap; + justify-content: flex-end; + align-items: center; +} + +h1 { + color: red; + font-size: 10rem; +} \ No newline at end of file diff --git a/000_temp/87-website/served/img/skyf.jpeg b/000_temp/87-website/served/img/skyf.jpeg new file mode 100644 index 00000000..620c76d5 Binary files /dev/null and b/000_temp/87-website/served/img/skyf.jpeg differ diff --git a/000_temp/87-website/skyfall b/000_temp/87-website/skyfall new file mode 100755 index 00000000..2aad6f6c Binary files /dev/null and b/000_temp/87-website/skyfall differ diff --git a/000_temp/87-website/templates/index.gohtml b/000_temp/87-website/templates/index.gohtml new file mode 100644 index 00000000..b57b18ac --- /dev/null +++ b/000_temp/87-website/templates/index.gohtml @@ -0,0 +1,15 @@ + + + + + Title + + + + +
+

SKYFALL

+
+ + + \ No newline at end of file diff --git a/000_temp/88-whole-enchilada/main.go b/000_temp/88-whole-enchilada/main.go new file mode 100644 index 00000000..6c587e24 --- /dev/null +++ b/000_temp/88-whole-enchilada/main.go @@ -0,0 +1,63 @@ +package main + +import ( + "html/template" + "net/http" + _ "github.com/lib/pq" + "database/sql" + "log" + "fmt" +) + +type customer struct { + ID int + First string +} + +var tpl *template.Template +var db *sql.DB + +func init() { + var err error + + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) + + connStr := "dbname=thanksgiving user=turkey password=gravy host=localhost port=5432 sslmode=disable" + db, err = sql.Open("postgres", connStr) + if err != nil { + log.Fatal("**** NO OPEN ****", err) + } + + err = db.Ping() + if err != nil { + log.Fatal("**** NO PING WORKING ****", err) + } else { + fmt.Println("Ping successful") + } +} + +func main() { + defer db.Close() + + http.HandleFunc("/", index) + http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("./resources")))) + http.ListenAndServe(":80", nil) +} + +func index(w http.ResponseWriter, r *http.Request) { + rows, err := db.Query("SELECT * FROM customers;") + if err != nil { + log.Fatal(err) + } + defer rows.Close() + + xc := []customer{} + + for rows.Next() { + c := customer{} + rows.Scan(&c.ID, &c.First) + xc = append(xc, c) + } + + tpl.ExecuteTemplate(w, "index.gohtml", xc) +} diff --git a/000_temp/88-whole-enchilada/resources/img/skyf.jpeg b/000_temp/88-whole-enchilada/resources/img/skyf.jpeg new file mode 100644 index 00000000..620c76d5 Binary files /dev/null and b/000_temp/88-whole-enchilada/resources/img/skyf.jpeg differ diff --git a/000_temp/88-whole-enchilada/templates/index.gohtml b/000_temp/88-whole-enchilada/templates/index.gohtml new file mode 100644 index 00000000..5b7b6df3 --- /dev/null +++ b/000_temp/88-whole-enchilada/templates/index.gohtml @@ -0,0 +1,21 @@ + + + + + + + HOME + + + +

HOME

+ +{{range .}} +

ID - {{.ID}} .......... FIRST - {{.First}}

+{{end}} + + + + + \ No newline at end of file diff --git a/000_temp/88-whole-enchilada/texan b/000_temp/88-whole-enchilada/texan new file mode 100755 index 00000000..c22cc5a1 Binary files /dev/null and b/000_temp/88-whole-enchilada/texan differ diff --git a/000_temp/90-div/index.html b/000_temp/90-div/index.html new file mode 100644 index 00000000..f45958a8 --- /dev/null +++ b/000_temp/90-div/index.html @@ -0,0 +1,417 @@ + + + + + Title + + + + + +
+ + + + + \ No newline at end of file diff --git a/000_temp/90-div/main.css b/000_temp/90-div/main.css new file mode 100644 index 00000000..6826090f --- /dev/null +++ b/000_temp/90-div/main.css @@ -0,0 +1,10 @@ +#dog { + /*formatting*/ + width: 150px; + height: 150px; + background-color: red; + /*layout*/ + position: fixed; + right: 0; + bottom: 0; +} \ No newline at end of file diff --git a/000_temp/91-flex/index.html b/000_temp/91-flex/index.html new file mode 100644 index 00000000..87342e3f --- /dev/null +++ b/000_temp/91-flex/index.html @@ -0,0 +1,14 @@ + + + + + Title + + + + + +
+ + + \ No newline at end of file diff --git a/000_temp/91-flex/main.css b/000_temp/91-flex/main.css new file mode 100644 index 00000000..67c623d9 --- /dev/null +++ b/000_temp/91-flex/main.css @@ -0,0 +1,23 @@ +html, body, div { + padding: 0; + border: 0; + margin: 0; + box-sizing: border-box; +} + +body { + height: 100vh; + border: 4px solid red; + display: flex; + flex-direction: row; + flex-wrap: nowrap; + justify-content: center; + align-items: center; +} + +#dog { + /*formatting*/ + width: 150px; + height: 150px; + background-color: red; +} \ No newline at end of file diff --git a/000_temp/92-whole-enchilada-2/main.go b/000_temp/92-whole-enchilada-2/main.go new file mode 100644 index 00000000..9bdcdea6 --- /dev/null +++ b/000_temp/92-whole-enchilada-2/main.go @@ -0,0 +1,175 @@ +package main + +import ( + "html/template" + "net/http" + _ "github.com/lib/pq" + "database/sql" + "log" + "fmt" +) + +type customer struct { + ID int + First string +} + +var tpl *template.Template +var db *sql.DB + +func init() { + var err error + + tpl = template.Must(template.ParseGlob("templates/*.gohtml")) + + connStr := "dbname=thanksgiving user=turkey password=gravy host=localhost port=5432 sslmode=disable" + db, err = sql.Open("postgres", connStr) + if err != nil { + log.Fatal("**** NO OPEN ****", err) + } + + err = db.Ping() + if err != nil { + log.Fatal("**** NO PING WORKING ****", err) + } else { + fmt.Println("Ping successful") + } +} + +func main() { + defer db.Close() + + http.HandleFunc("/", read) + http.HandleFunc("/process", create) + http.HandleFunc("/processtoo", ptoo) + http.HandleFunc("/update", up) + http.HandleFunc("/delete", del) + http.Handle("/assets/", http.StripPrefix("/assets", http.FileServer(http.Dir("./resources")))) + http.ListenAndServe(":8080", nil) +} + +//READ +func read(w http.ResponseWriter, r *http.Request) { + rows, err := db.Query("SELECT * FROM customers;") + if err != nil { + log.Fatal(err) + } + defer rows.Close() + + xc := []customer{} + + for rows.Next() { + c := customer{} + rows.Scan(&c.ID, &c.First) + xc = append(xc, c) + } + + tpl.ExecuteTemplate(w, "index.gohtml", xc) +} + +// CREATE +func create(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + http.Redirect(w, r, "/", http.StatusFound) + return + } + + fn := r.FormValue("fffnnnaaammmeee") + fmt.Println(fn) + + result, err := db.Exec("INSERT INTO customers (cfirst) VALUES ($1);", fn) + if err != nil { + log.Fatal(err) + } + + n, err := result.RowsAffected() + if err != nil { + log.Println(err) + http.Redirect(w, r, "/", http.StatusFound) + return + } + fmt.Println("rows affected", n) + + http.Redirect(w, r, "/", http.StatusFound) +} + + +// UPDATE +func up(w http.ResponseWriter, r *http.Request) { + + if r.Method != http.MethodGet { + http.Redirect(w, r, "/", http.StatusFound) + return + } + + customerid := r.FormValue("recordid") + + row, err := db.Query("SELECT * FROM customers WHERE cid = $1", customerid) + if err != nil { + http.Error(w, "coudn't retrieve record in up", http.StatusInternalServerError) + return + } + + c := customer{} + for row.Next() { + row.Scan(&c.ID, &c.First) + } + + tpl.ExecuteTemplate(w, "update.gohtml", c) +} + + +func ptoo(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodPost { + http.Redirect(w, r, "/", http.StatusFound) + return + } + + id := r.FormValue("customerid") + fn := r.FormValue("fffnnnaaammmeee") + fmt.Println(id) + fmt.Println(fn) + + result, err := db.Exec("UPDATE customers SET cfirst = $2 WHERE cid = $1;", id, fn) + if err != nil { + log.Fatal(err) + } + + n, err := result.RowsAffected() + if err != nil { + log.Println(err) + http.Redirect(w, r, "/", http.StatusFound) + return + } + fmt.Println("rows affected", n) + + http.Redirect(w, r, "/", http.StatusFound) +} + + +// DELETE +func del(w http.ResponseWriter, r *http.Request) { + + if r.Method != http.MethodGet { + http.Redirect(w, r, "/", http.StatusFound) + return + } + + customerid := r.FormValue("recordid") + + + result, err := db.Exec("DELETE FROM customers WHERE cid = $1;", customerid) + if err != nil { + http.Error(w, "didn't delete", http.StatusInternalServerError) + return + } + + n, err := result.RowsAffected() + if err != nil { + http.Error(w, "didn't show rows affected", http.StatusInternalServerError) + return + } + fmt.Println("rows affected", n) + + http.Redirect(w, r, "/", http.StatusFound) +} diff --git a/000_temp/92-whole-enchilada-2/resources/img/skyf.jpeg b/000_temp/92-whole-enchilada-2/resources/img/skyf.jpeg new file mode 100644 index 00000000..620c76d5 Binary files /dev/null and b/000_temp/92-whole-enchilada-2/resources/img/skyf.jpeg differ diff --git a/000_temp/92-whole-enchilada-2/templates/index.gohtml b/000_temp/92-whole-enchilada-2/templates/index.gohtml new file mode 100644 index 00000000..4a292971 --- /dev/null +++ b/000_temp/92-whole-enchilada-2/templates/index.gohtml @@ -0,0 +1,29 @@ + + + + + + + HOME + + + +

HOME

+ +{{range .}} +

ID - {{.ID}} .......... FIRST - {{.First}} .. UPDATE .. DELETE

+{{end}} + + + + + +
+ + + +
+ + + \ No newline at end of file diff --git a/000_temp/92-whole-enchilada-2/templates/update.gohtml b/000_temp/92-whole-enchilada-2/templates/update.gohtml new file mode 100644 index 00000000..3e0261fd --- /dev/null +++ b/000_temp/92-whole-enchilada-2/templates/update.gohtml @@ -0,0 +1,24 @@ + + + + + + + HOME + + + +

UPDATING

+ +

ID - {{.ID}} .......... FIRST - {{.First}}

+ +
+ + + + +
+ + + \ No newline at end of file diff --git a/003_string-to-html/03_os-Args/index.html b/003_string-to-html/03_os-Args/index.html new file mode 100644 index 00000000..624e6494 --- /dev/null +++ b/003_string-to-html/03_os-Args/index.html @@ -0,0 +1,12 @@ + + + + + + Hello World! + + +

JAMES

+ + + \ No newline at end of file diff --git a/003_string-to-html/README.md b/003_string-to-html/README.md index 8587b360..d7ae7b61 100644 --- a/003_string-to-html/README.md +++ b/003_string-to-html/README.md @@ -30,8 +30,8 @@ NewReader returns a new Reader reading from s. func NewReader(s string) *Reader ``` -##[os.Args](https://godoc.org/os#pkg-variables) +## [os.Args](https://godoc.org/os#pkg-variables) Args is a variable from package os. Args hold the command-line arguments, starting with the program name. ``` Go var Args []string -``` \ No newline at end of file +``` diff --git a/010_nested-templates/01_nested-templates/templates/index.gohtml b/010_nested-templates/01_nested-templates/templates/index.gohtml index 29296d88..8a809ac1 100644 --- a/010_nested-templates/01_nested-templates/templates/index.gohtml +++ b/010_nested-templates/01_nested-templates/templates/index.gohtml @@ -5,7 +5,10 @@ Hello World! +

The meaning of life: {{.}}

+

{{template "polarbear"}}

+ \ No newline at end of file diff --git a/011_composition-and-methods/04_method/tpl.gohtml b/011_composition-and-methods/04_method/tpl.gohtml index 8cbaaab8..341d3db9 100644 --- a/011_composition-and-methods/04_method/tpl.gohtml +++ b/011_composition-and-methods/04_method/tpl.gohtml @@ -10,6 +10,7 @@

{{.Age}}

{{.SomeProcessing}}

{{.AgeDbl}}

+

{{.Age | .TakesArg}}

{{.AgeDbl | .TakesArg}}

\ No newline at end of file diff --git a/015_understanding-TCP-servers/06_dial-write/README.md b/015_understanding-TCP-servers/06_dial-write/README.md index 3d836a76..5e9cdb6f 100644 --- a/015_understanding-TCP-servers/06_dial-write/README.md +++ b/015_understanding-TCP-servers/06_dial-write/README.md @@ -1,3 +1,3 @@ run "02_read-scanner" -run "07_dial-write" \ No newline at end of file +run "06_dial-write" \ No newline at end of file diff --git a/016_building-a-tcp-server-for-http/01/main.go b/016_building-a-tcp-server-for-http/01/main.go index fef0ddad..84875e68 100644 --- a/016_building-a-tcp-server-for-http/01/main.go +++ b/016_building-a-tcp-server-for-http/01/main.go @@ -56,7 +56,7 @@ func request(conn net.Conn) { func respond(conn net.Conn) { - body := `Hello World` + body := `Hello World` fmt.Fprint(conn, "HTTP/1.1 200 OK\r\n") fmt.Fprintf(conn, "Content-Length: %d\r\n", len(body)) diff --git a/016_building-a-tcp-server-for-http/03_solution/main.go b/016_building-a-tcp-server-for-http/03_solution/main.go index 33321d54..5417c964 100644 --- a/016_building-a-tcp-server-for-http/03_solution/main.go +++ b/016_building-a-tcp-server-for-http/03_solution/main.go @@ -58,7 +58,7 @@ func request(conn net.Conn) { func respond(conn net.Conn) { - body := `Hello World` + body := `Hello World` fmt.Fprint(conn, "HTTP/1.1 200 OK\r\n") fmt.Fprintf(conn, "Content-Length: %d\r\n", len(body)) diff --git a/016_building-a-tcp-server-for-http/05_solution/main.go b/016_building-a-tcp-server-for-http/05_solution/main.go index 10921185..d88b77cd 100644 --- a/016_building-a-tcp-server-for-http/05_solution/main.go +++ b/016_building-a-tcp-server-for-http/05_solution/main.go @@ -122,7 +122,7 @@ func contact(conn net.Conn) { func apply(conn net.Conn) { - body := ` + body := ` APPLY
index
about
diff --git a/022_hands-on/02/04_solution/main.go b/022_hands-on/02/04_solution/main.go index 7740f10b..2fdb743c 100644 --- a/022_hands-on/02/04_solution/main.go +++ b/022_hands-on/02/04_solution/main.go @@ -34,7 +34,5 @@ func main() { // how does the above reader know when it's done? fmt.Println("Code got here.") io.WriteString(conn, "I see you connected.") - - conn.Close() } } diff --git a/022_hands-on/02/05_hands-on/README.md b/022_hands-on/02/05_hands-on/README.md index 38d0de3a..9040f3ad 100644 --- a/022_hands-on/02/05_hands-on/README.md +++ b/022_hands-on/02/05_hands-on/README.md @@ -8,11 +8,13 @@ We will now break out of the reading. Package bufio has the Scanner type. The Scanner type "provides a convenient interface for reading data". When you have a Scanner type, you can call the SCAN method on it. Successive calls to the Scan method will step through the tokens (piece of data). The default token is a line. The Scanner type also has a TEXT method. When you call this method, you will be given the text from the current token. Here is how you will use it: +``` scanner := bufio.NewScanner(conn) for scanner.Scan() { ln := scanner.Text() fmt.Println(ln) } +``` Use this code to READ from an incoming connection and print the incoming text to standard out (the terminal). @@ -20,4 +22,4 @@ When your "ln" line of text is equal to an empty string, break out of the loop. Run your code and go to localhost:8080 in **your browser.** -What do you find? \ No newline at end of file +What do you find? diff --git a/022_hands-on/02/11_hands-on/README.md b/022_hands-on/02/11_hands-on/README.md index 64aaf71c..044f91eb 100644 --- a/022_hands-on/02/11_hands-on/README.md +++ b/022_hands-on/02/11_hands-on/README.md @@ -1,6 +1,6 @@ # Building upon the code from the previous problem: -Before we WRITE our RESPONSE , let's WRITE to our RESPONSE the STATUS LINE and some REPONSE HEADERS. Remember the request line and status line: +Before we WRITE our RESPONSE, let's WRITE to our RESPONSE the STATUS LINE and some RESPONSE HEADERS. Remember the request line and status line: REQUEST LINE GET / HTTP/1.1 @@ -22,4 +22,4 @@ fmt.Fprint(c, "Content-Type: text/plain\r\n") "\r\n" -Look in your browser "developer tools" under the network tab. Compare the RESPONSE HEADERS from the previous file with the RESPONSE HEADERS in your new solution. \ No newline at end of file +Look in your browser "developer tools" under the network tab. Compare the RESPONSE HEADERS from the previous file with the RESPONSE HEADERS in your new solution. diff --git a/023_serving-files/02_serving/04_FileServer/01/main.go b/023_serving-files/02_serving/04_FileServer/01/main.go index 5ff93afd..34a0df2a 100644 --- a/023_serving-files/02_serving/04_FileServer/01/main.go +++ b/023_serving-files/02_serving/04_FileServer/01/main.go @@ -7,11 +7,11 @@ import ( func main() { http.Handle("/", http.FileServer(http.Dir("."))) - http.HandleFunc("/dog", dog) + http.HandleFunc("/dog/", dog) http.ListenAndServe(":8080", nil) } func dog(w http.ResponseWriter, req *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") - io.WriteString(w, ``) + io.WriteString(w, ``) } diff --git a/023_serving-files/02_serving/04_FileServer/02/main.go b/023_serving-files/02_serving/04_FileServer/02/main.go index 2e190205..3a7a5ff0 100644 --- a/023_serving-files/02_serving/04_FileServer/02/main.go +++ b/023_serving-files/02_serving/04_FileServer/02/main.go @@ -15,3 +15,9 @@ func dog(w http.ResponseWriter, req *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") io.WriteString(w, ``) } + +/* + +./assets/toby.jpg + +*/ diff --git a/024_hands-on/09_hands-on/starting-files/css/main.css b/024_hands-on/09_hands-on/starting-files/public/css/main.css similarity index 100% rename from 024_hands-on/09_hands-on/starting-files/css/main.css rename to 024_hands-on/09_hands-on/starting-files/public/css/main.css diff --git a/024_hands-on/09_hands-on/starting-files/css/reset.css b/024_hands-on/09_hands-on/starting-files/public/css/reset.css similarity index 100% rename from 024_hands-on/09_hands-on/starting-files/css/reset.css rename to 024_hands-on/09_hands-on/starting-files/public/css/reset.css diff --git a/024_hands-on/09_hands-on/starting-files/pic/surf.jpg b/024_hands-on/09_hands-on/starting-files/public/pic/surf.jpg similarity index 100% rename from 024_hands-on/09_hands-on/starting-files/pic/surf.jpg rename to 024_hands-on/09_hands-on/starting-files/public/pic/surf.jpg diff --git a/024_hands-on/09_hands-on/starting-files/index.html b/024_hands-on/09_hands-on/starting-files/templates/index.gohtml similarity index 95% rename from 024_hands-on/09_hands-on/starting-files/index.html rename to 024_hands-on/09_hands-on/starting-files/templates/index.gohtml index bcbd3c5b..cb39f57e 100644 --- a/024_hands-on/09_hands-on/starting-files/index.html +++ b/024_hands-on/09_hands-on/starting-files/templates/index.gohtml @@ -3,12 +3,12 @@ - - + + -A man surfing a wave +A man surfing a wave diff --git a/024_hands-on/12_solution/main.go b/024_hands-on/12_solution/main.go index 8f8bf128..7e59a3e7 100644 --- a/024_hands-on/12_solution/main.go +++ b/024_hands-on/12_solution/main.go @@ -14,8 +14,8 @@ func init() { func main() { http.HandleFunc("/", index) - http.HandleFunc("/about", about) - http.HandleFunc("/contact", contact) + http.HandleFunc("/about/", about) + http.HandleFunc("/contact/", contact) http.HandleFunc("/apply", apply) http.ListenAndServe(":8080", nil) } diff --git a/026_appengine-deploy/01/app.yaml b/026_appengine-deploy/01/app.yaml index 1dd8f1c6..fb82ec67 100644 --- a/026_appengine-deploy/01/app.yaml +++ b/026_appengine-deploy/01/app.yaml @@ -1,8 +1,6 @@ -application: temp-145415 -version: 1 -runtime: go -api_version: go1 +runtime: go113 handlers: - url: /.* - script: _go_app \ No newline at end of file + script: auto + secure: always \ No newline at end of file diff --git a/026_appengine-deploy/01/main.go b/026_appengine-deploy/01/main.go index 68523458..671d6b1d 100644 --- a/026_appengine-deploy/01/main.go +++ b/026_appengine-deploy/01/main.go @@ -4,6 +4,7 @@ import ( "net/http" ) -func init() { +func main() { http.Handle("/", http.FileServer(http.Dir("."))) + http.ListenAndServe(":8080", nil) } diff --git a/026_appengine-deploy/02/app.yaml b/026_appengine-deploy/02/app.yaml index 1dd8f1c6..fb82ec67 100644 --- a/026_appengine-deploy/02/app.yaml +++ b/026_appengine-deploy/02/app.yaml @@ -1,8 +1,6 @@ -application: temp-145415 -version: 1 -runtime: go -api_version: go1 +runtime: go113 handlers: - url: /.* - script: _go_app \ No newline at end of file + script: auto + secure: always \ No newline at end of file diff --git a/026_appengine-deploy/02/main.go b/026_appengine-deploy/02/main.go index 68523458..671d6b1d 100644 --- a/026_appengine-deploy/02/main.go +++ b/026_appengine-deploy/02/main.go @@ -4,6 +4,7 @@ import ( "net/http" ) -func init() { +func main() { http.Handle("/", http.FileServer(http.Dir("."))) + http.ListenAndServe(":8080", nil) } diff --git a/026_appengine-deploy/README.md b/026_appengine-deploy/README.md index 247ba1be..c256d787 100644 --- a/026_appengine-deploy/README.md +++ b/026_appengine-deploy/README.md @@ -1,30 +1,27 @@ -# buying a domain + # buying a domain https://domains.google/#/ # deploying to [Google Cloud](https://cloud.google.com/) - [install google appengine](https://cloud.google.com/appengine/docs/go/download) -- [make sure python is installed VERSION 2.7.x](https://www.python.org/downloads/release/python-2712/) - - python -V - configure environment PATH variables - google cloud developer console - create a project - get the project ID -- update the app.yaml file with your project ID +- set your go version in the app.yaml file ``` -application: temp-137512 -version: 1 -runtime: go -api_version: go1 - +runtime: go113 handlers: - url: /.* - script: _go_app + script: auto + secure: always ``` -- deploy to that project +- deploy to that project. update --project with your project-id ``` -appcfg.py -A -V v1 update . +gcloud app deploy app.yaml --project= -v 1 +my example: +gcloud app deploy --project temp-137512 ``` - view your project - http://YOUR_PROJECT_ID.appspot.com/ diff --git a/029_cookies/01_set_get/main.go b/029_cookies/01_set_get/main.go index dbc499b6..69873249 100644 --- a/029_cookies/01_set_get/main.go +++ b/029_cookies/01_set_get/main.go @@ -16,6 +16,7 @@ func set(w http.ResponseWriter, req *http.Request) { http.SetCookie(w, &http.Cookie{ Name: "my-cookie", Value: "some value", + Path: "/", }) fmt.Fprintln(w, "COOKIE WRITTEN - CHECK YOUR BROWSER") fmt.Fprintln(w, "in chrome go to: dev tools / application / cookies") diff --git a/029_cookies/02_multiple/main.go b/029_cookies/02_multiple/main.go index e08b2fcc..379d69d2 100644 --- a/029_cookies/02_multiple/main.go +++ b/029_cookies/02_multiple/main.go @@ -18,6 +18,7 @@ func set(w http.ResponseWriter, req *http.Request) { http.SetCookie(w, &http.Cookie{ Name: "my-cookie", Value: "some value", + Path: "/", }) fmt.Fprintln(w, "COOKIE WRITTEN - CHECK YOUR BROWSER") fmt.Fprintln(w, "in chrome go to: dev tools / application / cookies") diff --git a/029_cookies/03_hands-on/README.md b/029_cookies/03_hands-on/README.md index 7319a52d..01b97f4d 100644 --- a/029_cookies/03_hands-on/README.md +++ b/029_cookies/03_hands-on/README.md @@ -1 +1,36 @@ -Using cookies, track how many times a user has been to your website domain. \ No newline at end of file +package main + +import ( + "fmt" + "net/http" +) + +func main() { + http.HandleFunc("/", set) + http.HandleFunc("/read", read) + http.Handle("/favicon.ico", http.NotFoundHandler()) + http.ListenAndServe(":8080", nil) +} + +func set(w http.ResponseWriter, req *http.Request) { + http.SetCookie(w, &http.Cookie{ + Name: "my-cookie", + Value: "some value", + Path: "/", + }) + fmt.Fprintln(w, "COOKIE WRITTEN - CHECK YOUR BROWSER") + fmt.Fprintln(w, "in chrome go to: dev tools / application / cookies") +} + +func read(w http.ResponseWriter, req *http.Request) { + + c, err := req.Cookie("my-cookie") + if err != nil { + http.Error(w, http.StatusText(400), http.StatusBadRequest) + return + } + + fmt.Fprintln(w, "YOUR COOKIE:", c) +} + +// Using cookies, track how many times a user has been to your website domain. \ No newline at end of file diff --git a/029_cookies/04_solution/main.go b/029_cookies/04_solution/main.go index 89b03c44..653ef59b 100644 --- a/029_cookies/04_solution/main.go +++ b/029_cookies/04_solution/main.go @@ -21,6 +21,7 @@ func foo(res http.ResponseWriter, req *http.Request) { cookie = &http.Cookie{ Name: "my-cookie", Value: "0", + Path: "/", } } diff --git a/029_cookies/05_maxage/main.go b/029_cookies/05_maxage/main.go index 0b095752..2c8373c5 100644 --- a/029_cookies/05_maxage/main.go +++ b/029_cookies/05_maxage/main.go @@ -21,6 +21,7 @@ func set(w http.ResponseWriter, req *http.Request) { http.SetCookie(w, &http.Cookie{ Name: "session", Value: "some value", + Path: "/", }) fmt.Fprintln(w, `

read

`) } diff --git a/029_cookies/06_path/03_templates/02/main.go b/029_cookies/06_path/03_templates/02/main.go index bb9726b8..b504073a 100644 --- a/029_cookies/06_path/03_templates/02/main.go +++ b/029_cookies/06_path/03_templates/02/main.go @@ -35,6 +35,7 @@ func bowzer(w http.ResponseWriter, r *http.Request) { Name: "user-cookie", Value: "this would be the value", Path: "/", + //Path: "/dog/bowzer/", } http.SetCookie(w, c) tpl.ExecuteTemplate(w, "bowzer.gohtml", c) diff --git a/030_sessions/03_signup/main.go b/030_sessions/03_signup/main.go index a1da2c8d..48f0d58c 100644 --- a/030_sessions/03_signup/main.go +++ b/030_sessions/03_signup/main.go @@ -1,9 +1,10 @@ package main import ( - "github.com/satori/go.uuid" "html/template" "net/http" + + uuid "github.com/satori/go.uuid" ) type user struct { @@ -30,12 +31,12 @@ func main() { } func index(w http.ResponseWriter, req *http.Request) { - u := getUser(w, req) + u := getUser(req) tpl.ExecuteTemplate(w, "index.gohtml", u) } func bar(w http.ResponseWriter, req *http.Request) { - u := getUser(w, req) + u := getUser(req) if !alreadyLoggedIn(req) { http.Redirect(w, req, "/", http.StatusSeeOther) return diff --git a/030_sessions/03_signup/session.go b/030_sessions/03_signup/session.go index 17a72572..bda111e9 100644 --- a/030_sessions/03_signup/session.go +++ b/030_sessions/03_signup/session.go @@ -2,26 +2,18 @@ package main import ( "net/http" - - "github.com/satori/go.uuid" ) -func getUser(w http.ResponseWriter, req *http.Request) user { +func getUser(req *http.Request) user { + var u user + // get cookie c, err := req.Cookie("session") if err != nil { - sID, _ := uuid.NewV4() - c = &http.Cookie{ - Name: "session", - Value: sID.String(), - } - + return u } - //Next line may not be required, commenting it - // http.SetCookie(w, c) // if the user exists already, get user - var u user if un, ok := dbSessions[c.Value]; ok { u = dbUsers[un] } diff --git a/030_sessions/09_middleware/main.go b/030_sessions/09_middleware/main.go index f3266f64..21cfaedd 100644 --- a/030_sessions/09_middleware/main.go +++ b/030_sessions/09_middleware/main.go @@ -167,7 +167,7 @@ func logout(w http.ResponseWriter, req *http.Request) { func authorized(h http.HandlerFunc) http.HandlerFunc { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if !alreadyLoggedIn(w, r) { + if !alreadyLoggedIn(w, r) { //http.Error(w, "not logged in", http.StatusUnauthorized) http.Redirect(w, r, "/", http.StatusSeeOther) return // don't call original handler diff --git a/030_sessions/10_temp/main.go b/030_sessions/10_temp/main.go index c710e405..38998347 100644 --- a/030_sessions/10_temp/main.go +++ b/030_sessions/10_temp/main.go @@ -166,7 +166,7 @@ func logout(w http.ResponseWriter, req *http.Request) { } func authorized(h http.HandlerFunc) http.HandlerFunc { - return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request){ + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // code before if !alreadyLoggedIn(w, r) { http.Redirect(w, r, "/", http.StatusSeeOther)