Skip to content

Instantly share code, notes, and snippets.

View JasonElkin's full-sized avatar

Jason Elkin JasonElkin

View GitHub Profile
@JasonElkin
JasonElkin / deploy.ps1
Last active September 6, 2023 16:40
Environment Variable replacement for appsettings.json on AppVeyor deployment
<#
AppVeyor Deployment Script
This script is run after deployment to the web server.
It substitutes environment variables in the appsettings.json file with values from the environment.
All environment variables that start with the prefix are loaded and substituted into the appsettings.json file
e.g. if the prefix is "APP_" then the environment variable "APP_ConnectionStrings.umbracoDbDSN" will set
the value of "ConnectionStrings.umbracoDbDSN" in the appsettings.json file.
@JasonElkin
JasonElkin / NullableDatePickerValueConverter.cs
Last active March 18, 2022 02:01
Nullable Date Picker Property Value Converter for Umbraco
public class NullableDatePickerValueConverter : DatePickerValueConverter
{
public override Type GetPropertyValueType(IPublishedPropertyType propertyType) => typeof(DateTime?);
public override object? ConvertSourceToIntermediate(
IPublishedElement owner,
IPublishedPropertyType propertyType,
object source,
bool preview)
@JasonElkin
JasonElkin / CustomDocumentRepository.cs
Created March 15, 2022 23:44
Enable non-unique node names based on parent content type in Umbraco v9
public class CustomDocumentRepository : DocumentRepository
{
private static readonly string[] allowNonUniqueChildNames = { EventsPage.ModelTypeAlias, NewsPage.ModelTypeAlias };
public CustomDocumentRepository(
IScopeAccessor scopeAccessor,
AppCaches appCaches,
ILogger<DocumentRepository> logger,
ILoggerFactory loggerFactory,
IContentTypeRepository contentTypeRepository,
@JasonElkin
JasonElkin / IEnumerableExtensions.cs
Last active November 25, 2021 14:42
Evenly distribute the contents of an IEnumerable between a (maximum) number of chunks
public static IEnumerable<IEnumerable<T>> ChunkEvenly<T>(this IEnumerable<T> list, int chunkCount)
{
int groups = 0;
int total = 0;
int count = list.Count();
while (total < count)
{
var size = (int)Math.Ceiling((count - total) / (decimal)(chunkCount - groups));
yield return list.Skip(total).Take(size);
groups++;
@JasonElkin
JasonElkin / ResponsiveImageHelper.cs
Last active November 8, 2021 17:37
Basic srcset generator for ImageProcessor in Umbraco v8
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Web;
namespace MooseCoding.Web.UI
{
public static class ResponsiveImageHelper
{
@JasonElkin
JasonElkin / AssemblyInfo.cs
Last active April 6, 2021 09:54
Application Insights tagging & versioning
//...
[assembly: PreApplicationStartMethod(typeof(Initializr), "Init")]
@JasonElkin
JasonElkin / DefaultController.cs
Created February 9, 2018 09:05 — forked from dawoe/DefaultController.cs
Donut Cache examples from Umbraco UK Festival talk "The need for speed"
public class DefaultController : RenderMvcController
{
[UmbracoDonutOutputCache(CacheProfile = "LongPageCache",
Options = OutputCacheOptions.NoCacheLookupForPosts &
OutputCacheOptions.ReplaceDonutsInChildActions, Order = 100)]
public override ActionResult Index(RenderModel model)
{
return base.Index(model);
}
}