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 2015

Databases Done Fresh

by in CodeSOD on

Wrapped by Aluminum foil and clear tape- other view

Nobody knew how Carl kept his job. Some said he was the boss' boss' nephew, or perhaps knew some dirt on the CEO. Some said he had been threatened with termination before, but his lawyer had advised the company it was cheaper to keep him than to get rid of him. Whatever the case, Carl's eccentricities were legendary.


Mid-Stream Switch

by in CodeSOD on

Submitter James writes: "I'm working on a project that has as one of its components a Microsoft App for Excel 2013. My team lead wrote most of the app up to this point, and I'm adding features. While exploring her code, I ran into this little gem (in JavaScript):"


function ClearData() {
    var spn = document.getElementById("spntest");
    spn.innerHTML = "";
    var def = $.Deferred();

    var arBlankMiddle = new Array();
    var arNull = new Array();
    arNull.push(0);
    spn.innerHTML = "";
    for (var i = 1; i <= 50; i++) {
        arBlankMiddle.push([0]);
    }
    spn.innerHTML = "";
    var arBlank = new Array();
   // arBlank.push(arBlankMiddle);

    arBlank = [[""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""], [""]];
    spn.innerHTML = "";
    $.when(writeData("A1:A50", arBlank), writeData("B1:B50", arBlank), writeData("C1:C50", arBlank), writeData("D1:D50", arBlank), writeData("E1:E50", arBlank), writeData("F1:F50", arBlank), writeData("G1:G50", arBlank), writeData("H1:H50", arBlank), writeData("I1:I50", arBlank), writeData("J1:J50", arBlank), writeData("K1:K50", arBlank), writeData("L1:L50", arBlank), writeData("M1:M50", arBlank), writeData("N1:N50", arBlank)).done(function (res1, res2, res3, res4, res5, res6, res7, res8, res9, res10, res11, res12, res13, res14) {
        spn.innerHTML = "";
        def.resolve();
    });

    //$.when(writeData("A1:A50", arBlank)).done(function (res1) {
    //    def.resolve();
    //});

    return def.promise();
}


Confession: The Coin-Flip Hash

by in CodeSOD on

There are certain problems in computing that you generally shouldn’t tackle unless you’re planning to make it your life’s work. Don’t write your own date handling logic. Don’t write your own encryption. If you do, you’ll probably screw it up, so use something developed by someone who knows what they are doing.

Handling passwords is a subset of encryption, in many ways. Samuel sends this to us as a confession- he hopes to unburden himself of his sins. It’s bad enough that he’s passing passwords in the clear, but he goes a step farther:


The Cleaner

by in CodeSOD on

In software development, there are people who get the unenviable task of being the cleaner. Somebody makes a mess, and the cleaner comes in to take care of it. And that brings us to Tina.

I'm Winston Wolf. I solve problems.

Tina was brought in as a cleaner. There was an application that was a mess , and the powers-that-be wanted it taken care of. Tina took a look, and she noticed that there were a lot of round trips to the database. In fact, after profiling, it almost looked like every query ran at least twice. She saw code following this pattern everywhere:


A Hardware Switch

by in CodeSOD on

Michele S. had recently worked on code for an engine-controlled device. Since the device had physically-moving parts operated by servos, the software had to be careful to not move anything out of bounds because it could actually break a physical piece of equipment.

Michele had written the low-level function which sets the position of a component.


Confession: rect.Contains(point)

by in CodeSOD on

A few years ago, Josip M decided to try his hand at building games using C# and the XNA framework. He started implementing the classic board game, Nine Men’s Morris, but like most side projects, he lost interest and mostly forgot about it…

…until a few months ago, when he started cleaning up his hard drive, and found the code again. Then he remembered why he lost interest and abandoned the project:


All Wrapped Up

by in CodeSOD on

PHP has a lot of warts, and one of those warts is its approach to database interactions. If you want to talk to a MySQL database, every function for doing it is prefixed mysql_, and for say, Postgres, you’d use functions prefixed pg_. On the other hand, it uses an object oriented approach for talking to SQLite3, while Oracle not only has a set of oci_ prefixed functions, but has to add a bunch of important functions that make it just different enough as to be difficult to switch to.

It’s a bit of a mess, is the point, and the result is that a lot of developers will write some wrapper functions to make it easier to write generic code that’s not tied to a specific database engine. That is, presumably, what Scott’s co-worker had in mind when building this library of wrapper functions:


Circle Space

by in CodeSOD on

Are you satisfied with your service today?

Answer a brief survey and enter to win a New* IPAD!!!!**

AFT-v2-CallToAction-Survey


Bonus WTF: Happy Birthday, George Boole

by in CodeSOD on
Today is George Boole's 200th Birthday. We've rerun this classic many times, but I can't think of a better time to reshare it! - Remy

The problem with "logic" is that it makes things out to be nothing but simple dualities. Proponents of logic want us to believe that everything is true or false, black or white, yes or no, paper or plastic, etc. Thankfully, there are some among us, like Mark Harrison's colleague, who are not afraid to stand up to these logic advocates and shout "no, I will not succumb to your false dichotomies!" Today, I think we all should salute those few brave people ...


Shadow Over XML

by in CodeSOD on

Halloween may be over, but it’s always a good time for a horror story.

Like many horror stories, Nick’s starts with a mysterious inheritance from a long-gone predecessor. This tool manages student data, and it needs to pull data from documents in Microsoft Word XML, using C#.