code-rag-bench/online-tutorials huggingface dataset:
Python Program for How to check if a given number is Fibonacci number?

24 Feb, 2022
Given a number \’n\’, how to check if n is a Fibonacci number. First few Fibonacci numbers are 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, .. Examples : 
Input : 8
Output : Yes

Input : 34
Output : Yes

Input : 41
Output : No
Following is an interesting property about Fibonacci numbers that can also be used to check if a given number is Fibonacci or not. A number is Fibonacci if and only if one or both of (5*n2 + 4) or (5*n2 – 4) is a perfect square (Source: Wiki).  
Python3
# python program to check if x is a perfect squareimport math # A utility function that returns true if x is perfect squaredef isPerfectSquare(x):    s = int(math.sqrt(x))    return s*s == x # Returns true if n is a Fibonacci Number, else falsedef isFibonacci(n):     # n is Fibonacci if one of 5*n*n + 4 or 5*n*n - 4 or both    # is a perfect square    return isPerfectSquare(5*n*n + 4) or isPerfectSquare(5*n*n - 4)    # A utility function to test above functionsfor i in range(1,11):     if (isFibonacci(i) == True):         print (i,"is a Fibonacci Number")     else:         print (i,"is a not Fibonacci Number ")
1 is a Fibonacci Number
2 is a Fibonacci Number
3 is a Fibonacci Number
4 is a not Fibonacci Number 
5 is a Fibonacci Number
6 is a not Fibonacci Number 
7 is a not Fibonacci Number 
8 is a Fibonacci Number
9 is a not Fibonacci Number 
10 is a not Fibonacci Number 
Please refer complete article on How to check if a given number is Fibonacci number? for more details! 
tiwaryshobhit
varshagumber28
amartyaghoshgfg
simmytarika5
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
MySQL Tryit Editor v1.0

SELECT LENGTH("SQL Tutorial") AS LengthOfString;
​
        
Edit the SQL Statement, and click "Run SQL" to see the result.
This SQL-Statement is not supported in the WebSQL Database.
The example still works, because it uses a modified version of SQL.
Your browser does not support WebSQL.
Your are now using a light-version of the Try-SQL Editor, with a read-only Database.
If you switch to a browser with WebSQL support, you can try any SQL statement, and play with the Database as much as you like. The Database can also be restored at any time.
Our Try-SQL Editor uses WebSQL to demonstrate SQL.
A Database-object is created in your browser, for testing purposes.
You can try any SQL statement, and play with the Database as much as you like. The Database can be restored at any time, simply by clicking the "Restore Database" button.
WebSQL stores a Database locally, on the user's computer. Each user gets their own Database object.
WebSQL is supported in Chrome, Safari, and Opera.
If you use another browser you will still be able to use our Try SQL Editor, but a different version, using a server-based ASP application, with a read-only Access Database, where users are not allowed to make any changes to the data.
Longest Continuous Increasing Subsequence in C++

Suppose we have an array of integers; we have to find the length of longest continuous
increasing subarray.
So, if the input is like [2,4,6,5,8], then the output will be 3. As the longest continuous increasing subsequence is [2,4,6], and its length is 3.
To solve this, we will follow these steps −
if size of nums <= 1, then −return size of nums
return size of nums
answer := 1, count := 1
for initialize i := 0, when i < size of nums, update (increase i by 1), do −if nums[i] < nums[i + 1], then −(increase count by 1)answer := maximum of answer and countOtherwisecount := 1
if nums[i] < nums[i + 1], then −(increase count by 1)answer := maximum of answer and count
(increase count by 1)
answer := maximum of answer and count
Otherwisecount := 1
count := 1
return answer
Let us see the following implementation to get better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
class Solution {
public:
   int findLengthOfLCIS(vector<int>& nums) {
      if (nums.size() <= 1)
         return nums.size();
      int answer = 1, count = 1;
      for (int i = 0; i < nums.size() - 1; i++) {
         if (nums[i] < nums[i + 1]) {
            count++;
            answer = max(answer, count);
         }
         else {
            count = 1;
         }
      }
      return answer;
   }
};
main(){
   Solution ob;
   vector<int> v = {2,4,6,5,8};
   cout << (ob.findLengthOfLCIS(v));
}
{2,4,6,5,8}
3
C# Linq Contains Method

To check for an element in a string, use the Contains() method.
The following is our string array.
string[] arr = { "Java", "C++", "Python"};
Now, use Contains() method to find a specific string in the string array.
arr.AsQueryable().Contains(str);
Let us see the complete example.
 Live Demo
using System;
using System.Linq;
using System.Collections.Generic;
class Demo {
   static void Main() {
      string[] arr = { "Java", "C++", "Python"};
      string str = "Python";
      bool res = arr.AsQueryable().Contains(str);
      Console.WriteLine("Array has Python? "+res);
   }
}
Array has Python? True
Create a text to speech application using ReactJS - GeeksforGeeks

09 Nov, 2021
React.js: React is a declarative, efficient, and flexible JavaScript library for building user interfaces. It’s ‘V’ in MVC. ReactJS is an open-source, component-based front-end library responsible only for the view layer of the application. It is maintained by Facebook.
Steps to Create Line Charts using Recharts in React JS :
Step 1: Create React Project 
npx create-react-app my-app
Step 2: Change your directory and enter your main folder charting as
cd my-app
The project Structure is as follows: 
Step 2: Installing react-speech-kit by below command: 
npm i react-speech-kit
Step 3: Write code on App.js: 
Javascript
import './App.css';import Speech from './speech';function App() {  return (    <div className="App">      <Speech/>    </div>  );}export default App;
 Step 4: Write code in the Speech.js file 
Javascript
import React from "react";import { useSpeechSynthesis } from "react-speech-kit";const Speech = () => {  const [value, setValue] = React.useState("");  const { speak } = useSpeechSynthesis();  return (    <div className="speech">      <div className="group">        <h2>Text To Speech Converter Using React Js</h2>      </div>      <div className="group">        <textarea          rows="10"          value={value}          onChange={(e) => setValue(e.target.value)}        ></textarea>      </div>      <div className="group">        <button onClick={() => speak({ text: value })}>          Speech        </button>      </div>    </div>  );};export default Speech;
Step 5: Write code on App.css
CSS
* {  margin: 0;  padding: 20px;  box-sizing: border-box;}body {  font-family: sans-serif;}.Speech {   width: 50px;}.group {  margin: 7px 0;}textarea {  width: 100%;  padding: 5px 10px;  border: 1px solid rgb(228, 20, 20);  outline: none;  border-radius: 3px;}button {  width: 100%;  display: block;  padding: 10px 22px;  color: rgb(10, 10, 10);  font-weight: bold;  cursor: pointer;  outline: none;  background: rgb(227, 240, 219);;}h2 {  margin-bottom: 10px;  text-align: center;}
 Step 6: Step to run the application: Open the terminal and type the following command.   
npm start
Output: Open the browser and our project is shown in the URL http://localhost:3000/ 
 
singghakshay
React-Questions
ReactJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
ReactJS useNavigate() Hook
Axios in React: A Guide for Beginners
How to set background images in ReactJS ?
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
Python | Ways to convert array of strings to array of floats

11 Aug, 2021
Sometimes in a competitive coding environment, we get input in some other datatypes and we need to convert them in other forms this problem is same as that we have an input in the form of string and we need to convert it into floats.Let’s discuss a few ways to convert an array of strings to array of floats.Method #1 : Using astype  
Python3
# Python code to demonstrate converting# array of strings to array of floats# using astype import numpy as np # initialising arrayini_array = np.array(["1.1", "1.5", "2.7", "8.9"]) # printing initial arrayprint ("initial array", str(ini_array)) # converting to array of floats# using np.astyperes = ini_array.astype(np.float) # printing final resultprint ("final array", str(res))
initial array ['1.1' '1.5' '2.7' '8.9']
final array [ 1.1  1.5  2.7  8.9]
 
  Method #2: Using np.fromstring  
Python3
# Python code to demonstrate converting# array of strings to array of floats# using fromstring import numpy as np # initialising arrayini_array = np.array(["1.1", "1.5", "2.7", "8.9"]) # printing initial arrayprint ("initial array", str(ini_array)) # converting to array of floats# using np.fromstringini_array = ', '.join(ini_array)ini_array = np.fromstring(ini_array, dtype = np.float,                                           sep =', ' ) # printing final resultprint ("final array", str(ini_array))
initial array ['1.1' '1.5' '2.7' '8.9']
final array [ 1.1  1.5  2.7  8.9]
 
  Method #3: Using np.asarray() and type  
Python3
# Python code to demonstrate# converting array of strings to array of floats# using asarray import numpy as np # initialising arrayini_array = np.array(["1.1", "1.5", "2.7", "8.9"]) # printing initial arrayprint ("initial array", str(ini_array)) # converting to array of floats# using np.asarrayfinal_array = b = np.asarray(ini_array,        dtype = np.float64, order ='C') # printing final resultprint ("final array", str(final_array))
initial array ['1.1' '1.5' '2.7' '8.9']
final array [ 1.1  1.5  2.7  8.9]
 
sagar0719kumar
Python-numpy
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 ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
Python | os.path.join() method
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python | Convert string dictionary to dictionary
Python Program for Fibonacci numbers
Python | Add keys to nested dictionary

14 May, 2020
Addition of keys in dictionaries have been discussed many times, but sometimes, we might have a problem in which we require to alter/add keys in the nested dictionary. This type of problem is common in today’s world with advent of NoSQL databases. Let’s discuss certain ways in which this problem can be solved.
Method #1 : Using dictionary bracketsThis task can be easily performed using the naive method of just keep nesting the dictionary brackets with the new value and new key is created on the go and the dictionary is updated.
# Python3 code to demonstrate working of# Update nested dictionary keys# Using dictionary brackets  # initializing dictionarytest_dict = {'GFG' : {'rate' : 4, 'since' : 2012}}  # printing original dictionaryprint("The original dictionary is : " + str(test_dict))  # Using dictionary brackets# Update nested dictionary keystest_dict['GFG']['rank'] = 1  # printing result print("Dictionary after nested key update : " + str(test_dict))
The original dictionary is : {'GFG': {'rate': 4, 'since': 2012}}
Dictionary after nested key update : {'GFG': {'rate': 4, 'since': 2012, 'rank': 1}}

 
Method #2 : Using update()This method is used in cases where more than one keys need to be added to the nested dictionaries. The update function accepts the dictionary and added the dictionary with the keys in it.
# Python3 code to demonstrate working of# Update nested dictionary keys# Using update()  # initializing dictionariestest_dict = {'GFG' : {'rate' : 4, 'since' : 2012}}upd_dict = {'rank' : 1, 'popularity' : 5}  # printing original dictionaryprint("The original dictionary is : " + str(test_dict))  # Using update()# Update nested dictionary keystest_dict['GFG'].update(upd_dict)  # printing result print("Dictionary after nested key update : " + str(test_dict))
The original dictionary is : {'GFG': {'rate': 4, 'since': 2012}}
Dictionary after nested key update : {'GFG': {'popularity': 5, 'rate': 4, 'since': 2012, 'rank': 1}}

Python dictionary-programs
Python-nested-dictionary
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to retrieve Python module path?

For a pure python module you can find the location of the source files by looking at the module.__file__. For example,
 >>> import mymodule
>>> mymodule.__file__
C:/Users/Ayush/mymodule.py 
 Many built-in modules, however,are written in C, and therefore module.__file__ points to a .so file (there is no module.__file__ on Windows), and therefore, you can't see the source.
 Running "python -v"from the command line tells you what is being imported and from where. This is useful if you want to know the location of built-in modules.
std::memcmp() in C++

11 Apr, 2022
It compares the first count characters of the arrays pointed to by buf1 and buf2.Syntax:
int memcmp(const void *buf1, const void *buf2, size_t count);
Return Value: it returns an integer.
Parameters:  
buf1 : Pointer to block of memory.
buf2 : Pointer to block of memory.
count : Maximum numbers of bytes to compare.
Return Value is interpreted as :
Value                                Meaning
Less than zero                       buf1 is less than buf2.
Zero                                 buf1 is equal to buf2.
Greater than zero                    buf1 is greater than buf2.

Example 1. When count Greater than zero( > 0)
// CPP program to illustrate std::memcmp()#include <iostream>#include <cstring>  int main(){    char buff1[] = "Welcome to GeeksforGeeks";    char buff2[] = "Hello Geeks ";      int a;      a = std::memcmp(buff1, buff2, sizeof(buff1));      if (a > 0)        std::cout << buff1 << " is greater than " << buff2;    else if (a < 0)        std::cout << buff1 << "is less than " << buff2;    else        std::cout << buff1 << " is the same as " << buff2;      return 0;}
Output:
Welcome to GeeksforGeeks is greater than Hello Geeks 

Example 2. When count less than zero( < 0)
// CPP program to illustrate std::memcmp() #include <cstring>#include <iostream>  int main(){    int comp = memcmp("GEEKSFORGEEKS", "geeksforgeeks", 6);    if (comp == 0) {        std::cout << "both are equal";    }    else if (comp < 0) {        std::cout << "String 1  is less than String 2";    } else {        std::cout << "String 1 is  greater than String 2";    }}
Output:
String 1 is less than String 2

Example 3 : When count equal to zero ( = 0)
// CPP program to illustrate std::memcmp()#include <iostream>#include <cstring>  int main(){    char buff1[] = "Welcome to GeeksforGeeks";    char buff2[] = "Welcome to GeeksforGeeks";      int a;      a = std::memcmp(buff1, buff2, sizeof(buff1));      if (a > 0)        std::cout << buff1 << " is greater than " << buff2;    else if (a < 0)        std::cout << buff1 << "is less than " << buff2;    else        std::cout << buff1 << " is the same as " << buff2;      return 0;}
Output:
Welcome to GeeksforGeeks is the same as Welcome to GeeksforGeeks

This article is contributed by Shivani Ghughtyal. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
yash_760
CPP-Library
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++
Map putAll() Method in Java with Examples

02 Jan, 2019
This method is used to copy all of the mappings from the specified map to this map.
Syntax:
void putAll(Map m)
Parameters: This method has the only argument map m, which contains key-value mappings to be copied to given map.
Returns: This method returns previous value associated with the key if present, else return -1.
Below programs show the implementation of int putAll() method.
Program 1:
// Java code to show the implementation of// putAll method in Map interface  import java.util.*;public class GfG {      // Driver code    public static void main(String[] args)    {          // Initializing a Map of type HashMap        Map<Integer, String> map = new HashMap<>();        map.put(1, "One");        map.put(3, "Three");        map.put(5, "Five");        map.put(7, "Seven");        map.put(9, "Nine");        System.out.println(map);          Map<Integer, String> mp = new HashMap<>();        mp.put(10, "Ten");        mp.put(30, "Thirty");        mp.put(50, "Fifty");          map.putAll(mp);          System.out.println(map);    }}
{1=One, 3=Three, 5=Five, 7=Seven, 9=Nine}
{1=One, 50=Fifty, 3=Three, 5=Five, 7=Seven, 9=Nine, 10=Ten, 30=Thirty}

Program 2: Below is the code to show implementation of put().
// Java code to show the implementation of// putAll method in Map interfaceimport java.util.*;public class GfG {      // Driver code    public static void main(String[] args)    {          // Initializing a Map of type HashMap        Map<String, String> map = new HashMap<>();        map.put("1", "One");        map.put("3", "Three");        map.put("5", "Five");        map.put("7", "Seven");        map.put("9", "Nine");        System.out.println(map);          Map<String, String> mp = new HashMap<>();        mp.put("10", "Ten");        mp.put("30", "Thirty");        mp.put("50", "Fifty");          map.putAll(mp);          System.out.println(map);    }}
{1=One, 3=Three, 5=Five, 7=Seven, 9=Nine}
{1=One, 3=Three, 5=Five, 7=Seven, 9=Nine, 50=Fifty, 30=Thirty, 10=Ten}

Reference:Oracle Docs
Java - util package
Java-Collections
Java-Functions
java-map
Java
Java
Java-Collections
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Union Operation in two Strings

27 Feb, 2020
One of the string operation can be computing the union of two strings. This can be useful application that can be dealt with. This article deals with computing the same through different ways.
Method 1 : Naive MethodThe task of performing string union can be computed by naive method by creating an empty string and checking for new occurrence of character common to both string and not common strings and appending it and hence computing the new union string. This can be achieved by loops and if/else statements.
# Python 3 code to demonstrate # Union Operation in two Strings# using naive method   # initializing stringstest_str1 = 'GeeksforGeeks'test_str2 = 'Codefreaks'  # Printing initial stringsprint ("The original string 1 is : " + test_str1)print ("The original string 2 is : " + test_str2)  # using naive method to# Union Operation in two Stringsres = ""temp = test_str1for i in test_str2:    if i not in temp:        test_str1 += i          # printing resultprint ("The string union is : " + test_str1)
The original string 1 is : GeeksforGeeks
The original string 2 is : Codefreaks
The string union is : GeeksforGeeksCda

 
Method 2 : Using set() + union()Set in python usually can perform the task of performing set operations such as set union. This utility of sets can be used to perform this task as well. Firstly, both the strings are converted into sets using set() and then union is performed using union(). Returns the sorted set.
# Python 3 code to demonstrate # Union Operation in two Strings# using set() + union()  # initializing stringstest_str1 = 'GeeksforGeeks'test_str2 = 'Codefreaks'  # Printing initial stringsprint ("The original string 1 is : " + test_str1)print ("The original string 2 is : " + test_str2)  # using set() + union() to# Union Operation in two Stringsres = set(test_str1).union(test_str2)          # printing resultprint ("The string union is : " + str(res))
The original string 1 is : GeeksforGeeks
The original string 2 is : Codefreaks
The string union is : {'s', 'G', 'r', 'e', 'o', 'f', 'k', 'C', 'd', 'a'}

Python list-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 ?
Python Classes and Objects
Python OOPs Concepts
Python | os.path.join() method
How to drop one or multiple columns in Pandas Dataframe
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python | Convert string dictionary to dictionary
Python Program for Fibonacci numbers
TensorFlow – How to add padding to a tensor

01 Aug, 2020
TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning  neural networks.
Padding means adding values before and after Tensor values.
Method Used:
tf.pad: This method accepts input tensor and padding tensor with other optional arguments and returns a Tensor with added padding and same type as input Tensor. Padding tensor is a Tensor with shape(n, 2).
Example 1: This example uses constant padding mode i.e. value at all the padded indices will be constant.
Python3
# importing the libraryimport tensorflow as tf  # Initializing the Inputinput = tf.constant([[1, 2], [3, 4]])padding = tf.constant([[2, 2], [2, 2]])  # Printing the Inputprint("Input: ", input)print("Padding: ", padding)  # Generating padded Tensorres = tf.pad(input, padding, mode ='CONSTANT')  # Printing the resulting Tensorsprint("Res: ", res )
Output:
Input:  tf.Tensor(
[[1 2]
 [3 4]], shape=(2, 2), dtype=int32)
Padding:  tf.Tensor(
[[2 2]
 [2 2]], shape=(2, 2), dtype=int32)
Res:  tf.Tensor(
[[0 0 0 0 0 0]
 [0 0 0 0 0 0]
 [0 0 1 2 0 0]
 [0 0 3 4 0 0]
 [0 0 0 0 0 0]
 [0 0 0 0 0 0]], shape=(6, 6), dtype=int32)


Example 2: This example uses REFLECT padding mode. For this mode to work paddings[D, 0] and paddings[D, 1] must be less than or equal to tensor.dim_size(D) – 1.
Python3
# importing the libraryimport tensorflow as tf  # Initializing the Inputinput = tf.constant([[1, 2, 5], [3, 4, 6]])padding = tf.constant([[1, 1], [2, 2]])  # Printing the Inputprint("Input: ", input)print("Padding: ", padding)  # Generating padded Tensorres = tf.pad(input, padding, mode ='REFLECT')  # Printing the resulting Tensorsprint("Res: ", res )
Output:
Input:  tf.Tensor(
[[1 2 5]
 [3 4 6]], shape=(2, 3), dtype=int32)
Padding:  tf.Tensor(
[[1 1]
 [2 2]], shape=(2, 2), dtype=int32)
Res:  tf.Tensor(
[[6 4 3 4 6 4 3]
 [5 2 1 2 5 2 1]
 [6 4 3 4 6 4 3]
 [5 2 1 2 5 2 1]], shape=(4, 7), dtype=int32)


Python-Tensorflow
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
Python | os.path.join() method
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
Python | Get unique values from a list
Python | datetime.timedelta() function
Python program to convert exponential to float

23 Dec, 2020
Given a number in exponential format, the task is to write a Python program to convert the number from exponential format to float. The exponential number is a way of representing a number.
Examples:
Input: 1.900000e+01
Output: 19.0

Input: 2.002000e+03
Output: 2002.0

Input: 1.101020e+05
Output: 110102.0
Approach:
First, we will declare an exponential number and save it in a variable.
Then we will use the float() function to convert it to float datatype.
Then we will print the converted number.
Syntax:
float(x)
The float() method is used to return a floating-point number from a number or a string.
Example:
Python3
# Python program to convert exponential to float  # Declaring the exponential numberexp_number = "{:e}".format(110102)  # Converting it to float data typefloat_number = float(exp_number)  # Printing the converted numberprint("Exponent Number:",exp_number)print("Float Number:",float_number)
Output:
Exponent Number: 1.101020e+05
Float Number: 110102.0
Picked
Technical Scripter 2020
Python
Python Programs
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
What is APIPA (Automatic Private IP Addressing)?

22 May, 2020
APIPA stands for Automatic Private IP Addressing (APIPA). It is a feature or characteristic in operating systems (eg. Windows) which enables computers to self-configure an IP address and subnet mask automatically when their DHCP(Dynamic Host Configuration Protocol) server isn’t reachable. The IP address range for APIPA is (169.254.0.1 to 169.254.255.254) having 65, 534 usable IP addresses, with the subnet mask of 255.255.0.0.
Initially, the Internet Engineering Task Force (IETF) has reserved the IPv4 address block 169.254.0.0/16 (169.254.0.0 – 169.254.255.255) for link-local addressing. Due to the simultaneous use of IPv4 addresses of different scopes, traffic overload becomes high. The link-local addresses are allocated to interface i.e., stateless in nature such that communication will be established when not getting a response from DHCP Server. After that Microsoft refers to this address autoconfiguration method as “Automatic Private IP Addressing (APIPA)”.
It starts with when the user(client) is unable to find the data/information, then uses APIPA to configure the system with an IP address automatically(ipconfig). The APIPA provides the configuration to check for the presence of a DHCP server(in every five minutes, stated by Microsoft). If APIPA detects a DHCP server on the network configuration area, it stops, and let run the DHCP server that replaces APIPA with dynamically allocated addresses.
Note: To Know the given IP address is provided by which addressing, just run the following command:
ipconfig/all
Communication can be established properly if not getting response from DHCP Server.
APIPA regulates the service, by which always checking response and status of the main DHCP server in a specific period of time.
It can be used as a backup of DHCP because when DHCP stops working then APIPA has the ability to assign IP to the networking hosts.
It stops unwanted broadcasting.
It uses ARP(Address Resolution Protocol) to confirm the address isn’t currently in use.
APIPA ip addresses can slow you network.
APIPA doesnot provide network gateway as DHCP does.
APIPA addresses are restricted for use in local area network.
APIPA configured devices follow the peer to peer communication rule.
Picked
Computer Networks
Computer Networks
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Assembly - System Calls

System calls are APIs for the interface between the user space and the kernel space. We have already used the system calls. sys_write and sys_exit, for writing into the screen and exiting from the program, respectively.
You can make use of Linux system calls in your assembly programs. You need to take the following steps for using Linux system calls in your program −
Put the system call number in the EAX register.
Store the arguments to the system call in the registers EBX, ECX, etc.
Call the relevant interrupt (80h).
The result is usually returned in the EAX register.
There are six registers that store the arguments of the system call used. These are the EBX, ECX, EDX, ESI, EDI, and EBP. These registers take the consecutive arguments, starting with the EBX register. If there are more than six arguments, then the memory location of the first argument is stored in the EBX register.
The following code snippet shows the use of the system call sys_exit −
mov	eax,1		; system call number (sys_exit)
int	0x80		; call kernel
The following code snippet shows the use of the system call sys_write −
mov	edx,4		; message length
mov	ecx,msg		; message to write
mov	ebx,1		; file descriptor (stdout)
mov	eax,4		; system call number (sys_write)
int	0x80		; call kernel
All the syscalls are listed in /usr/include/asm/unistd.h, together with their numbers (the value to put in EAX before you call int 80h).
The following table shows some of the system calls used in this tutorial −
The following example reads a number from the keyboard and displays it on the screen −
section .data                           ;Data segment
   userMsg db 'Please enter a number: ' ;Ask the user to enter a number
   lenUserMsg equ $-userMsg             ;The length of the message
   dispMsg db 'You have entered: '
   lenDispMsg equ $-dispMsg                 

section .bss           ;Uninitialized data
   num resb 5
	
section .text          ;Code Segment
   global _start
	
_start:                ;User prompt
   mov eax, 4
   mov ebx, 1
   mov ecx, userMsg
   mov edx, lenUserMsg
   int 80h

   ;Read and store the user input
   mov eax, 3
   mov ebx, 2
   mov ecx, num  
   mov edx, 5          ;5 bytes (numeric, 1 for sign) of that information
   int 80h
	
   ;Output the message 'The entered number is: '
   mov eax, 4
   mov ebx, 1
   mov ecx, dispMsg
   mov edx, lenDispMsg
   int 80h  

   ;Output the number entered
   mov eax, 4
   mov ebx, 1
   mov ecx, num
   mov edx, 5
   int 80h  
    
   ; Exit code
   mov eax, 1
   mov ebx, 0
   int 80h
When the above code is compiled and executed, it produces the following result −
Please enter a number:
1234  
You have entered:1234


    46 Lectures 
     2 hours 

 Frahaan Hussain

    23 Lectures 
     12 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page
Binary Search program in JavaScript

Create a function, say binarySearch() that takes in 4 arguments −
a sorted Number / String literal array
starting index of array (0)
ending index of array (length - 1)
number to be searched
If the number exists in the array, then the index of the number should be returned, otherwise -1
should be returned. Here is the full code −
const arr = [2,4,6,6,8,8,9,10,13,15,17,21,24,26,28,36,58,78,90];
//binary search function
//returns the element index if found otherwise -1
const binarySearch = (arr, start, end, num) => {
   const mid = start + Math.floor((end - start)/2);
   if(start <= end){
      if(arr[mid] === num){
         return mid;
      }
      if(num < arr[mid]){
         return binarySearch(arr, start, mid-1, num);
      }
      if(num > arr[mid]){
         return binarySearch(arr, mid+1, end, num);
      }
   }
   return -1;
};
console.log(binarySearch(arr, 0, arr.length-1, 13));
console.log(binarySearch(arr, 0, arr.length-1, 11));
The output of this code in the console will be −
8
-1
How to remove all trailing and leading whitespace in a string in Python?

To remove all trailing and leading whitespace in a string, we can use the method strip() in String class that gets rid of both these whitespaces. You can use it as follows:
>>> '   Hello People   '.strip()
'Hello People'
If you only want to remove leading or trailing whitespace use lstrip() or rstrip() respectively.
>>> '   Hello People'.lstrip()
'Hello People'
>>> 'Hello People   '.rstrip()
'Hello People'
JavaScript Map keys() Method - GeeksforGeeks

21 Jan, 2022
Below is the basic example of the Map.keys() method.
Javascript
<script>  let mp=new Map()  mp.set("a",11);  mp.set("b",2);  mp.set("c",5);  console.log(mp.keys());</script>
Output:
MapIterator {"a", "b", "c"}
The Map.keys() method is used to extract the keys from a given map object and return the iterator object of keys. The keys are returned in the order they were inserted.
Syntax: 
Map.keys()
Parameters: This method does not accept any parameters.
Returns: This returns the iterator object that contains keys in the map.
Code for the above method is provided below:Program 1:
HTML
<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <meta name="viewport"        content="width=device-width,                 initial-scale=1.0">  <title>Document</title></head><body>  <ul class="list">  </ul>  <script>    // Creating a map using Map object    let mp=new Map()    // Adding key value pairs to the map mp    mp.set("a",1);    mp.set("b",2);    mp.set("c",22);    mp.set("d",12);    console.log("Type of mp.keys() is: ",typeof (mp.keys()));    console.log("Keys in map mp are: ",mp.keys());  </script></body></html>
Output:
Program 2: Updating the value of the key in the map and printing values using the iterator object.
HTML
<!DOCTYPE html><html lang="en"><head>  <meta charset="UTF-8">  <meta name="viewport"        content="width=device-width,                 initial-scale=1.0">  <title>Document</title></head><body>  <ul class="list">  </ul>  <script>    // Creating a map using Map object    let mp=new Map()    // Adding key value pairs to the map mp    mp.set("q",1);    mp.set("w",2);    // Value of key "q" is updated to 22    mp.set("q",22);    mp.set("d",22);    mp.set("c",12);    let it=mp.keys();    // Logginfg iterator object    console.log(it);    console.log(it.next().value)    // Iterator pointing to next key and    // printing the value    console.log(it.next().value)  </script></body></html>
Output: 
Supported Browsers: 
Chrome 38 and above
Opera 25 and above
Edge 12 and above
Firefox 20 and above
Safari 8 and above
ysachin2314
JavaScript-Methods
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Difference between var, let and const keywords in JavaScript
Difference Between PUT and PATCH Request
Remove elements from a JavaScript Array
How to get character array from string in JavaScript?
How to get selected value in dropdown list using JavaScript ?
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?
Print an array with numbers having 1, 2 and 3 as a digit in ascending order

Here, the task is to print those number in an array having 1, 2 and 3 as digits in their numbers and if their is no such number than the output must be -1
Input : arr[] = {320,123,124,125,14532,126,340,123400,100032,13,32,3123,1100}
Output : 123 3123 14532 100032 123400

Since the array have values with digits 1, 2 and 3 it wouldn’t return -1 and print 5 values that
Contain 1, 2 and 3 in their respective numbers.
START
Step 1 -> Declare array with elements of int type as arr
Step 2 -> store size of array in int n
Step 3 -> declare int variable as one, two, three
Step 4 -> call sort functions with parameters as arr and arr+n
Step 5 -> declare variable of type osrtingstream as st and string as num
Step 6 -> Loop For i=0 and i<n and ++i
   Set one=two=three=1
   Print arr[i]
   Set num=st.str()
   Set one=num.find("1")
   Set two=num.find("2")
   Set three=num.find("3")
   IF((one!=-1)&&(two!=-1)&&(three!=-1))
      Print num
   End
   Call st.str(‘’”)
end
STOP
#include <bits/stdc++.h>
#include<string.h>
#include<sstream>
using namespace std;
int main() {
   int arr[] = {320,123,124,125,14532,126,340,123400,100032,13,32,3123,1100};
   int n = sizeof(arr)/sizeof(arr[0]);
   int one,two,three;
   sort(arr, arr+n);
   ostringstream st;
   string num;
   for (int i = 0; i < n; ++i) {
      one=two=three=-1;
      st << arr[i];
      num=st.str();
      one=num.find("1");
      two=num.find("2");
      three=num.find("3");
      if((one!=-1)&&(two!=-1)&&(three!=-1)) {
         cout<<num<<" ";
      }
      st.str("");
   }
}
if we run the above program then it will generate the following output
123 3123 14532 100032 123400
Apache Pig - Split Operator

The SPLIT operator is used to split a relation into two or more relations.
Given below is the syntax of the SPLIT operator.
grunt> SPLIT Relation1_name INTO Relation2_name IF (condition1), Relation2_name (condition2),

Assume that we have a file named student_details.txt in the HDFS directory /pig_data/ as shown below.
student_details.txt
001,Rajiv,Reddy,21,9848022337,Hyderabad
002,siddarth,Battacharya,22,9848022338,Kolkata
003,Rajesh,Khanna,22,9848022339,Delhi 
004,Preethi,Agarwal,21,9848022330,Pune 
005,Trupthi,Mohanthy,23,9848022336,Bhuwaneshwar 
006,Archana,Mishra,23,9848022335,Chennai 
007,Komal,Nayak,24,9848022334,trivendram 
008,Bharathi,Nambiayar,24,9848022333,Chennai

And we have loaded this file into Pig with the relation name student_details as shown below.
student_details = LOAD 'hdfs://localhost:9000/pig_data/student_details.txt' USING PigStorage(',')
   as (id:int, firstname:chararray, lastname:chararray, age:int, phone:chararray, city:chararray); 
Let us now split the relation into two, one listing the employees of age less than 23, and the other listing the employees having the age between 22 and 25.
SPLIT student_details into student_details1 if age<23, student_details2 if (22<age and age>25);
Verify the relations student_details1 and student_details2 using the DUMP operator as shown below.
grunt> Dump student_details1;  

grunt> Dump student_details2; 
It will produce the following output, displaying the contents of the relations student_details1 and student_details2 respectively.
grunt> Dump student_details1; 
(1,Rajiv,Reddy,21,9848022337,Hyderabad) 
(2,siddarth,Battacharya,22,9848022338,Kolkata)
(3,Rajesh,Khanna,22,9848022339,Delhi) 
(4,Preethi,Agarwal,21,9848022330,Pune)
  
grunt> Dump student_details2; 
(5,Trupthi,Mohanthy,23,9848022336,Bhuwaneshwar) 
(6,Archana,Mishra,23,9848022335,Chennai) 
(7,Komal,Nayak,24,9848022334,trivendram) 
(8,Bharathi,Nambiayar,24,9848022333,Chennai)


    46 Lectures 
     3.5 hours 

 Arnab Chakraborty

    23 Lectures 
     1.5 hours 

 Mukund Kumar Mishra

    16 Lectures 
     1 hours 

 Nilay Mehta

    52 Lectures 
     1.5 hours 

 Bigdata Engineer

    14 Lectures 
     1 hours 

 Bigdata Engineer

    23 Lectures 
     1 hours 

 Bigdata Engineer
 Print
 Add Notes
 Bookmark this page
How to Remove Characters from a String in Arduino?

The remove function in Arduino helps you remove one or more characters from within a string.
myString.remove(index, count)
Here, index refers to the index from where removal has to start. Note that indexing in Arduino starts with 0. Thus, within string "Hello", 'H' is at index 0, 'e' is at index 1, and so on.
The count argument is optional, and it specifies the number of characters to remove. If you don’t specify the count, then all characters starting from index till the end of the string will be removed. If you specify count as say, 3, then 3 characters starting from index position will be removed.
void setup() {
   // put your setup code here, to run once:
   Serial.begin(9600);
   Serial.println();
   String s1 = "Mississippi";
   String s2 = "Mississippi";
   String s3 = "Mississippi";

   Serial.println(s1);
   Serial.println(s2);
   Serial.println(s3);
   Serial.println();

   s1.remove(3,6); //Remove 6 characters starting from position 3
   s2.remove(3); //Remove all characters starting from position 3
   s3.remove(3,1); //Remove 1 character starting from position 3

   Serial.println(s1);
   Serial.println(s2);
   Serial.println(s3);
}

void loop() {
   // put your main code here, to run repeatedly:
}
The Serial Monitor output is shown below −
As you can see, the removal of characters happens exactly as described in the comments of the code.
ArrayDeque pop() Method in Java - GeeksforGeeks

10 Dec, 2018
The Java.util.ArrayDeque.pop() method in Java is used to pop an element from the deque. The element is popped from the top of the deque and is removed from the same.
Syntax:
Array_Deque.pop()
Parameters: The method does not take any parameters.
Return Value: This method returns the element present at the front of the Deque.
Exceptions: The method throws NoSuchElementException is thrown if the deque is empty.
Below programs illustrate the Java.util.ArrayDeque.pop() method:Program 1:
// Java code to illustrate pop()import java.util.*;  public class ArrayDequeDemo {    public static void main(String args[])    {        // Creating an empty ArrayDeque        Deque<String> de_que = new ArrayDeque<String>();          // Use add() method to add elements        de_que.add("Welcome");        de_que.add("To");        de_que.add("Geeks");        de_que.add("For");        de_que.add("Geeks");          // Displaying the ArrayDeque        System.out.println("Initial ArrayDeque: " + de_que);          // Removing elements using pop() method        System.out.println("Popped element: " + de_que.pop());        System.out.println("Popped element: " + de_que.pop());          // Displaying the ArrayDeque after pop        System.out.println("Deque after operation "                           + de_que);    }}
Initial ArrayDeque: [Welcome, To, Geeks, For, Geeks]
Popped element: Welcome
Popped element: To
Deque after operation [Geeks, For, Geeks]

Program 2:
// Java code to illustrate pop()import java.util.*;  public class ArrayDequeDemo {    public static void main(String args[])    {        // Creating an empty ArrayDeque        Deque<Integer> de_que = new ArrayDeque<Integer>();          // Use add() method to add elements into the Deque        de_que.add(10);        de_que.add(15);        de_que.add(30);        de_que.add(20);        de_que.add(5);          // Displaying the ArrayDeque        System.out.println("Initial ArrayDeque: " + de_que);          // Removing elements using pop() method        System.out.println("Popped element: " + de_que.pop());        System.out.println("Popped element: " + de_que.pop());          // Displaying the ArrayDeque after pop        System.out.println("Deque after operation "                           + de_que);    }}
Initial ArrayDeque: [10, 15, 30, 20, 5]
Popped element: 10
Popped element: 15
Deque after operation [30, 20, 5]

Java - util package
Java-ArrayDeque
Java-Collections
Java-Functions
Java
Java
Java-Collections
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Arrays in Java
Split() String method in Java with examples
For-each loop in Java
Arrays.sort() in Java with examples
Reverse a string in Java
Initialize an ArrayList in Java
Object Oriented Programming (OOPs) Concept in Java
HashMap in Java with Examples
Interfaces in Java
How to iterate any Map in Java
How to find the counts of categories in categorical columns in an R data frame?

If we have two categorical columns in an R data frame then we can find the frequency/count of each category with respect to each category in the other column. This will help us to compare the frequencies for all categories. To find the counts of categories, we can use table function as shown in the below examples.
 Live Demo
Consider the below data frame −
x1<−sample(c("Child","Teen","Adult","Old"),20,replace=TRUE)
x2<−sample(c("Unemployed","Employed"),20,replace=TRUE)
df1<−data.frame(x1,x2)
df1
x1 x2
1 Old Unemployed
2 Child Unemployed
3 Adult Employed
4 Adult Unemployed
5 Adult Employed
6 Teen Employed
7 Old Employed
8 Child Unemployed
9 Child Employed
10 Adult Unemployed
11 Child Unemployed
12 Old Employed
13 Child Unemployed
14 Child Employed
15 Teen Employed
16 Adult Employed
17 Adult Unemployed
18 Old Employed
19 Adult Unemployed
20 Child Employed
Finding the counts of categories in both columns of df1 −
table(df1$x1,df1$x2)
Employed Unemployed
Adult 3 4
Child 3 4
Old 3 1
Teen 2 0
 Live Demo
y1<−sample(c("Married","Unmarried"),20,replace=TRUE)
y2<−sample(c("Satisfied","Not-Satisfied"),20,replace=TRUE)
df2<−data.frame(y1,y2)
df2
y1 y2
1 Married Not-Satisfied
2 Unmarried Not-Satisfied
3 Married Not-Satisfied
4 Unmarried Not-Satisfied
5 Married Satisfied
6 Married Not-Satisfied
7 Unmarried Satisfied
8 Married Satisfied
9 Unmarried Not-Satisfied
10 Unmarried Not-Satisfied
11 Unmarried Not-Satisfied
12 Unmarried Not-Satisfied
13 Married Satisfied
14 Married Satisfied
15 Married Satisfied
16 Married Not-Satisfied
17 Married Satisfied
18 Unmarried Satisfied
19 Married Satisfied
20 Married Satisfied
Finding the counts of categories in both columns of df2 −
table(df2$y1,df2$y2)
Not−Satisfied Satisfied
Married 4 8
Unmarried 6 2
Clojure - Vectors

A Vector is a collection of values indexed by contiguous integers. A vector is created by using the vector method in Clojure.
Following is an example of creating a vector in Clojure.
(ns clojure.examples.example
   (:require [clojure.set :as set])
   (:gen-class))
(defn example []
   (println (vector 1 2 3)))
(example)
The above code produces the following output.
[1 2 3]

Following are the methods available in Clojure.
Creates a new vector of a single primitive type ‘t’, where ‘t’ is one of :int :long :float :double :byte :short :char or :boolean.
This function returns the item in the nth position in the vector.
Returns the element at the index position in the vector.
Appends an element to the vector and returns the new set of vector elements.
For a list or queue, returns a new list/queue without the first item, for a vector, returns a new vector without the last item.
Returns a sub vector from a starting and ending index.
 Print
 Add Notes
 Bookmark this page
Selenium - Mouse Actions

Listed below are some of the key mouse actions that one would come across in most of the applications -
Click − Performs a Click. We can also perform a click based on coordinates.
Click − Performs a Click. We can also perform a click based on coordinates.
contextClick − Performs a context click/right-click on an element or based on the coordinates
contextClick − Performs a context click/right-click on an element or based on the coordinates
doubleClick − Performs a double-click on the webelement or based on the coordinates. If left empty, it performs double-click on the current location.
doubleClick − Performs a double-click on the webelement or based on the coordinates. If left empty, it performs double-click on the current location.
mouseDown − Performs a mouse-down action on an element or based on coordinates.
mouseDown − Performs a mouse-down action on an element or based on coordinates.
mouseMove − Performs a mouse-move action on an element or based on coordinates.
mouseMove − Performs a mouse-move action on an element or based on coordinates.
mouseUp − Releases the mouse usually followed by mouse-down and acts based on co-ordinates.
mouseUp − Releases the mouse usually followed by mouse-down and acts based on co-ordinates.
Here are the syntax to call mouse actions using Selenium WebDriver -
void click(WebElement onElement)
void contextClick(WebElement onElement)
void doubleClick(WebElement onElement)
void mouseDown(WebElement onElement)
void mouseUp(WebElement onElement)
void mouseMove(WebElement toElement)
void mouseMove(WebElement toElement, long xOffset, long yOffset)

    46 Lectures 
     5.5 hours 

 Aditya Dua

    296 Lectures 
     146 hours 

 Arun Motoori

    411 Lectures 
     38.5 hours 

 In28Minutes Official

    22 Lectures 
     7 hours 

 Arun Motoori

    118 Lectures 
     17 hours 

 Arun Motoori

    278 Lectures 
     38.5 hours 

 Lets Kode It
 Print
 Add Notes
 Bookmark this page