Skip to content

Instantly share code, notes, and snippets.

View dwburke's full-sized avatar

Dan Burke dwburke

  • New Relic
  • Michigan
  • 01:34 (UTC -04:00)
View GitHub Profile
@dwburke
dwburke / kube-persistent-volume.yaml
Created March 1, 2018 15:39
Kubernetes persistent volume yaml for local testing (or when local storage is what you need)
apiVersion: v1
kind: PersistentVolume
metadata:
name: pv0001
spec:
accessModes:
- ReadWriteOnce
capacity:
storage: 8Gi
hostPath:
#include <string>
#include <sstream>
#include <vector>
#include <iterator>
template<typename Out>
void split(const std::string &s, char delim, Out result) {
std::stringstream ss(s);
std::string item;
while (std::getline(ss, item, delim)) {
@dwburke
dwburke / api-main.go
Last active September 2, 2018 15:39
golang cobra command to generate self-signed cert for dev use
package api
import (
"github.com/gin-gonic/gin"
endpoint_player "github.com/dwburke/addict-service/api/player"
)
func SetupRoutes(r *gin.Engine) {
endpoint_player.SetupRoutes(r)
import "github.com/gin-gonic/gin"
func AllGinParams(c *gin.Context) gin.Params {
var params gin.Params
for _, p := range c.Params {
params = append(params, gin.Param{Key: p.Key, Value: p.Value})
}
req := c.Request
@dwburke
dwburke / main.go
Last active November 8, 2018 01:29
cobra/viper root.go template
package main
import (
"github.com/dwburke/xxxx/cmd"
)
func main() {
cmd.Execute()
}
@dwburke
dwburke / unmarshal.defaults.go
Created June 29, 2020 15:55
Default values when unmarshalling json in go
package foo
type Foo struct {
Field string `json:"field"`
}
// UnmarshalJSON is the implementation of the json.Unmarshaler interface.
func (t *Foo) UnmarshalJSON(data []byte) error {
type innerFoo Foo
inner := &innerFoo{
@dwburke
dwburke / Tprintf.go
Last active January 18, 2021 15:19
printf using template vars... I found this a while back on stackoverflow or somewhere like that... original call is commented, just using an interface was more flexible for my uses
package util
import (
"bytes"
"text/template"
)
// Example:
// str := Tprintf("{{ .Thing }} a thing a do foo, bar", data)