Skip to content

Instantly share code, notes, and snippets.

@veggiemonk
veggiemonk / go_resources.md
Last active September 3, 2023 19:02
Resources about Go (Golang)

Go Resources

Now and then, people ask me how to learn Go. Note that this is just my opinion, do what works for you.

The best book to learn Go and how to think in Go: https://www.gopl.io/

Don't worry about learning generics, learn the mindset and the standard library, it will save you hours of pain later.

Must read:

@veggiemonk
veggiemonk / readme.md
Created May 16, 2023 13:28
starting a fake kubernetes cluster without docker or VMs

Testing kubernetes manifests without a cluster or cluster

The start.sh script is using kwok and Go.

To delete the cluster: kowkctl delete cluster --name fake

@veggiemonk
veggiemonk / badge.go
Created April 27, 2023 09:17
utility to download badge for go test coverage
func badgedl(pct float64) error {
color := ""
switch {
case pct < 50:
color = "orange"
case pct < 60:
color = "yellow"
case pct < 70:
color = "yellowgreen"
case pct < 80:
@veggiemonk
veggiemonk / gencert.go
Created February 5, 2023 01:53
Generate a self-signed certificate in Go
package main
import (
"bytes"
"crypto/ecdsa"
"crypto/elliptic"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
@veggiemonk
veggiemonk / main.go
Created December 29, 2022 11:41
simple docker client
package main
import (
"context"
"fmt"
"github.com/docker/docker/api/types"
"github.com/docker/docker/client"
)
@veggiemonk
veggiemonk / kant_dark.icls
Created December 25, 2022 11:44
IntelliJ / Goland dark theme - based on https://github.com/abrookins/kant
This file has been truncated, but you can view the full file.
<scheme name="Kant Dark" version="142" parent_scheme="Darcula">
<option name="FONT_SCALE" value="1.0" />
<metaInfo>
<property name="created">2022-12-24T19:40:03</property>
<property name="ide">GoLand</property>
<property name="ideVersion">2022.3.1.0.0</property>
<property name="modified">2022-12-24T19:40:11</property>
<property name="originalScheme">Kant Dark</property>
</metaInfo>
<option name="LINE_SPACING" value="1.2" />
@veggiemonk
veggiemonk / assert.go
Last active December 17, 2022 00:09
go testing framework with generics
package testutils
import "testing"
func equal[T comparable](a, b T) bool {
return a == b
}
func Equal[T comparable](t *testing.T, expected, actual T) {
if !equal(expected, actual) {
@veggiemonk
veggiemonk / jwt_function.sh
Created November 2, 2022 14:02
JWT with jq
# extract jwt token info
function jwtd () {
if [[ -x $(command -v jq) ]]; then
jq -R 'split(".") | .[0],.[1] | @base64d | fromjson' <<< "${1}"
echo "{\"Signature\": \"$(echo "${1}" | awk -F'.' '{print $3}')\"}"
fi
}
# Show the experiation date
# NOTE: on a mac, it needs coreutils for the date (use with `gdate`)

Capture a movie on your phone of the object by walking around it. If possible shoot it from different angles e.g. from above looking down, below looking up, side on etc. When you film it, walk around it or move the camera around it in a full 360 revolution (or even a couple of revolutions). You should get something like this (note that the image below is a resized copy of the orignal downrated to 1 fps):

DrinkingFountainSmall

Put the video into an empty folder and then use ffmpeg to extract the frames. You can experiment with different frame rates but generally there will be little value in extracting at 60fps or whatever your phone natively shoots at.

If you are on an iPhone you may need to convert your movie from .HEIC format first:

Archiving Websites

Every so often, you may find yourself needing to preserve a website in its current state. Whether this is in advance of a significant website change, general documentation, or the possibility that the site needs to be taken offline, it is a good idea to archive the site so that it is navigable locally and without the need for a server.

Introducing HTTrack HTTrack Website Copier will do just that, download a website to a local directory, build all the directories, get HTML, images, and other files from the server to your computer.

HTTrack has a GUI for Windows that works really well: http://www.httrack.com . You can also use this tool from the command line. See the following steps to archive websites using the HTTrack command line tools.

MacOS Installation: First, you will need to install HTTrack locally. On macOS, https://brew.sh/ is the package manager of choice (as opposed to MacPorts). Homebrew is simpler to set up but does require you