Skip to content

Instantly share code, notes, and snippets.

public static class UsefulExtensionMethods
{
public static TModel FirstOrNew<TModel>(this IEnumerable<TModel> queryable) where TModel : new()
=> queryable.FirstOrDefault() ?? new TModel();
public static async Task<TModel> FirstOrNewAsync<TModel>(this IQueryable<TModel> queryable) where TModel : new()
=> (await queryable.FirstOrDefaultAsync()) ?? new TModel();
public static bool IsActuallTheSameAs(this string s1, string s2, StringComparison stringComparison = StringComparison.InvariantCultureIgnoreCase)
=> string.Equals(s1, s2, stringComparison);
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates
# ASP.NET Core (.NET Framework)
# Build and test ASP.NET Core projects targeting the full .NET Framework.
# Add steps that publish symbols, save build artifacts, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/dotnet-core
trigger:
- master
- dev
pool:
public class RatioToFraction
{
/// <summary>
/// Converts a ratio to a fraction with the specified accuracy.
/// Accuracy = .0001 will make 1/1000 return correctly, but Accuracy = .001 return as 1/9991
/// </summary>
/// <param name="ratio">The ratio.</param>
/// <param name="accuracy">Accuracy is the maximum relative error; convert to absolute maxError</param>
/// <returns>Tuple in the form of (numerator, denominator)</returns>
public static (decimal, decimal) NormalizeFraction(decimal ratio, decimal accuracy)
public class KeyValuePairDataContainer : IEnumerable<KeyValuePair<string, string>[]>
{
public IEnumerator<KeyValuePair<string, string>[]> GetEnumerator()
{
yield return new KeyValuePair<string, string>[]
{
new KeyValuePair<string, string>("key1", "value1")
};
yield return new KeyValuePair<string, string>[]
{
@WrackedFella
WrackedFella / BootstrapCollapsibleCards.js
Created April 8, 2020 15:34
Small bit of JS that will make Bootstrap cards in your project collapsible if they have a `.card-header` element to use as a handle.
$('.card-header').append('<span class="fas fa-minus float-right position-absolute" style="top: 1em; right: 1em;"></span>');
$('.card-header').on('click', function (e) {
var card = $(this).closest('.card');
$(card.find('.card-body')[0]).toggle('slide');
swapCssClasses($(card.find('.position-absolute')), 'fa-plus', 'fa-minus');
});
public sealed class Status : TypeSafeEnum
{
private static readonly Dictionary<int, Status> Instance = new Dictionary<int, Status>();
public static readonly Status Active = new Status(0, "Active", 'A');
public static readonly Status Inactive = new Status(1, "InActive", 'I');
private Status(int value, string name, char code) : base(value, name, code)
{
Instance[value] = this;
}
@model EntityBase
@using System.ComponentModel
@using System.ComponentModel.DataAnnotations
@using System.Reflection
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.Extensions.Localization
@inject IHtmlLocalizer<DataAnnotationResources> DataAnnotationLocalizer
@inject IStringLocalizer<SharedResources> SharedLocalizer
using Microsoft.AspNetCore.Authorization;
namespace Api.Core
{
/// <summary>
/// Role based auth.
/// </summary>
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
public CustomAuthorizeAttribute()
using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
namespace IntegrationTest
{
internal class BasicRequestWithHttpClient
{
private const string Username = "";