Turn Off Windows Sound Notification Banner

Operating System: Windows 10

In an earlier article I posted how to How to Disable Windows Volume Popup, but that required a small 300 KB program to be installed.

In my opinion the real-offensive element is actually the browser notification banner that gets attached to the media control popup. This is what I mean:

Both Chrome and Firefox notification banner attaches to this volume popup. Disable it like this:

Chrome

  1. In Chrome address bar, type chrome://flags/
  2. Then find the setting Hardware Media Key Handling and set it to Disabled.

Firefox

  1. In Firefox address bar, type about:config
  2. Then set media.hardwaremediakeys.enabled to false

Enjoy just the volume control bar without the ugly offensive banner!

Add Gitignore in Visual Studio

Objective: You have multiple Visual Studio projects (using the same technology stack) under a single git repository and you need to manually add a .gitignore file.

Instead of copy/pasting an existing .gitignore file, let Visual Studio generate it for you.

2 Steps to Add the .gitignore File via Visual Studio

  1. Inside Visual Studio, open your solution and click the tab “Team Explorer”
  2. Then click “Add” under Ignore & Attributes Files -> Ignore File
Steps to add .ignore file in the Team Explorer tab
After successfully adding the .gitignore file

This will add the .gitignore file in your root git repository folder. So you should not need to repeat the projects for other Visual Studio projects in the same folder (provided they are all using the same technology stack).

Upgrade Phoenix Framework

The following shows a minor upgrade within version 1.5.x. If you need to upgrade 1.4.x to 1.5.x, please see: https://gist.github.com/chrismccord/e53e79ef8b34adf5d8122a47db44d22f

To upgrade a Phoenix project, edit mix.exs, look for the line (was upgraded from 1.5.1 to 1.5.4):

{:phoenix, "~> 1.5.4"},

To upgrade the Phoenix installer itself, run in the terminal (example shows upgrading phx_new 1.5.3 to phx_new 1.5.4):

> mix local.phx
Resolving Hex dependencies...
Dependency resolution completed:
New:
  phx_new 1.5.4
* Getting phx_new (Hex package)
All dependencies are up to date
Compiling 10 files (.ex)
warning: redefining module Mix.Tasks.Local.Phx (current version loaded from ~/.mix/archives/phx_new-1.5.3/phx_new-1.5.3/ebin/Elixir.Mix.Tasks.Local.Phx.beam)
  lib/mix/tasks/local.phx.ex:1

Generated phx_new app
Generated archive "phx_new-1.5.4.ez" with MIX_ENV=prod
Found existing entry: ~/.mix/archives/phx_new-1.5.3
Are you sure you want to replace it with "phx_new-1.5.4.ez"? [Yn] y
* creating c:/Users/sanji/.mix/archives/phx_new-1.5.4

> mix phx.new --version
Phoenix v1.5.4

Finally, if you updated mix.exs file for any project, run:

> mix deps.clean --all
> mix deps.get
> mix

Write a list comprehension that finds all the Pythagorean triples for right triangles with sides shorter than 100

Write a list comprehension that finds all the Pythagorean triples for right triangles with sides shorter than 100. A Pythagorean triple is three integers a, b, and c, where a² + b² = c².

In Elixir it takes a line of code with pattern-matching to produce this.

Note the 3 patterns below, nested loops, scary I know. But at least rather than starting from 1 each time, we loop through 1 more than the last value of the outer loop.

  • a<-1..99,
  • b<-(a+1)..99,
  • c<-(b+1)..99

And the final pattern which make it all work like magic:

a*a + b*b == c*c

File: pythag.exs

for a<-1..99, b<-(a+1)..99, c<-(b+1)..99, a*a + b*b == c*c, do: IO.puts "#{a}² + #{b}² = #{c}²"

Output: console

> elixir pythag.exs
3² + 4² = 5²
5² + 12² = 13²
6² + 8² = 10²
7² + 24² = 25²
8² + 15² = 17²
9² + 12² = 15²
9² + 40² = 41²
10² + 24² = 26²
11² + 60² = 61²
12² + 16² = 20²
12² + 35² = 37²
13² + 84² = 85²
14² + 48² = 50²
15² + 20² = 25²
15² + 36² = 39²
16² + 30² = 34²
16² + 63² = 65²
18² + 24² = 30²
18² + 80² = 82²
20² + 21² = 29²
20² + 48² = 52²
21² + 28² = 35²
21² + 72² = 75²
24² + 32² = 40²
24² + 45² = 51²
24² + 70² = 74²
25² + 60² = 65²
27² + 36² = 45²
28² + 45² = 53²
30² + 40² = 50²
30² + 72² = 78²
32² + 60² = 68²
33² + 44² = 55²
33² + 56² = 65²
35² + 84² = 91²
36² + 48² = 60²
36² + 77² = 85²
39² + 52² = 65²
39² + 80² = 89²
40² + 42² = 58²
40² + 75² = 85²
42² + 56² = 70²
45² + 60² = 75²
48² + 55² = 73²
48² + 64² = 80²
51² + 68² = 85²
54² + 72² = 90²
57² + 76² = 95²
60² + 63² = 87²
65² + 72² = 97²

Write a function even_length? that uses pattern matching only to return false if the list you pass it has an odd number of elements, true otherwise.

Write a function even_length? that uses pattern matching only to return false if the list you pass it has an odd number of elements, true otherwise.

This is a fun little exercise in Elixir. First we match a single item in the list (odd number) which is false. Then match exactly two items (even number) and return true. Then the 3rd function matches the first 2 elements (as throwaway) and recursively tails the list to match the first two patterns.

defmodule Lists do
  def even_length?([_a]), do: false
  def even_length?([_a, _b]), do: true
  def even_length?([_a, _b | t]), do: even_length?(t)
end

Some testing below in IEx:

iex> Lists.even_length? [1]
false
iex> Lists.even_length? [1, 2]
true
iex> Lists.even_length? [1, 2, 3]
false
iex> Lists.even_length? [1, 2, 3, 4]
true

Dark Mode for Sumatra PDF

Windows: version 10
Sumatra PDF: version 3.2 64-bit

A dark mode for Sumatra PDF is really easy – you just need to tinker with 3 lines of code in the settings.

Why Use Sumatra PDF?

In my opinion, it’s the best PDF reader. It’s small in size, super-fast and doesn’t have any annoying cruft.

Why a Dark Mode (Night Mode)?

If you code for long periods of time, then it’s really great to have your code editor run in dark mode. This greatly reduces the strain on the eyes.

But let’s say you are also following along an e-book, maybe a PDF and you switch to Sumatra PDF. The default setting is black text on white background. Immediately your eyes are shocked with bright luminescent white light. It’s as if you were relaxing in a room with the lights switched off and suddenly someone walked in and abruptly turned the lights on.

As you are coding along you have to switch back and forth multiple times between your PDF reader and code editor. It can be really jarring for the eyes and nerves.

How to Enable Dark Mode?

In Sumatra PDF, click on the Menu -> Settings -> Advanced Options

This should open the SumatraPDF-settings.txt file in your text editor. Change the following 3 lines under the heading FixedPageUI:

TextColor = #eeeeee
BackgroundColor = #111111
GradientColors = #000000

TextColor changes the text color of the PDF document. Background color changes, well the background color of the PDF document. GradientColors will change the background window of Sumatra PDF.

XAMPP Upgrade Tasks

I usually have 3 simple and separate tasks for a XAMPP upgrade or any general development environment migration (for example when moving to a new Windows or Mac hardware).

  1. Moving the source codes, files and assets: copy the www folder with all the project source codes local virtual host domains
  2. Apache configuration: edit the httpd.conf and httpd-vhosts.conf files
  3. MySQL migration: migrate the database

Source files

Usually I have a separate www folder configured with vhosts.

Apache Configuration

I only change the following line in httpd.conf because I like to develop on port 8080.

Listen 8080

And as a habit (Debian and FreeBSD) check if the vhosts file is included:

Include conf/extra/httpd-vhosts.conf

The httpd-vhosts.conf file has multiple entries (for each project or local domain name):

<VirtualHost *:8080>
    ServerName client1.san
    ServerAlias www.client1.san
    DocumentRoot C:/xampp/www/client1
</VirtualHost>

MySQL Migration

A fresh copy of a pristine MySQL installation with PHPMyAdmin has the following databases:

  • information_schema
  • mysql
  • performance_schema
  • phpmyadmin
  • test

So when migrating I try to avoid copying over those five databases / schema.

Preview(opens in a new tab)

While it might be OK to dump the database via PHPMyAdmin, it’s not a good idea to restore it via a web interface. For example my combined database size is almost 1 GB.

So ensure you have a decent max_allowed_packet size in specified in my.ini:

max_allowed_packet=16M

Then run the database restore command manually from the command line. For example:

mysql -u root < databases_to_migrate.sql

Using URLSearchParams in IE 11

Microsoft Edge has been around for a while, but IE 11 is not dead! There are people in the real world who still use IE 11, so the development process especially JavaScript implementation has to account for it.

While there are many Github projects and NPM packages providing Polyfill for URLSearchParams, the easiest way to use it is using a CDN link to one of the Polyfill implementations. Here is one from:

https://cdnjs.com/libraries/url-search-params

Then link from your code like this:

<script src="https://cdnjs.cloudflare.com/ajax/libs/url-search-params/1.1.0/url-search-params.js"></script>

MySQL Workbench 8.0 – Set the Default Time Zone

MySQL Workbench 8.0.19
MySQL Server 8.0.19

Summary

Here is a single screenshot summary of the actions you need to take in 6 labelled steps to change the time zone via MySQL workbench:

Detailed Steps

A detailed list of steps follow below.

Step 1 & 2

Either click from the main navigation menu -> Server -> Options File:

Or from the left navigation Administration tab -> Options File:

Step 3, 4 & 5

Then under General tab scroll down to the International field set, then locate the default-time-zone field, set it to your preferred zone:

Step 6

Then click on the Apply button:

You will get a confirmation box, hit the Apply button.

Directly Edit Config File my.ini

An alternative would be to directly edit the my.ini file and set the property:

default_time_zone = +8:00

In Windows 10, you can find the file here:

C:\ProgramData\MySQL\MySQL Server 8.0\my.ini

Set the JDK Path in GlassFish

GlassFish version: 5.1.0
Windows version: 10

Motivation

You may have several version of the JDK installed on your machine. By default you may be using JDK 11 or even 13, but GlassFish requires JDK 8.

Issue

Running asadmin generates the following error

Exception in thread “main” java.lang.NullPointerException
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.initializeServiceLocator(AbstractModulesRegistryImpl.java:128)
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.newServiceLocator(AbstractModulesRegistryImpl.java:120)
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.createServiceLocator(AbstractModulesRegistryImpl.java:194)
at com.sun.enterprise.module.common_impl.AbstractModulesRegistryImpl.createServiceLocator(AbstractModulesRegistryImpl.java:200)
at com.sun.enterprise.module.single.StaticModulesRegistry.createServiceLocator(StaticModulesRegistry.java:64)
at com.sun.enterprise.admin.cli.CLIContainer.getServiceLocator(CLIContainer.java:193)
at com.sun.enterprise.admin.cli.CLIContainer.getLocalCommand(CLIContainer.java:231)
at com.sun.enterprise.admin.cli.CLICommand.getCommand(CLICommand.java:207)
at com.sun.enterprise.admin.cli.AdminMain.executeCommand(AdminMain.java:347)
at com.sun.enterprise.admin.cli.AdminMain.doMain(AdminMain.java:282)
at org.glassfish.admin.cli.AsadminMain.main(AsadminMain.java:33)

Fix

Edit: ~\glassfish\config\asenv.bat
Assuming JDK 8 installation path is C:\Program Files\Java\jdk1.8.0_241

Add the line:

set AS_JAVA=C:\Program Files\Java\jdk1.8.0_241