Skip to content

Instantly share code, notes, and snippets.

View peterhellberg's full-sized avatar
💙
Coding Go

Peter Hellberg peterhellberg

💙
Coding Go
View GitHub Profile
@peterhellberg
peterhellberg / zen.go
Created August 19, 2014 11:24
Return zen proverb from the GitHub API
package main
import (
"fmt"
"io/ioutil"
"net/http"
"os"
)
func main() {
@peterhellberg
peterhellberg / download_swansong_data.go
Created October 7, 2014 22:24
Script used to download some data in order to run the code over at https://github.com/annaloverus/swansong
package main
import (
"fmt"
"io"
"net/http"
"os"
)
var (
@peterhellberg
peterhellberg / build.sh
Created November 3, 2014 22:52
Set build date using the Go linker
#!/bin/bash
go build -ldflags "-X main.buildDate `date -u +%Y-%m-%d.%H%M%S`"
@peterhellberg
peterhellberg / month.go
Created December 7, 2014 13:47
A Formula for the Number of Days in Each Month implemented in Go
package month
import "math"
func Length(n int) int {
f := float64(n)
return 28 + int(f+math.Floor(f/8))%2 + 2%n + 2*int(math.Floor(float64(1)/f))
}
@peterhellberg
peterhellberg / largenumbers.go
Last active August 29, 2015 14:12
Example of the Law of large numbers by rolling dice in Go
package main
import (
"flag"
"math/rand"
"time"
"code.google.com/p/plotinum/plot"
"code.google.com/p/plotinum/plotter"
"code.google.com/p/plotinum/plotutil"
@peterhellberg
peterhellberg / best-movies.go
Created December 29, 2014 11:15
Sort movie releases by IMDb rating
package main
import (
"flag"
"fmt"
"io/ioutil"
"sort"
"bitbucket.org/chrj/go-imdb"
"github.com/peterhellberg/release"
@peterhellberg
peterhellberg / actor-graph.go
Last active August 29, 2015 14:12
Actor graph using release, gographviz and go-imdb
package main
import (
"flag"
"fmt"
"io/ioutil"
"strings"
"bitbucket.org/chrj/go-imdb"
"code.google.com/p/gographviz"
package main
import (
"flag"
"image"
"image/color"
"image/gif"
"image/jpeg"
"image/png"
"log"
@peterhellberg
peterhellberg / dyno_usage.go
Created August 11, 2015 20:49
List all dynos in an organisation on Heroku using the hk tool.
package main
import (
"encoding/json"
"flag"
"os"
"os/exec"
"strings"
"time"
)
@peterhellberg
peterhellberg / lychrel.go
Created August 29, 2015 18:49
Naïve (brute-force) implementation of a Lychrel number classifier in Go
package main
import (
"flag"
"fmt"
"math/big"
"os"
"time"
)