Thursday, 8 September 2016

Monday, 13 June 2016

Loop optimizations

for(i;i<list.length;i++){
}

Looks familiar?
Well loops help us in writing less code, we use the everyday but do we use them effectively.
Here are some tips:
1. Avoid queries in loops.
If you put a query in a loop it means the loop has to do a trip to db each time.
2. If you are going to use conditions break them down and try to organize them logicaly.e.g.
for(i;i<list.length;i++){
      if(condition)
             if(condition)
                   
                   for(k;k<list.length;k++){
           
The logic is the first condition is never met the second loop will never run, but the second condition has to be met too.

Monday, 18 April 2016

pHp pitfalls

php is a great language with great language with alot of helpful functions.
Last month I was deploying a php farm app, where we had to register farmers.Registered farmers also had to get their photos taken, and their details like name, location etc on an android phone.
We had done numerous tests and everything was ok.
That is until we went to the field and farmers we been registered in their numbers, averaging 23 per device per day.
Little did we know there was a file called php.ini :) . There is a line in the file that that states the maximum number of files that can be uploaded per request for xamp the default is 20.
So what was happening was is that if there were more than 20 farmers the last file would repeat for all farmers after 20.
This had huge implications, several farmer with the same photo. some cards printed for farmers had wrong photos.
A single card costed around 5 dollars.

Conclusion be carefull on configuration files in servers.

Tuesday, 5 April 2016

Git Stash Command


The git stash command takes both staged and unstaged commands and storedms them internally, then clear the current working directory.
This can can be very handy given e.g. You were working on a feature and were told to add another feature that would not take alot of your time.
You have to options:
1)git reset --hard which will cause all your earlier work to be lost.
2)git commit -m "message" this would cause you to commit a half-baked feature.
The third option is to use the git stash command.
Use git stash pop to cause stored changes to re-appear in current working directory, then continue working on incomplete feature.
If you had multiple stashes you can use git stash list to view all of them, then choose which ones you would line to pop.

Monday, 25 January 2016

Learning the Yii2 Framework

Hello readers.
Right now I am leaning the yii2 framework moving on from codeigniter.Although codeigniter framework is good, I find it lacking in extensions. The Yii2 framework has the advantage of code generation.I can generate forms, models, CRUD table, extensions e.t.c. This lessens my development time by more than half the time. Also it picks up validation from the database e.g. If I declare a field in a table as an integer then in my view the validation will be the same. I find that the best tutorials for Yii2 are From the DoingItEasy Channel on Youtube. There are a few challanges here and there but I find the benefits outweigh the disadvantages.