Skip to content

Instantly share code, notes, and snippets.

Python3 FastAPI based REST API for storing and vending group memberships. Groups can have many members. Members are simply records with their type annoted in a 'type' column'. Every record, group or member, has an entry in a records table (types detailed below). The API is self documenting with OpenAPI (swagger) metadata.

The intention behind operations is to allow for eventual garbage collection of member records. These are units of work that operate on records within the database but shouldn't lock tables. Efforts will be made to perform partial updates and soft-delete memberships when external sytems notify of memberships being removed, the issue is that delta synchronization systems carry no guarantees, sometimes the system just doesn't tell you when someone was removed. That shorcoming can be worked around by triggering a member clean-up operation after a full-update, any membership whos last_operation_id value is less than the most recent completed full-update can be assumed no longer a member and soft

@sean-m
sean-m / srtshift.ps1
Created December 31, 2024 01:55
Apply a timeshift to an srt file and write to stdout.
#!/usr/bin/env pwsh
param($srtFile, $shiftMiliseconds=0)
if (-not $srtFile) {
throw "Must set srtFile path."
return
}
$srtLines = Get-Content $srtFile
## Takes and ACL and SID, returns an ACL with the correct entry for read-only permissions added.
function Add-ReadAce {
[OutputType([System.Security.AccessControl.FileSystemSecurity])]
param(
[Parameter(Mandatory=$true, ValueFromPipeline=$false)]
[System.Security.Principal.IdentityReference]$SID,
[Parameter(Mandatory=$true, ValueFromPipeline=$true, Position=0)]
[System.Security.AccessControl.FileSystemSecurity]$ACL
)
@sean-m
sean-m / ToKvText.cs
Last active November 2, 2023 22:45
Takes an object and does a naive pass at turing it into a string that would print well in a console.
public string ToKvText(object entry) {
if (entry == null) return string.Empty;
StringBuilder sb = new StringBuilder();
var properties = entry.GetType().GetProperties();
var longestPropertyLength = properties.Select(x => x.Name.Length).Max();
int indentation = longestPropertyLength + 3;
foreach (var p in properties) {
<?xml version="1.0" encoding="utf-16"?>
<StorableColorTheme xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Keys>
<string>ErrorForegroundColor</string>
<string>ErrorBackgroundColor</string>
<string>WarningForegroundColor</string>
<string>WarningBackgroundColor</string>
<string>VerboseForegroundColor</string>
<string>VerboseBackgroundColor</string>
<string>DebugForegroundColor</string>
@sean-m
sean-m / OrderGroupAtFirstOccurance.cs
Last active October 18, 2023 16:59
Extension method that will yield properties from a specified group of properties if any of them are encountered in the first collection. It's using the group metaphore because I use it for grouping properties together by name in a UI. Yes there's perf issues as things get big, it's your foot.
/// <summary>
/// Let's say you have a collection of things with an indeterminate ordering but when you
/// enumerate the things, you'd like a subset to be grouped together. That's what this
/// can do but there's no guarantee elements in the group parameter exist in the primaryCollection.
/// That can be seen as a bug or a feature, it's up to you.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="primaryCollection"></param>
/// <param name="group"></param>
/// <returns></returns>
@sean-m
sean-m / CsvFileReader.cs
Last active September 26, 2024 00:03
Helpers for optimistically loading strongly typed data in C# programs. Useful for bulk loading data for unit tests or dev environments. UglyDbInit will use the CsvFileReader to initlaize an entity framework database context.
using System.Reflection;
using System.Text.RegularExpressions;
using Microsoft.VisualBasic.FileIO;
namespace SMM {
public class CsvFileReader {
string file_path;
private CsvFileReader(string FilePath) {
@sean-m
sean-m / TimeKeeper.ps1
Last active June 30, 2025 16:35
Helper classes for performance instrumentation in PowerShell scripts. This is not the start and end of performance analysis of scripts, I'm not even saying it's good, it is as consistent and low overhead as I have the energy to make it right now and has helped troubleshoot a real problem at work.
#!/usr/bin/pwsh
#Requires -Version 5
#region TimeKeeper
################################################################################
## TimeKeeper ##
################################################################################
<#
This a set of helper functions for logging overlapping timeslices in regions
of your code. BeginFunctionTick, EndFunctionTick, New-TimeKeeper and
@sean-m
sean-m / StorageConverter.cs
Last active June 5, 2023 21:01
Just sick of looking up this size conversion math. This should be in the BCL.
/*
Usage:
var five = 5000.FromMB();
Console.WriteLine($"{five.ToKB()} KB");
Console.WriteLine($"{five.ToMB()} MB");
Console.WriteLine($"{five.ToGB()} GB");
Console.WriteLine($"{five.ToTB()} TB");
Console.WriteLine($"{five.ToPB()} PB");
@sean-m
sean-m / BeepOnChange.ps1
Created May 8, 2023 15:08
Take pipeline input and beep when the input changes. It will optionally stop when the change occurs.
function BeepOnChange {
<#
.Synopsis
Take pipeline input and beep when the input changes.
It will optionally stop when the change occurs.
.PARAMETER Skip
Number of lines to not consider for comparison. If you're piping
a long running command like ping /t, you want it to skip the
header of the command. Combine ping with the StopOnChange switch
for it to alert when a network connection comes back up and ping