How to traverse a binary tree

Here, traverse away!

function traverseTree($rootNode) {
    if($rootNode->left != null)
    if($rootNode->right != null)
    echo $rootNode->value;

Now and only now your interviewers will be impressed with your ability to code! YAY!. Never mind the decade of hard work that you’ve obviously put into learning how to code or the fact that every employer you’ve ever left offered a handsome counter-offer to keep you working there, no. Now it’s clear that you can code because you can traverse any binary tree that you come across. Your career at Binary Tree Traversal Experts LLC can finally commence…

One comment so far, add another

Sorting an array of numbers

Ok, so how would you sort an array of numbers?

In PHP:  sort($myArray);

In Javascript:  myArray.sort();

Simple right?  In my nearly 10 years in software development I have never once had the need to write a sorting algorithm.  Yet for some stupid reason, I am invariably asked to write a sorting algorithm on a whiteboard at just about every interview I’ve ever had.  Well, Here you go..  Study this useless piece of code so you can land your next job.  Have fun!

function bubble_sort($arr) {
    $size = count($arr);
    for ($i=0; $i<$size; $i++) {
        for ($j=0; $j<$size-1-$i; $j++) {
            if ($arr[$j+1] < $arr[$j]) {
                $tmp = $arr[$j];
                $arr[$j] = $arr[$j+1];
                $arr[$j+1] = $tmp; 
    return $arr;


Leave the first comment

Why Obama-care is not the problem

I just finished a 24 hour shift (with a small break for dinner) and i believe i have stumbled upon the reason why Obamacare is not the real problem with the current health care system, but before i continue i need to vent.

I work for a company which makes a software product for doctors/hospitals which among other things allows the doctors to write prescriptions electronically as opposed to scribbling them down on a dirty napkin as they have been doing for generations. The reason we even have a product and a market for this product is essentially because of obamacare (and also the 2010 Digital Health Records Act or some such thing which is technically not obamacare but is generally lumped in when describing obamacare).

The reason I say this is that from my experience most doctors actually don’t want to change anything. They are perfectly happy with sending their prescriptions in a rolled up piece of paper tied to a homing pigeon even though from any sane persons perspective it’s obvious that it is much more secure to send these prescriptions via the internet (because they can be encrypted and identities can be verified etc, etc etc…) with the old prescription system you could make 10 copies of your original prescription, go get them all filled and Bob’s your uncle

Another great thing about the new system is that now patients will be able to know how much their insurance will actually cover for any drug they might be prescribed and it will also show them lists of alternative drugs that may be cheaper. And I’m not just talking about the doctor or office person saying that the drug is covered and then you finding out 6 months later that it actually isn’t and now have a big bill to pay (which is pretty much what happens now). You will now know for a fact exactly how much will be covered before you ever spend dime one. This coverage information is what we refer to in the industry as a Drug Formulary Check and it’s a pretty tricky thing.

So why then would you suppose that doctors would not want to change to this clearly better system?  Doctor’s are smart right? what do they know that we don’t?  Well perhaps it’s because they are familiar with the current system and they know how god-awfully complicated it is. Perhaps they are afraid that the new system will add even more layers of complexity.  Perhaps it’s because they spent 12 years learning how to be a doctor and the rest of their lives learning how to navigate this ridicules system and now that they think they understand it, here we go and change everything.   perhaps?

Anyway, we just finished 6 months of hell in rebuilding our electronic prescription system and getting it certified by the government and today is the day that this new system gets rolled out and I’m the guy doing it. This new version of the system includes the Drug Formulary Check that i mentioned earlier.

Up until this point, however, we’ve been building our system using test data. Fake patients and fake drug formulary information that we can use to build and test the system, but yesterday at about 5pm I started the download of the real formulary information. Keep in mind we have a blazing fast internet connection when i say this.. The download took over 12 hours to complete! When all was said and done we had over 40 gigabytes of information!

What is all this info ask?

Well, lets see, this 40 gigs of info consists of every insurance carriers coverage info for every plan they have for every drug that is made, and relatively speaking there aren’t that many different drugs out there. What this means is that the system of determining how much you will pay is immensely complex and keep in mind this is not the obamacare system, this is the current non-obamacare system.  All we are doing is putting it in digital format.

Imagine how difficult it must be to wade through the mountains of paper our current system uses to represent this data, it’s a friggen miracle that anyone ever gets coverage for anything. Lets put some perspective on this:

Current Insurance Coverage Formulary info = 40 gigabytes

A Strand of Human DNA = 4.5 gigabytes of data

That means that our current insurance system is about 10 times more complicated than the code to create life itself! I don’t have the numbers but if i had to guess I’d say that the current insurance system makes all the other works of mankind including the lost library of Alexandria look like a cliff notes for a Hardy Boys novel. It is without doubt the most complicated thing we have ever created EVER!. In hundreds of years when we are flying our battlestars to distant galaxies it will still be the most complicated system ever made ever!

Why, why! why you ask?

It’s because they don’t want you understand the system that’s why. it’s in their benefit for you to not understand it because they can take advantage of you that’s way.  And by they, I don’t mean Obama and his cronies i mean the insurance industry.  They are the ones spreading the lies about obamacare and making everyone fear it because it is they who will be hurt the most by changing the current system.

So what are we to do?

Well the wheels are already in motion, obamacare is here and i don’t think it’s going away. Is it painful to make this transition? yes it is. There will not be an immediate benefit to most people, in fact most people will end up paying more…  At first that is.  And this fact won’t change quickly. It will take a generation for us to sort out the mess that we’ve created and for anyone to see the real benefits of this legislation but when we finally get to that day it will be worth it.

But why is this system better?

It’s better because now all the heavy lifting is going to be handled by computers.  No longer will there be any ambiguity about whether you are, or are not covered.  No longer will it take years for doctors to get paid for their work.  No longer will there be lawsuits over who should pay for what.

Also because the new system will handle all the complexity for the doctors and patients, it will become less beneficial for the insurance companies to purposely complicate the system.  Perhaps they will start to simplify their fee schedules which will make everyone happier.

Imagine if we applied this logic to other things, LIKE TAXES!  what if there was a computer program where all you had to do was press a button and it would figure out your taxes for you and guarantee that you got the maximum amount of money back using every possible deduction.  Do you think the IRS would simplify it’s tax code?  maybe they would because i’m guessing the same rule is in effect here.  Currently it makes more sense for them to make it complicated so that way they can rob you of more money.

One comment so far, add another

The newest scam

So I was recently approached by a book publishing company online who wanted to know if I would be willing to review an upcoming book that they were planning on releasing. The book was on the subject on optimizing MongoDB and they said that they thought I would be a good reviewer based on my years of experience in the industry. In exchange for reviewing the book I would get my name and my biography put into the book as one of the reviewers. I have to say, my spider sense immediately started tingling that this was somehow a scam but I could not quite put my finger on it. They weren’t asking for any money from me and it was flattering to be considered an expert on a subject (even though I am not an expert on MongoDB) so I decided to go forward with it.

Today, I started reading the first chapter of the book and oh boy… it was bad. I started taking notes right at the first paragraph. The problem wasn’t the accuracy of the technical content, the problem was that the writer of the book was clearly not a native english speaker. I had to re-read every sentence several times to determine what the F they were actually trying to say. They kept using wrong words like ‘recipe’ instead of ‘chapter’ and dont put transitional word proper or plural correct much yes?

I skimmed the rest of the chapter and sent an email back to the project coordinator with a list of the problems I found and an explanation that I would not be able to review the rest of the book. To make it worse, they wanted each chapter reviewed in 4 days, not business days mind you, just 4 days. I don’t have time for that.

So then I started to figure it out. What they were doing is paying someone in India say $2 a day to write a book… ok perhaps it was $3 a day after all it was written by a software developer. Then they figured they would get someone who speaks english to make the book readable by english people and rely on the vanity of that person to get them to do the work for free. Sorry sir, but I don’t need to be in a book that bad.

Here is the problem. I would never read that book. If I picked that book up off the shelf at Barnes and Noble I would put it right back down after reading the first paragraph. The thing is, we have this new invention called the fucking internet and all the information that I ever wanted to know about anything is already right at my fingertips. The days of cryptic tombs written by uber geeks who may or may not speak the language is over.

Don’t get me wrong, books are not dead by any means. I still purchase real paper books and enjoy reading them, but the books that I choose, I choose because of the writing style, not necessarily the fact that are inside them (even though I pretty much only read technical books). When I buy a new book I expect more that just the facts. I want the book to be easy to read and even easier to understand. And more that this I even expect the writer to make me laugh every once in a while because heck, i’m a god damn human being and I want to be entertained as well as educated.

So with this in mind. I think I am going to start a new project. I am going to write my own technical manual. Not sure what to call it but perhaps something like this:

PHP, Javascript, SQ-something and all that other crap programmers do to make lots of money in the real world.

– a technical guide for the un-technical –

or “How I bullshitted my way into a respectable career”



Leave the first comment

Opencart and vQmod, wtf?

So I recently had the opportunity to work on a site built on the Opencart open source e-commerce system. Coming from a site that was custom built with the Zend Framework I was initially pleased with the simplicity of the code. It was fairly obvious how things were put together and there was none of that object oriented madness that frustrates new developers. Then I discovered vQmod. After a day or so with it I was shouting wtf’s at a regular pace. Needless to say, I quit the job shortly thereafter.

Here is the problem. First, you start off with a simple easy to use pre-made site. Anyone with 6 months coding experience can get it installed and set up, yay! the bosses are happy with your amazing progress. Then your boss says, ‘Hey can you add XYZ functionality to the site?’. So you immediately look and see if someone else has already implemented XYZ and wholla! they have. there is a plugin that uses vQmod! YAY we are all happy!

Then your boss asks you for another feature, and another… pretty soon you say, ‘hey look, here is a site with all of the plugins we can add’. Bad Idea! your boss wants all of them but you have no idea what this means for your code because you don’t understand how vQmod works.

vQmod seems like a good idea at first. What it does is simple, whenever a third party developer wants to create a plugin they often have to make changes to the core code. Making changes to the core code is a bad thing because it makes it impossible to upgrade the core code later on. So what vQmod does is looks for the part of the core code that you want to change and essentially does a search and replace with the changes that you want. It then creates a new file which is used instead of your core code file so your core code never actually changes.

This works great when you have one plugin, but as soon as you add more than one you increase the risk of one plugin’s changes stomping all over another plugins changes. The thing your boss doesn’t realize is that these plugin developers don’t bother to test their changes against all the other plugins. In fact it’s practically impossible for them to do this because every time you add a new plugin you increase the possible combinations of plugins that they have to test.

Now as you go on adding more and more plugins you start to see more and more bugs, but you boss has gotten used to the quick fix of adding features practically overnight. This is not going to end well.

In the end, my suggestion was that the entire site should be scrapped and a new one built from the ground up correctly. Object oriented methods may appear to be unnecessary to the naive, but it is exactly those methods which prevents things like this from getting out of hand.

So in conclusion, my opinion of opencart is that its a great tool, if you happen to want exactly what it offers and not much more. If you actually want specific functionality then don’t waste your time. And its important to note that this is not a problem just with opencart, you have similar problems with all the other site-in-a-box solutions (ie gocart, oscommerce, drupal etc..).

There is also the flipside with products like Magento, which really are built correctly, however the problem with these is that they try to solve all problems at once. What you end up with is an extremely complicated code base that is difficult to maintain/learn. In the end there is nothing better (IMO) than building a site from scratch (or use a framework like Zend/CodeIgnitor/Symfony) and build it explicitly with the features you want.

Leave the first comment