Skip to content

Instantly share code, notes, and snippets.

View mikeplate's full-sized avatar

Mikael Plate mikeplate

View GitHub Profile
@mikeplate
mikeplate / runwithrowlimit.sql
Last active July 28, 2022 07:09
Run t-sql delete statement with adaptable rowcount for easier load on server until finished
declare @rowcount int = 1000
declare @maxseconds int = 10
declare @waitseconds int = 5
declare @sql nvarchar(max) = 'delete from Log where CreatedDate<''2022-06-28'' '
declare @message nvarchar(max)
declare @start datetime
declare @seconds int
set @start = getdate()
set rowcount @rowcount
exec sp_executesql @sql
@mikeplate
mikeplate / snippets.sql
Last active August 4, 2021 13:50
Microsoft SQL Server T-SQL Snippets
-- Run an Update statement for all tables that have a specific column. Set TenantId=69 in all tables that have that column.
declare @sql nvarchar(max)
set @sql = (select concat('update [', t.name, '] set TenantId=69; ') as [text()]
from sys.columns c join sys.tables t on c.object_id = t.object_id
where c.name = 'TenantId' for xml path(''))
print @sql
execute (@sql)
-- Disable all constrant checks temporarily for a specific table
alter table TheTableName nocheck constraint all
@mikeplate
mikeplate / snippets.sh
Last active October 22, 2021 13:43
Linux Bash Snippets
# Start reverse SSH tunnel from internal server to external endpoint on port 443
# Port 8081 on external endpoint will then be connectable to internal server localsql port 1433
ssh -N -R 0.0.0.0:8081:localsql:1433 remoteuser@company-endpoint.westeurope.cloudapp.azure.com -p 443 -i ./remoteuser.pem
# Show certificate for SMTP server with implicit TLS
openssl s_client -connect smtp.some-server.com:465 -servername smtp.some-server.com
# Show certificate for SMTP server with explicit TLS
openssl s_client -connect smtp.some-server.com:587 -servername smtp.some-server.com -starttls smtp
@mikeplate
mikeplate / snippets.ps1
Created July 15, 2021 13:29
PowerShell Snippets
# Run sql command and store result as csv
Invoke-Sqlcmd -ServerInstance localhost -Database dbname -Username usr -Password rty "select top 100 * from [Log]" | ConvertTo-Csv -Delimiter "`t" > output.csv
# Total size of all files in all subfolders of the current folder
Get-ChildItem . -Recurse | Measure-Object -Property Length -Sum
# Store result of http request in file
Invoke-WebRequest -Uri "https://site.com" | Select-Object -ExpandProperty Content > site.html
@mikeplate
mikeplate / windows.cmd
Created August 26, 2019 10:41
Windows command line commands for this and that
:: Refresh task bar icons
ie4uinit.exe -show
@mikeplate
mikeplate / sp-button-link.json
Last active November 23, 2020 14:13
SharePoint Column Formatting Download Link
@mikeplate
mikeplate / cssgrid.html
Created February 7, 2019 19:54
CSS Grid Sample with IE11 support
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>CSS Grid</title>
<style>
body {
margin: 0px;
@mikeplate
mikeplate / PhotoViewerJpeg.reg
Created December 19, 2018 17:40
Registry file for Windows Server 2016/2019 to restore jpeg opening in Photo Viewer
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\jpegfile\shell\open\command]
@=hex(2):25,00,53,00,79,00,73,00,74,00,65,00,6d,00,52,00,6f,00,6f,00,74,00,25,\
00,5c,00,53,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,5c,00,72,00,75,00,\
6e,00,64,00,6c,00,6c,00,33,00,32,00,2e,00,65,00,78,00,65,00,20,00,22,00,25,\
00,50,00,72,00,6f,00,67,00,72,00,61,00,6d,00,46,00,69,00,6c,00,65,00,73,00,\
25,00,5c,00,57,00,69,00,6e,00,64,00,6f,00,77,00,73,00,20,00,50,00,68,00,6f,\
00,74,00,6f,00,20,00,56,00,69,00,65,00,77,00,65,00,72,00,5c,00,50,00,68,00,\
6f,00,74,00,6f,00,56,00,69,00,65,00,77,00,65,00,72,00,2e,00,64,00,6c,00,6c,\
@mikeplate
mikeplate / azureauth.cs
Created December 13, 2018 11:35
Add Azure AD authentication to existing ASP.NET Core application
// Startup.cs
using Microsoft.IdentityModel.Tokens;
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication().AddOpenIdConnect(c =>
{
c.Authority = "https://login.microsoftonline.com/common";
c.ClientId = "<insert-registered-guid>";
c.TokenValidationParameters = new TokenValidationParameters
@mikeplate
mikeplate / web.config
Created August 14, 2018 09:32
ASP.NET and IIS 7+ configuration settings for upload limit
<!-- 50 MB limit -->
<system.web>
<httpRuntime maxRequestLength="51200" />
</system.web>
<system.webServer>
<security>
<requestFiltering>
<requestLimits maxAllowedContentLength="52428800" />
</requestFiltering>
</security>