Skip to content

Instantly share code, notes, and snippets.

@FilipDeVos
FilipDeVos / result.txt
Created March 16, 2021 18:31
Compare Select 1 vs Select * in SQL Server
Table 'test'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
if exists(select 1 from test)
|--Compute Scalar(DEFINE:([Expr1004]=CASE WHEN [Expr1005] THEN (1) ELSE (0) END))
|--Nested Loops(Left Semi Join, DEFINE:([Expr1005] = [PROBE VALUE]))
|--Constant Scan
|--Clustered Index Scan(OBJECT:([master].[dbo].[test].[ck_test1]))
Table 'test'. Scan count 1, logical reads 2, physical reads 0, read-ahead reads 0, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.
@FilipDeVos
FilipDeVos / 0README.md
Last active August 29, 2015 14:13
Archi Chocolatey package source files.

Archi

This gist contains the code required to build a chocolatey package for Archi (see http://archimatetool.com)

To create the package make sure you have chocolatey installed, save the 2 files Archi.nuspec and ChocolateyInstall.ps1 (make sure they are UTF-8 files without BOM) and call cpack

if object_id(N'p_create_backup') is null
exec('create procedure p_create_backup as return (-1)')
GO
alter procedure p_create_backup (@BackupPath nvarchar(266), @Database sysname)
as
declare @fileName nvarchar(266) = @Database + N'.bak'
, @safeDatabase nvarchar(258) = quotename(@Database)
, @fileFullPath nvarchar(266) = @BackupPath + @fileName
@FilipDeVos
FilipDeVos / Aggregate_Concatenate.sql
Last active October 15, 2023 03:36
SQL Server Aggregate to concatenate strings
-- This script deploys the dbo.Concatenate() aggregate function on SQL Server. This is compiled from the code Concatenate.cs below.
CREATE ASSEMBLY [concat]
FROM 0x4D5A90000300000004000000FFFF0000B800000000000000400000000000000000000000000000000000000000000000000000000000000000000000800000000E1FBA0E00B409CD21B8014CCD21546869732070726F6772616D2063616E6E6F742062652072756E20696E20444F53206D6F64652E0D0D0A2400000000000000504500004C010300E3EE2A540000000000000000E00002210B010B00000C00000006000000000000AE2B0000002000000040000000000010002000000002000004000000000000000400000000000000008000000002000000000000030040850000100000100000000010000010000000000000100000000000000000000000602B00004B000000004000009003000000000000000000000000000000000000006000000C000000282A00001C0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000080000000000000000000000082000004800000000000000000000002E74657874000000B40B000000200000000C000000020000000000000000000000000000200000602E7273726300000090030000004
using System;
namespace MoneyTest
{
public static class Program
{
static void Main(string[] args)
{
var twentyEuro = new Money(20.0, Currency.EUR);
@FilipDeVos
FilipDeVos / program.cs
Created March 3, 2014 21:19
this breaks Resharper
// install-package fakeiteasy
// install-package shortbus.markers -pre
// install-package shortbus -pre
using FakeItEasy;
using ShortBus;
public class MyItem
{
public string Name { get; set; }
}
@FilipDeVos
FilipDeVos / XDocumentExtensions.cs
Last active December 21, 2015 06:58
Extension method to output xml declaration with tostring
using System.IO;
using System.Text;
using System.Xml.Linq;
/// <summary>
/// Extension methods on the XDocument class.
/// </summary>
internal static class XDocumentExtensions
{
/// <summary>
@FilipDeVos
FilipDeVos / DebugAssertDialogDisabler.cs
Last active December 21, 2015 04:28
Wrapper class to disable debug assert ui from popping up in unit tests. (I know it should not be needed, but you know how it goes.)
using System;
using System.Diagnostics;
using System.Linq;
public class DebugAssertDialogDisabler : IDisposable
{
private readonly DefaultTraceListener _alteredListener;
public DebugAssertDialogDisabler()
{
@FilipDeVos
FilipDeVos / find_who_deleted_sql_server_db.sql
Created July 3, 2013 08:09
Detect who deleted a database based on the SQL Server default trace
With cteObjectTypes AS
(
SELECT TSV.trace_event_id, TSV.subclass_name, TSV.subclass_value
FROM sys.trace_subclass_values AS TSV
JOIN sys.trace_columns AS TC
ON TSV.trace_column_id = TC.trace_column_id
WHERE TC.[name] = 'ObjectType'
),
cteEventSubClasses AS
(
Public Sub Authenticate(username As String, password As String, connString As String)
Using oConn As New SqlConnection(connString)
'Check that connection exists and is open
oConn.Open()
If oConn.State = ConnectionState.Open Then
Using sqlCmd As New SqlCommand("EXEC dbo.sGetHashedPW @UserName = @userName", oConn)
sqlCmd.Parameters.Add("userName", SqlDbType.VarChar).Value = username
_pwhash = sqlCmd.ExecuteScalar
_authenticated = EncryptHash.VerifyHash(password, "SHA512", _pwhash)
If _authenticated Then