code-rag-bench/online-tutorials huggingface dataset:
Reading and writing files from/to Amazon S3 with Pandas | by Onel Harrison | Feb, 2021  | Towards Data Science

Write pandas data frame to CSV file on S3
> Using boto3
> Using s3fs-supported pandas API
Read a CSV file on S3 into a pandas data frame
> Using boto3
> Using s3fs-supported pandas API
Summary
There is an outstanding issue regarding dependency resolution when both boto3 and s3fs are specified as dependencies in a project. See this GitHub issue if you’re interested in the details.
This is still an issue as of 2021–02–19.
If you need both packages (e.g. to run the following examples in the same environment, or more generally to use s3fs for convenient pandas-to-S3 interactions and boto3 for other programmatic interactions with AWS), you will need to pin your s3fs to version “≤0.4” as a workaround (thanks Martin Campbell).
To follow along, you’ll need to install the following Python packages
boto3
s3fs (version ≤0.4)
pandas
python -m pip install boto3 pandas "s3fs<=0.4"
💭 You will notice that while we need to import boto3 and pandas in the following examples, we do not need to import s3fs despite needing to install the package. The reason is that we directly use boto3 and pandas in our code, but we won’t use the s3fs directly. Still, pandas needs it to connect with Amazon S3 under-the-hood.
pandas now uses s3fs for handling S3 connections. This shouldn’t break any code. However, since s3fs is not a required dependency, you will need to install it separately, like boto in prior versions of pandas. (GH11915).
Release notes for pandas version 0.20.1
You may want to use boto3 if you are using pandas in an environment where boto3 is already available and you have to interact with other AWS services too.
However, using boto3 requires slightly more code, and makes use of the io.StringIO (“an in-memory stream for text I/O”) and Python’s context manager (the with statement). Those are two additional things you may not have already known about, or wanted to learn or think about to “simply” read/write a file to Amazon S3.
I do recommend learning them, though; they come up fairly often, especially the with statement. But, pandas accommodates those of us who “simply” want to read and write files from/to Amazon S3 by using s3fs under-the-hood to do just that, with code that even novice pandas users would find familiar.
aws_credentials = { "key": "***", "secret": "***", "token": "***" }df = pd.read_csv("s3://...", storage_options=aws_credientials)
or
aws_credentials = { "key": "***", "secret": "***", "token": "***" }df.to_csv("s3://...", index=False, storage_options=aws_credentials)
Thank you for reading!
4 Cute Python Functions for Working with Dirty Data
Improving Code Quality in Python Codebases
How to recursively reverse a linked list
Watch videos covering a variety of topics in Computing at OnelTalksTech.com
GATE | GATE-CS-2015 (Set 3) | Question 65 - GeeksforGeeks

28 Jun, 2021
Consider three software items: Program-X, Control Flow Diagram of Program-Y and Control Flow Diagram of Program-Z as shown belowThe values of McCabe’s Cyclomatic complexity of Program-X, Program-Y and Program-Z respectively are(A) 4, 4, 7(B) 3, 4, 7(C) 4, 4, 8(D) 4, 3, 8Answer: (A)Explanation:
The cyclomatic complexity of a structured program[a] is defined
with reference to the control flow graph of the program, a directed
graph containing the basic blocks of the program, with an edge 
between two basic blocks if control may pass from the first to the
second. The complexity M is then defined as.

    M = E − N + 2P,

where

    E = the number of edges of the graph.
    N = the number of nodes of the graph.
    P = the number of connected components. 

Source: http://en.wikipedia.org/wiki/Cyclomatic_complexity


For first program X, E = 11, N = 9, P = 1,  So M = 11-9+2*1 = 4
For second program Y, E = 10, N = 8, p = 1, So M = 10-8+2*1 = 4
For Third program X, E = 22, N = 17, p = 1, So M = 22-17+2*1 = 7
Quiz of this Question
GATE-CS-2015 (Set 3)
GATE-GATE-CS-2015 (Set 3)
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
GATE | GATE CS 2019 | Question 27
GATE | GATE-IT-2004 | Question 66
GATE | GATE-CS-2014-(Set-3) | Question 65
GATE | GATE-CS-2016 (Set 2) | Question 48
GATE | GATE-CS-2006 | Question 49
GATE | GATE-CS-2004 | Question 3
GATE | GATE-CS-2017 (Set 2) | Question 42
GATE | GATE CS 2010 | Question 24
GATE | GATE-CS-2000 | Question 43
GATE | GATE CS 2021 | Set 1 | Question 47
Python Program for Print Number series without using any loop

In this article, we will learn about the solution to the problem statement given below −
Problem statement − Given Two number N and K, our problem is to subtract a number K from N until number(N) is greater than zero(0), once the N becomes negative or zero then we start adding K to it until that number become the original number(N).
For example,
N = 10
K = 4
Output will be: 10 6 2 -2 2 6 10
1. we call the function again and again until N is greater than zero (in every function 
   call we subtract K from N ).
2. Once the number becomes negative or zero we start adding K in each function call 
   until the number becomes the original number.
3. Here we used a single function for purpose of addition and subtraction but to switch 
   between addition or subtraction function we used a Boolean type variable flag.
Now let’s observe the implementation in Python
 Live Demo
def PrintNumber(N, Original, K, flag):
   #print the number
   print(N, end = " ")
   #if number become negative
   if (N <= 0):
      if(flag==0):
         flag = 1
      else:
         flag = 0
   if (N == Original and (not(flag))):
      return
   # if flag is true
   if (flag == True):
      PrintNumber(N - K, Original, K, flag)
   return
   if (not(flag)):
      PrintNumber(N + K, Original, K, flag);
   return
N = 10
K = 4
PrintNumber(N, N, K, True)
10 6 2 -2 2 6 10
Here all variables are declared in global namespace as shown in the image below −
In this article, we learned about the terminology for printing a number series without using any kind of looping construct in Python 3.x. Or earlier.
How to convert a matrix into a matrix with single column in R?

If we have a matrix then we might want to convert it to matrix with single column for some analytical purpose such as multiplying with a vector that has the length equal to the total number of elements as in the matrix. Thus, the matrix can be converted to a single column matrix by using matrix function itself but for this we would need to nullify the column names and row names.
Live Demo
> M1<-matrix(rnorm(20),nrow=5)
> M1
        [,1]        [,2]       [,3]      [,4]
[1,] -0.8067677 1.9855697 -2.5012312 1.01283626
[2,] -0.5107091 0.4632027 -1.3966282 0.02534344
[3,] -0.5564871 0.2924344 -0.8991352 -0.50715002
[4,] 0.2411252 -0.5139827 -1.3272964 -0.50694324
[5,] -0.5753370 -1.2357388 0.2028664 0.26498877
> matrix(M1,dimnames=list(t(outer(colnames(M1),rownames(M1),FUN=paste)),NULL))
         [,1]
[1,] -0.80676768
[2,] -0.51070906
[3,] -0.55648712
[4,] 0.24112516
[5,] -0.57533702
[6,] 1.98556973
[7,] 0.46320275
[8,] 0.29243441
[9,] -0.51398265
[10,] -1.23573882
[11,] -2.50123125
[12,] -1.39662824
[13,] -0.89913524
[14,] -1.32729635
[15,] 0.20286643
[16,] 1.01283626
[17,] 0.02534344
[18,] -0.50715002
[19,] -0.50694324
[20,] 0.26498877
Live Demo
> M2<-matrix(rpois(20,5),ncol=2)
> M2
[,1] [,2]
[1,] 6 1
[2,] 6 7
[3,] 4 5
[4,] 6 5
[5,] 4 5
[6,] 5 4
[7,] 4 9
[8,] 4 6
[9,] 3 6
[10,] 8 10
> matrix(M2,dimnames=list(t(outer(colnames(M2),rownames(M2),FUN=paste)),NULL))
[,1]
[1,] 6
[2,] 6
[3,] 4
[4,] 6
[5,] 4
[6,] 5
[7,] 4
[8,] 4
[9,] 3
[10,] 8
[11,] 1
[12,] 7
[13,] 5
[14,] 5
[15,] 5
[16,] 4
[17,] 9
[18,] 6
[19,] 6
[20,] 10
Live Demo
> M3<-matrix(sample(0:9,20,replace=TRUE),ncol=10)
> M3
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,] 2 2 6 1 7 3 8 6 1 2
[2,] 8 0 4 7 8 8 8 2 1 3
> matrix(M3,dimnames=list(t(outer(colnames(M3),rownames(M3),FUN=paste)),NULL))
[,1]
[1,] 2
[2,] 8
[3,] 2
[4,] 0
[5,] 6
[6,] 4
[7,] 1
[8,] 7
[9,] 7
[10,] 8
[11,] 3
[12,] 8
[13,] 8
[14,] 8
[15,] 6
[16,] 2
[17,] 1
[18,] 1
[19,] 2
[20,] 3
SQL Tryit Editor v1.6

SELECT Orders.OrderID, Employees.LastName, Employees.FirstName
FROM Orders
RIGHT JOIN Employees
ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;
​
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, Opera, and Edge(79).
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.
How to remove white spaces from a string using jQuery ?

22 Mar, 2021
In this article, we will see how to remove the white spaces from string using jQuery. To remove the white spaces, we will use trim() method. The trim() method is used to remove the white spaces from the beginning and end of a string.
Syntax:
jQuery.trim( str )
Parameters: This method accepts a single parameter string that is to be trimmed.
In this case, we write string containing white spaces in <pre> tag and then apply trim() method to remove all white spaces from starting and ending position. After removing the white spaces we use html() method to display the trimmed string.
Example:
HTML
<!DOCTYpe html><html>  <head>    <title>        How to remove white space from        a string using jQuery?    </title>      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js">    </script>      <script>        $(document).ready(function () {            $("h1").css("color", "green");            $("button").click(function () {                $(".str").html("String without whitespaces");                var str = $(".string").text();                var trimStr = $.trim(str);                $(".res-string").html(trimStr);            })        });    </script></head>  <body>    <h1>GeeksforGeeks</h1>      <h3>        How to remove white space from        a string using jQuery?    </h3>      <h4>String containing white spaces</h4>    <pre class="string">    GeeksforGeeks       </pre>      <button>Trim String</button>      <h4 class="str"></h4>    <pre class="res-string"></pre></body>  </html>
Output:
HTML-Questions
HTML-Tags
jQuery-Methods
jQuery-Questions
HTML
JQuery
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
String Alignment in Python f-string

28 Jul, 2020
Text Alignment in Python is useful for printing out clean formatted output. Some times the data to be printed varies in length which makes it look messy when printed. By using String Alignment the output string can be aligned by defining the alignment as left, right or center and also defining space (width) to reserve for the string.
Approach : We will be using the f-strings to format the text. The syntax of the alignment of the output string is defined by ‘<‘, ‘>’, ‘^’ and followed by the width number.
Example 1 : For Left Alignment output string syntax define ‘<‘ followed by the width number.
# here 20 spaces are reserved for the # particular output string. And the string# is printed on the left sideprint(f"{'Left Aligned Text' : <20}")
Output :
Left Aligned Text
Example 2 : For Right Alignment output string syntax define ‘>’ followed by the width number.
# here 20 spaces are reserved for the # particular output string. And the string# is printed on the right sideprint(f"{'Right Aligned Text' : >20}")
Output :
  Right Aligned Text
Example 3 : For Center Alignment output string syntax define ‘^’ followed by the width number.
# here 20 spaces are reserved for the # particular output string. And the string# is printed in the middleprint(f"{'Centered' : ^10}")
Output :
 Centered 
Example 4 : Printing variables in Aligned format
# assigning strings to the variablesleft_alignment = "Left Text"center_alignment = "Centered Text"right_alignment = "Right Text"  # printing out aligned textprint(f"{left_alignment : <20}{center_alignment : ^15}{right_alignment : >20}")
Left Text            Centered Text           Right Text

Example 5 : Printing out multiple list values in aligned column look.
# assigning list values to the variablesnames = ['Raj', 'Shivam', 'Shreeya', 'Kartik']marks = [7, 9, 8, 5]div = ['A', 'A', 'C', 'B']id = [21, 52, 27, 38]  # printing Aligned Headerprint(f"{'Name' : <10}{'Marks' : ^10}{'Division' : ^10}{'ID' : >5}")  # printing values of variables in Aligned mannerfor i in range(0, 4):    print(f"{names[i] : <10}{marks[i] : ^10}{div[i] : ^10}{id[i] : >5}")
Name        Marks    Division    ID
Raj           7         A        21
Shivam        9         A        52
Shreeya       8         C        27
Kartik        5         B        38

python-string
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
How to create a nested webpage in HTML ?

25 Aug, 2021
When the content of one completely different webpage is embedded into another webpage, it is called a nested webpage. In simple words, a webpage that is inside another webpage of a completely different domain.
 In this article, we are going to learn how to create a nested webpage. There are two methods to create a nested webpage. They are as follows.
Using <iframe> tagUsing <embed> tag
Using <iframe> tag
Using <embed> tag
1. Using <iframe> tag:
The iframe in HTML stands for Inline Frame. The “iframe” tag defines a rectangular region within the document in which the browser can display a separate document, including scrollbars and borders. An inline frame is used to embed another document within the current HTML document
 
Syntax:
<iframe src="URL"></iframe>
It can take the height and width of the inline frame as attribute.
Example:
HTML
<!DOCTYPE html><html>   <head></head>   <body>      <h1>        Creating a Nested Webpage using         'iframe' Tag: Geeksforgeeks      </h1>        <iframe src="https://www.geeksforgeeks.org"               height="500px" width="1000px">      </iframe>   </body></html>
Output:
2. Using <embed> tag:
The <embed> tag in HTML is used for embedding external applications which are generally multimedia content like audio or video into an HTML document. But another raw HTML content can be embedded using this tag. We can use this feature to create a nested webpage.
Syntax:
<embed src="URL" type="text/html" /> 
Example:
HTML
<!DOCTYPE html><html>   <head></head>   <body>      <h1>        Creating a Nested Webpage using        'embed' Tag: Geeksforgeeks      </h1>        <embed src="https://www.geeksforgeeks.org"           type="text/html" />   </body></html>
Output:
The website can prevent you from embedding their content due to copyright issues. So it is mandatory to have proper permission and authorization before using another webpage as a nested webpage inside your website.
HTML-Questions
Picked
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
REST API (Introduction)
Design a Tribute Page using HTML & CSS
Build a Survey Form using HTML and CSS
Design a web page using HTML and CSS
Angular File Upload
Installation of Node.js on Linux
How to create footer to stay at the bottom of a Web page?
How do you run JavaScript script through the Terminal?
Node.js fs.readFileSync() Method
How to set space between the flexbox ?
How to get the Response status code in Golang?

Response status codes are the numbers that we get in response that signify what type of response we received from the server when we asked for something from it.
There are different status codes that one gets from the response, and these are mainly divided into five categories.
Generally, the status codes are divided into these five classes.
1xx (Informational)
1xx (Informational)
2xx (Successful)
2xx (Successful)
3xx (Redirection)
3xx (Redirection)
4xx (Client Error)
4xx (Client Error)
5xx (Server Error)
5xx (Server Error)
In this article, we will try to get two or more of these status codes.
Let's start with a basic HTTP request to the google.com URL. Once we do that, we will get the response from the server and that response will contain the status code.
Consider the code shown below.
package main

import (
   "fmt"
   "log"
   "net/http"
)

func main() {
   resp, err := http.Get("https://www.google.com")
   if err != nil {
      log.Fatal(err)
   }

   fmt.Println("The status code we got is:", resp.StatusCode)
}
If we run the command go run main.go on the above code, then we will get the following output in the terminal.
The status code we got is: 200
Each status code also holds a StatusText with itself, which we can also print with the statusCode.
Consider the code shown below.
package main

import (
   "fmt"
   "log"
   "net/http"
)

func main() {
   resp, err := http.Get("https://www.google.com")
   if err != nil {
      log.Fatal(err)
   }

   fmt.Println("The status code we got is:", resp.StatusCode)
   fmt.Println("The status code text we got is:", http.StatusText(resp.StatusCode))
}
If we run the command go run main.go on the above code, then we will get the following output in the terminal.
The status code we got is: 200
The status code text we got is: OK
We were able to get the status code 200, as the URL was available at the moment. In case we make a request to a URL which isn't active, we will get a 404 status code.
Consider the code shown below.
package main

import (
   "fmt"
   "log"
   "net/http"
)

func main() {
   resp, err := http.Get("https://www.google.com/apple")
   if err != nil {
      log.Fatal(err)
   }

   fmt.Println("The status code we got is:", resp.StatusCode)
   fmt.Println("The status code text we got is:", http.StatusText(resp.StatusCode))
}
If we run the command go run main.go on the above code, then we will get the following output in the terminal.
The status code we got is: 404
The status code text we got is: Not Found
PHP | imagepng() Function

29 Oct, 2021
The imagepng() function is an inbuilt function in PHP which is used to display image to browser or file. The main use of this function is to view an image in the browser, convert any other image type to PNG and applying filters to the image.
Syntax:
bool imagepng( resource $image, int $to, int $quality, int $filters)
Parameters: This function accepts three parameters as mentioned above and described below:
$image: It specifies the image resource to work on.
$to (Optional): It specifies the path to save the file to.
$quality (Optional): It specifies the quality of the image.
$filters (Optional): It specifies the filters to apply to the image which help in reducing the image size.
Return Value: This function returns TRUE on success or FALSE on error.
Below examples illustrate the imagepng() function in PHP:
Example 1: In this example we will be viewing an image in browser.
php
<?php  // Load an image from PNG URL$im = imagecreatefrompng('https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');  // View the loaded image in browser using imagepng() functionheader('Content-type: image/png');  imagepng($im);imagedestroy($im);?>
Output:
Example 2: IN this example we will convert JPEG into PNG.
php
<?php  // Load an image from JPEG URL$im = imagecreatefromjpeg('https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');  // Convert the image into PNG using imagepng() functionimagepng($im, 'converted.png');imagedestroy($im);?>
Output:
This will save the PNG version of image in the same folder where your PHP script is.
Program 3: In this example we will use filters.
php
<?php  // Create an image instance$im = imagecreatefrompng('https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png');  // Save the image as image1.pngimagepng($im, 'image1.png');  // Save the image as image2.png with all filters to disable size compressionimagepng($im, 'image2.png', null, PNG_ALL_FILTERS);  imagedestroy($im);?>
Output:
This will save the image1.png as compressed and image2.png as uncompressed image
Reference: https://www.php.net/manual/en/function.imagepng.php
akshaysingh98088
PHP-function
PHP-Imagick
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Insert Form Data into Database using PHP ?
How to convert array to string in PHP ?
How to Upload Image into Database and Display it using PHP ?
How to check whether an array is empty using PHP?
PHP | Converting string to Date and DateTime
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
HTML <u> Tag

17 Mar, 2022
The <u> tag in HTML stands for underline, and it’s used to underline the text enclosed within the <u> tag. This tag is generally used to underline misspelled words. This tag requires a starting as well as ending tag.
Syntax:  
<u> Contents... </u>
Note: This tag is depreciated from HTML 4.1 and redefined in HTML 5 using CSS text-decoration property instead.Below examples illustrates the <u> tag in HTML:Example 1: 
HTML
<html>         <body>         <h1>GeeksforGeeks</h1>         <h2><u> Tag</h2>           <p>GeeksforGeeks: A <u>computer science</u>                                portal for geeks</p>       </body>     </html>                    
Output:  
Example 2: Alternate way of <u> tag to underline the text. 
HTML
<html>     <head>         <title>u Tag</title>         <style>             body {                 text-align:center;             }             .gfg {                 font-size:40px;                 font-weight:bold;                 color:green;             }             .geeks {                 font-size:25px;                 font-weight:bold;             }             p {                font-size:20px;            }            span {                text-decoration:underline;             }        </style>     </head>     <body>         <div class = "gfg">GeeksforGeeks</div>         <div class = "geeks"><u> Tag</div>           <p>GeeksforGeeks: A <span>computer science</span>                                       portal for geeks</p>       </body> </html>                    
Output:  
Supported Browsers: 
Google Chrome
Internet Explorer
Firefox
Opera
Safari
 
arorakashish0911
shubhamyadav4
hritikbhatnagar2182
HTML-Tags
HTML
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?
REST API (Introduction)
Hide or show elements in HTML using display property
How to set the default value for an HTML <select> element ?
How to set input type date in dd-mm-yyyy format using HTML ?
CSS to put icon inside an input element in a form
Types of CSS (Cascading Style Sheet)
HTTP headers | Content-Type
PostgreSQL – CREATE TABLESPACE

08 Feb, 2021
In PostgreSQL a tablespace is used to map a logical name to a physical location on disk. In the simplest word, we can understand tablespace as a location on the disk where all database objects of PostgreSQL are stored. These objects can be an index or a table etc.
PostgreSQL has two default tablespaces:
pg_defaulttablespace is used to store user data.
pg_globaltablespace is used to store the global data.
Tablespaces in general are used to manage and control the disk layout of PostgreSQL. There are two main advantages of using tablespaces:
It comes in handy when an initialized cluster in a partition runs out of space. The tablespace can here further be used to create a new tablespace in a different partition altogether until your configuration is adjusted for the lack of space on the previous partition.
The database performance can be optimized using tablespaces.
Syntax:
CREATE TABLESPACE tablespace_name
OWNER user_name
LOCATION directory_path;

It is also important to note that the name of the tablespace must not start with pg_, as these are reserved for the system tablespaces.
Example:
The following statement uses the CREATE TABLESPACE to create a new tablespace called gfg with the physical location c:\data\gfg.
CREATE TABLESPACE gfg
LOCATION 'C:\data\gfg';

To list all tablespaces in the current PostgreSQL database server, the following command can be used:
\db

Output:
The below command shows more information such as size and access privileges:
\db+

The result will be similar to the image depicted below:
postgreSQL-managing-table
PostgreSQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to create array using given columns, rows, and tables in R ?

24 Sep, 2021
In this article, we will discuss how to create an array using given columns, rows, and tables in R Programming Language. The array is created using the array() function.
Syntax: Array(vector.., dim=c(row, columns, tables))
Parameter:
x: vector
dim: values used to create array
Example 1: Creating a simple array with 2 rows, 3 columns, 1 table
The below example will create an array of 3×3 matrices with 1 table.
R
vector1 <- c(0,1,2)vector2 <- c(3,4,5) data <- array(c(vector1,vector2),dim = c(2,3,1))print(data)
Output: 
   [,1] [,2] [,3]
[1,]    0    2    4
[2,]    1    3    5
The above array is created with 2 rows and 3 columns.
Example 2: Creating an array using 3 rows, 3 columns, and 2 tables.
Here we will create an array with 3 rows, 3 columns, and 2 tables. 
R
vector1 <- c(1:15)vector2 <- c(16:30) data <- array(c(vector1,vector2),dim = c(3,3,2))print(data)
Output: 
 
sweetyty
Picked
R-Arrays
R Language
R Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to change any data type into a String in Python?

24 Jul, 2020
Python defines type conversion functions to directly convert one data type to another which is useful in day to day and competitive programming. A string is a sequence of characters. Strings are amongst the most popular types in Python. We can create them simply by enclosing characters in quotes.
Example : Creating strings in different ways :
# creating string using ' 'str1 = 'Welcome to the Geeks for Geeks !'print(str1)  # creating string using " "str2 = "Welcome Geek !"print(str2)  # creating string using ''' '''str3 = '''Welcome again'''print(str3)
Output :
Welcome to the Geeks for Geeks!
Welcome Geek!
Welcome again
There are two ways for changing any data type into a String in Python :
Using the str() functionUsing the __str__() function
Using the str() function
Using the __str__() function
Method 1 : Using the str() functionAny built-in data type can be converted into its string representation by the str() function. Built-in data type in python include:- int, float, complex, list, tuple, dict etc.Syntax :
str(built-in data type)
Example :
# a is of type inta = 10print("Type before : ", type(a))  # converting the type from int to stra1 = str(a)print("Type after : ", type(a1))  # b is of type floatb = 10.10print("\nType before : ", type(b))  # converting the type from float to strb1 = str(b)print("Type after : ", type(b1))  # type of c is listc = [1, 2, 3]print("\nType before :", type(c))  # converting the type from list to strc1 = str(c)print("Type after : ", type(c1))  # type of d is tupled = (1, 2, 3)print("\nType before:-", type(d))  # converting the type from tuple to strd1 = str(d)print("Type after:-", type(d1))
Output:
Type before : <class 'int'>
Type after : <class 'str'>

Type before : <class 'float'>
Type after : <class 'str'>

Type before : <class 'list'>
Type after : <class 'str'>

Type before : <class 'tuple'>
Type after : <class 'str'>

Method 2 : Defining __str__() function for a user defined class to be converted to string representation. For a user defined class to be converted to string representation, __str__() function needs to be defined in it.
Example :
# class additionclass addition:    def __init__(self):        self.a = 10        self.b = 10      # defining __str__() function    def __str__(self):        return 'value of a = {} value of b = {}'.format(self.a, self.b)  # creating object adad = addition()print(str(ad))  # printing the typeprint(type(str(ad)))
Output:
value of a =10 value of b =10
<class 'str'>
python-basics
python-string
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How To Fold Legend into Two Rows in ggplot2 in R

14 Sep, 2021
In this article, we are going to see how to draw a ggplot2 legend with two Rows in R Programming Language.
If we want to draw ggplot2 Legend with two rows, we have to add guides and guide_legend functions to the theme() function. Inside guides() function, we take parameter named color, which has call to guide_legend() guide function as value. 
Inside the guide_legend() function, we take an argument called nrow, which has the desired number of rows of legend as value.
Syntax : guide_legend(nrow)
Parameter :  
nrow : The Desired Number of rows of legend.
Return : Legend Guides for various scales
Dataframe in use:
  Batch Students                        Class
1  2017     2300                DSA Essential
2  2018     1200                 Placement100
3  2019     3500                  C++: Expert
4  2020     1400     Web Development Bootcamp
5  2021      120 Android Development Bootcamp
To Create an R plot, we use ggplot() function, and to make it a scatter plot we add geom_point() function, assign this whole plot to gplot data object. Let us first create a regular plot so that the difference is apparent.
Example: Default legend
R
library("ggplot2")    # Create a DataFramedata <- data.frame(Batch = c(2017, 2018, 2019, 2020, 2021),                   Students = c(2300, 1200, 3500, 1400, 120),                   Class = c("DSA Essential", "Placement100",                             "C++: Expert", "Web Development Bootcamp",                             "Android DevelopmentBootcamp"))  # Create a ggplot2 scatter plotggplot(data, aes(Batch, Students, color = Class)) +geom_point(size = 4)
Output:
Now to fold the legend, add guides() function with color as guide_legend() together with parameter nrow=2, which folds legend into two-row.
Example: Legend folded into 2 rows
R
library("ggplot2")    # Create a DataFramedata <- data.frame(Batch = c(2017, 2018, 2019, 2020, 2021),                   Students = c(2300, 1200, 3500, 1400, 120),                   Class = c("DSA Essential", "Placement100",                              "C++: Expert", "Web Development Bootcamp",                              "Android Development Bootcamp"))  # Create a ggplot2 scatter plotggplot(data, aes(Batch, Students, color = Class)) + geom_point(size = 4) + guides(color = guide_legend(nrow = 2))
Output:
Picked
R-ggplot
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Working with the Python Debugger

22 Jun, 2020
Python Debugger may be a new word for the beginner developers . In this post , we will try to explain the meaning of Debugging and Debugging with Python . 
Debugging means the complete control over the program execution. Developers use debugging to overcome program from any bad issues. So debugging is a healthier process for the program and keeps the diseases bugs far away. Python also allows developers to debug the programs using pdb module that comes with standard Python by default. We just need to import pdb module in the Python script. Using pdb module, we can set breakpoints in the program to check the current status. We can Change the flow of execution by using  jump,  continue statements . Let’s understand debugging with a Python program.
Example:
Python3
# Program to print Multiplication # table of a Numbern=5for x in range(1,11) :  print( n , '*' , x , '=' , n*x )
Output:
5 * 1 = 5
5 * 2 = 10
5 * 3 = 15
5 * 4 = 20
5 * 5 = 25
5 * 6 = 30
5 * 7 = 35
5 * 8 = 40
5 * 9 = 45
5 * 10 = 50
This program simply print multiplication table but now we need to debug the loop steps using set_trace() function call to pdb module .
Example:
Python3
# Python Program to print Multiplication Table# We want to debug the for loop so we use# set_trace() call to pdb module  import pdb    # It means , the Start of Debugging Modepdb.set_trace()  n=5for x in range(1,11) :  print( n , '*' , x , '=' , n*x )
Output:
 list command to see entire program .
list command
 list 3 , 6  to see the program lines from 3 to 5 only .
list lines command in pdb debugger
 
 break command to stop the program execution at particular line .
break command in pdb debugger
 continue command to see the next step in the loop .
continue command in pdb debugger
jump command allows us to go on any particular line in the program .
jump command in pdb debugger
 pp command to see variable value at the current position in the program .
pp command in pdb debugger
disable command to disable the current line output and we can use continue command to skip this line in program. We use  quit or  exit command to come outside the debugging mode .
Debugging helps developers to analyze programs line by line. Developers see the every interpreted line by using debugging mode in programs. Python comes with by default debugger that is easy to import and use. So it is good to start with debugger when confused about execution of large loops, current variable values and all . 
python-utility
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
Python | os.path.join() method
How to drop one or multiple columns in Pandas Dataframe
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | Get unique values from a list
Python | datetime.timedelta() function
How to Generate Barcode in Python?

05 Sep, 2020
In this article, we are going to write a short script to generate barcodes using Python. We’ll be using the python-barcode module which is a fork of the pyBarcode module. This module provides us the functionality to generate barcodes in SVG format. Pillow is required to generate barcodes in image formats (such as png or jpg).
python-barcode: This module is used to create bar codes as SVG objects. It provides us the power to create different standard types of barcodes such as EAN-8, EAN-13, EAN-14, UPC-A, JAN, ISBN-10, ISBN-13, and many more. To install this module type the below command in the terminal.
pip install python-barcode 
Pillow: This is used to create the barcodes in the image format. To install this module type the below command in the terminal.
pip install pillow

Here, we are going to generate a barcode in the EAN-13 format. First, let’s generate it as an SVG file.
Python3
# import EAN13 from barcode modulefrom barcode import EAN13  # Make sure to pass the number as stringnumber = '5901234123457'  # Now, let's create an object of EAN13# class and pass the numbermy_code = EAN13(number)  # Our barcode is ready. Let's save it.my_code.save("new_code")
Output:
Generated barcode as SVG file
Now, let’s generate the same barcode in PNG format.
Python3
# import EAN13 from barcode modulefrom barcode import EAN13  # import ImageWriter to generate an image filefrom barcode.writer import ImageWriter  # Make sure to pass the number as stringnumber = '5901234123457'  # Now, let's create an object of EAN13 class and # pass the number with the ImageWriter() as the # writermy_code = EAN13(number, writer=ImageWriter())  # Our barcode is ready. Let's save it.my_code.save("new_code1")
Output:
Generated barcode as PNG file
python-utility
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Select Subset of DataTable Columns in R

23 Sep, 2021
In this article, we will discuss how to select a subset of data table columns in R programming language.
Let’s create a data table using a matrix. First, we need to load data.table package in the working space.
Installation
install.packages(“data.table”)                         
Loading
library(“data.table”) 
Dataset in use:
We can select a subset of datatable columns by index operator – []
Syntax:
datatable[ ,  c(columns), with = FALSE]
Where,
datatable is the input data table
columns are the columns in the datatable to be selected
with =FALSE is an optional parameter
Example: R program to select subset of columns from the data table
R
# load data.table packagelibrary("data.table")  # create data table with matrix with 20 elements# 4 rows and 5 columnsdata= data.table(matrix(1:20, nrow=4,ncol = 5))               # display the subset that include v1 and v3 columnsprint(data[ ,  c("V1", "V3"), with = FALSE])  # display the subset that include v1 , v2 and v3 columnsprint(data[ ,  c("V1","V2", "V3"), with = FALSE])  # display the subset that include v2,v3,v4 and v5 columnsprint(data[ ,  c("V2", "V3","V4","V5"), with = FALSE])
Output:
Using ! operator before columns can be enough to get the job done by this approach. Here we are not including the subset that is selected from the data table
Syntax:
datatable[ ,  !c(columns), with = FALSE]
where,
datatable is the input data table
columns are the columns in the datatable to be selected
Example: R program to select columns from datatable
R
# load data.table packagelibrary("data.table")  # create data table with matrix with 20 elements# 4 rows and 5 columnsdata= data.table(matrix(1:20, nrow=4,ncol = 5))               # display the subset that exclude v1 and v3 columnsprint(data[ ,  !c("V1", "V3"), with = FALSE])  # display the subset that exclude  v1 , v2 and v3 columnsprint(data[ ,  !c("V1","V2", "V3"), with = FALSE])  # display the subset that exclude v2,v3,v4 and v5 columnsprint(data[ ,  !c("V2", "V3","V4","V5"), with = FALSE])
Output:
Picked
R DataTable
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
jQuery UI Button disable() Method

21 Dec, 2021
jQuery UI consists of GUI widgets, visual effects, and themes implemented using HTML, CSS, and jQuery. jQuery UI is great for building UI interfaces for the webpages. The jQuery UI Button disable() method is used to disable the button widget. It does not accept any parameter.
Syntax:
$(".selector").button("disable");
CDN Link: First, add jQuery UI scripts needed for your project.
<link rel=”stylesheet” href=”//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css”><script src=”//code.jquery.com/jquery-1.12.4.js”></script><script src=”//code.jquery.com/ui/1.12.1/jquery-ui.js”></script>
 
Example: This example describes the uses of jQuery UI Button disable() method.
HTML
<!doctype html><html lang="en">  <head>    <meta charset="utf-8">    <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css">    <script src="//code.jquery.com/jquery-1.12.4.js"></script>    <script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script></head>  <body>    <center>        <h1 style="color: green;">            GeeksforGeeks        </h1>          <h3>jQuery UI Button disable() Method</h3>          <button>GFG Button</button>        <br><br>          <input type="button" id="GFG"             style="padding: 5px 15px;"             value="Disable the Button Widget">    </center>      <script>        $(document).ready(function () {            $("button").button();              $("#GFG").on('click', function () {                $("button").button("disable");            });        });    </script></body>  </html>
Output:
Reference: https://api.jqueryui.com/button/#method-disable
jQuery-UI
jQuery-UI-Button
JQuery
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Neo4j Create Index

06 Jun, 2021
In neo4j you can create index for both property and nodes. Indexing is data structure that helps faster performance on retrieval operation on database. There is special features in neo4j indexing once you create indexing that index will manage itself and keep it up to date whenever changes made on the database. Similarly CREATE INDEX ON statement will provide the indexing. 
Example: In the below example we create index on the Tag property of all nodes with the GeeksforGeeks label.  
$ CREATE INDEX ON:GeeksforGeeks(Tag)
Output:  
Note: When you create an index, neo4j will create the index in background. If your database is large it will take some time.  
Note: When you create an index, neo4j will create the index in background. If your database is large it will take some time.  
View Index: Index and Constraint is the part of the database schema. To view the indexes you have to use :schema command, like below example.  
:schema
Output:  
 
Index hints: If the indexing is exist on your database then it will be helpful when you trigger similar type of queries, it improves the performance. You can create an index hint by including USING INDEX ... in your query.  
$ MATCH (a:GeeksforGeeks {Tag: "A Computer Science Portal"}) 
USING INDEX a:GeeksforGeeks(Tag) 
RETURN a 
Output: Note: You can also provide multiple hints. Simply add a new USING INDEX for each index you’d like to enforce.
Note: You can also provide multiple hints. Simply add a new USING INDEX for each index you’d like to enforce.
 
skyridetim
ruhelaa48
DBMS
DBMS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Ruby | Hash fetch function

07 Jan, 2020
Hash#fetch() is a Hash class method which returns a value from the hash for the given key. With no other arguments, it will raise a KeyError exception.
Syntax: Hash.fetch()
Parameter: Hash values
Return: value from the hash for the given key
Example #1 :
# Ruby code for Hash.fetch() method  # declaring Hash valuea = { "a" => 100, "b" => 200 }  # declaring Hash valueb = {"a" => 100}  # declaring Hash valuec = {"a" => 100, "c" => 300, "b" => 200}  # Handling no key argument# fetch? Valueputs "Hash a fetch form : #{a.fetch("x"){|el| "Not present, #{el}"}}\n\n"
Output :
Hash a fetch form : Not present, x


Example #2 :
# Ruby code for Hash.fetch() method  # declaring Hash valuea = { "a" => 100, "b" => 200 }  # declaring Hash valueb = {"a" => 100}  # declaring Hash valuec = {"a" => 100, "c" => 300, "b" => 200}  # fetch Valueputs "Hash a fetch form : #{a.fetch("a")}\n\n"  puts "Hash b fetch form : #{b.fetch("a")}\n\n"  puts "Hash c fetch form : #{c.fetch("b")}\n\n"
Output :
Hash a fetch form : 100

Hash b fetch form : 100

Hash c fetch form : 200


Ruby Hash-class
Ruby-Methods
Ruby
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to copy files of the specific extension using PowerShell?

To copy the files using the specific files extension using PowerShell, we can use the Copy-Item command.
The below command will copy only the .ps1 files from the source to the destination.
For example,
PS C:\> Copy-Item -Path C:\Temp -Recurse -Filter *.ps1 -Destination C:\Temp1\ -Verbose
If the C:\Temp1 doesn't exist, it will create the destination folder and then copy the content of the file but the problem with this command is it copies the subfolders as well which doesn’t have the .ps1 file.
So to copy the with the same folder structure without empty directories and the specific file extension we can write the code to check the size of the directory after copy and delete if the folder is empty but this would be a lengthy process.
We can use the xCopy or the RoboCopy command to overcome the above problem.
PS C:\> robocopy c:\temp c:\temp1 "*.ps1" /s
The above command will copy files with extension .ps1 from the C:\temp to the C:\temp1 without the empty folders.
C | String | Question 9 - GeeksforGeeks

28 Jun, 2021
Consider the following C program segment:
char p[20]; char *s = "string"; int length = strlen(s); int i; for (i = 0; i < length; i++)     p[i] = s[length — i]; printf("%s", p);
The output of the program is? (GATE CS 2004)(A) gnirts(B) gnirt(C) string(D) no output is printedAnswer: (D)Explanation: Let us consider below line inside the for loopp[i] = s[length — i];For i = 0, p[i] will be s[6 — 0] and s[6] is ‘\0′So p[0] becomes ‘\0’. It doesn’t matter what comes in p[1], p[2]..... as P[0] will not change for i >0. Nothing is printed if we print a string with first character ‘\0′Quiz of this Question
C-String
C-String-Question
C Language
C Quiz
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Command line arguments in C/C++
fork() in C
Different methods to reverse a string in C/C++
Function Pointer in C
Substring in C++
Compiling a C program:- Behind the Scenes
Operator Precedence and Associativity in C
C | Structure & Union | Question 4
C | File Handling | Question 5
C | Dynamic Memory Allocation | Question 5
HTML | DOM onsubmit Event

08 Mar, 2022
The onsubmit event in HTML DOM occurs after submission of a form. The form tag supports this event.Supported HTML Tags: 
<form>
Syntax:  
In HTML:  
<element onsubmit="Script">
In JavaScript:  
object.onsubmit = function(){myScript};
In JavaScript, using the addEventListener() method:  
object.addEventListener("submit", myScript);
Example: Using JavaScript  
html
<!DOCTYPE html><html> <head>    <title>      HTML DOM onsubmit Event  </title></head> <body>    <center>        <h1 style="color:green">GeeksforGeeks</h1>        <h2>HTML DOM onsubmit Event</h2>        <form id="formID" action="#">            Enter name:            <input type="text" name="fname">            <input type="submit" value="Submit">        </form>    </center>       <script>        document.getElementById("formID").onsubmit =            function() {GFGfun()};         function GFGfun() {            alert("form submitted");        }    </script> </body> </html>
Output: Before:  
After:  
Example: Using the addEventListener() method  
html
<!DOCTYPE html><html> <head>    <title>      HTML DOM onsubmit Event  </title></head> <body>    <center>        <h1 style="color:green">GeeksforGeeks</h1>        <h2>HTML DOM onsubmit Event</h2>        <form id="formID" action="#">            Enter name:            <input type="text" name="fname">            <input type="submit" value="Submit">        </form>    </center>       <script>        document.getElementById(          "FormID").addEventListener("submit", GFGfun);         function GFGfun() {            alert("form submitted");        }    </script> </body> </html>
Output: Before:  
After:  
Supported Browsers: The browsers supported by HTML DOM onsubmit Event are listed below:  
Google Chrome
Internet Explorer
Firefox
Apple Safari
Opera
 
ManasChhabra2
chhabradhanvi
HTML-DOM
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 ?
REST API (Introduction)
CSS to put icon inside an input element in a form
Design a Tribute Page using HTML & CSS
Types of CSS (Cascading Style Sheet)
Installation of Node.js on Linux
Difference between var, let and const keywords in JavaScript
How to fetch data from an API in ReactJS ?
Differences between Functional Components and Class Components in React
Remove elements from a JavaScript Array