- 2020-01-22 - 2020/01/22/Flush-MacOS-DNS-Cache/

Had to restart a dead remote VM server this morning, and it gets its IP address from DHCP. I don’t have physical access to the machine and I needed to SSH into the VM to manually restart some services. My MacOS system was still caching the old DNS address, and IT told me I needed to flush my DNS cache. I had no idea how to do that on MacOS, but turns out to be pretty simple. In the terminal, just run the following command:

sudo killall -HUP mDNSResponder


Author: Eric Asberry
URL: https://a42.us/2020/01/22/Flush-MacOS-DNS-Cache/
- 2020-01-07 - 2020/01/07/Copying-dot-files-from-the-shell/

This isn’t rocket science, more of a note to self.

Found myself moving to a new work machine at work. Part of that involves copying dot files that Mac OSX finder can’t see. I really only want to move the ones I absolutely need, because I’m moving from a machine that I’ve had for nearly 5 years, so a lot of cruft has accumulated.

I have to return the old machine soon though. So the first thing I did was use Carbon Copy Cloner to back up the entire image to a USB drive. Now, I don’t want to carry that USB drive around everywhere. Once I get the code repositories, etc copied I don’t want to be tethered to it. But I want to hang on to all those dot files and directories in case I miss something and need them.

So what I’ve done in the past is a bunch of ls -la commands, and pick out the ones I know I need, manually copying them one by one. Found myself about to do the same thing again, even though there are some I know for sure I don’t need, and while I could just delete those and copy everything, I still want to keep them on the backup because I’m paranoid.

Copying dot files from the terminal can be a little tricky though. Try doing:

ls -a .*

You get everything in the current directory and subdirectories. But a couple of grep commands can make it pretty easy:

for x in `ls -a | egrep '^\\.\\w' | egrep -v 'atom|Web|DS_Store|cache|vagrant'`; 
  cp -rpv $x ~/dotfiles; 

So let’s break this down:

for x in `somecommand`

(note: it’s a backtick, not a single quote!) iterates over the lines of output of somecommand.

In this case, somecommand is:

ls -a | egrep '^\\.\\w' | egrep -v 'atom|Web|DS_Store|cache|vagrant'

The ls command with the -a option lists all files in the current directory including hidden (dot) files, and at this point I’ve already cd’d to the directory containing the dot files on my backup drive.

We then pipe that to:

egrep '^\\.\\w'

That filters the output of ls to only include filenames that start with a ‘.’ (the backtick must be used to escape the period, since otherwise it means match any character) followed by a word character. We match on the word character because otherwise the output would include entries for ‘.’ and ‘..’ which we don’t want to include.

Finally, that output is piped to egrep again, and in this case we’re telling it to exclude output that matches the given patterns, separated by the | character. In this case, I know I don’t want the .DS_Store directory, or the .cache directory, and I haven’t used atom, WebStorm or vagrant in years, so I don’t want to bother copying those files.

Inside the do/done section, we use the copy command to copy each file from the list to a directory (previously created) called “dotfiles”; underneath my home directory. We use -r for recursive (so we copy dot directories and everything underneath them, not just the top level files), -p to preserve the permissions and -v so that we see output seeing the files as they are copied (otherwise the output from cp is silent).

Hopefully someone else finds this useful; if nothing else I will be referring back to this myself the next time I have to do this!

Author: Eric Asberry
URL: https://a42.us/2020/01/07/Copying-dot-files-from-the-shell/
- 2019-10-10 - 2019/10/10/This-Is-Unsafe/

Against my better judgement, I upgraded to MacOS Catalina. After surviving a panic when the upgrade was seemingly stuck “estimating time remaining” (I left it alone; the process ended up taking about 2 hours total) I fired up Chrome and tried to get to work.

The project I work on uses self-signed certificates for local dev, generated on the fly by an npm module called pem. This has always resulted in big warning page from Chrome about the certificate being invalid, but it’s always been easily bypassable by clicking the Advanced button and clicking the option to proceed anyway.

However, after the upgrade, the error page changed as shown above. Now it says the certificate is revoked (NET::ERR_CERT_REVOKED), and no longer gives me the option to proceed.

First, I was a little confused how the MacOS update caused this. I assume it’s tied to some connection between Chrome and the OS, but curiously, I did not have this same problem with Firefox. I thought it might be something that changed in Chrome itself, but I verified I do not have this issue with the same version of Chrome on Linux. I really didn’t want to spend hours going down this rathole (but, alas, so I did) and just wanted to get back to work, but sometimes that’s not how it goes in the life of a software developer.

So, my first sign of hope was this page I found. Seems there was a change where certificates with an expiration date greater than 825 days are no longer accepted. Looking at the code, I see the certificate being generated by pem is set to be valid for 3650 days. That must be it!

This did cause a change in behavior. Now instead of NET::ERR_CERT_REVOKED, I got the same page but with a different error: NET::ERR_CERT_INVALID. This is the same error I’m used to, but I still am not given the option to proceed.

I could not find anybody running into the exact same issue as me. I pondered trying to find a different NPM module (not at all confident that would help), generating a static certificate file and importing it into Chrome, starting Chrome from the command line with –ignore-certificate-errors, and myriad other solutions, all of which seemed less than ideal, when I stumbled across this forum thread from 2017. It wasn’t exactly the same scenario, other than the OP was also trying to bypass the NET::ERR_CERT_INVALID error.

When I saw this response, I honest to God thought it was a sarcastic joke, but out of desperation, I tried it anyway: There’s a secret passphrase built into the error page. Just make sure the page is selected (click anywhere on the background), and type thisisunsafe

I clicked back on my Chrome window, typed in the characters “thisisunsafe” (didn’t even have to hit Enter!), and lo and behold, my local dev site is back in all its glory!

Hope this helps someone else out.

Author: Eric Asberry
URL: https://a42.us/2019/10/10/This-Is-Unsafe/
- 2019-07-25 - 2019/07/25/Safari-blocking-new-window-opened-from-clicking-button-in-web-application/

I work on a web application that includes a feature that integrates with another of my company’s products. You trigger the integration by clicking a button in the first web app, which launches the second web app and passes along a document. The code is a little something like this:

$(document).on('click', '.my-button', function(e) {
     method: 'POST',
     url: '/api/call/to/get/the/url/we/need/to/open',
     error: function (status, err) { },
     success: function (data) {

I mostly use Chrome on either a Mac or Linux laptop and this has worked fine. But yesterday I got a report that the button was not functioning on Safari. Turns out that the window.open was being blocked by Safari’s popup blocker. Of course, the easiest thing is to just tell the user to turn off their popup blocker. But that’s obviously not ideal.

So I did some digging and found other people had run into similar issues with Safari. But the solution is relatively simple, according to this StackOverflow link. Do the window.open first, with no target, and then set that window’s location.

However, this still didn’t fix the issue for me. Digging a little deeper into the comments on the post, one additional thing I discovered is that the ajax call that’s triggering this also needs to NOT be asynchronous. Well, this is not ideal, but the web app is basically blocked until this completes anyway, so this turns out to be a good enough solution for now. The API call is pretty fast, but I throw up a little temporary modal with a spinner while this is being processed so the window doesn’t just completely freeze up with no feedback.

So the fixed code looks a little like this:

$(document).on('click', '.my-button', function(e) {
    method: 'POST',
    async: false,
    url: '/api/call/to/get/the/url/we/need/to/open',
    error: function (status, err) { },
    success: function (data) {
      var newWindow = window.open();
      newWindow.location = data.redirectUrl;

Hope this helps someone! And of course I welcome any feedback on better ways of handling this.

Author: Eric Asberry
URL: https://a42.us/2019/07/25/Safari-blocking-new-window-opened-from-clicking-button-in-web-application/
- 2017-06-14 - 2017/06/14/SOLVED-Docker-Networking-On-Fedora-Linux-Fails-When-I-m-Connected-To-VPN/

I do a lot of my development work inside docker containers.  Recently I ran into an issue where, when connected to my company’s VPN network, the docker containers on my local machine running Fedora would lose the ability to connect to external resources.  Eventually I discovered the issue was that the default subnet created for the docker bridge interface on my Linux machine was overlapping with the subnet used by our corporate VPN.  So everything worked fine, as long as I wasn’t connected to the VPN.

My home network is a 10.x.x.x subnet, while my corporate VPN (and my default docker bridger interface) were bothing using 172.x.x.x.  So I opted to use 192.168.1.x for my docker bridge.  Making the change was fairly straightforward.  I needed to create the file /etc/docker/daemon.json.  The documentation describes a lot of options in this file, but all I needed was the following:

  "bip": ""

Then I restarted docker:

sudo service docker restart

Problem solved!

Author: Eric Asberry
URL: https://a42.us/2017/06/14/SOLVED-Docker-Networking-On-Fedora-Linux-Fails-When-I-m-Connected-To-VPN/
- 2016-09-30 - 2016/09/30/Pairing-a-Logitech-MX-Master-Mouse-with-Ubuntu-16-04-Using-Bluetooth/

Compared to when I used to download 3.5” floppy disk install images to set up Slackware on my machine, Linux has grown by leaps and bounds in terms of usability.  The majority of things seem to “just work” these days.  However, every once in awhile I run into some kind of weird issue.

In this case, I wanted to pair my MX Master Wireless Mouse with my Lenovo laptop running Ubuntu 16.04.  I don’t use the unifying receiver (which, to be honest, I don’t even know if I still have) because I generally just pair with Bluetooth so I have one less dongle to mess with.  That’s even more important in the case of a small laptop that doesn’t have a lot of USB ports to spare.

Adding a bluetooth device is theoretically pretty straightforward.  Go into the bluetooth settings and click “Add Device” while the mouse is in pairing mode.  It actually finds the MX Master just fine, and even claims to complete the pairing process.

However, it still doesn’t recognize the mouse, and the LED for the connection is still blinking instead of staying solid.  After a lot of googling, I finally found a solution that worked for me.  Once you have gone through the regular pairing procedure, enter the following commands (as root):

hciconfig hci0 sspmode 1
hciconfig hci0 down
hciconfig hci0 up

Voila, a working mouse!

Author: Eric Asberry
URL: https://a42.us/2016/09/30/Pairing-a-Logitech-MX-Master-Mouse-with-Ubuntu-16-04-Using-Bluetooth/
- 2016-09-18 - 2016/09/18/Quick-tip-for-joining-lines-with-a-separator-in-vim/

Every so often I need to deal with some exported database id’s that come in the form of a CSV file.  The trouble is, instead of having the id’s one per line, I really need them on a single line, comma-separated so that I can use them in an IN clause in some kind of query.  I always remember this is easy to do in vim, but I can never remember the syntax.  So here it is, for my (and maybe somebody else’s) future reference:


: to enter command mode
% to select all lines
Then the substitute command to search and replace all newlines in the selected block with a comma.  

Of course you could use the pipe character or whatever other delimiter you need in place of the comma.

Now that I’ve written it down somewhere hopefully I’ll never forget it!

Author: Eric Asberry
URL: https://a42.us/2016/09/18/Quick-tip-for-joining-lines-with-a-separator-in-vim/