Sunday, 8 May 2022

python private methods, how it differs with public methods best practices

In Python, private methods are methods that are intended to be used only within the class in which they are defined. Private methods are defined by prefixing the method name with two underscores (__) at the beginning of the method name.

Here is an example of a private method in Python:

class MyClass:

    def __init__(self, value):

        self.__value = value


    def __private_method(self):

        print("This is a private method.")


    def public_method(self):

        self.__private_method()


Read more »

Labels: , ,

Monday, 27 January 2025

Perl Built-ins Quick Reference

1. String Functions

length

Returns the length of a string.

my $str = "Hello, World!";
my $len = length($str);
print "Length: $len\n";  # Output: Length: 13

substr

Extracts a substring from a string.

my $str = "Hello, World!";
my $sub = substr($str, 0, 5);
print "Substring: $sub\n";  # Output: Substring: Hello

index

Returns the position of a substring within a string.

my $str = "Hello, World!";
my $pos = index($str, "World");
print "Position: $pos\n";  # Output: Position: 7

rindex

Returns the last position of a substring within a string.

my $str = "Hello, World! World!";
my $pos = rindex($str, "World");
print "Last Position: $pos\n";  # Output: Last Position: 14

uc

Converts a string to uppercase.

my $str = "Hello, World!";
my $uc_str = uc($str);
print "Uppercase: $uc_str\n";  # Output: Uppercase: HELLO, WORLD!

lc

Converts a string to lowercase.

my $str = "Hello, World!";
my $lc_str = lc($str);
print "Lowercase: $lc_str\n";  # Output: Lowercase: hello, world!

ucfirst

Converts the first character of a string to uppercase.

my $str = "hello, world!";
my $ucfirst_str = ucfirst($str);
print "Ucfirst: $ucfirst_str\n";  # Output: Ucfirst: Hello, world!
Read more »

Labels:

Saturday, 11 March 2023

How to Build an Authentication API with JWT Token in Perl

Hi, In many web applications, user authentication is a critical feature that allows users to securely log in and access their data. One common approach to implementing authentication is to use JSON Web Tokens (JWT), which are a type of token-based authentication that can be used across multiple domains and platforms.

In this tutorial, we will show you how to build an authentication API with JWT token in Perl. We will be using the Mojolicious web framework, which is a powerful and flexible framework that makes it easy to build web applications in Perl.

Read more »

Labels: , , ,

Saturday, 15 March 2025

How will you ensure communication between containers in Docker?

In the world of containerization, Docker has become a cornerstone for building, shipping, and running applications. One of the key challenges developers face when working with Docker is ensuring seamless communication between containers. Whether you’re building a microservices architecture, a distributed system, or a simple multi-container application, effective inter-container communication is crucial for the success of your project.

This blog post will delve into the various methods and best practices for ensuring communication between containers in Docker. We’ll explore the underlying concepts, tools, and techniques that make inter-container communication possible, and provide detailed examples to help you implement these strategies in your own projects.

Table of Contents

  1. Introduction to Docker and Container Communication
  2. Understanding Docker Networking
    • Default Docker Networks
    • User-Defined Networks
  3. Methods for Container Communication
    • Using Docker Networks
    • Linking Containers
    • Using Docker Compose
    • Exposing Ports
    • Using Service Discovery
  4. Best Practices for Container Communication
  5. Advanced Techniques
    • Overlay Networks for Multi-Host Communication
    • Using Docker Swarm for Orchestration
    • Integrating with Kubernetes
  6. Common Pitfalls and How to Avoid Them
Read more »

Labels:

Wednesday, 9 March 2022

what are python private variables its best practices?

Python, private variables are variables that are meant to be used only within the class in which they are defined. Private variables are defined by prefixing the variable name with two underscores (__) at the beginning of the variable name.

For example, if you have a class called Person and you want to define a private variable called __age, you would write:

class Person: def __init__(self, name, age): self.name = name self.__age = age


Read more »

Labels: , ,

Monday, 13 June 2022

python @ decorators, how it differs with generators its best practices

Decorators and generators are both powerful features in Python, but they serve different purposes.

A decorator is a function that takes another function as input and returns a new function that usually modifies the behavior of the original function in some way. Decorators are commonly used for adding functionality to existing functions, such as caching, logging, or authentication.

Read more »

Labels: , ,

Friday, 2 October 2020

write 1000 uniq perl interview questions and answers to master in perl - part1

  1. Q: In Perl, what does the sigil $_ represent?

    A: In Perl, the sigil $_ represents the default argument to a subroutine. It is a global variable that is set automatically by Perl whenever a subroutine is called.

  2. Q: In Perl, what does the backslash \ do in front of a variable name?

    A: In Perl, the backslash \ in front of a variable name is used to force a string interpretation of the variable, rather than a numeric interpretation. This can be useful when working with non-numeric variables, or when you want to avoid potential side effects caused by Perl's built-in operations on numbers

Read more »

Labels:

Monday, 21 April 2025

How to Iterate Over a Range of Numbers Defined by Variables in Bash

When working with Bash, iterating over a range of numbers is common in scripting. One might naturally reach for brace expansion (e.g., {1..5}) when the range is hardcoded, but things get a bit trickier when the range is defined by variables. In this blog post, we’ll explore different ways to iterate over a range of numbers when the endpoints are determined by variables.

Read more »

Labels: