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/

Wednesday, July 6, 2016

Creating a PDF on the fly with Ionic/Cordova

So you've got an Ionic app and you need to create PDFs from within the app. You don't want to offload to a server for PDF generation/download because the PDF is user specific and unique each time it is generated, so why not just generated it client side? For one, that was near impossible a number of years ago. Two, you've tried before and it just never worked right. Well, I managed to get PDF generation in an Ionic app and wanted to share my experience so you can do the same.

What we are going to do is capture a portion of the HTML, turn it into a PDF, and trigger the download for the user.

The first step is to add the required libraries:
Cordova Plugins:
"cordova-plugin-file-transfer"
"cordova-plugin-file-opener2"

index.html (install via bower or point to CDN):
<script src="lib/jspdf/dist/jspdf.min.js"></script>
<script src="lib/html2canvas/dist/html2canvas.js"></script>

Next, we create the PDF generation function:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
$scope.generatePDF = function (method) {

       //set the margins for the PDF
 var margins = {
  top: 40,
  left: 40
 };

        // function to create a hidden clone of the target element,
        // allowing manipulation specific for the PDF output without changing the actual target element.
 var hiddenClone = function (element) {
  document.documentElement.style.overflow = 'visible';
  document.body.style.overflow = 'visible';

  // Create clone of element
  var clone = element.cloneNode(true);

  // Position element relatively within the
  // body but still out of the viewport
  var style = clone.style;
  style.position = 'relative';
  style.top = window.innerHeight + 'px';
  style.left = 0;
  style.width = '535px';
  style.zIndex = '9999';

  // Append clone to body and return the clone
  document.body.appendChild(clone);
  return clone;
 }

        // now create the clone of your target element and send it to html2canvas
 var html2Pdf = hiddenClone(document.getElementById('pdfTarget'));
 html2canvas(html2Pdf, {
  onrendered: function (canvas) {
                        // once the canvas is rendered, create new jsPDF object and working variables
   var doc = new jsPDF('p', 'pt', 'letter');
   var dataUrl = canvas.toDataURL('image/jpeg');

   doc.addImage(dataUrl, margins.top, margins.left, canvas.width, canvas.height);
   var dataUrlPdf = doc.output();
   var dataUrlPdfBase64 = 'data:application/pdf;base64,' + btoa(dataUrlPdf);

                        // once we've got the canvas, we can remove the clone element and reset styles
   document.body.removeChild(html2Pdf);
   document.documentElement.style.overflow = 'hidden';
   document.body.style.overflow = 'hidden';

   var filename = 'PDF-' + $filter('date')(new Date(), 'yyyy-M-d') + '.pdf';

   // Save location
   var targetPath = cordova.file.externalRootDirectory + filename;

                        // use the cordova file transfer plugin to send the file to the cordova file opener plugin,
                        // allowing user to pick download method (only seems to work on Android)
   $cordovaFileTransfer.download(dataUrlPdfBase64, targetPath, {}, true).then(function (fileEntry) {
    console.log('Success');
    console.log(fileEntry);
    fileEntry.file(function (file) {
     cordova.plugins.fileOpener2.open(
      file.localURL,
      file.type, {
       error: function (e) {
        console.log('Error status: ' + e.status + ' - Error message: ' + e.message);
       },
       success: function () {
        console.log('file opened successfully');
       }
      }
     );
    });
   }, function (error) {
    console.log('Error');
    console.log(error);
   }, function (progress) {
    // PROGRESS HANDLING GOES HERE
   });
  }
 });
};

Now you can run the function and try it out...
Hopefully you'll have successful client side PDF generation from HTML. I will say these plugins/libraries are touchy, especially when used together but this formula worked for me. Best of luck and feel free to share your implementations and feedback!

Tuesday, March 1, 2016

Implementing Ionic ion-slides in place of the deprecated ion-slide-box

I have been working with Ionic 1.7.14 lately and ran into issues with <ion-slide-box>. It turns out <ion-slide-box> is deprecated and replaced by <ion-slides>. Unfortunately, the documentation is poor. The silver lining is that it is worth the switch as ion-slides is built on iDangerous' Swiper which is probably the best slider/slidebox out there.

For those Ionic loyalists who live by the documentation, good luck making much of anything great based on the documentation at http://ionicframework.com/docs/v2/api/components/slides/Slides/ and http://ionicframework.com/docs/v2/components/#slides.

The reason I say this is because the documentation doesn't show how to expose all the functions of the Swiper plugin via javascript which are seemingly endless (http://idangero.us/swiper/api/). This is also the main reason to even use the new <ion-slides> directive. While you can specify options like loop and pagination (see below) via the Ionic directive's "option" directive, these aren't even explained in the docs except as when used as directives themselves (i.e. pager and loop). Further, it is especially unclear how the entire Swiper API can be leveraged using <ion-slides>.

Here is a solution, specifically note the onInit which captures the Swiper plugin (in original form) to the $scope. Now you can leverage the Swiper API (as referenced in link above) against this $scope.swiper object. The $scope.sliderOptions will be used by the <ion-slides> via the "options" directive as mentioned previously.

// CONTROLLER
// Setup swiper
$scope.sliderOptions = {
    loop: true,
    pagination: false,
    onInit: function(swiper){
        $scope.swiper = swiper;
    },
    onSlideChangeStart: function(swiper){
        //
    }
};

// TEMPLATE
<ion-slides options="sliderOptions">
    <ion-slide-page ng-repeat="slidesin slides">
        // iDangerous Swiper Slide in Ionic
    </ion-slide>
</ion-slides>

Tuesday, February 16, 2016

Installing Cisco VPN Client and SonicWall Global VPN Client on Windows 10 Upgrade

UPDATE 08/24/2016: The Windows 10 Anniversary Update broke my Cisco VPN Client again. The guide here got me back on track.

So you've upgraded to Windows 10 and been promised everything will keep working just as before... but one of the most important apps you have is now broken! This is what happened to me when upgrading to Windows 10. Both my Cisco VPN Client and SonicWall Global VPN Client stopped working. Fortunately, there is a fix... and it is surprisingly pretty.

In comes TechyGeeksHome to the rescue! They have put together a great utility to help rectify these issues (specifically for Cisco VPN, but works for SonicWall Global VPN too).


  1. Uninstall your VPN(s).
  2. Go to http://blog.techygeekshome.info/2016/01/cisco-vpn-client-how-to-make-it-work-with-windows-10.
  3. Download the Windows 10 fix package.
  4. Run the included WinFix.exe (by Citrix)
  5. Run the included DNE Update (by Citrix)
  6. Install the Cisco VPN MSI (the exe will not work) (msi for x64 can be found here according to Google search)
  7. Run the included CiscoVPNClientFixx (by TechyGeeksHome)
  8. If you also want to use SonicWall Global VPN, you can now install it as well
These steps solved my issues and I am back up and running on Windows 10 + VPN thanks to TechyGeeksHome.

Sunday, January 31, 2016

Android Intent App Options Now Include Apps from Play Store That Are Not Installed On Device

I was using my android recently and noticed something quite surprising. I was opening an .XLSX file and the typical intent/app selection popover came up on screen. I had Google Sheets and Quickoffice apps as options as always (they are installed on my device), but I now also had an "Excel" option with the text "Free" to the right. At this point I'm not sure what goes into getting a "yet-to-be-installed" app to appear in the list of intent/app options, but this is a pretty big move for Android to take. What do you think?

Here is a screenshot for your enjoyment: