Skip to content

Instantly share code, notes, and snippets.

View mtherien's full-sized avatar

Mike Therien mtherien

View GitHub Profile
@mtherien
mtherien / TimesSpanHelper.cs
Last active October 21, 2020 17:37
Timespan Helper
// Source: http://www.blackbeltcoder.com/Articles/time/creating-a-user-friendly-timespan-string
public static class TimeSpanHelper
{
/// <summary>
/// Constructs a user-friendly string for this TimeSpan instance.
/// </summary>
public static string ToUserFriendlyString(this TimeSpan span)
{
const int DaysInYear = 365;
const int DaysInMonth = 30;
@mtherien
mtherien / DbContextKeyExtensions.cs
Created May 7, 2020 19:56
DbContext Extension to get primary keys of an entity
// Source: https://stackoverflow.com/questions/30688909/how-to-get-primary-key-value-with-entity-framework-core
public static class DbContextKeyExtensions
{
private static readonly ConcurrentDictionary<Type, IProperty[]> KeyPropertiesByEntityType = new ConcurrentDictionary<Type, IProperty[]>();
public static string KeyValuesAsString(this EntityEntry entry)
{
if (entry == null)
{
@mtherien
mtherien / DbContextKeyExtensions.cs
Created May 7, 2020 19:55
DbContextExtension of getting primary keys on an entity
// Source: https://stackoverflow.com/questions/30688909/how-to-get-primary-key-value-with-entity-framework-core
public static class DbContextKeyExtensions
{
private static readonly ConcurrentDictionary<Type, IProperty[]> KeyPropertiesByEntityType = new ConcurrentDictionary<Type, IProperty[]>();
public static string KeyValuesAsString(this EntityEntry entry)
{
if (entry == null)
{
@mtherien
mtherien / Models.tst
Created December 19, 2018 15:02
Typewriter TypeScript Template for Models
${
// Enable extension methods by adding using Typewriter.Extensions.*
using Typewriter.Extensions.Types;
Template(Settings settings)
{
settings.OutputFilenameFactory = file => {
var firstClass = file.Classes.First();
var positionOfLastModel = firstClass.Name.LastIndexOf("Model");
var modelName = firstClass.Name.Substring(0, positionOfLastModel);
@mtherien
mtherien / ApiServices.tst
Last active December 19, 2018 15:01
Typewriter TypeScript template for Angular service
${
using Typewriter.Extensions.WebApi;
string ReturnType(Method m)
{
if (m.Type.Name == "IHttpActionResult" || m.Type.Name == "IActionResult")
{
return "void";
}
@mtherien
mtherien / CachedEnumerator.cs
Created June 21, 2018 13:24
CachedEnumerator
// Source: https://wilsonhut.wordpress.com/2012/03/15/obvious-extension-methods-ienumerable-cache/
public static class Extensions
{
public static CachedEnumerable<T> Cache<T>(this IEnumerable<T> enumerable)
{
return new CachedEnumerable<T>(enumerable);
}
}
@mtherien
mtherien / CreateMergeScript.sql
Created March 23, 2015 19:08
Creates a merge statement to get data from one table and merge it into another database table.
declare @sourceServer varchar(100)
declare @destinationTable varchar(100)
declare @destinationTableSchema varchar(100)
declare @sourceQuery nvarchar(max)
set @sourceQuery = 'select-statement-that-gets-data'
set @destinationTableSchema = 'dbo'
set @destinationTable = 'destination-table-name' -- set table name here
-- Begin work
@mtherien
mtherien / boxstarter.txt
Last active June 21, 2020 17:49
My Boxstarter script
Set-ExplorerOptions -showHidenFilesFoldersDrives -showFileExtensions
Enable-RemoteDesktop
#cinst visualstudio2019enterprise -y
cinst vscode -y
cinst git -y
cinst git-credential-manager-for-windows -y
cinst fiddler -y
cinst paint.net -y
cinst terminals -y
@mtherien
mtherien / CreateSeedScript.sql
Last active December 14, 2018 15:29
Creates a script that will maintain look-up table records for a database project. The resulting script can be used as a Post Deploy script in a database project, giving you the ability to create a working database from the project.Credits: http://www.codeproject.com/Articles/5598/Generating-INSERT-statements-in-SQL-Server http://www.codeproject.…
/// <summary>
/// Abstract class to use instead of an Enum class.
/// See https://lostechies.com/jimmybogard/2008/08/12/enumeration-classes/ for more information.
/// Also https://docs.microsoft.com/en-us/dotnet/standard/microservices-architecture/microservice-ddd-cqrs-patterns/enumeration-classes-over-enum-types.
/// </summary>
/// <example>
/// public class MyEnumerationClass : Enumeration
/// {
/// private MyEnumerationClass(int value, string displayName, string customParameter)
/// : base(value, displayName)