Skip to content

Instantly share code, notes, and snippets.

View mrichman's full-sized avatar

Mark Richman mrichman

View GitHub Profile
tr := TestResult{
URL: req.URL.String(),
Status: resp.StatusCode,
StartTime: startTime,
EndTime: endTime,
Latency: latency}
testResults = append(testResults, tr)
func EntryToRequest(entry *Entry) (*http.Request, error) {
req, _ := http.NewRequest(entry.Request.Method, entry.Request.URL, nil)
for _, h := range entry.Request.Headers {
if httplex.ValidHeaderFieldName(h.Name) && httplex.ValidHeaderFieldValue(h.Value) {
req.Header.Add(h.Name, h.Value)
}
}
for _, c := range entry.Request.Cookies {
@mrichman
mrichman / waitTimeout
Created October 24, 2016 15:46
Go waitTimeout
func waitTimeout(wg *sync.WaitGroup, timeout time.Duration) bool {
c := make(chan struct{})
go func() {
defer close(c)
wg.Wait()
}()
select {
case <-c:
return false // completed normally
case <-time.After(timeout):
@mrichman
mrichman / load.go
Created October 24, 2016 15:36
Hargo's load test
func LoadTest(r *bufio.Reader, workers int, timeout time.Duration, u url.URL) error {
c, err := NewInfluxDBClient(u)
if err != nil {
useInfluxDB = false
log.Warn("No test results will be recorded to InfluxDB")
} else {
log.Info("Recording results to InfluxDB: ", u.String())
}
// newReader returns a bufio.Reader that will skip over initial UTF-8 byte order marks.
// https://tools.ietf.org/html/rfc7159#section-8.1
func newReader(r io.Reader) *bufio.Reader {
buf := bufio.NewReader(r)
b, err := buf.Peek(3)
if err != nil {
// not enough bytes
return buf
}
@mrichman
mrichman / gist:259692006423a9fe167a69be34c15ed2
Created October 24, 2016 15:23
command structure using cli
app.Commands = []cli.Command{
{
Name: "fetch",
Aliases: []string{"f"},
Usage: "Fetch URLs in .har",
UsageText: "fetch - fetch all URLs",
Description: "fetch all URLs found in HAR file, saving all objects in an output directory",
ArgsUsage: "<.har file> <output dir>",
Action: func(c *cli.Context) {
harFile := c.Args().First()
@mrichman
mrichman / grafana_start.md
Created October 11, 2016 01:08
OSX Start Grafana Server

grafana-server --config=/usr/local/etc/grafana/grafana.ini --homepath /usr/local/share/grafana cfg:default.paths.logs=/usr/local/var/log/grafana cfg:default.paths.data=/usr/local/var/lib/grafana cfg:default.paths.plugins=/usr/local/var/lib/grafana/plugins

Keybase proof

I hereby claim:

  • I am mrichman on github.
  • I am mrichman (https://keybase.io/mrichman) on keybase.
  • I have a public key whose fingerprint is 9107 5C06 97D5 E564 8793 4822 EE68 4129 585B 1B3B

To claim this, I am signing this object:

@mrichman
mrichman / parallel-for-loop.go
Created June 10, 2016 18:14
Parallel for loop over array
wg := &sync.WaitGroup{}
results := make([]myType, len(sourceData)
for i, source := range sourceData {
wg.Add(1)
go func(i int, source mySourceType) {
defer wg.Done()
results[i] = doStuff(source)
}(i, source)
}
@mrichman
mrichman / dict.cs
Created February 2, 2016 00:22
C# vs. Go Dictionary
using System;
using System.Collections.Generic;
using System.Diagnostics;
public class DictionaryTest
{
public static void Main()
{
var cache = new Dictionary<int, int>(1000000);
var sw = Stopwatch.StartNew();