rcook's blog

Test posting

Posted on 5 September 2011 at 11:23am Pacific time.

Fun with contracts and anonymous delegates

I officially blew my own mind today. I discovered System.Diagnostics.Contracts and inline declaration and invocation of anonymous delegates all in the same day...

namespace FunWithContracts
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics.Contracts;
    using System.Linq;

    internal static class Program
    {
        private static void MySort<T>(T[] array, int index, int length, IComparer<T> comparer)
        {
            Contract.Requires<ArgumentNullException>(array != null);

Binding "this" in JavaScript: I finally get it!

var obj = {
  name: "Richard",
  callback: function(event) {
    print("event = " + event);
    print("name  = " + this.name);
  }
};
var element = {
  name: "Element",
  callback: null,
  invoke: function() {
    print("invoke");
    if (this.callback != null) {
      this.callback("hello");
    }
  }
};
function bind(context, func) {
  return function() {
    return func.apply(context, arguments);
  }
}
element.callback = bind(obj, obj.callback);
element.invoke();

Ductile# project goes public

Simulating packet loss with iptables/ipfw

I need to simulate packet loss for a little programming assignment I'm working on which involves implementing a multicast chat application using UDP sockets. I need to build reliability into the system (sequence numbers and acknowledgements etc.) and thought it might be sensible to test the behaviour of my program under WAN-style network conditions. Originally I was just going to randomly drop packets in my server, but then I thought to myself that there ought to be an OS-level way of doing it. Indeed, there is and here is my bash script that demonstrates it.

Mono C# extensibility project

I have created the "Mono C# extensibility project" with the intention of making it straightforward to write custom add-ins for the Mono C# compiler.

Here's a link: http://github.com/rcook/mono-extensibility/

Instrumenting IL generation in Mono's C# compiler

Someone asked me the other day how I'd go about instrumenting the IL generated by the Mono C# compiler: something to do with custom profiling I think. I still haven't come up with a totally satisfactory answer but here's a patch of some work I did showing how I hacked away at various bits of the sources to emit custom method prologues and epilogues. Download the patch and apply it to your Mono Git repo.

Visitor pattern (re)visited

I am aware that the visitor design pattern has been around in some form for years and so what I'm about to write in this post is not particularly innovative or special in any way. I just thought I'd discuss something I've been pondering for a while in my attempts to come up with interesting refactorings for the DuctileJ project.

Anyway, I read

"What to Know Before Debating Type Systems"

On my travels around the programming language community on-line I found many references to Chris Smith's review of types entitled "What to Know Before Debating Type Systems". Unfortunately, it was almost as if it had disappeared from the face of the planet. Of course, nothing ever really disappears from the Internet and I was able to summon it forth from the recesses of the Internet using Way Back Machine:

http://web.archive.org/web/20080822101209/http://www.pphsg.org/cdsmith/t...

Syndicate content