News





CodeSOD: Classic WTF: Time for a tblHoliday;
It's a holiday in the US today, which tracking the dates on which holidays fall is always a complicated, fraught proposition. Let's dig back into the archives for a classic article which can help us celebrate this holiday. This article originally ran waaaaaay back in 2006. --Remy

For most, the New Year is great occasion: not only is it kicked off with a big bash, but it's so easy to trick yourself in feeling like you have a "clean slate", setting all sorts of great goals and resolutions, and just all-around feeling good. But for some programmers, like Dave Sussman, it's not so joyous of an occasion; each change of the year is like a mini-Y2K. These programmers are the guys who get to maintain systems with comments like ...

  //I doubt this script will be in use two years
  //from now, so this should be fine for now ...

When 2006 hit, Dave got to learn about a database table named tblHoliday. It's hard to say what's more off: the fact that the original programmer had the hindsight to backdate the holidays to 1975, but just couldn't comprehend that the system might last more than four years, or the technique used to store and retrieve whether or not a specific date is a holiday (or, apparently, weekend) ...

SELECT * FROM tblHoliday
--

+---------+--------------------------------------------------------------------------+
| intYear | blnaryHoliday                                                            |
+---------+--------------------------------------------------------------------------+
|   ...   | ...                                                                      |
+---------+--------------------------------------------------------------------------+
|         | NYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNN  |
|         | YYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNY  |
|  1995   | YYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYY  |
|         | YYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYY  |
|         | YYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYY  |
|         | YNNYYYYYNN                                                               |
+---------+--------------------------------------------------------------------------+
|         | YYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNY  |
|         | YYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYY  |
|         | YYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYY  |
|  1996   | YYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYY  |
|         | YNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYYNNYYYYY  |
|         | NNYYYYYNNYY                                                              |
+---------+--------------------------------------------------------------------------+
|   ...   | ...                                                                      |
+---------+--------------------------------------------------------------------------+
[Advertisement] Manage IT infrastructure as code across all environments with Puppet. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your free trial today!


Error'd: The Developer Test;

"Apparently, if AMEX's site knows that you're a developer, it will present a REGEX challenge before allowing you to reset your password," Jim wrote.

 

Stuart writes, "Wait, I have a network drive!? Cool! I wonder how much space is available? Oh..."

 

"To you and me, $0.00375 isn't much, but to Western Digital, collecting the exact amount due is a pretty big deal," writes Jonathan.

 

"The page can say whatever it wants, but, well, here I am anyway," wrote Mark

 

Andy J. writes, "I don't know what I have just agreed to but at least the paper is now listed as one of my own publications."

 

"Um, excuse me, but it's not a 'hashtag'," Steve B. wrote, "It's an octothorpe! Or a number sign, or a pig pen..."

 

[Advertisement] Release! is a light card game about software and the people who make it. Play with 2-5 people, or up to 10 with two copies - only $9.95 shipped!


Icon on Fire;

Tim joined a company that provided a SaaS solution for tracking attendance and grades in schools. The job was mostly minor updates to a ColdFusion application, although there was an active project to replace it with something more modern. Tim felt like half of his hiring was based on him knowing when to throw out buzzwords like SPA or REST or Reactive Programming.

The fire emoji, as an image.

“It’s not the first time,” Karmen explained. She’d been with the company for some time. “When I joined, they had just upgraded to ColdFusion from a VBA hack on Microsoft Access. Crazy days, back then, when the whole ‘selling service, not software’ thing was new. Sometimes, I think I was hired because I knew the right buzzwords.”

Ostensibly, Karmen and Tim were meant to be focused on the new version of the application, but the ColdFusion version was so old and so poorly maintained that they spent 75% of their time in firefighting mode. The rest of the team had neatly adapted to the culture of “just put out the fire, and don’t worry about code quality, there’ll be a new fire tomorrow”, which of course only created more fires to put out.

One day, near the end of the month, the webmaster inbox had an alert message from their webhost.

This is to alert you that your account is nearing the data transfer threshold. Your account has transferred 995GB of data during this billing period, with a total account limit of 1,000GB of data allowed. At your pricing tier, overages will be charged at $10/GB.

“Wow, what?” Tim was pretty shocked. He knew they had a goodly number of schools, and were tracking many thousands of students, but there was no way that the application should be serving up 1TB of data in a month. 95% of the application just was text, and while they did have photographs of every student, those photos were only 9kb after resizing and compressing.

“Oh, yeah,” Karmen said. “I heard about this a few years back. We had to upgrade to the higher plan with our host. Guess they’ll probably do that again.”

“I mean, don’t you think this is wrong?”

“Probably, sure, but… y’know. Not my circus, not my monkeys.” Karmen shrugged, and got back to work on a different fire.

Tim fired up the browser debugger and loaded a page in test that was sure to have a lot of pictures, and was definitely the heaviest page. With 50 student images displayed, the payload of the HTML and assets was a whopping 452KB. That was the HTML and assets… except for one file.

The favicon.ico weighed in at 307kb. Apparently, at some point in the past, someone had decided that it needed to look good at any size. Since the ICO format lets you have multiple resolutions of the image stored at different bit-depths and resolutions, they had made sure to include everything up to 256x256 at 32-bits per color. Ironically, the source image had probably been a much smaller resolution, because the 256x256 version showed clear signs of having been upscaled.

Compounding the problem, since once-upon-a-time there had been issues with browsers serving up cached versions of pages, their web server had been configured to disable caching for every file served, guaranteeing that the favicon would be transferred for every request.

307kb wasn’t a lot of data, but it was certainly a lot for a favicon. Even at a massive 256x256 resolution, given the design of their icon, he could fit it into a PNG that was bytes in size- and every decent browser supported it. A quick check of their traffic showed that they still had a good number of users on old versions of IE that couldn’t support anything but ICO files, so he cut the massive resolutions out of the ICO file, and whipped up a little CFML that would serve the ICO to those users, and everyone else would get the PNG.

That cut their traffic nearly in half, but Tim didn’t get much chance to celebrate- there was another fire to put out.

[Advertisement] Otter allows you to easily create and configure 1,000's of servers, all while maintaining ease-of-use, and granular visibility down to a single server. Find out more and download today!


CodeSOD: Lucee Execution;

I Love Lucy title

Recently, at my dayjob, I had a burning need to understand how scheduled tasks work. You see, we've recently switched from Adobe Coldfusion to Lucee, and I was shaky on how Adobe did things before, so I wanted a deeper understanding of how the code I was working on would be executed. For the uninitiated, Lucee is an open-source reimplementation of Cold Fusion. And that's not the WTF.

It's open source, I thought to myself. I'll just take a look at the code.

I had one problem. Then I looked at the code. Now I have two problems ... and a headache:


private long calculateNextExecution(long now, boolean notNow) {
	long nowTime=util.getMilliSecondsInDay(timeZone,now);
	long nowDate=now-nowTime;
		
		
	// when second or date intervall switch to current date
	if(startDate<nowDate && (cIntervall==Calendar.SECOND || cIntervall==Calendar.DATE))
		startDate=nowDate;
		
	// init calendar
	Calendar calendar = JREDateTimeUtil.getThreadCalendar(timeZone);
	calendar.setTimeInMillis(startDate+startTime);
		
	long time;
	while(true) {
		time=getMilliSecondsInDay(calendar);
		if(now<=calendar.getTimeInMillis() && time>=startTime) {
			// this is used because when cames back sometme to early
			if(notNow && (calendar.getTimeInMillis()-now)<1000);
			else if(intervall==ScheduleTaskImpl.INTERVAL_EVEREY && time>endTime)
				now=nowDate+DAY;
			else 
				break;
		}
		calendar.add(cIntervall, amount);
	}
	return calendar.getTimeInMillis();
}

"So okay, if now is before or starting at—hang on, what's calendar again?" I found myself muttering aloud. "Okay, if now is before or equal to the start date plus the start time, and time—which, if I understand that method correctly, is the elapsed time in the current day—is after or equal to the start time ... when is that true exactly? You know what would be nice? Some #%#@$%@ Javadoc!"

This is only one representative method, and yet, there's just so much here. Why an if statement that does nothing, terminating in an easily-overlooked semicolon? Why the misspelling of EVERY? Or "Intervall?" Why are the programmers allergic to spaces? Why can't they name variables worth anything? Do I even really want to know how this works anymore?

If you want to witness the madness for yourself, may I remind you: this code is open source. Have at ye. According to the copyright statement at the top, this code was inherited from the Railo project, so if you're in Switzerland, please be sure to send your hate mail to the right address.

[Advertisement] Manage IT infrastructure as code across all environments with Puppet. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your free trial today!


Take the Bus;

Rachel started working as a web developer for the local bus company. The job made her feel young, since the buses, the IT infrastructure, and most of their back-office code was older than she was. The bus fare-boxes were cash only, and while you could buy a monthly pass, it was just a little cardboard slip that you showed the driver. Their accounting system ran on a mainframe, their garage management software was a 16-bit DOS application. Email ran on an Exchange 5.5 server.

Translink-B8017

In charge of all of the computing systems, from the web to DOS, was Virgil, the IT director. Virgil had been hired back when the accounting mainframe was installed, and had nestled into his IT director position like a tick. The bus company, like many such companies in the US, was ostensibly a private company, but chartered and subsidized by the city. This created a system which had all the worst parts of private-sector and public-sector employment merged together, and Virgil was the master of that system.

Rachel getting hired on was one of his rare “losses”, and he wasn’t shy about telling her so.

“I’ve been doing the web page for years,” Virgil said. “It has a hit counter, so you can see how many hits it actually gets- maybe 1 or 2 a week. But management says we need to have someone dedicated to the website.” He grumbled. “Your salary is coming out of my budget, you know.”

That website was a FrontPage 2000 site, and the hit-counter was broken in any browser that didn’t have ActiveX enabled. Rachel easily proved that there was far more traffic than claimed, not that there was a lot. And why should there be? You couldn’t buy a monthly pass online, so the only feature was the ability to download PDFs of the hand-schedules.

With no support, Rachel did her best to push things forward. She redesigned the site to be responsive. She convinced the guy who maintained their bus routes (in a pile of Excel spreadsheets) to give her regular exports of the data, so she could put the schedules online in a usable fashion. Virgil constantly grumbled about wasting money on a website nobody used, but as she made improvements, more people started using it.

Then it was election season. The incumbent mayor had been complaining about the poor service the bus company was offering, the lack of routes, the costs, the schedules. His answer was, “cut their funding”. Management started talking about belt-tightening, Virgil started dropping hints that Rachel was on the chopping block, and she took the hint and started getting resumes out.

A miracle occurred. The incumbent mayor’s campaign went off the rails. He got caught siphoning money from the city to pay for private trips. A few local cops mentioned that they’d been called in to cover-up the mayor’s frequent DUIs. His re-election campaign’s finances show strange discrepancies, and money had come in that couldn’t be tied back to a legitimate contribution. He tried to get a newly built stadium named after himself, which wasn’t illegal, but was in poor taste and was the final straw. He dropped out of the election, paving the way for “Mayor Fred” to take over.

Mayor Fred was a cool Mayor. He wanted to put in bike lanes. He wanted to be called “Mayor Fred”. He wanted to make it easier for food trucks to operate in the city. And while he shared his predecessor’s complaints about the poor service from the bus company, he had a different solution, which he revealed while taking a tour of the bus company’s offices.

“I’m working right now to secure federal grants, private sector funding, to fund a modernization project,” Mayor Fred said, grinning from behind a lectern. “Did you know we’re paying more to keep our old buses on the road for five years than it would cost to buy new buses?” And thus, Mayor Fred made promises. Promises about new buses, promises about top-flight consultants helping them plan better routes, promises about online functionality.

Promises that made Virgil grumble and whine. Promises that the mayor… actually kept.

New buses started to hit the streets. They had GPS and a radio communication system that gave them up-to-the-second location reporting. Rachel got put in charge of putting that data on the web, with a public API, and tying it to their schedules. A group of consultants swung through to help, and when the dust settled, Rachel’s title was suddenly “senior web developer” and she was in charge of a team of 6 people, integrating new functionality to the website.

Virgil made his opinion on this subject clear to her: “You are eating into my budget!”

“Isn’t your budget way larger?” Rachel asked.

“Yes, but there’s so much more to spend it on! We’re a bus company, we should be focused on getting people moving, not giving them pretty websites with maps that tell them where the buses are! And now there’s that new FlashCard project!”

FlashCard was a big project that didn’t involve Rachel very much. Instead of cash fares and cardboard passes, they were going to get an RFID system. You could fill your card at one of the many kiosks around the city, or even online. “Online” of course, put it in Rachel’s domain, but it was mostly a packaged product. Virgil, of all people, had taken over the install and configuration, Rachel just customized the stylesheet so that it looked vaguely like their main site.

Rachel wasn’t only an employee of the bus company, she was also a customer. She was one of the first in line to get a FlashCard. For a few weeks, it was the height of convenience. The stop she usually needed had a kiosk, she just waved her card at the farebox and paid. And then, one day, when her card was mostly empty and she wasn’t anywhere near a kiosk, she decided to try filling her card online.

Thank you for your purchase. Your transaction will be processed within 72 hours.

That was a puzzle. The kiosks completed the transaction instantly. Why on Earth would a website take 3 days to do the same thing? Rachel became more annoyed when she realized she didn’t have enough on her card to catch the bus, and she needed to trudge a few blocks out of her way to refill the card. That’s when it started raining. And then she missed her bus, and had to wait 30 minutes for the next one. Which is when the rain escalated to a downpour. Which made the next bus 20 minutes late.

Wet, cold, and angry, Rachel resolved to figure out what the heck was going on. When she confronted Virgil about it, he said, “That’s just how it works. I’ve got somebody working full time on keeping that system running, and that’s the best they can do.”

Somebody working full time? “Who? What? Do you need help? I’ve done ecommerce before, I can-”

“Oh no, you’ve already got your little website thing,” Virgil said. “I’m not going to let you try and stage a coup over this.”

With an invitation like that, Rachel decided to figure out what was going on. It wasn’t hard to get into the administration features of the FlashCard website. From there, it was easy to see the status of the ecommerce plugin for processing transactions: “Not installed”. In fact, there was no sign at all that the system could even process transactions at all.

The only hint that Rachel caught was the configuration of the log files. They were getting dumped to /dev/lp1. A printer. Next came a game of hide-and-seek- the server running the FlashCard software wasn’t in their tiny data-center, which meant she had to infer its location based on which routers were between her and it. It took a few days of poking around their offices, but she eventually found it in the basement, in an office.

In that office was one man with coke-bottle glasses, an antique continuous feed printer, a red document shredder, and a FlashCard kiosk running in diagnostic mode. “Um… can I help you?” the man asked.

“Maybe? I’m trying to track down how we’re processing credit card transactions for the FlashCard system?”

The printer coughed to life, spilling out a new line. “Well, you’re just in time then. Here’s the process.” He adjusted his glasses and peered at the output from the printer:

TRANSACTION CONFIRMED: f6ba779d22d5;4012888888881881;$25.00

The man then kicked his rolly-chair over to the kiosk. The first number was the FlashCard the transaction was for, the second was the credit card number, and the third was the amount. He punched those into the kiosk’s keypad, and then hit enter.

“When it gets busy, I get real backed up,” he confessed. “But it’s quiet right now.”

Rachel tracked down Virgil, and demanded to know what he thought he was doing.

“What? It’s not like anybody wants to use a website to buy things,” Virgil said. “And if we bought the ecommerce module, the vendor would have charged us $2,000/mo, on top of an additional transaction fee. This is cheaper, and I barely have enough room in my budget as it is!”

[Advertisement] Otter enables DevOps best practices by providing a visual, dynamic, and intuitive UI that shows, at-a-glance, the configuration state of all your servers. Find out more and download today!


CodeSOD: Hard Reboot;

Every day in IT, each one of us walks the fine line between "brilliant" and "appalling." We come across things that make our jaws drop, and we're not sure whether we're amazed or horrified or both. Here's a PHP sample that Brett P. was lucky—or unlucky—enough to discover:

This comes from circa 2001, back when there were MySQL stability issues on a server. If in response to the end user's request the script couldn't connect to the session database, PHP would shell out to a VB6 .EXE that rebooted the machine. Ta dum! No more connection error!


if (strpos(mysql_error(), "connect to MySQL server on 'localhost' (10061)")) {
    // The MySQL Error: Can't connect to MySQL server on 'localhost' (10061)
    // means that the MySQL database is not running. This is caused by a failed
    // reboot. Since MySQL is not running, it is safe to execute a hard boot.
    echo "Currently rebooting the server. Please try again in two minutes.";
    flush();
    exec("c:\Progra~1\progs\hardboot.exe");
}

That comment block full of flimsy assumptions and unwarranted confidence makes my insides knot up with dread. I'm leaning toward "appalling" on this one. Anyone else?

[Advertisement] Manage IT infrastructure as code across all environments with Puppet. Puppet Enterprise now offers more control and insight, with role-based access control, activity logging and all-new Puppet Apps. Start your free trial today!


Error'd: The Maybe Compiler;

"Maybe it it compiled...maybe it didn't. I guess that I have to find out myself from here on out," wrote, Y. Diomidov.

 

Ken W. writes, "Does buying the 4 year warranty mean Amazon will replace any steaks that don't last?"

 

"I *KNEW* that I should have gone for the blue one!" Connor C. wrote.

 

Adam writes, "Today was a bad day to switch from Chrome."

 

"Looks like my HP printer had been eating paper behind my back," wrote Peter D.

 

Jeanne P. writes, "Ironically, we came across this while looking for colleges that offer Computer Science or Software Engineering majors. The pie charts show acceptance rates."

 

[Advertisement] Universal Package Manager – store all your Maven, NuGet, Chocolatey, npm, Bower, TFS, TeamCity, Jenkins packages in one central location. Learn more today!