Recent CodeSOD

Code Snippet Of the Day (CodeSOD) features interesting and usually incorrect code snippets taken from actual production code in a commercial and/or open source software projects.

Nov 2013

A Privacy Monstrosity on Top of a Coding Monstrosity

by in CodeSOD on

I don't think that this will come as much of a surprise, but websites capture the details of your visit.

We here at TDWTF use Google Analytics to see who visits our site, but don't panic - it's not in some creepy, quasi-legal, three (or four) letter government agency way - really we just want to have an idea of who our readers are. Interpreting the collected browser and GeoIP data can take some time, so thank goodness installing the hook to collect site stats is a breeze. Just copy/paste some JavaScript that Google tells you to add into the page you want to monitor, and you're good to go.


Obviously!

by in CodeSOD on

T. L. has a co-worker, Taran, who was obviously the best there was, is, and ever will be. Taran had a penchant for using the word obviously. In almost every sentence. Of every paragraph. Of everything he ever wrote and said. Even in his comments. Most folks tried to ignore it, but after hearing it umpteen-thousand times, it began to wear a bit thin.

To his credit, Taran was a fairly bright person. This made their boss think that the other team members were obviously less than adequate, what with them needing obvious things explained to them all the time. To rectify this, he started replacing the lay-folk with people that Taran felt were obviously more qualified. After about a year, most of the team had been rotated out for people who were obviously better suited to their assigned tasks.


Breaking Delphi

by in CodeSOD on

Delphi, like all languages and tools, has its uses. Some folks use it for good. Others use it for evil. Still others somehow manage to break the language itself.

Oliver T. has been using Delphi 7 for the last decade. In particular, he has a DLL that has worked quite well during that time to produce a variety of MS Word document for his clients to send to their clients. With the advent of new requirements, he imported the Word Type Library for Office 2007, and compilation failed. Puzzled, he clicked "Find Declaration" on break, and saw this:


Best atoi() Implementation Ever

by in CodeSOD on

Most people know atoi() - it's been in C since before it was ANSI C... but here's a little Objective-C nugget from some sample code that was sent to "help" Joseph H. implement a client for a web API.


-(char) atoi:(char) a{
    if (a >= '0' && a <= '9') {
        return a - '0';
    } else if (a >= 'a' && a <= 'z') {
        return a - 'a' + 10;
    } else if (a >= 'A' && a <= 'Z') {
        return a - 'A' + 10;
    } else {
        return 0;
    }
}

The Nephew Way

by in CodeSOD on

Who among us hasn't had to scan a list looking for particular items? Sometimes, as you discover more and more items of interest, you need to explicitly resize the target list to hold them.

From the Bible of MSDN:

Array.Resize
"This method allocates a new array with the specified size, copies elements from the old array to the new one, and then replaces the old array with the new one."

Fourth Time's the Charm

by in CodeSOD on

For those who aren't familiar, the script below is a wrapper to fsck.xfs - a script that is supposed to repair an XFS journaling filesystem upon boot-up of a Linux server.

Out of the box, it does nothing, thus leaving many admins to author their own hacked-together solutions, often in response to an immediate, urgent need. Usually, these type of quick fixes are kept under wraps from the powers that be, or rather, anyone who might be in any way the slightest bit script-literate.


Interesting Year Length Logic

by in CodeSOD on

Glidder’s associate Anastasia, one of the resident DBAs at Big Blue Box, perpetually ran on Anastasia Time. She always seemed to work late, rushing away for coffee or other, White Rabbit-esque errands.

Eventually, Anastasia moved on, and Glidder got promoted to DBA. His first assignment was a year-old bug filed by Accounting: two reports showed different age groups for the same file.