Mike Wills Podcast 2017-08-01 – Dog Days of Podcasting 2017-01

Here is my first installment of the Dog Days of Podcasting podcast. I dusted off the equipment and I took you on a journey to figure out what the hell this Dog Days of Podcasting will be about.

Forcing SSL in IIS without being annoying

When we recently launched our site, and with everything going to HTTPS only, I wanted to force as much to HTTPS only as possible. There are many, many links on how to force HTTPS on an IIS server. The issue is that when you debug your application locally, you have to comment out that section of code, do your debugging and changes, then hope you don’t forget to uncomment out that section of code. I have finally found out to the force HTTPS and allow you to debug on localhost. Here is the code that you need in your web.config:

      <rule name="HTTP to HTTPS redirect" stopProcessing="true">
        <match url="(.*)" />
          <add input="{HTTPS}" pattern="off" ignoreCase="true" />
          <add input="{HTTP_HOST}" matchType="Pattern" pattern="^localhost(:\d+)?$" negate="true" />
          <add input="{HTTP_HOST}" matchType="Pattern" pattern="^127\.0\.0\.1(:\d+)?$" negate="true" />
        <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />

The HTTP_HOST lines are what need to be added then it will work! Reference

Add Visual Studio Code to your context menu

After the release of the new Visual Studio Code, I took a look at it and figured out that the target market is those that are currently using Sublime Text. I want to give it the ol’ college try, but the one big thing that was missing for me is the ability to right-click on any file and open it in Visual Studio Code, like I can with Sublime Text.

Here is how to add this functionality. In the registry add the key HKEY_CLASSES_ROOT\*\shell\Open with Visual Studio Code\command with the value of @="C:\\Users\\USERNAME\\AppData\\Local\\Code\\app-0.1.0\\Code.exe \"%1\"" replacing USERNAME with your username. That is it!

A Fix for PDF Display Issues in Chrome

We came across an interesting bug in Chrome two days in a row, a PDF wouldn’t display correctly. It would be missing either an entire page or just some of the information on the page. There are published work-arounds to disable the built-in Chrome PDF viewer and instead utilize Adobe Acrobat Reader instead and also notices to maybe use a different browser. Let’s be honest here, the fault is the person/company that creates the PDF to make sure to optimze the PDF for the best viewing experience on the web.

Here is the problem, the Chrome PDF viewer cannot work with layered PDF files. I didn’t know layers was possible until just yesterday. Apparently, though I don’t yet know how, you can turn on and off layers (think of Google Maps with turning on and off features on the map). So how do you fix it? In both our our instances, we needed to flatten the PDF. Once we flattened the PDF and optimized it for the web, it showed up correctly in Chrome.

Don’t get me wrong, sometimes you will want those features and then you will need to provide a disclaimer stating that some PDFs may not render correctly in the Chrome browser. At least until Chrome adds support for layers.

A Responsive Google Map Application Template

At work, I am working on rewriting a bunch of maps so that they are consistent and mobile-friendly (a.k.a. responsive). When I starting searching for some basic how-tos I turned up nothing. I did find how to make Google Maps itself responsive. My issue was how do I add a legend and form that will filter or add content to the map and keep it mobile-friendly. Since I couldn’t find anything, I set forth to make something myself. In one weekend, I created a basic framework utilizing Bootstrap, the following week I refined and finalized the application and I think it turned out well.

I made the template open-source so that others can benefit from what I learned and help make this a better template in the future. I hope others can help me make this even more accessible and improve the template further.

I used Bootstrap because that is what I am most familiar with. In the future, if I have time, I want to try to eliminate Bootstrap to reduce the overhead. Once our new website launches, I’ll add some examples of what I created with the template so you can see why I felt this was important.

Here is what the large-screen version looks like:

Large screen view of application
Large screen view of application

Here is the mobile views:

Mobile View of Application
Mobile view of application
Mobile View of Legend
Mobile view of legend
Mobile View of Filter
Mobile view of filter

Do Not Use Comments

This came across my Hacker News feed the other day, “I’ve never seen a language’s style guide recommend avoiding comments before.” After reading the link it became clear that the HN title was link bait. What the Haskel documentation was stating is something any good programmer already knows. Don’t document every line of code.

x = x + 1; // Increment x by 1

This comment is not required as it is obvious what it is doing. My rule of thumb for commenting is; if it’s complicated or was problematic, it requires a comment explaining the why or why not. A good programmer should be able to read through the simple code and know what is going on. However, commenting on why you wrote something the way you did would help yourself or the next guy to know what you were thinking.

This comes to light not only when I am looking at code I wrote 5 years ago, but recently I had a co-worker leave. He didn’t write many (read any) comments in his code. Now in some cases I am running debug just to see what the application is doing before I can think of fixing that bug or making that change.

So do your future self or co-worker a favor and comment… but not too much.

Now monitoring my websites with Google Spreadsheets and Pushover

I used a previous version of this free monitoring tool, but I recently setup their new version. It is quite neat. Basically, it uses Google’s infrastructure to constantly hit your website and if it doesn’t get a 200 status back, it will contact you via email or SMS saying your site is down. While this was nice, I really wanted to use Pushover more. So I looked through their API and discovered it is very easy to send messages. So I modified their script and now I get notifications via Pushover. Here are the changes that you need to perform.

  1. Add two new rows after the SMS notifications row.
  2. Call the title’s what you want, but I went with “Pushover API Token ::” on A5 and “Pushover User Key ::” on A6.
  3. I created a new Pushover app
  4. I put the new app’s API token in B5 and my user key in B6.5. Go to Tools | Script editor…
  5. Then add the following code to the function logMessage(url, message) funtion in the script after the email portion:
    if (sheet.getRange(“B5”).getValue() != “”){           var options = {               ‘method’: ‘post’            };    var url = ‘https://api.pushover.net/1/messages.json?’     + ‘token=’ + sheet.getRange(“B5”).getValue()    + ‘&user=’ + sheet.getRange(“B6”).getValue()    + ‘&message=’ + alert    + ‘&title=’ + “Site ” + message;    var response = UrlFetchApp.fetch(url, options);        }

Controlling a Epson TM-T20 on the IBM i (or iSeries)

The past couple days I was on a mission to look for a way to replace our aging dot-matrix receipt printer. We got some new printers to go with our new credit card processor. These printers are Epson TM-T20 thermal printers. I had some problems finding the information to have the printer cut the paper and to get it to eject the cash drawer. I am documenting what I found here for people in the future to figure out.

You need these codes embedded in the spool file. The first hex character, 03, tells the OS we are sending ASCII characters. The second, 06, tells the OS that the next x characters are ASCII.

  • To cut the paper – X'03060D0A1D564220'
  • To eject the cash drawer 1 – X'03051B703040F0'
  • To eject the cash drawer 2 – X'03051B703140F0'