Adding a network delay in Windows Server 2008 R2

There is a very cool tool called DummyNet (aka IPFW) which allows you to add latency and set bandwidth or packet loss parameters to any network connection. This can be really useful when testing a client-server application on your local machine, or with virtual machines as it will simulate a more normal network experience and can highlight when you are taking too many round-trips to the server, or 

Download the binary (there is a link at the top of the page) and extract it (I’m assuming you put it in C:\DummyNet).

If you are using a 64-bit version of Windows, then copy all the files in \binary64 to \binary.

Follow the instructions in \binary\readme.txt.

Launch a Command Prompt (as administrator) and start slowing down your network!

Set 200ms of latency

Note we set the latency as 100ms as it will be applied to both incoming and outgoing messages (thus giving 200ms total).

$> ipfw pipe 3 config delay 100ms

$> ipfw add pipe 3 ip from any to any

Remove settings

$> ipfw -q flush

$> ipfw -q pipe flush

 

Disable dashboard in Mac OS X

I find the dashboard in Mac OS X pretty pointless. Luckily, there is an easy way to remove it (thanks to this post).

Note that I’ve tested this in 10.8 Mountain Lion.

Disable

defaults write com.apple.dashboard mcx-disabled -boolean YES 
killall Dock

Enable

defaults write com.apple.dashboard mcx-disabled -boolean NO
killall Dock

A tale of two jobs.

For the last 3 years, I have been working for a large, UK financial institution, on a major transformation programme. The aim of this programme was to rip out their 40 year old banking platform, and replace it with a brand-new SAP platform. The total cost of this project was £400 million. Yet when I asked for a 2nd monitor to complement my existing 19″ (and 2 monitors is the *minimum* a developer should expect these days) I waited 6 weeks only to have a man turn up and plonk a 17″ on my desk.

“What the hell is that?!” I exclaimed.

“Yeah, sorry, budget won’t stretch to 19 inches” he explained.

I checked on Amazon and the difference in price was approximately £30. Now, bear in mind that they were paying over £500 a day for me, and you can see how nuts this was!

Before I sound like a whiny little bitch, it’s important to understand that this is an illustrative example of the attitude. The PC I was supplied with was unusably slow – it would sometimes take 15 seconds to open “All Programs” in the Start menu, and when I ordered another 2 GB of RAM a man came and installed 1…

Yet, what a contrast it is with my new company. 3 weeks before I joined they gave me my new laptop. It’s a top-spec Retina Macbook Pro that literally cost more than my car (granted my car wasn’t very expensive, but still!). And the day I started, my boss said “Here’s your iPhone 5. Oh, and someone pinched your monitor so pick whatever you want off Amazon and get Sally to order it.”. The next day I had two 24″ monitors on my desk. Also, there is free Coke in the fridge and nice toilet paper in the bogs.

The flip-side is that the work is challenging – but then, that’s why they employed me. I’m no longer a faceless cog in a giant machine – I’m once again a valued employee and I love it!

Using MvcSiteMapProvider with Twitter Bootstrap

<a href=”http://nuget.org/packages/MvcSiteMapProvider“>MvcSiteMapProvider</a> provides an easy way to add Sitemap functionality to your MVC application. One very nice thing is that integrating it with Twitter’s Bootstrap UI framework is child’s play (assuming the child in question has a decent background in .NET web-programming of course).

Once you have NuGet’ed both the sitemap provider and Bootstrap, and defined your sitemap XML file, you will typically add the following code to your master page to render the menu into the output HTML.

@Html.MvcSiteMap().Menu()

However, Bootstrap expects the HTML elements to use certain classes (e.g. “nav nav-pills”) which, by default, MvcSiteMapProvider will not do.

You can fix this easily by modifying the following template:

Views\Shared\DisplayTemplates\MenuHelperModel.ascx

to include all the necessary CSS classes.

Edited template

<!-- Edited to work with Twitter Bootstrap by adding 'nav' and 'nav-pills' classes. -->
<ul class="nav nav-pills">
<% foreach (var node in Model.Nodes) { %>
    <!-- Edited to work with bootstrap by adding 'active' class for current node. -->
    <li class='<%= node.IsCurrentNode ? "active" : string.Empty %>'><%=Html.DisplayFor(m => node)%>
    <% if (node.Children.Any()) { %>
        <%=Html.DisplayFor(m => node.Children)%>
    <% } %>
    </li>
<% } %>
</ul>

Cross-domain tabbing issues with SimpleModal

I’ve been using Eric Martin’s brilliant SimpleModal jQuery plugin for a couple of weeks now and am loving it’s simplicity.

However, I’ve run into a problem whereby if I use an iframe, with a source which points to a different domain, then I cannot tab into my modal dialog. This is because SimpleModal works out the first and last input elements in the modal dialog to ensure that you cannot tab out of it (after all, you don’t want your users tabbing to controls which should not be enabled!). However, if the iframe has loaded a page from a different domain then javascript is unable to “see” the input elements inside the page (due to cross-domain policy).

Thanks to StackOverflow I’ve come up with the following solution. Add invisible inputs before and after your modal frame, and modify SimplyModal.js slightly.

So instead of

$.modal("<iframe src='http://www.bing.co.uk' />");

we use

$.modal("<input style='display:none' /><iframe src='http://www.bing.co.uk' /><input style='display:none' />");

This provides two input elements that SimpleModal can detect as they are on your domain. Anything between these two elements is tabbable. However, you also need to edit the following function in jquery.SimpleModal.js to ensure that invisible input elements are detected.

// s.inputs = $(':input:enabled:visible:first, :input:enabled:visible:last', s.d.data[0]);
s.inputs = $(':input:enabled:first, :input:enabled:last', s.d.data[0]);