Skip to content

Instantly share code, notes, and snippets.

using System;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
namespace Util
{
public static class XmlUtil
{
namespace Util
{
public static class ExceptionExtensions
{
public static T Unwrap<T>(this Exception exception) where T : class
{
return exception.InnerException?.Unwrap<T>() ?? exception as T;
}
public static Exception Unwrap(this Exception exception)
using System;
using System.Configuration;
namespace Util
{
public static class Config
{
public static string GetSetting(string key) => ConfigurationManager.AppSettings[key];
public static bool HasSetting(string key) => !string.IsNullOrEmpty(GetSetting(key));
using System;
namespace Util
{
public interface IClock
{
DateTime NowUtc { get; }
}
public class Clock : IClock
using System;
using System.Configuration;
using System.Linq;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using log4net;
namespace Utils
{
@alastairtree
alastairtree / PluralisationHelper.cs
Last active October 2, 2022 07:48
Detecting plurals
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace LanguageUtils
{
public static class PluralisationHelper
{
private static readonly Dictionary<string, string> KnownCommonPluralsDictionary = new Dictionary<string, string>
{
{"children", "child"},
@alastairtree
alastairtree / XmlDocumentCleanJsonFormatter.cs
Created June 12, 2016 12:16
xml and json conversion formatters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using Newtonsoft.Json.Linq;
namespace Formatters
{
public class XmlDocumentCleanJsonFormatter : XmlDocumentRawJsonFormatter
{
$DemoUser = 'Domain\username'
$DemoPass = 'complexpassword'
$Command = "ECHO 'Hello world'; WhoAmi;"
$StdOutLogFile = "$env:windir\temp\PowerShellElevatedStdOut.log"
$SecurePassword = ConvertTo-SecureString $DemoPass -AsPlainText -Force
$Credential = New-Object System.Management.Automation.PSCredential $DemoUser, $securePassword
"Running '$Command' as current user"
@alastairtree
alastairtree / System Design.md
Created April 18, 2016 03:27 — forked from vasanthk/System Design.md
System Design Cheatsheet

#System Design Interview Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

##Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?
@alastairtree
alastairtree / create-and-share.bat
Created December 14, 2015 12:04
cmd.exe/psexec.exe oneliner to create a folder and share it
REM Will create c:\Deploy, share as "\\server\Deploy"
REM and grant change permissions to administrators and users
cmd /c "(C: & (mkdir C:\Deploy 2> NUL)) & (net share Deploy=C:\Deploy /grant:"Users",CHANGE /grant:Administrators,CHANGE 2> NUL)"