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 / 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
@tompazourek
tompazourek / ListPKsAndFKs.sql
Created June 26, 2016 14:03
List foreign keys and primary keys in the database
SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
SCHEMA_NAME(schema_id) AS SchemaName,
OBJECT_NAME(parent_object_id) AS TableName,
type_desc AS ConstraintType
FROM sys.objects
WHERE type_desc IN ('FOREIGN_KEY_CONSTRAINT','PRIMARY_KEY_CONSTRAINT')
@tompazourek
tompazourek / gulpfile.js
Created June 17, 2016 22:22
Browserify experiment
'use strict';
var gulp = require('gulp')
var path = require('path')
var uglify = require('gulp-uglify')
var vinylPaths = require('vinyl-paths');
var del = require('del')
var browserify = require('browserify');
var sourcemaps = require('gulp-sourcemaps');
@tompazourek
tompazourek / FooBar.js
Last active June 17, 2016 22:21
JS inheritance
var Bar = (function(parent) {
// constructor
var cls = function Bar(/* ... */) {
parent.call(this, /* ... */);
/* ... */
};
// inheritance
inherits(cls, parent);
public static class TaskExtensions
{
/// <summary>
/// Use to run async tasks in sync context. Configures await (by default set to false to not continue) and unwraps exception and result.
/// </summary>
public static TResult UnwrapResult<TResult>(this Task<TResult> task, bool continueOnCapturedContext = false)
{
try
{
task.ConfigureAwait(continueOnCapturedContext);
@tompazourek
tompazourek / gist:347436920bfaa5fb2bb2
Created October 16, 2015 08:32 — forked from lontivero/gist:593fc51f1208555112e0
Generates Markdown from VS XML documentation file
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;
using System.Xml.Linq;
namespace GithubWikiDoc
{
-- When renaming tables or moving schemas in Entity Framework, EF doesn't rename all related things (like FKs and PKs)
-- This might help to locate those database objects:
-- selects FKs and PKs with schema 'Core.' in their name
SELECT s.name, o.name FROM sys.objects AS o
INNER JOIN sys.schemas AS s ON s.schema_id = o.schema_id
WHERE o.name LIKE '%Slug%' OR o.name LIKE '%PageMetadata%'
-- performs renaming
sp_rename '[Inventory].[FK_Inventory.BaseProduct_Core.PageMetadata_PageMetadata_Id]', 'FK_Inventory.BaseProduct_Navigation.PageMetadata_PageMetadata_Id'
set statistics time on
-- execute queries
set statistics time off
-- http://stackoverflow.com/a/11675263/108374