Monday, 5 October 2015

Create 'Go To Top' or 'Scroll To Top' via jQuery


Create 'Go To Top' or 'Scroll To Top' via jQuery, please follow below steps:
1. Add the below HTML code,
< div class="scroll-to-top" >
     < a href="#" id="to-top" rel="nofollow" style="outline: none;" >Top< /a >
< /div >

2. Then, include the jQuery library and add the below Javascript Code
jQuery(function($) {

    var scrollToTop = function() {
        $("a[href='#top']").click(function () {
            $("html, body").animate({scrollTop: 0}, "slow");
            return false;
        });
    }
    // Call the scroll to top function.
    scrollToTop();

});


To check whether the Jquery Library is called or not

To check whether the Jquery Library is called or not, please run below function;

if (typeof jQuery != 'undefined') {
    alert("jQuery library is loaded!");
}else{
    alert("jQuery library is not found!");
}

Tuesday, 1 September 2015

To get the Array request/input value in Joomla 3+

To get the Array request/input value in Joomla 2.5/3.0/3.4.3/3+
        // Initialise the global application object
        $this->main = JFactory::getApplication();

        // To get the an array of item from joomla input/request variable. 
        $cids = $this->main->input->get('cid', array(), 'ARRAY'); // 'ARRAY' or 'array'

        // To get the first item from the array;
        $cid = current($cids);

Thursday, 6 August 2015

How to read a file content and convert it into an array

If you have a config.txt file containing the following code;
DB_HOST=localhost
DB_NAME=demo_database
DB_USER=root
DB_PASSWORD=dbpswd15

Please use the below function to read the text file content into an array with key and values;
/**
 * Function to read the file content and return into an array separating key = value;
 * @param $filepath The Document File path to read the file contents;
 * @return array Return the files content into array by separating each lines with '=' separated with first part as key (into lowercase) and second part key's as value.
 */
function get_file_content_in_array($filepath)
{
    $fp = fopen($filepath, "r") or die("Please configure the forum database.");

    $lines = array();

    while (!feof($fp))
    {
        $line = fgets($fp);

        //process line however you like
        $line = trim($line);

        // If line empty, do continue
        if (empty($line)) continue;

        // Split the line string with '=' operator into key and value;
        list($key, $value) = explode('=', $line);

        // check the empty key
        if (!empty($key)) {
            //add to array
            $lines[trim($key)] = trim($value);
        }
    }
    fclose($fp);

    return $lines;
}

To read the file content, just call the above below script after including the above function.

// Read the file and content and convert it into an array
$config = get_file_content_in_array($filepath = "cofig.txt");
Output:
Array
(
    [db_host] => localhost
    [db_name] => demo_database
    [db_user] => root
    [db_password] => dbpswd15
)


Hope that helps!

Wednesday, 29 July 2015

Xampp Apache and Visual Studio Port 80 conflict

If you already install Xampp Apache running into your PC and later install the Visual Studio 2015, then there will port conflicts. Normally, Visual Studio overtake the default IIS HTTP port 80 and use it.

However, if you want both to be working by running one at a time.
To do that,
Type Services.msc from the run command prompt > scroll down to World Wide Web Publishing service.
OR go to Control Panel > Administrative Tools > Services.msc > World Wide Web Publishing service.

Then, Right click  the Web Publishing and 'Stop' it, also, Go the same Properties and set a Startup type: 'Manual'.

Then, try to restart the apache. It should be working.

On the other hand, when you need to start the Visual Studio part of service, you can do same thing manually and later disable it.


Hope that helps;

Friday, 17 July 2015

Get the input array variable in Joomla 3+

In Joomla 3+ or Joomla 3.4, To get/filter the INPUT or POST variable whose value is in array, please use the below script to pull the values:

JFactory::getApplication()->input->get('cid', null, 'array');


Thursday, 14 May 2015

Deleting all large size files from all directories using Bash in Linux

If you are looking to delete all the files in Linux Web Server by specifing File Name and File Size,
then follow steps below:

1. Login into your server Terminal via root login.
2. Create a new bash file called clean_up.sh in one of the location
e.g. /home/my_script/

3. Then Copy and the below code and Paste into that file and Save it.
clear
echo ' -------------------------------------------------------------------------'
echo '  Cleaning all large size error_log files from all directories.'
echo ' -------------------------------------------------------------------------'

filename="error_log"
filesize="50000"

echo " Deleting all files (including subfolders) having Filename:'$filename', Size: greater than $filesize Kb only."
echo ' '
echo ' Listing all the files which are greater than 50MB'
find / -type f -size +50M -exec du -h {} \; | sort -n

echo ' Deleting all the "error_log" files which are greater than 50MB'
#find -name "error_log" -size +30000k #-delete
find -name "$filename" -size +"$filesize"k -delete

echo ' Listing again all the files which are greater than 50MB'
find / -type f -size +50M -exec du -h {} \; | sort -n

4. Then go to your specified directory where you want to Search and Delete the files by specifying the File Name and File Size as below;

5. Then run the below command
sh  /home/my_script/clean_up.sh