Custom Vagrant Cloud Versioned Box Host

With the recent addition of Atlas to the Hashicorp arsenal, Vagrant got an update to be integrated into Atlas for hosting your VM boxes and handling versioned updates. If you are still looking to have your boxes versioned and are hosting them yourself, or your company has them private, you can still achieve versioning your boxes with the latest Vagrant (1.7.2) and some manual work. In this post I will go through:

  1. Basics of building a Virtualbox Vagrant box, just enough to follow along.
  2. Building a box metadata file, used to resolve box versions and download URLs.
  3. Hooking everything up with your Vagrantfile.
Read on →

Golang Documenting Package Examples

Go has been gaining a lot of popularity recently. With a lot of the success stories centered on the performance gains switching from other languages. For me a lot of the smaller features, that shows an attention to detail, which makes it enjoyable to code in. These details are also what will help the Golang community grow as well. One of these details is the built in documentation into the language.

There is a built in go doc command with the language where you can view your package documentation locally by running an http server to serve your docs. GoDoc is the main hosting for open source packages that will build docs for your package by doing a go get and generating docs. Read on →

Golang Timed Function Wrapper

Wrote this quick and probably dirty wrapper for timing functions in Go. TimedReturn returns an interface{} in case a return value is needed from whatever you are wrapping.

package main

import (
  "fmt"
  "time"
)

type wrapped func()
type wrappedReturn func() interface{}

func Timed(fn wrapped, key string) {
  start := time.Now().Unix()
  fn()
  end := time.Now().Unix()
  fmt.Printf("Time: %d, Key: %s\n", end-start, key)
}

func TimedReturn(fn wrappedReturn, key string) interface{} {
  start := time.Now().Unix()
  resp := fn()
  end := time.Now().Unix()
  fmt.Printf("Time: %d, Key: %s]n", end-start, key)
  return resp
}

func main() {
  fn := func() {
    fmt.Println("Hello from wrapped function!")
    time.Sleep(time.Duration(1) * time.Second)
  }
  Timed(fn, "go.playground")

  fn2 := func() interface{} {
    fmt.Println("Hello from wrapped function with return!")
    time.Sleep(time.Duration(2) * time.Second)
    return []int{3}
  }
  returned := TimedReturn(fn2, "go.playground")
  fmt.Println("TimedReturn got:", returned.([]int))
}