Skip to content

Instantly share code, notes, and snippets.

@markcastle
markcastle / commandprompthere.bat
Created July 31, 2025 12:25
Adds a "Command Prompt Here" right click context menu to Windows
@echo off
:: Hide command output for a cleaner experience
:: Check if the script is running with admin rights
:: This attempts to access a protected system file to trigger a permissions error if not elevated
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
:: If the previous command failed, we are not running as admin
if '%errorlevel%' NEQ '0' (
echo Requesting administrative privileges...
@markcastle
markcastle / subnet_scanner.py
Created July 21, 2025 10:21
Scans a specified subnet by sending ICMP ping requests to every IP address in the range, then reports which hosts are responsive and which are not.
#!/usr/bin/env python3
"""
Subnet Ping Scanner
Scans a specified subnet by sending ICMP ping requests to every IP address in the range, then reports which hosts are responsive and which are not.
Features:
- Pings all hosts in a given IPv4 subnet (CIDR notation)
- Uses concurrent threads for fast scanning
- Customizable timeout and worker thread count
@markcastle
markcastle / setup-vacuum.sh
Last active July 7, 2025 19:16
This script creates a systemd journal cleanup script and installs a cron job to run it weekly (Sunday at 2:00 AM). It ensures that journal logs are automatically trimmed to a maximum of 500MB total disk usage.
#!/bin/bash
# ------------------------------------------------------------------------
# setup-vacuum.sh
#
# This script creates a systemd journal cleanup script and installs a cron
# job to run it weekly (Sunday at 2:00 AM). It ensures that journal logs
# are automatically trimmed to a maximum of 500MB total disk usage.
#
# USAGE:
@markcastle
markcastle / folder_cleaner.py
Created June 11, 2025 00:02
This script recursively searches for Unity Library folders and node_modules folders in a given directory tree, then interactively asks the user whether to delete each one.
#!/usr/bin/env python3
"""
Unity Library and Node Modules Folder Cleaner - Clean Version v2.0
This script recursively searches for Unity Library folders and node_modules folders
in a given directory tree, then interactively asks the user whether to delete each one.
Usage:
python folder_cleaner.py /path/to/main/folder
@markcastle
markcastle / WhoOwns.ps1
Created March 3, 2025 14:08
dentifies the "ultimate owner" of a given process by tracing its parent process hierarchy and analyzing its command-line arguments.
<#
.SYNOPSIS
Identifies the "ultimate owner" of a given process by tracing its parent process hierarchy and analyzing its command-line arguments.
.DESCRIPTION
This script finds all instances of a specified process name and attempts to determine the application that spawned it.
It does this by:
1. Retrieving all matching processes from the system.
2. Checking if the process's command-line arguments include `--webview-exe-name=`, which often reveals the true owner.
@markcastle
markcastle / path_pretty_print.ps1
Created May 24, 2023 21:48
Powershell script to list the directories in PATH on Windows for either User or Machine
# List the directories in PATH on Windows for either User or Machine
# Specify the target (User or Machine)
# Usage .\path_pretty_print.ps1 -Target Machine
# or .\path_pretty_print.ps1 -Target User
param(
[Parameter(Mandatory=$false)]
[ValidateSet("User", "Machine")]
[string]$Target = "User"
)
@markcastle
markcastle / remove_path_duplicates.ps1
Last active May 24, 2023 21:50
Powershell script to remove Duplicate paths in the PATH on Windows (for either User or Machine). Has an optional 'Dry Run' mode
# Remove Duplicate paths in the PATH on Windows (for either User or Machine). Has an optional 'Dry Run' mode
# Specify the target (User or Machine) and dry run mode
# example...
# .\remove_path_duplicates.ps1 -Target Machine -DryRun true
# .\remove_path_duplicates.ps1 -Target User -DryRun false
param(
[Parameter(Mandatory=$false)]
[ValidateSet("User", "Machine")]
[string]$Target = "User",
@markcastle
markcastle / repair_vscode_path.ps1
Created May 24, 2023 21:40
Powershell script to repair the PATH variable for VS Code (if it gets lost or removed). With optional 'Dry Run' mode.
# Repairs the PATH variable for VS Code (if it gets lost or removed).
#
# Specify the target (User or Machine) and dry run mode
# .\repair_vscode_path.ps1 -Target Machine -DryRun true
#
# If dry run is true (default) the it only shows you what it would
# have done if dryrun had been false... it's a safety thing!
# Specify the target (User or Machine) and dry run mode
param(
@markcastle
markcastle / remove_from_path.ps1
Created May 24, 2023 21:39
Powershell script to remove a directory from the PATH on Windows (for either System or User) with optional 'Dry Run' mode
# Powershell script to remove a directory from the PATH on Windows for either System or User
# Can optionally run it in dry run mode to be certain it's going to do what you require
#
# Specify the target (User or Machine), dry run mode, and directory to remove
# Examples
# .\remove_from_path.ps1 -DirectoryToRemove "C:\Path\To\Directory"
# This will remove C:\Path\To\Directory from the user PATH.
#
# .\remove_from_path.ps1 -DirectoryToRemove "C:\Path\To\Directory" -Target Machine
# This will remove C:\Path\To\Directory from the system PATH.
@markcastle
markcastle / InactiveCodeDetector.cs
Last active May 15, 2023 16:45 — forked from Happsson/InactiveCodeDetector.cs
A script that lets you find unused scripts in your unity projects.
/*
Original tool from Hannes Paulsson
From: https://gist.github.com/Happsson/af02d7a644db6b44bc834c8699bf3495
Updated 2023/05/15 by Mark Castle (and ChatGPT :P) to add excluded paths and to also
give the option of opening files in the current editor, plus some minor tweaks
to keep re-sharper happy.
https://gist.github.com/markcastle/be019a471b44016d73c11f308feb5249