Skip to content

Instantly share code, notes, and snippets.

@mikegoatly
mikegoatly / DynaCacheSimpleInjector
Created June 20, 2014 11:36
Sample code for using DynaCache with SimpleInjector
using System;
namespace DynaCacheSimpleInjector
{
using System.Threading;
using DynaCache;
using SimpleInjector;
@mikegoatly
mikegoatly / DynaCacheSimpleInjectorWithUsage
Created June 27, 2014 10:59
DynaCache SimpleInjector with example usage
namespace DynaCacheSimpleInjector
{
using DynaCache;
using SimpleInjector;
class Program
{
static void Main()
{
namespace Microsoft.ServiceFabric.Data
{
#region Using directives
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
#endregion
@mikegoatly
mikegoatly / Program.cs
Created November 14, 2016 22:22
AsyncLocal and immutable stack state
using System;
using System.Threading;
using System.Collections.Immutable;
using System.Linq;
using System.Threading.Tasks;
public class Program
{
private static AsyncLocal<ImmutableStack<string>> stack = new AsyncLocal<ImmutableStack<string>>();
@mikegoatly
mikegoatly / Program.cs
Last active December 26, 2017 19:43
Merge MP3 files
namespace MergeMP3
{
#region Using statements
using System;
using System.IO;
using NAudio.Wave;
#endregion
function range(start: number, count: number) {
function* iterateRange() {
for (let i = start; i < count; i++) {
yield i;
}
}
return Array.from(iterateRange());
}
@mikegoatly
mikegoatly / code.cs
Created August 17, 2020 13:51
Reverse engineering read/write properties of a type
void Main()
{
Console.WriteLine(GetDefinition<Test>());
/* Prints:
public class Test
{
public System.Int32 Number { get; set; }
public System.String Name { get; set; }
}
@mikegoatly
mikegoatly / SafeTableKey.cs
Last active March 8, 2021 12:05
A simple struct that automatically replaces unsupported characters from an Azure Table partition or row key value.
/// <summary>
/// A helper class that removes any characters that are unsupported in an Azure Table partition or row key value.
/// </summary>
/// <example>
/// this.PartitionKey = new SafeTableKey("Somestring with unsupported characters");
/// this.RowKey = new SafeTableKey("....");
/// </example>
public struct SafeTableKey : IEquatable<SafeTableKey>
{
private static readonly ISet<char> reservedCharacters = new HashSet<char> { '\\', '/', '#', '?', '%' };
@mikegoatly
mikegoatly / iishelpers.ps1
Last active March 18, 2022 18:27
Useful PowerShell functions for working with local IIS sites and app pools
Import-Module IISAdministration
# Sets an environment variable for an IIS site in the applicationHost.config, rather than the web.config
# This allows for secrets to be stored securely, without any risk of them being added to source control.
function SetIISSiteEnvironmentVariable([string]$SiteName, [string]$Name, [string]$Value) {
$sm = Get-IISServerManager
$Env = $sm.GetApplicationHostConfiguration().GetSection("system.webServer/aspNetCore", $SiteName).
GetChildElement("environmentVariables").
GetCollection()
@mikegoatly
mikegoatly / ExtendedDependencyTelemetryInitializer.cs
Created July 25, 2022 07:52
Application Insights dependency header logging
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddExtendedDependencyTelemetry(this IServiceCollection services)
{
services.AddSingleton<ITelemetryInitializer, ExtendedDependencyTelemetryInitializer>();
return services;
}
}
public class ExtendedDependencyTelemetryInitializer : ITelemetryInitializer