Showing posts with label webdev. Show all posts
Showing posts with label webdev. Show all posts

October 06, 2014

MacOS and multiple (concurrent) Vagrant boxes

Are you running more than one Vagrant box concurrently, forcing you to resort to port numbers for correct working?

I am, and it's been annoying me for quite a while. Every of my sites has its own specific VirtualBox VM. Sometimes I might work on more than one at a given time (eg 2 sites communicating with each other via an API) so keeping them on the default ports and then only using 1 at a time wasn't a real solution.

So I decided to spend some time on the matter and see what I could trump up.
As it turns out... a lot!

March 08, 2013

No explanation required...

I guess this needs no further explanation besides a "sigh":


switch ($month) {
case '01':
$maand = 'Januari';
break;
case '02':
$maand = 'Februari';
break;
case '03':
$maand = 'Maart';
break;
case '04':
$maand = 'April';
break;
case '05':
$maand = 'Mei';
break;
case '06':
$maand = 'Juni';
break;
case '07':
$maand = 'Juli';
break;
case '08':
$maand = 'Augustus';
break;
case '09':
$maand = 'September';
break;
case '10':
$maand = 'Oktober';
break;
case '11':
$maand = 'November';
break;
case '12':
$maand = 'December';
break;
}

December 18, 2012

Ticketing & Locking

We provide services to facilitate communication between us and our distributors. This application is called "contacts". Any contact request can only be updated by one party at a time (it is locked while someone has the page open), but the person who logged the question is always able to view the request.

Today I received a mail about an issue with the locking system. Our customer was told that their contact request was under treatment by themselves and that they could not update it while someone else was editing.

After spending a while trying to figure out under which circumstances a contact was locked and unlocked and not being able to find anything (seriously) wrong with it I looked a bit further.

Turns out that the column in the table that stores who locked the contact contained the name of the user instead of the (expected) user-id.

The fun part was this: This column was limited to 20 characters and the users' name was longer than that. The result? A concatenated string and the comparison that goes wrong everywhere, considering the actual contact owner and the person who locked the request as 2 different ones.

Welcome to the world of non-programmers writing code.



October 04, 2012

The life of a Fixer #2

PHP: How to convert a date into a different format

$timestamp = explode(' ',$transaction['datetime']); // 2008-04-28 17:40:19
$date = explode('-',$timestamp[0]);
$date = $date[2].'/'.$date[1].'/'.$date[0];
$time = substr($timestamp[1],0,5);
$datetime = $date.' '.$time; // 28/04/2008 17:40

Tada!

Javascript: Drag and drop with different processes

So we have a callback function for a drag and drop script that was found on the web somewhere and we have a box called IN where we can drop "products" on. 

Some of the thoughts we have during development of "this solution":
  • Of course we write a single function of about 400 lines of code, it's cooler that way.
  • We need to check the drop target as it needs to have a specific ID, so we do some getElementById magic.
  • Oh crap, now we also need an OUT box. We have a couple issues here... The drop box for that one has a different ID (a '2' was appended, obviously!). Also: sometimes we have to show a prompt and the text there needs to be different. Conclusion: We can't possibly re-use the code from the other box! Let's just copy/paste all 400 lines and make a different function (ah and of course, add a '2' to the name).
  • Hmm crap... The customer seems to work with internet explorer. The one line of code that checks the drop target does not work there. Easy fix! Let's just take the entire javascript file, copy it into a "script-ie.js" file. And presto, we include that one if the customer has IE. Modifying 4 functions every time? No problem!
  • Hmm we appear to have 2 kinds of products. The ones that need to go through the ERP system and products that remain local to the shop. How do we handle that? Simple! We just add an asterisk before the name to indicate the difference. Actually we thought about this a lot, since there are way less local products, we show the asterisk for those. Our customers won't wonder at all what a "* name of the hardware" is (no there aren't any footnotes at the end of the page).
  • So now we have to ask a serial number for some of the products. How do we indicate that? Yes of course, you guessed it already! We just add another asterisk, but AFTER the product name! We cant do 2 before the name, how would we know which one stands for what? You silly! So yeah... "*I'm a local product and I need a serial*". It's gotta be clear what this means, no?

The life of a Fixer

Intro

So, for those of you who don't already know: I've recently stepped into my own business fulltime. I work as a freelancer for a company that has outsourced me to another company as a consultant. (Yeah complicated,  I know).

In that company ("the client") I'm taking care of all the internally used PHP applications. Internally I'm what they refer to as "a fixer" and boy that expression holds some serious truth.

Most of the tools were originally written by non-developers (basically by anyone that had some web-experience and needed some kind of tool to get something done) and unfortunately it shows.

Now mind you, they are doing everything humanly possible to clean all this up, I wouldn't be here if they weren't. So in no way do these posts say negative things about the company as a whole, this is just about the legacy they have to deal with on a daily basis. I consider it my mission to improve their code while I'm maintaining it, but unfortunately it will take a while.

And... ?

Well as you might already suspect, I've been working there for a month now and I used up my "WTF!?" quota for the next 5 years. Which is why I figured I might as well share some stuff with the world :-)

Unfortunately I've missed a lot of good ones already, perhaps I'll recall enough details one day to still post them, but I'm sure there's more than enough stuff remaining :-)

A lot of these assume you know a thing or 2 about web development, which is why I'm putting them all under nerdy and webdev (and definitely WTF!).

Why not The Daily WTF you might ask? I don't want to fill up their news queue for the next year ;-)

Here we go!

A very urgent ticket was created yesterday. When arriving on the target site whilst not being logged in, you would get an error after logging in there. (Invalid template).

Some investigating later we determined that the user was correctly redirected to the login form if still anonymous, but that the redirect back to the originating page seemed to lose the query parameters.
This of course resulted in the described error, as the target page did not know what article to show.

Easy fix right? Figure out where the access check is done and make it include the query string as well. Mind you, for once this actually was the problem! Unfortunately as with everything I encounter here, there's more!

The code that did the check was in the actual target file. Not an included file, not a class... the actual source file. I'm pretty sure this will cause "oh shit" thoughts in every developers' head.

So we have an "isAuthorized"-function and a piece of regular code below, with a lot of MM_ prefixes (ah MacroMedia Dreamweaver stuff... nostalgia!).

A search later (a lot of doubting on whether I should actually do that) it turns out that the same snippet (function AND regular code) is copy/pasted into every one of the 253 entry scripts.

The allocated budget is limited to just this one fix, so there's no fixing the rest... So we log a "problem ticket" about the 252 other cases (that have the same bug but aren't currently considered an issue). If the customer ever approves that ticket we'll handle those. 'til then it's 252 pieces of buggy code!

See you on the one ;-)