Skip to content

Instantly share code, notes, and snippets.

View thrawn01's full-sized avatar
🎯
Focusing

Derrick J. Wippler thrawn01

🎯
Focusing
View GitHub Profile
@thrawn01
thrawn01 / dist.go
Created June 12, 2023 22:10
Distribution plot of rand.Shuffle() on a 3 item array 1000 times
package main
import (
"image/color"
"log"
"math/rand"
"gonum.org/v1/plot"
"gonum.org/v1/plot/plotter"
)
@thrawn01
thrawn01 / structToYAMLNode.go
Last active June 8, 2023 02:13
A bit of code to convert a struct into yaml.Node structure.
import "gopkg.in/yaml.v3"
func StructToYAMLNode(data interface{}, node *yaml.Node) error {
value := reflect.ValueOf(data)
switch value.Kind() {
case reflect.Struct:
// If the struct has a `String()` method call that instead
if strMethod := value.MethodByName("String"); strMethod.IsValid() {
obj := strMethod.Call(nil)[0].Interface()
@thrawn01
thrawn01 / result.go
Created April 20, 2023 01:33
The code that ChatGPT gave me
package main
import (
"fmt"
"io"
"math/rand"
"time"
)
type Job struct {
@thrawn01
thrawn01 / prompt.go
Created April 20, 2023 01:32
The code I gave ChatGPT
type Job struct {
Id int
FileName string
FSType string
Status string
}
type Store1 interface {
GetBatchID() int
}
// Distribute takes the slice of IonosUsers and distributes export jobs. Any errors during export are collected
// into the Supervisor's errorMap. This will return a ErrExportHadFailures error if any AppIDs failed to export
func (s *Supervisor) Distribute(ctx context.Context, exportUsers []IonosUser) error {
pool := conc.NewWithResults[int64]().WithMaxGoroutines(s.numWorkers).WithErrors().WithContext(ctx)
for _, user := range exportUsers {
pool.Go(func(c context.Context) (int64, error) {
err := s.ExportAppID(c, user)
if err != nil {
// To allow for recovery file creation
commit b1fbfd306a573e327cc2aac9176e7d43ec87e17d
Author: Derrick Wippler <[email protected]>
Date: Thu Sep 23 16:46:02 2021 -0500
WIP: added steve job library
diff --git a/steve/README.md b/steve/README.md
new file mode 100644
index 0000000..e75ce66
--- /dev/null

Timecop Service

Timecop is a service which is handles various public API and SMTP testing tools.

Testing email send round trip

Timecop periodically sends emails to it's self through Mailgun public HTTP and SMTP servers. It attaches a special header with a timestamp of when the email was sent, when timecop receives the email via it's own SMTP server running on port 25, it compares the send timestamp with the current time and emits a round trip metric via prometheus. If the round trip time is longer than a set thresh hold it alerts the pipeline team via pagerduty.

@thrawn01
thrawn01 / workerpool.go
Last active June 15, 2020 23:08
Simple WorkerPool Implementation
package main
import (
"io"
"log"
"net"
_ "net/http/pprof"
"strings"
"sync"
"sync/atomic"
@thrawn01
thrawn01 / printf-array-scan.go
Created May 12, 2020 15:34
Take []byte output from printing with fmt.Printf("%v", myBytes) and convert it back into a golang []byte
package main
import (
"fmt"
"strings"
)
func main() {
// [ and ] have been manually removed
s := "76 105 99 32 83 105 110 100 105 97 32 78 117 241"
client := http.Client{
Transport: &http2.Transport{
// So http2.Transport doesn't complain the URL scheme isn't 'https'
AllowHTTP: true,
// Pretend we are dialing a TLS endpoint.
// Note, we ignore the passed tls.Config
DialTLSContext: func(ctx context.Context, n, a string, _ *tls.Config) (net.Conn, error) {
var d net.Dialer
return d.DialContext(ctx, n, a)
},