Skip to content

Instantly share code, notes, and snippets.

View DanielLoth's full-sized avatar

Daniel Loth DanielLoth

View GitHub Profile
@DanielLoth
DanielLoth / 0 - Tally (numbers) table and Calendar table T-SQL
Last active September 30, 2017 13:10
Calendar and Number tables for Microsoft SQL Server
Refer to other files.
@DanielLoth
DanielLoth / Program.cs
Created January 16, 2017 08:24
AsyncEx.Context question (dotnet core)
using Nito.AsyncEx;
using System;
using System.Threading.Tasks;
namespace AsyncEx.Context.ConsoleApp
{
public class Program
{
public static int Main(string[] args)
{
@DanielLoth
DanielLoth / Experimenting with CHECK constraint impact.txt
Last active September 30, 2017 13:07
The impact of CHECK constraint on query plans
Refer to other files.
@DanielLoth
DanielLoth / DapperBenchmarks.cs
Created October 3, 2017 04:22
Benchmarking Dapper data access - Dynamic vs Expando vs POCO
using BenchmarkDotNet.Attributes;
using Dapper;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Dynamic;
using System.Linq;
namespace Benchmarks.Benchmarks
@DanielLoth
DanielLoth / ServiceNowAttachmentRetrievalTests.cs
Created October 3, 2017 05:14
ServiceNow attachment retrieval
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
namespace UnitTests
{
[TestClass]
@DanielLoth
DanielLoth / LargeStringToMultiLine.cs
Created October 3, 2017 22:00
(For LINQPad) Take a long string in C# and break it into multiple concatenated lines
var bigString = "But I must explain to you how all this mistaken idea of denouncing pleasure and praising pain was born and I will give you a complete account of the system, and expound the actual teachings of the great explorer of the truth, the master-builder of human happiness. No one rejects, dislikes, or avoids pleasure itself, because it is pleasure, but because those who do not know how to pursue pleasure rationally encounter consequences that are extremely painful. Nor again is there anyone who loves or pursues or desires to obtain pain of itself, because it is pain, but because occasionally circumstances occur in which toil and pain can procure him some great pleasure. To take a trivial example, which of us ever undertakes laborious physical exercise, except to obtain some advantage from it? But who has any right to find fault with a man who chooses to enjoy a pleasure that has no annoying consequences, or one who avoids a pain that produces no resultant pleasure? On the other hand, we denounce with
@DanielLoth
DanielLoth / 3.sql
Last active October 7, 2017 03:58
Foreign key dependency tree in T-SQL
;with RowPerForeignKeyColumn as (
select
--fk.name, fk.is_system_named,
fkChild.ChildTableName, fkChild.ChildColumnName, fkChild.ChildColumnOrdinal,
fkParent.ParentTableName, fkParent.ParentColumnName, fkParent.ParentColumnOrdinal,
ConstraintName = fk.name,
fkChild.ChildSchema,
fkParent.ParentSchema --,
--fkParent.*, fkChild.*
from sys.foreign_keys fk
@DanielLoth
DanielLoth / SQL Server - Object dependency queries.sql
Last active October 24, 2017 23:16
SQL Server - Object dependency queries
IF OBJECT_ID('tempdb.dbo.#tempdep', 'U') IS NOT NULL
DROP TABLE #tempdep;
CREATE TABLE #tempdep (objid int NOT NULL, objname sysname NOT NULL, objschema sysname NULL, objdb sysname NOT NULL, objtype smallint NOT NULL)
exec sp_executesql N'
INSERT INTO #tempdep
SELECT
tbl.object_id AS [ID],
@DanielLoth
DanielLoth / All the kings horses and all the kings men.txt
Created October 24, 2017 23:27
All the kings horses and all the kings men.txt
-----BEGIN CERTIFICATE-----
N3q8ryccAARv0zvW0fUAAAAAAAAkAAAAAAAAAJ7EOroM7Zc0a6+nStey+OM7CfYN
jOFPik6bvYw80OCK9XtdvCpjNhqVOcmqH8nm3wSpBid2RCt/kOxnevEbrGAxe4oA
JOFnI+T2J25XphO9QATnd62Sassxl1ci57iiYMpVW3ef3/pFXUpFAqanMl65w6Ie
GKVyZZVr+Rk3esLMNfOKFo73yqUxflnGUfrI/fXRK0WbULgOGWTlIoIZ/4ahEbgP
cNmJNeRq+cXq43O6LXrOZsli2rQymuvO6nBS5uqgE/nFV3aiWMhZIiZUo64rDL2a
l1WYIHKAgI/02hDCOKyBhNIEHq2aRrtxBla/rOtYvmOxttVD1l4ZPYyowcg2AShc
kafOkU4dd5TTucc9dZpHqIRxCwvvhZ3kvmThakEn0LADSDr3B19Hnil2jsYtfkQ3
fq/ldPQJD/DxjGmolifwBlx3Wh5OVDq7u72bMmHOtHjchrc0AFo+0tDeXGH1q9rk
Amqe9bwRjf1fuptEzYqK6lTmEQCiEn+ao/XCqkgaIAvWhG5FFIElWb/tlve9azqN