Skip to content

Instantly share code, notes, and snippets.

View deadlydog's full-sized avatar

Daniel Schroeder deadlydog

View GitHub Profile
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 = ""
$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'
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 / 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
[Parameter(Mandatory = $true, HelpMessage = 'The script block to execute.')]
[scriptblock] $ScriptBlock,
[Parameter(Mandatory = $false, HelpMessage = 'The maximum number of times to retry the script block.')]
[int] $MaxNumberOfRetries = 5,
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:
:: Be sure to do the "Complete" installation, not just the "Typical" so that the Web Deployment Agent Service gets installed.
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:…
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 / 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)
return method.Invoke();
catch (Exception ex)
deadlydog / PowerShellSingleFileScriptTemplate.ps1
Last active June 3, 2024 08:16
PowerShell template for a single-file script
param (
process {
deadlydog /
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 / Repository's .editorconfig file
Last active March 12, 2024 21:04
This .editorconfig file should live in the repository and be committed to source control. This file should not contain personal preference settings like `indent_size`, as those should be specified in a parent .editorconfig file outside of the repository.
# This file should only include settings that affect the physical contents of the file, not just how it appears in an editor.
# Do not include personal preference presentation settings like a tab's `indent_size` in this file; those should be specified
# in a parent .editorconfig file outside of the repository.
# v1.7 - Source:
# Ensure that personal preference presentation settings can be inherited from parent .editorconfig files.
root = false
#### Core EditorConfig Options ####
deadlydog / Personal .editorconfig file
Last active January 2, 2022 05:24
This .editorconfig file should live outside of the repository (and thus not be committed to source control) in a parent directory, as it includes personal preference settings like `indent_size`.
# This .editorconfig file should live outside of all repositories (and thus not be committed to source control) in
# a parent directory, as it includes personal preference settings, like a tab's `indent_size`.
# v1.3
root = true
charset = utf-8
end_of_line = crlf
indent_style = tab