Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / Start SQL Server Container.ps1
Last active March 6, 2023 23:47
Using Docker, create a SQL Server container, or start one of it already exists.
# Start SQL Server docker instance
function Start-SQLServer {
param (
[Parameter()][string]$Tag = 'latest'
)
$containerName = 'sqlserver'
$sa_password = 'yourStrong(!)Password'
$container = docker inspect $containerName | ConvertFrom-Json
@chadbaldwin
chadbaldwin / auto entities card + restriction card + template card.md
Last active September 1, 2023 00:54
auto entities card + restriction card + template card

.

@chadbaldwin
chadbaldwin / alert - garage door open - no motion.yaml
Last active September 1, 2023 00:54
Home Assistant - Create an Alert that announces on Google Home when the garage door has been left open and there has beeen no motion for at least 5 minutes
tts:
- platform: google_translate
template:
- binary_sensor:
- name: garage_open_no_motion
state: >
{{
(is_state('binary_sensor.contact_7_contact', 'on'))
and
@chadbaldwin
chadbaldwin / Garage Left Open - Loop.yaml
Last active October 11, 2022 07:19
Home Assistant automation to send a notification every X minutes the garage door was left open without motion
alias: Garage Door Open Notification
description: Send out repeating notifications or announcements that the garage door is left open
mode: restart
trigger:
- platform: state
entity_id:
- group.garage_motion
- binary_sensor.contact_7_contact
condition:
- condition: state
@chadbaldwin
chadbaldwin / zz Filename Start with Space - added via git
Last active September 1, 2023 00:55
Testing how gist sorts files and readme's
​If you try to add a space to the name in GitHub, it gets trimmed.
If you try to add a space to the name in Windows, it gets trimmed.
The best option seems to be to add the file via command line with the space in the name, then commit and push.
@chadbaldwin
chadbaldwin / test_ripgrep_glob.ps1
Last active September 1, 2023 00:55
Testing globs in ripgrep
$string = 'Tables'
$result = '','/','*/','**/' | ? {$true} -PV left |
% { '','/','/*','/**' } -PV right |
% {
$glob = "${left}${string}${right}"
$stat = Measure-Command { $list = rg --files -g $glob }
[pscustomobject]@{
Glob = $glob
Count = $list.Count
Stat = $stat.Milliseconds
@chadbaldwin
chadbaldwin / sample_template_sensor.yaml
Created April 28, 2022 20:13
HomeAssistant Round template sensor example
# configuration.yaml
template:
- sensor:
- name: new_entity_id
device_class: power
unit_of_measurement: W # watts
state: "{{ states('sensor.target_entity_id') | default(0, true) | round(2, default=0) }}"
# customize.yaml
sensor.new_entity_id: