C++ Static Initialization Order Fiasco Workaround

The C++ Static Initialization Order Fiasco (SIOF) can happen when 2 classes have static initializers and one classes static initializer calls the other class before its static initializer has been executed. The order of static initializer execution is determined by the linker.

SIOF Example

A parser that stores some regexes.

Parser.h

class Parser {
	static std::map<std::string, Regex> regexs;
}

Parser.cpp

using namespace std;
map<string, Regex> Parser::regexs = {
	{"table" , Regex("!\\{\\|[^{]*?\\|\\}!m")},
	{"link" , Regex("!\\[\\[[^\\[\\]]*?\\]\\]!")}
};

Regex.h

class Regex {
	static std::map<char, int> modifiers;
	Regex(string& regex);
}

Regex.cpp

using namespace std;
map<char, int> Regex::modifiers {
	{'i', PCRE_CASELESS},
	{'m', PCRE_MULTILINE}
};

Regex::Regex(string& regex) {
	modifiers['m'] could fail
}

Parser::regexes and Regex::modifers are both globally initialized statics.

Depending on the linker, Parser::regexes could get initialized before Regex::modifers. If that happens, then the reference to modifiers[‘m’] will fail in the Regex constructor that the Parser::regexes initializer calls.
Continue reading C++ Static Initialization Order Fiasco Workaround

AT&T Cordless Phone – Manual Handset Registration

If the automatic new handset registration does not work by putting the handset in the base cradle, a manual registration process is available.

This is for the Accessory Handset model CL80113 for use with the following Base units: CL81113, CL81213, CL81313, CL82113, CL82213, CL82263, CL82313, CL82363, CL82413, CL82463, CL83113, CL83213, CL83263, CL83313, CL83363, CL83413, CL83463.

Press and hold the Handset Locater button in the base cradle until the In Use light is steady red. Release the button. The base display will say Registering…
Press the # key on an unregistered handset to start the registration process. That is it.

Tweaking Ubuntu Unity To Show All Of An Apps Windows

In OS X, clicking on a dock icon shows all open windows for the app. In Ubuntu, clicking on a launcher icon only shows the most recently used open window. This is annoying if you want to copy files between two folders or view all Xpad note windows.
Read on to see how I modified and recompiled Unity to get the OS X like behaviour.
Continue reading Tweaking Ubuntu Unity To Show All Of An Apps Windows

X Windows – Window Swallowing

X Windows “window swallowing” is the process of program 1 capturing the main window of program 2 to display it inside of program 1’s main window. For example, Firefox using an external program to display a PDF in a tab. Firefox’s built-in javascript PDF viewer leaves a lot to be desired. Slow rendering or no rendering at all, memory hog, with the download button not working when it doesn’t render.

The following description is derived from my experience getting MozPlugger to work in Firefox to display PDF files using Evince.
Continue reading X Windows – Window Swallowing

Abolish 10-Point Rating Scales

People are frequently asked to rate something on a scale of 1 to 10. Let’s take the pain Numeric Rating Scale (NRS-11) as an example. 1 means low pain (bump), 10 means extreme pain (migraine). Now what would warrant a 2 or a 9? A person simply can’t categorize pain into 10 different levels. The  NRS-11 groups the 10 pain levels into 3 categories (Mild, Moderate, Severe). Why not just use a 3-point scale or the category names?

I postulate that most 10-point scales can be replaced with 5-point scales with no loss of information. For analysis purposes, most responses are going to be grouped into 3 – 5 categories or averaged.

Conversion of existing 10-point data values to 5-point data values is easy.

  1. Add 1 to the 10-point value
  2. Divide the result by 2
  3. Drop the fractional part

Example for value 9:

  1. 9 + 1 = 10
  2. 10 / 2 = 5

Example for value 10:

  1. 10 + 1 = 11
  2. 11 / 2 = 5.5
  3. Drop the .5 = 5

Adventures in the AT&T U-verse®

My DSL internet was becoming painfully slow, so I decided to upgrade from 768K to 3Meg download speed. DSL was not available to me at 3Meg because of my distance from the exchange. I compared Uverse to Xfinity (Comcast) internet on price and chose Uverse. The order process was simple and it looked like the installation would be the same as the DSL installation. ie. Install phone line filters and plug the new modem in after the activation time.

The activation time rolled around and I plugged the modem in and went through AT&Ts configuration process. Everything went smoothly and I had higher speed internet. Sometime later I checked a phone for a dial tone, and there was none. Read on the follies that ensued.
Continue reading Adventures in the AT&T U-verse®

Mysqldump to TSV Conversion Using Flex

First a little background information. I wanted to import an 8 Gig Wikipedia table dump for a project that I was working on. The table was too big to import all of the records on my Linode server. I only needed certain rows and columns, so I tried parsing the dump file in PHP. This worked, but it was much too slow. So then I went looking for text processor programs. This turned up awk, grep, lex and sed. awk, grep and sed are all line based processors. These would not work because the dump file has multiple database records per line. That left lex and its successor flex.
Continue reading Mysqldump to TSV Conversion Using Flex