Category: code

Trying to get JetPack Markdown with code to play nicely with WordPress

After a lot of trial and error here’s how I got code in markdown to work in WordPress. 2 plug-ins are required Smart Syntax for adding class=”prettyprint lang-xyz to the <pre> tag and Prettify Code Syntax for the most flexible syntax highlighter I have ever found for WordPress. Finally, go to Settings – Prettify Code Syntax and change the top… Read more →

Building a Func<TEntity, bool> delegate from an anonymous object

The background to this code is that I’m getting rid of Entity Framework – it’s too slow and IQueryable is so cool but ends up sucking by slowly bleeding into the code base and thereby becoming difficult to performance tune. Thanks, as always, go to my friend .NETJunkie for his remarkable post on the query pattern that has led me… Read more →

Migrating from NUnit to xUnit

These regular expression came in handy recently – they’re not perfect, in particular a couple of the second grouping need to be more greedy – but I did the migration first time through so didn’t get to improve them. Find: Assert.That((.+?), Is.EqualTo((.+?))) Replace: Assert.Equal($2, $1) Find: Assert.That((.+?) == (.+?)) Replace: Assert.Equal($2, $1) Find: Assert.That((.+?), Is.StringContaining((.+))) Replace: Assert.Contains($2, $1) Find: Assert.That((.+?).Contains((.+)))… Read more →

markdown in WordPress – AT LAST!!!!!

Here’s some normal text interspersed with some Code, some italics and bold. a quote some sql select a.FILEID, [FILE_SIZE_MB] = convert(decimal(12,2),round(a.size/128.000,2)), [SPACE_USED_MB] = convert(decimal(12,2),round(fileproperty(a.name,’SpaceUsed’)/128.000,2)), [FREE_SPACE_MB] = convert(decimal(12,2),round((a.size-fileproperty(a.name,’SpaceUsed’))/128.000,2)) , NAME = left(a.NAME,15), FILENAME = left(a.FILENAME,30) from dbo.sysfiles a some code [TestFixture] public class ScrewdriverTests { [Test] public void Container_ExplicitRegistration1_ReturnsExpectedClass() { Container container = new Container(); container.Register(typeof(IScrewdriver<FlatHead>), typeof(FlatHeadScrewdriver)); var screwdriver = container.GetInstance(typeof(IScrewdriver<FlatHead>));… Read more →

Microsoft’s Task Parallel Library and the principle behind node.js

I wanted to see how Microsoft’s Task Parallel Library compared with node.js in so far as passing the next method in to the current to chain the calls indefinitely. So I created a method that iteratively adds itself to the current executing Task. The initial test was to see if the code would fail with a StackOverflowException but what I… Read more →

Sql Server Shrink Log File

Easy with Simple Recovery DBCC SHRINKFILE (“<FileName>_Log”, 1); GO otherwise http://social.technet.microsoft.com/Forums/sqlserver/en-US/0a7a7fc5-d30e-4841-8ed1-84676b575e55/sql-server-2012-how-to-shrink-the-database-transaction-log USE AdventureWorks2008R2; GO — Truncate the log by changing the database recovery model to SIMPLE. ALTER DATABASE AdventureWorks2008R2 SET RECOVERY SIMPLE; GO — Shrink the truncated log file to 1 MB. DBCC SHRINKFILE (AdventureWorks2008R2_Log, 1); GO — Reset the database recovery model. ALTER DATABASE AdventureWorks2008R2 SET RECOVERY FULL; GO Read more →

node.js calling multiple web services in parallel

http://askhds.blogspot.co.uk/2012/02/nodejs-rest-call-using-http-library.html var http = require(‘http’); // Add helloworld module var helloworld = require(‘helloworld_mod’); http.createServer(function(req, res) { res.writeHead(200, { ‘Content-Type’ : ‘text/xml’ }); try { // Bypass function call to “Google Maps API” getFromGoogle(req, res); } catch (e) { res.end(“Try again later”); } }).listen(1337, ‘127.0.0.1’); console.log(‘Server running at http://127.0.0.1:1337/’); console.log(‘Type the URL in address bar’); console.log(‘http://127.0.0.1:1337/maps/api/geocode/xml?’ + ‘address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false’); function getFromGoogle(mainreq, mainres)… Read more →

Extract details from an Expression

I wanted to come up with a way of establishing the type name and property name when applying general validations within my code. So, for example for this validation:. var bool = Requires.IsNotNull(user.lastName) I have to explicitly code the exception: throw NullReferenceException(“User.lastName”) What I’d like is for all this to happen when I declare the test, without double typing the… Read more →

Multiple Dispatch, Double Dispatch and the Visitor Pattern

I’ve been looking into the Visitor pattern and figuring out how to make it work with overloaded methods. Starting with the abstractions interface IVisitor { void Visit(AbstractElement element); } abstract class AbstractElement { public void Accept(IVisitor visitor) { visitor.Visit(this); } } And initial implementations class TestElement1 : AbstractElement { } partial class TestVisitor1 : IVisitor { public string visitedMethod =… Read more →