Skip to content

Instantly share code, notes, and snippets.

Avatar

Krzysztof Kowalczyk kjk

View GitHub Profile
@kjk
kjk / main.go
Created Nov 5, 2019
Encode data to file and decode from file
View main.go
// :collection Essential Go
package main
import (
"encoding/gob"
"os"
"log"
"fmt"
)
@kjk
kjk / main.go
Created Nov 5, 2019
Reading records from CSV file
View main.go
// :collection Essential Go
package main
import (
"bytes"
"encoding/csv"
"fmt"
"io"
"log"
)
@kjk
kjk / main.go
Created Nov 5, 2019
Writing records to CSV file
View main.go
// :collection Essential Go
package main
import (
"encoding/csv"
"fmt"
"io/ioutil"
"log"
"os"
)
@kjk
kjk / main.go
Created Nov 5, 2019
for, while loops
View main.go
// :collection Essential Go
package main
import "fmt"
func main() {
// :show start
for i := 0; i < 5; i += 2 {
fmt.Printf("i: %d\n", i)
}
@kjk
kjk / main.go
Created Nov 5, 2019
for without initialization statement
View main.go
// :collection Essential Go
package main
import "fmt"
func main() {
// :show start
i := 0
for ; i < 5; i += 2 {
fmt.Printf("i: %d\n", i)
@kjk
kjk / main.go
Created Nov 5, 2019
for without test expression
View main.go
// :collection Essential Go
package main
import "fmt"
func main() {
// :show start
i := 0
for ; ; i += 2 {
fmt.Printf("i: %d\n", i)
@kjk
kjk / main.go
Created Nov 5, 2019
for without increment statement
View main.go
// :collection Essential Go
package main
import "fmt"
func main() {
// :show start
for i := 0; i < 5; {
fmt.Printf("i: %d\n", i)
i += 2
@kjk
kjk / main.go
Created Nov 5, 2019
infinite for loop
View main.go
// :collection Essential Go
package main
import "fmt"
func main() {
// :show start
i := 0
for {
fmt.Printf("i: %d\n", i)
@kjk
kjk / main.go
Created Nov 5, 2019
for loop over a slice with range
View main.go
// :collection Essential Go
package main
import "fmt"
func main() {
// :show start
a := []int{1, 3, 5}
for idx, value := range a {
fmt.Printf("idx: %d, value: %d\n", idx, value)
@kjk
kjk / main.go
Created Nov 5, 2019
Hex encode and decode
View main.go
// collection: Essential Go
package main
import (
"bytes"
"encoding/hex"
"fmt"
"log"
)