Skip to content

Instantly share code, notes, and snippets.

View mikeplate's full-sized avatar

Mikael Plate mikeplate

View GitHub Profile
@mikeplate
mikeplate / Awake.ps1
Created June 4, 2026 07:42
Awake - PowerShell script to keep computer running
Add-Type @"
using System;
using System.Runtime.InteropServices;
public static class Power {
public const uint ES_CONTINUOUS = 0x80000000;
public const uint ES_SYSTEM_REQUIRED = 0x00000001;
[DllImport("kernel32.dll", SetLastError=true)]
public static extern uint SetThreadExecutionState(uint f);
}
"@
@mikeplate
mikeplate / statusline-command.ps1
Last active June 4, 2026 09:20
Claude Code CLI Status Line PowerShell Script
# ~/.claude/settings.json
#
# {
# "statusLine": {
# "type": "command",
# "command": "powershell -NoProfile -File C:/Users/<username>/.claude/statusline-command.ps1"
# },
# }
$jsonText = $null
@mikeplate
mikeplate / ShowTableByteSizes.sql
Created August 28, 2024 07:16
Show the byte size of all tables in current database
SELECT
t.NAME AS TableName,
s.Name AS SchemaName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
(SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
sys.tables t
INNER JOIN
@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;