Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Day5 added #2

Open
wants to merge 56 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
3668e96
Fixes and speaker name change
dlahoza Sep 17, 2016
752051d
day2 fixes
dlahoza Sep 19, 2016
bd96433
Typo fix
dlahoza Sep 19, 2016
8c5b11b
New example with map, URL in slides
dlahoza Sep 19, 2016
5bd7439
Merge pull request #1 from DLag/fixes
dlahoza Sep 20, 2016
7b54bc1
Changes#
dlahoza Sep 21, 2016
727f234
Merge pull request #3 from DLag/fixes
dlahoza Sep 21, 2016
a5eb9fa
Merge remote-tracking branch 'grsmv/master'
dlahoza Sep 21, 2016
fe6b507
Merge remote-tracking branch 'grsmv/master'
dlahoza Sep 21, 2016
25bdcb0
Actualize
iscander Sep 22, 2016
bd502ee
Back to women and ages
iscander Sep 22, 2016
96560b3
Merge remote-tracking branch 'grsmv/master'
dlahoza Sep 22, 2016
1560646
day4 update
iscander Sep 23, 2016
b02e08e
Goroutines and channels slides
iscander Sep 23, 2016
caa42b7
Example of code for goroutines and channels
iscander Sep 23, 2016
2c0335a
Cleanup
iscander Sep 23, 2016
f684ce9
gitignore
dlahoza Sep 25, 2016
0c0e68d
Merge branch 'master' into pr/4
dlahoza Sep 25, 2016
9927951
Merge pull request #5 from DLag/pr/4
dlahoza Sep 25, 2016
8a3db38
Clockmultiserver with timeouts.
iscander Sep 26, 2016
71e9824
HTTP server and basic API
dlahoza Sep 26, 2016
6f9083c
Merge pull request #1 from DLag/master
iscander Sep 26, 2016
ac59700
Id generator web service & simple fileserver
dlahoza Sep 26, 2016
ff09bc2
Merge pull request #2 from DLag/master
iscander Sep 26, 2016
61e45e0
Simple fileserver - easy to read
iscander Sep 26, 2016
e3b8cb1
TLS support
iscander Sep 26, 2016
f4aa18f
Code decomposition for wiki example
iscander Sep 27, 2016
c5c7680
Update edit template
iscander Sep 27, 2016
d421d8e
Tests for templates
iscander Sep 27, 2016
53ce5dc
Use variables and environment settings
iscander Sep 27, 2016
747c9c1
Rename
iscander Sep 27, 2016
328e367
Rename
iscander Sep 27, 2016
829208b
change formating
iscander Sep 27, 2016
e02896c
Use render interface implemantators
iscander Sep 27, 2016
341fd32
Benchmarks and test
iscander Sep 27, 2016
44b0e73
Templates for testing
iscander Sep 27, 2016
d177235
Stylish templates
iscander Sep 27, 2016
81ff19a
Handlers test mockup
iscander Sep 27, 2016
ea7691b
Day 6 slides
iscander Sep 29, 2016
5d69e76
Remove binary
iscander Sep 29, 2016
239fb78
Code for day6
iscander Sep 29, 2016
c1dba6d
Wiki application
iscander Sep 29, 2016
1ab517e
Mockup for inmemory database
iscander Sep 29, 2016
16b50c5
Database call to save and expire value. Mockups for result's converting
iscander Sep 29, 2016
234c8f8
Dedicated file for errors
iscander Sep 29, 2016
6a55792
Implement close for the storage and expire for a key
iscander Sep 29, 2016
eeac500
Type detection and assigment example
iscander Sep 29, 2016
dd8586d
Get value implemented. CloseDB implemented
iscander Sep 29, 2016
468211e
Return values for keys wich matched to the pattern
iscander Sep 29, 2016
e95d4b0
Interface to return multiple string values from DB. Types conversions…
iscander Sep 29, 2016
844833a
Mockup for sql/driver integration
iscander Sep 29, 2016
64bbb4d
Slides for DB
iscander Sep 29, 2016
4871f22
Types for db.sql
iscander Sep 29, 2016
6500636
MongoDB and sqlite examples
iscander Sep 29, 2016
b66774a
Addons
iscander Sep 30, 2016
6bbd3c9
Docker slides
iscander Sep 30, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Created by .ignore support plugin (hsz.mobi)
.DS_Store
.idea
.idea
softserve-go-bootcamp-materials.iml
19 changes: 19 additions & 0 deletions day1/code/hello-world-map.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
j "encoding/json"
"fmt"
)

type Vocabulary map[string]string

func main() {
var vocabulary = Vocabulary{
"Ua": "Привіт, світ!",
"En": "Hello world!",
"De": "Hallo welt!",
}
v, _ := j.Marshal(vocabulary)
fmt.Print(string(v))
println(vocabulary["Ua"])
}
7 changes: 6 additions & 1 deletion day1/code/hello-world-string.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package main

var greeting = "Hello World"

func main() {

// you can use `greeting := "hw"` as well
var greeting = "Hello World"

greeting := "Hola!"

println(greeting)
}
10 changes: 8 additions & 2 deletions day1/code/hello-world-struct.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package main

import (
j "encoding/json"
"fmt"
)

type Vocabulary struct {
Ua string
Ua string `json:"ua"`
En string
De string
}
Expand All @@ -12,6 +17,7 @@ func main() {
En: "Hello world!",
De: "Hallo welt!",
}

v, _ := j.Marshal(vocabulary)
fmt.Println(string(v))
println(vocabulary.De)
}
2 changes: 1 addition & 1 deletion day1/code/hello-world.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package main

func main() {
println("Hello world")
println("Hello world", 1, 2, 3)
}
4 changes: 2 additions & 2 deletions day1/code/simple-web-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
)

func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
fmt.Fprintf(w, "Hi there, I love %+v!", r)
}

func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":8080", nil)
}
}
13 changes: 6 additions & 7 deletions day1/slides/index.slide
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Introduction to the language
Week 1, day 1

Serhii Herasymov
Dmytro Lahoza
SoftServe
[email protected]

[email protected]
@dlagoza
https://github.com/DLag/softserve-go-bootcamp-materials



Expand Down Expand Up @@ -169,7 +170,7 @@ Magic declaration:

iota is a constant generator, used to create a sequence of related values without spelling out each one explicitly.

Classic exmaple:
Classic example:

type Weekday int

Expand Down Expand Up @@ -234,7 +235,7 @@ Slice can be created with make function, which receives slice length and capacit
s[2] = 1
fmt.Println(s) // => [0 0 1 0 0]

Length and capacity of the slice can be accepted with cap() and len() functions:
Length and capacity of the slice can be fetched with cap() and len() functions:

len(s) // => 5
cap(s) // => 10
Expand Down Expand Up @@ -415,5 +416,3 @@ We can access fields using the . operator:

println(r.Width)
r.Width = 420

.image ./tim-and-eric-mind-blown.gif
13 changes: 13 additions & 0 deletions day2/code/ammount.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

func add(amount int, paymants ...int) (sum int) {
sum = len(paymants)
for _, i := range paymants {
sum += i
}
return
}

func main() {
println("Total:", add(10, 20, 30, -20))
}
20 changes: 20 additions & 0 deletions day2/code/runtime.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

import "fmt"

func process(j *int) {
fmt.Printf("Execption: %+v\n\n", recover())
fmt.Printf("Index: %d\n", *j)
}

func main() {
var arr = [5]int{1, 2, 3, 4, 5}
var i int
i = -1
defer process(&i)
for i = 0; i <= len(arr); i++ {
println(arr[i])
}

println(arr[i])
}
20 changes: 13 additions & 7 deletions day2/slides/index.slide
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Functions, error handling, panic and recovery
Week 1, day 2

Serhii Herasymov
Dmytro Lahoza
SoftServe
[email protected]
[email protected]
@dlagoza



Expand All @@ -26,10 +27,17 @@ Go functions schematics:

Go is also capable of returning multiple values from a function:

func f() (int, int) {
func f1() (int, int) {
return 5, 6
}

You can predefine result value names

func f2() (a, b int) {
a, b = 1, 2
return
}

func main() {
x, y := f()
}
Expand All @@ -38,7 +46,6 @@ Multiple values are often used to return an error value along with the result:

x, err := f()

x, ok := f() // `ok` is a boolean to indicate subroutine success


* Variadic functions
Expand All @@ -58,6 +65,7 @@ There is a special form available for the last parameter in a Go function:
}

[...] indicates that function takes zero or more of those parameters.
They will be passed as slice.
BTW, this is good way to work with "optional" parameters.

* Closures
Expand Down Expand Up @@ -92,8 +100,6 @@ Function is able to call itself:
return x * factorial(x-1)
}

.image ./recursion.gif




Expand Down Expand Up @@ -134,7 +140,7 @@ recover() stops this Drama Queen and returns the value that was passed to the ca
str := recover()
println(str)
}()
panic("AAAAA, we gonna dye")
panic("AAAAA, we gonna die")
}


Expand Down
23 changes: 23 additions & 0 deletions day3/code/fizbuzz.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package main
import "fmt"

type fizzbuzz int

func (x fizzbuzz) String() string {
switch [2]bool{x%3 == 0, x%5 == 0} {
case [2]bool{true, true}:
return "FizzBuzz"
case [2]bool{true, false}:
return "Fizz"
case [2]bool{false, true}:
return "Buzz"
default:
return fmt.Sprint(int(x))
}
}

func main() {
for x := fizzbuzz(1); x <= 100; x++ {
fmt.Println(x)
}
}
6 changes: 4 additions & 2 deletions day4/slides/index.slide
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
Packages, go tool, vendoring
Week 1, day 4

Serhii Herasymov
<<<<<<< HEAD
Dmytro Lahoza
SoftServe
[email protected]
[email protected]
@dlagoza


* Go tool
Expand Down
16 changes: 16 additions & 0 deletions day5/code/broken.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import (
"time"
)

func do(num int) {
println("Task ", num)
time.Sleep(2 * time.Second)
}

func main() {
for i := 1; i < 10; i++ {
go do(i)
}
}
12 changes: 12 additions & 0 deletions day5/code/buffered-channels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import "fmt"

func main() {
ch := make(chan int, 2)
ch <- 2
ch <- 1

fmt.Println(<-ch)
fmt.Println(<-ch)
}
22 changes: 22 additions & 0 deletions day5/code/channels.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package main

import "fmt"

func sum(s []int, c chan int) {
sum := 0
for _, v := range s {
sum += v
}
c <- sum // send sum to c
}

func main() {
s := []int{7, 2, 8, -9, 4, 0}

c := make(chan int)
go sum(s[:len(s)/2], c)
go sum(s[len(s)/2:], c)
x, y := <-c, <-c // receive from c

fmt.Println(x, y, x+y)
}
24 changes: 24 additions & 0 deletions day5/code/client1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Netcat1 is a read-only TCP client.
package main

import (
"io"
"log"
"net"
"os"
)

func main() {
conn, err := net.Dial("tcp", "localhost:8000")
if err != nil {
log.Fatal(err)
}
defer conn.Close()
mustCopy(os.Stdout, conn)
}

func mustCopy(dst io.Writer, src io.Reader) {
if _, err := io.Copy(dst, src); err != nil {
log.Fatal(err)
}
}
35 changes: 35 additions & 0 deletions day5/code/clock1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Clock1 is a TCP server that periodically writes the time.
package main

import (
"io"
"log"
"net"
"time"
)

func main() {
listener, err := net.Listen("tcp", "localhost:8000")
if err != nil {
log.Fatal(err)
}
for {
conn, err := listener.Accept()
if err != nil {
log.Print(err) // e.g., connection aborted
continue
}
handleConn(conn) // handle one connection at a time
}
}

func handleConn(c net.Conn) {
defer c.Close()
for {
_, err := io.WriteString(c, time.Now().Format("15:04:05\n"))
if err != nil {
return // e.g., client disconnected
}
time.Sleep(1 * time.Second)
}
}
Loading