Skip to content

Instantly share code, notes, and snippets.

View mabster's full-sized avatar

Matt Hamilton mabster

View GitHub Profile
@mabster
mabster / Program.cs
Created July 22, 2023 10:30
Parse a string into an array of tags (denoted by square brackets) and terms (which may be quoted to preserve whitespace).
using System;
using System.Linq;
public class Program
{
static readonly char[] _trmDelimiters = { ' ', ',', '.', '!', '/' };
static readonly char[] _tagDelimiters = { '[', ']' };
public static void Main()
{
@mabster
mabster / Start-ChinWag.ps1
Created October 25, 2022 23:14
Starts a call with a random, available member of a group.
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory, Position = 0)]
[string] $GroupName
)
function Test-Module($moduleName) {
if (-not (Get-Module $moduleName -ListAvailable)) {
Install-Module $moduleName -Scope CurrentUser -Force
}
@mabster
mabster / UserPhoto.razor
Last active February 13, 2022 23:47
UserPhoto Blazor Component
@inject GraphServiceClient GraphClient
<AuthorizeView>
<Authorized>
<img src="@_src"
title="@_title"
onerror="this.src = '@DEFAULT';"
class="rounded-circle img-fluid"
@attributes="AdditionalAttributes" />
</Authorized>
@mabster
mabster / Program .cs
Created January 20, 2021 21:40
Tiny HTTP Redirect
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;
var config = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: false, reloadOnChange: false).Build();
[cmdletbinding()]
param (
[parameter(parametersetname='test1')]
[switch]$p1,
[parameter(parametersetname='test2')]
[switch]$p2
)
DynamicParam
@mabster
mabster / enrol.ps1
Created June 10, 2020 23:30
PowerShell Parameter Madness
# This function takes a user and a course, but it should be possible to specify either argument
# as an ID rather than an instance of the class.
# Named parameters work fine, but positional parameters don't always parse correctly.
# All the commands at the bottom of this file *should* work.
class User { [int] $Id }
class Course { [int] $Id }
function New-Enrolment {
@mabster
mabster / icontest.html
Created January 28, 2020 02:53
Office UI Fabric Core Icon Alignment
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="https://static2.sharepointonline.com/files/fabric/office-ui-fabric-core/11.0.0/css/fabric.min.css" />
</head>
<body class="ms-Fabric" dir="ltr">
<p class="ms-fontSize-12" style="line-height: 20px;"><i class="ms-Icon ms-Icon--Calendar" aria-hidden="true"></i> Due 22/03/2020</p>
@mabster
mabster / Program.cs
Created September 26, 2019 03:04
EF Core query translation fails with internal properties
using Microsoft.EntityFrameworkCore;
using System;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
add-type -AssemblyName System.Drawing
New-Item "$($env:USERPROFILE)\Pictures\Spotlight" -ItemType directory -Force;
New-Item "$($env:USERPROFILE)\Pictures\Spotlight\CopyAssets" -ItemType directory -Force;
New-Item "$($env:USERPROFILE)\Pictures\Spotlight\Horizontal" -ItemType directory -Force;
New-Item "$($env:USERPROFILE)\Pictures\Spotlight\Vertical" -ItemType directory -Force;
foreach($file in (Get-Item "$($env:LOCALAPPDATA)\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets\*"))
{
if ((Get-Item $file).length -lt 100kb) { continue }
Copy-Item $file.FullName "$($env:USERPROFILE)\Pictures\Spotlight\CopyAssets\$($file.Name).jpg";
}
using System;
using System.Collections.Generic;
using System.Linq;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{