Skip to content

Instantly share code, notes, and snippets.

View Eonasdan's full-sized avatar

Eonasdan Eonasdan

View GitHub Profile
@Eonasdan
Eonasdan / IPrincipalProvider.cs
Last active December 14, 2021 15:28
PrincipalProvider is a way to pass information about a user to various layers of a project
using System.Security.Claims;
namespace YourProject.Interfaces
{
/// <summary>
/// This interface provides a way to inject the user into the services without
/// crossing responsibilities.
/// </summary>
/// <example>
/// var userId = _principalProvider.ClaimsUser.GetUserId();
@Eonasdan
Eonasdan / Displaying Angular control errors with bootstrap.md
Last active December 2, 2021 19:29
Angular bootstrap control display error

TODO

@Eonasdan
Eonasdan / IOperationResult
Last active December 6, 2021 16:36
OperationResult
using System.Collections.Generic;
public interface IOperationResult
{
public bool Succeeded { get; }
public IEnumerable<OperationError> Errors { get; }
}
public interface IOperationResult<out T>: IOperationResult
@Eonasdan
Eonasdan / EntityTypeBuilderExtensions.cs
Last active November 9, 2021 19:56
A EF extension to run SQL scripts as part of a migration
/// <summary>
/// Added auditable metadata to the entity mapping.
/// </summary>
/// <typeparam name="TProperty"></typeparam>
/// <param name="builder"></param>
public static void AddAuditableMetadata<TProperty>([NotNull] this EntityTypeBuilder<TProperty> builder) where TProperty : class, IAuditableEntity
{
builder.HasOne(t => t.CreatedBy).WithMany().HasForeignKey(t => t.CreatedById);
builder.Property(t => t.CreatedOn).HasColumnName(nameof(AuditableEntity.CreatedOn));
builder.Property(t => t.UpdatedOn).HasColumnName(nameof(AuditableEntity.UpdatedOn));
@Eonasdan
Eonasdan / ComparePlugin.ini
Last active September 28, 2023 13:59
Notepad++ Compare plugin dark mode colors
[Main]
Old is First=1
Old on Left=1
Default Compare is to Prev=1
Go to First Diff=0
Check Encodings=1
Wrap Around=0
Compact NavBar=1
Ignore Spaces=0
Detect Moves=1
@Eonasdan
Eonasdan / bootstrap.toast.ts
Created October 2, 2021 14:40
ngx-toastr Bootstrap 5
import { Component } from '@angular/core';
import { GlobalConfig, Toast, ToastPackage, ToastrService } from 'ngx-toastr';
import { BootstrapContextEnum } from '../../models/bootstrap-context-enum';
@Component({
selector: '[bootstrap-toast-component]',
template: `
<div
class="toast {{ containerClass }} show"
role="alert"
@Eonasdan
Eonasdan / ApplicationDbContext.cs
Created April 15, 2020 20:30
Read dates from SQL as UTC in EF Core
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
//....
var dateTimeConverter = new ValueConverter<DateTime, DateTime>(
v => v.ToUniversalTime(),
v => DateTime.SpecifyKind(v, DateTimeKind.Utc));
var nullableDateTimeConverter = new ValueConverter<DateTime?, DateTime?>(
@Eonasdan
Eonasdan / PredicateExtensions.cs
Created April 13, 2020 20:21
Predicate Extensions
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq.Expressions;
namespace Extensions
{
[DebuggerStepThrough]
public static class PredicateExtensions
{
@Eonasdan
Eonasdan / HallOfShame.md
Last active October 5, 2019 14:51
Recruiter Hall of Shame

This is a list of recuiter companies that either

  • Don't actually read/understand your skill profile.
  • Don't pay attention to location requirements
  • Don't pay attention to your job type (full time, contract) requirements.
Company Email Suffix (@xyz.com)
@Eonasdan
Eonasdan / crystal_flower_plant.json
Last active June 6, 2019 11:56
Agricraft + Seeds For Wizardry + Electroblob's Wizardry. Place under config\agricraft\json\defaults\mod_t3s4ebw
{
"path": "mod_t3s4ebw/crystal_flower_plant.json",
"enabled": true,
"id": "ebwizardry:crystal_flower_plant",
"plant_name": "Crystal Flower",
"seed_name": "Magic Seeds",
"seed_items": [
{
"item": "t3s4ebw:magic_seed",
"meta": 0,