Skip to content

Instantly share code, notes, and snippets.

@SQL-MisterMagoo
SQL-MisterMagoo / Explainer.md
Last active September 4, 2024 00:13
Get Windows Display By Convention - Numbered Top Left To Bottom Right

Windows Displays

...are likely/possibly numbered in the order they are detected - not necessarily in the order they appear in Settings or their physical order on your desk.

So, for example, it might seem natural to number your displays from top left to bottom right - just like reading a book.

This function GetDisplayByConvention() maps a number to a screen based on the Convention described above.

It gets AllScreens, orders them by Top, then by Left, skips the required number and returns the requested screen

@SQL-MisterMagoo
SQL-MisterMagoo / program.cs
Created August 1, 2023 23:23
Why dotnet, why? Or how to deserialize with a collection of interface
using System.Text.Json;
using System.Text.Json.Serialization;
/* Setup */
Thing[] someThings = { new("1"), new("2") };
var myThings = new Things(someThings);
/* Staying in dotnet - this all works as expected */
var asInterfaces = myThings as IThings;
@SQL-MisterMagoo
SQL-MisterMagoo / Microsoft.Playwright.runtimeconfig.json
Created July 20, 2023 14:31
Call playwright actions from CLI
{
"runtimeOptions": {
"tfm": "net7.0",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "7.0.8"
}
}
}
@SQL-MisterMagoo
SQL-MisterMagoo / 7.01.txt
Created December 15, 2022 13:12
dotnet --info
.NET SDK:
Version: 7.0.101
Commit: bb24aafa11
Runtime Environment:
OS Name: Windows
OS Version: 10.0.25267
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.101\
@SQL-MisterMagoo
SQL-MisterMagoo / README-Hosted.md
Last active May 18, 2023 22:50
Compress Static Files in wwwroot (or anywhere) in Blazor WebAssembly

Compress Static Files in Blazor WebAssembly Hosted

This goes into your msbuild config (normally csproj) and runs before the Publish Task, before files are copied to the final destination.

<!-- 2022 @SQL-MisterMagoo containing some code from (c) .NET Foundation. All rights reserved. -->

<PropertyGroup Condition="'$(_BlazorWebAssemblySdkToolAssembly)'==''">
  <_SDKRoot>$(NetCoreRoot)sdk\$(NETCoreSDKVersion)\Sdks</_SDKRoot>
@SQL-MisterMagoo
SQL-MisterMagoo / Readme.md
Created June 17, 2021 09:41
Example Blazor Server SignalR config for a busy VPN network
@SQL-MisterMagoo
SQL-MisterMagoo / PowershellSysTrayIcon
Last active December 24, 2020 01:26
Show system tray icon from poweshell
Add-Type -AssemblyName PresentationFramework, System.Drawing, System.Windows.Forms
$icon = New-Object System.Windows.Forms.NotifyIcon
$icon.icon = New-Object System.Drawing.Icon("someicon.ico")
$icon.Visible = $true
@SQL-MisterMagoo
SQL-MisterMagoo / CssHelper.cs
Last active November 23, 2020 19:08
Helper class to calculate the Scoped Css id that Blazor will use
public static class CssHelper
{
public static string GenerateScope(string targetName, string relativePath)
{
using var hash = SHA256.Create();
var bytes = Encoding.UTF8.GetBytes(relativePath.ToLowerInvariant().Replace("\\", "//") + targetName);
var hashBytes = hash.ComputeHash(bytes);
var builder = new StringBuilder();
builder.Append("b-");
@SQL-MisterMagoo
SQL-MisterMagoo / MyBase.cs
Created September 6, 2020 01:01
Provide content from a base component that is not overridden
public class MyBase : ComponentBase
{
string someValue = "test";
public MyBase()
{
var rf = typeof(ComponentBase).GetField("_renderFragment", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var pqr= typeof(ComponentBase).GetField("_hasPendingQueuedRender", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
var nr= typeof(ComponentBase).GetField("_hasNeverRendered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
rf.SetValue(this, (RenderFragment)(builder =>
{
@SQL-MisterMagoo
SQL-MisterMagoo / ChangeDefaultBranch.ps1
Created June 15, 2020 16:58
Change default branch on all your Github repos
$token = <your github personal token>
$headers = @{"Authorization"="token $token"}
$body = (ConvertTo-Json @{ default_branch='main' })
Write-Host "Fetching repo list"
[Console]::Out.Flush()
$repos = Invoke-RestMethod -Headers $headers -Method GET -Uri "https://api.github.com/user/repos?type=owner&per_page=80"
foreach($repo in $repos) {
if($repo.default_branch -eq "master")
{