Skip to content

Instantly share code, notes, and snippets.

View skurik's full-sized avatar

Standa Kuřík skurik

  • Prague, Czech Republic
View GitHub Profile
<Query Kind="Program">
<Namespace>System.Net.Http</Namespace>
<Namespace>Newtonsoft.Json</Namespace>
<Namespace>System.Threading.Tasks</Namespace>
</Query>
void Main()
{
}
@skurik
skurik / queries-with-multiple-plans.sql
Last active May 19, 2022 05:32
SQL Server plan cache bloat
with RedundantQueries as
(select top 20
query_hash as QueryHash,
count(query_hash) as PlansCached,
count(distinct(query_hash)) as DistinctPlansCached,
sum(execution_count) as TotalExecutions,
min(creation_time) as FirstPlanCreationTime,
max(creation_time) as LastPlanCreationTime,
max(s.last_execution_time) as LastExecutionTime,
statement_start_offset as StatementStartOffset,
@skurik
skurik / AlertStackPoC.cs
Last active August 12, 2021 11:16
Declarative IaC with Pulumi
public class AlertStack : Stack
{
public AlertStack()
{
var resourceGroup = ResourceGroup.Get(resourceGroupName, resourceGroupId);
var redis = Pulumi.AzureNative.Cache.Redis.Get(redisName, redisId);
var actionGroup = ActionGroup.Get(actionGroupName, actionGroupId);
var redisAlert = CreateRedisMemoryUsageAlert(resourceGroup, redis, actionGroup);
public sealed class AzureRedisAlerts
{
public readonly MewsResource<MetricAlert<RedisCache>> MemoryHigh = MewsResource<MetricAlert<RedisCache>>.CreateManaged(
name: "redis-memory-high",
resource: new MetricAlert<RedisCache>(
resourceGroup: ResourceDependency<ResourceGroup>.Create<AzureResourceGroups>(g => g.Monitoring),
actionGroup: ResourceDependency<ActionGroup>.Create<AzureActionGroups>(g => g.Default),
targetResource: ResourceDependency<RedisCache>.Create<AzureRedisCaches>(c => c.WestEurope),
description: "Redis memory high"
)
public class AzureAlertStack : Stack
{
public AzureAlertStack()
{
var resourceGroup = ResourceGroup.Get(resourceGroupName, resourceGroupId);
var redis = Pulumi.AzureNative.Cache.Redis.Get(redisName, redisId);
var actionGroup = ActionGroup.Get(actionGroupName, actionGroupId);
var redisAlert = CreateRedisMemoryUsageAlert(resourceGroup, redis, actionGroup);
@skurik
skurik / HopcroftKarpMaxBipartiteMatcher.cs
Last active August 29, 2015 14:15
Maximum-cardinality bipartite matching in an unweighted graph, implementing the Hopcroft-Karp algorithm
public static class HopcroftKarpMaxBipartiteMatcher
{
public static List<Tuple<int, int>> MaximumMatching(IEnumerable<int> partition1, IEnumerable<int> partition2, List<Tuple<int, int>> edges)
{
var unmatchedVertices1 = new HashSet<int>(partition1);
var unmatchedVertices2 = new HashSet<int>(partition2);
var matching = GreedyMatch(partition1, edges, unmatchedVertices1, unmatchedVertices2);
var augmentingPaths = GetAugmentingPaths(matching, edges, unmatchedVertices1, unmatchedVertices2);
while (augmentingPaths.Any())