Skip to content

Instantly share code, notes, and snippets.

View davidfowl's full-sized avatar

David Fowler davidfowl

View GitHub Profile
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.WebUtilities;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
namespace WebApplication404
@davidfowl
davidfowl / parsingperf.cs
Last active November 12, 2019 00:45
Trying out various parsing techniques
using System;
using System.Buffers;
using System.IO;
using System.Text;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Running;
namespace MyBenchmarks
{
var state = new State();
var queue = new QueueClient();
try
{
    var item = await queue.DequeueAsync();
    state.Item = item;
}
@davidfowl
davidfowl / AsyncEnumerableQueue.cs
Last active July 8, 2019 07:27
Event loop flipped inside out with IAsyncEnumerable
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading.Tasks;
using Microsoft.Azure.ServiceBus;
namespace ConsoleApp60
{
class Program
{
@davidfowl
davidfowl / Program.cs
Last active June 29, 2024 18:09
A minimal fully asynchronous C# ASP.NET Core 3.0 application with routing (learn more about ASP.NET Core here https://docs.microsoft.com/en-us/aspnet/core/?view=aspnetcore-3.0)
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Hosting;
public class Program
{
public static void Main(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
public class NamedPipeConnectionListener : IConnectionListener
{
private readonly NamedPipeEndPoint _endpoint;
private readonly CancellationTokenSource _listeningSource = new CancellationTokenSource();
public NamedPipeConnectionListener(NamedPipeEndPoint endpoint)
{
_endpoint = endpoint;
ListeningToken = _listeningSource.Token;
}
public class DuplexPipe<TStream> : Stream, IDuplexPipe where TStream : Stream
{
private readonly IDuplexPipe _duplexPipe;
public DuplexPipe(IDuplexPipe duplexPipe, Func<Stream, TStream> wrapper)
{
_duplexPipe = duplexPipe;
Stream = wrapper(this);
Input = PipeReader.Create(Stream);
@davidfowl
davidfowl / bedrock-server.cs
Last active December 8, 2022 15:18
A sample of the current API usage with bedrock's listener layer
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
@davidfowl
davidfowl / FormReaderExtensions.cs
Last active March 15, 2019 00:35
FormReader prototype
public static class FormReaderExtensions
{
public static async ValueTask<IFormCollection> ReadFormAsync2(this HttpRequest request)
{
var reader = request.BodyPipe;
KeyValueAccumulator accumulator = default;
while (true)
{
var result = await reader.ReadAsync();
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v3.0",
"signature": "22c69940c9b25639e4f75123b23a701826ae1b1a"
},
"compilationOptions": {
"defines": [
"TRACE",
"DEBUG",
"NETCOREAPP",