code-rag-bench/online-tutorials huggingface dataset:
MongoDB - Database References

As seen in the last chapter of MongoDB relationships, to implement a normalized database structure in MongoDB, we use the concept of Referenced Relationships also referred to as Manual References in which we manually store the referenced document's id inside other document. However, in cases where a document contains references from different collections, we can use MongoDB DBRefs.
As an example scenario, where we would use DBRefs instead of manual references, consider a database where we are storing different types of addresses (home, office, mailing, etc.) in different collections (address_home, address_office, address_mailing, etc). Now, when a user collection's document references an address, it also needs to specify which collection to look into based on the address type. In such scenarios where a document references documents from many collections, we should use DBRefs.
There are three fields in DBRefs −
$ref − This field specifies the collection of the referenced document
$ref − This field specifies the collection of the referenced document
$id − This field specifies the _id field of the referenced document
$id − This field specifies the _id field of the referenced document
$db − This is an optional field and contains the name of the database in which the referenced document lies
$db − This is an optional field and contains the name of the database in which the referenced document lies
Consider a sample user document having DBRef field address as shown in the code snippet −
{
   "_id":ObjectId("53402597d852426020000002"),
   "address": {
   "$ref": "address_home",
   "$id": ObjectId("534009e4d852427820000002"),
   "$db": "tutorialspoint"},
   "contact": "987654321",
   "dob": "01-01-1991",
   "name": "Tom Benzamin"
}
The address DBRef field here specifies that the referenced address document lies in address_home collection under tutorialspoint database and has an id of 534009e4d852427820000002.
The following code dynamically looks in the collection specified by $ref parameter (address_home in our case) for a document with id as specified by $id parameter in DBRef.
>var user = db.users.findOne({"name":"Tom Benzamin"})
>var dbRef = user.address
>db[dbRef.$ref].findOne({"_id":(dbRef.$id)})
The above code returns the following address document present in address_home collection −
{
   "_id" : ObjectId("534009e4d852427820000002"),
   "building" : "22 A, Indiana Apt",
   "pincode" : 123456,
   "city" : "Los Angeles",
   "state" : "California"
}

    44 Lectures 
     3 hours 

 Arnab Chakraborty

    54 Lectures 
     5.5 hours 

 Eduonix Learning Solutions

    44 Lectures 
     4.5 hours 

 Kaushik Roy Chowdhury

    40 Lectures 
     2.5 hours 

 University Code

    26 Lectures 
     8 hours 

 Bassir Jafarzadeh

    70 Lectures 
     2.5 hours 

 Skillbakerystudios
 Print
 Add Notes
 Bookmark this page
Python Data Types

In programming, data type is an important concept.
Variables can store data of different types, and different types can do 
different things.
Python has the following data types built-in by default, in these categories:
You can get the data type of any object by using the type() function:
Print the data type of the variable x:
In Python, the data type is set when you assign a value to a variable:
If you want to specify the data type, you can use the following 
constructor functions:
The following code example would print the data type of x, what data type would that be?
x = 5
print(type(x))


Start the Exercise
We just launchedW3Schools videos
Get certifiedby completinga course today!
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
help@w3schools.com
Your message has been sent to W3Schools.
What does the method size() do in java?

The size() method of the class java.util.ArrayList returns the number of elements in this list i.e. the size of the list.
import java.util.ArrayList;

public class ArrayListDemo {
   public static void main(String[] args) {
      ArrayList<Integer> arrlist = new ArrayList<Integer>(5);
      arrlist.add(15);
      arrlist.add(20);
      arrlist.add(25);
      arrlist.add(22);
      for (Integer number : arrlist) {
         System.out.println("Number = " + number);
      }
      int retval = arrlist.size();
      System.out.println("Size of list = " + retval);
   }
}
Number = 15
Number = 20
Number = 25
Number = 22
Size of list = 4
MySQL query to extract last word from a field?

To extract last word from a field, use in-built SUBSTRING_INDEX() function. The syntax is as follows −
SELECT SUBSTRING_INDEX(yourColumnName,’ ‘,-1) as anyVariableName from yourTableName;
To understand the above concept, let us create a table. The following is the query to create a table −
mysql> create table FirstWordDemo
   −> (
   −> AllWords longtext
   −> );
Query OK, 0 rows affected (0.83 sec)
Now insert some words in the table using insert command. The query is as follows −
mysql> insert into FirstWordDemo values('This is the first MySQL Query');
Query OK, 1 row affected (0.11 sec)

mysql> insert into FirstWordDemo values('MySQL is a Relational Database');
Query OK, 1 row affected (0.17 sec)

mysql> insert into FirstWordDemo values('FirstWord is not correct');
Query OK, 1 row affected (0.21 sec)
Now display all records from the table using select statement. The query is as follows −
mysql> select *from FirstWordDemo;
The following is the output −
+--------------------------------+
| AllWords                       |
+--------------------------------+
| This is the first MySQL Query  |
| MySQL is a Relational Database |
| FirstWord is not correct       |
+--------------------------------+
3 rows in set (0.00 sec)
Here is the query to display the last word from a field. We discussed the same syntax in the beginning. The following is the query −
mysql> select SUBSTRING_INDEX(AllWords, ' ', -1) as MyFirstWordResult from FirstWordDemo;
The following is the output −
+-------------------+
| MyFirstWordResult |
+-------------------+
| Query             |
| Database          |
| correct           |
+-------------------+
3 rows in set (0.00 sec)
Output in C++ - GeeksforGeeks

01 Feb, 2021
In this article, we will discuss the very basic and most common I/O operations required for C++ programming. C++ runs on lots of platforms like Windows, Linux, Unix, Mac, etc. This is the most basic method for handling output in C++.The cout is used very often for printing outputs i.e.., on the monitor. The predefined object cout is an instance of iostream class. For formatted output operations, cout is used together with the insertion operator, which is written as “<<“ (i.e., two “less than” signs).  
Program 1:Below is the C++ program to demonstrate the use of cout object:
C++
// C++ program to demonstrate cout#include <iostream>using namespace std;  // Driver Codeint main(){    // Used to display the output    // to the standard output device    cout << "GeekforGeeks!";      return 0;}
GeekforGeeks!

Note:
#include is known as a preprocessor directive, which is used to load files.
iostream is a header file that contains functions for input/output operations (cin and cout).
Program 2:Below is the C++ program to demonstrate a manipulator that can be used with the cout object:
C++
// C++ program to demonstrate the// endl manipulator#include <iostream>using namespace std;  // Driver Codeint main(){      // Stores the data in a    // variable str    char str[] = "Geekforgeeks";      // Print the output    cout << " A computer science portal"         << " for geeks - " << str;      return 0;}
A computer science portal for geeks - Geekforgeeks

Program 3:
In this example, the user is asked for his/her city name, when the user enters his/her city it will store the city name in the name variable. After that console will print the output string. Below is the program for the same:
C++
// C++ program to illustrate the// above concept#include <iostream>using namespace std;  // Driver Codeint main(){    // Name variable can store    // upto 30 character    char name[30];      // Print the output(asking user    // to enter city name)    cout << "Please enter your city name: ";      // Take input from user and store    // in name variable    cin >> name;      // Print output string including    // user input data    cout << "Your city is: "         << name << endl;      return 0;}
Input:Output:
cpp-input-output
Input Output Systems
Picked
C++
C++ Programs
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Operator Overloading in C++
Sorting a vector in C++
Polymorphism in C++
Friend class and function in C++
List in C++ Standard Template Library (STL)
Header files in C/C++ and its uses
C++ Program for QuickSort
How to return multiple values from a function in C or C++?
Program to print ASCII Value of a character
C++ program for hashing with chaining
Add values of two columns considering NULL values as zero in MySQL

For this, use COALESCE() function from MySQL. Let us first create a table −
mysql> create table DemoTable
-> (
-> Value1 int,
-> Value2 int
-> );
Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(100,200);
Query OK, 1 row affected (0.27 sec)

mysql> insert into DemoTable values(NULL,90);
Query OK, 1 row affected (0.13 sec)

mysql> insert into DemoTable values(NULL,NULL);
Query OK, 1 row affected (0.12 sec)

mysql> insert into DemoTable values(600,NULL);
Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+--------+
| Value1 | Value2 |
+--------+--------+
| 100    | 200    |
| NULL   | 90     |
| NULL   | NULL   |
| 600    | NULL   |
+--------+--------+
4 rows in set (0.00 sec)
Following is the query to treat NULL as zero and add values from two columns −
mysql> SELECT COALESCE(Value1, 0) + COALESCE(Value2, 0) AS Sum from DemoTable;
This will produce the following output −
+------+
| Sum  |
+------+
| 300  |
| 90   |
| 0    |
| 600  |
+------+
4 rows in set (0.00 sec)
Path getRoot() method in Java with Examples - GeeksforGeeks

16 Jul, 2019
The Java Path interface was added to Java NIO in Java 7. The Path interface is located in the java.nio.file package, so the fully qualified name of the Java Path interface is java.nio.file.Path. A Java Path instance represents a path in the file system. A path can use to locate either a file or a directory.path of an entity could be of two types one is an absolute path and other is a relative path. The absolute path is the location address from the root to the entity while the relative path is the location address which is relative to some other path.
getRoot() method of java.nio.file.Path used to return path object of the root component of this path object or null if this path does not have a root component.
Syntax:
Path getRoot()

Parameters: This method accepts nothing.
Return value: This method returns a path representing the root component of this path, or null.
Below programs illustrate getRoot() method:Program 1:
// Java program to demonstrate// java.nio.file.Path.getRoot() method  import java.io.IOException;import java.nio.file.Path;import java.nio.file.Paths;  public class GFG {    public static void main(String[] args)        throws IOException    {          // create object of Path        Path path = Paths.get("D:\\eclipse");          // call getRoot() to get root path        Path root = path.getRoot();          // print Root Path        System.out.println("Root Path: "                           + root);    }}
Program 2:
// Java program to demonstrate// java.nio.file.Path.getRoot() method  import java.io.IOException;import java.nio.file.Path;import java.nio.file.Paths;  public class GFG {    public static void main(String[] args)        throws IOException    {          // create object of Path        Path path = Paths.get("C:/Resume.pdf");          // call getRoot() to get root path        Path root = path.getRoot();          // print RootPath        System.out.println("Root Path: "                           + root);    }}
References: https://docs.oracle.com/javase/10/docs/api/java/nio/file/Path.html#getRoot()
Java-Functions
Java-Path
java.nio.file package
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Initialize an ArrayList in Java
HashMap in Java with Examples
Interfaces in Java
How to iterate any Map in Java
ArrayList in Java
Object Oriented Programming (OOPs) Concept in Java
Multidimensional Arrays in Java
Overriding in Java
Stack Class in Java
Set in Java
std::list::sort in C++ STL - GeeksforGeeks

17 Jan, 2018
Lists are containers used in C++ to store data in a non contiguous fashion, Normally, Arrays and Vectors are contiguous in nature, therefore the insertion and deletion operations are costlier as compared to the insertion and deletion option in Lists.
sort() function is used to sort the elements of the container by changing their positions.
Syntax :
listname.sort()
Parameters :
No parameters are passed.
Result :
The elements of the container
are sorted in ascending order.

Examples:
Input  : mylist{1, 5, 3, 2, 4};
         mylist.sort();
Output : 1, 2, 3, 4, 5

Input  : mylist{"hi", "bye", "thanks"};
         mylist.sort();
Output : bye, hi, thanks

Errors and Exceptions
1. It has a basic no exception throw guarantee.2. Shows error when a parameter is passed.
// SORTING INTEGERS// CPP program to illustrate// Implementation of sort() function#include <iostream>#include <list>using namespace std;  int main(){    // list declaration of integer type    list<int> mylist{ 1, 5, 3, 2, 4 };      // sort function    mylist.sort();      // printing the list after sort    for (auto it = mylist.begin(); it != mylist.end(); ++it)        cout << ' ' << *it;    return 0;}
Output:
1 2 3 4 5
// SORTING STRINGS// CPP program to illustrate// Implementation of sort() function#include <iostream>#include <list>#include <string>using namespace std;  int main(){    // list declaration of string type    list<string> mylist{ "hi", "bye", "thanks" };      // sort function    mylist.sort();      // printing the list after sort    for (auto it = mylist.begin(); it != mylist.end(); ++it)        cout << ' ' << *it;    return 0;}
Output:
bye hi thanks
Time Complexity : O(nlogn)
Similar function : Sort in C++ STL
cpp-list
STL
C++
STL
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Inheritance in C++
C++ Classes and Objects
Virtual Function in C++
Bitwise Operators in C/C++
Constructors in C++
Operator Overloading in C++
Templates in C++ with Examples
Socket Programming in C/C++
Object Oriented Programming in C++
Polymorphism in C++
How to access nested json objects in JavaScript?

Accessing nested json objects is just like accessing nested arrays. Nested objects are the objects that are inside an another object.
In the following example 'vehicles' is a object which is inside a main object called 'person'. Using dot notation the nested objects' property(car) is accessed.
Live Demo
<html>
<body>
<script>
   var person = {
      "name":"Ram",
      "age":27,
      "vehicles": {
         "car":"limousine",
         "bike":"ktm-duke",
         "plane":"lufthansa"
      }
   }
   document.write("Mr Ram has a car called" + " " + person.vehicles.car);
</script>
</body>
</html>
Mr Ram has a car called limousine
In the following example, an object called "air-lines" is doubly nested (nested inside a nested object). The property of that doubly nested object(lufthansa) is accessed through dot notation as shown below.
Live Demo
<html>
<body>
<script>
   var person = {
      "name":"Ram",
      "age":27,
      "vehicles": {
         "car":"limousine",
         "bike":"ktm-duke",
         "airlines":{
            "lufthansa" : "Air123",
             "British airways" : "Brt707"
         }
      }
   }
   document.write("Mr Ram travels by plane called" + " " + person.vehicles.airlines.lufthanza);
</script>
</body>
</html>
Mr Ram travels by plane called Air123
How to set cookies to expire in 1 hour in JavaScript?

You can extend the life of a cookie beyond the current browser session by setting an expiration date and saving the expiry date within the cookie. This can be done by setting the ‘expires’ attribute to a date and time.
You can try to run the following example to set cookies to expire in 1 hour −
<html>
   <head>
      <script>
         <!--
            function WriteCookie() {
               var now = new Date();
               now.setTime(now.getTime() + 1 * 3600 * 1000);
               cookievalue = escape(document.myform.customer.value) + ";"

               document.cookie="name=" + cookievalue;
               document.cookie = "expires=" + now.toUTCString() + ";"
               document.write ("Setting Cookies : " + "name=" + cookievalue );
            }
         //-->
      </script>
   </head>
   <body>
      <form name="myform" action="">
         Enter name: <input type="text" name="customer"/>
         <input type="button" value="Set Cookie" onclick="WriteCookie()"/>
      </form>
   </body>
</html>
How to get the attribute value of a web element in Selenium (using Java or Python)?

We can get the attribute value of a web element with Selenium webdriver using the method getAttribute and then pass the attribute for which we want to get the value as a parameter to that method.
In an html code, an element is defined with attributes and its values in a key-value pair. Let try to get the class – heading, for the below element on the page −
WebElement t =driver.findElement(By.xpath("//li[text()='About Tutorialspoint']"));
String s = t.getAttribute("class");
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
public class AttribtValue{
   public static void main(String[] args) {
      System.setProperty("webdriver.gecko.driver",
         "C:\\Users\\ghs6kor\\Desktop\\Java\\geckodriver.exe");
      WebDriver driver = new FirefoxDriver();
      //implicit wait
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //URL launch
      driver.get("https://www.tutorialspoint.com/about/about_careers.htm");
      // identify element with xpath
      WebElement t =driver.
      findElement(By.xpath("//li[text()='About Tutorialspoint']"));
      //get value of class attribute
      String s = t.getAttribute("class");
      System.out.println("Class attribute value is : " + s);
      driver.close();
   }
}
Tk - Treeview Widget

Treeview widget is used to choose a numeric value through sliders. The syntax for treeview widget is shown below.
treeview treeviewName options

The options available for the treeview widget are listed below in table.
-columns columnNames
An array of column names for widget.
-displaycolumns columns
An array of column names or indices specifying columns to be displayed. Use #all for all.
-height number
Height for widget.
-selectmode mode
Selection mode which can be extended, browse, or none.
A simple example for treeview widget is shown below.
#!/usr/bin/wish

ttk::treeview .tree -columns "Creator Year" -displaycolumns "Year Creator" 
.tree heading Creator -text "Creator" -anchor center
.tree heading Year -text "Year" -anchor center
pack .tree
.tree insert {} end -id Languages -text "Languages"
.tree insert Languages end -text C -values [list "Dennis Ritchie" "1990"]
.tree insert "" end -id Direct -text "Direct"   
When we run the above program, we will get the following output.
To move the elements, we can use the following command.
.tree move Languages Direct end

We will get the following output when the above command is executed.
Similarly, we can use the delete command to delete a values from treeview.
 Print
 Add Notes
 Bookmark this page
Sort the Array of Strings on the basis of given substring range - GeeksforGeeks

09 Sep, 2021
Given two positive integers I and X and an array of strings arr[], the task is to sort the given array of strings on the basis of substrings starting from index I of size X.
Examples: 
Input: I = 2, X = 2, arr[] = { “baqwer”, “zacaeaz”, “aaqzzaa”, “aacaap”, “abbatyo”, “bbbacztr”, “bbbdaaa” } Output: abbatyo bbbacztr bbbdaaa aacaap zacaeaz baqwer aaqzzaa Explanation: All sub-strings starting from index I = 2 and of size x = 2 are {“qw”, “ca”, “qz”, “ca”, “ba”, “ba”, “bd”}. Sorting them in lexicographical increasing order gives {“ba”, “ba”, “bd”, “ca”, “ca”, “qw”, “qz” }, then print the corresponding original string in this order.
Input: I = 1, X = 3, arr[] = { “submit”, “source”, “skills”, “epidemic”, “ample”, “apple” } Output: submit epidemic skills ample apple source  
Approach: The idea is to create a substring of all the strings in the given array from index I of size X and keep the count of pair of a substring with the corresponding string in a map of pairs. After inserting in the map of pairs. After inserting, traverse the map and print the string.
Below is the implementation of the above approach: 
C++
// C++ program for the above approach#include <bits/stdc++.h>using namespace std; // Function to sort the given array// of strings based on substringvoid sortArray(vector<string> s,               int l, int x){    // Map of pairs to sort vector    // of strings    map<pair<string, string>, int> mp;     for (int i = 0; i < s.size(); i++) {         // Create substring from index        // 'l' and of size 'X'        string part = s[i].substr(l, x);         // Insert in Map        mp[{ part, s[i] }] += 1;    }     // Print the sorted vector of strings    for (auto it = mp.begin();         it != mp.end(); ++it) {         // Traverse the number of time        // a string is present        for (int j = 0; j < it->second; j++) {             // Print the string            cout << it->first.second << ' ';        }    }} // Driver Codeint main(){    // Given array of strings    vector<string> arr;    arr = { "baqwer", "zacaeaz", "aaqzzaa",            "aacaap", "abbatyo", "bbbacztr",            "bbbdaaa" };     // Given I and X    int I = 2, X = 2;     // Function Call    sortArray(arr, I, X);    return 0;}
abbatyo bbbacztr bbbdaaa aacaap zacaeaz baqwer aaqzzaa
 
Time Complexity: O(N*log N) Auxiliary Space: O(N) 
varshagumber28
array-range-queries
substring
Arrays
Hash
Sorting
Strings
Arrays
Hash
Strings
Sorting
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Window Sliding Technique
Building Heap from Array
Trapping Rain Water
Reversal algorithm for array rotation
Program to find sum of elements in a given array
Internal Working of HashMap in Java
Hashing | Set 1 (Introduction)
Hashing | Set 3 (Open Addressing)
Count pairs with given sum
Hashing | Set 2 (Separate Chaining)
PHP program to check if a string has a special character

To check if a string has a special character, the PHP code is as follows;
 Live Demo
<?php
   function check_string($my_string){
      $regex = preg_match('[@_!#$%^&*()<>?/|}{~:]', $my_string);
      if($regex)
         print("String has been accepted");
      else
         print("String has not been accepted");
   }
   $my_string = 'This_is_$_sample!';
   check_string($my_string);
?>
String has not been accepted
Above, a function named ‘check_string’ is defined, that takes a string as its parameter −
$my_string = 'This_is_$_sample!';
Use regular expression to check if a string has a special character. If there is a special character, a
specific message is printed. Outside the function, the string is defined, and the function is called by
passing the string as parameter −
function check_string($my_string){
   $regex = preg_match('[@_!#$%^&*()<>?/|}{~:]', $my_string);
   if($regex)
      print("String has been accepted");
   else
      print("String has not been accepted");
}
VBA - Variables

Variable is a named memory location used to hold a value that can be changed during the script execution. Following are the basic rules for naming a variable.
You must use a letter as the first character.
You must use a letter as the first character.
You can't use a space, period (.), exclamation mark (!), or the characters @, &, $, # in the name.
You can't use a space, period (.), exclamation mark (!), or the characters @, &, $, # in the name.
Name can't exceed 255 characters in length.
Name can't exceed 255 characters in length.
You cannot use Visual Basic reserved keywords as variable name.
You cannot use Visual Basic reserved keywords as variable name.
Syntax
In VBA, you need to declare the variables before using them.
Dim <<variable_name>> As <<variable_type>>

There are many VBA data types, which can be divided into two main categories, namely numeric and non-numeric data types.
Following table displays the numeric data types and the allowed range of values.
-3.402823E+38 to -1.401298E-45 for negative values
1.401298E-45 to 3.402823E+38 for positive values.
-1.79769313486232e+308 to -4.94065645841247E-324 for negative values
4.94065645841247E-324 to 1.79769313486232e+308 for positive values.
+/- 79,228,162,514,264,337,593,543,950,335 if no decimal is use
+/- 7.9228162514264337593543950335 (28 decimal places).
Following table displays the non-numeric data types and the allowed range of values.
Example
Let us create a button and name it as 'Variables_demo' to demonstrate the use of variables.
Private Sub say_helloworld_Click()
   Dim password As String
   password = "Admin#1"

   Dim num As Integer
   num = 1234

   Dim BirthDay As Date
   BirthDay = DateValue("30 / 10 / 2020")

   MsgBox "Passowrd is " & password & Chr(10) & "Value of num is " &
      num & Chr(10) & "Value of Birthday is " & BirthDay
End Sub
Output
Upon executing the script, the output will be as shown in the following screenshot.

    101 Lectures 
     6 hours 

 Pavan Lalwani

    41 Lectures 
     3 hours 

 Arnold Higuit

    80 Lectures 
     5.5 hours 

 Prashant Panchal

    25 Lectures 
     2 hours 

 Prashant Panchal

    26 Lectures 
     2 hours 

 Arnold Higuit

    92 Lectures 
     10.5 hours 

 Vijay Kumar Parvatha Reddy
 Print
 Add Notes
 Bookmark this page
Google Charts - Histogram Chart Colors

Following is an example of a histogram chart with custom color. We've already seen the configuration used to draw this chart in Google Charts Configuration Syntax chapter. So, let's see the complete example.
We've used color configuration to change default color of histogram chart.
// Set chart options
var options = {colors: ['green']};

googlecharts_histogram_color.htm
<html>
   <head>
      <title>Google Charts Tutorial</title>
      <script type = "text/javascript" src = "https://www.gstatic.com/charts/loader.js">
      </script>
      <script type = "text/javascript">
         google.charts.load('current', {packages: ['corechart']});     
      </script>
   </head>
   
   <body>
      <div id = "container" style = "width: 550px; height: 400px; margin: 0 auto">
      </div>
      <script language = "JavaScript">
         function drawChart() {
            // Define the chart to be drawn.
             var data = google.visualization.arrayToDataTable([
               ['Student Roll No', 'height'],
               ['1', 80],['2', 55],['3', 68],['4', 80],['5', 54],
               ['6', 70],['7', 85],['8', 78],['9', 70],['10', 58],
               ['11', 90],['12', 65],['13', 88],['14', 82],['15', 65],
               ['16', 86],['17', 45],['18', 62],['19', 84],['20', 75],
               ['21', 82],['22', 75],['23', 58],['24', 70],['25', 85]		  
            ]);
              
            // Set chart options
            var options = {
               title: 'Students height, in cm',
               legend: { position: 'none' },
               colors: ['green']
            };				

            // Instantiate and draw the chart.
            var chart = new google.visualization.Histogram(document.getElementById('container'));
            chart.draw(data, options);
         }
         google.charts.setOnLoadCallback(drawChart);
      </script>
   </body>
</html>
Verify the result.
 Print
 Add Notes
 Bookmark this page
Ruby | Hash each_key function - GeeksforGeeks

07 Jan, 2020
Hash#each_key() is a Hash class method which finds the nested value which calls block once for each_key pair in the hash by passing the key as parameters.
Syntax: Hash.each_key()
Parameter: Hash values
Return: calls block once for key_value pair in hash with key as a parameter otherwise, Enumerator if no argument is passed.
Example #1 :
# Ruby code for Hash.each_key() method  # declaring Hash valuea = {a:100, b:200}  # declaring Hash valueb = {a:100, c:300, b:200}  # declaring Hash valuec = {a:100}  # each Valueputs "Hash a each_key form : #{a.each_key()}\n\n"  puts "Hash b each_key form : #{b.each_key {|key| puts "#{key}"}}\n\n"  puts "Hash c each_key form : #{c.each_key {|value| puts "#{value}"}}\n\n"
Output :
Hash a each_key form : #

a
c
b
Hash b each_key form : {:a=>100, :c=>300, :b=>200}

a
Hash c each_key form : {:a=>100}


Example #2 :
# Ruby code for Hash.each_key() method  # declaring Hash valuea = { "a" => 100, "b" => 200 }  # declaring Hash valueb = {"a" => 100}  # declaring Hash valuec = {"a" => 100, "c" => 300, "b" => 200}  # each Valueputs "Hash a each_key form : #{a.each_key()}\n\n"  puts "Hash b each_key form : #{b.each_key {|key| puts "#{key}"}}\n\n"  puts "Hash c each_key form : #{c.each_key {|value| puts "#{value}"}}\n\n"
Output :
Hash a each_key form : #

a
Hash b each_key form : {"a"=>100}

a
c
b
Hash c each_key form : {"a"=>100, "c"=>300, "b"=>200}


Ruby Hash-class
Ruby-Methods
Ruby
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Ruby | Enumerator each_with_index function
How to Make a Custom Array of Hashes in Ruby?
Ruby | Decision Making (if, if-else, if-else-if, ternary) | Set - 1
Ruby | pop() function
Ruby | String concat Method
Ruby For Beginners
Ruby | Array shift() function
Ruby on Rails Introduction
Ruby | Class Method and Variables
Ruby | String empty? Method
What are object data types in C#?

The object types can be assigned values of any other types, value types, reference types, predefined or user-defined types. However, before assigning values, it needs type conversion.
The Object Type is the ultimate base class for all data types in C# Common Type System (CTS). Object is an alias for System.Object class.
When a value type is converted to object type, it is called boxing and on the other hand, when an object type is converted to a value type, it is called unboxing.
The following is an example −
object obj;
obj = 100; // this is boxing
Here is the complete example showing the usage of object data types −
 Live Demo
using System;
using System.IO;

namespace Demo {
   class objectClass {
      public int x = 200;
   }

   class MyApplication {
      static void Main() {
         object obj;
         obj = 50;
         Console.WriteLine(obj);
         Console.WriteLine(obj.GetType());
         Console.WriteLine(obj.ToString());
   
         obj = new objectClass();
         objectClass newRef;
         newRef = (objectClass)obj;
         Console.WriteLine(newRef.x);
      }
   }
}
50
System.Int32
50
200
Gradle - Multi-Project Build

Gradle can handle smallest and largest projects easily. Small projects have a single build file and a source tree. It is very easy to digest and understand a project that has been split into smaller, inter-dependent modules. Gradle perfectly supports this scenario that is multi-project build.
Such builds come in all shapes and sizes, but they do have some common characteristics, which are as follows−
A settings.gradle file in the root or master directory of the project.
A settings.gradle file in the root or master directory of the project.
A build.gradle file in the root or master directory.
A build.gradle file in the root or master directory.
Child directories that have their own *.gradle build files (some multi-project builds may omit child project build scripts).
Child directories that have their own *.gradle build files (some multi-project builds may omit child project build scripts).
For listing all the projects in the build file, you can use the following command.
C:\> gradle -q projects

Output
You will receive the following output −
------------------------------------------------------------
Root project
------------------------------------------------------------

Root project 'projectReports'
+--- Project ':api' - The shared API for the application
\--- Project ':webapp' - The Web application implementation

To see a list of the tasks of a project, run gradle <project-path>:tasks
For example, try running gradle :api:tasks

The report shows the description of each project, if specified. You can use the following command to specify the description. Paste it in the build.gradle file.
description = 'The shared API for the application'

In a build.gradle file in the root_project, general configurations can be applied to all projects or just to the sub projects.
allprojects {
   group = 'com.example.gradle'
   version = '0.1.0'
}

subprojects {
   apply plugin: 'java'
   apply plugin: 'eclipse'
}
This specifies a common com.example.gradle group and the 0.1.0 version to all projects. The subprojects closure applies common configurations for all sub projects, but not to the root project, like the allprojects closure does.
The core ui and util subprojects can also have their own build.gradle file, if they have specific needs, which are not already applied by the general configuration of the root project.
For instance, the ui project usually has a dependency to the core project. So the ui project needs its own build.gradle file to specify this dependency.
dependencies {
   compile project(':core')
   compile 'log4j:log4j:1.2.17'
}

Project dependencies are specified with the project method.
 Print
 Add Notes
 Bookmark this page
JavaScript: Sort Object of Objects

Suppose we have an Object of Objects like this −
const obj = {
   "CAB": {
      name: 'CBSSP',
      position: 2
   },
   "NSG": {
      name: 'NNSSP',
      position: 3
   },
   "EQU": {
      name: 'SSP',
      position: 1
   }
};
We are required to write a JavaScript function that takes in one such array and sorts the sub-objects on the basis of the 'position' property of sub-objects (either in increasing or decreasing order).
The code for this will be −
const obj = {
   "CAB": {
      name: 'CBSSP',
      position: 2
   },
   "NSG": {
      name: 'NNSSP',
      position: 3
   },
   "EQU": {
      name: 'SSP',
      position: 1
   }
};
const sortByPosition = obj => {
   const order = [], res = {};
   Object.keys(obj).forEach(key => {
      return order[obj[key]['position'] - 1] = key;
   });
   order.forEach(key => {
      res[key] = obj[key];
   });
   return res;
}
console.log(sortByPosition(obj));
And the output in the console will be −
{
   EQU: { name: 'SSP', position: 1 },
   CAB: { name: 'CBSSP', position: 2 },
   NSG: { name: 'NNSSP', position: 3 }
}
Interleaving String in C++

Suppose we have three strings s1, s2 and s3. Then check whether s3 is formed by interleaving s1 and s2 or not. So if the strings are “aabcc”, s2 = “dbbca”, and s3 is “aadbbcbcac”, then the result will be true.
To solve this, we will follow these steps −
Define one method called solve(), this will take s1, s2, s3 and one 3d array dp, then i, j, k
Define one method called solve(), this will take s1, s2, s3 and one 3d array dp, then i, j, k
if i = 0 and j = 0 and k = 0, then return true
if i = 0 and j = 0 and k = 0, then return true
if dp[i, j, k] is not -1, then return dp[i, j, k]
if dp[i, j, k] is not -1, then return dp[i, j, k]
ans := false
ans := false
if j > 0 and k >= 0 and s2[j] = s3[k], thenans := solve(s1, s2, s3, dp, i – 1, j, k – 1)
if j > 0 and k >= 0 and s2[j] = s3[k], then
ans := solve(s1, s2, s3, dp, i – 1, j, k – 1)
ans := solve(s1, s2, s3, dp, i – 1, j, k – 1)
if j > 0 and k >= 0 and s2[j] = s3[k], thenans := ans OR solve(s1, s2, s3, dp, i, j – 1, k – 1)
if j > 0 and k >= 0 and s2[j] = s3[k], then
ans := ans OR solve(s1, s2, s3, dp, i, j – 1, k – 1)
ans := ans OR solve(s1, s2, s3, dp, i, j – 1, k – 1)
set dp[i, j, k] := ans
set dp[i, j, k] := ans
return dp[i, j, k]
return dp[i, j, k]
From the main method, do the following −
From the main method, do the following −
n := size of s1, m := size of s2, o := size of s3
n := size of s1, m := size of s2, o := size of s3
Add one blank space before s1, s2, s3.
Add one blank space before s1, s2, s3.
make one array of size (n + 1) x (m + 1) x (o + 1), fill this with -1
make one array of size (n + 1) x (m + 1) x (o + 1), fill this with -1
return solve(s1, s2, s3, dp, n, m, o)
return solve(s1, s2, s3, dp, n, m, o)
Let us see the following implementation to get better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
   bool solve(string s1, string s2, string s3, vector < vector < vector <int>>>& dp, int i, int j, int k){
      if(i ==0 && j == 0 && k == 0)return true;
      if(dp[i][j][k] !=-1)return dp[i][j][k];
      bool ans = false;
      if(i > 0 && k >= 0 && s1[i] == s3[k]){
         ans = solve(s1, s2, s3, dp, i - 1, j, k - 1);
      }
      if(j >0 && k >=0 && s2[j] == s3[k]){
         ans |= solve(s1, s2, s3, dp, i, j - 1, k - 1);
      }
      return dp[i][j][k] = ans;
   }
   bool isInterleave(string s1, string s2, string s3) {
      int n = s1.size();
      int m = s2.size();
      int o = s3.size();
      s1 = " " + s1;
      s2 = " " + s2;
      s3 = " " + s3;
      vector < vector < vector <int>>> dp(n + 1, vector < vector <int>>(m + 1, vector <int> (o + 1, -1)));
      return solve(s1, s2, s3, dp, n , m , o );
   }
};
main(){
   Solution ob;
   cout << (ob.isInterleave("aabcc", "dbbca", "aadbbcbcac"));
}
"aabcc", "dbbca", "aadbbcbcac"
1
C Program to add two fractions

Given with the input as fraction i.e. a/b and c/d where a, b, c and d can be any integer values other than 0 and the task is to add these two fraction to generate their final sum.
Fractions are represented by −
a / b, where a is known as numerator and b is known as denominator.
a and b can have any numeric values but b can have any numeric value other than 0.
Sum of two fractions is represented as a / b + c / d, and the rule for adding the two terms is that their denominator must be equal and if they are not equal they should be made equal and then only addition can be performed.
Input-: 1/4 + 2/12
Output-: 5/12
Since both the fractions denominators are unequal so to make them equal either GCD or LCM can be calculated. So in this case by multiplying the denominator which is 4 by 3 we can make them equal
(1 * 3) / (4 * 3) = 3 / 12
Add both the terms: 3 / 12 + 2 / 12 = 5 / 12
Input-: 1/4 + 2/4
Output-: 3/4
Since both the terms have same denominator they can be directly added
In function int gcd(int a, int b)
Step 1-> If a == 0 then,
   return b
Step 2-> Return gcd(b%a, a)
In function void smallest(int &den3, int &n3)
   Step 1-> Declare and initialize common_factor as gcd(n3,den3)
   Step 2-> Set den3 = den3/common_factor
   Step 3-> Set n3 = n3/common_factor
In Function void add_frac(int n1, int den1, int n2, int den2, int &n3, int &den3)
   Step 1-> Set den3 = gcd(den1,den2)
   Step 2-> Set den3 = (den1*den2) / den3
   Step 3-> Set n3 = (n1)*(den3/den1) + (n2)*(den3/den2)
   Step 4-> Call function smallest(den3,n3)
In Function int main()
   Step 1-> Declare and initialize n1=1, den1=4, n2=2, den2=12, den3, n3
   Step 2-> Call add_frac(n1, den1, n2, den2, n3, den3)
   Step 3-> Print the values of n1, den1, n2, den2, n3, den3
#include <stdio.h>
int gcd(int a, int b) {
   if (a == 0)
      return b;
   return gcd(b%a, a);
}
void smallest(int &den3, int &n3) {
   // Finding gcd of both terms
   int common_factor = gcd(n3,den3);
   den3 = den3/common_factor;
   n3 = n3/common_factor;
}
void add_frac(int n1, int den1, int n2, int den2, int &n3, int &den3) {
   // to find the gcd of den1 and den2
   den3 = gcd(den1,den2);
    // LCM * GCD = a * b
   den3 = (den1*den2) / den3;
   // Changing the inputs to have same denominator
   // Numerator of the final fraction obtained
   n3 = (n1)*(den3/den1) + (n2)*(den3/den2);
   smallest(den3,n3);
}
// Driver program
int main() {
   int n1=1, den1=4, n2=2, den2=12, den3, n3;
   add_frac(n1, den1, n2, den2, n3, den3);
   printf("%d/%d + %d/%d = %d/%d\n", n1, den1, n2, den2, n3, den3);
   return 0;
}
1/4 + 2/12 = 5/12
What is a class in JavaScript?

A class is a type of function, but instead of using the keyword 'function', keyword 'class' is used to initiate it, and the properties are assigned inside a constructor() method. The constructor() method is called each time the class object is initialized.
In the following example, a class called 'company' is created and inside a constructor() method the name of the company is assigned and displayed the result in the output.
Live Demo
<html>
<body>
<p id="class"></p>
<script>
   class Company {
      constructor(branch) {
         this.name = branch;
      }
   }
   myComp = new Company("Tutorialspoint");
   document.getElementById("class").innerHTML = myComp.name;
</script>
</body>
</html>
Tutorialspoint
Live Demo
<html>
<body>
<script>
   class Company {
      constructor(branch) {
         this.name = branch;
      }
   }
   myComp = new Company("Rk enterprises");
   document.write(myComp.name);
</script>
</body>
</html>
Rk enterprises
Convert a floating point number to string in C

In this section we will see how to convert a number (integer or float or any other numeric type data) to a string.
The logic is very simple. Here we will use the sprintf() function. This function is used to print some value or line into a string, but not in the console. This is the only difference between printf() and sprintf(). Here the first argument is the string buffer. where we want to save our data.
Input: User will put some numeric value say 42.26
Output: This program will return the string equivalent result of that number like “42.26”
Step 1 − Take a number from the user
Step 2 − Create an empty string buffer to store result
Step 3 − Use sprintf() to convert number to string
Step 4 − End
 Live Demo
#include<stdio.h>
main() {
   char str[20]; //create an empty string to store number
   float number;
   printf("Enter a number: ");
   scanf("%f", &number);
   sprintf(str, "%f", number);//make the number into string using sprintf function
   printf("You have entered: %s", str);
}
Enter a number: 46.3258
You have entered: 46.325802
How can we remove composite PRIMARY KEY constraint applied on multiple columns of an existing MySQL table?

We can remove composite PRIMARY KEY constraint from multiple columns of an existing table by using DROP keyword along with ALTER TABLE statement.
Suppose we have a table ‘Room_allotment’ having a composite PRIMARY KEY constraint on columns ‘ID’ and ‘RoomNo’ as follows −
mysql> describe room_allotment;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id     | int(11)     | NO   | PRI | 0       |       |
| Name   | varchar(20) | NO   | PRI |         |       |
| RoomNo | int(11)     | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.06 sec)
Now if we want to remove the composite PRIMARY KEY constraint then we can use ALTER TABLE statement as follows −
mysql> Alter table room_allotment DROP PRIMARY KEY;
Query OK, 0 rows affected (0.19 sec)
Records: 0  Duplicates: 0  Warnings: 0  

mysql> describe room_allotment;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id     | int(11)     | NO   |     | 0       |       |
| Name   | varchar(20) | NO   |     |         |       |
| RoomNo | int(11)     | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.07 sec)
The above result set shows that composite PRIMARY KEY constraint from columns ‘ID’ and ‘RoomNo’ has been removed.
How to draw a line 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 line in HTML SVG, use the SVG <line> element.
You can try to run the following code to learn how to draw a line in HTML5 SVG.
<!DOCTYPE html>
<html>
   <head>
      <style>
         #svgelem {
            position: relative;
            left: 10%;
            -webkit-transform: translateX(-20%);
            -ms-transform: translateX(-20%);
            transform: translateX(-20%);
         }
      </style>
      <title>HTML5 SVG Line</title>
   </head>
   <body>
      <h2>HTML5 SVG Line</h2>
      <svg id = "svgelem" width = "300" height = "200" xmlns = "http://www.w3.org/2000/svg">
         <line x1 = "0" y1 = "0" x2 = "100" y2 = "100" style = "stroke:red;stroke-width:2"/>
      </svg>
   </body>
</html>
LocalTime get() method in Java with Examples - GeeksforGeeks

04 Sep, 2021
The get() method of a LocalTime class helps to get the value for the specified field passed as a parameter from this LocalTime as an integer value. This method queries this time for the value of the field and the returned value will always be within the valid range of values for the field. When the field is not supported and method is unable to return int value then an exception is thrown. 
Syntax:  
public int get(TemporalField field)
Parameters: This method accepts a single parameter TemporalField field which is the field to get. It should not be null.Return value: This method returns the integer value for the field.Exception: This method throws following exceptions:  
DateTimeException: if a value for the field cannot be obtained or the value is outside the range of valid values for the field.
UnsupportedTemporalTypeException: if the field is not supported or the range of values exceeds an int.
ArithmeticException: if numeric overflow occurs.
Below programs illustrate the get() method:Program 1:  
Java
// Java program to demonstrate// LocalTime.get() method import java.time.*;import java.time.temporal.ChronoField; public class GFG {    public static void main(String[] args)    {        // create a LocalTime object        LocalTime time            = LocalTime.parse("19:34:50.63");         // get Mili of Second value from LocalTime        // using get method        int secondvalue            = time.get(ChronoField.MILLI_OF_SECOND);         // print result        System.out.println("MilliSecond Field: "                           + secondvalue);    }}
MilliSecond Field: 630
Program 2: To get UnsupportedTemporalTypeException 
Java
// Java program to demonstrate// LocalTime.get() method import java.time.*;import java.time.temporal.ChronoField; public class GFG {    public static void main(String[] args)    {        // create a LocalTime object        LocalTime time            = LocalTime.parse("19:34:50.63");         // try to find era using ChronoField        try {             int secondvalue                = time.get(ChronoField.YEAR);        }        catch (Exception e) {             // print exception            System.out.println("Exception: " + e);        }    }}
Exception: java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: Year
 
Reference: https://docs.oracle.com/javase/10/docs/api/java/time/LocalTime.html#get(java.time.temporal.TemporalField)
saurabh1990aror
Java-Functions
Java-LocalTime
Java-time package
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Initialize an ArrayList in Java
Object Oriented Programming (OOPs) Concept in Java
HashMap in Java with Examples
Interfaces in Java
ArrayList in Java
How to iterate any Map in Java
Multidimensional Arrays in Java
Stack Class in Java
Singleton Class in Java
Overriding in Java