Skip to content

Instantly share code, notes, and snippets.

View NaserKhoshfetrat's full-sized avatar

Naser Khoshfetrat NaserKhoshfetrat

View GitHub Profile
@NaserKhoshfetrat
NaserKhoshfetrat / scan-revs
Created September 13, 2021 09:00 — forked from timabell/scan-revs
scan git revision list for bug #s in the comments
#!/bin/bash
#scan revision list for bug #s in the comments
#convert into comma separated values
bugs=`git log $1..$2 --pretty=oneline | grep -o " bug *[0-9]*" | \
cut -d " " -f 3 | sort -n | uniq | while read x; do echo -n $x,; done;`
#strip final comma
bugs=${bugs%,}
@NaserKhoshfetrat
NaserKhoshfetrat / PageDataExtensions.cs
Created September 13, 2021 09:00 — forked from timabell/PageDataExtensions.cs
PageDataExtensions for making it easier to work with EpiServer 6.1 pages
using System;
using EPiServer;
using EPiServer.Core;
using EPiServer.DataAccess;
using EPiServer.Security;
using EPiServer.Web.Hosting;
namespace EpiServerShine
{
static internal class PageDataExtensions
@NaserKhoshfetrat
NaserKhoshfetrat / NodeEntryCollection.cs
Created September 13, 2021 09:00 — forked from timabell/NodeEntryCollection.cs
hierarchy reader from stack overflow
using System.Collections.Generic;
namespace util
{
/// <summary>
/// Storage and parsing of flat string based folder hierarchy.
/// See http://stackoverflow.com/a/8621711/10245
/// </summary>
/// <example><code>
/// NodeEntryCollection cItems = new NodeEntryCollection();
@NaserKhoshfetrat
NaserKhoshfetrat / missing-keys.sql
Created September 13, 2021 09:00 — forked from timabell/missing-keys.sql
sql server - find tables / fields with missing keys
-- http://richarddingwall.name/2008/12/21/find-missing-foreignprimary-keys-in-sql-server/
-- Find columns on tables with names like FooID or FooCode which should
-- be part of primary or foreign keys, but aren't.
SELECT
t.name AS [Table],
c.name AS [Column],
i.*
FROM
sys.tables t
@NaserKhoshfetrat
NaserKhoshfetrat / SqlExceptionMocker.cs
Created September 13, 2021 09:00 — forked from timabell/SqlExceptionMocker.cs
Workaround completely test-unfriendly sql error classes
using System.Data.SqlClient;
using System.Reflection;
namespace HorribleThingsInHere
{
/// <summary>
/// Workaround completely test-unfriendly sql error classes.
/// Copy-paste from http://stackoverflow.com/a/1387030/10245
/// Adjusted with updates in comments
/// </summary>
@NaserKhoshfetrat
NaserKhoshfetrat / db-backup-utils.sql
Created September 13, 2021 09:00 — forked from timabell/db-backup-utils.sql
Sql for simplifying and automating the process of loading/backing up multiple databases
USE master;
SET NOCOUNT ON
GO
-- Sql for simplifying and automating the process of loading/backing up multiple databases.
-- Optionally override the restored db name.
-- Also has proc for doing an upgrade of a backup file via an intermediate sql server version.
-- The UI for backup/restore in ssms takes many clicks and doesn't remember anything, this
-- script will allow you to codify repetive actions.
@NaserKhoshfetrat
NaserKhoshfetrat / db-backup-utils.sql
Created September 13, 2021 09:00 — forked from timabell/db-backup-utils.sql
Sql for simplifying and automating the process of loading/backing up multiple databases
USE master;
SET NOCOUNT ON
GO
-- Sql for simplifying and automating the process of loading/backing up multiple databases.
-- Optionally override the restored db name.
-- Also has proc for doing an upgrade of a backup file via an intermediate sql server version.
-- The UI for backup/restore in ssms takes many clicks and doesn't remember anything, this
-- script will allow you to codify repetive actions.
@NaserKhoshfetrat
NaserKhoshfetrat / identity-baseline.sql
Created September 13, 2021 09:00 — forked from timabell/identity-baseline.sql
Script to set the minimum id for all tables in a sql server database
/*
Script to set the minimum id for all tables.
Note that new tables get @baseId as the next id, tables that have had data in get @baseId+1. Ref http://stackoverflow.com/a/13303429/10245
*/
set xact_abort on -- automatically rollback on error
set nocount on -- make it easier to spot errors by reducing output verbosity
BEGIN TRAN
@NaserKhoshfetrat
NaserKhoshfetrat / schema-doc-properties.sql
Created September 13, 2021 09:00 — forked from timabell/schema-doc-properties.sql
templates for addings sql server schema documentation
-- templates:
-- table description:
exec sys.sp_addextendedproperty @name=N'MS_Description', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE',
@level1name=N'TableNameHere', @value=N'Table description here'
-- column description:
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level2type=N'COLUMN',
@level1name=N'TableNameHere', @level2name=N'ColumnNameHere', @value=N'Column description here'
@NaserKhoshfetrat
NaserKhoshfetrat / FK-validation.sql
Created September 13, 2021 09:00 — forked from timabell/FK-validation.sql
misnamed sql server foreign key query
-- https://gist.github.com/timabell/d017038af96196b84e56
SELECT
obj.name,
fk.name
FROM sys.foreign_keys fk
inner join sys.objects obj on obj.object_id = fk.parent_object_id
-- use this where clause to find FKs that aren't named after their table:
where fk.name not like 'FK_' + obj.name + '_%'