Loading...

Follow My Programming Tutorials on Feedspot

Continue with Google
Continue with Facebook
or

Valid
What is CodeLabs?

Codelabs is an online platform for learning and practicing programming. It provides a guided tutorial on how a programming language works and allows the user to learn a new programming language quickly. The user can execute their programs in the programming lab provided on the browser.

The various programming languages available on CodeLabs are :

  • PHP
  • Ruby
  • Python
  • JavaScript
  • Angular
  • Java
  • MySQL
  • React

PHP :

PHP is a server-side scripting language which is used for developing software applications. Its components are free to use as it is an open source programming language. PHP is compatible with all operating systems i.e. it is platform independent. It is the most preferred language for CMS development, as it can be fully customized to match customer needs.

Advantages of PHP :

  • Easy
  • Reliable
  • Fast
  • Dynamic
  • Secure

Applications of PHP:

  • File Handling
  • Parsing XML documents
  • Executing Shell Commands
  • Encryption using MD5 and SHA1 hashing algorithms

Ruby :

Ruby is an object-oriented general-purpose programming language. It is one of the commonly used programming languages in the world. It was originally designed with the goal of making programming fun. Its syntax is easy to read, write and understand. Just like PHP, Ruby is also a platform independent programming language.

Advantages of Ruby :

  • Cost-Effective
  • Productive
  • Consistent
  • Refined

Applications of Ruby :

  • Internet applications and Intranet applications
  • Form Processing
  • Web Applications
  • Writing CGI Scripts

Python :

Python is an interpreter, high-level programming language. It emphasizes code readability and has a syntax similar to the English language. It allows the user to write programs having greater functionality with fewer lines of code. Python can be used for developing desktop GUI applications, websites, and web applications.

Advantages of Python :

  • Extensible
  • Embeddable
  • Portable
  • Robust Standard Library
  • User-Friendly

Applications of Python :

  • Desktop applications based on GUI
  • Scientific and numeric applications
  • Web frameworks
  • Software Development
  • Education

JavaScript :

JavaScript is a lightweight programming language which is designed for creating network-centric applications. It is an open and cross-platform programming language. It is very easy to implement as it is integrated with HTML. It has object-oriented capabilities.

Advantages of JavaScript :

  • Dynamic
  • Weakly typed
  • Simple
  • Versatile
  • Increased interactivity

Applications of JavaScript :

  • Mobile Applications
  • Graphics
  • Client-side programming
  • Validating user input
  • Displaying pop up and dialogue boxes

Angular :

Angular is a TypeScript-based front-end web application framework. The very first version of Angular is known as AngularJS. It is easy to learn and is mainly used for building single page applications (SPAs).

Advantages of Angular :

  • Consistent
  • Productive
  • Maintainable
  • Modular

Applications of Angular :

  • Web Applications
  • Desktop Applications
  • Mobile Applications

Java :

Java is an object-oriented, class-based programming language. It works on various platforms and is one of the most widely used programming languages. It is fast, powerful and secure. It is mainly used for developing applications. It is simple to use. It has a large standard library and the code written on one platform can be executed on other platforms without any modifications.

Advantages of Java :

  • Robust
  • Secure
  • Distributed
  • Multithreaded
  • High Performance

Applications of Java :

  • Web Servers and Application Servers
  • Enterprise Applications
  • Mobile Games Development

MySQL :

MySQL is a relational database management system. It is an open-sourced programming language that uses structured query language for processing the data in the database. It works on various operating systems and supports large databases. It is an essential part of almost every PHP application.

Advantages of MySQL :

  • Data Security
  • Comprehensive transactional support
  • Cost Effective
  • Portable
  • Seamless Connectivity

Applications of MySQL :

  • Ecommerce
  • Session stores
  • Content Management Systems (CMS)
  • Web applications

React :

React is a front-end JavaScript Library which is developed by Facebook. It is used for building user interfaces. It can be used as a base in the development of mobile applications or single page applications. It is the view layer of an MVC application (Model View Controller).

Advantages of React :

  • Easy to learn
  • Reusable
  • UI-centric
  • Efficient
  • Maintainable

Applications of React :

  • Dynamic web applications
  • Mobile applications
  • Single page applications

Conclusion :

The above are few programming languages which are widely used for developing web and mobile applications. These are open source languages which makes them much more popular and influential. The main benefit of an open source language is that the source code can be customized efficiently to meet the user’s requirements.

CodeLabs is a free online platform offered by GreyCampus. It provides a user-friendly environment to learn and practice new programming languages. It is beneficial for beginners as well as advanced programmers. CodeLabs has interactive resources like videos, assignments, projects etc..which makes it easy and convenient for learning.

The post Learning and coding with CodeLabs appeared first on My Programming Tutorials.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

In the current society, education is really important and the tendency starts to show up that people are trying to get the best education quality that they can. However, in most of the countries it is impossible to get an education for free. That means that if you want to become successful in the today’s society, you will have to start paying money all the way from the first years of getting out of the kinder garden.

The thing which has also become popular among those studying at schools and colleges is learning of the foreign languages. That is a thing which is told to help you a lot in the future if you will have an ability to visit a place abroad. However, people say that even if you will not have that opportunity given to you, you will still be able to learn a lot by studying the second or third foreign language. The main argument is the fact that you will be learning about a new culture, while learning the language. You will find out about the new countries and their cultures when learning some words that do not happen to be real in your home country.

So, how does all of this apply to the topic of the text. Well, we can call many various ways of studying the languages, but one of the oldest and yet the best ways that you will find nowadays is the dictionary method. It has been proven that the method where you learn the new words is not that good for those who are just starting to learn the new language. Yet with the learning of the groups of words, and also the single ones later on in the process of studying, you can easily become pretty fluent in the language you are studying. The other great thing about the dictionary method is the fact that if you add it to the other methods, it will make the learning process way easier. Therefore, such an old and not really efficient method can still exist in the current learning variety.

So, why dictionaries should be free in the current society. Well, that is pretty simple. They are the only way which can be used by poor to learn the new languages. Yet, with the price of some advanced dictionaries, the poorer people are left without a chance to learn something a little over the basics. And many services are already trying to provide help with such works. For example, some volunteer programs are giving out dictionaries to the poor and those in need. For students many various programs exist, which help with their languages. For those looking for a job it is a little harder, as they have no time to actually learn something, because of their look for a job. Therefore, such people should try to use the cover letter writing service in order to save their time and do the stuff they actually need, while they can still study the foreign language a little later.

The other great reason for starting a free distribution of dictionaries is the fact that many foreign tourists come into the new countries with them, and they definitely require some help from the locals at most of their period of staying abroad. And the problem is that many of them do not know the local language or at least English, or the locals might not know how to communicate with the strangers. Moreover, many travellers travel around the world with literally no money, meaning that they would not be able to even get the simplest help from the locals. That brings us to the point where we can say that dictionaries are going to be useful for those travelling on a low budget. It will definitely help the tourists to stay informed in the foreign country and have some help from the people who they are going to be surrounded by. Also, that will help a lot with the getting of new friends. Even if you can communicate well with your friends from abroad, using one of the words from their language will definitely boost the morale of the group, and that will help to keep the nice relations between the friends.

The topic of friendship is actually a great reason to make dictionaries free. People, especially the new generations are going to be able to talk to the people from abroad, which is always good for both of those talking, as they are going to learn a lot of new stuff about each other cultures, and at the same time they will be able to communicate on any of the topics of the interests that both people share. Therefore, we can say that by giving out the free knowledge in general, we can easily create new ties with people all around the world. The other reason is the fact that the companies that print can easily make a portion of dictionaries to be given out for free. They will not lose that much money to care about it. Moreover, they can create a new version of a dictionary to be less advanced, and at the same time with the soft cover, which will decrease the price of producing of such a book way lower, and that will definitely boost the PR of that company and rating in the eyes of people.

To sum everything up, we can say that there is no doubt that dictionaries should be made free, and that will not bring anything bad to any of the sides. However, the modern companies are so scared to lose the money that they would never risk making such a PR move, because it requires some money invested into something which might not bring too many people in. Yet, we all know that free dictionaries will give many people a chance to know much more.

The post Dictionaries should be free appeared first on My Programming Tutorials.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Web notification is a particular message that generates from a website, whenever any update or important message is shared on the app. These messages pop up on your desktop or device even when the respective page is not opened on your current browser.

These push notifications are a great addition to the traditional email and marketing campaigns. As a user is notified with a push notification every time whenever any update is generated and the users just have to click on that to be notified about any update.

Pusher

Pusher is a hosted service that allows web and mobile applications to add real time data to its live functionality. It works as a real time correspondent between the servers and clients. It establishes persistent connections with the clients on HTTP using WebSocket, therefore, whenever your server receives new data, it gets instantly passed on to the respective clients for maintaining live data concurrency.

In order to integrate in all major languages and frameworks, Pusher offers several libraries to achieve the integration, including libraries of PHP, Ruby, Python, Java, .NET, Go and Node for the server, and JavaScript, Objective-C (iOS) and Java (Android) for the client.

Being known as a highly scalable real time solution for apps, Pusher first came to prominence in 2010 and since then it has continued to remain as the top choice for many. The list of its happy customers includes GitHub, MailChimp, CodeShip, The Financial Times, UserVoice, Travis CI and many others.

Pusher Real-time Use Cases

Pusher has a number of common use cases for real-time web technologies including:

  1. Activity Streams
  2. Data Visualisations/Dashboards
  3. Notifications & Signalling
  4. Collaborative Apps
  5. Chat
  6. Multiplayer Games

The simplest use case of Pusher is the real time notifications. Whenever something relevant occurs according to the website user’s journey, it automatically pops up a notification for the event. This is the same functionality we have seen on Twitter, Facebook and in many other social media platforms for years.

Notification can also be seen as a form of signaling, as it does not contains any organized representation in the UI of the application, but still triggers a reaction within an application.

As far as the current social web apps are concerned, it is very common to have interactive real time notifications. We have the examples of Facebook, Twitter and other social networking sites, which support integration of creative built-in notification systems within them. In this regard, Pusher is one of the most used and popular services which helps you incorporate real-time notifications to your apps and helps you make them more lively and interactive.

In this blog, I will demonstrate about how to implement real time notification system using Laravel and Pusher.

Prerequisites

For the purpose of this tutorial, I assume that you have a Laravel application installed on a web server. My setup is:

  • Laravel 5.5
  • Pusher

I have decided to host my Laravel application on PHP MySQL hosting. It has great devstack and is known for its highly secured platform. You can also try out Cloudways for free by signing up for an account

Setup your Pusher Account

After successfully completing Laravel installation, now let’s create a Pusher account to get API key and other necessary credentials.

Setup Pusher in Laravel application

After completing the signup process, carefully note down all the credentials including API key, secret key and others. Then open SSH command interface and write down the following command:

.env
Once the composer finishes its process, you can configure Laravel and Pusher. Open the .env file from the root directory of Laravel app and update its values to the desired ones.

// Get the credentials from your pusher dashboard
PUSHER_APP_ID=XXXXX
PUSHER_APP_KEY=XXXXXXX
PUSHER_APP_SECRET=XXXXXXX

Create Notification Event

First of all, you must create an Event class that could broadcast to Pusher from your live Laravel application. Also remember that you can easily eradicate Events from anywhere in the application.

php artisan make:event Notification

The above-mentioned code will create a new Notification class in the app/Events directory. Open the contents of the file and update as shown below:

<?php

namespace App\Events;

use Illuminate\Queue\SerializesModels;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class Notification implements ShouldBroadcast{
    use Dispatchable, InteractsWithSockets, SerializesModels;
    public $username;
    public $message;

    public function __construct(){
        //your variables
    }

    public function broadcastOn(){
        return ['notification'];
    }
}

In the above-mentioned code, I have created a ShouldBroadcast interface which defines Laravel that the broadcasting of event should be with using whatever driver, which I have configured in the configuration file.

I have also created a constructor which accepts two parameters (username and verb). I have assigned these variables to class properties which also have the same name. Do remember to set the visibility of these properties to public, because they will be ignored if they aren’t set to public.

Lastly, I have set the channel name to broadcast on.

Create Controller

Now let’s create a controller, which will hold notification code logic. Open the SSH command terminal and paste the following command.

.$ php artisan make:controller PusherNotificationController

After successfully creating the controller, paste the following code in controller file.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Pusher\Pusher;

class PusherNotificationController extends Controller{

    public function sendNotification(){
        //Remember to change this with your cluster name.
        $options = array(
            'cluster' => 'ap2',
            'encrypted' => true
        );

        //Remember to set your credentials below.
        $pusher = new Pusher(
            'key',
            'secret',
            'app_id', $options
        );

        $message= "Hello Cloudways";

        //Send a message to notify channel with an event name of notify-event
        $pusher->trigger('notification', 'notification-event', $message);
    }
}

It’s time to add Pusher in the controller. You will have to setup cluster and other credentials like secret key, API etc in your controller as well.

Afterwards, you can publish to a channel and can define a specific name for that channel. For this particular tutorial, I have given channel the name of ‘Notification’, and ‘Notification Event’ as the event name. You can also change these names to any other name according to your preference. Do remember to always use the same channel name and event name in your front end clients.

Setup Route

Now I will show you how to add notification route to the web.php file, which I will use to send notifications using Pusher.

//web.php

Route::get('/notification', 'PusherNotificationController@sendNotification');
Create View

Finally after setting up controller and required routes, now let’s move to create view. Working on welcome.blade.php, paste the below following code in your view file.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Real-time notifications in Laravel using Pusher</title>

</head>
<body>
    <h1>Real-time notifications using Pusher In Laravel</h1>

    <!-- Incldue Pusher Js Client via CDN -->
    <script src="https://js.pusher.com/4.2/pusher.min.js"></script>
    <!-- Alert whenever a new notification is pusher to our Pusher Channel -->

    <script>
        //Remember to replace key and cluster with your credentials.
        var pusher = new Pusher('key', {
            cluster: 'ap2',
            encrypted: true
        });

        //Also remember to change channel and event name if your's are different.
        var channel = pusher.subscribe('notification');
        channel.bind('notification-event', function(message) {
            alert(message);
        });

    </script>
</body>
</html>

Now, let’s open up a new tab and visit www.yourdomain/notification while having the www.yourdomain.dev/welcome open in another tab and you should see the alert!.

To see the alert, open a new tab and visit www.yourdomain/notification while having the www.yourdomain.dev/welcome open on one tab. It will definitely show the alert and hence it will confirm the process mentioned in the preceding paragraphs.

Summing Up

In this blog, I have demonstrated how to implement real time notifications in a Laravel app using Pusher. Because Pusher allows us to add more live functionality to our apps and helps make it more interactive, popular social apps like Facebook and Twitter have live web notifications system integrated in their platform. Hence, using Pusher, we can also implement the same functionality in our apps and can enhance the real time interaction while using them.

If you still have more questions regarding this blog, or you want to contribute more on this topic, do feel free to share your thoughts and comments in the comments section below.

The post Web Notifications Using Laravel and Pusher appeared first on My Programming Tutorials.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

In this tutorial, we are going to learn that how to create infinite scroll pagination with PHP and Ajax.

All of you probably must have seen this feature in some websites that you can load more content by just scrolling down.

It can be possible via AJAX. I hope all of you guys will be familiar with Ajax, if not please see what actually an AJAX is?

Let me show you some live examples of infinite scroll pagination, as you are a regular user of Facebook & Twitter etc. I bet you noticed that they use this kinda pagination. When you scroll down they load more contents on your timeline.

View Demo

In my previous article, I have covered the pagination with PHP and MySql, If you have not read it yet, then I suggest you read that article first. Because the pagination part will be done by PHP itself.

Requirements to create infinite scroll pagination with PHP and Ajax

1. GIF Loader

I have used Preloaders in this article. Preloader provides almost all type of animated GIF Loaders. It is necessary to show a loading process while fetching data asynchronously.

2. A jQuery plugin called Inview

Inview is a JQuery Plugin, which is designed to fire an event as soon as the targeted element appears on the user’s viewport.

You must have JQuery installed in your page to work with Inview. The important thing is, it works only with jQuery 1.8 & upwards. To learn more about Inview, visit Github jquery.inview.

Usage of Inview

$('#target_element_id').on('inview', function(event, isInView) {
    if (isInView) {

        // element is now visible in the viewport

    } else {

        // element has gone out of viewport

    }
});
Let’s dig into actual coding

1. HTML part

<div id="response">

    <!-- response(next page's data) will get appended here -->

</div>

<input type="hidden" id="pageno" value="1">
<img id="loader" src="loader.svg">

Lets split above HTML snippet and see what actually they will perform. So here we have Three elements #response, #pageno & #loader.

#response element would be the container for our fetched data. We will use AJAX request to fetch next page’s data and append it in #response element.

#pageno is a kind of page number counter, we are using it to identify that how much pages have loaded. We have set its default value to “1” so that it loads the first page first.

#loader will be placed at the last of the results as you can see it in the HTML snippet. When the user scrolls down, the Ajax function that will bring the data of the next page will get fired as soon as the #loader comes in the viewport.

2. AJAX JQuery Part

var nextPage = parseInt($('#paegno').val())+1;

$.ajax({
    type: 'POST',
    url: 'pagination.php',
    data: {
        nextPage: nextPage
    },
    success: function(data){
        $('#response').append(data);
        $('#paegno').val(nextPage);
    }
});

Every time when #loader appears in the browser’s viewport then the above Ajax function gets fired and sends a POST request to the pagination.php file.

We are sending a nextPage number along with the POST request so that the pagination.php file can understand which page to load.

When execution of the Ajax function gets finished then pagination.php file returns next page’s data. We need to append that data in our #response element as you can see in the above snippet.

3. PHP part

$pageno = $_POST['pageno'];

$no_of_records_per_page = 10;
$offset = ($pageno-1) * $no_of_records_per_page;

As you can see from here the PHP pagination part has started, as I have suggested earlier you should read my previous article pagination with PHP and MySQL.

The SQL Query for Pagination

$sql = "SELECT * FROM table LIMIT $offset, $no_of_records_per_page";
Let’s assemble the PHP pagination codes

We are going to put all the PHP codes in the pagination.php file, so go ahead and create the pagination.php file and put below codes into it.

<?php

    $pageno = $_POST['pageno'];

    $no_of_records_per_page = 10;
    $offset = ($pageno-1) * $no_of_records_per_page;

    $conn=mysqli_connect("localhost","my_user","my_password","my_db");
    // Check connection
    if (mysqli_connect_errno()){
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
        die();
    }

    $sql = "SELECT * FROM table LIMIT $offset, $no_of_records_per_page";
    $res_data = mysqli_query($conn,$sql);

    while($row = mysqli_fetch_array($res_data)){

        echo '<div>Demo'.$row["id"].'</div>';

    }

    mysqli_close($conn);

?>

so PHP part has been done here.

Let’s assemble the Html and JQuery codes
<!DOCTYPE html>
<html>
<head>
    <title>Infinite Scroll Demo</title>

    <!-- JQuery CDN -->
    <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>

    <!-- Inview Js CDN -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.inview/1.0.0/jquery.inview.js"></script>

    <style>
        #response div{
            border: 1px solid lightgrey;
            height: 80px;
            margin-bottom: 5px;
            padding: 50px 0px 0px 0px;
            text-align: center;
        }
        #loader{
            display: block;
            margin: auto;
        }
    </style>
</head>
<body>

    <div id="response">

        <!-- response(next page's data) will get appended here -->

    </div>

    <input type="hidden" id="pageno" value="1">
    <img id="loader" src="loader.svg">

    <script>

        $(document).ready(function(){

            $('#loader').on('inview', function(event, isInView) {

                if (isInView) {

                    var nextPage = parseInt($('#paegno').val())+1;

                    $.ajax({
                        type: 'POST',
                        url: 'pagination.php',
                        data: {
                            nextPage: nextPage
                        },
                        success: function(data){
                            $('#response').append(data);
                            $('#paegno').val(nextPage);
                        }
                    });

                }

            });

        });

    </script>

</body>
</html>

That’s all folks!!!, If you find this article helpful, don’t forget to share and subscribe us.

The post How To Create Infinite Scroll Pagination With PHP And Ajax appeared first on My Programming Tutorials.

  • Show original
  • .
  • Share
  • .
  • Favorite
  • .
  • Email
  • .
  • Add Tags 

Separate tags by commas
To access this feature, please upgrade your account.
Start your free month
Free Preview