Skip to content

Instantly share code, notes, and snippets.

@mohae
mohae / gist:16862996c67baba1fdac20160df37fdf
Last active March 22, 2017 19:23
exec.Command on windows with spaces in the path
package main
import (
"bytes"
"fmt"
"os/exec"
)
func main() {
cmd := exec.Command("C:\\Program Files (x86)\\Notepad++\\notepad++.exe", "C:\\Program Files (x86)\\Notepad++\\LICENSE")
package ex
type Foo struct {
Val string
}
func (f *Foo) Bar() string {
return f.Val
}
@mohae
mohae / gist:54c1b0e2cba548e61e9ad73df0d8d5e3
Created December 20, 2016 23:42
3 parm vs 2 parm slice make
package main
import (
"fmt"
)
func main() {
b := make([]byte, 0, 4096)
fmt.Printf("len: %d\t\tcap: %d\t%#v\n", len(b), cap(b), b)
package main
import "fmt"
var foo = map[string]func(){}
func init() {
foo["a"] = a
foo["b"] = b
}
package main
import "fmt"
var foo = map[string]func(){}
func init() {
foo["a"] = a
foo["b"] = b
}
@mohae
mohae / gist:b3078498205b314daede9e98242a1dc6
Last active October 19, 2016 17:48
deepcopy test time copy
type T struct {
time.Time
}
func TestTimeCopy(t *testing.T) {
tests := []struct{
Y int
M time.Month
D int
h int
package main
import (
"encoding/json"
"fmt"
"time"
"github.com/mohae/deepcopy"
)
Group Name Ops ns/Op B/Op Allocs/Op
------------------------------------------------------------------------------------------
CPU joefriday/cpu/facts.Get 200000 8590 800 18
CPU joefriday/cpu/stats.Get 200000 7706 264 4
CPU DataDog/gohai/cpu.Cpu.Collect 10000 273546 999489 822
CPU shirou/gopsutil/cpu.Info 50000 32987 9656 120
CPU shirou/gopsutil/cpu.Times 50000 27780 10384 28
Memory joefriday/mem.Get 200000 7746 352 1
package main
import (
"fmt"
"os"
"os/exec"
"github.com/mohae/randchars"
)
@mohae
mohae / gist:0cc9ffb700c25313f23aa749e050789c
Created July 27, 2016 22:30
benchmark for @atomi's bench stuff
package min
import (
"testing"
)
var (
n10 = []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
n50 = []int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
n100 = []int{