Skip to content

Instantly share code, notes, and snippets.

View comtom's full-sized avatar

Tomás Dowling comtom

View GitHub Profile

Keybase proof

I hereby claim:

  • I am comtom on github.
  • I am comtom (https://keybase.io/comtom) on keybase.
  • I have a public key whose fingerprint is 131E 694F 783E B32F 7AA2 D216 19EE 87EA E285 F732

To claim this, I am signing this object:

@comtom
comtom / type.go
Last active September 27, 2018 17:45
func f1(arg int) (int, error) {
if arg == 42 {
return -1, errors.New("can't work with 42")
}
return arg + 3, nil
}
if rresult, err := f1(i); err != nil {
fmt.Println("f1 failed:", err)
}
var firstVar interface{}
firstVar = "this is a string"
firstString, ok := firstVar.(string)
if (!ok) {
fmt.Printf("firstString is not a string, do something about it! Value:'%v'\n", firstString)
}
go func(msg string) {
fmt.Println(msg)
}("going")
@comtom
comtom / var_func.go
Last active September 27, 2018 18:55
func sum(nums ...int) {
fmt.Print(nums, " ")
total := 0
for _, num := range nums {
total += num
}
fmt.Println(total)
}
func main() {
sum(1, 2)
@comtom
comtom / pkg.go
Created September 27, 2018 18:58
package main
import "fmt"
func worker(done chan bool) {
fmt.Print("working...")
time.Sleep(time.Second)
fmt.Println("done")
done <- true
}
func main() {
done := make(chan bool, 1)
go worker(done)
@comtom
comtom / channels3.go
Last active September 27, 2018 19:31
import "golang.org/x/sync/errgroup"
...
g, ctx := errgroup.WithContext(ctx)
complete := make(chan []Store, len(locations))
for _, location := range locations {
g.Go(fetchStores(ctx, store.Id, complete))
}
if err := g.Wait(); err != nil {
log.Errorf("%s", err)
@comtom
comtom / pprof.bash
Last active September 27, 2018 19:44
1.sh
#!/bin/bash
go test -cpuprofile cpu.prof -memprofile mem.prof -bench .
pprof -http=:6060 -alloc_objects mem.prof
pprof -http=:6060 cpu.prof
package main
import "fmt"
func main() {
messages := make(chan string)
signals := make(chan bool)
select {
case msg := <-messages:
fmt.Println("received message", msg)