View PasswordResetUrl.txt
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
{policy} = "Azure Password Reset Policy"; | |
{0} = "B2C directory name"; | |
{client_id} = B2C Client Id; | |
https://{0}.b2clogin.com/{0}.onmicrosoft.com/oauth2/v2.0/authorize?p={policy}&client_id=&redirect_uri=https://localhost:44310/oauth/passwordresetresponse&scope=openid&response_type=id_token&prompt=login&response_mode=form_post |
View CreditCardExpiryValidator.cs
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; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var x = new CardExpiryValidator("10/2021"); | |
Console.WriteLine(x.IsExpired); | |
} | |
} |
View PassesLuhnTest.cs
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
private static bool PassesLuhnTest(string cardNumber) | |
{ | |
ReadOnlySpan<char> value = cardNumber; | |
var sum = 0; | |
var isDouble = false; | |
for (var i = value.Length - 1; i >= 0; i--) | |
{ | |
int digit; |
View QueryBuilder.cs
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
internal static class QueryBuilder | |
{ | |
internal static string Build(string uri, IDictionary<string, string> queryString) | |
{ | |
var sb = new StringBuilder(uri); | |
var hasQuery = uri.IndexOf('?') != -1; | |
foreach (var item in queryString) | |
{ |
View BearerPolicyEvaluator.cs
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 BearerPolicyEvaluator : IPolicyEvaluator | |
{ | |
private const string Scheme = "Bearer"; | |
public Task<AuthenticateResult> AuthenticateAsync(AuthorizationPolicy _, HttpContext context) | |
{ | |
if (!context.Request.Headers.ContainsKey("Authorization")) | |
return Task.FromResult(AuthenticateResult.Fail("No Authorization header found!")); | |
string authHeader = context.Request.Headers["Authorization"]; |
View JsonContent.cs
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 JsonContent : StreamContent | |
{ | |
private static MediaTypeHeaderValue JsonMediaType => new MediaTypeHeaderValue("application/json"); | |
public JsonContent(Stream stream) : base(stream) | |
{ | |
Headers.ContentType = JsonMediaType; | |
} | |
public static JsonContent Create(object value) |
View IntegerArray.cs
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 BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Order; | |
using BenchmarkDotNet.Running; | |
namespace App | |
{ | |
public sealed class Program | |
{ |
View RepositoryPattern.cs
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
//Insert new record to database | |
public interface ICreatableRepository<T> | |
{ | |
int Create(T value); | |
} | |
//List records | |
public interface IListableRepository<T> | |
{ | |
IList<T> List(DataParameterDictionary dataParameters); |
View FeedPagerService.cs
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
internal static class FeedPagerService | |
{ | |
private const int PageSize = 10; | |
internal static (List<FeedItem> feeds, int pageSize, int maxRecords) SkipRecords(int pageIndex, List<FeedItem> feeds) | |
{ | |
if (pageIndex < 0) pageIndex = 0; //fix negative | |
var startPage = pageIndex <= 1 ? 0 : (pageIndex - 1) * PageSize; |
NewerOlder