Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / Readme.md
Created June 17, 2021 09:41
Example Blazor Server SignalR config for a busy VPN network
@foreach (var item in new string[] { "AspNetCore","AspNet","SomeJsThingWhatever"})
{
<div>
<input type="radio" name="technology" id="@item" value="@item" @onchange="RadioSelection" checked=@(RadioValue.Equals(item,StringComparison.OrdinalIgnoreCase)) />
<label for="@item">@item</label>
</div>
}
<div>
<label>Selected Value is @RadioValue</label>
</div>
@SQL-MisterMagoo
SQL-MisterMagoo / App.razor
Created December 29, 2019 00:33
Sample code to handle deep links to anchors in Blazor components
@* Code below handles deep links to anchors through the entire application *@
@inject NavigationManager NavMan
@inject IJSRuntime JS
@code
{
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender && NavMan.Uri.Contains('#'))
{
@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 / Custom Blazor Startup.html
Created November 27, 2019 00:48
Custom Blazor Startup Example with custom Retries/Interval and custom Reconnection Handler (not production code)
<script autostart="false" src="_framework/blazor.server.js"></script>
<script>
async function connectionDown(options) {
console.log("Connection Down - you could do some UI here...");
for (let i = 0; i < options.maxRetries; i++) {
console.log("Waiting for reconnect attempt #"+(i+1)+" ...");
await this.delay(options.retryIntervalMilliseconds);
if (this.isDisposed) {
break;
}
@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 / 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 / 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;