Skip to content

Instantly share code, notes, and snippets.

SQL-MisterMagoo / PowershellSysTrayIcon
Last active Dec 24, 2020
Show system tray icon from poweshell
View PowershellSysTrayIcon
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 / CssHelper.cs
Last active Nov 23, 2020
Helper class to calculate the Scoped Css id that Blazor will use
View CssHelper.cs
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();
SQL-MisterMagoo / MyBase.cs
Created Sep 6, 2020
Provide content from a base component that is not overridden
View MyBase.cs
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 / ChangeDefaultBranch.ps1
Created Jun 15, 2020
Change default branch on all your Github repos
View ChangeDefaultBranch.ps1
$token = <your github personal token>
$headers = @{"Authorization"="token $token"}
$body = (ConvertTo-Json @{ default_branch='main' })
Write-Host "Fetching repo list"
$repos = Invoke-RestMethod -Headers $headers -Method GET -Uri ""
foreach($repo in $repos) {
if($repo.default_branch -eq "master")
View index.html
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Input Test</title>
.container {
SQL-MisterMagoo / App.razor
Created Apr 24, 2020
TouchEvents example
View App.razor
<main @ontouchstart="TouchStart" @ontouchend="TouchEnd" style="height:100vh;">
<Router AppAssembly="@typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
View example.razor
<table class="table-bordered">
<td @ondblclick="StartEdit">
@if (Editing)
<input @bind="Name" @onblur="EndEdit" />
<span>@(Name ?? "double-click here")</span>
SQL-MisterMagoo / App.razor
Created Dec 29, 2019
Sample code to handle deep links to anchors in Blazor components
View App.razor
@* Code below handles deep links to anchors through the entire application *@
@inject NavigationManager NavMan
@inject IJSRuntime JS
protected override async Task OnAfterRenderAsync(bool firstRender)
if (firstRender && NavMan.Uri.Contains('#'))
SQL-MisterMagoo / BrowserRenderer.ts
Last active Nov 30, 2019
Playing with autofocus
View BrowserRenderer.ts
import { RenderBatch, ArrayBuilderSegment, RenderTreeEdit, RenderTreeFrame, EditType, FrameType, ArrayValues } from './RenderBatch/RenderBatch';
import { EventDelegator } from './EventDelegator';
import { EventForDotNet, UIEventArgs, EventArgsType } from './EventForDotNet';
import { LogicalElement, PermutationListEntry, toLogicalElement, insertLogicalChild, removeLogicalChild, getLogicalParent, getLogicalChild, createAndInsertLogicalContainer, isSvgElement, getLogicalChildrenArray, getLogicalSiblingEnd, permuteLogicalChildren, getClosestDomElement } from './LogicalElements';
import { applyCaptureIdToElement } from './ElementReferenceCapture';
import { EventFieldInfo } from './EventFieldInfo';
import { dispatchEvent } from './RendererEventDispatcher';
import { attachToEventDelegator as attachNavigationManagerToEventDelegator } from '../Services/NavigationManager';
const selectValuePropname = '_blazorSelectValue';
const sharedTemplateElemForParsing = document.createElement('template');
SQL-MisterMagoo / Custom Blazor Startup.html
Created Nov 27, 2019
Custom Blazor Startup Example with custom Retries/Interval and custom Reconnection Handler (not production code)
View Custom Blazor Startup.html
<script autostart="false" src="_framework/blazor.server.js"></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) {