Using the option key in macOS Terminal

I like using the Meta+left/right to navigate back and forth between words. On macOS by default, no key is mapped to Meta!

Fortunately for me, it is possible to configure the Option key to act as a Meta key. With the Terminal app selected, this can be done by going in to Terminal > Preferences (Cmd+,) > Profiles > Select your profile > Keyboard > Use Option as Meta.

React: Unexpected token <

I’ve been fiddling around with React recently and made some pages with some normal-looking URLs, despite being a single-page application. This was done using React Router and configuring it to use the History API with browserHistory. Here is one of those URLS:

http://localhost:3000/course/react-flux-building-applications

When the page was refreshed (either manually or by the hot loader), or when I visited that page manually, I got this odd error in the console:

Unexpected token <

When I inspected the contents of bundle.js, which is what I had configured webpack to bundle all of my JS in to, I noticed it wasn’t JS at all; it was the HTML for my index page!

<!DOCTYPE html>
<html lang="en">
<head>
    <title>Pluralsight Admin</title>
</head>
<body>
    <div id="app"></div>
    <script src="bundle.js"></script>
</body>
</html>

After a few moments of wondering, I realised what had happened. It was pretty dumb. Can you see it?


What happened is that bundle.js was being loaded from:

http://localhost:3000/course/bundle.js

And not:

http://localhost:3000/bundle.js

Since the URL was not recognised, webpack or React Router (I’m unsure exactly which) merely served index.html instead of a 404 error.

This meant that HTML was served for a JS request!

The simple fix is to change:

<script src="bundle.js"></script>

To:

<script src="/bundle.js"></script>

That way the requests always go to http://localhost:3000/bundle.js.

This may need to be solved slightly better if I don’t want to host the application at the root of a domain, but it’ll work for now while I experiment!

Working around Chroma Subsampling over HDMI on Nvidia cards

If you have chroma subsampling issues when connecting a display via HDMI on an Nvidia card, despite all the settings appearing as if there shouldn’t be any, try creating a new custom profile at a fractionally higher refresh rate and using that new profile.

  1. Go in to the Nvidia Control Panel.
  2. Go to Display > Change resolution
  3. Select Customise…
  4. Check “Enable resolutions not exposed by the display”
  5. Select Create Custom Resolution…
  6. Select the correct horizontal pixels, vertical pixels, colour depth and scan type. Then enter the desired Refresh rate, and add 1 to it.
    • The Nvidia Control Panel does not allow you to create duplicates of profiles that exist by default. So changing the refresh rate ensures that the new profile is not a duplicate, and means you do not need to change resolution.
  7. Test the profile, save it, exit the customise window.
  8. Select your new resolution off the list, and click Apply.

With any luck, your new profile will not have any chroma subsampling, leaving your colours (particularly reds) looking good, especially on menus.

Printing Brother labels through GIMP

I’ve been fiddling with a Brother P-Touch D600, which is able to connect to a computer through USB. Since I’ve realised that it appears to Windows as a standard printer, I’ve been trying to see if any applications can print to the device. They can!

Notepad works (albeit not in the most useful fashion). But I had a bit of trouble with GIMP.

I found that, for some reason, even after setting the correct image/DPI settings and running through page setup, GIMP still seems to think it is printing via A4. I’m unclear where the problem comes from, but it can be worked around when you go to print.

After selecting Print, select the Image Settings tab, and ensure the image is aligned to the top-left corner. You’ll need to factor in a margin. On my 24mm labels, I set a top and left margin of 3mm or so.

How to update Qualcomm Atheros QCA61x4 drivers

Qualcomm seem to make up-to-date wireless and wireless+bluetooth drivers available to Killer Networking first. Forunately you are able to download and install them yourself.

  1. Go to the Killer Networking driver page.
  2. Download the Standard drivers (no Killer Features).
  3. If your wireless adapter has Bluetooth, download the Bluetooth drivers as well.
    • My QCA61x4 device has Bluetooth, so I downloaded the Bluetooth driver for the K1525/1535.
  4. Install the driver(s) in the usual manual way: Device Manager > your wireless adapter > Driver > Update driver… > Browse > Let me pick > Have disk… > Browse to driver.
    • In my case, the k11acw10 directory worked for the wireless adapter.
    • If Windows complains there is no valid driver, try another directory.

Bonus chatter: The driver needed updating as it was causing BSODs. A very helpful post by Glenn Meuth on this forum thread helped me identify the unreliable driver via analysing the BSOD’s memory dump.

Making CD Mixtapes

If I’m making informal CD mixtapes (mixdiscs?), use Foobar2000 (or other software) to convert the tracks to WAV, and then use ImgBurn to create a CUE file (Tools > Create CUE file…), drag and drop the tracks in to the new window, and customise the disc before burning it.

EAC can also be used for this (and is likely the better choice for making clones of audio CDs), but seems to be a little unreliable on my laptop. And I don’t like to waste CDs, especially when I only have 2 or 3 of them!

Caching git credentials on Windows

You may have already used the git credential cache to cache your remote credentials for some time, via something like:

git config --global credential.helper 'cache --timeout=3600'

However this will not work on Windows, as cache communicates over a Unix socket.

Fortunately, support for Windows’s built-in credential manager has been added to the Windows git distribution (along with msysgit). To leverage it, use the wincred helper:

git config --global credential.helper wincred

If, like me, you like to use your dotfiles across many platforms, you may not want to put this in your global .gitconfig. Instead, you can include an environment-specific config file globally and make a new file with the credential helper configuration inside:

git config --global include.path .gitconfig_env
git config --file ~/.gitconfig_env credential.helper wincred

If you want to remove, modify or otherwise manage your Windows credentials, use the Credential Manager. This can be found in Control Panel > Credential Manager.

PRO TIP: In Windows 8 and above, you can quickly get to the Control Panel by pressing Win+X, P.

Dynamic DNS (DDNS) on Asus routers

When using the stock or Merlin firmware on various Asus routers (I have an RT-N66U), you can use dynamic DNS to get a web domain to point to your router’s IP address.

To use dynamic DNS, do the following:

  1. Go to your router’s administration console (sometimes available at http://router.asus.com) and head to WAN > DDNS. There is also a link on the Network Map page.
  2. Enable the DDNS client, set Server to Custom and set the hostname to the web domain you will be updating (e.g. example.com).
  3. Connect to the router. I tend to enable SSH (and disable Telnet) via Administration > System.
  4. Create the script that will update your DDNS at /jffs/scripts/ddns-start. My favoured tactic here is to run:

    cat > /jffs/scripts/ddns-start
    

    Then paste the code, ensure the cursor is on a blank line (press Enter if not), then press Ctrl+D.

  5. Finally, ensure the script is executable:

    chmod +x /jffs/scripts/ddns-start
    

In my case, I’m updating an address using the http://afraid.org service. I get my private key from the dynamic section of the Afraid.org site, and I use a script taken almost verbatim from the Merlin wiki:

#!/bin/sh

curl "https://freedns.afraid.org/dynamic/update.php?<PRIVATE_KEY_HERE>"

if [ $? -eq 0 ]; then
    /sbin/ddns_custom_updated 1
else
    /sbin/ddns_custom_updated 0
fi