Skip to content

Instantly share code, notes, and snippets.

View tcartwright's full-sized avatar

Tim Cartwright tcartwright

  • Houston, Texas
View GitHub Profile
@tcartwright
tcartwright / AlterDateTimeColumnsToDateTimeOffset.ps1
Last active September 17, 2024 14:03
SQL SERVER: Converts sql server datetime and datetime2 columns to datetimeoffset
Clear-Host
$module = Get-Module tcdbtools
if (!$module) {
Install-Module tcdbtools -Force
}
Import-Module tcdbtools
$module = Get-Module SqlServer
if (!$module) {
Install-Module SqlServer -Force
}
@tcartwright
tcartwright / GetWebSiteProcessId.ps1
Last active August 29, 2024 18:13
POWERSHELL: Get W3WP ProcessId for specific app pool name
Get-WmiObject Win32_Process -Filter "name = 'w3wp.exe'" |
Where-Object {$_.CommandLine -imatch "appPoolName"} |
Select-Object ProcessId, Name, CommandLine
@tcartwright
tcartwright / Directory.Build.props
Created August 12, 2024 14:03
VISUAL STUDIO: MY Standard Directory.Build.props file
<Project>
<PropertyGroup>
<!--ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally-->
<TreatWarningsAsErrors>true</TreatWarningsAsErrors> <!-- True for new projects, false for existing ones with lots of warnings -->
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<PublishReadyToRun>true</PublishReadyToRun>
<SelfContained>true</SelfContained>
<SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
@tcartwright
tcartwright / ComparePackageVersions.ps1
Last active July 23, 2024 18:51
POWERSHELL: Compare a project file to the Directory.Packages.props file
Clear-Host
<#
PURPOSE: To scan all of the projects in a directory and compare the PackageReferences to the
Directory.Packages.props PackageVersions. Outputs if any are missing from the Directory.Packages.props
#>
$solutionFolder = "C:\..solution path..\"
$files = (Get-ChildItem $solutionFolder -Recurse -Filter "*.csproj").FullName
@tcartwright
tcartwright / DisableClientIpMaskingForAppInsights.ps1
Created June 24, 2024 14:32
POWERSHELL: Turn off client ip masking for all application insights resources
Clear-Host
<###########################################################################
Author: Tim Cartwright
Purpose to turn off client ip masking for all application insights resources if masking is enabled
DisableIPMasking:
- true: disable masking client ips with 0.0.0.0 and show the real client ip
- false: masks all client ips with 0.0.0.0
@tcartwright
tcartwright / EFCommandInterceptor.cs
Last active June 7, 2024 14:16
C#: EFCommandInterceptor - Intercepts EF commands and tags them with the class.method(parameters).linenumber. Even action queries, while .TagWithCallSite() only does Selects
using System.Data.Common;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.Diagnostics;
namespace ~~~~~;
public class EFCommandInterceptor : DbCommandInterceptor
{
public override InterceptionResult<int> NonQueryExecuting(DbCommand command, CommandEventData eventData, InterceptionResult<int> result)
@tcartwright
tcartwright / ObjectExtensions.cs
Created May 14, 2024 15:39
C#: IsDisposed() Checks to see if an object is disposed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
public static class ObjectExtensions
{
@tcartwright
tcartwright / UpdatePackages.bat
Last active May 10, 2024 14:58
DOTNET: Update all packages in a solution
dotnet restore --no-cache --force
OR
nuget restore -nocache -force
LAST RESORT, CLEAR THE LOCAL CACHE:
nuget locals all -clear
@tcartwright
tcartwright / SimpleMaintenance.sql
Created February 15, 2024 21:00
SQL SERVER: Simple maintenance scripts
/*****************************************************************************************************************************************/
/**** SHRINK LOG FILES *******************************************************************************************************************/
/*****************************************************************************************************************************************/
DECLARE @sql VARCHAR(max) = ''
SELECT @sql += CONCAT('USE [', DB_NAME([mf].[database_id]), ']', CHAR(13), CHAR(10), 'DBCC SHRINKFILE (''', [mf].[name], ''', 1) WITH NO_INFOMSGS;', CHAR(13), CHAR(10))
FROM sys.[master_files] AS [mf]
WHERE [mf].[type_desc] = 'LOG'
@tcartwright
tcartwright / GitPopCommit.bat
Created January 16, 2024 22:51
GIT: Pop last commit off
@rem remove last commit and destroy it
git reset --hard HEAD~1
@rem remove last commit and edit it
git reset HEAD~1