Squashing git commits with interactive rebase

Sometimes, you’ll want to re-write the history of a feature branch so your repository isn’t cluttered before merging it into your mainline branch.  This is a simple tutorial about how to accomplish just that.  Watch in HD quality or it isn’t going to look very good.

Two reasons your MarkLogic code is failing silently, part 1

If you’re new to MarkLogic application programming, it’s easy to get frustrated when your code fails without any obvious reason why.  There’s no run-time error, no exception to catch, and when you surround the code block in question with log writing expressions, the “before” log expression and the “after” log expression both work perfectly.

Even now, excellent application developers are still making these same mistakes because they’re so easy to do if you aren’t paying perfect attention.

Coworker: Hey, can you look at this code and see if you know what's wrong with it?
Me: (before he pastes the code into the IM window) 
    It's namespaces or function mapping.
Coworker: ...
Coworker: Damnit.

Read more »

Minor site changes and software sharing info

I’m making a couple of minor changes to the site.  In particular, I’m scrapping the WordPress idea of categories.  It had a hard time finding a categorization method that I liked, and even once I defined the categories, I usually wanted to file my posts into several categories even with the tagging mechanism.  So, instead of using categories at all, I’ll just tag articles with whatever topics are touched upon.  I think maintaining a list of tags is easier and makes more sense than maintaining a list of categories and tags when they’re going to be used basically the same way.  For the articles that have already been categorized, they’ll stay categorized.  I just won’t be adding any more categories and I won’t show the categories on the right-hand navigation either.

I’m also going to try to make it easier to use the code I post on here.  Sure, with libraries with a specific purpose, it is usually easy to grab them off GitHub or BitBucket and integrate them into your project.  Sometimes, though, I’ll post random snippets of code that can’t easily be integrated or tested without going through a lot of trouble.  From now on, when I will try to be more proactive about writing the code in a way that you can download and execute it without having to do much additional setup.  My goal is to put any code I write on the blog also on GitHub.

In addition to putting practically everything on GitHub, I am also going to make it easier to find posts that have code on GitHub.  Any article that has code on GitHub will be filed with a GitHub tag.  You can easily filter for posts that have code on GitHub by clicking the tag.

The last thing I want to say about SCM and social sharing sites is that I will not be sharing on BitBucket as part of this blog.  I used BitBucket a couple of years ago when it was only offering Mercurial support and I was a Mercurial user.  Nowadays, I am using Git more and more, and GitHub simply has more momentum as far as social coding that BitBucket does.  It’s not that I don’t like BitBucket, it’s just not worth keeping track of code on both sites.

Links to my GitHub and BitBucket pages are in my links section in the right hand navigation bar, but here they are just in case:

Nelson Well’s GitHub
Nelson Well’s BitBucket

Oh, Bing, it’s cute that you tried

But who really thought it could end up any other way? ?

Lovin’ Bing’s bitter message about winning yada yada

Some friendly competition will do both search engines some good, so I invite you to Bing It On.

How Jenkins CI parses and displays jUnit output

Now that I’ve had the opportunity to work on a continuous integration infrastructure for both Mirth Connect interfaces and a MarkLogic-powered REST API.  The Mirth interface testing software was built with Perl and TAP (Test Anything Protocol).  The ML REST API testing software was built on MarkLogic itself.  What they both had in common is that Jenkins was used to build the environments and run the tests.

I’ve really come to appreciate how useful Jenkins can be.  Jenkins can aggregate jUnit style reports out of the box, and Jenkins can give you meaningful textual and graphical representations of those reports.  It will tell you how many tests failed, how many tests passed, what class and packages were being tested, and it give you this information over the course of many builds.

However, since neither CI testing software was actually built on Java, I was unable to leverage the actual jUnit testing framework.  In addition, neither the Mirth Connect interfaces nor MarkLogic/Xquery have a concept of grouping code into packages and classes as a Java programmer may expect.  Because of these two issues, I had to generate jUnit output programmatically.  Even though I was able to start with someones stab at the jUnit XML schema, I found that Jenkins does not parse and display the jUnit output exactly as I would have expected.  For the time being, it is probably easier to ignore the jUnit schema and instead listen to what I’m about to say ? Read more »

Using jquery.bgpos.js with jQuery 1.8

Today, I spent way too much time working on a front-end problem to a code base that I wasn’t very familiar with.  This project’s animated navigation menu stopped working when upgrading from jQuery 1.7 to jQuery 1.8, and we needed jQuery 1.8 because of another dependency.  After digging my way through the code, I finally found that the problem was occurring because Alexander Farkas’ jquery.bgpos.js jQuery plugin was not compatible with jQuery 1.8.

Since the internals of jQuery’s animation code has changed from 1.7 to 1.8, the plugin needed to be updated as well.  I’m pasting the entirety of the change here so that, hopefully, maybe, someone else doesn’t go through the same frustration that I went through today.  I’ve made the necessary changes bold and italic in the following code block.  I can’t guarantee this code would work with jQuery versions less than 1.8 ?

/**
 * @author Alexander Farkas
 * v. 1.02
 *
 * Edited by Nelson Wells for jQuery 1.8 compatibility
 */
(function($) {
    $.extend($.fx.step,{
        backgroundPosition: function(fx) {
            if (fx.pos === 0 && typeof fx.end == 'string') {
                var start = $.css(fx.elem,'backgroundPosition');
                start = toArray(start);
                fx.start = [start[0],start[2]];
                var end = toArray(fx.end);
                fx.end = [end[0],end[2]];
                fx.unit = [end[1],end[3]];
            }
            var nowPosX = [];
            nowPosX[0] = ((fx.end[0] - fx.start[0]) * fx.pos) + fx.start[0] + fx.unit[0];
            nowPosX[1] = ((fx.end[1] - fx.start[1]) * fx.pos) + fx.start[1] + fx.unit[1];
            fx.elem.style.backgroundPosition = nowPosX[0]+' '+nowPosX[1];
 
           function toArray(strg){
               strg = strg.replace(/left|top/g,'0px');
               strg = strg.replace(/right|bottom/g,'100%');
               strg = strg.replace(/([0-9.]+)(s|)|$)/g,"$1px$2");
               var res = strg.match(/(-?[0-9.]+)(px|%|em|pt)s(-?[0-9.]+)(px|%|em|pt)/);
               return [parseFloat(res[1],10),res[2],parseFloat(res[3],10),res[4]];
           }
        }
    });
})(jQuery);

Big Data and how Isaac Asimov will have successfully predicted psychohistory

A couple of weeks ago, I had the opportunity to attend MarkLogic World 2012.  The overall theme of the conference was converting Big Data into Big Ideas.  Big Data is a paradigm shift for many in the IT industry; briefly, Big Data saves everything, whether it’s usefulness is obvious or not, in hopes that decisions can be made on that data.  In theory, the traditional data model would be unable to make informed decisions because the data set would not be large enough accurately describe super-complex issues.

Psychohistory, then, as defined by Isaac Asimov in his novel Foundation, goes something like this:

Branch of mathematics which deals with the reactions of human conglomerates to fixed social and economic stimuli; implicit in all these definitions is the assumption that the human conglomerate being dealt with is sufficiently large for valid statistical treatment.

Read more »

Words With Friends bug

TheDailyWTF would be proud

Is an empty string really a misspelled word?

Convert an integer to a sequence of digits in Xquery

I am new to the functional programming paradigm and Xquery. As part of a larger exercise, I wanted to sum the digits of an integer.  The first part of that problem is to solve the smaller problem: convert an integer to a sequence of integers that I can then pass to fn:sum as a parameter.

(: I've declared the function in the nwnu namespace for testing purposes :)
declare function nwnu:number-to-seq($num as xs:integer)
as xs:integer* {
  if($num gt 9) then
    (
      nwnu:number-to-seq(xs:integer(math:floor($num div 10))),
      xs:integer(math:floor($num mod 10))
    )
  else
    $num
};

Read more »

Pair Programming

Pair Programming

Nothing like cracking the whip