Skip to content

Instantly share code, notes, and snippets.

@chadbaldwin
chadbaldwin / auto_equations.tex
Last active September 1, 2023 00:57
Latex code used for generating formulas in Auto Finance Equations blog post
% Standard loan forumula
P=\begin{cases}
\frac{r(PV)}{1-(1+r)^{-n}} &\text{if }r\neq0\\\\
\;\;\;\;\;\frac{PV}{n} &\text{if }r=0
\end{cases}
% Finance Cost - Using Payment and Loan Amount
FC=\frac{P}{PV}
% Finance Cost - Using Rate and Term
service: media_player.play_media
target:
device_id: b9e3064654ed6eb45dd434c508d656a3
data:
media_content_type: "audio/mp3"
media_content_id: "media-source://media_source/local/filename.mp3"
@chadbaldwin
chadbaldwin / Set-ForegroundWindow.ps1
Last active September 1, 2023 00:57
Function to set the foreground window in Windows using the user32.dll API
function Set-ForegroundWindow {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline)][string]$ProcessName
)
$type = '
using System;
using System.Runtime.InteropServices;
public class WinAp {
# Dark Theme
$file = gi "${env:ProgramFiles(x86)}\Microsoft SQL Server Management Studio 18\Common7\IDE\ssms.pkgundef"; ($file | gc) -Replace '(.*{1ded0138-47ce-435e-84ef-9ec1f439b749})', '//$1' | Out-File $file;
# Query execution settings
$ssmsUserSettingsFile = "$($env:APPDATA)\Microsoft\SQL Server Management Studio\18.0\UserSettings.xml";
$newXml = "<Element><Key><int>-1</int></Key><Value><string /></Value></Element>
<Element><Key><int>3</int></Key><Value><string /></Value></Element>
<Element><Key><int>4</int></Key><Value><string /></Value></Element>
<Element><Key><int>5</int></Key><Value><string>USE </string></Value></Element>
<Element><Key><int>6</int></Key><Value><string>SELECT FORMAT(COUNT(*),'N0') FROM </string></Value></Element>
<Element><Key><int>7</int></Key><Value><string>SELECT TOP(100) * FROM </string></Value></Element>
@chadbaldwin
chadbaldwin / string_agg_bug.sql
Created November 13, 2023 22:17
SQL Server STRING_AGG bug
SELECT TOP(100) t.[name], c.TestA, c.TestB
FROM sys.tables t
CROSS APPLY (
SELECT TestA = STRING_AGG(c.[name], '_')
, TestB = STRING_AGG(c.[name], ',')
FROM sys.columns c
WHERE c.[object_id] = t.[object_id]
) c
WHERE t.is_ms_shipped = 1
ORDER BY t.[object_id]
@chadbaldwin
chadbaldwin / .gitignore
Last active January 31, 2024 21:09
My personal PowerShell profile file
*
!Microsoft.*_profile.ps1
!.gitignore
@chadbaldwin
chadbaldwin / gist:a6f17da40d6696a4febb9c3de3fb521f
Last active February 5, 2024 21:46
SQL Server Suggestions
Add some sort of "reset_time" or similar to Index stats DMVs
https://feedback.azure.com/d365community/idea/e9e84bf2-64c4-ee11-92bc-000d3a0fb290
Output warning message when altering an indexed view that all indexes (clustered and non-clustered will be dropped)
https://feedback.azure.com/d365community/idea/0f1f2993-43b6-ee11-92bc-000d3a033659
Statement execution duration global variable - Similar to @@ROWCOUNT, but instead how long the previous statement took to run
https://feedback.azure.com/d365community/idea/884c86b1-9b85-ee11-a81c-000d3ae5ae95
# Run this script from within the git repo you want to copy data OUT of
$copyTo = 'C:\MyTestFolder'
$ErrorActionPreference = 'Stop'
$currBranch = git branch --show-current
$repoRoot = git rev-parse --show-toplevel
if ($LASTEXITCODE -gt 0) { return }
@chadbaldwin
chadbaldwin / Windows Setup File.ps1
Last active April 24, 2024 07:58
Used for setting up a new clean install of Windows
# --------------------------------------------------
# -- Windows/System settings
# --------------------------------------------------
# Settings:
# System:
# Notifications & actions:
# Show me the Windows welcome experience...: Uncheck
# Suggest ways I can finish setting up my device...: Uncheck
# Get tips, tricks, and suggestions...: Uncheck
# Multitasking: