Wednesday, February 7, 2018

Detecting Cordova Webview Visibility Changes (e.g. detecting when an AdMob ad is running on top of the webview)

I've not posted in awhile, but recently worked through a challenge that I think needs to be recorded for future reference.

Running a Cordova AdMob interstitial ad on top of a Cordova webview that already has an AdMob banner ad (bottom positioned) is breaking the viewport height calculation in iOS (except iPhone X) for me once the interstitial is closed. In order to address this, the banner ad needs to be removed when the interstitial is shown (easy with showInterstitial callback), but the banner ad needs to be added back once the interstitial is closed (hard without any callback).

Sorting through lots of ideas online, all of which were hacks or not quite what I need (pause and resume cordova events don't fire in this case), I was left trying to find anything about the DOM that changed when the interstitial was on top. Traditional element visibility checks yielded the same results regardless of whether the interstitial was open or closed. What to do?

HTML5 Page Visibility API to the rescue! Listening for 'visibilitychange' and then checking document.hidden is exactly what I was looking for.

            document.addEventListener('visibilitychange',function(){
                if (document.hidden) {
                    // remove the ad
                } else {
                    // show the ad
                }
            },false);


While this may seem simple, it is not insignificant. While Cordova handles pause and resume states, when the app has a plugin sitting on top of the webview (oAuth SDKs, ads, etc), we sometimes need the webview to be aware of that and the page visibility API gives us that ability.

Sunday, June 4, 2017

How-To Tail (ColdFusion) Log Files in Windows Command Line via PowerShell and .bat Script

Setting up a new environment, I wanted to tail my coldfusion log files. Usually this is simple in the CFEclipse or CFBuilder log window. Unfortunately, that doesn't work in my new environment (beside the point). So I needed a different solution.... PowerShell to the rescue! It turns out it is super simple to tail files in PowerShell via a command like $ Get-Content coldfusion-out.log -wait. Awesome! But when I save this to a .ps1 file and double-click, it just opens my text editor. How can I double click like a good old .bat file?... well make a a .bat file named the exact same with contents like this:
@ECHO OFF
PowerShell.exe -executionpolicy remotesigned -File %~dpn0.ps1
PAUSE


Now I can double-click my .bat and launch a regular old command window that tails my log file using PowerShell.

In the end, the files look like this:

And the .bat file double-click to command window looks like this:

Rinse and repeat with different log file names for any other log files you want to tail. Of course, this has nothing specifically to do with ColdFusion, but that's what I use it for :-)

Thursday, March 23, 2017

Samsung Gear S2 Won't Turn On - How I fixed it

I was a reluctant buyer of a smartwatch. I got the Gear S2 refurbished a few months ago and I ended up really liking it. Unfortunately, I had one charger die and had to replace it. Otherwise, it has been all good.... until yesterday. I grabbed my watch off the charger and it was dead. It wouldn't even turn on. The charger indicator LED showed blue as if it were charging. I went watch-less for the day. Upon returning home, I tried the following steps which brought my Gear S2 back to life:

  1. Remove any protective backing from the watch (I had a protector skin on it)
  2. Plug the charger into a computer USB (low voltage) port
  3. Place the watch on the charger
  4. Wait 2-3 minutes
  5. The watchface should light up and show that it is charging
  6. Let it fully charge (will take awhile)
  7. Take it off charger and power on
  8. Back to normal! Charge with regular power adapter again as needed
Essentially, my watch refused to charge on the regular power adapter. It would only "trickle-charge" on the lower voltage power source. I think it was in some sort of protective anti-overheating mode as it had been very hot when I pulled it off the charger when it wouldn't power on. The low voltage charge must have been "allowed" by the software whereas the higher voltage charging was being restricted. Just my theory...

Wednesday, March 1, 2017

Prevent Ionic Header from Auto-Scrolling Content to Top when Header is Tapped

An interesting piece of functionality in Ionic that only became aware of today is "tap-scroll" which auto-scrolls to the top of the screen when the header/title of the view is tapped. This only seems to work in iOS and caused some strange behavior in a view that had some custom scrolling related javascript code. This led me to look for ways to disable this cleanly. It turns out there is an attribute available on ion-header-bar called "no-tap-scroll" that can disable this behavior when set to "true".

Take a look at ionic.bundle.js and you'll see this defined for ion-header-bar.


When setting no-tap-scroll="true" on the ion-header-bar element, you'll be able to disable this auto-scroll to top functionality, which I think is rather unexpected behavior.

Synology Cloud Sync with Multiple Folders / Directories

If you have a Synology NAS running DSM, you are likely familiar with the Cloud Sync package. This package has lots of potential, but has one major blocker: each account can only sync one folder. This has supposedly been addressed via "tasks" in newer DSM versions (6+) but if you are stuck on an older version of DSM, you are limited to syncing one folder to the cloud service of choice (i.e. Drive, OneDrive, Amazon, etc). This is problematic if you have a folder structure where folders like Homes, Videos, Music, Photos, etc are all top level shared folders with various permissions. Say you want to back up all Homes and also Videos, Music, and Photos... you must back each one up to a different cloud service. This is a deal breaker. Alternatively, you can move your folder structure around, but that is also a deal breaker if you have multiple users with different permission levels on these folders.

What is the solution for DSM < 6 then? Permanent Symlinks
With permanent symlinks, you can create "virtual" directories that Cloud Sync will see as real directories to include in the sync. This allows you to have something like "\homes\user1\movies" that actually points to "\movies". Granted, your cloud backup folder structure will be different than your actual folder structure, you will at least get everything backed up.

To implement this, there are two steps:

  1. Make the links:
    1. SSH into your Synology
    2. Run "mount -o bind ‹TargetDirectory› ‹VirtualDirectory›"
  2. Make them permanent
    1. Run the link scripts at startup (more info at https://forum.synology.com/enu/viewtopic.php?t=102158)


Saturday, November 12, 2016

Find Your GSM SIM Ready Laptop / Convertible / 2-in-1 / Tablet IMEI

I have been using a Lenovo Thinkpad Helix for months now, successfully replacing 4 towers, 1 laptop, 1 iPad, and 1 Android tablet with the single all-in-one device. It has been great! Now, I am ready to add a GSM SIM card and get this thing fully mobile.

I had no idea what the IMEI is on the device as there is no sticker and I don't have the original box or documentation. After a little searching, I found a handy command that works in Windows command line: '$ netsh mbn show interface'

This produces the following results:


Tuesday, July 12, 2016

How to Convert Apache .htaccess URL Rewrite Rules to IIS web.config

Having put in lots of testing and debugging time, your .htaccess URL rewrites are finally rock solid ( or good enough maybe :-) ). Now you are changing servers from Apache to IIS and you have to come up with all new web.config URL rewrite rules. I've been though this, manually refactoring .htaccess to web.config, and it isn't quick. The good news is that Microsoft has a tool to make this super simple and fast!

First, make sure you have the URL Rewrite module installed in IIS. This is a simple download and install.

Second, open up IIS and go to your website. You should now have a URL Rewrite icon. Double-click on this new icon and you'll see a menu on the right side with an "Import Rules..." option. This is where the magic happens. You can import your .htaccess file or copy/paste the contents and IIS will do the heavy lifting to convert it to web.config.

One thing to note here that could save you some time... the web.config gets generated in the website root. Therefore if your source .htaccess was not in the website root, the generated web.config may need some touch up to the paths. Otherwise, the generated web.config is spot on based on my experience and you are all set!

Reference: https://blogs.msdn.microsoft.com/azureossds/2015/04/23/converting-apache-htaccess-rules-to-iis-web-config-using-iis-manager-for-azure-websites/