Skip to content

Instantly share code, notes, and snippets.

Avatar

Aaron Hoffman aaronhoffman

View GitHub Profile
@aaronhoffman
aaronhoffman / MacKeyboardOnWindows.ahk
Created Nov 18, 2020
AutoHotKey Mac keyboard on Windows
View MacKeyboardOnWindows.ahk
;=========================================
; 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 Nov 13, 2020
Async Thread Safe Concurrent Dictionary
View ThreadSafeConcurrentDictionary.cs
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 Nov 13, 2020
Run Async Methods Synchronously
View AsyncHelper.cs
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 Nov 13, 2020
Thread safe way to use MS Random in C#
View RandomFactory.cs
public interface IRandomFactory
{
Random CreateOrRetrieve();
}
public class RandomFactory : IRandomFactory
{
public Random CreateOrRetrieve()
{
return _threadLocalRandom.Value;
@aaronhoffman
aaronhoffman / ArgumentNullExceptionUnitTestHelper.cs
Last active Nov 5, 2020
Unit Test Constructor ArgumentNullException
View ArgumentNullExceptionUnitTestHelper.cs
// 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 Feb 13, 2020
IdentityServer Configuration SQL Tables EF Migration Issue
View 20200213083642_InitialIdentityServerConfigurationDbMigration.Designer.cs
// <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 Feb 11, 2020
Convert RSACryptoServiceProvider ToXmlString RsaXML W3C XKMS format to Public Private key PEM base64 string
View RSACryptoServiceProviderHelper.cs
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
View postal-code-to-state-map-condensed.csv
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 Sep 13, 2018
Newtonsoft.Json BaseJsonConverter example
View TrivialJsonConverter.cs
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
public class TrivialJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType)
{
return true;
}
View find-next-value-change-in-column.vba
Sub FindNextValueChangeInColumn()
'
' FindNextValueChangeInColumn Macro
'
On Error GoTo ErrHandler
Dim currentValue As String
Dim compareValue As String
currentValue = ActiveCell.Value
You can’t perform that action at this time.