Skip to content

Instantly share code, notes, and snippets.

View dwburke's full-sized avatar

Dan Burke dwburke

  • New Relic
  • Michigan
  • 11:11 (UTC -05:00)
View GitHub Profile
@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)
@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 / 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()
}
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 / 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)
#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 / 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:
@dwburke
dwburke / Pipe.h
Last active February 17, 2018 13:52
Pipe :: Class for running a system command and capturing output, automatically closing when it goes out of scope
class Pipe {
public:
Pipe() {};
Pipe(char *command, char *mode) {
open(command, mode);
};
~Pipe() {
if (pfp)
pclose(pfp);
@dwburke
dwburke / Factory.h
Last active July 9, 2024 15:40
c++ factory
#pragma once
template <typename T, typename KEYT, typename... Args>
class Factory
{
public:
template <typename TDerived>
void registerType(KEYT key)
{
static_assert(std::is_base_of<T, TDerived>::value, "Factory::registerType doesn't accept this type because doesn't derive from base class");
@dwburke
dwburke / create_kube_sa.sh
Created August 3, 2017 18:34
Create kubernetes service account
#!/bin/bash
set -eu
die () {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 1 ] || die "Usage: $0 <username>"