Skip to content

Instantly share code, notes, and snippets.

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

Chris F Carroll chrisfcarroll

🤹‍♂️
🌍...☕...🖥️...⏳...⛪...🛌🏼
View GitHub Profile
@chrisfcarroll
chrisfcarroll / UsableSemaphoreSlim.cs
Created May 27, 2026 10:28
A SemaphoreSlim(1,1) wrapper for use as an async lock in a using statement
/// <summary>
/// A <see cref="SemaphoreSlim"/> wrapper that can be used in a using statement.
/// The wrapped semaphore has initialCount=1, maxCount=1.
/// <code>using(await theUsableSemaphoreSlim.WaitAsync())
/// {
/// ... access resources ...
/// }
/// </code>
/// <p>Calling <see cref="Dispose"/> on a <see cref="UsableSemaphoreSlim"/>
/// does not dispose the Semaphore, it releases the lock.</p>
@chrisfcarroll
chrisfcarroll / ChrisConventionalCommitStyle.md
Last active June 1, 2026 12:51
Chris's Conventional Commit Style

Comment and Commit Style

Less is More. XML docs are required on every public member, but only tell the developer things they don't know, not things they can already see from the names. No comment is better than verbose comment.

The only goal of style rules is readability. Scratching the tidiness itch is not a goal. Syntax cannot always determine what is most readable, so syntax-based linting is not an infallible oracle.

@chrisfcarroll
chrisfcarroll / SerilogSourceContextShortName.And.Example.Config.json
Last active April 23, 2026 15:17
SerilogSourceContextShortName - Abbreviate "Well.Known.Long.Namespace.And.Class" to "WellKnown:Class" in your log lines
"Serilog": {
"Using": [ "Serilog.Sinks.File","Serilog.Sinks.Console"],
"MinimumLevel": {
"Default": "Information",
"Override": {
"Ljmu": "Verbose",
"DbsChecksStaging": "Verbose",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information",
"Microsoft.EntityFrameworkCore": "Information",
@chrisfcarroll
chrisfcarroll / SqliteDb.cs
Last active January 29, 2026 16:22
Create and bootstrap a Sqlite database. In particular, create shared in-memory databases, either named or anonymous.
using Microsoft.Data.Sqlite;
/// <summary>
/// This class encapsulates the creation and one-time bootstrapping
/// of a Sqlite database.
/// In particular, it can create named or anonymous shared in-memory databases
/// which will persist until the last connection to the shared database is
/// closed.
/// </summary>
/// <remarks>
@chrisfcarroll
chrisfcarroll / EnumerablePredicateExtensions.cs
Last active November 6, 2025 16:24
IEnumerable<T>?.None() , IEnumerable<T>?.None(predicate) , IEnumerable<T>?.HasCountAtLeast()
public static class EnumerablePredicateExtensions
{
/// <returns><c>true</c> if <paramref name="source"/>has no elements</returns>
public static bool IsEmpty<T>(this IEnumerable<T> source)
=> !source.Any();
///<summary>Synonym for <see cref="None"/></summary>
/// <returns><c>true</c> if <paramref name="source"/> is null or empty</returns>
public static bool IsNullOrEmpty<T>([NotNullWhen(false)]
this IEnumerable<T>? source)
@chrisfcarroll
chrisfcarroll / Autohotkey V2 for Mac User on Mac or PC keyboard.ahk
Last active March 11, 2026 16:27
AutoHotKey V2 Script for Mac Users on Windows. Switchable between Mac Keyboard and PC Keyboard.
#Requires AutoHotkey v2.0
#SingleInstance
;
; AutoHotKey 2.0 typographic relief for Mac keyboard users on Windows, whether
; — plugging a Mac Keyboard into a PC
; — or using a PC keyboard and missing the extended typographic symbols that the Mac puts on the Alt keys.
;
; + in addition, options for
; - even more typography and emojis
; - open favourite folders and URL shortcuts
@chrisfcarroll
chrisfcarroll / ParamsFromScriptFileName.ps1
Last active July 29, 2025 10:09
PowerShell example of getting parameter names from the script file with a regex for each parameter
#
# Get parameter values from the script file name.
#
$validparam1s= "Value1|Value2|Value3"
$param1PatternInFileName = "[^ \.]+(?=\.ps1$)"
$param1= (select-string -Pattern $param1PatternInFileName -InputObject $MyInvocation.MyCommand.Name).Matches.Value
if(-not( $param1 -match $validparam1s))
{
throw "$($MyInvocation.MyCommand.Name) does not end with a valid param1 name. Expected one of $validparam1s."
}
@chrisfcarroll
chrisfcarroll / Program.cs
Last active June 18, 2025 15:41
.Net 9 webapi template with minimal api + Swagger + Swashbuckle
using Microsoft.OpenApi.Models;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("v1", new OpenApiInfo { Title = "Your SwaggerUI Title Here", Version = "v1", });
@chrisfcarroll
chrisfcarroll / LogActions.cs
Last active October 10, 2025 14:45
Briefer application log lines automatically adds method name and item descriptions | log.LogAction() | log.LogAction( thisAndthat ) | log.LogAction( thisAndthat, other )
using System.Runtime.CompilerServices;
using Microsoft.Extensions.Logging;
public static class LogActions
{
/// <summary>
/// Log the current Method call and any relevant
/// parameter(s) <paramref name="loggableState"/> at log level <see cref="LogLevel.Information"/>
/// </summary>
/// <param name="log">the ILogger.</param>
@chrisfcarroll
chrisfcarroll / CSharpKeywordRequiredAttributes.cs
Created May 28, 2025 08:29
CompilerServices and Diagnostics.CodeAnalysis Attribute polyfills for the required keyword in .NetStandard2, .Net5, .Net6
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
//
// License statement and more attributes source code at
// https://github.com/dotnet/runtime/tree/main/src/libraries/System.Private.CoreLib/src/System/Runtime/CompilerServices
//
// ReSharper disable CheckNamespace
using System.ComponentModel;
namespace System.Runtime.CompilerServices