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 / organize-daily-notes.go
Created July 23, 2023 15:39
Obsidian Script to Organize Daily Notes
/* This code organizes obsidian notes in format `YYYY-MM-DD.md` in the target directory into
the following folder structure `YYYY/MM Month/YYYY-MM-DD.md`
Examples
/2023/07 July/2023-07-26.md
/2023/08 August/2023-08-01.md
/2023/10 October/2023-10-31.md
*/
package main

Sorting

Everyone does it differently 😭 and most query string parsers don't support LHS or RHS parsing or building. Prefer RHS for clarity and simplicity of parsing. I don't like the - or + operators because It's easy to over look.

Options from different sources

  • ChatGPT /users?sort=email,asc
  • RHS Single Field /users?sort=email:ASC
  • RHS Multiple Fields /users?sort=email:asc,name:desc
  • RHS Multiple Fields Keyed /users?sort=email:asc&sort=name:desc
  • LHS /users?sort=[asc]email
  • LHS Multiple Fields /users?sort=[asc]email,[desc]name
@thrawn01
thrawn01 / description.md
Last active August 14, 2023 14:38
Fix This Code

This bit of code fetches 100 integers from an endpoint called https://example.com/integers which returns { "value": 2 } . The code makes 10 concurrent requests to the endpoint so we don't trigger a rate limit and then reports a list of which integers were even and which were odd.

How would you improve the following code? Feel free to rewrite as if this was production code. There are coding mistake and often just bad form in the code, please fix it!

@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.