CR2032 With Wire

Booting my NUC I noted the following message:

The following are warnings that were detected during this boot.
These can be viewed in setup on the Event Log Page.
WARNING : CMOS Time Not Set

Oldsters keeping their machine longer than a few years are probably already yelling CR2032. And guess what - I had those ready to go. After opening NUC (darn IR window is really annoying to get out) I got into trouble as battery wasn’t in the holder. Nope, it was on the wire.

While you can hack the solution by simply soldering wires to the battery, I would recommend thinking twice about it. I have done it multiple times and it is not only annoying to solder onto whatever alloy battery is made of (no, it is not pure aluminium) but heating the lithum batteries significantly decreases their life.

As I didn’t know the type of connector of the top of my head I went over to Intel’s support pages and of course they had an article ready. It went even so far to actually specify connector as Molex 51020-0200. I couldn’t actually find such Molex connector but I’ve found 51021-0200 looking exactly the same. I guess not even Intel is immune to typos.

Armed with knowledge of connector, I went on Amazon hunt and found a few of them. Of course, I went with cheapest which at $5 is not really cheap at all. I guess you pay premium for that sweet cable.

Moments before plugging it in I noticed something disturbing. Black and red wires were swapped on my replacement battery as compared to the one I pulled out. I am not sure which one is more standard but Intel and Dell like to play on opposite side of spectrum. Plugging Dell battery into NUC would almost surely damage it as CMOS battery circuits are rarely protected against reverse polarity. It was a time for surgery.

Using small blade (scalpel actually) I gently lifted plastic holding each terminal in the housing and pulled them out. Done gently enough this enables reinsertion of the terminals into the housing with the black wire at position #1 - the same as used in NUC.

This whole battery swap took way longer than it should have but at least my BIOS complains no more. :)

PS: Since computer was plugged in at all times, I find it really strange to have battery fail on me after only three years. I have way older machines with their original battery still working…

Parsing Double.MinValue

If you try converting double.MinValue to string and then back again, you will be greeted with OverflowException:

var text = double.MinValue.ToString(CultureInfo.InvariantCulture);
Console.WriteLine(text);
var number = double.Parse(text, NumberStyles.Float, CultureInfo.InvariantCulture);
Console.WriteLine(number);

Seemingly output string of -1.79769313486232E+308 is a bit lower than double would go despite the implicit promise minimum value makes: to be a minimum.

Reason for this is ToString() method not showing all the digits it can by default but actually a few less with a bit of rounding. This actually generally gives a better result (for example try 1.0/3). Last digit or two are noise anyhow due to the nature of double.

However, if we are emotionally connected to every possible digit or we need to parse stuff we give as output, there is a little thing called round-trip formatting. That works for Single, Double, and BigInteger data types and it consists of a single “r”:

var text = double.MinValue.ToString("r", CultureInfo.InvariantCulture);
Console.WriteLine(text);
var number = double.Parse(text, NumberStyles.Float, CultureInfo.InvariantCulture);
Console.WriteLine(number);

Now we get -1.7976931348623157E+308 as a text representation and parsing fails no more.

PS: Equivalent “issue” exists for .MaxValue.

Duplicates in Dictionary

If one needs to fill dictionary with bunch of keys while tracking only last value for each, a generic inner loop code might looks something like this:

if (dict.ContainsKey(key)) {
    dict[key] = value;
} else {
    dict.Add(key, value);
}

Code checks if key exists, if not it is added; otherwise the old value is replaced. Pretty straightforward.

Surprisingly, this code can be simplified - a lot:

dict[key] = value;

Dictionary’s indexed property will do exactly the same thing as code above - but in less lines.

StarCraft 1.18 for Free

Zealot

Nineteen years after the StarCraft’s release, there is yet another patch. Alongside many bug-fixes, it also made StarCraft and Brood War expansion completely free.

While giving the old game for free could be considered a bit of a gimmick in the light of newly announced StarCraft: Remastered, an HD version of the original StarCraft, it is not only that.

Blizzard actually released new features within this patch and that is not the first time. They simply kept up the great customer care of the StarCraft saga. Frankly I wouldn’t be surprised if we see another patch or two for it in the future.

Without the further ado, download the new (free) version and have fun.

PS: And yes, StarCraft color issue has been resolved.

PPS: You can also check some other free games from Blizzard. My personal favorites being The Lost Vikings but also Warcraft II and Diablo are nothing to frown upon. :)

[2017-07-02: StarCraft Remastered will be available at August 14th and it will cost $15. You can preorder it now.]

Adding Domain Search Option to Mikrotik DHCP

Illustration

I already wrote about using Mikrotik’s DNS to resolve a short name lookup in Windows. And there I noted that domain-name DHCP option seemingly has no effect on Linux. Well, let me introduce you to domain search option.

Most of the Linux/Unix based operating systems, whether it is Linux, FreeBSD, or MacOS support arguably a more proper way to define which domain we are referring to when using a single word host name.

To define suffix for domain search, just add option 119:

/ip dhcp-server option
add name="domain-search-option" code=119 value="'^^example^^'"

And of course add this option to DHCP network:

/ip dhcp-server network
set 1 dhcp-option=domain-search-option

PS: And no, you cannot use this instead of domain-name. Windows clients only support domain-name while Linux/Mac only supports domain-search option.