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 / generate-hn-uri.sh
Last active June 23, 2021 12:33
hacker news firebase download
#!/bin/bash
# generate file containing all URIs to execute to retrieve data from hacker news firebase API
# api docs: https://github.com/HackerNews/API
echo generating file hn-uri.txt
URICOUNT=10000000
echo file will contain $URICOUNT lines
@aaronhoffman
aaronhoffman / RedditOAuthApiController.cs
Last active December 23, 2020 23:25
Reddit OAuth API C# .NET
public ActionResult StartOAuth()
{
var redditOAuthAuthorizeUri = "https://www.reddit.com/api/v1/authorize";
var redditOAuthRedirectUri = "https://localhost:44399/RedditRedirectUri"; // your redirect uri
var redditOAuthScopes = ""; // ex: "identity,history" scope param https://github.com/reddit/reddit/wiki/OAuth2#authorization
var redditClientId = ""; // from app: https://www.reddit.com/prefs/apps
var oauthState = Guid.NewGuid(); // used to uniquely identify this request
// todo: store oauthState somewhere...
@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 / 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 / KuduWebJobService.cs
Last active October 30, 2020 13:40
Start and Stop Azure WebJobs via the Kudu REST API
public class KuduWebJobService
{
private string KuduUserName { get; set; }
private string KuduPassword { get; set; }
private string AzureWebsiteName { get; set; }
public KuduWebJobService()
{
this.KuduUserName = "";
this.KuduPassword = "";
@aaronhoffman
aaronhoffman / message.txt
Created December 5, 2017 17:17
keybase just for fun
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
keybase is fun!
-----BEGIN PGP SIGNATURE-----
Version: Keybase OpenPGP v2.0.76
Comment: https://keybase.io/crypto
wsBcBAABCgAGBQJaJtRyAAoJEGnJ5Wt+lYeyjTIH/13v97tzANkiSM3i+Vbr9Q8g
isis5gh3+4slL2SgsiF0YvnUH5o2hycYArm6r05DLdPZ2rja1YEzB1K0IV2EoAad
@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