Skip to content

Instantly share code, notes, and snippets.

View vanbukin's full-sized avatar

Roman Bukin vanbukin

View GitHub Profile
@vanbukin
vanbukin / Auth.cs
Created June 3, 2020 17:49
Client credentials flow ASP.NET Core Background refresh
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;
using IdentityModel.Client;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
namespace Auth
@vanbukin
vanbukin / EventsGateway.fs
Created May 28, 2020 20:26
EventsGateway
namespace Dodo.EventStream
open System
open System.IO
open System.Threading.Tasks
open Microsoft.Azure.WebJobs
open Microsoft.Azure.WebJobs.Extensions.Http
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.Logging
open System.Text.Json
@vanbukin
vanbukin / Serializer.cs
Created May 27, 2020 18:29
System.Text.Json CosmosDb Serializer
using System;
using System.Buffers;
using System.IO;
using System.Text.Encodings.Web;
using System.Text.Json;
using Microsoft.Azure.Cosmos;
namespace Cosmos.Serialization
{
/// <summary>
public unsafe partial struct Uuid
{
public string ToStringWithStringCreate(string? format, IFormatProvider? formatProvider)
{
// ... same as original ToString
var uuidString = string.Create(32, this, (span, state) =>
{
fixed (char* uuidChars = &span.GetPinnableReference())
{
FormatNThis(state, uuidChars);
private unsafe void FormatD(char* dest)
{
// dddddddd-dddd-dddd-dddd-dddddddddddd
uint* destUints = (uint*)dest;
char** destUintsAsChars = (char**)&destUints;
uint* tableToHex = TableToHex;
dest[8] = dest[13] = dest[18] = dest[23] = '-';
destUints[0] = tableToHex[(byte)(_a >> 24)];
destUints[1] = tableToHex[(byte)(_a >> 16)];
@vanbukin
vanbukin / Program.cs
Created February 24, 2020 03:31
GuidBenchmarks - MemoryMarshal remove
using System;
using System.Collections.Generic;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace GuidBenchmarks
{
public static class Program
{
public static void Main(string[] args)
@vanbukin
vanbukin / CoreLibInternal.cs
Last active January 1, 2020 16:44
Uuid Interop
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
[assembly:IgnoresAccessChecksTo("System.Private.CoreLib")]
namespace Uuid.CoreLib
{
public static class Internal
{
public static unsafe void GetRandomBytes(byte* buffer, int length)
@vanbukin
vanbukin / HttpCallException.cs
Last active September 6, 2019 06:50
HttpExtensinos
using System;
namespace Infrastructure.ApiClients.Http
{
public class HttpCallException : Exception
{
public HttpCallException(int? statusCode, string message) : base(message)
{
StatusCode = statusCode;
}
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace Uuid1
{
[StructLayout(LayoutKind.Explicit, Pack = 1)]
[SuppressMessage("ReSharper", "InconsistentNaming")]
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Uuid1
{
public unsafe struct Uuidv1 : IFormattable
{
static Uuidv1()