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 / singleflight.go
Last active May 29, 2025 15:16
Go: Single-Flight #go #performance #concurrency
// https://play.golang.com/p/GoyqwZ5jW_L
// https://pkg.go.dev/golang.org/x/sync/singleflight
// https://victoriametrics.com/blog/go-singleflight/index.html
package main
import (
"fmt"
"math/rand"
"sync"
@Integralist
Integralist / Programming Terminology in Go.md
Last active May 26, 2025 15:58
Code: Programming Terminology #programming #terminology

Programming Terminology in Go

1. Expression

  • Definition: A combination of values, variables, operators, and function calls that evaluates to a single value.
  • Examples:
    • 2 + 2 (evaluates to 4)
    • x * y (evaluates to the product of x and y)
    • time.Second * 10 (evaluates to a time.Duration value of 10 seconds)
  • Usage: Expressions are used to compute values. They can appear within statements, assignments, or function arguments.
@Integralist
Integralist / main.go
Last active May 29, 2025 15:16
Go: Custom Error Handling #go #errors
package main
import (
"errors"
"fmt"
"io"
)
func main() {
err := doSomething()
@Integralist
Integralist / shell-script-best-practices.md
Last active May 26, 2025 15:58
Shell: Shell Scripting Best Practices #shell #bash

Shell Script Best Practices

This article is about a few quick thumb rules I use when writing shell scripts that I’ve come to appreciate over the years. Very opinionated.

Things

  1. Use bash. Using zsh or fish or any other, will make it hard for others to understand / collaborate. Among all shells, bash strikes a good balance between portability and DX.
@Integralist
Integralist / yaml-anchors.md
Last active May 26, 2025 15:58
YAML: anchors #yaml #anchors

If you've not used YAML before you might be wondering what &<name> means.

What this will do is create an 'anchor'.

Anchors allow you to inject the associated block of data any where else within your YAML configuration file.

This allows you to avoid duplicating those particular settings.

The way to do that injection is to 'dereference' the anchor with an asterisk.

@Integralist
Integralist / slice-map.go
Last active May 29, 2025 15:16
Go: Generic Slice Map function #go #computation #generics
// https://play.golang.com/p/TbawROSRv8X
package main
import (
"fmt"
"golang.org/x/net/idna"
)
@Integralist
Integralist / delete-entry-from-slice.go
Last active May 29, 2025 15:15
Go: Delete a slice entry in Go #go #computation
// zones == complete list of dns zones
// denyList == list of zones to remove
for _, deniedZone := range denyList {
for i := 0; i < len(zones); i++ {
if zones[i] == deniedZone {
zones = append(zones[:i], zones[i+1:]...)
i-- // Adjust index to stay at the correct position after removal
}
}
}
@Integralist
Integralist / diff.go
Last active May 29, 2025 15:15
Go: Simple line-by-line diff in Go #go #utility
// Probably should just use https://github.com/sergi/go-diff
// printDiff prints the differences between two files line by line.
func printDiff(file1, file2 string) error {
f1, err := os.Open(file1)
if err != nil {
return fmt.Errorf("failed to open file1: %w", err)
}
defer f1.Close()
@Integralist
Integralist / main.go
Last active May 29, 2025 15:14
Go: Structured Logging #go #logs
// https://play.golang.com/p/tfop7CgoGF5
// https://goplay.tools/snippet/aZatTtNaElZ
package main
import (
"context"
"fmt"
"log/slog"
"os"
@Integralist
Integralist / 1. README.md
Last active May 29, 2025 15:13
Go: Bitwise Operations in Go #go #computation

Bitwise Operations in Go

In the below Go file we use bitwise operators to manipulate individual flags (on/off switches) in a single integer, where each bit position represents a different status.

Visualising Bits

In case you need a reminder of a what bit alignment and shifting look like:

example of bits in a byte