January 04 2017

Cron with wget always created an empty file on server

Tagged Under :

Linux
I am trying to write a cron task to call wget on a url. The cron runs fine, but every time it runs it will creates a cron.php.X file in my home directory. I’ve tried to turn off output using the –quiet option but it’s still outputting a new file with every running.

December 13 2016

Jquery validation validate money method function

Tagged Under :

javascript
Jquery validation itself didn’t give money validate method function. What we can to do is write a custom method to validate the money format with regular expression.

Below is the money validate method.
jQuery.validator.addMethod(
    "money",
    function(value, element) {
        var isValidMoney = /^\d{0,4}(\.\d{0,2})?$/.test(value);
        return this.optional(element) || isValidMoney;
    },
    "Insert "
);

December 13 2016

How the get total file inside the folder

Tagged Under :

Linux
On Linux without the GUI (Gnome or KDE) if you want to know how many files inside folder, you are unable to right click and select the properties to get the number of files inside the folder.

You can use below command to get number of files inside the folder

October 23 2016

Firebird log execute SQL query

Tagged Under :

On Firebird it have a function to let you log the SQL Query where the system call. How to the log the Firebird SQL query?

First, you need install Firebird 2.5 or 3.0 server on your PC. After that, go to the Firebird folder find a file name call fbtrace.conf and then open the file with notepad.

August 29 2016

Yii2 number compare validation rules

Tagged Under :

Yii
In Yii2 compare two numbers attributes in operator function. you will found that it not working properly. This is because the wrongly “type” in compare validation rules.

You may need to set the type to number as below:
'type' => 'number'
Example:
['min_price', 'compare', 'compareAttribute' => 'max_price', 'operator' => '<', 'type' => 'number'],

August 29 2016

Jquery find the specific Id if exists

Tagged Under :

javascript
If want to check the specific Id already exists inside the site. you may using “length” to do it.

For Example:
if( $('#selector').length) {
     // it exists
}
if the length more then 0, that’s mean the following Id already exists inside the site.

if you are using class to check
if( $('.selector').length) {
     // it exists
}

August 29 2016

check if a string is JSON in Javascript

Tagged Under :

javascript
In javascript it don’t have function to check if the string is JSON. So we may need to write a function to check the string if is JSON.

The below function is to check the string and it will return true if the string is JSON else it will return false.

July 27 2016

Yii2 ActiveRecord model use MySQL function

Tagged Under : ,

Yii
To use the MySQL function on Yii2 ActiveRecord Model you to add “\yii\db\Expression” on your script instead of you direct use the “DATE_ADD” function.

Example:
$model->date = new \yii\db\Expression('DATE_ADD(CURRENT_DATE, INTERVAL - 7 DAY)')

July 27 2016

Yii2 an absolute url image src

Tagged Under :

Yii
If you want to set full url or absolute url on Yii2 Html img, you may need to use “Url” helper this class on your page.

use yii\helpers\Url;
The way to use:
Html::img(Url::to('@web/images/logo.png', true));

July 27 2016

Bootstrap glyphicons checkbox

Tagged Under : ,

Because the default HTML chekcbox look not nice, So i decided use Boostrap Glyphicons as the checkbox and also it got provide checked and uncheck glyphicons.

Glyphicons check and uncheck icon: