code-rag-bench/online-tutorials huggingface dataset:
GATE CS 2012 - GeeksforGeeks

11 Oct, 2021
BCNF is a stronger version 3NF. So every relation in BCNF will also be in 3NF.
No choice
Choice A
Choice A
Choice B No choice
Program gives no output as it is erroneous
int main()
{
    char inchar = 'A';
    switch (inchar)
    {
    case 'A' :
        printf ("choice A \n") ;
    case 'B' :
    {
        printf ("choice B") ;
        break;
    }
    case 'C' :
    case 'D' :
    case 'E' :
    default:
        printf ("No Choice") ;
    }
}
Assuming P != NP, which of the following is true ?
(A) NP-complete = NP
(B) NP-complete  P = 
(C) NP-hard = NP
(D) P = NP-complete

The answer is B (no NP-Complete problem can be solved in polynomial time). Because, if one NP-Complete problem can be solved in polynomial time, then all NP problems can solved in polynomial time. If that is the case, then NP and P set become same which contradicts the given condition.
(A) 

(B) 

(C) 

(D)  
= XY’+XY
= X(Y’+Y)
= X *1
= X 
Column x = f(x,y) 
So , 
f(x,y)=x 

fork();
fork();
fork(); 
  fork ();    // Line 1
  fork ();   // Line 2
  fork ();   // Line 3

       L1       // There will be 1 child process created by line 1
    /     \
  L2      L2    // There will be 2 child processes created by line 2
 /  \    /  \
L3  L3  L3  L3  // There will be 4 child processes created by line 3
Consider the function f(x) = sin(x) in the interval [π/4, 7π/4]. The number and location(s) of the local minima of this function are 
One, at π/2
One, at 3π/2
Two, at π/2 and 3π/2
Two, at π/4 and 3π/2
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Comments
Old Comments
Must Do Coding Questions for Product Based Companies
Microsoft Interview Experience for Internship (Via Engage)
Difference between var, let and const keywords in JavaScript
Array of Objects in C++ with Examples
How to Replace Values in Column Based on Condition in Pandas?
C Program to read contents of Whole File
Hash Functions and list/types of Hash functions
How to Replace Values in a List in Python?
Spring - REST Controller
How to Read Text Files with Pandas?
SELECT where row value contains string in MySQL?

To select the row value containing string in MySQL, use the following syntax.
SELECT *FROM yourTableName where yourColumnName like ‘%yourPattern%’;
To understand the above syntax, let us first create a table. The query to create a table is as follows.
mysql> create table PatternDemo
-> (
-> Id int,
-> Name varchar(100),
-> Age int
-> );
Query OK, 0 rows affected (0.97 sec)
Insert records in the table using insert command. The query is as follows.
mysql> insert into PatternDemo values(1,'James',23);
Query OK, 1 row affected (0.11 sec)

mysql> insert into PatternDemo values(2,'Joseph',21);
Query OK, 1 row affected (0.18 sec)

mysql> insert into PatternDemo values(3,'Robert',20);
Query OK, 1 row affected (0.11 sec)

mysql> insert into PatternDemo values(4,'John',26);
Query OK, 1 row affected (0.10 sec)

mysql> insert into PatternDemo values(5,'Richard',24);
Query OK, 1 row affected (0.17 sec)
Now you can display all records from the table using select statement. The query is as follows.
mysql> select *from PatternDemo;
The following is the output.
+------+---------+------+
| Id   | Name    | Age  |
+------+---------+------+
| 1    | James   | 23   |
| 2    | Joseph  | 21   |
| 3    | Robert  | 20   |
| 4    | John    | 26   |
| 5    | Richard | 24   |
+------+---------+------+
5 rows in set (0.00 sec)
Here is the query that will give all names with the characters “Jo”. The query is as follows.
mysql> select *from PatternDemo where Name like '%Jo%';
The following is the output.
+------+--------+------+
| Id   | Name   | Age  |
+------+--------+------+
| 2    | Joseph | 21   |
| 4    | John   | 26   |
+------+--------+------+
2 rows in set (0.00 sec)
GATE | GATE-CS-2015 (Set 3) | Question 41 - GeeksforGeeks

07 Sep, 2021
Consider the following grammar G.
  S → F ⎪ H
  F → p ⎪ c
  H → d ⎪ c 
Where S, F and H are non-terminal symbols, p, d and c are terminal symbols. Which of the following statement(s) is/are correct?
S1: LL(1) can parse all strings that are generated using grammar G.
S2: LR(1) can parse all strings that are generated using grammar G. 
(A) Only S1(B) Only S2(C) Both S1 and S2(D) Neither S1 and S2Answer: (D)Explanation: The given grammar is ambiguous as there are two possible leftmost derivations for string “c”.

First Leftmost Derivation
  S → F 
  F → c

Second Leftmost Derivation
  S → H
  H → c  
An Ambiguous grammar can neither be LL(1) nor LR(1)
YouTubeGeeksforGeeks GATE Computer Science16.1K subscribersPYQ - Parsing and SDT (Continued) with Joyojyoti Acharya | GeeksforGeeks GATEWatch laterShareCopy linkInfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.You're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmMore videosMore videosSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:0021:42 / 44:16•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=9LF8Bby1Qhc" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>Quiz of this Question
GATE-CS-2015 (Set 3)
GATE-GATE-CS-2015 (Set 3)
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
GATE | GATE-CS-2014-(Set-3) | Question 38
GATE | GATE CS 2018 | Question 37
GATE | GATE-IT-2004 | Question 83
GATE | GATE-CS-2016 (Set 1) | Question 65
GATE | GATE-CS-2016 (Set 1) | Question 63
GATE | GATE-IT-2004 | Question 12
GATE | GATE-CS-2007 | Question 17
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE-CS-2007 | Question 64
GATE | GATE CS 2010 | Question 33
Checking MySQL Database Size in Linux - GeeksforGeeks

11 Feb, 2021
Mysql is the most popular open-source database among developers. It is developed and managed by Oracle Corporation and initially released on 23 May 1995. It is compatible with each operating system, Like(Linux, Windows, and macOS) which is major support for web-based applications. In this article, we are going to see how to get the size of a database in MySQL in Linux. Every operating system follows the same approach(Syntax) to check the size of a database. 
So let’s see the approach in step-wise:
Step 1: Check your MySql is installed or not.
mysql --version
Step 2: Start MySql.
sudo mysql
Step 3: Check the databases.
show databases;
Step 4: Check the all databases.
Here we define the table_schema and show the size of our database in a new column by following commands:
SELECT table_schema "Database_Name"
SUM(data_length + index_length) / (1024 * 1024) "Database Size in MB"
FROM information_schema.TABLES
GROUP BY table_schema;
Output:
Step 5: Check single databases.
Here we define the table_schema and show the size of any one database (students) in a new column by following commands:
SELECT table_schema "Database_Name",
SUM(data_length + index_length) / (1024 * 1024) "Database Size in MB"
FROM information_schema.TABLES
WHERE table_schema = "students"
ORDER BY (data_length + index_length) DESC;
mysql
Picked
How To
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install FFmpeg on Windows?
How to Add External JAR File to an IntelliJ IDEA Project?
How to Set Git Username and Password in GitBash?
How to create a nested RecyclerView in Android
How to Create and Setup Spring Boot Project in Eclipse IDE?
Sed Command in Linux/Unix with examples
AWK command in Unix/Linux with examples
grep command in Unix/Linux
cut command in Linux with examples
cp command in Linux with examples
C program to Count the digits of a number - GeeksforGeeks

29 Apr, 2020
Given a number N, write a C program to find the count of digits in number N.
Examples:
Input: N = 12345Output: 5Explanation:The count of digit in 12345 = 5.
Input: N = 23451452Output: 8Explanation:The count of digits in 23451452 = 8.
Approach: Count of digits in a number can be found efficiently in few steps:
Remove the last digit of number by dividing it with 10.Increment the count of digit by 1.Keep repeating steps 1 and 2 until the value of N becomes 0. In this case, there will be no more digit left in the number to count
Remove the last digit of number by dividing it with 10.
Increment the count of digit by 1.
Keep repeating steps 1 and 2 until the value of N becomes 0. In this case, there will be no more digit left in the number to count
C
// C Program to find count of// digits in a number  #include <stdio.h>  // Find the count of digitsint findCount(int n){    int count = 0;      // Remove last digit from number    // till number is 0    while (n != 0) {    //Increment count        count++;        n /= 10;    }      // return the count of digit    return count;}  // Driver programint main(){    int n = 98562;    printf("Count of digits in %d = %d\n", n, findCount(n));    return 0;}
Count of digits in 98562 = 5

Time complexity: O(D), where D is the count of digits in number N.Auxiliary Space complexity: O(1)
number-digits
C Programs
Mathematical
School Programming
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
C Program to read contents of Whole File
Producer Consumer Problem in C
C program to find the length of a string
C / C++ Program for Dijkstra's shortest path algorithm | Greedy Algo-7
Regular expressions in C
Program for Fibonacci numbers
Write a program to print all permutations of a given string
C++ Data Types
Set in C++ Standard Template Library (STL)
Program to find GCD or HCF of two numbers
Fizz Buzz in Python

Suppose we have a number n. We have to display a string representation of all numbers from 1 to n, but there are some constraints.
If the number is divisible by 3, write Fizz instead of the number
If the number is divisible by 5, write Buzz instead of the number
If the number is divisible by 3 and 5 both, write FizzBuzz instead of the number
To solve this, we will follow these steps −
For all number from 1 to n,if a number is divisible by 3 and 5 both, print “FizzBuzz”otherwise when the number is divisible by 3, print “Fizz”otherwise when the number is divisible by 5, print “Buzz”otherwise, write the number as a string
if a number is divisible by 3 and 5 both, print “FizzBuzz”
otherwise when the number is divisible by 3, print “Fizz”
otherwise when the number is divisible by 5, print “Buzz”
otherwise, write the number as a string
Let us see the following implementation to get a better understanding −
 Live Demo
class Solution(object):
   def fizzBuzz(self, n):
      """
      :type n: int
      :rtype: List[str]
      """
      result = []
      for i in range(1,n+1):
         if i% 3== 0 and i%5==0:
            result.append("FizzBuzz")
         elif i %3==0:
            result.append("Fizz")
         elif i% 5 == 0:
            result.append("Buzz")
         else:
            result.append(str(i))
      return result
ob1 = Solution()
print(ob1.fizzBuzz(30))
30
["1","2","Fizz","4","Buzz","Fizz","7","8","Fizz","Buzz","11","Fizz",
"13","14","FizzBuzz","16","17","Fizz","19","Buzz","Fizz","22","23",
"Fizz","Buzz","26","Fizz","28","29","FizzBuzz"]
Extract Content from XML

How to extract content from an XML document using java.
Following is the program to extract content from an XML document using java.
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.parser.html.HtmlParser;
import org.apache.tika.sax.BodyContentHandler;
import org.xml.sax.SAXException;

public class ExtractContentFromXMLDoc {
   public static void main(String[] args) throws IOException,SAXException, TikaException {
      
      //detecting the file type
      BodyContentHandler handler = new BodyContentHandler();
      
      Metadata metadata = new Metadata();
      FileInputStream inputstream = new FileInputStream(new File(
         "C:/tika/xmlExample.xml"));
      ParseContext pcontext = new ParseContext();

      //Html parser
      HtmlParser htmlparser = new HtmlParser();
      
      htmlparser.parse(inputstream, handler, metadata,pcontext);
      System.out.println("Contents of the document:" + handler.toString());
      System.out.println("Metadata of the document:");
      String[] metadataNames = metadata.names();

      for(String name : metadataNames) {
         System.out.println(name + ": " + metadata.get(name));
      }
   }
}
Contents of the document: 
   Tanmay Patil 
   TutorialsPoint 
   (011) 123-4567   

Metadata of the document: 
Content-Encoding: windows-1252 
Content-Type: text/html; charset = windows-1252 

 Print
 Add Notes
 Bookmark this page
How do I remove a substring from the end of a string in Python?

If you want to remove a substring from the end of a string, you should fisrt check if the string ends with that substring. If it does, then slice the string keeping only the part without substring. For example,
def rchop(string, ending):
  if string.endswith(ending):
    return string[:-len(ending)]
  return string
chopped_str = rchop('Hello world', 'orld')
print chopped_str
This will give the output:
Hello w
If speed is not important, you can also use a regex here. For example,
>>> import re
>>> re.sub('orld$', '', 'Hello world')
Hello w
HTMLCollection item() Method - GeeksforGeeks

26 Jul, 2019
The item() method is used to return the content of element at the given index of the collection of all HTML element. The index starts from zero(0). The elements in the collection are sorted in the order as they appear in the sourcecode.
Syntax:
HTMLCollection.item(index) 
OR
HTMLCollection[index] 
Parameters: It contains a number that represents the index of the element that the user wants to return. The index starts from 0.
Example-1:
<!DOCTYPE html><html>  <head>    <style>        h1 {            color: green;        }    </style></head>  <body>    <center>        <h1>GeeksForGeeks</h1>        <h2>HTMLCollection item() Method</h2>          <button onclick="Geeks()">Submit</button>          <script>            function Geeks() {                var w = document.getElementsByTagName("h1");                alert(w.item(0).innerHTML);            }        </script>  </body>  </html>
Output:Before clicking on the button:After clicking on the button:
Example-2: To change the content of an HTML Element.
<!DOCTYPE html><html>  <head>    <style>        h1 {            color: green;        }    </style></head>  <body>    <center>        <h1>GeeksForGeeks</h1>        <h2>HTMLCollection item() Method</h2>        <p>geeforgeefs</p>        <button onclick="Geeks()">Submit</button>          <script>            function Geeks() {                document.getElementsByTagName("P")[0].innerHTML =                                                   "GeeksForGeeks";            }        </script>  </body>  </html>
Output:Before clicking on the button:After clicking on the button:
Supported Browsers: The browser supported by HTMLCollection item() Method are listed below:
Google Chrome
Internet Explorer
Firefox
Opera
Safari
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.
HTML-Methods
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to update Node.js and NPM to next version ?
How to Insert Form Data into Database using PHP ?
Types of CSS (Cascading Style Sheet)
REST API (Introduction)
Form validation using HTML and JavaScript
Roadmap to Become a Web Developer in 2022
Installation of Node.js on Linux
How to fetch data from an API in ReactJS ?
Convert a string to an integer in JavaScript
Top 10 Angular Libraries For Web Developers
How to get the id of a form containing a dropdown list with JavaScript?

To get the id of a form with a drop-down list, use the id property in JavaScript.
You can try to run the following code to find the id of a form containing drop-down list −
Live Demo
<!DOCTYPE html>
<html>
   <body>
      <form id="myForm1">
         <button id="btn" type="button" value="my_button">Demo</button>
      </form><br>
      <form id="myForm2">
         <select id="mySelect">
            <option>One</option>
            <option>Two</option>
            <option>Three</option>
         </select>
      </form>
      <script>
         var val = document.getElementById("mySelect").form.id;
         document.write("<br>Form id with dropdown: "+val);
      </script>
   </body>
</html>
How to create a self-signed certificate using PowerShell?

To create a self-signed certificate there are various methods like OpenSSL, IIS, PowerShell, etc. Here, we will see how we can create a self-signed certificate with PowerShell.
To create a self-signed certificate with PowerShell, we need to use the New-SelfSignedCertificate command. When you create a self-signed certificate manually, you need to give few properties like DNSName, FriendlyName, Certificate start date, expiry date, Subject, a path of the certificate. Similarly, you can use those properties for this command to create it. Not all properties are mandatory.
New-SelfSignedCertificate `
   -CertStoreLocation Cert:\LocalMachine\My `
   -DnsName "testdomain.local" -Verbose
PSParentPath: Microsoft.PowerShell.Security\Certificate::LocalMachine\My
Thumbprint                                Subject                                                             ----------                                -------                                                             17722DE732EB07465938FF4810D3CC4B3E87AA5A  CN=testdomain.local                    
You will get output something like above. By default, the self-signed certificate creates a 1-year expiry date from creation. To create a certificate with different expiry and a start date and other properties like a friendly name, use the below command.
New-SelfSignedCertificate `
   -CertStoreLocation Cert:\LocalMachine\My `
   -DnsName "testdomain.local" `
   -FriendlyName "testdomain" `
   -NotAfter "03/12/2025" -Verbose
There are also other options like adding the Subject and other properties.
Python | Inverse Fast Walsh Hadamard Transformation - GeeksforGeeks

31 Jan, 2022
It is an Hadamard ordered efficient algorithm to compute the inverse Walsh Hadamard transform (WHT). Normal WHT computation has N = 2m complexity but using IFWHT reduces the computation to O(n2). The FWHT requires O(n logn) additions and subtraction operations. It is a divide and conquer algorithm which breaks down the WHT recursively. 
It can perform Inverse Walsh Hadamard Transform (WHT). This method is based on Hadamard sequence ordering. Automatically the sequence is padded with zero to the right because the radix-2 FWHT requires the sample point number as a power of 2.  
Syntax: 
sympy.discrete.transforms.ifwht()

Parameters : 
-> seq : [iterable] sequence on which IWHT is to be applied.

Returns : 
Coefficient of Inverse Fast Walsh Hadamard Transform Transform
Example #1 :  
Python3
# import sympyfrom sympy import ifwht # sequenceseq = [15, 21, 13, 44] # ifwhttransform = ifwht(seq)print ("Transform  : ", transform)
Output :  
Transform  :  [93/4, -37/4, -21/4, 25/4]
Example #2 :  
Python3
# import sympyfrom sympy import ifwht # sequenceseq = [23,       56,       12,       555] # ifwhttransform = ifwht(seq)print ("Transform  : ", transform)
Output :  
Transform  :  [323/2, -144, -122, 255/2]
 
varshagumber28
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Python Dictionary
Read a file line by line in Python
Enumerate() in Python
How to Install PIP on Windows ?
Different ways to create Pandas Dataframe
Python String | replace()
Reading and Writing to text files in Python
sum() function in Python
Create a Pandas DataFrame from Lists
How to drop one or multiple columns in Pandas Dataframe
Are true and false keywords in java?

Keywords − Keywords in Java convey a special meaning to the compiler therefore, these cannot be used as identifiers. Java provides a set of 50 keywords.
Reserved words − Among the list of key words list mentioned above the key words goto and const are currently not in use. They are reserved words (for the future use).
The true false and null − True, false and null represents certain values in Java, they are used as literals. They are not considered as keywords.
Still, you cannot use them as identifiers in Java if you try to do so, a compile time error will be generated.
public class Example {
   public static void main(String args[]) {
      int true = 20;
      int false = 30;
      float null = 23.6f;
   }
}
Example.java:3: error: not a statement
   int true = 20;
   ^
Example.java:3: error: ';' expected
   int true = 20;
       ^
Example.java:4: error: not a statement
   int false = 30;
   ^
Example.java:4: error: ';' expected
   int false = 30;
       ^
Example.java:5: error: not a statement
   float null = 23.6f;
   ^
Example.java:5: error: ';' expected
   float null = 23.6f;
         ^
6 errors
How to insert Date in MongoDB?

To insert date in MongoDB, use Date(). Let us create a collection with documents −
> db.demo421.insert({"DueDate":new Date(Date.now())});
WriteResult({ "nInserted" : 1 })
> db.demo421.insert({"DueDate":new Date("2020-01-15")});
WriteResult({ "nInserted" : 1 })
> db.demo421.insert({"DueDate":new Date("2018-12-31")});
WriteResult({ "nInserted" : 1 })
Display all documents from a collection with the help of find() method −
> db.demo421.find();
This will produce the following output −
{ "_id" : ObjectId("5e73a2ec9822da45b30346de"), "DueDate" : ISODate("2020-03-19T16:50:52.746Z") }
{ "_id" : ObjectId("5e73a2fb9822da45b30346df"), "DueDate" : ISODate("2020-01-15T00:00:00Z") }
{ "_id" : ObjectId("5e73a3079822da45b30346e0"), "DueDate" : ISODate("2018-12-31T00:00:00Z") }
IntStream mapToDouble() method in Java

The mapToDouble() method returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.
The syntax is as follows.
DoubleStream mapToDouble(IntToDoubleFunction mapper)
Here, the parameter mapper is the stateless function applied to each element.
Create an IntStream with some elements.
IntStream intStream = IntStream.of(5, 20, 25, 45, 60, 75, 85, 90);
Now, use the mapToDouble() method to return a DoubleStream.
DoubleStream doubleStream = intStream.mapToDouble(val -> (double) val);
The following is an example to implement IntStream mapToDouble() method in Java.
 Live Demo
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.of(5, 20, 25, 45, 60, 75, 85, 90);
      DoubleStream doubleStream = intStream.mapToDouble(val -> (double) val);
      doubleStream.forEach(System.out::println);
   }
}
5.0
20.0
25.0
45.0
60.0
75.0
85.0
90.0
Create a password generator using shell scripting - GeeksforGeeks

19 Jul, 2019
Creating a strong password is often a time-consuming task and even after creating a good password by yourself it gets brute-forced by hackers. In this article, we will learn how to create a strong password which fulfills all requirements including symbols, capitals length etc using a simple shell script in Linux.
How to create a password generator using shell script ?This a simple short and quick method, just open the nano editor with .sh file using this command –
nano passwdgen.sh
You can use any name of the file.
#!/bin/bash  # this can be anything of your choiceecho "Welcome to simple password generator"   # ask the user how much long should beecho "please enter the length of the password"    # read the input given by user and store in variableread  PASS_LENGTH   # loop will create 5 passwords according to# user as per length given by user                        for p in $(seq 1 5);                                   do     openssl rand -base64 48 | cut -c1-$PASS_LENGTH done
Save the file and give executable permission using sudo chmod +x command and run the script.
Output:
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
nohup Command in Linux with Examples
scp command in Linux with Examples
Thread functions in C/C++
mv command in Linux with examples
chown command in Linux with Examples
SED command in Linux | Set 2
Docker - COPY Instruction
Array Basics in Shell Scripting | Set 1
Basic Operators in Shell Scripting
nslookup command in Linux with Examples
JavaScript - The Boolean Object

The Boolean object represents two values, either "true" or "false". If value parameter is omitted or is 0, -0, null, false, NaN, undefined, or the empty string (""), the object has an initial value of false.
Use the following syntax to create a boolean object.
var val = new Boolean(value);

Here is a list of the properties of Boolean object −
Returns a reference to the Boolean function that created the object.
The prototype property allows you to add properties and methods to an object.
In the following sections, we will have a few examples to illustrate the properties of Boolean object.
Here is a list of the methods of Boolean object and their description.
Returns a string containing the source of the Boolean object; you can use this string to create an equivalent object.
Returns a string of either "true" or "false" depending upon the value of the object.
Returns the primitive value of the Boolean object.
In the following sections, we will have a few examples to demonstrate the usage of the Boolean methods.

    25 Lectures 
     2.5 hours 

 Anadi Sharma

    74 Lectures 
     10 hours 

 Lets Kode It

    72 Lectures 
     4.5 hours 

 Frahaan Hussain

    70 Lectures 
     4.5 hours 

 Frahaan Hussain

    46 Lectures 
     6 hours 

 Eduonix Learning Solutions

    88 Lectures 
     14 hours 

 Eduonix Learning Solutions
 Print
 Add Notes
 Bookmark this page
C++ Program to calculate the value of sin(x) and cos(x)

Given with the input as angles and the task is to calculate the value of sin(x) and cos(x) corresponding to the given angle and display the result
Sin(x) is a trigonometric function which is used to calculate the value of x angle.
sin⁡(x)=∑k=0∞(−1)k(2k+1)!x2k+1
Cos(x) is a trigonometric function which is used to calculate the value of x angle.
cos⁡(x)=∑k=0∞(−1)k(2k)!x2k
Approach used in the below program is as follows −
Input the value of x angle for sin(x) and cos(x)
Apply the formulas given for sin(x) and cos(x)
Print the result
START
Step 1-> declare function to calculate value of sin
   void cal_sin(float n)
   declare and set float acc = 0.0001, denominator, sinx, sinval
   Set n = n * (3.142 / 180.0)
   Declare float temp = n
   Set sinx = n
   Set sinval = sin(n)
   Declare and set int i = 1
   DO
      set denominator = 2 * i * (2 * i + 1)
      set temp = -temp * n * n / denominator
      Set sinx = sinx + temp
      Set i = i + 1
   While(acc <= fabs(sinval - sinx))
      print sinx
Step 2-> Declare function to calculate value of cos
   void cal_cos(float n)
   Declare and set float acc = 0.0001, temp, denominator, cosx, cosval
   Set n = n * (3.142 / 180.0)
   Set temp = 1
   set cosx = temp
   set cosval = cos(n)
   Set int i = 1
   Do
      set denominator = 2 * i * (2 * i - 1)
      Set temp = -temp * n * n / denominator
      Set cosx = cosx + temp
      Set i = i + 1
   While(acc <= fabs(cosval - cosx))
      print cosx
Step 3-> In main()
   Declare float n = 30
   Call cal_sin(n0
   set n=60
   Call cal_cos(n)
STOP
#include <iostream>
#include <math.h>
using namespace std;
//calculate value of sin
void cal_sin(float n) {    
    float acc = 0.0001, denominator, sinx, sinval;
    n = n * (3.142 / 180.0);  //convert in radian
    float temp = n;
    sinx = n;          
    sinval = sin(n);    
    int i = 1;
    do {
        denominator = 2 * i * (2 * i + 1);
        temp = -temp * n * n / denominator;
        sinx = sinx + temp;
        i = i + 1;
    } while (acc <= fabs(sinval - sinx));
    cout<<sinx;
}
//calculate value of cos  
void cal_cos(float n) {
    float acc = 0.0001, temp, denominator, cosx, cosval;
    n = n * (3.142 / 180.0); //convert in radiam
    temp = 1;
    cosx = temp;          
    cosval = cos(n);
    int i = 1;
    do {
        denominator = 2 * i * (2 * i - 1);
        temp = -temp * n * n / denominator;
        cosx = cosx + temp;
        i = i + 1;
    } while (acc <= fabs(cosval - cosx));
    cout<< cosx;
}
int main() {
    float n = 30;
    cout<<"value of Sin is : "; cal_sin(n);
cout<<"\n";
    n=60;
cout<<"value of Cos is : ";
cal_cos(n);
    return 0;
}
value of Sin is : 0.500061
value of Cos is : 0.499847
Changing three.js background to transparent or another color in HTML

If you want a transparent background in three.js, you need a pass in the alpha parameter to the WebGLRenderer constructors in the below-given code −
var renderer = new THREE.WebGLRenderer( {alpha: true } );
// You can leave the clear color at the defaultvalue.
renderer.setClearColor( 0x000000, 0 ); //default
However, to set the background color,
renderer.setClearColor(0xb0f442 );
Is `definer` required when creating a MySQL stored procedure?

No, definer part is not compulsory when you are creating a stored procedure. It is used when you want to create a definer.
Check all the user and host from the MySQL.user table −
mysql> select user,host from mysql.user;
The following is the output −
+------------------+-----------+
| user             | host      |
+------------------+-----------+
| Manish           | %         |
| User2            | %         |
| mysql.infoschema | %         |
| mysql.session    | %         |
| mysql.sys        | %         |
| root             | %         |
| Adam Smith       | localhost |
| User1            | localhost |
| am               | localhost |
+------------------+-----------+
9 rows in set (0.03 sec)
Here, let us create a definer as Adam Smith. The query to create a stored procedure is as follows −
mysql> delimiter //
mysql> CREATE DEFINER = 'Adam Smith'@'localhost' procedure Sp_Definer()
   -> begin
   -> select 'Hello MySQL';
   -> end;
   -> //
Query OK, 0 rows affected (0.14 sec)
mysql> delimiter ;
Call the stored procedure using CALL command. The syntax is as follows −
CALL yourStoredProcedureName();
Call the above stored procedure.
mysql> call Sp_Definer();
The following is the output.
+-------------+
| Hello MySQL |
+-------------+
| Hello MySQL |
+-------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
How to delete the windows certificate using PowerShell?

To delete the Windows certificate using PowerShell, we can use the Remove-Item command.
Suppose you know the thumbprint of the certificate then to retrieve all the certificates that use that particular thumbprint, we will use the below command.
PS C:\> gci cert:\ -Recurse | where{$_.Thumbprint -eq
To remove the certificates, we will pipeline the Remove-Item command.
PS C:\> gci cert:\ -Recurse | where{$_.Thumbprint -eq
'920B033462B2FE268E6F9679F8621AEDC78D506C'} | Remove-Item -Force -Verbose
Or if you have the Subject name, then instead of the Thumbprint property, you can use the subject name.
PS C:\> gci cert:\ -Recurse | where{$_.Subject -eq "DemoCert"} | Remove-Item -Force - Verbose
To remove the certificate on the remote servers, you can use the Invoke-Command.
Invoke-Command -ComputerName $Server -ScriptBlock{
   gci cert:\ -Recurse | where{$_.Subject -eq "DemoCert"} |
Remove-Item -Force -Verbose
}
Difference between continue and pass statements in Python - GeeksforGeeks

25 Jun, 2020
Using loops in Python automates and repeats the tasks in an efficient manner. But sometimes, there may arise a condition where you want to exit the loop completely, skip an iteration or ignore that condition. These can be done by loop control statements. Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed. Python supports the following control statements.
Continue statement
Break statement
Pass statement
In this article, the main focus will be on the difference between continue and pass statement.
This statement is used to skip over the execution part of the loop on a certain condition. After that, it transfers the control to the beginning of the loop. Basically, it skips its following statements and continues with the next iteration of the loop.
Syntax:
continue

As the name suggests pass statement simply does nothing. We use pass statement to write empty loops. Pass is also used for empty control statements, functions and classes.
Syntax:
pass

Consider the below example for better understanding the difference between continue and pass statement.
Example:
# Python program to demonstrate# difference between pass and # continue statements  s = "geeks"  # Pass statementfor i in s:    if i == 'k':        print('Pass executed')        pass    print(i)  print()      # Continue statementfor i in s:    if i == 'k':        print('Continue executed')        continue    print(i)
Output:
g
e
e
Pass executed
k
s

g
e
e
Continue executed
s

In the above example, when the value of i becomes equal to ‘k‘, the pass statement did nothing and hence the letter ‘k‘ is also printed. Whereas in the case of continue statement, the continue statement transfers the control to the beginning of the loop, hence the letter k is not printed.
Akanksha_Rai
python-basics
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
Enumerate() in Python
How to Install PIP on Windows ?
Iterate over a list in Python
Different ways to create Pandas Dataframe
Python String | replace()
Create a Pandas DataFrame from Lists
Python program to convert a list to string
Reading and Writing to text files in Python
JSP - The taglib Directive

The JavaServer Pages API allow you to define custom JSP tags that look like HTML or XML tags and a tag library is a set of user-defined tags that implement custom behavior.
The taglib directive declares that your JSP page uses a set of custom tags, identifies the location of the library, and provides means for identifying the custom tags in your JSP page.
The taglib directive follows the syntax given below −
<%@ taglib uri = "uri" prefix = "prefixOfTag" >

Where, the uri attribute value resolves to a location the container understands and the prefix attribute informs a container what bits of markup are custom actions.
You can write the XML equivalent of the above syntax as follows −
<jsp:directive.taglib uri = "uri" prefix = "prefixOfTag" />

When you use a custom tag, it is typically of the form <prefix:tagname>. The prefix is the same as the prefix you specify in the taglib directive, and the tagname is the name of a tag implemented in the tag library.
For example, suppose the custlib tag library contains a tag called hello. If you wanted to use the hello tag with a prefix of mytag, your tag would be <mytag:hello> and it will be used in your JSP file as follows −
<%@ taglib uri = "http://www.example.com/custlib" prefix = "mytag" %>

<html>
   <body>
      <mytag:hello/>
   </body>
</html>
We can call another piece of code using <mytag:hello>. We will see how to develop our custom tags and how to use them in JSP - Custom Tags tutorial.

    108 Lectures 
     11 hours 

 Chaand Sheikh

    517 Lectures 
     57 hours 

 Chaand Sheikh

    41 Lectures 
     4.5 hours 

 Karthikeya T

    42 Lectures 
     5.5 hours 

 TELCOMA Global

    15 Lectures 
     3 hours 

 TELCOMA Global

    44 Lectures 
     15 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page
DOM - NamedNodeMap Object Method - item ()

The method item () returns the indexth item in the map. If index is greater than or equal to the number of nodes in this map, this returns null.
Following is the syntax for the usage of the item() method.
nodemapObject.item(index)

index
It specifies the position of the item into the map. It is of type unsigned long.
This method returns the indexth item in the map.
node.xml contents are as below −
<Company>
   <Employee category = "Technical">
      <FirstName>Tanmay</FirstName>
      <LastName>Patil</LastName>
      <ContactNo>1234567890</ContactNo>
      <Email>tanmaypatil@xyz.com</Email>
   </Employee>
   
   <Employee category = "Non-Technical">
      <FirstName>Taniya</FirstName>
      <LastName>Mishra</LastName>
      <ContactNo>1234667898</ContactNo>
      <Email>taniyamishra@xyz.com</Email>
   </Employee>
   
   <Employee category = "Management">
      <FirstName>Tanisha</FirstName>
      <LastName>Sharma</LastName>
      <ContactNo>1234562350</ContactNo>
      <Email>tanishasharma@xyz.com</Email>
   </Employee>
</Company>
Following example demonstrates the usage of the item() method −
<!DOCTYPE html>
<html>
   <body>
      <script>
         if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
         }
         else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
         }
         xmlhttp.open("GET","/dom/node.xml",false);
         xmlhttp.send();
         xmlDoc = xmlhttp.responseXML;

         x = xmlDoc.getElementsByTagName('Employee');


         item_name = x.item(0).attributes.getNamedItem("category");
         document.write("Get the specified item value : ")
         document.write( item_name.value );
     </script>
   </body>
</html>
Save this file as namednodemapmethod_item.htm on the server path (this file and node_methods.xml should be on the same path in your server). We will get the output as shown below −
Get the specified item value : Technical


    41 Lectures 
     5 hours 

 Abhishek And Pukhraj

    33 Lectures 
     3.5 hours 

 Abhishek And Pukhraj

    15 Lectures 
     1 hours 

 Zach Miller

    15 Lectures 
     4 hours 

 Prof. Paul Cline, Ed.D

    13 Lectures 
     4 hours 

 Prof. Paul Cline, Ed.D

    17 Lectures 
     2 hours 

 Laurence Svekis
 Print
 Add Notes
 Bookmark this page
Convert a Binary Tree to Threaded binary tree | Set 1 (Using Queue) in C++

In this tutorial, we will be discussing a program to convert a binary tree to a threaded binary tree using a queue data structure.
For this, we will be provided with a binary tree. Our task is to convert that particular binary tree into a threaded binary tree by adding additional routes for quicker inorder traversal with the help of a queue data structure.
 Live Demo
#include <iostream>
#include <queue>
using namespace std;
//node structure for threaded tree
struct Node {
   int key;
   Node *left, *right;
   bool isThreaded;
};
//putting the inorder pattern into a queue
void convert_queue(Node* root, std::queue<Node*>* q){
   if (root == NULL)
      return;
   if (root->left)
      convert_queue(root->left, q);
   q->push(root);
   if (root->right)
      convert_queue(root->right, q);
}
//traversing the queue and making threaded tree
void create_threadedtree(Node* root, std::queue<Node*>* q){
   if (root == NULL)
      return;
   if (root->left)
      create_threadedtree(root->left, q);
   q->pop();
   if (root->right)
      create_threadedtree(root->right, q);
   //if right pointer in NUll, point it to
   //inorder successor
   else {
      root->right = q->front();
      root->isThreaded = true;
   }
}
//finally taking the tree and converting it into threaded
void createThreaded(Node* root){
   std::queue<Node*> q;
   convert_queue(root, &q);
   create_threadedtree(root, &q);
}
Node* leftMost(Node* root){
   while (root != NULL && root->left != NULL)
      root = root->left;
      return root;
   }
   //performing inorder traversal of threaded tree
   void inOrder(Node* root){
      if (root == NULL)
         return;
      Node* cur = leftMost(root);
      while (cur != NULL) {
         cout << cur->key << " ";
         //if threaded node, move to inorder successor
         if (cur->isThreaded)
            cur = cur->right;
         else
            cur = leftMost(cur->right);
      }
   }
   Node* newNode(int key){
      Node* temp = new Node;
      temp->left = temp->right = NULL;
      temp->key = key;
      return temp;
}
int main(){
   Node* root = newNode(1);
   root->left = newNode(2);
   root->right = newNode(3);
   root->left->left = newNode(4);
   root->left->right = newNode(5);
   root->right->left = newNode(6);
   root->right->right = newNode(7);
   createThreaded(root);
   cout << "Traversing threaded tree :\n";
   inOrder(root);
   return 0;
}
Traversing threaded tree :
4 2 5 1 6 3 7
Program for Identity Matrix in C

Given a square matrix M[r][c] where ‘r’ is some number of rows and ‘c’ are columns such that r = c, we have to check that ‘M’ is identity matrix or not.
Identity matrix is also known as Unit matrix of size nxn square matrix where diagonal elements will only have integer value one and non diagonal elements will only have integer value as 0
Like in the given Example below −
I1=[1],I2=[1001],I3=[100010001],In=[100...0010...0001...0..............000...1]
Input: m[3][3] = { {1, 0, 0},
   {0, 1, 0},
   {0, 0, 1}}
Output: yes
Input: m[3][3] == { {3, 0, 1},
   {6, 2, 0},
   {7, 5, 3} }
Output: no
Start
Step 1 -> declare function for finding identity matrix
   int identity(int num)
      declare int row, col
      Loop For row = 0 and row < num and row++
         Loop For col = 0 and col < num and col++
            IF (row = col)
               Print 1
            Else
               Print 0
      End
   End
Step 2 -> In main()
   Declare int size = 4
   Call identity(size)
Stop
#include<stdio.h>
int identity(int num){
   int row, col;
   for (row = 0; row < num; row++){
      for (col = 0; col < num; col++){
         if (row == col)
            printf("%d ", 1);
         else
            printf("%d ", 0);
      }
      printf("\n");
   }
   return 0;
}
int main(){
   int size = 4;
   identity(size);
   return 0;
}
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Scala - break Statement

As such there is no built-in break statement available in Scala but if you are running Scala version 2.8, then there is a way to use break statement. When the break statement is encountered inside a loop, the loop is immediately terminated and program control resumes at the next statement following the loop.
The following is the syntax for break statement.
// import following package
import scala.util.control._

// create a Breaks object as follows
val loop = new Breaks;

// Keep the loop inside breakable as follows
loop.breakable {
   // Loop will go here
   for(...){
      ....
      
      // Break will go here
      loop.break;
   }
}

Try the following example program to understand break statement.
import scala.util.control._

object Demo {
   def main(args: Array[String]) {
      var a = 0;
      val numList = List(1,2,3,4,5,6,7,8,9,10);

      val loop = new Breaks;
      
      loop.breakable {
         for( a <- numList){
            println( "Value of a: " + a );
            
            if( a == 4 ){
               loop.break;
            }
         }
      }
      println( "After the loop" );
   }
}
Save the above program in Demo.scala. The following commands are used to compile and execute this program.
\>scalac Demo.scala
\>scala Demo

Value of a: 1
Value of a: 2
Value of a: 3
Value of a: 4
After the loop

Existing break has an issue while using for nested loops. Just in case to use break for nested loops, follow this method. This is an example program for breaking nested loops.
import scala.util.control._

object Demo {
   def main(args: Array[String]) {
      var a = 0;
      var b = 0;
      val numList1 = List(1,2,3,4,5);
      val numList2 = List(11,12,13);

      val outer = new Breaks;
      val inner = new Breaks;

      outer.breakable {
         for( a <- numList1){
            println( "Value of a: " + a );
            
            inner.breakable {
               for( b <- numList2){
                  println( "Value of b: " + b );
                  
                  if( b == 12 ){
                     inner.break;
                  }
               }
            } // inner breakable
         }
      } // outer breakable.
   }
}
Save the above program in Demo.scala. The following commands are used to compile and execute this program.
\>scalac Demo.scala
\>scala Demo

Value of a: 1
Value of b: 11
Value of b: 12
Value of a: 2
Value of b: 11
Value of b: 12
Value of a: 3
Value of b: 11
Value of b: 12
Value of a: 4
Value of b: 11
Value of b: 12
Value of a: 5
Value of b: 11
Value of b: 12


    82 Lectures 
     7 hours 

 Arnab Chakraborty

    23 Lectures 
     1.5 hours 

 Mukund Kumar Mishra

    52 Lectures 
     1.5 hours 

 Bigdata Engineer

    76 Lectures 
     5.5 hours 

 Bigdata Engineer

    69 Lectures 
     7.5 hours 

 Bigdata Engineer

    46 Lectures 
     4.5 hours 

 Stone River ELearning
 Print
 Add Notes
 Bookmark this page
Locating child nodes of WebElements in selenium.

We can locate child nodes of web elements with Selenium webdriver. First of all we need to identify the parent element with help of any of the locators like id, class, name, xpath or css. Then we have to identify the children with the findElements(By.xpath()) method.
We can identify the child nodes from the parent, by localizing it with the parent and then passing ( ./child::*) as a parameter to the findElements(By.xpath())
Syntax−
parent.findElements(By.xpath("./child::*"))
Let us identify the text of the child nodes of ul node in below html code−
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;

public class ChildNodes{
   public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      driver.get("https://www.tutorialspoint.com/about/about_careers.htm");
      // identify element
      WebElement t=driver.findElement(By.xpath("//ul[@class='toc chapters']"));
      //identify child nodes with ./child::* expression in xpath
      List<WebElement> c = t.findElements(By.xpath("./child::*"));
      // iterate child nodes
      for ( WebElement i : c ) {
      //getText() to get text for child nodes
      System.out.println(i.getText());}
      driver.close();
   }
}
Defanging an IP Address in Python

Suppose we have a valid IPv4 IP address. We have to return the Defanged version of the IP address. A Defanged IP address is basically replace every period “.” by “[.]” So if the IP address is “192.168.4.1”, the output will be “192[.]168[.]4[.]1”
To solve this, we will follow these steps −
We will split the string using dot, then put each element separated by “[.]”
Let us see the following implementation to get better understanding −
 Live Demo
class Solution(object):
   def defangIPaddr(self, address):
      address = address.split(".")
      return "[.]".join(address)
ob1 = Solution()
print(ob1.defangIPaddr("192.168.4.1"))
"192.168.4.1"
"192[.]168[.]4[.]1"