Skip to content

Instantly share code, notes, and snippets.

@flq
flq / chatgpt-webserver.cs
Last active March 2, 2025 14:27
The minimal file server written by ChatGPT
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Hosting;
using System;
using System.IO;
using System.Linq;
using System.Text.Encodings.Web;
using System.Threading.Tasks;
@flq
flq / Program.cs
Created March 1, 2025 10:20
Http File server V2025
using System.Net.Mime;
using Microsoft.AspNetCore.StaticFiles;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddSingleton(new RootDirectory(args[0]));
var app = builder.Build();
app.MapGet("/{*path}", (string? path, RootDirectory dir) =>
{
var fsItem = dir.Combine(path);
@flq
flq / AsyncEnumerableStream.cs
Last active October 3, 2024 15:10
A class that is supposed to help you consume an IAsyncEnumerable<byte[]> and expose it as a Stream
#nullable enable
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Utilities;
public class AsyncEnumerableStream(IAsyncEnumerable<byte[]> source) : Stream
@flq
flq / AssemblyPoolRegistrar.cs
Last active July 8, 2021 10:23
Utility classes for named dependencies (,NET Core, C# 9)
using System;
using System.Linq;
using System.Reflection;
using Microsoft.Extensions.DependencyInjection;
namespace DIPlaygroundWebApp.ServiceCollectionInfrastructure
{
public static class AssemblyPoolRegistrar
{
public static AssembliesForRegistration UseBulkRegistration(this IServiceCollection svcCollection,
@flq
flq / dotnet_snippets.txt
Created August 16, 2018 20:44
Some nice .NET snippets
.NET snippets
1. Deconstruct a regex match group collection
@flq
flq / nasties.cs
Last active December 16, 2017 12:04
Ye olde NRE from a ctor call
using System;
using System.Runtime.Remoting.Proxies;
internal class Program
{
private static void Main(string[] args)
{
var c = new CrazyObject();
Console.WriteLine(c.Hello());
Console.ReadLine();
}
@flq
flq / GetWSDLs.ps1
Created August 17, 2017 08:23
Acccess discovery service, download all WSDLs for listed services
function indent([parameter(ValueFromPipeline)]$Content)
{
$StringWriter = New-Object System.IO.StringWriter
$XmlWriter = New-Object System.XMl.XmlTextWriter $StringWriter
$xmlWriter.Formatting = "indented"
$xmlWriter.Indentation = 2
$Content.WriteContentTo($XmlWriter)
$XmlWriter.Flush()
$StringWriter.Flush()
Write-Output $StringWriter.ToString()
@flq
flq / BitempTests.fs
Last active December 16, 2016 13:15
Bitemporal code samples
module BitempTests
type TimePoint<'S> = {
recorded : int;
actual : int;
state : 'S;
}
type HistoryEntry<'S> = {
time : int;

Keybase proof

I hereby claim:

  • I am flq on github.
  • I am fquednau (https://keybase.io/fquednau) on keybase.
  • I have a public key ASDraf_OUnnhDWmgwKEoWTSV7QHQ1pjDPm0pCCSGME0ttwo

To claim this, I am signing this object:

@flq
flq / IiUnitTests.cs
Last active December 30, 2015 21:40
Gist for using NMeasure for surplus energy in atmosphere...
using System.Collections.Generic;
using Xunit;
using static NMeasure.U;
using static NMeasure.Tests.IiUnits;
namespace NMeasure.Tests
{
public class IIUnitsTests
{
public IIUnitsTests()