Skip to main content

Posts

JS: Cheatsheet

   Datatypes Difference Between Var, Let and Const Functions and its types Asynchronous operations in JS

React: Print Specific Section of the page with - ReactToPrint

  Want to know how can you easily print specific section of your website just follow the steps below and I am sure you will find this pretty easy. There is no rocket science to crack it you just need basic code knowledge only. Step 1: Add the ReactToPrint in your project    npm install --save react-to-print Step2: Add the following code in your component   import React, { useRef } from 'react'; import ReactToPrint from 'react-to-print'; const Example = () => {      const componentRef = useRef();      return (           <div>                <ReactToPrint                     trigger={() => <button>Print this out!</button>}                     content={() => componentRef}    ...

React: Remember me functionality with React

Want to know how can you easily integrate Remember me on your website just follow the steps below and I am sure you will find this pretty easy. There is no rocket science to crack it you just need basic code knowledge only. Step 1: Add the react-cookie in your project    npm install react-cookie Step2: Add the following code in index.js import { CookiesProvider } from "react-cookie"; ReactDOM.render(      <CookiesProvider>           <App />      </CookiesProvider>,      document.getElementById('root') ); Step3: Add the following code in your component    import React, { useState } from 'react'; import { useCookies } from 'react-cookie'; const App = () => { const [name, setName] = useState(''); const [pwd, setPwd] = useState(''); const [cookies, setCookie] = useCookies(['user']); const handle = () => {      setCooki...

WP: 8. Dynamically show post taxonomies and their data in tab format [Solved]

    Today I ran into a problem, I need to dynamically show post taxonomies and their data in tab format and found this solution. And nonetheless, It's better to fix the thing with some bunch of code rather than uploading one more bulky plugin on your website that will end up making your site heavy. Just follow the steps below and avoid heading up into any malicious or bulky plugin for this particular problem from now on forever. Step 1: Get the taxonomies terms first <?php     $terms = get_terms( array(       'taxonomy' => 'off_plan_categories',       'hide_empty' => true,     ) );     // echo '<pre>';     // print_r($terms);     // die; ?> Step 2:  Execute loop first for tab navigation <nav id="offPlanPropertyTabs" class="offplan-property-type-tabs nav nav-tabs"> <?php foreach($terms as $key => $term): ?>   <button class="nav-item nav-link <?php...

WP: 7. Control Tab on frontend with ACF[Solved]

    Today I ran into a problem, I needed to implement tabs on the front end with ACF dynamically and found this solution. And nonetheless, It's better to fix the thing with some bunch of code rather than uploading one more bulky plugin on your website that will end up making your site heavy. Just follow the steps below and avoid heading up into any malicious or bulky plugin for this particular problem from now on forever. Step 1: Execute loop first for tab navigation <?php $i=1; while(have_rows('data')) : the_row(); ?>   <button class="nav-item nav-link <?php if($i==1){echo "active";}?>" data-bs-toggle="tab" data-bs-target="#tab <?php echo $i;$i++;?> "> <h3 class="s-floorplan__tabs__title"><?php the_sub_field('tab_title'); ?></h3> <p class="s-floorplan__tabs__text"><?php the_sub_field('tab_sub_title'); ?></p>   </button> <?php ...

WP: 6. Related post loop by excluding the current post in single.php

   Today I ran into a problem, I need to implement a related post on the blog detail page and found this solution. And nonetheless, It's better to fix the thing with some bunch of code rather than uploading one more bulky plugin on your website that will end up making your site heavy. Just follow the steps below and avoid heading up into any malicious or bulky plugin for this particular problem from now on forever. Step 1: Get the id of current post in starting of single.php like following <?php $do_not_duplicate = $post->ID; ?> Step 1: Now in your related post query add the following <?php $args = array( 'post_type' => 'post', 'posts_per_page' => 3, 'post__not_in'   => array( $do_not_duplicate ), 'order' => 'ASC', ); $related_query = new WP_Query($args);               while ( $related_query->have_posts() ): $related_query->the_post(); ?> Now Cheers !😊

WP: 5. Guide to Implement Next Previous Post Navigation in WP

  Today I ran into a problem, I need to implement to post previous and next navigation and found this solution. And nonetheless, It's better to fix the thing with some bunch of code rather than uploading one more bulky plugin on your website that will end up making your site heavy. Just follow the steps below and avoid heading up into any malicious or bulky plugin for this particular problem from now on forever. Step 1: Go ahead and paste the following code in your active theme's single.php //To return the URL of the previous page, use the following php code: $prev = get_permalink(get_adjacent_post(false,'',false)); //To return the URL of the next page, use the following php code: $next = get_permalink(get_adjacent_post(false,'',true)); //To use them, simply echo the variables $prev and $next where you need them. <a href="<?php echo $prev; ?>">Previous Post</a> and the  <a href="<?php echo $next; ?>">Next Post...

Brought up your Website's Google Page Speed upto 90+

 Hi Guys, If you are running or developing a website you may encounter low Google page speed, So let's dig deeper into the technical guide of Google Page Speed Insights to ensure a good score. Google defines page speed in two ways: How long it takes to display content above the fold. How long it takes a browser to fully render the page. The tool has two main things: Field Data,” or the performance data Second, it measures your page performance via the Lighthouse API. This is called “Lab Data” Field Data  or  Core  Web Vitals : First Contentful Paint (FCP): The time it takes for the first text or image asset to load. Largest Contentful Paint (LCP): The time it takes for the largest text or image asset to load. First Input Delay (FID): The time it takes for the browser to respond to the user’s first interaction. Cumulative Layout Shift (CLS): This measures any movement of the page in the viewport. Lab Data  : Speed Index:  The time it takes for the conten...

Error: Ensure text remains visible during webfont load [Resolved]

 Hi Guys, If you are running or developing a website you may encounter this error on Google page speed or GtMetrix, We should consider the following approach to get rid of this error. Suggestion 1: Load the fonts from your server, Even if you are using google fonts you should download and host it on your server.   Suggestion 2:  Use the font-display: swap CSS property while implementing custom fonts, this means the system default fonts will be loaded first and then the custom font is visible, hence text will remain visible.

C++: 9. File Handling

Files are used to store data in a storage device permanently. File handling provides a mechanism to store the output of a program in a file and perform various operations on it. Example of opening/creating a file    #include<iostream> #include<fstream> using namespace std; int main() { fstream new_file; new_file.open("new_file",ios::out); if(!new_file) { cout<<"File creation failed"; } else { cout<<"New file created"; new_file.close(); // Step 4: Closing file } return 0; } Writing to a File #include <iostream> #include <fstream> using namespace std; int main() { fstream new_file; new_file.open("new_file_write.txt",ios::out); if(!new_file) { cout<<"File creation failed"; } else { cout<<"New file created"; new_file<<"Learning File handling"; //Writing to file new_file.close(); ...

C++: 8. Polymorphism

Polymorphism is an important concept of object-oriented programming. It simply means more than one form. That is, the same entity (function or operator) behaves differently in different scenarios. Function Overloading in C++ In C++, two or more functions can have the same name if the number and/or type of parameters are different, this is called function overloading. Example:-  #include <iostream> using namespace std; int add(int a, int b) {     return a+b; } int add(int a, int b, int c) {     return a+b+c; } double add(double a, double b) {     return a+b; } int main() {   int x = 3, y = 7, z = 12;   double n1 = 4.56, n2 = 13.479;   cout<<"x+y = "<<add(x,y)<<endl;   cout<<"x+y+z = "<<add(x,y,z)<<endl;   cout<<"n1+n2 = "<<add(n1,n2);   return 0; } Output:-  x+y = 10 x+y+z = 22 n1+n2 = 18.039 Function Overriding in C++ When a member function of a base class is redef...

C++: 7. Inheritance

In C++, inheritance is a process in which one object acquires all the properties and behaviors of its parent object automatically. In such way, you can reuse, extend or modify the attributes and behaviors which are defined in other class. In C++, the class which inherits the members of another class is called derived class and the class whose members are inherited is called base class. The derived class is the specialized class for the base class. Single Level Inheritance When one class inherits another class, it is known as single level inheritance. Example:-  #include <iostream>   using namespace std;    class Account {      public:      float salary = 60000;     };      class Programmer: public Account {      public:      float bonus = 5000;        };        int main(void) {   ...

C++: 6. Constructors

A constructor is a special type of member function that is called automatically when an object is created. In C++, a constructor has the same name as that of the class and it does not have a return type. C++ Default Constructor A constructor which has no argument is known as default constructor. It is invoked at the time of creating object. Example:-  #include <iostream>   using namespace std;   class Employee    {      public:           Employee()             {                 cout<<"Default Constructor Invoked"<<endl;             }     };   int main(void)    {       Employee e1; //creating an object of Employee        Employee e2;        return 0;   }  ...

C++: 5. Friend function

If a function is defined as a friend function in C++, then the protected and private data of a class can be accessed using the function. By using the keyword friend compiler knows the given function is a friend function. For accessing the data, the declaration of a friend function should be done inside the body of a class starting with the keyword friend. Syntax:- class class_name     {         friend data_type function_name(argument/s);            // syntax of friend function.   };     Example:-  #include <iostream>     using namespace std;     class Box     {         private:             int length;         public:             Box(): length(0) { }             friend int printLength(Bo...

C++: 4. Array of Objects

You can store objects of user defined datatype in a C++ Array. To store objects of user defined datatype in an array, you can declare an array of the specific type and initialize the array Advantages of Array of Objects: The array of objects represent storing multiple objects in a single name. In an array of objects, the data can be accessed randomly by using the index number. Reduce the time and memory by storing the data in a single variable. Example:-  // C++ program to implement // the above approach #include<iostream> using namespace std;   class Employee {   int id;   char name[30];   public:       // Declaration of function   void getdata();       // Declaration of function   void putdata(); };   // Defining the function outside // the class void Employee::getdata() {   cout << "Enter Id : ";   cin >> id;   cout << "Enter Name : ";   cin >> name; }   // Def...

C++: 3. Scope resolution operator

The scope resolution operator ( :: ) is used for several reasons. For example: If the global variable name is same as local variable name, the scope resolution operator will be used to call the global variable. It is also used to define a function outside the class To access a global variable when there is a local variable with same name: #include <iostream>   using namespace std;   // declare global variable   int num = 50;   int main ()   {   // declare local variable    int num = 100;   // print the value of the variables   cout << " The value of the local variable num: " << num;   // use scope resolution operator (::) to access the global variable    cout << "\n The value of the global variable num: " << ::num;    return 0;   }   Output:-  The value of the local variable num: 100 The value of the global variabl...

C++: 2. OOPs Concepts

; OOP stands for Object-Oriented Programming.  As the name suggests uses objects in programming. Object means a real word entity such as pen, chair, table etc. Object-Oriented Programming is a methodology or paradigm to design a program using classes and objects. It simplifies the software development and maintenance.  Object-oriented programming aims to implement real-world entities like inheritance, hiding, polymorphism, etc in programming. Class It is a user-defined data type, which holds its own data members and member functions, which can be accessed and used by creating an instance of that class. Object Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike etc. It can be physical and logical. Object-oriented programming has several advantages OOP is faster and easier to execute OOP provides a clear structure for the programs OOP helps to keep the C++ code DRY "Don't Repeat Yourself", and makes the code easier to...

Py: 14. Python GUI

Python provides the standard library Tkinter for creating the graphical user interface for desktop-based applications. Developing desktop-based applications with python Tkinter is not a complex task. An empty Tkinter top-level window can be created by using the following steps. Exercises:-  Write a py program to create a window with a simple message. Write a py program to demonstrate Grid. Write a py program to generate a button. Write a py program to take user input in GUI format. Write a py program to perform arithmetic operation in GUI format.

Py: 13. Quiz Implementation

  Just looking for another "Real Life Problem" basic problem that can be automated and here I got an idea to make a basic quiz system, The program takes user choices and calculates the total based on the user inputs. Excited, Let's Start, Step 1:  Just Copy paste the code below in a file and save it with extension .py def quiz():     print("This is a simple gk quiz, Here you will get 4 marks for right answer and -1 mark for wrong answer.")     name=input("please enter your name: ")     print("*",name,"*welcome in the quiz:")     print("Q1. What is the height of Qutub minar?")     first_question=input("A. 82 m \nB. 73 m:\n")     if first_question=='B':         number=0         print('Correct answer')         number=(number+4)         print("YOUR SCORE: ",number)     else:         print('Wrong answer')   ...

C++: 1. Introduction

C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. C++ is a MUST for students and working professionals to become a great Software Engineer. Why to Learn C++ C++ is very close to hardware, so you get a chance to work at a low level which gives you lot of control in terms of memory management, better performance and finally a robust software development. C++ programming gives you a clear understanding about Object Oriented Programming. C++ really teaches you the difference between compiler, linker and loader, different data types, storage classes, variable types their scopes etc. Application of C++ Application Software Development  Programming Languages Development Games Development Computation Programming How to Use Use any one of the link to directly see it in action in your browser:- https://www.programiz.com/cpp-programming/online-compiler/ https://www.tutorialspoint.com/compile_cpp_online.php https://www.onlinegdb.com/o...