code-rag-bench/online-tutorials huggingface dataset:
Dart Programming - Debugging

Every now and then, developers commit mistakes while coding. A mistake in a program is referred to as a bug. The process of finding and fixing bugs is called debugging and is a normal part of the development process. This section covers tools and techniques that can help you with debugging tasks.
The WebStorm editor enables breakpoints and step-by-step debugging. The program will break at the point where the breakpoint is attached. This functionality is like what you might expect from Java or C# application development. You can watch variables, browse the stack, step over and step into method and function calls, all from the WebStorm Editor.
Consider the following code snippet. (TestString.dart)
void main() { 
   int a = 10, b = 20, c = 5; 
   c = c * c * c; 
   
   print("$a + $b = ${a+b}"); 
   print("$a%$b = ${a%b}");  // Add a break point here 
   print("$a*$b = ${a*b}"); 
   print("$a/$b = ${a/b}"); 
   print(c); 
}
To add a breakpoint, click on the left margin to. In the figure given below, line number 7 has a break point.
Run the program in debug mode. In the project explorer right click on the dart program in our case TestString.dart.
Once the program runs in debug mode, you will get the Debugger window as shown in the following screenshot. The variables tab shows the values of variables in the current context. You can add watchers for specific variables and listen to that values changes using watches window.
Step Into (F7) arrow icon on debug menu helps to Executes code one statement at a time. If main methods call a subroutine, then this will go into the subroutine code also.
Step over (F8): It is similar to Step Into. The difference in use occurs when the current statement contains a call to a subroutine. If the main method calls a subroutine, step over will not drill into the subroutine. it will skip the subroutine.
Step Out (Shift+F8): Executes the remaining lines of a function in which the current execution point lies. The next statement displayed is the statement following the subroutine call.
After running in debug mode, the program gives the following output −
10 + 20 = 30 
10 % 20 = 10 
10 * 20 = 200 
10 / 20 = 0.5 
125


    44 Lectures 
     4.5 hours 

 Sriyank Siddhartha

    34 Lectures 
     4 hours 

 Sriyank Siddhartha

    69 Lectures 
     4 hours 

 Frahaan Hussain

    117 Lectures 
     10 hours 

 Frahaan Hussain

    22 Lectures 
     1.5 hours 

 Pranjal Srivastava

    34 Lectures 
     3 hours 

 Pranjal Srivastava
 Print
 Add Notes
 Bookmark this page
All possible permutations of N lists in Python

If we have two lists and we need to combine each element of the first element with each element of the second list, then we have the below approaches.
In this straight forward approach we create a list of lists containing the permutation of elements from each list. we design a for loop within another for loop. The inner for loop refers to the second list and Outer follow refers to the first list.
 Live Demo
A = [5,8]
B = [10,15,20]

print ("The given lists : ", A, B)
permutations = [[m, n] for m in A for n in B ]
Running the above code gives us the following result:
The given lists : [5, 8] [10, 15, 20]
permutations of the given values are : [[5, 10], [5, 15], [5, 20], [8, 10], [8, 15], [8, 20]]
The itertools module has a iterator named product. It does the same thing what the above nested for loop does. Creates nested for loops internally to give the required product.
 Live Demo
import itertools

A = [5,8]
B = [10,15,20]

print ("The given lists : ", A, B)
result = list(itertools.product(A,B))
print ("permutations of the given lists are : " + str(result))
Running the above code gives us the following result:
The given lists : [5, 8] [10, 15, 20]
permutations of the given values are : [(5, 10), (5, 15), (5, 20), (8, 10), (8, 15), (8, 20)]
Move rows from one table to another in MySQL?

You can move rows from one table to another with the help of INSERT INTO SELECT statement.
The syntax is as follows −
insert into yourDestinationTableName select *from yourOriginalTable where someCondition
To understand the above syntax. let us create a table. The following is the query to create a table −
mysql> create table StudentTable
   −> (
      −> Id int,
      −> Name varchar(100)
   −> );
Query OK, 0 rows affected (0.65 sec)
Now, I will create second table. The query is as follows −
mysql> create table Employee
   −> (
      −> EmployeeId int
      −> ,
      −> EmployeeName varchar(100)
   −> );
Query OK, 0 rows affected (0.54 sec)
Inserting some records in the table Employee. The query to insert records is as follows −
mysql> insert into Employee values(1,'Carol');
Query OK, 1 row affected (0.18 sec)

mysql> insert into Employee values(2,'John');
Query OK, 1 row affected (0.16 sec)

mysql> insert into Employee values(3,'Johnson');
Query OK, 1 row affected (0.11 sec)
Now you can display all records from Employee table with the help of SELECT statement. The query is as follows:
mysql> select *from Employee;
The following is the output −
+------------+--------------+
| EmployeeId | EmployeeName |
+------------+--------------+
|          1 | Carol        |
|          2 | John         |
|          3 | Johnson      |
+------------+--------------+
3 rows in set (0.00 sec)
Implement the syntax we discussed in the beginning to move row in another table. The below query moves row from Employee table to StudentTable −
mysql> insert into StudentTable select *from Employee where EmployeeId = 3 and EmployeeName = 'Johnson';
Query OK, 1 row affected (0.17 sec)
Records: 1 Duplicates: 0 Warnings: 0
Now, you can check whether the row is present in second table ‘StudentTable’ or not. The query is as follows −
mysql> select *from StudentTable;
The following is the output −
+------+---------+
| Id   |    Name |
+------+---------+
| 3    | Johnson |
+------+---------+
1 row in set (0.00 sec)
Look at the above sample output, we have moved row from one table to another. To move all the rows, you just need to remove the “where” condition. The query is as follows −
mysql> insert into StudentTable select *from Employee;
Query OK, 3 rows affected (0.15 sec)
Records: 3 Duplicates: 0 Warnings: 0
The query displays all the updated records in the StudentTable −
mysql> select *from StudentTable;
The following is the output −
+------+---------+
| Id   | Name    |
+------+---------+
| 1    | Carol   |
| 2    | John    |
| 3    | Johnson |
+------+---------+
3 rows in set (0.00 sec)
Selects all <p> elements where the parent is a <div> element with CSS

Use the element > element selector to select an element with a parent element.
You can try to run the following code to select all <p> elements where the parent is a <div> element,
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <style>
         div > p {
            color: white;
            background-color: blue;
         }
      </style>
   </head>

   <body>
      <h1>Demo Website</h1>
      <h2>Fruits</h2>
      <p>Fruits are good for health.</p>
      <div>
         <p>This is demo text.</p>
      </div>
   </body>
</html>
How to use Hidden Component in ReactJS?

20 Jun, 2022
Hidden component quickly and responsively toggles the visibility value of components and more with the hidden utilities. Material UI for React has this component available for us and it is very easy to integrate. We can use the Hidden component in ReactJS using the following approach.
Creating React Application And Installing Module:
Step 1: Create a React application using the following command:
npx create-react-app foldername
Step 2: After creating your project folder i.e. foldername, move to it using the following command:
cd foldername
Step 3: After creating the ReactJS application, Install the material-ui modules using the following command:
npm install @material-ui/core
Project Structure: It will look like the following.
Project Structure
Filename-App.js: Now write down the following code in the App.js file. Here, App is our default component where we have written our code.
App.js
import React from 'react';import { makeStyles } from '@material-ui/core/styles';import Hidden from '@material-ui/core/Hidden';import Paper from '@material-ui/core/Paper';  const App = () => {    const useStyles = makeStyles((theme) => ({    paper: {      flex: '1 0 auto',      margin: theme.spacing(1),      padding: theme.spacing(2),      color: theme.palette.text.secondary,      textAlign: 'center',    },  }));    const classes = useStyles();    return (    <div style={{      display: 'flex',      flexWrap: 'wrap',    }}>      <div style={{ width: '100%', float: 'left' }}>        <h3>How to use Hidden Component in ReactJS?</h3> <br />      </div>      <Hidden mdDown>        <Paper className={classes.paper}>Small Down</Paper>      </Hidden>      <Hidden smDown>        <Paper className={classes.paper}>Medium Down</Paper>      </Hidden>      <Hidden xsDown>        <Paper className={classes.paper}>Large Down</Paper>      </Hidden>    </div>  );}  export default App;
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Now are you start reducing the size of your window, you will notice that the first box will get hidden, followed by the next two. This is how Hidden Component works in ReactJS.
JavaScript
ReactJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python | Maximum and Minimum in a Set

28 Dec, 2017
In this article, we will learn how to get the maximum and minimum element in a set in Python, using the built-in functions of Python.Examples:
Input : set = ([8, 16, 24, 1, 25, 3, 10, 65, 55])
Output : max is 65

Input : set = ([4, 12, 10, 9, 4, 13])
Output : min is 4

max() in a Set
The built-in function max() in Python is used to get the maximum of all the elements in a set.
# Python code to get the maximum element from a setdef MAX(sets):    return (max(sets))      # Driver Codesets = set([8, 16, 24, 1, 25, 3, 10, 65, 55])print(MAX(sets))
Output:
65

min() in a Set
# Python code to get the minimum element from a setdef MIN(sets):    return (min(sets))      # Driver Codesets = set([4, 12, 10, 9, 4, 13])print(MIN(sets))
Output:
4

python-set
Python
python-set
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Program for Linear Search

22 Jun, 2022
Problem: Given an array arr[] of n elements, write a function to search a given element x in arr[]. 
Examples :
Input : arr[] = {10, 20, 80, 30, 60, 50, 
                     110, 100, 130, 170}
          x = 110;
Output : 6
Element x is present at index 6

Input : arr[] = {10, 20, 80, 30, 60, 50, 
                     110, 100, 130, 170}
           x = 175;
Output : -1
Element x is not present in arr[].
A simple approach is to do a linear search, i.e
Start from the leftmost element of arr[] and one by one compare x with each element of arr[]
If x matches with an element, return the index.
If x doesn’t match with any of the elements, return -1.
Example:  Iterative Approach:
Python
# Searching an element in a list/array in python# can be simply done using \'in\' operator# Example:# if x in arr:#   print arr.index(x) # If you want to implement Linear Search in python # Linearly search x in arr[]# If x is present then return its location# else return -1 def search(arr, x):     for i in range(len(arr)):         if arr[i] == x:            return i     return -1
Recursive Approach: 
Python
# This is similar to the above one, with the only difference# being that it is using the recursive approach instead of iterative.  def search(arr, curr_index, key):    if curr_index == -1:        return -1    if arr[curr_index] == key:        return curr_index    return search(arr, curr_index-1, key)
The time complexity of the above algorithm is O(n). 
Auxiliary Space: O(1) for iterative and O(n) for recursive.
Please refer complete article on Linear Search and Difference Between Recursive and Iterative Algorithms for more details!
talktoanmol
chandramauliguptach
python searching-exercises
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
PostgreSQL – INNER JOIN

28 Aug, 2020
In PostgreSQL the INNER JOIN keyword selects all rows from both the tables as long as the condition satisfies. This keyword will create the result-set by combining all rows from both the tables where the condition satisfies i.e value of the common field will be the same.
Syntax:
SELECT table1.column1, table1.column2, table2.column1, ....
FROM table1 
INNER JOIN table2
ON table1.matching_column = table2.matching_column;


table1: First table.
table2: Second table
matching_column: Column common to both the tables.
Let’s analyze the above syntax:
Firstly, using the SELECT statement we specify the tables from where we want the data to be selected.
Second, we specify the main table.
Third, we specify the table that the main table joins to.
The below Venn Diagram illustrates the working of PostgreSQL INNER JOIN clause:For the sake of this article we will be using the sample DVD rental database, which is explained here and can be downloaded by clicking on this link in our examples.
Now, let’s look into a few examples.
Example 1:Here we will be joining the “customer” table to “payment” table using the INNER JOIN clause.
SELECT
    customer.customer_id,
    first_name,
    last_name,
    email,
    amount,
    payment_date
FROM
    customer
INNER JOIN payment ON payment.customer_id = customer.customer_id;
Output:
Example 2:
Here we will be joining the “customer” table to “payment” table using the INNER JOIN clause and sort them with the ORDER BY clause:
SELECT
    customer.customer_id,
    first_name,
    last_name,
    email,
    amount,
    payment_date
FROM
    customer
INNER JOIN payment ON payment.customer_id = customer.customer_id
ORDER BY
    customer.customer_id;
Output:
Example 3:Here we will be joining the “customer” table to “payment” table using the INNER JOIN clause and filter them with the WHERE clause:
SELECT
    customer.customer_id,
    first_name,
    last_name,
    email,
    amount,
    payment_date
FROM
    customer
INNER JOIN payment ON payment.customer_id = customer.customer_id
WHERE
    customer.customer_id = 15;
Output:
Example 4:Here we will establish the relationship between three tables: staff, payment, and customer using the INNER JOIN clause.
SELECT
    customer.customer_id,
    customer.first_name customer_first_name,
    customer.last_name customer_last_name,
    customer.email,
    staff.first_name staff_first_name,
    staff.last_name staff_last_name,
    amount,
    payment_date
FROM
    customer
INNER JOIN payment ON payment.customer_id = customer.customer_id
INNER JOIN staff ON payment.staff_id = staff.staff_id;
Output:
postgreSQL-joins
Misc
Misc
Misc
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Creating a Pandas DataFrame

22 Jun, 2021
In the real world, a Pandas DataFrame will be created by loading the datasets from existing storage, storage can be SQL Database, CSV file, and Excel file. Pandas DataFrame can be created from the lists, dictionary, and from a list of dictionary etc.  
A Dataframe is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. In dataframe datasets arrange in rows and columns, we can store any number of datasets in a dataframe. We can perform many operations on these datasets like arithmetic operation, columns/rows selection, columns/rows addition etc.  
Pandas DataFrame can be created in multiple ways. Let’s discuss different ways to create a DataFrame one by one.Creating an empty dataframe : A basic DataFrame, which can be created is an Empty Dataframe. An Empty Dataframe is created just by calling a dataframe constructor.  
Python3
# import pandas as pdimport pandas as pd # Calling DataFrame constructordf = pd.DataFrame() print(df)
Output :  
Empty DataFrame
Columns: []
Index: []
  Creating a dataframe using List: DataFrame can be created using a single list or a list of lists.  
Python3
# import pandas as pdimport pandas as pd # list of stringslst = ['Geeks', 'For', 'Geeks', 'is',            'portal', 'for', 'Geeks'] # Calling DataFrame constructor on listdf = pd.DataFrame(lst)print(df)
Output:  
  Creating DataFrame from dict of ndarray/lists: To create DataFrame from dict of narray/list, all the narray must be of same length. If index is passed then the length index should be equal to the length of arrays. If no index is passed, then by default, index will be range(n) where n is the array length.  
Python3
# Python code demonstrate creating# DataFrame from dict narray / lists# By default addresses. import pandas as pd # initialise data of lists.data = {'Name':['Tom', 'nick', 'krish', 'jack'], 'Age':[20, 21, 19, 18]} # Create DataFramedf = pd.DataFrame(data) # Print the output.print(df)
Output:  
  Create pandas dataframe from lists using dictionary: Creating pandas data-frame from lists using dictionary can be achieved in different ways. We can create pandas dataframe from lists using dictionary using pandas.DataFrame. With this method in Pandas we can transform a dictionary of list to a dataframe. 
Python3
# importing pandas as pdimport pandas as pd # dictionary of listsdict = {'name':["aparna", "pankaj", "sudhir", "Geeku"],        'degree': ["MBA", "BCA", "M.Tech", "MBA"],        'score':[90, 40, 80, 98]} df = pd.DataFrame(dict) print(df)
Output:  
 Multiple ways of creating dataframe :  
Different ways to create Pandas Dataframe
Create pandas dataframe from lists using zip
Create a Pandas DataFrame from List of Dicts
Create a Pandas Dataframe from a dict of equal length lists
Creating a dataframe using List
Create pandas dataframe from lists using dictionary
 
anikaseth98
Python pandas-dataFrame
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Int16.CompareTo() Method in C#

The Int16.CompareTo() method in C# is used to compare this instance to a specified object or another Int16 instance and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object or the other Int16 instance.
Following is the syntax −
public int CompareTo (short val);
public int CompareTo (object val);
Above, in the 1st syntax, the value val is an integer to compare, whereas Val in the 2nd syntax is an object to compare.
The return value is less than zero if the current instance is less than the value. It’s zero, if the current instance is equal to value, whereas return value is more than zero if the current instance is more than value.
Let us now see an example to implement the Int16.CompareTo() method −
using System;
public class Demo {
   public static void Main(){
      short val1 = 20;
      short val2 = 18;
      Console.WriteLine("Value 1 = "+val1);
      Console.WriteLine("Value 2 = "+val2);
      Console.WriteLine("Return value (comparison) = "+val1.CompareTo(val2));
   }
}
This will produce the following output −
Value 1 = 20
Value 2 = 18
Return value (comparison) = 2
Let us now see another example to implement the Int16.CompareTo() method −
using System;
public class Demo {
   public static void Main(){
      short val1 = 10;
      short val2 = 10;
      Console.WriteLine("Value 1 = "+val1);
      Console.WriteLine("Value 2 = "+val2);
      Console.WriteLine("Return value (comparison) = "+val1.CompareTo(val2));
   }
}
This will produce the following output −
Value 1 = 10
Value 2 = 10
Return value (comparison) = 0
How to get full path of current file's directory in Python?

To know the complete path to current file use the os module.
>>> import os
>>> print(os.path.realpath(__file__))
/home/ayush/qna/path.py
Find Harmonic mean using Arithmetic mean and Geometric mean using C++.

Here we will see how to get the Harmonic mean using the arithmetic mean and the geometric mean. The formula for these three means are like below −
Arithmetic Mean − (a + b)/2
Geometric Mean − ⟮a∗b⟯
Harmonic Mean − 2ab/(a+b)
The Harmonic Mean can be expressed using arithmetic mean and geometric mean using this formula −
HM=GM2AM
 Live Demo
#include <iostream>
#include <cmath>
using namespace std;
double getHarmonicMean(int a, int b) {
   double AM, GM, HM;
   AM = (a + b) / 2;
   GM = sqrt(a * b);
   HM = (GM * GM) / AM;
   return HM;
}
int main() {
   int a = 5, b = 15;
   double res = getHarmonicMean(a, b);
   cout << "Harmonic Mean of " << a << " and " << b << " is " << res ;
}
Harmonic Mean of 5 and 15 is 7.5
How to return table from MySQL function?

You cannot return table from MySQL function. The function can return string, integer, char etc. To return table from MySQL, use stored procedure, not function.
Let us first create a table −
mysql> create table DemoTable696 (
   Id int,
   Name varchar(100)
);
Query OK, 0 rows affected (0.77 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable696 values(100,'Mike');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable696 values(101,'Sam');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable696 values(102,'Adam');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable696 values(103,'Carol');
Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable696;
This will produce the following output -
+------+-------+
| Id   | Name  |
+------+-------+
| 100  | Mike  |
| 101  | Sam   |
| 102  | Adam  |
| 103  | Carol |
+------+-------+
4 rows in set (0.00 sec)
Following is the query to return table from MySQL.
The stored procedure is as follows −
mysql> DELIMITER //
mysql> CREATE PROCEDURE getResultSet(studId int )
   BEGIN
      select *from DemoTable696 where Id=studId;
   END
   //
Query OK, 0 rows affected (0.14 sec)
mysql> DELIMITER ;
Now you can call the stored procedure using call command −
mysql> call getResultSet(103);
This will produce the following output -
+------+-------+
| Id   | Name  |
+------+-------+
| 103  | Carol |
+------+-------+
1 row in set (0.00 sec)
Query OK, 0 rows affected (0.01 sec)
How can we use a MySQL subquery with FROM clause?

Subqueries can work well in a SELECT statement FROM clause. Following is the syntax for the same −
SELECT ... FROM(subquery) [AS] name ...
To make it understand we are using the following data from table ‘cars’ −
mysql> Select * from Cars;
+------+--------------+---------+
| ID   | Name         | Price   |
+------+--------------+---------+
| 1    | Nexa         | 750000  |
| 2    | Maruti Swift | 450000  |
| 3    | BMW          | 4450000 |
| 4    | VOLVO        | 2250000 |
| 5    | Alto         | 250000  |
| 6    | Skoda        | 1250000 |
| 7    | Toyota       | 2400000 |
| 8    | Ford         | 1100000 |
+------+--------------+---------+
8 rows in set (0.02 sec)
Now in the following query, we are using the subquery with FROM clause −
mysql> Select Id_New, Name_New, Price_New FROM (SELECT Id as Id_New, Name as Name_New, Price as Price_New FROM Cars) as c Where Price_New > 500000;
+--------+----------+-----------+
| Id_New | Name_New | Price_New |
+--------+----------+-----------+
| 1      | Nexa     | 750000    |
| 3      | BMW      | 4450000   |
| 4      | VOLVO    | 2250000   |
| 6      | Skoda    | 1250000   |
| 7      | Toyota   | 2400000   |
| 8      | Ford     | 1100000   |
+--------+----------+-----------+
6 rows in set (0.00 sec)
DAX Aggregation SELECTCOLUMNS function

Adds calculated columns to the given table or table expression. DAX SELECTCOLUMNS function is new in Excel 2016.
SELECTCOLUMNS (<table>, <name>, <scalar_expression>, [<name>, <scalar_expression>] ...) 

table
Table or a DAX expression that returns a table.
name
The name given to the column, enclosed in double quotes.
scalar_expression
DAX expression that returns a scalar value like a column reference, integer or string value.
A table with the same number of rows as the table specified as the first parameter. The returned table has one column for each pair of name and scalar_expression parameters. Each scalar_expression is evaluated in the context of a row from the specified table parameter.
SELECTCOLUMNS is similar to ADDCOLUMNS, and has the same behavior except that instead of starting with the table specified, SELECTCOLUMNS start with an empty table before adding columns.
= SELECTCOLUMNS ( 
   Products,"Product-NoOfUnits",Products[Product]&" - "&Products[Units Sold])

    53 Lectures 
     5.5 hours 

 Abhay Gadiya

    24 Lectures 
     2 hours 

 Randy Minder

    26 Lectures 
     4.5 hours 

 Randy Minder
 Print
 Add Notes
 Bookmark this page
shutdown - Unix, Linux Command

If shutdown is called with a delay, it creates the advisory file
/etc/nologin which causes programs such as login(1) to not allow new user
logins. Shutdown removes this file if it is stopped before it
can signal init (i.e. it is cancelled or something goes wrong).
It also removes it before calling init to change the runlevel.


The -f flag means ‘reboot fast’.  This only creates an advisory
file /fastboot which can be tested by the system when it comes
up again.  The boot rc file can test if this file is present, and decide not
to run fsck(1) since the system has been shut down in the proper way. 
After that, the boot process should remove /fastboot.


The -F flag means ‘force fsck’.  This only creates an advisory
file /forcefsck which can be tested by the system when it comes
up again.  The boot rc file can test if this file is present, and decide
to run fsck(1) with a special ‘force’ flag so that even properly
unmounted filesystems get checked.
After that, the boot process should remove /forcefsck.


The -n flag causes shutdown not to call init,
but to kill all running processes itself.
shutdown will then turn off quota, accounting, and swapping
and unmount all filesystems.



shutdown: no authorized users logged in


to the (physical) system console. The format of /etc/shutdown.allow
is one user name per line. Empty lines and comment lines (prefixed by a
#) are allowed. Currently there is a limit of 32 users in this file.


Note that if /etc/shutdown.allow is not present, the -a
argument is ignored.

/fastboot
/etc/inittab
/etc/init.d/halt
/etc/init.d/reboot
/etc/shutdown.allow


Init can only capture CTRL-ALT-DEL and start shutdown in console mode.
If the system is running the X window System, the X server processes
all key strokes. Some X11 environments make it possible to capture
CTRL-ALT-DEL, but what exactly is done with that event depends on
that environment.


Shutdown wasn’t designed to be run setuid. /etc/shutdown.allow is
not used to find out who is executing shutdown, it ONLY checks who
is currently logged in on (one of the) console(s).

fsck (8)
fsck (8)
init (8)
init (8)
halt (8)
halt (8)
poweroff (8)
poweroff (8)
reboot (8)
reboot (8)

Advertisements


    129 Lectures 
     23 hours 

 Eduonix Learning Solutions

    5 Lectures 
     4.5 hours 

 Frahaan Hussain

    35 Lectures 
     2 hours 

 Pradeep D

    41 Lectures 
     2.5 hours 

 Musab Zayadneh

    46 Lectures 
     4 hours 

 GUHARAJANM

    6 Lectures 
     4 hours 

 Uplatz
 Print
 Add Notes
 Bookmark this page
Java 9 - REPL (JShell)

REPL stands for Read-Eval-Print Loop. With JShell, java has REPL capability. Using REPL, we can code and test java based logic without compiling using javac and see the result of calculations directly.
Open command prompt and type jshell.
$ jshell
|  Welcome to JShell -- Version 9-ea
|  For an introduction type: /help intro
jshell>

Type /help once jshell command starts running.
jshell> /help
|  Type a Java language expression, statement, or declaration.
|  Or type one of the following commands:
|  /list [<name or id>|-all|-start]
|  list the source you have typed
|  /edit <name or id>
|  edit a source entry referenced by name or id
|  /drop <name or id>
|  delete a source entry referenced by name or id
|  /save [-all|-history|-start] <file>
|  Save snippet source to a file.
|  /open <file>
|  open a file as source input
|  /vars [<name or id>|-all|-start]
|  list the declared variables and their values
|  /methods [<name or id>|-all|-start]
|  list the declared methods and their signatures
|  /types [<name or id>|-all|-start]
|  list the declared types
|  /imports 
|  list the imported items

Type /imports once jshell command starts running and see the used imports.
jshell> /imports
|    import java.io.*
|    import java.math.*
|    import java.net.*
|    import java.nio.file.*
|    import java.util.*
|    import java.util.concurrent.*
|    import java.util.function.*
|    import java.util.prefs.*
|    import java.util.regex.*
|    import java.util.stream.*
jshell>

Try running simple calculations in JShell.
jshell> 3+1
$1 ==> 4
jshell> 13%7
$2 ==> 6
jshell> $2
$2 ==> 6
jshell>

Create a function doubled() to take int and return its doubled value.
jshell> int doubled(int i){ return i*2;}
|  created method doubled(int)
jshell> doubled(6)
$3 ==> 12
jshell>

Type /exit.
jshell> /exit
| Goodbye


    16 Lectures 
     2 hours 

 Malhar Lathkar

    19 Lectures 
     5 hours 

 Malhar Lathkar

    25 Lectures 
     2.5 hours 

 Anadi Sharma

    126 Lectures 
     7 hours 

  Tushar Kale

    119 Lectures 
     17.5 hours 

 Monica Mittal

    76 Lectures 
     7 hours 

 Arnab Chakraborty
 Print
 Add Notes
 Bookmark this page
C program to calculate distance between three points in 3D

Given with the 3-D plane and hence three coordinates and the task is to find the distance between the given points and display the result.
In a three dimension plane there are three axis that are x-axis with its coordinates as (x1, y1, z1), y-axis with its coordinates as (x2, y2, z2) and z-axis with its coordinates as (x3, y3, z). To calculate the distance between them there is a direct formula which is given below
⟮x2−x1⟯2+⟮y2−y1⟯2+⟮z2−z1⟯2
Given below is the diagram representing three different axis and their coordinates
Approach used below is as follows −
Input the coordinates as (x1, y1, z1), (x2, y2, z2) and (x3, y3, z3)
Apply the formula to compute the difference between these points
Print the distance
Start
Step 1-> declare function to calculate distance between three point
   void three_dis(float x1, float y1, float z1, float x2, float y2, float z2)
      set float dis = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) + pow(z2 - z1, 2) * 1.0)
      print dis
step 2-> In main()
   Set float x1 = 4
   Set float y1 = 9
   Set float z1 = -3
   Set float x2 = 5
   Set float y2 = 10
   Set float z2 = 9
   Call three_dis(x1, y1, z1, x2, y2, z2)
Stop
#include <stdio.h>
#include<math.h>
//function to find distance bewteen 3 point
void three_dis(float x1, float y1, float z1, float x2, float y2, float z2) {
   float dis = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2) + pow(z2 - z1, 2) * 1.0);
   printf("Distance between 3 points are : %f", dis);
   return;
}
int main() {
   float x1 = 4;
   float y1 = 9;
   float z1 = -3;
   float x2 = 5;
   float y2 = 10;
   float z2 = 9;
   three_dis(x1, y1, z1, x2, y2, z2);
   return 0;
}
IF WE RUN THE ABOVE CODE IT WILL GENERATE FOLLOWING OUTPUT
Distance between 3 points are : 12.083046
VB.Net - Arithmetic Operators

Following table shows all the arithmetic operators supported by VB.Net. Assume variable A holds 2 and variable B holds 7, then −
Try the following example to understand all the arithmetic operators available in VB.Net −
Module operators
   Sub Main()
      Dim a As Integer = 21
      Dim b As Integer = 10
      Dim p As Integer = 2
      Dim c As Integer
      Dim d As Single
      
      c = a + b
      Console.WriteLine("Line 1 - Value of c is {0}", c)
      
      c = a - b
      Console.WriteLine("Line 2 - Value of c is {0}", c)
      
      c = a * b
      Console.WriteLine("Line 3 - Value of c is {0}", c)
      
      d = a / b
      Console.WriteLine("Line 4 - Value of d is {0}", d)
      
      c = a \ b
      Console.WriteLine("Line 5 - Value of c is {0}", c)
      
      c = a Mod b
      Console.WriteLine("Line 6 - Value of c is {0}", c)
      
      c = b ^ p
      Console.WriteLine("Line 7 - Value of c is {0}", c)
      Console.ReadLine()
   End Sub
End Module
When the above code is compiled and executed, it produces the following result −
Line 1 - Value of c is 31
Line 2 - Value of c is 11
Line 3 - Value of c is 210
Line 4 - Value of d is 2.1
Line 5 - Value of c is 2
Line 6 - Value of c is 1
Line 7 - Value of c is 100


    63 Lectures 
     4 hours 

 Frahaan Hussain

    103 Lectures 
     12 hours 

 Arnold Higuit

    60 Lectures 
     9.5 hours 

 Arnold Higuit

    97 Lectures 
     9 hours 

 Arnold Higuit
 Print
 Add Notes
 Bookmark this page
How to use hide() method on button click using jQuery ?

10 Aug, 2021
jQuery has a lot of handy methods to get the work done easily. In this article, we will discuss one of them which is the hide() method. We can use this method for various purposes on our webpage and get an efficient result.
The very first step will be creating an HTML file and link the jQuery library file via CDN.
jQuery CDN Link: 
<script src=”https://code.jquery.com/jquery-3.6.0.min.js” integrity=”sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=” crossorigin=”anonymous”></script>
 
jQuery hide() method: This method is used for hiding the web elements.
Example 1: Create an HTML file and add the following code to it.
HTML
<!DOCTYPE html><html lang="en">  <head>    <!-- jQuery CDN link. -->    <script      src="https://code.jquery.com/jquery-3.6.0.min.js"      integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="      crossorigin="anonymous">    </script>  </head>    <body>    <button id="btn">Hide</button>      <p><b>GeeksforGeeks</b></p>      <!-- Using hide() method to hide <p/> element. -->    <script>      $(document).ready(function () {        $("#btn").click(function () {          $("p").hide();        });      });    </script>  </body></html>
Output:
Hide p element
Example 2: We can use the hide() method to hide an image.
HTML
<!DOCTYPE html><html lang="en">  <head>    <!-- jQuery CDN link. -->    <script      src="https://code.jquery.com/jquery-3.6.0.min.js"      integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="      crossorigin="anonymous">    </script>  </head>    <body>    <img      id="image"      src="https://media.geeksforgeeks.org/wp-content/uploads/20210805112556/gfgImage.png"      alt=""/>    <button id="btn"             style="padding-left: 10px;             margin-left: 30px">       Hide    </button>    <!-- Using hide() method to hide an image.-->    <script>      $(document).ready(function () {        $("#btn").click(function () {          $("#image").hide();        });      });    </script>  </body></html>
Output:
Hide Image
Example 3: The hide() method can also be used to hide any geometrical shape. 
HTML
<!DOCTYPE html><html lang="en">  <head>    <!-- jQuery CDN link. -->    <script      src="https://code.jquery.com/jquery-3.6.0.min.js"      integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4="      crossorigin="anonymous">    </script>  </head>        <body>    <div id="shape"          style="height:100px; width:100px;                 background-color:green;                 border-radius:00%;margin:10px;">    </div>          <button id="btn" style="margin:10px;">Hide Shape</button>        <!-- Using hide() method to hide a shape. -->    <script>      $(document).ready(function () {        $("#btn").click(function () {          $("#shape").hide();        });      });    </script>  </body></html>
Output:
Hide shape
jQuery-Methods
jQuery-Questions
Picked
HTML
JQuery
Web Technologies
HTML
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
FORMAT() Function in SQL Server

04 Oct, 2021
The FORMAT() function is one of the String Functions, which is used to format the specified value in the given format. 
Syntax : 
FORMAT(value, format, culture)  
Parameter: 
This method accepts three parameters as mentioned above and described below: 
Value: It is the value to do formatting. It should be in support of the data type format. 
Format: It is the required format in which we require the output.
Culture: It is an optional parameter. By default, SQL Server uses the current session language for a default culture. We can provide a specific culture here, but the .Net framework should support it. We get an error message in case of invalid Culture
Returns: It returns a value formatted with the specified format and optional culture.  
Now if we want to Format a Number. then we use the below query:Query:
SELECT FORMAT(25, 'N')
Output :  
Take another example of PERCENTAGE format. Query:
SELECT FORMAT(1, 'P', 'en-US')AS [PERCENTAGE IN US FORMAT], 
    FORMAT(1, 'P', 'en-IN') AS [PERCENTAGE IN INDIA FORMAT];
Output : 
Example of DATE format. Query:
DECLARE @d DATETIME = GETDATE();  
SELECT FORMAT( @d, 'dd/MM/yyyy', 'en-US' ) AS 'DateTime Result'
Output :  
In this example, we will format the current time with AM or PM. Query:
SELECT FORMAT(SYSDATETIME(), N'hh:mm tt');
Output :  
In this example, we change the CURRENCY format. Query:
SELECT 
    FORMAT(1, 'C', 'in-IN') AS 'INDIA', 
    FORMAT(1, 'C', 'ch-CH') AS 'CHINA', 
    FORMAT(1, 'C', 'sw-SW') AS 'SWITZERLAND', 
    FORMAT(1, 'C', 'us-US') AS 'USA';
Output :  
 
varshachoudhary
DBMS-SQL
SQL-Server
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
CTE in SQL
SQL Trigger | Student Database
How to Update Multiple Columns in Single Update Statement in SQL?
SQL | Views
Difference between DELETE, DROP and TRUNCATE
Difference between SQL and NoSQL
Window functions in SQL
MySQL | Group_CONCAT() Function
SQL | GROUP BY
Difference between DDL and DML in DBMS
Lodash_.shuffle() Method

01 Oct, 2020
The _.shuffle() method shuffles of collection by returning the new array.
Syntax: 
_.shuffle(collection)

Parameters: This method accepts a single parameter as mentioned above and described below:
collection: This parameter holds the collection to inspect.
Return Value: This method returns the new array after shuffling.
Example 1: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.
Javascript
// Requiring the lodash library const _ = require("lodash");        // Original array and use _.shuffle() methodvar gfg = _.shuffle([1, 2, 3,4]);  // Printing the output console.log(gfg);
Output :
[4, 1, 3, 2]

Example 2 :
Javascript
// Requiring the lodash library const _ = require("lodash");        // Original array and use _.shuffle() methodvar gfg = _.shuffle(["g", "e", "e", "k", "s", "f", "o",                     "r", "g", "e", "e", "k", "s"]);  // Printing the output console.log(gfg);
Output :
["o", "e", "k", "s", "e", "e", "s",
 "g", "r", "e", "g", "f", "k"]

Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.
JavaScript-Lodash
JavaScript
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Difference between var, let and const keywords in JavaScript
Remove elements from a JavaScript Array
Difference Between PUT and PATCH Request
Roadmap to Learn JavaScript For Beginners
JavaScript | Promises
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
Python – Network Interface

24 Nov, 2020
Network interface is nothing but interconnection between two hardware equipment or protocol layers in a computer network. A network interface usually has some form of the network address. It is generally a network interface card that does not have any physical existence. It can be implemented in a software interface.
It is difficult to keep track of interface names, status, or any other information related to them when we have multiple interfaces. For this purpose, Python has a library called netifaces which can list the interfaces and their status. The netifaces module is a portable third-party library which enumerates the network interfaces on the local machine. Below is a simple example using python netifaces module giving details of interfaces and their status.
Installation:
pip install netifaces
Implementation of netifaces module for various network operations:
Python3
# Import librariesimport netifaces  # Showing gateway listnetifaces.gateways()  # Getting interfacesinterfaces = netifaces.interfaces()  # Showing interfacesfor interface in interfaces:    print(interface)  # Getting interface infoprint(netifaces.ifaddresses(str(interfaces[0])))  # Getting interface statusaddrs = netifaces.ifaddresses(str(interfaces[0]))print(addrs[netifaces.AF_INET])print(addrs[netifaces.AF_LINK])
Output:
Python-Networking
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 ?
Python Classes and Objects
Python OOPs Concepts
Introduction To PYTHON
How to drop one or multiple columns in Pandas Dataframe
Check if element exists in list in Python
Python | os.path.join() method
How To Convert Python Dictionary To JSON?
Python | Get unique values from a list
Defaultdict in Python
Tabs With Dropdown Bootstrap Example

To create tabs with Bootstrap, use the .nav and .nav-tabs classes. With that use the .dropdown-menu class.
Start with a basic unordered list with the base class of .nav
 Add the class .nav-tabs.
Now add an unordered list with a .dropdown-menu class.
You can try to run the following code to create tabs with drop-down −
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">
         <li class = "active"><a href = "#">Home</a></li>
         <li><a href = "#">About</a></li>
         <li class = "dropdown">
            <a class = "dropdown-toggle" data-toggle = "dropdown" href = "#">
               Products
               <span class = "caret"></span>
            </a>
            <ul class = "dropdown-menu">
               <li><a href = "#">Online Compiler</a></li>
               <li><a href = "#">Image Editor</a></li>
               <li><a href = "#">Document Viewer</a></li>
            </ul>
         </li>
         <li><a href = "#">Services</a></li>
         <li><a href = "#">Contact</a></li>
      </ul>
   </body>
</html>
Convert vowels from upper to lower or lower to upper using C program

An array of characters is called a string.
Following is the declaration for an array −
char stringname [size];
For example − char a[50]; string of length 50 characters
Using single character constant −
char a[10] = { ‘H’, ‘e’, ‘l’, ‘l’, ‘o’ ,‘\0’}
Using string constants −
char a[10] = "Hello":;
There is a control string "%s" used for accessing the string till it encounters ‘\0’.
The logic used to convert vowels from upper to lower or lower to upper is −
for(i=0;string[i]!='\0';i++){
   if(string[i]=='a'||string[i]=='e'||string[i]=='i'||string[i]=='o'||string[i]=='u'){
      string[i]=toupper(string[i]);
   }
}
printf("The result string with converted vowels is : ");
puts(string);
Following is the C program using conversion functions to convert an Upper case string to Lower case string −
#include<stdio.h>
#include<ctype.h>
void main(){
   //Declaring variable for For loop (to read each position of alphabet) and string//
   int i;
   char string[40];
   //Reading string//
   printf("Enter the string : ");
   gets(string);
   //For loop to read each alphabet//
   for(i=0;string[i]!='\0';i++){
      if(string[i]=='a'||string[i]=='e'||string[i]=='i'||string[i]=='o'||string[i]=='u'){
         string[i]=toupper(string[i]);
      }
   }
   printf("The result string with converted vowels is : ");
   puts(string);
}
When the above program is executed, it produces the following result −
Run 1:
Enter the string : TutoRialsPoint
The result string with converted vowels is : TUtORIAlsPOInt
Run 2:
Enter the string : c programming
The result string with converted vowels is : c programming
list push_back() function in C++ STL

13 Jun, 2022
The list:push_back() function in C++ STL is used to add a new element to an existing list container. It takes the element to be added as a parameter and adds it to the list container.Syntax:  
list_name.push_back(value) 
Parameters: This function accepts a single parameter which is mandatory value. This refers to the element needed to be added to the list, list_name.Return Value: The return type of this function is void and it does not returns any value. Below program illustrates the list::push_back() function.  
CPP
// CPP program to illustrate the// list::push_back() function#include <bits/stdc++.h>using namespace std; int main(){ // Initialization of list list<int> demo_list;  // initial size of list cout << "Initial Size of the list: "  << demo_list.size() << endl;  // Adding elements to the list // using push_back function demo_list.push_back(10); demo_list.push_back(20); demo_list.push_back(30);  // Size of list after adding // some elements cout << "Size of list after adding three "  << "elements: " << demo_list.size();  return 0;}
Initial Size of the list: 0
Size of list after adding three elements: 3
 
Time Complexity: O(1)
Auxiliary Space: O(1)
simranarora5sos
utkarshgupta110092
CPP-Functions
STL
C++
STL
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Bitwise Operators in C/C++
Set in C++ Standard Template Library (STL)
vector erase() and clear() in C++
unordered_map in C++ STL
Inheritance in C++
Substring in C++
C++ Classes and Objects
Sorting a vector in C++
Object Oriented Programming in C++
Priority Queue in C++ Standard Template Library (STL)
Eigenspace and Eigenspectrum Values in a Matrix

15 Jan, 2020
Prerequisites:
Mathematics | Eigen Values and Eigen Vectors
Matrix Multiplication
Null Space and Nullity of a Matrix
For a given matrix A the set of all eigenvectors of A associated with an eigenvalue  spans a subspace, which is called the Eigenspace of A with respect to  and is denoted by . The set of all eigenvalues of A is called Eigenspectrum, or just spectrum, of A.If  is an eigenvalue of A, then the corresponding eigenspace  is the solution space of the homogeneous system of linear equations . Geometrically, the eigenvector corresponding to a non – zero eigenvalue points in a direction that is stretched by the linear mapping. The eigenvalue is the factor by which it is stretched. If the eigenvalue is negative, then the direction of the stretching is flipped.
Below are some useful properties of eigenvalues and eigenvectors in addition to the properties which are already listed in the article Mathematics | Eigen Values and Eigen Vectors.
A matrix A and its transpose  possess the same eigenvalues but not necessarily the same eigenvectors.
The eigenspace  is the null space of  since      
Note: ker stands for Kernel which is another name for null space.
Computing Eigenvalues, Eigenvectors, and Eigenspaces:
Consider given 2 X 2 matrix:


Step 1: Characteristic polynomial and Eigenvalues.
The characteristic polynomial is given by 
det() 





After we factorize the characteristic polynomial, we will get



which gives eigenvalues as  and 

Step 2: Eigenvectors and Eigenspaces
We find the eigenvectors that correspond to these eigenvalues by looking 
at vectors x such that 
 


For  we obtain



After solving the above homogeneous system of equations,
we will obtain a solution space



This eigenspace is one dimensional as it possesses a single basis vector.
Similarly, we find eigenvector for  by solving
the homogeneous system of equations



This means any vector , where  
such as  is an eigenvector with 
eigenvalue 2. This means eigenspace is given as 


The two eigenspaces  and  in the above example are one dimensional as they are each spanned by a single vector. However, in other cases, we may have multiple identical eigenvectors and the eigenspaces may have more than one dimension.
Technical Scripter 2019
Machine Learning
Mathematical
Technical Scripter
Mathematical
Machine Learning
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.