Skip to content

Instantly share code, notes, and snippets.

View deadlydog's full-sized avatar

Daniel Schroeder deadlydog

View GitHub Profile
@deadlydog
deadlydog / NewApplicationOrServiceChecklist.md
Last active August 30, 2020 16:54
Things every application / service should have

Things to include in every application / service

Some things that every application or service you build should have:

  • Logging (preferably centralized)
  • Metrics (to know how the app is performing (slow endpoints, etc.))
  • Alerts (to be notified when things aren't working properly)
  • Telemetry (to know which parts of the app / service are used most, or not at all and can be removed)
  • User Feedback Mechanism (so users can easily report issues or request new features)
  • Feature Flags (to enable rolling features / changes out in a controlled manner)
@deadlydog
deadlydog / PowerShellSingleFileScriptTemplate.ps1
Last active February 28, 2024 23:44
PowerShell template for a single-file script
[CmdletBinding()]
Param
(
)
Process
{
}
@deadlydog
deadlydog / InvokeMethodWithRetries.cs
Created December 15, 2021 04:16
C# generic function to execute any function, retrying if an exception is thrown
public static T InvokeMethodWithRetries<T>(Func<T> method, int maxNumberOfAttempts = 5)
{
int numberOfAttempts = 0;
while (numberOfAttempts < maxNumberOfAttempts)
{
try
{
return method.Invoke();
}
catch (Exception ex)
@deadlydog
deadlydog / PowerShell bug reproduction code.ps1
Last active March 10, 2022 04:35
Paste this into the PowerShell command line and you'll get an odd `An error occurred while creating the pipeline` error. Remove one "d" from the end and you'll get the expected `Get-Something is not recognized as a name of a cmdlet` error. This info is related to this tweet: https://twitter.com/deadlydog/status/1500295904615702531?s=20&t=7XvHRhT…
Get-Something dslkfjds lkjfdsl jflkdsfljdsalkf dslkf jlkdsjf lkdsj fljds lkf jdsalkf dslkfj dslfj lkdsjf ldskj flkds jflkjds lkf jdslfk jdsalkf jds jflkds jflkdsjflkds flkjdsflk jdslkf lkdsjflkdsj fljds lkf jdslfj sldjf kds flk jdsfl dsf dsljf ds jfhds lf jdsjf dsljflkds jfsjldsj fl jdsflkjdsflkjds dsfadsf dd
@deadlydog
deadlydog / MigrateIisAppsAndConfigurationToOtherServer.cmd
Created November 17, 2022 16:24
Migrate IIS Apps And Configuration ToOther Server
:: This script will migrate all of the IIS Applications and Configuration from the local server to the destination server.
:: This script needs to be ran from the source server that has the IIS configuration that you want to migrate.
:: MsDeploy will often generate a lot of output, so it's best to remote desktop onto the server that you want to migrate,
:: rather than running this command via PowerShell Remoting, as it will take a very long time to pipe the output back to
:: your local machine.
:: The server you are syncing to must also have Web Deploy installed on it. You can download it from:
:: http://www.microsoft.com/en-ca/download/details.aspx?id=43717
:: Be sure to do the "Complete" installation, not just the "Typical" so that the Web Deployment Agent Service gets installed.
@deadlydog
deadlydog / PowerShellUtilities.psm1
Last active December 17, 2023 18:26
Powershell function Invoke-ScriptBlockWithRetries to execute arbitrary PowerShell code and automatically retry if an exception is thrown
function Invoke-ScriptBlockWithRetries
{
param
(
[Parameter(Mandatory = $true, HelpMessage = 'The script block to execute.')]
[ValidateNotNullOrEmpty()]
[scriptblock] $ScriptBlock,
[Parameter(Mandatory = $false, HelpMessage = 'The maximum number of times to retry the script block.')]
[int] $MaxNumberOfRetries = 5,
@deadlydog
deadlydog / ExampleUsage.cs
Last active June 28, 2023 09:07
Wraps the .NET IMemoryCache in the Stale Cache pattern to provide Best-Before (Stale) date functionality, allowing apps to achieve better fault tolerance
using Caching;
using Microsoft.Extensions.Logging;
namespace App;
public class ExampleUsage
{
private readonly ILogger<ExampleUsage> _logger;
private readonly StaleMemoryCache _staleMemoryCache;
private readonly IAuthService _authService;
@deadlydog
deadlydog / SlackWebhookTest.ps1
Created November 28, 2023 23:12
PowerShell snippet for testing a Slack webhook
# This code shows how to easily test a Slack webhook from PowerShell. The URL here is a dummy URL.
$slackUri = "https://hooks.slack.com/services/T025sdfsdfsdf/B67sdfsdfsdf/khAfsdfsfsfsdfsdfsdf"
$body = ConvertTo-Json @{
pretext = "Testing Slack integration"
text = "This is just a test to ensure the Slack webhook works and sends messages to the correct Slack channel."
color = "#142954"
}
Invoke-RestMethod -Uri $slackUri -Method Post -Body $body -ContentType 'application/json'