Monday, February 29, 2016

Rustic way to import your AngularJS configuration from an external JS file

Many times we want to store our constants/config details into a different file to simplify the deployment process or simply to organise the code.

Here you can see a very basic way to save your app's config file into a different location.

https://jsfiddle.net/sergioloppe/bvajr7bw/

The code is self-explanatory.

Hope helps





Friday, February 12, 2016

How to avoid errors using the function eval in php (under any framework)

Sometimes when you have to evaluate some mathematical expressions with eval it is difficult to control the errors even using try-catch. Here you have a trick to solve that problem:


$calculation = '1/0';

$result = @eval($calculation . "; return true;");
if($result) {
$rule2_val = doubleval(@eval($calculation));
}
else {
return 'Impossible to perform the calculation';
}

Hope helps!