Skip to content

Instantly share code, notes, and snippets.

@gambrell
gambrell / postJson.go
Created September 23, 2015 20:56
http post json
func postJson(url string, jsonStr []byte) {
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
panic(err)
}
@gambrell
gambrell / randomInt.go
Created September 23, 2015 20:55
golang randomInt
func randomInt(min int, max int) int {
// min and max inclusive
// assumes Seed has been set once for the program
// use something like rand.Seed(time.Now().UTC().UnixNano())
return min + rand.Intn(max-min+1)
}
@gambrell
gambrell / epoch.go
Created September 23, 2015 20:54
golang epoch
func epoch() int64 {
return time.Now().Unix()
}
@gambrell
gambrell / logstash-remove-nulls.conf
Created March 19, 2015 13:47
Logstash filter to remove embedded NULL characters
# Logstash filter to remove embedded NULL characters
filter {
mutate {
gsub => [
# Replace all NULL characters empty string. Do this to the message field first which will apply to all fields instead of specifying individual fields.
"message", "[\u0000]", ""
]
}