Skip to content

Instantly share code, notes, and snippets.

@oldergod
oldergod / slices.go
Created September 11, 2014 15:00
Tour of Go Slices
package main
import (
"code.google.com/p/go-tour/pic"
)
func Pic(dx, dy int) [][]uint8 {
top := make([][]uint8, dy)
for i := range top {
top[i] = make([]uint8, dx)
@oldergod
oldergod / maps.go
Created September 11, 2014 15:12
Tour of Go Maps
package main
import (
"code.google.com/p/go-tour/wc"
"strings"
)
func WordCount(s string) map[string]int {
array := strings.Fields(s)
m := make(map[string]int)
@oldergod
oldergod / fibonacci.go
Last active August 29, 2015 14:06
Tour of Go Fibonacci
package main
import "fmt"
func fibonacci() func() int {
n1 := 1
n2 := 0
return func() int {
n1, n2 = n2, n1+n2
return n1
@oldergod
oldergod / cubes.go
Created September 13, 2014 04:27
Tour of Go Complex Cube Roots
package main
import "fmt"
import "math/cmplx"
func Cbrt(x complex128, z complex128) complex128 {
for i := 0; i < 10; i++ {
z = z - (cmplx.Pow(z, 3)-x)/(3*cmplx.Pow(z, 2))
}
return z
@oldergod
oldergod / sqrt_negative.go
Created September 13, 2014 06:27
Tour of Go Errors
package main
import (
"fmt"
"math"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
@oldergod
oldergod / server.go
Created September 15, 2014 14:07
Tour of Go Http Handlers
package main
import (
"fmt"
"net/http"
)
type String string
type Struct struct {
Greeting string
@oldergod
oldergod / image.go
Last active August 29, 2015 14:06
Tour of Go Image
package main
import (
"code.google.com/p/go-tour/pic"
"image"
"image/color"
)
const DIM = 1024
@oldergod
oldergod / rot13.go
Created September 16, 2014 08:00
Tour of Go Rot13
package main
import (
"io"
"os"
"strings"
"unicode"
)
type rot13Reader struct {
@oldergod
oldergod / trees.go
Last active August 29, 2015 14:06
Tour of Go Binary Trees
package main
import (
"code.google.com/p/go-tour/tree"
"fmt"
)
func Walk(t *tree.Tree, ch chan int) {
if t.Left != nil {
Walk(t.Left, ch)
@oldergod
oldergod / count_access_per_user.sh
Last active August 29, 2015 14:07
アクセスログから月単位でユーザID(整数5桁)毎にアクセス数をCSV形式提出
#!/bin/bash
# アクセス数を抽出するスクリプト
# yyyy/dd/*.log.bz2 しか対応しない
# アクセスログから月単位でユーザID(整数5桁)毎にアクセス数をCSVファイルに提出
declare -A USERS
# 6月から8月まで
months=( 6 7 8 )
output=~/access_count_per_user.csv
for month in ${months[@]};do