Skip to content

Instantly share code, notes, and snippets.


Daniel Schroeder deadlydog

View GitHub Profile
deadlydog / SetUserPermissionsOnAllSqlDatabases.sql
Last active Aug 29, 2015
Loop through every SQL Server database on server, create user if they don't exist, and set that user's permissions
View SetUserPermissionsOnAllSqlDatabases.sql
exec master.dbo.sp_foreachdb
'USE ?
IF NOT EXISTS (SELECT 1 FROM sys.database_principals WHERE name = ''Domain\UserOrGroup'')
CREATE USER [Domain\UserOrGroup] FROM LOGIN [Domain\UserOrGroup]
exec sp_addrolemember ''db_backupoperator'', ''IQMETRIXHO\Development'';
deadlydog / CopySqlDatabase.sql
Last active Aug 29, 2015
Backup and restore (copy) sql database to specific drive based on environment
View CopySqlDatabase.sql
-- This script copies a database. The paths in this script are designed to run on IQ-RGVSQL009.
-- You need to have SQLCMD mode enabled to run this script (Query menu -> SQLCMD Mode).
:setvar DbToBackup "SeedCore" -- The database to copy from.
:setvar DbToRestore "Developer_DanS" -- The database to create/overwrite.
:setvar Environment "" -- Should be either "Test", "Automation", or an empty string (for Dev). Corresponds to the Sql Server Instance the DB is on.
:setvar TruncateDevDatabases "True" -- Leave this as 'True' to not keep full logs for the DbToRestore on the Dev Sql Server Instance.
:setvar PutAutomationDbOnSlowDrive "True" -- Leave this as 'True' to restore the DbToRestore to the Slow hard drive on the Automation Sql Server Instance.
USE [master]
deadlydog / RevertTFSWorkItemPriorityAndStackRanks.ps1
Last active May 13, 2016
In TFS 2012 a "bug" was introduced that transformed the functionality of the Priority and StackRank fields so that they get updated to a large random number when a work item is reordered in the web access UI, effectively wiping out the previous value that had been set manually (and purposely) by a human being. This script reverts the Priority an…
View RevertTFSWorkItemPriorityAndStackRanks.ps1
Set-StrictMode -Version Latest
$TFS_TEAM_PROJECT_COLLECTION_URI = 'YourProjectCollectionUrl' # e.g.
Function RevertField ($WorkItemCollection, $FieldName)
$WorkItemCount = $WorkItemCollection.Count
$WorkItemCounter = 0
Foreach ($WorkItem in $WorkItemCollection) {
deadlydog / Show Why Projects Rebuilt in Visual Studio.reg
Last active Sep 10, 2016
Modifies the registry to have the Visual Studio output window show additional info about why a project was rebuilt, even if you had just built it.
View Show Why Projects Rebuilt in Visual Studio.reg
Windows Registry Editor Version 5.00
; This will cause Visual Studio to display additional info in the Output pane as to why a project was rebuilt, even if you had just built it.
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 / 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 / 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 / Import-PfxCertificate.ps1
Created Dec 1, 2016
PowerShell script that imports a .pfx certificate file. Useful to do before building the solution on a build server.
View Import-PfxCertificate.ps1
param($PfxFilePath, $Password)
$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")
$store = new-object -argumentlist "MY", CurrentUser
deadlydog /
Last active Aug 30, 2020
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 / PowerShellSingleFileScriptTemplate.ps1
Last active Nov 21, 2020
Template for a single-file PowerShell script
View PowerShellSingleFileScriptTemplate.ps1