Archive for the ‘workarounds’ Category

vimeo OEmbed service rejects Apache Commons Http Client User Agent

February 24th, 2011 2 comments

Recently I was working on implementing an OEmbed client for work, and I spent a while trying to figure out why an oembed lookup worked in firefox, but not in my Java Service…

The url was:

For whatever reason, everytime I was making the request in my service I was receiving a 404 error.  I used tamper data in Firefox 3.6 to remove ALL headers except the host header, and it worked…  So, I set the user agent for apache commons HttpClient to a mozilla user agent string instead of the default “Jakarta Commons-HttpClient/3.1”  Just to verify this was the problem, I used tamper data again to set the User Agent for a request from firefox to “Jakarta Commons-HttpClient/3.1” and I received a 404 error…

The User-Agent string I used is: “Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20101206 Ubuntu/10.04 (lucid) Firefox/3.6.13”

Categories: Social Media, workarounds Tags:

nicEdit Firefox center and right align bug patch.

July 28th, 2010 2 comments

If you are using nicEdit on content editable areas instead of the iFrame method, then you may have run across the FireFox bug that prevents you from changing the text alignment on the first line of a content editable element. 

As a work around, change the nicCommand method in nicEdit.js (Line 610 or so), to the below. This code catches the error that firefox throws, inserts a temporary div immediately before the selection, repeats the call that failed (the bug only causes the alignment to fail when it is the very first element in the content editable), and then removes the temporary div.

nicCommand : function(cmd, args) {
        if ((cmd == 'justifyright') || (cmd == 'justifyleft') || (cmd ==
        'justifycenter') || (cmd == 'justifyfull')) {
              try {
                 document.execCommand(cmd, false, null);
              catch (e) {
                 //special case for Mozilla Bug #442186
                 if (e && e.result == 2147500037) {
                    //probably firefox bug 442186 - workaround
                    var range = window.getSelection().getRangeAt(0);
                    var dummy = document.createElement('div');

                     //To restore the range after collapsing for triple click bug...
                     var restoreSelection = false;                     

                    //find node with contentEditable

                    //Triple Click selection Problem in mozilla, the selection contains the content editable div, which creates a problem for some reason, so we collapse the selection to the end, and then re-select everything...
                    if(range.startContainer.contentEditable == 'true'){
                        restoreSelection = true;

                    var ceNode = window.getSelection().getRangeAt(0).startContainer;

                    while (ceNode && ceNode.contentEditable != 'true')
                       ceNode = ceNode.parentNode;

                    if (!ceNode) throw 'Selected node is not editable!';

                    ceNode.insertBefore(dummy, ceNode.childNodes[0]);                    
                    document.execCommand(cmd, false, null);

                     //RestoreSelection if we changed it...
                 } else if (console && console.log) console.log(e);
           } else {
              document.execCommand(cmd, false, args);