Skip to content

Instantly share code, notes, and snippets.

View paulczy's full-sized avatar

Paul Czywczynski paulczy

View GitHub Profile
@paulczy
paulczy / ETagAttribute.cs
Last active April 26, 2018 15:32
Add ETags to your ASP.NET Core responses.
using System;
using System.IO;
using System.Security.Cryptography;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Newtonsoft.Json;
using Newtonsoft.Json.Bson;
// ReSharper disable once CheckNamespace
@paulczy
paulczy / DistributedCacheServiceClient.cs
Created December 12, 2016 16:53
Caching extension using ServiceStack IServiceClient and IDistributedCache on .NET Core
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Caching.Distributed;
using Serilog;
using ServiceStack;
@paulczy
paulczy / ConvertFromCanonical.txt
Last active January 12, 2017 19:31
Convert Distinguished Name to Canonical Name. A C# port of a PowerShell script by Glenn Sizemore. http://practical-admin.com/blog/convert-dn-to-canoincal-and-back/
static string ConvertFromCanonical(string cn)
{
var canoincal = "host.tempworks.com";
var obj = canoincal.Replace(",", @"\,").Split('/');
var dn = "CN=" + obj[obj.Count() - 1];
for (int i = obj.Count() - 2; i >= 1; i--)
{
dn += ",OU=" + obj[i];
}
foreach (var item in obj[0].Split('.'))
@paulczy
paulczy / GetFirstOU.txt
Last active January 12, 2017 21:07
Get the first OU in distinguished name string.
string GetFirstOU(string dn)
{
var firstOU = dn.Split(',')
.FirstOrDefault(x => x.StartsWith("ou=", StringComparison.OrdinalIgnoreCase));
if (string.IsNullOrEmpty(firstOU)) return null;
var result = Regex.Replace(firstOU, Regex.Escape("ou="), "".Replace("$", "$$"), RegexOptions.IgnoreCase);
return result;
}
@paulczy
paulczy / SSMS17-HiDPI.ps1
Created April 30, 2017 11:23 — forked from NickCraver/SSMS17and17-HiDPI.ps1
PowerShell: SSMS 17 HiDPI Enable
Set-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\SideBySide" -Name PreferExternalManifest -Value 1 -Type DWord;
'<?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"><asmv3:application><asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings"><dpiAware>True</dpiAware></asmv3:windowsSettings></asmv3:application><dependency><dependentAssembly><assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /></dependentAssembly></dependency><dependency><dependentAssembly><assemblyIdentity type="win32" name="debuggerproxy.dll" processorArchitecture="X86" version="1.0.0.0"></assemblyIdentity></dependentAssembly></dependency></assembly>' | Out-File -FilePath "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Ssms.exe.mani
@paulczy
paulczy / Windows Defender Exclusions for Developer.ps1
Created November 19, 2020 15:18 — forked from nerzhulart/Windows Defender Exclusions for Developer.ps1
Adds Windows Defender exclusions for developers (Visual Studio, JetBrains Rider, IntellIJ Idea, Git, MsBuild, dotnet, mono etc.)
$userPath = $env:USERPROFILE
$pathExclusions = New-Object System.Collections.ArrayList
$processExclusions = New-Object System.Collections.ArrayList
$pathExclusions.Add('C:\Windows\Microsoft.NET') > $null
$pathExclusions.Add('C:\Windows\assembly') > $null
$pathExclusions.Add($userPath + '\AppData\Local\Microsoft\VisualStudio') > $null
$pathExclusions.Add('C:\ProgramData\Microsoft\VisualStudio\Packages') > $null
$pathExclusions.Add('C:\Program Files (x86)\MSBuild') > $null
$pathExclusions.Add('C:\Program Files (x86)\Microsoft Visual Studio 14.0') > $null
@paulczy
paulczy / run-applicationinsights-weeklyemails.csx
Created January 5, 2021 17:34 — forked from SidShetye/run-applicationinsights-weeklyemails.csx
To get application insight emails on a weekly basis. rename to run.csx when moving into azure functions
#r "Newtonsoft.Json"
using System.Configuration;
using System.Net.Mail;
using System.Net.Mime;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
private const string AppInsightsApi = "https://api.applicationinsights.io/beta/apps";
// MIT License
//
// Copyright (c) 2018 Kristian Hellang
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@paulczy
paulczy / Instructions.md
Created September 8, 2021 19:25 — forked from NickCraver/Microsoft.PowerShell_profile.ps1
Craver's oh-my-posh profile

Included here are the PowerShell profile I use as well as the oh-my-posh 3 config, but in addition to these you'll need:

  1. The PowerShell modules:
Install-Module -Name posh-git -Repository PSGallery
Install-Module -Name oh-my-posh -Repository PSGallery
[CmdletBinding()]
Param(
# gather permission requests but don't create any AppId nor ServicePrincipal
[switch] $DryRun = $false,
# other possible Azure environments, see: https://docs.microsoft.com/en-us/powershell/module/azuread/connect-azuread?view=azureadps-2.0#parameters
[string] $AzureEnvironment = "AzureCloud",
[ValidateSet(
"UnitedStates",
"Preview(UnitedStates)",