Skip to content

Instantly share code, notes, and snippets.

View DamianEdwards's full-sized avatar

Damian Edwards DamianEdwards

View GitHub Profile
@DamianEdwards
DamianEdwards / FormRepro.csproj
Created November 1, 2026 16:57
Minimal API RDG form validation: generated 500 versus runtime 400 (.NET 10 and 11 RC3)
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework Condition="'$(TargetFramework)' == ''">net11.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<DefaultItemExcludes>$(DefaultItemExcludes);evidence\**</DefaultItemExcludes>
<EnableRequestDelegateGenerator Condition="'$(EnableRequestDelegateGenerator)' == ''">true</EnableRequestDelegateGenerator>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(IntermediateOutputPath)generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
@DamianEdwards
DamianEdwards / get-yt-captions-feed.cs
Created April 21, 2026 01:12
Discovers the captions feed URL for a YouTube video by fetching the watch page, extracting the Innertube API key, calling the player API, selecting a caption track, and producing a fmt=json3 timedtext URL. It also does a quick fetch of that URL to confirm the captions feed is reachable.
#!/usr/bin/env dotnet
// This script takes a YouTube video ID and discovers the video's captions feed URL.
//
// It:
// - fetches the YouTube watch page for the video
// - extracts the INNERTUBE_API_KEY from the page HTML
// - calls YouTube's internal player API to retrieve caption track metadata
// - selects an English caption track when available, otherwise falls back to the first track
// - reads the track's baseUrl and ensures it requests JSON captions (fmt=json3)
@DamianEdwards
DamianEdwards / hex1bapp-simplified.cs
Last active April 17, 2026 05:34
hex1b daemon spawner sample
#!/usr/bin/env dotnet
#:property SuppressTrimAnalysisWarnings=false
#:property TrimmerSingleWarn=false
#:package System.CommandLine@2.0.6
#:package Spectre.Console@0.55.0
#:package Hex1b@0.128.0
using System.CommandLine;
using System.ComponentModel;
#!/usr/bin/env dotnet
#:property SuppressTrimAnalysisWarnings=false
#:property TrimmerSingleWarn=false
#:package System.CommandLine@2.0.6
#:package Spectre.Console@0.55.0
#:package Hex1b@0.128.0
using System.CommandLine;
using System.ComponentModel;
@DamianEdwards
DamianEdwards / SKILL.md
Created February 15, 2026 22:03
C# File-based apps skill
name csharp-scripts
description Run single-file C# programs as scripts for quick experimentation, prototyping, and concept testing. Use when the user wants to write and execute a small C# program without creating a full project.

C# Scripts

When to Use

  • Testing a C# concept, API, or language feature with a quick one-file program
@DamianEdwards
DamianEdwards / Ocr-Pdfs.ps1
Created January 17, 2026 20:49
Batch OCR PDFs using NAPS2 with auto-acquisition of portable NAPS2 CLI
# OCR-Pdfs.ps1
# Batch-OCR PDFs using NAPS2.Console.exe
[CmdletBinding()]
param(
[Parameter(Mandatory = $true, HelpMessage = "Path to a PDF file or folder containing PDFs to OCR.")]
[ValidateScript({ Test-Path $_ })]
[string]$InputPath,
[Parameter(Mandatory = $false, HelpMessage = "Path to the output folder. Defaults to InputPath\OCR (or parent folder\OCR for single file).")]
@DamianEdwards
DamianEdwards / Program.cs
Last active August 24, 2023 17:31
Auto-sized number parsing with System.Text.Json
using System.Numerics;
using System.Text;
using System.Text.Json;
using System.Text.Unicode;
var json = """
{
"anInt": 123,
"negativeInt": -123,
"biggerInt": 1234567890,
@DamianEdwards
DamianEdwards / Output.txt
Created January 4, 2023 01:22
PathGenerator utility for ASP.NET Core that generates URL paths (e.g. for links) using patterns that follow usual route syntax and provided values.
** Value Objects **
/user/123/posts?page=2&f=&q=test%20with%20spaces
/user/123/posts/?page=2&f=&q=test%20with%20spaces
user/123/posts?page=2
user/123/entity%20with%20spaces?page=2
/user/123?page=2
/user/123/posts?page=2
** Ordinal **
/user/123/posts?page=2
@DamianEdwards
DamianEdwards / Index.cshtml
Last active November 19, 2022 00:10
Example ASP.NET Core Razor Page in C# that calls a quotes REST API with fallback to offline quotes in case of failure
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
<div class="card">
<div class="card-body">
@await Model.GetInspirationalQuote()
</div>
<div class="card-footer">
@DamianEdwards
DamianEdwards / Program.cs
Created November 5, 2022 04:02
GZip a string and base64 encode the result in C# (.NET 7)
using System.Buffers;
using System.Buffers.Text;
using System.Diagnostics;
using System.IO.Compression;
using System.Security.Cryptography;
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
BenchmarkRunner.Run<Benchmarks>();