code-rag-bench/online-tutorials huggingface dataset:
How to draw a rectangle in HTML5 SVG?

SVG stands for Scalable Vector Graphics and is a language for describing 2D-graphics and graphical applications in XML and the XML is then rendered by an SVG viewer. Most of the web browsers can display SVG just like they can display PNG, GIF, and JPG.
To draw a rectangle in HTML SVG, use the SVG <rect> element.
You can try to run the following code to learn how to draw a rectangle in HTML5 SVG.
<!DOCTYPE html>
<html>
   <head>
      <style>
         #svgelem {
            position: relative;
            left: 10%;
            -webkit-transform: translateX(-20%);
            -ms-transform: translateX(-20%);
            transform: translateX(-20%);
         }
      </style>
      <title>SVG</title>
   </head>

   <body>
      <h2>HTML5 SVG Rectangle</h2>
      <svg id="svgelem" width="300" height="200" xmlns="http://www.w3.org/2000/svg">
         <rect width="200" height="100" fill="green"/>
      </svg>
   </body>
</html>
Memory leaks in Java

07 May, 2021
In C, programmers totally control allocation and deallocation of dynamically created objects. And if a programmer does not destroy objects, memory leak happens in C,
Java does automatic Garbage collection. However there can be situations where garbage collector does not collect objects because there are references to them. There might be situations where an application creates lots of objects and does not use them. Just because every objects has valid references, garbage collector in Java can’t destroys the objects. Such types of useless objects are called as Memory leaks. If allocated memory goes beyond limit, program will be terminated by rising OutOfMemoryError. Hence if an object is no longer required, it is highly recommended to make that object eligible for garbage collector. Otherwise We should use some tools that do memory management to identifies useless objects or memory leaks like: 
HP OVO
HP J METER
JProbe
IBM Tivoli
Java
// Java Program to illustrate memory leaksimport java.util.Vector;public class MemoryLeaksDemo{    public static void main(String[] args)    {        Vector v = new Vector(214444);        Vector v1 = new Vector(214744444);        Vector v2 = new Vector(214444);        System.out.println("Memory Leaks");    }}
Output: 
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space exceed
 
sweetyty
java-garbage-collection
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Collections in Java
Stream In Java
Singleton Class in Java
Set in Java
Initializing a List in Java
Introduction to Java
Multithreading in Java
Constructors in Java
Exceptions in Java
LinkedList in Java
Python getpass module

23 Dec, 2020
When we use terminal based application with some security credentials that use password before execution the application, Then It will be done with Python Getpass module. In this article we are going see how to use Getpass module.
Getpass module provides two function:
getpass.getpass()
getpass.getuser()
In many programs we need a secure the data or program then this case we use some secret key or passwords to identifying the users. Using getpass() it is possible to accept the password in python program.
Python3
import getpass  pwd = getpass.getpass(prompt = 'Enter the password')if pwd == 'Admin':    print('Unlock!')else:    print('You entered wrong password')
Output:
Let’s understand this module some example:
In this example we will see how to get password from users and return the same password with no prompt.
Python3
import getpass  pwd = getpass.getpass()print("You entered: ", pwd)
Output:
If user want some message before login like security question then we will use prompt attributes in getpass.
Python3
import getpass  pwd = getpass.getpass(prompt = 'What is you last Name: ')if pwd == 'Kumar':    print('Unlock! Welcome kumar')else:    print('You entered wrong Name')
Output:
This function allow us to stream the password a user enter.
Python3
import getpassimport sys  pwd = getpass.getpass(stream = sys.stderr)print('Entered Password: ', pwd)
Output:
This function return system login name of the user. It checks the environment variable of your computer and fetch the user name and return as a string and if it can not able to find the environment variable then exception is raised.
Example 1:
Here we will get username of our computer with getuser().
Python3
import getpass  print(getpass.getuser())
Output:
Example 2:
Here we will get username and password with getuser() and getpass().
Python3
import getpass   user_name = getpass.getuser()pass_word = getpass.getpass("Enter password: ")   print("User name: ", user_name)print("Your password :", pass_word)
Output:
Picked
python-modules
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
SQL Query to Drop Unique Key Constraints Using ALTER Command

19 Apr, 2021
Here, we see how to drop unique constraints using alter command. ALTER is used to add, delete/drop or modify columns in the existing table. It is also used to add and drop various constraints on the existing table.
Syntax :
ALTER TABLE table_name
DROP CONSTRAINT unique_constraint;
For instance, consider the below table ‘Employee’.
Create a Table:
CREATE TABLE Employee
('ID INT, F_Name CHAR(10), L_Name CHAR(10), Age INT);
Insert values to the table:
INSERT INTO Employee
VALUES('1','Rahul','Pal','20');
INSERT INTO Employee
VALUES('2','Ajay','Soni','32');
INSERT INTO Employee
VALUES('3','Jay','Harjai','24');
INSERT INTO Employee
VALUES('4','Ram','Meena','30');
Our table at this point will look like below:
To add a unique constraint to the table use the below statement:
ALTER TABLE Employee
ADD CONSTRAINT/INDEX unique_id UNIQUE (ID);
Now, if we add duplicates to it. It will throw the error as below. In order to add duplicates, we need to Drop Unique constraints.
Now the below query can be used to drop the unique constraint that we created above:
ALTER TABLE Employee
DROP CONSTRAINT unique_id;
Now let’s try an add duplicates in the table:
INSERT INTO Employee
VALUES('4', 'ABC', 'XYZ', '35');
Since we didn’t get an error, we have successfully removed the unique constraint. Let’s check out the tables to verify the same using the below statement:
SELECT * FROM Employee;
Output:
Picked
SQL-Query
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
React.js static getDerivedStateFromProps()

12 Mar, 2021
The getDerivedStateFromProps() method is used when the state of a component depends on changes of props.
getDerivedStateFromProps(props, state) is a static method that is called just before render() method in both mounting and updating phase in React. It takes updated props and the current state as arguments.
We have to return an object to update state or null to indicate that nothing has changed.
Creating React Application:
Step 1: Create a React application using the following command:npx create-react-app foldername
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:cd foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
cd foldername
Project Structure: It will look like the following.
App.js
import React from 'react';import ReactDOM from 'react-dom';  class App extends React.Component {    render() {      return (      <div>      <Child name = "sachin"></Child>      </div>    )  }}  class Child extends React.Component{    constructor(props){        super(props);        this.state = {        name: "kapil"        };    }    static getDerivedStateFromProps(props, state) {        if(props.name !== state.name){            //Change in props            return{                name: props.name            };        }        return null; // No change to state    }    /* if props changes then after getDerivedStateFromProps       method, state will look something like       {        name: props.name    }    */    render(){       return (        <div> My name is {this.state.name }</div>       )    }}                      export default App;
If props changes, then the state will also change accordingly else, getDerivedStateFromProps will return null that indicates no change in state. In the above example props have a property called name but the state has that property with a different value. so the state will change according to the value of props property.
Output:
Reference: https://reactjs.org/docs/react-component.html#static-getderivedstatefromprops
Picked
React.js-Methods
ReactJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Axios in React: A Guide for Beginners
ReactJS setState()
How to pass data from one component to other component in ReactJS ?
Re-rendering Components in ReactJS
ReactJS defaultProps
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?
Differences between Functional Components and Class Components in React
Python os.access() Method

Python method access() uses the real uid/gid to test for access to path. Most operations will use the effective uid/gid, therefore this routine can be used in a suid/sgid environment to test if the invoking user has the specified access to path.It returns True if access is allowed, False if not.
Following is the syntax for access() method −
os.access(path, mode);

path − This is the path which would be tested for existence or any access.
path − This is the path which would be tested for existence or any access.
mode − This should be F_OK to test the existence of path, or it can be the inclusive OR of one or more of R_OK, W_OK, and X_OK to test permissions.

os.F_OK − Value to pass as the mode parameter of access() to test the existence of path.
os.R_OK − Value to include in the mode parameter of access() to test the readability of path.
os.W_OK Value to include in the mode parameter of access() to test the writability of path.
os.X_OK Value to include in the mode parameter of access() to determine if path can be executed.


mode − This should be F_OK to test the existence of path, or it can be the inclusive OR of one or more of R_OK, W_OK, and X_OK to test permissions.
os.F_OK − Value to pass as the mode parameter of access() to test the existence of path.
os.R_OK − Value to include in the mode parameter of access() to test the readability of path.
os.W_OK Value to include in the mode parameter of access() to test the writability of path.
os.X_OK Value to include in the mode parameter of access() to determine if path can be executed.
This method returns True if access is allowed, False if not.
The following example shows the usage of access() method.
#!/usr/bin/python

import os, sys

# Assuming /tmp/foo.txt exists and has read/write permissions.

ret = os.access("/tmp/foo.txt", os.F_OK)
print "F_OK - return value %s"% ret

ret = os.access("/tmp/foo.txt", os.R_OK)
print "R_OK - return value %s"% ret

ret = os.access("/tmp/foo.txt", os.W_OK)
print "W_OK - return value %s"% ret

ret = os.access("/tmp/foo.txt", os.X_OK)
print "X_OK - return value %s"% ret
When we run above program, it produces following result −
F_OK - return value True
R_OK - return value True
W_OK - return value True
X_OK - return value False


    187 Lectures 
     17.5 hours 

 Malhar Lathkar

    55 Lectures 
     8 hours 

 Arnab Chakraborty

    136 Lectures 
     11 hours 

 In28Minutes Official

    75 Lectures 
     13 hours 

 Eduonix Learning Solutions

    70 Lectures 
     8.5 hours 

 Lets Kode It

    63 Lectures 
     6 hours 

 Abhilash Nelson
 Print
 Add Notes
 Bookmark this page
How to Plot Multiple Histograms in R? - GeeksforGeeks

19 Dec, 2021
In this article, we will discuss how to plot multiple histograms in the R Programming language.
To create multiple histograms in base R, we first make a single histogram then add another layer of the histogram on top of it. But in doing so some plots may clip off as axis are made according to the first plot. So, we can add the xlim, and the ylim parameters in the first plot to change the axis limit according to our dataset.
Syntax:
hist( data, col, xlim, ylim )
hist( data, col )
where,
data: determines the data vector to be plotted.
xlim: determines the vector with x-axis limit.
ylim: determines the vector with y-axis limit.
col: determines the color of bars of the histogram.
Example:
Here, is basic multiple histograms made in the base R Language with help of hist() function.
R
# create data vectorx1 = rnorm(1000, mean=60, sd=10)x2 = rnorm(1000, mean=0, sd=10)x3 = rnorm(1000, mean=30, sd=10)  # create multiple histogramhist(x1, col='red', xlim=c(-35, 100))hist(x2, col='green', add=TRUE)hist(x3, col='blue', add=TRUE)
Output:
To create multiple histograms in ggplot2, we use ggplot() function and geom_histogram() function of the ggplot2 package. To visualize multiple groups separately we use the fill property of aesthetics function to color the plot by a categorical variable.
Syntax:
ggplot( df, aes( x, fill ) ) + geom_histogram( color, alpha ) 
where,
df: determines the data frame to be plotted.
x: determines the data variable.
fill: determines the color of bars in the histogram.
color: determines the color of the boundary of bars in the histogram.
alpha: determines the transparency of the plot.
Example:
Here, is basic multiple histograms made by using the geom_histogram() function of the ggplot2 package in the R Language.
R
# load library ggplot2library(ggplot2)   # set themetheme_set(theme_bw(12))  # create x vectorxAxis <- rnorm(500)               # create groups in variable using conditional # statementsgroup <- rep(1, 500)              group[xAxis > -2] <- 2group[xAxis > -1] <- 3group[xAxis > 0] <- 4group[xAxis > 1] <- 5group[xAxis > 2] <- 6  # create sample data framesample_data <- data.frame(xAxis, group)    # create histogram using ggplot() # function colored by groupggplot(sample_data, aes(x=xAxis, fill = as.factor(group)))+   geom_histogram( color='#e9ecef', alpha=0.6, position='identity')
Output:
Picked
R-Charts
R-ggplot
R-Graphs
R-plots
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Change Color of Bars in Barchart using ggplot2 in R
How to Change Axis Scales in R Plots?
Group by function in R using Dplyr
How to Split Column Into Multiple Columns in R DataFrame?
Replace Specific Characters in String in R
How to filter R DataFrame by values in a column?
How to filter R dataframe by multiple conditions?
R - if statement
How to import an Excel File into R ?
Time Series Analysis in R
Implement Onclick in JavaScript and allow web browser to go back to previous page?

For reaching the back page on button click, use the concept of −
window.history.go(-1)
 Live Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fontawesome/4.7.0/css/font-awesome.min.css">
<style>
</style>
</head>
<body>
<input action="gotoPreviousPage" onclick="window.history.go(-1);
return false;" type="submit"
value="Click the button to Goto the Previous Page...." />
<script>
</script>
</body>
</html>
To run the above program, save the file name “anyName.html(index.html)” and right click on the
file. Select the option “Open with Live Server” in VS Code editor.
This will produce the following output −
After clicking the button “Click the button to Goto the Previous Page....”, you will reach the
previous page as in the below screenshot −
C# program to check if a Substring is present in a Given String

Use the contains() method in C# to check if a substring is in a given string.
Let us say the string is −
United
Within the string, you need to find the substring “Uni”. For that, use the contains method and use it like the following code snippet −
res = str1.Contains(str2);
You can try to run the following code to find a substring in a string.
Live Demo
using System;
public class Demo {
   public static void Main() {
      string str1 = "United", str2 = "Uni";
      bool res;
      res = str1.Contains(str2);
      if (res)
         Console.Write("The substring " + str2 + " is in the string " + str1);
      else
         Console.Write("The substring " + str2 + " is not in the string " + str1);
   }
}
The substring Uni is in the string United
HTML5 Canvas - Text and Fonts

HTML5 canvas provides capabilities to create text using different font and text properties listed below −
font [ = value ]
This property returns the current font settings and can be set, to change the font.
textAlign [ = value ]
This property returns the current text alignment settings and can be set, to change the alignment. The possible values are start, end, left, right, and center.
textBaseline [ = value ]
This property returns the current baseline alignment settings and can be set, to change the baseline alignment. The possible values are top, hanging, middle , alphabetic, ideographic and bottom.
fillText(text, x, y [, maxWidth ] )
This property fills the given text at the given position indicated by the given coordinates x and y.
strokeText(text, x, y [, maxWidth ] )
This property strokes the given text at the given position indicated by the given coordinates x and y.
Following is a simple example which makes use of above mentioned attributes to draw a text −
<!DOCTYPE HTML>

<html>
   <head>
   
      <style>
         #test {
            width: 100px;
            height:100px;
            margin: 0px auto;
         }
      </style>
      
      <script type = "text/javascript">
         function drawShape() {
         
            // get the canvas element using the DOM
            var canvas = document.getElementById('mycanvas');
            
            // Make sure we don't execute when canvas isn't supported
            if (canvas.getContext) {
            
               // use getContext to use the canvas for drawing
               var ctx = canvas.getContext('2d');
               
               ctx.fillStyle = '#00F';
               ctx.font = 'Italic 30px Sans-Serif';
               
               ctx.textBaseline = 'Top';
               ctx.fillText('Hello world!', 40, 100);
               
               ctx.font = 'Bold 30px Sans-Serif';
               ctx.strokeText('Hello world!', 40, 50);
            } else {
               alert('You need Safari or Firefox 1.5+ to see this demo.');
            }
         }
      </script>
   </head>
   
   <body id = "test" onload = "drawShape();">
      <canvas id = "mycanvas"></canvas>
   </body>
   
</html>
The above example would produce the following result −

    19 Lectures 
     2 hours 

 Anadi Sharma

    16 Lectures 
     1.5 hours 

 Anadi Sharma

    18 Lectures 
     1.5 hours 

 Frahaan Hussain

    57 Lectures 
     5.5 hours 

 DigiFisk (Programming Is Fun)

    54 Lectures 
     6 hours 

 DigiFisk (Programming Is Fun)

    45 Lectures 
     5.5 hours 

 DigiFisk (Programming Is Fun)
 Print
 Add Notes
 Bookmark this page
Python - Smallest integer possible from combination of list elements - GeeksforGeeks

29 Dec, 2019
Given a list of integers, the task is to get smallest integer possible from the combination of list elements. This is one of the problems that is essential in a competitive point of view and this article discusses various shorthands to solve this problem in Python. Let’s discuss certain ways in which this problem can be solved.
Method #1 : Using sorted() + lambdaThe combination of the above function can be used to perform this task. The sorted function performs the sort of list indices converted into string and lambda functions handle the conversion and iteration operation.
# Python code to demonstrate # Smallest number from list# using sorted() + lambdaimport functools  # initializing list test_list = [23, 65, 98, 3, 4]  # printing original listprint ("The original list is : " + str(test_list))  # lambda for custom operationcustom = lambda i, j: -1 if str(j) + str(i) > str(i) + str(j) else 1  # using sorted() + custom function# Smallest number from list res = sorted(test_list, key = functools.cmp_to_key(custom))    # printing result print ("The smallest possible number : " + "".join(map(str, res)))
The original list is : [23, 65, 98, 3, 4]
The smallest possible number : 23346598

 
Method #2 : Using itertools.permutation() + join() + min()
The itertools.permutation can be used to get possible permutation and min function chooses the minimum of it after being converted to integer as a result of joined output as given by join function.
# Python3 code to demonstrate # Smallest number from list# using itertools.permutation() + join() + min()from itertools import permutations  # initializing list test_list = [23, 65, 98, 3, 4]  # printing original listprint ("The original list is : " + str(test_list))  # using itertools.permutation() + join() + min()# Smallest number from listres = int(min((''.join(i) for i in permutations(str(i)                      for i in test_list)), key = int))  # printing result print ("The smallest possible number : " + str(res))
The original list is : [23, 65, 98, 3, 4]
The smallest possible number : 23346598

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

The replication of matrix by rows means that repeating a matrix one or more times but row-wise. For example, if we have a matrix that contains only one row and three columns then the replication of that matrix three times will repeat that one row three times. This can be done by using rep function along with matrix function as shown in the below example.
 Live Demo
M<-matrix(1:25,ncol=5)
M
[,1] [,2] [,3] [,4] [,5]
[1,] 1 6 11 16 21
[2,] 2 7 12 17 22
[3,] 3 8 13 18 23
[4,] 4 9 14 19 24
[5,] 5 10 15 20 25
Replicating matrix M twice −
matrix(rep(t(M),2),ncol=ncol(M),byrow=TRUE)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 6 11 16 21
[2,] 2 7 12 17 22
[3,] 3 8 13 18 23
[4,] 4 9 14 19 24
[5,] 5 10 15 20 25
[6,] 1 6 11 16 21
[7,] 2 7 12 17 22
[8,] 3 8 13 18 23
[9,] 4 9 14 19 24
[10,] 5 10 15 20 25
Replicating matrix M thrice −
matrix(rep(t(M),3),ncol=ncol(M),byrow=TRUE)
     [,1] [,2] [,3] [,4] [,5]
[1,]   1   6    11   16   21
[2,]   2   7    12  17   22
[3,]   3   8    13  18   23
[4,]   4   9    14  19   24
[5,]   5   10   15  20   25
[6,]   1   6    11 16 21
[7,]   2   7    12 17 22
[8,]   3   8   13 18 23
[9,]   4   9    14 19 24
[10,]  5  10    15 20 25
[11,]  1   6   11 16 21
[12,]  2   7   12 17 22
[13,]  3   8   13 18 23
[14,]  4   9   14 19 24
[15,]  5  10  15 20 25
Replicating matrix M five times −
matrix(rep(t(M),5),ncol=ncol(M),byrow=TRUE)
     [,1] [,2] [,3] [,4] [,5]
[1,]  1    6   11   16 21
[2,]  2    7   12   17 22
[3,]  3    8   13   18 23
[4,]  4    9   14   19 24
[5,]  5   10   15   20 25
[6,]  1   6   11   16 21
[7,]  2   7   12    17 22
[8,]  3    8   13   18 23
[9,]  4   9   14   19 24
[10,] 5   10   15  20 25
[11,] 1   6   11   16 21
[12,] 2   7   12   17 22
[13,] 3   8   13   18 23
[14,] 4   9   14   19 24
[15,] 5  10   15  20 25
[16,] 1   6   11  16 21
[17,] 2   7  12   17 22
[18,] 3   8  13   18 23
[19,] 4   9  14   19 24
[20,] 5   10  15 20 25
[21,] 1   6   11 16 21
[22,] 2   7  12 17 22
[23,] 3   8   13 18 23
[24,] 4   9  14 19 24
[25,] 5   10  15 20 25
Replicating matrix M five times −
matrix(rep(t(M),6),ncol=ncol(M),byrow=TRUE)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 6 11 16 21
[2,] 2 7 12 17 22
[3,] 3 8 13 18 23
[4,] 4 9 14 19 24
[5,] 5 10 15 20 25
[6,] 1 6 11 16 21
[7,] 2 7 12 17 22
[8,] 3 8 13 18 23
[9,] 4 9 14 19 24
[10,] 5 10 15 20 25
[11,] 1 6 11 16 21
[12,] 2 7 12 17 22
[13,] 3 8 13 18 23
[14,] 4 9 14 19 24
[15,] 5 10 15 20 25
[16,] 1 6 11 16 21
[17,] 2 7 12 17 22
[18,] 3 8 13 18 23
[19,] 4 9 14 19 24
[20,] 5 10 15 20 25
[21,] 1 6 11 16 21
[22,] 2 7 12 17 22
[23,] 3 8 13 18 23
[24,] 4 9 14 19 24
[25,] 5 10 15 20 25
[26,] 1 6 11 16 21
[27,] 2 7 12 17 22
[28,] 3 8 13 18 23
[29,] 4 9 14 19 24
[30,] 5 10 15 20 25
How to change text inside an element using jQuery?

To change text inside an element using jQuery, use the text() method.
You can try to run the following code to replace text inside an element:
Live Demo
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $('#demo').text('The replaced text.');
});
</script>
</head>
<body>

<div id="demo">
   <p>The initial text</p>
</div>

</body>
</html>
java.time.LocalDate.plus() Method Example

The java.time.LocalDate.plus(long amountToAdd, TemporalUnit unit) method returns a copy of this date with the specified amount added.
Following is the declaration for java.time.LocalDate.plus(long amountToAdd, TemporalUnit unit) method.
public LocalDate plus(long amountToAdd, TemporalUnit unit)

amountToAdd − the amount of the unit to add to the result, may be negative.
amountToAdd − the amount of the unit to add to the result, may be negative.
unit − the unit of the amount to add, not null.
unit − the unit of the amount to add, not null.
a LocalDate based on this date with the specified amount added, not null.
DateTimeException −  if the addition cannot be made.
DateTimeException −  if the addition cannot be made.
UnsupportedTemporalTypeException −  if the unit is not supported.
UnsupportedTemporalTypeException −  if the unit is not supported.
ArithmeticException −  if numeric overflow occurs.
ArithmeticException −  if numeric overflow occurs.
The following example shows the usage of java.time.LocalDate.plus(long amountToAdd, TemporalUnit unit) method.
package com.tutorialspoint;

import java.time.LocalDate;
import java.time.temporal.ChronoUnit;

public class LocalDateDemo {
   public static void main(String[] args) {
	   
	      LocalDate date = LocalDate.parse("2017-02-03");
	      LocalDate date1 = date.plus(10, ChronoUnit.DAYS);
	      System.out.println(date1);  
   }
}
Let us compile and run the above program, this will produce the following result −
2017-02-13

 Print
 Add Notes
 Bookmark this page
Python – Remove given character from first element of Tuple

02 Dec, 2021
Given a Tuple list, remove K character from 1st element of Tuple being String.
Input : test_list = [(“GF$g!”, 5), (“!i$s”, 4), (“best!$”, 10)], K = ‘$’Output : [(‘GFg!’, 5), (‘!is’, 4), (‘best!’, 10)]Explanation : First element’s strings K value removed.
Input : test_list = [(“GF$g!”, 5), (“best!$”, 10)], K = ‘$’Output : [(‘GFg!’, 5), (‘best!’, 10)]Explanation : First element’s strings K value removed.
Method #1 : Using replace() + list comprehension
In this, we use replace() to perform task of removal of K character and list comprehension to reform tuple.
Python3
# Python3 code to demonstrate working of # Remove K character from first element of Tuple# Using replace() + list comprehension  # initializing listtest_list = [("GF ! g !", 5), ("! i ! s", 4), ("best !!", 10)]  # printing original listprint("The original list is : " + str(test_list))  # initializing K K = "!"  # replace with empty string removes the desired char.res = [(sub[0].replace(K, ''), sub[1]) for sub in test_list]  # printing result print("The filtered tuples : " + str(res))
The original list is : [('GF!g!', 5), ('!i!s', 4), ('best!!', 10)]
The filtered tuples : [('GFg', 5), ('is', 4), ('best', 10)]

Method #2 : Using translate() + list comprehension
In this, we perform task of removal using translate(), which needs conversion to ascii using ord(), and replaced with empty character.
Python3
# Python3 code to demonstrate working of # Remove K character from first element of Tuple# Using translate() + list comprehension  # initializing listtest_list = [("GF ! g !", 5), ("! i ! s", 4), ("best !!", 10)]  # printing original listprint("The original list is : " + str(test_list))  # initializing K K = "!"  # translation after conversion to ascii number res = [(sub[0].translate({ord(K): None}), sub[1]) for sub in test_list]  # printing result print("The filtered tuples : " + str(res))
The original list is : [('GF!g!', 5), ('!i!s', 4), ('best!!', 10)]
The filtered tuples : [('GFg', 5), ('is', 4), ('best', 10)]

rkbhola5
Python tuple-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Different ways to create Pandas Dataframe
Enumerate() in Python
Python String | replace()
How to Install PIP on Windows ?
Python Classes and Objects
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python Program for Fibonacci numbers
Python | Convert string dictionary to dictionary
Python | Remove consecutive duplicates from list

11 Feb, 2019
In Python, we generally wish to remove the duplicate elements, but sometimes for several specific usecases, we require to have remove just the elements repeated in succession. This is a quite easy task and having a shorthand for it can be useful. Let’s discuss certain ways in which this task can be performed.
Method #1 : Using groupby() + list comprehensionUsing the groupby function, we can group the together occurring elements as one and can remove all the duplicates in succession and just let one element be in the list.
# Python3 code to demonstrate # removing consecutive duplicates# using groupby() + list comprehensionfrom itertools import groupby   # initializing listtest_list = [1, 4, 4, 4, 5, 6, 7, 4, 3, 3, 9]  # printing original listprint ("The original list is : " + str(test_list))  # using groupby() + list comprehension# removing consecutive duplicates res = [i[0] for i in groupby(test_list)]  # printing result print ("The list after removing consecutive duplicates : " +  str(res))
The original list is : [1, 4, 4, 4, 5, 6, 7, 4, 3, 3, 9]
The list after removing consecutive duplicates : [1, 4, 5, 6, 7, 4, 3, 9]

 Method #2 : Using zip_longest() + list comprehensionThis function can be used to keep the element and delete the successive elements with the use of slicing. The zip_longest function does the task of getting the values together in the one list.
# Python3 code to demonstrate # removing consecutive duplicates# using zip_longest()+ list comprehensionfrom itertools import zip_longest  # initializing listtest_list = [1, 4, 4, 4, 5, 6, 7, 4, 3, 3, 9]  # printing original listprint ("The original list is : " + str(test_list))  # using zip_longest()+ list comprehension# removing consecutive duplicates res = [i for i, j in zip_longest(test_list, test_list[1:])                                                if i != j]  # printing result print ("List after removing consecutive duplicates : " +  str(res))
The original list is : [1, 4, 4, 4, 5, 6, 7, 4, 3, 3, 9]
List after removing consecutive duplicates : [1, 4, 5, 6, 7, 4, 3, 9]

Python list-programs
python-list
Python
python-list
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Iterate over a list in Python
Python OOPs Concepts
Producer Consumer Problem using Semaphores

The producer consumer problem is a synchronization problem. There is a fixed size buffer and the producer produces items and enters them into the buffer. The consumer removes the items from the buffer and consumes them.
A producer should not produce items into the buffer when the consumer is consuming an item from the buffer and vice versa. So the buffer should only be accessed by the producer or consumer at a time.
The producer consumer problem can be resolved using semaphores. The codes for the producer and consumer process are given as follows −
The code that defines the producer process is given below −
do {
   .
   . PRODUCE ITEM
   .
   wait(empty);
   wait(mutex);
   .
   . PUT ITEM IN BUFFER
   .
   signal(mutex);
   signal(full);

} while(1);
In the above code, mutex, empty and full are semaphores. Here mutex is initialized to 1, empty is initialized to n (maximum size of the buffer) and full is initialized to 0.
The mutex semaphore ensures mutual exclusion. The empty and full semaphores count the number of empty and full spaces in the buffer.
After the item is produced, wait operation is carried out on empty. This indicates that the empty space in the buffer has decreased by 1. Then wait operation is carried out on mutex so that consumer process cannot interfere.
After the item is put in the buffer, signal operation is carried out on mutex and full. The former indicates that consumer process can now act and the latter shows that the buffer is full by 1.
The code that defines the consumer process is given below:
do {

   wait(full);
   wait(mutex);
   . .
   . REMOVE ITEM FROM BUFFER
   .
   signal(mutex);
   signal(empty);
   .
   . CONSUME ITEM
   .
} while(1);
The wait operation is carried out on full. This indicates that items in the buffer have decreased by 1. Then wait operation is carried out on mutex so that producer process cannot interfere.
Then the item is removed from buffer. After that, signal operation is carried out on mutex and empty. The former indicates that consumer process can now act and the latter shows that the empty space in the buffer has increased by 1.
How to sort lines of text files in Linux?


To sort lines of text files, we use the sort command in the Linux system.
The sort command is used to prints the lines of its input or concatenation of all files listed in its argument list in sorted order. The operation of sorting is done based on one or more sort keys extracted from each line of input. By default, the entire input is taken as the sort key.
The general syntax of the sort command is as follows.
sort [OPTION]... [FILE]...
sort [OPTION]... --files0-from=F
Brief description of options available in the sort command.
Here, we will create a file using the cat command and sort this file using the sort command in the Linux system.
$ cat >text.txt
Sid
Vikash
Gaurav
^C
$ sort text.txt
Gaurav
Sid
Vikash
Here, we will sort a file in the reverse order using the -r or --reverse option with the sort command in the Linux operating system.
$ cat >text.txt
Sid
Vikash
Gaurav
^C
$ sort text.txt
Vikash
Sid
Gaurav
In the above example, we already saw that how can we sort a file but output of the sort command on standard output. Here, we will save output into a new file in the file system.
$ sort text.txt > newtext.txt
After executing the above command, a new file will be created with the newtext.txt name.
To check more information and options with descriptions about the sort command, we use the --help option with the sort command as shown below.
$ sort --help
To check in which version the sort command is working, we use the --version option with the sort command in the Linux system as shown below.
$ sort --version
Bar Charts - Online Quiz

Following quiz provides Multiple Choice Questions (MCQs) related to Bar Charts. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.
Directions: Answer the questions given below using the graph below:
Q 1 - How many people preferring to play Tennis in 2006 (in million)  were fewer than the   number of people preferring to play Tennis in 2005? 
A - 115
B - 120
C - 100
D - 97
Answer - C
Explanation
Required difference  =(275-175) = 100 millions 

Directions: Following  bar diagrams  depict the changes in student of a collage  in four faculties from 2004- 05  to 2006-07. Study the diagram and answer the questions given below it:
Q 2 - Which of the following was the percent increase in Science students from the year 2004-05 to 2006-07?
A - 50%
B - 200/3%
C - 75%
D - 150%
Answer - A
Explanation
Required% = {(600-400/400)*100}% = 50%

Directions: Study the given bar  graph carefully and answer the questions given below:
Q 3 - In which of the following year the difference between the working and non-working  women was the highest?
A - 2005  
B - 2007  
C - 2003  
D - 2004 
Answer - B
Explanation
Required difference in various years are 
2003  (60-50)millions =10 millions,
2004  (60-50) millions = 10 millions
2005  (70-40) millions= 30 millions     
2006  (70-40)= 30 millions
2007  (75-35) millions= 40 millions
It is highest in the year 2007. 

Directions: Study the given bar  graph carefully and answer the questions given below:
Q 4 - From 2002 to 2007, the total number of people who preferred to travel by rail was approximately how many in million?
A - 1300 
B - 1800 
C - 1600 
D - 1700 
Answer - B
Explanation
Required number = (350+300+300+275+300+275)= 1800 million.

Directions: Given below is a multiple bar diagram depicting the changes in student of a collage  in four faculties from 2004- 05  to 2006-07. Study the diagram and answer the questions given below it.:
Q 5 - How much percent was the increase  in Science students in 2006-07  over 2005-06? 
A - 50%
B - 150%
C - 200/3%
D - 75%
Answer - A
Explanation
Number of science student in 2004-05 was 400.
Number of science student in 2006-07 was 600.
Increase%  = (200/400*100)% = 50% 

Directions: The following bar diagram given below shows the result of B.S.C students of a collage for three years. Study the bar diagram and answer the questions given below:
Q 6 - Which of the following % of the students passed in first division in 2005? 
A - 20%
B - 34% 
C - 100/7% 
D - 100/9%  
Answer - D
Explanation
Percentage of 1st divisioners = (200/1800*100)% = 100/9%

Directions: The following bar diagram given below shows the result of B.S.C students of a collage for three years. Study the bar diagram and answer the questions given below:
Q 7 - Which of the following is the number of third divisions in 2007? 
A - 1650  
B - 750 
C - 700  
D - 650  
Answer - B
Explanation
Number of 3rd divisions  in 2007 = (1750-1000)= 750
How to hide border and background on empty cells in a table using CSS ?

06 Apr, 2021
In this article, we will learn how to hide borders and backgrounds on empty cells in a table using CSS. The empty-cells property of CSS is used to hide the borders and backgrounds on empty cells.
Approach: The empty-cells property of CSS is used to hide the borders and backgrounds on empty cells. To hide the borders and backgrounds on empty cells, we will set the empty-cells value to hide that will hide the borders and backgrounds of empty-cells.
Syntax:
empty-cells: hide;
Example
HTML
<!DOCTYPE html><html lang="en">  <head>    <style>        .gfg {            font-size: 50px;            empty-cells: hide;        }                  td,        th {            background-color: rgb(0, 168, 0);            border: solid 1px red;        }    </style></head>  <body>    <table class="gfg" border="1">        <tr>            <td>Name</td>            <td>Marks</td>        </tr>          <tr>            <td>Nikhil</td>            <td>200</td>        </tr>          <tr>            <td>Vijay</td>            <td></td>        </tr>    </table></body>  </html>
 
Output:
Before applying empty-cells property:
After applying empty-cells property:
CSS-Properties
CSS-Questions
HTML-Questions
HTML-Tags
Picked
CSS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Calculate a Bootstrap Standard Error in R?

04 Jan, 2022
In this article, we will be looking at the different approaches to calculate a bootstrap standard error using various packages and their functionalities in the R programming language.
Bootstrap Standard Error:
The standard deviation of the bootstrap samples (also known as the bootstrap standard error) is an estimate of the standard deviation of the sampling distribution of the mean.
Steps to calculate the bootstrap standard error of given data:
Take k repeated samples with replacement from a given dataset.
For each sample, calculate the standard error: s/√n.
This results in k different estimates for the standard error. To find the bootstrapped standard error, take the mean of the k standard errors.
In this method, the user first needs to install and import the boot package in the working R console, then the user needs to call the boot() function with the required data passed into it as its parameter, which will further return the Bootstrap Standard Error of the given data in R programming language.
Syntax to install and import the boot package:
install.packages('boot')
library('boot')
Boot() function: This function provides a simple front-end to the boot function in the boot package that is tailored to bootstrapping based on regression models. 
Syntax: Boot(object, f=coef, labels=names(f(object)),R=999, ...)
Parameters:
object: An object of the class.
f: A function whose one argument is the name of a regression object that will be applied to the updated regression object to compute the statistics of interest.
labels: Provides labels for the statistics computed by f.
R: Number of bootstrap samples.
Example:
In this example, we will be using the boot() function from the boot package to the bootstrap standard error of the vector containing 10 elements and using 100 bootstrapped samples in the R programming language.
R
library(boot)  # Create datagfg <- c(244,753,596,645,874,141,639,465,999,654)  # Calculating the mean m <- function(gfg,i){mean(gfg[i])}  # Calculate standard error using 100# bootstrapped samplesboot(gfg, m, 100)
Output:
ORDINARY NONPARAMETRIC BOOTSTRAP


Call:
boot(data = gfg, statistic = m, R = 100)


Bootstrap Statistics :
    original  bias    std. error
t1*      601  -3.231    80.02706
In this method to calculate the bootstrap standard error, the user needs to use the direct formula to get the same, simply without any use of any packages in the R programming language.
Example:
In this example, we will be using the direct formula to get the bootstrap standard error of the vector containing 10 elements in the R programming language.
R
# Create datagfg <- c(244,753,596,645,874,141,639,465,999,654)  # Calculating the bootstrap standard error mean(replicate(100, sd(sample(  gfg, replace=T))/sqrt(length(gfg))))
Output:
[1] 78.53055
Picked
R-Statistics
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Unix / Linux Shell - The select Loop

The select loop provides an easy way to create a numbered menu from which users can select options. It is useful when you need to ask the user to choose one or more items from a list of choices.
select var in word1 word2 ... wordN
do
   Statement(s) to be executed for every word.
done

Here var is the name of a variable and word1 to wordN are sequences of characters separated by spaces (words). Each time the for loop executes, the value of the variable var is set to the next word in the list of words, word1 to wordN.
For every selection, a set of commands will be executed within the loop. This loop was introduced in ksh and has been adapted into bash. It is not available in sh.
Here is a simple example to let the user select a drink of choice −
#!/bin/ksh

select DRINK in tea cofee water juice appe all none
do
   case $DRINK in
      tea|cofee|water|all) 
         echo "Go to canteen"
         ;;
      juice|appe)
         echo "Available at home"
      ;;
      none) 
         break 
      ;;
      *) echo "ERROR: Invalid selection" 
      ;;
   esac
done
The menu presented by the select loop looks like the following −
$./test.sh
1) tea
2) cofee
3) water
4) juice
5) appe
6) all
7) none
#? juice
Available at home
#? none
$

You can change the prompt displayed by the select loop by altering the variable PS3 as follows −
$PS3 = "Please make a selection => " ; export PS3
$./test.sh
1) tea
2) cofee
3) water
4) juice
5) appe
6) all
7) none
Please make a selection => juice
Available at home
Please make a selection => none
Python VLC MediaList – Adding Media to it

29 Aug, 2020
In this article we will see how we can add media to the MediaList object in the python vlc module. VLC media player is a free and open-source portable cross-platform media player software and streaming media server developed by the VideoLAN project. MediaList object contains the multiple media, in other words it has list of media which can be used with MediaListPlayer object to play these multiple media object. Adding media act similar to inserting media at the end of the list.
In order to do this we will use add_media method with the MediaList object
Syntax : media_list.add_media(media)
Argument : It takes Media object as argument
Return : It returns None
Below is the implementation
# importing vlc moduleimport vlc  # importing time moduleimport time  # creating a media player objectmedia_player = vlc.MediaListPlayer()  # creating Instance class objectplayer = vlc.Instance()  # creating a media list objectmedia_list = vlc.MediaList()  # creating a new mediamedia = player.media_new("death_note.mkv")  # adding media to media listmedia_list.add_media(media)  # creating a new mediamedia = player.media_new("1.mp4")  # adding media to media listmedia_list.add_media(media)  # setting media list to the media playermedia_player.set_media_list(media_list)    # start playing videomedia_player.play()  # wait so the video can be played for 5 seconds# irrespective for length of videotime.sleep(5)
Output :
Another example
# importing vlc moduleimport vlc  # importing time moduleimport time  # creating a media player objectmedia_player = vlc.MediaListPlayer()  # creating Instance class objectplayer = vlc.Instance()  # creating a media list objectmedia_list = vlc.MediaList()  # creating a new mediamedia = player.media_new("1.mp4")  # adding media to media listmedia_list.add_media(media)  # creating a new mediamedia = player.media_new("death_note.mkv")  # adding media to media listmedia_list.add_media(media)      # setting media list to the media playermedia_player.set_media_list(media_list)    # start playing videomedia_player.play()  # wait so the video can be played for 5 seconds# irrespective for length of videotime.sleep(5)
Output :
Python vlc-mediaList
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.