Skip to content

Instantly share code, notes, and snippets.

@d1820
d1820 / buffers.ts
Last active March 4, 2017 19:40
Circular and Memory Buffer Example
//taken from https://github.com/tomsmeding/circular-buffer/blob/master/index.js and modified
//new features:
//find()
//getKeys()
//getValues()
//Persistant Buffer new features
//find() - finds a value by key
//getKeys() - gets only the keys available
//getValues() - gets the values
//load() - loads a buffer for use (useful if coming from server or localstorage)
@d1820
d1820 / multifield.sort.js
Last active March 15, 2017 02:37
Cool multiple sort function found online, that also handles reverse sorting.
generateSortFn(props) {
return function (a, b) {
for (var i = 0; i < props.length; i++) {
var prop = props[i];
var name = prop.name;
var reverse = prop.reverse;
if (a[name] < b[name])
return reverse ? 1 : -1;
if (a[name] > b[name])
return reverse ? -1 : 1;
@d1820
d1820 / BuilderResult.cs
Last active November 27, 2023 22:17
.Net Controller Unit Test Mock Builder
using System.Security.Claims;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Moq;
namespace Infrastructure.Testing.Builders
{
public class BuilderResult : HttpContextBuilderResult
{
@d1820
d1820 / AWS_Aurora_DataAPI_Expression_Mappers.cs
Last active June 4, 2020 03:23
AWS Aurora DataAPI expression mappers - .Net Core 3.1
public static class ColumnTypes
{
public const int STRING = 12;
public const int BOOL = -7;
public const int TIMESTAMP = 93;
}
@d1820
d1820 / ObfuscatorConverter.cs
Created October 18, 2023 13:49
JsonConverter Obfuscator
public class ObfuscatorConverter : JsonConverter
{
private readonly IEnumerable<Type> _types;
private readonly int _charsToShow;
private readonly char _obfuscateChar;
public ObfuscatorConverter() : this(2, '*')
{
}
@d1820
d1820 / TaskExtensions.cs
Created October 24, 2023 15:02
.Net Task Extensions
// we use this to group them all as available based on already using this namespace
namespace Common.Extensions
{
/// <summary>
/// adapted from https://archive.ph/2022.10.14-213608/https://betterprogramming.pub/my-top-7-custom-extension-methods-for-net-7-and-c-494acb2e6634#selection-1935.0-2339.1
/// </summary>
public static class TaskExtensions
{
/// <summary>
@d1820
d1820 / PropertyMap.cs
Last active March 19, 2024 13:02
Parse object to create getter and setter expresssions
using System.Reflection;
namespace Entities
{
public class PropertyMap<T>
{
public Func<T, object> Getter { get; set; }
public PropertyInfo PropertyInfo { get; set; }
@d1820
d1820 / CleanBinObj.ps1
Last active November 1, 2023 19:10 — forked from xtrmstep/cleanup-objbin.ps1
PowerShell command to delete all \bin and \obj folders. Use as a VS2022 External Tool
Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { Write-Host "Removing $($_.fullname)"; remove-item $_.fullname -Force -Recurse }; Write-Host "Complete"
@d1820
d1820 / SqlExpressionVisitor Example.txt
Last active December 29, 2023 17:57
Convert Linq Where expressions to user friendly string
foreach (var item in spec.WhereExpressions)
{
var sqlVisitor = new ExportsAPI.Domain.Visitors.SqlSearchExpressionVisitor();
string sqlString = sqlVisitor.VisitExpression(item.Filter, test);
sql.Add(sqlString);
}
SQL list:
[0]: "(Assigned.UserName = 'Awesome')"
[1]: "(Id = 'fb9244e7-72d5-4842-95a2-7b44af136a9c')"
[2]: "(ClientId = 'fb9244e7-72d5-4842-95a2-7b44af136a9c')"
@d1820
d1820 / ExampleTest.cs
Last active January 13, 2024 19:14
Running XUNIT Tests that need a static implementation of a class
public class CommentHelperTests: IClassFixture<TestFixture>
{
private readonly TestFixture fixture;
public CommentHelperTests(TestFixture fixture, ITestOutputHelper output)
{
this.fixture = fixture;
this.fixture.Initialize(output);
}