Skip to content

Instantly share code, notes, and snippets.

@markrendle
markrendle / Info.md
Created Jul 6, 2022
Prisoners Riddle
View Info.md
@markrendle
markrendle / TypedClaimsPrincipal.cs
Created Jun 26, 2022
Typed ClaimsPrincipal sketch
View TypedClaimsPrincipal.cs
using System.Security.Claims;
using Microsoft.AspNetCore.Http;
namespace TypedClaimsPrincipal;
public interface IClaimsPrincipalProperties<out T>
where T : IClaimsPrincipalProperties<T>
{
static abstract T Create(ClaimsPrincipal claimsPrincipal);
}
@markrendle
markrendle / ObsoleteLoggingInterceptor.cs
Last active Jun 10, 2020
gRPC Interceptor to check for an X-Obsolete header
View ObsoleteLoggingInterceptor.cs
internal class ObsoleteLoggingInterceptor : Interceptor
{
private readonly ILogger<ObsoleteLoggingInterceptor> _logger;
public ObsoleteLoggingInterceptor(ILogger<ObsoleteLoggingInterceptor> logger)
{
_logger = logger;
}
public override AsyncUnaryCall<TResponse> AsyncUnaryCall<TRequest, TResponse>(TRequest request,
@markrendle
markrendle / Program.cs
Created Apr 14, 2020
Get server URLs in .NET Core 3.1 app
View Program.cs
public static async Task Main(string[] args)
{
var host = CreateHostBuilder(args).Build();
var task = host.RunAsync();
var serverAddresses = host.Services.GetRequiredService<IServer>()
.Features
.Get<IServerAddressesFeature>();
View keybase.md

Keybase proof

I hereby claim:

  • I am markrendle on github.
  • I am rendle (https://keybase.io/rendle) on keybase.
  • I have a public key ASDQ0O3lbZRJvt1ZVJW5eOADbKKANZ3TNvT8kAoZq7Ox7go

To claim this, I am signing this object:

@markrendle
markrendle / Program.cs
Created Jul 24, 2019
IndentedTextWriter Async Fail
View Program.cs
using System.CodeDom.Compiler;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace IndentFail
{
class Program
{
static async Task Main(string[] args)
@markrendle
markrendle / Client.cs
Last active Jun 7, 2019
.NET Core 3.0 gRPC code
View Client.cs
using Greet;
using Grpc.Core;
namespace ClientApp
{
class Program
{
static async Task Main(string[] args)
{
var channel = new Channel("localhost:50051",
@markrendle
markrendle / ChannelsQueue.cs
Last active May 16, 2022
Better implementation of ChannelsQueue
View ChannelsQueue.cs
public class ChannelsQueue : IJobQueue<Action>
{
private ChannelWriter<Action> _writer;
public ChannelsQueue()
{
var channel = Channel.CreateUnbounded<Action>();
var reader = channel.Reader;
_writer = channel.Writer;
View Squares.cs
public static class Squares
{
public static int Square(int i) => i * i;
public static int SumOfSquares(int i) => Enumerable.Range(1, i).Select(Square).Sum();
}
@markrendle
markrendle / IXmlSerializable.cs
Last active Mar 2, 2018
SXmlSerializable shape for fixing Jon Skeet's problems in C# 9.0
View IXmlSerializable.cs
/*
The IXmlSerializable interface assumes the mutability of the type the implements it.
Now we have readonly structs, that's not a valid assumption. Ideally, there'd be a static
method that returned a new instance of the type, but you can't have static methods on
interfaces, because reasons.
*/
[Deprecated]
public interface IXmlSerializable