Skip to content

Instantly share code, notes, and snippets.

View Grinderofl's full-sized avatar

Nero Sule Grinderofl

View GitHub Profile
@Grinderofl
Grinderofl / SearchFieldMutator.cs
Created May 22, 2012 06:47
Search field mutator to allow easy filter function writing
public delegate IQueryable<T> QueryMutator<T>(IQueryable<T> item);
/// <summary>
/// Mutator class
/// </summary>
/// <typeparam name="TSearch">Predicate expression</typeparam>
/// <typeparam name="TQuery">Query expression if TSearch == true</typeparam>
public class SearchFieldMutator<TSearch, TQuery>
{
public Predicate<TSearch> Condition { get; set; }
@Grinderofl
Grinderofl / Startup.cs
Created December 19, 2019 14:13
UnCSS PoC
services.AddWebOptimizer(x =>
{
x.AddBundle("/css/site.css", "text/css;charset=UTF-8", "static/css/styles.css")
.UnCss()
.MinifyCss()
.AutoPrefixCss()
.Concatenate()
.FingerprintUrls();
});
@Grinderofl
Grinderofl / RandomStringGenerator.cs
Created October 27, 2011 09:09
C# .NET: Random String Generator
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RandomStringGenerator.cs" company="">
// Nero Sule
// </copyright>
// <summary>
// Class for random string generation. Does not include ambiguous characters like
// I, 1 and l.
// Every four characters include one lower case character, one upper case character,
// one number and a special symbol in a random order. String will start with
// an alphanumeric character.
@Grinderofl
Grinderofl / project-summary-query.sql
Last active October 19, 2019 19:35
Dashboard Summary Query
-- Outermost query for the final projection of the calculated values
SELECT
ProjectId, -- Primary key of the project
ProjectName, -- Name of the project
ProjectArchived, -- Whether the project is archived
ProjectQuotedDayRate, -- Daily rate quoted for the client
ProjectBaseDayRate, -- Estimated day rate for the project (cost to the company)
ProjectTotalBudget, -- Total budget (amount billed to the client) of the project
CurrencyCode, -- Currency code (presently only 'GDP')
ClientId, -- Primary key of the client
@Grinderofl
Grinderofl / json_source.php
Created October 27, 2011 09:08
PHP CakePHP: JSON DataSource
<?php
// CORE/app/models/datasources/json_source.php
/**
* JSON Source module for CakePHP.
*
* @package cake
*/
@Grinderofl
Grinderofl / Artifacts-DotNetCore-Ef.cake
Created June 19, 2019 09:02
Specify starting migration
#addin nuget:?package=Newtonsoft.Json&version=12.0.1
using Newtonsoft.Json;
public class EfMigration
{
public string Id { get; set; }
public string Name { get; set; }
public string SafeName { get; set; }
}
@Grinderofl
Grinderofl / RouteConstraintExample.cs
Created May 31, 2019 09:12
Custom route constraint
public class PageRouteConstraint : IRouteConstraint
{
private static readonly Regex regex = new Regex($"^page=(\\d+)$");
public bool Match(HttpContext httpContext, IRouter route, string routeKey, RouteValueDictionary values, RouteDirection routeDirection)
{
if (routeDirection != RouteDirection.IncomingRequest || !values.TryGetValue(routeKey, out var page))
{
return false;
}
@Grinderofl
Grinderofl / AbstractAsyncInitializationMiddleware.cs
Created May 15, 2019 12:11
Initialize Database from middleware
public abstract class AbstractAsyncInitializationMiddleware
{
private readonly RequestDelegate next;
private readonly ILogger logger;
private Task initializationTask;
// ReSharper disable AccessToModifiedClosure
protected AbstractAsyncInitializationMiddleware(RequestDelegate next, IApplicationLifetime lifetime, ILogger logger)
{
this.next = next;
@Grinderofl
Grinderofl / TIcketsQuery.cs
Created April 5, 2019 08:03
Projection Example
public async Task<Model> Handle(Request request, CancellationToken cancellationToken)
{
var query = context.Tickets.AsNoTracking().AsQueryable();
query = FilterQuery(query, request);
var total = await query.CountAsync(cancellationToken);
query = OrderQuery(query, request);
query = PageQuery(query, request);
@Grinderofl
Grinderofl / MySigninManager.cs
Created January 9, 2019 12:54
Update last login date
public class MySigninManager : SignInManager<IdentityUser>
{
public MySigninManager(UserManager<IdentityUser> userManager, IHttpContextAccessor contextAccessor,
IUserClaimsPrincipalFactory<IdentityUser> claimsFactory, IOptions<IdentityOptions> optionsAccessor,
ILogger<SignInManager<IdentityUser>> logger, IAuthenticationSchemeProvider schemes)
: base(userManager, contextAccessor, claimsFactory, optionsAccessor, logger, schemes)
{
}
protected override async Task<SignInResult> SignInOrTwoFactorAsync(IdentityUser user, bool isPersistent, string loginProvider = null, bool bypassTwoFactor = false)