Skip to content

Instantly share code, notes, and snippets.

View paddy74's full-sized avatar

Patrick Young paddy74

View GitHub Profile
@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.ps1
Last active September 4, 2024 14:50
Clean the current git repository of ignored files
if (git tag 2>$null) {
git rm -r --cached .
git clean -dfX
git add .
} else {
Write-Host "fatal: not a git repository (or any of the parent directories): .git"
}
@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 April 24, 2026 09:38
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)\$ '
@paddy74
paddy74 / readJsonFile.hpp
Last active April 9, 2021 09:24
Read the values of a JSON file using C++ REST SDK
#pragma once
#include <cpprest/json.h>
/**
* @brief Parse a JSON file into a JSON object.
*
* @param jsonFileName The path to the JSON file to parse.
*/
@paddy74
paddy74 / CloneGitModule.cmake
Last active August 20, 2019 16:54
Allows using a git submodule if the parent project is not a git project
# Allows the use of external Git repositories outside of a Git project
# The contents of ${OUTPUT_DIR} should be in the appropriate .gitignore
find_package(Git QUIET)
function(clone_submodule REPO_URL BRANCH OUTPUT_DIR)
if(GIT_FOUND)
message(STATUS "Cloning git submodule from ${REPO_URL}")
execute_process(
@paddy74
paddy74 / ClangFormat.cmake
Created June 5, 2019 16:58
Runs clang-format on all files in src/ and include/
# ------------------------------------------------------------------------------
# Clang Format
# ------------------------------------------------------------------------------
OPTION(ENABLE_FORMAT "Run clang-format on all files in src/ and include/" OFF)
if(ENABLE_FORMAT)
# Get all project files
file(GLOB_RECURSE ALL_CXX_SOURCE_FILES
${PROJECT_SOURCE_DIR}/src/*.[chi]pp
${PROJECT_SOURCE_DIR}/src/*.[chi]xx