Skip to content

Instantly share code, notes, and snippets.

View randyburden's full-sized avatar

Randy Burden randyburden

View GitHub Profile
@randyburden
randyburden / retryHelper.js
Created March 10, 2022 08:02
JavaScript retry helper utility that retries a function until the function returns a truthy value or the timeout elapses.
/*
Retry helper utility
Author: Randy Burden - 2022 - https://www.randyburden.com/
Dependencies: none
License:
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
@randyburden
randyburden / RoundRobinList.cs
Created November 12, 2021 03:43
C# Round Robin List that uses a simple, thread-safe, round-robin load balancing algorithm where it provides the next item in the list each time the Next method is called and starts back at the top of the list when it reaches the end of the list.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Helpers
{
/// <summary>
/// Creates a round robin list that uses a simple, thread-safe, round-robin
/// load balancing algorithm where it provides the next item in the list each
/// time <see cref="Next"/> is called and starts back at the top of the list
@randyburden
randyburden / SplitLargeLogFile.ps1
Last active November 8, 2021 18:37
Splits a large log file using PowerShell. Tested against very large multi-terabyte log files.
# Split Large Log File
$inputFile = "C:\temp\VeryLargeLogFile.log"
$outputDirectory = "C:\temp\logFileSplit"
$outputFileName = "LogFile"
$outputFileExtension = "log"
$upperBound = 500MB
New-Item -ItemType Directory -Force -Path $outputDirectory
$fromFile = [io.file]::OpenRead($inputFile)
@randyburden
randyburden / TableToCSV.md
Last active November 8, 2021 18:10
Export Table to CSV File

How to Export a Table to CSV

If you ever find yourself needing to export a table on a webpage you are viewing but they don't have a download or export to CSV button, use the following code to export the table to a CSV file.

  1. Use a Table to CSV browser extension like the following one. If that is not possible then following the instructions below:

  2. Open the browser's Developer Tools (F12 on Windows)

  3. Run the following command in the Console tab of the Developer Tools:

@randyburden
randyburden / How to Capture a Memory Dump When an App Crashes.md
Last active August 3, 2022 14:15
How to Capture a Memory Dump When an App Crashes, particularly an app that is crashing with a stack overflow exception. Tested with .NET Core apps.

How to Capture a Memory Dump When an App Crashes

  1. Download ProcDump

    • ProcDump is a Microsoft Sysinternals command-line utility for creating memory dumps / crash dumps.
  2. Run the following command to start capturing a memory dump anytime an application crashes:

mkdir C:\MemoryDumps
procdump.exe -accepteula -ma -i C:\MemoryDumps
@randyburden
randyburden / MethodInterceptionHelper.cs
Created October 27, 2021 17:19
C# Method Interception and Redirect Extension Methods and Examples using the MonoMod.RuntimeDetour library. Useful for testing hard to test code, libraries, static methods, simulating exceptions in deep call stacks of old code or libraries, etc. Keywords: C# test static methods, telerik justmock alternative, typemock alternative, typemock isolat…
using MonoMod.RuntimeDetour; // <PackageReference Include="MonoMod.RuntimeDetour" Version="21.1.11.1" />
using NUnit.Framework;
using System;
using System.Reflection;
namespace MethodInterceptionHelper
{
public static class MethodExtensions
{
/// <summary>
@randyburden
randyburden / CustomDataProtectionProvider.cs
Created September 20, 2021 20:52
CustomDataProtectionProvider for ASP.NET Core that uses a hard-coded AES Key. This is more like the old machine key in classic ASP.NET. This can easily be refactored to have the key supplied from appsettings.json or the database.
using Microsoft.AspNetCore.DataProtection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using System;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
namespace DataProtectionHelpers
{
@randyburden
randyburden / NonOverlappingTimer.cs
Last active February 14, 2023 18:30
Wraps System.Threading.Timer and guarantees non-overlapping executions.
using System;
using System.Threading;
namespace Helpers
{
///<summary>
/// Provides a mechanism for executing a method at specified intervals without overlapping executions.
/// While the timer is executing the method/action, if another interval run occurs, it will return
/// immediately (skipping the new run) to prevent an overlapping execution and allow the previous execution to continue.
/// </summary>
@randyburden
randyburden / RetryHelper.cs
Created April 16, 2021 18:24
Retry Helpers
using System;
using System.Threading;
namespace Helpers
{
/// <summary>
/// Retry helpers.
/// </summary>
public static class RetryHelper
{
@randyburden
randyburden / EntityFrameworkEnumerationClassPattern.cs
Created December 1, 2020 20:43
Entity Framework Enumeration Class Pattern
public class EmailType
{
// Provides enum-like behavior while the persisted
// reference/lookup/enum table provides referential integrity
public static readonly EmailType Welcome = new EmailType
{
Id = 1,
Name = "Welcome"
};