Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Schroeder deadlydog

View GitHub Profile
@deadlydog
deadlydog / PowerShell bug reproduction code.ps1
Last active Mar 10, 2022
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…
View PowerShell bug reproduction code.ps1
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 / InvokeMethodWithRetries.cs
Created Dec 15, 2021
C# generic function to execute any function, retrying if an exception is thrown
View InvokeMethodWithRetries.cs
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 / PowerShellSingleFileScriptTemplate.ps1
Last active Jan 9, 2022
PowerShell template for a single-file script
View PowerShellSingleFileScriptTemplate.ps1
[CmdletBinding()]
Param
(
)
Process
{
}
@deadlydog
deadlydog / NewApplicationOrServiceChecklist.md
Last active Aug 30, 2020
Things every application / service should have
View NewApplicationOrServiceChecklist.md

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 / Repository's .editorconfig file
Last active Mar 11, 2021
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.
View Repository's .editorconfig file
# 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.6
# Ensure that personal preference presentation settings can be inherited from parent .editorconfig files.
root = false
[*]
charset = utf-8
@deadlydog
deadlydog / Personal .editorconfig file
Last active Jan 2, 2022
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`.
View Personal .editorconfig file
# 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
@deadlydog
deadlydog / Synchronous-ZipAndUnzip.psm1
Created Feb 17, 2017
PowerShell Module to Synchronously Zip and Unzip using PowerShell 2.0
View Synchronous-ZipAndUnzip.psm1
#Requires -Version 2.0
# Recursive function to calculate the total number of files and directories in the Zip file.
function GetNumberOfItemsInZipFileItems($shellItems)
{
[int]$totalItems = $shellItems.Count
foreach ($shellItem in $shellItems)
{
if ($shellItem.IsFolder)
{ $totalItems += GetNumberOfItemsInZipFileItems -shellItems $shellItem.GetFolder.Items() }
@deadlydog
deadlydog / UpdateDirectoryLog4NetFilesAreWrittenToForClickOnceApplications.cs
Created Jan 25, 2017
Updates Log4Net appenders to adjust where they are set to write their log files to, to instead write them to the ClickOnce application's data directory.
View UpdateDirectoryLog4NetFilesAreWrittenToForClickOnceApplications.cs
// If we are running via ClickOnce, we need to adjust the path where the log files are written to, otherwise they won't be written at all.
if (ApplicationDeployment.IsNetworkDeployed)
{
var dataDirectory = ApplicationDeployment.CurrentDeployment.DataDirectory;
foreach (var appender in LogManager.GetRepository().GetAppenders())
{
var fileAppender = appender as FileAppender;
if (fileAppender != null)
{
var pathToReplace = Directory.GetParent(Directory.GetParent(fileAppender.File).FullName).FullName;
@deadlydog
deadlydog / IncludeClickOnceRevisionInVersionNumber.cs
Created Jan 10, 2017
Shows how to include part of the ClickOnce version in your application version
View IncludeClickOnceRevisionInVersionNumber.cs
public Version ApplicationVersion = new Version("1.11.2");
private void MainWindow_Loaded(object sender, RoutedEventArgs e)
{
// If this is a ClickOnce deployment, append the ClickOnce Revision to the version number (as it gets updated with each publish).
if (ApplicationDeployment.IsNetworkDeployed)
ApplicationVersion = new Version(ApplicationVersion.Major, ApplicationVersion.Minor, ApplicationVersion.Build, ApplicationDeployment.CurrentDeployment.CurrentVersion.Revision);
// Display the Version as part of the window title.
wndMainWindow.Title += ApplicationVersion;
@deadlydog
deadlydog / Import-PfxCertificate.ps1
Last active Jan 28, 2022
PowerShell script that imports a .pfx certificate file. Useful to do before building the solution on a build server. For more info, see https://blog.danskingdom.com/creating-a-pfx-certificate-and-applying-it-on-the-build-server-at-build-time/
View Import-PfxCertificate.ps1
param([string] $PfxFilePath, $Password)
# You may provide a [string] or a [SecureString] for the $Password parameter.
$absolutePfxFilePath = Resolve-Path -Path $PfxFilePath
Write-Output "Importing store certificate '$absolutePfxFilePath'..."
Add-Type -AssemblyName System.Security
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($absolutePfxFilePath, $Password, [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"PersistKeySet")