code-rag-bench/online-tutorials huggingface dataset:
PHP | Spreadsheet | Setting a cell value by coordinate

04 Oct, 2021
The setCellValue() function is an inbuilt function in PHPSpreadsheet which is used to set the value of a cell in a spreadsheet.
Syntax: 
setCellValue( $coordinate, $value )
Parameters: This function accepts two parameters as mentioned above and described below:  
$coordinate: This parameter is used to store the value of the coordinate of the excel sheet.
$value: This parameter is used to store the value of data which is to be set in an excel sheet.
Return Value: This function returns Object of class PhpOffice\PhpSpreadsheet\Worksheet\Worksheet.
Example 1:  
PHP
<?php // require_once('path/vendor/autoload.php');use PhpOffice\PhpSpreadsheet\Spreadsheet;use PhpOffice\PhpSpreadsheet\Writer\Xlsx;  // Creates New Spreadsheet$spreadsheet = new Spreadsheet(); // Retrieve the current active worksheet$sheet = $spreadsheet->getActiveSheet(); // Sets cell A1 with String Value$sheet->setCellValue('A1', 'GeeksForGeeks!'); // Sets cell A2 with Boolean Value$sheet->setCellValue('A2', TRUE); // Sets cell B1 with Numeric Value$sheet->setCellValue('B1', 123.456); // Write an .xlsx file$writer = new Xlsx($spreadsheet); // Save .xlsx file to the current directory$writer->save('gfg1.xlsx');?>
Output: 
Alternatively, It can be achieved by retrieving the cell object firstly and then set the value. For this purpose, Cell object can be retrieved with the help of getCell() function, and then the value can be set with the help of setValue() function. 
Syntax:  
$spreadsheet->getActiveSheet()->getCell($coordinate)->setValue($value);
Example 2:  
PHP
<?php // require_once('vendor/autoload.php');use PhpOffice\PhpSpreadsheet\Spreadsheet;use PhpOffice\PhpSpreadsheet\Writer\Xlsx; // Creates New Spreadsheet$spreadsheet = new Spreadsheet(); // Retrieve the current active worksheet$sheet = $spreadsheet->getActiveSheet(); // Sets cell A1 with String Value$sheet->getCell('A1')->setValue('GeeksForGeeks!'); // Sets cell A2 with Boolean Value$sheet->getCell('A2')->setValue(TRUE); // Sets cell B1 with Numeric Value$sheet->getCell('B1')->setValue(123.456); // Write an .xlsx file$writer = new Xlsx($spreadsheet); // Save .xlsx file to the current directory$writer->save('gfg2.xlsx');?>
Output: 
Reference: https://phpspreadsheet.readthedocs.io/en/develop/topics/accessing-cells/ 
saurabh1990aror
PHP-function
PHP-Spreadsheet
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Collect.js | first() Function

12 Jun, 2020
The first() function gives the first value of the collection. Simply means it returns the first value or the first method returns the first element in the collection that passes a given condition.  In JavaScript, the array is first converted to a collection and then the function is applied to the collection.
Syntax: 
data.first(e)

Parameters:  This function accepts a single parameter as mentioned above and described below:
e : This parameter holds a condition that has to pass by the collection
Return value: Processed value
Below examples illustrate the first() function in collect.js
Example 1: Here in this example, we take a collection and then using the first() function to get first value.
Javascript
// It is used to import collect.js library  const collect = require('collect.js');  const nums = [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9];const data = collect(nums);  let value = data.first(e => e =4);console.log(value);
Output : 
0
Example 2: In this example, we will get the first negative value.
Javascript
// It is used to import collect.js library  const collect = require('collect.js');  const num = [0 , 1 , 2 , 3 , -4 , 5 , -6 , 7 , 8 , 9];const data = collect(num);  let value = data.first(e => e < 0);console.log(value);
Output: 
-4
Reference: https://collect.js.org/api/first.html
akhilsharma870
Collect.js
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
MongoDB – FindOne() Method

05 Feb, 2021
The findOne() method finds and returns one document that matches the given selection criteria. If multiple documents satisfy the given query expression, then this method will return the first document according to the natural order which reflects the order of documents on the disk. If no document matches the selection criteria, then this method will return null. It takes two parameters first one is the query criteria and the other is optional.
If you want to find fields of the embedded document, then use the following syntax:
“field.nestedfieldname”: <value>
or
{field: {nestedfieldname: <value>}}
The document return by this method always contains the _id field. If you don’t want the _id field, then set _id:0 in the projection.
Syntax:
db.Collection_Name.findOne(
    query:<document>,
    projection:<document>
)
Parameters:
The first parameter is a query criteria on the collection.
Other is optional.
Optional parameters:
projection: The projection parameter determines which fields are returned to the matching documents. The projection parameter takes a document that contains field : value pairs:
{field1: <value1>, field: <value2>...}
Here,
<field>: <1 or true>: It means we specify the inclusion of a field.
<field>: <0 or false>: It means we specify the exclusion of a field.
“<field>.$”: <1 or true>: Here, by using $ array projection operator we specify the projection to return the first element that matches the given query expression on the array field.
<field>: <array projection>: Here, by using array projection operators we specify the array items to include, by excluding those items that do not match the given expression. 
<field>: <$meta expression>: Here, by using $meta expression operator we specify the inclusion of available per-document metadata. 
<field>: <aggregation expression>: It means we specify the value of the projection field.
Return:
It returns one matched document with the specified query criteria in the collection. And if you specify a projection parameter, then is method returns a document that only contains projection fields.
Examples:
In the following examples, we are working with:
Database: gfg
Collections: student
Document: Three documents contains name and the language in which they are interested.
With empty query specification it returns the first document in the collection:
db.student.findOne()
Return first document that contains the specified field:
db.student.findOne({language:"python"})
Return first document that contains language field:
db.student.findOne({language:"c++"})
Finding document using projection:
db.student.findOne({name: "Avinash"}, {_id: 0, language:1})
Here, we find a document whose name is “Avinash”, and only want to display the language that Avinash know. So, in the projection document, we set the value of the language field to 1 and the value of _id to 0.
MongoDB-method
Picked
MongoDB
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How do I make a transparent canvas in HTML5?

The globalAlpha property returns the transparency value of drawing. The value 1.0 of this property specifies no transparency and the value 0.0 of this property specifies full transparency. Hence, by setting the globalAlpha property to 0.0, we can get a transparent canvas.
You can try to run the following code to make a transparent canvas −
<!DOCTYPE html>
<html>
   <body>
      <canvas id = "idCanvas" width = "400" height = "200" style = "border:2px solid #000000;">
         Your browser does not support the HTML5 canvas tag.</canvas>
      <script>
         var c = document.getElementById("idCanvas");
         var ctx = c.getContext("2d");
         ctx.fillStyle = "green";
         ctx.fillRect(20, 20, 75, 50);
         ctx.globalAlpha = 0.0;
         ctx.fillStyle = "yellow";
         ctx.fillRect(50, 50, 75, 50);
         ctx.fillStyle = "red";
         ctx.fillRect(80, 80, 75, 50);
      </script>
   </body>
</html>
Groovy - getAt()

String getAt(int index)

Index – The position of the string to return
String value at the index position
Following is an example of the usage of this method −
class Example { 
   static void main(String[] args) { 
      String a = "Hello World"; 
		
      println(a.getAt(2)); 
      println(a.getAt(6)); 
      println(a.getAt(7)); 
   } 
}
When we run the above program, we will get the following result −
l 
W 
O


    52 Lectures 
     8 hours 

 Krishna Sakinala

    49 Lectures 
     2.5 hours 

 Packt Publishing
 Print
 Add Notes
 Bookmark this page
Set disabled links with Bootstrap

For each of the .nav classes, if you add the .disabled class, it will create a gray link that also disables the :hover state.
You can try to run the following code to set disabled links −
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Example</title>
      <link href = "/bootstrap/css/bootstrap.min.css" rel = "stylesheet">
      <script src = "/scripts/jquery.min.js"></script>
      <script src = "/bootstrap/js/bootstrap.min.js"></script>
   </head>
   <body style = "background: #FADBD8;">
      <h2>Website</h2>
      <ul class = "nav nav-tabs nav-justified">
         <li class = "active"><a href = "#">Home</a></li>
         <li><a href = "#">Team</a></li>
         <li><a href = "#">Authors</a></li>
         <li><a href = "#">MVPs</a></li>
      </ul>
      <h2>Website (With disabled links)</h2>
      <ul class = "nav nav-tabs nav-justified">
         <li class = "active"><a href = "#">Home</a></li>
         <li><a href = "#">Team</a></li>
         <li class = "disabled"><a href = "#">Authors (disabled link)</a></li>
         <li><a href = "#">MVPs</a></li>
      </ul>
   </body>
</html>
MySQL Select Date Equal to Today and return results for the same date?

To get today’s date, use in-built function CURDATE(). The CURDATE() gives only current date not time. With that, to get the records for the same day, you can try the following syntax −
select yourColumnName1,yourColumnName2,......,yourColumnNameN,DATE_FORMAT(yourDateColumnName, '%Y-%m-%d') from yourTableName
WHERE DATE(yourDateColumnName) = CURDATE();
To understand the above concept, let us create a table. The query to create a table is as follows. One of these columns will have datetime datatype to display dates −
mysql> create table GmailSignIn
   −> (
   −> UserId int,
   −> UserName varchar(200),
   −> DateOfSignIn datetime
   −> );
Query OK, 0 rows affected (1.56 sec)
Now you can insert some records into the table with the help of insert command. We have set the current date as well, which is 2018-12-06.
The query is as follows −
mysql> insert into GmailSignIn values(222111,'John',now());
Query OK, 1 row affected (0.15 sec)

mysql> insert into GmailSignIn values(333222,'Johnson',curdate());
Query OK, 1 row affected (0.18 sec)

mysql> insert into GmailSignIn values(444333,'Carol',date_add(curdate(),interval 1 day));
Query OK, 1 row affected (0.13 sec)

mysql> insert into GmailSignIn values(555444,'David',date_add(curdate(),interval -1 day));
Query OK, 1 row affected (0.83 sec)
Display all records from the table with the help of select statement. The query is as follows −
mysql> select *from GmailSignIn;
The following is the output −
+--------+----------+---------------------+
| UserId | UserName | DateOfSignIn        |
+--------+----------+---------------------+
| 222111 | John     | 2018-12-06 19:13:30 |
| 333222 | Johnson  | 2018-12-06 00:00:00 |
| 444333 | Carol    | 2018-12-07 00:00:00 |
| 555444 | David    | 2018-12-05 00:00:00 |
+--------+----------+---------------------+
4 rows in set (0.00 sec)
Here is the query to select date equal to today and display the records for the same date −
mysql> select UserId,UserName,DateOfSignIn,DATE_FORMAT(DateOfSignIn, '%Y-%m-%d') from GmailSignIn
   −> where date(DateOfSignIn) = curdate();
The following is the output −
+--------+----------+---------------------+---------------------------------------+
| UserId | UserName | DateOfSignIn        | DATE_FORMAT(DateOfSignIn, '%Y-%m-%d') |
+--------+----------+---------------------+---------------------------------------+
| 222111 | John     | 2018-12-06 19:13:30 | 2018-12-06                            |
| 333222 | Johnson  | 2018-12-06 00:00:00 | 2018-12-06                            |
+--------+----------+---------------------+---------------------------------------+
2 rows in set (0.00 sec)
How to check if string or a substring of string ends with suffix in Python?

Python has a method endswith(string) in the String class. This method accepts a suffix string that you want to search and is called on a string object. You can call this method in the following way:
string = 'C:/Users/TutorialsPoint1/~.py'
print(string.endswith('.py'))
OUTPUT
True
There is another way to find if a string ends with a given suffix. You can use re.search(suffix + '$', string) from the re module(regular expression) to do so. Regex interprets $ as end of line, so if you want to search for a suffix, you need to do the following:
string = 'C:/Users/TutorialsPoint1/~.py'
import re
print(bool(re.search('py$', string)))
OUTPUT
True
re.search returns an object, to check if it exists or not, we need to convert it to a boolean using bool(). You can read more about Python regex <a href="https://docs.python.org/2/library/re.html" target="_blank">here</a>.
Bind function and placeholders in C++

Here we will see the Bind function and the placeholders in C++. Sometimes we need to manipulate the operation of some functions as we need. We can use some default parameters to get some essence of manipulating.
In C++11, one new feature is introduced, called the bind function. This helps us to do such manipulating in some easier fashion. To use these features, we have to use <functional> header file.
Bind functions with the help of placeholders helps to determine the positions, and number of arguments to modify the function according to desired outputs.
Placeholders are namespaces which detect the position of a value in a function. Placeholders are represented by _1, _2, _3 etc.
 Live Demo
#include <functional>
#include <iostream>
struct Foo {
   Foo(int num) : num_(num) {}
   void print_add(int i) const { std::cout << num_+i << '\n'; }
   int num_;
};
void print_num(int i) {
   std::cout << i << '\n';
}
struct PrintNum {
   void operator()(int i) const {
      std::cout << i << '\n';
   }
};
int main() {
   std::function<void(int)> f_display = print_num;
   f_display(-9);
   std::function<void()> f_display_42 = []() { print_num(42); };
   f_display_42();
   std::function<void()> f_display_31337 = std::bind(print_num, 31337);
   f_display_31337();
   std::function<void(const Foo&, int)> f_add_display = &Foo::print_add;
   const Foo foo(314159);
   f_add_display(foo, 1);
   std::function<int(Foo const&)> f_num = &Foo::num_;
   std::cout << "num_: " << f_num(foo) << '\n';
   using std::placeholders::_1;
   std::function<void(int)> f_add_display2= std::bind( &Foo::print_add, foo, _1 );
   f_add_display2(2);
   std::function<void(int)> f_add_display3= std::bind( &Foo::print_add, &foo, _1 );
   f_add_display3(3);
   std::function<void(int)> f_display_obj = PrintNum();
   f_display_obj(18);
}
-9
42
31337
314160
num_: 314159
314161
314162
18
Program to find how many ways we can climb stairs in Python

Suppose we have a staircase with n steps, and we can climb up either 1 or 2 steps at a time. We have to define a function that returns the number of unique ways we can climb the staircase.
The order of the steps should not be changed, so each different order of steps counts as a way. If the answer is very large then mod the result by 10^9 + 7
So, if the input is like n = 5, then the output will be 8, as there are 8 unique ways −
1, 1, 1, 1, 1
2, 1, 1, 1
1, 2, 1, 1
1, 1, 2, 1
1, 1, 1, 2
1, 2, 2
2, 1, 2
2, 2, 1
To solve this, we will follow these steps −
dp:= an array of size n+1, and fill with 0
dp[1]:= 1
for i in range 2 to n+1, dodp[i]:= dp[i-1]+dp[i-2]
dp[i]:= dp[i-1]+dp[i-2]
return last element of dp mod m
Let us see the following implementation to get better understanding −
 Live Demo
m =(10**9)+7
class Solution:
   def solve(self, n):
      dp=[0 for _ in range(n+2)]
      dp[1]=1
      for i in range(2,n+2):
         dp[i]=dp[i-1]+dp[i-2]
      return dp[-1] % m
ob = Solution()
print(ob.solve(5))
5
8
C Program for N-th term of Geometric Progression series

Given ‘a’ the First term, ‘r’ the common ratio and ‘n’ for the number of terms in a series. The task is to find the nth term of the series.
So, before discussing how to write a program for the problem first we should know what is Geometric Progression.
Geometric progression or Geometric sequence in mathematics are where each term after the first term is found by multiplying the previous one with the common ratio for a fixed number of terms.
Like 2, 4, 8, 16, 32.. is a geometric progression with first term 2 and common ratio 2. If we have n = 4 then the output will be 16.
So, we can say that Geometric Progression for nth term will be like −
GP1 = a1
GP2 = a1 * r^(2-1)
GP3 = a1 * r^(3-1)
. . .
GPn = a1 * r^(n-1)
So the formula will be GP = a * r^(n-1).
Input: A=1
   R=2
   N=5
Output: The 5th term of the series is: 16
Explanation: The terms will be
   1, 2, 4, 8, 16 so the output will be 16
Input: A=1
   R=2
   N=8
Output: The 8th Term of the series is: 128
Approach we will be using to solve the given problem −
Take first term A, common ratio R, and N the number of series.
Then calculate nth term by A * (int)(pow(R, N - 1).
Return the Output obtained from the above calculation.
Start
   Step 1 -> In function int Nth_of_GP(int a, int r, int n)
      Return( a * (int)(pow(r, n - 1))
   Step 2 -> In function int main()
      Declare and set a = 1
      Declare and set r = 2
      Declare and set n = 8
      Print The output returned from calling the function Nth_of_GP(a, r, n)
Stop
#include <stdio.h>
#include <math.h>
//function to return the nth term of GP
int Nth_of_GP(int a, int r, int n) {
   // the Nth term will be
   return( a * (int)(pow(r, n - 1)) );
}
//Main Block
int main() {
   // initial number
   int a = 1;
   // Common ratio
   int r = 2;
   // N th term to be find
   int n = 8;
   printf("The %dth term of the series is: %d\n",n, Nth_of_GP(a, r, n) );
   return 0;
}
The 8th term of the series is: 128
D3.js | d3.quantile() Function - GeeksforGeeks

28 Jun, 2019
The d3.quantile() function in D3.js is used to returns the p-quantile of the given sorted array of elements. Where p is the number lies in the range[0, 1].
Syntax:
d3.quantile(Array, p)
Parameters: This function accept two parameters as mentioned above and described below:
Array: It holds the sorted array of elements.
p: It is the p-quantile which are returned over the given sorted array of elements.
Return Value: It returns the p-quantile of the given sorted array of elements.
Below programs illustrate the d3.quantile() function in D3.js:
Example 1:
<!DOCTYPE html><html>  <head>    <title>        d3.quantile() function    </title>          <script src = "https://d3js.org/d3.v4.min.js"></script></head>  <body>    <script>              // Initialising a array            var Array = [10, 20, 30, 40, 50];                  // Calling the d3.quantile() function        A = d3.quantile(Array, 0);         B = d3.quantile(Array, 0.25);         C = d3.quantile(Array, 0.5);        D = d3.quantile(Array, 0.75);         E = d3.quantile(Array, 1);                   // Getting the shuffled elements        document.write(A + "<br>");        document.write(B + "<br>");        document.write(C + "<br>");        document.write(D + "<br>");        document.write(E + "<br>");    </script></body>  </html>                    
Output:
10
20
30
40
50

Example 2:
<!DOCTYPE html><html>  <head>    <title>        d3.quantile() function    </title>          <script src = "https://d3js.org/d3.v4.min.js"></script></head>  <body>    <script>              // Initialising an array            var Array = [10, 20, 30];                  // Calling the d3.quantile() function        A = d3.quantile(Array, 0);         B = d3.quantile(Array, 0.25);         C = d3.quantile(Array, 0.5);        D = d3.quantile(Array, 0.75);         E = d3.quantile(Array, 1);                   // Getting the shuffled elements        document.write(A + "<br>");        document.write(B + "<br>");        document.write(C + "<br>");        document.write(D + "<br>");        document.write(E + "<br>");    </script></body>  </html>                    
Output:
10
15
20
25
30

Reference: https://devdocs.io/d3~5/d3-array#quantile
android
D3.js
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Convert a string to an integer in JavaScript
Difference between var, let and const keywords in JavaScript
Differences between Functional Components and Class Components in React
How to Open URL in New Tab using JavaScript ?
Difference Between PUT and PATCH Request
Roadmap to Become a Web Developer in 2022
Installation of Node.js on Linux
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?
Top 10 Projects For Beginners To Practice HTML and CSS Skills
LTRIM() Function in MySQL - GeeksforGeeks

03 Dec, 2020
LTRIM() :This function in MySQL is used to remove leading spaces from a string.
Syntax :
LTRIM(str)
Parameter :It accepts one parameter as mentioned above and described below as follows.
str – The string from which we want to remove leading spaces.
Returns :It returns a string after truncating all leading spaces.
Example-1 :Removing all the leading spaces of a given string using LTRIM Function.
SELECT '    geeksforgeeks'  As OriginalString,
LTRIM ('    geeksforgeeks')  AS LeftTrimmedString;
Output :
Example-2 :Removing all the leading spaces of a given string using LTRIM Function.
SELECT '    MySQL' AS String, 
RTRIM ('MySQL')  AS Tstring;
Output :
Example-3 :LTRIM Function can also be used to remove all the leading spaces of column data. To demonstrate create a table named Employee.
CREATE TABLE Employee
(
 Employee_id INT AUTO_INCREMENT,  
 Employee_name VARCHAR(100) NOT NULL,
 Joining_Date DATE NOT NULL,
 PRIMARY KEY(Employee_id )
);
Inserting some data to the Employee table :
INSERT INTO Employee
(Employee_name, Joining_Date )
VALUES
 ('     Ananya Majumdar', '2000-01-11'),
 ('   Anushka Samanta', '2002-11-10' ),
 ('   Aniket Sharma ', '2005-06-11' ),
 ('   Anik Das', '2008-01-21'  ),
 ('  Riya Jain', '2008-02-01' ),
 ('    Tapan Samanta', '2010-01-11' ),
 ('   Deepak Sharma', '2014-12-01'  ),
 ('   Ankana Jana', '2018-08-17'),
 ('  Shreya Ghosh', '2020-09-10') ;
So, the Employee Table is as follows.
select * from Employee ;
Output :
Now, we are going to remove all leading spaces from the Employee_name column.
 SELECT  
 Employee_id,  Employee_name,
 LTRIM( Employee_name) AS  TrimmedEname  
 FROM  Employee ;
Output :
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
How to use WriteLine() method of Console class in C#?

WriteLine() is a method of the Console class defined in the System namespace
This statement causes the message "Welcome!" to be displayed on the screen as shown below −
 Live Demo
using System;
namespace Demo {
   class Test {
      static void Main(string[] args) {
         Console.WriteLine("Welcome!");
         Console.ReadKey();
      }
   }
}
Welcome!
To display a char array using the Console.WriteLine.
 Live Demo
using System;
namespace Demo {
   class Test {
      static void Main(string[] args) {
         char[] arr = new char[] { 'W', 'e'};
         Console.WriteLine(arr);
         Console.ReadKey();
      }
   }
}
We
VBScript FormatDateTime Function

It is a function that helps the developers to format and return a valid date and time expression.
FormatDateTime(date,format) 

date, a Required Parameter.
date, a Required Parameter.
format, an Optional Parameter. The Value that specifies the date or time format to be used. It can take the following values −

0 = vbGeneralDate - Default.
1 = vbLongDate - Returns date.
2 = vbShortDate - Returns date.
3 = vbLongTime - Returns time.
4 = vbShortTime - Returns time.


format, an Optional Parameter. The Value that specifies the date or time format to be used. It can take the following values −
0 = vbGeneralDate - Default.
0 = vbGeneralDate - Default.
1 = vbLongDate - Returns date.
1 = vbLongDate - Returns date.
2 = vbShortDate - Returns date.
2 = vbShortDate - Returns date.
3 = vbLongTime - Returns time.
3 = vbLongTime - Returns time.
4 = vbShortTime - Returns time.
4 = vbShortTime - Returns time.
<!DOCTYPE html>
<html>
   <body>
      <script language = "vbscript" type = "text/vbscript">
         d = ("2013-08-15 20:25")
         document.write("Line 1 : " & FormatDateTime(d) & " <br />")
         document.write("Line 2 : " & FormatDateTime(d,1) & "<br />")
         document.write("Line 3 : " & FormatDateTime(d,2) & "<br />")
         document.write("Line 4 : " & FormatDateTime(d,3) & "<br />")
         document.write("Line 5 : " & FormatDateTime(d,4) & "<br />")
       
      </script>
   </body>
</html>
When you save it as .html and execute it in Internet Explorer, then the above script will produce the following result −
Line 1 : 15/08/2013 8:25:00 PM 
Line 2 : Thursday, 15 August 2013
Line 3 : 15/08/2013
Line 4 : 8:25:00 PM
Line 5 : 20:25


    63 Lectures 
     4 hours 

 Frahaan Hussain
 Print
 Add Notes
 Bookmark this page
Clojure - If Statement

The first decision-making statement is the ‘if’ statement. Following is the general form of this statement in Clojure.
if (condition) statement#1 statement #2

In Clojure, the condition is an expression which evaluates it to be either true or false. If the condition is true, then statement#1 will be executed, else statement#2 will be executed. The general working of this statement is that first a condition is evaluated in the ‘if’ statement. If the condition is true, it then executes the statements. Following diagram shows the flow of the ‘if’ statement.
Following is an example of the simple ‘if’ expression in Clojure.
(ns clojure.examples.hello
   (:gen-class))

;; This program displays Hello World
(defn Example [] (
   if ( = 2 2)
   (println "Values are equal")
   (println "Values are not equal")))
(Example)
The output of the above program will be “Values are equal”. In the above code example, the ‘if’ condition is used to evaluate whether the values of 2 and 2 are equal. If they are, then it will print the value of “Values are equal” else it will print the value of “Values are not equal”.
Values are equal

 Print
 Add Notes
 Bookmark this page
Display Date in E MMM dd yyyy format in Java

Firstly, import the following Java packages −
import java.text.SimpleDateFormat;
import java.util.Date;
Now, create objects −
Date dt = new Date();
SimpleDateFormat dateFormat;
Displaying date in the format we want
dateFormat = new SimpleDateFormat("E MMM dd yyyy");
The following is an example −
 Live Demo
import java.text.SimpleDateFormat;
import java.util.Date;
public class Demo {
   public static void main(String args[]) {
      Date dt = new Date();
      SimpleDateFormat dateFormat;
      dateFormat = new SimpleDateFormat("E MMM dd yyyy");
      System.out.println("Date: "+dateFormat.format(dt));
   }
}
Date: Thu Nov 22 2018
XML - Comments

This chapter explains how comments work in XML documents. XML comments are similar to HTML comments. The comments are added as notes or lines for understanding the purpose of an XML code.
Comments can be used to include related links, information, and terms. They are visible only in the source code; not in the XML code. Comments may appear anywhere in XML code.
XML comment has the following syntax −
<!--Your comment-->
A comment starts with <!-- and ends with -->. You can add textual notes as comments between the characters. You must not nest one comment inside the other.
Following example demonstrates the use of comments in XML document −
<?xml version = "1.0" encoding = "UTF-8" ?>
<!--Students grades are uploaded by months-->
<class_list>
   <student>
      <name>Tanmay</name>
      <grade>A</grade>
   </student>
</class_list>
Any text between <!-- and --> characters is considered as a comment.
Following rules should be followed for XML comments −
Comments cannot appear before XML declaration.
Comments may appear anywhere in a document.
Comments must not appear within attribute values.
Comments cannot be nested inside the other comments.

    84 Lectures 
     6 hours 

 Frahaan Hussain

    29 Lectures 
     2 hours 

 YouAccel

    27 Lectures 
     1 hours 

 Jordan Stanchev

    16 Lectures 
     2 hours 

 Simon Sez IT
 Print
 Add Notes
 Bookmark this page
C program to find GCD of numbers using recursive function

Find the greatest common divisor (GCD) for the given two numbers by using the recursive function in C programming language.
The solution to find the greatest common divisor (GCD) for the given two numbers by using the recursive function is as follows −
Refer an algorithm given below to find the greatest common divisor (GCD) for the given two numbers by using the recursive function.
Step 1 − Define the recursive function.
Step 2 − Read the two integers a and b.
Step 3 − Call recursive function.
a. if i>j
b. then return the function with parameters i,j
c. if i==0
d. then return j
e. else return the function with parameters i,j%i.
A flowchart is given below for an algorithm to find the greatest common divisor (GCD) for the given two numbers by using the recursive function.
Following is the C program to find the greatest common divisor (GCD) for the given two numbers by using the recursive function −
 Live Demo
#include<stdio.h>
#include<math.h>
unsigned int GCD(unsigned i, unsigned j);
int main(){
   int a,b;
   printf("Enter the two integers: \n");
   scanf("%d%d",&a,&b);
   printf("GCD of %d and %d is %d\n",a,b,GCD(a,b));
   return 0;
}
/* Recursive Function*/
unsigned int GCD(unsigned i, unsigned j){
   if(j>i)
      return GCD(j,i);
   if(j==0)
      return i;
   else
      return GCD(j,i%j);
}
When the above program is executed, it produces the following result −
Enter the two integers: 4 8
GCD of 4 and 8 is 4
JSTL - XML <x:transform> Tag

The <x:transform> tag applies an XSL transformation on an XML document.
The <x:transform> tag has the following attributes −
Consider the following XSLT stylesheet style.xsl −
<?xml version = "1.0"?>
<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" 
   version = "1.0">

<xsl:output method = "html" indent = "yes"/>
   <xsl:template match = "/">
      <html>
         <body>
            <xsl:apply-templates/>
         </body>
      </html>
   </xsl:template>

   <xsl:template match = "books">
      <table border = "1" width = "100%">
         <xsl:for-each select = "book">
            <tr>
               <td>
                  <i><xsl:value-of select = "name"/></i>
               </td>
               
               <td>
                  <xsl:value-of select = "author"/>
               </td>
               
               <td>
                  <xsl:value-of select = "price"/>
               </td>
            </tr>
         </xsl:for-each>
      </table>
   </xsl:template>

</xsl:stylesheet>
Now consider the following JSP file −
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix = "x" uri = "http://java.sun.com/jsp/jstl/xml" %>

<html>
   <head>
      <title>JSTL x:transform Tags</title>
   </head>

   <body>
      <h3>Books Info:</h3>
      <c:set var = "xmltext">
         <books>
            <book>
               <name>Padam History</name>
               <author>ZARA</author>
               <price>100</price>
            </book>
          
            <book>
               <name>Great Mistry</name>
               <author>NUHA</author>
               <price>2000</price>
            </book>
         </books>
      </c:set>

      <c:import url = "http://localhost:8080/style.xsl" var = "xslt"/>
      <x:transform xml = "${xmltext}" xslt = "${xslt}"/>

   </body>
</html>
You will receive the following result −
Books Info:


Padam History
ZARA

100


Great Mistry
NUHA

2000



Padam History
ZARA
Great Mistry
NUHA

    108 Lectures 
     11 hours 

 Chaand Sheikh

    517 Lectures 
     57 hours 

 Chaand Sheikh

    41 Lectures 
     4.5 hours 

 Karthikeya T

    42 Lectures 
     5.5 hours 

 TELCOMA Global

    15 Lectures 
     3 hours 

 TELCOMA Global

    44 Lectures 
     15 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page
IntStream boxed() method in Java

The boxed() method of the IntStream class returns a Stream consisting of the elements of this stream, each boxed to an Integer.
The syntax is as follows.
Stream<Integer> boxed()
At first, create an IntStream
IntStream intStream = IntStream.range(20, 30);
Now, use the boxed() method to return a Stream consisting of the elements of this stream, each boxed to an Integer.
Stream<Integer> s = intStream.boxed();
The following is an example to implement IntStream boxed() method in Java.
 Live Demo
import java.util.*;
import java.util.stream.Stream;
import java.util.stream.IntStream;
public class Demo {
   public static void main(String[] args) {
      IntStream intStream = IntStream.range(20, 30);
      Stream<Integer> s = intStream.boxed();
      s.forEach(System.out::println);
   }
}
20
21
22
23
24
25
26
27
28
29
How to draw a rectangle with rounded corner in PyGame? - GeeksforGeeks

16 Mar, 2022
Pygame is a Python library designed to develop video games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the python language. In this article, we will see how can we draw a rectangle with rounded corners in Pygame.
pygame.display.set_mode(): This function is used to initialize a surface for display. This function takes the size of the display as a parameter.
pygame.display.flip(): This function is used to update the content of the entire display surface of the screen.
pygame.draw.rect(): This function is used to draw a rectangle. It takes surface, color, and pygame Rect objects as input parameters and draws a rectangle on the surface.
Syntax:
rect(surface, color, rect, width=0, border_radius=0, border_top_left_radius=-1, border_top_right_radius=-1, border_bottom_left_radius=-1, border_bottom_right_radius=-1)
The border_radius parameters were only added to PyGame version 2.0.0.dev8.
Approach
Import module
Initialize Pygame
Draw a rectangle with rounded borders
Display shape
Example 1: This example draws a rectangle with all corner rounded
Python3
# Importing the libraryimport pygame # Initializing Pygamepygame.init() # Initializing surfacesurface = pygame.display.set_mode((400, 300)) # Initializing Colorcolor = (48, 141, 70) # Drawing Rectanglepygame.draw.rect(surface, color, pygame.Rect(30, 30, 60, 60),  2, 3)pygame.display.flip()
Output:
Not just this, Pygame can be used to round even only one corner as per requirement. Given below is the implementation using the above approach. 
Example 2: This example draws a rectangle with only the top right corner rounded. 
Python3
# Importing the libraryimport pygame # Initializing Pygamepygame.init() # Initializing surfacesurface = pygame.display.set_mode((400, 300)) # Initializing Colorcolor = (48, 141, 70) # Drawing Rectanglepygame.draw.rect(surface, color, pygame.Rect(30, 30, 60, 60),  2, 0, 0, 3) # Displaying Objectpygame.display.flip()
Output:
Example 3: This example uses keyword arguments to draw a rectangle with the bottom right corner rounded.
Python3
# Importing the libraryimport pygame # Initializing Pygamepygame.init() # Initializing surfacesurface = pygame.display.set_mode((400, 300)) # Initializing Colorcolor = (48, 141, 70) # Drawing Rectanglepygame.draw.rect(surface, color, pygame.Rect(    30, 30, 60, 60),  2,  border_bottom_right_radius=5) # Displaying Objectpygame.display.flip()
Output:
punamsingh628700
kk9826225
varshagumber28
sweetyty
Python-PyGame
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Python OOPs Concepts
How to Install PIP on Windows ?
Bar Plot in Matplotlib
Defaultdict in Python
Python Classes and Objects
Deque in Python
Check if element exists in list in Python
How to drop one or multiple columns in Pandas Dataframe
Python - Ways to remove duplicates from list
Class method vs Static method in Python
What is an unsigned char in C++?

In C++ we have seen there is character type data called char. Sometimes we have seen unsigned char also. So here we will see what is basically the unsigned char means. What are the basic differences between signed char and unsigned char?
Signed char and unsigned char both are used to store single character. The variable stores the ASCII value of the characters. For an example if ‘A’ is stored, actually it will hold 65. For signed char we need not to write the signed keyword. But for unsigned, we have to mention the keyword. The syntax is like below.
unsigned char ch = ‘n’;
Both of the Signed and Unsigned char, they are of 8-bits. So for signed char it can store value from -128 to +127, and the unsigned char will store 0 to 255.
The basic ASCII values are in range 0 to 127. The rest part of the ASCII is known as extended ASCII. Using char or signed char we cannot store the extended ASCII values. By using the unsigned char, we can store the extended part as its range is 0 to 255.
Java Math sin() method with Examples - GeeksforGeeks

28 Jul, 2021
The java.lang.Math.sin() returns the trigonometry sine of an angle in between 0.0 and pi. If the argument is NaN or infinity, then the result is NaN. If the argument is zero, then the result is a zero with the same sign as the argument. The value returned will be between -1 and 1.
Syntax : 
public static double sin(double a) ;
Parameter: The value whose sine is to be returned.
Return type: This method returns the sine value of the argument.
Implementation:
Here we will be proposing 2 examples one in which we will simply be showcasing the working of Math.sin() method of java.lang package method and secondary be edge case of the first example specific taken where argument is NaN or infinity. 
Example 1
Java
// Java program to demonstrate working// of java.lang.Math.sin() methodimport java.lang.Math; class Gfg {     // driver code    public static void main(String args[])    {        double a = 30;                 // converting values to radians        double b = Math.toRadians(a);         System.out.println(Math.sin(b));         a = 45;                 // converting values to radians        b = Math.toRadians(a);         System.out.println(Math.sin(b));         a = 60;                 // converting values to radians        b = Math.toRadians(a);         System.out.println(Math.sin(b));         a = 90;                 // converting values to radians        b = Math.toRadians(a);         System.out.println(Math.sin(b));    }}
0.49999999999999994
0.7071067811865475
0.8660254037844386
1.0
 
Example 2  
Java
// Java program to demonstrate working of Math.cos() method// of java.lang package considering infinity case // Importing classes from java.lang packageimport java.lang.Math; public class GFG {     // Main driver method    public static void main(String[] args)    {         double positiveInfinity = Double.POSITIVE_INFINITY;        double negativeInfinity = Double.NEGATIVE_INFINITY;        double nan = Double.NaN;        double result;         // Here argument is negative infinity,        // output will be NaN        result = Math.sin(negativeInfinity);        System.out.println(result);         // Here argument is positive infinity,        // output will also be NaN        result = Math.sin(positiveInfinity);        System.out.println(result);         // Here argument is NaN, output will be NaN        result = Math.sin(nan);        System.out.println(result);    }}
NaN
NaN
NaN
 
AshokJaiswal
java-math
Java
Technical Scripter
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Interfaces in Java
Initialize an ArrayList in Java
ArrayList in Java
Multidimensional Arrays in Java
Stack Class in Java
Singleton Class in Java
LinkedList in Java
Collections in Java
Set in Java
Overriding in Java
Python | after method in Tkinter - GeeksforGeeks

16 Jun, 2021
Tkinter provides a variety of built-in functions develop interactive and featured GUI (Graphical User Interface). after() function is also a Universal function which can be used directly on the root as well as with other widgets. 
after(parent, ms, function = None, *args)
 
Parameters: parent: is the object of the widget or main window whichever is using this function. ms: is the time in milliseconds. function: which shall be called. *args: other options.
Code #1: 
Python3
# importing only those functions which# are neededfrom tkinter import Tk, mainloop, TOPfrom tkinter.ttk import Button # time function used to calculate timefrom time import time # creating tkinter windowroot = Tk() button = Button(root, text = 'Geeks')button.pack(side = TOP, pady = 5) print('Running...')# Calculating starting timestart = time() # in after method 5000 milliseconds# is passed i.e after 5 seconds# main window i.e root window will# get destroyedroot.after(5000, root.destroy) mainloop() # calculating end timeend = time()print('Destroyed after % d seconds' % (end-start))
Output:  
When you run the program it will show a Tkinter window having a Button but after 5 seconds the window gets destroyed.Code #2: Prompting a message after certain time (in our program after 5 seconds). 
Python3
# importing only those functions which# are neededfrom tkinter import Tk, mainloop, TOPfrom tkinter.ttk import Buttonfrom tkinter.messagebox import _show # creating tkinter windowroot = Tk()root.geometry('200x100 + 300 + 250') button = Button(root, text = 'Geeks')button.pack(side = TOP, pady = 5) # in after method 5000 milliseconds# is passed i.e after 5 seconds# a message will be promptedroot.after(5000, lambda : _show('Title', 'Prompting after 5 seconds')) # Destroying root window after 6.7 secondsroot.after(6700, root.destroy) mainloop()
Output: In below output a messagebox will prompt after 5 seconds you can even call any function after a certain period of time by passing the function name. 
 
arorakashish0911
Python-gui
Python-tkinter
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Read a file line by line in Python
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Iterate over a list in Python
Python String | replace()
*args and **kwargs in Python
Reading and Writing to text files in Python
Create a Pandas DataFrame from Lists
Python | Find all distinct pairs with difference equal to k - GeeksforGeeks

25 Nov, 2019
Given a list of integers and a positive integer k, write a Python program to count all distinct pairs with difference equal to k.
Examples:
Input : [1, 5, 3, 4, 2], k = 3
Output : [(5, 2), (4, 1)]

Input : [8, 12, 16, 4, 0, 20], k = 4
Output : [(8, 4), (12, 8), (16, 12), (4, 0), (20, 16)]

 Approach #1 : Python list comprehension
We will use list comprehension using two loops using ‘e1’ and ‘e2’ that will traverse given list. We check if e1-e2 == k or not and return the (e1, e2) tuple respectively. Finally, a list with required tuples will be returned.
# Python3 program to Find all distinct # pairs with difference equal to k  def findPairs(lst, k):          return [(e1, e2) for e1 in lst             for e2 in lst if (e1-e2 == k)]          # Driver codelst = [1, 5, 3, 4, 2]k = 3print(findPairs(lst, k))
[(5, 2), (4, 1)]

 Approach #2 :
This is an efficient approach with respect to the above approach as it uses only O(n) space. We take an empty list to store the output. Then, we use a loop with iterator ‘e’ to traverse through given list. In every iteration, we check is e+k i.e the required pair integer for e is available or not. If yes, we append the tuple to ‘res’.
# Python3 program to Find all distinct # pairs with difference equal to k  def findPairs(lst, k):    res = []    for e in lst:        if e + k in lst:            res.append(tuple((e, e + k)))                  return res      # Driver codelst = [1, 5, 3, 4, 2]k = 3print(findPairs(lst, k))
[(1, 4), (2, 5)]

 
Approach #3 : combinations() from itertools module
The best approach is to use the inbuilt function from itertools module. combinations() produces an iterator over tuples of all combinations of n elements in inputs. We make the use of these combinations and output those having ‘k’ difference.
# Python3 program to Find all distinct # pairs with difference equal to kfrom itertools import combinations  def findPairs(lst, k):    return [(x, y) for x, y in combinations(lst, r = 2)                   if abs(x - y) == k]              # Driver codelst = [1, 5, 3, 4, 2]k = 3print(findPairs(lst, k))
[(1, 4), (5, 2)]

nidhi_biet
Marketing
Python list-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
How to Install PIP on Windows ?
Enumerate() in Python
Different ways to create Pandas Dataframe
Iterate over a list in Python
Python program to convert a list to string
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Split string into list of characters
Python | Convert a list to dictionary
Check if the image is empty using Python - OpenCV - GeeksforGeeks

30 Jun, 2021
Prerequisite: Basics of OpenCV
OpenCV (Open Source Computer Vision) is a computer vision library that contains various functions to perform operations on pictures or videos. It was originally developed by Intel but was later maintained by Willow Garage and is now maintained by Itseez. This library is cross-platform that it is available in multiple programming languages such as Python, C++, etc. In this article, we’ll try to check if the opened image is empty or not by using OpenCV (Open Source Computer Vision). 
To do this OpenCV libraries are required to install:
pip install opencv-python
To achieve this objective we will use cv2.imread() method, If this method read the image then it returns the image coordinates matrix otherwise it will return None.
Input Image:
Gfg.png
Example:
In this example, we will read the image and check found or not.
Python3
# Importing OpenCV libraryimport cv2 # user define function# that return None ordef check_empty_img(img):    # Reading Image    # You can give path to the    # image as first argument    image = cv2.imread(img)     # Checking if the image is empty or not    if image is None:        result = "Image is empty!!"    else:        result = "Image is not empty!!"     return result     # driver nodeimg = "Gfg.png" # Calling and printing# the functionprint(check_empty_img(img))
Output:
Image is not empty!!
Example 2:
In this example, here the image is not found.
Python3
# Importing OpenCV libraryimport cv2 # user define function# that return None ordef check_empty_img(url):    # Reading Image    # You can give path to the    # image as first argument    image = cv2.imread(url)     # Checking if the image is empty or not    if image is None:        result = "Image is empty!!"    else:        result = "Image is not empty!!"     return result     # driver nodeimg = "geek.png" # Calling and printing# the functionprint(check_empty_img(img))
Output:
Image is empty!!
anikakapoor
Python-OpenCV
Technical Scripter 2020
Python
Technical Scripter
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
Python Classes and Objects
How to drop one or multiple columns in Pandas Dataframe
Defaultdict in Python
Python | Get unique values from a list
Python | os.path.join() method
Create a directory in Python
Python | Pandas dataframe.groupby()