Skip to content

Instantly share code, notes, and snippets.

@roundand
roundand / AsyncEvents
Created June 13, 2014 14:29
Demonstration of Async Event processing in PowerShell v2
# Illustration (based on concepts in http://blogs.technet.com/b/heyscriptingguy/archive/2011/06/16/use-asynchronous-event-handling-in-powershell.aspx
# and code nicked from an answer in http://social.technet.microsoft.com/Forums/en-US/96b339e2-e9da-4802-a66d-be619aeb21ac/execute-function-one-time-in-every-10-mins-in-windows-powershell
# )
#####
#
# PASTE LINES BELOW INTO CONSOLE
#
#
@roundand
roundand / XmlCanonicalization.linq
Last active August 29, 2015 13:57
Demonstration of #XML #Canonicalisation in C# using #LinqPad
<Query Kind="Statements">
<Reference>&lt;RuntimeDirectory&gt;\System.Security.dll</Reference>
<Namespace>System.Security.Cryptography.Xml</Namespace>
</Query>
// need to load System.Security via F4
XmlDocument myDoc = new XmlDocument();
myDoc.LoadXml("<root x='x' a='a'><trunk>etc</trunk></root>");
myDoc.OuterXml.Dump("Attributes in original document order");
XmlDsigC14NTransform t = new XmlDsigC14NTransform();
@roundand
roundand / replaceTokens.linq
Last active August 29, 2015 13:57
linqPad demo of c# Regex extension method to replace tokens in a string using a token / value dictionary
<Query Kind="Program" />
// define regex to match $-delimited tokens, eg $name$
static Regex toke = new Regex(@"\$(\w+)\$", RegexOptions.Compiled);
static void Main()
{
string input = @"Dear $name$, as of $date$ your balance is $amount$";
var args = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
args.Add("name", "Mr Smith");