Skip to content

Instantly share code, notes, and snippets.

View matryer's full-sized avatar
🔨
Building things at @grafana

Mat Ryer matryer

🔨
Building things at @grafana
View GitHub Profile
cfg := nsq.NewConfig()
producer, err := nsq.NewProducer("127.0.0.1:4161", cfg)
if err != nil {
fatal(err)
}
producer.Publish("topic", []byte("Test"))
producer.Stop()
{
"snippets": [
{
"match": {"global": true, "pkgname": ".", "fn": ".*_test.go"},
"snippets": [
{"text": "func Test", "title": "", "value": "func Test${1:ObjectName}${2:TestName}(t *testing.T) {\n\t$0\n}"},
{"text": "func Benchmark", "title": "", "value": "func Benchmark${1:ObjectName}${2:BenchmarkName}(b *testing.B) {\n\n\tb.StopTimer()\n\n\t$0\n\n\tb.StartTimer()\n\n\tfor i := 0; i < b.N; i++ {\n\t\t\n\t}\n\n}"},
{"text": "func Example", "title": "", "value": "func Example${1:ObjectName}${2:ExampleName}() {\n\n\t$0\n\n\t// Output:\n\t// \n\n}"}
]
},
@matryer
matryer / quiz.go
Last active October 22, 2018 23:08
golanguk.com quiz
package main
import (
"fmt"
)
/*
Question:
What will be printed by this program?
@matryer
matryer / example.silk.md
Created January 13, 2016 17:00
Example Silk API test file

Comments

POST /comments

Create a comment.

  • Content-Type: "application/json"
  • Accept: "application/json"
@matryer
matryer / params.go
Created August 28, 2016 13:44
Simple path parameter parsing function for Go
// pathParams parses the URL.Path of the Request with the given
// pattern, and extracts the value for each segment into a map.
func pathParams(r *http.Request, pattern string) map[string]string {
params := map[string]string{}
pathSegs := strings.Split(strings.Trim(r.URL.Path, "/"), "/")
for i, seg := range strings.Split(strings.Trim(pattern, "/"), "/") {
if i > len(pathSegs)-1 {
return params
}
params[seg] = pathSegs[i]
@matryer
matryer / params_test.go
Created August 28, 2016 13:52
Simple path parameter parsing function tests
func TestPathParams(t *testing.T) {
r, err := http.NewRequest("GET", "1/2/3/4/5", nil)
if err != nil {
t.Errorf("NewRequest: %s", err)
}
params := pathParams(r, "one/two/three/four")
if len(params) != 4 {
t.Errorf("expected 4 params but got %d: %v", len(params), params)
}
for k, v := range map[string]string{
### Keybase proof
I hereby claim:
* I am matryer on github.
* I am matryer (https://keybase.io/matryer) on keybase.
* I have a public key ASCC8YrsmU_t9rWCOgUqUGE0Zv9wb519A25FyiDH7xMXfAo
To claim this, I am signing this object:
@matryer
matryer / speaker.go
Created May 21, 2017 15:49
Speaks the names of people detected from facebox (Machine Box)
package main
import (
"encoding/json"
"log"
"os"
"os/exec"
)
type result struct {
@matryer
matryer / term_context.go
Last active March 10, 2022 05:23
Making Ctrl+C termination cancel the context.Context
func main() {
ctx := context.Background()
// trap Ctrl+C and call cancel on the context
ctx, cancel := context.WithCancel(ctx)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
defer func() {
signal.Stop(c)
@matryer
matryer / sending_mock.go
Created July 11, 2017 21:25
Moq generated mock of a simple interface
package sending
// AUTOGENERATED BY MOQ - DO NOT EDIT
// github.com/matryer/moq
import (
"sync"
)
var (