PHP: function number_format issues and solution

By | PHP

Following is not really an issue but we could run into a trap if we don’t be careful about it. Bottom line is to understand that number_format returns string and when any arithmetic operation is performed to it, we could end up with huge problems.


$a = number_format(100000, 2);
$b = number_format(100000, 2);

$c = $a + $b; // 200


$a = round(100000, 2);
$b = round(100000, 2);

$c = $a + $b; // float(200000)

setlocale(LC_MONETARY, 'en_CA');

var_dump(money_format('%i', $c)); // string(13) "CAD200,000.00"

JavaScript Numbers

By | Javascript

What is JavaScript equivalent for number_format in php?

// Lodash to rescue
// Works exactly as we expect. Output is a typeof number.
_.round("10.608", 2); // 10.61

// Following returns the output as string. That's one major down side.
parseFloat("10").toFixed(2); // 10.00
parseFloat("10.60").toFixed(2); // 10.60
parseFloat("10.605").toFixed(2); // 10.61

Laravel 5.2 – Local query scope not working with cron job / scheduler

By | Laravel

I have observed local query scopes do not work with cron job.

To make it work, I simply scaled down. I put the conditions itself rather than using local query scope.

I know it completely defeats the purpose of creating local query scopes in the first place but at least for now it made the cron job run. Let’s hope this issue gets addressed soon. It is really convenient to use local query scopes.

There is one more issue I found with Laravel cron job.

Issues with Laravel cron job (scheduler)

By | Laravel

Laravel is great at almost everything but there are few areas where it lacks it’s awesomeness.

Problem with cron job (Laravel – 5.2)

I noticed some of the cron jobs were not running. You can use following command to check and run the cron job execution.

php artisan schedule:run
Turns out when the cron has withoutOverlapping method chained. It creates a file in the storage/framework folder with the name of schedule-***. 

It appers the existence of this file is used to check whether the cron job is running or not. When the cron job fails for whatever reason the file is not deleted. Since, the file exists the system thinks the cron job is still running and it is not done yet.

This prevents the cron job execution.

For now the solution is to delete the schedule-*** file.

Note: I would also want to add one of my observations: php artisan schedule:run will not show the task(s), if the job only runs on specific day (e.g. everyFriday()) and specific time. The tasks with everyMinute() should run just fine. It makes sense too.

I came across one more issue with Laravel cron job.

What is the ideal slider image size for homepage for various resolutions/breakpoints?

By | CSS, Responsive, Uncategorized

It is essential to use different slider images for desktop and mobiles. Because, the desktop slider image will look very small in terms of length. Any text over slider will have very little space. Hence, for mobile we must use an entirely different image.


For mobile I use – 500px x 375px. While writing media queries. You should also consider the landscape resolution (will be discussed soon).


The resolution – 960px x 540px seems like a good fit on a tablet.


For desktop whatever looks good to your eyes should do it. In one of my recent project, I’ve used – 1900px x 600px


By | Uncategorized

If you have two checkboxes with same name (value should of course be different).

When user submits a form with one selected. In PHP you will get the value as a string for the checked checkbox. Interestingly if user checks both, PHP gives an array and this is without specifying name with an array.