Skip to content

Instantly share code, notes, and snippets.

View JeffMill's full-sized avatar

Jeff Miller JeffMill

  • Microsoft
  • Redmond, WA
View GitHub Profile
@JeffMill
JeffMill / pipe-powershell.cs
Last active April 22, 2025 23:07
Pipe powershell command output to C# program
using System.Diagnostics;
using System.Text;
using (Process process = new Process())
{
int timeoutMS = 1000;
process.StartInfo.FileName = "powershell.exe";
process.StartInfo.Arguments = "-NoLogo -NoProfile -NonInteractive -Command \"&{ Get-DeliveryOptimizationLog }\"";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
@JeffMill
JeffMill / gitgrepblame.ps1
Last active April 22, 2025 17:30
gitgrepblame: Combination of "git grep" and "git blame".
<#
.SYNOPSIS
Combination of "git grep" and "git blame".
#>
function gitgrepblame {
Param([Parameter(Mandatory)][string]$Query)
# grep "--null" uses null separators, blame "-c" uses tab separators.
git.exe --no-pager grep --null --line-number $Query `
| Select-String -Pattern '(?<Filename>[^\0]+)\0(?<Line>[1-9][0-9]*)\0\s*(?<Text>.+)' `
@JeffMill
JeffMill / Remove-Old-Az-Modules.ps1
Last active March 25, 2025 18:57
Remove older PowerShell Az modules
# Note: This doesn't always work correctly.
# might get: Uninstall-Package: No match was found for the specified search criteria and module names...
# Can remove all az.* packages (and then manually reinstall) using:
# $env:PSModulePath -split ';' | ForEach-Object { Get-ChildItem -Directory -Path (Join-Path $_ 'Az.*') | ForEach-Object { Remove-Item -LiteralPath $_.FullName -Recurse -Verbose -Force } }
# (Which could also be updated to remove just older versions in each folder)
foreach ($module in (Get-Module -ListAvailable -Name 'Az*').Name | Get-Unique) {
$modules = Get-Module -ListAvailable $module
if ($modules.Count -gt 1) {
@JeffMill
JeffMill / Dump-Signers.ps1
Last active September 20, 2024 20:41
Dump certs in a binary
Param([Parameter(Mandatory)][string]$Path)
# Caveats:
#
# Get-AuthenticodeSignature cmdlet has the following limitations:
# * Only first signature is fetched;
# * If the signature is timestamped, no signing time is provided;
# * No signature algorithm information is provided.
$chain = New-Object -TypeName Security.Cryptography.X509Certificates.X509Chain
@JeffMill
JeffMill / GitBackup.ps1
Last active September 20, 2024 20:19
git backup
git.exe stash store -m ('WIP on {0}: {1}' -f (git.exe rev-parse --abbrev-ref HEAD), (git.exe log -1 --pretty=format:'%h %s')) (git.exe stash create)
git.exe stash show 0
@JeffMill
JeffMill / MessageBoxHook.cpp
Created May 31, 2024 19:56
Using a CBT Hook to modify a Windows dialog box.
#pragma comment(linker, "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <SDKDDKVer.h>
#include <windows.h>
#include "resource.h"
INT_PTR CALLBACK AboutProc(
HWND hDlg,
UINT message,
@JeffMill
JeffMill / ansi.ps1
Created April 10, 2024 22:20
PowerShell ansi
# https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
function Write-Bold() {
param([Parameter(Mandatory)][string]$Message)
$ESC = [char]27
"$ESC[1m$Message$ESC[0m"
}
@JeffMill
JeffMill / windows_build.md
Last active November 2, 2024 11:36
Windows build environment using cmake and Visual Studio Build Tools

Windows build environment using cmake, vcpkg, Visual Studio Build Tools

Installation

App Installer (winget)

This is included in Windows 11.

Downlevel: In Microsoft Store, Install "App Installer" (aka winget)

@JeffMill
JeffMill / git-vs.ps1
Last active August 2, 2023 22:38
Edit all open git files in a new vscode instance
& "$env:LocalAppData\Programs\Microsoft VS Code\bin\code.cmd" --new-window $(git diff --name-only --diff-filter=d HEAD | ForEach-Object { Join-Path (git rev-parse --show-toplevel) $_ })
@JeffMill
JeffMill / kdiff3-config.md
Last active November 2, 2024 12:57
kdiff3 configuration for Windows

KDiff3

Fast on Linux and Windows, and supports 3-way merging! Diffinity and Meld are a couple of other viable options.

KDiff3 Merge Tutorial

Install KDiff3

winget install KDE.KDiff3