Amazon needs smarter warnings

I had pre-ordered Call of Duty: Black Ops 2 from Amazon a few months ago.  Today, I get an email stating that my credit card that I used to place the order would be expired at the time that the order would be fulfilled.  

It was kind of disturbing, because my credit card that I used expired back in August, but Amazon knew that the Black Ops 2 is released on November 13 and knew when my credit card expires.  Couldn’t they at least notified me back in August?

One good thing that I can say about Amazon is that their customer service is pretty good. They do answer question in a timely manner. 

Bash: Detecting if Script is Sourced

Here is a quick way of detecting if your script is being source as part of a larger script or being executed directly:


#!/bin/sh

[ "$0" = "$(basename $SHELL)" ] && echo "Script is sourced"

And here are some tests:


ralph@goten:bin$ ./sourced.sh
ralph@goten:bin$ bash sourced.sh
ralph@goten:bin$ . sourced.sh
Script is sourced
ralph@goten:bin$ source sourced.sh
Script is sourced
ralph@goten:bin$

MySQL Query Browser in Ubuntu 12.04

I going to outright say it: MySQL Workbench completely sucks. It is a convoluted, complicated, steaming pile of bloated nonsense. It is hard to perform a simple query. Worse, the damn thing keeps crashing. I missed the simplicity of MySQL Query Browser. Yet, Oracle deprecated it a while back and Canonical removed the package in Ubuntu 12.04.

After some searching, I found that Tyler Wagner maintains an APT repository containing MySQL Query Browser ported from Oneiric.

I summarize the installation here:

sudo apt-add-repository 'deb http://www.tolaris.com/apt/ precise main'
wget -q http://www.tolaris.com/apt/tolaris-keyring.gpg -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get install mysql-query-browser

So, a big shout out to Tyler for doing this work!

Edit: You do need to execute sudo apt-get update before install. Thanks, Steve!

libgmp.so missing in Ubuntu 10.04?

When programming Haskell, I usually hack in a GHCi interactive session.  So I was surprise when I tried to make a test executable the other day:

ralph@vegeta:~/src/haskell$ ghc --make Hello
[1 of 1] Compiling Main             ( Hello.hs, Hello.o )
Linking Hello ...
/usr/bin/ld: cannot find -lgmp
collect2: ld returned 1 exit status

libgmp is a library for arbitrary precision arithmetic, which is something Haskell does well. So, I was surprise that I was getting this message. The obvious solution is install the Ubuntu package for libgmp:

ralph@vegeta:~/src/haskell$ sudo apt-get install libgmp3c2
Reading package lists... Done
Building dependency tree       
Reading state information... Done
libgmp3c2 is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 44 not upgraded.

Well that was strange!  So, I searched for libgmp on my system:

ralph@vegeta:~/src/haskell$ find /usr/lib/ -name libgmp*
/usr/lib/ssl/engines/libgmp.so
/usr/lib/libgmp.so.3.5.2
/usr/lib/libgmp.so.3

There is no libgmp.so symlink, so I just created one:

ralph@vegeta:~/src/haskell$ cd /usr/lib 
ralph@vegeta:/usr/lib$ sudo ln -s libgmp.so.3 libgmp.so

Now everything compiles and links:

ralph@vegeta:~/src/haskell$ ghc --make Hello
[1 of 1] Compiling Main             ( Hello.hs, Hello.o )
Linking Hello ...

String Similarity Library

Today, I submitted a new open source project onto Google Code. It is a Java port of a string similarity library that I wrote years ago. The API is a service that calculates a distance or similarity score between two strings. A score of 0.0 means that the two strings are absolutely dissimilar, and 1.0 means that absolutely similar (or equal). Anything in between is a metric on how similar each the two strings are.

Here is a simple example, using the Jaro-Winkler algorithm strategy:


SimilarityStrategy strategy = new JaroWinklerStrategy();
String target = "McDonalds";
String source = "MacMahons";
StringSimilarityService service = new StringSimilarityServiceImpl(strategy);
double score = service.score(source, target); // Score is 0.90

The next step for this project will be documentation and figure out where to host binary releases.

Epic Design Fail

Apple tries very hard to do unique designs, but I think my iPod Shuffle 3rd Generation has a serious flaw. It has no control buttons on the unit itself. The controls are embedded inline with the earbuds. The control has a single button operations where a single-click starts and stops playback, a double-click moves you forward on your playlist, and a triple-click moves you backward on your playlist. While playing a song, a single click-and-hold initiates a Voice-Over feature where the name of your current song is spoken above your song. On a superficial level, it seems so simple and modern. So, why is this necessarily an epic design fail?

Let’s set aside the fact that this Shuffle model requires earbuds with remote functionality. If I lose my earbuds, I would have to buy either a new set of these “special” earbuds, or by an adapter that has the controls. I thought that I can accept this fact, so I was OK with the situation.

Alas, the situation has changed. This morning, I was doing a half-hour cardio program on a treadmill while listening some tunes. After a half-hour, I was working up a good sweat. All of the sudden, the Shuffle starts to tell me the name of my current song and keeps repeating it. Then, it goes into a mode where it starts announcing every song in my current playlist. I thought that the remote control was stuck or something, but it was not it. It got so annoying that I just shut the unit off.

Eventually, I was able to figure out what was going on. Because the control is near the earbuds, the control switch rests at the top of my chest. Since I was doing a lot of cardio, the top of my chest was covered in sweat. The control was swimming in a pool of my sweat and most likely started to short out. I tried different configurations but there is really no good fix. If there was buttons on the unit itself, this would not be an issue.

In most circumstances, we accept a certain level design failures. Our tolerances are very high, especially with electronic devices. The design fail becomes epic when you cannot use said device in normal, practical scenarios. It does not matter if the design looks good, if it is not functional, then its useless.

Lexical Illusion

Occasionally, I have an issue where my grammar is bad. I can’t count how many times this problem when I comment my code. I always thought it was a cut and paste issue or a typo, but how come I could never catch it when proofreading? Then, I realized that my problem may be in my proofreading.

For example, read the following text:

Many readers are not aware that the
the brain will automatically ignore
a second instance of the word “the”
when it starts a new line.

Now read the same text, with the line breaks in different position:

Many readers are not aware that the the
brain will automatically ignore a second
instance of the word “the” when it starts
a new line.

See the problem? This is called a lexical illusion. It is more prominent now than ever because of the use of IM, text messaging, and email. It appears in documents that are written in text editors rather than word processors, because most word processors have grammar correction. When proofreading, people often miss the errors because brains like to process information fast and lazily. When we read from one line to the next, our brain is willing to filter duplicate or redundant words at the beginning of a line. It takes extra concentration to catch the illusion.

Reflecting back, I noticed that it often happens when I shorten or lengthen existing code, rather than creating new comments. So, I have to make extra effort to find when this happens.



Follow

Get every new post delivered to your Inbox.