code-rag-bench/online-tutorials huggingface dataset:
PHP | implode() Function

17 Jan, 2018
The implode() is a builtin function in PHP and is used to join the elements of an array. implode() is an alias for PHP | join() function and works exactly same as that of join() function.
If we have an array of elements, we can use the implode() function to join them all to form one string. We basically join array elements with a string. Just like join() function , implode() function also returns a string formed from the elements of an array.
Syntax :
string implode(separator,array)

Parameters: The implode() function accepts two parameter out of which one is optional and one is mandatory.
separator: This is an optional parameter and is of string type. The values of the array will be join to form a string and will be separated by the separator parameter provided here. This is optional, if not provided the default is “” (i.e. an empty string).array: The array whose value is to be joined to form a string.
separator: This is an optional parameter and is of string type. The values of the array will be join to form a string and will be separated by the separator parameter provided here. This is optional, if not provided the default is “” (i.e. an empty string).
array: The array whose value is to be joined to form a string.
Note: The separator parameter of implode() is optional. However, it is recommended to always use two parameters for backwards compatibility.
Return Type: The return type of implode() function is string. It will return the joined string formed from the elements of array.
Examples:
Input : implode(array('Geeks','for','Geeks')
Output : GeeksforGeeks

Input : implode("-",array('Geeks','for','Geeks')
Output : Geeks-for-Geeks

Below program illustrates the working of implode() function in PHP:
<?php    // PHP Code to implement join function          $InputArray = array('Geeks','for','Geeks');          // Join without separator    print_r(implode($InputArray));          print_r("\n");          // Join with separator    print_r(implode("-",$InputArray));?>
Output:
GeeksforGeeks
Geeks-for-Geeks

Reference: http://php.net/manual/en/function.implode.php
PHP-string
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
How to fetch data from an API in ReactJS ?
Differences between Functional Components and Class Components in React
Remove elements from a JavaScript Array
REST API (Introduction)
Difference Between PUT and PATCH Request
ReactJS | Router
How to float three div side by side using CSS?
Roadmap to Learn JavaScript For Beginners
Design a Tribute Page using HTML & CSS
Python – Concatenate values with same keys in a list of dictionaries

19 Jan, 2022
Sometimes, while working with Python dictionaries, we can have a problem in which we need to perform concatenation of all the key values list that is like in dictionary list. This is quite a common problem and has applications in domains such as day-day programming and web development domain. Let’s discuss the certain ways in which this task can be performed.
This task can be performed using brute force way. In this we iterate for all the dictionaries and perform the concatenation of like keys by adding one list element to other on the key match.
Python3
# Python3 code to demonstrate working of# Concatenate Similar Key values# Using loop # initializing listtest_list = [{'gfg': [1, 5, 6, 7], 'good': [9, 6, 2, 10],              'CS': [4, 5, 6]},             {'gfg': [5, 6, 7, 8], 'CS': [5, 7, 10]},             {'gfg': [7, 5], 'best': [5, 7]}] # printing original listprint("The original list is : " + str(test_list)) # Concatenate Similar Key values# Using loopres = dict()for dict in test_list:    for list in dict:        if list in res:            res[list] += (dict[list])        else:            res[list] = dict[list] # printing resultprint("The concatenated dictionary : " + str(res))
The original list is : [{'gfg': [1, 5, 6, 7], 'good': [9, 6, 2, 10], 'CS': [4, 5, 6]}, {'gfg': [5, 6, 7, 8], 'CS': [5, 7, 10]}, {'gfg': [7, 5], 'best': [5, 7]}]
The concatenated dictionary : {'gfg': [1, 5, 6, 7, 5, 6, 7, 8, 7, 5], 'good': [9, 6, 2, 10], 'CS': [4, 5, 6, 5, 7, 10], 'best': [5, 7]}
Python3
from collections import defaultdicttest_list = [{'gfg' : [1, 5, 6, 7], 'good' : [9, 6, 2, 10],              'CS' : [4, 5, 6]},             {'gfg' : [5, 6, 7, 8], 'CS' : [5, 7, 10]},             {'gfg' : [7, 5], 'best' : [5, 7]}] print("Original List: " + str(test_list))result = defaultdict(list) for i in range(len(test_list)):    current = test_list[i]    for key, value in current.items():        for j in range(len(value)):            result[key].append(value[j]) print("Concatenated Dictionary: " + str(dict(result)))
Original List: [{'gfg': [1, 5, 6, 7], 'good': [9, 6, 2, 10], 'CS': [4, 5, 6]}, {'gfg': [5, 6, 7, 8], 'CS': [5, 7, 10]}, {'gfg': [7, 5], 'best': [5, 7]}]
Concatenated Dictionary: {'gfg': [1, 5, 6, 7, 5, 6, 7, 8, 7, 5], 'good': [9, 6, 2, 10], 'CS': [4, 5, 6, 5, 7, 10], 'best': [5, 7]}
sswarna1001
Python list-programs
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Iterate over a list in Python
Rotate axis tick labels in Seaborn and Matplotlib
Enumerate() in Python
Deque in Python
Stack in Python
Python Dictionary
sum() function in Python
Print lists in Python (5 Different Ways)
Different ways to create Pandas Dataframe
Queue in Python
Python Random – random() Function

13 Jun, 2022
There are certain situations that involve games or simulations which work on non-deterministic approach. In these types of situations, random numbers are extensively used in the following applications:
Creating pseudo-random numbers on Lottery scratch cards
reCAPTCHA on login forms uses a random number generator to define different numbers and images
Picking a number, flipping a coin, throwing of a dice related games required random numbers
Shuffling deck of playing cards
In Python, random numbers are not generated implicitly; therefore, it provides a random module in order to generate random numbers explicitly. random module in Python is used to create random numbers.  To generate a random number, we need to import a random module in our program using the command:
import random
There are various functions associated with the random module are:
random()randrange()seed()randint()uniform()choice()shuffle()
random()
randrange()
seed()
randint()
uniform()
choice()
shuffle()
and many more. We are only demonstrating the use of random() function.
1. random.random() function generates random floating numbers in the range[0.1, 1.0). (See the opening and closing brackets, it means including 0 but excluding 1). It takes no parameters and returns values uniformly distributed between 0 and 1.
Syntax : random.random()
Parameters : This method does not accept any parameter.
Returns : This method returns a random floating number between 0 and 1.
Python3
# Python3 program to demonstrate# the use of random() function .   # import random from random import random   # Prints random itemprint(random())
Output:
0.41941790721207284
Python3
# Python3 program to demonstrate# the use of random() function .  import random     # Prints random itemprint(random.random())
Output:
0.059970593824388185
Note: Every time you run this program, it will give a different answer.
Example 2: Creating a list of random numbers in Python using random() function 
Python3
# Python3 program to demonstrate# the use of random() function . # import random from random import random  lst = [] for i in range(10):  lst.append(random())   # Prints random itemsprint(lst)
Output:
[0.12144204979175777, 0.27614050014306335, 0.8217122381411321, 0.34259785168486445, 0.6119383347065234, 0.8527573184278889, 0.9741465121560601, 0.21663626227016142, 0.9381166706029976, 0.2785298315133211] 
2. seed(): This function generates a random number based on the seed value. It is used to initialize the base value of the pseudorandom number generator. If the seed value is 10, it will always generate 0.5714025946899135 as the first random number. 
Python3
import random random.seed(10)print(random.random())#Printing the random number twicerandom.seed(10)print(random.random())
Output:
0.5714025946899135
0.5714025946899135
kumar_satyam
sheetal18june
Python-random
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Check if all elements in list follow a condition

02 Oct, 2019
Sometimes, while working with Python list, we can have a problem in which we need to check if all the elements in list abide to a particular condition. This can have application in filtering in web development domain. Let’s discuss certain ways in which this task can be performed.
Method #1 : Using all()We can use all(), to perform this particular task. In this, we feed the condition and the validation with all the elements is checked by all() internally.
# Python3 code to demonstrate working of# Check if all elements in list follow a condition# Using all()  # initializing listtest_list = [4, 5, 8, 9, 10]  # printing listprint("The original list : " + str(test_list))  # Check if all elements in list follow a condition# Using all()res = all(ele > 3 for ele in test_list)  # Printing resultprint("Are all elements greater than 3 ? : " + str(res))
 
The original list : [4, 5, 8, 9, 10]
Are all elements greater than 3 ? : True

 
Method #2 : Using itertools.takewhile()This function can also be used to code solution of this problem. In this, we just need to process the loop till a condition is met and increment the counter. If it matches list length, then all elements meet that condition.
# Python3 code to demonstrate working of# Check if all elements in list follow a condition# Using itertools.takewhile()import itertools  # initializing listtest_list = [4, 5, 8, 9, 10]  # printing listprint("The original list : " + str(test_list))  # Check if all elements in list follow a condition# Using itertools.takewhile()count = 0for ele in itertools.takewhile(lambda x: x > 3, test_list):    count = count + 1res = count == len(test_list)  # Printing resultprint("Are all elements greater than 3 ? : " + str(res))
 
The original list : [4, 5, 8, 9, 10]
Are all elements greater than 3 ? : True

Python list-programs
Python
Python Programs
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()
Python program to convert a list to string
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python | Convert string dictionary to dictionary
What is C++ Standard Error Stream (cerr)?

std::cerr is an object of class ostream that represents the standard error stream oriented to narrow characters (of type char). It corresponds to the C stream stderr. The standard error stream is a destination of characters determined by the environment. This destination may be shared by more than one standard object (such as cout or clog).
As an object of class ostream, characters can be written to it either as formatted data using the insertion operator (operator<<) or as unformatted data, using member functions such as write. The object is declared in the header <iostream> with external linkage and static duration: it lasts the entire duration of the program.
You can use this object to write to the screen. For example, if you want to write "Hello" to the screen, you'd write −
Live Demo
#include<iostream>
int main() {
   std::cerr << "Hello";
   return 0;
}
Then save this program to hello.cpp file. Finally navigate to the saved location of this file in the terminal/cmd and compile it using −
$ g++ hello.cpp
Run it using −
$ ./a.out
This will give the output −
Hello
vnstat command in Linux with Examples

29 Nov, 2021
vnstat is a command-line tool in Linux that is generally used by system administrators in order to monitor network parameters such as bandwidth consumption or maybe some traffic flowing in or out. It monitors the traffic on the network interfaces of the system.  
In case of RedHat based Linux  
yum install vnstat
In case of a ubuntu or debian Linux 
apt install vnstat 
1. To get basic stats of all network interfaces 
vnstat
This command will print all the basic stats of the network interfaces connected to the system. 
2. To monitor a specific interface 
vnstat -i wlo1
This will monitor and display the stats of the specified interface that is wlo1. 
3. To get the daily stats of an interface 
vnstat -d -i wlo1
This will print the daily stats of the specified interface which is wlo1. 
4. To get the hourly stats of an interface 
vnstat -h -i wlo1
This will print the hourly stats of the specified interface which is wlo1. 
5. To display the monthly stats of a interface 
vnstat -m -i wlo1
This command will display the monthly stats of the specified interface. 
6. To save output to a XML file 
vnstat --xml -i wlo1 >output.xml
The command will create an XML file with name output.xml and will have the output of the command in XML format. 
7. To save output to a JSON file 
vnstat --json -i wlo1 >output.json
This command will create a JSON file with name output.json and will have the output of the command in JSON format. 
8. To save output to a text file 
vnstat --oneline -i wlo1 >output.txt
This command will create a text file with name output.txt and will have the output in a one-line format. 
9. To calculate traffic on the current interface 
vnstat -tr
This command will display the traffic on the current network interface in use. 
10. To display vnstat help 
vnstat --help
This command will display the vnstat help section.
surinderdawra388
linux-command
Linux-networking-commands
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Docker - COPY Instruction
scp command in Linux with Examples
chown command in Linux with Examples
Introduction to Linux Operating System
SED command in Linux | Set 2
nohup Command in Linux with Examples
mv command in Linux with examples
Array Basics in Shell Scripting | Set 1
chmod command in Linux with examples
Basic Operators in Shell Scripting
Jython – Introduction and Installation

10 May, 2020
It’s not hidden that Java is a powerful and Python is a simple and easy language. To get them both together, Jython was introduced so it is both powerful and simple. It is a pure Java implementation of Python. It uses Python’s syntax and Java’s environment. It allows using features of Python in Java environment or to import Java classes in Python codes and hence, is very flexible. Jython can run on almost any platform which provides flexibility in application deployment and it also provides many libraries with many more APIs.
It is really beneficial for those who create applications in Java and are new to Python. Python has three implementations:
Cpython(mostly used)
Jython
IronPython
Download your copy from www.jython.org
It will be combined as a cross-platform executable JAR file
If you don’t have Java installed in your system you will need to grab a copy of it. you can download it from www.java.com and install it.
Double click on the JAR file and install it with “All” features installed
Find the jython.bat(windows) or jython.sh(Mac OS) file in the same folder where you installed Jython
Place this folder within your PATH environment variable
After all this has done you will be able to open up the command prompt, type jython and then hit the “enter” key
To install Jython in Linux type the below command in the terminal.
sudo apt install jython
After typing this command provide your sudo password and that’s it. Linux will handle the rest. After installation, check whether Jython is installed correctly or not. See the below image for checking.
Python-Miscellaneous
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python – API.get_user() in Tweepy

08 Jun, 2020
Twitter is a popular social network where users share messages called tweets. Twitter allows us to mine the data of any user using Twitter API or Tweepy. The data will be tweets extracted from the user. The first thing to do is get the consumer key, consumer secret, access key and access secret from twitter developer available easily for each user. These keys will help the API for authentication.
The get_user() method of the API class in Tweepy module is used to get the information of the specified user.
Syntax : API.get_user(id / user_id / screen_name)
Parameter : Only use one of the 3 options:id : specifies the ID or the screen name of the useruser_id : specifies the ID of the user, useful to differentiate accounts when a valid user ID is also a valid screen namescreen_name : specifies the screen name of the user, useful to differentiate accounts when a valid screen name is also a user ID
Returns : an object of the class User
Example 1 :
# import the moduleimport tweepy  # assign the values accordinglyconsumer_key = ""consumer_secret = ""access_token = ""access_token_secret = ""  # authorization of consumer key and consumer secretauth = tweepy.OAuthHandler(consumer_key, consumer_secret)  # set access to user's access key and access secret auth.set_access_token(access_token, access_token_secret)  # calling the api api = tweepy.API(auth)  # using get_user with id_id = "103770785"user = api.get_user(_id)  # printing the name of the userprint("The id " + _id +      " corresponds to the user with the name : " +      user.name)
Output :
The id 103770785 corresponds to the user with the name : Twitter India

Example 2 : Sometimes the user_id and the screen_name of 2 different users might be the same, so we need to explicitly mention either the user_id or the screen_name.
# using get_user with user_iduser_id = "57741058"user = api.get_user(user_id)  # printing the name of the userprint("The user id " + user_id +      " corresponds to the user with the name : " +      user.name)  # using get_user with screen_namescreen_name = "geeksforgeeks"user = api.get_user(screen_name)  # printing the name of the userprint("\nThe screen name " + screen_name +      " corresponds to the user with the name : " +      user.name)
Output :
The user id 57741058 corresponds to the user with the name : GeeksforGeeks

The screen name geeksforgeeks corresponds to the user with the name : GeeksforGeeks

Python-Tweepy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
unordered_set clear() function in C++ STL - GeeksforGeeks

20 Aug, 2021
The unordered_set::clear() function is a built-in function in C++ STL which is used to clear an unordered_set container. That is, this function removes all of the elements from an unordered_set and empties it. All of the iterators, pointers, and references to the container are invalidated. This reduces the size of the container to zero. 
Syntax:  
unordered_set_name.clear()
Parameter: This function does not accepts any parameter.Return Value: This function does not returns any value.Below programs illustrate the unordered_set::clear() function:Program 1:  
CPP
// C++ program to illustrate the// unordered_set::clear() function #include <iostream>#include <unordered_set> using namespace std; int main(){     unordered_set<int> sampleSet;     // Inserting elements    sampleSet.insert(5);    sampleSet.insert(10);    sampleSet.insert(15);    sampleSet.insert(20);    sampleSet.insert(25);     // displaying all elements of sampleSet    cout << "sampleSet contains: ";    for (auto itr = sampleSet.begin(); itr != sampleSet.end(); itr++) {        cout << *itr << " ";    }     // clear the set    sampleSet.clear();     // size after clearing    cout << "\nSize of set after clearing elements: "         << sampleSet.size();     return 0;}
sampleSet contains: 25 20 15 5 10 
Size of set after clearing elements: 0
Program 2: 
CPP
// C++ program to illustrate the// unordered_set::clear() function #include <iostream>#include <unordered_set> using namespace std; int main(){     unordered_set<string> sampleSet;     // Inserting elements    sampleSet.insert("Welcome");    sampleSet.insert("To");    sampleSet.insert("GeeksforGeeks");    sampleSet.insert("Computer Science Portal");    sampleSet.insert("For Geeks");     // displaying all elements of sampleSet    cout << "sampleSet contains: ";    for (auto itr = sampleSet.begin(); itr != sampleSet.end(); itr++) {        cout << *itr << " ";    }     // clear the set    sampleSet.clear();     // size after clearing    cout << "\nSize of set after clearing elements: "         << sampleSet.size();     return 0;}
sampleSet contains: For Geeks GeeksforGeeks Computer Science Portal Welcome To 
Size of set after clearing elements: 0
anikakapoor
natu
CPP-Functions
cpp-unordered_set
cpp-unordered_set-functions
C++
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Inheritance in C++
Map in C++ Standard Template Library (STL)
C++ Classes and Objects
Bitwise Operators in C/C++
Virtual Function in C++
Templates in C++ with Examples
Constructors in C++
Operator Overloading in C++
Socket Programming in C/C++
Object Oriented Programming in C++
How to turn off PHP Notices ? - GeeksforGeeks

16 Oct, 2019
In PHP, Notices are the undefined variables indicated in the PHP project on a set of lines or particular lines. It usually does not affect or break the functionality of the code written. When PHP notices detect errors, it will display like this:
PHP Notice: Use of undefined constant name - assumed 'name' in line number
PHP editing differs from the versions of it. Hence, methods to turn off PHP notices are as follows:
Method 1: It is the most easy and convenient way to turn off the notices. The notices can be disabled through settings the php.ini file. In the current file, search for the line of code error_reporting. There will be a line of Default Value: E_ALL as shown below:
Replace this line of code with Default Value: E_ALL & ~E_NOTICE.It will display all the errors except for the notices. Make sure the part is enabled and then restart or refresh the server for PHP. In some versions of PHP, the default value is set to Default Value: E_ALL & ~E_NOTICE.
Method 2: To turn the notices off, a line of code can be added to the PHP file, at the beginning of the code of the file. For example gfg.phpThe following code would looks something like this
<?php  // Open a file$file = fopen("gfg.txt", "w")         or die("Unable to open file!");  // Store the string into variable$txt = "GeeksforGeeks \n";  // Write the text content to the filefwrite($file, $txt);  // Store the string into variable$txt = "Welcome to Geeks! \n";  // Write the text content to the filefwrite($file, $txt);  // Close the filefclose($file);  ?>
Add this line at the start of the code:
error_reporting(E_ERROR | E_WARNING | E_PARSE);
<?php  error_reporting(E_ERROR | E_WARNING | E_PARSE);   // Open a file$file = fopen("gfg.txt", "w")         or die("Unable to open file!");  // Store the string into variable$txt = "GeeksforGeeks \n";  // Write the text content to the filefwrite($file, $txt);  // Store the string into variable$txt = "Welcome to Geeks! \n";  // Write the text content to the filefwrite($file, $txt);  // Close the filefclose($file);  ?>
It will display the errors, warnings, and compile-time parse errors.
Method 3: The ‘@’ can be added to any operator to make PHP Notices silent while performing current operation:@$mid= $_POST[‘mid’];
PHP-basics
Picked
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.
How to Insert Form Data into Database using PHP ?
How to convert array to string in PHP ?
How to Upload Image into Database and Display it using PHP ?
How to check whether an array is empty using PHP?
PHP | Converting string to Date and DateTime
How to Insert Form Data into Database using PHP ?
How to convert array to string in PHP ?
How to Upload Image into Database and Display it using PHP ?
How to call PHP function on the click of a Button ?
How to check whether an array is empty using PHP?
jQuery UI dialog destroy() Method - GeeksforGeeks

13 Jan, 2021
destroy() Method is used to destroy the dialog. This method does not accept any argument
Syntax:
$( ".selector" ).dialog("destroy");
Approach: First, add jQuery UI scripts needed for your project.
<link href = “https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css” rel = “stylesheet”><script src = “https://code.jquery.com/jquery-1.10.2.js”></script><script src = “https://code.jquery.com/ui/1.10.4/jquery-ui.js”></script>
Example:
HTML
<!doctype html><html lang="en">  <head>    <meta charset="utf-8">    <link href="https://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css"        rel="stylesheet">    <script src="https://code.jquery.com/jquery-1.10.2.js"></script>    <script src="https://code.jquery.com/ui/1.10.4/jquery-ui.js">    </script>      <script>        $(function () {            $("#gfg").dialog({                autoOpen: false,            });            $("#geeks").click(function () {                $("#gfg").dialog("destroy");            });        });    </script></head>  <body>    <div id="gfg">        Jquery UI| destroy dialog method    </div>          <button id="geeks">Open Dialog</button></body>  </html>
Output:
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.
jQuery-UI
HTML
JQuery
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
How to update Node.js and NPM to next version ?
How to set the default value for an HTML <select> element ?
Hide or show elements in HTML using display property
JQuery | Set the value of an input text field
Form validation using jQuery
How to change selected value of a drop-down list using jQuery?
How to change the background color after clicking the button in JavaScript ?
How to fetch data from JSON file and display in HTML table using jQuery ?
How to sorting an array without using loops in Node.js ? - GeeksforGeeks

31 Aug, 2020
The setInterval() method repeats or re-schedules the given function at every given time-interval. It is somewhat like window.setInterval() Method of JavaScript API, however, a string of code can’t be passed to get it executed.
Syntax:
setInterval(timerFunction, millisecondsTime);
Parameter: It accepts two parameters which are mentioned above and described below:
timerFunction <function>: It is the function to be executed.
millisecondsTime <Time>: It indicates a period of time between each execution.
The setTimeout() method is used to schedule code execution after waiting for a specified number of milliseconds. It is somewhat like window.setTimeout() Method of JavaScript API, however a string of code can’t be passed to get it executed.
Syntax:
setTimeout(timerFunction, millisecondsTime);
Parameter: It accepts two parameters which are mentioned above and described below:
timerFunction <function>: It is the function to be executed.
timerFunction <function>: It is the function to be executed.
millisecondsTime <Time>: It indicates a period of time between each execution.
millisecondsTime <Time>: It indicates a period of time between each execution.
Examples:
Input: Array = [ 46, 55, 2, 100, 0, 500 ]
Output: [0, 2, 46, 55, 100, 500]

Input: Array = [8, 9, 2, 7, 18, 5, 25]
Output: [ 2, 5, 7, 8, 9, 18, 25 ]

Approach: The sorting requires visiting each element and then performing some operations, which requires for loop to visit those elements.
Now here, we can use setInterval() method to visit all those elements, and perform those operations.
The below code illustrates the above approach in JavaScript Language.
File Name: Index.js
const arr = [46, 55, 2, 100, 0, 500];const l = arr.length;var arr1 = [];var j = 0;  var myVar1 = setInterval(myTimer1, 1);  function myTimer1() {   const min = Math.min.apply(null, arr);   arr1.push(min);     // arr[arr.indexOf(min)]=Math.max.apply(null, arr);   arr.splice(arr.indexOf(min), 1);   j++;        if(j == l){     clearInterval(myVar1);         console.log(arr1);   }}
Run Index.js file either on the online compiler or follow the following:
node index.js
Output:
[0, 2, 46, 55, 100, 500]

[0, 2, 46, 55, 100, 500]

Node.js-Misc
JavaScript
Node.js
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Difference between var, let and const keywords in JavaScript
Difference Between PUT and PATCH Request
JavaScript | Promises
How to get character array from string in JavaScript?
Installation of Node.js on Linux
How to update Node.js and NPM to next version ?
Node.js fs.readFileSync() Method
Node.js fs.writeFile() Method
Node.js fs.readFile() Method
React-Bootstrap Spinner Component - GeeksforGeeks

30 Apr, 2021
React-Bootstrap is a front-end framework that was designed keeping react in mind. Spinner Component provides a way to show the loading effect. We can use it to show the loading state, whenever required in our application. We can use the following approach in ReactJS to use the react-bootstrap Spinner Component.
Spinner Props:
animation: It is used to define the type of animation for the spinner.
as: It can be used as a custom element type for this component.
children: It is used to wrap child elements or components, this component can be used.
role: In the menu component, it is the ARIA accessible role applied to it.
size: It is used to define the size of the component.
variant: It is used to define the visual style of our spinner component.
bsPrefix: It is an escape hatch for working with strongly customized bootstrap CSS.
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:npx create-react-app foldername
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 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 required module using the following command:npm install react-bootstrap 
npm install bootstrap
Step 3: After creating the ReactJS application, Install the required module using the following command:
npm install react-bootstrap 
npm install bootstrap
Project Structure: It will look like the following.
Project Structure
Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
App.js
import React from 'react';import 'bootstrap/dist/css/bootstrap.css';import Spinner from 'react-bootstrap/Spinner';  export default function App() {  return (    <div style={{ display: 'block', width: 700, padding: 30 }}>      <h4>React-Bootstrap Spinner Component</h4>      With Border Animation:       <Spinner animation="border" variant="primary" /> <br/>      With Grow Animation:      <Spinner animation="grow" variant="warning" />    </div>  );}
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:
Reference: https://react-bootstrap.github.io/components/spinners/
React-Bootstrap
ReactJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
ReactJS useNavigate() Hook
How to set background images in ReactJS ?
Axios in React: A Guide for Beginners
How to create a table in ReactJS ?
How to navigate on path by button click in react router ?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
Difference between var, let and const keywords in JavaScript
DoubleAdder reset() method in Java with Examples - GeeksforGeeks

28 Jan, 2019
The java.DoubleAdder.reset() is an inbuilt method in java that resets variables maintaining the sum to zero. When the object of the class is created its initial value is zero.
Syntax:
public void reset()

Parameters: This method does not accepts any parameter.
Return Value: The method returns the reset value.
Below programs illustrate the above method:
Program 1:
// Program to demonstrate the reset() method  import java.lang.*;import java.util.concurrent.atomic.DoubleAdder;  public class GFG {    public static void main(String args[])    {        DoubleAdder num = new DoubleAdder();          // add operation on num        num.add(42);        num.add(10);          // reset operation on variable num        num.reset();          // Print after add operation        System.out.println(" the current value is: " + num);    }}
the current value is: 0.0

Program 2:
// Program to demonstrate the reset() method  import java.lang.*;import java.util.concurrent.atomic.DoubleAdder;  public class GFG {    public static void main(String args[])    {        DoubleAdder num = new DoubleAdder();          // add operation on num        num.add(10);          // reset operation on variable num        num.reset();          // Print after add operation        System.out.println(" the current value is: " + num);    }}
the current value is: 0.0

Reference: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/DoubleAdder.html#reset–
Java-DoubleAdder
Java-Functions
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Object Oriented Programming (OOPs) Concept in Java
HashMap in Java with Examples
Interfaces in Java
Stream In Java
How to iterate any Map in Java
ArrayList in Java
Initialize an ArrayList in Java
Stack Class in Java
Multidimensional Arrays in Java
Singleton Class in Java
Python | Vowel indices in String - GeeksforGeeks

22 Apr, 2020
Sometimes, while working with Python Strings, we can have a problem in which we need to extract indices of vowels in it. This kind of application is common in day-day programming. Lets discuss certain ways in which this task can be performed.
Method #1 : Using loopThis is one way in which this task can be performed. In this we use brute force to perform this task. In this we iterate for each string element and test for vowel.
# Python3 code to demonstrate working of # Vowel indices in String# Using loop  # initializing stringtest_str = "geeksforgeeks"  # printing original stringprint("The original string is : " + test_str)  # Vowel indices in String# Using loopres = []for ele in range(len(test_str)):    if test_str[ele] in "aeiou":       res.append(ele)  # printing result print("The vowel indices are : " + str(res)) 
The original string is : geeksforgeeks
The vowel indices are : [1, 2, 6, 9, 10]

 
Method #2 : Using enumerate() + list comprehensionThe combination of above methods can also be used to perform this task. In this, we access the index using enumerate() and list comprehension is used to check for vowels.
# Python3 code to demonstrate working of # Vowel indices in String# Using list comprehension + enumerate()  # initializing stringtest_str = "geeksforgeeks"  # printing original stringprint("The original string is : " + test_str)  # Vowel indices in String# Using list comprehension + enumerate()res = [idx for idx, ele in enumerate(test_str) if ele in "aeiou"]  # printing result print("The vowel indices are : " + str(res)) 
The original string is : geeksforgeeks
The vowel indices are : [1, 2, 6, 9, 10]

Python string-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
How to drop one or multiple columns in Pandas Dataframe
Python Classes and Objects
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Split string into list of characters
Python | Convert a list to dictionary
How to print without newline in Python?
How to get the count of each distinct value in a column in MySQL?

Let us see an example to get the count of each distinct value in a column. Firstly, we will create a table.
The CREATE command is used to create a table.
mysql> create table DistinctDemo1
   - > (
   - > id int,
   - > name varchar(100)
   - > );
Query OK, 0 rows affected (0.43 sec)
mysql> insert into DistinctDemo1 values(1,'John');
Query OK, 1 row affected (0.34 sec)

mysql> insert into DistinctDemo1 values(2,'John');
Query OK, 1 row affected (0.20 sec)

mysql> insert into DistinctDemo1 values(3,'John');
Query OK, 1 row affected (0.09 sec)

mysql> insert into DistinctDemo1 values(4,'Carol');
Query OK, 1 row affected (0.17 sec)

mysql> insert into DistinctDemo1 values(5,'David');
Query OK, 1 row affected (0.12 sec)
mysql> select *from DistinctDemo1;
The following is the output that displays all the records.
+------+-------+
| id   | name  |
+------+-------+
|    1 | John  |
|    2 | John  |
|    3 | John  |
|    4 | Carol |
|    5 | David |
+------+-------+
5 rows in set (0.00 sec)

The following is the syntax to get the count.
mysql> SELECT name,COUNT(1) as OccurenceValue FROM DistinctDemo1 GROUP BY name ORDER BY OccurenceValue;
Here is the output.
+-------+----------------+
| name  | OccurenceValue |
+-------+----------------+
| Carol |              1 |
| David |              1 |
| John  |              3 |
+-------+----------------+
3 rows in set (0.04 sec)
Tensorflow.js tf.argMax() Function - GeeksforGeeks

18 May, 2021
Tensorflow.js is an open-source library developed by Google for running machine learning models and deep learning neural networks in the browser or node environment.
The tf.argMax() function is used to return the indices for the maximum values of the specified Tensor along an axis.
The output result has the same shape as input with the dimension along the axis removed.
Syntax:
tf.argMax (x, axis)
Parameters: This function accepts two parameters which are illustrated below:
x: The input tensor.
axis: The specified dimension(s) to reduce. It is an optional parameter and its default value is 0.
Return Value: It returns a Tensor of the indices of the maximum values along an axis.
Example 1:
Javascript
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs"  // Initializing a some tensors const a = tf.tensor1d([1, 0]);const b = tf.tensor1d([3, 5]);const c = tf.tensor1d([6, 3, 5, 12]);  // Calling the .argMax() function over // the above tensorsa.argMax().print();b.argMax().print();c.argMax().print();
Output:
Tensor
   0
Tensor
   1
Tensor
   3
Example 2:
Javascript
// Importing the tensorflow.js libraryimport * as tf from "@tensorflow/tfjs"  // Initializing a some tensors const a = tf.tensor1d([0, 1]);const b = tf.tensor2d([9, 5, 2, 8], [2, 2]);const c = tf.tensor1d([6, 4, 7]);  // Initializing a axis parametersconst axis1 = -1;const axis2 = -2;const axis3 = 0;  // Calling the .argMax() function over // the above tensorsa.argMax(axis1).print();b.argMax(axis2).print();c.argMax(axis3).print();
Output:
Tensor
   1
Tensor
   [0, 1]
Tensor
   2
Reference: https://js.tensorflow.org/api/latest/#argMax
Tensorflow
Tensorflow.js
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Difference between var, let and const keywords in JavaScript
Difference Between PUT and PATCH Request
JavaScript | Promises
How to get character array from string in JavaScript?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Difference between var, let and const keywords in JavaScript
array::begin() and array::end() in C++ STL - GeeksforGeeks

10 Feb, 2021
Array classes are generally more efficient, light-weight and reliable than C-style arrays. The introduction of array class from C++11 has offered a better alternative for C-style arrays.
begin() function is used to return an iterator pointing to the first element of the array container. begin() function returns a bidirectional iterator to the first element of the container.Syntax : 
arrayname.begin()
Parameters :
No parameters are passed.

Returns :
This function returns a bidirectional
iterator pointing to the first element.
Examples:  
Input  : myarray{1, 2, 3, 4, 5};
Output : returns an iterator to the element 1

Input  : myarray{8, 7};         
Output : returns an iterator to the element 8
Errors and Exceptions1. It has a no exception throw guarantee. 2. Shows error when a parameter is passed. 
CPP
// CPP program to illustrate// Implementation of begin() function#include <array>#include <iostream>using namespace std; int main(){    // declaration of array container    array<int, 5> myarray{ 1, 2, 3, 4, 5 };     // using begin() to print array    for (auto it = myarray.begin();         it != myarray.end(); ++it)        cout << ' ' << *it;     return 0;}
Output: 
1 2 3 4 5
end() returns an iterator pointing to the past-the-end element in the array container. Syntax :  
arrayname.end()
Parameters :
No parameters are passed.

Returns :
This function returns a bidirectional
iterator pointing to the past-the-end element.
Examples:  
Input  : myarray{1, 2, 3, 4, 5};
Output : returns an iterator to the element next to 5 i.e,. some garbage value

Input  : myarray{8, 7};
Output : returns an iterator to the element next to 7 i.e,. some garbage value
Errors and Exceptions1. It has a no exception throw guarantee. 2. Shows error when a parameter is passed. 
CPP
// CPP program to illustrate// Implementation of end() function#include <array>#include <iostream>using namespace std; int main(){    // declaration of array container    array<int, 5> myarray{ 1, 2, 3, 4, 5 };     // using end() to print array    for (auto it = myarray.begin();         it != myarray.end(); ++it)        cout << ' ' << *it;             auto it = myarray.end();      cout << "\n myarray.end(): " << *it << " [some garbage value]";    return 0;}
Output: 
1 2 3 4 5
myarray.end(): 0 [some garbage value]
klynsaha
cpp-array
STL
C++
STL
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Operator Overloading in C++
Polymorphism in C++
Friend class and function in C++
Sorting a vector in C++
std::string class in C++
Pair in C++ Standard Template Library (STL)
Inline Functions in C++
Queue in C++ Standard Template Library (STL)
Array of Strings in C++ (5 Different Ways to Create)
Convert string to char array in C++
File opening modes(r versus r+) - GeeksforGeeks

14 Aug, 2019
A file has to be opened before the beginning of reading and writing operations. Opening a file creates a link between the operating system and the file function.
Syntax for opening a file:
  FILE *fp;
  fp = fopen( " filename with extension ", " mode " );
Opening of file in detail:FILE: structure defined in stdio.h header file. FILE structure provides us the necessary information about a FILE.fp: file pointer which contains the address of the structure FILE.fopen(): this function will open file with name “filename” in specified “mode”.
Different reading modes:
rr+for binary files: rb, rb+, r+b
r
r+
for binary files: rb, rb+, r+b
Difference:
C program for opening file in r mode:
#include <stdio.h>  void main(){    FILE* fp;    char ch;    // Open file in Read mode    fp = fopen("INPUT.txt", "r+");      // data in file: geeksforgeeks      while (1) {        ch = fgetc(fp); // Read a Character        if (ch == EOF) // Check for End of File            break;          printf("%c", ch);    }    fclose(fp); // Close File after Reading}
Output:
geeksforgeeks
Note: File opened should be closed in the program after processing.
C program for opening file in r+ mode:
#include <stdio.h>  void main(){    FILE* fp;    char ch;    // Open file in Read mode    fp = fopen("INPUT.txt", "r+");      // content of the file:geeksforgeeks      while (1) {        ch = fgetc(fp); // Read a Character        if (ch == EOF) // Check for End of File            break;          printf("%c", ch);    }    fprintf(fp, " online reference.");      fclose(fp); // Close File after Reading      // content of the file: geeksforgeeks online reference.      fp = fopen("INPUT.txt", "r+"); // Open file in r + mode    while (1) {        ch = fgetc(fp); // Read a Character        if (ch == EOF) // Check for End of File            break;          printf("%c", ch);    }    fclose(fp);}
Output:
geeksforgeeks online reference
rishiSingh2
File Handling
C Programs
File Handling
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C Program to read contents of Whole File
Producer Consumer Problem in C
Exit codes in C/C++ with Examples
C program to find the length of a string
Handling multiple clients on server with multithreading using Socket Programming in C/C++
C / C++ Program for Dijkstra's shortest path algorithm | Greedy Algo-7
Regular expressions in C
Create n-child process from same parent process using fork() in C
Conditional wait and signal in multi-threading
How to store words in an array in C?
How to divide a polynomial to another using NumPy in Python? - GeeksforGeeks

29 Aug, 2020
In this article, we will make a NumPy program to divide one polynomial to another. Two polynomials are given as input and the result is the quotient and remainder of the division.
The polynomial p(x) = C3 x2 + C2 x + C1  is represented in NumPy as : ( C1, C2, C3 ) { the coefficients (constants)}.
Let take two polynomials p(x) and g(x) then divide these to get quotient q(x) = p(x) // g(x) and  remainder r(x) = p(x) % g(x) as a result.
If p(x) = A3 x2 + A2 x + A1
and 
g(x) = B3 x2 + B2 x + B1 

then result is 
q(x) = p(x) // g(x) and r(x) = p(x) % g(x)

and the output is coefficientes of remainder and
 the coefficientes of quotient.

This can be calculated using the polydiv() method. This method evaluates the division of two polynomials and returns the quotient and remainder of the polynomial division.
Syntax:
numpy.polydiv(p1, p2)
Below is the implementation with some examples :
Example 1 :  
Python3
# importing packageimport numpy  # define the polynomials# p(x) = 5(x**2) + (-2)x +5px = (5, -2, 5)  # g(x) = x +2gx = (2, 1, 0)  # divide the polynomialsqx, rx = numpy.polynomial.polynomial.polydiv(px, gx)  # print the result# quotiientprint(qx)  # remainderprint(rx)
Output :
[-12.   5.]
[ 29.]
Example 2 : 
Python3
# importing packageimport numpy  # define the polynomials# p(x) = (x**2) + 3x + 2px = (1,3,2)  # g(x) = x + 1gx = (1,1,0)  # divide the polynomialsqx,rx = numpy.polynomial.polynomial.polydiv(px,gx)  # print the result# quotiientprint(qx)  # remainderprint(rx)
Output :
[ 1.  2.]
[ 0.]

Python numpy-Mathematical Function
Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
How to drop one or multiple columns in Pandas Dataframe
Python Classes and Objects
Python | os.path.join() method
Python | Get unique values from a list
Create a directory in Python
Defaultdict in Python
Python | Pandas dataframe.groupby()