This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class ProducerConsumerStream | |
{ | |
public static Stream Create(Func<Stream, Task> producer, PipeOptions? options = null) | |
{ | |
var pipe = new Pipe(options ?? PipeOptions.Default); | |
var readStream = pipe.Reader.AsStream(); | |
var writeStream = pipe.Writer.AsStream(); | |
Run(); | |
return readStream; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class JsonExtensions | |
{ | |
public static IEnumerable<JsonElement> SelfAndDescendants(this JsonElement element) | |
{ | |
if (element.ValueKind == JsonValueKind.Undefined) | |
yield break; | |
yield return element; | |
if (element.ValueKind == JsonValueKind.Object) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/dotnet/runtime/issues/27869#issuecomment-475356398 | |
public static class MemoryOwnerSliceExtensions | |
{ | |
public static IMemoryOwner<T> Slice<T>(this IMemoryOwner<T> owner, int start, int length) | |
{ | |
if (start == 0 && length == owner.Memory.Length) | |
return owner; | |
return new SliceOwner<T>(owner, start, length); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- authors: Hadriel Kaplan <hadriel@128technology.com>, Stephen Cleary | |
-- Copyright (c) 2015-2022, Hadriel Kaplan, Stephen Cleary | |
-- This code is in the Public Domain, or the BSD (3 clause) license if Public Domain does not apply in your country. | |
-- Thanks to Hadriel Kaplan, who wrote the original FPM Lua script. | |
-- This is a starting point for defining a dissector for a custom TCP protocol. | |
-- This approach assumes that each message has a header that indicates the message length. | |
-- The code in this example uses a 4-byte header which is just a 4-byte big-endian message length, | |
-- and this length does not include the length of the header. | |
-- Modify the sections marked TODO to adjust these assumptions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// LINQPad script | |
async Task Main() | |
{ | |
byte[] LogicalAnd(byte[] x, byte[] y) | |
{ | |
var result = new byte[x.Length]; | |
for (int i = 0; i != x.Length; ++i) | |
result[i] = (byte) (x[i] & y[i]); | |
return result; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Microsoft.Extensions.Caching.Memory; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Logging; | |
using Microsoft.Extensions.Primitives; | |
using Nito.Logging; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// A hash combiner that is implemented with the Fowler/Noll/Vo algorithm (FNV-1a). This is a mutable struct for performance reasons. | |
/// </summary> | |
public struct FnvHash | |
{ | |
/// <summary> | |
/// The starting point of the FNV hash. | |
/// </summary> | |
public const int Offset = unchecked((int)2166136261); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Try | |
{ | |
public static Try<T> FromException<T>(Exception exception) => Try<T>.FromException(exception); | |
public static Try<T> FromValue<T>(T value) => Try<T>.FromValue(value); | |
public static Try<T> Create<T>(Func<T> func) => Try<T>.Create(func); | |
} | |
public sealed class Try<T> | |
{ | |
public static Try<T> FromException(Exception exception) => new Try<T>(exception, default, true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class InMemoryFileProvider : IFileProvider | |
{ | |
private readonly string _json; | |
public InMemoryFileProvider(string json) | |
{ | |
_json = json; | |
} | |
public IFileInfo GetFileInfo(string subpath) => new FileInfo(_json); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IdentityModel.Tokens.Jwt; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
using System.Security.Claims; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using Microsoft.IdentityModel.Protocols; | |
using Microsoft.IdentityModel.Protocols.OpenIdConnect; | |
using Microsoft.IdentityModel.Tokens; |