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 ;-)

June 07, 2012

Hurray voor de CBPL! (en in your face stad Mechelen)

Since this post is local to Belgium and more specific Mechelen, I'm going to write it in Dutch. My apologies to the English speaking folks following my blog (if any ;-) )

Waarover gaat het?

Vlak nadat ik een bouwvergunning aanvroeg in Mechelen om renovaties te doen aan mijn woonst, begon ik van een hoop bedrijven van bouwmaterialen geadresseerde reclame te krijgen. Elke dag zat er wel een ander stuk in mijn bus. Ik heb zelf een hartsgrondige hekel aan reclame, er kleven niet voor niets 2 NEE stickers op mijn brievenbus (wat de ronddragers overigens nog steeds niet tegenhoud). 

Kun je niets tegen beginnen, toch?

Toen de vloed aan reclame niet stopte besloot ik om een klacht in te dienen tegen Stad Mechelen bij de CBPL (Commissie voor de Bescherming van de Persoonlijke Levenssfeer). Zo'n praktijken kunnen gewoon niet meer.

Na ettelijke maanden over en weer mailen (want snel zijn ze helaas niet) en de nodige bewijsstukken (reclame dus) over te maken, heb ik vandaag dan toch een brief gekregen die mij hoop geeft. 

De CBPL heeft heel deze zaak heel grondig opgevolgd. Ze heeft de stad Mechelen meermaals om verantwoording gevraagd (met 2 herinneringsbrieven tussendoor wegens geen antwoord). Uiteindelijk is Mechelen dan toch in beweging gekomen en daar heb ik vandaag verslag van gekregen.

Wat dan?

Sta me toe een deel van de brief openbaar te maken:
Geachte heer,
Ik verwijs hierbij naar mijn e-mail d.d. 31 januari 2012 waarin ik u beloofde u op de hoogte te brengen van het antwoord van de Stad Mechelen.
 Na het versturen van twee herinneringsbrieven aan de stad Mechelen heeft de Commissie op 23 mei 2012 een antwoord ontvangen.
Uit hun antwoord blijkt dat bij de controle van de verwerking van de persoonlijke gegevens, na de beslissing van het College van burgemeester en schepenen, de gegevens worden doorgegeven aan het Kadaster en aan het Nationaal Instituut voor statistiek. De gegevens worden ook doorgegeven aan zogenaamde "niet-relevante" instantie (Belgacom, Bouwkroniek, BTW, Confederatiebouw, Electrabel, Pidpa, Polder). Dit systeem is blijkbaar al vele jaren een gewoonte.
 Naar aanleiding van het schreven van de Commissie heeft het College van burgemeester en schepenen beslist dat er geen gegevens meer worden doorgegeven aan niet-relevante instanties.

W00t zou ik zo zeggen! Ik heb er zelf niets meer aan, moet me nog altijd van al die adreslijsten zien te krijgen, maar aan de toekomstige bouwvergunnings-aanvrager: You're welcome! :-)

Ik weet niet waarom ze het al jaren zo doen, maar het hoort gewoon niet. Ik heb letterlijk weken aan een stuk 3 tot 4 stukken reclamedrukwerk per dag gekregen. 


January 20, 2012

MacOS Lion: Slow Disk?

In September I bought a brand new iMac with 8GB RAM and a regular harddisk. Even though it should've been a work horse, it wasn't. The CPU itself was never really loaded, but everything that required disk access seemed to be ULTRA SLOW. When the disk was under heavy load, the swiping between desktops would just hang halfway a slide and so on.

I guess I don't have to mention that, given the price of one of those Macs, this was extremely frustrating.

It even annoyed me up to the point that I actually called Apple to ask how much it would cost me to add an SSD. Unfortunately the price tag (about 800 euro's) was a bit too steep for my wallet. Apparently the back cover of the iMac has different configurations as well and if you buy a Mac with a regular disk alone, it has no bracket to mount the SSD. So its not SSD + hours but also the price of a new back cover. So people: Think before you buy! An SSD is a really good investment and it will cost you half that price when you add it right at the start.

Anyway, back to the point: I recently found this little post on one of the mac boards about that issue. Since I had Quicksilver installed, I thought like: Eureka! Nothing else had worked before. The minute I disabled it it became apparent that that was indeed the root cause of the extremely slow disk! The Mac now behaves as I would expect it.

So people if you run Lion: Don't use Quicksilver! 

December 09, 2011

iFit - Another follow up.

Since it's been a while, I decided to write a bit of a follow up on the iFit module as there have been some developments.

The classical music
I recently found out with some help from Amanda (@IFit Live Support) that getting rid of that pesky song is as easy as connecting the module to your PC and going into the "Audio" folder on the drive. In there you'll find a file called "test.mp3". Delete it (or move it to somewhere on your PC for safekeeping) and let the silence engulf you!

The not posting to Facebook
A new firmware was released recently that apparently takes care of this issue. So far I have done 2 workouts and both were correctly finalized (mail + facebook post).

What's still wrong?
I still have to press the iFit or "My Training" buttons a zillion times before I get the new workout, it keeps suggesting the last done workout. The best way to get to the new workout seems to be to remove the safety key again, put it back and try again.

Also the shutdowns seem to have stopped too. The only shutdown is if I let the machine idle for 10 minutes or so. Seems that the way the iFit asks for a shutdown is not the way the machine likes it, as it requires a power cycle to get it started again.


Maps?
I have to admit I didn't try the maps feature anymore since it caused so much issues last time, but perhaps I should and let you all know how it went. Now that I don't have to sit through that entire song anymore it doable.



Signing off.

Still Alive!

Hi!


(This is a pretty long one. If you want to take away anything of this and just skip the junk, start reading at "So?" :) )


It's been a while since my last post but rest assured, I'm still here :)


Been somewhat busy lately, but wanted to take some time to tell you about a couple of my anxieties the last couple of weeks. 


Usually when I go on a vacation, with my food addiction and all, I come back a couple of kg's heavier. When there is a buffet for example, I've always felt the urge to taste everything, every evening. A 3kg heavier return trip from a 2 weeks vacation? Very plausible.


So yeah, queue a week to Turkey followed by a week in Romania for work. Since I have been doing so well lately I was pretty scared about both weeks. Didn't wanna break the flow ya'know?


New mindset?
Luckily it turned out that my need for all these things is not really there anymore. Somehow I managed to change my thinking process into a realistic one. Lately, when I look at something sweet that I used to be very fond of I'm always thinking: This is probably about X calories. To get rid of that many calories I have to abuse my treadmill about this long. Is it worth it? And somehow the answer is "naah!" most of the time. 


The cool thing is that when I decide it is, I consciously will take a much smaller portion than I used to. I just eat it a lot slower. This way the enjoyment lasts a lot longer than the bigger portion (which usually got swallowed in one piece).  


Turkey
The week in Turkey went pretty well food wise. Ate a lot of vegetables from the buffet and tasted a lot of the local dishes, but in moderation. I checked out the dessertbuffet every day but couldn't usually find something that I liked very much so most of the time I returned without anything. And of course I made a ton of pictures (take a look if you are interested).


Not having my treadmill wasn't so bad since we were walking around all the time. 
The netto result of our trip to Turkey? -900gr after 8 days. So despite of the different food with lots and lots of olive oil still managed to lose almost my average loss in a week. Moderation works!


Romania
The week to Romania was a bit worse, as I've been working there the entire week. Not much movement there. I really don't like to run outside. In Belgium this is mainly because of my bad knees. But the idea of running around in Romania, hmm no I'd rather not. 


Unfortunately the food there is not nearly as good as Turkey and because we usually order out it's hard form me to try to get something healthy every time. I ate a pizza while we were there, albeit a small one and so on. 


On the flights to and from they seduced me with one thing I still really like: Snickers! Both meals included a little one (like 1/4th of the regular size). I ate them both but by choice, not by "forced behavior".


So?
I'm starting to realize that I feel less and less "obliged" to eat something just because it's there. In my entire history with weight problems this is something I never managed before. In my opinion this is the single most important thing that everyone who wants to loose weight needs to accomplish first.  


But how?
The reason for this is twofold:
First, I'm extremely lucky to have someone who is in the same situation and who fully supports me. I don't think I would been able to get here without the support of my girlfriend in all this. 


Secondly: Because I gave myself a frame of reference to compare against! I know how hard I have to workout to get rid of 100kcals. Before all this I never even cared. Knowing this helps you think about something you are about to put in your mouth. That in turn gives you the power to say no.


So what about diets then? 
Pfuh, away with them as far as I'm concerned. They do way more damage than good. My girlfriend has been in that situation. She tried a lot of the diets out there. The end result was that the weight she gained back after the diet stopped was all fat and nearly no muscle. That really sucks, because she did lose a lot of muscle mass during. 


The end result of all that is that she has had a way harder time than I did to hang in there. She needed to gain more muscle first before she could burn enough energy to lose weight. Of course all the medication she was getting during did no good either. 


Luckily we have one of those scales that measures the muscle-% versus the fat-%. This is by no means an exact science, but it showed enough difference every weigh-in for her to continue. I'm happy to be able to say that she's now at a point were she is also starting to lose weight.


But if you take everything into consideration you realize there is no such thing as a quick-fix-diet to lose weight permanently. Anything that involves food supplements, pills, whatever is bound to fail in the long run. 


The only thing that works is changing your eating habits and to make sure you get plenty of workout. 


Will this last for me? I don't know, I guess time will tell. But I'm doing it like this since about September and so far I've lost 14kg! Since we're not dieting, we also don't feel that we need to indulge once in a while and the cravings have almost absent (or perfectly manageable) as well.


Before/After(during) picture. Ignore the pink in the before picture (it was taken at "Race for the Cure", a breast cancer awareness event) and for the during picture, the just-out-of-bed-head:



November 04, 2011

Minus 9!


I'm really pushing myself hard to only use the scale once a week. For me that day is usually Saturday morning. This morning however, I couldn't wait... I stepped on the scale and waited and it told me 121kgs. To be sure I turned it off again, stepped on it: 121kg.

Woah!

For me that pretty much means -9kg since we started eating healthy. Put in context that means that it is the first time I'm around the 120kg barrier in about 2 years. For me this is a big thing. Passing that barrier will be even bigger.

What is even more awesome is that we aren't actually following a diet or whatever. We just decided that we had enough of our unhealthy lifestyle of soda and take-out food. Drinking plenty of water, eating healthy and some extra workouts.

It's amazing for me that in those 2 short months I learned to appreciate vegetables again and my food portions have shrunk significantly as well.

See you on the other side of 120!

PS: For the doomsayers: I fully realize that it won't be going as smoothly the rest of the way, but as long as it does? You don't hear me complaining. If I start to lose less weight I'm gonna work harder, its that easy :)

Tata.