code-rag-bench/online-tutorials huggingface dataset:
<mat-radio-button> in Angular Material - GeeksforGeeks

06 Oct, 2021
Angular Material is a UI component library that is developed by the Angular team to build design components for desktop and mobile web applications. In order to install it, we need to have angular installed in our project, once you have it you can enter the below command and can download it. <mat-radio-button> is used to select one option when we have multiple options.
Installation syntax:
ng add @angular/material
Approach:
First, install the angular material using the above-mentioned command.
After completing the installation, Import ‘MatRadioModule’ from ‘@angular/material/radio’ in the app.module.ts file.
Then we need to use the <mat-radio-button> tag for displaying the radio button.
We can also disable the radio button by using the disabled input property.
If we want to change the theme then we can change it by using the color property. In angular we have 3 themes, they are primary, accent, and warn.
Once done with the above steps then serve or start the project.
Project Structure: It will look like the following:
Filename: app.module.ts
Javascript
import { NgModule } from '@angular/core';import { BrowserModule } from '@angular/platform-browser';import { FormsModule } from '@angular/forms'; import { MatRadioModule } from '@angular/material/radio';import { AppComponent } from './app.component';import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; @NgModule({  imports:  [    BrowserModule,    FormsModule,    MatRadioModule,    BrowserAnimationsModule  ],  declarations: [ AppComponent ],  bootstrap: [ AppComponent ]}) export class AppModule { }
Filename: app.component.html
HTML
<h3> Radio buttons in Angular material </h3> <mat-radio-button value="1" color="primary">  Primary Theme radio button</mat-radio-button><br><br> <mat-radio-button value="2" color="warn">  Warn Theme Radio button</mat-radio-button><br><br> <mat-radio-button value="3" color="accent">  Accent Theme Radio button</mat-radio-button> <br><br> <mat-radio-button value="4" color="accent" disabled>  Disabled Radio Button</mat-radio-button>
Output:
 
prachisoda1234
Angular-material
AngularJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Angular PrimeNG Dropdown Component
Angular PrimeNG Calendar Component
Angular PrimeNG Messages Component
Angular 10 (blur) Event
How to make a Bootstrap Modal Popup in Angular 9/8 ?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Disable the underlying window when a popup is created in Python TKinter

We are familiar with popup and used it in many applications. Popup in a tkinter application can be created by creating an instance of Toplevel(root) window. For a particular application, we can trigger the popup on a button object.
Let us create a Python script to close the underlying or the main window after displaying the popup. We can close the main window while residing in a popup window by using the withdraw() method.
Through this example, we will create a popup dialog that can be triggered after clicking a button. Once the popup will open, the parent window will close automatically.
#Import the required library
from tkinter import*
#Create an instance of tkinter frame
win= Tk()
#Define geometry of the window
win.geometry("750x250")
#Define a function to close the popup window
def close_win(top):
   top.destroy()
   win.destroy()
#Define a function to open the Popup Dialogue
def popupwin():
   #withdraw the main window
   win.withdraw()
   #Create a Toplevel window
   top= Toplevel(win)
   top.geometry("750x250")
   #Create an Entry Widget in the Toplevel window
   entry= Entry(top, width= 25)
   entry.insert(INSERT, "Enter Your Email ID")
   entry.pack()
   #Create a Button Widget in the Toplevel Window
   button= Button(top, text="Ok", command=lambda:close_win(top))
   button.pack(pady=5, side= TOP)
#Create a Label
label= Label(win, text="Click the Button to Open the Popup Dialogue", font= ('Helvetica 15 bold'))
label.pack(pady=20)
#Create a Button
button= Button(win, text= "Click Me!", command= popupwin, font= ('Helvetica 14 bold'))
button.pack(pady=20)
win.mainloop()
When we execute the above code snippet, it will display a window.
Now click the "Click Me" button. It will open a Popup window and close the parent window.
How to get return text from PHP file with ajax ? - GeeksforGeeks

06 Dec, 2021
In this article, we will see how to get return the text from the PHP file with ajax. Ajax is an acronym for Asynchronous JavaScript and XML is a series of web development techniques that build asynchronous web applications using many web technologies on the client-side. Without reloading the web page, AJAX enables you to send and receive information asynchronously.
Approach: When the button gets clicked, we have initialized the XMLHttpRequest object, which is responsible for making AJAX calls. Then, we have to check if the readyState value is 4, which means the request is completed, and we have got a response from the server.
Next, we have checked if the status code equals 200, which means the request was successful. Finally, we fetch the response which is stored in the responseText property of the XMLHttpRequest object. After setting up the listener, we initiate the request by calling the open method of the XMLHttpRequest object. Then call the send method of the XMLHttpRequest object, which actually sends the request to the server. When the server responds, you can see the text displaying the response from the PHP file.
Example: This example describes returning the text from PHP with AJAX.
HTML
<!DOCTYPE html><html>  <body>    <button type="button" id="fetchBtn">Click Me!</button>    <p id="txt"></p>            <script>    let fetchBtn = document.getElementById('fetchBtn');    fetchBtn.addEventListener('click', buttonClickHandler);      function buttonClickHandler() {                // Instantiate an xhr object        var xhr = new XMLHttpRequest();                // What to do when response is ready          xhr.onreadystatechange = () => {            if(xhr.readyState === 4) {                if(xhr.status === 200) {                    document.getElementById("txt").innerHTML =                     xhr.responseText;                } else {                    console.log('Error Code: ' + xhr.status);                    console.log('Error Message: ' + xhr.statusText);                }            }        }        xhr.open('GET', 'data.php');                // Send the request        xhr.send();    }    </script></body>  </html>
PHP code: The following is the code for the “data.php” file used in the above HTML code.
data.php
<html><body>   <?php echo '<h1>Welcome to GfG</h1>'; ?>  </body></html>
Output:
bhaskargeeksforgeeks
PHP-Questions
Picked
Technical Scripter 2020
HTML
JavaScript
PHP
PHP Programs
Technical Scripter
Web Technologies
HTML
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
REST API (Introduction)
HTML Cheat Sheet - A Basic Guide to HTML
Design a web page using HTML and CSS
Form validation using jQuery
Angular File Upload
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
How to calculate the number of days between two dates in javascript?
Python | Numpy matrix.reshape() - GeeksforGeeks

18 Apr, 2019
With the help of Numpy matrix.reshape() method, we are able to reshape the shape of the given matrix. Remember all elements should be covered after reshaping the given matrix.
Syntax : matrix.reshape(shape)
Return: new reshapped matrix
Example #1 :In the given example we are able to reshape the given matrix by using matrix.reshape() method.
# import the important module in pythonimport numpy as np           # make matrix with numpygfg = np.matrix('[64, 1; 12, 3]')           # applying matrix.reshape() methodgeeks = gfg.reshape((1, 4))     print(geeks)
[[64  1 12  3]]

Example #2 :
# import the important module in pythonimport numpy as np           # make a matrix with numpygfg = np.matrix('[1, 2; 4, 5; 7, 8]')           # applying matrix.reshape() methodgeeks = gfg.reshape((2, 3))     print(geeks)
[[1 2 4]
 [5 7 8]]

Python numpy-Matrix Function
Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Iterate over a list in Python
Python String | replace()
*args and **kwargs in Python
Reading and Writing to text files in Python
Create a Pandas DataFrame from Lists
Python Slicing | Reverse an array in groups of given size - GeeksforGeeks

11 May, 2020
Given an array, reverse every sub-array formed by consecutive k elements.
Examples:
Input: 
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9]
k = 3
Output:  
[3, 2, 1, 6, 5, 4, 9, 8, 7]

Input: 
arr = [1, 2, 3, 4, 5, 6, 7, 8]
k = 5
Output:  
[5, 4, 3, 2, 1, 8, 7, 6]

Input: 
arr = [1, 2, 3, 4, 5, 6]
k = 1
Output:  
[1, 2, 3, 4, 5, 6]

Input: 
arr = [1, 2, 3, 4, 5, 6, 7, 8]
k = 10
Output:  
[8, 7, 6, 5, 4, 3, 2, 1]

We have existing solution for this problem please refer Reverse an array in groups of given size link. We can solve this problem quickly in Python using list slicing and reversed() function.Below example will give you better understanding of approach.
Example:
# function to Reverse an array in groups of given size  def reverseGroup(input,k):      # set starting index at 0    start = 0      # run a while loop len(input)/k times    # because there will be len(input)/k number     # of groups of size k     result = []    while (start<len(input)):             # if length of group is less than k           # that means we are left with only last            # group reverse remaining elements            if len(input[start:])<k:                result = result + list(reversed(input[start:]))                break             # select current group of size of k           # reverse it and concatenate            result = result + list(reversed(input[start:start + k]))           start = start + k    print(result)  # Driver programif __name__ == "__main__":    input = [1, 2, 3, 4, 5, 6, 7, 8]    k = 5    reverseGroup(input,k)
[5, 4, 3, 2, 1, 8, 7, 6]

Using Direct Function
# function to Reverse an array in groups of given size   def reverseGroup(a, k):     # take an empty list   res = []     # iterate over the list with increment of    # k times in each iteration   for i in range(0, len(a), k):              # reverse the list in each iteration over        # span of k elements using extend       res.extend((a[i:i + k])[::-1])   print(res)   # Driver programif __name__ == "__main__":    input = [1, 2, 3, 4, 5, 6, 7, 8]    k = 5    reverseGroup(input, k)
[5, 4, 3, 2, 1, 8, 7, 6]

nikhilk26
Python list-programs
python-list
Python
python-list
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Python String | replace()
*args and **kwargs in Python
Create a Pandas DataFrame from Lists
Check if element exists in list in Python
Convert integer to string in Python
How To Convert Python Dictionary To JSON?
sum() function in Python
Vulscan - Vulnerability Scanning with Nmap in Kali Linux - GeeksforGeeks

07 Oct, 2021
Vulscan is a free and open-source tool available on GitHub. Vulscan uses nmap as the main scanner to scan the IP addresses and domains, the easiest and useful tool for reconnaissance of network. Vulscan interface is very similar to Metasploit 1 and Metasploit 2 which makes it easy to use. This tool provides a command-line interface that you can run on the Kali Linux terminal in order to scan hosts and domains. This tool can be used to get information about our target(domain) which can be a website or an IP address or a domain. The interactive console provides a number of helpful features, such as command completion and contextual help. Vulscan is a web reconnaissance tool that uses NSE script. Vulscan has NSE scripts that give additional features to nmap to detect and find vulnerabilities and further which can be used to perform exploitation.  Nse scripts have many modules such as network discovery and backdoor detection. It has so many modules such as database interaction, built-in convenience functions, interactive help, and command completion. Vulscan provides a powerful environment in which open source web-based reconnaissance can be conducted and you can gather all information about the target.
Step 1: Use the following command to install the tool in your kali Linux operating system.
git clone https://github.com/scipag/vulscan scipag_vulscan
ln -s `pwd`/scipag_vulscan /usr/share/nmap/scripts/vulscan    
Step 2: Now use the following command to move into the directory of the tool. Use the second command to list out the contents of the tool
cd scipag_vulscan
ls
The tool has been downloaded and installed successfully now we will see an example to use the tool.
nmap -sV --script=vulscan/vulscan.nse <domain>
This tool automates the nmap vulnerability scanner using NSE scripts.
sweetyty
Kali-Linux
Linux-Tools
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
scp command in Linux with Examples
Docker - COPY Instruction
mv command in Linux with examples
SED command in Linux | Set 2
chown command in Linux with Examples
nohup Command in Linux with Examples
Thread functions in C/C++
Named Pipe or FIFO with example C program
uniq Command in LINUX with examples
Start/Stop/Restart Services Using Systemctl in Linux
GATE | GATE CS 2011 | Question 65 - GeeksforGeeks

30 Sep, 2021
Consider an instruction pipeline with four stages (S1, S2, S3 and S4) each with combinational circuit only. The pipeline registers are required between each stage and at the end of the last stage. Delays for the stages and for the pipeline registers are as given in the figure:
What is the approximate speed up of the pipeline in steady state under ideal conditions when compared to the corresponding non-pipeline implementation?(A) 4.0(B) 2.5(C) 1.1(D) 3.0Answer: (B)Explanation:
Pipeline registers overhead is not counted in normal 
time execution

So the total count will be

5+6+11+8= 30 [without pipeline]

Now, for pipeline, each stage will be of 11 n-sec (+ 1 n-sec for overhead).
and, in steady state output is produced after every pipeline cycle. Here,
in this case 11 n-sec. After adding 1n-sec overhead, We will get 12 n-sec
of constant output producing cycle.

dividing 30/12 we get 2.5 
YouTubeGeeksforGeeks GATE Computer Science16.4K subscribersPrevious Year Questions Pipelining | COA | GeeksforGeeks GATE | Harshit NigamWatch laterShareCopy linkInfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.You're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmMore videosMore videosSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:0025:57 / 57:56•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=i9nHxd-NCdg" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>Quiz of this Question
GATE-CS-2011
GATE-GATE CS 2011
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | Gate IT 2007 | Question 25
GATE | GATE-CS-2000 | Question 41
GATE | GATE-CS-2001 | Question 39
GATE | GATE-CS-2005 | Question 6
GATE | GATE MOCK 2017 | Question 21
GATE | GATE-CS-2006 | Question 47
GATE | GATE MOCK 2017 | Question 24
GATE | Gate IT 2008 | Question 43
GATE | GATE-CS-2009 | Question 38
GATE | GATE-CS-2003 | Question 90
numpy.random.shuffle() in python - GeeksforGeeks

18 Aug, 2020
With the help of numpy.random.shuffle() method, we can get the random positioning of different integer values in the numpy array or we can say that all the values in an array will be shuffled randomly.
Syntax : numpy.random.shuffle(x)
Return : Return the reshuffled numpy array.
Example #1 :
In this example we can see that by using numpy.random.shuffle() method, we are able to do the reshuffling of values in the numpy array or change the positions of values in an array.
Python3
# import numpyimport numpy as npimport matplotlib.pyplot as plt  gfg = np.arange(10)# Using shuffle() methodnp.random.shuffle(gfg)  print(gfg)
Output :
[7 1 5 0 8 4 3 9 6 2]
Example #2 :
Python3
# import numpyimport numpy as npimport matplotlib.pyplot as plt  gfg = np.arange(16).reshape((4, 4))# Using shuffle() methodnp.random.shuffle(gfg)  print(gfg)
Output :
[[ 4  5  6  7]
[ 0  1  2  3]
[ 8  9 10 11]
[12 13 14 15]]
Python numpy-Random
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 | Get unique values from a list
Python | os.path.join() method
Create a directory in Python
Defaultdict in Python
Python | Pandas dataframe.groupby()
How to install NumPy package in Julia? - GeeksforGeeks

17 May, 2020
Julia is a very new and fast high-level programming language and has the power to compete with python. Like python, Julia is also compatible to do machine learning and data analysis part. In this tutorial, we will learn about how to install NumPy and use it in our Julia environment.
Before we begin with the installation of Julia, it is good to check if it might be already installed on your system. To check if your device is preinstalled with Julia or not, just go to the Command line(search for cmd in the Run dialog( + R)).Now run the following command:
julia
If Julia is not installed, please follow the steps on How to Install Julia on Windows?
Follow these steps to make use of libraries like NumPy in Julia:
Step 1: Use the Using Pkg command to install the external packages in Julia.
using Pkg
Step 2: Add the PyCall package to install the required python modules in julia and to do so use the command given below:
Pkg.add("PyCall")
Step 3: In this step, we have to use the PyCall package and for that use the following command:
using PyCall
Step 4: And Here we go, this is the final statement which we use to complete the setup for numpy.
np = pyimport("numpy")
Python-numpy
How To
Julia
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Align Text in HTML?
How to filter object array based on attributes?
Java Tutorial
How to Install FFmpeg on Windows?
How to Install Anaconda on Windows?
Vectors in Julia
Printing Output on Screen in Julia
String concatenation in Julia
Getting rounded value of a number in Julia - round() Method
Decision Making in Julia (if, if-else, Nested-if, if-elseif-else ladder)
Dart – Loops

01 Feb, 2021
Looping statement in Dart or any other programming language is used to repeat a certain set of commands until certain conditions are not completed. There are different ways to do so. They are:  
for loop
for... in loop
for each loop
while loop
do-while loop
For loop in Dart is similar to that in Java and also the flow of execution is the same as that in Java.Syntax: 
 for(initialization; condition; test expression){
    // Body of the loop
}
Control flow goes as: 
initializationConditionBody of loopTest expression
initialization
Condition
Body of loop
Test expression
The first is executed only once i.e in the beginning while the other three are executed until the condition turns out to be false.Example:  
Dart
// Printing GeeksForGeeks 5 timesvoid main(){    for (int i = 0; i < 5; i++) {        print('GeeksForGeeks');    }}
Output:  
GeeksForGeeks
GeeksForGeeks
GeeksForGeeks
GeeksForGeeks
GeeksForGeeks
 
For...in loop in Dart takes an expression or object as an iterator. It is similar to that in Java and its flow of execution is also the same as that in Java. 
Syntax: 
 for (var in expression) {
   // Body of loop
}
Example:  
Dart
void main(){    var GeeksForGeeks = [ 1, 2, 3, 4, 5 ];    for (int i in GeeksForGeeks) {        print(i);    }}
Output:  
1
2
3
4
5
The for-each loop iterates over all elements in some container/collectible and passes the elements to some specific function.
Syntax:
 collection.foreach(void f(value))
Parameters:
f( value): It is used to make a call to the f function for each element in the collection.
Dart
void main() {  var GeeksForGeeks = [1,2,3,4,5];  GeeksForGeeks.forEach((var num)=> print(num));}
Output:
1
2
3
4
5
The body of the loop will run until and unless the condition is true. 
Syntax: 
 while(condition){
    text expression;
    // Body of loop
}
Example:  
Dart
void main(){    var GeeksForGeeks = 4;    int i = 1;    while (i <= GeeksForGeeks) {        print('Hello Geek');        i++;    }}
Output:  
Hello Geek
Hello Geek
Hello Geek
Hello Geek
 
The body of the loop will be executed first and then the condition is tested. 
Syntax: 
 do{
    text expression;
    // Body of loop
}while(condition);
Example:  
Dart
void main(){    var GeeksForGeeks = 4;    int i = 1;    do {        print('Hello Geek');        i++;    } while (i <= GeeksForGeeks);}
Output:  
Hello Geek
Hello Geek
Hello Geek
Hello Geek
 
vermaaayush68
Dart Loops
Dart
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to convert IEnumerable to List and List back to IEnumerable in C#?

IEnumerable is an interface defining a single method GetEnumerator() that returns an IEnumerator interface. It is the base interface for all non-generic collections that can be enumerated.
This works for read-only access to a collection that implements that IEnumerable can be used with a foreach statement.
List class represents the list of objects which can be accessed by index. It comes under the System.Collection.Generic namespace.
List class can be used to create a collection of different types like integers, strings etc. List class also provides the methods to search, sort, and manipulate lists.
static void Main(string[] args) {
   List list = new List();
   IEnumerable enumerable = Enumerable.Range(1, 5);

   foreach (var item in enumerable) {
      list.Add(item);
   }
   foreach (var item in list) {
      Console.WriteLine(item);
   }
   Console.ReadLine();
}
1
2
3
4
5
convert List to IEnumerable
static void Main(string[] args) {
   List list = new List();
   IEnumerable enumerable = Enumerable.Range(1, 5);

   foreach (var item in enumerable) {
      list.Add(item);
   }
   foreach (var item in list) {
      Console.WriteLine(item);
   }
   IEnumerable enumerableAfterConversion= list.AsEnumerable();
   foreach (var item in enumerableAfterConversion) {
      Console.WriteLine(item);
   }
   Console.ReadLine();
}
1
2
3
4
5
1
2
3
4
5
Python | Pandas DatetimeIndex.day_name()

29 Dec, 2018
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas DatetimeIndex.day_name() function return the day names of the DateTimeIndex with specified locale. The default locale is None in which case the names are returned in English language.
Syntax: DatetimeIndex.day_name(locale=None)
Parameters :locale : locale determining the language in which to return the day name
Return : Index of day names
Example #1: Use DatetimeIndex.day_name() function to return the names of the day for each entry in the DatetimeIndex object. Return the names of the days in French locale
# importing pandas as pdimport pandas as pd  # Create the DatetimeIndex# Here 'Q' represents quarterly frequency didx = pd.DatetimeIndex(start ='2018-11-15 09:45:10', freq ='Q', periods = 5)  # Print the DatetimeIndexprint(didx)
Output :
Now we want to return the names of the days in French locale.
# return the names of the days in Frenchdidx.day_name(locale ='French')
Output :As we can see in the output, the function has returned an Index object containing the names of the days in French.
Let’s return the name of the days in English
# return the names of the days in Englishdidx.day_name(locale ='English')
Output : Example #2: Use DatetimeIndex.day_name() function to return the names of the day for each entry in the DatetimeIndex object. Return the names of the day in German locale
# importing pandas as pdimport pandas as pd  # Create the DatetimeIndex# Here 'M' represents monthly frequency didx = pd.DatetimeIndex(start ='2015-03-02', freq ='M', periods = 5)  # Print the DatetimeIndexprint(didx)
Output :
Now we want to return the names of the days in German locale.
# return the names of the days in Germandidx.day_name(locale ='German')
Output :As we can see in the output, the function has returned an Index object containing the names of the day in German locale.
Python pandas-datetimeIndex
Python-pandas
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
Convert integer to string in Python
Modulus function in C++ STL

14 Sep, 2018
Modulus function is used to return the value of the modulus between its two arguments. It works same as modulus operator works.
template  struct modulus : binary_function  
{
  T operator() (const T& x, const T& y) const 
  {
   return x%y;
  }
};

Member types:
Type of first argument
Type of second argument
Type of result returned by member operator
Note: We must include library ‘functional’ and ‘algorithm’ to use modulus and transform.
Bewlo programs illustrate the working of modulus function:
// C++ program to implement modulus function#include <algorithm> // transform#include <functional> // modulus, bind2nd#include <iostream> // coutusing namespace std;  int main(){    // defining the array    int array[] = { 8, 6, 3, 4, 1 };      int remainders[5];      // transform function that helps to apply    // modulus between the arguments    transform(array, array + 5, remainders,              bind2nd(modulus<int>(), 2));      for (int i = 0; i < 5; i++)        // printing the results while checking        // whether no. is even or odd        cout << array[i] << " is a "             << (remainders[i] == 0 ? "even" : "odd")             << endl;      return 0;}
8 is a even
6 is a even
3 is a odd
4 is a even
1 is a odd

// C++ program to implement modulus function#include <algorithm> // transform#include <functional> // modulus, bind2nd#include <iostream> // cout#include <iterator>#include <vector>using namespace std;  int main(){      // Create a std::vector with elements    // {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}    vector<int> v;    for (int i = 0; i < 10; ++i)        v.push_back(i);      // Perform a modulus of two on every element    transform(v.begin(), v.end(), v.begin(),              bind2nd(modulus<int>(), 2));      // Display the vector    copy(v.begin(), v.end(),         ostream_iterator<int>(cout, " "));    cout << endl;      return 0;}
0 1 0 1 0 1 0 1 0 1

CPP-Functions
cpp-template
STL
C++
STL
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Sorting a vector in C++
Polymorphism in C++
Friend class and function in C++
Pair in C++ Standard Template Library (STL)
std::string class in C++
Queue in C++ Standard Template Library (STL)
Unordered Sets in C++ Standard Template Library
std::find in C++
List in C++ Standard Template Library (STL)
Inline Functions in C++
numpy.ceil() in Python

04 Dec, 2020
The numpy.ceil() is a mathematical function that returns the ceil of the elements of array. The ceil of the scalar x is the smallest integer i, such that i >= x
Syntax : numpy.ceil(x[, out]) = ufunc ‘ceil’)Parameters :a : [array_like] Input array
Return : The ceil of each element with float data-type.
 Code #1 : Working
# Python program explaining# ceil() functionimport numpy as np  in_array = [.5, 1.5, 2.5, 3.5, 4.5, 10.1]print ("Input array : \n", in_array)  ceiloff_values = np.ceil(in_array)print ("\nRounded values : \n", ceiloff_values)    in_array = [.53, 1.54, .71]print ("\nInput array : \n", in_array)  ceiloff_values = np.ceil(in_array)print ("\nRounded values : \n", ceiloff_values)  in_array = [.5538, 1.33354, .71445]print ("\nInput array : \n", in_array)  ceiloff_values = np.ceil(in_array)print ("\nRounded values : \n", ceiloff_values)
Output :
Input array : 
 [0.5, 1.5, 2.5, 3.5, 4.5, 10.1]

Rounded values : 
 [  1.   2.   3.   4.   5.  11.]

Input array : 
 [0.53, 1.54, 0.71]

Rounded values : 
 [ 1.  2.  1.]

Input array : 
 [0.5538, 1.33354, 0.71445]

Rounded values : 
 [ 1.  2.  1.]

 
Code #2 : Working
# Python program explaining# ceil() functionimport numpy as np  in_array = [1.67, 4.5, 7, 9, 12]print ("Input array : \n", in_array)  ceiloff_values = np.ceil(in_array)print ("\nRounded values : \n", ceiloff_values)    in_array = [133.000, 344.54, 437.56, 44.9, 1.2]print ("\nInput array : \n", in_array)  ceiloff_values = np.ceil(in_array)print ("\nRounded values upto 2: \n", ceiloff_values)
Output :
Input array : 
 [1.67, 4.5, 7, 9, 12]

Rounded values : 
 [  2.   5.   7.   9.  12.]

Input array : 
 [133.0, 344.54, 437.56, 44.9, 1.2]

Rounded values upto 2: 
 [ 133.  345.  438.   45.    2.]
 References : https://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.ceil.html#numpy.ceil.
Python numpy-Mathematical Function
Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
DATEDIFF() Function in MySQL

25 Nov, 2020
DATEDIFF() function in MySQL is used to return the number of days between two specified date values. 
Syntax:
DATEDIFF(date1, date2)


Parameter: This function accepts two parameters as given below:
date1: First specified date
date2: Second specified date
Returns :
It returns the number of days between two specified date values.
Example 1 :
Getting the number of days between two specified date values where the date is specified in the format of YYYY-MM-DD. Here the date1 is greater than date2, so the return value is positive.
SELECT DATEDIFF("2020-11-20", "2020-11-1");  


Output :
19


Example 2:
Getting the number of days between two specified date values where the date is specified in the format of YYYY-MM-DD. Here the date1 is less than date2, so the return value is negative.
SELECT DATEDIFF("2020-11-12", "2020-11-19");  


Output:
-7


Example 3:
Getting the number of days between two specified date values where the date is specified in the format of YYYY-MM-DD HH-MM-SS. 
SELECT DATEDIFF("2020-11-20 09:34:21", "2020-11-17 09:34:21");  


Output:
3


Example 4:
Getting the number of days between two specified date values where the date is specified in the format of YYYY-MM-DD HH-MM-SS. Here time value does not matter as date1 and date2 are taken the same but time is different still the output is zero (0).
SELECT DATEDIFF("2020-11-20 09:34:21", "2020-11-20 08:11:23");  


Output:
0


mysql
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Update Multiple Columns in Single Update Statement in SQL?
SQL Interview Questions
SQL | Views
Difference between DELETE, DROP and TRUNCATE
Window functions in SQL
MySQL | Group_CONCAT() Function
SQL | GROUP BY
Difference between DDL and DML in DBMS
Difference between DELETE and TRUNCATE
SQL Correlated Subqueries
Python | Replace negative value with zero in numpy array

17 Oct, 2019
Given numpy array, the task is to replace negative value with zero in numpy array. Let’s see a few examples of this problem.
Method #1: Naive Method
# Python code to demonstrate# to replace negative value with 0import numpy as np  ini_array1 = np.array([1, 2, -3, 4, -5, -6])  # printing initial arraysprint("initial array", ini_array1)  # code to replace all negative value with 0ini_array1[ini_array1<0] = 0  # printing resultprint("New resulting array: ", ini_array1)
initial array [ 1  2 -3  4 -5 -6]
New resulting array:  [1 2 0 4 0 0]

 Method #2: Using np.where
# Python code to demonstrate# to replace negative values with 0import numpy as np  ini_array1 = np.array([1, 2, -3, 4, -5, -6])  # printing initial arraysprint("initial array", ini_array1)  # code to replace all negative value with 0result = np.where(ini_array1<0, 0, ini_array1)  # printing resultprint("New resulting array: ", result)
initial array [ 1  2 -3  4 -5 -6]
New resulting array:  [1 2 0 4 0 0]

 Method #3: Using np.clip
# Python code to demonstrate# to replace negative values with 0import numpy as np  # supposing maxx value array can holdmaxx = 1000  ini_array1 = np.array([1, 2, -3, 4, -5, -6])  # printing initial arraysprint("initial array", ini_array1)  # code to replace all negative value with 0result = np.clip(ini_array1, 0, 1000)  # printing resultprint("New resulting array: ", result)
initial array [ 1  2 -3  4 -5 -6]
New resulting array:  [1 2 0 4 0 0]

 Method #4: Comparing the given array with an array of zeros and write in the maximum value from the two arrays as the output.
# Python code to demonstrate# to replace negative values with 0import numpy as np   ini_array1 = np.array([1, 2, -3, 4, -5, -6])   # printing initial arraysprint("initial array", ini_array1)   # Creating a array of 0zero_array = np.zeros(ini_array1.shape, dtype=ini_array1.dtype)print("Zero array", zero_array)  # code to replace all negative value with 0ini_array2 = np.maximum(ini_array1, zero_array)  # printing resultprint("New resulting array: ", ini_array2)
initial array [ 1  2 -3  4 -5 -6]
Zero array [0 0 0 0 0 0]
New resulting array:  [1 2 0 4 0 0]

nikhilaggarwal3
Python numpy-program
Python-numpy
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Dart – Break Statement

15 Jul, 2020
The break statement in Dart inside any loop gives you a way to break or terminate the execution of the loop containing it, and hence transfers the execution to the next statement following the loop. It is always used with the if-else construct.
Syntax: break;

Example 1:
Dart
// Dart program in Dart to // illustrate Break statement void main(){  var count = 0;  print("GeeksforGeeks - Break Statement in Dart");      while(count<=10)  {    count++;    if(count == 5)    {      //break statement      break;     }          print("Inside loop ${count}");  }  print("Out of while Loop");}
Output:
In this above program, the variable count is initialized as 0. Then a while loop is executed as long as the variable count is less than 10.
Inside the while loop, the count variable is incremented by 1 with each iteration (count = count + 1). Next, we have an If statement that checks the variable count is equal to 5, if it returns TRUE causes loop to break or terminate, Within the loop, there is a cout statement that will execute with each iteration of the while loop until the loop breaks. Then, there is a final cout statement outside of the while loop.
Example 2:
Dart
// Dart program in Dart to // illustrate Break statement void main() {    var i = 1;    while(i<=10) {       if (i %  == 0) {          print("The first multiple of 2  between 1 and 10 is : ${i}");          break ;             // exit the loop if the          // first multiple is found       }       i++;    }}
Output:
The first multiple of 5 between 1 and 10 is: 2 

Dart Control-Flow
Dart
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
ListView Class in Flutter
Flutter - Search Bar
Flutter - Dialogs
Flutter - FutureBuilder Widget
Flutter - Flexible Widget
Flutter - Pop Up Menu
What is widgets in Flutter?
Android Studio Setup for Flutter Development
Flutter - CircleAvatar Widget
Flutter - RichText Widget
C# Enum TryParse() Method

The TryParse() method converts the string representation of one or more enumerated constants to an equivalent enumerated object.
Firstly, set an enum.
enum Vehicle { Bus = 2, Truck = 4, Car = 10 };
Now, let us declare a string array and set some values.
string[] VehicleList = { "2", "3", "4", "bus", "Truck", "CAR" };
Now parse the values accordingly using Enum TryParse() method.
 Live Demo
using System;
public class Demo {
   enum Vehicle { Bus = 2, Truck = 4, Car = 10 };
   public static void Main() {
      string[] VehicleList = { "2", "3", "4", "bus", "Truck", "CAR" };
      foreach (string val in VehicleList) {
         Vehicle vehicle;
         if (Enum.TryParse(val, true, out vehicle))
         if (Enum.IsDefined(typeof(Vehicle), vehicle) | vehicle.ToString().Contains(","))
         Console.WriteLine("Converted '{0}' to {1}", val, vehicle.ToString());
         else
         Console.WriteLine("{0} is not a value of the enum", val);
         else
         Console.WriteLine("{0} is not a member of the enum", val);
      }
   }
}
Converted '2' to Bus
3 is not a value of the enum
Converted '4' to Truck
Converted 'bus' to Bus
Converted 'Truck' to Truck
Converted 'CAR' to Car
How to declare, define and call a method in Java?

Following is the syntax to declare a method in Java.
modifier return_type method_name(parameters_list){
   //method body
}

Where,
modifier − It defines the access type of the method and it is optional to use.
modifier − It defines the access type of the method and it is optional to use.
return_type − Method may return a value.
return_type − Method may return a value.
method_name − This is the method name. The method signature consists of the method name and the parameter list.
method_name − This is the method name. The method signature consists of the method name and the parameter list.
parameters_list − The list of parameters, it is the type, order, and a number of parameters of a method. These are optional, method may contain zero parameters.
parameters_list − The list of parameters, it is the type, order, and a number of parameters of a method. These are optional, method may contain zero parameters.
method body − The method body defines what the method does with the statements.
method body − The method body defines what the method does with the statements.
For using a method, it should be called. There are two ways in which a method is called i.e., method returns a value or returning nothing (no return value).
Following is the example to demonstrate how to define a method and how to call it −
 Live Demo
public class ExampleMinNumber {
   public static void main(String[] args) {
      int a = 11;
      int b = 6;
      int c = minFunction(a, b);
      System.out.println("Minimum Value = " + c);
   }
   
   /** Returns the minimum of two numbers */
   public static int minFunction(int n1, int n2) {
      int min;
      if (n1 > n2){
         min = n2;
      } else {
         min = n1;
      }
      return min;
   }
}
Minimum value = 6
What is the difference between ng-if and data-ng-if directives ? - GeeksforGeeks

23 Jul, 2019
The ng-if is a directive in AngularJS which is used to remove the HTML element if the value of the expression or variable is false, unlike ng-hide which just hides the HTML element from the DOM.
Syntax:
<element angular_directive=expression> Contents... </element>
There are few other options which behave like ng-if. There is no difference among them in functionality wise.
ng:if
ng_if
x-ng-if
data-ng-if
Note: The best practice is to use ng-if only.
The reason behind why these options come into the picture is that in AngularJS we refer to the directive using camel case (example:ngIf) but when we use it in HTML since HTML is case insensitive we use a dash-delimited form (example:ng-if) or other delimiters as mentioned in the list above. So the AngularJS normalizes (It means it converts the delimiter form into camelcase.) the element’s tag and figures out to which directive does the element belong.
Example 1: This example uses “data-ng-if” directive.
<!DOCTYPE html><html>  <head>    <title>        What is the difference between ng-if        and data-ng-if directives ?    </title>          <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">    </script></head>  <body ng-app="">    <center>        <h1 style="color:green">            GeeksforGeeks        </h1>          <input ng-model="var1">          <div data-ng-if="var1">            <h3>                This will disappear if the value of                input var1 is set to false and will                 appear again when true            </h3>        </div>    </center></body>  </html>
Output:
Example 2: This example uses “ng-if” directive.
<!DOCTYPE html><html>  <head>    <title>        What is the difference between ng-if        and data-ng-if directives ?    </title>          <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">    </script></head>  <body ng-app="">    <center>        <h1 style="color:green">            GeeksforGeeks        </h1>          <input ng-model="var1">          <div ng-if="var1">            <h3>                This will disappear if the value of                input var1 is set to false and will                 appear again when true            </h3>        </div>    </center></body>  </html>
Output:
AngularJS-Misc
Picked
AngularJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Angular PrimeNG Dropdown Component
How to make a Bootstrap Modal Popup in Angular 9/8 ?
Angular 10 (blur) Event
How to setup 404 page in angular routing ?
How to create module with Routing in Angular 9 ?
Top 10 Front End Developer Skills That You Need in 2022
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
GATE | GATE CS 2019 | Question 6 - GeeksforGeeks

13 Feb, 2019
Ten friends planned to share equally the cost of buying a gifts for their teacher. When two of them decided not to contribute, each of the other friends had to pay Rs. 150 more. The cost of the gift was Rs. _________ .(A) 666(B) 3000(C) 6000(D) 12000Answer: (C)Explanation: Let share of each student = x
Since cost of gift will be same in both situation, therefore,
→ 10*x = 8*(x + 150) 
→ 10*x = 8*x + 8*150
→ 2*x = 8*150
→ x = 8*150 / 2
→ x = 600 
Therefore, cost of gift is,
10*x = 10*600 = 6000 
Option (C) is correct.Quiz of this Question
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
GATE | GATE-IT-2004 | Question 83
GATE | GATE-CS-2016 (Set 1) | Question 65
GATE | GATE-CS-2016 (Set 2) | Question 48
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE-CS-2007 | Question 17
GATE | GATE CS 2019 | Question 37
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE CS 1997 | Question 25
GATE | GATE-CS-2007 | Question 64
GATE | GATE-CS-2015 (Set 1) | Question 62
Check whether two strings are equivalent or not according to given condition in Python

Suppose we have two strings s and t of same size. We have to check whether s and t are equivalent or not. There are few conditions to check:
They both are equal. Or,
If we divide the s into two contiguous substrings of same size and the substrings are s1 and s2 and also divide t same like, s into t1 and t2, then one of the following should be valid:s1 is recursively equivalent to t1 and s2 is recursively equivalent to t2s1 is recursively equivalent to t2 and s2 is recursively equivalent to t1
s1 is recursively equivalent to t1 and s2 is recursively equivalent to t2
s1 is recursively equivalent to t2 and s2 is recursively equivalent to t1
So, if the input is like s = "ppqp" t = "pqpp", then the output will be True as if we divide s and t into two parts s1 = "pp", s2 = "qp" and t1 = "pq", t2 = "pp", here s1 = t2 and if we divide s2 and t1 into two parts s21 = "q", s22 = "p", t11 = "p", t12 = "q", here also s21 = t12 and s22 = t11, so they are recursively equivalent.
To solve this, we will follow these steps −
Define a function util() . This will take s
if size of s is odd, thenreturn s
return s
left := util(left half part of s)
right := util(right half part of s)
return minimum of (left concatenate right), (right concatenate left)
From the main method return true when util(s) is same as util(t) otherwise false
Let us see the following implementation to get better understanding −
Live Demo
def util(s):
   if len(s) & 1 != 0:
      return s
 
   left = util(s[0:int(len(s) / 2)])
   right = util(s[int(len(s) / 2):len(s)])
 
   return min(left + right, right + left)
 
def solve(s,t):
   return util(s) == util(t)

s = "ppqp"
t = "pqpp"
print(solve(s, t))
"ppqp", "pqpp"

True
How to set margin of ImageView using code in Android?

This example demonstrates how do I set margin of ImageView using code in android.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.
Step 2 − Add the following code to res/layout/activity_main.xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity">

   <ImageView
      android:id="@+id/imageView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:background="@drawable/image"/>

</RelativeLayout>
Step 3 – Copy an image file and paste in the res/drawable
Step 4 − Add the following code to src/MainActivity.java
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class MainActivity extends AppCompatActivity {

   ImageView imageView;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      imageView = findViewById(R.id.imageView);
      final RelativeLayout.LayoutParams layoutparams = (RelativeLayout.LayoutParams)imageView.getLayoutParams();
      layoutparams.setMargins(100,100,100,100);
      imageView.setLayoutParams(layoutparams);
   }
}
Step 5 - Add the following code to androidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="app.com.sample">

   <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">
      <activity android:name=".MainActivity">
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
      </activity>
   </application>
</manifest>
Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project's activity files and click Run  Icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen –