Skip to content

Instantly share code, notes, and snippets.

View ghotz's full-sized avatar

Gianluca Hotz ghotz

View GitHub Profile
@ghotz
ghotz / cscv-face-detect-binary.ps1
Last active August 15, 2018 17:39
Face dection of local image with Azure Cognitive Services Computer Vision API in PowerShell
$ComputerVisionAPILocation = "westeurope";
$ComputerVisionAPIURL = "https://$ComputerVisionAPILocation.api.cognitive.microsoft.com/face/v1.0";
$ComputerVisionAPIKey = "YOUR_KEY_GOES_HERE";
$ComputerVisionAPIAnalyzeTemplateURL = ($ComputerVisionAPIURL + "/detect?returnFaceId={0}&returnFaceLandmarks={1}&returnFaceAttributes={2}")
$returnFaceId = "true";
$returnFaceLandmarks = "true";
$returnFaceAttributes = "age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise";
$ImageFilename = "C:\Temp\cognitive\20180804-104929-GH01C12-S00.jpg";
@ghotz
ghotz / cscv-face-detect-by-url.ps1
Created August 15, 2018 17:38
Face detection by URL with Azure Cognitive Services Computer Vision API in PowerShell
$ComputerVisionAPILocation = "westeurope";
$ComputerVisionAPIURL = "https://$ComputerVisionAPILocation.api.cognitive.microsoft.com/face/v1.0";
$ComputerVisionAPIKey = "YOUR_KEY_GOES_HERE";
$ComputerVisionAPIAnalyzeTemplateURL = ($ComputerVisionAPIURL + "/detect?returnFaceId={0}&returnFaceLandmarks={1}&returnFaceAttributes={2}")
$returnFaceId = "true";
$returnFaceLandmarks = "true";
$returnFaceAttributes = "age,gender,headPose,smile,facialHair,glasses,emotion,hair,makeup,occlusion,accessories,blur,exposure,noise";
$Param = @{"url"="https://cloud.google.com/vision/images/rushmore.jpg"}
@ghotz
ghotz / temp-table-stats.sql
Created October 22, 2018 10:17
Get info about temp table statistics
SELECT S1.name AS stats_name, C1.name AS column_name
FROM tempdb.sys.stats AS S1
JOIN tempdb.sys.stats_columns AS S2
ON S1.object_id = S2.object_id
AND S1.stats_id = S2.stats_id
JOIN tempdb.sys.all_columns AS C1
ON S2.object_id = C1.object_id
AND S2.column_id = C1.column_id
WHERE S1.[object_id] = OBJECT_ID('tempdb..#ftplog_t_dati_1')
ORDER BY
@ghotz
ghotz / single-plan-usage.sql
Created January 26, 2019 10:31
Analyze single plan usage
SELECT
objtype
, COUNT_BIG(*) AS plans_count
, SUM(CAST(size_in_bytes AS bigint) / 1024. / 1024.) AS plans_MB
, AVG(usecounts) AS plans_count_avg
, SUM(CASE WHEN usecounts = 1 THEN 1 ELSE 0 END) AS plans_single_use_count
, SUM(CASE WHEN usecounts = 1 THEN CAST(size_in_bytes AS bigint) / 1024. / 1024. ELSE 0 END) AS plans_single_use_MB
FROM sys.dm_exec_cached_plans
GROUP BY objtype
ORDER BY plans_single_use_MB DESC
@ghotz
ghotz / find-forced-plan-not-being-forced-no-explanation.sql
Created April 10, 2019 08:55
Finds in Query Store forced plan not being forced and without an explanation
SELECT I.start_time, I.end_time, P.query_id, p.plan_id
, (SELECT P2.plan_id
FROM sys.query_store_plan AS P2
WHERE P.query_id = P2.query_id
AND P.plan_id <> P2.plan_id
AND P.last_force_failure_reason = 0
) AS plan_id_different
FROM sys.query_store_runtime_stats_interval AS I
JOIN sys.query_store_runtime_stats AS S
ON I.runtime_stats_interval_id = S.runtime_stats_interval_id
@ghotz
ghotz / generate-query-store-activate.sql
Last active April 11, 2019 14:45
Generate Query Store activation commands for multiple databases
WITH DBsize AS
(
SELECT D1.[name] AS DatabaseName, SUM(CAST(F1.size as bigint)) * 8192 / 1024 / 1024 AS DatabaseSizeMB
FROM sys.databases AS D1
JOIN sys.master_files AS F1
ON D1.database_id = F1.database_id
WHERE D1.database_id > 4 AND F1.type_desc = 'ROWS'
GROUP BY D1.[name]
)
, SizeRules AS
@ghotz
ghotz / get-users-default-schema-alldbs.sql
Last active April 17, 2019 17:14
Get all users with a non standard default schema for all databases
EXEC sp_MSforeachdb '
USE [?];
SELECT DB_NAME() AS database_name, name AS principal_name, default_schema_name
FROM sys.database_principals
WHERE default_schema_name NOT IN (''dbo'', ''guest'');
';
@ghotz
ghotz / clear-broker-queue.sql
Last active July 25, 2019 20:27 — forked from jdaigle/gist:2781349
SQL Server Service Broker: Short Script to clear empty a named queue
DECLARE @handle UNIQUEIDENTIFIER;
WHILE (SELECT COUNT(*) FROM NameOfQueue) > 0
BEGIN
RECEIVE TOP (1) @handle = conversation_handle FROM NameOfQueue;
END CONVERSATION @handle WITH CLEANUP
END
@ghotz
ghotz / compress-pal.ps1
Created August 6, 2019 11:55
Compress Perfmon BLG files
dir C:\PerfLogs\Admin\PAL | % { Compress-Archive -Path $_.FullName -CompressionLevel Optimal -DestinationPath (Join-Path $_.DirectoryName $_.BaseName) }
@ghotz
ghotz / sys-health-memory-broker.sql
Created August 14, 2019 15:04
Various memory troubleshooting queries on System Health session files
-- get memory broker events from system health file session
IF OBJECT_ID('tempdb..#events') IS NOT NULL
DROP TABLE #events;
WITH XmlDataSet AS
(
SELECT CAST(xe.event_data AS xml) AS XMLDATA
FROM sys.fn_xe_file_target_read_file('system_health_*.xel',NULL,NULL,NULL) as xe
WHERE xe.[object_name] = 'memory_broker_ring_buffer_recorded'
)