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.

Feb 2014

Split Second Load Balancing

by in CodeSOD on

In case you're not familiar with the concept of a load balancer, the purpose of having one is to spread requests across multiple, identical servers associated with it so as to give the requester the best possible experience. As an added bonus, you can take a box out of load, patch/fix/update it, and throw it back into the fray as the other servers, if you're doing things correctly, can temporarily handle the additional load.

Bottom line - load balancers are cool ...but it can be complicated and/or expensive to implement what is often a hardware based solution. So what can you do? Well, for starters, you could code your own.


The Best Shopping System EVER

by in CodeSOD on

Dani was asked to replace a shopping system (that had been developed by a Highly Paid Consultant) with a better one. Dani expected to find high quality, well organized code that would be easy to modify. Undoubtedly, there would be some database housing all of the data.

Dani searched the code for the database connection to know where to connect and found this in a file named: shop$db.asp:


Christmas is Cancelled

by in CodeSOD on

Murray’s company needed an easy way to tell whether or not a given date was a banking holiday or not. Someone wrote this function for MySQL .

CREATE FUNCTION `IS_HOLIDAY`(a_date datetime) RETURNS char(5) CHARSET utf8 COLLATE utf8_bin
   READS SQL DATA
   DETERMINISTIC
BEGIN

   DECLARE is_holiday char(5);

     select (CASE WHEN (DAYOFWEEK(a_date) = 1 OR DAYOFWEEK(a_date) = 7)

                      THEN 'Yes' ELSE 'No' END) INTO is_holiday;

   RETURN is_holiday;

 END

TC119a()

by in CodeSOD on

Matt recently made some changes to a “legacy” application. Unlike most legacy applications, this one was well instrumented with unit tests. Matt’s changes failed some of those unit tests, so he went to look and see what he needed to change to update the tests.


Total Recall: The Directory's Cut

by in CodeSOD on

By day, Curtis was a PHP developer for a small ISV. The people he worked with were enjoyable and the work itself was decently challenging. All in all, it was nothing special.

However, in the evening, Curtis changed. Well, not 'changed', so much as charged. His clients, that is. You see, Curtis moonlighted for a number of small, developer-challenged companies, helping them build and maintain their Internet presence.


Date Formatting Done Right

by in CodeSOD on

Dates are complicated things. There are many different ways of storing them, and even more ways to present them. Converting them from one format to another always seems to challenge certain individuals. For this reason, the designers of most modern language libraries have taken it as part of their task to provide date handling utilities to deal with the nitty gritty of this task.

Most people appreciate the help and gladly use the built-in tools.


The Midnight Cowboy Coder

by in CodeSOD on

The ball had just dropped, and Eric was taking the stairs to the fifteenth floor two at a time. Initech's New Year's party was in full swing, but it Eric wasn't simply in a hurry to join the festivities. He'd been watching the support queue all night, and at midnight the new monitoring program lit up like Times Square. The program was supposed to be simple: The new security cameras Initech had installed in their headquarters dumped video files in a folder every hour, and the powers-that-be wanted to make sure they were working without being obliged to keep an obssessive eye on the filesystem. Eric's colleague Ted was put in charge of solving the problem before the party, and he'd dumped his solution onto a production server in the nick of time. All had been well... for the first hour.

Eric burst through the balcony doors, out of breath. Around him, fellow Initechnicians were pouring champagne and trying to remember the inscrutable lyrics to Auld Lang Syne. Ted had attached himself to a gaggle of salespeople in sharp blue suits, one of whom was handing around cigars. Before Ted could lay hands on a lighter, Eric clasped his shoulder.