Skip to content

Instantly share code, notes, and snippets.

View stefanolsen's full-sized avatar

Stefan Holm Olsen stefanolsen

View GitHub Profile
// Copyright 2019 Stefan Holm Olsen
//
// Permission to use, copy, modify, and/or distribute this software for an
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@stefanolsen
stefanolsen / ArabicGlyphConverter.cs
Last active April 18, 2023 07:28
Code listings for blog post about converting Arabic letters to correct glyphs depending on their position. Read about it here: https://stefanolsen.com/posts/rendering-correct-arabic-glyphs-in-pdf-using-pdfsharp/
// Copyright 2019 Stefan Holm Olsen
//
// Permission to use, copy, modify, and/or distribute this software for an
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@stefanolsen
stefanolsen / Startup.cs
Created April 20, 2019 09:25
Code listings for blog post about cache busting and long time caching. Read about it here: https://stefanolsen.com/posts/cache-busting-2-an-update-for-aspnet-core/
using Microsoft.AspNetCore.Builder;
using Microsoft.Net.Http.Headers;
public class Startup
{
public void Configure(IApplicationBuilder app)
{
var staticFileOptions = new StaticFileOptions
{
OnPrepareResponse = context =>
@stefanolsen
stefanolsen / CollectionExtensions.cs
Last active June 2, 2019 18:29
Extension method for materializing a LINQ method chain to an Array or List without resizing. Mentioned here: https://stefanolsen.com/posts/8-things-to-avoid-to-make-an-episerver-site-go-faster/
// Copyright 2019 Stefan Holm Olsen
//
// Permission to use, copy, modify, and/or distribute this software for an
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@stefanolsen
stefanolsen / ApplicationInsightsJobFilter.cs
Last active March 21, 2023 20:37
Code listings for blog post about Hangfire and Optimizely. Read about it here: https://stefanolsen.com/posts/4-tips-and-tricks-for-hangfire-on-optimizely-cms/
using System;
using System.Text.Json;
using Hangfire.Server;
using Microsoft.ApplicationInsights;
using Microsoft.ApplicationInsights.DataContracts;
using Microsoft.ApplicationInsights.Extensibility;
namespace DemoSite.Hangfire;
public class ApplicationInsightsJobFilter : IServerFilter
@stefanolsen
stefanolsen / SampleScheduledJob.cs
Last active August 15, 2023 19:45
Code listings for blog post about log correlation with Optimizely scheduled jobs and Application Insights. Read more at https://stefanolsen.com/posts/correlate-telemetry-for-scheduled-jobs-in-optimizely-cms/
using System;
using EPiServer.PlugIn;
using EPiServer.Scheduler;
using EPiServer.ServiceLocation;
using Microsoft.ApplicationInsights;
namespace DemoSite.ScheduledJobs;
[ScheduledPlugIn(
DisplayName = "Sample job",