Skip to content

Instantly share code, notes, and snippets.

View jknopp's full-sized avatar
🏠
Working from home

Jon Knopp jknopp

🏠
Working from home
View GitHub Profile
@jknopp
jknopp / hierarchicalConverter
Created April 27, 2024 00:27 — forked from thesid/hierarchicalConverter
Convert Flat string list to hierarchical object using C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
public static class Program
{
@jknopp
jknopp / create-contained-user.sql
Created September 22, 2023 17:14
Create SQL Contained User
DECLARE @UName varchar(50)
DECLARE @PW varchar(50)
DECLARE @SQL varchar(400)
SET @UName='connection-string-user'
SET @PW='password'
SET @SQL='DROP USER IF EXISTS ['+@UName+'];'+
' CREATE USER ['+@UName+'] WITH PASSWORD = '''+@PW+''', DEFAULT_SCHEMA = dbo;'+
' GRANT VIEW DEFINITION TO ['+@UName+'];'+
' EXEC sp_addrolemember ''db_owner'', '''+@UName+''';'+
' ALTER ROLE db_owner ADD MEMBER ['+@UName+'];'
@jknopp
jknopp / navitembase-inherit.sql
Created August 28, 2023 16:26
SQL Query that produces a list of items that directly or indirectly inherit from NavigableItemBase
WITH ClassHierarchy AS
(
--initialization
SELECT [ClassName], [ClassDisplayName], ClassID, ClassInheritsFromClassID
FROM CMS_Class
WHERE [ClassName] = 'ContentBase.NavigableItemBase'
UNION ALL
--recursive execution
SELECT e.ClassName, e.[ClassDisplayName], e.ClassID, e.ClassInheritsFromClassID
FROM CMS_Class e INNER JOIN ClassHierarchy m
@jknopp
jknopp / rewrite.config
Created August 25, 2023 17:20
Kentico Rewrite Rule Example
<rewrite>
<rules>
<rule name="RedirectWwwToNonWww" stopProcessing="false">
<match url="(.*)" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{HTTP_HOST}" pattern="^(www\.)(.*)$" />
</conditions>
<action type="Redirect" url="https://{C:2}{REQUEST_URI}" redirectType="Permanent" />
</rule>
<rule name="Remove trailing slash" stopProcessing="true">
@jknopp
jknopp / .gitconfig
Created August 10, 2023 17:00 — forked from natescode/.gitconfig
Git Aliases to make GIT easier to work with
[user]
email = your_email
name = your_username
[alias]
# view your global git config Aliases from CLI
aliases = config --get-regexp '^alias\\.'
# git clone
cl = !git clone
# Git shallow clone for large repos
clq= !git clone --depth=1
@jknopp
jknopp / blocking-query.sql
Created August 7, 2023 19:27
Identify impactful blocking queries - Azure
WITH cteHead (session_id,request_id,wait_type,wait_resource,last_wait_type,
is_user_process,request_cpu_time,request_logical_reads,request_reads,
request_writes,wait_time,blocking_session_id,memory_usage,
session_cpu_time,session_reads, session_writes,session_logical_reads,
percent_complete,est_completion_time,request_start_time,request_status,
command,plan_handle,sql_handle, statement_start_offset,statement_end_offset,
most_recent_sql_handle,session_status,group_id, query_hash,query_plan_hash)
AS
(SELECT sess.session_id, req.request_id,
LEFT (ISNULL (req.wait_type, ''), 50) AS 'wait_type',
@jknopp
jknopp / kentico-db-cleanse.sql
Created June 2, 2023 20:24
Kentico DB Cleanse
-- Note: replace UserPrivilegeLevel = 3 with UserIsGlobalAdministrator = 1 for K9 and lower.
-- Sanitize Settings
UPDATE CMS_SettingsKey SET KeyValue = NULL WHERE KeyName in (
'CMSAdminEmailAddress', -- Clear the Administrator email
'CMSUsePasswordPolicy', -- Clear the password policy
'CMSUseSSLForAdministrationInterface', -- Clear 'SSL for administration interface'
'CMSScreenLockEnabled', -- Clear screen lock feature
'CMSSMTPServer', -- Clear sending e-mails
'CMSDisableDebug' -- Clear 'Disable debugging'
@jknopp
jknopp / Delete-Loop.sql
Created March 15, 2022 23:05
SQL - Process items in a loop
SET NOCOUNT ON;
-- Declare local variables
DECLARE @NumberOfLoops AS int = (select count(*)/50000 from [Staging_Task]);
DECLARE @CurrentLoop AS int = 0
WHILE @CurrentLoop < @NumberOfLoops
BEGIN
# Push to multiple remotes
# To do this, choose a remote ID which will refer to all the remotes.
# I usually call it all, but there are developers who prefer origin.
# The idea is to add all the remote repo URLs as “push URLs” to this remote.
# Here’s what you do:
# Create a new remote called "all" with the URL of the primary repo.
git remote add all git@github.com:jknopp/toggl2redmine.git
# Re-register the remote as a push URL.
git remote set-url --add --push all git@github.com:jknopp/toggl2redmine.git
# Add a push URL to a remote. This means that "git push" will also push to this git URL.
@jknopp
jknopp / QueryStore.sql
Last active May 26, 2021 21:00
SQL Query Store provides insight on query plan choice and performance.
--query store status
SELECT actual_state_desc, desired_state_desc, current_storage_size_mb,
max_storage_size_mb, readonly_reason
FROM sys.database_query_store_options;
--top 10 bad runners. This gives you the query ID to search for the query in SSMS->Query Store->Tracked Queries. Type in the ID, get details on the query.
SELECT TOP 10
qt.query_text_id,
q.query_id,
p.plan_id,