Wednesday, May 31, 2017

Cute Compilation Of Clueless Cats

Cats are usually pretty smart and inventive, but that’s not what this video is about. This one is all about the other end of that spectrum…

The post Cute Compilation Of Clueless Cats appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

The Bravest Baby Elephant You’ve Ever Seen

This baby elephant has months of courage worked up and it all comes out in one silly but heroic moment. He’s been waiting for this moment all his little life!

The post The Bravest Baby Elephant You’ve Ever Seen appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

The Relationship Simulator Bed

Can’t find a partner, just out of a relationship, or just longing for some company? This is the bed for you!

The post The Relationship Simulator Bed appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

A True Crowd Pleaser

Huge crowds everywhere, but there is one to rule them all.

The post A True Crowd Pleaser appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

Happy Dog Is Aggressive

Stop laughing at me or I’ll smack your face!

The post Happy Dog Is Aggressive appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

Dot-Matrix Ragnarok

Fresh out of college and out of money, Johan K. started work at Midgard Manufacturing as a junior developer. His supervisor Ragna made it clear: he would only be responsible for coding error handlers.

“Our plant equipment is several decades old,” she said, “and we have to rely on the manufacturer-provided documentation for adequate coverage. To be honest, none of the senior developers want to bother. So instead of bothering one of them, you’ll be doing it.”

Johan didn’t have a problem with this. He knew he’d have to earn his chops at Midgard. But after he was given the stack of manuals that towered over his monitor, he wondered just how long it would take.

Pride Goeth Before a Fall

One month later, he had made it through a hundred pages of the first manual. Ragna checked in periodically, more interested in how complete his code was than how quickly he was getting through his list of error conditions.

the painting 'Thor and the Midgard Serpent'

The manual he was working on was for a steel press. Vintage 1985, the steel press’s firmware - using Microsoft Xenix - relied on the flakiest of communication protocols: passing information via temp file. Every night around 2AM, the press would go down for maintenance. A shell script, written by Johan, would read data from the temp file the steel press had created, enter it into a SQL database, then delete the file from disk.

Half the lines of code in Johan’s script were if/then blocks, one for each condition listed in the manual.

# if the temp file was created successfully
...
# if the local file was written successfully
...
# if the temp file was successfully removed from the firmware
...

That last one got Johan thinking. When has a rm command ever failed silently? Would he really need to check that the file was removed? The conditions for that to happen seemed as impossible as, well, the end of the world. However, as it was listed as an error condition in the manual, he had to put something in.

echo "Ragnarok has come, the Midgard serpent awakes" > /dev/lpr

In this unlikely event, an error would be spit out to the old dot matrix printer in the office, so someone would see it. For good measure, he also had an email sent to all@midgardmanufacturing.se, as well as sending an SMS text. Johan thought that should take care of it.

Hour of the Wolf

Several months later, Johan had finished coding the conditions in the first manual. His script had been tested and deployed, and it now monitored the steel press. Things had gone well for a few weeks.

Then, at 3 AM, his phone started buzzing.

The screen filled text messages. Each read the same: Ragnarok has come, the Midgard serpent awakes. His inbox overflowed with a thousand emails, each with the same text as the alert. At first he thought it was a prank by one of the senior developers.

Then he remembered.

He rushed to the office, half-awake. As he entered the unlit office, he heard something tearing and squealing from the other side of the room. After stumbling over some office chairs, he found the source: the dot matrix printer. It had chewed through an entire box of feed paper.

Ragnarok has come, the Midgard serpent awakes
Ragnarok has come, the Midgard serpent awakes
Ragnarok has come, the Midgard serpent awakes
...

Not Worthy of Valhalla

Ragna was surprisingly forgiving of Johan. Johan wrote out a proper error message, which would be emailed to only himself and a few other staff, so that his script could fail gracefully.

The senior developers, though, weren’t so kind. His cubicle walls were papered with sheets of line feed, glued so they couldn’t be pulled off, the apocalyptic words smeared in ribbon ink. Someone impersonating Loki from the Marvel movies would randomly message him from an unlisted number. He even found a plush snake wrapped around his computer monitor one morning.

Johan thought it was a good lesson in hubris. He knew it could have been worse: at least it hadn’t gone out to all of Midgard’s customers

[Advertisement] Infrastructure as Code built from the start with first-class Windows functionality and an intuitive, visual user interface. Download Otter today!


To read the full article, please visit The Daily WTF

Tuesday, May 30, 2017

Haddaway – What Is Love (Animal Cover)

“Baby, don’t hurt me!” This animal cover is pretty dope, but it definitely isn’t easy on the ears…

The post Haddaway – What Is Love (Animal Cover) appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

Is Killer Bee Honey Dangerous?!

They are named killer bees for a reason, right? Their honey is delicious though, so how dangerous is it to actually get some of that lovely gold stuff?

The post Is Killer Bee Honey Dangerous?! appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

Reporter Goes HAM Inside Disney Ride

This reporter is keen on checking out Disney’s Guardians of the Galaxy ride, and boy, is he in for a ride! If you don’t like grown men screaming like a little baby, don’t watch.

The post Reporter Goes HAM Inside Disney Ride appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

Gotta Be Productive

See, I deserve the salary you’re paying me!

The post Gotta Be Productive appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

I’ll Be Civil If You’ll Stay Away From My Food

Sure, we can hold hands, but don’t touch my food pal.

The post I’ll Be Civil If You’ll Stay Away From My Food appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

CodeSOD: Flubbed Buzz

Interviewing developers always poses a challenge. You can’t rate their skills at writing code without seeing them write code, and most of the code they’ve written probably belongs to someone else. Writing anything non-trivial takes time, which both the candidate and the interviewer may not be willing to spend. Even then, it’s not always representative. And let’s not even talk about whiteboard programming.

Douglas’s company makes a compromise- they’ll give a time-boxed programming challenge. A developer is given two hours, access to the Internet, and a moderately complex problem. A smart developer might make some mistakes on the trickier parts of the problems, which is great, because it doesn’t fail them- it shows how they think. One candidate, Steve, never quite got that far.

At one point in the process, the code needs to determine if two dates are within 90 days of each other. Even in Java, this is a trivial task, worthy of one line of code. Possibly two, if you want to be super clear:

long days = TimeUnit.MILLISECONDS.toDays(d1.getTime() - d2.getTime());

Steve did this:

public Map<TimeUnit,Long> computeDiff(Date date1, Date date2) {
    long diffInMillies = date2.getTime() - date1.getTime();
    List<TimeUnit> units = new ArrayList<TimeUnit>(EnumSet.allOf(TimeUnit.class));
    Collections.reverse(units);
    Map<TimeUnit,Long> result = new LinkedHashMap<TimeUnit,Long>();
    long milliesRest = diffInMillies;
    for ( TimeUnit unit : units ) {
        long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS);
        long diffInMilliesForUnit = unit.toMillis(diff);
        milliesRest = milliesRest - diffInMilliesForUnit;
        result.put(unit,diff);
    }
    return result;
}

Now, we see the use of the same objects and methods- getTime and TimeUnit, but obviously Steve didn’t know anything about them. In fact, I suspect that Steve found this code in a tutorial on Java date times, saw that it calculated the difference in every possible unit, and just said, “Yeah, that sounds good.”

If that were the case, that would also mean Steve was a terrible researcher, because this was where he spent most of those two hours. For further proof that Steve hadn’t a clue, we can also look at how he called this method. Keep in mind the signature of this method- it’s a Map<TimeUnit,Long>, leveraging Java’s generics system.

Map m = computeDiff(inputRecIn.date,inputRec.date);
Object o = m.get(TimeUnit.DAYS);
long l = Long.parseLong((String)o);

It might be stored that way, but Steve decided to catch the number of days as an Object, and then cast that to a string so that he could parse it back into a Long. Everything about this is wrong.

This is an example of something I think is a true: coding challenges won’t help you find good candidates during your interview process, but it’ll definitely identify the bad ones.

[Advertisement] Atalasoft’s imaging SDKs come with APIs & pre-built controls for web viewing, browser scanning, annotating, & OCR/barcode capture. Try it for 30 days with included support.


To read the full article, please visit The Daily WTF

Monday, May 29, 2017

Inside World’s Most Expensive Boomerang

A true boomerang fanatic isn’t satisfied with a boomerang that just returns. There’s a lot to it really, so let’s have a educational look inside the most expensive boomerang worldwide, shall we?

The post Inside World’s Most Expensive Boomerang appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

Fidget Spinners: The Hype Is Over

Fidget spinners, fidget spinners everywhere. The hype is real… was real. It’s over boys, wrap it up.

The post Fidget Spinners: The Hype Is Over appeared first on Viral Viral Videos.



To read the full article, please visit Viral Viral Videos

Playground For Suicidal Children

Some playgrounds just ain’t for happy kids, but for the ones with a dark soul.

To read the full article, please visit Viral Viral Videos

Don’t Fuck With Merkel

You can try all you want buddy, but Angela Merkel will not budge.

To read the full article, please visit Viral Viral Videos

10 Movie Mistakes That Even Digital Effects Couldn’t Save

CGI and special effects is cool and all, but you still have to put in some effort to get the footage you actually want. These filmmakers didn’t get the memo.

To read the full article, please visit Viral Viral Videos

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!


To read the full article, please visit The Daily WTF

Sunday, May 28, 2017

How Did You Get Here?

You’re browsing the internet for funny or educational videos, so therefor you are alive. This video explains exactly how you got here. Wherever you may be right now.

To read the full article, please visit Viral Viral Videos

7 Signs That Cats Are Scientists

This video shows compelling evidence that cats are scientists. I’m just waiting for the cat-Einstein to emerge to explain to us why cats can always land on their feet.

To read the full article, please visit Viral Viral Videos

Impressive Progress Pic

In just two weeks you can make a lot of progress, such as losing your bloody watch.

To read the full article, please visit Viral Viral Videos

When The Peer Pressure Gets To You

Slippery stairs are slippery, but these friends have great fun tumbling down!

To read the full article, please visit Viral Viral Videos

Insane Real Life Trickshots

The guys from Dude Perfect are insanely popular on YouTube, and this video immediately shows why. They perform some very cool real life trick shots! And there is a panda bear doing gym exercises in […]

To read the full article, please visit Viral Viral Videos

Baby Daughter Is Not Impressed With Daddy’s Clean Shave

This dad is curious to find out what his daughter thinks of his new look. Without a beard he looks about twenty years younger, which doesn’t really impress the baby girl.

To read the full article, please visit Viral Viral Videos

Saturday, May 27, 2017

The Best Truck Fails Of This Month

Truck drivers are either very skilled or just downright notorious on the road. They both had their fair share of epic truck fails this month!

To read the full article, please visit Viral Viral Videos

Sleeping

Busy day ahead, with countless hours of sleeping.

To read the full article, please visit Viral Viral Videos

The Secret Of Trump And The Pope

Not sure what to make of this look of the Pope into the soul of the Donald.

To read the full article, please visit Viral Viral Videos

This Is The Best Car Dealer Commercial Ever (Because Of The Dog)

Are dogs good salesmen? I don’t think so, but the voice-over here makes this dog sound like a tough but fair pro. Go get yourself a nice deal on a car, before the government shuts […]

To read the full article, please visit Viral Viral Videos

Friday, May 26, 2017

How To Make People Understand You In Austria

Did you actually know German is quite different from Austro-Bavarian? In this video you’ll learn how to speak the latter fluently.

To read the full article, please visit Viral Viral Videos

Why Apple Pie Isn’t American

As American as apple pie you say? Think again friendo, this video tells quite a different story.

To read the full article, please visit Viral Viral Videos

Too Scientific For You

When you’re just not on the same level as a scientist near you.

To read the full article, please visit Viral Viral Videos

Chemistry Experiment Looks Awesome

Chemistry experiments make for amazing visuals, and this one is no exception. Will food coloring dye liquid nitrogen?

To read the full article, please visit Viral Viral Videos

Relationship Goals

Not sure how this relationship is recovering from this…

To read the full article, please visit Viral Viral Videos

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!


To read the full article, please visit The Daily WTF

Thursday, May 25, 2017

Professional Chef Cooks Unconvential Meal Using Just A Wooden Table

Take away a professional chef’s kitchen supplies and he’s going to need some crazy ingenious skills to pull off a decent meal. This particular chef has a really hard time coping…

To read the full article, please visit Viral Viral Videos

Dog Is Co-Host In Special News Edition

Ever get that feeling a dog understands what we’re thinking or feeling? Well then why wouldn’t we allow dogs to talk to us as well? Here is an example of a dog playing a formidable […]

To read the full article, please visit Viral Viral Videos

Detective Barbie

Find your inner Sherlock Holmes and you’ll know what the fuck is going on in no time.

To read the full article, please visit Viral Viral Videos

The Two Most Unlikely Animal Friends Ever

A Bengal cat and an otter best friends? Yeah right. I was as skeptical as you are right now, but had to change my mind after watching this.

To read the full article, please visit Viral Viral Videos

Walking The Stairs Into Eternity

Just keep walking boy, doesn’t matter if you go up or down.

To read the full article, please visit Viral Viral Videos

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. 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!


To read the full article, please visit The Daily WTF

Wednesday, May 24, 2017

Fidget Spinners And Dogs Are A No Go

Fidget spinners are the latest hype, and if you see our videos regularly you already know this (or if you use an internet connection). But this dog isn’t all that excited about yet another crazy human […]

To read the full article, please visit Viral Viral Videos

These Alcohol Life Hacks Will Change Your Life

Alcohol is strange stuff — it either boosts your party to slurring levels or it kills all bacteria you didn’t know you didn’t want. Anyway, this little video shows some amazing life hacks involving alcohol.

To read the full article, please visit Viral Viral Videos

You Know They Read It All

The most silence ones are the ones you can’t lose sight of.

To read the full article, please visit Viral Viral Videos

50 Amazing Facts To Blow Your Mind

The world truly is a remarkable place, and these guys put in great effort to make it graspable for us. Here is a list of some of the most amazing facts in life.

To read the full article, please visit Viral Viral Videos

Not Sure If The Waitress Will Receive A Tip After This

Creditcard roulette taken to a whole new level…

To read the full article, please visit Viral Viral Videos

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!


To read the full article, please visit The Daily WTF

Tuesday, May 23, 2017

Melting A Padlock With A Hair Dryer

A hair dryer can reach unfathomable temperatures, but did you know you could melt a padlock with it? Looks pretty cool if you ask me.

To read the full article, please visit Viral Viral Videos

I’m Black, Not Poor

Collegehumor is back at it, and their assumptions about a black man are way too real.

To read the full article, please visit Viral Viral Videos

Protective Dog Is Protective

This dog sure shows who’s boss.

To read the full article, please visit Viral Viral Videos

I Asked For The Pizza

The pizza is something I actually wanted in the first place, the rest you can keep.

To read the full article, please visit Viral Viral Videos

This Cyclops Goat Is Freaky As Hell

Goats are usually very cute, but this one is kind of… special. Not exactly cute, as far as I’m concerned.

To read the full article, please visit Viral Viral Videos

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!


To read the full article, please visit The Daily WTF

Monday, May 22, 2017

Cheating

Cheating: to act dishonestly or unfairly in order to gain an advantage, especially in a game or examination.

To read the full article, please visit Viral Viral Videos

Sea Lion Wants To Be On Top Of The Animal Kingdom

It doesn’t come recommended to turn your back to a ‘caged’ animal, and this little girl is about to find out why…

To read the full article, please visit Viral Viral Videos

Grated Cheese With Style

Grated cheese has never tasted this good, I promise.

To read the full article, please visit Viral Viral Videos

What A Time To Be Alive

Bacon that isn’t really bacon, but it’s healthier and is actually a vegetable. Sign me up?!

To read the full article, please visit Viral Viral Videos

This Swimming Pool Works Like A Fata Morgana

You set up your freshly bought swimming pool, and next thing you know your in the middle of some ocean somewhere. What. The. Hell?!

To read the full article, please visit Viral Viral Videos

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!


To read the full article, please visit The Daily WTF

Sunday, May 21, 2017

Gordon Ramsay Teaches Students How To Get Really Furious

Gordon Ramsay is as explosive as a balloon in the claws of your gnarly cat, we all know that. Naturally he wants other to thrive in this department too, so he drops a few cursing […]

To read the full article, please visit Viral Viral Videos

Reacting To Old Performances

These guys react to performances we’ve put away somewhere far away in our memories, just because they are so embarrassing. Thanks for reminding us, boys…

To read the full article, please visit Viral Viral Videos

Run Over By A Disabled Granny

I don’t care about you, just let me through please.

To read the full article, please visit Viral Viral Videos

When Your Life Is Falling Apart

When your life is falling apart, and Mercury isn’t even in retrograde.

To read the full article, please visit Viral Viral Videos

How Every Twenty One Pilots Song Is Written

The secret behind every song Twenty One Pilots ever wrote is now revealed, this is how where they base all of them songs on.

To read the full article, please visit Viral Viral Videos

Saturday, May 20, 2017

A Very Honest Trailer For Aliens

The movie Aliens couldn’t be ignored any longer, and the latest installment of Honest Trailers is well-deserved.

To read the full article, please visit Viral Viral Videos

How To Be Sad

It’s perfectly natural to be sad every once in a while, but what’s actually the best way to get the most out of your sadness? Sounds weird, I know, but it can help you tremendously.

To read the full article, please visit Viral Viral Videos

The First To Finish The Test

Depending on your age, being the first to finish a test can mean a totally different thing.

To read the full article, please visit Viral Viral Videos

How To Put Your Pants On

Don’t you wish you had friends like this?

To read the full article, please visit Viral Viral Videos

Test Your International Languages’ Accents On Siri And Google Home

Our robot friends Siri, Echo and Google Home don’t always recognize when we try to speak another language, so these guys put the machines to one final big test.

To read the full article, please visit Viral Viral Videos

Friday, May 19, 2017

A Dog’s Dreams

Ever see your dog shiver in its dreams? This video might provide an answer of what’s its dreaming of.

To read the full article, please visit Viral Viral Videos

Famous YouTubers React To History Of The World

I don’t know why you would display your lack of history knowledge publicly on YouTube, but at least these uneducated people learn a thing or two.

To read the full article, please visit Viral Viral Videos

You Can Leave Early If You Wa-

When your boss is in a good mood, you can’t waste any time to seize the opportunity and abandon your work immediately.

To read the full article, please visit Viral Viral Videos

The 10 Worst Jobs In History Ever

You think a lot of jobs suck these days? Think again after watching this video–there’s a lot more shitty stuff you could be doing as your bread and butter.

To read the full article, please visit Viral Viral Videos

Did I Forget Something?

That moment when you’re still getting used to actually having a child.

To read the full article, please visit Viral Viral Videos

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!


To read the full article, please visit The Daily WTF

Thursday, May 18, 2017

How To Escape The Cops

Sure, you’ll have to be fast and be in decent shape to outrun the police, but a good camouflage will get you a long way as well.

To read the full article, please visit Viral Viral Videos

Dog Has A Hard Time Staying Awake In Front Of The TV

Watching tv isn’t any fun when you’re not in charge of the remote, you might as well squeeze in a little nap.

To read the full article, please visit Viral Viral Videos

Bees Are Dying

We all try our best to make the world a better place, in our own unique way.

To read the full article, please visit Viral Viral Videos

Ultimate Goalkeeping

Everyone needs a keeper like this one in their life.

To read the full article, please visit Viral Viral Videos

Cute Kid Waiting For The Beat To Drop

Nothing ever beats cute kids listening to music, and Maddie here is no exception. She very patiently waits for the beat to drop…

To read the full article, please visit Viral Viral Videos

The Smell-O-Vision

Ron used to work for a company which built “smell-o-visions”. These were customized systems running small form factor Windows PCs that operated smell pumps and fans using USB relays timed to a video to give a so-called “4D Experience.” Their product was gimmicky, and thus absolutely loved by marketing groups.

One such marketing group, whose client was a branch of the military, worked with them to create a gimmick to help with recruiting. A smell-o-vision was installed on a trailer and towed around the country, used to convince teenagers to join the service by making them smell fresh-squeezed orange juice while watching a seizure-inducing video with guns. The trailer was staffed by grunts, and these guys cycled through so frequently that they received little or no training on the system.

A vintage ad for a smell-o-vision film called 'Scent of Mystery'

“Hey Ron,” Sam, his boss, told him one day. “The recruiter is having a ton of trouble with their system and I need you to go on-site and take a look.”

Going on-site was the only option. The recruiter’s system was not on the Internet so remote diagnosis was impossible. And so he soon found himself cooking in the hot desert sun on a base in the Southwest, looking at a small LCD screen on a 1U pull-out tray accessible through an access panel in the trailer.

“This is what it always does,” said the grunt assigned to work with him. “It always says it’s corrupted and the 4D stuff doesn’t work. Rebooting doesn’t fix it.”

Ron looked at the screen as the outdated Windows XP booted up and watched it flash an error stating “Windows was not properly shut down” before beginning a long filesystem scan and repair and then using System Restore to return to an earlier checkpoint. A checkpoint created before the presentation software was installed…

Ron shook his head and started the Help Desk 101 questions. “Do you shut down the system when you’re packing up?”

“Oh, we just turn the generator off,” the grunt answered. “That shuts everything down.”

Ron mentally facepalmed. “You need to properly shut down the system before killing power or this will happen again.” He went inside the trailer and showed them a power button on the control panel. The button was just wired to the power switch header on the PC’s motherboard and acted exactly like any computer case’s power button. Pressing it briefly tells the operating system to shut itself down. “Just press this button and it will shut itself down in a minute or two.”

“Okay, that’s simple enough,” the grunt said.

Then Ron spent the day re-installing and configuring their system by downloading all the software over his phone’s mobile hotspot to his laptop, then transferring it via USB stick. Eventually he had it back up and running. He made sure to stress how important it was to shut down the system, and on a whim left them a DVD with all the software so he could talk someone through the process over the phone if it happened again.

He returned home. And two weeks later, it happened again. He spent three days on the phone talking to a different grunt and walking him through restoring the system. Again he emphasized the importance of shutting down the system with the power button before killing power, but this grunt explained he did that. Ron was confused, but finished the support call.

Just a few days later, they called again. He talked to yet another grunt, asked them how shutdown was handled, and he explained he pressed the button until it shut down. His boss decided to send Ron on-site again, and he repaired the system. It was much faster this time since he had a DVD with everything he needed on it, only taking most of a morning. When he was done, he tested the power button. It shut down the system properly.

“Show me how you get ready for a presentation,” he asked. “From setup once you’re on-site, to shutdown.”

The pair of grunts assigned to him–two more he’d never worked with before–spent an hour walking through the process. When they got to the end, Ron reminded him to shut down the system.

And the grunt did so. By pressing and holding the power button for about five seconds. Which killed power to the PC without properly shutting down the operating system.

He mentally facepalmed again. “No, you can’t press and hold. Just tap the button. It will eventually shut down.” He was getting fast at restoring the system and spent that afternoon correcting it all. This time he took a System Restore snapshot once everything was in place, and taped a hand-written note on the control panel saying “DO NOT HOLD THIS BUTTON TO TURN OFF THE MACHINE. DO NOT SHUT OFF THE GENERATOR WITHOUT FIRST TURNING THE SYSTEM OFF PROPERLY.”

He returned home. And a couple weeks later, they called again. He was unable to fix it over the phone and was sent on-site yet again. This time the filesystem was too corrupted to repair and he had to set everything up from scratch. Upon querying the new grunts he discovered they ignored the note and were still holding the power button to kill the system.

This continued for a couple more months. The client refused to shut down the system properly and was constantly causing severe filesystem corruption or even killing hard disks. Each time the client called, getting angrier and angrier. “It says there is no OS! I thought you fixed this bug!!” Each time the problems were caused by operator error.

During a meeting with his boss Sam, Ron explained all the issues and how much of his time it was taking, and while brainstorming a solution Ron pitched a new idea. “What if we modify the custom power button? Alter it to only send a pulse, instead of a constant closed signal, so it’s impossible to hold it down?”

“Figure it out and do it,” Sam ordered. “These guys are idiots and won’t do things right. They’re killing us on support time, we have to fix this or fire the client. How hard is it to shut this thing down properly?”

So, being a software engineer, Ron devised a clever solution based on an Arduino that sampled the power button’s state and sent pulses to the motherboard’s power button header. It passed all his testing and he went on-site to install it. And finally the support calls ceased completely. This unit was the only one that received the update since none of their other clients had issues with operator error.

With the issue solved, Ron decided to take some badly-needed vacation to attend a family reunion in North Carolina and tried to stay off the grid. Meanwhile, Sam took a demo unit to an expo in London so visitors could smell what it was like to go skiiing.

During his vacation, Ron received a phone call from Sam in the middle of the night. Being on vacation and trying to stay offline, he ignored it. But the phone rang in quick succession several more times and he finally answered.

“Ron! Sorry to wake you, but our demo unit quit working and I need your help!”

Ron grunted. “It’s one AM here…”

“I know but I need to get this back up before the conference starts this morning!”

“Okay,” he said with a sigh. “What’s it doing?”

Sam proceeded to describe a series of error screens over the phone. It stated that “Windows was not shut down properly,” followed by a long filesystem scan, followed by an error that critical system files were corrupted and Windows could not boot.

Ron facepalmed for real this time.

[Advertisement] Universal Package Manager - ProGet easily integrates with your favorite Continuous Integration and Build Tools, acting as the central hub to all your essential components. Learn more today!


To read the full article, please visit The Daily WTF

Wednesday, May 17, 2017

Even With Gordon Ramsey On Board This Can Get Messed Up

Gordon Ramsey isn’t a ‘succes guaranteed’-stamp per se, as this head chef demonstrates. How the hell do you ruin the re-opening of your restaurant in such an epic way?!

To read the full article, please visit Viral Viral Videos

Life Hacks That Have Worked For Over A Century

Yeah, some of the life hacks people come up with nowadays are pretty cool, but the best ones have a long history. Watch and learn!

To read the full article, please visit Viral Viral Videos

Outside Me vs Inside Me

Looking tough on the outside, crying uncontrollably on the inside.

To read the full article, please visit Viral Viral Videos

When You’re Partying But Not Really

This woman has serious skills–fake boozing, but still dedicated enough to bite the lemon.

To read the full article, please visit Viral Viral Videos

$500 Lottery Ticket Challenge

Ever wonder what would happen if you’d just buy a ton of lottery tickets? You’d expect to win at least a little something, right?!

To read the full article, please visit Viral Viral Videos

Bring Your Own Code: Your Private Foursome

Last week, I shared some code that, while imperfect, wasn’t that bad. I then issued a challenge: make it worse. Or better, if you really want. As many comments noted: one case covers only the first iteration of the loop, and one case only covers the last iteration of the loop. You could easily pull those out of the loop, and not need a for-case at all. Others noticed that this pattern looked like odd slices out of an identity matrix.

With that in mind, we got a few numpy, Matlab, or MatrixUtils based solutions generally were the “best” solutions to the problem: generate an identity matrix and take slices out of it. This is reasonable and fine. It makes perfect sense. Let’s see if we can avoid making sense.

I’ll start with Abner Qian’s Ruby solution.

module MagicalArrayGenerator
  def magical_array_generator
    main_array = []
    self.times do |i|
      inner_array = []
      self.times do |j|
        i == j ? inner_array << 1 : inner_array << 0
      end
      main_array << inner_array
    end

    e_1 = []
    n_1 = []
    e_n = []
    n_n = []

    self.times do |i|
      e_1 << [main_array[i].first]
      e_n << [main_array[i].last]
      n_1 << main_array[i][1..-1]
      n_n << main_array[i][0..-2]
    end

    [e_1, n_1, e_n, n_n]
  end
end

class Integer
  include MagicalArrayGenerator
end

e_1, n_1, e_n, n_n = 4.magical_array_generator

At it’s core, this is simply an implementation that generates an identity matrix and slices it up. The actual implementation, however, is a pitch-perfect parody of Ruby development: “There’s no problem that can’t be solved by monkey-patching a method into a built-in type”. That’s what happens here- the include statment injects this method into the build-in Integer data-type, meaning you can call 4.magical_array_generator and get your arrays. Abner also points out that Ruby uses 62-bit integers, just in case you want some 4611686018427387903 by 4611686018427387904 arrays.

Several folks looked at the idea of taking slices, and said, “Gee, I bet you I could do this with pointers in C”. My personal favorite in that category would have to be Ron P’s approach.

#include <stdio.h>

int main( int argc, char **argv)
{
    int *e_1 = 0;
    int *e_n = 0;
    int **n_1 = 0;
    int **n_n = 0;
    int *fugly = 0;
    int i,j;

    if ( argc != 2 ) return 1;

    int n = atoi(argv[1]);

    fugly = calloc( n*(n+1),sizeof(int));

    n_1 = calloc(n,sizeof(int *));
    n_n = calloc(n,sizeof(int *));

    for ( i = 0, j=n; i < n; ++i, j+=n+1 )
    {
        fugly[j]=1;
        n_1[i]=fugly+n*i;
        n_n[i]=n_1[i]+n;
    }
    e_1 = fugly+n;
    e_n = fugly+1;

    printf( "e_1\n" );
    for ( i = 0; i < n; ++i ) {
      printf( "  %d\n", e_1[i]);
    }

    printf( "\ne_n\n" );
    for ( i = 0; i < n; ++i ) {
      printf( "  %d\n", e_n[i]);
    }

    printf( "\nn_1\n" );
    for ( i = 0; i < n; ++i ) {
      printf( "  " );
      for ( j = 0; j < n-1; ++j ) {
        printf("%d ", n_1[i][j]);
      }
      printf("\n" );
    }

    printf( "\nn_n\n" );
    for ( i = 0; i < n; ++i ) {
      printf( "  " );
      for ( j = 0; j < n-1; ++j ) {
        printf("%d ", n_n[i][j]);
      }
      printf("\n" );
    }

    return 0;
}

Now, Martin Scolding gets bonus points for two reasons: first, he uses one of the worst languages in the world (not designed as an esolang), and second, this language doesn’t technically support multi-dimensional arrays. I speak, of course, of PL/SQL. Note the use of substrings to figure out what number to put in each position of the array.

DECLARE

    TYPE data_t  IS TABLE OF INTEGER INDEX BY PLS_INTEGER;
    TYPE array_t IS TABLE OF data_t  INDEX BY PLS_INTEGER;

   e_1 array_t;
   e_n array_t;
   n_1 array_t;
   n_n array_t;

   l_array_size INTEGER := 0;

PROCEDURE gen_arrays(n INTEGER, p_e_1 IN OUT array_t, p_e_n IN OUT array_t, p_n_1 IN OUT array_t, p_n_n IN OUT array_t)
--' Generate 4 Arrays of the form (example n=4)
--
--    '       | 1 |         | 0 0 0 |
--    ' e_1 = | 0 |   n_1 = | 1 0 0 |
--    '       | 0 |         | 0 1 0 |
--    '       | 0 |         | 0 0 1 |
--    '
--    '       | 0 |         | 1 0 0 |
--    ' e_n = | 0 |   n_n = | 0 1 0 |
--    '       | 0 |         | 0 0 1 |
--    '       | 1 |         | 0 0 0 |
--
IS
    l_n_string LONG := RPAD('1',n+1,'0');
BEGIN

    For i in 1..n Loop
        p_e_1(i)(1)   := TO_NUMBER(SUBSTR(l_n_string, 1, 1));
        p_e_n(i)(1)   := TO_NUMBER(SUBSTR(l_n_string, n, 1));
        For j in 1..n-1 Loop
            p_n_1(i)(j) := TO_NUMBER(SUBSTR(l_n_string, j+1, 1));
            p_n_n(i)(j) := TO_NUMBER(SUBSTR(l_n_string, j,   1));
        End Loop;
        l_n_string := LPAD(SUBSTR(l_n_string, 1, n), n+1, '0');
    End Loop;

END;

BEGIN
    l_array_size := &inp_array;

    gen_arrays(l_array_size, e_1, e_n, n_1, n_n);

    --==========================================================================
    -- DISPLAY RESULTS
    --==========================================================================
     DBMS_OUTPUT.PUT_LINE('e_1 = ');
     For i in 1..l_array_size Loop
        DBMS_OUTPUT.PUT_LINE('         | ' || e_1(i)(1) || ' |');
     End Loop;
     DBMS_OUTPUT.PUT_LINE('--------------------------------------------------');
     DBMS_OUTPUT.PUT_LINE('e_n = ');
     For i in 1..l_array_size Loop
        DBMS_OUTPUT.PUT_LINE('         | ' || e_n(i)(1) || ' |');
     End Loop;
     DBMS_OUTPUT.PUT_LINE('--------------------------------------------------');
     DBMS_OUTPUT.PUT_LINE('n_1 = ');
     For i in 1..l_array_size Loop
        DBMS_OUTPUT.PUT('         | ');
        For j in 1..l_array_size-1 Loop
            DBMS_OUTPUT.PUT(n_1(i)(j) || ' ');
        End Loop;
        DBMS_OUTPUT.PUT('|');
        DBMS_OUTPUT.NEW_LINE;
     End Loop;
     DBMS_OUTPUT.PUT_LINE('--------------------------------------------------');
     DBMS_OUTPUT.PUT_LINE('n_n = ');
     For i in 1..l_array_size Loop
        DBMS_OUTPUT.PUT('         | ');
        For j in 1..l_array_size-1 Loop
            DBMS_OUTPUT.PUT(n_n(i)(j) || ' ');
        End Loop;
        DBMS_OUTPUT.PUT('|');
        DBMS_OUTPUT.NEW_LINE;
     End Loop;
     DBMS_OUTPUT.PUT_LINE('--------------------------------------------------');
    --==========================================================================
    --
    --==========================================================================

END;
/

Finally, though, I have to give a little space to Airdrik. While the code may contain some errors, it is in Visual Basic, as was the original solution, and it knows that recursion makes everything better.

Public Sub GenerateIdentitySquare(ByVal n As Long, ByRef sq As Variant, ByVal i As Long, ByVal j As Long)
        Select Case j
        Case i:
                sq(i, j) = #1
                If i < n Then
                        GenerateIdentitySquare(n, sq, i, j+1)
                End If
        Case n:
                sq(i, j) = #0
                GenerateIdentitySquare(n, sq, i+1, 1)
        Case Else:
                sq(i, j) = #0
                GenerateIdentitySquare(n, sq, i, j+1)
        End Select
End Sub

Public Sub CopyRowValues(ByVal n As Long, ByRef sq As Variant, ByRef e As Variant, ByVal sq_i As Long, ByVal e_i As Long, ByVal j As Long)
        e(e_i, j) = sq(sq_i, j)
        if j < n Then
                CopyRowValues(n, sq, e, sq_i, e_i, j+1)
        End If
End Sub

Public Sub CopyRows(ByVal n As Long, ByRef sq As Variant, ByRef e_1 As Variant, ByRef e_n As Variant, ByRef n_1 As Variant, ByRef n_n As Variant, ByVal i As Long)
        Select Case i
        Case 1:
                CopyRowValues(n, sq, e_1, i, 1, 1)
                CopyRowValues(n, sq, n_n, i, i, 1)
                CopyRows(n, sq, e_1, e_n, n_1, n_n, i+1)
        Case n:
                CopyRowValues(n, sq, n_1, i, i-1, 1)
                CopyRowValues(n, sq, n_n, i, i, 1)
        Case Else:
                CopyRowValues(n, sq, n_1, i, i-1, 1)
                CopyRowValues(n, sq, e_n, i, 1, 1)
                CopyRows(n, sq, e_1, e_n, n_1, n_n, i+1)
        End Select
End Sub

Public Sub DefineProjectionArrays(ByVal n As Long, ByRef e_1 As Variant, ByRef e_n As Variant, ByRef n_1 As Variant, ByRef n_n As Variant)
    Dim i As Long, j As Long

    ' Generate 4 Arrays of the form (example n=4)
    '       | 1 |         | 0 0 0 |
    ' e_1 = | 0 |   n_1 = | 1 0 0 |
    '       | 0 |         | 0 1 0 |
    '       | 0 |         | 0 0 1 |
    '
    '       | 0 |         | 1 0 0 |
    ' e_n = | 0 |   n_n = | 0 1 0 |
    '       | 0 |         | 0 0 1 |
    '       | 1 |         | 0 0 0 |

        Dim sq(n, n) As Variant
        GenerateIdentitySquare(n, sq, 1, 1)

    ReDim e_1(n, 1)
    ReDim e_n(n, 1)
    ReDim n_1(n, n - 1)
    ReDim n_n(n, n - 1)

        CopyRows(n, sq, e_1, e_n, n_1, n_n, 1)
End Sub

Functional programming is always the best approach, obviously.

[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!


To read the full article, please visit The Daily WTF