code-rag-bench/online-tutorials huggingface dataset:
How to create fading buttons with CSS?

Following is the code to create fading buttons with CSS −
 Live Demo
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
button {
   background-color: rgb(255, 175, 222);
   border: none;
   color: black;
   padding: 25px;
   text-align: center;
   font-size: 20px;
   margin: 4px 2px;
   transition: 0.3s;
   font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
   font-weight: bolder;
}
button:hover {
   background-color: #4d0036;
   color: white;
}
</style>
</head>
<body>
<h1>Fading Button Example</h1>
<button>Hover Here</button>
<h1>Hover on the above button to see background fade on button</h1>
</body>
</html>
The above code will produce the following output −
On hovering the button darker background will fade in −
How to increase varchar size of an existing column in a database without breaking existing data in MySQL?

Increase the varchar size of an existing column in a database with the help of CHANGE command. The syntax is as follows −
alter table yourTableName change yourColumnName yourColumnName dataType;
Here, we are creating a table with a single column and varchar size 200 −
mysql> create table IncreaseVarcharDemo
   −> (
   −> StudentId varchar(200)
   −> );
Query OK, 0 rows affected (0.60 sec)
Now insert record in the table. The query is as follows −
mysql> insert into IncreaseVarcharDemo values('John123');
Query OK, 1 row affected (0.16 sec)
Displaying all records from the table with the help of the following query −
mysql> select *from IncreaseVarcharDemo;
The following is the output −
+-----------+
| StudentId |
+-----------+
| John123   |
+-----------+
1 row in set (0.00 sec)
The following is the query to increase varchar size from 200 to 1000 −
mysql> alter table IncreaseVarcharDemo change StudentId StudentId varchar(1000);
Query OK, 0 rows affected (0.18 sec)
Records: 0 Duplicates: 0 Warnings: 0
Now you can check the varchar size has been increased or not. The query is as follows −
mysql> desc IncreaseVarcharDemo;
The following is the output −
+-----------+---------------+------+-----+---------+-------+
| Field     | Type          | Null | Key | Default | Extra |
+-----------+---------------+------+-----+---------+-------+
| StudentId | varchar(1000) | YES  |     | NULL    |       |
+-----------+---------------+------+-----+---------+-------+
1 row in set (0.03 sec)
basename( ) function in PHP

The basename() function gets the the filename component of a path. The file path is set as a parameter.
basename(file_path, suffix)
file_path − Set the path of file or directory to be checked. Required.
file_path − Set the path of file or directory to be checked. Required.
suffix − Set the extension of the file. Optional.
suffix − Set the extension of the file. Optional.
The basename() function returns the basename of the file.
The following is an example that checks for file “new.php” and returns the basename with the extension since we added the suffix parameter.
 Live Demo
<?php
   $file_path = "/backup/myfiles/new.php";
   // displays name of the file with extension
   echo basename($file_path);
?>
new.php
Let us see another example that checks the file and display the basename without the extension.
 Live Demo
<?php
   $file_path = "/backup/myfiles/new.php";
   // displays name of the file without extension
   echo basename($file_path,".php");
?>
new
Java Operators - GeeksforGeeks

10 Mar, 2018
-2
2
2
2
0
2
7
3
1
15
7
3
0
0
0
1
1
1
30GeeksQuiz
GeeksQuiz30
1020GeeksQuiz
GeeksQuiz1020
30GeeksQuiz
GeeksQuiz1020
1020GeeksQuiz
GeeksQuiz30
10*20GeeksQuiz
GeeksQuiz10*20
200GeeksQuiz
GeeksQuiz200
200GeeksQuiz
GeeksQuiz10*20
1020GeeksQuiz
GeeksQuiz220
Class Test
{
 public static void main (String [] args)
 {
 int x = 0;
 int y = 0;
 for (int z = 0; z < 5; z++)
 {
 if((++x > 2) || (++y > 2))
 {
 x++;
 }
 }
 System.out.println( x + " " + y);
 }
}

z = 0: x = 1, y = 1, if condition false
z = 1: x = 2, y = 2, if condition false
z = 2: x = 3, if condition true and due
to short circuiting ++y is not evaluated,
x++ // x = 4
z = 3: x = 5, again if condition is true,
x++ // x = 6
z = 4: x = 7, condition true, x++ // x = 8
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Must Do Coding Questions for Product Based Companies
How to Replace Values in Column Based on Condition in Pandas?
C Program to read contents of Whole File
How to Download and Install Spring Tool Suite (Spring Tools 4 for Eclipse) IDE?
Hash Functions and list/types of Hash functions
How to Replace Values in a List in Python?
How to Concat Two Columns Into One With the Existing Column Name in MySQL?
Spring - REST Controller
How to Read Text Files with Pandas?
How to Calculate Moving Averages in Python?
How to remove NULL values from a list in R?

The value NULL is used to represent an object especially a list of length zero. If a list contains NULL then we might want to replace it with another value or remove it from the list if we do not have any replacement for it. To remove the NULL value from a list, we can use the negation of sapply with is.NULL.
 Live Demo
x<-list(rep(10,5),NULL,12,"Tutorialspoint",2006,NULL,NULL,NULL,TRUE,c(rep(1,5),rep(2,5),NULL,"Education","Video Lectures","Online",NULL,"Over Million Visitors"))
x
[[1]]
[1] 10 10 10 10 10
[[2]]
NULL
[[3]]
[1] 12
[[4]]
[1] "Tutorialspoint"
[[5]]
[1] 2006
[[6]]
NULL
[[7]]
NULL
[[8]]
NULL
[[9]]
[1] TRUE
[[10]]
[1] "1"      "1"         "1"
[4] "1"      "1"         "2"
[7] "2"      "2"         "2"
[10] "2" "Education" "Video Lectures"
[13] "Online" "Over Million Visitors"
x<-x[!sapply(x,is.null)]
x
[[1]]
[1] 10 10 10 10 10
[[2]]
[1] 12
[[3]]
[1] "Tutorialspoint"
[[4]]
[1] 2006
[[5]]
[1] TRUE
[[6]]
[1]          "1"        "1"    "1"
[4]          "1"        "1"    "2"
[7]          "2"        "2"    "2"
[10] "2" "Education" "Video Lectures"
[13] "Online" "Over Million Visitors"
y<-list(c(5,10,15),NULL,c(rep("A",4)),rep(5,15,10,times=4),c(78,91,56,47,58,26,36,74,84),NULL,NULL,NULL)
y
[[1]]
[1] 5 10 15
[[2]]
NULL
[[3]]
[1] "A" "A" "A" "A"
[[4]]
[1] 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
[[5]]
[1] 78 91 56 47 58 26 36 74 84
[[6]]
NULL
[[7]]
NULL
[[8]]
NULL
y<-y[!sapply(y,is.null)]
y
[[1]]
[1] 5 10 15
[[2]]
[1] "A" "A" "A" "A"
[[3]]
[1] 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5
[[4]]
[1] 78 91 56 47 58 26 36 74 84
Algorithm to construct an Expression Tree in Data Structure

Expression trees are those in which the leaf nodes have the values to be operated, and internal nodes contain the operator on which the leaf node will be performed.
4 + ((7 + 9) * 2) will have an expression tree as follows
Let T be the expression tree.
If T is not NULL:   If T->data is an operand:      return T.data   A = solve(T.left)   B = solve(T.right)   --> Calculate operator for 'T.data' on A and B, and call recursively,      return calculate(A, B, T.data)
If T is not NULL:
   If T->data is an operand:
      return T.data
   A = solve(T.left)
   B = solve(T.right)
   --> Calculate operator for 'T.data' on A and B, and call recursively,
      return calculate(A, B, T.data)
To construct an Expression Tree for the given expression, we generally use Stack Data Structure.
Initially we Iterate over the given postfix expression and follow the steps as given below -
If we get an operand in the given expression, then push it in the stack. It will become the root of the expression Tree.
If an operator gets two values in the expression, then add in the expression tree as its child, and push them in the current node.
Repeat Step-1 and Step-2 until we do not complete over the given expression.
Now check if every root node contains nothing but operands and every child node contains only values.
Alternative of click() in Selenium

There are several alternatives to the usage of click method in Selenium webdriver. We can use the JavaScript Executor to perform a click action. Selenium can execute JavaScript commands with the help of the executeScript method.
The parameters – arguments[0].click() and locator of the element on which the click is to be performed are passed to this method.
WebElement n=driver.findElement(By.linkText("Refund"));
JavascriptExecutor j = (JavascriptExecutor) driver;
j.executeScript("arguments[0].click();", n);
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.JavascriptExecutor;
public class JsClickLink{
   public static void main(String[] args) {
      System.setProperty("webdriver.chrome.driver",
         "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      //implicit wait
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //launch URL
      driver.get("https://www.tutorialspoint.com/index.htm");
      // identify element
      WebElement m = driver.findElement(By.xpath("//a[@title='TutorialsPoint - Home']"));
      // click with Javascript Executor
      JavascriptExecutor j = (JavascriptExecutor) driver;
      j.executeScript("arguments[0].click();", m);
      driver.quit();
   }
}
If we want to click the submit button within a form tag having the value of type attribute as submit, it can be done using the submit method.
Let us the html code of a button with type=submit within the form tag.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.util.concurrent.TimeUnit;
public class ClsNameStrategy{
   public static void main(String[] args) {
      System.setProperty("webdriver.gecko.driver",
         "C:\\Users\\ghs6kor\\Desktop\\Java\\geckodriver.exe");
      WebDriver driver = new FirefoxDriver();
      //implicit wait
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      //URL launch
      driver.get("https://www.linkedin.com/");
      // identify element
      WebElement l = driver.findElement(By.className("input__input"));
      l.sendKeys("test@gmail.com");
      WebElement x = driver.findElement(By.id("session_password"));

      x.sendKeys("1258147");
      WebElement m = driver.
      findElement(By.cssSelector("button[type='submit']"));
      //click button with type submit
      m.submit();
      driver.close();
   }
}
What does the str() function do in Python Object Oriented Programming?

__str__ is a special method, like __init__, that returns a 'informal' string representation of an object. It is useful in debugging.
Consider the following code that uses the __str__ method
class Time:
    def __str__(self):
        return '%.2d:%.2d:%.2d' % (self.hour, self.minute, self.second)
When we print an object, Python invokes the str method −
>>> time = Time(7, 36)
>>> print time
07:36:00
Python program to find N largest elements from a list

Given an integer list, our task is to find N largest elements in the list.
Input : [40, 5, 10, 20, 9]
N = 2
Output: [40, 20]
Step1: Input an integer list and the number of largest number.
Step2: First traverse the list up to N times.
Step3: Each traverse find the largest value and store it in a new list.
def Nnumberele(list1, N):
   new_list = []
   for i in range(0, N):
      max1 = 0
   for j in range(len(list1)):
      if list1[j] > max1:
         max1 = list1[j];
         list1.remove(max1);
         new_list.append(max1)
      print("Largest numbers are ",new_list)
      # Driver code
      my_list = [12, 61, 41, 85, 40, 13, 77, 65, 100]
      N = 4
      # Calling the function
Nnumberele(my_list, N)
Largest numbers are [100, 85, 77, 65]
Get multiple count in a single MySQL query for specific column values

For this, you can use aggregate function sum() along with parameter value for specific column. Let us first create a table −
mysql> create table DemoTable1790
     (
     Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
     Name varchar(20),
     Score int
     );
Query OK, 0 rows affected (0.94 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1790(Name,Score) values('Chris',45);
Query OK, 1 row affected (0.38 sec)
mysql> insert into DemoTable1790(Name,Score) values('David',55);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable1790(Name,Score) values('David',98);
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable1790(Name,Score) values('Chris',91);
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable1790(Name,Score) values('Mike',99);
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable1790(Name,Score) values('Carol',55);
Query OK, 1 row affected (0.35 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1790;
This will produce the following output −
+----+-------+-------+
| Id | Name  | Score |
+----+-------+-------+
|  1 | Chris |    45 |
|  2 | David |    55 |
|  3 | David |    98 |
|  4 | Chris |    91 |
|  5 | Mike  |    99 |
|  6 | Carol |    55 |
+----+-------+-------+
6 rows in set (0.00 sec)
Here is the query to get multiple counts in a single MySQL query −
mysql> select sum(Name='Chris'),sum(Score=55) from DemoTable1790;
This will produce the following output −
+-------------------+---------------+
| sum(Name='Chris') | sum(Score=55) |
+-------------------+---------------+
|                 2 |             2 |
+-------------------+---------------+
1 row in set (0.00 sec)
How to use multiple versions of jQuery on the same page?

Yes, you can use multiple versions of jQuery on the same page. To avoid any kind of conflict, use the jQuery.noConflict() method. jQuery.noConflict() method allows you to use multiple frameworks, while using jQuery. Other JavaScript frameworks include Ember, Angular, Backbone, etc.
The $ sign is used for jQuery, but what if other frameworks also use the same $ sign; this may create issues and conflict. To avoid this, jQuery issued the noConflict() method. The method releases the $ sign to be used my other JavaScript frameworks. Use jQuery with the name, jQuery.
With this, you can also use multiple versions of jQuery on the same page. You can try to run the following code to learn how to use multiple versions of jQuery on the same web page −
Live Demo
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
   var $x = jQuery.noConflict();
   alert("Version: "+$x.fn.jquery);
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
   var $y = jQuery.noConflict();
   alert("Version: "+$y.fn.jquery);
</script>
</head>
<body>
</body>
</html>
C++ Program to Compute DFT Coefficients Directly

In discrete Fourier transform (DFT), a finite list is converted of equally spaced samples of a function into the list of coefficients of a finite combination of complex sinusoids. They ordered by their frequencies, that has those same sample values, to convert the sampled function from its original domain (often time or position along a line) to the frequency domain.
Begin
   Declare three variables which are the coefficient of linear equation and max value
   Read the variables
   Define a class with two variables real, img
   Create a constructor and set real, img to zero
   Take a variable M and initialize it to some integer
   Create function[M]
   For i=0 to M do
      function[i] = (((a * (double) i) + (b * (double) i)) - c)
   Declare function sine[M]
   Declare function cosine[M]
   for i = 0 to M do
      cosine[i] = cos((2 * i * k * PI) / M)
      sine[i] = sin((2 * i * k * PI) / M)
   for i = 0 to M do
      dft_value.real += function[i] * cosine[i]
      dft_value.img += function[i] * sine[i]
   Print the value
End
#include<iostream>
#include<math.h>
using namespace std;
#define PI 3.14159265
class DFT_Coeff {
   public:
   double real, img;
   DFT_Coeff() {
      real = 0.0;
      img = 0.0;
   }
};
int main(int argc, char **argv) {
   int M = 10;
   cout << "Enter the coeff of simple linear function:\n";
   cout << "ax + by = c\n";
   double a, b, c;
   cin >> a >> b >> c;
   double function[M];
   for (int i = 0; i < M; i++) {
      function[i] = (((a * (double) i) + (b * (double) i)) - c);
   }
   cout << "Enter the max K value: ";
   int k;
   cin >> k;
   double cosine[M];
   double sine[M];
   for (int i = 0; i < M; i++) {
      cosine[i] = cos((2 * i * k * PI) / M);
      sine[i] = sin((2 * i * k * PI) / M);
   }
   DFT_Coeff dft_value;
   cout << "The coeffs are: ";
   for (int i = 0; i < M; i++) {
      dft_value.real += function[i] * cosine[i];
      dft_value.img += function[i] * sine[i];
   }
   cout << "(" << dft_value.real << ") - " << "(" << dft_value.img << " i)";
}
Enter the coeff of simple linear function:
ax + by = c
4 6 7
Enter the max K value:
4
The coeffs are: (-50) - (-16.246 i)
How to select a single field in MongoDB?

You can select a single field in MongoDB using the following syntax:
db.yourCollectionName.find({"yourFieldName":yourValue},{"yourSingleFieldName":1,_id:0});
In the above syntax "yourSingleFieldName":1, _id:0 means get all data from one field without _id.
To understand the above syntax, let us create a collection with document. The query to create a collection with document is as follows:
> db.singleFieldDemo.insertOne({"StudentName":"David","StudentAge":28});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c6eba356fd07954a489067c")
}
> db.singleFieldDemo.insertOne({"StudentName":"Bob","StudentAge":18});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c6eba406fd07954a489067d")
}
> db.singleFieldDemo.insertOne({"StudentName":"Chris","StudentAge":24});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c6eba4c6fd07954a489067e")
}
> db.singleFieldDemo.insertOne({"StudentName":"Robert","StudentAge":26});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5c6eba586fd07954a489067f")
}
Now you can display all documents from a collection with the help of find() method. The query is as follows:
> db.singleFieldDemo.find().pretty();
The following is the output:
{
   "_id" : ObjectId("5c6eba356fd07954a489067c"),
   "StudentName" : "David",
   "StudentAge" : 28
}
{
   "_id" : ObjectId("5c6eba406fd07954a489067d"),
   "StudentName" : "Bob",
   "StudentAge" : 18
}
{
   "_id" : ObjectId("5c6eba4c6fd07954a489067e"),
   "StudentName" : "Chris",
   "StudentAge" : 24
}
{
   "_id" : ObjectId("5c6eba586fd07954a489067f"),
   "StudentName" : "Robert",
   "StudentAge" : 26
}
Here is the query to select a single field:
> db.singleFieldDemo.find({"StudentAge":18},{"StudentName":1,"_id":0});
The following is the output:
{ "StudentName" : "Bob" }
FIRSTNONBLANK function

Returns the first value in the column filtered by the current context, where the expression is not blank.
FIRSTNONBLANK (<column>, <expression>) 

column
A column expression.
expression
An expression evaluated for blanks for each value of column.
A table containing a single column and single row with the computed first non-blank value.
The dates parameter can be any of the following −
A reference to a date/time column.
A reference to a date/time column.
A table expression that returns a single column of date/time values.
A table expression that returns a single column of date/time values.
A Boolean expression that defines a single-column table of date/time values.
A Boolean expression that defines a single-column table of date/time values.
Constraints on Boolean expressions −
The expression cannot reference a calculated field.
The expression cannot reference a calculated field.
The expression cannot use CALCULATE function.
The expression cannot use CALCULATE function.
The expression cannot use any function that scans a table or returns a table, including aggregation functions.
The expression cannot use any function that scans a table or returns a table, including aggregation functions.
However, a Boolean expression can use any function that looks up a single value, or that calculates a scalar value.
= FIRSTNONBLANK (Sales [Sales Amount], MIN (Sales [Date])>3/31/2015) 

    53 Lectures 
     5.5 hours 

 Abhay Gadiya

    24 Lectures 
     2 hours 

 Randy Minder

    26 Lectures 
     4.5 hours 

 Randy Minder
 Print
 Add Notes
 Bookmark this page
How to open a website in Android's web browser from my application using Kotlin?

This example demonstrates how to open a website in Android's web browser from my application using Kotlin.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.
Step 2 − Add the following code to res/layout/activity_main.xml.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity">
   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="70dp"
      android:background="#008080"
      android:padding="5dp"
      android:text="TutorialsPoint"
      android:textColor="#fff"
      android:textSize="24sp"
      android:textStyle="bold" />
   <Button
      android:id="@+id/btnAmazon"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_centerInParent="true"
      android:text="Amazon"
      android:textStyle="bold" />
</RelativeLayout>

Step 3 − Add the following code to src/MainActivity.kt
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
   override fun onCreate(savedInstanceState: Bundle?) {
      super.onCreate(savedInstanceState)
      setContentView(R.layout.activity_main)
      title = "KotlinApp"
      val button: Button = findViewById(R.id.btnAmazon)
      button.setOnClickListener {
         val url = "http://www.amazon.com"
         startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(url)))
      }
   }
}

Step 4 − Add the following code to androidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.q11">
<uses-permission android:name="android.permission.Internet" />
   <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">
      <activity android:name=".MainActivity">
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
      </activity>
   </application>
</manifest>
Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project's activity files and click the Run icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen
Python | Sum of number digits in List

When it is required to sum the number of digits in a list, a simple loop and the ‘str’ method can be used.
A list can be used to store heterogeneous values (i.e data of any data type like integer, floating point, strings, and so on).
The ‘str’ method converts the given value into a string data type.
Below is a demonstration for the same −
 Live Demo
my_list = [11, 23, 41, 62, 89, 0, 10]
print("The list is : ")
print(my_list)
my_result = []
for elem in my_list:
   sum_val = 0
   for digit in str(elem):
      sum_val += int(digit)
   my_result.append(sum_val)
print ("The result after adding the digits is : " )
print(my_result)
The list is :
[11, 23, 41, 62, 89, 0, 10]
The result after adding the digits is :
[2, 5, 5, 8, 17, 0, 1]
A list is defined, and is displayed on the console.
Another empty list is created.
The list is iterated over, and every element in the list is converted to a string, and iterated over.
It is then added and converted as a single digit.
This is done on all elements of the list.
This is appended to the empty list.
It is then displayed as output on the console.
HTML Window alert( ) Method

The HTML window alert() method shows an alert box with the defined message and an OK button in an HTML document.
Following is the syntax −
alert(“message”);
Let us see an example of HTML window alert() method −
 Live Demo
<!DOCTYPE html>
<html>
<head>
<style>
   body {
      color: #000;
      height: 100vh;
      background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
      text-align: center;
      padding: 20px;
   }
   .btn {
      background: #db133a;
      border: none;
      height: 2rem;
      border-radius: 2px;
      width: 40%;
      display: block;
      color: #fff;
      outline: none;
      cursor: pointer;
      margin: 1rem auto;
   }
</style>
</head>
<body>
<h1>HTML Window alert() Method</h1>
<button class='btn' onclick="add()">Click me to open an alert box</button>
<script>
   function add() {
      alert("Hello! I'm an alert box");
   }
</script>
</body>
</html>
Click on “Create me to open an alert box” button to open an alert box.
Java Examples - Extract Image from PDF

How to extract an image from a PDF using java.
Following is the program to extract an image from a PDF using Java.
import java.awt.image.BufferedImage; 
import java.io.File; 

import javax.imageio.ImageIO; 
import org.apache.pdfbox.pdmodel.PDDocument; 
import org.apache.pdfbox.rendering.PDFRenderer;  

public class ExtractImageFromPdf {  
   public static void main(String args[]) throws Exception {  
      
      //Loading an existing PDF document 
      File file = new File("C:/pdfBox/ExtractImage_IP.pdf"); 
      PDDocument document = PDDocument.load(file); 
      
      //Instantiating the PDFRenderer class 
      PDFRenderer renderer = new PDFRenderer(document);  
      
      //Rendering an image from the PDF document 
      BufferedImage image = renderer.renderImage(0);  
      
      //Writing the image to a file 
      ImageIO.write(image, "JPEG", new File("C:/pdfBox/ExtractImage_OP.png")); 
      System.out.println("Image created"); 

      //Closing the document 
      document.close();  
   } 
}
 Print
 Add Notes
 Bookmark this page
How to convert a column values to column names in R?

To convert a column values to column names, we can use dcast function of reshape2 package. For example, if we have a data frame called df that contains two columns say x and y, where x is categorical and y is numerical. Now if we want to convert the categories in x as column names then it can be done as dcast(df,y~x).
Consider the below data frame −
Live Demo
> x1<-sample(c("A","B","C"),20,replace=TRUE)
> x2<-rpois(20,5)
> df1<-data.frame(x1,x2)
> df1
   x1 x2
1   B  4
2   A  2
3   A  5
4   C  3
5   A  7
6   A  4
7   C  6
8   A  5
9   B  4
10  B  3
11  B  7
12  A  8
13  C  2
14  B  4
15  A  5
16  C  5
17  A  6
18  C  1
19  A  6
20  C  3
Loading reshape2 package and converting values in x1 to column names −
> library(reshape2)
> dcast(df1,x2~x1)
Using x2 as value column: use value.var to override.
Aggregation function missing: defaulting to length
   x2 A B C
1  1 0 0 1
2  2 1 0 1
3  3 0 1 2
4  4 1 3 0
5  5 3 0 1
6  6 2 0 1
7  7 1 1 0
8  8 1 0 0
Live Demo
> Gender<-sample(c("Male","Female"),20,replace=TRUE)
> Rate<-rpois(20,3)
> df2<-data.frame(Gender,Rate)
> df2
   Gender Rate
1    Male    2
2    Male    5
3  Female    6
4  Female    3
5    Male    5
6    Male    1
7    Male    5
8    Male    2
9  Female    3
10 Female    2
11   Male    2
12   Male    3
13 Female    6
14   Male    0
15   Male    5
16 Female    4
17   Male    3
18 Female    5
19   Male    4
20 Female    3
Converting values in Gender to column names −
> dcast(df2,Rate~Gender)
Using Rate as value column: use value.var to override. 
Aggregation function missing: defaulting to length
   Rate Female Male
1    0      0    1
2    1      0    1
3    2      1    3
4    3      3    2
5    4      1    1
6    5      1    4
7    6      2    0
Knights' Attack in Python

Suppose we have a two-dimensional binary matrix, representing a rectangular chess board,
here 0 is for empty cell and 1 is for a knight. The knight is able to move two squares away
horizontally and one square vertically, or two squares vertically and one square horizontally
(like chess board knight). We have to check whether any two knights are attacking each other
or not.
So, if the input is like
Then the output will be True
To solve this, we will follow these steps −
row, col := row count of matrix, column count of matrix
for r in range 0 to row-1, dofor c in range 0 to col-1, doif A[r][c] is non-zero, thenfor each nr, nc in [(r+1, c-2), (r+1, c+2), (r+2, c-1), (r+2, c+1)], doif nr is in range of row and nc is in range of col and A[nr, nc] is non-zero, thenreturn True
for c in range 0 to col-1, doif A[r][c] is non-zero, thenfor each nr, nc in [(r+1, c-2), (r+1, c+2), (r+2, c-1), (r+2, c+1)], doif nr is in range of row and nc is in range of col and A[nr, nc] is non-zero, thenreturn True
if A[r][c] is non-zero, thenfor each nr, nc in [(r+1, c-2), (r+1, c+2), (r+2, c-1), (r+2, c+1)], doif nr is in range of row and nc is in range of col and A[nr, nc] is non-zero, thenreturn True
for each nr, nc in [(r+1, c-2), (r+1, c+2), (r+2, c-1), (r+2, c+1)], doif nr is in range of row and nc is in range of col and A[nr, nc] is non-zero, thenreturn True
if nr is in range of row and nc is in range of col and A[nr, nc] is non-zero, thenreturn True
return True
return False
Let us see the following implementation to get better understanding −
 Live Demo
class Solution:
   def solve(self, A):
      row, col = len(A), len(A[0])
      for r in range(row):
         for c in range(col):
            if A[r][c]:
               for nr, nc in ((r+1, c-2), (r+1, c+2), (r+2, c-1), (r+2, c+1)):
                  if 0 <= nr < row and 0 <= nc <col and
                     A[nr][nc]:
                     return True
      return False
ob = Solution()
mat = [[0,0,0,0,0],
[0,1,0,0,0],
[0,0,0,1,0]]
print(ob.solve(mat))
[[0,0,0,0,0],
[0,1,0,0,0],
[0,0,0,1,0]]
True
How to embed Scrolling Text Banners in New Google Sites ? - GeeksforGeeks

10 Sep, 2020
In this article, we will be using the marquee tag. To learn more about this tag follow this article.
To add scroll text banners in a Google site website select embed option from the insert panel and then go to embed code division of the dialogue box appeared.
Write your code in the space provided. To add a simple banner use this code:
HTML
<html>  <body>    <marquee font style="bold" scrolldelay="100">        <font size="5" face="Verdana">            <font color="ForestGreen">Geeks For Geeks    </marquee></body>  </html>
Now you can also set border, or change the direction, or run image with the text with simple modifications in HTML code, especially in the marquee tag.
Google Sites
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Remove elements from a JavaScript Array
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
How to create footer to stay at the bottom of a Web page?
Node.js fs.readFileSync() Method
HTML Cheat Sheet - A Basic Guide to HTML
Difference Between PUT and PATCH Request
REST API (Introduction)
How do I update the decimal column to allow more digits in MySQL?

To update the decimal column to allow more digit, use the MODIFY COLUMN. The syntax is as follows:
ALTER TABLE MODIFY COLUMN yourColumnName DECIMAL(yourIntValue,yourIntValue);
To understand the above syntax, let us create a table. The query to create a table is as follows:
mysql> create table allowDecimalWithMoreDigit
   -> (  
   -> Id int NOT NULL AUTO_INCREMENT,
   -> Salary DECIMAL(3,2),
   -> PRIMARY KEY(Id)
   -> );
Query OK, 0 rows affected (0.64 sec)
Now you can check the description of table using DESC command. The syntax is as follows:
DESC yourTableName;
Now you can check the description of table using above command. The query is as follows:
mysql> desc allowDecimalWithMoreDigit;
The following is the output:
+--------+--------------+------+-----+---------+----------------+
| Field  | Type         | Null | Key | Default | Extra          |
+--------+--------------+------+-----+---------+----------------+
| Id     | int(11)      | NO   | PRI | NULL    | auto_increment |
| Salary | decimal(3,2) | YES  |     | NULL    |                |
+--------+--------------+------+-----+---------+----------------+
2 rows in set (0.18 sec)
Look at the sample output, the column Salary has DECIMAL(3,2). Now you can change the DECIMAL(10,4) using MODIFY COLUMN with ALTER command. The query is as follows:
mysql> alter table allowDecimalWithMoreDigit modify column Salary DECIMAL(10,4);
Query OK, 0 rows affected (2.46 sec)
Records: 0 Duplicates: 0 Warnings: 0
Now check the table description once again. The query is as follows:
mysql> desc allowDecimalWithMoreDigit;
The following is the output:
+--------+---------------+------+-----+---------+----------------+
| Field  | Type          | Null | Key | Default | Extra          |
+--------+---------------+------+-----+---------+----------------+
| Id     | int(11)       | NO   | PRI | NULL    | auto_increment |
| Salary | decimal(10,4) | YES  |     | NULL    |                |
+--------+---------------+------+-----+---------+----------------+
2 rows in set (0.00 sec)
Look at the sample output, Salary data type DECIMAL(3,2) has been changed to DECIMAL(10,4).
MongoDB - sort() Method - GeeksforGeeks

05 Feb, 2021
The sort() method specifies the order in which the query returns the matching documents from the given collection. You must apply this method to the cursor before retrieving any documents from the database. It takes a document as a parameter that contains a field: value pair that defines the sort order of the result set. The value is 1 or -1 specify an ascending or descending sort respectively.
If a sort returns the same result every time we perform on same data, then such type of sort is known as a stable sort. 
If a sort returns a different result every time we perform on same data, then such type of sort is known as unstable sort.
MongoDB generally performs a stable sort unless sorting on a field that holds duplicate values.  
We can use limit() method with sort() method, it will return first m documents, where m is the given limit.
MongoDB can find the result of the sort operation using indexes.
If MongoDB does not find sort order using index scanning, then it uses top-k sort algorithm.
Syntax:
db.Collection_Name.sort({filed_name:1 or -1})
Parameter:
The parameter contains a field: value pair that defines the sort order of the result set. The value is 1 or -1 that specifies an ascending or descending sort respectively. The type of parameter is a document.
Return: 
It returns the documents in sorted order.
Examples:
In the following examples, we are working with:
Database: gfg
Collections: student
Document: Four documents contains name and age of the students.
Return all the documents in ascending order of the age:
db.student.find().sort({age:1})
Return all the documents in descending order of the age:
db.student.find().sort({age:-1})
Return all the documents in the ascending order of the age:
db.student.find().sort({name:1})
Return all the documents in the descending order of the age:
db.student.find().sort({name:-1})
Picked
MongoDB
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to connect MongoDB with ReactJS ?
MongoDB - Distinct() Method
MongoDB - limit() Method
MongoDB - FindOne() Method
MongoDB insertMany() Method - db.Collection.insertMany()
Create user and add role in MongoDB
MongoDB updateOne() Method - db.Collection.updateOne()
MongoDB - Map Reduce
MongoDB updateMany() Method - db.Collection.updateMany()
MongoDB - Update() Method
C / C++ Program for Subset Sum (Backtracking)

Backtracking is a technique to solve dynamic programming problems. It works by going step by step and rejects those paths that do not lead to a solution and trackback (moves back ) to the previous position.
In the subset sum problem, we have to find the subset of a set is such a way that the element of this subset-sum up to a given number K. All the elements of the set are positive and unique (no duplicate elements are present).
For this, we will create subsets and check if their sum is equal to the given number k. Let's see a program to create a solution.
 Live Demo
#include <stdio.h>
#include <stdlib.h>
static int total_nodes;
void printValues(int A[], int size){
   for (int i = 0; i < size; i++) {
      printf("%*d", 5, A[i]);
   }
   printf("\n");
}
void subset_sum(int s[], int t[], int s_size, int t_size, int sum, int ite, int const target_sum){
   total_nodes++;
   if (target_sum == sum) {
      printValues(t, t_size);
      subset_sum(s, t, s_size, t_size - 1, sum - s[ite], ite + 1, target_sum);
      return;
   }
   else {
      for (int i = ite; i < s_size; i++) {
         t[t_size] = s[i];
         subset_sum(s, t, s_size, t_size + 1, sum + s[i], i + 1, target_sum);
      }
   }
}
void generateSubsets(int s[], int size, int target_sum){
   int* tuplet_vector = (int*)malloc(size * sizeof(int));
   subset_sum(s, tuplet_vector, size, 0, 0, 0, target_sum);
   free(tuplet_vector);
}
int main(){
   int set[] = { 5, 6, 12 , 54, 2 , 20 , 15 };
   int size = sizeof(set) / sizeof(set[0]);
   printf("The set is ");
   printValues(set , size);
   generateSubsets(set, size, 25);
   printf("Total Nodes generated %d\n", total_nodes);
   return 0;
}
The set is 5 6 12 54 2 20 15
5 6 12 2
5 20
Total Nodes generated 127
Can Selenium be used for .NET applications?

We can use Selenium for .NET applications. We should have Visual Studio 2019 installed in the system along with Selenium webdriver and any browser like Firefox, Chrome, and so on. Then we must utilize the NUnit framework.
Launch Visual Studio 2019 and then click on Create a new project.
Type NUnit in the search box appearing in Create a new project pop−up. Select NUnit Test Project(.NET Core) from the search results.
Enter Project name and Location. Then click on Create to proceed.
As the project is set up on NUnit(.Net Core), the Setup and Test methods shall be given by default.
We should navigate to the Tools menu, select NuGet Package Manager, and then click on Package Manager Console.
We must execute the required Package Manager commands for installation of Selenium Webdriver and NUnit.
For Selenium installation for Firefox, run the below commands in Package Manager Console −
Install−Package Selenium.WebDriver
Install−Package Selenium.Firefox.WebDriver
For Selenium installation for Chrome, run the below commands in Package Manager Console −
Install−Package Selenium.WebDriver
Install−Package Selenium.Chrome.WebDriver
For NUnit installation, run the below commands in Package Manager Console −
Install−Package NUnit
Install−Package UUnit3TestAdapter
To check the installation status, run the command in Package Manger Console −
Get−Package
using NUnit.Framework;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using System;
namespace NUnitTestProject1{
   public class Tests{
      String u = "https://www.tutorialspoint.com/index.htm";
      IWebDriver d;
      [SetUp]
      public void Setup(){
         //creating object of FirefoxDriver
         d = new FirefoxDriver();
      }
      [Test]
      public void Test1(){
         //launching URL
         d.Navigate().GoToUrl(u);
         Console.WriteLine("Url launched");
      }
      [TearDown]
      public void close_Browser(){
         d.Quit();
      }
   }
}
Go to Build, then select Build Solution.
Go to Test−>Test Explorer. Then run the tests. The output in Test Explorer is −
Click on Open additional output for this result link, we should get the Test Outcome and Standard Output.
Pascal - Subprogram Call by Reference

The call by reference method of passing arguments to a subprogram copies the address of an argument into the formal parameter. Inside the subprogram, the address is used to access the actual argument used in the call. This means that changes made to the parameter affect the passed argument.
In order to pass the arguments by reference, Pascal allows to define variable parameters. This is done by preceding the formal parameters by the keyword var. Let us take the example of the procedure swap() that swaps the values in two variables and reflect the change in the calling subprogram.
procedure swap(var x, y: integer);
var
   temp: integer;

begin
   temp := x;
   x:= y;
   y := temp;
end;
Next, let us call the procedure swap() by passing values by reference as in the following example −
program exCallbyRef;
var
   a, b : integer;
(*procedure definition *)
procedure swap(var x, y: integer);

var
   temp: integer;

begin
   temp := x;
   x:= y;
   y := temp;
end;

begin
   a := 100;
   b := 200;
   writeln('Before swap, value of a : ', a );
   writeln('Before swap, value of b : ', b );
   
   (* calling the procedure swap  by value   *)
   swap(a, b);
   writeln('After swap, value of a : ', a );
   writeln('After swap, value of b : ', b );
end.
When the above code is compiled and executed, it produces the following result −
Before swap, value of a : 100
Before swap, value of b : 200
After swap, value of a : 200
After swap, value of b : 100

Which shows that now the procedure swap() has changed the values in the calling program.

    94 Lectures 
     8.5 hours 

 Stone River ELearning
 Print
 Add Notes
 Bookmark this page
Program to find duplicate elements and delete last occurrence of them in Python

Suppose we have a list of numbers A, we have to find all duplicate numbers and remove their
last occurrences.
So, if the input is like [10, 30, 40, 10, 30, 50], then the output will be [10, 30, 40, 50]
To solve this, we will follow these steps −
seen:= a new map
d:= a new map
for i in range 0 to size of nums, doif nums[i] is not in d, thend[nums[i]]:= 1otherwise,d[nums[i]] := d[nums[i]] + 1
if nums[i] is not in d, thend[nums[i]]:= 1
d[nums[i]]:= 1
otherwise,d[nums[i]] := d[nums[i]] + 1
d[nums[i]] := d[nums[i]] + 1
i:= 0
while i < size of nums, don:= d[nums[i]]if nums[i] is not in seen, thenseen[nums[i]]:= 1otherwise,seen[nums[i]] := seen[nums[i]] + 1if n is same as seen[nums[i]] and n > 1, thendelete ith element from numsi := i - 1i := i + 1
n:= d[nums[i]]
if nums[i] is not in seen, thenseen[nums[i]]:= 1
seen[nums[i]]:= 1
otherwise,seen[nums[i]] := seen[nums[i]] + 1
seen[nums[i]] := seen[nums[i]] + 1
if n is same as seen[nums[i]] and n > 1, thendelete ith element from numsi := i - 1
delete ith element from nums
i := i - 1
i := i + 1
return nums
Let us see the following implementation to get better understanding −
 Live Demo
class Solution:
   def solve(self, nums):
      seen={}
      d={}
      for i in range(len(nums)):
         if not nums[i] in d:
            d[nums[i]]=1
         else:
            d[nums[i]]+=1
      i=0
      while i < len(nums):
         n=d[nums[i]]
         if not nums[i] in seen:
            seen[nums[i]]=1
         else:
            seen[nums[i]]+=1
         if n == seen[nums[i]] and n > 1:
            nums.pop(i)
         i-=1
         i+=1
      return nums
ob = Solution()
print(ob.solve([10, 30, 40, 10, 30, 50]))
[10, 30, 40, 10, 30, 50]
[10, 30, 40, 50]
list push_front() function in C++ STL - GeeksforGeeks

25 Jun, 2018
The list::push_front() is a built-in function in C++ STL which is used to insert an element at the front of a list container just before the current top element. This function also increases the size of the container by 1.
Syntax:
list_name.push_front(dataType value)

Parameters: This function accepts a single parameter value. This parameter represents the element which is needed to be inserted at the front of the list container.
Return Value: This function does not return anything.
Below program illustrate the list::push_front() function in C++ STL:
// CPP program to illustrate the// list::push_front() function#include <bits/stdc++.h>using namespace std;  int main(){    // Creating a list    list<int> demoList;      // Adding elements to the list    // using push_back()    demoList.push_back(10);    demoList.push_back(20);    demoList.push_back(30);    demoList.push_back(40);      // Initial List:    cout << "Initial List: ";    for (auto itr = demoList.begin(); itr != demoList.end(); itr++)        cout << *itr << " ";      // Adding elements to the front of List    // using push_front    demoList.push_front(5);      // List after adding elements to front    cout << "\n\nList after adding elements to the front:\n";    for (auto itr = demoList.begin(); itr != demoList.end(); itr++)        cout << *itr << " ";      return 0;}
Initial List: 10 20 30 40 

List after adding elements to the front:
5 10 20 30 40

CPP-Functions
cpp-list
STL
C++
STL
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Inheritance in C++
Map in C++ Standard Template Library (STL)
Constructors in C++
C++ Classes and Objects
Socket Programming in C/C++
Bitwise Operators in C/C++
Operator Overloading in C++
Copy Constructor in C++
Virtual Function in C++
Templates in C++ with Examples
Java â String indexOf() Method

This method returns the index within this string of the first occurrence of the specified character or -1, if the character does not occur.
Here is the syntax of this method −
public int indexOf(char ch)

Here is the detail of parameters −
ch − a character.
ch − a character.
See the description.
import java.io.*;
public class Test {

   public static void main(String args[]) {
      String Str = new String("Welcome to Tutorialspoint.com");
      System.out.print("Found Index :" );
      System.out.println(Str.indexOf( 'o' ));
   }
}
This will produce the following result −
Found Index :4


    16 Lectures 
     2 hours 

 Malhar Lathkar

    19 Lectures 
     5 hours 

 Malhar Lathkar

    25 Lectures 
     2.5 hours 

 Anadi Sharma

    126 Lectures 
     7 hours 

  Tushar Kale

    119 Lectures 
     17.5 hours 

 Monica Mittal

    76 Lectures 
     7 hours 

 Arnab Chakraborty
 Print
 Add Notes
 Bookmark this page
How to plot gamma distribution with alpha and beta parameters in Python using Matplotlib?

To plot gamma distribution with alpha and beta parameters in Python, we can use gamma.pdf() function.
Set the figure size and adjust the padding between and around the subplots.
Set the figure size and adjust the padding between and around the subplots.
Create x using numpy and y using gamma.pdf() function at x of the given RV.
Create x using numpy and y using gamma.pdf() function at x of the given RV.
Plot x and y data points using plot() method.
Plot x and y data points using plot() method.
Use legend() method to place the legend elements for the plot.
Use legend() method to place the legend elements for the plot.
To display the figure, use show() method.
To display the figure, use show() method.
import numpy as np
import scipy.stats as stats
from matplotlib import pyplot as plt

plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True

x = np.linspace(0, 10, 10)
y = stats.gamma.pdf(x, a=5, scale=0.333)

plt.plot(x, y, "ro-", label=(r'$\alpha=0, \beta=3$'))
plt.legend(loc='upper right')

plt.show()
HTML5 date field and placeholder text in Safari

The placeholder attribute does not support input elements on the input type date.
However, you may have seen it works on Safari web browser because it is not supporting the date type. That would mean the attribute is ignored and the remaining is only a plain text field.
Therefore, the following works on Safari Desktop −
<input type = "date" name = "dob" id = "dob" value = "" placeholder = "add dob" />
As an alternative for Safari mobile, use:
input[type='date']:after {
   color: #000000;
   content: attr(placeholder);
}
And the HTML −
<input name = "mydate" type = "date" value = "" placeholder = "add dob" />