Skip to content

Instantly share code, notes, and snippets.

@mikegoatly
mikegoatly / README.md
Created March 29, 2024 20:21
Flying duck animation for the Pimorini Cosmic Unicorn display

A simple animated bouncing duck on the Cosmic Unicorn display.

image

@mikegoatly
mikegoatly / books.json
Created February 23, 2024 10:29
Some generated book synopsis that can be used for testing purposes
[
{
"title": "Whispers of the Ancients",
"genre": "Fantasy",
"author": "Elena Marrow",
"synopsis": "In a realm where magic intertwines with the fabric of reality, a forgotten prophecy surfaces, beckoning a young farmhand, Kael, into a labyrinth of mysteries and ancient powers. With the guidance of a mysterious sorceress, Kael embarks on a journey to unlock his latent magic and prevent the resurgence of a dark god."
},
{
"title": "The Last Starship",
"genre": "Science Fiction",
@mikegoatly
mikegoatly / HttpLoggingHandler.cs
Created January 25, 2023 16:03
HttpLoggingHandler using Refit
/*
Based on https://medium.com/@florian.baader/log-http-requests-with-refit-81ee47bffb05
Usage:
services.AddRefitClient<TClient>(refitSettings)
.ConfigureHttpMessageHandlerBuilder(b => b.AdditionalHandlers.Add(new HttpLoggingHandler()));
*/
public class HttpLoggingHandler : DelegatingHandler
@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
@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 / 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 / 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; }
}
function range(start: number, count: number) {
function* iterateRange() {
for (let i = start; i < count; i++) {
yield i;
}
}
return Array.from(iterateRange());
}
@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
@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>>();