Skip to content

Instantly share code, notes, and snippets.

View Swimburger's full-sized avatar
🍔
Creating full snack content

Niels Swimberghe Swimburger

🍔
Creating full snack content
View GitHub Profile
@Swimburger
Swimburger / CompressFile.ps1
Created December 31, 2020 00:54
Minimal script to gzip and brotli compress a file
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string]
$FilePath
)
$OutputBrotliFilePath = "$FilePath.br";
$OutputGzipFilePath = "$FilePath.gz";
@Swimburger
Swimburger / FixIntegrity.ps1
Last active December 30, 2020 21:28
Recalculates hashes for service-worker-assets.js in Blazor WASM PWA application
# make sure you're in the wwwroot folder of the published application
$JsFileContent = Get-Content -Path service-worker-assets.js -Raw
# remove JavaScript from contents so it can be interpreted as JSON
$Json = $JsFileContent.Replace("self.assetsManifest = ", "").Replace(";", "") | ConvertFrom-Json
# grab the assets JSON array
$Assets = $Json.assets
foreach ($Asset in $Assets) {
$OldHash = $Asset.hash
$Path = $Asset.url
{
"profiles":
{
"list":
[
{
"guid": "{e970efe0-4276-4895-b377-cfe4df8aa0e4}",
"hidden": false,
"name": "PowerShell Conda",
"icon": "%ALLUSERSPROFILE%\\Miniconda3\\Menu\\Iconleak-Atrous-PSConsole.ico",
@Swimburger
Swimburger / ConvertFrom-SecureString-AsPlainText.ps1
Created November 2, 2020 22:30
A function to convert secure string to plain text as a pre-PowerShell 7 alternative
Function ConvertFrom-SecureString-AsPlainText{
[CmdletBinding()]
param (
[Parameter(
Mandatory = $true,
ValueFromPipeline = $true
)]
[System.Security.SecureString]
$SecureString
)
@Swimburger
Swimburger / App.config
Created August 20, 2020 19:14
Change ServicePointManager.SecurityProtocol through configuration appsettings
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="SecurityProtocol.Remove" value="Ssl3,Tls" />
<add key="SecurityProtocol.Add" value="Tls11,Tls12" />
</appSettings>
</configuration>
@Swimburger
Swimburger / UsDistricts.json
Last active April 16, 2020 18:18
US States, Territories, and Districts JSON scraped from Wikipedia https://en.wikipedia.org/wiki/List_of_states_and_territories_of_the_United_States
[
{
"img": "//upload.wikimedia.org/wikipedia/commons/thumb/d/d4/Flag_of_the_District_of_Columbia.svg/46px-Flag_of_the_District_of_Columbia.svg.png",
"code": "DC",
"name": "District of Columbia"
}
]
@Swimburger
Swimburger / GetOptionSet.ps1
Last active April 18, 2020 00:27
Get all option values and labels for Dynamics CRM Entity OptionSet Attribute
Param(
[Parameter(Mandatory=$true)]
[String]
$ConnectionString,
[Parameter(Mandatory=$true)]
[String]
$EntityLogicalName,
[Parameter(Mandatory=$true)]
[String]
$OptionSetAttributeName
@Swimburger
Swimburger / SampleResponsive.html
Last active October 14, 2019 22:43
Sample Picture HTML
<picture>
<source srcset="/media/bdpjq2s3/umbracologolarge.png?mode=pad&width=420" media="(max-width: 480px)" sizes="420px" />
<source srcset="/media/bdpjq2s3/umbracologolarge.png?mode=pad&width=720" media="(max-width: 768px)" sizes="720px" />
<source srcset="/media/bdpjq2s3/umbracologolarge.png?mode=pad&width=960" sizes="960px" />
<img src="/media/bdpjq2s3/umbracologolarge.png" alt="Umbraco logo" />
</picture>
@Swimburger
Swimburger / SeleniumHeadlessChromeDriver.cs
Last active July 25, 2019 14:52
C# instantiate ChromeDriver in headless mode
var options = new ChromeOptions();
options.AddArgument("headless");
using(var driver = new ChromeDriver(".", options)){
}
$LogFolder = "D:\home\site\wwwroot\App_Data\Logs";
$DaysToKeepLogsAround = 30;
Get-ChildItem -Path $LogFolder -Recurse -File | Where LastWriteTime -lt (Get-Date).AddDays(-$DaysToKeepLogsAround) | Remove-Item -Force