code-rag-bench/online-tutorials huggingface dataset:
RxJava - MayBe Observable

The MayBe class represents deferred response. MayBe observable can emit either a single successful value or no value.
Following is the declaration for io.reactivex.Single<T> class −
public abstract class Maybe<T>
   extends Object
      implements MaybeSource<T>

Following is the sequential protocol that MayBe Observable operates −
onSubscribe (onSuccess | onError | OnComplete)?

Create the following Java program using any editor of your choice in, say, C:\> RxJava.
import java.util.concurrent.TimeUnit;

import io.reactivex.Maybe;
import io.reactivex.disposables.Disposable;
import io.reactivex.observers.DisposableMaybeObserver;
import io.reactivex.schedulers.Schedulers;

public class ObservableTester {
   public static void main(String[] args) throws InterruptedException {
      //Create an observer
      Disposable disposable = Maybe.just("Hello World")
         .delay(2, TimeUnit.SECONDS, Schedulers.io())
         .subscribeWith(new DisposableMaybeObserver<String>() {
         @Override
         public void onError(Throwable e) { 
            e.printStackTrace();
         }

         @Override
         public void onSuccess(String value) {
            System.out.println(value);
         }

         @Override
         public void onComplete() {
            System.out.println("Done!");
         }
      }); 
      Thread.sleep(3000);
      //start observing
      disposable.dispose();
   }
}
Compile the class using javac compiler as follows −
C:\RxJava>javac ObservableTester.java

Now run the ObservableTester as follows −
C:\RxJava>java ObservableTester

It should produce the following output −
Hello World

 Print
 Add Notes
 Bookmark this page
Strip last two characters of a column in MySQL?

You can strip last two characters with the help of SUBSTRING() and CHAR_LENGTH() methods. The syntax is as follows −
select yourColumnName,SUBSTRING(yourColumnName,1,CHAR_LENGTH(yourColumnName) - 2) AS anyVariableName from yourTableName;
To understand the above syntax, let us create a table −
mysql> create table LastTwoCharacters
   −> (
   −> Words varchar(200)
   −> );
Query OK, 0 rows affected (0.71 sec)
Now you can insert some records in the table with the help of select statement. The query to insert records is as follows −
mysql> insert into LastTwoCharacters values('Hellooo');
Query OK, 1 row affected (0.23 sec)

mysql> insert into LastTwoCharacters values('Worldsss');
Query OK, 1 row affected (0.10 sec)

mysql> insert into LastTwoCharacters values('Johnson');
Query OK, 1 row affected (0.22 sec)
Display all records with the help of select statement −
mysql> select *from LastTwoCharacters;
The following is the output −
+----------+
| Words    |
+----------+
| Hellooo  |
| Worldsss |
| Johnson  |
+----------+
3 rows in set (0.00 sec)
The following is the query to strip the last two characters of a column −
mysql> select Words,SUBSTRING(Words,1,CHAR_LENGTH(Words) - 2) AS AfterStripLastTwoChar from LastTwoCharacters;
The following is the output −
+----------+-----------------------+
| Words    | AfterStripLastTwoChar |
+----------+-----------------------+
| Hellooo  | Hello                 |
| Worldsss | Worlds                |
| Johnson  | Johns                 |
+----------+-----------------------+
3 rows in set (0.00 sec)
Iterate Over Keys and Values in Python Dictionaries | Towards Data Science

Dictionaries are among the most useful data structures in Python. Iterating over the keys and values of dictionaries is one of the most commonly used operations that we need to perform while working with such objects.
In today’s short guide, we are going to explore how to iterate over dictionaries in Python 3. Specifically, we’ll discuss how to
iterate over just keys
iterate over just values
iterate over both keys and values in one go
First, let’s create an example dictionary that we’ll reference across the article to demonstrate a few concepts.
my_dict = {'a': 1, 'b': 2, 'c': 3, 'd': 4}
In order to iterate only over keys you need to call keys() method that returns a new view of the dictionary’s keys.
for key in my_dict.keys():    print(key)# Outputabcd
In order to iterate over the values of the dictionary, you simply need to call values() method that returns a new view containing dictionary’s values.
for value in my_dict.values():    print(value)# Output1234
Now in case you need to iterate over both keys and values in one go, you can call items(). The method will return a tuple containing the key value pairs in the form (key, value).
for key, value in my_dict.items():    print(f'Key: {key}, Value: {value}')# OutputKey: a, Value: 1Key: b, Value: 2Key: c, Value: 3Key: d, Value: 4
Note that the objects returned by the three methods explored above, return view objects. In other words, these objects provide a dynamic view of the entries in the dictionary that means that once an entry gets modified, the view object will reflect this change as well.
The notation in Python 2 is slightly different than Python 3. In order to iterate over keys and values you need to call iteritems() method as shown below:
for key, value in my_dict.iteritems():    print(f'Key: {key}, Value: {value}')# OutputKey: a, Value: 1Key: b, Value: 2Key: c, Value: 3Key: d, Value: 4
In today’s article we discussed how to iterate over keys and values independently or at the same time, in one go using the methods keys(), values() and items(). Additionally, we discussed how to iterate over keys and values using the Python 2 notation and iteritems() method.
Become a member and read every story on Medium. Your membership fee directly supports me and other writers you read.
You may also like
Datagram in Python - GeeksforGeeks

21 Jan, 2019
Datagram is a type of wireless communication between two endpoints and it requires the ip address and port number to establish connection. Datagram uses UDP(User Datagram Protocol), it converts user data into small packets or chunks of data so that it can be sent over a network in a continuous manner. In UDP type of connection data packets have no records at the sender’s end, it just sends by the user then it’s upon receiver that it wants to accept data packets or not. UDP type of connection we use in video conferencing or in video calls.
Let’s learn how to send some data on localhost network and receive the same data as a receiver on the same machine to demonstrate the use of datagram.
To know the IP configurations of your computer, use this command on terminal:
ipconfig
Code #1: For sender’s end.
# importing socket moduleimport socket  UDP_IP = "localhost"UDP_PORT = 8080MESSAGE = "GeeksforGeeks"  print ("message:", MESSAGE)  sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)sock.sendto(bytes(MESSAGE, "utf-8"), (UDP_IP, UDP_PORT))
Output:
message: Geeksforgeeks
Explanation:
Specify your IPv4 address in the place of UDP_IP and remember port number 8080 is your localhost port number so you need to specify the same.
socket.socket() uses AF_INET in order to use the IPv4 address of your system and SOCK_DGRAM is a type of protocol that we are using for communication.
Use sock object to call function sendto(), then pass argument of tuple containing IP address and port number.
Step #2: At the receiver’s end.
# importing socket moduleimport socket  UDP_IP = "localhost"UDP_PORT = 8080  sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)sock.bind((UDP_IP, UDP_PORT))  while True:    # buffer size is 1024 bytes    data, addr = sock.recvfrom(1024)     print ("Received message:", data)
Output:
Received Message: b'Geeksforgeeks'
Explanation:
We need to specify the localhost IPaddress in UDP_IP and use the socket.socket() function same as above.
bind the parameter to the socket object so that anything receive at these port address will we catch at this end. In the loop, define the buffer size as 1024, As message is not big, it is sufficient buffer size.
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
How to drop one or multiple columns in Pandas Dataframe
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Defaultdict in Python
Python | os.path.join() method
Python | Get unique values from a list
Selecting rows in pandas DataFrame based on conditions
Create a directory in Python
Python | Pandas dataframe.groupby()
PHP | ImagickDraw line() Function - GeeksforGeeks

10 Oct, 2021
The ImagickDraw::line() function is an inbuilt function in Imagick library of PHP which is used to draw a line. This function draw the line using the current stroke color, stroke opacity, and stroke width. 
Syntax:  
bool ImagickDraw::line( $sx, $sy, $ex, $ey )
Parameters: This function accepts four parameters as mentioned above and described below:  
$sx: This parameter takes the value of starting x coordinate.
$sy: This parameter takes the value of starting y coordinate.
$ex: This parameter takes the value of ending x coordinate.
$ey: This parameter takes the value of ending y coordinate.
Return Value: This function returns TRUE on success.Below program illustrate the ImagickDraw::line() function in PHP:Program:  
php
<?php // Create an Imagick object$draw = new \ImagickDraw(); // Function to fill color$draw->setFillColor('red'); // Function to draw line$draw->line(10, 30, 180, 200); // Create Imagick object$imagick = new \Imagick(); // Create new image of given size$imagick->newImage(300, 300, 'white'); // Set the image format$imagick->setImageFormat("png"); // Function to draw the image$imagick->drawImage($draw); header("Content-Type: image/png"); // Display the output image   echo $imagick->getImageBlob();?>
Output: 
Reference: http://php.net/manual/en/imagickdraw.line.php 
saurabh1990aror
gabaa406
Image-Processing
PHP-function
PHP-Imagick
PHP
Web Technologies
PHP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Insert Form Data into Database using PHP ?
How to execute PHP code using command line ?
How to pop an alert message box using PHP ?
PHP in_array() Function
How to receive JSON POST with PHP ?
Express.js express.Router() Function
Installation of Node.js on Linux
How to set input type date in dd-mm-yyyy format using HTML ?
Differences between Functional Components and Class Components in React
How to insert spaces/tabs in text using HTML/CSS?
MongoDB query to filter object where all elements from nested array match the condition

For this, use aggregate(). Let us first create a collection with documents −
> db.demo418.insertOne(
...    {
...       "details":[
...          {
...             "CountryName":"US",
...             "Marks":45
...          },
...          {
...             "CountryName":"US",
...             "Marks":56
...          },
...
...       ],
...       "Name":"John"
...    }
... );
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5e724324b912067e57771ae6")
}
> db.demo418.insertOne(
...    {
...       "details":[
...          {
...             "CountryName":"US",
...             "Marks":78
...          },
...          {
...             "CountryName":"UK",
...             "Marks":97
...          },
...
...       ],
...       "Name":"Mike"
...    }
... );
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5e724325b912067e57771ae7")
}
Display all documents from a collection with the help of find() method −
> db.demo418.find();
This will produce the following output −
{ "_id" : ObjectId("5e724324b912067e57771ae6"), "details" : [ { "CountryName" : "US", "Marks" : 45 }, { "CountryName" : "US", "Marks" : 56 } ], "Name" : "John" }
{ "_id" : ObjectId("5e724325b912067e57771ae7"), "details" : [ { "CountryName" : "US", "Marks" : 78 }, { "CountryName" : "UK", "Marks" : 97 } ], "Name" : "Mike" }
Following is the query to filter object where all elements from nested array match the condition −
> db.demo418.aggregate([
...    {$unwind:"$details"},
...    { $group: {
...       _id: '$_id',
...       details : { $first: '$details' },
...       alldetails: { $sum: 1 },
...       alldetailsmatch: { $sum: { $cond: [ { $eq: [ '$details.CountryName', "US" ] }, 1, 0 ] } },
... Name: { $first: '$Name' }
... }},
... { $project: {
...    _id: 1,
...    Name: 1,
...    details: 1,
...    arrayValue: { $cond: [ { $eq: [ '$alldetails', '$alldetailsmatch' ] }, 1, 0 ] }
...    }},
... { $match: { 'arrayValue' : 1 } }
... ])
This will produce the following output −
{ "_id" : ObjectId("5e724324b912067e57771ae6"), "details" : { "CountryName" : "US", "Marks" : 45 }, "Name" : "John", "arrayValue" : 1 }
Beautifulsoup Installation - Python - GeeksforGeeks

05 Oct, 2021
Beautiful Soup is a Python library for pulling data out of HTML and XML files. It works with your favorite parser to provide idiomatic ways of navigating, searching, and modifying the parse tree. It commonly saves programmers hours or days of work. The latest Version of Beautifulsoup is v4.9.3 as of now.  
Python
Pip  
 
To install Beautifulsoup on Windows, Linux, or any operating system, one would need pip package. To check how to install pip on your operating system, check out – PIP Installation – Windows || Linux. Now, run a simple command,  
pip install beautifulsoup4
Wait and relax, Beautifulsoup would be installed shortly. 
 
One can install beautifulsoup, using source code directly, install beautifulsoup tarball from here – download the Beautiful Soup 4 source tarball after downloading cd into the directory and run,  
Python setup.py install
 
To check whether the installation is complete or not, let’s try implementing it using python  
 
singhaniket
how-to-install
Python-BS3
How To
Installation Guide
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Align Text in HTML?
How to Install OpenCV for Python on Windows?
Java Tutorial
How to Install FFmpeg on Windows?
How to filter object array based on attributes?
Installation of Node.js on Linux
How to Install OpenCV for Python on Windows?
How to Install FFmpeg on Windows?
How to Install and Run Apache Kafka on Windows?
How to Install Pygame on Windows ?
How to sort array of strings by their lengths following longest to shortest pattern in Java

At first, let us create and array of strings:
String[] strArr = { "ABCD", "AB", "ABCDEFG", "ABC", "A", "ABCDE", "ABCDEF", "ABCDEFGHIJ" }
Now, for longest to shortest pattern, for example ABCDEFGHIJ, ABCDEFG, ABCDEF, etc.; get the length of both the string arrays and work them like this:
Arrays.sort(strArr, (str1, str2) → str2.length() - str1.length());
The following is an example to sort array of strings by their lengths with longest to shortest pattern in Java:
import java.util.Arrays;
public class Demo {
   public static void main(String[] args) {
      String[] strArr = { "ABCD", "AB", "ABCDEFG", "ABC", "A", "ABCDE", "ABCDEF", "ABCDEFGHIJ" };
      System.out.println("Sorting array on the basis of their lengths (longest to shortest) = ");
      Arrays.sort(strArr, (str1, str2) → str2.length() - str1.length());
      Arrays.asList(strArr).forEach(System.out::println);
   }
}
Sorting array on the basis of their lengths (longest to shortest) =
ABCDEFGHIJ
ABCDEFG
ABCDEF
ABCDE
ABCD
ABC
AB
A
What is a remote interface in java?

A Remote interface is available in the java.rmi package it is a marking/tagging interface, it is used with remote method invocation(RMI).
RMI is a mechanism that allows an object residing in one system (JVM) to access/invoke an object running on another JVM.
To it is a marking interface, to mark an object of a class remote, you need to implement this interface.
To create a remote interface −
Create an interface that extends the predefined interface Remote which belongs to the package or, implement the Remote interface with the class, which you need to make remote.
Create an interface that extends the predefined interface Remote which belongs to the package or, implement the Remote interface with the class, which you need to make remote.
Declare all the business methods that can be invoked by the client in this interface.
Declare all the business methods that can be invoked by the client in this interface.
Since there is a chance of network issues during remote calls, an exception named RemoteException may occur; throw it.
Since there is a chance of network issues during remote calls, an exception named RemoteException may occur; throw it.
import java.rmi.Remote;
import java.rmi.RemoteException;
// Creating Remote class for our application
public class RemoteExample implements Remote {
}
Or,
import java.rmi.Remote;
import java.rmi.RemoteException;
// Creating Remote interface for our application
public interface Hello extends Remote {
   void printMsg() throws RemoteException;
}
C++ Stream Classes Structure

In C++ stream refers to the stream of characters that are transferred between the program thread and i/o.
Stream classes in C++ are used to input and output operations on files and io devices. These classes have specific features and to handle input and output of the program.
The iostream.h library holds all the stream classes in the C++ programming language.
Let's see the hierarchy and learn about them,
Now, let’s learn about the classes of the iostream library.
ios class − This class is the base class for all stream classes. The streams can be input or output streams. This class defines members that are independent of how the templates of the class are defined.
istream Class − The istream class handles the input stream in c++ programming language. These input stream objects are used to read and interpret the input as a sequence of characters. The cin handles the input.
ostream class − The ostream class handles the output stream in c++ programming language. These output stream objects are used to write data as a sequence of characters on the screen. cout and puts handle the out streams in c++ programming language.
COUT
 Live Demo
#include <iostream>
using namespace std;
int main(){
   cout<<"This output is printed on screen";
}
Output
This output is printed on screen
PUTS
 Live Demo
#include <iostream>
using namespace std;
int main(){
   puts("This output is printed using puts");
}
Output
This output is printed using puts
CIN
 Live Demo
#include <iostream>
using namespace std;
int main(){
   int no;
   cout<<"Enter a number ";
   cin>>no;
   cout<<"Number entered using cin is "<
Output
Enter a number 3453
Number entered using cin is 3453
gets
#include <iostream>
using namespace std;
int main(){
   char ch[10];
   puts("Enter a character array");
   gets(ch);
   puts("The character array entered using gets is : ");
   puts(ch);
}
Output
Enter a character array
thdgf
The character array entered using gets is :
thdgf
Find N Unique Integers Sum up to Zero in C++

Suppose we have an integer n. We have to return any array that contains n unique integers, such that they add up to 0. So if input is n = 5, then one possible output will be [-7, -1, 1, 3, 4]
To solve this, we will follow these steps −
take an array A as final answer, and take x := 0
for i in range 0 to n – 2A[i] = (i + 1)x := x + i + 1
A[i] = (i + 1)
x := x + i + 1
A[n – 1] = x
return A
Let us see the following implementation to get better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
void print_vector(vector<int> v){
   cout << "[";
   for(int i = 0; i<v.size(); i++){
      cout << v[i] << ", ";
   }
   cout << "]"<<endl;
}
class Solution {
   public:
      vector<int> sumZero(int n) {
         vector <int> ans(n);
         int x = 0;
         for(int i = 0; i < n - 1; i++){
            ans[i] = (i + 1);
            x += (i + 1);
         }
         ans[n - 1] = -x;
         return ans;
      }
};
main(){
   Solution ob;
   print_vector(ob.sumZero(10)) ;
}
10
[1, 2, 3, 4, 5, 6, 7, 8, 9, -45, ]
Calculation of Serial and Non-Serial Schedules in DBMS - GeeksforGeeks

10 Jan, 2022
The serial execution of a transaction is defined as Schedule. It is made up of a number of transactions each comprising of a number of instructions.
Types of Schedules –
Serial Schedules
Non-Serial Schedules
Calculation of Number of Schedules :Consider there to be N number of transactions t1, t2, t3, ...., tN with k1, k2, k3, ....., kN number of operations respectively.
Total Number of Schedules –(N1 + N2 + N3 + ..... + Nn)! / (N1! * N2! * N3! * ... * Nn!)Number of Serial Schedules –It is all possible permutations of n transactions = N!Number of Non-Serial Schedules –Total Schedules = Serial Schedules + Non-Serial SchedulesNumber of Non-Serial Schedules = Total Number of Schedules – Number of Serial Schedules((N1 + N2 + N3 + ..... + Nn)! / (N1! * N2! * N3! * ... * Nn!)) - (N!)
Total Number of Schedules –(N1 + N2 + N3 + ..... + Nn)! / (N1! * N2! * N3! * ... * Nn!)
(N1 + N2 + N3 + ..... + Nn)! / (N1! * N2! * N3! * ... * Nn!)
Number of Serial Schedules –It is all possible permutations of n transactions = N!
It is all possible permutations of n transactions = N!
Number of Non-Serial Schedules –Total Schedules = Serial Schedules + Non-Serial SchedulesNumber of Non-Serial Schedules = Total Number of Schedules – Number of Serial Schedules((N1 + N2 + N3 + ..... + Nn)! / (N1! * N2! * N3! * ... * Nn!)) - (N!)
((N1 + N2 + N3 + ..... + Nn)! / (N1! * N2! * N3! * ... * Nn!)) - (N!)
Example –Consider there to be three transactions with 1, 2, and 3 operations respectively.We have to find –
Total number of schedules possible.
Total number of serial schedules and non-serial schedules possible.
Solution –Total Number of Schedules,
= (1 + 2 + 3)! / (1! + 2! + 3!) = 6! / 12 = 60

Number of Serial Schedules,
= 3! = 6

Number of Non-Serial Schedules,
= Total Number of Schedules - Number of Serial Schedules 
= 60 - 6 
= 54 
saronind93
DBMS
GATE CS
DBMS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Second Normal Form (2NF)
Introduction of Relational Algebra in DBMS
Types of Functional dependencies in DBMS
KDD Process in Data Mining
Difference between File System and DBMS
Layers of OSI Model
Types of Operating Systems
TCP/IP Model
Page Replacement Algorithms in Operating Systems
Semaphores in Process Synchronization
Types of Parallelism in Processing Execution

Data Parallelism means concurrent execution of the same task on each multiple computing core.
Let’s take an example, summing the contents of an array of size N. For a single-core system, one thread would simply sum the elements [0] . . . [N − 1]. For a dual-core system, however, thread A, running on core 0, could sum the elements [0] . . . [N/2 − 1] and while thread B, running on core 1, could sum the elements [N/2] . . . [N − 1]. So the Two threads would be running in parallel on separate computing cores.
Task Parallelism means concurrent execution of the different task on multiple computing cores.
Consider again our example above, an example of task parallelism might involve two threads, each performing a unique statistical operation on the array of elements. Again The threads are operating in parallel on separate computing cores, but each is performing a unique operation.
Bit-level parallelism is a form of parallel computing which is based on increasing processor word size. In this type of parallelism, with increasing the word size reduces the number of instructions the processor must execute in order to perform an operation on variables whose sizes are greater than the length of the word.
E.g., consider a case where an 8-bit processor must add two 16-bit integers. First the 8 lower-order bits from each integer were must added by processor, then add the 8 higher-order bits, and then two instructions to complete a single operation. A processor with 16- bit would be able to complete the operation with single instruction.
Instruction-level parallelism means the simultaneous execution of multiple instructions from a program. While pipelining is a form of ILP, we must exploit it to achieve parallel execution of the instructions in the instruction stream.
for (i=1; i<=100; i= i+1)
   y[i] = y[i] + x[i];
This is a parallel loop. Every iteration of the loop can overlap with any other iteration, although within each loop iteration there is little opportunity for overlap.
Java Variables

Variables are containers for storing data values. 
In Java, there are different types of variables, for example:
String - stores text, such as "Hello". String values are 
 surrounded by double quotes
int - stores integers (whole numbers), without decimals, such as 123 or -123
float - stores floating point numbers, with decimals, such as 19.99 or -19.99
char - stores single characters, such as 
 'a' or 'B'. Char values are surrounded by single quotes
boolean - stores values with two states: 
 true or false
To create a variable, you must specify the type and assign it a value:
type variableName = value;

Where type is one of Java's types (such as int or String), and 
variableName is the name of the variable (such as x or
name). The equal sign is used to assign values to the variable.
To create a variable that should store text, look at the following example:
Create a variable called name of type String and assign it the value "John":
String name = "John";
System.out.println(name);


Try it Yourself »

To create a variable that should store a number, look at the following example:
Create a variable called myNum of type int and assign it the value 15:
int myNum = 15;
System.out.println(myNum);


Try it Yourself »

You can also declare a variable without assigning the value, and assign the value later:
int myNum;
myNum = 15;
System.out.println(myNum);


Try it Yourself »

Note that if you assign a new value to an existing variable, it will overwrite the previous value:
Change the value of myNum from 15 to 20:
int myNum = 15;
myNum = 20;  // myNum is now 20
System.out.println(myNum);


Try it Yourself »

If you don't want others (or yourself) to overwrite existing values, use the final keyword (this will declare the variable as "final" or "constant", which means unchangeable and read-only):
final int myNum = 15;
myNum = 20;  // will generate an error: cannot assign a value to a final variable


Try it Yourself »

A demonstration of how to declare variables of other types:
int myNum = 5;
float myFloatNum = 5.99f;
char myLetter = 'D';
boolean myBool = true;
String myText = "Hello";

You will learn more about data types in the next section.
Create a variable named carName and assign the value Volvo to it.
  = ;

Start the Exercise
We just launchedW3Schools videos
Get certifiedby completinga course today!
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
help@w3schools.com
Your message has been sent to W3Schools.
Detach interrupts from a source in Arduino

We have seen that in order to attach interrupts to a source, we use the .attachInterrupt() function, with the required arguments.
For example, for attaching the interrupts to a specific pin, we use
attachInterrupt(digitalPinToInterrupt(pin), ISR, mode);
In the same way, to detach the interrupt from a source, we can call the detachInterrupt() function. This will simply disable that particular interrupt. The recommended syntax for disabling pin interrupts is −
detachInterrupt(digitalPinToInterrupt(pin))
where pin is the pin number on which you wish to disable the interrupt.
Java Program to sort an array in alphabetical order

Let us first create a string array:
String[] strArr = new String[] { "r", "p", "v","y", "s", "q" };
Now, use the Arrays.sort() method to sort an array in alphabetical order. Here, we have set the order to be case insensitive:
Arrays.sort(strArr, String.CASE_INSENSITIVE_ORDER);
import java.util.Arrays;
public class Demo {
   public static void main(String[] args) {
      String[] strArr = new String[] { "r", "p", "v","y", "s", "q" };
      System.out.println("Sort array in alphabetical order...");
      Arrays.sort(strArr, String.CASE_INSENSITIVE_ORDER);
      for (int a = 0; a < strArr.length; a++) {
         System.out.println(strArr[a]);
      }
   }
}
Sort array in alphabetical order...
p
q
r
s
v
y
TypeScript Tutorial

TypeScript lets you write JavaScript the way you really want to. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. TypeScript is pure object oriented with classes, interfaces and statically typed like C# or Java. The popular JavaScript framework Angular 2.0 is written in TypeScript. Mastering TypeScript can help programmers to write object-oriented programs and have them compiled to JavaScript, both on server side and client side.
Programmers coming from Object Oriented world will find it easy to use TypeScript. With the knowledge of TypeScript, they can build web applications much faster, as TypeScript has good tooling support.
As a reader of this tutorial, you should have a good understanding of OOP concepts and basic JavaScript, to make the most of this tutorial.
We have provided Typescript Online Compiler which helps you  to Edit and Execute the code directly from your browser. Try to click the icon  to run the following Typescript code to print conventional "Hello, World!".
var message:string = "Hello World" 
console.log(message)

On compiling, it will generate following JavaScript code.
//Generated by typescript 1.8.10
var message = "Hello World";
console.log(message);


    45 Lectures 
     4 hours 

 Antonio Papa

    41 Lectures 
     7 hours 

 Haider Malik

    60 Lectures 
     2.5 hours 

 Skillbakerystudios

    77 Lectures 
     8 hours 

 Sean Bradley

    77 Lectures 
     3.5 hours 

 TELCOMA Global

    19 Lectures 
     3 hours 

 Christopher Frewin
 Print
 Add Notes
 Bookmark this page
Tada Animation Effect with CSS

To create Tada animation effect with CSS, you can try to run the following code:
Live Demo
<html>
   <head>
      <style>
         .animated {
            background-image: url(/css/images/logo.png);
            background-repeat: no-repeat;
            background-position: left top;
            padding-top:95px;
            margin-bottom:60px;
            -webkit-animation-duration: 10s;
            animation-duration: 10s;
           -webkit-animation-fill-mode: both;
            animation-fill-mode: both;
         }
         @-webkit-keyframes tada {
            0% {-webkit-transform: scale(1);}
            10%, 20% {-webkit-transform: scale(0.9) rotate(-3deg);}
            30%, 50%, 70%, 90% {-webkit-transform: scale(1.1) rotate(3deg);}
            40%, 60%, 80% {-webkit-transform: scale(1.1) rotate(-3deg);}
            100% {-webkit-transform: scale(1) rotate(0);}
         }
         @keyframes tada {
            0% {transform: scale(1);}
            10%, 20% {transform: scale(0.9) rotate(-3deg);}
            30%, 50%, 70%, 90% {transform: scale(1.1) rotate(3deg);}
            40%, 60%, 80% {transform: scale(1.1) rotate(-3deg);}
            100% {transform: scale(1) rotate(0);}
         }
         .tada {
            -webkit-animation-name: tada;
            animation-name: tada;
         }
      </style>
   </head>
   <body>
      <div id = "animated-example" class = "animated tada"></div>
      <button onclick = "myFunction()">Reload page</button>
      <script>
         function myFunction() {
            location.reload();
         }
      </script>
   </body>
</html>
How to position text to bottom left on an image with CSS

To position text to bottom left, use the bottom and left property. You can try to run the following code to position text to bottom left on an image
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <style>
         .box {
            position: relative;
         }
         img {
            width: 100%;
            height: auto;
            opacity: 0.6;
         }
         .direction {
            position: absolute;
            bottom: 10px;
            left: 19px;
            font-size: 13px;
         }
      </style>
   </head>
   <body>
      <h1>Heading One</h1>
      <p>Below image has text in the bottom left:</p>
      <div class = "box">
         <img src = "https://www.tutorialspoint.com/python/images/python_data_science.jpg" alt="Tutorial" width="800" height="400">
         <div class = "direction">Bottom Left Corner</div>
      </div>
   </body>
</html>
Inserting Date() in MongoDB through Mongo shell?

In order to insert Date() in MongoDB through Mongo shell, use the following syntax
var yourVariableName= new Date(year,month, day, hour, minute);
db.yourCollectionName({yourDateFieldName:yourVariableName});
Let us first create a date variable
> var creatingDate = new Date(2019, 03, 29, 13, 12);
Let us create a collection with documents:
>db.insertingDateUsingVariableDemo.insertOne({"UserName":"John","UserMessages":["Hi","Hello","Awesome"],"UserPostDate":creatingDate});
Following is the query to display all documents from a collection with the help of find() method
> db.insertingDateUsingVariableDemo.find().pretty();
This will produce the following output
{
   "_id" : ObjectId("5c9d1b19a629b87623db1b21"),
   "UserName" : "John",
   "UserMessages" : [
      "Hi",
      "Hello",
      "Awesome"
   ],
   "UserPostDate" : ISODate("2019-04-29T07:42:00Z")
}
Creating a popup message box with an Entry field in tkinter

Tkinter Popup are toplevel window interfaces that wrap up the widget and the element with the main window. It can be embedded in any main window using a handler like Button Widget. Popup can be created using the Toplevel(root) constructor.
In this example, we will create a simple application containing a Label widget and a button to open the popup message box which contains an Entry field. Once the popup is opened, it can have the functionality to go back to the main window.
#Import the required library
from tkinter import*

#Create an instance of tkinter frame
win= Tk()

#Define geometry of the window
win.geometry("750x250")

#Define a function to close the popup window
def close_win(top):
   top.destroy()
def insert_val(e):
   e.insert(0, "Hello World!")

#Define a function to open the Popup Dialogue
def popupwin():
   #Create a Toplevel window
   top= Toplevel(win)
   top.geometry("750x250")

   #Create an Entry Widget in the Toplevel window
   entry= Entry(top, width= 25)
   entry.pack()

   #Create a Button to print something in the Entry widget
   Button(top,text= "Insert", command= lambda:insert_val(entry)).pack(pady= 5,side=TOP)
   #Create a Button Widget in the Toplevel Window
   button= Button(top, text="Ok", command=lambda:close_win(top))
   button.pack(pady=5, side= TOP)
#Create a Label
label= Label(win, text="Click the Button to Open the Popup Dialogue", font= ('Helvetica 15 bold'))
label.pack(pady=20)

#Create a Button
button= Button(win, text= "Click Me!", command= popupwin, font= ('Helvetica 14 bold'))
button.pack(pady=20)
win.mainloop()
Running the above code will display a window that contains a button to open the Popup Dialogue.
Once we click the button, it will open the popup Dialog Box. The popup Dialog has two buttons, each for a different purpose. When we click the “Ok” button, it will destroy the popup and revert back to the main window.
How to make a specific text on TextView bold in Android?

This example demonstrates how do I make a specific text on TextView bold in android.
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"
   android:id="@+id/coordinator_layout"
   android:layout_width="match_parent"
   android:layout_height="match_parent">
   <TextView
      android:id="@+id/textView"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:textSize="40sp"
      android:layout_gravity="center"
      android:layout_margin="25dp" />
</RelativeLayout>
Step 3 − Add the following code to src/MainActivity.java
import android.graphics.Typeface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.StyleSpan;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
   TextView textView;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      textView = (TextView) findViewById(R.id.textView);
      String text = "My favourite food is Biriyani";
      SpannableString ss = new SpannableString(text);
      StyleSpan boldSpan = new StyleSpan(Typeface.BOLD);
      ss.setSpan(boldSpan, 21, 29,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      textView.setText(ss);
   }
}
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="app.com.sample" >
   <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 Run  icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen −
Click here to download the project code.
How to use the same JavaScript in multiple content pages?

To use the same JavaScript in more than one page, add the js code in an external JavaScript file. Let’s say the following demo.js is our external JavaScript file −
function display() {
   alert("Hello World!");
}
Now add the external JavaScript file to the following HTML web page. In the same way, you can add it to multiple content page.
<html>
   <body>
      <form>
         <input type="button" value="Result" onclick="display()"/>
      </form>
      <script src="demo.js">
      </script>
   </body>
</html>
Display numbers with thousands separator in Java

To display number with thousands separator, set a comma flag.
System.out.printf( "%,d\n",78567);
The above would result.
78, 567
Let’s check for bigger numbers.
System.out.printf( "%,d\n", 463758);
The above would result.
463,758
 Live Demo
public class Demo {
   public static void main( String args[] ) {
      System.out.printf( "%,d\n", 95647 );
      System.out.printf( "%,d\n", 687467 );
      System.out.printf( "%,.2f\n", 7546.21 );
      System.out.printf( "%,.2f\n", 463758.787 );
      System.out.printf( "%,.2f", 123456.5 );
   }
}
95,647
687,467
7,546.21
463,758.79
123,456.50
Tryit Editor v3.7

HTML form attributes
Tryit: HTML form action attribute
How to create an ordered list with list items numbered with numbers in HTML?

To create ordered list in HTML, use the <ol> tag. Ordered list starts with the <ol> tag. The list item starts with the <li> tag and will be marked as numbers, lowercase letters uppercase letters, roman letters, etc. The default numbers for list items.
For creating an ordered list with numbers, use the <ol> tag attribute type. This attribute will assign the value number i.e. <ol type = “1”> to create ordered list numbered with numbers.
You can try to run the following code to create an ordered list of list items numbered with numbers in HTML −
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <title>World Cup Teams</title>
   </head>
   <body>
      <h1>List of teams for World Cup</h1>
      <ol type = "1">
         <li>India</li>
         <li>Australia</li>
         <li>South Africa</li>
         <li>New Zealand</li>
         <li>Pakistan</li>
         <li>Srilanka</li>
         <li>West Indies</li>
         <li>Bangladesh</li>
      </ol>
   </body>
</html>
How to return object from an array with highest key values along with name - JavaScript?

Suppose, we have an array of objects that contains information about marks of some students in a test −
const students = [
   { name: 'Andy', total: 40 },
   { name: 'Seric', total: 50 },
   { name: 'Stephen', total: 85 },
   { name: 'David', total: 30 },
   { name: 'Phil', total: 40 },
   { name: 'Eric', total: 82 },
   { name: 'Cameron', total: 30 },
   { name: 'Geoff', total: 30 }
];
We are required to write a JavaScript function that takes in one such array and returns a object with the name and total of the student that have highest value for total.
Therefore, for the above array, the output should be −
{ name: 'Stephen', total: 85 } 
Following is the code −
const students = [
   { name: 'Andy', total: 40 },
   { name: 'Seric', total: 50 },
   { name: 'Stephen', total: 85 },
   { name: 'David', total: 30 },
   { name: 'Phil', total: 40 },
   { name: 'Eric', total: 82 },
   { name: 'Cameron', total: 30 },
   { name: 'Geoff', total: 30 }
];
const pickHighest = arr => {
   const res = {
      name: '',
      total: -Infinity
   };
   arr.forEach(el => {
      const { name, total } = el;
      if(total > res.total){
         res.name = name;
         res.total = total;
      };
   });
   return res;
};
console.log(pickHighest(students));
This will produce the following output on console −
{ name: 'Stephen', total: 85 }
What is Control Statements?

Control statements are the statements that change the flow of execution of statements. For example, If, If-else, Switch-Case, while-do statements. In programming languages, Boolean expressions are used to
Alter the flow of control− Boolean expressions are used as conditional expressions in a statement that alter the flow of control. The value of such Boolean expression is implicit in a position reached in a program. For example, if (E) S, the expression E should be true if statement S is reached.
Alter the flow of control− Boolean expressions are used as conditional expressions in a statement that alter the flow of control. The value of such Boolean expression is implicit in a position reached in a program. For example, if (E) S, the expression E should be true if statement S is reached.
Compute logical values− A Boolean expression can define true or false values. Such Boolean expressions can be computed in parallel to arithmetic expressions using three address instruction with logical operators.
Compute logical values− A Boolean expression can define true or false values. Such Boolean expressions can be computed in parallel to arithmetic expressions using three address instruction with logical operators.
The designed use of the Boolean expression is decided by its syntactic context. For example, an expression following the keyword ‘if’ is used to alter the flow of control while an expression on the right side of an assignment can indicate a logical value. Such syntactic contexts can be defined in several ways. It can use several nonterminals,
use inherited attributes, or set a flag during parsing. It can generate a syntax tree and invoke multiple procedures for the two different uses of Boolean expressions.
Example1− Generate three Address Code for
while (a < b) do
If (c < d) then
   x = y + z
else
   x = y – z.
Solution
(1) If a < b goto(3) 
(2) goto(11) 
(3) If c < d goto(5) 
(4) goto(8) 
(5) t1 = y + z 
(6) x = t1 
(7) goto(1) 
(8) t2 = y − z 
(9) x = t2 
(10) goto(1)
Example2− Generate three Address Code for
while (A < C and B < D) do
If A=1 then C = C + 1
else while A≤D do A = A + 2.
Solution
(1) If A < C goto(3)
(2) goto(15)
(3) If B < D goto(5)
(4) goto(15)
(5) If A = 1 goto(7)
(6) goto (10)
(7) T1 = C + 1
(8) C = T1
(9) goto (1)
(10) If A ≤ D goto (12)
(11) goto (1)
(12) T2 = A + 2
(13) A = T2
(14) goto (10)
Example3− Generate three Address Code for
Switch (a)
{
   Case 1−
      b = c + d
      break;
   Case 2−
      e = f + g
      break;
}
Solution
(1) If a = 1 goto(3)
(2) If a = 2 goto (6)
(3) t1 = c + d
(4) b = t1
(5) goto(9)
(6) t2 = f + g
(7) e = t2
(8) goto(9)
Example4− Generate three address code for
while (i<5)
{
   i=i+1;
}
Solution
(1)if i<5 goto(3)
(2) goto (5)
(3) i = i + 1
(4) goto (1)
Example5− Convert the following control statements into Three Address Code.
If (A < B OR C > D)
X = X + Y + Z
Solution
(1) If A < B goto(4)
(2) If C > D goto(4)
(3) goto(7)
(4) T1− = X + Y
(5) T2 = T1 + Z
(6) X− = T2
H2 Database - Merge

MERGE command is used to update the existing rows and insert new rows into a table.  The primary key column plays an important role while using this command; it is used to find the row.
Following is the generic syntax of the MERGE command.
MERGE INTO tableName [ ( columnName [,...] ) ] 
[ KEY ( columnName [,...] ) ] 
{ VALUES { ( { DEFAULT | expression } [,...] ) } [,...] | select } 

In the above syntax, the KEY clause is used to specify the primary key column name. Along with VALUES clause, we can use primitive values to insert or we can retrieve and store another table values into this table using the select command.
In this example, let us try to add a new record into Customers table. Following are the details of the new record in the table.
Using the following query, let us insert the given record into the H2 database query.
MERGE INTO CUSTOMER KEY (ID) VALUES (8, 'Lokesh', 32, 'Hyderabad', 2500);

The above query produces the following output.
Update count: 1 

Let us verify the records of the Customer table by executing the following query.
SELECT * FROM CUSTOMER;
The above query produces the following output.
Now let us try to update the record using the Merge command. Following are the details of the record to be updated.
Use the following query to insert the given record into the H2 database query.
MERGE INTO CUSTOMER KEY (ID) VALUES (8, 'Loki', 32, 'Hyderabad', 3000);

The above query produces the following output.
Update count: 1 

Let us verify the records of the Customer table by executing the following query.
SELECT * FROM CUSTOMER; 

The above query produces the following output −

    14 Lectures 
     1 hours 

 Mahesh Kumar

    100 Lectures 
     9.5 hours 

 Hari Om Singh

    108 Lectures 
     8 hours 

 Pavan Lalwani

    10 Lectures 
     1 hours 

 Deepti Trivedi

    20 Lectures 
     2 hours 

 Deepti Trivedi

    14 Lectures 
     1 hours 

 Deepti Trivedi
 Print
 Add Notes
 Bookmark this page
Crop Images in CSS with object-fit and object-position

CSS object-fit and object-position property helps us crop images and specify how it is displayed in an element.
The syntax of CSS object-fit property is as follows −
Selector {
   object-fit: /*value*/
   object-position:/*value*/
}
The following examples illustrate CSS object-fit property.
 Live Demo
<!DOCTYPE html>
<html>
<head>
<style>
img {
   object-fit: cover;
}
img:last-of-type {
   object-fit: contain;
}
</style>
</head>
<body>
cover
<img src="https://images.unsplash.com/photo-1611423837981- 2cba00ee7631?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=120&ixlib=rb1.2.1&q=80&w=120" width="200" height="250"/>
<img src="https://images.unsplash.com/photo-1611423837981- 2cba00ee7631?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=120&ixlib=rb1.2.1&q=80&w=120" width="200" height="250"/>
contain
</body>
</html>
This will produce the following result −
 Live Demo
<!DOCTYPE html>
<html>
<style>
div {
   border: 1px solid blue;
   width:100%;
   height:300px;
}
img {
   float:left;
   width:50%;
   height:100%;
   object-fit:cover;
   object-position: 20px -10px;
}
</style>
<body>
<div >
<img src="https://images.unsplash.com/photo-1611800065908-
233b597db552?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=350&ixlib=rb1.2.1&q=80&w=250" />
<img src="https://images.unsplash.com/photo-1612626256634-
991e6e977fc1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=350&ixlib=rb1.2.1&q=80&w=250"/>
</div>
</body>
</html>
This will produce the following result −
Effect of resizing