Skip to content

Instantly share code, notes, and snippets.

Avatar
:shipit:
SHIP IT

Benoît Quenaudon oldergod

:shipit:
SHIP IT
View GitHub Profile
@oldergod
oldergod / maps.go
Created Sep 11, 2014
Tour of Go Maps
View maps.go
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 / slices.go
Created Sep 11, 2014
Tour of Go Slices
View slices.go
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 / fibonacci.go
Last active Aug 29, 2015
Tour of Go Fibonacci
View fibonacci.go
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 Sep 13, 2014
Tour of Go Complex Cube Roots
View cubes.go
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
View sqrt_negative.go
package main
import (
"fmt"
"math"
)
type ErrNegativeSqrt float64
func (e ErrNegativeSqrt) Error() string {
@oldergod
oldergod / server.go
Created Sep 15, 2014
Tour of Go Http Handlers
View server.go
package main
import (
"fmt"
"net/http"
)
type String string
type Struct struct {
Greeting string
@oldergod
oldergod / trees.go
Last active Aug 29, 2015
Tour of Go Binary Trees
View trees.go
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 / image.go
Last active Aug 29, 2015
Tour of Go Image
View image.go
package main
import (
"code.google.com/p/go-tour/pic"
"image"
"image/color"
)
const DIM = 1024
@oldergod
oldergod / rot13.go
Created Sep 16, 2014
Tour of Go Rot13
View rot13.go
package main
import (
"io"
"os"
"strings"
"unicode"
)
type rot13Reader struct {
@oldergod
oldergod / count_access_per_user.sh
Last active Aug 29, 2015
アクセスログから月単位でユーザID(整数5桁)毎にアクセス数をCSV形式提出
View count_access_per_user.sh
#!/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