Monday, 21 November 2022

Understanding Differences in Behavior of Process.join() in Windows 10 and Ubuntu 18.04 in Python 3.6

When it comes to multi-processing in Python, developers often run into differences in behavior between different operating systems. One such difference is in how Windows 10 and Ubuntu 18.04 handle the Process.join() function. In this article, we will explore this difference in behavior and understand what accounts for it.

Read more »

Labels: , ,

Friday, 13 June 2025

Understanding select_related and prefetch_related in Django ORM

 When working with Django ORM, optimizing database queries is crucial for performance, especially when dealing with related objects. Django offers two methods, select_related() and prefetch_related(), which are designed to reduce the number of database hits when fetching related data. But what exactly is the difference between these two methods, and when should you use each? Let’s dive deeper into their functionalities.

What is select_related?

The select_related() method is designed to work with foreign-key relationships. It performs an SQL join and retrieves data in a single query. This is highly efficient when you need to fetch related objects in one-to-one or foreign-key relationships because it avoids making multiple queries to the database.

When you use select_related(), Django generates a JOIN clause in the SQL query. This means that the related object’s data is fetched along with the original query, reducing the number of queries executed.

Read more »

Labels:

Saturday, 5 October 2019

how many ways string concatenation in perl?

Method 1:

$v='a';
print "$v$v$v";


Method 2:

print "a"."string"."c";


Method 3:

$v='a';
print "a".$v."c";


Method 4:

$v='a';
print "$v".$v.$v;


Method 5:

$v='a';
print  join "", "/home/$v.txt";


Method 6:

$v='a';
print  join "", "/home/".a.".txt";


Method 7:

$v='a';
print  join "", "/home/$v.txt";


Method 8:

$v='a';
print  join "", "/home/${v}.txt";


Method 9:

print join('', 'AA',$var1, 'BB', $var2, 'CC');


Method 10:

print sprintf("%sAA%sBB%sCC%s", $var1, $var2);


Method 11:

$s .= $_ for ($v,$v,$v);
print $s;


Method 12:

@vars = ($v,$v,$v);
print join "",@vars;


Method 13:

push @str, $v, $v, $v;
print join '', @str;


Method 14:

@var = ($v,$v,$v);
$s = "@var";
print $s;


Method 15:

undef $";
print "@{[$v,$v,$v]}";


Method 16:

$v='a';
print join(' AA ',sprintf("%s%s", $v, $v),sprintf("%s%s", $v, $v),sprintf("%s%s", $v, $v));




For More Methods Reach Me:@ letscrackperlinterviewblogspot@gmail.com  

Thursday, 21 October 2021

write 1000 uniq perl interview questions and answers to master in perl part 2

 251. Q: In Perl, how can you find the position of a substring within a string?

1A: In Perl, you can find the position of a substring within a string by using the `index` function. Here is an example: 2 3```perl 4use strict; 5use warnings; 6 7my $string = 'Hello, World! World is beautiful.'; 8my $substring = 'World'; 9 10my $position = index $string, $substring; 11 12if ($position == -1) { 13 print "The substring was not found in the string.\n"; 14} else { 15 print "The substring was found at position: $position\n"; 16} 17``` 18 19In this example, the script finds the position of the substring `'World'` within the string `'Hello, World! World is beautiful.'` and prints the resulting position.

Read more »

Labels:

Sunday, 21 April 2024

Migrating Kafka Producers/Consumers to Use CompletableFuture in Spring-Kafka

 

When upgrading from older versions of Spring to Spring-Kafka 3.1 or later, developers must adapt their code to accommodate changes in asynchronous handling mechanisms. One significant shift is the migration from ListenableFuture to CompletableFuture. In this post, we’ll explore how to replace ListenableFuture with CompletableFuture in a Kafka producer and consumer scenario, ensuring backward compatibility and leveraging the new API’s capabilities.

Read more »

Labels:

Friday, 21 June 2024

How to Write a Select Query Retrieving Values from Two Tables in ServiceNow

If you’re new to ServiceNow but familiar with SQL, you might find it challenging to translate SQL JOIN queries into ServiceNow’s GlideRecord queries. ServiceNow has its own way of handling data relationships, which can be different from traditional SQL but is equally powerful. In this post, we’ll explore how to retrieve values from two tables in ServiceNow, similar to how you would with SQL JOINs.

Read more »

Labels:

Tuesday, 22 April 2025

How prefetch_related and Other Optimization Techniques Work in Django ORM

Django’s Object-Relational Mapper (ORM) is one of its most powerful features, allowing developers to interact with databases using Python code instead of writing raw SQL queries. However, as your application grows, inefficient database queries can become a bottleneck. This is where optimization techniques like prefetch_related, select_related, and others come into play.

In this blog post, we’ll dive deep into how Django ORM works, explore the differences between prefetch_related and select_related, and discuss other optimization techniques to make your Django application faster and more efficient.

Table of Contents

  1. Introduction to Django ORM
  2. The N+1 Problem
  3. Understanding select_related
  4. Understanding prefetch_related
  5. When to Use prefetch_related vs select_related
  6. Other Optimization Techniques
    • only() and defer()
    • annotate() and aggregate()
    • values() and values_list()
  7. Best Practices for ORM Optimization
  8. Conclusion
Read more »

Labels:

Friday, 5 August 2022

Given the input string 'hello boss!,where are you?,"how, are you!",hi,"di chellam","welcome"' our objective is to design a Perl program that intelligently separates and extracts each individual word from the CSV-like structure. The complexity lies in correctly handling quoted content containing commas.

CODE:

use strict;
use warnings;
my $input_string = 'hello boss!,where are you?,"how, are you!",hi,"di chellam","welcome"';

# Initialize empty array to store extracted words
my @words = ();

# Use a while loop with a regex to extract words
while ($input_string =~ /((?:(?<=,)|^)\s*"[^"]*"\s*(?=,|$)|[^,]*),?/g) {
    my $word = $1;
    # Remove leading and trailing spaces
    $word =~ s/^\s+|\s+$//g;\
    # Check if the word is quoted

    if ($word =~ /^\"(.*)\"$/) {
        # Extract the word without the quotes
        my $quoted_word = $1;
        # Add the word to the array
        push @words, $quoted_word;
    } else {
        # Add the word to the array
        push @words, $word;
    }
}

# Print the extracted words
print join("\n", @words), "\n";
Read more »

Labels: ,