Skip to content

Instantly share code, notes, and snippets.

@pauladam
Created July 15, 2015 17:10
Show Gist options
  • Save pauladam/19f216a16fa3fd49322e to your computer and use it in GitHub Desktop.
Save pauladam/19f216a16fa3fd49322e to your computer and use it in GitHub Desktop.
scribe
// ex
// $ gb build all; bin/scribe
// scribe
// Jesse
package main
import "os"
import "fmt"
import "time"
import "bufio"
import "math/rand"
func main() {
var i int
var index int
var name string
var names []string
var nameMap = make(map[int][]string)
var dayOfWeek = int(time.Now().Weekday()) - 1
inFile, _ := os.Open("/Users/PaulHowe/Documents/analytics/names")
defer inFile.Close()
scanner := bufio.NewScanner(inFile)
scanner.Split(bufio.ScanLines)
// add names and loop around after we have one
// cycle
i = 0
for scanner.Scan() {
name = scanner.Text()
index = int(i) % 5 // # work days
names = append(names, name)
nameMap[index] = append(nameMap[index], name)
i = i + 1
}
// pull the scribe based on the day, randomly selecting an individual if
// there is more than one possible scribe on the current day
rand.Seed(time.Now().UTC().UnixNano())
fmt.Println(nameMap[dayOfWeek][rand.Intn(len(nameMap[dayOfWeek]))])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment