Skip to content

Instantly share code, notes, and snippets.

View tompazourek's full-sized avatar
👨‍💻
Busy

Tom Pažourek tompazourek

👨‍💻
Busy
View GitHub Profile
@tompazourek
tompazourek / DebugHelper.cs
Created June 12, 2019 17:40
Helper to generate Object IDs for debugging (to identify the same object via a number)
using System;
using System.Runtime.CompilerServices;
public static class DebugHelper
{
private static readonly ConditionalWeakTable<object, object> _objectIds = new ConditionalWeakTable<object, object>();
private static int _lastObjectId;
private static readonly object _lock = new object();
public static string GetObjectId(object obj)
@tompazourek
tompazourek / SeqExportAllToJson.cs
Created January 12, 2019 18:35
Program that downloads data from a Seq instance and stores it in a JSON file (CLEF format)
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using Seq.Api;
namespace SeqExportAllToJson
{
internal class Program
{
@tompazourek
tompazourek / Numbers.sql
Last active August 16, 2018 12:49
Numbers from 0 to 9999.
WITH [Numbers] AS
(
SELECT
[Ones].[Number] +
10 * [Tens].[Number] +
100 * [Hundreds].[Number] +
1000 * [Thousands].[Number]
AS [Number]
FROM (VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) [Ones]([Number]),
(VALUES(0),(1),(2),(3),(4),(5),(6),(7),(8),(9)) [Tens]([Number]),
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace Guids
{
public static class SequentialGuid
USE MASTER
ALTER DATABASE [DatabaseOldName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
ALTER DATABASE [DatabaseOldName] MODIFY NAME = [DatabaseNewName]
ALTER DATABASE [DatabaseNewName] SET MULTI_USER
@tompazourek
tompazourek / nodes-with-parents.sql
Created November 1, 2017 09:47
Load items with all of their parent items as well.
WITH [NodesWithParents] AS
(
SELECT * FROM [Nodes] n WHERE n.[Id] IN (...)
UNION ALL
SELECT parent.* FROM [Nodes] parent
INNER JOIN [NodesWithParents] child ON child.[ParentNode_Id] = parent.[Id]
)
SELECT DISTINCT [Id] FROM [NodesWithParents]
@tompazourek
tompazourek / tables_and_rows.sql
Created October 24, 2017 13:12
Database tables and rows
SELECT
CONVERT(NVARCHAR(MAX), t.[table_schema]) AS [Owner],
CONVERT(NVARCHAR(MAX), t.[table_name]) AS [TableName],
MAX(i.[rows]) AS [RecordCount]
FROM
[sysindexes] i,
[information_schema].[tables] t
WHERE
t.[table_name] = OBJECT_NAME(i.[id])
AND t.[table_type] = 'BASE TABLE'
@tompazourek
tompazourek / count_tables.sql
Created October 24, 2017 13:05
Count number of tables in MS SQL database
SELECT COUNT(*) AS [TableCount] FROM [information_schema].[tables] WHERE [table_type] = 'BASE TABLE'
SELECT CONCAT('ABC', REPLICATE('0',6-LEN(CAST(other_id as nvarchar(max)))), CAST(other_id as nvarchar(max)))
FROM [experiments].[dbo].[Table_1]
SELECT CONCAT('ABC', FORMAT(Other_Id, '000000'))
FROM [experiments].[dbo].[Table_1]
@tompazourek
tompazourek / FKsWithoutIX.sql
Last active March 8, 2017 20:55
Find foreign keys that don't have single-column indexes on them.
SELECT
*
FROM
sys.foreign_keys fk
WHERE
EXISTS
(
SELECT
*
FROM