Skip to content

Instantly share code, notes, and snippets.

View chrisfcarroll's full-sized avatar
🤹‍♂️
🌍...☕...🖥️...⏳...⛪...🛌🏼

Chris F Carroll chrisfcarroll

🤹‍♂️
🌍...☕...🖥️...⏳...⛪...🛌🏼
View GitHub Profile
@chrisfcarroll
chrisfcarroll / DisposableArray.cs
Created April 30, 2025 14:48
DotNet C# DisposableArray<T>, DisposableList<T>. Simplify creating and disposing an array or list of disposable elements by having the container be disposable.
using System.Collections;
/// <summary>
/// A <see cref="IDisposable"/> wrapper for a <see cref="T[]"/> which, when it is disposed,
/// disposes each of its non-null elements.
/// </summary>
public class DisposableArray<T> : Array<T>, IDisposable where T : IDisposable
{
public DisposableArray(IEnumerable<T> items):base(items){}
public DisposableArray(int size):base(size){}
@chrisfcarroll
chrisfcarroll / SqlScriptFileMigration.cs
Last active April 25, 2025 17:05
An EntityFrameworkCore Migration base class for Sql Script File-backed Migrations.
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
// ReSharper disable InconsistentNaming
#region migrations
[Migration(nameof(Script1))]public class Script1 : MigrationConfiguredWithScriptDirectoryAndDbContext{}
[Migration(nameof(Script2))]public class Script2 : MigrationConfiguredWithScriptDirectoryAndDbContext{}
#endregion
@chrisfcarroll
chrisfcarroll / FakeClaimsIdentity.cs
Last active March 27, 2025 18:30
A Fake Claims Identity for testing, with claims settable in code.
using System.Collections.Generic;
using System.Security.Claims;
using System.Security.Principal;
public class FakeClaimsIdentity : ClaimsIdentity
{
public readonly List<Claim> ClaimsValue = new List<Claim>();
public bool IsAuthenticatedSet;
@chrisfcarroll
chrisfcarroll / DevAzureReleaseVariableTransform.Tests.ps1
Created March 11, 2025 12:05
Dev Azure Release Pipeline Web.*.config Variable Transform PowerShell Script
using namespace System.Diagnostics
using namespace System.Collections
using namespace System.Collections.Generic
using namespace System.IO.Compression
param ( [switch]$NoRun )
function Assert( [bool]$condition, [string]$message = "Assertion failed" ){
if( -not $condition ) {
Get-PSCallStack | ForEach-Object { Write-Host $_.FunctionName $_.Location $_.Arguments }
@chrisfcarroll
chrisfcarroll / DevAzureReleaseNetCoreWebConfigTransformStep.ps1
Created March 11, 2025 11:24
DevAzure Release Pipeline NetCore Web.Config Transform Step for Environment Variables Substitution
# Populate Web.config EnvironmentVariables from Pipeline variables
#
# Usage: Copy-paste this script into a Powershell Task, as an inline script, in your release pipeline.
#
# -----------------------------------------------------
# Known Variables:
# DOTNET_ENVIRONMENT
# TraceTransforms
# -----------------------------------------------------
# Editing this script:
@chrisfcarroll
chrisfcarroll / DevAzure tasks and GOTCHAS.yml
Last active October 11, 2024 16:57
DevAzure tasks and GOTCHAS
task: PowerShell@2
displayName: "Dev Azure tasks and GOTCHAS"
inputs:
targetType: 'inline'
script: |
# Write your PowerShell commands here.
@"
DevAzure tasks and GOTCHAS: NuGet.config, MsBuild Path, Unit Tests, Integration Tests
"@
@chrisfcarroll
chrisfcarroll / SoftDictionary.cs
Last active March 27, 2025 10:31
A .Net SoftDictionary<K,V> is a Dictionary<K,V> which, if you try to read an empty entry, returns default(V) instead of throwing an exception.
/// <summary>
/// A SoftDictionary is a <see cref="Dictionary{TKey,TValue}"/> which does not
/// throw if you try to to access a non-existent entry. Instead, it returns <c>default(TValue)</c>
/// </summary>
/// <typeparam name="TKey"></typeparam>
/// <typeparam name="TValue"></typeparam>
public class SoftDictionary<TKey,TValue> : Dictionary<TKey,TValue> where TKey : notnull
{
/// <inheritdoc cref="IDictionary{TKey,TValue}"/>
/// <remarks>
@chrisfcarroll
chrisfcarroll / StringExtensionMethods.md
Last active April 30, 2025 10:09
.Net string.Chop(), .MaskStart(), .MaskEnd(), .ToWikiWords(), .PascalCaseToWords() .WithWhiteSpaceRemoved() StringJoin.WhereNotNull() StringJoin.WhereNotNullOrEmpty()()

Contents

  • Strings.cs: string extension methods such as string.Chop(), .MaskStart(), .MaskEnd(), .ToWikiWords(), .PascalCaseToWords() .WithWhiteSpaceRemoved()
  • StringJoinWhereNotNull.cs: String.Join() alternatives for removing null entries
  • StringJoinWhereNotNullOrEmpty.cs: String.Join() alternatives for removing null and empty entries

Strings.cs

  • TrimEnd(this string? str, string terminator)
    • Trims the specified terminator string from the end of the input string if it exists.
@chrisfcarroll
chrisfcarroll / EFCoreAndDomainModels.cs
Last active November 7, 2023 12:39
Minimal EFCore Demo for Domain-Application-Infrastructure DDD structure
using System.Diagnostics;
using EFCoreAndDomainModels.Application;
using EFCoreAndDomainModels.Domain;
using EFCoreAndDomainModels.Infrastructure;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using TestBase;
using Xunit.Abstractions;
namespace EFCoreAndDomainModels
@chrisfcarroll
chrisfcarroll / azcommandlineexamples.sh
Created January 28, 2023 16:42
Show some example az cli commands to create and delete a VM
#! /usr/bin/env sh
cat << 'EOF'
Get pricing:
location.href="https://prices.azure.com/api/retail/prices?$skip=0&currencyCode='GBP'&$filter=location eq 'UK South' and serviceName eq 'Virtual Machines' and priceType eq 'Consumption'"
Create Spot VM
az vm create -g VM --name VM --admin-username azureuser --image CentOS --generate-ssh-keys --public-ip-sku Standard --priority Spot --eviction-policy Delete
Destroy VM