Skip to content

Instantly share code, notes, and snippets.

View gyuwon's full-sized avatar

Gyuwon Yi gyuwon

View GitHub Profile
@gyuwon
gyuwon / TryGetBasicAutheticationCredentials.cs
Created December 11, 2018 10:01
Extract credentials from basic authentication header.
// Although this function works it may not be the best way and has some bug.
bool TryGetBasicAutheticationCredentials(string authorizationHeader, out string username, out string password)
{
const string schemePrefix = "Basic ";
if (authorizationHeader != null &&
authorizationHeader.StartsWith(schemePrefix, System.StringComparison.OrdinalIgnoreCase))
{
try
{
public static class HostFunctions
{
public static void ConfigureServices(WebHostBuilderContext context, IServiceCollection services) => services
.AddSingleton<IMessageSerializer, JsonMessageSerializer>()
.AddSingleton(container => GetDbContextOptions(context.Configuration))
.AddTransient<EventStoreDbContext, IdentityEventStoreDbContext>()
.AddSingleton<Func<EventStoreDbContext>>(container => container.GetRequiredService<EventStoreDbContext>)
.AddSingleton<ISqlEventStore, SqlEventStore>()
.AddSingleton<ISqlEventPublisher, SqlEventPublisher>()
.AddSingleton<ISqlEventSourcedRepository<User>, UserRepository>()
using System;
namespace AnonymousFunctionsVsLocalFunctions
{
public class Program
{
public static void Main(string[] args)
{
var functions = new Functions();
.class public auto ansi beforefieldinit FailFastAsync.Functions
extends [mscorlib]System.Object
{
.method public hidebysig specialname rtspecialname instance void .ctor () cil managed
{
IL_0000: ldarg.0
IL_0001: call instance void [mscorlib]System.Object::.ctor()
IL_0006: ret
}
using System;
using System.Threading.Tasks;
namespace FailFastAsync
{
public class Program
{
public static async Task Main(string[] args)
{
var functions = new Functions();
@gyuwon
gyuwon / CombineLatestTest.cs
Created April 8, 2017 01:21
CombineLatest 테스트 케이스
using System;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace RxUnitTest
{
[TestClass]
public class CombineLatestTest
{
@gyuwon
gyuwon / Set-CsiPath.ps1
Created March 13, 2016 11:29
Set C# REPL path
function Append-Path {
param([string]$path)
if (Test-Path $path) { $env:Path += (";" + $path) }
}
Append-Path("${env:ProgramFiles}\MSBuild\14.0\Bin")
Append-Path("${env:ProgramFiles(x86)}\MSBuild\14.0\Bin")
@gyuwon
gyuwon / CallPerf.cs
Created February 16, 2016 02:54
Method call performance
using System;
using System.Diagnostics;
using System.Reflection;
namespace CallPerf
{
internal interface ICounter
{
long Count { get; }
@gyuwon
gyuwon / Optimization.cs
Last active February 16, 2016 02:53
Compilier optimization
using System;
using System.Diagnostics;
namespace Optimization
{
public class Program
{
public static void Main(string[] args)
{
var instance = new Program();
@gyuwon
gyuwon / ValidateParametersAttribute.cs
Last active September 25, 2017 00:08
ValidateParametersAttribute.cs
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Filters;
using static AttributeTargets;