Skip to content

Instantly share code, notes, and snippets.

View paddy74's full-sized avatar

Patrick Young paddy74

View GitHub Profile
@paddy74
paddy74 / find_netmask.ps1
Created April 1, 2025 18:03
find_netmask.ps1
function Convert-PrefixToNetmask {
param (
[Parameter(Mandatory = $true)]
[int]$PrefixLength
)
# Create a binary mask string with 1's for the prefix and pad with 0's
$binaryMask = ("1" * $PrefixLength).PadRight(32, "0")
$octets = @()
@paddy74
paddy74 / parse_yaml.md
Last active November 28, 2024 18:14
parse_yaml.sh

It understands files such as:

## global definitions
global:
  debug: yes
  verbose: no
  debugging:
    detailed: no
 header: "debugging started"
@paddy74
paddy74 / urlencode.sh
Last active October 22, 2024 18:37 — forked from sergeiwaigant/url_encode_string_with_linux_tools.md
Simply URL encode string with Linux/Bash/Shell tools
# Reference https://stackoverflow.com/a/34407620/13287790
# Requires `jq`
# $ echo -n "encode this" | jq -sRj @uri
# encode%20this
# MY_VAR=$(urlencode "encode this")
echo -n "${1}" | jq -sRj @uri
@paddy74
paddy74 / clear-aws-env.ps1
Created October 2, 2024 12:46
Clear all AWS related environment variables
# Clear all AWS related environment variables
function awskill {
Remove-Item -Path Env:AWS_DEFAULT_PROFILE -ErrorAction SilentlyContinue
Remove-Item -Path Env:AWS_ACCESS_KEY_ID -ErrorAction SilentlyContinue
Remove-Item -Path Env:AWS_SECRET_ACCESS_KEY -ErrorAction SilentlyContinue
Remove-Item -Path Env:AWS_SECRET_KEY -ErrorAction SilentlyContinue
Remove-Item -Path Env:AWS_SECURITY_TOKEN -ErrorAction SilentlyContinue
Remove-Item -Path Env:AWS_SESSION_TOKEN -ErrorAction SilentlyContinue
}
@paddy74
paddy74 / pip-upgrade.ps1
Last active September 4, 2024 15:13
Upgrade all Python packages in the active environment
# https://github.com/pypa/pip/issues/4551
python -m pip freeze | ForEach-Object{$_.split('==')[0]} | %{python -m pip install --upgrade $_}
@paddy74
paddy74 / git-drop-gone.ps1
Created September 4, 2024 14:47
Remove all local branches that are not on remote
# from https://stackoverflow.com/a/33548037/7706917
#
# Explanation:
# ---
# Switch to the main branch
# $> git checkout main
# Prune remote branches
# $> git remote update origin --prune # Prune remote branches
# Get a verbose output of all branches (git reference)
# $> git branch -vv
@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