Skip to content

Instantly share code, notes, and snippets.

@thoemmi
thoemmi / Add-XmlFragment.ps1
Created June 15, 2012 15:50
PowerShell function to add an XML fragment to an XmlNode
<#
.SYNOPSIS
Adds an XML fragment to an XmlNode
.DESCRIPTION
Adds an XML fragment to an XmlNode
.NOTES
Author : Thomas Freudenberg - info@thomasfreudenberg.com
@thoemmi
thoemmi / AnsiConsoleExtensions.cs
Created June 13, 2022 20:44
Extension method for Spectre.Console to write JSON with syntax highlighting
public static class AnsiConsoleExtensions
{
public static IAnsiConsole WriteJson(this IAnsiConsole console, JsonElement node, JsonStyle? jsonStyle = null)
{
ArgumentNullException.ThrowIfNull(console);
ArgumentNullException.ThrowIfNull(node);
console.WriteJson(node, jsonStyle ?? JsonStyle.Default, 0);
return console;
}
public class EncryptingJsonConverter : JsonConverter {
private readonly byte[] _encryptionKeyBytes;
public EncryptingJsonConverter(string encryptionKey) {
if (encryptionKey == null) {
throw new ArgumentNullException(nameof(encryptionKey));
}
// Hash the key to ensure it is exactly 256 bits long, as required by AES-256
using (var sha = new SHA256Managed()) {
@thoemmi
thoemmi / Clear-NuGetCache.ps1
Created April 21, 2017 21:11
Script to delete old NuGet packages from %USERPROFILE%\.nuget\packages which haven't been accessed for 150 days
[CmdletBinding(SupportsShouldProcess=$True)]
Param(
[int]$CutoffDays = 150
)
$cutoffDate = (Get-Date).AddDays(-$CutoffDays)
# get path to cached NuGet packages ("%USERPROFILE$\.nuget\packages")
$nugetCachePath = Join-Path "$([System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::UserProfile))" ".nuget\packages"