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 / image-reduce.sh
Created January 2, 2025 15:47
[Image resize with ImageMagick] #bash #shell #imagemagick #resize #image
brew install imagemagick
magick example.png -quality 70 optimised.jpg
@Integralist
Integralist / singleflight.go
Created December 20, 2024 12:32
[Golang Single-Flight] #go #golang #singleflight #requestcollapsing #sync
// 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 December 20, 2024 10:45
[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
Created December 19, 2024 17:44
[Golang Custom Error Handling] #go #golang
package main
import (
"errors"
"fmt"
"io"
)
func main() {
err := doSomething()
@Integralist
Integralist / shell-script-best-practices.md
Created December 18, 2024 17:20
[Shell Script 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 February 15, 2025 06:40
[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
Created December 3, 2024 11:54
[Golang Generic Slice Map function] #go #golang #slices #map #functional #generics
// https://play.golang.com/p/TbawROSRv8X
package main
import (
"fmt"
"golang.org/x/net/idna"
)
@Integralist
Integralist / delete-entry-from-slice.go
Created December 3, 2024 07:10
[Delete a slice entry in Go] #go #golang #slices
// 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 December 2, 2024 10:45
[Simple line-by-line diff in Go] #go #golang #diff
// 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 December 18, 2024 15:14
[Structured Logging in Go] #go #golang #slog #log #structuredlogging
// https://play.golang.com/p/tfop7CgoGF5
// https://goplay.tools/snippet/aZatTtNaElZ
package main
import (
"context"
"fmt"
"log/slog"
"os"