This file contains hidden or 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
| class Future<T> { | |
| private resolver: (value: T) => void; // readonly | |
| private rejecter: (error: Error) => void; // readonly | |
| private _isCompleted: boolean = false; | |
| constructor() { | |
| this.promise = new Promise((resolve, reject) => { | |
| this.resolver = resolve; | |
| this.rejecter = reject; | |
| }); |
This file contains hidden or 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> | |
| /// Creates a custom object based on the json values. | |
| /// </summary> | |
| /// <typeparam name="T">The object type to convert.</typeparam> | |
| public abstract class JsonCreationConverter<T> : JsonConverter | |
| { | |
| public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) | |
| { | |
| if (reader.TokenType == JsonToken.Null) | |
| return null; |
This file contains hidden or 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; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 <[email protected]>, 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 hidden or 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); | |
| } |