February, 2014

Debugging F# NUnit equals for mixed type tuples

Twitter user Richard Dalton asked a great question recently:

Twitter question

And after a bit more digging he then mentioned

Twitter question

Interesting. I downloaded the NUnit source and saw this:

public bool AreEqual(object x, object y, ref Tolerance tolerance)
{
    this.failurePoints = new List<FailurePoint>();

    if (x == null && y == null)
        return true;

    if (x == null || y == null)
        return false;

    if (object.ReferenceEquals(x, y))
        return true;

    Type xType = x.GetType();
    Type yType = y.GetType();

    EqualityAdapter externalComparer = GetExternalComparer(x, y);
    if (externalComparer != null)
        return externalComparer.AreEqual(x, y);

    if (xType.IsArray && yType.IsArray && !compareAsCollection)
        return ArraysEqual((Array)x, (Array)y, ref tolerance);

    if (x is IDictionary && y is IDictionary)
        return DictionariesEqual((IDictionary)x, (IDictionary)y, ref tolerance);

    //if (x is ICollection && y is ICollection)
    //    return CollectionsEqual((ICollection)x, (ICollection)y, ref tolerance);

    if (x is IEnumerable && y is IEnumerable && !(x is string && y is string))
        return EnumerablesEqual((IEnumerable)x, (IEnumerable)y, ref tolerance);

    if (x is string && 
Read more

,

Single producer many consumer

When I’m bored, I like to roll my own versions of things that already exist. That’s not to say I use them in production, but I find that they are great learning tools. If you read the blog regularly you probably have realized I do this A LOT. Anyways, today is no different. I was thinking about single producer, multiple consumer functions, like an SNS Topic, but for your local machine. In reality, the best way to do this would be to publish your event through an Rx stream and consume it with multiple subscribers, but that’s no fun. I want to roll my own!

BlockingCollection in .NET supports thread safe multiple consumers, but only 1 item will ever get dequeued from your collection. That means that if you have multiple threads waiting on a consuming enumerable, only one of them will get a result (not all of them). That’s … Read more

, , ,

Building LINQ in Java pt 2

In my last post I discussed building a static class that worked as the fluent interface exposing different iterator sources that provide transformations. For 1:1 iterators, like take, skip, while, for, nth, first, last, windowed, etc, you just do whatever you need to do internally in the iterator by manipulating the output the stream.

But if you want to do a transformation like a map, you need to project the input source to something else. Now the base class each iterator inherits from isn’t good enough. But thankfully we can just add another generic parameter and create a new mappable base class that can handle transformations.

The following iterator handles projecting from a source to a result type and yields an enumerable iterator of the result type.

package com.devshorts.enumerable.iterators;

import java.util.function.Function;

public class MapIterator<TSource, TResult> extends EnumerableIterator<TResult> {

    private Function<TSource, TResult> projection;

    /***
     * Need this constructor for flatMap
     * 
Read more

, ,

Logitech mx mouse zoom button middle click on Ubuntu

Any good engineer has their own tools of their trade: keyboard, mouse, and licenses to their favorite editors (oh and a badass chair).

I work now on an Ubuntu box and I wanted to get my logitech MX mouse’s zoom button to act as middle click. I really like this functionality since its easy to copy, paste, close windows, and open new links with this button.

However, the button mapping in Ubuntu isn’t trivial. On windows you used the setpoint program to do it and called it a day. But in linux land you need to put more work into it.

Here is a great tutorial describing how to do it, but for the lazy, here is the mapping you need.

"xte 'mouseclick 2'"
  b:13+Release

What this says is “when button 13 is clicked, then released, issue a mouseclick 2 command”. xte is a program that simulates mouse and … Read more