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.

Sep 2013

Fields of Booleans

by in CodeSOD on

A long time ago, we learned the true values of boolean fields. But sometimes, {true, false, file_not_found} isn’t enough. Sometimes, you need more truthiness.

Wayne supports an application that uses its own custom macro-language to define how to generate Word documents. It’s database driven, and many of the documents depend on one notable table with 160 columns.


A Careless Merge

by in CodeSOD on

Some time ago, Marla was asked to take a look at a problematic data load to help figure out exactly what the heck was going wrong with it and report back to management.

The process was supposed to be simple: download an XML file from a web service and then merge the data to the database, updating and inserting as needed.


A Rip in Time

by in CodeSOD on

The Academy graduating class of 2316 gathered in lecture hall. The moment was almost at hand. A moment they had been anticipating for the last four years. Indeed, for many of them, they had been eagerly looking forward to finding out the secret since the time they formed their first differential equation.

As the professor strode to the lectern, a murmur spread through the room. As she placed her notes on the lectern, she straightened her glasses, a hush fell over the crowd.


Indexed Image

by in CodeSOD on

A common task for JavaScript is to do something clever, like display a random image . Those of us old enough to remember the late 90s might recall an era when that was the coolest trick you could build into a web page.

Marcus found this approach to this problem, which is the sort of code that seems just plain ugly at first glance. At second glance, you can’t help but wonder- what were they thinking?


But...It's Reading One Row at a Time!

by in CodeSOD on

We've all written a DAO:

  Connection        con  = ...;
  PreparedStatement ps   = con.prepareStatement("select ...");
  ResultSet         rs   = ps.executeQuery();
  List<YourEntity>  list = new ArrayList<YourEntity>();
  while (rs.next()) {
    // extract individual column values
    YourEntity entity = new YourEntity(...);
    list.add(entity);
  }
  rs.close();
  ps.close();
  con.close();
  return list;

The Key to the City

by in CodeSOD on

In New York City, especially after September 11, they take security seriously. There are numerous police officers patrolling around in high-priority places. There are armed military personnel with assault weapons in-hand in heavily travelled areas. They even make you use electronic key cards to access public bicycles. Multiple levels of picture identification and key card access are required for most major institutions.

Bruce K. found this snippet of code to destroy stuff. There is no form with a password field that calls this method. It's just out there. Unprotected. Waiting for someone to figure out how to call it...


Daylight Failing Time

by in CodeSOD on

A. Dev had just inherited a C# project to finish and maintain. The application was so infested with WTFs that the stench overpowered any working code. The story behind the application was very simple: the customer originally let the CTO's nephew develop the application as a consultant. The nephew then disappeared and upper management got worried. The CTO told management that his plan was to outsource the rest of the development of the application in order to ensure good-quality code.

Once A. Dev discovered blocks like the following, he realized that they had been not assigned with "completing the development of the application" but rather a full rewrite:


Laborious Transitions

by in CodeSOD on

Today is Labor Day in the United States and as a result, many of us have the day off in honor of the working man.

So, if you have the day off - hooray! If not, well, sucks to be you. In either case, please consider the amount of work done by the below JavaScript that Andrew T. sent our way. I hope that if the developer does not have the day off he or she takes the time to work on a better solution.