Category: technology

Excel Spreadsheet add value in cells/columns based on a condition from another cells/column

The function SUM in Excel is quite useful to add values in a column. But this one is not useful when we have to count the values based on a criteria that should satisfy in another column.

For Example we have a scenario where we have to count items cost that are delivered and undelivered and Grand Total. To get the Grand Total we can use sum function directly. But to count total price which are delivered and undelivered we have to use the sumif function. Look at below screenshots.

To calculate all items Total:

To calculate Items that are delivered:

To calculate Items that are undelivered

This is how it looks finally

Perl and Python program syntactic differences

If you know Perl Programming then learning Python is not that hard. But many times we would be confusing Perl syntax for Python and might get into trouble while writing Python code. So here I am listing some differences that I know and will keep adding as I knew it.

Variable names

In Perl we would save a variable like $my_variable/@my_varibale etc, but in Python we just can write the names nothing else needed.

Regex Substituion

In Perl we write $in=~s/to/too/g; In Python it is in = re.sub(r'to', 'too', in). Note the difference? In Perl substituion happens in same variable in Python we explicitly need to specify in which variable we are saving the substitution. To replicate the Perl code we have saved in same variable.

Modules

In Perl to import modules we write as use 'modulename' in Python we write as import re. To install module in Perl we have cpan and in Python we use Pip to install modules.

Hash/Dictionary usage

In Perl to assign value to a key we write as $hash{$key} = $value in Python we write as hash[key] = value

Code Indendataion

Perhaps this is the major difference between Python and many other major programming languages. In Perl we have to use curly braces to enclose a block of code into a function/loop/if-else-block in Python we need to indent properly. Also no semicolons are needed to tell the compiler that it is the end of the line we need to just press enter after a line of code. This allows code to look very readable.

పాట మర్చిపోయారా? ట్యూన్ మాత్రమే గుర్తుందా.. అయితే ఇది మీ కోసమే.

మీరు ఏదైనా పాట రాగం తప్ప ఇంకా ఏం గుర్తు లేకపోతే మీ మొబైల్ తీసి ” హే గూగుల్ ‍వాట ఈస్ డిస్ సాంగ్” అని అడిగితే గూగుల్ మీకు ఇట్టే చెప్పేస్తుంది.

చాలా బాగుంది కదా. ” హే గూగుల్ ‍వాట ఈస్ డిస్ సాంగ్” లేదా “సెర్చ్ ఏ సాంగ్” మీటని నొక్కండి. తరువాత “ఉఊఆఅఅఅఅఅఅ….” సాగరసంగమం సినిమాలో కమల్ హాసన్ లాగా పాడితే సరిపోతుంది. శృతి తప్పినా పర్లేదు అనుకోండి. అలా చేసిన వెంటనే మీకు కొన్ని పాటలు వేతికి మీ ముందు ఉంచుతుంది.

నాకు రోబో సినిమాలో చూపించిన “ఇది ఏ రాగం”? అని ఒక పెద్దాయన చిట్టని అడిగిన సందర్బం గుర్తుతెచ్చంచి. అప్పుడు నేనైతే అస్సలు అనుకోలేదు ఇలా అవుతుందని. ఇప్పడు అవుతుంది కూడా.

If you forgot a song and is stuck in your head, just hum to find or search that song.

Google Assistant has now rolled out a new feature where you can just hum the song for 10-15 seconds and Google will try to show relevant items it found.

This gets to me to the memory of the movie Rajinikanth’s Robo first part where a person asks the robo to identify the song and it does and corrects the person too. Now this is a reality in Google Assistant.

Sounds pretty cool right. Here’s how you can do it.

Open Google Assistant “Hey Google” or “Okay Google”

Then say “What’s this song”? Or you can even click the “Search a song” button.

Now you can hum the tune for 10-15 seconds.

Your pitch need not be perfect, but for accurate results you might need to be a bit closer to perfect.

Then Google will show you relevant songs it found and show it you.

I found a video just showing how you can do that.

PHP calling a POST request API using CURL

In this article we will see how can we call a post request using CURL. This curl request can send post data/json post data, disable SSL verification of host(when you call https), also you can send a Authorization Bearer token a secret shared by your API host.

Pre-Requisites: Install php-curl. Choose the below command according to your PHP Version.

sudo apt install php5-curl 
sudo apt install php7.0-curl

Now lets suppose we are having an API call that just does some function with the string you pass to it.

Now lets write the code.

<?php

#get the required variables
$slang = 'eng';
$tlang = 'hin';
$str = "Hello. How are you?";
#$token = 'LongsecretstringsharedbyyourAPIhost"

#parameters
$data = array("source_language"=>$slang, "target_language"=>$tlang, "text"=>$str);

#set the header type if you want to send json response
header('content-type: application/json');

#calling api here, replace with your URL
$ch = curl_init("http://getAPI/request/");
curl_setopt($ch, CURLOPT_POST, true);

#comment below line if you are not sending data as JSON
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_PROXY, '');

#set  headers, remove authorization if you are not using one
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Authorization: Bearer '.$token));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

#comment below line if you don't want to SSL Verification to false
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

#execute the curl request 
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
//echo 'Operation completed without any errors';
}
// Close handle
curl_close($ch);

#send response
echo $response;

With the above code you can call any API you want to and configure the CURL request as per your requirements.