Skip to content

Instantly share code, notes, and snippets.

View aaronhoffman's full-sized avatar

Aaron Hoffman aaronhoffman

View GitHub Profile
@aaronhoffman
aaronhoffman / list-azure-app-insights-Instrumentation-Key.ps1
Last active May 11, 2022 17:17
list all azure app insights resources and Instrumentation Keys powershell script Azure Az
# more info https://aaron-hoffman.blogspot.com/2020/12/Find-Azure-Application-Insights-Resource-by-InstrumentationKey.html
# for each subscription in context
foreach ($subId in (Get-AzSubscription).Id | Get-Unique) {
write-host "Subscription $subId"
# set context to the given subId
Set-AzContext -SubscriptionId $subId
# List the name and InstrumentationKey of all Application Insights resources in this sub
Get-AzResource -ResourceType Microsoft.Insights/components -ExpandProperties | select -ExpandProperty Properties | select Name, InstrumentationKey | ft
@aaronhoffman
aaronhoffman / MacKeyboardOnWindows.ahk
Created November 18, 2020 20:45
AutoHotKey Mac keyboard on Windows
;=========================================
; AutoHotKey scripts for Corrections/Improvements to Mac keyboard on Windows OS https://github.com/aaronhoffman/autohotkey
;=========================================
; NOTES
; ! = ALT
; ^ = CTRL
; + = SHIFT
; # = WIN
#InstallKeybdHook
@aaronhoffman
aaronhoffman / ThreadSafeConcurrentDictionary.cs
Created November 13, 2020 18:18
Async Thread Safe Concurrent Dictionary
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Tasks;
public class ThreadSafeConcurrentDictionary
{
public bool TryGetValue<TValue>(string key, out TValue value)
{
return _dictionary.TryGetValue(key, out value);
@aaronhoffman
aaronhoffman / AsyncHelper.cs
Created November 13, 2020 17:30
Run Async Methods Synchronously
public static class AsyncHelper
{
private static readonly TaskFactory _taskFactory = new
TaskFactory(CancellationToken.None,
TaskCreationOptions.None,
TaskContinuationOptions.None,
TaskScheduler.Default);
public static TResult RunSync<TResult>(Func<Task<TResult>> func)
{
@aaronhoffman
aaronhoffman / RandomFactory.cs
Last active November 13, 2020 16:41
Thread safe way to use MS Random in C#
public interface IRandomFactory
{
Random CreateOrRetrieve();
}
public class RandomFactory : IRandomFactory
{
public Random CreateOrRetrieve()
{
return _threadLocalRandom.Value;
@aaronhoffman
aaronhoffman / ArgumentNullExceptionUnitTestHelper.cs
Last active November 5, 2020 21:14
Unit Test Constructor ArgumentNullException
// source: https://mikhail.io/2015/04/unit-testing-null-parameter-checks/
public void ConstructorMustThrowArgumentNullException(Type type)
{
foreach (var constructor in type.GetConstructors())
{
var parameters = constructor.GetParameters();
var mocks = parameters.Select(
p =>
{
@aaronhoffman
aaronhoffman / 20200213083642_InitialIdentityServerConfigurationDbMigration.Designer.cs
Last active February 13, 2020 08:50
IdentityServer Configuration SQL Tables EF Migration Issue
// <auto-generated />
using System;
using IdentityServer4.EntityFramework.DbContexts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
namespace SqlServer.Data.Migrations.IdentityServer.ConfigurationDb
@aaronhoffman
aaronhoffman / RSACryptoServiceProviderHelper.cs
Created February 11, 2020 12:52
Convert RSACryptoServiceProvider ToXmlString RsaXML W3C XKMS format to Public Private key PEM base64 string
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
public class RSACryptoServiceProviderHelper
{
// code from here:
// - https://stackoverflow.com/questions/23734792/c-sharp-export-private-public-rsa-key-from-rsacryptoserviceprovider-to-pem-strin
// - https://stackoverflow.com/questions/28406888/c-sharp-rsa-public-key-output-not-correct/28407693#28407693
StateName StateCode CondensedPostalCodeRanges
Alabama AL 35000-35299;35400-36999
Alaska AK 99500-99999
Arizona AZ 85000-85399;85500-85799;85900-86099;86300-86599
Arkansas AR 71600-72999
California CA 90000-90899;91000-92899;93000-96199
Colorado CO 80000-81699
Connecticut CT 06000-06389;06391-06999
Delaware DE 19700-19999
District of Columbia DC 20000-20099;20200-20587;56900-56999;20589-20597;20599
@aaronhoffman
aaronhoffman / TrivialJsonConverter.cs
Created September 13, 2018 21:47
Newtonsoft.Json BaseJsonConverter example
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public class TrivialJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return true;
}