code-rag-bench/online-tutorials huggingface dataset:
Kali Linux – Default Passwords

30 Jun, 2020
Kali Linux is a great OS for hacking and penetration testing, but as it could be used to hack others it could even get you hacked easily. So it is recommended to use Kali Linux in live mode but during the time of installation we are asked for credentials so we enter them manually. But when we use Kali Live, it uses some default credentials. Here is the list of these credentials:
Kali Linux user policy has changes after the version 2020.1. So, Kali Linux has 2 credentials depending on the version of kali Linux you are using.
For Versions before 2020.1
Root username : root
Root password : toor

For versions after 2020.1 including it
Root username : kali
Root password : kali

For vagrant images(based on their policy)
Root username : vagrant
Root password : vagrant

BeEf-XSS
username : beef
password : beef

MySQL
username : root
password : (blank)

Note: Here (blank) means you have to leave the password space empty.
OpenVAS
username : admin
password : <Generated during Setup>

Metasploit
username : postgres
password : postgres

Kali-Linux
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between include() and include_once() in PHP

29 Oct, 2021
The include() function in PHP is mostly used to include the code/data of one PHP file to another file. During this process if there are any kind of errors then this require() function will display/give a warning but unlike the require() function in which the execution comes to a halt, the include() function will not stop the execution of the script rather the script will continue its process.
In order to use the include() function, we will first need to create two PHP files. Then using the include() function put one PHP file into another one. After that, you will see two PHP files combined into one HTML file. This include() will not see whether the code is already included in the specified file, rather it will include the code number of times the include() is been used.
Example: Assume we have a file called includegfg.php.
includegfg.php
<?php   echo "<p>Visit Again; " . date("Y") . " Geeks for geeks.com</p>";?>
We have created a file demo.php. Using the include() method we will include the includegfg.php file into the demo.php file.
demo.php
<html><body>  <h1>Welcome to geeks for geeks!</h1>  <p>Myself, Gaurav Gandal</p>  <p>Thank you</p>    <?php     include 'includegfg.php';  ?></body></html>
Output:
include_once():
The include_once() function in PHP is mainly used to include one PHP file into another PHP file. It provides us with a feature that if a code from a PHP file is already included in a specified file then it will not include that code again. It means that this function will add a file into another only once. In case this function locates an error then it will produce a warning but will not stop the execution.
If ABC.php file calls XYZ.php file using include_once() and any error occurs then it will produce a warning but will not stop the script execution.
Example: Below we have created a sample PHP file called demo.php, which displays the message “Hello from Geeks for Geeks.”
demo.php
<?php   echo "Hello from Geeks for Geeks";?>
In the following PHP file require_once_demo.php, we have called the demo.php file twice using the require_once(), but it will not execute the second call.
require_once_demo.php
<?php   include_once('demo.php');   include_once('demo.php');?>
Output:
Difference between include() and include_once():
PHP-Questions
Difference Between
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to convert Python’s .isoformat() string back into datetime object

28 Jul, 2021
In this article, we will learn how to convert Pythons .isoFormat() string back into a datetime object. Here we are using the current time and for that, we will store the current time in the current_time variable.
The function now() of this module, does the job perfectly.
Example: Getting current time
Python3
from datetime import datetime  current_time = datetime.now()  print(current_time)
Output:
2021-07-22 15:17:19.735037
In this step, we are going to get the string format of the iso time. For this, isoformat() function is used.
Example: getting string format of time
Python3
from datetime import datetime  current_time = datetime.now().isoformat()print(current_time)
2021-07-26T11:36:17.090181

So here we are going to get the DateTime object from the iso string. For that fromisoformat() function is used.
Example: Get the DateTime object from the iso format
Python3
from datetime import datetime  current_time = datetime.now().isoformat()  print(datetime.fromisoformat(current_time))
Output:
2021-07-26 17:06:51.149731
Picked
Python datetime-program
Python-datetime
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to connect Node.js application to MySQL ?

19 Oct, 2021
Node.js is an open-source and cross-platform runtime environment built on Chrome’s V8 engine that enables us to use JavaScript outside the browser. Node.js helps us to use build server-side applications using JavaScript. In this article, we will discuss how to connect the Node.js application to MySQL. For connecting the node.js with MySQL database we need a third-party mysql module.
Approach:
First, initialize the node.js project in the particular folder in your machine.
Download the mysql module in the project folder.
After this create connection to the database with the createconnection() method of the mysql module.
The above approach is discussed below:
Step 1: Create a NodeJS Project and initialize it using the following command:
npm init
Step 2: Install the mysql modules using the following command:
npm install mysql
File Structure: Our file structure will look like the following:
Mysql database Structure:
index.js
// Importing modulevar mysql = require('mysql')  var connection = mysql.createConnection({    host:"localhost",    user:"root",    password:"Aayush",    database : "aayush"})  // Connecting to databaseconnection.connect(function(err) {    if(err){      console.log("Error in the connection")      console.log(err)    }    else{      console.log(`Database Connected`)      connection.query(`SHOW DATABASES`,       function (err, result) {        if(err)          console.log(`Error executing the query - ${err}`)        else          console.log("Result: ",result)       })    }})
Run index.js file using below command:
node index.js
Console Output:
NodeJS-MySQL
NodeJS-Questions
Picked
TrueGeek-2021
Node.js
TrueGeek
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
DoubleStream average() method in Java

The average() method of the DoubleStream class in Java returns an OptionalDouble which is the arithmetic mean of elements of this stream. If the stream is empty, empty is returned.
The syntax is as follows:
OptionalDouble average()
Here, OptionalDouble is a container object which may or may not contain a double value.
To use the DoubleStream class in Java, import the following package:
import java.util.stream.DoubleStream;
First, create DoubleStream and add some elements:
DoubleStream doubleStream = DoubleStream.of(50.8, 35.7, 49.5,12.7, 89.7, 97.4);
Get the average of the elements of the stream:
OptionalDouble res = doubleStream.average();
The following is an example to implement DoubleStream average() method in Java:
 Live Demo
import java.util.*;
import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.of(50.8, 35.7, 49.5,12.7, 89.7, 97.4);
      OptionalDouble res = doubleStream.average();
      System.out.println("Average of the elements of the stream...");
      if (res.isPresent()) {
         System.out.println(res.getAsDouble());
      } else {
         System.out.println("Nothing!");
      }
   }
}
Average of the elements of the stream...
55.96666666666667
Let us see another example:
 Live Demo
import java.util.*;
import java.util.stream.DoubleStream;
public class Demo {
   public static void main(String[] args) {
      DoubleStream doubleStream = DoubleStream.empty();
      OptionalDouble res = doubleStream.average();
      if (res.isPresent()) {
         System.out.println(res.getAsDouble());
      } else {
         System.out.println("Nothing! Stream is empty!");
      }
   }
}
The following is the output displaying nothing since the stream is empty:
Nothing! Stream is empty!
Scala Map get() method with example - GeeksforGeeks

13 Aug, 2019
The get() method is utilized to give the value associated with the keys of the map. The values are returned here as an Option i.e, either in form of Some or None.
Method Definition:def get(key: A): Option[B]
Return Type: It returns the keys corresponding to the values given in the method as argument.
Example #1:
// Scala program of get()// method  // Creating objectobject GfG{       // Main method    def main(args:Array[String])    {              // Creating a map        val m1 = Map("geeks" -> 5, "for" -> 3, "cs" -> 2)                   // Applying get method        val result = m1.get("for")                  // Displays output        println(result)          }}
Some(3)

Here, the key in the argument i.e, for is present in the map stated above so, the value of the key is returned in the Some form.Example #2:
// Scala program of get()// method  // Creating objectobject GfG{       // Main method    def main(args:Array[String])    {              // Creating a map        val m1 = Map("geeks" -> 5, "for" -> 3, "cs" -> 2)                   // Applying get method        val result = m1.get("portal")                  // Displays output        println(result)          }}
None

Here, the key in the argument is not present in the map so, None is returned.
Scala
Scala-Map
Scala-Method
Scala
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Scala Tutorial – Learn Scala with Step By Step Guide
Type Casting in Scala
Scala Lists
Class and Object in Scala
Scala String substring() method with example
Break statement in Scala
Lambda Expression in Scala
Scala String replace() method with example
Operators in Scala
How to move specific item in array list to the first item in Java?

To move an item from an ArrayList and add it to the first position you need to -
Get the position (index) of the item using the indexOf() method of the ArrayList class.
Remove it using the remove() method of the ArrayList class.
Finally, add it to the index 0 using the add() method of the ArrayList class.
Live Demo
import java.util.ArrayList;

public class ArrayListSample {
   public static void main(String args[]) {
      ArrayList al = new ArrayList();
      al.add("JavaFX");
      al.add("HBase");
      al.add("WebGL");
      al.add("OpenCV");
      System.out.println(al);
      String item = "WebGL";
      int itemPos = al.indexOf(item);
      al.remove(itemPos);
      al.add(0, item );
      System.out.println(al);
   }
}
[JavaFX, HBase, WebGL, OpenCV]
[WebGL, JavaFX, HBase, OpenCV]
Program to find goal parser interpretation command in Python

Suppose we have a Goal Parser that can interpret a given string command. A command consists of
An alphabet "G",
An alphabet "G",
Opening and closing parenthesis "()"
Opening and closing parenthesis "()"
and/or "(al)" in some order.
and/or "(al)" in some order.
Our Goal Parser will interpret "G" as the string "G", "()" as "o", and "(al)" as the string "al". Finally interpreted strings are then concatenated in the original order. So if we have string command, we have to find the Goal Parser's interpretation of command.
So, if the input is like command = "G()()()(al)(al)", then the output will be Goooalal.
To solve this, we will follow these steps −
s:= blank string
s:= blank string
for i in range 0 to size of command - 1, doif command[i] is not same as "(" and command[i] is not same as ")", thens := s concatenate command[i]if command[i] is same as "(" and command[i+1] is same as ")" and i+1<len(command) , thens := s concatenate 'o'if command[i] is same as "(", thengo for next iterationif command[i] is same as ")", thengo for next iteration
for i in range 0 to size of command - 1, do
if command[i] is not same as "(" and command[i] is not same as ")", thens := s concatenate command[i]
if command[i] is not same as "(" and command[i] is not same as ")", then
s := s concatenate command[i]
s := s concatenate command[i]
if command[i] is same as "(" and command[i+1] is same as ")" and i+1<len(command) , thens := s concatenate 'o'
if command[i] is same as "(" and command[i+1] is same as ")" and i+1<len(command) , then
s := s concatenate 'o'
s := s concatenate 'o'
if command[i] is same as "(", thengo for next iteration
if command[i] is same as "(", then
go for next iteration
go for next iteration
if command[i] is same as ")", thengo for next iteration
if command[i] is same as ")", then
go for next iteration
go for next iteration
return s
return s
Let us see the following implementation to get better understanding −
 Live Demo
def solve(command):
   s=""
   for i in range(len(command)):
      if command[i]!="(" and command[i]!=")":
         s+=command[i]
      if command[i]=="(" and command[i+1]==")" and i+1<len(command):
         s+='o'
      if command[i]=="(":
         continue
      if command[i]==")":
         continue
   return s

command = "G()()()(al)(al)"
print(solve(command))
"G()()()(al)(al)"
Goooalal
Python 3 - String split() Method

The split() method returns a list of all the words in the string, using str as the separator (splits on all whitespace if left unspecified), optionally limiting the number of splits to num.
Following is the syntax for split() method −
str.split(str="", num = string.count(str)).

str − This is any delimeter, by default it is space.
str − This is any delimeter, by default it is space.
num − this is number of lines to be made
num − this is number of lines to be made
This method returns a list of lines.
The following example shows the usage of split() method.
#!/usr/bin/python3

str = "this is string example....wow!!!"
print (str.split( ))
print (str.split('i',1))
print (str.split('w'))
When we run above program, it produces the following result −
['this', 'is', 'string', 'example....wow!!!']
['th', 's is string example....wow!!!']
['this is string example....', 'o', '!!!']


    187 Lectures 
     17.5 hours 

 Malhar Lathkar

    55 Lectures 
     8 hours 

 Arnab Chakraborty

    136 Lectures 
     11 hours 

 In28Minutes Official

    75 Lectures 
     13 hours 

 Eduonix Learning Solutions

    70 Lectures 
     8.5 hours 

 Lets Kode It

    63 Lectures 
     6 hours 

 Abhilash Nelson
 Print
 Add Notes
 Bookmark this page
Hash-Buster v3.0 – Crack Hashes In Seconds

23 Sep, 2021
Hashing is a cryptographic method that can be used to authenticate the authenticity and integrity of various types of information. It is widely used in authentication systems to circumvent storing plaintext passwords in databases but is also used to authenticate files, documents, and other types of data. This makes the communication between sender and receiver more secure. Although it’s not totally secure, there are various tools that can crack the hashes and get the results in plain text format. Hash-Buster is an automated tool developed in the Python Language which cracks all types of hashes in seconds.  
Hash-Buster tool can automatically detect the type of hash also tool can identify hashes from a directory, recursively. Hash-buster tool is available on the GitHub platform, it’s free and open-source to use.
Step 1: Use the following command to install the tool in your Kali Linux operating system.
git clone https://github.com/s0md3v/Hash-Buster.git
Step 2: Now use the following command to move into the directory of the tool. You have to move in the directory in order to run the tool.
cd Hash-Buster
Step 3: You are in the directory of the Hash-Buster. Now install the tool by using the following command.
sudo make install
Step 4: Now use the following command to run the tool and check the help section.
buster -h
Example 1: Cracking a single hash
buster -s a6eb56f80be8a120436d6f1c9b8d87ca
In this example, we are cracking the single hash which is inputted by using the -s tag.
Example 2: Finding hashes from a directory
buster -d /home/kali/Videos/
In this example, the tool will search the hashes in the directory and it will be cracked.
Cracked hash results are displayed in the below screenshot.
Example 3: Cracking hashes from a file
buster -f hashes.txt
In this example, we will be cracking multiple hashes which are specified in the hashes.txt file.
Results are displayed in the below screenshot.
Example 4: Specifying number of threads
buster -s a6eb56f80be8a120436d6f1c9b8d87ca -t 10
In this example, we are specifying the value of threads for faster execution.
Kali-Linux
Linux-Tools
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Introduction to Syntax Analysis in Compiler Design

15 Jun, 2022
When an input string (source code or a program in some language) is given to a compiler, the compiler processes it in several phases, starting from lexical analysis (scans the input and divides it into tokens) to target code generation.
Syntax Analysis or Parsing is the second phase, i.e. after lexical analysis. It checks the syntactical structure of the given input, i.e. whether the given input is in the correct syntax (of the language in which the input has been written) or not. It does so by building a data structure, called a Parse tree or Syntax tree. The parse tree is constructed by using the pre-defined Grammar of the language and the input string. If the given input string can be produced with the help of the syntax tree (in the derivation process), the input string is found to be in the correct syntax. if not, the error is reported by the syntax analyzer.
The pushdown automata (PDA) is used to design the syntax analysis phase.
The Grammar for a Language consists of Production rules.
Example: Suppose Production rules for the Grammar of a language are:
  S -> cAd
  A -> bc|a
  And the input string is “cad”.
Now the parser attempts to construct a syntax tree from this grammar for the given input string. It uses the given production rules and applies those as needed to generate the string. To generate string “cad” it uses the rules as shown in the given diagram: 
In step (iii) above, the production rule A->bc was not a suitable one to apply (because the string produced is “cbcd” not “cad”), here the parser needs to backtrack, and apply the next production rule available with A which is shown in step (iv), and the string “cad” is produced.
Thus, the given input can be produced by the given grammar, therefore the input is correct in syntax. But backtrack was needed to get the correct syntax tree, which is really a complex process to implement.
There can be an easier way to solve this, which we shall see in the next article “Concepts of FIRST and FOLLOW sets in Compiler Design”.
Quiz on Syntax Analysis
This article is compiled by Vaibhav Bajpai. Please write comments if you find anything incorrect, or if you want to share more information about the topic discussed above
VaibhavRai3
aayushi2402
Compiler Design
GATE CS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Tailwind CSS Width

23 Mar, 2022
This class accepts lots of values in tailwind CSS in which all the properties are covered as in class form. It is the alternative to the CSS Width Property. This class is used to set the width of the text, images. The width can be assigned to the text and images in the form of pixels(px), percentage(%), centimeter(cm) etc. 
Width classes:
w-0: This class means the width is set to zero.
w-auto: This class means the width is set according to the content
w-1/2: This class means the width is set to half of the window.
w-1/3: This class means the width is set to one-third of the window.
w-1/4: This class means the width is set to one-fourth of the window.
w-1/5: This class means the width is set to one-fifth of the window.
w-1/6: This class means the width is set to one-sixth of the window.
w-1/12: This class means the width is set to one-twelfth of the window.
w-full: This class means the width is set to full.
w-screen: This class means the width is set to the screen size.
w-min:  This class is used to define the min-width.
w-max: This class is used to define the max-width.
Note: You can change the number with the valid “rem” values or set the percentage value.
Syntax:
<element class="w-0">...</element>
Example:
HTML
<!DOCTYPE html> <head>     <link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css"           rel="stylesheet"> </head>   <body class="text-center mx-4 space-y-2">     <h1 class="text-green-600 text-5xl font-bold">        GeeksforGeeks    </h1>     <b>Tailwind CSS Width Class</b>     <div class="flex">        <div class="w-1/2 bg-green-600 h-12 rounded-l-lg">          w-1/2        </div>        <div class="w-1/2 bg-green-300 h-12 rounded-r-lg">          w-1/2        </div>    </div>    <div class="flex ...">      <div class="w-2/5 bg-green-600 h-12 rounded-l-lg">          w-2/5      </div>      <div class="w-3/5 bg-green-300 h-12 rounded-r-lg">          w-3/5      </div>    </div>    <div class="flex ...">      <div class="w-1/3 bg-green-600 h-12 rounded-l-lg">          w-1/3      </div>      <div class="w-2/3 bg-green-300 h-12 rounded-r-lg">          w-2/3      </div>    </div>    <div class="flex ...">      <div class="w-1/4 bg-green-600 h-12 rounded-l-lg">          w-1/4      </div>      <div class="w-3/4 bg-green-300 h-12 rounded-r-lg">          w-3/4      </div>    </div>    <div class="flex ...">      <div class="w-1/5 bg-green-600 h-12 rounded-l-lg">          w-1/5      </div>      <div class="w-4/5 bg-green-300 h-12 rounded-r-lg">          w-4/5      </div>    </div>    <div class="flex ...">      <div class="w-1/6 bg-green-600 h-12 rounded-l-lg">          w-1/6      </div>      <div class="w-5/6 bg-green-300 h-12 rounded-r-lg">          w-5/6      </div>    </div>    <div class="w-full bg-green-300 h-12 rounded-lg">          w-full    </div></body>   </html>
Output:
Tailwind CSS
Tailwind-Sizing
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
numpy.bitwise_xor() in Python

29 Nov, 2018
numpy.bitwise_xor() function is used to Compute the bit-wise XOR of two array element-wise. This function computes the bit-wise XOR of the underlying binary representation of the integers in the input arrays.
Syntax : numpy.bitwise_xor(arr1, arr2, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, ufunc ‘bitwise_xor’)
Parameters :arr1 : [array_like] Input array.arr2 : [array_like] Input array.out : [ndarray, optional] A location into which the result is stored. If provided, it must have a shape that the inputs broadcast to. If not provided or None, a freshly-allocated array is returned.**kwargs : Allows you to pass keyword variable length of argument to a function. It is used when we want to handle named argument in a function.where : [array_like, optional] True value means to calculate the universal functions(ufunc) at that position, False value means to leave the value in the output alone.
Return : [ndarray or scalar] Result. This is a scalar if both x1 and x2 are scalars.
Code #1 : Working
# Python program explaining# bitwise_xor() function  import numpy as geekin_num1 = 10in_num2 = 11  print ("Input  number1 : ", in_num1)print ("Input  number2 : ", in_num2)     out_num = geek.bitwise_xor(in_num1, in_num2) print ("bitwise_xor of 10 and 11 : ", out_num) 
Output :
Input  number1 :  10
Input  number2 :  11
bitwise_xor of 10 and 11 :  1

 Code #2 :
# Python program explaining# bitwise_xor() function  import numpy as geek  in_arr1 = [2, 8, 125]in_arr2 = [3, 3, 115]   print ("Input array1 : ", in_arr1) print ("Input array2 : ", in_arr2)    out_arr = geek.bitwise_xor(in_arr1, in_arr2) print ("Output array after bitwise_xor: ", out_arr) 
Output :
Input array1 :  [2, 8, 125]
Input array2 :  [3, 3, 115]
Output array after bitwise_xor:  [ 1 11 14]

 Code #3 :
# Python program explaining# bitwise_xor() function  import numpy as geek  in_arr1 = [True, False, True, False]in_arr2 = [False, False, True, True]   print ("Input array1 : ", in_arr1) print ("Input array2 : ", in_arr2)    out_arr = geek.bitwise_xor(in_arr1, in_arr2) print ("Output array after bitwise_xor: ", out_arr) 
Output :
Input array1 :  [True, False, True, False]
Input array2 :  [False, False, True, True]
Output array after bitwise_xor:  [ True False False  True]

Python numpy-Binary Operation
Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Iterate over a list in Python
Python OOPs Concepts
PHP | stristr() Function

28 Mar, 2018
The stristr() function is a built-in function in PHP. It searches for the first occurrence of a string inside another string and displays the portion of the latter starting from the first occurrence of the former in the latter (before if specified). This function is case-insensitive.Syntax :
stristr( $string, $search, $before )
Parameters : This function accepts three parameters as shown in the above syntax out of which the first two parameters must be supplied and the third one is optional. All of these parameters are described below:
$string : It is a mandatory parameter which specifies the string to be searched.
$search : It is a mandatory parameter which specifies the string to search for. If this parameter is a number, it will search for the character matching the ASCII value of the number
$before : It is an optional parameter. It specifies a boolean value whose default is false. If set to true, it returns the part of the string before the first occurrence of the search parameter.
Return Value : The function returns the rest of the string (from the matching point), or FALSE, if the string to search for is not found.
Examples:
Input : $string = "Hello world!", $search = "WORLD"
Output : world!

Input : $string = "Geeks for Geeks!", $search = "K"
Output : ks for Geeks!

Below programs illustrate the stristr() function in PHP :
Program 1: In this program we will display the portion of $string from the first occurrence of $search.
<?phpecho stristr("Geeks for Geeks!", "K");?>  
Output:
ks for Geeks! 
Program 2: In this program we will display the portion of $string before the first occurrence of $search.
<?phpecho stristr("Geeks for Geeks!", "K", true);?>     
Output:
Gee
Program 3: In this program we will pass an integer as $search.
<?php  $string = "Geeks";  echo stristr($string, 101); // 101 is ASCII value of lowercase e?>     
Output:
eeks
Reference:http://php.net/manual/en/function.stristr.php
PHP-string
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Minimum number of subsets with distinct elements using Counter

21 Nov, 2018
You are given an array of n-element. You have to make subsets from the array such that no subset contain duplicate elements. Find out minimum number of subset possible.
Examples:
Input : arr[] = {1, 2, 3, 4}
Output :1
Explanation : A single subset can contains all 
values and all values are distinct

Input : arr[] = {1, 2, 3, 3}
Output : 2
Explanation : We need to create two subsets
{1, 2, 3} and {3} [or {1, 3} and {2, 3}] such
that both subsets have distinct elements.

We have existing solution for this problem please refer Minimum number of subsets with distinct elements link. We will solve this problem quickly in python using Counter(iterable) method. Approach is very simple, calculate frequency of each element in array and print value of maximum frequency because we want each subset to be different and we have to put any repeated element in different subset, so to get minimum number of subset we should have at least maximum frequency number of subsets.
# Python program to find Minimum number of # subsets with distinct elements using Counter  # function to find Minimum number of subsets # with distinct elementsfrom collections import Counter  def minSubsets(input):       # calculate frequency of each element     freqDict = Counter(input)       # get list of all frequency values     # print maximum from it      print (max(freqDict.values()))  # Driver programif __name__ == "__main__":    input = [1, 2, 3, 3]    minSubsets(input)
Output:
2

Python dictionary-programs
Python set-programs
python-dict
python-set
Python
python-dict
python-set
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Iterate over a list in Python
Convert integer to string in Python
How to download all pdf files with selenium python?

Answer − We can download all pdf files using Selenium webdriver in Python. A file is downloaded in the default path set in the Chrome browser. However, we can modify the path of the downloaded file programmatically in Selenium.
This is done with the help of the Options class. We have to create an object of this class and apply add_experimental_option. We have to pass the parameters - prefs and the path where the pdf is to be downloaded to this method. Finally, this information has to be sent to the webdriver object.
op = Options()
p = {"download.default_directory": "../pdf"}
op.add_experimental_option("prefs", p)
Code Implementation
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
#Options instance
op = Options()
#configure path of downloaded pdf file
p = {"download.default_directory": "../pdf"}
op.add_experimental_option("prefs", p)
#send browser option to webdriver object
driver = webdriver.Chrome(executable_path='../drivers/chromedriver',
options=op)
#implicit wait
driver.implicitly_wait(0.8)
#url launch
driver.get("http://demo.automationtesting.in/FileDownload.html")
#browser maximize
driver.maximize_window()
#identify element
m = driver.find_element_by_id('pdfbox')
m.send_keys("infotest")
t = driver.find_element_by_id('createPdf')
t.click()
e = driver.find_element_by_id('pdf-link-to-download')
e.click()
#driver close
driver.close()
How to subset a data frame based on a vector values in R?

If we have a vector and a data frame, and the data frame has a column that contains the values similar as in the vector then we can create a subset of the data frame based on that vector. This can be done with the help of single square brackets and %in% operator. The %in% operator will help us to find the values in the data frame column that matches with the vector values. Check out the below examples to understand how it works.
Consider the below data frame df1 and vector v1 −
Live Demo
> x1<-rpois(20,2)
> x2<-rnorm(20)
> df1<-data.frame(x1,x2)
> df1
x1 x2
1 2 -1.0627997
2 4 -0.2159125
3 1 0.2443734
4 3 -1.3513780
5 3 1.7359994
6 1 1.2563915
7 1 -0.8998470
8 2 0.4187820
9 1 2.6305826
10 4 -0.8040052
11 4 0.4067659
12 3 -1.7879203
13 3 1.7214544
14 2 -0.4699642
15 2 0.3626548
16 4 1.3013632
17 2 -0.2983836
18 1 1.8943313
19 1 1.5637219
20 2 0.8786897
Sub-setting the data frame df1 based on values in vector v1 −
> df1[df1$x1 %in% v1,]
x1 x2
1 2 -1.0627997
3 1 0.2443734
4 3 -1.3513780
5 3 1.7359994
6 1 1.2563915
7 1 -0.8998470
8 2 0.4187820
9 1 2.6305826
12 3 -1.7879203
13 3 1.7214544
14 2 -0.4699642
15 2 0.3626548
17 2 -0.2983836
18 1 1.8943313
19 1 1.5637219
20 2 0.8786897
Live Demo
> y1<-sample(LETTERS[1:5],20,replace=TRUE)
> y2<-rpois(20,2)
> y3<-rpois(20,5)
> df2<-data.frame(y1,y2,y3)
> df2
y1 y2 y3
1 C 0 5
2 A 2 5
3 A 2 1
4 D 1 6
5 B 0 4
6 E 6 9
7 E 0 5
8 C 1 9
9 D 1 6
10 D 2 6
11 A 4 5
12 D 1 6
13 E 1 5
14 E 2 6
15 C 5 4
16 A 0 3
17 D 2 5
18 B 1 10
19 E 3 3
20 A 2 1
Sub-setting the data frame df2 based on values in vector v2 −
> v2<-c("A","B","C","D")
> df2[df2$y1 %in% v2,]
y1 y2 y3
1 C 0 5
2 A 2 5
3 A 2 1
4 D 1 6
5 B 0 4
8 C 1 9
9 D 1 6
10 D 2 6
11 A 4 5
12 D 1 6
15 C 5 4
16 A 0 3
17 D 2 5
18 B 1 10
20 A 2 1
How can I convert a bytes array into JSON format in Python?

You need to decode the bytes object to produce a string. This can be done using the decode function from string class that will accept then encoding you want to decode with. 
my_str = b"Hello" # b means its a byte string
new_str = my_str.decode('utf-8') # Decode using the utf-8 encoding
print(new_str)
This will give the output
Hello
Once you have the bytes as a string, you can use the JSON.dumps method to convert the string object to JSON. 
my_str = b'{"foo": 42}' # b means its a byte string
new_str = my_str.decode('utf-8') # Decode using the utf-8 encoding

import json
d = json.dumps(my_str)
print(d)
This will give the output −
"{\"foo\": 42}"
Why can't my HTML file find the JavaScript function from a sourced module?

This may happen if you haven’t used “export” statement. Use “export” before the function which
will be imported into the script file. The JavaScript file is as follows which has the file name
demo.js.
demo.js
console.log("function will import");
export function test(){
   console.log("Imported!!!");
}
Here is the “index.html” file that imports the above function −
index.html
 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>
</head>
<body>
<script type='module'>
   import { test } from "./demo.js"
   test();
</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.
Following is the output from the file demo.js which has the function name test().
DAX Text - LEN function

Returns the number of characters in a text string.
LEN (<text>) 

text
The text whose length you want to find, or a column that contains text.
A whole number indicating the number of characters in the text string.
Spaces count as characters.
DAX uses Unicode and stores all the characters with the same length. Hence, LEN always counts each character as 1, no matter what the default language setting is.
If you use DAX LEN function with a column that contains non-text values, such as dates or Boolean values, the function implicitly casts the value to text, using the current column format.
= LEN ([Product]) 
Returns a calculated column with the number of characters in the corresponding Product text values.

    53 Lectures 
     5.5 hours 

 Abhay Gadiya

    24 Lectures 
     2 hours 

 Randy Minder

    26 Lectures 
     4.5 hours 

 Randy Minder
 Print
 Add Notes
 Bookmark this page
How to compare two lists for equality in C#?

Set the two lists −
List < string > list1 = new List < string > ();
list1.Add("A");
list1.Add("B");
list1.Add("C");
list1.Add("D");
List < string > list2 = new List < string > ();
list2.Add("C");
list2.Add("D");
Now if the following returns different elements, then it would mean the lists are not equal −
using System;
using System.Collections.Generic;
using System.Linq;

public class Demo {
   public static void Main() {
      List < string > list1 = new List < string > ();
      list1.Add("P");
      list1.Add("Q");
      list1.Add("R");

      Console.WriteLine("First list...");
      foreach(string value in list1) {
         Console.WriteLine(value);
      }

      Console.WriteLine("Second list...");
      List < string > list2 = new List < string > ();

      list2.Add("P");
      list2.Add("R");
      foreach(string value in list2) {
         Console.WriteLine(value);
      }

      Console.WriteLine("Difference in the two lists...");
      IEnumerable < string > list3;
      list3 = list1.Except(list2);
      foreach(string value in list3) {
         Console.WriteLine(value);
      }
   }
}
Barrier Objects in Python

Barrier provides one of the python synchronization technique with which single or multiple threads wait until a point in a set of activities and make progress together.
To define a barrier object, “threading. Barrier” is used.
threading.Barrier(parties, action = None, timeout = None)
Where,
parties = Number of threads
parties = Number of threads
action = called by one of the threads when they are released.
action = called by one of the threads when they are released.
timeout = Default timeout value. In case no timeout value is specified for the wait(), this timeout value is used.
timeout = Default timeout value. In case no timeout value is specified for the wait(), this timeout value is used.
Below mentioned methods are used by Barrier class.
barrierThread.py
 Live Demo
from random import randrange
from threading import Barrier, Thread
from time import ctime, sleep
num = 4
# 4 threads will need to pass this barrier to get released.
b = Barrier(num)
names = ['India', 'Japan', 'USA', 'China']
def player():
   name = names.pop()
   sleep(randrange(2, 5))
   print('%s reached the barrier at: %s \n' % (name, ctime()))
   b.wait()
threads = []
print("Race starts now...")
for i in range(num):
   threads.append(Thread(target=player))
   threads[-1].start()
"""
Below loop enables waiting for the threads to complete before moving on with the main script.
"""
for thread in threads:
   thread.join()
print("All Reached Barrier Point!")
Race starts now...
India reached the barrier at: Fri Jan 18 14:07:44 2019
China reached the barrier at: Fri Jan 18 14:07:44 2019
Japan reached the barrier at: Fri Jan 18 14:07:46 2019
USA reached the barrier at: Fri Jan 18 14:07:46 2019
All Reached Barrier Point!
Java Examples - Array Compare

How to sort an array and search an element inside it?
Following example shows how to use sort () and binarySearch () method to accomplish the task. The user defined method printArray () is used to display the output −
import java.util.Arrays;

public class MainClass {
   public static void main(String args[]) throws Exception {
      int array[] = { 2, 5, -2, 6, -3, 8, 0, -7, -9, 4 };
      Arrays.sort(array);
      printArray("Sorted array", array);
      
      int index = Arrays.binarySearch(array, 2);
      System.out.println("Found 2 @ " + index);
   }
   private static void printArray(String message, int array[]) {
      System.out.println(message + ": [length: " + array.length + "]");
      for (int i = 0; i < array.length; i++) {
         if(i != 0){
            System.out.print(", ");
         }
         System.out.print(array[i]);
      } 
      System.out.println();
   }
}
The above code sample will produce the following result.
Sorted array: [length: 10]
-9, -7, -3, -2, 0, 2, 4, 5, 6, 8
Found 2 @ 5

How to compare Two arrays?
public class HelloWorld { 
   public static void main (String[] args) {
      int arr1[] = {1, 2, 3};
      int arr2[] = {1, 2, 3};
      
      if (arr1 == arr2) System.out.println("Same"); 
      else System.out.println("Not same");
   } 
}
The above code sample will produce the following result.
Not same   

Another sample example of Array compare
import java.util.Arrays;

public class HelloWorld { 
   public static void main (String[] args) { 
      int arr1[] = {1, 2, 3};
      int arr2[] = {1, 2, 3};
   
      if (Arrays.equals(arr1, arr2)) System.out.println("Same"); 
      else System.out.println("Not same");
   }
}
The above code sample will produce the following result.
Same   

 Print
 Add Notes
 Bookmark this page
How to randomly select a fixed number of rows without replacement from a data frame in R?

This can be done simply by using sample function.
> df = data.frame(matrix(rnorm(20), nrow=5))
> df
    X1         X2          X3        X4
1 -0.3277833 -0.1810403  0.2844406 -2.9676440
2 0.8262923   0.4334449  0.4031084 -1.9278049
3 -0.1769219 -0.1583660 -0.2829540 -0.1962654
4 1.0357773   0.9326049  0.3250011 -1.8835882
5 -1.0682642 -0.6589731 -0.4783144 -0.2945062
Let’s say we want to select 3 rows randomly then it can be done as follows −
> df[sample(nrow(df), 3), ]
    X1        X2          X3       X4
2  0.8262923  0.4334449  0.4031084 -1.9278049
1 -0.3277833 -0.1810403  0.2844406 -2.9676440
5 -1.0682642 -0.6589731 -0.4783144 -0.2945062
Count the number of paragraph tag using BeautifulSoup - GeeksforGeeks

07 Apr, 2021
Sometimes, while extracting data from an HTML webpage, do you want to know how many paragraph tags are used in a given HTML document? Don’t worry we will discuss about this in this article.
print(len(soup.find_all("p")))
Step 1: First, import the libraries, BeautifulSoup, and os.
from bs4 import BeautifulSoup as bs
import os
Step 2: Now, remove the last segment of the path by entering the name of the Python file in which you are currently working.
base=os.path.dirname(os.path.abspath(‘#Name of Python file in which you are currently working’))
Step 3: Then, open the HTML file from which you want to read the value.
html=open(os.path.join(base, ‘#Name of HTML file from which you wish to read value’))
Step 4: Moreover, parse the HTML file in BeautifulSoup.
soup=bs(html, 'html.parser')
Step 5: Next, print a certain line if you want to. 
print("Number of paragraph tags:")
Step 6: Finally, calculate and print the number of paragraph tags in the HTML document.
print(len(soup.find_all("p")))
Example 1
Let us consider the simple HTML webpage, which has numerous paragraph tags.
HTML
<!DOCTYPE html><html>     <head>   Geeks For Geeks </head>     <body>      <div>       <p>King</p>         <p>Prince</p>         <p>Queen</p>   </div>      <p id="vinayak">Princess</p>    </body>    </html>
For finding the number of paragraph tags in the above HTML webpage, implement the following code.
Python
# Python program to get number of paragraph tags# of a given HTML document in Beautifulsoup  # Import the libraries beautifulsoup # and osfrom bs4 import BeautifulSoup as bsimport os  # Open the HTML filehtml = open('gfg.html')  # Parse HTML file in Beautiful Soupsoup = bs(html, 'html.parser')  # Print a certain lineprint("Number of paragraph tags:")  # Calculating and printing the# number of paragraph tagsprint(len(soup.find_all("p")))
Output:
Example 2
In the below program, we will find the number of paragraph tags on a particular website.
Python
# Python program to get number of paragraph tags# of a given Website in Beautifulsoup  # Import the libraries beautifulsoup # and osfrom bs4 import BeautifulSoup as bsimport osimport requests  # Assign URLURL = 'https://www.geeksforgeeks.org/'  # Page content from Website URLpage = requests.get(URL)  # Parse HTML file in Beautiful Soupsoup = bs(page.content, 'html.parser')  # Print a certain lineprint("Number of paragraph tags:")  # Calculating and printing the# number of paragraph tagsprint(len(soup.find_all("p")))
Output:
Picked
Python BeautifulSoup
Python bs4-Exercises
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
How To Convert Python Dictionary To JSON?
How to drop one or multiple columns in Pandas Dataframe
Check if element exists in list in Python
Selecting rows in pandas DataFrame based on conditions
Python | os.path.join() method
Defaultdict in Python
Create a directory in Python
Python | Get unique values from a list
Python | Pandas dataframe.groupby()
Compare two char arrays in a single line in Java

Two char arrays can be compared in Java using the java.util.Arrays.equals() method. This method returns true if the arrays are equal and false otherwise. The two arrays are equal if they contain the same number of elements in the same order.
A program that compares two char arrays using the Arrays.equals() method is given as follows −
 Live Demo
import java.util.Arrays;
public class Demo {
   public static void main(String[] argv) throws Exception {
      boolean flag = Arrays.equals(new char[] { 'a', 'b', 'c' }, new char[] { 'a', 'b', 'c' });
      System.out.println("The two char arrays are equal? " + flag);
   }
}
The two char arrays are equal? true
Now let us understand the above program.
The Arrays.equals() method is used to compare two char arrays. If they are equal then true is stored in flag and if they are not equal then false is stored in flag. The value of flag is displayed. A code snippet which demonstrates this is as follows −
boolean flag = Arrays.equals(new char[] { 'a', 'b', 'c' }, new char[] { 'a', 'b', 'c' });
System.out.println("The two char arrays are equal? " + flag);
Excel Undo and Redo

The Undo function lets you reverse an action.
Undo is helpful if you regret an action and want to go back to how it was before.
Examples of use
Undo deleting a formula
Undo adding a column
Undo removing a row
Note: You cannot Undo things that you do in the File Menu, such as deleting a sheet, saving a spreadsheet or changing the options. The thumb rule is that you can Undo things you do in your sheet.
There are two ways to access the Undo command.
1) Pressing the Undo button in the Ribbon:
2) Using the keyboard shortcut CTRL + Z / Command + Z
Let's have a look at an example:
Note: It is recommended to practice using the keyboard shortcut. It saves you time!
The Redo function has the opposite effect as Undo, it reverses the Undo action.
Redo is helpful if you regret using Undo.
Note: The Redo command is only available if you have used Undo.
There are two ways to access the Redo command.
1) Pressing the Redo button in the Ribbon:
2) Using the keyboard shortcut CTRL + Y / Command + Y
Tip: Practice for yourself to get familiar with Undo and Redo.
Complete the keyboard shortcut for the Undo command (for Windows and MAC):
CTRL + 
Command + 

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.
Center alignment using the margin property in CSS

We can center horizontally a block-level element by using the CSS margin property, but CSS width property of that element should be set.
Let’s see an example to center an element using CSS margin property −
 Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Center Alignment using CSS Margin</title>
<style>
#yinyangSymbol {
   width: 100px;
   height: 50px;
   background: #fff;
   border-color: #000;
   border-style: solid;
   border-width: 2px 2px 50px 2px;
   border-radius: 100%;
   position: relative;
}
#yinyangSymbol::before {
   content: "";
   position: absolute;
   top: 50%;
   left: 0;
   background: #fff;
   border: 18px solid #000;
   border-radius: 100%;
   width: 14px;
   height: 14px;
}
#yinyangSymbol::after {
   content: "";
   position: absolute;
   top: 50%;
   left: 50%;
   background: #000;
   border: 18px solid #fff;
   border-radius:100%;
   width: 14px;
   height: 14px;
}
div{
   width: 50%;
   margin: 10px auto;
   border:4px solid black;
}
#text {
   border: 4px solid black;
   background-color: grey;
   color: white;
   text-align: center;
}
</style>
</head>
<body>
<div id="main">
<div>
<div id="yinyangSymbol"></div>
</div>
<div id="text">Be Centered & Balanced</div>
</div>
</body>
</html>
This will produce the following output
Let’s see another example to center an element using CSS margin property −
 Live Demo
<!DOCTYPE html>
<html>
<head>
<title>Center Alignment using CSS Margin</title>
<style>
.screen{
   padding: 10px;
   margin: 10px auto;
   text-align: center;
   color: white;
   border-radius: 0 0 50px 50px;
   border: 4px solid #000;
}
.screen1 {
   background-color: #f06d06;
   width: 70%;
}
.screen2 {
   background-color: #48C9B0;
   width: 50%;
}
.screen3 {
   background-color: #DC3545;
   width: 30%;
}
</style>
</head>
<body>
<div class="screen screen1">Screen 70%</div>
<div class="screen screen2">Screen 50%</div>
<div class="screen screen3">Screen 30%</div>
</div>
</body>
</html>
This will produce the following output