Skip to content

Instantly share code, notes, and snippets.

View VisualBean's full-sized avatar
🐵

Alex Wichmann VisualBean

🐵
View GitHub Profile
asyncapi: 2.5.0
info:
title: Example
version: 0.1.0
channels:
user/signedup:
subscribe:
message:
description: An event describing that a user just signed up.
payload:
@VisualBean
VisualBean / BidirectionalDictionary.cs
Created October 4, 2022 12:34
BidirectionalDictionary
public class BidirectionalDictionary<TFirst, TSecond>
{
internal Dictionary<TFirst, TSecond> FirstToSecondDictionary { get; set; }
internal Dictionary<TSecond, TFirst> SecondToFirstDictionary { get; set; }
internal BidirectionalDictionary()
{
this.FirstToSecondDictionary = new Dictionary<TFirst, TSecond>();
this.SecondToFirstDictionary = new Dictionary<TSecond, TFirst>();
}
@VisualBean
VisualBean / xunit_unittest.snippet
Created September 23, 2022 08:26
A visual studio snippet for a quick test setup
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>XUnit unit test</Title>
<Author>Alexander Wichmann</Author>
<Description>Creates a unit test structure</Description>
<Shortcut>xtest</Shortcut>
</Header>
<Snippet>
@VisualBean
VisualBean / Demon.cs
Created August 19, 2021 06:29
Demon class without equality overrides
public class Demon
{
private const int maxNameLength = 15;
private readonly IList<Underling> underlings = new List<Underling>();
private Demon(string name, ushort age, Power power)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException($"'{nameof(name)}' cannot be null or whitespace.", nameof(name));
@VisualBean
VisualBean / Demon.cs
Created August 19, 2021 06:28
fully encapsulated demon
public class Demon
{
private const int maxNameLength = 15;
private readonly IList<Underling> underlings = new List<Underling>();
private Demon(string name, ushort age, Power power)
{
if (string.IsNullOrWhiteSpace(name))
{
throw new ArgumentException($"'{nameof(name)}' cannot be null or whitespace.", nameof(name));
@VisualBean
VisualBean / copy.js
Created August 6, 2021 07:02
vuejs copy paste
<template>
<div id="app">
<input
v-on:focus="$event.target.select()"
ref="clone"
readonly
:value="text"/>
<button @click="copy">Copy</button>
</div>
</template>
if (_configuration == null && Options.ConfigurationManager != null)
{
_configuration = await Options.ConfigurationManager.GetConfigurationAsync(Context.RequestAborted);
}
var validationParameters = Options.TokenValidationParameters.Clone();
if (_configuration != null)
{
var issuers = new[] { _configuration.Issuer };
validationParameters.ValidIssuers = validationParameters.ValidIssuers?.Concat(issuers) ?? issuers;
public static async Task<OpenIdConnectConfiguration> GetAsync(string address, IDocumentRetriever retriever, CancellationToken cancel)
{
OpenIdConnectConfiguration openIdConnectConfiguration = JsonConvert.DeserializeObject<OpenIdConnectConfiguration>(doc);
if (!string.IsNullOrEmpty(openIdConnectConfiguration.JwksUri))
{
string keys = await retriever.GetDocumentAsync(openIdConnectConfiguration.JwksUri, cancel).ConfigureAwait(false);
openIdConnectConfiguration.JsonWebKeySet = JsonConvert.DeserializeObject<JsonWebKeySet>(keys);
foreach (SecurityKey key in openIdConnectConfiguration.JsonWebKeySet.GetSigningKeys())
{
services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.Authority = "<yourdomain>";
options.Audience = "<audience here>";
});
if (_configuration == null && Options.ConfigurationManager != null)
{
_configuration = await Options.ConfigurationManager.GetConfigurationAsync(Context.RequestAborted);
}