Skip to content

Instantly share code, notes, and snippets.

View jiripolasek's full-sized avatar
🧙‍♂️
I'm Busy Making Miracles

Jiří Polášek jiripolasek

🧙‍♂️
I'm Busy Making Miracles
View GitHub Profile
@jiripolasek
jiripolasek / Get-ProtocolAssoc.ps1
Created October 16, 2025 13:24
Detects effective default browser using Windows API
<#
Get-ProtocolAssoc.ps1
Queries Windows for the effective handler of http/https using AssocQueryString.
Compatible with Windows PowerShell 5.1 and PowerShell 7+.
OUTPUT
- Prints each field for http and https
- Returns a PSCustomObject you can pipe to ConvertTo-Json
USAGE
@jiripolasek
jiripolasek / Detect-DefaultBrowser.ps1
Last active October 16, 2025 10:58
Mirrors Microsoft.CmdPal.Ext.WebSearch.Helpers.DefaultBrowserInfo detection flow; Prints results of each step to help diagnose mismatches on a user's machine.
<#
Detect-DefaultBrowser.ps1 (PowerShell 5.1+ compatible)
Prints step-by-step diagnostics for default browser detection (http and optional https).
USAGE
powershell -NoProfile -ExecutionPolicy Bypass -File .\Detect-DefaultBrowser.ps1 -Verbose
.\Detect-DefaultBrowser.ps1 -IncludeHttps -TestUrl "https://example.com"
.\Detect-DefaultBrowser.ps1 -TestUrl "https://example.com" -Launch
#>
// HashSet supports collection initializer syntax
private static readonly HashSet<string> abcCollection1 = ["a", "b", "c"];
private static readonly FrozenSet<string> abcCollection2 = ["a", "b", "c"]; // doesn't work, yet...
// example with freezer:
private static readonly FrozenSet<FileAttributes> allowedAttributes = Freeze(FileAttributes.Archive, FileAttributes.Device, FileAttributes.Hidden);
private static readonly FrozenSet<string> allowedKeywords = Freeze(StringComparer.OrdinalIgnoreCase, "squirrel", "cat", "dog");
// example without:
private static readonly FrozenSet<FileAttributes> allowedAttributesUgly = new HashSet<FileAttributes>([FileAttributes.Archive, FileAttributes.Device, FileAttributes.Hidden]).ToFrozenSet();
@jiripolasek
jiripolasek / ReflectionExtensions.cs
Last active November 23, 2020 04:45
Detect init-only property using reflection
public static class ReflectionExtensions
{
/// <summary>
/// Gets a value indicating whether property has init accessor declared.
/// </summary>
/// <param name="propertyInfo"></param>
/// <returns>Returns <c>true</c> if the property is declared as init-only; otherwise returns <c>false</c>.</returns>
public static bool IsInitOnly(this PropertyInfo propertyInfo)
{
if (propertyInfo == null)