Skip to content

Instantly share code, notes, and snippets.

@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
@markcastle
markcastle / IsNumeric.cs
Created August 6, 2022 11:06
Simple check if a string contains a number in C# using LINQ
using System.Linq;
namespace CaptiveReality.Utils
{
public class Common
{
public static bool IsNumeric(string value)
{
return value.All(char.IsNumber);
}
@markcastle
markcastle / viewimage.aspx
Created July 22, 2022 18:36
A really really old image manipulation script
' Author: Mark Castle
' Email: mark@markcastle.com
' Updated: 03 March 2003
' Language: VB.NET
' Framework Version: V1.1
' Create thumbnail images on the fly.
<%@ Import Namespace=System.Drawing %>
<%@ Import Namespace=System %>
<%@ Import Namespace=System.Web %>
/*
* Some simple Float Extensions
*/
using System;
namespace YOURNAMESPACE.Extensions
{
public static class FloatExtensions
{
@markcastle
markcastle / bitbucket.yml section
Created December 3, 2021 02:06
Get build version from a C# project file for use in Bitbucket pipelines
# Set the Solution and Application Names
- export SOLUTION_NAME=YourSolutionName
- export APP_NAME=YourAppName
# Create an Env Var File that we'll import from
- export ENV_VARS_FILE=ENVIRONMENT_VARIABLES.txt
- echo -n "VERSION=" >> $ENV_VARS_FILE
# Search for the version tag, pipe the tag into sed then extract just the version, append that to the env vars file
- grep -Eoi "<version>([[:digit:]\.]+)</version>" ./$SOLUTION_NAME/$SOLUTION_NAME.csproj | sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' >> $ENV_VARS_FILE
# Finally, parse the env vars file and then export those vars so that we can use them in bitbucket pipelines.
- export $(cat $ENV_VARS_FILE | xargs)
@markcastle
markcastle / get-version
Created December 2, 2021 19:58
Extract Version string from a dotnet C# project file using just grep and sed
rem Extract Version string from a dotnet C# project file using just grep and sed...
# eg source file ./ProjectFolder/ProjectName.csproj contains..
# <Version>0.0.3</Version>
grep -Eoi "<version>([[:digit:]\.]+)</version>" ./ProjectFolder/ProjectName.csproj | sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p'
# Expected Result...
0.0.3