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 / README.md
Last active May 28, 2025 14:43
Homebrew: custom version install #homebrew #macOS

You can't install specific package versions using Homebrew.

If you have a version installed you can pin it:

brew pin <package>

That will prevent a brew upgrade from updating the package.

@Integralist
Integralist / 1. README.md
Last active May 29, 2025 13:41
Go: httpx.WriteJSON #go #http #json #api

Here is some problematic code...

func WriteJSON(l *slog.Logger, w http.ResponseWriter, r *http.Request, code int, v any) {
	ctx := r.Context()
	w.Header().Set("Content-Type", "application/json")
        w.WriteHeader(code)

	if err := json.NewEncoder(w).Encode(v); err != nil {
 l.LogAttrs(ctx, slog.LevelError, "encode_json_response", slog.Any("err", err))
@Integralist
Integralist / main.go
Last active May 29, 2025 13:41
Go: 1.23 iter.Seq/iter.Seq2 iterators #go #iterator
// This code demonstrates how iterators work in Go.
// This particular example is contrived, but I wanted something simple enough to demonstrate the point.
package main
import (
"fmt"
"iter"
"strings"
)
@Integralist
Integralist / README.md
Last active May 29, 2025 13:40
Go: JSON omitempty vs omitzero #go #json

Guidelines:

Tip

The super quick summary is: use omitzero
Unless you need to identify an empty map/slice/interface, then use omitempty.
If you need to identify if value was deliberately set to the zero type, use a pointer.
If you have specific zero requirements define custom type with IsZero method.

  • to filter out a nil map, use omitzero
  • to filter out a nil map and an empty map, use omitempty
@Integralist
Integralist / example.go
Last active May 30, 2025 08:42
Go: HTTP handler Write error after WriteHeader #go #http #middleware
func exampleHandler(w http.ResponseWriter, r *http.Request) {
defer func() {
if rec := recover(); rec != nil {
// The net/http server itself has a recovery mechanism that specifically looks for http.ErrAbortHandler.
// When it catches this particular panic, it knows to abort the current request handler and close the connection.
if rec == http.ErrAbortHandler {
log.Println("Handler aborted with http.ErrAbortHandler. Connection will be closed by server.")
} else {
log.Printf("Unhandled panic: %v.", rec)
}
@Integralist
Integralist / TLS, Certificate, and ACME Glossary.md
Last active May 29, 2025 13:40
TLS, Certificate, and ACME Glossary #TLS #ACME

TLS, Certificate, and ACME Glossary

This glossary defines common terms related to Transport Layer Security (TLS), digital certificates, Certificate Authorities (CAs), and the Automatic Certificate Management Environment (ACME) protocol. It's intended to help users understand the concepts involved in securing services and using APIs that manage certificate issuance, particularly focusing on Subject Alternative Names (SANs).

@Integralist
Integralist / ctxkey.md
Last active May 29, 2025 13:59
Go: Why choose tailscale.com/util/ctxkey over Go standard context package #go #ctx
@Integralist
Integralist / DNS Delegation.md
Last active March 26, 2025 18:05
DNS Delegation #dns

DNS Management and Delegation

If a domain owner wants to use another company for handling DNS management over its domain, then they can update the "Name Servers" for their domain wherever DNS is currently managed, and set the Name Servers to a different DNS provider.

This is known as DNS delegation.

Once that Name Server change has propagated, the new DNS provider will be responsible for managing DNS records for the domain.

CNAME redirection magic

@Integralist
Integralist / 1. README.md
Last active May 29, 2025 14:00
Basic Go Project Structure #go #project
.
├── Makefile
├── cmd
│   └── api
│       └── main.go
├── go.mod
├── go.sum
├── internal
│   ├── api
@Integralist
Integralist / main.go
Last active May 29, 2025 14:00
Go: Serialize and Deserialize types using gob #go #serialization
// Package gob manages streams of gobs - binary values exchanged between an Encoder
// (transmitter) and a Decoder (receiver).
package main
import (
"bytes"
"encoding/gob"
"fmt"
"log"
)