Skip to content

Instantly share code, notes, and snippets.

View Integralist's full-sized avatar
🎯
Making an impact

Mark McDonnell Integralist

🎯
Making an impact
View GitHub Profile
@Integralist
Integralist / .muttrc
Last active April 12, 2024 19:26
Mutt configuration and usage
# http://www.mutt.org/doc/manual/
# decrypt passwords
source "gpg -d ~/.mutt/passwords.gpg |"
# Change the following six lines to match your Gmail account details
set imap_user = "mark.mcdx@gmail.com"
set smtp_url = "smtp://mark.mcdx@gmail.com@smtp.gmail.com:587/"
set smtp_authenticators = "gssapi:login"
set from = "mark.mcdx@gmail.com"
@Integralist
Integralist / Go API JSON Issues.md
Last active April 10, 2024 08:55
[Go API JSON Issues] #go #golang #json #api #omitempty

Reference: https://willnorris.com/2014/05/go-rest-apis-and-pointers/

If a struct field isn't populated, and is marshalled to JSON, then the field's zero value will be used (e.g. type string zero value == "", type int zero value == 0).

You can use omitempty to prevent the field from being marshalled, but then you won't know if the zero value was intentional or not (e.g. a user might want to set an type int field to zero or a type string field to an empty string).

To avoid that situation you need to have the field be set to a pointer of the type. This is because the zero value for a pointer is nil. This means if the field is nil then the field was never set but if it looks like a zero value for the type being pointed to, then you know it was set to the zero value intentionally.

@Integralist
Integralist / 1. README.md
Last active April 10, 2024 00:53
[Golang slog structure logging] #go #golang #log #logging #structuredlogs
  • Dynamic Dispatch
  • Dynamic Method
  • Ghost Methods
  • Dynamic Proxies
  • Blank Slate
  • Kernel Method
  • Flattening the Scope (aka Nested Lexical Scopes)
  • Context Probe
  • Class Eval (not really a 'spell' more just a demonstration of its usage)
  • Class Macros
@Integralist
Integralist / netcat.py
Created September 18, 2016 19:19
Netcat in Python
# pylint: disable-all
# flake8: noqa
import sys
import socket
import getopt
import threading
import subprocess
listen = command = upload = False
@Integralist
Integralist / Upstream vs Downstream.md
Last active April 2, 2024 14:01
[Upstream vs Downstream] #upstream #downstream

Upstream

Upstream components are other parts of the system that your component depends on to do its job.

If the design of an upstream component changes, the ability of your component to function may be affected.

If an upstream component has a bug, this bug may be manifested in your component.

Downstream

@Integralist
Integralist / 1. install.sh
Last active April 2, 2024 11:14
[Redis Install and Examples] #redis #install #macos
brew install redis
brew services start redis
@Integralist
Integralist / 0. README.md
Last active March 28, 2024 07:47
[Golang CLI Flags and Subcommands] #tags: golang, go, cli, flags, subcommands, logs, logging

Three approaches...

  1. Flags are known up front. 👌🏻
  2. Flags are defined by user (ugly data structure). ❌
  3. Flags are defined by user (dynamic struct creation BUT doesn't work fully) ❌
  4. Flags are defined by user (dynamic population of a struct provided by the user) ✅

flag.FlagSet ?

Note: the trick to understanding flag.NewFlagSet is that you have to pass it a string of command line args that you need it to parse. flag.Parse is able to do this automatically for you, but a flag set is expected to work with a subset of the arguments provided to the program when it's being run. The way I typically do this is as follows...

@Integralist
Integralist / 1. middleware.go
Last active March 27, 2024 12:03
[Go basic middleware abstraction] #go #golang #middleware
// THIS IS THE REDESIGNED VERSION (see 3. middleware.go for my original approach)
package middleware
import (
"net/http"
)
// Decorator is a middleware function.
type Decorator func(http.Handler) http.Handler