Wednesday, 26 August 2020

PHP Program Reverse the String without Function

PHP Program Reverse the String without Function


 Write a PHP  function FirstReverse(str) take the str parameter being passed and return the string in reversed order. 

    For Example: if the input string is "Hello World and Coders" then your program should return the string sredoC dna dlroW olleH.

Solution:


function FirstReverse($str) {
    $result='';
    for($i=strlen($str)-1; $i>=0; $i--){
      $result = $result.$str[$i];
    }  
      return $result;

}



PHP Program Find Intersection between Two array

PHP Program Find Intersection between Two array

Create PHP  function FindIntersection(strArr) read the array of strings stored in strArr which will contain 2 element

 the first element will represent a list of comma-separated numbers sorted in ascending order.
 the second element will represent a second list of comma-separated numbers. 

Your function should return a comma-separated string containing the numbers that occur in elements of strArr in sorted order.
  If there is no intersection, return the string false.


Solution:

  function FindIntersection($strArr) {
    $return ='false';  
    $array1 = explode(',',$strArr[0]);
    $array1= array_map('trim',$array1);

    $array2 = explode(',',$strArr[1]);
    $array2= array_map('trim',$array2);

    $result= array_intersect($array1,$array2);
    if(!empty($result)){
      $return=implode(',',$result);  
    }

  return $return;

}
  

PHP Program Longest Word from the string

PHP Program Longest Word from the string

 Create PHP function LongestWord(sen) take the sen parameter being passed and return the largest word in the string.

If there are two or more words that are the same length, return the first word from the string with that length. 

Ignore punctuation and assume sen will not be empty.




Solution: 


function LongestWord($sen) {
    $return = '';

    //Convert string into Array
    $strArrayList = explode(' ', $sen);
    $finalArray = array();

    ///////Filter the words///////////
    foreach($strArrayList as $str){
        $str = preg_replace("#[[:punct:]]#", "", $str);
        $finalArray[] = $str;
    }
    ///////Filter the words///////////
    
    /////////// Get the First word  from the string with that length////////
    foreach($finalArray as $word){
        if(strlen($word)> strlen($return)){
        $return = $word;
        }
    }
    /////////// Get the First word  from the string with that length////////
    
    
    return $return;

}


Tuesday, 25 August 2020

PHP Username Validation program

 

PHP Username Validation program

Creat function usernameValidation(str) take the str parameter being passed and determine if the string is a valid username according to the following rules:
  1. The username is between 4 and 25 characters.
  2. It must start with a letter.
  3. It can only contain letters, numbers, and the underscore character.
  4. It cannot end with an underscore character.
If the username is valid then your program should return the string true, otherwise return the string false

Solution:
function usernameValidation($str) {
    $return = true;
    
    ////////////////// 4 to 25 character////////////
    if ($return) {
        if (!(strlen($str) >= 4 && strlen($str) <= 25)) {
            $return = false;
        }
    }
    ////////////////// 4 to 25 character////////////
    
    ////////////////// Must start with Number ////////////
    if ($return) {
        $asciiCode = ord($str[0]);
        if (!(($asciiCode >= 97 && $asciiCode <= 122) || ($asciiCode >= 65 && $asciiCode <= 90))) {
            $return = false;
        }
    }
    ////////////////// Must start with Number ////////////
    
    ///////////// It can only contain letters, numbers, and the underscore character.///////////
    if ($return) {
        for ($i = 0; $i < strlen($str); $i++) {
            $asciiCode = ord($str[$i]);
            if (!( ($asciiCode >= 97 && $asciiCode <= 122) || ($asciiCode >= 65 && $asciiCode <= 90) || ($asciiCode >= 48 && $asciiCode <= 57) || ($asciiCode == 95))) {
                $return = false;
                break;
            }
        }
    }
    ///////////// It can only contain letters, numbers, and the underscore character.///////////
    
    ///////////It cannot end with an underscore character.///////////
    if ($return) {
        $asciiCode = ord($str[$i - 1]);
        if ($asciiCode == 95) {
            $return = false;
        }
    }
    ///////////It cannot end with an underscore character.///////////
    
    return $return ? 'true' : 'false';
}

Docker tutorial for beginners

Docker tutorial for beginners

Question: What is docker?
Docker is a container management service.
It is for mainly for developers to easily develop applications, push them into containers which then be deployed anywhere to physical server/virtual server/cloud server.


Question: Features of Docker?
  1. Docker containers are lightweight so they can be easily scalable.
  2. Deploy docker containers on any physical and virtual machines and even on the cloud.
  3. Docker has the ability to reduce the size of development by providing a smaller part of the operating system via containers



Question: What is container in docker?
A container is a standard unit of software that packages up code and all its dependencies so the application runs quickly and reliably from one computing environment to another.
Applications are better shape in containers and Docker provides the isolation capabilities.


Question: What is docker image?
A Docker image is a file, comprised of multiple layers, that is used to execute code in a Docker container.
Images can exist without containers, whereas a container needs to run an image to exist.


Question: What is a docker hub repository?
Docker Hub is a hosted repository service provided by Docker for searching and sharing container images.
hosted repository can be public or private.
URL: hub.docker.com


Question: How to install docker in windows 10 Pro?
  1. Open the link : Download docker for windows
  2. Click on "Get Stable" Link
  3. Download the file
  4. Once downloaded, then simply install



Question: How to check the version of docker?
docker --version



Question: How to list the running docker containers ?
docker container ls



Question: How to list the all docker containers ?
docker container ls -a



Question: How to list the all docker images?
docker images



Question: How to pull the docker container from docker hub?
docker run --name my-mysql -e MYSQL_ROOT_PASSWORD=123456 -d mysql




Wednesday, 12 August 2020

npm firebase

npm firebase


Question: What is firebase?
Firebase provides the tools and infrastructure you need to develop, grow, and earn money from your app.


Question: What is firebase used for?
Firebase is mobile application development platform that helps you build, improve, and grow your app.


Question: Is firebase a backend?
Firebase is a fully managed platform for building Android, iOS, and web apps that provides automatic data synchronization services, authentication services, messaging services, file storage services and analytics etc.


Question: Is firebase free to use?
Both (free and Paid)


Question: What companies use firebase?
  1. Client Platform
  2. Accenture
  3. LaunchDarkly
  4. Bepro Company
  5. ViaVarejo
  6. Stack
  7. Twitch
  8. Instacart



Question: Does firebase provide Crash Reporting?
Yes, Its provide crash reports for both App (android and IOS)


Question: Which language is used in firebase?
The Firebase SDK supports programming in C++, Java, JavaScript, JavaScript/Node. js, Objective-C, and Swift.


Question: Which language is used in firebase?
The Firebase SDK supports programming in C++, Java, JavaScript, JavaScript/Node. js, Objective-C, and Swift.


Question: What does provide the firebase?
Firebase Realtime Database - The Firebase Realtime Database lets you store and query user data, and makes it available between users in realtime.
Cloud Firestore - Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud Platform.
Firebase Storage - Firebase Storage lets you upload and store user generated content, such as files, and images.
Firebase Cloud Messaging - Firebase Cloud Messaging is a cross-platform messaging solution that lets you reliably deliver messages at no cost.
Firebase Authentication - Firebase helps you authenticate and manage users who access your application.
Create and setup your account - Get started using Firebase for free.


Question: How to use firebase in browser?
//Include the below JS in HTML
https://www.gstatic.com/firebasejs/${JSCORE_VERSION}/firebase.js

//Create the Firebase Object
  var app = firebase.initializeApp({
    apiKey: '',
    authDomain: '',
    databaseURL: '',
    projectId: '',
    storageBucket: '',
    messagingSenderId: ''
  });

Question: How to use firebase with node?
//Install the firebase in node
npm install --save firebase

//Create the Firebase object
var firebase = require('firebase');
var app = firebase.initializeApp({ ... });



Monday, 3 August 2020

log analyzer tool for linux - GoAccess

log analyzer tool for linux - GoAccess

Question: What is GoAccess in linux?
GoAccess is an open source real-time web log analyzer and interactive viewer that runs in a terminal.


Question: How GoAccess works?
It analyse the Log file (access.log) which is cotinue in writes by application.



Question: What are the benefits of GoAccess?
  1. Completely Real Time
  2. Nearly All Web Log Formats
  3. Track Application Response Time
  4. Incremental Log Processing
  5. Minimal configuration needed
  6. Visitors
  7. Color Scheme Customizable




Question: Does GoAccess is available for GUI?
Yes, You can watch in Terminal and GUI.


How to install GoAccess in Server?
git clone https://github.com/allinurl/goaccess.git
cd goaccess
autoreconf -fi
./configure --enable-geoip --enable-utf8
make



How to run GoAccess to check the analytics?
goaccess access.log -c




How to check the analytics in HTML page?
goaccess access.log -o report.html --log-format=COMBINED

Now run, https://example.com/report.html



How to check the analytics in HTML page dynamically?
goaccess access.log -o /var/www/html/dynamic.html --log-format=COMBINED --real-time-html

Now run, https://example.com/dynamic.html




Question: Share the Offical website link?
https://goaccess.io/