Skip to content

Instantly share code, notes, and snippets.

View fkurz's full-sized avatar

Friedrich Kurz fkurz

View GitHub Profile
@fkurz
fkurz / is_docker_disk_space_usage_above_limit.sh
Last active April 8, 2024 07:58
bash-docker-is-disk-space-usage-above-limit
#!/bin/bash
# --
# Test if Docker daemon disk space usage is above a given limit in bytes.
#
# Example 1: Docker disk space usage is above limit
#
# $ source is_docker_disk_space_usage_above_limit.sh
# $ is_docker_disk_space_usage_above_limit 1
# Docker disk space usage is above limit (actual: 1050000005B, limit: 1B)
# $ printf $?
@fkurz
fkurz / tfsec-how-to-ignore-multiple-errors.md
Last active June 7, 2021 17:37
tfsec: how to ignore multiple errors

How To Ignore Multiple tfsec Errors

I stumbled upon this today when I wanted to get a precommit hook running again that runs tfsec.

If we want to ignore multiple errors with tfsec, then we can use the -e flag and a comma separated string.

E.g. if we have a s3.tf violating AWS001, AWS002, and AWS017, we'll get the following output from tfsec:

$ tfsec
@fkurz
fkurz / haskell-shell.md
Last active February 17, 2021 14:40
Haskell Shell Scripting with GHCI and Turtle

Shell scripting with Haskell

Problem

Shell scripting is kinda broken:

  • Shell scripting languages differ or are interpreted with subtle differences
  • Higher level language concepts are typically missing

Can Haskell be a good replacement for Bash—or similar languages—as a shell scripting language?

@fkurz
fkurz / mermaid-image-export.md
Last active April 15, 2024 00:11
Mermaid Diagram Image Export

We can export a mermaid diagram to PNG very simply using the official Mermaid CLI Tool.

Installation via npm

npm i -g mermaid.cli

Usage:

@fkurz
fkurz / zsh-compaudit-fix-insecure-directories.md
Last active June 28, 2021 15:51
ZSH Compaudit Insecure Directories Fix

This is more or less a note-to-self.

Note: this doesn't seem to be the simplest solution. See edit from 27th June 2021 below.

If ZSH's compaudit complains about insecure directories on a Mac, removing write permissions will fix the issue (see this SO answer):

chmod g-w ${insecure-directories}
@fkurz
fkurz / brew-permissions-macos-multi-user.md
Last active June 27, 2021 13:26
Brew Permissions on macOS for Multiple Users

If you run a multi-user setup, [Brew][brew-home]'s doctor command will likely report lack of write permission on directories under /usr/local (e.g. /usr/local/etc).

The suggested fix is to chown -R $(whoami) ${directory} for all directories ${directory} without write permission by the current user. While this is a quick fix, it will force us to do the same procedure over again when we change to another user.

A better solution is to create a brew user group and add every user to this group that uses Brew as detailed [in this blog post][brew-multi-user]. While it's possible to add a user group via the command line. The simpler solution is to just use System Preferences > Users & Groups.

Once the group is created — called brew-users in this example — we can run the following to change the group for all files/directories managed by Brew (i.e. those stored under $(brew --prefix)) to the Brew user group and give the group writing

@fkurz
fkurz / manjaro-boot-drive-usb-mac.md
Last active November 22, 2023 17:38
Howto: Create a Manjaro Linux USB Boot Drive on MacOS

Create a Manjaro Linux USB Boot Drive on MacOS

  1. Download Manjaro Distribution

    Download page

  2. Format USB Drive

    To find the volume identifier of our USB stick, we run

@fkurz
fkurz / creating-instant-vectors-with-arbitrary-labels-in-promql.md
Created June 24, 2019 13:02
Snippet: Creating instant vectors with arbitrary labels in PromQL

Creating Instant Vectors with Arbitrary Labels in PromQl

Problem

We need to create an instant vector with a given label set.

An example use case would be supplying a default value in combination with or.

Solution

@fkurz
fkurz / protobuf-python-generation-with-working-import-statements.md
Last active June 22, 2019 19:51
Snippet: Protobuf Python Generation With Working Import Statements

Protobuf Python: Generating Code With Working Import Statements

Problem

The import statements in Python code generated from factored Protobuf files do not correctly point to the modules to be imported.

Note: By factored, I mean at least two files a.proto and b.proto with potential of mutual dependencies.

Solution

@fkurz
fkurz / generating-protobuf-message-serializations-from-the-command-line.md
Last active May 18, 2019 13:30
Snippet: Generating Protobuf Message Serializations from the Command Line

Snippet: Generating Protobuf Message Serializations from the Command Line

Problem

We want to send some protobuf serialized data to an implemented RPC API endpoint for testing.

Note: This is especially helpful if you work with [Twirp][3] and code in Python since the code generator does not yield a JSON Protobuf client.

Solution

You can use the protoc command to generate binary data and then pass them to curl (see [1] and [2]).