Skip to content

Instantly share code, notes, and snippets.

using Xunit;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace ProofOfConcept.ClearSingleton;
public sealed class Singleton : IDisposable
{
private static Singleton? _instance;
@Stroniax
Stroniax / DockerCompose.csproj
Last active August 25, 2023 15:46
Docker Mounted DotNet Watch Run
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="PSValueWildcard" Version="1.0.0-alpha1" />
@Stroniax
Stroniax / SingleCollectionBenchmark.cs
Created February 16, 2023 19:45
SingleCollection Benchmark
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
using System.Collections;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace SingleCollectionBenchmark;
/// <summary>
/// <code>
@Stroniax
Stroniax / StrongInject.HttpApplication.cs
Created January 23, 2023 18:13
Example StrongInject Application Configured HttpClient
// See https://aka.ms/new-console-template for more information
using StrongInject;
using System.Net;
using System.Net.Http.Json;
namespace StrongInjectConfiguredHttpClientExample;
public class Program
{
public async Task Main(string[] args)
@Stroniax
Stroniax / ContinuationJob.cs
Created March 16, 2022 18:30
PowerShell job to subscribe a continuation action or script for when an initial job completes.
// PowerShell continuation job allows you to subscribe a continuation to an existing job.
// The following example is a bit useless but demonstrates the functionality of the job.
// PS:\> function Register-ContinuationJob { param([Job]$Job, [ScriptBlock]$Continuation) process { $cont = [ContinuationJob]::new($Job, $Continuation); $PSCmdlet.JobRepository.Add($cont); $cont }
// PS:\> $WakeUpJob = Start-Job { while (-not (Test-Connection Server01 -Quiet -Count 1)) { Start-Sleep -Seconds 1 } }
// PS:\> $ShutdownJob = Register-ContinuationJob -Job $WakeUpJob -Continuation { Invoke-Command -computerName Server01 -ScriptBlock { 'Sending shut down' ; Stop-Computer } }
// PS:\> $WakeUpJob, $ShutdownJob | Receive-Job -Wait -AutoRemoveJob
using System;
using System.Threading;
using System.Threading.Tasks;
@Stroniax
Stroniax / New-ModuleProject.ps1
Created November 12, 2021 19:46
Generates a module template for developing a PowerShell module.
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory)]
[string]$ModuleName,
[Parameter(Mandatory)]
[Alias('OutputPath')]
[string]$DestinationPath,
[switch]$NoBinaryProject,
[switch]$NoScriptProject,
@Stroniax
Stroniax / TaskJob.cs
Last active October 9, 2023 18:34
A PowerShell Job wrapper for System.Threading.Tasks.Task to bridge the gap between asynchronous operations in C# and PowerShell.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Threading;
using System.Threading.Tasks;
namespace Casion.PowerShell
{
/// <summary>