Skip to content

Instantly share code, notes, and snippets.

{"title":"Martin Fowler","link":"https://martinfowler.com/feed.atom","items":[{"title":"My favorite musical discoveries of 2022","description":{"_":"\n<div class = 'img-link'><a href = 'https://martinfowler.com/articles/2022-music.html'><img src = 'https://martinfowler.com/articles/2022-music/card.png' width = ''></img></a></div>\n\n<p>I continue my habit of picking out <a href = 'https://martinfowler.com/articles/2022-music.html'>six favorite musical discoveries</a> for\n last year. 2022 includes big-band techno, Mediterranean fusion,\n afrobeat in England, jazz-folk vocals, and accordion-led jazz trio.</p>\n\n<p><a class = 'more' href = 'https://martinfowler.com/articles/2022-music.html'>more…</a></p>","$":{"type":"html"}},"entryDate":"2023-01-12T08:50:00-05:00","link":"https://martinfowler.com/articles/2022-music.html"},{"title":"Some activities for the Data Mesh Accelerate Workshop","description":{"_":"\n<div class = 'img-link'><a href = 'https://martinfowler.com/articles/data-mesh-accelerate-work
@lafleurh
lafleurh / EditNameBehavior.cs
Created August 23, 2022 18:44
WPF Set Focus on Textbox when Clicking on Button as Behavior
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
namespace myapp.Views
@lafleurh
lafleurh / RunOnAllDBs.sql
Created April 8, 2021 14:04
Run a SQL command or script on all databases.
-- Change this to 1 to also run on system databases.
DECLARE @UseSystem bit = 0
-- Change this line for the script to run.
DECLARE @SQL NVARCHAR(MAX) = 'SELECT DB_NAME() AS DBName, COUNT(*) AS TableCount FROM sys.tables'
DECLARE @DBName NVARCHAR(255)
DECLARE csrData CURSOR FOR
SELECT name
FROM sys.databases
WHERE ((@UseSystem = 1) OR name NOT IN ('master', 'tempdb', 'model', 'msdb'))
@lafleurh
lafleurh / GetAllForeignKeys.sql
Created June 11, 2020 22:55
Gets all foreign keys for a table.
-- Table for which to find foreign keys
DECLARE @TableName NVARCHAR(255) = 'MyTable'
-- Select foreign keys and delete statements to remove references. Also get a select.
-- Generated statements only work for tables with single column foreign keys.
SELECT
'DELETE FROM ' + pt.name + ' WHERE ' + pc.name + ' NOT IN (' +
'SELECT ' + rc.name + ' FROM ' + rt.name + ');' AS del,
'SELECT ' + pc.name + ' FROM ' + pt.name + ' WHERE ' + pc.name + ' NOT IN (' +
'SELECT ' + rc.name + ' FROM ' + rt.name + ');' AS sel,
SELECT CASE WHEN sys.databases.name IS NULL THEN '--TOTAL--' ELSE sys.databases.name END AS DBName,
CAST(SUM(size)*8.0/1024.0 AS INT) AS SizeMB
FROM sys.databases JOIN sys.master_files ON sys.databases.database_id = sys.master_files.database_id
GROUP BY sys.databases.name WITH ROLLUP
ORDER BY SizeMB DESC
@lafleurh
lafleurh / GetAllTableRowCounts.sql
Created May 13, 2020 15:31
SQL Server get all table names and row counts
DECLARE @sql NVARCHAR(MAX)
DECLARE @RowCounts AS TABLE (name NVARCHAR(MAX), RowCnt int)
DECLARE csrData CURSOR FAST_FORWARD FOR
SELECT
'SELECT ''[' + schema_name(schema_id) + '].[' + name + ']'', COUNT(*) AS RowCnt FROM [' + schema_name(schema_id) + '].[' + + name + '] (NOLOCK)'
FROM sys.tables
OPEN csrData
@lafleurh
lafleurh / GetProcessLocks.sql
Created April 28, 2020 21:22
Get processes blocking each other and the queries being run
CREATE TABLE #tempHAL (
SPID NVARCHAR(255),
Status NVARCHAR(255),
Login NVARCHAR(255),
HostName NVARCHAR(255),
BlkBy NVARCHAR(255),
DBName NVARCHAR(255),
Command NVARCHAR(MAX),
CPUTime NVARCHAR(255),
DiskIO NVARCHAR(255),
@lafleurh
lafleurh / GenerateGenericTableMerge.sql
Last active December 20, 2019 21:43
Generate a MS SQL Server merge statement to insert or update all rows in a table
-- This will generate Microsoft TSQL (MS SQL Server) in order to merge table records given a specific single-column key.
SET NOCOUNT ON
DECLARE @UseTempTable bit = 0
DECLARE @ColumnList NVARCHAR(MAX);
DECLARE @SColumnList NVARCHAR(MAX);
DECLARE @SetColumnList NVARCHAR(MAX);
DECLARE @SelectValueList NVARCHAR(MAX);
@lafleurh
lafleurh / SyncFolders.ps1
Last active April 6, 2024 02:45
PowerShell script to do a two-way sync of Windows folders
Param (
[string]$LeftFolder,
[string]$RightFolder
)
function CreateFolderStructure([string]$Path)
{
if (-not [string]::IsNullOrWhiteSpace($Path))
{
if (-not (Test-Path $Path))
@lafleurh
lafleurh / StripHTML.bas
Created March 7, 2018 22:08
VB Script to Convert HTML to Text for Excel
' This function uses HTMLAgilityPack, available from NuGet.
' You must COM Register HTMLAgilityPack and reference it from your Excel macros.
' This is not a proper implementation, but should work in general.
Public Function StripHTML(html As Object, Optional NL As Boolean = False, Optional LI As Boolean = False) As String
Dim HDoc As HtmlAgilityPack.HtmlDocument
Dim ret As String
Dim htmlStr As String