BOM Away

I find the Visual Studio the best development tool there is and I always find myself missing it whenever I have to work in some other tool (damn you Java!). However, there is one annoying “feature” that bugged me through all .NET versions.

Whenever Visual Studio decides file needs Unicode encoding, it does so by converting it to the UTF-8 which I personally find quite a good decision. What I hate is that file also gets “spoiled” by adding BOM (byte order mark). Now my every UTF-8 file has three nonsense bytes as a prefix (0xEF,0xBB,0xBF).

Although Unicode does not recommend usage of this marking and most programs do right by omitting it, Microsoft decided to use it back in the dark ages of Visual Studio .NET (and Unicode Notepad). At that time this might have been good decision considering how bad everybody treated Unicode. But in the year 2014 it is feature that survived for no good reason (not completely dissimilar to using a Ctrl+Z as an end-of-file character).

If you perform your work in a mixed OS environment (god forbid you have some Unix/Linux laying around) it gets quite annoying dealing with those simple bytes. While partial blame for this is on encoding-challenged Linux tools, truth is that nobody really needs that BOM if we assume all input files are already UTF-8 (which is fair assumption, I believe).

Source control makes this problem visible to the extreme. On multiple occasions I would accidentally check-in a file with no change other than the pesky BOM. As I am a fan of an overkill reactions I decided to stop this issue once and for all. It was the time to build the extension for the Mercurial, my source control of choice.

In order to use this extension just copy killbom.py to a location of your choice and, in the project configuration or global configuration file, add it in the extensions section:

[extensions]
killbom = C:/path/to/killbom.py

From that moment everything you commit will have it’s BOM stripped and it will get converted to the UTF-8. Be it annoying UTF-8 with BOM, just unusual UTF-16BE, or any other Unicode encoding. Everything will get an UTF-8 face-lift.

Of course, you can check how new files are doing using hg checkbom, modify existing files by using hg killbom --all or just check on state of your repository with hg checkbom --all.

Those just wanting to know whether files are proper UTF-8 but cringe on the thought of the modifying extension are fine too. You can force extension to only report offending files or only to check for certain offences, e.g. to make it verify-only and sensitive to only big-endian encoding you would add following in the configuration:

[killbom]
action = verify
extensions = utf-8 utf-16be utf-32be

Full source for the extension is available at GitHub.

PS: There is also a Git version of this hook.

Getting a Visa

Three years ago I applied for US L1 visa. After getting all company paperwork in order, I had to fill DS-160 form before I could even come to the embassy.

Application process threw me down the memory lane since it required annoying precision when it came to education and previous work engagements. I usually know a year when most of important events in my life took place, for quite a few I even know a month. But this was probably first time in my life that anybody asked me about exact start date of my high school and college.

Then questionare took a stupid turn. I am sure that other country’s questionnaires are probably as dumb but I was surprised that anyone would include “Do you seek to engage in espionage, sabotage, export control violations, or any other illegal activity while in the United States?” as a question on their form. Maybe you could catch world’s-most-stupid-criminal this way but even that is probably farfetched idea. I would enjoy seeing statistics on this question. How many people ever answered yes?

Questions following that one were no better. I had to read most of them twice just to be sure I was not hallucinating and it took a super-human strength to answer them “no”. For example, one that asked about my involvement in genocide just begged for a description of my crimes toward pig population (hams, sausages, bacon; you name it, I did it). But alas I was a coward.

One explanation that I’ve heard about the purpose of these questions was that they allow legal system to stick Visa Application Fraud in addition to other convictions if you do naughty things you promised not to do. While this has a ring of truth to it, I personally find it silly at best.

After filling that again for my wife and for my kids I was ready for an interview process in the embassy…

This post is intended to be a light read and hopefully draw a few smiles here or there. Don’t take anything you read too seriously. It is intentionally overly generalized, takes into account only my personal experience, information might be stale, and I won’t be above lying for the comedy effect. Be warned!

Curious USA

I am a fairly new to States, just counting my third year as a resident. I have only ever lived in the Virginia and the Washington state and traveled through another fifteen or so. My experience is not only incomplete but heavily skewed toward north. Even worse, it is limited only to small towns with big IT companies around.

Historically I come from quite a small town within even a smaller country (Osijek, Croatia). I have traveled decent amount but almost always within Europe. In other words I have really limited experience of other countries and their customs.

Maybe it is all those factors together or maybe it is my confused person, but I found living in the USA full of interesting peculiarities and customs. Since most of my wonder happened at the very beginning of my life in USA I caught myself forgetting some details and even outright understanding a thing or two.

Since I will be on blog hiatus for a next few weeks as far as technical content goes, I might as well write some overly generalized easy going opinions. I plan to keep it light and hopefully readable.

Death of the Desktop Mapping

Illustration

After a long time Microsoft is discontinuing its MapPoint and Streets and Trips offerings. On one side I didn’t expect this move - I even recommended using MapPoint to a friend just a few weeks ago. But I cannot say it was really a surprise. Considering its overlap with the Bing maps it probably had a good stretch.

I cannot say anything about Streets and Trips since I really haven’t used them although I know few people who swear by it. MapPoint is completely different story and a program I will miss a lot. Well, not really the program - I will miss its API.

MapPoint as a mapping program was quite humble. Not too bad albeit not really any better than all other offerings. I must confess that I rarely used it to search anything - for that web-based maps are God-given. But I did adore option of using MapPoint as cheap local Bing/Google maps alternative. It had it all: search for coordinates, conversion from coordinates to address, map image… It was a perfect tool for quick one-time mapping work. You buy it and do whatever you want to it on your local computer (or server) and, unless you need newer maps, there is no additional expense.

Its replacement, Bing maps, might be better but it does come at the cost. Licensing for Bing maps is ridiculously difficult and costly. For just a basic mapping application you are looking at steady monthly expense that can easily get into thousands of dollars. Compared to one-time cost of $400 for MapPoint, price hike is definitely noticeable.

Yes, Bing maps has a free offering for small project doing under 125,000 transactions but only if you are not using GPS functionality and you plan to create a Windows Store App. As soon as you utter Desktop usage, you are looking at the death by a thousand cuts.

Big business will probably live with this change just fine. They haven’t used MapPoint to start with and cost of Bing maps license is cheap enough for them. Small independent software developers will be affected the most with this change and there is no full replacement for MapPoint.

While there are some alternatives on the web, MapPoint was an unique flower that worked just fine without an internet connection. It will be missed.

Compacting VHD of a Linux Host

At home I use Linux exclusively in virtual machines under Windows. Call me spoiled but I still use Windows as my main OS.

Since I have multiple machines quite often I use dynamic disks (Microsoft VHD format) so I can fit them all on my notebook. With usage some of them simply grow to large and a compact is needed.

In order for compact to work, we need to zero-out all free disk space. While dd is a popular choice, I personally prefer zerofree. As always, first step is to install it:

sudo apt-get install zerofree
...

Again, there are ways to do it on-line but I prefer to play it safe. Upon system reboot, just pressand you’ll be greeted by Grub’s menu. Go to Recovery and select root. Once single user prompt is shown, everything is ready for zerofree:

zerofree /dev/sda1

Once command has completed (and it’ll take a while) shut machine down.

As Linux virtual machine is powered off we are ready for Windows part. Everything here is done in the diskpart:

DISKPART> **select vdisk file "C:\VMs\Mint\Mint.vhd"**
DiskPart successfully selected the virtual disk file.

DISKPART> **attach vdisk readonly**
DiskPart successfully attached the virtual disk file.

DISKPART> **compact vdisk**
DiskPart successfully compacted the virtual disk file.

After this is done, your virtual disk should be much smaller than before.