Skip to content

Instantly share code, notes, and snippets.

View karelkral's full-sized avatar

Karel Kral karelkral

View GitHub Profile
@copernicus365
copernicus365 / CommaSeparatedArrayModelBinder.cs
Created December 8, 2021 20:26
A model binder allowing ASP.NET Core binding of primitive arrays as query parameters, modified from: https://stackoverflow.com/q/65544525/264031
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ModelBinding.Binders;
using Microsoft.Extensions.DependencyInjection;
@CarlosLanderas
CarlosLanderas / Program.cs
Created September 29, 2019 19:53
WorkerService + HealthCheck
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Diagnostics.HealthChecks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Routing;
public static class MessageConverter
{
private static InheritedTypeConverter<IMessage> _default = null;
public static InheritedTypeConverter<IMessage> Default
{
get
{
// TODO would be nice to have an attribute I could plug onto classes and have it "auto" find the classes through an assembly
if (_default == null)
@0xced
0xced / ForEachAsync.cs
Created May 26, 2018 17:57
Parallel foreach async enumeration with maximum degree of parallelism
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Parallel
{
public static class EnumerableExtensions
{
@Adam--
Adam-- / app.config
Created April 26, 2017 11:56
Newtonsoft.Json binding redirect
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
</dependentAssembly>
</assemblyBinding>
@yesvods
yesvods / gist:51af798dd1e7058625f4
Created August 15, 2015 11:13
Merge Arrays in one with ES6 Array spread
const arr1 = [1,2,3]
const arr2 = [4,5,6]
const arr3 = [...arr1, ...arr2] //arr3 ==> [1,2,3,4,5,6]
@GrantByrne
GrantByrne / UserValidator.cs
Created April 24, 2014 06:02
Using Fluent Validation with WPF - Dead Simple
using System.Text.RegularExpressions;
using FluentValidation;
using WpfFluentValidationExample.ViewModels;
namespace WpfFluentValidationExample.Lib
{
public class UserValidator : AbstractValidator<UserViewModel>
{
public UserValidator()
{
@jmangelo
jmangelo / CallerInfo.cs
Created June 9, 2012 14:51
Extended Logging Sample with .NET 4.5 Caller Info Attributes and NLog
using System;
using System.IO;
using System.Runtime.CompilerServices;
using NLog;
public sealed class CallerInfo
{
private CallerInfo(string filePath, string memberName, int lineNumber)
{
this.FilePath = filePath;