Friday, 14 April 2023

                                   Backend Developers Paradise --> DTL (Django Template Language)

If you're a full stack web developer who's been around the block when it comes to frontend and backend development, you may be feeling a pull towards the backend side of things. However, you may not be too keen on making the shift to JavaScript for fetching APIs. Fear not! There's a powerful tool at your disposal that may just tickle your fancy: the Django template language.

Django is a high-level Python web framework that takes care of a lot of the heavy lifting when it comes to building web applications. It's been around for quite some time and has built up a solid reputation in the development community. One of the key features of Django is its templating system, which allows you to create dynamic web pages using a combination of HTML, CSS, and Python.

The Django template language is a powerful tool that allows you to create complex, dynamic web pages without having to rely on a lot of JavaScript. With its easy-to-use syntax and powerful features, the Django template language is an excellent choice for developers who want to focus on the backend but still want to create stunning, interactive web pages.

So if you're looking to level up your backend game and want to explore a powerful and flexible tool for creating dynamic web pages, then look no further than the Django template language. Whether you're building a small-scale web application or a large-scale enterprise project, Django has got you covered.

Django Template Language (DTL) is a template language that is an integral part of the Django web framework. DTL provides developers with a powerful and flexible way to create dynamic web pages. With its rich set of features, DTL is an excellent choice for developers who want to create high-quality web applications quickly and efficiently.

One of the key advantages of using DTL is that it is easy to learn and use. The syntax of DTL is simple and straightforward, making it accessible to developers of all skill levels. The template tags and filters provided by DTL make it easy to manipulate data and create dynamic content.

Another advantage of using DTL is its modular design. DTL allows you to create modular templates that can be reused across multiple pages. This makes it easy to maintain consistency across your website and reduces the amount of code you need to write.

DTL also provides built-in security features that prevent common web vulnerabilities such as cross-site scripting (XSS) attacks. It also provides protection against SQL injection attacks by automatically escaping any data that is entered into the templates. This makes DTL a popular choice among developers who value security.

DTL is also highly customizable, allowing developers to create their own template tags and filters. This enables them to extend the functionality of DTL to meet their specific needs, which is a valuable feature for developers working on complex projects.

However, there are some limitations to using DTL. It is primarily a template language and does not support complex logic or control structures. While you can use if/else statements and loops, they are limited in their functionality. Additionally, DTL is not designed to work with dynamic content such as real-time updates or live streaming.

Despite these limitations, DTL remains a powerful tool that offers many benefits to web developers. Its ease of use, security, and performance make it a great choice for creating dynamic and engaging web pages that are easy to maintain and customize. For developers looking to create powerful and scalable web applications, DTL is a valuable tool that should not be overlooked.

In conclusion, Django Template Language is a powerful template language that provides a wide range of features and capabilities for web developers. While it has some limitations, these are outweighed by its many advantages, including its ease of use, security, and performance. Whether you are a beginner or an experienced web developer, DTL is a great choice for creating dynamic and engaging web pages that are easy to maintain and customize.

You can start learning about Django and DTL from its official documentation and from the Youtube channel Geeky Shows (It is long but rock-solid playlist available on youtube)

Sunday, 4 December 2022

Learning more will never be a disadvantage

Hello world, 🙏

Every novice in programming get stuck with a basic problem WHICH LANGUAGE DO THEY PREFER? They are advised by the most to not follow C language. They should directly jump into some language supporting OOPs. Well, I disagree here as C language gives you an encapsulated feel of MEMORY architecture which is paramount topic in CS . Also, learning more will never be a disadvantage. It will only act as a boon.

You can read an article by Mario Galindo Queralt related to this topic below which I found on Quora. I am attaching the link of the same below.

Question:  

Why do universities teach C and C++, though they are regarded as the most difficult languages and there are better alternatives? C and C++ aren’t expanding and will be dead in 30 years, but Stanford, Harvard and U Mich use C++ as a primary language.

 

Answer:

You are totally uninformed. C++ is expanding a lot. The latest version is C++17, next year the C++20 version is being issued, the committee is working hard on C++23 and C++26 is scheduled.

You believe that C and C++ will be dead in 30 years. That belief is based entirely on unsubstantiated speculation. If you don't know anything about the present, less can you know about the future.

In spite of that, 30 years of prognosis in the future is a great deal of time for CS. Therefore, it is feasible to consider that everything, yes EVERYTHING, what exists today in CS will somehow be dead in 30 years. Based on this presumption, should you, and everyone, stop studying absolutely everything today?

Stanford and Harvard are among the most important engineering universities in the world. You must trust their teachers when they choose C and C++ as their primary computer languages. Believe me, they know much more than you.

Therefore, if something is difficult for you, I recommend that you study it more, instead of looking for false arguments to modify what is taught in the university. Do not pretend to teach your teachers, it is the other way around, they are the ones who teach and you who learn.

Regards.

Link to read above on Quora:  Why do universities teach C and C++, though they are regarded as the most difficult languages and there are better alternatives? C and C++ aren’t expanding and will be dead in 30 years, but Stanford, Harvard and U Mich use C++ as a primary language. - Quora

Friday, 30 September 2022

Problem Statement : 

Program to Implement two Stacks using a Single Array & Check for                                      Overflow & Underflow

My code:


//Here is my solution to this question in C language

//I have taken the size of array containing STACK 1 and STACK 2 as 10. Readers may change it as per their need


#include <stdio.h>

#include <stdlib.h>

#define size 10

int arr[size];

int top1=-1;

int top2=size;

//push() for STACK 1:

void push_stack_1(int value)

{

    if(top1<top2-1)

    {

        top1=top1+1;

        arr[top1]=value;

    }

    else

    {

        printf("STACK 1 OVERFLOW\n");

    }

}

//push() for STACK 2:

void push_stack_2(int value)

{

    if(top1<top2-1)

    {

        top2=top2-1;

        arr[top2]=value;

    }

    else

    {

        printf("STACK 2 OVERFLOW\n");

    }

}


//pop() for STACK 1:

void pop_stack_1()

{

    if(top1>=0)

    {

        int popped_value=arr[top1];

        top1=top1-1; 

        printf("%d is popped from STACK 1\n",popped_value);

    }

    else

    {

        printf("STACK 1 UNDERFLOW\n");

    }

}


//pop() for STACK 2:

void pop_stack_2()

{

    if(top2<size)

    {

        int popped_value=arr[top2];

        top2=top2+1; 

        printf("%d is popped from STACK 2\n",popped_value);

    }

    else

    {

        printf("STACK 2 UNDERFLOW\n");

    }

}


//Displaying


//display() for STACK 1:

void display_stack_1()

{

    int i;

    printf("The values of STACK 1 in LIFO manner is:\n");

    for(i=top1;i>=0;i--)

    {

        printf("%d\n",arr[i]);

    }

}


//display() for STACK 2:

void display_stack_2()

{

    int i;

     printf("The values of STACK 2 in LIFO manner is:\n");

    for(int i=top2;i<size;i++)

    {

        printf("%d\n",arr[i]);

    }

}



 int main()  

{  

  int arr[size];  

  int i;  

  int num_of_ele;  

   

  printf ("We can push a total of 10 values\n"); 

  printf("-----------------------------------------------------------");

printf("\n"); 

   

  //Number of elements pushed in stack 1 is 5 

  //Number of elements pushed in stack 2 is 5 

   

// loop to insert the elements into Stack1    

for (i = 1; i <= 5; i++)  

  {  

    push_stack_1(i);  

    printf ("Value Pushed in Stack 1 is %d\n", i);  

  }  

 printf("-----------------------------------------------------------");

printf("\n");  

// loop to insert the elements into Stack2.    

for (i = 6; i <= 10; i++)  

  {  

    push_stack_2(i);  

    printf ("Value Pushed in Stack 2 is %d\n", i);  

  }  

   

  //Print Both Stacks  

 display_stack_1(); 

 printf("-----------------------------------------------------------");

printf("\n"); 

 display_stack_2 ();  

   

  //Pushing on Stack Full  

  printf ("Pushing Value in Stack 1 is %d\n", 11);  

  push_stack_1 (11); 

  printf ("Pushing Value in Stack 2 is %d\n", 110);  

  push_stack_2 (110);   

printf("-----------------------------------------------------------");

printf("\n");

  //Popping All Elements from Stack 1  

  num_of_ele = top1 + 1;  

  while (num_of_ele)  

  {  

    pop_stack_1 ();  

    num_of_ele--;  

  }  

printf("-----------------------------------------------------------");

printf("\n");

num_of_ele = top2 + 1;  

  while (num_of_ele)  

  {  

    pop_stack_2 ();  

    num_of_ele--;  

  }  

    

  // Trying to Pop the element From the Empty Stack  

printf("-----------------------------------------------------------");

printf("\n");

printf("Trying to Pop the element From the Empty Stack 1\n");

pop_stack_1 ();   

printf("-----------------------------------------------------------");

printf("\n");

printf("Trying to Pop the element From the Empty Stack 2\n");

pop_stack_2 ();   

return 0;  

} 

Tuesday, 9 August 2022

 

'''
problem--
Given a time in 12-hour AM/PM format, convert it to military (24-hour) time.
Note: Midnight is 12:00:00AM on a 12-hour clock, and 00:00:00 on a 24-hour clock. Noon is 12:00:00PM on a 12-hour clock, and 12:00:00 on a 24-hour clock.
Function Description--
Complete the timeConversion function in the editor below. It should return a new string representing the input time in 24 hour format.
timeConversion has the following parameter(s):
s: a string representing time in 12 hour format
Input Format--
A single string containing a time in 12-hour clock format (i.e.:hh:mm:ssAM or hh:mm:ssPM) ,where 00<=hh<=12 and 00<=mm,ss<=59.
Constraints--
All input times are valid
Output Format--
Convert and print the given time in 24-hour format, where 00<=hh<=23.
Sample Input 0--
07:05:45PM
Sample Output 0--
19:05:45
'''
# Here is my solution to the question given in HackerRank site
s=input()
time=""
if (s[8:10]=='AM' and int(s[0:2]+s[3:5]+s[6:8])<=116059):
    time=s[0:8]
    print(time)

elif (s[8:10]=='AM' and int(s[0:2]+s[3:5]+s[6:8])>=120000 and int(s[0:2]+s[3:5]+s[6:8])<=126059):
    #time=str(int(s[0:2])-12)+'0'+s[2:8]  
    time=str(int(s[0:2])-12)+'0'+s[2:8]
    print(time)

elif (s[8:10]=='PM' and int(s[0:2]+s[3:5]+s[6:8])>=120000 and int(s[0:2]+s[3:5]+s[6:8])<=126059):
    time=s[0:8]
    print(time)


else:
    time=str((int(s[0:2]))+12)+s[2:8]
    print(time)
    






Good thoughtful question on Binary search on answers

Problem link:  https://leetcode.com/problems/maximize-score-of-numbers-in-ranges/description/ Solution: //import java.util.Arrays; class So...