code-rag-bench/online-tutorials huggingface dataset:
Python – Binding and Listening with Sockets

01 Jun, 2022
Socket programming is a way of connecting two nodes on a network to communicate with each other. One socket(node) listens on a particular port at an IP, while other socket reaches out to the other to form a connection. The server forms the listener socket while the client reaches out to the server. Note: For more information, refer Socket Programming in Python
A server has a bind() method which binds it to a specific IP and port so that it can listen to incoming requests on that IP and port. A server has a listen() method which puts the server into listen mode. This allows the server to listen to incoming connections. And last a server has an accept() and close() method. The accept method initiates a connection with the client and the close method closes the connection with the client.
 Example 
Python3
import socketimport sys  # specify Host and PortHOST = ''PORT = 5789   soc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)  try:    # With the help of bind() function    # binding host and port    soc.bind((HOST, PORT))      except socket.error as message:         # if any error occurs then with the    # help of sys.exit() exit from the program    print('Bind failed. Error Code : '          + str(message[0]) + ' Message '          + message[1])    sys.exit()     # print if Socket binding operation completed   print('Socket binding operation completed')  # With the help of listening () function# starts listeningsoc.listen(9)  conn, address = soc.accept()# print the address of connectionprint('Connected with ' + address[0] + ':'      + str(address[1]))
First of all we import socket which is necessary.
Then we made a socket object and reserved a port on our pc.
After that we bound our server to the specified port. Passing an empty string means that the server can listen to incoming connections from other computers as well. If we would have passed 127.0.0.1 then it would have listened to only those calls made within the local computer.
After that we put the server into listen mode. 9 here means that 9 connections are kept waiting if the server is busy and if a 10th socket tries to connect then the connection is refused.
Now we need something with which a server can interact. We could tenet to the server like this just to know that our server is working. Type these commands in the terminal:
# start the server
$ python server.py
Keep the above terminal open now open another terminal and type:
$ telnet localhost 12345
Output:  
anikakapoor
sweetyty
Python-socket
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
Difference between JavaScript and JSP

16 Jun, 2022
JavaScript is a lightweight and object-oriented scripting language used to create dynamic HTML pages with interactive effects within a webpage. It is an interpreted scripting language and its code is run in a web browser. It is also called a browser’s language and can be used for client-side developments as well as server-side developments. It was developed by Brendan Eich at Netscape and was first released in 1995. Features of JavaScript:  Some important features of JavaScript are : 
It is a lightweight scripting language.
It is platform-independent, it can run anytime on any platform or any browser.
It can handle date and time easily as it has in-built functions for date and time.
It allows dynamic typing, define types of the variable on the basis of stored value.
It provides support for Object-Oriented programming.
It reduces the load on the server by providing greater control to the browser itself.
Example: 
javascript
<script type="text/javascript">    document.write("Hello Geeks, Greetings from GeeksforGeeks")</script>
JSP stands for Java Server Pages, are a dynamic web technology based on servlet container and Java EE specification which is used to generate dynamic web content in webpages. It was launched in the year 1999. It serves as a server-side technology based on various content formats such as XML or HTML or any other type of document contents.  
Features of JSP: Some important features of JSP are : 
It is an expression language for the server-side.
It is easy to code as it allows tag-based programming.
It is platform-independent, it can run anytime on any platform or any browser.
It allows the building of dynamic web pages which helps to interact with the users in a real-time environment.
It primarily connects with the server which provides an easy connection to the database.
Example:  
html
<html>   <head><title>Hello!</title></head>   <body>      Hello Geeks!<br/>      <%         out.println("Welcome to Geeksforgeeks");      %>   </body></html>
Difference between JavaScript and JSP: 
siddharthredhu01
priyansh70890
Java-JSP
JavaScript-Misc
Web Technologies
Web technologies Questions
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Wand oil_paint() function – Python

08 Jul, 2021
The oil_paint() function is an inbuilt function in the Python Wand ImageMagick library which is used to simulate an oil painting by replace each pixel with most frequent surrounding color. 
Syntax:  
oil_paint(radius, sigma)
Parameters: This function accepts three parameters as mentioned above and defined below:  
radius: This parameter is used to store the radius of the simulation.
sigma: This parameter is used to store the sigma of the simulation.
Return Value: This function returns the Wand ImageMagick object.
Original Image:  
Example 1:  
Python3
# Import library from Imagefrom wand.image import Image # Import the imagewith Image(filename ='../geeksforgeeks.png') as image:    # Clone the image in order to process    with image.clone() as oil_paint:        # Invoke oil_paint function with radius 6 and sigma 4        oil_paint.oil_paint(6, 4)        # Save the image        oil_paint.save(filename ='oil_paint1.jpg')
Output:  
Example 2:  
Python3
# Import libraries from the wand from wand.image import Imagefrom wand.drawing import Drawingfrom wand.color import Color with Drawing() as draw:    # Set Stroke color the circle to black    draw.stroke_color = Color('black')    # Set Width of the circle to 2    draw.stroke_width = 1    # Set the fill color to 'White (# FFFFFF)'    draw.fill_color = Color('white')     # Invoke Circle function with center at 50, 50 and radius 25    draw.circle((200, 200), # Center point                (100, 100)) # Perimeter point    # Set the font style    draw.font = '../Helvetica.ttf'    # Set the font size    draw.font_size = 30         with Image(width = 400, height = 400, background = Color('# 45ff33')) as pic:        # Set the text and its location        draw.text(int(pic.width / 3), int(pic.height / 2), 'GeeksForGeeks !')        # Draw the picture        draw(pic)        # Invoke oil_paint function with radius 9 and sigma 7        pic.oil_paint(9, 7)        # Save the image        pic.save(filename ='oil_paint2.jpg')
Output:  
 
sweetyty
Image-Processing
Python-wand
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python – Interconvert Horizontal and Vertical String

02 Sep, 2020
Given a String, convert to vertical if horizontal and vice-versa.
Input : test_str = ‘geeksforgeeks’Output : geeksExplanation : Horizontal String converted to Vertical.
Input : test_str = geeksOutput : ‘geeks’Explanation : Vertical String converted to Horizontal.
Method #1 : [Horizontal to Vertical] using loop + “\n”
In this, we add newline character to after each character so that each element gets rendered at next line. 
Python3
# Python3 code to demonstrate working of # Interconvert Horizontal and Vertical String# using [Horizontal to Vertical] using loop + "\n"  # initializing stringtest_str = 'geeksforgeeks'  # printing original Stringprint("The original string is : " + str(test_str))  # using loop to add "\n" after each character res = ''for ele in test_str:    res  += ele + "\n"       # printing result print("The converted string : " + str(res)) 
The original string is : geeksforgeeks
The converted string : g
e
e
k
s
f
o
r
g
e
e
k
s


Method #2 : [Vertical to Horizontal] using replace() + “\n”
In this, we perform the task of  conversion by removing “\n” by replacement by empty string.
Python3
# Python3 code to demonstrate working of # Interconvert Horizontal and Vertical String# using [Vertical to Horizontal] using replace() + "\n"  # initializing stringtest_str = 'g\ne\ne\nk\ns\nf\no\nr\ng\ne\ne\nk\ns\n'  # printing original Stringprint("The original string is : " + str(test_str))  # using replace() + "\n" to solve this problemres = test_str.replace("\n", "")      # printing result print("The converted string : " + str(res)) 
The original string is : g
e
e
k
s
f
o
r
g
e
e
k
s

The converted string : geeksforgeeks

Python string-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
Python | Split string into list of characters
Python Program for Fibonacci numbers
Tryit Editor v3.7

Tryit: The traditional way - no use of variables
Working With Command Line

In this chapter, we will learn how to make use of the command line to run test cases.
To begin with, let us open the command prompt and go to the folder where your test cases are saved. We have created test cases and saved in the folder robotframework in C Drive.
Test cases created so far are available in the folder C:\robotframework.
If you have saved your project as a file, the command is −
robot -T nameoftestcase.robot

If you have saved your project as a directory, the command is −
robot -T projectname testsuite

We will run one of the test created from the folder as shown below −
The output, log and report paths are displayed at the end as shown above.
The following screenshot shows the execution details −
We can use command line to execute robot test cases. The details of the test case pass or fail are displayed in the command line along with log and report URLs.

    17 Lectures 
     1 hours 

 Musab Zayadneh

    11 Lectures 
     31 mins

 Musab Zayadneh

    20 Lectures 
     1.5 hours 

 Maksym Rudnyi

    25 Lectures 
     3 hours 

 Kamal Kishor Girdher

    16 Lectures 
     3.5 hours 

 Onur

    10 Lectures 
     34 mins

 Ashraf Said
 Print
 Add Notes
 Bookmark this page
Python - Sum of Cubes in List - GeeksforGeeks

29 Dec, 2019
Python being the language of magicians can be used to perform many tedious and repetitive tasks in a easy and concise manner and having the knowledge to utilize this tool to the fullest is always useful. One such small application can be finding sum of cubes of list in just one line. Let’s discuss certain ways in which this can be performed.
Method #1 : Using reduce() + lambdaThe power of lambda functions to perform lengthy tasks in just one line, allows it combined with reduce which is used to accumulate the subproblem, to perform this task as well. Works with only Python 2.
# Python code to demonstrate # Cube Summation in List# using reduce() + lambda  # initializing listtest_list = [3, 5, 7, 9, 11]  # printing original list print ("The original list is : " + str(test_list))  # using reduce() + lambda# Cube Summation in Listres = reduce(lambda i, j: i + j * j*j, [test_list[:1][0]**3]+test_list[1:])  # printing resultprint ("The sum of cubes of list is : " + str(res))
The original list is : [3, 5, 7, 9, 11]
The sum of cubes of list is : 2555

 
Method #2 : Using map() + sum()The similar solution can also be obtained using the map function to integrate and sum function to perform the summation of the cube number.
# Python3 code to demonstrate # Cube Summation in List# using sum() + map()  # initializing listtest_list = [3, 5, 7, 9, 11]  # printing original list print ("The original list is : " + str(test_list))  # using sum() + map()# Cube Summation in Listres = sum(map(lambda i : i * i * i, test_list))  # printing resultprint ("The sum of cubes of list is : " + str(res))
The original list is : [3, 5, 7, 9, 11]
The sum of cubes of list is : 2555

Python list-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Enumerate() in Python
How to Install PIP on Windows ?
Different ways to create Pandas Dataframe
Python String | replace()
Defaultdict in Python
Python | Split string into list of characters
Python | Get dictionary keys as a list
Python | Convert a list to dictionary
How to print without newline in Python?
C++ Program to Implement Circular Queue

A queue is an abstract data structure that contains a collection of elements. Queue implements the FIFO mechanism i.e the element that is inserted first is also deleted first.
A circular queue is a type of queue in which the last position is connected to the first position to make a circle.
A program to implement circular queue in C++ is given as follows −
#include <iostream>
using namespace std;

int cqueue[5];
int front = -1, rear = -1, n=5;

void insertCQ(int val) {
   if ((front == 0 && rear == n-1) || (front == rear+1)) {
      cout<<"Queue Overflow \n";
      return;
   }
   if (front == -1) {
      front = 0;
      rear = 0;
   } else {
      if (rear == n - 1)
      rear = 0;
      else
      rear = rear + 1;
   }
   cqueue[rear] = val ;
}
void deleteCQ() {
   if (front == -1) {
      cout<<"Queue Underflow\n";
      return ;
   }
   cout<<"Element deleted from queue is : "<<cqueue[front]<<endl;

   if (front == rear) {
      front = -1;
      rear = -1;
   } else {
      if (front == n - 1)
      front = 0;
      else
      front = front + 1;
   }
}
void displayCQ() {
   int f = front, r = rear;
   if (front == -1) {
      cout<<"Queue is empty"<<endl;
      return;
   }
   cout<<"Queue elements are :\n";
   if (f <= r) {
      while (f <= r){
         cout<<cqueue[f]<<" ";
         f++;
      }
   } else {
      while (f <= n - 1) {
         cout<<cqueue[f]<<" ";
         f++;
      }
      f = 0;
      while (f <= r) {
         cout<<cqueue[f]<<" ";
         f++;
      }
   }
   cout<<endl;
}
int main() {

   int ch, val;
   cout<<"1)Insert\n";
   cout<<"2)Delete\n";
   cout<<"3)Display\n";
   cout<<"4)Exit\n";
   do {
      cout<<"Enter choice : "<<endl;
      cin>>ch;
      switch(ch) {
         case 1:
         cout<<"Input for insertion: "<<endl;
         cin>>val;
         insertCQ(val);
         break;

         case 2:
         deleteCQ();
         break;

         case 3:
         displayCQ();
         break;

         case 4:
         cout<<"Exit\n";
         break;
         default: cout<<"Incorrect!\n";
      }
   } while(ch != 4);
   return 0;
}
The output of the above program is as follows −
1)Insert
2)Delete
3)Display
4)Exit

Enter choice : 1
Input for insertion:
Enter choice : 1
Input for insertion:
Enter choice : 1
Input for insertion:
Enter choice : 1
Input for insertion:
Enter choice : 1
Input for insertion:
Enter choice : 2
Element deleted from queue is : 5
Enter choice : 2
Element deleted from queue is : 3
Enter choice : 2
Element deleted from queue is : 2
Enter choice : 1
Input for insertion: 6
Enter choice : 3
Queue elements are :
7 9 6
Enter choice : 4
Exit
Python File read() Method

Python file method read() reads at most size bytes from the file. If the read hits EOF before obtaining size bytes, then it reads only available bytes.
Following is the syntax for read() method −
fileObject.read( size );

size − This is the number of bytes to be read from the file.
size − This is the number of bytes to be read from the file.
This method returns the bytes read in string.
The following example shows the usage of read() method.
This is 1st line
This is 2nd line
This is 3rd line
This is 4th line
This is 5th line

#!/usr/bin/python

# Open a file
fo = open("foo.txt", "rw+")
print "Name of the file: ", fo.name

# Assuming file has following 5 lines
# This is 1st line
# This is 2nd line
# This is 3rd line
# This is 4th line
# This is 5th line

line = fo.read(10)
print "Read Line: %s" % (line)

# Close opend file
fo.close()
When we run above program, it produces following result −
Name of the file:  foo.txt
Read Line: Python is 


    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 use the ConvertFrom-StringData command in PowerShell?


The ConvertFrom-String command converts the String to the Hashtable format as shown below.
PS C:\> "This is string" | ConvertFrom-String
P1 P2 P3
-- -- --
This is string
In the above example, We haven’t specified any header so that the output is separated the delimiter by space P1, P2 and continuous. By default, this command separates the string with a ‘=’ delimiter as shown below.
$stringhash = @"
   Name = Spooler
   Starttype = Manual
   Status = Stopped
"@
$stringhash | ConvertFrom-StringData
Name      Value
----      -----
Status    Stopped
Starttype Manual
Name      Spooler
Another method we can use is by separating string Keys and values with a delimiter parameter. This parameter is only available in the PowerShell core 7.1 version.
$stringhash = @"
   Name | Spooler
   Starttype | Manual
   Status | Stopped
"@
ConvertFrom-StringData -StringData $stringhash -Delimiter '|'
We can also use the below method.
PS C:\> $stringhash = "Name = Spooler `n StartType = Manual `n Status = Stopped"
PS C:\> ConvertFrom-StringData -StringData $stringhash
Name Value
---- -----
Status Stopped
Name Spooler
StartType Manual
ArrayList clone() method in Java with Examples - GeeksforGeeks

18 Dec, 2018
The Java.util.ArrayList.clone() method is used to create a shallow copy of the mentioned array list. It just creates a copy of the list.
Syntax:
ArrayList.clone()
Parameters: This method does not take any parameters.
Return Value: This function returns a copy of the instance of Linked list.
Below program illustrate the Java.util.ArrayList.clone() method:
Example 1:
// Java code to illustrate clone() method  import java.io.*;import java.util.ArrayList;  public class ArrayListDemo {      public static void main(String args[])    {          // Creating an empty ArrayList        ArrayList<String> list            = new ArrayList<String>();          // Use add() method        // to add elements in the list        list.add("Geeks");        list.add("for");        list.add("Geeks");        list.add("10");        list.add("20");          // Displaying the list        System.out.println("First ArrayList: "                           + list);          // Creating another linked list and copying        ArrayList sec_list = new ArrayList();        sec_list = (ArrayList)list.clone();          // Displaying the other linked list        System.out.println("Second ArrayList is: "                           + sec_list);    }}
First ArrayList: [Geeks, for, Geeks, 10, 20]
Second ArrayList is: [Geeks, for, Geeks, 10, 20]

Example 2:
// Java code to illustrate clone() method  import java.io.*;import java.util.ArrayList;  public class ArrayListDemo {      public static void main(String args[])    {          // Creating an empty ArrayList        ArrayList<Integer> list            = new ArrayList<Integer>();          // Use add() method        // to add elements in the list        list.add(10);        list.add(20);        list.add(30);        list.add(40);        list.add(50);          // Displaying the list        System.out.println("First ArrayList: "                           + list);          // Creating another linked list and copying        ArrayList sec_list = new ArrayList();        sec_list = (ArrayList)list.clone();          // Displaying the other linked list        System.out.println("Second ArrayList is: "                           + sec_list);    }}
First ArrayList: [10, 20, 30, 40, 50]
Second ArrayList is: [10, 20, 30, 40, 50]

Java - util package
Java-ArrayList
Java-Collections
Java-Functions
Picked
Java
Java
Java-Collections
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
HashMap in Java with Examples
Initialize an ArrayList in Java
Interfaces in Java
ArrayList in Java
How to iterate any Map in Java
Multidimensional Arrays in Java
Multithreading in Java
LinkedList in Java
Overriding in Java
Stack Class in Java
How to use Tooltip component in ReactJS? - GeeksforGeeks

05 Mar, 2021
Tooltips display informative text when users hover over, focus on, or tap an element. Material UI for React has this component available for us, and it is very easy to integrate. We can use the Tooltip Component in ReactJS using the following approach.
Creating React Application And Installing Module:
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 3: After creating the ReactJS application, Install the material-ui modules using the following command.
npm install @material-ui/core
npm install @material-ui/icons
Project Structure: It will look like the following.
Project Structure
Example: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
App.js
import React from "react";import IconButton from "@material-ui/core/IconButton";import Tooltip from "@material-ui/core/Tooltip";import PersonIcon from "@material-ui/icons/Person";import DeleteIcon from "@material-ui/icons/Delete";  export default function App() {  return (    <div style={{ display: "block", padding: 30 }}>      <h4>How to use Tooltip Component in ReactJS?</h4>      <Tooltip title="Delete">        <IconButton>          <DeleteIcon />        </IconButton>      </Tooltip>      <Tooltip title="Person">        <IconButton>          <PersonIcon />        </IconButton>      </Tooltip>    </div>  );}
Step to Run Application: Run the application using the following command from the root directory of the project.
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output.
Reference: https://material-ui.com/components/tooltips/
Material-UI
React-Questions
ReactJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
React-Router Hooks
How to set background images in ReactJS ?
How to create a table in ReactJS ?
How to navigate on path by button click in react router ?
ReactJS useNavigate() Hook
Roadmap to Become a Web Developer in 2022
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
Convert a string to an integer in JavaScript
\begin - Tex Command

\begin - is used in begin/end environment.
{ \begin }
\begin command is used in begin/end environment.

\begin{gather}a\\a+b\\a+b+c\end{gather}

aa+ba+b+c



\begin{gather}a\\a+b\\a+b+c\end{gather}

aa+ba+b+c


\begin{gather}a\\a+b\\a+b+c\end{gather}

    14 Lectures 
     52 mins

 Ashraf Said

    11 Lectures 
     1 hours 

 Ashraf Said

    9 Lectures 
     1 hours 

 Emenwa Global, Ejike IfeanyiChukwu

    29 Lectures 
     2.5 hours 

 Mohammad Nauman

    14 Lectures 
     1 hours 

 Daniel Stern

    15 Lectures 
     47 mins

 Nishant Kumar
 Print
 Add Notes
 Bookmark this page
How to add months to a date in JavaScript?

To add months to a JavaScript Date, use the setMonth() method. JavaScript date setMonth() method sets the months for a specified date according to local time.
You can try to run the following code to add 2 months.
<html>
   <head>
      <title>JavaScript setMonth Method</title>
   </head>
   <body>
      <script>
         var dt = new Date("August 20, 2017 11:30:25");
         dt.setMonth( dt.getMonth() + 2 );
         document.write( dt );
      </script>
   </body>
</html>
What are the Rules of Regular Expressions in Compiler Design?

The language accepted by finite automata can be simply defined by simple expressions known as Regular Expressions. It is an effective approach to describe any language. A regular expression can also be represented as a sequence of patterns that represent a string. Regular expressions are used to connect character sequence in strings. The string searching algorithm used this pattern to discover the operations on a string.
There are various rules for regular expressions which are as follows −
ε is a Regular expression.
ε is a Regular expression.
Union of two Regular Expressions R1 and R2.
Union of two Regular Expressions R1 and R2.
i.e., R1 + R2 or R1|R2 is also a regular expression.
Concatenation of two Regular Expressions R1 and R2.
Concatenation of two Regular Expressions R1 and R2.
i.e., R1
R2 is also a Regular Expression.
Closure of Regular Expression R, i.e., R* is also a Regular Expression.
Closure of Regular Expression R, i.e., R* is also a Regular Expression.
If R is a Regular Expression, then (R) is also a Regular Expression.
If R is a Regular Expression, then (R) is also a Regular Expression.
R1|R2=R2|R1 or R1+ R2=R2+ R1 (Commutative)
R1| (R2|R3)=(R1| R2)|R3 (Associative)
Or
R1+ (R2+ R3)=(R1+ R2)+R3
R1 (R2|R3)=(R1R2)R3 (Associative)
R1| (R2|R3)=R1R2| R1R3 (Distributive)
Or
R1 (R2+ R3)=R1R2+R1R3
ε R=R ε=R (Concatenation)
Example1 − Write Regular Expressions for the following language over ∑ ={a,b}
String of length zero or one.
Answer: ε | a | b or (ε+a+b)
Strings of length two.
Answer: aa | ab | bb or (aa+ab+ba +bb)
Strings of Even Length
Answer: (aa| ab| ba | bb)* or (aa+ab+ba +bb)*
Set of all strings of a’s and b’s having at least two occurrences of aa.
Answer − (a+b)*aa(a+b)aa(a+b)*
Example2 − Find Regular Expressions for following language.
L={ε,1,11,111,....}
{∴ 10=ε,11=1,12=11,13=111.....}
Answer: 1*
L={ε,11,1111,111111,.....}
Answer: (11) ∗
L = Set of all strings of 0’s and 1’s = {ε,0,1,01,11,00,000,101,......}
L = Set of all strings of 0’s and 1’s = {ε,0,1,01,11,00,000,101,......}
Answer: (0+1) ∗ or (0|1) ∗
L = Set of all strings of 0’s and 1’s ending with 11.
L = Set of all strings of 0’s and 1’s ending with 11.
Answer: (0+1) ∗ 11
L = Set of all strings of 0’s and 1’s beginning with 0 and ending with 1.
L = Set of all strings of 0’s and 1’s beginning with 0 and ending with 1.
Answer: 0(0+1) ∗ 1
Example3 − Write Regular Expression in which the second letter from the right end of the string is 1 where ∑ ={0,1}.
Answer: (0+1) ∗ 1(0+1)
Example4 − Write Regular Expressions for the following language over ∑ ={a,b}
L=Set of strings having at least one occurrence of the double letter
L=Set of strings having at least one occurrence of the double letter
Answer: (a+b)*(aa+bb)(a+b)*
L = Set of strings having double letter at Beginning and Ending of string.
L = Set of strings having double letter at Beginning and Ending of string.
Answer: (aa+bb)(a+b)*(aa+bb)
L = Set of strings having double letter at Beginning or on Ending of string.
L = Set of strings having double letter at Beginning or on Ending of string.
Answer: (aa+bb)(a+b)*+ (a+b)*(aa+bb)+(aa+bb)(a+b)*(aa+bb)
XML - Encoding

Encoding is the process of converting unicode characters into their equivalent binary representation. When the XML processor reads an XML document, it encodes the document depending on the type of encoding. Hence, we need to specify the type of encoding in the XML declaration.
There are mainly two types of encoding −
UTF-8
UTF-16
UTF stands for UCS Transformation Format, and UCS itself means Universal Character Set. The number 8 or 16 refers to the number of bits used to represent a character. They are either 8(1 to 4 bytes) or 16(2 or 4 bytes). For the documents without encoding information, UTF-8 is set by default.
Encoding type is included in the prolog section of the XML document. The syntax for UTF-8 encoding is as follows −
<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>

The syntax for UTF-16 encoding is as follows −
<?xml version = "1.0" encoding = "UTF-16" standalone = "no" ?>

Following example shows the declaration of encoding −
<?xml version = "1.0" encoding = "UTF-8" standalone = "no" ?>
<contact-info>
   <name>Tanmay Patil</name>
   <company>TutorialsPoint</company>
   <phone>(011) 123-4567</phone>
</contact-info>
In the above example encoding="UTF-8", specifies that 8-bits are used to represent the characters. To represent 16-bit characters, UTF-16 encoding can be used.
The XML files encoded with UTF-8 tend to be smaller in size than those encoded with UTF-16 format.

    84 Lectures 
     6 hours 

 Frahaan Hussain

    29 Lectures 
     2 hours 

 YouAccel

    27 Lectures 
     1 hours 

 Jordan Stanchev

    16 Lectures 
     2 hours 

 Simon Sez IT
 Print
 Add Notes
 Bookmark this page
Python String isspace() Method

Python string  method isspace() checks whether the string consists of whitespace.
Following is the syntax for isspace() method −
str.isspace()

NA
NA
This method returns true if there are only whitespace characters in the string and there is at least one character, false otherwise.
The following example shows the usage of isspace() method.
#!/usr/bin/python

str = "       "; 
print str.isspace()

str = "This is string example....wow!!!";
print str.isspace()
When we run above program, it produces following result −
True
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 do I do a case insensitive string comparison in Python?

The following code is an example of case insensitive string comparison in Python.
string1 = 'Star Wars'
string2 = 'star wars'
if string1.lower() == string2.lower():
    print "The strings are case insensitive"
else:
    print "The strings are not case insensitive"
This code gives the following output
The strings are case insensitive
Can we call Superclass’s static method from subclass in Java?

A static method is the one which you can call without instantiating the class. If you want to call a static method of the superclass, you can call it directly using the class name.
 Live Demo
public class Sample{
   public static void display(){
      System.out.println("This is the static method........");
   }
   public static void main(String args[]){
      Sample.display();
   }
}
This is the static method........
It also works, if you call a static method using an instance. But, it is not recommended.
 Live Demo
public class Sample{
   public static void display(){
      System.out.println("This is the static method........");
   }
   public static void main(String args[]){
      new Sample().display();
   }
}
This is the static method........
If you compile the above program  in eclipse you will get a warning as −
The static method display() from the type Sample should be accessed in a static way
You can call the static method of the superclass −
Using the constructor of the superclass.
new SuperClass().display();
Directly, using the name of the superclass.
SuperClass.display();
Directly, using the name of the subclass.
SubClass.display();
Following Java example calls the static method of the superclass in all the 3 possible ways −
 Live Demo
class SuperClass{
   public static void display() {
      System.out.println("This is a static method of the superclass");
   }
}
public class SubClass extends SuperClass{
   public static void main(String args[]){
      //Calling static method of the superclass
      new SuperClass().display(); //superclass constructor
      SuperClass.display(); //superclass name
      SubClass.display(); //subclass name
   }
}
This is a static method of the superclass
This is a static method of the superclass
This is a static method of the superclass
Creating a new table in SAP HANA

New tables can be created using the two methods given below −
Using SQL editor
Using GUI option
The new table can be created using SQL Create Table statement –
Create column Table Test1 (
   ID INTEGER,
   NAME VARCHAR(10),
   PRIMARY KEY (ID)
);
When you run this SQL query, you get a message like this:
The statement 'Create column Table Test1 (
ID INTEGER, NAME VARCHAR(10), PRIMARY KEY (ID) )'
successfully executed in 5 ms 136 μs (server processing time: 4 ms 432 μs) -
Rows Affected: 0
To create a table using GUI, you need to right-click on any schema name -> New Table
It will open a window to enter the Table name, Choose Schema name from the drop-down, Define Table type from the drop-down list: Column Store or Row Store.
Define data type as shown below. Columns can be added by clicking on the + sign, Primary Key can be chosen by clicking on the cell under Primary key in front of the Column name, Not Null will be active by default. Once columns are added, click on Execute.
Check for balanced parentheses in an expression in C++

Suppose we have an expression. The expression has some parentheses; we have to check the parentheses are balanced or not. The order of the parentheses are (), {} and []. Suppose there are two strings. “()[(){()}]” this is valid, but “{[}]” is invalid.
The task is simple; we will use stack to do this. We should follow these steps to get the solution −
Traverse through the expression until it has exhaustedif the current character is opening bracket like (, { or [, then push into stackif the current character is closing bracket like ), } or ], then pop from stack, and check whether the popped bracket is corresponding starting bracket of the current character, then it is fine, otherwise that is not balanced.
if the current character is opening bracket like (, { or [, then push into stack
if the current character is closing bracket like ), } or ], then pop from stack, and check whether the popped bracket is corresponding starting bracket of the current character, then it is fine, otherwise that is not balanced.
After the string is exhausted, if there are some starting bracket left into the stack, then the string is not balanced.
 Live Demo
#include <iostream>
#include <stack>
using namespace std;
bool isBalancedExp(string exp) {
   stack<char> stk;
   char x;
   for (int i=0; i<exp.length(); i++) {
      if (exp[i]=='('||exp[i]=='['||exp[i]=='{') {
         stk.push(exp[i]);
         continue;
      }
      if (stk.empty())
         return false;
      switch (exp[i]) {
      case ')':
         x = stk.top();
         stk.pop();
         if (x=='{' || x=='[')
            return false;
         break;
      case '}':
         x = stk.top();
         stk.pop();
         if (x=='(' || x=='[')
            return false;
         break;
      case ']':
         x = stk.top();
         stk.pop();
         if (x =='(' || x == '{')
            return false;
         break;
      }
   }
   return (stk.empty());
}
int main() {
   string expresion = "()[(){()}]";
   if (isBalancedExp(expresion))
      cout << "This is Balanced Expression";
   else
      cout << "This is Not Balanced Expression";
}
This is Balanced Expression
JavaScript | Namespace - GeeksforGeeks

21 Mar, 2020
Namespace refers to the programming paradigm of providing scope to the identifiers (names of types, functions, variables, etc) to prevent collisions between them. For instance, the same variable name might be required in a program in different contexts. Using namespaces in such a scenario will isolate these contexts such that the same identifier can be used in different namespaces. In this article, we will discuss how namespaces can be initialized and used in JavaScript. JavaScript does not provide namespace by default. However, we can replicate this functionality by making a global object which can contain all functions and variables.
Syntax:
To initialise an empty namespace var <namespace> = {}; 
 var <namespace> = {}; 
To access variables in the namespace <namespace>.<identifier> 
 <namespace>.<identifier> 
Below example illustrates the namespace in JavaScript:
Example: As shown below, the identifier startEngine is used to denote different functions in car and bike objects. In this manner, we can use the same identifier in different namespaces by attaching it to different global objects.
<script>var car = {    startEngine: function () {        console.log("Car started");                 }        }  var bike = {    startEngine: function () {        console.log("Bike started");    }}  car.startEngine();bike.startEngine();</script>
Output:
Car started
Bike started
javascript-basics
Picked
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
Convert a string to an integer in JavaScript
How to append HTML code to a div using JavaScript ?
Difference Between PUT and PATCH Request
Installation of Node.js on Linux
Roadmap to Become a Web Developer in 2022
How to fetch data from an API in ReactJS ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
How to use REPLACE() function with column’s data of MySQL table?

For using it with column’s data we need to provide column name as the argument of REPLACE() function. It can be demonstrated by using ‘Student’ table data as follows −
mysql> Select Id, Name, Subject, REPLACE(Subject, 's', ' Science') from Student WHERE Subject = 'Computers';
+------+--------+-----------+-----------------------------------+
| Id   | Name   | Subject   | REPLACE(Subject, 's', ' Science') |
+------+--------+-----------+-----------------------------------+
| 1    | Gaurav | Computers | Computer Science                  |
| 20   | Gaurav | Computers | Computer Science                  |
+------+--------+-----------+-----------------------------------+
2 rows in set (0.00 sec)
Node.js fs.exists() Method - GeeksforGeeks

12 Oct, 2021
The fs.exists() method is an inbuilt application programming interface of fs module which provides an API for interacting with the file system in a manner closely modeled around standard POSIX functions. The fs.exists() method is used to test whether the given path exists or not in the file system.
Syntax:
fs.exists( path, callback )
Parameters: This method accept two parameters as mentioned above and described below:
path: The path at which directory is to be tested for existence. It can be string, buffer, etc.
callback: It is a callback function passed to the exists() method.
Return value: It returns boolean values which signifies that the path exists or not.
Note: It is now deprecated.
Below examples illustrate the use of fs.exists() method in Node.js:
Example 1:
// Node.js program to demonstrate the // fs.exists() method   var fs = require('fs');   // Using fs.exists() methodfs.exists('/etc/passwd', (exists) => {  console.log(exists ? 'Found' : 'Not Found!');});
Output:
Found

Example 2:
// Node.js program to demonstrate the // fs.exists() method   var fs = require('fs');   // Using fs.exists() methodfs.exists('/etc/geeks', (exists) => {    console.log(exists ? 'Found' : 'Not found!');});
Output:
Not found!

Note: The above program will compile and run by using the node index.js command.
Reference: https://nodejs.org/dist/latest-v13.x/docs/api/fs.html#fs_fs_exists_path_callback
Node.js-fs-module
Picked
Node.js
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to update Node.js and NPM to next version ?
Node.js fs.readFileSync() Method
Express.js express.Router() Function
Node.js fs.writeFile() Method
How to update NPM ?
Roadmap to Become a Web Developer in 2022
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Convert a string to an integer in JavaScript
Console.MoveBufferArea Method in C# - GeeksforGeeks

08 Mar, 2019
Console.MoveBufferArea Method is used to move the specified screen area to destination area.
Syntax: public static void MoveBufferArea (int sourceLeft, int sourceTop, int sourceWidth, int sourceHeight, int targetLeft, int targetTop);
Parameters:sourceLeft: The leftmost column of the source area.sourceTop: The topmost row of the source area.sourceWidth: The number of columns in the source area.sourceHeight: The number of rows in the source area.targetLeft: The leftmost column of the destination area.targetTop: The topmost row of the destination area.
Exceptions:
ArgumentOutOfRangeException:One or more of the parameters is less than zero.If sourceLeft or targetLeft is greater than or equal to BufferWidth.If sourceTop or targetTop is greater than or equal to BufferHeight.If sourceTop + sourceHeight is greater than or equal to BufferHeight.If sourceLeft + sourceWidth is greater than or equal to BufferWidth.
One or more of the parameters is less than zero.
If sourceLeft or targetLeft is greater than or equal to BufferWidth.
If sourceTop or targetTop is greater than or equal to BufferHeight.
If sourceTop + sourceHeight is greater than or equal to BufferHeight.
If sourceLeft + sourceWidth is greater than or equal to BufferWidth.
IOException: If an I/O error occured.
Example 1:
// C# program to print GeeksForGeeksusing System;  namespace GFG {  class Program {      static void Main(string[] args)    {        Console.WriteLine("GeeksForGeeks");    }}}
Output:
Example 2:
// C# program to change area// of GeeksForGeeksusing System;  namespace GFG {  class Program {      static void Main(string[] args)    {        Console.WriteLine("GeeksForGeeks");          // using the method        Console.MoveBufferArea(0, 0, Console.BufferWidth,                           Console.BufferHeight, 10, 10);    }}}
Output:
Note:
See the difference of text positions in output images.
If the destination and source parameters specify a position located outside the boundaries of the current screen buffer, only the portion of the source area that fits within the destination area is copied. That is, the source area is clipped to fit the current screen buffer.
The MoveBufferArea method copies the source area to the destination area. If the destination area does not intersect the source area, the source area is filled with blanks using the current foreground and background colors. Otherwise, the intersected portion of the source area is not filled.
Reference:
https://docs.microsoft.com/en-us/dotnet/api/system.console.movebufferarea?view=netframework-4.7.2
CSharp-Console-Class
CSharp-method
Picked
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C# Dictionary with examples
C# | Delegates
C# | Method Overriding
C# | Abstract Classes
Difference between Ref and Out keywords in C#
Extension Method in C#
C# | Replace() Method
C# | String.IndexOf( ) Method | Set - 1
C# | Class and Object
C# | Constructors
C++ Program to Implement Dijkstra’s Algorithm Using Set

This is a C++ Program to Implement Dijkstra’s Algorithm using Set. Here we need to have two sets. We generate a shortest path tree with given source node as root. One set contains vertices included in shortest path tree and other set includes vertices not yet included in shortest path tree. At every step, we find a vertex which is in the other set (set of not yet included) and has minimum distance from source.
Begin
   function dijkstra() to find minimum distance:
   1) Create a set Set that keeps track of vertices included in shortest
   path tree, Initially, the set is empty.
   2) A distance value is assigned to all vertices in the input graph.
   Initialize all distance values as INFINITE. Distance value is assigned as
   0 for the source vertex so that it is picked first.
   3) While Set doesn’t include all vertices
      a) Pick a vertex u which is not there in the Set and has minimum distance value.
      b) Include u to Set.
      c) Distance value is updated of all adjacent vertices of u.
      For updating the distance values, iterate through all adjacent
      vertices. if sum of distance value of u (from source) and weight of
      edge u-v for every adjacent vertex v, is less than the distance value
      of v, then update the distance value of v.
End
#include <iostream>
#include <climits>
#include <set>
using namespace std;
#define N 5
int minDist(int dist[], bool Set[])//calculate minimum distance
{
   int min = INT_MAX, min_index;
   for (int v = 0; v < N; v++)
   if (Set[v] == false && dist[v] <= min)
   min = dist[v], min_index = v;
   return min_index;
}
int printSol(int dist[], int n)//print the solution
{
   cout<<"Vertex Distance from Source\n";
   for (int i = 0; i < N; i++)
   cout<<" \t\t \n"<< i<<" \t\t "<<dist[i];
}
void dijkstra(int g[N][N], int src)
{
   int dist[N];
   bool Set[N];
   for (int i = 0; i < N; i++)
   dist[i] = INT_MAX, Set[i] = false;
   dist[src] = 0;
   for (int c = 0; c < N- 1; c++)
   {
      int u = minDist(dist, Set);
      Set[u] = true;
      for (int v = 0; v < N; v++)
      if (!Set[v] && g[u][v] && dist[u] != INT_MAX && dist[u]
         + g[u][v] < dist[v])
         dist[v] = dist[u] + g[u][v];
   }
   printSol(dist, N);
}
int main()
{
   int g[N][N] = { { 0, 4, 0, 0, 0 },
      { 4, 0, 7, 0, 0 },
      { 0, 8, 0, 9, 0 },
      { 0, 0, 7, 0, 6 },
      { 0, 2, 0, 9, 0 }};
   dijkstra(g, 0);
   return 0;
}
Vertex Distance from Source
0 0
1 4
2 11
3 20
4 26
Algorithms | Recursion | Question 6 - GeeksforGeeks

01 Jun, 2021
Output of following program?
#include<stdio.h>void print(int n){    if (n > 4000)        return;    printf("%d ", n);    print(2*n);    printf("%d ", n);}  int main(){    print(1000);    getchar();    return 0;}
(A) 1000 2000 4000(B) 1000 2000 4000 4000 2000 1000(C) 1000 2000 4000 2000 1000(D) 1000 2000 2000 1000Answer: (B)Explanation: First time n=1000Then 1000 is printed by first printf function then call print(2*1000) then again print 2000 by printf function then call print(2*2000) and it prints 4000 next time print(4000*2) is called.
Here 8000 is greater than 4000 condition becomes true and it return at function(2*4000). Here n=4000 then 4000 will again print through second printf.
Similarly print(2*2000) after that n=2000 then 2000 will print and come back at print(2*1000) here n=1000, so print 1000 through second printf.
Option (B) is correct.Quiz of this Question
vivekkumarmth0077
amalchandranmv
Algorithms-Recursion
Algorithms Quiz
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Algorithms | Graph Traversals | Question 2
Algorithms | Graph Traversals | Question 12
Algorithms | Analysis of Algorithms | Question 17
Algorithms | Graph Traversals | Question 12
Algorithms | Graph Traversals | Question 1
Algorithms | Analysis of Algorithms | Question 8
Algorithms | Sorting | Question 5
Algorithms | Sorting | Question 7
Algorithms | Sorting | Question 1
Algorithms Quiz | Dynamic Programming | Question 8