Wednesday, September 23, 2015

Tech: Adding depth to Firefox rendered pages by over-riding white backgrounds with alpha channel

This is one of those interesting but accidental things.  I was intending to figure out a way to get translucency on Firefox with OS X so that my Tron background theme would show through web pages in the same way it does for my Terminal windows.  That brought me to some interesting discussion about ways to override the background through user scripts.  Specifically a script credited to "Howard Smith" with no OP URL*

// ==UserScript==
// @name        tronBG
// @namespace   hightidetech
// @description change the default bgcolor of websites
// @version     1
// @grant       none
// ==/UserScript==
(function () {
    function noWhiteBackgroundColor() {
        function changeBackgroundColor(x)  {  // auto change colors too close to white
            var backgroundColorRGB=window.getComputedStyle(x,null).backgroundColor;  // get background-color
            if(backgroundColorRGB!="transparent")  {  // convert hex color to rgb color to compare
                var RGBValuesArray = backgroundColorRGB.match(/\d+/g); //get rgb values
                var red   = RGBValuesArray[0];
                var green = RGBValuesArray[1];
                var blue  = RGBValuesArray[2];

                // ============================================================================
                // Set the base colors you require: 
                // use: http://www.colorpicker.com
                // to find the rgb values of the base colour you wish to suppress white backgrounds with:
                // Default gray provided:
                // ============================================================================

                var red_needed   = 220;
                var green_needed = 220;
                var blue_needed  = 255;


                if (red>=220&&green>=220&&blue>=220) {   // white range detection

                   if      (red>=250&&red<=255&&green>=250&&green<=255&&blue>=250&&blue<=255) {
                      red_needed   += 0;
                      green_needed += 0; }

                   else if (red>=240&&red<=255&&green>=240&&green<=255&&blue>=240&&blue<=255) {
                      red_needed   += 6;
                      green_needed += 3; }  

                   else if (red>=230&&red<=255&&green>=230&&green<=255&&blue>=230&&blue<=255) {
                      red_needed   += 10;
                      green_needed += 5; }

                   else if (red>=220&&red<=255&&green>=220&&green<=255&&blue>=220&&blue<=255) {
                      red_needed   += 14;
                      green_needed += 7; } 

                   x.style.backgroundColor="rgba( " +red_needed+ ", " +green_needed+ ", " +blue_needed+ ", " +opacity+ ")"; // the background-color you want 
                   }
                }
            }
        var allElements=document.getElementsByTagName("*");  // get all elements on a page
        for(var i=0; i
            changeBackgroundColor(allElements[i]);}
    }
    window.addEventListener("DOMContentLoaded",noWhiteBackgroundColor, false); 
})() ;

Once loaded up in to greasemonkey this will essentially turn all of your white background pages to a spiffy shade of lavender.  So, I tried to due the same thing for Tron blue** by changing the RGB values in the variable declarations to:

                var red_needed   = 24;
                var green_needed = 202;
                var blue_needed  = 230;

The results were pretty interesting but way too bright for my taste, possibly even a worse contrast of the white on black.  However, moving from RGB to RGBA which has a way to specify opacity, the rendered results are much more interesting depending on how the original page is styled.  To do this, simply add another variable and change the method call below it to use rgba.

                var red_needed   = 24;
                var green_needed = 202;
                var blue_needed  = 230;
                var opacity      = 0.5;
                ...
                x.style.backgroundColor="rgba( " +red_needed+ ", " +green_needed+ ", " +blue_needed+ ", " +opacity+ ")";

Although there is still some white blockiness here and there, the result is much more interesting providing a layering effect to many of today's most frequently visited web sites; and of course if you don't like Tron blue feel free to try something else more to your taste.



*http://superuser.com/a/808537
**http://www.colourlovers.com/color/18CAE6/Tron_Blue



Friday, September 18, 2015

Tech: Crobee "almost" Cool Playstation 4 (PS4) bluetooth adapter/dongle...

There is this saying that something that if something looks too good to be true than it usually is.  I'm sad to say that seems to be the case here with my first ever Groupon purchase, the PS4 Bluetooth Adapter/Dongle offered through Crobee.Cool.  https://www.groupon.com/deals/gs-ps4-bluetooth-adapter-playstation-4-bluetooth-dongle .

Although it took an unexpectedly long time to get through shipping and handling after my initial purchase, when the unit arrived it was professionally packaged, and had a surprise mic that would plug directly in to the controller to go wireless.  That was immediately suspicious because my use case was simply to have an existing bluetooth headset work for the chat channel during gaming while the other gaming sounds continued through the external TV speakers.

The instructions too were a bit misleading because they indicated the dongle would immediately go in to pairing mode upon being plugged in.  But there is a button affixed to the top that clearly needs to be depressed to enter in to pairing mode.

Trying out the mic, it worked great, but echoes obviously because it picks up the sound of the TV w/o using ear phones.  Put two TVs in the same room and that is a surefire recipe for a headache and lots of complaints on the other end of the chat.

The USB dongle does eventually get recognized by the Playstation 4 as an audio accessory, so everything looked like it was good to go.  The only problem was that the dongle was not actually discoverable over bluetooth.  Initially I tried with my Powerbeats2 wireless headphones, then a Sony PS3 bluetooth headset, then my Apple Mac and the PS4 itself, and none of them could actually discover the bluetooth ID for the dongle.

Since it is a final sale and the support appears to be non-existent, I thought I'd post to save anyone else the same frustration of an unmet expectation.


Friday, September 04, 2015

Tech: MS Excel trick - How to transpose "FirstName LastName" to "LastName, FirstName"

For me, Excel is becoming a "data fixup" glue of sorts that I used to use simple Unix commands for.  The chief reason for this is that many of the tools producing the data have export functions to native Excel file formats, so it is easy enough to put output of disparate tools in to multiple tabs of the same workbook and fix them up locally.  But this also presents certain challenges working within the confines of Excel formula's, which like Perl can be very hard to understand what is happening in a complex formula if each part is not well documented.

Thus, the reason behind this post.  While trying to determine if all of the employees of interest from one sheet had completed each of 5 mandatory training modules tracked in another, the first thing I had to do was transpose how the name was represented from one to the other so that I could do a match.

In this instance I want to take "Jane Doe" to "Doe, Jane" .

First, to get the last name we use the RIGHT function assuming the first name is in Column A Row 2:

=RIGHT(A2,LEN(A2)-FIND(" ", A2,1))

Concatenating a trailing comma is as simple as using "&"

=RIGHT(A2,LEN(A2)-FIND(" ", A2,1)) & ", "

Now we use the LEFT function to get the first name:

=LEFT(A2,FIND(" ",A2,1)-1)

Put it all together and we have the following:

=RIGHT(A2,LEN(A2)-FIND(" ", A2,1)) & ", " & LEFT(A2,FIND(" ",A2,1)-1)

All this is really doing is extracting out the substring on either side of the whitespace character and allowing you to manipulate that text independently of the rest.  Obviously if there is another separator, you would specify that instead to do the same thing.