Greg Donald : 2015/01 Archive

Raspberry Pi LEDs Test

#!/usr/bin/env python3 import time import RPi.GPIO as GPIO GPIO.setmode( GPIO.BCM ) ENABLE = 1; DISABLE = 0 RED = 23; GREEN = 24; BLUE = 25 RGB = [ RED, GREEN, BLUE ] RGB2 = RGB[::-1]

Read More...

raspberry-pi (2)

Shell script to automate go lang pkg test coverage

#!/bin/sh PACKAGE=mypkg # set mode go test -coverprofile=coverage.out $PACKAGE go tool cover -func=coverage.out go tool cover -html=coverage.out # count mode go test -covermode=count -coverprofile=count.out $PACKAGE go tool cover -func=count.out go tool cover -html=count.out # more info: http://blog.golang.org/cover

Read More...

go-lang (3) testing (2)

go log function

func log(s ...interface{}) { f, err := os.OpenFile("info.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { fmt.Printf("error opening log file: %v", err) os.Exit(1) } defer f.Close() log.SetOutput(f) ss := "" for _, p := range s { switch p.(type) { case bool: ss += fmt.Sprintf("%t ", p.(bool)) case int: ss += fmt.Sprintf("%d ", p.(int)) case float64: ss += fmt.Sprintf("%.2f ", p.(float64)) case string: ss += fmt.Sprintf("%s ", p.(string)) } } log.Println(ss) }

Read More...

go-lang (3)