code-rag-bench/online-tutorials huggingface dataset:
Matplotlib.dates.drange() in Python

19 Apr, 2020
Matplotlib is an amazing visualization library in Python for 2D plots of arrays. Matplotlib is a multi-platform data visualization library built on NumPy arrays and designed to work with the broader SciPy stack.
The matplotlib.dates.drange() function returns a sequence of equally spaced Matplotlib dates. The date range starts from ‘dstart’ and go up to, but not including ‘dend’. The space between each date is called delta.
Syntax: matplotlib.dates.drange(dstart, dend, delta)
Parameters:
dstart: Starting point of the date range and is a python’s datetime date.dend: Ending point of the date range and is a python’s datetime date.delta: It represents the spacing between each dates and belongs to python’s datetime.timedelta.
dstart: Starting point of the date range and is a python’s datetime date.
dend: Ending point of the date range and is a python’s datetime date.
delta: It represents the spacing between each dates and belongs to python’s datetime.timedelta.
Returns: It returns a numpy array which is a list of floats representing Matplotlib dates.
Example 1:
import datetimeimport matplotlib.pyplot as pltfrom matplotlib.dates import DayLocator, HourLocator, DateFormatter, drangeimport numpy as np    date_1 = datetime.datetime( 2020, 3, 2)date_2 = datetime.datetime( 2020, 10, 10)  time_delta = datetime.timedelta(days = 28)dates = drange(date_1, date_2, time_delta)  y_axis = np.arange( len(dates) )  fig, ax = plt.subplots()ax.plot_date(dates, y_axis * y_axis)  ax.xaxis.set_major_formatter( DateFormatter('% Y-% m') )  plt.show()
Output:
Example 2:
import datetimeimport matplotlib.pyplot as pltimport matplotlib.dates as mdates  date = [datetime.datetime(2020, 8, 24, 0, 0),        datetime.datetime(2020, 8, 23, 0, 0),         datetime.datetime(2020, 8, 22, 0, 0),         datetime.datetime(2020, 8, 21, 0, 0),         datetime.datetime(2020, 8, 18, 0, 0),        datetime.datetime(2020, 8, 17, 0, 0),        datetime.datetime(2020, 8, 16, 0, 0),        datetime.datetime(2020, 8, 15, 0, 0),        datetime.datetime(2020, 8, 14, 0, 0),        datetime.datetime(2020, 8, 11, 0, 0),        datetime.datetime(2020, 8, 10, 0, 0),         datetime.datetime(2020, 8, 9, 0, 0),        datetime.datetime(2020, 8, 8, 0, 0),        datetime.datetime(2020, 8, 7, 0, 0),        datetime.datetime(2020, 8, 4, 0, 0),        datetime.datetime(2020, 8, 3, 0, 0),        datetime.datetime(2020, 8, 2, 0, 0),        datetime.datetime(2020, 8, 1, 0, 0)]  # is a datetime.datetime object # according to typestart_date = date[0]  # is a datetime.datetime object according # to type    end_date = date[-1]delta = datetime.timedelta(days = 5)  # the drange functiondates = mdates.drange(start_date, end_date, -delta)y_data = range(len(dates))  plt.plot(dates, y_data)
Output:
Python-matplotlib
Python
Write From Home
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
D3.js nest.key() Function

19 Jul, 2020
nest.key() function in D3.js is used to register a new key function which is invoked for each element in the input array. Whenever a new key is registered, it is then pushed in the array to the end.
Syntax:
nest.keys(key)
Parameters:
It takes only one parameter i.e the key function.
Return: It returns a string identifier.
Below given are few examples that explain the function in a better way.
Example 1:
<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <meta name="viewport"         content="width=device-width,                  initial-scale=1.0">  <title>Document</title></head><style>  .originalColor{    height: 100px;    width: 100px;  }  .darkerColor{    height: 100px;    width: 100px;  }</style><body>      <!-- Fetching from CDN of D3.js -->  <script type = "text/javascript"           src = "https://d3js.org/d3.v4.min.js"></script>  <script>    let collection=[      {val:"val1"},      {val:"val2"},      {val:"val3"},      {val:"val4"}    ]    let data=d3.nest().key((d)=>{return d.val})                      .entries(collection)    console.log(data);  </script></body></html>
Output:
Example 2:
<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <meta name="viewport"         content="width=device-width,                 initial-scale=1.0">  <title>Document</title></head><style>  .originalColor{    height: 100px;    width: 100px;  }  .darkerColor{    height: 100px;    width: 100px;  }</style><body>      <!--fetching from CDN of D3.js -->  <script type = "text/javascript"          src = "https://d3js.org/d3.v4.min.js">   </script>  <script>    let collection=[      {val:"val1", data:"data1", anotherData:"data1"},      {val:"val2", data:"data2", anotherData:"data2"},      {val:"val3", data:"data3", anotherData:"data3"},      {val:"val4", data:"data4", anotherData:"data4"}    ]    //key is added    let data=d3.nest().key((d)=>{return d.val})                      //another key is nested and added                      .key((d)=>{return d.data})                      //another key is added and nested                      .key((d)=>{return d.anotherData})                      .entries(collection)    console.log(data);  </script></body></html>
Output:
D3.js
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to access an associative array by integer index in PHP? - GeeksforGeeks

11 Feb, 2019
There are two types of arrays in PHP, indexed and associative arrays. In case of indexed array strict numeric indexing is followed but in case of associative array there are keys corresponding to each element.The elements of an associative array can only be accessed by the corresponding keys. As there is not strict indexing between the keys, accessing the elements normally by integer index is not possible in PHP.
Although the array_keys() function can be used to get an indexed array of keys for an associative array. As the resulting array is indexed the elements of the resulting array can be accessed by integer index. Using this resulting array, the keys of the original array can be accessed by integer index and then the keys can be used to access the elements of the original array. Thus by using the integer index the elements of the original array can be accessed with the help of an additional indexed array of keys.
array_keys() function: The array_keys() function takes an array as input and returns an indexed array which consists only the keys of the original array, indexed where indexing is started from zero.
Syntax:
array array_keys( $arr )
Parameters: The array_keys() function takes an array as input and use only the keys of the array to make the indexed resulting array.
Note: The array_keys() function does not change the order of the keys of the original array. If an indexed array is passed then the resulting array will have integers as value.
Program: PHP program to access an associative array using integer index.
<?php// PHP program to accessing an associative// array by integer index  // Sample associative array$arr = array( 'one' => 'geeks',              'two' => 'for',               'three' => 'geeks'        );      // Getting the keys of $arr// using array_keys() function$keys = array_keys( $arr );      echo "The keys array: ";  print_r($keys);      // Getting the size of the sample array$size = sizeof($arr);      //Accessing elements of $arr using//integer index using $xecho "The elements of the sample array: " . "\n";  for($x = 0; $x < $size; $x++ ) {    echo "key: ". $keys[$x] . ", value: "             . $arr[$keys[$x]] . "\n";}      ?>
The keys array: Array
(
    [0] => one
    [1] => two
    [2] => three
)
The elements of the sample array: 
key: one, value: geeks
key: two, value: for
key: three, value: geeks

Picked
PHP
PHP Programs
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Insert Form Data into Database using PHP ?
How to convert array to string in PHP ?
PHP | Converting string to Date and DateTime
Download file from URL using PHP
How to fetch data from localserver database and display on HTML table using PHP ?
How to Insert Form Data into Database using PHP ?
How to convert array to string in PHP ?
How to call PHP function on the click of a Button ?
How to fetch data from localserver database and display on HTML table using PHP ?
Split a comma delimited string into an array in PHP
Tryit Editor v3.6 - Show Node.js Command Prompt

var mysql = require('mysql');
​
var con = mysql.createConnection({
  host: "localhost",
  user: "myusername",
  password: "mypassword",
  database: "mydb"
});
​
con.connect(function(err) {
  if (err) throw err;
[
  { id: 1, name: 'John', address: 'Highway 71'},
  { id: 2, name: 'Peter', address: 'Lowstreet 4'},
  { id: 3, name: 'Amy', address: 'Apple st 652'},
  { id: 4, name: 'Hannah', address: 'Mountain 21'},
  { id: 5, name: 'Michael', address: 'Valley 345'},
  { id: 6, name: 'Sandy', address: 'Ocean blvd 2'},
  { id: 7, name: 'Betty', address: 'Green Grass 1'},
  { id: 8, name: 'Richard', address: 'Sky st 331'},
  { id: 9, name: 'Susan', address: 'One way 98'},
  { id: 10, name: 'Vicky', address: 'Yellow Garden 2'},
  { id: 11, name: 'Ben', address: 'Park Lane 38'},
  { id: 12, name: 'William', address: 'Central st 954'},
  { id: 13, name: 'Chuck', address: 'Main Road 989'},
  { id: 14, name: 'Viola', address: 'Sideway 1633'}
Java Program for Iterative Merge Sort

Following is the Java program for Iterative Merge Sort −
 Live Demo
import java.util.Arrays;
public class Demo{
   public static void merge_sort(int[] my_arr){
      if(my_arr == null){
         return;
      }
      if(my_arr.length > 1){
         int mid = my_arr.length / 2;
         int[] left = new int[mid];
         for(int i = 0; i < mid; i++){
            left[i] = my_arr[i];
         }
         int[] right = new int[my_arr.length - mid];
         for(int i = mid; i < my_arr.length; i++){
            right[i - mid] = my_arr[i];
         }
         merge_sort(left);
         merge_sort(right);
         int i = 0;
         int j = 0;
         int k = 0;
         while(i < left.length && j < right.length){
            if(left[i] < right[j]){
               my_arr[k] = left[i];
               i++;
            } else {
               my_arr[k] = right[j];
               j++;
            }
            k++;
         }
         while(i < left.length){
            my_arr[k] = left[i];
            i++;
            k++;
         }
         while(j < right.length){
            my_arr[k] = right[j];
            j++;
            k++;
         }
      }
   }
   public static void main(String[] args){
      int my_arr[] = {56, 78, 91, 21, 34, 0, 11};
      int i=0;
      merge_sort(my_arr);
      System.out.println("The array after sorting is ");
      for(i=0; i<my_arr.length; i++)
      System.out.print(my_arr[i]+" ");
   }
}
The array after sorting is
0 11 21 34 56 78 91
A class named Demo contains the ‘merge_sort’ function, that checks if the array is empty, if yes, returns nothing. If the length of the array is greater than one, the value for ‘mid’ is calculated and the array is iterated over upto the ‘mid’ value. Basically the array is divided into two equal parts and the elements to the left of the array are put into a new array and the elements to the right of the array are put into a different array. Now, these arrays are separated and sorted. Then they are merged together.
In the main function, the array is defined and the function is called on this array elements. The output is displayed on the console.
JavaScript | Convert a string to boolean

28 Mar, 2019
Sometimes it is needed to convert a string representing boolean value “true”, “false” into intrinsic type of JavaScript. Given a string and the task is to convert given string to its boolean value.
Example 1: This example uses == operator to convert string to its boolean value.
<!DOCTYPE html> <html>   <head>     <title>         Convert string to boolean    </title></head>           <body style = "text-align:center;">           <h1 style = "color:green;" >         GeeksForGeeks     </h1>               <input id = "input" type="text" name="input"/>           <button onclick="convertToBoolean()">         Click to convert    </button>           <h3 id = "div" style="color: green"></h3>          <!-- Script to convert string to its        boolean value -->        <script>         function convertToBoolean() {            var input = document.getElementById("input");            var x = document.getElementById("div");            var str = input.value;            x.innerHTML = str == 'true';        }    </script> </body>   </html>                    
Output:
Before click on the button:
After click on the button:
Example 2: This example uses === operator to convert string to its boolean value.
<!DOCTYPE html> <html>   <head>     <title>         Convert string to boolean    </title></head>           <body style = "text-align:center;">           <h1 style = "color:green;" >         GeeksForGeeks     </h1>                   <input id = "input" type="text" name="input"/>           <button onclick="convertToBoolean()">         Click to convert    </button>           <h3 id = "div" style="color: green"></h3>          <!-- Script to convert string to its        boolean value -->    <script>         function convertToBoolean() {            var input = document.getElementById("input");            var x = document.getElementById("div");            var str = input.value;            x.innerHTML = str === 'true';        }    </script> </body>   </html>                    
Output:
Before click on the button:
After click on the button:
javascript-string
JavaScript
Web Technologies
Web technologies Questions
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
Remove elements from a JavaScript Array
Difference Between PUT and PATCH Request
How to append HTML code to a div using JavaScript ?
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
Remove key value from Map in Scala

13 Aug, 2019
The deletion of Scala map keys can be obtained by utilizing – operator. This operator is utilized to delete the set of keys of the map.Syntax:
def -(elem1: A, elem2: A, elems: A*): Map[A, B]

It returns a new map containing all the elements of the given Map except the set of keys which are deleted using the above operator.Example #1:
// Scala program of deleting // keys  // Creating objectobject GfG{       // Main method    def main(args:Array[String])    {              // Creating a map        val m1 = Map("geeks" -> 5, "for" -> 3)                   // Applying - operator        val result = m1.-("for")                  // Displays output        println(result)          }}
Map(geeks -> 5)

In above example here for key is deleted.Example #2:
// Scala program of deleting // keys  // Creating objectobject GfG{       // Main method    def main(args:Array[String])    {              // Creating a map        val m1 = Map("geeks" -> 5, "for" -> 3, "cs" -> 2)                   // Applying - operator        val result = m1.-("for", "geeks")                  // Displays output        println(result)          }}
Map(cs -> 2)

Scala
Scala-Map
Scala
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Type Casting in Scala
Class and Object in Scala
Scala Tutorial – Learn Scala with Step By Step Guide
Scala Lists
Operators in Scala
Scala String substring() method with example
Scala | Arrays
Scala Constructors
Enumeration in Scala
Inheritance in Scala
Plot a bar using matplotlib using a dictionary

First, we can define our dictionary and then, convert that dictionary into keys and values. Finally, we can use the data to plot a bar chart.
Create a dictionary, i.e., data, where milk and water are the keys.
Create a dictionary, i.e., data, where milk and water are the keys.
Get the list of keys of the dictionary.
Get the list of keys of the dictionary.
Get the list of values of the dictionary.
Get the list of values of the dictionary.
Plot the bar using plt.bar().
Plot the bar using plt.bar().
Using plt.show(), show the figure.
Using plt.show(), show the figure.
import matplotlib.pyplot as plt

data = {'milk': 60, 'water': 10}
names = list(data.keys())
values = list(data.values())

plt.bar(range(len(data)), values, tick_label=names)
plt.show()
\mbox - Tex Command

\mbox - creates a box just wide enough to hold the text in its argument;no linebreaks are allowed in the text;text appears in \rm. 
{ \mbox <text argument>}
\mbox command creates a box just wide enough to hold the text in its argument;no linebreaks are allowed in the text;text appears in \rm.

a + b \mbox{ (are you paying attention?) } = c

a+b (are you paying attention?) =c


a + b \text{ (are you paying attention?) } = c

a+b (are you paying attention?) =c



a + b \mbox{ (are you paying attention?) } = c

a+b (are you paying attention?) =c


a + b \mbox{ (are you paying attention?) } = c
a + b \text{ (are you paying attention?) } = c

a+b (are you paying attention?) =c


a + b \text{ (are you paying attention?) } = c

    14 Lectures 
     52 mins

 Ashraf Said

    11 Lectures 
     1 hours 

 Ashraf Said

    9 Lectures 
     1 hours 

 Emenwa Global, Ejike IfeanyiChukwu

    29 Lectures 
     2.5 hours 

 Mohammad Nauman

    14 Lectures 
     1 hours 

 Daniel Stern

    15 Lectures 
     47 mins

 Nishant Kumar
 Print
 Add Notes
 Bookmark this page
Getting an array of all items of a collection in Julia - collect() Method - GeeksforGeeks

26 Mar, 2020
The collect() is an inbuilt function in julia which is used to return an array of all items in the specified collection or iterator.
Syntax:collect(collection)orcollect(element_type, collection)
Parameters:
collection: Specified collection or iterator.
element_type: Specified type of elements.
Returns: It returns an array of all items in the specified collection or iterator.
Example 1:
# Julia program to illustrate # the use of collection() method  # Getting an array of all items in# the specified collection or iterator.println(collect(1:2:13))println(collect(1:4))println(collect(1:10))println(collect(1:5:10))
Output:
[1, 3, 5, 7, 9, 11, 13]
[1, 2, 3, 4]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
[1, 6]

Example 2:
# Julia program to illustrate # the use of collection() method  # Getting an Array with the given # element type of all items in # a collection or iterable.println(collect(Int32, 1:2:5))println(collect(Int64, 1:5))println(collect(Float32, 1:2:5))println(collect(Float64, 1:5))
Output:
Int32[1, 3, 5]
[1, 2, 3, 4, 5]
Float32[1.0, 3.0, 5.0]
[1.0, 2.0, 3.0, 4.0, 5.0]

Julia
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Vectors in Julia
Storing Output on a File in Julia
Reshaping array dimensions in Julia | Array reshape() Method
Getting rounded value of a number in Julia - round() Method
Creating array with repeated elements in Julia - repeat() Method
Get array dimensions and size of a dimension in Julia - size() Method
Searching in Array for a given element in Julia
Taking Input from Users in Julia
while loop in Julia
Tuples in Julia
Tryit Editor v3.7

Tryit: HTML link to another folder
Difference between OOP and POP - GeeksforGeeks

20 Aug, 2019
OOP:Related with the real life objects and their properties. OOP Concepts:
1. Class and Objects
2. Data abstraction
3. Encapsulation
4. Polymorphism
5. Inheritance 
POP:Related with the conventional style. This approach is also known as the top-down approach. In this approach, a program is divided into functions that perform specific tasks. This approach is mainly used for medium-sized applications. Data is global, and all the functions can access global data. The basic drawback of the procedural programming approach is that data is not secured because data is global and can be accessed by any function. Program control flow is achieved through function calls and go to statements.
Difference between OOP and POP:
Santosh Kumar 7
Object-Oriented-Design
Difference Between
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Difference Between Method Overloading and Method Overriding in Java
Difference between Prim's and Kruskal's algorithm for MST
Difference between Internal and External fragmentation
Differences and Applications of List, Tuple, Set and Dictionary in Python
Difference between HashMap and HashSet
Difference between Compile-time and Run-time Polymorphism in Java
Similarities and Difference between Java and C++
Difference between List and ArrayList in Java
Difference Between map() And flatMap() In Java Stream
Tryit Editor v3.7

Tryit: SVG circle
XAML Vs C# Code

You can use XAML to create, initialize, and set the properties of objects. The same activities can also be performed using programming code.
XAML is just another simple and easy way to design UI elements. With XAML, it is up to you to decide whether you want to declare objects in XAML or declare them using code.
Let’s take a simple example to demonstrate how to write in XAML −
<Window x:Class = "XAMLVsCode.MainWindow"
   xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x = "http://schemas.microsoft.com/winfx/2006/xaml" Title = "MainWindow" Height = "350" Width = "525"> 
	
   <StackPanel> 
      <TextBlock Text = "Welcome to XAML Tutorial" Height = "20" Width = "200" Margin = "5"/>
      <Button Content = "Ok" Height = "20" Width = "60" Margin = "5"/> 
   </StackPanel> 
	
</Window> 
In this example, we have created a stack panel with a Button and a Text block and defined some of the properties of button and text block such as Height, Width, and Margin. When the above code is compiled and executed, it will produce the following output −
Now look at the same code which is written in C#.
using System; 
using System.Text; 
using System.Windows; 
using System.Windows.Controls;  

namespace XAMLVsCode { 
   /// <summary> 
      /// Interaction logic for MainWindow.xaml 
   /// </summary> 
	
   public partial class MainWindow : Window {
      public MainWindow() { 
         InitializeComponent();  
         
         // Create the StackPanel 
         StackPanel stackPanel = new StackPanel();
         this.Content = stackPanel; 
			
         // Create the TextBlock 
         TextBlock textBlock = new TextBlock(); 
         textBlock.Text = "Welcome to XAML Tutorial"; 
         textBlock.Height = 20;
         textBlock.Width = 200; 
         textBlock.Margin = new Thickness(5); 
         stackPanel.Children.Add(textBlock);  
			
         // Create the Button 
         Button button = new Button(); 
         button.Content = "OK"; 
         button.Height = 20; 
         button.Width = 50; 
         button.Margin = new Thickness(20); 
         stackPanel.Children.Add(button); 
      } 
   }
}
When the above code is compiled and executed, it will produce the following output. Note that it is exactly the same as the output of XAML code.
Now you can see that how simple it is to use and understand XAML.
 Print
 Add Notes
 Bookmark this page
Bandit - A Wargame For Linux Beginners - GeeksforGeeks

22 Jan, 2021
The Bandit is a wargame for those who are beginners at Linux/UNIX environment and are facing problems while learning the real-time use of Linux commands. The game will teach the basics of Linux and will make you compatible to play even other wargames. This game basically provides you the environment which is similar to real-time with files having data the same as used in real time. Basically, the game starts with level 0. Then to proceed further you have to visit the Official Game Website and there is a hint for every level would be given. What you have to do is just go through the hint, find the password for the next level using that hint and proceed further. And to get the password you will have to use Linux Commands which will help you in understanding the Linux commands easily.  
1. Open Terminal and Enter the following command.  
$ssh bandit0@bandit.labs.overthewire.org -p 2220
It will ask for a password 
Enter password -> bandit0
2. After entering the password you will be connected to the server of the game. 
Now enter the following command 
$ls
$cat readme
3. It will give you the password for the next level. The highlighted text in the image is the password for the next level. 
Now, after getting your first level done, use the exit command to exit the current level. Similarly, continue with the game, now to connect to level 1 use the following command. 
$ssh bandit1@bandit.labs.overthewire.org -p 2220
It will ask for the password. Enter the password we get from level 0. Bravo! You are in the game. Meanwhile, you will face some problems but keep going you will rock the game and will master Linux commands. 
shreya18bit1140
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++
SED command in Linux | Set 2
mv command in Linux with examples
Docker - COPY Instruction
chown command in Linux with Examples
Array Basics in Shell Scripting | Set 1
Basic Operators in Shell Scripting
nslookup command in Linux with Examples
Finding minimum absolute difference within a Binary Search Tree in JavaScript

We are required to write a JavaScript function that takes in the root of a BST that holds some numerical data like this −
1
\
3
/
2
The function should return the minimum absolute difference between any two nodes of the tree.
For example −
For the above tree, the output should be −
const output = 1;
because |1 - 2| = |3 - 2| = 1
The code for this will be −
 Live Demo
class Node{
   constructor(data) {
      this.data = data;
      this.left = null;
      this.right = null;
   };
};
class BinarySearchTree{
   constructor(){
      // root of a binary seach tree
      this.root = null;
   }
   insert(data){
      var newNode = new Node(data);
      if(this.root === null){
         this.root = newNode;
      }else{
         this.insertNode(this.root, newNode);
      };
   };
   insertNode(node, newNode){
      if(newNode.data < node.data){
         if(node.left === null){
            node.left = newNode;
         }else{
            this.insertNode(node.left, newNode);
         };
      } else {
         if(node.right === null){
            node.right = newNode;
         }else{
            this.insertNode(node.right,newNode);
         };
      };
   };
};
const BST = new BinarySearchTree();
BST.insert(1);
BST.insert(3);
BST.insert(2);
const getMinimumDifference = function(root) {
   const nodes = [];
   const dfs = (root) => {
      if(root) {
         dfs(root.left);
         nodes.push(root.data);
         dfs(root.right);
      };
   };
   dfs(root);
   let result = nodes[1] - nodes[0];
   for(let i = 1; i < nodes.length - 1; i++) {
      result = Math.min(result, nodes[i + 1] - nodes[i]);
   };
   return result;
};
console.log(getMinimumDifference(BST.root));
And the output in the console will be −
1
List add() Method in Java with Examples - GeeksforGeeks

02 Jan, 2019
This method of List interface is used to append the specified element in argument to the end of the list.
Syntax:
boolean add(E e)
Parameters: This function has a single parameter, i.e, e – element to be appended to this list.
Returns: It returns true if the specified element is appended and list changes.
Below programs show the implementation of this method.
Program 1:
// Java code to show the implementation of// add method in list interfaceimport java.util.*;public class GfG {      // Driver code    public static void main(String[] args)    {        List<Integer> l = new ArrayList<>();        l.add(10);        l.add(15);        l.add(20);        System.out.println(l);    }}
[10, 15, 20]

Program 2: Below is the code to show implementation of list.add() using Linkedlist.
// Java code to show the implementation of// add method in list interface using LinkedListimport java.util.*;public class CollectionsDemo {      // Driver code    public static void main(String[] args)    {          List<Integer> ll = new LinkedList<>();        ll.add(100);        ll.add(200);        ll.add(300);        ll.add(400);        ll.add(500);          System.out.println(ll);    }}
[100, 200, 300, 400, 500]

Reference:Oracle Docs
Java - util package
Java-Collections
Java-Functions
java-list
Java
Java
Java-Collections
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Initialize an ArrayList in Java
HashMap in Java with Examples
Interfaces in Java
Multidimensional Arrays in Java
Stream In Java
Stack Class in Java
Singleton Class in Java
Set in Java
Overriding in Java
Collections in Java
Check Armstrong Number in PL/SQL

04 Jul, 2018
Given a number x, determine whether the given number is Armstrong number or not. A positive integer of n digits is called an Armstrong number of order n (order is number of digits) if.
abcd... = pow(a, n) + pow(b, n) + pow(c, n) + pow(d, n) + .... 
Example:
Input : 153
Output : Yes
153 is an Armstrong number.
1*1*1 + 5*5*5 + 3*3*3 = 153

Input : 120
Output : No
120 is not a Armstrong number.
1*1*1 + 2*2*2 + 0*0*0 = 9

Input : 1253
Output : No
1253 is not a Armstrong Number
1*1*1*1 + 2*2*2*2 + 5*5*5*5 + 3*3*3*3 = 723

Input : 1634
Output : Yes
1*1*1*1 + 6*6*6*6 + 3*3*3*3 + 4*4*4*4 = 1634
declare-- declare variable n, s,r, len-- and m of datatype number    n number:=1634;    s number:=0;    r number;    len number;    m number;  begin    m := n;      len := length(to_char(n));          -- while loop till n>0    while n>0    loop        r := mod(n , 10);        s := s + power(r , len);        n := trunc(n / 10);    end loop;          if m = s    then        dbms_output.put_line('yes');    else        dbms_output.put_line('no');    end if;      end;  -- End program
output:
Yes
SQL-PL/SQL
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Update Multiple Columns in Single Update Statement in SQL?
SQL | Sub queries in From Clause
Window functions in SQL
What is Temporary Table in SQL?
SQL Query to Find the Name of a Person Whose Name Starts with Specific Letter
SQL using Python
SQL Query to Convert VARCHAR to INT
RANK() Function in SQL Server
How to Import JSON Data into SQL Server?
SQL Query to Compare Two Dates
Retrieve elements from Python Set

18 Jan, 2022
Prerequisites: Python Set
In this article, we will discuss how to retrieve elements from the sets in Python.
By iterating the elements in a set using for loop we can get them all set elements.
Example:
Python3
# create a set with integer elementsdata = {7058, 7059, 7072, 7074, 7076} # display set elements using for loopfor i in data:    print(i) print("----") # create a set with string elementsdata1 = {"sravan", "harsha", "jyothika"} # display set elements using for loopfor i in data1:    print(i)
Output:
7072
7074
7076
7058
7059
----
sravan
harsha
jyothika
In set we can not perform indexing, first, we have to convert that set into a list and then perform the indexing. So we are using list() function to convert the set into the list.
Example:
Python3
# create a set with integer elementsdata = {7058, 7059, 7072, 7074, 7076} # retrieve 1 st elementprint(list(data)[0]) # retrieve 4 th  elementprint(list(data)[3]) # retrieve last  elementprint(list(data)[-1])
Output:
7072
7058
7059
We can convert it into a list and then access the last element by using pop() function. This will get the last element or we can also use index = -1 to get the last element.
Example:
Python3
# create a set with integer elementsdata = {7058, 7059, 7072, 7074, 7076} # retrieve last elementprint(list(data)[-1]) # retrieve last elementprint(list(data).pop())
Output:
7076
7076
We can access the first item in the set by using iter() function, we have to apply next() to it to get the first element.
Syntax: next(iter(set))
Example:
Python3
# create a set with integer elementsdata = {7058, 7059, 7072, 7074, 7076}  # retrieve first elementprint(next(iter(data)))
Output:
7058
We can also use first() method from the iteration_utilities module, Which will return the first element.
Syntax: first(set)
Example:
Python3
# import iteration_utilitiesfrom iteration_utilities import first # create a set with integer elementsdata = {7058, 7059, 7072, 7074, 7076}  # retrieve first elementprint(first(data))
Output:
7058
We can get n number of random elements from a set using sample() function. This is available in a random module and this will return a list of sample elements.
Example:
Python3
# import random moduleimport random # create a set with integer elementsdata = {7058, 7059, 7072, 7074, 7076}  # retrieve 2 random elementsprint(random.sample(data, 2)) # retrieve 1 random elementprint(random.sample(data, 1)) # retrieve 4 random elementsprint(random.sample(data, 4))
Output:
[7058, 7074]
[7072]
[7059, 7074, 7058, 7076]
gulshankumarar231
Picked
python-set
Python
python-set
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Consecutive elements pairing in list

18 May, 2020
Sometimes, while working with lists, we need to pair up the like elements in the list and then store them as lists of lists. This particular task has its utility in many domains, be it web development or day-day programming. Let’s discuss certain ways in which this can be achieved.
Method #1 : Using list comprehensionThe list comprehension can be easily used to perform this particular task, but consecutively making the pairs of i’th and (i+1)th element.
# Python3 code to demonstrate# consecutive element pairing # using list comprehension  # initializing listtest_list = [5, 4, 1, 3, 2]  # printing original listprint("The original list : " + str(test_list))  # using list comprehension# consecutive element pairing res = [[test_list[i], test_list[i + 1]]        for i in range(len(test_list) - 1)]  # print resultprint("The consecutive element paired list is : " + str(res))
    
The original list : [5, 4, 1, 3, 2]
The consecutive element paired list is : [[5, 4], [4, 1], [1, 3], [3, 2]]

 
Method # 2: Using zip()This task can also be achieved using only the zip function which performs the task for all the elements.
# Python3 code to demonstrate# consecutive element pairing # using zip()  # initializing listtest_list = [5, 4, 1, 3, 2]  # printing original listprint("The original list : " + str(test_list))  # using zip()# consecutive element pairing res = list(zip(test_list, test_list[1:]))  # print resultprint("The consecutive element paired list is : " + str(res))
    
The original list : [5, 4, 1, 3, 2]
The consecutive element paired list is : [[5, 4], [4, 1], [1, 3], [3, 2]]

mvdream02
Python list-programs
python-list
Python
Python Programs
python-list
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Enumerate() in Python
Different ways to create Pandas Dataframe
Read a file line by line in Python
How to Install PIP on Windows ?
Python program to convert a list to string
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python | Convert string dictionary to dictionary
GATE | Gate IT 2005 | Question 8

29 Mar, 2018
Using Booth’s Algorithm for multiplication, the multiplier -57 will be recoded as(A) 0 -1 0 0 1 0 0 -1(B) 1 1 0 0 0 1 1 1(C) 0 -1 0 0 1 0 0 0(D) 0 1 0 0 -1 0 0 1Answer: (A)Explanation: Booth’s algorithm: first take 2’s complement of given number if number is negative, then append 0 into LSB.
Then, for each pair from LSB to MSB (add 1 bit at a time):
00 = 0, 01 = +1, 10 = -1, 11 = 0
Therefore, given number in signed representation (2’s complementation) of -57
= 2's complement of (00111001) = 11000110+1 = 11000111
= append 0 into LSB of (11000111) = 110001110
Now Booth's code (add 1 bit at a time, from LSB to MSB):
= 11, 10, 00, 00, 01, 11, 11, 10 = 0 -1 0 0 1 0 0 -1
Alternative way –You can calculated decimal values in given options:(A) 0 -1 0 0 1 0 0 -1 = 0*(2^6) -1*(2^6) + 0*(2^5) + 0*(2^4) + 1*(2^3) + 0*(2^2) + 0*(2^1) -1*(2^0) = -2^6 + 2^3 – 2^0 = -64 +8 -1 = -57(B) 1 1 0 0 0 1 1 1 = 2^7 + 2^6 + 2^2 2^1 + 2^0 = 199(C) 0 -1 0 0 1 0 0 0 = -2^6 + 2^3 = -56(D) 0 1 0 0 -1 0 0 1 = 2^6 – 2^3 + 2^0 = 57
So, option (A) is correct.Quiz of this Question
Gate IT 2005
GATE-Gate IT 2005
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | GATE-CS-2014-(Set-2) | Question 65
GATE | Sudo GATE 2020 Mock I (27 December 2019) | Question 33
GATE | GATE-CS-2014-(Set-3) | Question 20
GATE | GATE-CS-2015 (Set 3) | Question 65
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE CS 2008 | Question 46
GATE | GATE CS 1996 | Question 63
GATE | Gate IT 2005 | Question 52
GATE | GATE CS 2012 | Question 18
GATE | GATE-CS-2001 | Question 50
How to draw a polyline in HTML5 SVG?

SVG stands for Scalable Vector Graphics and is a language for describing 2D-graphics and graphical applications in XML and the XML is then rendered by an SVG viewer. Most of the web browsers can display SVG just like they can display PNG, GIF, and JPG.
To draw a polygon in HTML SVG, use the SVG <polyline> element. The <polyline> element is to create a shape that consists of straight lines. The points attribute is the x and y coordinates for each corner.
You can try to run the following code to learn how to draw a polyline in HTML5 SVG:
<!DOCTYPE html>
<html>
   <head>
      <style>
         #svgelem {
            position: relative;
            left: 20%;
            -webkit-transform: translateX(-20%);
            -ms-transform: translateX(-20%);
            transform: translateX(-20%);
         }
      </style>
      <title>HTML5 SVG Polyline</title>
   </head>

   <body>
      <h2>HTML5 SVG Polyline</h2>
      <svg id="svgelem" width="300" height="300" xmlns="http://www.w3.org/2000/svg">
         <polyline points="0,0 0,20 20,20 20,40 40,40 40,60" fill="red" />
      </svg>
   </body>
</html>
jQuery | :has() Selector with example - GeeksforGeeks

27 Feb, 2019
The :has() selector in jQuery is used to select all elements that have one or more elements inside of them, that matches the specified selector.
Syntax:
$(":has(selector)")
Parameter: This selector contains single parameter selector which is mandatory and used to specify the element to select. It is also required to accept any kind of selector.
Example 1: This example uses :has selector to select <h2> span element to create solid green border.
<!DOCTYPE html><html>   <head>      <title>jQuery :has() Selector</title>              <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">      </script>              <!-- Script to use :has selector -->      <script>         $(document).ready(function(){           $("h2:has(span)").css("border", "solid green");         });      </script>   </head>        <body>      <center>         <h1 id="geeks1" style = "color:green;">GeeksForGeeks</h1>         <h2 id="geeks2"><span>jQuery :has() Selector</span></h2>      </center>   </body></html>
Output:
Example 2: This example uses :has selector to select element and create border.
<!DOCTYPE html><html>   <head>      <title>jQuery :has() Selector</title>              <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">      </script>              <!-- Script to use :has selector -->      <script>         $(document).ready(function(){           $("body:has(h1, span)").css("border", "solid green");         });      </script>   </head>        <body>      <center>         <h1 id="geeks1" style = "color:green;">GeeksForGeeks</h1>         <h2 id="geeks2"><span>jQuery :has() Selector</span></h2>      </center>   </body></html>
Output:
jQuery-Selectors
JQuery
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Form validation using jQuery
How to Dynamically Add/Remove Table Rows using jQuery ?
How to Show and Hide div elements using radio buttons?
Scroll to the top of the page using JavaScript/jQuery
jQuery | children() with Examples
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Tryit Editor v3.7

Background Image Repeat
Tryit: Strange background image
How to change text font for JLabel with HTML in Java?

To change text font, you can use the setFont() method of JLabel −
label.setFont(new Font("Verdana", Font.PLAIN, 12));
The following is an example to change text font for JLabel with HTML −
import java.awt.Font;
import javax.swing.*;
public class SwingDemo {
   public static void main(String args[]) {
      JFrame frame = new JFrame("Label Example");
      JLabel label;
      label = new JLabel("<html><font size=+1>" + "<center>ABC</html>");
      label.setBounds(50, 50, 100, 30);
      label.setFont(new Font("Verdana", Font.PLAIN, 12));
      frame.add(label);
      frame.setSize(500,300);
      frame.setLayout(null);
      frame.setVisible(true);
   }
}
How do I set browser width and height in Selenium WebDriver?

We can set browser width and height in Selenium webdriver. There are multiple methods available to achieve this. Whenever an application is launched, it opens in its default browser size.
We can resize the browser with the help of the Dimension class in Java. We create an object of the Dimension class and pass the desired width and height of the browser as parameters to that class. Finally we pass the object of the Dimension class as an argument to the setSize method.
Dimension dem = new Dimension(750,450);
driver.manage().window().setSize(dem);
We can also set the browser width and height with the help of Chrome options. We have to create an object of the ChromeOptions class and apply addArguments to it. The parameter window-size set with values of height and width of the browser are passed as arguments to the method. This knowledge is passed to the browser invocation method with the help of DesiredCapabilities class.
ChromeOptions options = new ChromeOptions();
options.addArguments("window-size=750,450");

DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
Code Implementation with Dimension class.
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class BrowserResize{
   public static void main(String[] args) {
      System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      String url = " https://www.tutorialspoint.com/tutor_connect/index.php";
      driver.get(url);
      // Dimension class with browser width and height value passed
      Dimension dem = new Dimension(750,450);
      // passing the Dimension object as an argument to setSize method
      driver.manage().window().setSize(dem);
Implementation with Chrome Options.
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class BrowserResizeOptions{
   public static void main(String[] args) {
      System.setProperty("webdriver.chrome.driver", "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
      // ChromeOptions class with addArguments method
      ChromeOptions options = new ChromeOptions();
      options.addArguments("window-size=750,450");
      DesiredCapabilities capabilities = DesiredCapabilities.chrome();
      capabilities.setCapability(ChromeOptions.CAPABILITY, options);
      WebDriver driver = new ChromeDriver(capabilities);
      String url = "https://www.tutorialspoint.com/tutor_connect/index.php";
      driver.get(url);
   }
}
How to use user variables in MySQL LIKE clause?

Using the CONCAT() function, we can work with user variables in LIKE clause. The syntax is as follows.
set @anyVariableName='anyValue';
select yourColumnName1,yourColumnName2,yourColumnName3,...N from yourTableName
whereyourColumnName like CONCAT('%', @anyVariableName, '%');
To understand the above syntax, let us first create a table. The query to create a table is as follows.
mysql> create table UserVariableInLike
-> (
-> id int,
-> Name varchar(100),
-> Age int
-> );
Query OK, 0 rows affected (0.83 sec)
Insert records in the table using insert command. The query is as follows.
mysql> insert into UserVariableInLike values(101,'John',23);
Query OK, 1 row affected (0.23 sec)

mysql> insert into UserVariableInLike values(102,'John Smith',24);
Query OK, 1 row affected (0.20 sec)

mysql> insert into UserVariableInLike values(103,'Carol Smith',23);
Query OK, 1 row affected (0.15 sec)

mysql> insert into UserVariableInLike values(104,'Johnson',25);
Query OK, 1 row affected (0.20 sec)

mysql> insert into UserVariableInLike values(105,'Adam Smith',26);
Query OK, 1 row affected (0.21 sec)
Display all records from the table using select statement. The query is as follows
mysql> select *from UserVariableInLike;
The following is the output.
+------+-------------+------+
| id   | Name        | Age  |
+------+-------------+------+
| 101  | John        | 23   |
| 102  | John Smith  | 24   |
| 103  | Carol Smith | 23   |
| 104  | Johnson     | 25   |
| 105  | Adam Smith  | 26   |
+------+-------------+------+
5 rows in set (0.00 sec)
Here is the query which uses the user variable in the LIKE clause. The query is as follows −
mysql> set @searchName='John';
Query OK, 0 rows affected (0.00 sec)

mysql> select id,Name,Age from UserVariableInLike where Name like CONCAT('%',
@searchName, '%');
The following is the output.
+------+------------+------+
| id   | Name       | Age  |
+------+------------+------+
| 101  | John       | 23   |
| 102  | JohnSmith  | 24   |
| 104  | Johnson    | 25   |
+------+------------+------+
3 rows in set (0.05 sec)
Bootstrap 4 .card-group class

Use the card-group class to create a group of cards in Bootstrap 4 −
<div class="card-group">

  <div class="card bg-success">
    <! - -  One  - - >
  </div>
  <div class="card bg-success">
    <! - -  Two  - - >
  </div>
  <div class="card bg-success">
    <! - -  Three  - - >
  </div>

</div>
Let us create a group of cards like a grid in Bootstrap −
Live Demo
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Bootstrap Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
  </head>
<body>
  <div class="container">
    <h3>Group of Messages</h3>
    <div class="card-group">
      <div class="card bg-success">
        <div class="card-body text-center text-white">
          <p class="card-text">Argentina won convincingly!</p>
        </div>
      </div>
      <div class="card bg-primary">
        <div class="card-body text-center">
          <p class="card-text">Demo Text!</p>
        </div>
      </div>
      <div class="card bg-warning">
        <div class="card-body text-center text-white">
          <p class="card-text">Do not cross!</p>
        </div>
      </div>
      <div class="card bg-success">
        <div class="card-body text-center">
          <p class="card-text">I did it!</p>
        </div>
      </div>
      <div class="card bg-success">
        <div class="card-body text-center">
          <p class="card-text">It worked!</p>
        </div>
      </div>
    </div>
  </div>
</body>
</html>