Skip to content

Instantly share code, notes, and snippets.

@flc
flc / http_handlers.go
Created August 28, 2013 22:19
A Tour of Go - Exercise: HTTP Handlers http://tour.golang.org/#58
package main
import (
"fmt"
"net/http"
)
type String string
@flc
flc / errors.go
Created August 28, 2013 21:56
A Tour of Go - Exercise: Errors http://tour.golang.org/#56
package main
import (
"fmt"
"math"
)
type ErrNegativeSqrt float64
@flc
flc / complex_cube_roots.go
Created August 28, 2013 20:20
A Tour of Go - Advanced Exercise: Complex cube roots http://tour.golang.org/#48
package main
import (
"fmt"
"math/cmplx"
)
const e = 1e-10
func Cbrt(x complex128) complex128 {
@flc
flc / wordcount.go
Created August 28, 2013 18:50
A Tour of Go - Exercise: Maps http://tour.golang.org/#41
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
ret := make(map[string]int)
@flc
flc / slices.go
Created August 28, 2013 18:40
A Tour of Go - Exercise: Slices http://tour.golang.org/#36
package main
import "code.google.com/p/go-tour/pic"
func Pic(dx, dy int) [][]uint8 {
img_func := func(x, y int) uint8 {
//return uint8(x*y)
//return uint8((x+y) / 2)
return uint8(x^y)
}
@flc
flc / loops_and_functions.go
Last active December 21, 2015 21:39
A Tour of Go - Exercise: Loops and Functions http://tour.golang.org/#24
package main
import (
"fmt"
"math"
)
const e = 1e-8 // small delta
@flc
flc / fibonacci_closure.go
Created August 28, 2013 18:01
A Tour of Go - Exercise: Fibonacci closure http://tour.golang.org/#44
package main
import "fmt"
// fibonacci is a function that returns
// a function that returns an int.
func fibonacci() func() int {
i, j := 0, 1
return func() int {
ret := i