Skip to content

Instantly share code, notes, and snippets.

@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"
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 / 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;
}
@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 / build.xml
Created May 11, 2011 09:07
Determine number of git revisions with inline MSBuild task
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="GitVersion" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
<ParameterGroup>
<LocalPath ParameterType="System.String" />
<Path ParameterType="System.String" />
<CommitCount ParameterType="System.Int32" Output="true" />
</ParameterGroup>
<Task>
@thoemmi
thoemmi / Create-WorkflowDiagramFromWitd.ps1
Last active February 10, 2020 19:59
This Powershell scripts generates a nice workflow diagram from a TFS work item template definition file. See http://thomasfreudenberg.com/archive/2018/01/16/generating-workflow-diagram-for-witd/ for details
[CmdletBinding()]
param(
[Parameter(Mandatory=$true, HelpMessage="Path to work item template definition file")]
[string]
$witdPath
)
# path to dot.exe; e.g. use "choco install graphviz"
$dotPath = "C:\ProgramData\chocolatey\bin\dot.exe"
@thoemmi
thoemmi / SingleThreadedTaskScheduler.cs
Created February 9, 2012 16:31
SingleThreadedTaskScheduler
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
namespace SingleThreadedTaskSchedulerDemo {
public class SingleThreadedTaskScheduler : TaskScheduler, IDisposable {
private readonly string _backgroundThreadName;
private readonly object _backgroundThreadLock = new object();

Keybase proof

I hereby claim:

  • I am thoemmi on github.
  • I am thoemmi (https://keybase.io/thoemmi) on keybase.
  • I have a public key ASD1LqmfVwJ9qgVmFamgIyLV28FTLDOwzDiIph2oyBtA9go

To claim this, I am signing this object:

@thoemmi
thoemmi / EnumFlagsConverter.cs
Created September 5, 2018 15:31
JSON Converter for enum flags
public class EnumFlagsConverter : JsonConverter
{
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
var x = ((Enum) value).ToString();
var list = new List<string>();
foreach (var v in x.Split(new[] {", "}, StringSplitOptions.RemoveEmptyEntries))
{
list.Add(v);
@thoemmi
thoemmi / PreBuild.targets.xml
Created September 14, 2012 19:58
Embed referenced assemblies, because ILMerge won't work with WPF applications
<?xml version="1.0" encoding="utf-8" ?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
Originally written by Daniel Chambers (http://www.digitallycreated.net)
http://www.digitallycreated.net/Blog/61/combining-multiple-assemblies-into-a-single-exe-for-a-wpf-application
-->
<Target Name="EmbedReferencedAssemblies" AfterTargets="ResolveAssemblyReferences">
<ItemGroup>
<!-- get list of assemblies marked as CopyToLocal -->
<AssembliesToEmbed Include="@(ReferenceCopyLocalPaths)" Condition="'%(Extension)' == '.dll'"/>