Skip to content

Instantly share code, notes, and snippets.

View luebster's full-sized avatar

Chris Luebbe luebster

View GitHub Profile
@luebster
luebster / DateTimeComparion.cs
Created March 17, 2023 13:30
Comparing "Now" to local datetimes in C# that makes the most sense to me
// create a DateTime in UTC Time
DateTime _startDate = TimeZoneInfo.ConvertTimeToUtc(Convert.ToDateTime("3/12/2023 20:00:00"), TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time"));
// Use UTC Now to compare UTC datetimes
DateTime _now = DateTime.UtcNow;
bool nowIsBefore = _now < _startDate;
bool nowIsEqual = _now == _startDate;
@luebster
luebster / MarketingCloudAPI.cs
Created January 27, 2023 20:19
MarketingCloud: Get the first page of records from a given Data Extension
using System;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
using System.Linq;
using RestSharp;
public class MarketingCloudApi
@luebster
luebster / flatpickr-config.js
Created July 20, 2022 20:16
DataFormatString for passing value to Flatpickr
$(".datePicker").flatpickr({
enableTime: true,
altInput: true,
altFormat: "n-j-Y h:i K"
});
@luebster
luebster / Azure_autoswap_config.md
Last active March 23, 2022 15:06
How to configure Azure deployment slots for reliable auto swaps

Configure warmup ("staging", "preproduction") deployment slot

WEBSITE_SWAP_WARMUP_PING_PATH: /statuscheck WEBSITE_SWAP_WARMUP_PING_STATUSES: 200

Set in every deployment slot, including production

WEBSITE_ADD_SITENAME_BINDINGS_IN_APPHOST_CONFIG: 1 //prevent random cold starts

Create a status check page

This is an example for ASP.NET Core

@luebster
luebster / UpdateUserPassword.cshtml
Last active October 28, 2021 14:45
Easy way to manually reset a user's password in .net core identity
@page
@model Demo.Pages.Users.UpdateUserPasswordModel
@{
}
<section class="section">
<div class="container">
<h1 class="is-headline">Update User Password</h1>
<form method="post">
@luebster
luebster / visualStudioSettings.vssettings
Created January 15, 2020 15:37
Visual Studio settings
<UserSettings>
<ApplicationIdentity version="16.0"/>
<ToolsOptions>
<ToolsOptionsCategory name="Environment" RegisteredName="Environment">
<ToolsOptionsSubCategory name="Import and Export Settings" RegisteredName="Import and Export Settings" PackageName="Visual Studio Environment Package">
<PropertyValue name="TrackTeamSettings">false</PropertyValue>
<PropertyValue name="TeamSettingsFile"/>
<PropertyValue name="AutoSaveFile">%vsspv_vs_localappdata_dir%\settings\CurrentSettings.vssettings</PropertyValue>
</ToolsOptionsSubCategory>
<ToolsOptionsSubCategory name="ProductUpdates" RegisteredName="ProductUpdates" PackageName="VS Setup Composition">
@luebster
luebster / Instructions.txt
Created January 9, 2020 12:41
Could not find roslyn/csc.exe
When Running a web app in Visual Studio errors in Could not find a part of the path '[path]\roslyn\csc.exe'.
Run this command in Package Manager Console:
Update-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -r
@luebster
luebster / Startup.cs
Created May 2, 2019 19:53
ASP.NET CORE SubdomainRedirect
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
// add this somewhere in your configure method
app.UseRewriter(new RewriteOptions()
.Add(new SubdomainRedirectRule())
.AddRedirectToWwwPermanent()
);
}
@luebster
luebster / IdentityExtensions.cs
Last active March 21, 2019 14:20
Extend All The Things: A set of helpers for ASP.NET Core
using System.Linq;
using System.Security.Principal;
public static class AuthorizationExtensions
{
public static bool IsInAllRoles(this IPrincipal principal, string[] roles)
{
return roles.All(r => principal.IsInRole(r));
}
@luebster
luebster / Program.cs
Last active March 20, 2019 12:40
Automatically apply Entity Framework Core database migrations on app first run after restart/deploy
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System.Threading.Tasks;
using MyApp.Data;
namespace MyApp
{
public class Program