Skip to content

Instantly share code, notes, and snippets.

View taikedz's full-sized avatar

Tai Kedzierski taikedz

View GitHub Profile
@taikedz
taikedz / README.md
Last active December 5, 2023 11:12
Mocker

Mocker

A versatile object mocking utility for unit testing.

For example, assuming a function that uses a connection utility:

def find_python_files_at(connection):
  try:
 status, stdout, stderr = connection.send_command("ls /my/path", shell=True)
@taikedz
taikedz / README.md
Created December 5, 2023 09:47
Basic attributes dictionary / namespacer

DictNamespace

A basic namespacing utility to provide "nicer" code.

It's a small snippet for a minor quality-of-life utility.

ns = DictNamesspace(a=1, b="hello")
assert ns.a == 1
assert ns.b == "hello"
@taikedz
taikedz / rustr
Created October 17, 2023 10:46
rustr - run rust source file as an executable script
#!/usr/bin/env bash
# Use this `rustr` script as a shebang target.
# put `rustr` somewhere on your PATH
filename="$1"; shift
temp="$(mktemp)"
rmtemp() { rm "$temp"; }
touch "$temp"
@taikedz
taikedz / goenv
Last active October 17, 2023 10:40
GoEnv - python virtualenv-like way to set GOPATH
#!/usr/bin/env bash
# Run `goenv ./env-dir` to create an isolated dependencies dir
# Source the resulting file to activate it in a local shell session
# . env-dir/go-activate
# This sets GOPATH and adds a PATH entry to the environment
# Run `go-deactivate` to deactivate it.
if [[ -z "$1" ]]; then
echo "No name specified"
@taikedz
taikedz / comprehension.groovy
Created October 16, 2023 12:33
Basic comprehensions in Groovy
// Some things
List<String> items = ["banana", "pear", "apple"]
// Filtering out
List<String> e_items = items.findAll { it.contains("e") }
println(e_items)
// List from list
List<String> fruity = items.collect { "Fruit: $it" }
println fruity
@taikedz
taikedz / README.md
Last active October 17, 2023 10:47
Rust-style Option objects in Python

Mimic Rust's Option type in Python

Commentary published in an article: https://dev.to/taikedz/rusts-option-type-in-python-547p

How to use this

Using this type allows the developer to express nullness and force the recipient of the Option to code for it. The Option does not stand in for the value, the value must be unpacked from it.

@taikedz
taikedz / oci-image-rm-remote.sh
Last active October 12, 2023 11:29
Delete a remote OCI image (if supported) (docker/podman registry)
#!/usr/bin/env bash
if [[ -z "$*" ]]; then
echo -e "Usage:\n\t$(basename "$0") \$SERVER/\$IMAGE:\$TAG [delete]"
echo "Omit the 'delete' argument to query the manifest for the image"
echo "Use 'delete' to actually perform deletion"
exit 0
fi
REGISTRY_SERVER="$(echo "$1" | cut -d/ -f1)"
@taikedz
taikedz / README.md
Last active September 6, 2023 07:07
pathctl

pathctl

A quick and dirty script for loading/appending to PATH

Oftentimes when I write install scripts i have to go looking for a path and its presence to avoid duplication, parsing the .bashrc and .profile scripts .

This is tedious, and prone to issues.

If we could have a basic utility that already took care of this as a default item in the system, it would be handy.

@taikedz
taikedz / README.md
Last active September 1, 2023 10:36
Install ZIG

Install Zig

A basic script to pull the latest master, or specified version, of zig

bash install-zig.sh # installs master build as 'zig'
bash install-zig.sh 0.11.0 # installs latest build for this version as 'zig-0.11.0'

# This command is always the latest-installed master build
zig --help
@taikedz
taikedz / README.md
Last active August 23, 2023 08:11
Using syncthing

Converterd to an articla: https://dev.to/taikedz/considering-syncthing-at-work-3pin

An interim solution for passing around large files using decentralised means

Syncthing uses end-to-end encryption to send files directly to other devices. If two devices are on the same network, the instances communicate directly with eachother. If not, they send traffic, encrypted, via a relay server (akin to a router).

This solution can be useful for sending large files between workstations, when other means are unavailable.

Security considerations