Skip to content

Instantly share code, notes, and snippets.

@paddy74
paddy74 / haos-privacy-policy.txt
Created March 2, 2024 21:16
Required privacy policy link for HAOS + Google Assist integration
This application is intended for the private use of its developer. Any unauthorized users which connect to this service should have no expectation of privacy or protection of their data.
@paddy74
paddy74 / str_helpers.py
Created April 12, 2023 15:27
Helper functions for Python strings
def str_isnullorwhitespace(value: str) -> bool:
"""
Indicates whether a specified string is `null`, empty, or consists only of
white-space characters
Parameters
-----------
value: str
The string to test.
@paddy74
paddy74 / count_sentences.py
Created January 21, 2022 20:39
Regex based Python function to count the number of sentences in a given string.
import re
def count_sentences(text: str) -> int:
"""
Count the number of sentences in a given string.
This function is based on the Stack Overflow answer https://stackoverflow.com/a/38589115/7706917
Inputs
--------
@paddy74
paddy74 / batfromdir.bat
Created May 11, 2021 19:05
Running a batch file from the directory containing the batch file.
@echo off
PUSHD %~dp0
:: Do some stuff
:: Return to the caller directory
POPD
@paddy74
paddy74 / git-clean.sh
Last active October 26, 2020 21:10
Clean the current git repository of ignored files
#!/bin/bash
if git tag > /dev/null 2>&1 && [ $? -eq 0 ]; then
git rm -r --cached .
git clean -dfX
git add .
else
echo "fatal: not a git repository (or any of the parent directories): .git";
fi
@paddy74
paddy74 / kubectl-clean-pods.sh
Created September 3, 2020 17:25
Clean bad pods from kubernetes
#!/bin/bash
kubectl get pods --all-namespaces | grep -E 'ImagePullBackOff|ErrImagePull|Evicted' | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod
#kubectl get pods --all-namespaces --field-selector 'status.phase==Failed' -o json | kubectl delete -f -
@paddy74
paddy74 / epsilonCompare.hpp
Last active May 12, 2020 23:39
Compare floats while safely handling invisible float precision overflow
#pragma once
#include <limits>
/**
* Check if a and b are within epsilon range of eachother.
*
* Based on this post: https://www.reddit.com/r/ProgrammerHumor/comments/ggwxjp/the_dwindling_sanity_of_valves_programmers/fq646zf?utm_source=share&utm_medium=web2x
**/
template<typename T> // Numeric type
@paddy74
paddy74 / docker-clean.sh
Created January 27, 2020 20:30
Clean the Docker environment
#!/bin/bash
docker rm -v $(docker ps -a -q -f status=exited)
docker rmi $(docker images -f "dangling=true" -q)
if [[$1 == "-vfs" ]]; then
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin
fi
@paddy74
paddy74 / setup_wol.sh
Last active September 12, 2023 06:52
Setting up wake-on-lan on Arch
#!/bin/bash
# https://wiki.archlinux.org/index.php/Wake-on-LAN
sudo pacman -Syu ethtool
# d (disabled), p (PHY activity), u (unicast activity), m (multicast activity),
# b (broadcast activity), a (ARP activity), and g (magic packet activity)
ethtool <interface> | grep Wake-on
# If not g
ethtool -s <interface> wol g
#!/bin/bash
# Git branch recognizer # TODO: Auto add
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;31m\] $(parse_git_branch)\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(parse_git_branch)\$ '