Skip to content

Instantly share code, notes, and snippets.

View Xor-el's full-sized avatar
🏠
Working from home

Ugochukwu Mmaduekwe Xor-el

🏠
Working from home
View GitHub Profile
@Xor-el
Xor-el / SwashBuckleUtils.cs
Created May 13, 2024 20:57
Swagger Utils to generate Schema Id
static class SwashBuckleUtils
{
private static readonly Dictionary<Type, string> _map = new Dictionary<Type, string>();
private static string ToSchemaId(Type type, bool skipDeclaringType)
{
if (!_map.TryGetValue(type, out var name))
{
if (type.IsGenericType && !type.IsGenericTypeDefinition)
{
@Xor-el
Xor-el / gist:733de78e6c29c5c07eb441beb73c6e1a
Created May 11, 2024 18:36 — forked from rxaviers/gist:7360908
Complete list of github markdown emoji markup

People

:bowtie: :bowtie: 😄 :smile: 😆 :laughing:
😊 :blush: 😃 :smiley: ☺️ :relaxed:
😏 :smirk: 😍 :heart_eyes: 😘 :kissing_heart:
😚 :kissing_closed_eyes: 😳 :flushed: 😌 :relieved:
😆 :satisfied: 😁 :grin: 😉 :wink:
😜 :stuck_out_tongue_winking_eye: 😝 :stuck_out_tongue_closed_eyes: 😀 :grinning:
😗 :kissing: 😙 :kissing_smiling_eyes: 😛 :stuck_out_tongue:
@Xor-el
Xor-el / ReadRequestBody.cs
Created May 9, 2024 19:13
ReadRequestBody
public static async Task<string?> ReadBody(this HttpRequest httpRequest, Encoding? encoding = default)
{
encoding ??= Encoding.UTF8;
// don't get it by `PipeReader.Create(httpContext.Request.Body);`
var bodyReader = httpRequest.BodyReader;
var context = httpRequest.HttpContext;
ReadResult readResult;
@Xor-el
Xor-el / DbDataReaderExtensions.cs
Created May 2, 2024 07:58
DbDataReaderExtensions
using System.Data.Common;
using System.Reflection;
namespace Demo.Extensions
{
public static class DbDataReaderExtensions
{
public static T? Map<T>(this DbDataReader reader) where T : class, new()
{
// Check if the reader has rows
@Xor-el
Xor-el / Program.cs
Created May 1, 2024 15:42
Progressive Tax C#
var taxBands = new List<TaxBand>()
{
new() {
LowerLimit = 0,
UpperLimit = 11600,
RateInPercent = 10
},
new() {
LowerLimit = 11601,
@Xor-el
Xor-el / google-docs-copy.js
Created April 20, 2024 14:21 — forked from Snarp/google-docs-copy.js
Script to allow copying from a protected Google Doc
/*
<https://stackoverflow.com/questions/40296831/is-it-possible-to-force-a-copy-of-a-protected-google-doc>
NOTE - 2021-05-24
-----------------
The script below isn't the fastest way to copy-and-paste from a protected
Google Doc. Before trying it, I'd suggest following MikoFrosty's advice from
the comments:
@Xor-el
Xor-el / LaxVersusStrict.sql
Created April 16, 2024 23:03 — forked from bertwagner/LaxVersusStrict.sql
SQL Server 2016 JSON's Lax versus Strict modes
-- Lax (default: function will return an error if invalid JSON path specified
SELECT JSON_VALUE('{ "Color" : "Red" }', '$.Shape') --lax is the default, so you don't need to be explicitly state it
-- Output: NULL
SELECT JSON_VALUE('{ "Color" : "Red" }', 'lax $.Shape')
-- Output: NULL
-- Strict: function will return an error if invalid JSON path specified
SELECT JSON_VALUE('{ "Color" : "Red" }', 'strict $.Shape')
-- Output: Property cannot be found on the specified JSON path.
using System;
using System.Threading.Tasks;
namespace System.Collections.Concurrent
{
public static class ConcurrentDictionaryExtensions
{
/// <summary>
/// Provides an alternative to <see cref="ConcurrentDictionary{TKey, TValue}.GetOrAdd(TKey, Func{TKey, TValue})"/> that disposes values that implement <see cref="IDisposable"/>.
/// </summary>
@Xor-el
Xor-el / IQueryableExtensions.cs
Created November 24, 2023 15:58 — forked from ErikEJ/IQueryableExtensions.cs
Replacement for EF Core .Contains, that avoids SQL Server plan cache pollution
using System.Linq.Expressions;
namespace Microsoft.EntityFrameworkCore
{
public static class IQueryableExtensions
{
public static IQueryable<TQuery> In<TKey, TQuery>(
this IQueryable<TQuery> queryable,
IEnumerable<TKey> values,
Expression<Func<TQuery, TKey>> keySelector)
@Xor-el
Xor-el / QueryableExtensions.cs
Created September 15, 2023 18:53 — forked from jacobsimeon/QueryableExtensions.cs
IQueryable Extensions for ordering by a property specified by a string
using System;
using System.Collections.Generic;
using System.Data.Objects;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
namespace JacobSimeon.Extensions
{
public static class IQueryableExtensions