code-rag-bench/online-tutorials huggingface dataset:
HTML autofocus Attribute

13 Dec, 2021
The autofocus attribute in HTML is used to specify that the element should get focused when the page loads. It is a boolean attribute.
Syntax:
<elementName autofocus>
Note: It supports only the following elements: <button>, <input>, <select> and <textarea>.
Supported Tags: 
Button autofocus Attribute
Input autofocus Attribute
Keygen autofocus Attribute
Select autofocus Attribute
Textarea autofocus Attribute
Example 1: In this example, we are using a select autofocus attribute which creates the dropdown for GeeksforGeeks courses.
HTML
<!DOCTYPE html><html>  <body>    <h2>GeeksforGeeks</h2>    <p>    The select element is used to create a drop-down list.  </p>        <form>    <label for="courses">Select a course:</label>    <select name="DSA Self Paced GfG"            id="DSA">      <option value="Full Stack Web Technology">        Web Tech      </option>      <option value="Amazon Interview Preparation">        Amazon      </option>      <option value="Complete Interview Preparation">        CIP      </option>      <option value="Google Test Series">        GTS      </option>    </select>    <br><br>    <input type="submit" value="Submit">  </form>  </body>  </html>
Output:
autofocus attribute
Example 2: This example uses the autofocus attribute to create the focus on the first name while loading the page for the first time.
HTML
<!DOCTYPE html><html>  <head>  <title>HTML autofocus Attribute</title></head>  <body style="text-align: center;">  <h1 style="color: green;">GeeksforGeeks</h1>  <h2>HTML autofocus Attribute</h2>  <form>    <label>First Name:      <input type="text" autofocus placeholder="Enter Name">    </label>  </form></body>  </html>
Output:
autofocus attribute
Example 3: This example uses the autofocus attribute with the <textarea> tag.
HTML
<!DOCTYPE html><html>  <head>  <title>HTML autofocus Attribute</title></head>  <body style="text-align: center;">  <h1 style="color: green;">GeeksforGeeks</h1>  <h2>HTML autofocus Attribute</h2>  <textarea rows="3" cols="30" autofocus>            A computer science portal for geeks.        </textarea></body>  </html>
Output:
autofocus attribute
Supported Browsers:
Google Chrome 5.0
Internet Explorer 10.0
Firefox 4.0
Opera 9.6
Safari 5.0
hritikbhatnagar2182
shubhamyadav4
bhaskargeeksforgeeks
HTML-Attributes
CSS
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to update Node.js and NPM to next version ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
How to create footer to stay at the bottom of a Web page?
CSS to put icon inside an input element in a form
How to update Node.js and NPM to next version ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
REST API (Introduction)
Hide or show elements in HTML using display property
InStr() and InstrRev() Function in MS Access

28 Aug, 2020
1. InStr() Function :The InStr() Function returns the position of a string in another string. It always returns the first occurrence of the string. It works not case sensitive. It returns 0 if the string2 is not found in string1 or string1 is null or the parameter starts in the function is greater than length of string1 and it returns null if string1 is null and if the length of string2 is zero then it returns value of start parameter.
Syntax –
InStr(start, string1, string2, compare)
Parameters –
start : Optional (By default the position is 1)
String1 : Required (The string to be searched)
string2 : Required (The string to search for)
compare : Optional (Type of string comparison)
Possible Values –
-1 : Use the setting of Option Compare.
0 : Binary comparison.
1 : Textual comparison.
2 : Comparison based on information in your database.
Return – It returns 0, 1 or null.
Example –
SELECT InStr("geeksforgeeks", "f") 
AS MatchPosition;
Output –
Example –
SELECT InStr("DSA self paced", "a") 
AS MatchPosition;
Output –
2. InstrRev() Function :The InstrRev() Function function works like Instr() function but it returns position of the first occurrence of a string in another, from the end of string. The start parameter in this default -1.
Syntax :
InstrRev(string1, string2, start, compare)
Example –
SELECT InStrRev("geeksforgeeks", "k") 
AS MatchPosition;
Output –
Example –
SELECT InStrRev("gfg", "k") 
AS MatchPosition;
Output –
DBMS-SQL
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to align images side by side with CSS?

Following is the code to align images side by side using CSS −
 Live Demo
<!DOCTYPE html>
<html>
<head>
<style>
* {
   box-sizing: border-box;
}
.imageColumn {
   float: left;
   width: 25%;
   padding: 10px;
}
h1{
   text-align: center;
}
</style>
</head>
<body>
<h1>Images Aligned Side by Side example</h1>
<div class="alignRow">
<div class="imageColumn">
<img src="https://i.picsum.photos/id/811/400/400.jpg" alt="Snow" style="width:100%">
</div>
<div class="imageColumn">
<img src="https://i.picsum.photos/id/871/400/400.jpg" alt="Forest" style="width:100%">
</div>
<div class="imageColumn">
<img src="https://i.picsum.photos/id/471/400/400.jpg" alt="Mountains" style="width:100%">
</div>
<div class="imageColumn">
<img src="https://i.picsum.photos/id/271/400/400.jpg" alt="Snow" style="width:100%">
</div>
</div>>
</body>
</html>
The above code will produce the following output −
screenshot() element method – Selenium Python

27 Apr, 2020
Selenium’s Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout – Navigating links using get method – Selenium Python. Just being able to go to places isn’t terribly useful. What we’d really like to do is to interact with the pages, or, more specifically, the HTML elements within a page. There are multiple strategies to find an element using Selenium, checkout – Locating Strategies
This article revolves around how to use screenshot method in Selenium. screenshot method is used to save a screenshot of current element to a PNG file. It returns false if there is any IOError, else return True.Args:filename: The full path you wish to save your screenshot to. This should end with a .png extension.
element.screenshot('foo.png')
Example –
<input type="text" name="passwd" id="passwd-id" />
To find an element one needs to use one of the locating strategies, For example,
element = driver.find_element_by_id("passwd-id")
element = driver.find_element_by_name("passwd")
element = driver.find_element_by_xpath("//input[@id='passwd-id']")
Also, to find multiple elements, we can use –
elements = driver.find_elements_by_name("passwd")
Now one can click a screenshot this field with
element.screenshot('foo.png')
Let’s try to get header of geeksforgeeks and then click its screenshot.Program –
# import webdriverfrom selenium import webdriver  # create webdriver objectdriver = webdriver.Firefox()  # get geeksforgeeks.orgdriver.get("https://www.geeksforgeeks.org/")  # get element element = driver.find_element_by_class_name("header--navbar")  # click screenshot element.screenshot('foo.png')
Output-
Screenshot –
Python-selenium
selenium
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
Python OOPs Concepts
Introduction To PYTHON
How to log errors and warnings into a file in php? - GeeksforGeeks

02 Jan, 2019
In PHP, errors and warnings can be logged into a file by using a php script and changing configuration of php.ini file. Two such approaches are mentioned below:
Approach 1: The error_log() function can be used to send error messages to a given file. First argument to the function is the error message to be sent. Second argument tells where to send/log the error message. In this case, second argument is set to 3, used to redirect error message to a file. Third argument is used to specify the file path of the error logging file.
Below is the implementation of the above approach:
<?php// php code for logging error into a given file  // error message to be logged$error_message = "This is an error message!";  // path of the log file where errors need to be logged$log_file = "./my-errors.log";  // logging error message to given log fileerror_log($error_message, 3, $log_file);  ?>
Output:
[20-Dec-2018 17:32:00 UTC] This is an error message!
Approach 2:
The init_set() function allows a user to programmatically update configuration of the php.ini file.
The ini_set(“log_errors”, TRUE) command can be added to the php script to enable error logging in php.
The ini_set(‘error_log’, $log_file) command can be added to the php script to set the error logging file.
Further error_log($error_message) function call can be used to log error message to the given file.
Below is the implementation of the above approach:
<?php// PHP code for logging error into a given file  // error message to be logged$error_message = "This is an error message!";  // path of the log file where errors need to be logged$log_file = "./my-errors.log";  // setting error logging to be activeini_set("log_errors", TRUE);   // setting the logging file in php.iniini_set('error_log', $log_file);  // logging the errorerror_log($error_message);  ?>
Output:
[20-Dec-2018 17:30:35 UTC] This is an error message!
Similar Approach: Following lines can also be added directly to php.ini to make the configuration changes permanent for every php script that logs errors and warnings.
log_errors = on
error_log = ./errors.log

Note:: This approach is not highly reliable as compared to other approaches. Its better to use approach 1 as it gives flexibility of choosing different files for logging at same time without changing configuration of php.ini file.
PHP-basics
PHP-file-handling
Picked
PHP
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Insert Form Data into Database using PHP ?
How to execute PHP code using command line ?
PHP in_array() Function
How to pop an alert message box using PHP ?
How to convert array to string in PHP ?
How to delete an array element based on key in PHP?
How to Upload Image into Database and Display it using PHP ?
How to check whether an array is empty using PHP?
Comparing two dates in PHP
PHP | strval() Function
HTML | DOM createDocumentFragment() Method - GeeksforGeeks

24 Jul, 2019
The createDocumentFragment() method in HTML DOM is used to create the document fragment which is useful to change the content of the document such as delete, modify or add a new node. This method creates the document fragment, then append the elements of the document to the document fragment and make the changes according to the need. Finally, append the document fragment to the document. It is a safe method and thus prevents destroying of the DOM structure.
Syntax:
document.createDocumentFragment()
Parameters: This method does not accepts any parameter.
Return Value: It returns the created DocumentFragment node.
Example:
<!DOCTYPE html><html>  <head>      <!--script to delete first child of    the list, and modify it -->    <script>        function myGeeks() {            var doc = document.createDocumentFragment();            doc.appendChild                (document.getElementsByTagName("li")[0]);            doc.childNodes[0].childNodes[0].nodeValue =                                                    "SQL";            document.getElementsByTagName                                ("ul")[0].appendChild(doc);        }    </script></head>  <body>    <h1>GeeksforGeeks<h1/>          <h3>        DOM createDocumentFragment() Method    </h3>          <p>        Click on the button to change        list element    </p>          <ul>        <li>Data Structure</li>        <li>Operating System</li>        <li>C Programming</li>        <li>DBMS</li>    </ul>          <button onclick = "myGeeks()">        Click Here!    </button></body>  </html>                    
Output:Before click on the button:After click on the button:
Supported Browsers: The browser supported by DOM createDocumentFragment() Method are listed below:
Google Chrome
Internet Explorer
Firefox
Opera
Safari
Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.
HTML-DOM
HTML-Methods
Picked
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
How to set the default value for an HTML <select> element ?
How to update Node.js and NPM to next version ?
How to set input type date in dd-mm-yyyy format using HTML ?
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?
Set a default value for a ttk Combobox in Tkinter?

Tkinter Combobox is used to add a drop-down menu to the Entry widget, making it useful to handle multiple data of any application. A Combobox widget can be created using the Combobox(arguments). However, for the particular need of an application, we can set the default value for the Combobox widget. It can be set by listing all the records in a variable that needs to be present in the Combobox. By specifying the index of the particular value in the current(index) method, we can set the default value in the Combobox widget.
#Import Tkinter library
from tkinter import *
from tkinter import ttk
#Create an instance of Tkinter frame or window
win= Tk()
#Set the geometry of tkinter frame
win.geometry("750x250")
#Create a Combobox
combobox= ttk.Combobox(win,state= "readonly")
combobox['values']=('C++','Java','Python')
combobox.current(2)
combobox.pack(pady=30, ipadx=20)
win.mainloop()
Running the above code will display a window that contains a Combobox with some default value. We can change the default value by changing the index of the current method.
C++ Program to check if tank will overflow, underflow or filled in given time

Given with the rate of filling the tank, height of a tank and radius of a tank and the task is to check whether the tank is overflow, underflow and filled in given time.
Input-: radius = 2, height = 5, rate = 10
Output-: tank overflow
Input-: radius = 5, height = 10, rate = 10
Output-: tank undeflow
Approach used below is as follows −
Input the rate of filling time, height and radius of a tank
Calculate the volume of a tank to find the original rate of flow of water.
Check for the conditions to determine the resultIf expected < original than tank will overflowIf expected > original than tank will underflowIf expected = original than tank will fill on time
If expected < original than tank will overflow
If expected > original than tank will underflow
If expected = original than tank will fill on time
Print the resultant output
Start
Step 1->declare function to calculate volume of tank
   float volume(int rad, int height)
   return ((22 / 7) * rad * 2 * height)
step 2-> declare function to check for overflow, underflow and filled
   void check(float expected, float orignal)
      IF (expected < orignal)
         Print "tank overflow"
      End
      Else IF (expected > orignal)
         Print "tank underflow"
      End
      Else
         print "tank filled"
      End
Step 3->Int main()
   Set int rad = 2, height = 5, rate = 10
   Set float orignal = 70.0
   Set float expected = volume(rad, height) / rate
   Call check(expected, orignal)
Stop
 Live Demo
#include <bits/stdc++.h>
using namespace std;
//calculate volume of tank
float volume(int rad, int height) {
   return ((22 / 7) * rad * 2 * height);
}
//function to check for overflow, underflow and filled
void check(float expected, float orignal) {
   if (expected < orignal)
      cout << "tank overflow";
   else if (expected > orignal)
      cout << "tank underflow";
   else
      cout << "tank filled";
}
int main() {
   int rad = 2, height = 5, rate = 10;
   float orignal = 70.0;
   float expected = volume(rad, height) / rate;
   check(expected, orignal);
   return 0;
}
tank overflow
How to insert a single line break in HTML?

Use the <br> tag to insert a single line break in HTML. You can try to run the following code to insert a line break using the <br> tag −
<!DOCTYPE html>
<html>
   <head>
      <title>HTML br Tag</title>
   </head>
   <body>
      <p>This is before the line break<br />
      and this after the line break.</p>
   </body>
</html>
Lexicographical Numbers in C++

Suppose we have an integer n. We have to return 1 to n in lexicographic order. So for example when 13 is given, then the output will be [1, 10, 11, 12, 13, 2, 3, 4, 5, 6, 7, 8, 9].
To solve this, we will follow these steps −
define one array ret of size n
define one array ret of size n
curr := 1
curr := 1
for i in range 0 to n – 1ret[i] := currif curr * 10 <= n, then set curr := curr * 10otherwiseif curr >= n, then curr := curr / 10increase curr by 1while curr is divisible by 10, then curr := curr / 10
for i in range 0 to n – 1
ret[i] := curr
ret[i] := curr
if curr * 10 <= n, then set curr := curr * 10
if curr * 10 <= n, then set curr := curr * 10
otherwiseif curr >= n, then curr := curr / 10increase curr by 1while curr is divisible by 10, then curr := curr / 10
otherwise
if curr >= n, then curr := curr / 10
if curr >= n, then curr := curr / 10
increase curr by 1
increase curr by 1
while curr is divisible by 10, then curr := curr / 10
while curr is divisible by 10, then curr := curr / 10
return ret
return ret
Let us see the following implementation to get better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
void print_vector(vector<auto> v){
   cout << "[";
   for(int i = 0; i<v.size(); i++){
      cout << v[i] << ", ";
   }
   cout << "]"<<endl;
}
class Solution {
   public:
   vector<int> lexicalOrder(int n) {
      vector <int> ret(n);
      int curr = 1;
      for(int i = 0; i < n; i++){
         ret[i] = curr;
         if(curr * 10 <= n){
            curr*= 10;
         } else {
            if(curr>= n)curr /= 10;
            curr += 1;
            while(curr % 10 == 0)curr/=10;
         }
      }
      return ret;
   }
};
   main(){
   Solution ob;
   print_vector(ob.lexicalOrder(20));
}
20
[1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 20, 3, 4, 5, 6, 7, 8, 9, ]
Difference between indexed array and associative array - GeeksforGeeks

22 Oct, 2021
An array is a collection of objects that contain a group of variables stored under the same name. All the elements belong to the same data type, i.e. string, integers, or lists. Keys are unique in the case of both indexed and associative arrays. 
Indexed array: Indexed array is an array with a numeric key. It is basically an array wherein each of the keys is associated with its own specific value. 
Example 1:
PHP
<?php  // Declaring an array$arr = array(1, 2, 3, 4, 5);  echo('Array : ');  // Print the arrayprint_r($arr);  ?>
Array : Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => 4
    [4] => 5
)

Example 2: Individual values can be assigned to the array indices values using integer index values as indicated in the below code snippet.
PHP
<?php    // Declaring an array$arr = array();  // Assigning values$arr[0] = 5;$arr[1] = 6;  print("Array : ");print_r($arr);  ?>
Array : Array
(
    [0] => 5
    [1] => 6
)

Associative array: An associative array is stored in the form of key-value pair. This type of array is where the key is stored in the numeric or string format. 
Example 1:
PHP
<?php    // Declaring an array$arr = array(      "Java" => "Spring Boot",       "Python" => "Django",       "PHP" => "CodeIgniter");  // Assigning valuesprint("Array : ");print_r($arr);  ?>
Array : Array
(
    [Java] => Spring Boot
    [Python] => Django
    [PHP] => CodeIgniter
)

The array[key] = value expression can be used to assign individual values as components of the array.   
Example 2:
PHP
<?php  // Declaring an array$arr = array();  // Declaring key-value pairs$arr['Python'] = "Django";$arr['Java'] = "SpringBoot";$arr['PHP'] = "CodeIgniter";  print("Array : ");print_r($arr);  ?>
Array : Array
(
    [Python] => Django
    [Java] => SpringBoot
    [PHP] => CodeIgniter
)

Difference between Indexed array and associative array:
PHP-array
PHP-function
PHP-Questions
Picked
Difference Between
PHP
Web Technologies
PHP
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 Method Overloading and Method Overriding in Java
Difference between Informed and Uninformed Search in AI
Difference between Internal and External fragmentation
Difference between HashMap and HashSet
How to Insert Form Data into Database using PHP ?
How to execute PHP code using command line ?
How to pop an alert message box using PHP ?
PHP in_array() Function
How to convert array to string in PHP ?
How to layout table cells, rows, and columns with JavaScript?

To layout tables correctly in JavaScript, use the tableLayout property. Set the property to fixed to set the layout.
You can try to run the following code to set the way to layout table cells, rows, and columns with JavaScript −
<!DOCTYPE html>
<html>
   <head>
      <style>
         table, td {
            border: 2px solid blue;
         }
         #myID {
            width: 100%;
         }
      </style>
   </head>
   <body>
      <button onclick = "display()">Set Layout Property</button>
      <table id = "myID">
         <tr>
            <td>This is a text for demo</td>
            <td>This is another text</td>
         </tr>
         <tr>
            <td>One</td>
            <td>1</td>
         </tr>
         <tr>
            <td>Two</td>
            <td>2</td>
         </tr>
         <tr>
            <td>Three</td>
            <td>3</td>
         </tr>
      </table>
      <script>
         function display() {
            document.getElementById("myID").style.tableLayout = "fixed";
         }
      </script>
   </body>
</html>
How to sort a String array in Java?

To sort a String array in Java, you need to compare each element of the array to all the remaining elements, if the result is greater than 0, swap them.
One solution to do so you need to use two loops (nested) where the inner loop starts with i+1 (where i is the variable of outer loop) to avoid repetitions in comparison.
Live Demo
import java.util.Arrays;

public class StringArrayInOrder {
   public static void main(String args[]) {
      String[] myArray = {"JavaFX", "HBase", "OpenCV", "Java", "Hadoop", "Neo4j"};
      int size = myArray.length;

      for(int i = 0; i<size-1; i++) {
         for (int j = i+1; j<myArray.length; j++) {
            if(myArray[i].compareTo(myArray[j])>0) {
               String temp = myArray[i];
               myArray[i] = myArray[j];
               myArray[j] = temp;
            }
         }
      }
      System.out.println(Arrays.toString(myArray));
   }
}
[HBase, Hadoop, Java, JavaFX, Neo4j, OpenCV]
You can also sort an array using the sort() method of the Arrays class.
String[] myArray = {"JavaFX", "HBase", "OpenCV", "Java", "Hadoop","Neo4j"};
Arrays.sort(myArray);
System.out.println(Arrays.toString(myArray));
Determinant of a Matrix | Practice | GeeksforGeeks

Given a square matrix of size N x N. The task is to find the determinant of this matrix.

Example 1:
Input:
N = 4
matrix[][] = {{1, 0, 2, -1},
              {3, 0, 0, 5},
              {2, 1, 4, -3},
              {1, 0, 5, 0}}
Output: 30
Explanation:
Determinant of the given matrix is 30.

Example 2:
Input:
N = 3
matrix[][] = {{1, 2, 3},
              {4, 5, 6},
              {7, 10, 9}}
Output: 12
Explanation:
Determinant of the given matrix is 12.


Your Task:
You don't need to read input or print anything. Complete the function determinantOfMatrix() that takes matrix and its size n as input parameters and returns the determinant of the matrix.

Expected Time Complexity: O(N4)
Expected Auxiliary Space: O(N2)

Constraints:
1 <= N <= 8
-10 <= mat[i][j] <= 10
0
cshubham439
This comment has been flagged for violating our community guidelines.
0
guptadish389
This comment was deleted.
0
guptadish389
This comment was deleted.
-6
kuvar07217 months ago
def determinantOfMatrix(self,matrix,n):       # Broken coder 
      # to be Pythonic       return(int(round(np.linalg.det(matrix))))
0
Darshan Agrawalla8 months ago
Darshan Agrawalla
Recursive Solution https://uploads.disquscdn.c...
-1
Aman lateef9 months ago
Aman lateef
Java Solution: 0.7s https://uploads.disquscdn.c...
-1
martial9 months ago
martial
https://gist.github.com/sur...
-1
martial9 months ago
martial
https://uploads.disquscdn.c...
-1
martial9 months ago
martial
https://uploads.disquscdn.c...
+15
Akshat Dhiman9 months ago
Akshat Dhiman
In Maths it is basic but in programming it is upto medium level and how 10mins avg is showing ;(  ? 
We strongly recommend solving this problem on your own before viewing its editorial. Do you still
                    want to view the editorial?
 Login to access your submissions. 

Problem


Contest

Reset the IDE using the second button on the top right corner.
Avoid using static/global variables in your code as your code is tested against multiple test cases and these tend to retain their previous values.
Passing the Sample/Custom Test cases does not guarantee the correctness of code. On submission, your code is tested against multiple test cases consisting of all possible corner cases and stress constraints.
You can access the hints to get an idea about what is expected of you as well as the final solution code.
You can view the solutions submitted by other users from the submission tab.
Pointers vs References in C++

Pointers are used to store the address of variable.
Type *pointer;
Type *pointer;
pointer = variable name;
When a variable is declared as reference, it becomes an alternative name for an existing variable.
Type &newname = existing name;
Type &pointer;
pointer = variable name;
The main differences between pointers and references are -
References are used to refer an existing variable in another name whereas pointers are used to store address of variable.
References are used to refer an existing variable in another name whereas pointers are used to store address of variable.
References cannot have a null value assigned but pointer can.
References cannot have a null value assigned but pointer can.
A reference variable can be referenced by pass by value whereas a pointer can be referenced but pass by reference.
A reference variable can be referenced by pass by value whereas a pointer can be referenced but pass by reference.
A reference must be initialized on declaration while it is not necessary in case of pointer.
A reference must be initialized on declaration while it is not necessary in case of pointer.
A reference shares the same memory address with the original variable but also takes up some space on the stack whereas a pointer has its own memory address and size on the stack.
A reference shares the same memory address with the original variable but also takes up some space on the stack whereas a pointer has its own memory address and size on the stack.
Ceil and floor of the dataframe in Pandas Python – Round up and Truncate

08 Oct, 2021
In this article, we will discuss getting the ceil and floor values of the Pandas Dataframe. First, Let’s create a dataframe.
Example:
Python3
# importing pandas and numpyimport pandas as pdimport numpy as np  # Creating a DataFramedf = pd.DataFrame({'Student Name': ['Anuj', 'Ajay', 'Vivek',                                    'suraj', 'tanishq', 'vishal'],                   'Marks': [55.3, 82.76, 95.23, 98.12,                             95.78, 90.56]}) df
 Output:
We can get the ceil value using the ceil() function. Ceil() is basically used to round up the values specified in it. It rounds up the value to the nearest greater integer.
Example: 
Python3
# using np.ceil to round to# nearest greater integer for# 'Marks'df['Marks'] = df['Marks'].apply(np.ceil) df
 Output:
We can get the floor value using the floor() function. Floor() is basically used to truncate the values. Basically, it truncates the values to their nearest smaller integer. 
Example: 
Python3
# using np.floor to# truncate the 'Marks' columndf['Marks'] = df['Marks'].apply(np.floor) df
 Output:
round() is also used in this purpose only as it rounds off the value according to their decimal digits. Here we can give that to how many decimal places we have to round off our data.
Example: 
Python3
# using round() to round up or# down acc. to their decimal digitsdf['Marks'] = df['Marks'].round(decimals=1) df
Output: 
 
varshagumber28
Python pandas-dataFrame
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
URL getUserInfo() method in Java with Examples

31 Dec, 2018
The getUserInfo() function is a part of URL class. The function getUserInfo() returns the UserInfo part of a specified URL.
Function Signature:
public String getUserInfo()
Syntax:
url.getUserInfo()
Parameter: This function does not require any parameter
Return Type: The function returns String Type
Below programs illustrates the use of getUserInfo() function:
Example 1: Given a URL we will get the UserInfo using the getUserInfo() function.
// Java program to show the use// of the function getUserInfo()  import java.net.*;  class Solution {    public static void main(String args[])    {        // url  object        URL url = null;          try {            // create a URL            url = new URL(                "https:// Arnab_Kundu@www.geeksforgeeks.org");              // get the  UserInfo            String _UserInfo = url.getUserInfo();              // display the URL            System.out.println("URL = " + url);              // display the  UserInfo            System.out.println(" UserInfo= "                               + _UserInfo);        }        // if any error occurs        catch (Exception e) {              // display the error            System.out.println(e);        }    }}
URL = https:// Arnab_Kundu@www.geeksforgeeks.org
 UserInfo=  Arnab_Kundu

Example 2: Now we will not provide any User Info and use the function to get the UserInfo and see the results.
// Java program to show the use// of the function getUserInfo()  import java.net.*;  class Solution {    public static void main(String args[])    {        // url  object        URL url = null;          try {            // create a URL            url = new URL("https:// www.geeksforgeeks.org");              // get the  UserInfo            String _UserInfo = url.getUserInfo();              // display the URL            System.out.println("URL = " + url);              // display the  UserInfo            System.out.println(" UserInfo= "                               + _UserInfo);        }        // if any error occurs        catch (Exception e) {              // display the error            System.out.println(e);        }    }}
URL = https:// www.geeksforgeeks.org
 UserInfo= null

Java-Functions
Java-net-package
Java-URL
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Go - Environment Setup

If you are still willing to set up your environment for Go programming language, you need the following two software available on your computer −
A text editor 
Go compiler
You will require a text editor to type your programs. Examples of text editors include Windows Notepad, OS Edit command, Brief, Epsilon, EMACS, and vim or vi.
The name and version of text editors can vary on different operating systems. For example, Notepad is used on Windows, and vim or vi is used on Windows as well as Linux or UNIX.
The files you create with the text editor are called source files. They contain program source code. The source files for Go programs are typically named with the extension ".go".
Before starting your programming, make sure you have a text editor in place and you have enough experience to write a computer program, save it in a file, compile it, and finally execute it.
The source code written in source file is the human readable source for your program. It needs to be compiled and turned into machine language so that your CPU can actually execute the program as per the instructions given. The Go programming language compiler compiles the source code into its final executable program.
Go distribution comes as a binary installable for FreeBSD (release 8 and above), Linux, Mac OS X (Snow Leopard and above), and Windows operating systems with 32-bit (386) and 64-bit (amd64) x86 processor architectures.
The following section explains how to install Go binary distribution on various OS.
Download the latest version of Go installable archive file from Go Downloads. The following version is used in this tutorial: go1.4.windows-amd64.msi.
It is copied it into C:\>go folder.
Extract the download archive into the folder /usr/local, creating a Go tree in /usr/local/go. For example −
tar -C /usr/local -xzf go1.4.linux-amd64.tar.gz
Add /usr/local/go/bin to the PATH environment variable.
Use the MSI file and follow the prompts to install the Go tools. By default, the installer uses the Go distribution in c:\Go. The installer should set the c:\Go\bin directory in Window's PATH environment variable. Restart any open command prompts for the change to take effect.
Create a go file named test.go in C:\>Go_WorkSpace.
package main

import "fmt"

func main() {
   fmt.Println("Hello, World!")
}
Now run test.go to see the result −
C:\Go_WorkSpace>go run test.go

Hello, World!


    64 Lectures 
     6.5 hours 

 Ridhi Arora

    20 Lectures 
     2.5 hours 

 Asif Hussain

    22 Lectures 
     4 hours 

 Dilip Padmanabhan

    48 Lectures 
     6 hours 

 Arnab Chakraborty

    7 Lectures 
     1 hours 

 Aditya Kulkarni

    44 Lectures 
     3 hours 

 Arnab Chakraborty
 Print
 Add Notes
 Bookmark this page
How to convert Python date in JSON format?

There is no standard JSON format for dates. Although JavaScript does have a standard date format that is human readable, sorts correctly, includes fractional seconds(which can help re-establish chronology) and  conforms to ISO 8601. You can convert a Python date to the JS date format using the strftime function and deserialize it using the client that needs this date. To get an ISO 8601 date in string format in Python 3, you can simply use the isoformat function. It returns the date in the ISO 8601 format. For example, if you give it the date 31/12/2017, it'll give you the string '2017-12-31T00:00:00'. You can use it as follows −
from datetime import datetime
my_date = datetime.now()
print(my_date.isoformat())
This will give the output −
2018-01-02T22:08:12.510696
In older python versions, you can use the strftime function to format the datetime object such that you get the desired result. 
from datetime import datetime
my_date = datetime.now()
print(my_date.strftime('%Y-%m-%dT%H:%M:%S.%f%z'))
This will give the output −
2018-01-02T22:10:05.284208
C library function - isupper()

The C library function int isupper(int c) checks whether the passed character is uppercase letter.
Following is the declaration for isupper() function.
int isupper(int c);
c − This is the character to be checked.
c − This is the character to be checked.
This function returns a non-zero value(true) if c is an uppercase alphabetic letter else, zero (false).
The following example shows the usage of isupper() function.
#include <stdio.h>
#include <ctype.h>

int main () {
   int var1 = 'M';
   int var2 = 'm';
   int var3 = '3';
    
   if( isupper(var1) ) {
      printf("var1 = |%c| is uppercase character\n", var1 );
   } else {
      printf("var1 = |%c| is not uppercase character\n", var1 );
   }
   
   if( isupper(var2) ) {
      printf("var2 = |%c| is uppercase character\n", var2 );
   } else {
      printf("var2 = |%c| is not uppercase character\n", var2 );
   }   
   
   if( isupper(var3) ) {
      printf("var3 = |%c| is uppercase character\n", var3 );
   } else {
      printf("var3 = |%c| is not uppercase character\n", var3 );
   }
   
   return(0);
}
Let us compile and run the above program that will produce the following result −
var1 = |M| is uppercase character
var2 = |m| is not uppercase character
var3 = |3| is not uppercase character


    12 Lectures 
     2 hours 

 Nishant Malik

    12 Lectures 
     2.5 hours 

 Nishant Malik

    48 Lectures 
     6.5 hours 

 Asif Hussain

    12 Lectures 
     2 hours 

 Richa Maheshwari

    20 Lectures 
     3.5 hours 

 Vandana Annavaram

    44 Lectures 
     1 hours 

 Amit Diwan
 Print
 Add Notes
 Bookmark this page
C Program to count the number of lines in a file?

In this program, we are going to learn how to find the total number of lines available in a text file using C program?
This program will open a file and read the file’s content character by character and finally return the total number of lines in the file. To count the number of lines we will check the available Newline (\n) characters.
Input:
File "test.text"
   Hello friends, how are you?
   This is a sample file to get line numbers from the file.
Output:
Total number of lines are: 2
This program will open a file and read the file’s content character by character and finally return the total number of lines in the file. To count the number of lines we will check the available Newline (\n) characters. This will check all the new line and count then and return the count.
#include<iostream>
using namespace std;
#define FILENAME "test.txt"
int main() {
   FILE *fp;
   char ch;
   int linesCount=0;
   //open file in read more
   fp=fopen(FILENAME,"r");
   if(fp==NULL) {
      printf("File \"%s\" does not exist!!!\n",FILENAME);
      return -1;
   }
   //read character by character and check for new line
   while((ch=fgetc(fp))!=EOF) {
      if(ch=='\n')
         linesCount++;
   }
   //close the file
   fclose(fp);
   //print number of lines
   printf("Total number of lines are: %d\n",linesCount);
   return 0;
}
How to set Heading alignment in HTML?

Headings in HTML have 6 tags, <h1> to <h6>. To set the heading alignment in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <h1> to <h6> tag, with the CSS property text-align. HTML5 do not support the align attribute of the heading tag, so the CSS style is used to set alignment.
Just keep in mind, the usage of style attribute overrides any style set globally. It will override any style set in the HTML <style> tag or external style sheet.
You can try to run the following code to set heading alignment in HTML
<!DOCTYPE html>
<html>
   <head>
      <title>HTML Document</title>
   </head>

   <body>
      <h1 style="text-align:center">Tutorial</h1>
      <p>Learn for free</p>
   </body>
</html>
Turn on the general log in MySQL?

To turn ON the general log, you need to use SET command.
 Following is the syntax −
set global general_log=ON;
Let us check the general log status with the help of SHOW command −
mysql> SHOW variables like '%general_log%';
This will produce the following output −
+------------------+---------------------+
| Variable_name    | Value               |
+------------------+---------------------+
| general_log      | OFF                 |
| general_log_file | DESKTOP-QN2RB3H.log |
+------------------+---------------------+
2 rows in set (0.06 sec)
Following is the query to turn on the general log −
mysql> set global general_log=ON;
Query OK, 0 rows affected (0.18 sec)
Let us check the status of general log once again −
mysql> SHOW variables like '%general_log%';
This will produce the following output −
+------------------+---------------------+
| Variable_name    | Value               |
+------------------+---------------------+
| general_log      | ON                  |
| general_log_file | DESKTOP-QN2RB3H.log |
+------------------+---------------------+
2 rows in set (0.01 sec)
You can change the location of general_log_file −
mysql> SET GLOBAL general_log_file = 'E:\mysqllog';
Query OK, 0 rows affected (0.11 sec)
Let us check the status of general_log_file once again −
mysql> SHOW variables like '%general_log%';
This will produce the following output −
+------------------+------------+
| Variable_name    | Value      |
+------------------+------------+
| general_log      | ON         |
| general_log_file | E:mysqllog |
+------------------+------------+
2 rows in set (0.01 sec)
Merge two arrays with alternating Values in JavaScript

Let’s say, we are required to write a function that takes in two arrays and returns a new array
that contains values in alternating order from first and second array. Here, we will just loop over
both the arrays simultaneously picking values from them one after the other and feed them into
the new array.
The full code for doing the same will be −
const arr1 = [34, 21, 2, 56, 17];
const arr2 = [12, 86, 1, 54, 28];
let run = 0, first = 0, second = 0;
const newArr = [];
while(run < arr1.length + arr2.length){
   if(first > second){
      newArr[run] = arr2[second];
      second++;
   }else{
      newArr[run] = arr1[first];
      first++;
   }
   run++;
};
console.log(newArr);
The console output for this code will be −
[
   34, 12, 21, 86, 2,
   1, 56, 54, 17, 28
]
Perl unless Statement

A Perl unless statement consists of a boolean expression followed by one or more statements.
The syntax of an unless statement in Perl programming language is −
unless(boolean_expression) {
   # statement(s) will execute if the given condition is false
}

If the boolean expression evaluates to false, then the block of code inside the unless statement will be executed. If boolean expression evaluates to true then the first set of code after the end of the unless statement (after the closing curly brace) will be executed.
The number 0, the strings '0' and "" , the empty list () , and undef are all false in a boolean context and all other values are true. Negation of a true value by ! or not returns a special false value.
#!/usr/local/bin/perl
 
$a = 20;
# check the boolean condition using unless statement
unless( $a < 20 ) {
   # if condition is false then print the following
   printf "a is not less than 20\n";
}
print "value of a is : $a\n";

$a = "";
# check the boolean condition using unless statement
unless ( $a ) {
   # if condition is false then print the following
   printf "a has a false value\n";
}
print "value of a is : $a\n";
First unless statement makes use of less than operator (<), which compares two operands and if first operand is less than the second one then it returns true otherwise it returns false. So when the above code is executed, it produces the following result −
a is not less than 20
value of a is : 20
a has a false value
value of a is : 


    46 Lectures 
     4.5 hours 

 Devi Killada

    11 Lectures 
     1.5 hours 

 Harshit Srivastava

    30 Lectures 
     6 hours 

 TELCOMA Global

    24 Lectures 
     2 hours 

 Mohammad Nauman

    68 Lectures 
     7 hours 

 Stone River ELearning

    58 Lectures 
     6.5 hours 

 Stone River ELearning
 Print
 Add Notes
 Bookmark this page
How does Python generate random numbers?

Standard distribution of Python has a random module that has functions for random number generation. Basic random() function returns a random floating point number between 0 and 1
>>> import random
>>> random.random()
0.5204702770265925
From same module, there is randrange() function which returns a random number between a sequential range.
>>> random.randrange(0,10)
4
There is also choice() function which randomly chooses an item from list or tuple
>>> random.choice([10,20,30,40,50])
40
>>> random.choice((10,20,30,40,50))
20
SaltStack - Salt through SSH

Salt executes commands in a remote system by using salt-minion. This is the normal behavior. In some scenarios, the remote system can be accessed only by the SSH protocol. For these scenarios, Salt provides an option to connect the remote system using the SSH protocol only and execute the command through the SSH layer.
Salt SSH is very easy to configure. The only needed configuration is to specify the remote system details in a special file called as the Roster file. This roster file is normally located in /etc/salt/roster. The roster file will have all the information regarding the remote system and how can we connect to it. Once the roster files are configured, all the Salt commands are executed using the salt-ssh instead of the salt command.
The Roster System is designed specifically for Salt SSH. This is designed as a pluggable system. The sole purpose of the roster system is to gather information about the remote system. The roster file is a YAML based configuration file containing remote system information as targets. These targets are a special data structure with a predefined set of attributes. A roster file contains one or more targets and each target is identified by a Salt ID.
The basic structure of the roster file is as follows −
<Salt ID>:
   host: <host name>
   user: <user name>
   passwd: <password of the user>

All the other attributes supported by the roster file is optional. They are as follows −
port − SSH port number.
port − SSH port number.
sudo − whether to run the command via sudo.
sudo − whether to run the command via sudo.
sudo_user − sudo user name.
sudo_user − sudo user name.
tty − true if sudo is enabled.
tty − true if sudo is enabled.
priv − private key.
priv − private key.
timeout − timeout for an SSH connection.
timeout − timeout for an SSH connection.
minion_opts − dictionary of minion opts.
minion_opts − dictionary of minion opts.
thin_dir − target system's storage directory for salt components.
thin_dir − target system's storage directory for salt components.
cmd_umask − umask to force for the salt-call command.
cmd_umask − umask to force for the salt-call command.
The sample roster file is as follows −
web:
   host: 192.168.2.1
   user: webuser
   passwd: secret
   sudo: True   
db:
   host: 192.168.2.2

Salt SSH will generate a default public/private key pairs for SSH logins. The default path will be /etc/salt/pki/master/ssh/salt-ssh.rsa. This key can be deployed to the remote system using the ssh-copy-id command as shown below.
ssh-copy-id -i /etc/salt/pki/master/ssh/salt-ssh.rsa.pub user@web.company.com

Executing a salt command is as simple as changing the salt cli command into salt-ssh as shown below.
salt-ssh '*' test.ping

Salt SSH provides an option (-r) to execute a raw command in the remote system bypassing the salt module and functions.
salt-ssh '*' -r 'ls'

Targeting the remote system in Salt SSH supports only glob and regex targets. Since Salt SSH is a separate module, it provides only limited options as of now and will provide more features in the near future.
 Print
 Add Notes
 Bookmark this page
Resolve the MySQL error 'TYPE=MyISAM'?

To fix the error, you just need to replace TYPE with ENGINE. The syntax to set the engine is as follows −
ENGINE = MyISAM;
The MySQL error occurs when TYPE is used. Let us see the same scenario while creating a table −
mysql> create table Customers
   −> (
   −> CustomerId int,
   −> CustomerName varchar(200)
   −> )TYPE = MyISAM;
The error is as follows −
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'TYPE = MyISAM' at line 5
To resolve the above error, replace TYPE with ENGINE as shown below −
mysql> create table Customers
   −> (
   −> CustomerId int,
   −> CustomerName varchar(200)
   −> )ENGINE = MyISAM;
Query OK, 0 rows affected (0.24 sec)
The “ENGINE = MyISAM” in MySQL updates successfully.