code-rag-bench/online-tutorials huggingface dataset:
How to create relative frequency table using dplyr in R?

The relative frequency is the proportion of something out of total. For example, if we have 5 bananas, 6 guava, 10 pomegranates then the relative frequency of banana would be 5 divided by the total sum of 5, 6, and 10 that is 21 hence it can be also called proportional frequency.
 Live Demo
Consider the below data frame −
set.seed(21)
x<−sample(LETTERS[1:4],20,replace=TRUE)
Ratings<−sample(1:50,20)
df1<−data.frame(x,Ratings)
df1
x Ratings
1 C 44
2 A 29
3 C 14
4 A 10
5 B 46
6 C 1
7 D 47
8 A 8
9 C 23
10 C 7
11 D 50
12 B 31
13 B 34
14 B 3
15 D 48
16 B 33
17 C 45
18 B 9
19 B 40
20 C 21
Loading dplyr package −
library(dplyr)
Finding the table of relative frequencies of values in x −
df1%>%group_by(x)%>%summarise(n=n())%>%mutate(freq=n/sum(n))
`summarise()` ungrouping output (override with `.groups` argument)
# A tibble: 4 x 3
x n freq
<chr> <int> <dbl>
1 A 3 0.15
2 B 7 0.35
3 C 7 0.35
4 D 3 0.15
Warning message:
`...` is not empty.
We detected these problematic arguments:
* `needs_dots`
These dots only exist to allow future extensions and should be empty.
Did you misspecify an argument?
Note − Do not worry about this warning message because our problem is correctly solved and the warning has no relation with that.
 Live Demo
y<−sample(c("Male","Female"),20,replace=TRUE)
Salary<−sample(20000:50000,20)
df2<−data.frame(y,Salary)
df2
   y Salary
1 Female 40907
2 Female 47697
3 Male 49419
4 Female 23818
5 Male 21585
6 Male 22276
7 Female 21856
8 Male 22092
9 Male 27892
10 Female 47655
11 Male 34933
12 Female 48027
13 Female 48179
14 Male 21460
15 Male 24233
16 Female 43762
17 Female 22369
18 Female 47206
19 Male 34972
20 Female 30222
Finding the relative frequencies of genders in y −
df2%>%group_by(y)%>%summarise(n=n())%>%mutate(freq=n/sum(n))
`summarise()` ungrouping output (override with `.groups` argument)
# A tibble: 2 x 3
y n freq
<chr> <int> <dbl>
1 Female 11 0.55
2 Male 9 0.45
Warning message:
`...` is not empty.
We detected these problematic arguments:
* `needs_dots`
These dots only exist to allow future extensions and should be empty.
Did you misspecify an argument?
EXTRACT() Function in MySQL - GeeksforGeeks

27 Nov, 2020
EXTRACT() function :
This function in MySQL is used to extract a part from a specified date.
Syntax :
EXTRACT(part FROM date)
Parameter :
This method accepts two parameters which are illustrated below:
part – Specified part to extract like SECOND, MINUTE, HOUR, DAY, WEEK, MONTH, YEAR, etc.
date – Specified date to extract a part from.
Returns :
It returns the desired extracted part from a specified date.
Example-1 :
Extracting the week of the specified date “2020-11-24”.
SELECT EXTRACT(WEEK FROM "2020-11-24");
Output :
47
Example-2 :
Extracting hour from the specified date and time “2020-10-22 07:12:23”.
SELECT EXTRACT(HOUR FROM "2020-10-22 07:12:23");
Output :
7
Example-3 :
Extracting Year and month from the specified date and time “2020-10-22 07:12:23”.
SELECT EXTRACT(YEAR_MONTH FROM "2020-10-22 07:12:23");
Output :
202010
DBMS-SQL
mysql
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Update Multiple Columns in Single Update Statement in SQL?
What is Temporary Table in SQL?
SQL Query to Find the Name of a Person Whose Name Starts with Specific Letter
SQL using Python
SQL | Subquery
How to Write a SQL Query For a Specific Date Range and Date Time?
SQL Query to Convert VARCHAR to INT
SQL Query to Delete Duplicate Rows
SQL indexes
SQL Query to Compare Two Dates
GATE | GATE-CS-2003 | Question 90

28 Jun, 2021
The subnet mask for a particular network is 255.255.31.0. Which of the following pairs of IP addresses could belong to this network?(A) 172.57.88.62 and 172.56.87.233(B) 10.35.28.2 and 10.35.29.4(C) 191.203.31.87 and 191.234.31.88(D) 128.8.129.43 and 128.8.161.55Answer: (D)Explanation:  Background required – Subnetting and SubNet Mask
Answer – D
Explanation – Suppose we have a host A with IP Address IPA and Subnet mask of the subnet of which A is a part is Ms. Now when A wants to send packet to a host B with an IP address say IPB, then A will first AND the subnet-Mask Ms with IPA to find out the subnet-id IDN of the subnet in order to identify whether IPB belongs to the same network. Now if B also belongs to the same network, then IPB BITWISE-AND Ms must be equal to IDN which A has calculated.
If IPA and IPB belongs to same network, we must have
    IPA BITWISE-AND Ms == IPBBITWISE-AND Ms

Out of the 4 options, only option D matches.
128.8.129.43 BITWISE-AND 255.255.31.0 = 128.8.1.0
128.8.161.55 BITWISE-AND 255.255.31.0 = 128.8.1.0

You can check rest of the options.
This explanation has been provided by Pranjul Ahuja.Quiz of this Question
GATE-CS-2003
GATE-GATE-CS-2003
GATE
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to fix the height of rows in the table?

29 Jul, 2021
The height of rows ‘tr’ in a table can be fixed very easily. This can be done by adding the height attribute in the tr tag. If the height is not specified, the height of the row changes according to the content. The height can be specified either in pixels, or percentage.
Syntax:
<tr height="px | %">
Approach:
The height attribute is used to set the height of a row. It is added in the <tr> tag.
The height should be specified according to the content, either in pixels or percentage.
If the content in the row is large, it will overflow.
Example: In this example, the height of the first row has been fixed, but the height of the second row has not been. So, when we vary the size of the screen, the height of the first row remains the same, but the height of the second-row changes according to the content. However, if the specified height is not sufficiently large according to the content, this may not work, and the first row will overflow and behave similarly to the second row.
Run the following code and vary the screen-size to see the difference between both the rows:
<!DOCTYPE html><html><head>    <meta charset="UTF-8">    <title>How to fix height of table tr?</title>          <style>        table {            margin-left: auto;            margin-right: auto;            font-size: 10px;            width: 100%;            table-layout:fixed;        }          td {            border: 1px solid black;            text-align: center;            padding: 10px;        }          tr:nth-child(even) {            background-color: green;        }    </style></head><body>  <table>  <!-- row with fixed height-->  <tr height="300px">    <td>Height of this row remains same on varying screen-size</td>    <td>Geeks for Geeks</td>    <td>        Geeks for Geeks is a Computer Science        Portal created with the goal of        providing well written, well thought        and well-explained solutions for        selected questions.    </td>  </tr>  <!-- row without fixed height-->  <tr>    <td>Height of this row changes on varying screen-size</td>    <td>Geeks for Geeks</td>    <td>        Geeks for Geeks is a Computer Science        Portal created with the goal of        providing well written, well thought        and well-explained solutions for        selected questions.    </td>  </tr></table>  </body></html>
Output:
Before decreasing screen-size:
After decreasing screen-size:
HTML is the foundation of webpages, is used for webpage development by structuring websites and web apps.You can learn HTML from the ground up by following this HTML Tutorial and HTML Examples.
HTML-Misc
Picked
HTML
Web Technologies
Write From Home
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to find the maximum element of an Array using STL in C++?

19 Mar, 2022
Given an array arr[], find the maximum element of this array using STL in C++.Example:  
Input: {1, 45, 54, 71, 76, 12}
Output: 76

Input: {1, 7, 5, 4, 6, 12}
Output: 12
Approach: Max or Maximum element can be found with the help of *max_element() function provided in STL.Syntax:  
*max_element (first_index, last_index);
CPP
// C++ program to find the max// of Array using sort() in STL #include <bits/stdc++.h>using namespace std; int main(){    // Get the array    int arr[] = { 1, 45, 54, 71, 76, 12 };     // Compute the sizes    int n = sizeof(arr) / sizeof(arr[0]);     // Print the array    cout << "Array: ";    for (int i = 0; i < n; i++)        cout << arr[i] << " ";     // Find the maximum element    cout << "\nMax Element = " << *max_element(arr, arr + n);    return 0;}
Array: 1 45 54 71 76 12 
Max Element = 76
Time Complexity:- O(n)
surbhikumaridav
cpp-array
STL
C++
STL
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C++ iostream Library - cin Object

The object of class istream that represents the standard input stream oriented to narrow characters (of type char). It corresponds to the C stream stdin. The standard input stream is a source of characters determined by the environment. It is generally assumed to be input from an external source, such as the keyboard or a file.
Object of class istream, characters can be retrieved either as formatted data using the extraction operator (operator>>) or as unformatted data, using member functions such as read.
Following is the declaration for std::cin.
extern istream cin;
cin is tied to the standard output stream cout (see ios::tie), which indicates that cout's buffer is flushed (see ostream::flush) before each i/o operation performed on cin.
The program should not mix input operations on cin with input operations on wcin (or with other wide-oriented input operations on stdin): Once an input operation has been performed on either, the standard input stream acquires an orientation (either narrow or wide) that can only be safely changed by calling freopen on stdin.
 Print
 Add Notes
 Bookmark this page
C# Program to replace a character with asterisks in a sentence

Use the Replace() method to replace a character with asterisks.
Let’s say our string is −
string str = "dem* text";
To replace it, use the Replace() method −
str.Replace('*', 'o');
Here is the complete code −
 Live Demo
using System;
public class Program {
   public static void Main() {
      string str = "dem* text";
      Console.WriteLine("Initial string = " + str);
      string res = str.Replace('*', 'o');
      // after replacing
      Console.WriteLine("After replacing asterisk = " + res.ToString());
   }
}
Initial string = dem* text
After replacing asterisk = demo text
Compare array elements to equality - JavaScript

We are required to write a function which compares how many values match in an array.
It should be sequence dependent. That means i.e. the first object in the first array should be compared to equality to the first object in the second array and so on.
For example −
If the two input arrays are −
const arr1 = [4, 7, 4, 3, 3, 3, 7, 6, 5];
const arr2 = [6, 5, 4, 5, 3, 2, 5, 7, 5];
Then the output should be 3.
We can solve this problem simply by using a for loop and checking values at the corresponding indices in both the arrays.
Following is the code −
const arr1 = [4, 7, 4, 3, 3, 3, 7, 6, 5];
const arr2 = [6, 5, 4, 5, 3, 2, 5, 7, 5];
const correspondingEquality = (arr1, arr2) => {
   let res = 0;
   for(let i = 0; i < arr1.length; i++){
      if(arr1[i] !== arr2[i]){
         continue;
      };
      res++;
   };
   return res;
};
console.log(correspondingEquality(arr1, arr2));
This will produce the following output in console −
3
alias command in Linux with Examples - GeeksforGeeks

19 Nov, 2021
alias command instructs the shell to replace one string with another string while executing the commands. 
When we often have to use a single big command multiple times, in those cases, we create something called as alias for that command. Alias is like a shortcut command which will have same functionality as if we are writing the whole command. 
Syntax:  
alias [-p] [name[=value] ... ]
  Creating an alias : 
Syntax: 
alias name="value"
Creating an Unalias : Removing an existing alias is known as unaliasing. Syntax: 
unalias [alias name]
Options for Alias command: 
-p option : This option prints all the defined aliases is reusable format. Syntax: 
Syntax: 
alias -p
–help option : It displayes help Information. Syntax: 
Syntax: 
alias --help
How to remove an alias? We use unailas command for this purpose. 
How to permanently store aliases across sessions? We can store aliases in shell configuration files. For example for Bash Shell, we can write in ~/.bashrc. 
alias CD="cd Desktop" 
YouTubeGeeksforGeeks500K subscribersLinux Tutorials | Command Substitution and Shell Aliasing | GeeksforGeeksWatch laterShareCopy linkInfoShoppingTap to unmuteIf playback doesn't begin shortly, try restarting your device.You're signed outVideos you watch may be added to the TV's watch history and influence TV recommendations. To avoid this, cancel and sign in to YouTube on your computer.CancelConfirmMore videosMore videosSwitch cameraShareInclude playlistAn error occurred while retrieving sharing information. Please try again later.Watch on0:000:000:00 / 8:43•Live•<div class="player-unavailable"><h1 class="message">An error occurred.</h1><div class="submessage"><a href="https://www.youtube.com/watch?v=rTAKKboE-0M" target="_blank">Try watching this video on www.youtube.com</a>, or enable JavaScript if it is disabled in your browser.</div></div>
?t=291  
sumitgumber28
linux-command
Linux-misc-commands
Picked
Technical Scripter 2018
Linux-Unix
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
TCP Server-Client implementation in C
ZIP command in Linux with examples
tar command in Linux with examples
Conditional Statements | Shell Script
UDP Server-Client implementation in C
curl command in Linux with Examples
tee command in Linux with examples
echo command in Linux with Examples
Cat command in Linux with examples
touch command in Linux with Examples
How to retrieve data from JSON file using jQuery and Ajax?

To retrieve data from JSON file using jQuery and Ajax, use the jQuery.getJSON( url, [data], [callback] )The jQuery.getJSON( url, [data], [callback] ) method loads JSON data from the server using a GET HTTP request.
Here is the description of all the parameters used by this method −
url − A string containing the URL to which the request is sent
data − This optional parameter represents key/value pairs that will be sent to the server.
callback − This optional parameter represents a function to be executed whenever the data is loaded successfully.
Let’s say we have the following JSON content in result.json file −
{
"name": "John",
"age" : "30",
"sex": "male"
}
The following is the code snippet showing the usage of this method −
  <head>
      <title>The jQuery Example</title>
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
       
      <script>
         $(document).ready(function() {
           
            $("#driver").click(function(event){
               $.getJSON('result.json', function(jd) {
                  $('#stage').html('<p> Name: ' + jd.name + '</p>');
                  $('#stage').append('<p>Age : ' + jd.age+ '</p>');
                  $('#stage').append('<p> Sex: ' + jd.sex+ '</p>');
               });
            });
               
         });
      </script>
   </head>
   
   <body>
   
      <p>Click on the button to load result.html file:</p>
       
      <div id = "stage" style = "background-color:#cc0;">
         STAGE
      </div>
       
      <input type = "button" id = "driver" value = "Load Data" />
       
   </body>
Stream.Builder build() in Java - GeeksforGeeks

06 Dec, 2018
Stream.Builder build() builds the stream, transitioning this builder to the built state.
Syntax :
Stream<T> build()

Exceptions :
IllegalStateException : If the builder has already transitioned to the built state, IllegalStateException is thrown. It signals that a method has been invoked at an illegal or inappropriate time. In other words, the Java environment or Java application is not in an appropriate state for the requested operation.
Return Value : The built stream.
Note : A stream builder has a lifecycle, which starts in a building phase, during which elements can be added, and then transitions to a built phase, after which elements may not be added. The built phase begins when the build() method is called, which creates an ordered stream whose elements are the elements that were added to the stream builder, in the order they were added.
Example 1 :
// Java code to show the implementation// of Stream.Builder build()import java.util.stream.Stream;  class GFG {      // Driver code    public static void main(String[] args)    {          Stream.Builder<String> str_b = Stream.builder();          str_b.add("Geeks");        str_b.add("for");        str_b.add("GeeksforGeeks");        str_b.add("Data Structures");        str_b.add("Geeks Classes");          // creating the string stream        Stream<String> s = str_b.build();          // printing the elements        s.forEach(System.out::println);    }}
Output :
Geeks
for
GeeksforGeeks
Data Structures
Geeks Classes

Example 1 :
// Java code to show the implementation// of Stream.Builder build()import java.util.stream.Stream;  class GFG {      // Driver code    public static void main(String[] args)    {          Stream.Builder<String> str_b = Stream.builder();          str_b.add("Geeks");        str_b.add("for");        str_b.add("GeeksforGeeks");        str_b.add("Data Structures");        str_b.add("Geeks Classes");          // creating the string stream        Stream<String> s = str_b.build();          // printing the elements        s.forEach(System.out::println);    }}
Output :
Geeks
for
GeeksforGeeks
Data Structures
Geeks Classes

Java - util package
Java-Functions
java-stream
Java-Stream-Builder
Java
Java
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
Object Oriented Programming (OOPs) Concept in Java
ArrayList in Java
How to iterate any Map in Java
Multidimensional Arrays in Java
Singleton Class in Java
Stack Class in Java
Set in Java
Multithreading in Java
Maximum size square submatrix with all 1s

When a binary matrix is given, our task is to find a square matrix whose all elements are 1.
For this problem, we will make an auxiliary size matrix, whose order is the same as the given matrix. This size matrix will help to represent, in each entry Size[i, j], is the size of a square matrix with all 1s. From that size matrix, we will get the maximum number to get the size of the biggest square matrix.
Input:
The binary matrix.
0 1 1 0 1
1 1 0 1 0
0 1 1 1 0
1 1 1 1 1
0 0 0 0 0

Output:
The largest submatrix with all 1’s.



subMatWithOne(given matrix)
Input − The main matrix.
Output − Display the square matrix with all 1, which one is the largest.
Begin
   define subMat whose order is same as given matrix
   copy first row and first column of given matrix to subMat

   for all row i (1 to n), do
      for all column j (1 to n), do
         if matrix[i, j] = 1, then
            subMat[i, j] := 1 + minimum of subMat[i, j-1]
            and subMat[i-1, j-1]
         else
            subMat[i, j] := 0
      done
   done

   maxSize := subMat[0, 0], iMax := 0 and jMax := 0
   for all row i and column j, do
      if maxSize < subMat[i, j], then
         maxSize := subMat[i, j]
         iMax := i, jMax := j
   done

   print sub matrix from row = iMax to (iMax - maxSize), and column jMax to (jMax - maxSize)
End
#include<iostream>
#define ROW 6
#define COL 5
using namespace std;

int matrix[ROW][COL] =  {
   {0, 1, 1, 0, 1},
   {1, 1, 0, 1, 0},
   {0, 1, 1, 1, 0},
   {1, 1, 1, 1, 0},
   {1, 1, 1, 1, 1},
   {0, 0, 0, 0, 0}
};

int min(int a, int b, int c) {
   return ((a<b?a:b))?((a<c)?a:c):((b<c)?b:c);
}

void subMatWithOne() {
   int subMat[ROW][COL];
   int maxSize, iMax, jMax;

   for(int i = 0; i < ROW; i++)    //copy first row of matrix to sub matrix
      subMat[i][0] = matrix[i][0];

   for(int j = 0; j < COL; j++)    //copy first column of matrix to sub matrix
      subMat[0][j] = matrix[0][j];

   for(int i = 1; i < ROW; i++) {
      for(int j = 1; j < COL; j++) {
         if(matrix[i][j] == 1)    //find minimum of left, top and diagonal element + 1
            subMat[i][j] = min(subMat[i][j-1], subMat[i-1][j], subMat[i-1][j-1]) + 1;
         else
            subMat[i][j] = 0;    //if item is 0, put only 0
      }  
   }

   maxSize = subMat[0][0]; iMax = 0; jMax = 0;
   for(int i = 0; i < ROW; i++) {    //find the order of sub square matrix

      for(int j = 0; j < COL; j++) {
         if(maxSize < subMat[i][j]) {

            maxSize = subMat[i][j];
            iMax = i;
            jMax = j;
         }      
      }                
   }  
 
   cout << "Subsquare matrix: "<<endl;
   for(int i = iMax; i > iMax - maxSize; i--) {    //print the submatrix using max size
      for(int j = jMax; j > jMax - maxSize; j--) {
         cout << matrix[i][j]<<" ";
      }
      cout << endl;
   }
}  
 
int main() {
   subMatWithOne();
} 
Subsquare matrix:
1 1 1
1 1 1
1 1 1
Date before() method in Java with Examples - GeeksforGeeks

02 Jan, 2019
The before() method of Java Date class tests whether the date is before the specified date or not.
Syntax:
public boolean before(Date when)

Parameters: The function accepts a single parameter when which specifies the date that has to be checked.
Return Value: It returns a Boolean value. It will return true if this date is before the specified date otherwise false.
Exception: The function throws a single exception that is NullPointerException if when is null.
Program below demonstrates the above mentioned function:
// Java code to demonstrate// before() function of Date class  import java.util.Date;import java.util.Calendar;public class GfG {    // main method    public static void main(String[] args)    {          // creating a Calendar object        Calendar c = Calendar.getInstance();          // set Month        // MONTH starts with 0 i.e. ( 0 - Jan)        c.set(Calendar.MONTH, 11);          // set Date        c.set(Calendar.DATE, 05);          // set Year        c.set(Calendar.YEAR, 1996);          // creating a date object with specified time.        Date dateOne = c.getTime();          System.out.println("Date 1: " + dateOne);          // creating a date of object        // storing the current date        Date currentDate = new Date();          System.out.println("Date 2: " + currentDate);          System.out.println("Is Date 2 before Date 1: "                         + currentDate.before(dateOne));    }}
Date 1: Thu Dec 05 08:15:01 UTC 1996
Date 2: Wed Jan 02 08:15:01 UTC 2019
Is Date 2 before Date 1: false

// Java code to demonstrate// before() function of Date class  import java.util.Date;  public class GfG {    // main method    public static void main(String[] args)    {          // creating a date of object        // storing the current date        Date currentDate = new Date();          System.out.println("Date 1: " + currentDate);          // specifiedDate is assigned to null.        Date specifiedDate = null;          System.out.println("Date 1: " + specifiedDate);          System.out.println("On checking these 2 dates: ");          try {            // throws NullPointerException            System.out.println(currentDate                                   .before(specifiedDate));        }        catch (Exception e) {            System.out.println("Exception: " + e);        }    }}
Date 1: Wed Jan 02 08:15:06 UTC 2019
Date 1: null
On checking these 2 dates: 
Exception: java.lang.NullPointerException

Java - util package
Java-Functions
Java-util-Date
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Different ways of Reading a text file in Java
Stream In Java
Constructors in Java
Generics in Java
Exceptions in Java
Functional Interfaces in Java
Comparator Interface in Java with Examples
Commonly Asked Java Programming Interview Questions | Set 2
HashMap get() Method in Java
Strings in Java
StringBuilder.ToString() Method in C#

The StringBuilder.ToString() method in C# is used to convert the value of a
StringBuilder to a String.
The syntax is as follows −
public override string ToString ();
public string ToString (int begnIndex, int len);
Above, the parameter begnIndex is the starting position of the substring in this instance, whereas len is the length of the substring.
Let us now see an example −
 Live Demo
using System;
using System.Text;
public class Demo{
   public static void Main(){
      StringBuilder strBuilder = new StringBuilder("Katie");
      Console.WriteLine("String = "+strBuilder.ToString());
      Console.WriteLine("\nStringBuilder capacity = "+strBuilder.Capacity);
      Console.WriteLine("StringBuilder length = "+strBuilder.Length);
      strBuilder.EnsureCapacity(35);
      Console.WriteLine("\nStringBuilder capacity= "+strBuilder.Capacity);
      Console.WriteLine("StringBuilder length = "+strBuilder.Length);
      strBuilder.EnsureCapacity(0);
      strBuilder.Length = 0;
      Console.WriteLine("\nStringBuilder capacity= "+strBuilder.Capacity);
      Console.WriteLine("StringBuilder length = "+strBuilder.Length);
   }
}
This will produce the following output −
String = Katie
StringBuilder capacity = 16
StringBuilder length = 5
StringBuilder capacity= 35
StringBuilder length = 5
StringBuilder capacity= 35
StringBuilder length = 0
Let us now see another example −
 Live Demo
using System;
using System.Text;
public class Demo{
   public static void Main(){
      StringBuilder strBuilder = new StringBuilder("TomHanks");
      Console.WriteLine("StringBuilder = "+strBuilder.ToString());
      Console.WriteLine("String = "+strBuilder.ToString(3, 5));
      Console.WriteLine("\nStringBuilder capacity = "+strBuilder.Capacity);
      Console.WriteLine("StringBuilder length = "+strBuilder.Length);
      strBuilder.EnsureCapacity(35);
      Console.WriteLine("\nStringBuilder capacity= "+strBuilder.Capacity);
      Console.WriteLine("StringBuilder length = "+strBuilder.Length);
      strBuilder.EnsureCapacity(0);
      strBuilder.Length = 0;
      Console.WriteLine("\nStringBuilder capacity= "+strBuilder.Capacity);
      Console.WriteLine("StringBuilder length = "+strBuilder.Length);
   }
}
This will produce the following output −
StringBuilder = TomHanks
String = Hanks
StringBuilder capacity = 16
StringBuilder length = 8
StringBuilder capacity= 35
StringBuilder length = 8
StringBuilder capacity= 35
StringBuilder length = 0
How to Build a Web Server Docker File? - GeeksforGeeks

16 Oct, 2020
In this article, you can learn how to create your own docker customized image and get familiar with the docker file. Similarly, you can build a web server image that can be used to build containers. Here we will be exploring the process of using an Apache Web Server on Ubuntu to build our docker image.
Installed docker software in your respective operating system.
Follow the below steps to achieve so:
Step 1: The first step is to build our Docker file for which you can use vim editor. 
vim Dockerfile

Note:- Name of the file has to be “Dockerfile”
Write the below information into the Docker file.
FROM ubuntu
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install apache2 -y
RUN apt-get install apache2-utils -y
RUN apt-get clean
EXPOSE 80
CMD ["apache2ctl","-D","FOREGROUND"]


Description of the above commands
Ubuntu is our base image in which we are launching our server.
In the second line, is to set a non-interactive environment.
In the third line, the apt-get update command is used to update all the packages on Ubuntu.
In the fourth line, we are installing apache2 on our image.
In the fifth line, we are installing all the necessary utility Apache packages.
In the sixth line, the apt-get clean command cleans all the unnecessary files from the system.
In the seventh line, the EXPOSE command is used to expose the port 80 of Apache in the container.
The last command is used to run apache2 in the background.
Step 2: Next step is to build the docker file by using the docker build command.
docker build -t="mywebserver"

Command:
-t: this option is to tag the image, mywebserver is the tag to our image.

After the building of the image is finished, a message will print in the end that the has to build.
Step 3:
The web server file has built, the next step is to create a container from the image for that we use the docker run command.
docker run -d -p 80:80 tag_name

Commands:
-d: This option is used to run the container in detached mode i.e the container 
    can run in the background.

-p: This option is used to map our port number with 5000 port numbers on our localhost.
 Now run the docker images command to see the built image.
If you go to your web browser and write localhost_ip:80 your Apache server is up and running on that port.
This is the complete process to build a web server docker file.
Advanced Computer Subject
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
ML | Linear Regression
Decision Tree
Copying Files to and from Docker Containers
System Design Tutorial
Python | Decision tree implementation
Decision Tree Introduction with example
Reinforcement learning
ML | Underfitting and Overfitting
Clustering in Machine Learning
KDD Process in Data Mining
Function returning another function in JavaScript

Following is the code wherein a function returns another function in JavaScript −
 Live Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   }
   .result {
      font-size: 18px;
      font-weight: 500;
      color: blueviolet;
   }
</style>
</head>
<body>
<h1>Function returning another function in JavaScript</h1>
<div class="result"></div>
<button class="Btn">CLICK HERE</button>
<h3>Click on the above button to double the number</h3>
<script>
   let BtnEle = document.querySelector(".Btn");
   let resEle = document.querySelector(".result");
   function test() {
      let b = 1;
      return function () {
         resEle.innerHTML = "Number = " + (b *= 2);
      };
   }
   let returnFunc = test();
   BtnEle.addEventListener("click", () => {
      returnFunc();
   });
</script>
</body>
</html>
On clicking the ‘CLICK HERE’ button, the number will be multiplied by 2 on each click −
jQuery - Slidebar.js

Slidebars is a jQuery plugin for quickly and easily implementing app style off-canvas menus and sidebars into your website.
A Simple of slidebar example as shown below −
<!doctype html>
<html>
   
   <head>
      <title>Slidebars Animation Styles</title>
      <meta name = "viewport" content = "width = device-width, 
         initial-scale = 1.0, minimum-scale = 1.0, 
         maximum-scale = 1.0, user-scalable = no">
      <link rel = "stylesheet" href = "slidebars.css">
      <link rel = "stylesheet" href = "example-styles.css">
   </head>
	
   <body>
      <div id = "sb-site">
         <h1>Tutorilaspoint</h1>
			
         <p>Slidebars is a jQuery plugin for quickly and easily
            implementing app style off-canvas menus and sidebars into your website.</p>
			
         <ul>
            <li class = "sb-toggle-left">Click here for slider</li> 
         </ul>
      </div>
		
      <div class = "sb-slidebar sb-left sb-style-push">
         <p>Android</p>
         <hr/>
         <p>Java</p>
         <hr/>
         <p>CSS</p>
         <hr/>
         <p>PHP</p>
         <hr/>
      </div>
	
      <script 
         src = "https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
      </script>	
      <script src = "slidebars.js">
      </script>
		
      <script>
         (function($) {
            $(document).ready(function() {
               $.slidebars();
            });
         }) (jQuery);
      </script>
   </body>
</html>
This should produce following result −

    27 Lectures 
     1 hours 

 Mahesh Kumar

    27 Lectures 
     1.5 hours 

 Pratik Singh

    72 Lectures 
     4.5 hours 

 Frahaan Hussain

    60 Lectures 
     9 hours 

 Eduonix Learning Solutions

    17 Lectures 
     2 hours 

 Sandip Bhattacharya

    12 Lectures 
     53 mins

 Laurence Svekis
 Print
 Add Notes
 Bookmark this page
Python Tuple tuple() Method

Python tuple method tuple() converts a list of items into tuples
Following is the syntax for tuple() method −
tuple( seq )

seq − This is a sequence to be converted into tuple.
seq − This is a sequence to be converted into tuple.
This method returns the tuple.
The following example shows the usage of tuple() method.
#!/usr/bin/python

aList = [123, 'xyz', 'zara', 'abc']
aTuple = tuple(aList)
print "Tuple elements : ", aTuple
When we run above program, it produces following result −
Tuple elements :  (123, 'xyz', 'zara', 'abc')
How to concatenate two files into a new file using Python?

To merge multiple files in a new file, you can simply read files and write them to a new file using loops.
filenames = ['file1.txt', 'file2.txt', 'file3.txt']
with open('output_file', 'w') as outfile:
    for fname in filenames:
        with open(fname) as infile:
            outfile.write(infile.read())
If you have very big files, instead of writing them at once, you could write them line by line.
filenames = ['file1.txt', 'file2.txt', 'file3.txt']
with open('output_file', 'w') as outfile:
    for fname in filenames:
        with open(fname) as infile:
            for line in infile:
                outfile.write(line)
File.ReadAllText(String) Method in C# with Examples

26 Feb, 2021
File.ReadAllText(String) is an inbuilt File class method that is used to open a text file then reads all the text in the file and then closes the file.Syntax:  
public static string ReadAllText (string path);
Parameter: This function accepts a parameter which is illustrated below:  
path: This is the specified file to open for reading.
Exceptions: 
ArgumentException: The path is a zero-length string, contains only white space, or one or more invalid characters as defined by InvalidPathChars.
ArgumentNullException: The path is null.
PathTooLongException: The specified path, file name, or both exceed the system-defined maximum length.
DirectoryNotFoundException: The specified path is invalid.
IOException: An I/O error occurred while opening the file.
UnauthorizedAccessException: The path specified a file that is read-only. OR this operation is not supported on the current platform. OR the path specified a directory. OR the caller does not have the required permission.
FileNotFoundException: The file specified in the path was not found.
NotSupportedException: The path is in an invalid format.
SecurityException: The caller does not have the required permission.
Return Value: Returns a string containing all the text in the file.Below are the programs to illustrate the File.ReadAllText(String) method.Program 1: Initially, a file file.txt is created with some contents shown below- 
 
C#
// C# program to illustrate the usage// of File.ReadAllText(String) method  // Using System, System.IO and// System.Text namespacesusing System;using System.IO;using System.Text;  class GFG {    public static void Main()    {        // Specifying a file        string path = @"file.txt";          // Calling the ReadAllText() function        string readText = File.ReadAllText(path);          // Printing the file contents        Console.WriteLine(readText);    }}
Output:  
GFG
gfg
Geeks
GeeksforGeeks
geeksforgeeks
Program 2: Initially, no file was created. Below code itself create a file file.txt with some specified contents. 
C#
// C# program to illustrate the usage// of File.ReadAllText(String) method  // Using System, System.IO and// System.Text namespacesusing System;using System.IO;using System.Text;  class GFG {    public static void Main()    {        // Specifying a file        string path = @"file.txt";          // Adding below contents to the file        string[] createText = { "GFG", "is", "a", "CS", "portal" };        File.WriteAllLines(path, createText);          // Calling the ReadAllText() function        string readText = File.ReadAllText(path);          // Printing the file contents        Console.WriteLine(readText);    }}
Output:  
GFG
is
a
CS
portal
arorakashish0911
CSharp-File-Handling
C#
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Compiled or Interpreted ?

02 Aug, 2019
In various books of python programming, it is mentioned that python language is interpreted. But that is half correct the python program is first compiled and then interpreted. The compilation part is hidden from the programmer thus, many programmers believe that it is an interpreted language. The compilation part is done first when we execute our code and this will generate byte code and internally this byte code gets converted by the python virtual machine(p.v.m) according to the underlying platform(machine+operating system).Now the question is – if there is any proof that python first compiles the program internally and then run the code via interpreter?The answer is yes! and note this compiled part is get deleted by the python(as soon as you execute your code) just it does not want programmers to get into complexity.
Code : Sample Python code
print("i am learning python")print("i am enjoying it")
now if you run this code using command prompt just save this above code in notepad and save with the extension “.py”syntax: python (name of the program.py) and press enter.Note: If you are writing code in the notepad just save the code with extension “py” inlet suppose you have created a folder named python_prog in d drive.
as you press enter the byte code will get generated. A folder created and this will contain the byte code of your program. This folder is in the python_prog folder where you will save your python codes.
now to run the compiled byte code just type the following command in the command prompt:-the extension .pyc is python compiler..
Thus, it is proven that python programs are both compiled as well as interpreted!! but the compilation part is hidden from the programmer.
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 | os.path.join() method
Introduction To PYTHON
Python OOPs Concepts
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
Create a directory in Python
Write a one line C function to round floating point numbers

02 Jun, 2017
Algorithm: roundNo(num)1. If num is positive then add 0.5.2. Else subtract 0.5.3. Type cast the result to int and return.
Example:num = 1.67, (int) num + 0.5 = (int)2.17 = 2num = -1.67, (int) num – 0.5 = -(int)2.17 = -2Implementation:
/* Program for rounding floating point numbers */# include<stdio.h>  int roundNo(float num){    return num < 0 ? num - 0.5 : num + 0.5;}  int main(){    printf("%d", roundNo(-1.777));    getchar();    return 0;}
Output: -2
Time complexity: O(1)Space complexity: O(1)
Now try rounding for a given precision. i.e., if given precision is 2 then function should return 1.63 for 1.63322 and -1.63 for 1.6332.
C-Data Types
c-puzzle
C Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Substring in C++
Multidimensional Arrays in C / C++
Function Pointer in C
Left Shift and Right Shift Operators in C/C++
Different Methods to Reverse a String in C++
std::string class in C++
Unordered Sets in C++ Standard Template Library
rand() and srand() in C/C++
Power Function in C/C++
Enumeration (or enum) in C
Design Turing machine for multiplication

A Turing machine is a seven tuples
(Q, Σ, Γ, δ, q0, qacc, qrej)
Where,
Q is a finite set of states;
Q is a finite set of states;
Σ is the input alphabet does not contain the blank symbol t;
Σ is the input alphabet does not contain the blank symbol t;
Γ is the tape alphabet, where t ∈ Γ and Σ ⊆ Γ;
Γ is the tape alphabet, where t ∈ Γ and Σ ⊆ Γ;
δ: (Q × Γ) → (Q × Γ × {L, R}) is the transition function;
δ: (Q × Γ) → (Q × Γ × {L, R}) is the transition function;
q0 ∈ Q is the start state;
q0 ∈ Q is the start state;
qacc ∈ Q is the accept state;
qacc ∈ Q is the accept state;
qrej ∈ Q is the reject state, where qrej ≠ qacc.
qrej ∈ Q is the reject state, where qrej ≠ qacc.
Construct Turing machine (TM) for multiplication of two unary integers.
Multiplication of two unary integers
3*2=6
In Turing Machine 3 represents − 111
                  2 represents − 11
Let ‘M’ be a symbol used to separate two integers
Here B= blank
M= Symbol used two separate two integers
⇑= Head
After performing multiplication, the output is as follows −
The TM for multiplication is given below −
q0 − Looking at the first unused symbol in input.
q0 − Looking at the first unused symbol in input.
q0 − Looking at the first unused symbol in input.
q0 − Looking at the first unused symbol in input.
q1 − Found a 1 in the first factor; skipping to the x symbol
q1 − Found a 1 in the first factor; skipping to the x symbol
q2 − Found x
q2 − Found x
q4 − Found a 1 in the second factor; changed it to Y; skipping to the =
q4 − Found a 1 in the second factor; changed it to Y; skipping to the =
q3 − Used all the 1s in the second factor; convert the Ys back to 1s
q3 − Used all the 1s in the second factor; convert the Ys back to 1s
q5 − Skipping to end of tape
q5 − Skipping to end of tape
q6 − Skipping back to =
q6 − Skipping back to =
q7 − Skipping back over second factor
q7 − Skipping back over second factor
q8 − Found Y marking previously used 1 from second factor
q8 − Found Y marking previously used 1 from second factor
q9 − Skip back over 1ʼs in first factor
q9 − Skip back over 1ʼs in first factor
q12 − Consumed the entire first factor; convert xs back to 1s
q12 − Consumed the entire first factor; convert xs back to 1s
q11 − Found ⊔
q11 − Found ⊔
PHP ereg() Function

03 Feb, 2021
The Ereg() function in PHP searches a string to match the regular expression given in the pattern. The function is case-sensitive. This function has been deprecated in PHP 5.3.0 and removed in PHP 7.0.0.
Syntax:
int ereg ( string $pattern , string $str, array &$arr );
Parameters:
pattern: It is a regular case-sensitive expression.
str: It is the input string.
arr: It’s an optional input parameter that contains an array of all matched expressions that were grouped by parentheses in the regular expression.
Return value:
If the pattern is found, the function will return true else false. It returns the length of the matched string if the pattern match was found in the string, or false if no match was found or an error occurred.  The function returns 1 if the optional parameter arr has not been passed or the length of the matched string is 0.
Example 1:  In this example, the statement checks whether the subject provided to ereg() function contains .org or not.
PHP
<?php   echo ereg("(\.)(org$)", "www.geeksforgeeks.org");  ?>
Output: 
1
Example 2: This example examines whether the subject begins with ‘g’ or not. The ‘^’ symbol is used to check if the subject starts with the required string.
PHP
<?php  echo ereg("g","gfg");    ?>
Output: 
1
Example 3: In this example, the following code snippet will take the date in DD-MM-YYYY format and print it in ISO format (YYYY-MM-DD).
PHP
<?php  if (ereg ("([0-9]{1,2})-([0-9]{1,2})-([0-9]{4})",            "10-12-1999", $arr)) {     echo "$arr[3]-$arr[2]-$arr[1]";  } else {     echo "Invalid date format entered";  }  ?>
Output: 
1999-12-10
PHP-function
Picked
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to fetch data from localserver database and display on HTML table using PHP ?
Difference between HTTP GET and POST Methods
Different ways for passing data to view in Laravel
PHP | file_exists( ) Function
PHP | Ternary Operator
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Installation of Node.js on Linux
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
What is a Fieldset in HTML ?

21 Sep, 2021
The <fieldset> is used for grouping all the controls of the form together to give it a structured look. It adds a border around the form to give it a differentiated look from all the other parts of the web page. We can also use the <legend> tag to give a caption to the form which is included inside the <fieldset>.
Syntax : 
<fieldset>....</fieldset>
Attributes:
disabled: It specifies that the group of related form elements should be disabled.
form: It specifies that one or more forms the fieldset belongs to.
name: It specifies the name for the fieldset.
Example 1:
HTML
<!DOCTYPE html><html>  <body>    <form>        <fieldset>            <legend>Details</legend>             Student Name: <input type="text">            <br /> MCA Subjects: <input type="text">            <br /> Class: <input type="text">        </fieldset>    </form></body>  </html>
 
Output:
Example 2:
HTML
<!DOCTYPE html><html>  <body>    <form>        <fieldset>            <legend>Details</legend>            <label for="fname">First name:</label>            <input type="text" id="fname" name="fname">            <br>            <br>            <label for="lname">Last name:</label>            <input type="text" id="lname" name="lname">            <br>            <br>            <label for="email">Email:</label>            <input type="email" id="email" name="email">            <br>            <br>            <input type="submit" value="Submit">        </fieldset>    </form></body>  </html>
Output:
Blogathon-2021
HTML-Questions
HTML-Tags
Picked
Blogathon
HTML
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Import JSON Data into SQL Server?
SQL Query to Convert Datetime to Date
Python program to convert XML to Dictionary
Scrape LinkedIn Using Selenium And Beautiful Soup in Python
How to toggle password visibility in forms using Bootstrap-icons ?
How to update Node.js and NPM to next version ?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to insert spaces/tabs in text using HTML/CSS?
REST API (Introduction)
Hide or show elements in HTML using display property
unordered_map find in C++ STL

24 Dec, 2018
find function in C++ is used to search for a specific key in an unordered map.
Syntax
unordered_map.find(key);
Parameters: It takes the key as a parameter.
Return values: If the given key exists in unordered_map it returns an iterator to that element otherwise it returns the end of the map iterator.
Below program illustrate the working of find function:
// CPP program to demonstrate implementation of// find function in unordered_map.#include <bits/stdc++.h>using namespace std;  int main(){    unordered_map<int, bool> um;      um[12] = true;    um[6789] = false;    um[456] = true;      // Searching for element 23    if (um.find(23) == um.end())        cout << "Element Not Present\n";    else        cout << "Element Present\n";      // Searching for element 12    if (um.find(12) == um.end())        cout << "Element Not Present\n";    else        cout << "Element Present\n";      return 0;}
Element Not Present
Element Present

Time Complexity : O(1) on average.
cpp-unordered_map
cpp-unordered_map-functions
Picked
STL
C++
STL
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Sorting a vector in C++
Polymorphism in C++
Friend class and function in C++
Pair in C++ Standard Template Library (STL)
std::string class in C++
Queue in C++ Standard Template Library (STL)
Unordered Sets in C++ Standard Template Library
std::find in C++
List in C++ Standard Template Library (STL)
Inline Functions in C++