Skip to content

Instantly share code, notes, and snippets.

View cep21's full-sized avatar

Jack Lindamood cep21

View GitHub Profile
@cep21
cep21 / abstract_example.go
Last active March 20, 2020 16:06
Example of interface wrapping erasure
package main
// Given an interface
type I interface {
Func()
}
// And another interface
type I2 interface {
Another()
@cep21
cep21 / pprof_example.txt
Created December 15, 2016 00:13
pprof from console
> go tool pprof 'localhost:6060/debug/pprof/my_experiment_thing?debug=1'
Fetching profile from http://localhost:6060/debug/pprof/my_experiment_thing?debug=1
Saved profile in /Users/.../pprof/pprof.localhost:6060.my_experiment_thing.007.pb.gz
Entering interactive mode (type "help" for commands)
(pprof) top30
6 of 6 total ( 100%)
flat flat% sum% cum cum%
6 100% 100% 6 100% main.usesAResource
0 0% 100% 2 33.33% main.main.func3
0 0% 100% 2 33.33% net/http.(*ServeMux).ServeHTTP
@cep21
cep21 / pprof.go
Last active December 15, 2016 00:02
Example of how to use a custom pprof profile
package main
import (
"fmt"
"log"
"net/http"
_ "net/http/pprof"
"os"
"runtime/pprof"
"sync/atomic"
my_experiment_thing profile: total 6
4 @ 0x2245 0x5d961
# 0x2244 main.usesAResource+0x64 /Users/.../pproftest.go:64
2 @ 0x2245 0x2574 0x9c184 0x9d56f 0x9df7d 0x9aa07 0x5d961
# 0x2244 main.usesAResource+0x64 /Users/.../pproftest.go:64
# 0x2573 main.main.func3+0x13 /Users/.../pproftest.go:79
# 0x9c183 net/http.HandlerFunc.ServeHTTP+0x43 /usr/local/Cellar/go/1.7.1/libexec/src/net/http/server.go:1726
# 0x9d56e net/http.(*ServeMux).ServeHTTP+0x7e /usr/local/Cellar/go/1.7.1/libexec/src/net/http/server.go:2022
# 0x9df7c net/http.serverHandler.ServeHTTP+0x7c /usr/local/Cellar/go/1.7.1/libexec/src/net/http/server.go:2202
package main
import (
"bytes"
"fmt"
"reflect"
)
func main() {
buf := bytes.Buffer{}
s := Stats{}
go s.Loop(ctx)
fmt.Println("I started service", s)
@cep21
cep21 / stats.go
Last active November 15, 2016 06:54
type Stats struct {
prev runtime.MemStats
}
func (p *Stats) stats() {
ms := runtime.MemStats{}
runtime.ReadMemStats(&ms)
mallocCount := ms.Mallocs - p.prev.Mallocs
fmt.Println("malloc change is", mallocCount)
p.prev = ms
package main
import (
"app"
"store"
)
func main( {
// ./store_main.go:9: cannot use Store literal (type *Store) as type app.Renderable in argument to app.RunApplication:
// *Store does not implement app.Renderable (wrong type for RenderPage method)
package app
type Totaller interface {
Subtotal() float64
}
type Renderable interface {
RenderPage(t Totaller)
}
package news
type Totaller interface {
Subtotal() float64
}
type NewsfeedRenderable struct {}
func (n *NewsfeedRenderable) RenderPage(t Totaller) {