code-rag-bench/online-tutorials huggingface dataset:
How to calculate natural log of a number in Python?

In the math module, two functions for calculation of logarithmic value are defined. The log() function returns natural logarithm of a number, whereas log10() calculates the standard loarithm i.e. to the base 10
The log() function takes two arguments, the number and base
import math
print ("math.log(100.12) : ", math.log(100.12))
print ("math.log(100.72) : ", math.log(100.72))
print ("math.log(math.pi) : ", math.log(math.pi))
Find the number of distinct islands in a 2D matrix in Python

Suppose we have a binary matrix. We have to count the number of islands in it. An island is place that is surrounded by water and is formed by connecting adjacent lands horizontally or vertically. We can assume that all four edges of the grid are all surrounded by water.
Suppose the grid is like −
There are three islands.
To solve this, we will follow these steps −
There will be two methods, one will be used to count number of islands called numIslands() and makeWater(). The makeWater() will be like −
There will be two methods, one will be used to count number of islands called numIslands() and makeWater(). The makeWater() will be like −
if number of rows in the grid is 0, then return 0
if number of rows in the grid is 0, then return 0
n = row count and m := column count, and ans := 0
n = row count and m := column count, and ans := 0
for i in range 0 to n – 1for j in range 0 to mif grid[i, j] = 1, then ans := ans + 1makeWater(i, j, n, m, grid)
for i in range 0 to n – 1
for j in range 0 to mif grid[i, j] = 1, then ans := ans + 1makeWater(i, j, n, m, grid)
for j in range 0 to m
if grid[i, j] = 1, then ans := ans + 1
if grid[i, j] = 1, then ans := ans + 1
makeWater(i, j, n, m, grid)
makeWater(i, j, n, m, grid)
the makeWater() will take the indices i, j, row and col count n and m, and grid
the makeWater() will take the indices i, j, row and col count n and m, and grid
if i <0 or j < 0 or i >= n or j >= m, then return from this method
if i <0 or j < 0 or i >= n or j >= m, then return from this method
if grid[i, j] = 0, then return otherwise make grid[i, j] := 0
if grid[i, j] = 0, then return otherwise make grid[i, j] := 0
call makeWater(i + 1, j, n, m, grid)
call makeWater(i + 1, j, n, m, grid)
call makeWater(i, j + 1, n, m, grid)
call makeWater(i, j + 1, n, m, grid)
Let us see the following implementation to get better understanding −
class Solution(object):
   def numIslands(self, grid):
      """
      :type grid: List[List[str]]
      :rtype: int
      """
      if len(grid) == 0:
         return 0
      n= len(grid)
      m = len(grid[0])
      ans = 0
      for i in range(n):
         for j in range(m):
            if grid[i][j] == "1":
               ans+=1
            self.make_water(i,j,n,m,grid)
         return ans
   def make_water(self,i,j,n,m,grid):
      if i<0 or j<0 or i>=n or j>=m:
         return
      if grid[i][j] == "0":
         return
      else:
         grid[i][j]="0"
      self.make_water(i+1,j,n,m,grid)
      self.make_water(i,j+1,n,m,grid)
      self.make_water(i-1,j,n,m,grid)
      self.make_water(i,j-1,n,m,grid)
[["1","1","0","0","0"],
["1","1","0","0","0"],
["0","0","1","0","0"],
["0","0","0","1","1"]]
3
VBA - Date Function

The Function returns the current system date.
date()

Add a button and add the following function.
Private Sub Constant_demo_Click()
   Dim a as Variant
   a = date()
   msgbox "The Value of a : " & a
End Sub
When you execute the function, it produces the following output.
The Value of a : 19/07/2014 


    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
How to create a smooth scrolling effect with CSS?

To create a smooth scrolling effect with CSS, the code is as follows −
 Live Demo
<!DOCTYPE html>
<html>
<head>
<style>
   html {
      scroll-behavior: smooth;
   }
   * {
      box-sizing: border-box;
   }
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
      margin: 0px;
      padding: 0px;
   }
   #firstSection {
      height: 100vh;
      background-color: rgb(119, 77, 219);
      color: white;
      padding: 20px;
   }
   #secondSection {
      height: 100vh;
      color: white;
      background-color: rgb(42, 128, 168);
      padding: 20px;
   }
   a {
      text-decoration: none;
      font-size: 20px;
      font-weight: bold;
      color: yellow;
   }
</style>
</head>
<body>
<h1>Smooth Scroll Example</h1>
<div id="firstSection">
<h2>Section 1</h2>
<p>Click on the link to see the "smooth" scrolling effect.</p>
<a href="#secondSection">Click Here to Smooth Scroll to Section 2 Below</a>
</div>
<div id="secondSection">
<h2>Section 2</h2>
<a href="#firstSection">Click Me to Smooth Scroll to Section 1 Above</a>
</div>
</body>
</html>
The above code will produce the following output −
On clicking the smooth scroll text we will scroll to section 2 smoothly −
Tryit Editor v3.7

Tryit: class on span elements
Creating an associative array in JavaScript?

You can create an associative array in JavaScript using an array of objects with key and value pair.
Associative arrays are basically objects in JavaScript where indexes are replaced by user defined keys.
var customerDetails=
[
   {
      "customerId":"customer-1",
      "customerName":"David",
      "customerCountryName":"US"
   },
   {
      "customerId":"customer-2",
      "customerName":"Bob",
      "customerCountryName":"UK"
   },
   {
      "customerId":"customer-3",
      "customerName":"Carol",
      "customerCountryName":"AUS"
   }
]
for(var i=0;i<customerDetails.length;i++){
   console.log(customerDetails[i].customerName);
}
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo115.js.
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo115.js
David
Bob
Carol
C++ Program to Multiply Two Matrix Using Multi-dimensional Arrays

A matrix is a rectangular array of numbers that is arranged in the form of rows and columns.
An example of a matrix is as follows.
A 3*3 matrix has 3 rows and 3 columns as shown below −
8 6 3
7 1 9
5 1 9
A program that multiplies two matrices using multidimensional arrays is as follows.
 Live Demo
#include<iostream>
using namespace std;
int main() {
   int product[10][10], r1=2, c1=3, r2=3, c2=3, i, j, k;
   int a[2][3] = { {2, 4, 1} , {2, 3, 9} };
   int b[3][3] = { {1, 2, 3} , {3, 6, 1} , {2, 9, 7} };
   if (c1 != r2) {
      cout<<"Column of first matrix should be equal to row of second matrix";
   } else {
      cout<<"The first matrix is:"<<endl;
      for(i=0; i<r1; ++i) {
         for(j=0; j<c1; ++j)
         cout<<a[i][j]<<" ";
         cout<<endl;
      }
      cout<<endl;
      cout<<"The second matrix is:"<<endl;
      for(i=0; i<r2; ++i) {
         for(j=0; j<c2; ++j)
         cout<<b[i][j]<<" ";
         cout<<endl;
      }
      cout<<endl;
      for(i=0; i<r1; ++i)
      for(j=0; j<c2; ++j) {
         product[i][j] = 0;
      }
      for(i=0; i<r1; ++i)
      for(j=0; j<c2; ++j)
      for(k=0; k<c1; ++k) {
         product[i][j]+=a[i][k]*b[k][j];
      }
      cout<<"Product of the two matrices is:"<<endl;
      for(i=0; i<r1; ++i) {
         for(j=0; j<c2; ++j)
         cout<<product[i][j]<<" ";
         cout<<endl;
      }
   }
   return 0;
}
The first matrix is:
2 4 1
2 3 9

The second matrix is:
1 2 3
3 6 1
2 9 7

Product of the two matrices is:
16 37 17
29 103 72
In the above program, the two matrices a and b are initialized as follows.
int a[2][3] = { {2, 4, 1} , {2, 3, 9} };
int b[3][3] = { {1, 2, 3} , {3, 6, 1} , {2, 9, 7} };
If the number of columns in the first matrix are not equal to the number of rows in the second matrix then multiplication cannot be performed. In this case an error message is printed. It is given as follows.
if (c1 != r2) {
   cout<<"Column of first matrix should be equal to row of second matrix";
}
Both the matrices a and b are displayed using a nested for loop. This is demonstrated by the following code snippet.
cout<<"The first matrix is:"<<endl;
for(i=0; i<r1; ++i) {
   for(j=0; j<c1; ++j)
   cout<<a[i][j]<<" ";
   cout<<endl;
}
cout<<endl;
cout<<"The second matrix is:"<<endl;
for(i=0; i<r2; ++i) {
   for(j=0; j<c2; ++j)
   cout<<b[i][j]<<" ";
   cout<<endl;
}
cout<<endl;
After this, the product[][] matrix is initialized to 0. Then a nested for loop is used to find the product of the 2 matrices a and b. This is demonstrated in the below code snippet.
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j) {
   product[i][j] = 0;
}
for(i=0; i<r1; ++i)
for(j=0; j<c2; ++j)
for(k=0; k<c1; ++k) {
   product[i][j]+=a[i][k]*b[k][j];
}
After the product is obtained, it is printed. This is shown as follows.
cout<<"Product of the two matrices is:"<<endl;
for(i=0; i<r1; ++i) {
   for(j=0; j<c2; ++j)
   cout<<product[i][j]<<" ";
   cout<<endl;
}
How to use Link Component in ReactJS? - GeeksforGeeks

08 Feb, 2021
The Link component allows you to easily customize anchor elements with our own theme colors and typography styles. Material UI for React has this component available for us and it is very easy to integrate. We can use Link Component in ReactJS using the following approach:
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
cd foldername
Step 3: After creating the ReactJS application, Install the material-ui modules using the following command:
npm install @material-ui/core
Project Structure: It will look like the following.
Project Structure
App.js: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
Javascript
import React from "react";import Link from "@material-ui/core/Link";  const App = () => {  const preventDefault = (event) => event.preventDefault();    return (    <div      style={{        margin: "auto",        display: "table",      }}    >      <h4>How to use Link Component in ReactJS?</h4>      <Link        href="http://geeksforgeeks.org/"        onClick={() => {          alert("Redirecting to GeeksforGeeks");        }}      >        Click GeeksforGeeks      </Link>    </div>  );};  export default App;
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
React-Questions
JavaScript
ReactJS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Difference between var, let and const keywords in JavaScript
How to create a link in JavaScript ?
How to Show Images on Click using HTML ?
How to remove an HTML element using JavaScript ?
Remove elements from a JavaScript Array
How to fetch data from an API in ReactJS ?
How to redirect to another page in ReactJS ?
How to pass data from child component to its parent in ReactJS ?
How to navigate on path by button click in react router ?
ReactJS Functional Components
Check valid date format in JavaScript?

To check for valid date format, match the date with −
const dateFormat = /^\d{4}\-\d{2}\-\d{2}$/;
 Live Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style>
   .check-valid-date {
      border: 1px solid red;
   }
</style>
</head>
<body>
<input type="date" id="check-valid-date" class="form-control
calender-black" name="dateCalender">
<script>
   const dateFormat = /^\d{4}\-\d{2}\-\d{2}$/;
   document.getElementById("check-valid-date").addEventListener("change",
   checkingForValidDate);
   function checkingForValidDate() {
      console.log(this.value, dateFormat.test(this.value));
      this.classList.toggle('check-valid-date',
      dateFormat.test(this.value));
   }
</script>
</body>
</html>
To run the above program, save the file name “anyName.html(index.html)” and right click on the
file. Select the option “Open with Live Server” in VS Code editor.
This will produce the following output −
Now, I am picking a date. The snapshot is as follows −
Above, the console displays TRUE i.e. valid date format.
HTML - <a> Tag

The HTML <a> tag is used for creating a hyperlink to either another document, or somewhere within the current document.
<!DOCTYPE html>
<html>

   <head>
      <title>HTML a Tag</title>
   </head>

   <body>
      <p>This is a link to <a href = "http://www.amrood.com">AMROOD.com</a></p>
   </body>
	
</html>
This will produce the following result −
 
This is a link to AMROOD.com

This tag supports all the global attributes described in HTML Attribute Reference
The HTML <a> tag also supports the following additional attributes −
if shape = "rect" then
coords = "left, top, right, bottom"
if shape = "circ" then
coords = "centerx,centery,radius"
if shape = "poly" then
coords = "x1, y1, x2, y2,..,xn,yn"
Where to open the target URL.
_blank - the target URL will open in a new window.
_self - the target URL will open in the same frame as it was clicked.
_parent - the target URL will open in the parent frameset.
_top - the target URL will open in the full body of the window.
This tag supports all the event attributes described in HTML Events Reference

    19 Lectures 
     2 hours 

 Anadi Sharma

    16 Lectures 
     1.5 hours 

 Anadi Sharma

    18 Lectures 
     1.5 hours 

 Frahaan Hussain

    57 Lectures 
     5.5 hours 

 DigiFisk (Programming Is Fun)

    54 Lectures 
     6 hours 

 DigiFisk (Programming Is Fun)

    45 Lectures 
     5.5 hours 

 DigiFisk (Programming Is Fun)
 Print
 Add Notes
 Bookmark this page
What is the data type for unix_timestamp in MySQL?

The best data type for unix_timestamp in MySQL is integer. The integer data type is as follows
int(11);
The integer data type is useful for condition checking like ( > ,<= ) and indexing. The return type of unix_timestamp is an integer.
However, let us see what we get as UNIX Timestamp, when we convert datetime to timestamp.
To understand the above concept, let us first create a table. The query to create a table is as follows
mysql> create table UnixTime
   -> (
   -> DueTime datetime
   -> );
Query OK, 0 rows affected (0.55 sec)
Insert records in the form of date using insert command. The query is as follows
mysql> insert into UnixTime values(now());
Query OK, 1 row affected (0.15 sec)

mysql> insert into UnixTime values('2010-10-14');
Query OK, 1 row affected (0.15 sec)

mysql> insert into UnixTime values('2020-09-24');
Query OK, 1 row affected (0.15 sec)
Let us now display all records from the table using select command. The query is as follows
mysql> select *from UnixTime;
The following is the output
+---------------------+
| DueTime             |
+---------------------+
| 2018-12-19 10:07:11 |
| 2010-10-14 00:00:00 |
| 2020-09-24 00:00:00 |
+---------------------+
3 rows in set (0.00 sec)
Let us see the query to convert datetime to UNIX timestamp
mysql> select unix_timestamp(DueTime) as Output from UnixTime;
The following is the output
+------------+
| Output     |
+------------+
| 1545194231 |
| 1286994600 |
| 1600885800 |
+------------+
3 rows in set (0.00 sec)
Sort Characters By Frequency in C++

Suppose we have a string, we have to sort the characters based on the frequency. So if the string is like “abbbacbcc”, then the output will be “bbbbcccaa”
To solve this, we will follow these steps −
create an array of pairs called v, create one map m
for all characters in string,increase value of m[character] by 1
increase value of m[character] by 1
i := first element of map
while map has elementsinsert (i.second, i.first) into vand increase i to point to the next element
insert (i.second, i.first) into v
and increase i to point to the next element
sort the vector v
ans := an empty string
for i := 0 to size of vt := first element of v[i]while t is not 0ans := ans + second part of v[i]decrease t by 1
t := first element of v[i]
while t is not 0ans := ans + second part of v[i]decrease t by 1
ans := ans + second part of v[i]
decrease t by 1
return ans
Let us see the following implementation to get a better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
   static bool cmp(pair <int, char> a, pair <int, char> b){
      return a.first < b.first;
   }
   string frequencySort(string s) {
      vector < pair <int, char> > v;
      map <char, int> m;
      for(int i = 0; i < s.size(); i++){
         m[s[i]]++;
      }
      map <char, int> :: iterator i = m.begin();
      while(i != m.end()){
         v.push_back({i->second, i->first});
         i++;
      }
      sort(v.rbegin(), v.rend(), cmp);
      string ans = "";
      for(int i = 0; i < v.size(); i++){
         int t = v[i].first;
         while(t--)ans += v[i].second;
      }
      return ans;
   }
};
main(){
   Solution ob;
   cout << ob.frequencySort("abbbacbcc");
}
"abbbacbcc"
bbbbcccaa
jQuery - removeAttr( name ) Method

The removeAttr( name ) method removes an attribute from each of the matched elements.
Here is the simple syntax to use this method
selector.removeAttr( name )

Here is the description of all the parameters used by this method −
name − The name of the property to be removed.
name − The name of the property to be removed.
Following example would remove border from each table −
<html>
   <head>
      <title>The Selecter Example</title>
      <script type = "text/javascript" 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
      </script>
   
      <script type = "text/javascript" language = "javascript">
         $(document).ready(function() {
            $("table").removeAttr("border");
         });
      </script>
   </head>
	
   <body>
      <table border = "2">
         <tr><td>This is first table</td></tr>
      </table>

      <table border = "3">
         <tr><td>This is second table</td></tr>
      </table>

      <table border = "4">
         <tr><td>This is third table</td></tr>
      </table>	
   </body>
</html>
This will produce following result −

    27 Lectures 
     1 hours 

 Mahesh Kumar

    27 Lectures 
     1.5 hours 

 Pratik Singh

    72 Lectures 
     4.5 hours 

 Frahaan Hussain

    60 Lectures 
     9 hours 

 Eduonix Learning Solutions

    17 Lectures 
     2 hours 

 Sandip Bhattacharya

    12 Lectures 
     53 mins

 Laurence Svekis
 Print
 Add Notes
 Bookmark this page
Why can't variables be declared in a switch statement in C/C++?

Variables can be declared in a switch statement. You'll just need to declare them and use them within a new scope in the switch statement. For example,
#include<iostream>
using namespace std;

int main() {
   int i = 10;
   switch(i) {
      case 2:
      //some code
      break;
      case 10:{
         int x = 13;
         cout << x;
      }
   }
   return 0;
}
This will give the output:
13
If you try to declare the variable out in the open you might get an error as Jumping to a case label is the same as using goto, so you aren't allowed to jump over a local variable declaration while you're in the same scope as it and might be using it someplace further in that scope.
Display the collapsible content by default with Bootstrap

Use the ‘collapse in’ class in Bootstrap to show collapsible content by default −
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Example</title>
      <link href = "/bootstrap/css/bootstrap.min.css" rel = "stylesheet">
      <script src = "/scripts/jquery.min.js"></script>
      <script src = "/bootstrap/js/bootstrap.min.js"></script>
   </head>
   <body>
      <div class = "container">
         <h2>More Quizzes</h2>
         <a href = "#test" class = "btn btn-info" data-toggle = "collapse">More</a>
         <div id = "test" class = "collapse in">
            We have quizzes on Java, PHP, Ruby, C, C++, etc. as well.
         </div>
      </div>
   </body>
</html>
JavaScript Array some() function

The some() method of JavaScript is used to check if any of the elements in an array fulfills the condition.
The syntax is as follows −
array.some(function(currentVal, index, arr), val)
Above, the parameters under function(), include currentVal – value of the current element, index – array index, whereas val the array object the current element fits
Let us now implement the some() method in JavaScript −
 Live Demo
<!DOCTYPE html>
<html>
<body>
   <h2>Ranking Points</h2>
   <p>Is any point above 400...</p>
   <button onclick="display()">Result</button>
   <p id="demo"></p>
   <script>
      var pointsArr = [50, 100, 200, 300, 400, 500, 600];
      function pointsFunc(points) {
         return points > 400;
      }
      function display() {
         document.getElementById("demo").innerHTML = pointsArr.some(pointsFunc);
      }
   </script>
</body></html>
Click the “Result” button −
 Live Demo
<!DOCTYPE html>
<html>
<body>
   <h2>Ranking Points</h2>
   <p>Is any point equal to 550...</p>
   <button onclick="display()">Result</button>
   <p id="demo"></p>
   <script>
      var pointsArr = [10, 20, 30, 40, 50, 60, 70, 80, 90, 1000];
      function pointsFunc(points) {
         return points == 550;
      }
      function display() {
         document.getElementById("demo").innerHTML = pointsArr.some(pointsFunc);
      }
   </script>
</body></html>
Click the “Result” button −
Rexx - TRUNC

This method truncates a number.
TRUNC(i) 

i − This the input number for which the value needs to be truncated.
i − This the input number for which the value needs to be truncated.
Returns the truncated number.
/* Main program */ 
say TRUNC(12.22)  
When we run the above program, we will get the following result.
12 

 Print
 Add Notes
 Bookmark this page
How can I convert string to double in C/C++?

Here is an example to convert a string to double.
 Live Demo
#include <iostream>
using namespace std;
int main() {
   char s[20] = "18.2894 is a number";
   char *p;
   double result;
   result = strtod(s, &p);
   cout<<"The number after conversion of string : "<<result;
   return(0);
}
The number after conversion of string : 18.289400
In the above program, a char type array s[20] is declared which is initialized with a alphanumeric characters. The function strtod() is used to convert that string into a double number.
char s[20] = "18.2894 is a number";
char *p;
double result;
result = strtod(s, &p);
Instruction type RRC in 8085 Microprocessor

In 8085 Instruction set, RRC stands for “Rotate Right Accumulator”. With the help of this instruction, we can rotate the Accumulator current content to the right by 1-bit position. The following Fig. will depict the rotation operation.
In this right rotation, the least significant bit will come out from the Accumulator and will be copied to Cy bit in the flag register and also will be copied to the most significant bit position of the Accumulator. Notice that the Cy flag is not involved in the rotation, and it is only 8-bit rotation of Accumulator contents. Only Cy flag is affected by this instruction execution.
This instruction can be used in multiple following operations −
To check the value of the least significant bit value of the Accumulator through the value of the cy bit.
To check the value of the least significant bit value of the Accumulator through the value of the cy bit.
It can be used to perform division by 2. We know that Accumulator’s content will have n-bits right shift if we divide the Accumulator by 2n.
It can be used to perform division by 2. We know that Accumulator’s content will have n-bits right shift if we divide the Accumulator by 2n.
The execution of this instructions has been depicted through following examples −
(A)
(Cy)
8AH --->    1000 1010
 0100 0101 ---> 45H (Last bit 0 is copied to Cy bit)

Note that Accumulator value is halved.
(A)
(Cy)
8AH --->    1000 1011
 1100 0101 --->C5H (Last bit 1 is copied to Cy bit)

Note that Accumulator value is not halved in this case because LS bit of Accumulator was a 1 before rotation.
The timing diagram against this instruction RRC execution is as follows −
Summary − So this instruction RRC requires 1-Byte, 1-Machine Cycle (Opcode Fetch) and 4 T-States for execution as shown in the timing diagram.
The accept() method in Java Stream.Builder

Add an element to the stream using the accept() method of Java Stream.Builder.
The following is the syntax:
void accept(T t)
Here, t is the argument to be inserted.
Import the following package for the Stream.Builder class in Java:
import java.util.stream.Stream;
First, declare a Stream.Builder:
Stream.Builder<String> builder = Stream.builder();
Now, use the accept() method:
builder.accept("Demo");
builder.accept("Text");
The following is an example displaying how to implement accept() method of Stream.Builder in Java:
 Live Demo
import java.util.stream.Stream;
public class Demo {
   public static void main(String[] args){
      Stream.Builder<String> builder = Stream.builder();
      builder.accept("Demo");
      builder.accept("Text");
      Stream<String> str = builder.build();
      str.forEach(System.out::println);
   }
}

Demo
Text
Get the dates of Yesterday, Today, and Tomorrow using NumPy - GeeksforGeeks

26 Nov, 2020
In NumPy with the help of NumPy.datetime64(‘today’, ‘D’), we will find today date and if we want some date before today then we will subtract the no-of-date with the help of np.timedelta64() from today. And if we want some date after today then we will add the no of date with the help of np.timedelta64() from today. For yesterday, we will subtract 1 date, for tomorrow we will add 1 date.
Example #1: Get the dates yesterday, today, and tomorrow.
Python3
import numpy as np  # for todaytoday = np.datetime64('today', 'D')print("Today: ", today)  # for yesterdayyesterday = np.datetime64('today', 'D')- np.timedelta64(1, 'D')  print("Yestraday: ", yesterday)  # for tomorrowtomorrow = np.datetime64('today', 'D')+ np.timedelta64(1, 'D')  print("Tomorrow: ", tomorrow)
Output:
Today:  2020-08-15
Yestraday:  2020-08-14
Tomorrow:  2020-08-16

Example #2: Get the dates in the interval.
Python3
import numpy as np  # for todaytoday = np.datetime64('today', 'D')print("Today: ", today)  # for before_2_daybefore_2_day = np.datetime64('today', 'D')- np.timedelta64(2, 'D')print("before_2_day : ", before_2_day)  # for after_2_dayafter_2_day = np.datetime64('today', 'D')+ np.timedelta64(2, 'D')  print("after_2_day :", after_2_day)
Output:
Today:  2020-08-15
before_2_day :  2020-08-13
after_2_day : 2020-08-17

Python numpy-program
Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Box Plot in Python using Matplotlib
Python | Get dictionary keys as a list
Bar Plot in Matplotlib
Multithreading in Python | Set 2 (Synchronization)
Python Dictionary keys() method
loops in python
Python - Call function from another file
Ways to filter Pandas DataFrame by column values
Python | Convert set into a list
Python program to find number of days between two given dates
Different Ways to Add Stacktrace or debug Option when Building Android Studio Project

19 Jun, 2021
While developing your favorite app, you might at some point of time arrived upon this strange error, 
:GfGapp:processDebugResources FAILED

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:processDebugResources'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Yes, and now you want to run with the –stacktrace option as the error log now shows!
Image 1. That error!
Go forward with this article and you’ll be up and running in no time. 
This might be the easiest way to add the Stacktrace option in Android Studio, simply navigate to the files option and then you can add Stacktrace in place of command-line options and you are good to go.
File > Settings > Build, Execution, Deployment > Compiler
Image 2. The Compiler Settings Panel
You will get the same result as stated in method #1 above on a Mac. Only the names of certain settings are different.
Navigate to Android Studio -> Preferences-> Build, Execution, Deployment-> Compiler
The GUI Method
Note: To view the Compiler option in the newest versions of AS (2.2 and 2.3), exit the open project, go to AS begin (where the current projects are shown), and select Configure -> Preferences->Build, Execution,Deployment. Otherwise, the Compiler is hidden.
configurations.all {
    resolutionStrategy {
        force 'com.android.support:support-v4:27.0.0'
    }
}
Adding the Configurations in the Gradle
./gradlew assembleMyBuild --stacktrace
If you’re a fan of the Android Studio terminal then this might turn to be the best one for you as this involves using the terminal to add the Stacktrace option and achieve the required result. Input the above statement in the Android Studio’s terminal and results will start popping.
The Android Studio’s Terminal
Just add this additional flag and you’re good to go!
gradle(
   flags: "{--stacktrace}"
)
And that’s how you just managed to run stacktrace option!
Android-Studio
Picked
Android
Android
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Add Views Dynamically and Store Data in Arraylist in Android?
Android SDK and it's Components
Flutter - Custom Bottom Navigation Bar
How to Communicate Between Fragments in Android?
Retrofit with Kotlin Coroutine in Android
How to Post Data to API using Retrofit in Android?
Flutter - Stack Widget
Introduction to Android Development
Activity Lifecycle in Android with Demo App
Fragment Lifecycle in Android
Monitor vs Semaphore - GeeksforGeeks

16 Mar, 2020
Both semaphores and monitors are used to solve the critical section problem (as they allow processes to access the shared resources in mutual exclusion) and to achieve process synchronization in the multiprocessing environment.
Monitor:A Monitor type high-level synchronization construct. It is an abstract data type. The Monitor type contains shared variables and the set of procedures that operate on the shared variable.
When any process wishes to access the shared variables in the monitor, it needs to access it through the procedures. These processes line up in a queue and are only provided access when the previous process release the shared variables. Only one process can be active in a monitor at a time. Monitor has condition variables.
Syntax:
monitor  {
    
    //shared variable declarations
    data variables;
    Procedure P1() { ... }
    Procedure P2() { ... }
    .
    .
    .
    Procedure Pn() { ... }

} 
Semaphore:A Semaphore is a lower-level object. A semaphore is a non-negative integer variable. The value of Semaphore indicates the number of shared resources available in the system. The value of semaphore can be modified only by two functions, namely wait() and signal() operations (apart from the initialization).
When any process accesses the shared resources, it performs the wait() operation on the semaphore and when the process releases the shared resources, it performs the signal() operation on the semaphore. Semaphore does not have condition variables. When a process is modifying the value of the semaphore, no other process can simultaneously modify the value of the semaphore.
The Semaphore is further divided into 2 categories:
Binary semaphoreCounting semaphore
Binary semaphore
Counting semaphore
Syntax:
    // Wait Operation
    wait(Semaphore S) {   
        while (S<=0);
            S--;
    }
    // Signal Operation
    signal(Semaphore S) {
        S++;
    } 
Advantages of Monitors:
Monitors are easy to implement than semaphores.
Mutual exclusion in monitors is automatic while in semaphores, mutual exclusion needs to be implemented explicitly.
Monitors can overcome the timing errors that occur while using semaphores.
Shared variables are global to all processes in the monitor while shared variables are hidden in semaphores.
Advantages of Semaphores:
Semaphores are machine independent (because they are implemented in the kernel services).
Semaphores permit more than one thread to access the critical section, unlike monitors.
In semaphores there is no spinning, hence no waste of resources due to no busy waiting.
Process Synchronization
GATE CS
Operating Systems
Operating Systems
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Differences between IPv4 and IPv6
Preemptive and Non-Preemptive Scheduling
Difference between Clustered and Non-clustered index
Phases of a Compiler
Introduction of Process Synchronization
Banker's Algorithm in Operating System
Program for FCFS CPU Scheduling | Set 1
Paging in Operating System
Introduction of Deadlock in Operating System
Program for Round Robin scheduling | Set 1
init command in Linux with examples - GeeksforGeeks

26 Aug, 2020
init is parent of all Linux processes with PID or process ID of 1. It is the first process to start when a computer boots up and runs until the system shuts down. init stands for initialization. In simple words the role of init is to create processes from script stored in the file /etc/inittab which is a configuration file which is to be used by initialization system. It is the last step of the kernel boot sequence.
/etc/inittab Specifies the init command control file.

init script initializes the service. So, it responsible for initializing the system.
Init scripts are also called rc scripts (run command scripts)
Init script is also used in UNIX.
Syntax
init [OPTIONS...] {COMMAND}

Run Levels
Run Levels is the state of init where a group of processes are defined to start at the startup of OS. The process spawned by init for each of this run levels are defined in the file /etc/inittab. Each runlevel has a certain number of services stopped or started. Conventionally seven runlevel exist numbers from zero to six.
Runlevel
Does not configure network interfaces, start daemons, 
or allow non-root logins
By default most of the LINUX based system boots to runlevel 3 or runlevel 5. In addition to the standard runlevels, users can modify the preset runlevels or even create new ones according to the requirement. Runlevels 2 and 4 are used for user defined runlevels and runlevel 0 and 6 are used for halting and rebooting the system.
 
akashpatil242000
linux-command
Linux-system-commands
Picked
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
scp command in Linux with Examples
mv command in Linux with examples
Docker - COPY Instruction
SED command in Linux | Set 2
chown command in Linux with Examples
nohup Command in Linux with Examples
Named Pipe or FIFO with example C program
Thread functions in C/C++
uniq Command in LINUX with examples
Start/Stop/Restart Services Using Systemctl in Linux
C# | Check if HashSet and the specified collection contain the same elements - GeeksforGeeks

01 Feb, 2019
A HashSet is an unordered collection of the unique elements. It comes under System.Collections.Generic namespace. It is used in a situation where we want to prevent duplicates from being inserted in the collection. As far as performance is concerned, it is better in comparison to the list. HashSet.SetEquals(IEnumerable) Method is used to check if a HashSet and the specified collection contain the same elements or not.
Syntax:
mySet1.SetEquals(mySet2);

Here, mySet1 and mySet2 are HashSets objects.
Return Type: This method return True if the mySet1 is equal to mySet2 else returns False.
Exception: This method will give ArgumentNullException if the HashSet is null.
Below given are some examples to understand the implementation in a better way:
Example 1:
// C# code to check if HashSet and the specified// collection contain the same elements.using System;using System.Collections.Generic;  class GFG {      // Driver code    public static void Main()    {          // Creating a HashSet of strings        HashSet<string> mySet1 = new HashSet<string>();          // Inserting elements in HashSet        mySet1.Add("Geeks");        mySet1.Add("GeeksforGeeks");        mySet1.Add("GeeksClasses");        mySet1.Add("GeeksQuiz");          // Creating a HashSet of strings        HashSet<string> mySet2 = new HashSet<string>();          // Inserting elements in HashSet        mySet2.Add("Geeks");        mySet2.Add("GeeksforGeeks");        mySet2.Add("GeeksClasses");        mySet2.Add("GeeksQuiz");          // Check if both HashSets contains same elements        Console.WriteLine(mySet1.SetEquals(mySet2));    }}
True

Example 2:
// C# code to check if HashSet and the specified// collection contain the same elements.using System;using System.Collections.Generic;  class GFG {      // Driver code    public static void Main()    {          // Creating a HashSet of integers        HashSet<int> mySet1 = new HashSet<int>();          // Inserting elements in HashSet        mySet1.Add(4);        mySet1.Add(8);        mySet1.Add(12);        mySet1.Add(16);          // Creating a HashSet of integers        HashSet<int> mySet2 = new HashSet<int>();          // Inserting elements in HashSet        mySet2.Add(5);        mySet2.Add(10);        mySet2.Add(15);        mySet2.Add(20);          // Check if both HashSets contains same elements        Console.WriteLine(mySet1.SetEquals(mySet2));    }}
False

Reference:
https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.hashset-1.setequals?view=netframework-4.7.2
CSharp-Generic-HashSet
CSharp-Generic-Namespace
CSharp-method
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C# | Delegates
C# | Abstract Classes
Extension Method in C#
C# | Class and Object
C# | Constructors
C# | String.IndexOf( ) Method | Set - 1
C# | Replace() Method
Introduction to .NET Framework
C# | Data Types
C# | Arrays
Matcher toString() method in Java with Examples - GeeksforGeeks

27 Nov, 2018
The toString() method of Matcher Class is used to get the String representation of this matcher. This method is derived from the Object Class and behaves in the similar way.
Syntax:
public String toString()

Parameters: This method takes no parameters.
Return Value: This method returns a String value which is the String representation of this matcher.
Below examples illustrate the Matcher.toString() method:
Example 1:
// Java code to illustrate toString() method  import java.util.regex.*;  public class GFG {    public static void main(String[] args)    {          // Get the regex to be checked        String regex = "(Geeks)";          // Create a pattern from regex        Pattern pattern = Pattern.compile(regex);          // Get the String to be matched        String stringToBeMatched            = " Geeks for For Geeks Geek";          // Create a matcher for the input String        Matcher matcher            = pattern.matcher(stringToBeMatched);          // Get the String representation of this matcher        // using toString() method        System.out.println(matcher.toString());    }}
java.util.regex.Matcher[pattern=(Geeks) region=0,25 lastmatch=]

Example 2:
// Java code to illustrate toString() method  import java.util.regex.*;  public class GFG {    public static void main(String[] args)    {          // Get the regex to be checked        String regex = "(GFG)";          // Create a pattern from regex        Pattern pattern            = Pattern.compile(regex);          // Get the String to be matched        String stringToBeMatched            = "FGF GFG GFG FGF";          // Create a matcher for the input String        Matcher matcher            = pattern.matcher(stringToBeMatched);          // Get the String representation of this matcher        // using toString() method        System.out.println(matcher.toString());    }}
java.util.regex.Matcher[pattern=(GFG) region=0,15 lastmatch=]

Reference: https://docs.oracle.com/javase/9/docs/api/java/util/regex/Matcher.html#toString–
Java - util package
Java-Functions
Java-Matcher
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Stream In Java
Constructors in Java
Exceptions in Java
Functional Interfaces in Java
Different ways of Reading a text file in Java
Generics in Java
Introduction to Java
Internal Working of HashMap in Java
Comparator Interface in Java with Examples
Strings in Java
Batch Script - Length of an Array - GeeksforGeeks

28 Nov, 2021
The length of the array is the number of elements in the array. The index of the array starts from “0” to “N-1” where N is a number of elements. 
For example 
arr[0]=1
arr[1]=2
arr[2]=3
Here we can see that the index starts from 0 and ends with 2 . So, we know that the index of the element goes from 0 to N-1. Now, N-1=2, and hence the value of N becomes 3 i.e. N=3, where N is number of elements in the array. 
In the batch script, there is no function to find the length of the array direct so we have to iterate the elements of the array.
First, open the notepad and write the below command.
@echo off 
:: Here an array is defined
set array[0]=1 
set array[1]=4 
set array[2]=9 
set array[3]=10 


:: Here we initializing an variable named len to calculate length of array
set len=0 

:: To iterate the element of array
:Loop 

:: It will check if the element is defined or not
if defined array[%len%] ( 
set /a len+=1
GOTO :Loop 
)
echo The length of the array is %len%
pause
Save the above file with “.bat” extension and run the file.
Output : 
The length of the array is 4
First, we create an array to calculate the length.
After this, we have to initialize a variable to calculate the length of the array. Above we initialize len=0
Now we have to iterate the elements of the array to calculate the length of the array.
To check the element is exists or not in the array we have to put an if statement as shown in the above code.
In case if statement is true then there is an increment in len.
In case if statement is false then it will exit from the loop and return the length of the array.
Batch-script
Picked
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
scp command in Linux with Examples
mv command in Linux with examples
Docker - COPY Instruction
SED command in Linux | Set 2
chown command in Linux with Examples
nohup Command in Linux with Examples
Named Pipe or FIFO with example C program
Thread functions in C/C++
uniq Command in LINUX with examples
Start/Stop/Restart Services Using Systemctl in Linux
How to apply inline CSS ?

17 Mar, 2021
Inline CSS contains the CSS property in the body section attached with the element is known as inline CSS. This kind of style is specified within an HTML tag using the style attribute. It is used to apply a unique style to a single HTML element.
Syntax:
<tag style = " "></tag>
Example 1:
HTML
<!DOCTYPE html><html>  <body>    <p style="color: #009900;              font-size: 50px;              font-style: italic;              text-align: center;">      GeeksForGeeks    </p>  </body></html>
Output:
Example 2:
HTML
<!DOCTYPE html><html>  <body>    <h2 style="color: green; background: yellow">      Geeks For Geeks    </h2>    <p style="color: black">      Happy Preparation!!.    </p>  </body></html>
Output:
CSS-Basics
CSS-Questions
Picked
CSS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
UPPER() function in SQL Server

09 Dec, 2020
UPPER() :This function in SQL Server helps to convert all the letters of the given string to Uppercase. If the given string contains special characters or numeric values, then they will remain unchanged by this function.
Syntax :
UPPER( str )
Parameters :
str – The string which will be converted to uppercase
Result :This function will return the uppercase string.
Example-1 :Using UPPER() function with Lowercase string.
SELECT UPPER('be patience be awake') 
As New;
Output :
New
Example-2 :Using UPPER() function with Mixed case string.
SELECT UPPER('EvERy DAy iS A NEW day') 
As New;
Output :
New
Example-3 :Using UPPER() function with Select statement.Create Players table and Insert value in it.
Create table Players
(
 Firstname varchar(40),
 Lastname varchar(40),
 Country varchar(40)
)

Inserting data into players :
Insert into Players values 
('Kane', 'Williamson', 'New Zealand')

The table will look like.
Use of UPPER() function.
SELECT Firstname,  
      UPPER(Lastname) As New_name,  
      Country
FROM Players;

Output :
Example-4 :Using UPPER() function in a Variable.
DECLARE @text VARCHAR(45);
SET @text = 'be happy be light ';
SELECT @text,  
      UPPER(@text) AS Upper;

Output :
DBMS-SQL
SQL-Server
Technical Scripter 2020
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to print all the values of an array in PHP ?

01 Jun, 2020
We have given an array containing some array elements and the task is to print all the values of an array arr in PHP. In order to do this task, we have the following approaches in PHP:
Approach 1: Using foreach loop: The foreach loop is used to iterate the array elements. The foreach loop though iterates over an array of elements, the execution is simplified and finishes the loop.
Syntax:
foreach( $array as $element ) {
    // PHP Code to be executed
}

Example:
PHP
<?php// PHP program to print all // the values of an array    // given array$array = array("Geek1", "Geek2",           "Geek3", "1", "2","3");    // Loop through arrayforeach($array as $item){    echo $item . "\n";}  ?>
Geek1
Geek2
Geek3
1
2
3
 
Approach 2: Using count() function and for loop: The count() function is used to count the number of element in an array and for loop is used to iterate over the array.
Syntax:
for (initialization; test condition; increment/decrement) {
    // Code to be executed
}

Example:
PHP
<?php// PHP program to print all // the values of an array    // given array$array = array("Geek1", "Geek2",            "Geek3", "1", "2","3");    $items = count($array);  // Loop through arrayfor($num = 0; $num < $items; $num += 1){    echo  $array[$num]. "\n";}  ?>
Geek1
Geek2
Geek3
1
2
3
 
PHP-array
PHP
PHP Programs
Web Technologies
Web technologies Questions
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Java Program for Sieve of Eratosthenes

05 May, 2021
Given a number n, print all primes smaller than or equal to n. It is also given that n is a small number. For example, if n is 10, the output should be “2, 3, 5, 7”. If n is 20, the output should be “2, 3, 5, 7, 11, 13, 17, 19”.   
Java
// Java program to print all primes smaller than or equal to// n using Sieve of Eratosthenes class SieveOfEratosthenes{    void sieveOfEratosthenes(int n)    {        // Create a boolean array "prime[0..n]" and initialize        // all entries it as true. A value in prime[i] will        // finally be false if i is Not a prime, else true.        boolean prime[] = new boolean[n+1];        for(int i=0;i<=n;i++)            prime[i] = true;                 for(int p = 2; p*p <=n; p++)        {            // If prime[p] is not changed, then it is a prime            if(prime[p] == true)            {                // Update all multiples of p                for(int i = p*p; i <= n; i += p)                    prime[i] = false;            }        }                 // Print all prime numbers        for(int i = 2; i <= n; i++)        {            if(prime[i] == true)                System.out.print(i + " ");        }    }         // Driver Program to test above function    public static void main(String args[])    {        int n = 30;        System.out.print("Following are the prime numbers ");        System.out.println("smaller than or equal to " + n);        SieveOfEratosthenes g = new SieveOfEratosthenes();        g.sieveOfEratosthenes(n);    }} // This code has been contributed by Amit Khandelwal.
Following are the prime numbers smaller than or equal to 29
2 3 5 7 11 13 17 19 23 29 
Please refer complete article on Sieve of Eratosthenes for more details! 
sakethreddynarahari
dularnikode1
Java Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.