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 / Install Windows on macOS with VirtualBox.md
Created February 29, 2024 10:42
[Install Windows on macOS with VirtualBox] #virtualbox #vm #windows
@Integralist
Integralist / 1. README.md
Last active March 8, 2024 13:01
[Fastly create, validate, and destroy service] #CLI #Fastly

Compute readthrough cache validator

This directory contains a Compute application that proxies incoming requests onto https://http-me.glitch.me/.

There is a run.sh script which will attempt to validate the

@Integralist
Integralist / Makefile
Last active February 23, 2024 13:15
[Download latest GitHub Asset Release] #github #asset #release
.PHONY: bin-viceroy
bin-viceroy: # Download latest version of Viceroy to ./bin/ directory
@arch=$$(uname -m | sed 's/x86_64/amd64/'); \
os=$$(uname -s | tr '[:upper:]' '[:lower:]'); \
url=$$(curl -s https://api.github.com/repos/fastly/viceroy/releases/latest | jq --arg arch $$arch --arg os $$os -r '.assets[] | select((.name | contains($$arch)) and (.name | contains($$os))) | .browser_download_url'); \
filename=$$(basename $$url); \
curl -sLO $$url && mkdir -p bin && tar -xzvf $$filename --directory ./bin/ && \
./bin/viceroy --version && rm $$filename && sudo cp ./bin/viceroy /usr/local/bin/viceroy # NOTE: sudo is a no-op in GitHub Actions
@Integralist
Integralist / main.go
Created February 9, 2024 10:30
[Go type cast] #go #golang
// https://play.golang.com/p/fLovZCiAzn1
package main
import (
"fmt"
)
type myString string
func main() {
@Integralist
Integralist / 1. README.md
Last active April 10, 2024 00:53
[Golang slog structure logging] #go #golang #log #logging #structuredlogs
@Integralist
Integralist / main.go
Last active February 7, 2024 12:34
[Go copy struct from pointer] #go #golang
// structs are considered a primitive type and as such are passed by value.
// but if you have a pointer to struct you need to be careful not to assign it to a variable thinking you're getting a copy of the 'value'.
// you're only getting a copy of the 'pointer'! which means the newly assigned variable will mutate the underlying struct.
// so to make a copy you have to dereference the struct pointer first.
package main
import "fmt"
type Foo struct {
@Integralist
Integralist / main.go
Created January 18, 2024 12:30
[Golang init] #go #golang
// This is a file designed to be run on go.dev/play (link below).
// It validates the behaviour of init() functions.
// i.e. init() is only called once regardless of how many times its package is imported.
// https://go.dev/play/p/99YpDma6mVJ
package main
import (
"play.ground/bar"
"play.ground/foo"
)
@Integralist
Integralist / main.go
Last active January 12, 2024 15:52
[Go pointer receiver method avoids runtime panic] #go #golang
// https://play.golang.com/p/NOxcQO8U-G7
//
// IMPORTANT: Even though you can call the pointer receiver method, you still can't access a field without triggering a runtime panic. But just being able to call the method is still useful/interesting.
//
// The explanation for this is as follows...
//
// There’s two things going on here. The first is calling a method. Go knows which method to call thanks to the name of the method and the type of the receiver. That’s all there is to knowing which method to call.
// e.g. The Go runtime evaluates the code `e.PointerMethod()` into something like `(*Example).PointerMethod(e)`.
// The trick to understand the rest is to remember that having a pointer be nil is not a reason to panic just yet. You only panic when you try to do something that needs to dereference that nil pointer.
// Now when the method gets called, the sugared version (e.g. `(*Example).PointerMethod(e)`) shows that the first argument is the receiver.
@Integralist
Integralist / template.sh
Created December 15, 2023 12:25
[Generate OpenAPI schema dynamically] #openapi #template #bash #shell
#!/bin/bash
AWK_PATH=$(which awk)
CAT_PATH=$(which cat)
read -rp "Enter API Version (e.g. 1.0.0): " VERSION
read -rp "Enter API Title: " TITLE
read -rp "Enter API Description: " DESCRIPTION
read -rp "Enter Your Name (for contact info): " NAME
read -rp "Enter Your Email (for contact info): " EMAIL
@Integralist
Integralist / README.md
Last active November 17, 2023 12:56
[Go range bug] #go #golang #range

Problem

Consider the following example:

package main

import "fmt"

func main() {