Category: code

Holistic Abstractions (Take 2)

In this post I will outline an updated perspective on Commands and Queries with respect to applying cross-cutting concerns (aka Aspects or Decorators). If you are unfamiliar with these two patterns then please see these posts here and here for a great introduction. Bertrand Meyer defines CQS as: every method should either be a command that performs an action, or… Read more →

dynamic code generation in c#

Copied directly from ayende.com Given a Dictionary<string, string>, convert that dictionary into a type in as performant a manner as possible. The conversion will happen many time, and first time costs are acceptable. public static Func<Dictionary<string, string>, T> Generate<T>() where T : new() { var dic = Expression.Parameter(typeof (Dictionary<string, string>), “dic”); var tmpVal = Expression.Parameter(typeof (string), “tmp”); var args =… Read more →

How to find your Windows 10 Product Key after the upgrade

source Save the following as a .vbs Option Explicit Dim objshell,path,DigitalID, Result Set objshell = CreateObject(“WScript.Shell”) ‘Set registry key path Path = “HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\” ‘Registry key value DigitalID = objshell.RegRead(Path & “DigitalProductId”) Dim ProductName,ProductID,ProductKey,ProductData ‘Get ProductName, ProductID, ProductKey ProductName = “Product Name: ” & objshell.RegRead(Path & “ProductName”) ProductID = “Product ID: ” & objshell.RegRead(Path & “ProductID”) ProductKey = “Installed Key:… Read more →

Dealing with a MySQL warning from my hosting provider

I got a warning email from my hosting company today MySQL Quota DB: has used 136.87 MB out of 50 MB limit After some research I discovered that 2 database tables used by Apocalypse Meow are using approx. 120MB. I resolved the issue: Delete the data: open Apocalypse Meow settings page and click Purge ALL data Reclaim the disk space:… Read more →

LINQ: Group a list of strings into chunks

LINQ: Group a list of strings into chunks, dividing the chunks by a whole-line marker (in the example “<Custom>”) public static partial class Queries { public static IEnumerable<string[]> Execute( this IQueryHandler<DataChunker, IEnumerable<string[]>> handler, IEnumerable<string> data) { return handler.Execute(new DataChunker(data)); } public class DataChunker : IQuery<IEnumerable<string[]>> { public DataChunker(IEnumerable<string> data) { this.Data = data; } public IEnumerable<string> Data { get; set;… Read more →

Markdown and Prettify V2

Install the smart syntax plugin Go to Smart Syntax settings tab and ensure that Custom Skin is ticked Remove the following from smart-syntax/includes/functions.php: remove all 3 lines ?> <script>prettyPrint()</script> <?php Open file wp-content/plugins/smart-syntax/assets/css/smart_syntax.css and replace the contents with this: .prettyprint .com { color: #008000; } .prettyprint .str, .tag { color: #A31515; } .prettyprint .kwd, .atv { color: #0000FF; } .prettyprint… Read more →

Give background threads time to complete in IIS

Thanks to this post public sealed class OutOfProcessMediatorDecorator<TCommand> : IMediatingHandler<TCommand>, IRegisteredObject where TCommand : IMediator { private readonly IMediatingHandler<TCommand> decorated; private readonly Container container; public OutOfProcessMediatorDecorator( IMediatingHandler<TCommand> decorated, Container container) { this.decorated = decorated; this.container = container; } public void Execute(TCommand command) { HostingEnvironment.RegisterObject(this); var task = Task.Factory.StartNew(() => { using(container.BeginLifetimeScope()) { try { this.decorated.Execute(command); } finally { HostingEnvironment.UnregisterObject(this); }… Read more →

System.Windows.Controls.WebBrowser

interaction from javascript in the Document to external C# code [ComVisible(true)] public class ScriptProxy { // This method can be called from JavaScript. public void AMethod(string message) { MessageBox.Show(message); } } this.webBrowser1.ObjectForScripting = new ScriptProxy(); <input type=”button” value=”Go Again!” onclick=”window.external.AMethod(‘Hello’);” /> subscriber to browser events thanks to this answer [ComVisible(true)] [ClassInterface(ClassInterfaceType.AutoDispatch)] public class EventListener { [DispId(0)] public void NameDoesNotMatter(object data)… Read more →

NDepend, a second look

After my previous post regarding NDepend I have decided to give it another go, this time on a new project. I am using Visual Studio 2015 for the first time so need to install NDepend for VS2015; this is now very easy after setting things up last time. Navigate to the NDepend folder, run NDepend.VisualStudioExtension.Installer.exe and click install for VS… Read more →