Skip to content

Instantly share code, notes, and snippets.

View kjk's full-sized avatar

Krzysztof Kowalczyk kjk

View GitHub Profile
@kjk
kjk / main.go
Created November 5, 2019 09:38
Channels and select
// :collection Essential Go
package main
import (
"fmt"
"math/rand"
)
// :show start
@kjk
kjk / main.go
Last active November 5, 2019 09:40
Interfaces
// :collection Essential Go
package main
import (
"fmt"
"strconv"
)
// :show start
// Stringer is an interface with a single method
@kjk
kjk / main.go
Created November 5, 2019 09:42
Methods
// :collection Essential Go
package main
import "fmt"
// :show start
type Person struct {
FirstName string
LastName string
}
@kjk
kjk / main.go
Last active January 20, 2020 09:21
Value vs. pointer receiver (made with https://codeeval.dev)
// :collection Essential Go
package main
import "fmt"
// :show start
type Person struct {
FirstName string
LastName string
}
@kjk
kjk / main.go
Created November 5, 2019 09:44
Arrays
// :collection Essential Go
package main
import "fmt"
func main() {
// :show start
a := [2]int{4, 5} // array of 2 ints
// access element of array
@kjk
kjk / main.go
Created November 5, 2019 20:50
Variables
// :collection Essential Go
package main
import (
"bytes"
"fmt"
"io"
)
// :show start
// :collection Essential Go
package main
import (
"fmt"
)
// :show start
// addCheckOverflow adds two int16 numbers and additionally
// returns true if the result overflowed
@kjk
kjk / main.go
Created November 5, 2019 20:55
XML
// :collection Essential Go
package main
import (
"encoding/xml"
"fmt"
"log"
)
// :show start
@kjk
kjk / main.go
Created November 5, 2019 20:56
Serialize a struct as XML
// :collection Essential Go
package main
import (
"encoding/xml"
"fmt"
"log"
)
// :show start
@kjk
kjk / read file into lines.go
Last active July 12, 2020 22:31
Files and I/O (made with https://codeeval.dev)
// :collection Essential Go
package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
)