code-rag-bench/online-tutorials huggingface dataset:
SAS - One Way Anova

ANOVA stands for Analysis of Variance. In SAS it is done using PROC ANOVA. It performs analysis of data from a wide variety of experimental designs. In this process, a continuous response variable, known as a dependent variable, is measured under experimental conditions identified by classification variables, known as independent variables. The variation in the response is assumed to be due to effects in the classification, with random error accounting for the remaining variation.
The basic syntax for applying PROC ANOVA in SAS is −
PROC ANOVA dataset ;
CLASS Variable;
MODEL Variable1 = variable2 ;
MEANS ;
Following is the description of the parameters used −
dataset is the name of the dataset.
dataset is the name of the dataset.
CLASS gives the variables the variable used as classification variable.
CLASS gives the variables the variable used as classification variable.
MODEL defines the model to be fit using certain variables from the dataset.
MODEL defines the model to be fit using certain variables from the dataset.
Variable_1 and Variable_2 are the variable names of the dataset used in analysis.
Variable_1 and Variable_2 are the variable names of the dataset used in analysis.
MEANS defines the type of computation and comparison of means.
MEANS defines the type of computation and comparison of means.
Let us now understand the concept of applying ANOVA in SAS.
Lets consider the dataset SASHELP.CARS. Here we study the dependence between the variables car type and their horsepower. As the car type is a variable with categorical values, we take it as class variable and use both these variables in the MODEL.
PROC ANOVA DATA = SASHELPS.CARS;
CLASS type;
MODEL horsepower = type;
RUN;
When the above code is executed, we get the following result −
Let us now understand the concept of applying ANOVA with MEANS in SAS.
We can also extend the model by applying the MEANS statement in which we use Turkey's Studentized method to compare the mean values of various car types.The category of car types are listed with the mean value of horsepower in each category along with some additional values like error mean square etc.
PROC ANOVA DATA = SASHELPS.CARS;
CLASS type;
MODEL horsepower = type;
MEANS type / tukey lines;
RUN;
When the above code is executed, we get the following result −

    50 Lectures 
     5.5 hours 

 Code And Create

    124 Lectures 
     30 hours 

 Juan Galvan

    162 Lectures 
     31.5 hours 

 Yossef Ayman Zedan

    35 Lectures 
     2.5 hours 

 Ermin Dedic

    167 Lectures 
     45.5 hours 

 Muslim Helalee
 Print
 Add Notes
 Bookmark this page
mysql_secure_installation - Improve MySQL Installation Security

Let us understand the MySQL installation related program mysql_secure_installation −
This program enables the user to improve the security of their MySQL installation in the below mentioned ways:
This program enables the user to improve the security of their MySQL installation in the below mentioned ways:
The user can set a password for root accounts.
The user can set a password for root accounts.
The user can remove root accounts which are accessible from outside the local host.
The user can remove root accounts which are accessible from outside the local host.
The user can remove anonymous-user accounts.
The user can remove anonymous-user accounts.
The user can remove the test database which, by default, can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.
The user can remove the test database which, by default, can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.
The mysql_secure_installation helps the user to implement security recommendations.
The mysql_secure_installation helps the user to implement security recommendations.
Normal usage is to connect to the local MySQL server, then invoke mysql_secure_installation without arguments. The example has been shown below −
shell> mysql_secure_installation
When the above statement is executed, mysql_secure_installation prompts the user to determine which actions need to be performed.
Most of the usual MySQL client options like --host and --port can be used on the command line and in the option files. Let us take an example −
To connect to the local server over IPv6 using port 3307, the below command can be used −
shell> mysql_secure_installation --host=::1 --port=3307
The mysql_secure_installation supports the below options and can be specified on the command line or in the [mysql_secure_installation] and [client] groups of an option file.
--host=host_name, -h host_name
It helps connect to the MySQL server on the given host.
--no-defaults
It doesn’t read any option files. If program startup fails due to reading unknown options from an option file, --no-defaults option can be used to prevent them from being read.
--help, -?
It helps display a help message and exit.
--use-default
It is used to execute noninteractively. This option can be used for unattended installation operations.
--user=user_name, -u user_name
It is the user name of the MySQL account to be used to connect to the server.
C++ Program to Represent Graph Using Incidence Matrix

The incidence matrix of a graph is another representation of a graph to store into the memory. This matrix is not a square matrix. The order of the incidence matrix is V x E. Where V is the number of vertices and E is the number of edges in the graph.
In each row of this matrix we are placing the vertices, and in each column the edges are placed. In this representation for an edge e {u, v}, it will be marked by 1 for the place u and v of column e.
The incidence matrix representation takes O(Vx E) amount of space while it is computed. For complete graph the number of edges will be V(V-1)/2. So incidence matrix takes larger space in memory.
The incidence matrix representation takes O(Vx E) amount of space while it is computed. For complete graph the number of edges will be V(V-1)/2. So incidence matrix takes larger space in memory.
Input
Output
Input − The u and v of an edge {u,v}
Output − Incidence matrix of the graph G
At first, there are edge count ed_cnt is 0 for the incidence matrix.
Begin
   ed_cnt := ed_cnt + 1
   inc_matrix[u, ed_cnt] := 1
   inc_matrix[v, ed_cnt] := 1
End
 Live Demo
#include<iostream>
using namespace std;
int inc_arr[20][20]; //initial array to hold incidence matrix
int ed_no = 0;
void displayMatrix(int v, int e) {
   int i, j;
   for(i = 0; i < v; i++) {
      for(j = 0; j < e; j++) {
         cout << inc_arr[i][j] << " ";
      }
      cout << endl;
   }
}
void add_edge(int u, int v) { //function to add edge into the matrix with edge number
   inc_arr[u][ed_no] = 1;
   inc_arr[v][ed_no] = 1;
   ed_no++; //increase the edge number
}
main(int argc, char* argv[]) {
   int v = 6; //there are 6 vertices in the graph
   int e = 9; //there are 9 edges in the graph
   add_edge(0, 4);
   add_edge(0, 3);
   add_edge(1, 2);
   add_edge(1, 4);
   add_edge(1, 5);
   add_edge(2, 3);
   add_edge(2, 5);
   add_edge(5, 3);
   add_edge(5, 4);
   displayMatrix(v, e);
}
1 1 0 0 0 0 0 0 0
0 0 1 1 1 0 0 0 0
0 0 1 0 0 1 1 0 0
0 1 0 0 0 1 0 1 0
1 0 0 1 0 0 0 0 1
0 0 0 0 1 0 1 1 1
How to use sizeof() operator to find the size of a data type or a variable in C#

The sizeof() datatype returns the size of a data type. Let’s say you need to find the size of int datatype −
sizeof(int);
For double datatype
sizeof(double);
Let us see the complete example to find the size of various datatypes −
 Live Demo
using System;

namespace Demo {

   class Program {

      static void Main(string[] args) {

         Console.WriteLine("The size of int is {0}", sizeof(int));
         Console.WriteLine("The size of int is {0}", sizeof(char));
         Console.WriteLine("The size of short is {0}", sizeof(short));
         Console.WriteLine("The size of long is {0}", sizeof(long));
         Console.WriteLine("The size of double is {0}", sizeof(double));

         Console.ReadLine();
      }
   }
}
The size of int is 4
The size of int is 2
The size of short is 2
The size of long is 8
The size of double is 8
zlib.decompress(s) in Python

06 Mar, 2020
With the help of zlib.decompress(s) method, we can decompress the compressed bytes of string into original string by using zlib.decompress(s) method.
Syntax : zlib.decompress(string)Return : Return decompressed string.
Example #1 :In this example we can see that by using zlib.decompress(s) method, we are able to decompress the compressed string in the byte format of string by using this method.
# import zlib and decompressimport zlib    s = b'This is GFG author, and final year student.'   # using zlib.compress(s) methodt = zlib.compress(s)print("Compressed String")print(t)  print("\nDecompressed String")print(zlib.decompress(t))
Output :
Compressed Stringb’x\x9c\x0b\xc9\xc8,V\x00′′w7w\x85\xc4\xd2\x92\x8c\xfc”\x1d\x85\xc4\xbc\x14\x85\xb4\xcc\xbc\xc4\x1c\x85\xca\xd4\xc4′′\x85\xe2\x92\xd2\x94\xd4\xbc\x12=\x00A\xc9\x0f\x0b’
Decompressed Stringb’This is GFG author, and final year student.’
Example #2 :
# import zlib and decompressimport zlib    s = b'GeeksForGeeks@12345678'   # using zlib.compress(s) methodt = zlib.compress(s)print("Compressed String")print(t)  print("\nDecompressed String")print(zlib.decompress(t))
Output :
Compressed Stringb’x\x9csOM\xcd.v\xcb/r\x07\xd1\x0e\x86F\xc6&\xa6f\xe6\x16\x00X\xf6\x06\xea’
Decompressed Stringb’GeeksForGeeks@12345678′
Python-Miscellaneous
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Apache Solr - On Windows Environment

In this chapter, we will discuss how to set up Solr in Windows environment. To install Solr on your Windows system, you need to follow the steps given below −
Visit the homepage of Apache Solr and click the download button.
Visit the homepage of Apache Solr and click the download button.
Select one of the mirrors to get an index of Apache Solr. From there download the file named Solr-6.2.0.zip.
Select one of the mirrors to get an index of Apache Solr. From there download the file named Solr-6.2.0.zip.
Move the file from the downloads folder to the required directory and unzip it.
Move the file from the downloads folder to the required directory and unzip it.
Suppose you downloaded the Solr fie and extracted it in onto the C drive. In such case, you can start Solr as shown in the following screenshot.
To verify the installation, use the following URL in your browser.
http://localhost:8983/
If the installation process is successful, then you will get to see the dashboard of the Apache Solr user interface as shown below.
We can also communicate with Apache Solr using Java libraries; but before accessing Solr using Java API, you need to set the classpath for those libraries.
Set the classpath to Solr libraries in the .bashrc file. Open .bashrc in any of the editors as shown below.
$ gedit ~/.bashrc

Set classpath for Solr libraries (lib folder in HBase) as shown below.
export CLASSPATH = $CLASSPATH://home/hadoop/Solr/lib/*

This is to prevent the “class not found” exception while accessing the HBase using Java API.

    46 Lectures 
     3.5 hours 

 Arnab Chakraborty

    23 Lectures 
     1.5 hours 

 Mukund Kumar Mishra

    16 Lectures 
     1 hours 

 Nilay Mehta

    52 Lectures 
     1.5 hours 

 Bigdata Engineer

    14 Lectures 
     1 hours 

 Bigdata Engineer

    23 Lectures 
     1 hours 

 Bigdata Engineer
 Print
 Add Notes
 Bookmark this page
Type Casting operators in C++

A cast is a special operator that forces one data type to be converted into another. As an operator, a
cast is unary and has the same precedence as any other unary operator.
The most general cast supported by most of the C++ compilers is as follows
(type) expression
Where type is the desired data type. There are other casting operators supported by C++, they are
listed below -
? const_cast<type> (expr) The const_cast operator is used to explicitly override const and/or volatile in a cast. The target type must be the same as the source type except for the alteration of its const or volatile attributes. This type of casting manipulates the const attribute of the passed object, either to be set or removed.
? const_cast<type> (expr) The const_cast operator is used to explicitly override const and/or volatile in a cast. The target type must be the same as the source type except for the alteration of its const or volatile attributes. This type of casting manipulates the const attribute of the passed object, either to be set or removed.
? dynamic_cast<type> (expr) The dynamic_cast performs a runtime cast that verifies the validity of the cast. If the cast cannot be made, the cast fails and the expression evaluates to null. A dynamic_cast performs casts on polymorphic types and can cast a A* pointer into a B* pointer only if the object being pointed to actually is a B object.
? dynamic_cast<type> (expr) The dynamic_cast performs a runtime cast that verifies the validity of the cast. If the cast cannot be made, the cast fails and the expression evaluates to null. A dynamic_cast performs casts on polymorphic types and can cast a A* pointer into a B* pointer only if the object being pointed to actually is a B object.
? reinterpret_cast<type> (expr) The reinterpret_cast operator changes a pointer to any other type of pointer. It also allows casting from pointer to an integer type and vice versa.
? reinterpret_cast<type> (expr) The reinterpret_cast operator changes a pointer to any other type of pointer. It also allows casting from pointer to an integer type and vice versa.
? static_cast<type> (expr) The static_cast operator performs a nonpolymorphic cast. For example, it can be used to cast a base class pointer into a derived class pointer.
? static_cast<type> (expr) The static_cast operator performs a nonpolymorphic cast. For example, it can be used to cast a base class pointer into a derived class pointer.
All of the above-mentioned casting operators will be used while working with classes and objects.
For now, try the following example to understand a simple cast operators available in C++. Copy and
paste the following C++ program in test.cpp file and compile and run this program.
#include <iostream>
using namespace std;
main() {
   double a = 21.09399;
   float b = 10.20;
   int c ;
   c = (int) a;
   cout << "Line 1 - Value of (int)a is :" << c << endl ;
   c = (int) b;
   cout << "Line 2 - Value of (int)b is :" << c << endl ;
   return 0;
}
Line 1 - Value of (int)a is :21
Line 2 - Value of (int)b is :10
How does spring boot connect localhost MySQL

For this, use application.properties −
spring.datasource.username=yourMySQLUserName
spring.datasource.password=yourMySQLPassword
spring.datasource.url=jdbc:mysql://localhost:3306/yoruDatabaseName
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
To understand the above syntax, let us create a table −
mysql> create table demo71
−> (
−> id int,
−> name varchar(20)
−> );
Query OK, 0 rows affected (3.81 sec)
Insert some records into the table with the help of insert command −
mysql> insert into demo71 values(100,'John');
Query OK, 1 row affected (0.13 sec)

mysql> insert into demo71 values(101,'David');
Query OK, 1 row affected (0.49 sec)

mysql> insert into demo71 values(102,'Bob');
Query OK, 1 row affected (0.15 sec)
Display records from the table using select statement −
mysql> select *from demo71;
This will produce the following output −
+------+-------+
| id   | name  |
+------+-------+
| 100  | John  |
| 101  | David |
| 102  | Bob  |
+------+-------+
3 rows in set (0.00 sec)
To verify the above application.properties is working with local MySQL or not, you can write spring boot application to test.
Following is the application.properties file.
Following is the controller class code. The code is as follows −
package com.demo.controller;
import java.util.Iterator;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/table")
public class TableController {
   @Autowired
   EntityManager entityManager;
   @ResponseBody
   @GetMapping("/demo71")
   public String getData() {
      Query sqlQuery= entityManager.createNativeQuery("select name from demo71");
      List<String> result= sqlQuery.getResultList();
      StringBuilder sb=new StringBuilder();
      Iterator itr= result.iterator();
      while(itr.hasNext()) {
         sb.append(itr.next()+" ");
      }
      return sb.toString();
   }
}
Following is the main class. The Java code is as follows −
package com.demo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class JavaMysqlDemoApplication {
   public static void main(String[] args) {
      SpringApplication.run(JavaMysqlDemoApplication.class, args);
   }
}
To run the above, go to the main class and right click and select “Run as Java Application”.After successfully executing, you need to hit below url.
The url is as follows −
http://localhost:8093/table/demo71
This will produce the following output −
How to get text from Selenium element WebElement object?

We can get text from a webelement with Selenium webdriver. The getText() methods obtains the innerText of an element. It fetches the text of an element which is visible along with its sub elements. It ignores the trailing and leading spaces.
First of all we need to identify the element with help of any of the locators like id,
class, name, xpath or css and then apply getText() method on it to get the text content of the element.
Let us get the text of the element About Careers at Tutorials on the page−
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;

public class GetElementText{
   public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
      driver.get("https://www.tutorialspoint.com/about/about_careers.htm");
      // identify element
      WebElement p=driver.findElement(By.xpath("//h1"));
      //getText() to obtain text
      String s= p.getText();
      System.out.println("Text content is : " + s);
      driver.close();
   }
}
Run SQL file in MySQL database from terminal?

To run SQL file in database, you need to use below syntax:
mysql -u yourUserName -p yourDatabaseName < yourFileName.sql
To understand the above syntax, let us open command prompt using windows+R shortcut key.
The snapshot is as follows:
After pressing OK button, you will get a command prompt. The snapshot is as follows:
Now reach the bin directory, the snapshot is as follows:
Here is my file ‘mydb.sql’ which is located in bin directory. The snapshot and content of SQL file is as follows:
Now you can type the above syntax which I have discussed to run SQL file. The snapshot of command is as follows:
Now you can check the table ‘Instructor’ is created in database test or not.
Now switch to database test using USE command. The query is as follows:
mysql>Use test
Now check the table ‘Instructor’ is present in test database. The query is as follows:
Yes, we have Instructor table. Now we need to check the record is present or not which is inserted in the table. The query is as follows:
mysql> select *from instructor;
The following is the output:
+----+-------+
| id | Name  |
+----+-------+
|  1 | John  |
|  2 | Larry |
|  3 | Sam   |
+----+-------+
3 rows in set (0.00 sec)
MATLAB - The Nested Loops

MATLAB allows to use one loop inside another loop. Following section shows few examples to illustrate the concept.
The syntax for a nested for loop statement in MATLAB is as follows −
for m = 1:j
   for n = 1:k
      <statements>;
   end
end

The syntax for a nested while loop statement in MATLAB is as follows −
while <expression1>
   while <expression2>
      <statements>
   end
end

Let us use a nested for loop to display all the prime numbers from 1 to 100. Create a script file and type the following code −
for i = 2:100
   for j = 2:100
      if(~mod(i,j)) 
         break; % if factor found, not prime
      end 
   end
   if(j > (i/j))
      fprintf('%d is prime\n', i);
   end
end
When you run the file, it displays the following result −
2 is prime
3 is prime
5 is prime
7 is prime
11 is prime
13 is prime
17 is prime
19 is prime
23 is prime
29 is prime
31 is prime
37 is prime
41 is prime
43 is prime
47 is prime
53 is prime
59 is prime
61 is prime
67 is prime
71 is prime
73 is prime
79 is prime
83 is prime
89 is prime
97 is prime


    30 Lectures 
     4 hours 

 Nouman Azam

    127 Lectures 
     12 hours 

 Nouman Azam

    17 Lectures 
     3 hours 

 Sanjeev

    37 Lectures 
     5 hours 

 TELCOMA Global

    22 Lectures 
     4 hours 

 TELCOMA Global

    18 Lectures 
     3 hours 

 Phinite Academy
 Print
 Add Notes
 Bookmark this page
JavaScript filter an array of strings, matching case insensitive substring?

Let’s first create array of strings −
let studentDetails =
[
   {studentName: "John Smith"},
   {studentName: "john smith"},
   {studentName: "Carol Taylor"}
];
Now, match case insensitive substring, use the filter() and the concept of toLowerCase() in it.
Following is the code −
let studentDetails =
[
   {studentName: "John Smith"},
   {studentName: "john smith"},
   {studentName: "Carol Taylor"}
];
var searchName="John Smith"
console.log(studentDetails.filter(obj =>
obj.studentName.toLowerCase().indexOf(searchName.toLowerCase()) >= 0));
To run the above program, you need to use the following command;
node fileName.js.
Here, my file name is demo55.js.
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo55.js
[ { studentName: 'John Smith' }, { studentName: 'john smith' } ]
An Interesting Method to Generate Binary Numbers from 1 to n?

Here we will see one interesting method for generating binary numbers from 1 to n. Here we are using queue. Initially the queue will hold first binary number ‘1’. Now repeatedly delete element from queue, and print it, and append 0 at the end of the front item, and append 1 at the end of the front time, and insert them into the queue. Let us see the algorithm to get the idea.
Begin
   define empty queue.
   insert 1 into the queue
   while n is not 0, do
      delete element from queue and store it into s1
      print s1
      s2 := s1
      insert s1 by adding 0 after it into queue
      insert s1 by adding 1 after it into queue
      decrease n by 1
   done
End
#include <iostream>
#include <queue>
using namespace std;
void genBinaryNumbers(int n){
   queue<string> qu;
   qu.push("1");
   while(n != 0){
      string s1 = qu.front();
      qu.pop();
      cout << s1 << " ";
      string s2 = s1;
      qu.push(s1 + "0");
      qu.push(s1 + "1");
      n--;
   }
}
int main() {
   int n = 15;
   genBinaryNumbers(n);
}
1 10 11 100 101 110 111 1000 1001 1010 1011 1100 1101 1110 1111
How to Install iPython on Windows? - GeeksforGeeks

22 Sep, 2021
Ipython is a toolkit used for using Python interactively using a Python shell and also provides a Jupyter kernel to work with Python code in Jupyter notebooks. In this article, we will look into the process of installing ipython package on Windows.
The only thing that you need for installing the Scrapy module on Windows are:
Python 
PIP or Conda (depending upon user preference)
If you want the installation to be done through conda,  open up the Anaconda Powershell Prompt and use the below command:
conda install -c anaconda ipython
Type y for yes when prompted.
You will get a similar message once the installation is complete:
Make sure you follow the best practices for installation using conda as:
Use an environment for installation rather than in the base environment using the below command:
conda create -n my-env
conda activate my-env
Note: If your preferred method of installation is conda-forge, use the below command:
conda config --env --add channels conda-forge
To verify if IPython Package has been successfully installed in your system run the below command in Anaconda Powershell Prompt:
conda list ipython
You’ll get the below message if the installation is complete:
If you want the installation to be done through PIP,  open up the Command Prompt and use the below command:
pip install ipython
You will get a similar message once the installation is complete:
To verify if the  IPython Package has been successfully installed in your system run the below command in Command Prompt:
python -m pip show ipython
You’ll get the below message if the installation is complete:
how-to-install
Picked
How To
Installation Guide
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Install FFmpeg on Windows?
How to Set Git Username and Password in GitBash?
How to Add External JAR File to an IntelliJ IDEA Project?
How to Create and Setup Spring Boot Project in Eclipse IDE?
How to Install Jupyter Notebook on MacOS?
Installation of Node.js on Linux
How to Install FFmpeg on Windows?
How to Install Pygame on Windows ?
How to Add External JAR File to an IntelliJ IDEA Project?
How to Install Jupyter Notebook on MacOS?
Stream empty() in Java with Examples

06 Dec, 2018
Stream empty() creates an empty sequential Stream.
Syntax :
static <T> Stream<T> empty()

Parameters :
T : The type of stream elements.
Stream : A sequence of objects that supports various methods which can be pipelined to produce the desired result.
Return Value : Stream empty() returns an empty sequential stream.
Note : An empty stream might be useful to avoid null pointer exceptions while callings methods with stream parameters.
Example :
// Java code for Stream empty()import java.util.*;import java.util.stream.Stream;  class GFG {      // Driver code    public static void main(String[] args)    {        // Creating an empty Stream        Stream<String> stream = Stream.empty();          // Displaying elements in Stream        stream.forEach(System.out::println);    }}
Output :
No Output

Java - util package
Java-Functions
java-stream
Java-Stream interface
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python PIL | copy() method

25 Jun, 2019
Syntax:Image.copy()

Parameters: no arguments

Returns:An image object

# Importing Image module from PIL packagefrom PIL import Image  # creating a image objectim1 = Image.open(r"C:\Users\sadow984\Desktop\i3.PNG")  # copying image to another image objectim2 = im1.copy()  # shows the copied imageim2.show()
Output:
# Importing Image module from PIL packagefrom PIL import Image  # creating a image objectim1 = Image.open(r"C:\Users\sadow984\Desktop\i3.PNG")  # copying image to another image objectim2 = im1.copy()  # shows the original imageim1.show()
Output:
python-utility
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Python Classes and Objects
Iterate over a list in Python
Python OOPs Concepts
Java Program to Return the Elements at Odd Positions in a List

17 Dec, 2020
Given a List, the task is to return the elements at Odd positions in a list. Let’s consider the following list.
Clearly, we can see that elements 20, 40, 60 are at Odd Positions as the index of the list is zero-based. Now we should return these elements.
Approach 1:
Initialize a temporary value with zero.
Now traverse through the list.
At each iteration check the temporary value if value equals to odd then return that element otherwise just continue.
After each iteration increment the temporary value by 1.
However, this can be done without using temporary value. Since the data in the list is stored using fixed index therefore we can directly check if the index is odd or even and return the element accordingly    
Example:
Java
// Java Program to Return the Elements// at Odd Positions in a Listimport java.io.*;import java.util.*;  class GFG {        public static void main(String[] args)    {        // Creating our list from above illustration        List<Integer> my_list = new ArrayList<Integer>();        my_list.add(10);        my_list.add(20);        my_list.add(30);        my_list.add(40);        my_list.add(50);        my_list.add(60);          // creating a temp_value for checking index        int temp_val = 0;          // using a for-each loop to          // iterate through the list        System.out.print("Elements at odd position are : ");        for (Integer numbers : my_list) {            if (temp_val % 2 != 0) {                System.out.print(numbers + " ");            }            temp_val += 1;        }    }}
Elements at odd position are : 20 40 60
Approach 2:
Traverse the list starting from position 1.
Now increment the position by 2 after each iteration. By doing this we always end up in an odd position.
Iteration 1: 1+2=3
Iteration 2: 2+3=5
Iteration 3: 5+2=7
And so on.
Return the value of the element during each iteration.
Example:
Java
// Java Program to Return the Elements// at Odd Positions in a List  import java.io.*;import java.util.*;  class GFG {        public static void main(String[] args)    {        // creating list from above illustration        List<Integer> my_list = new ArrayList<>();        my_list.add(10);        my_list.add(20);        my_list.add(30);        my_list.add(40);        my_list.add(50);        my_list.add(60);          // iterating list from position one and incrementing        // the index value by 2        System.out.print(            "Elements at odd positions are : ");                for (int i = 1; i < 6; i = i + 2) {            System.out.print(my_list.get(i) + " ");        }    }}
Elements at odd positions are : 20 40 60
java-list
Picked
Java
Java Programs
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Stream In Java
Introduction to Java
Constructors in Java
Exceptions in Java
Generics in Java
Java Programming Examples
Convert Double to Integer in Java
Implementing a Linked List in Java using Class
Factory method design pattern in Java
Java Program to Remove Duplicate Elements From the Array
C Program to print all permutations of a given string

10 Dec, 2021
A permutation also called an “arrangement number” or “order,” is a rearrangement of the elements of an ordered list S into a one-to-one correspondence with S itself. A string of length n has n! permutation. 
Source: Mathword(http://mathworld.wolfram.com/Permutation.html)
Below are the permutations of string ABC. ABC ACB BAC BCA CBA CAB
Here is a solution that is used as a basis in backtracking.
C
// C program to print all permutations // with duplicates allowed #include <stdio.h> #include <string.h>   /* Function to swap values at    two pointers */void swap(char *x, char *y) {     char temp;     temp = *x;     *x = *y;     *y = temp; }   /* Function to print permutations    of string    This function takes three parameters:    1. String    2. Starting index of the string    3. Ending index of the string. */void permute(char *a, int l, int r) {     int i;     if (l == r)         printf("%s\n", a);     else    {         for (i = l; i <= r; i++)         {             swap((a + l), (a + i));             permute(a, l + 1, r);               //backtrack             swap((a + l), (a + i));         }     } }   // Driver codeint main() {     char str[] = "ABC";     int n = strlen(str);     permute(str, 0, n-1);     return 0; } 
Output: 
ABC
ACB
BAC
BCA
CBA
CAB
Algorithm Paradigm: Backtracking 
Time Complexity: O(n*n!) Note that there are n! permutations and it requires O(n) time to print a permutation.
Auxiliary Space: O(r – l)
Note: The above solution prints duplicate permutations if there are repeating characters in the input string. Please see the below link for a solution that prints only distinct permutations even if there are duplicates in input.Print all distinct permutations of a given string with duplicates. Permutations of a given string using STL
Please write comments if you find the above codes/algorithms incorrect, or find other ways to solve the same problem. 
C Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Header files in C/C++ and its uses
C Program to read contents of Whole File
How to return multiple values from a function in C or C++?
C++ Program to check Prime Number
How to Append a Character to a String in C
Producer Consumer Problem in C
Program to find Prime Numbers Between given Interval
C program to sort an array in ascending order
Set, Clear and Toggle a given bit of a number in C
time() function in C
Tryit Editor v3.6 - Show Python

username = input("Enter username:")
print("Username is: " + username)
Groovy - Break Statement

The break statement is used to alter the flow of control inside loops and switch statements. We have already seen the break statement in action in conjunction with the switch statement. The break statement can also be used with while and for statements. Executing a break statement with any of these looping constructs causes immediate termination of the innermost enclosing loop.
The following diagram shows the diagrammatic explanation of the break statement.
Following is an example of the break statement −
class Example {
   static void main(String[] args) {
      int[] array = [0,1,2,3];
		
      for(int i in array) {
         println(i);
         if(i == 2)
         break;
      }
   } 
}
The output of the above code would be −
0 
1 
2 

As expected since there is a condition put saying that if the value of i is 2 then break from the loop that is why the last element of the array which is 3 is not printed.

    52 Lectures 
     8 hours 

 Krishna Sakinala

    49 Lectures 
     2.5 hours 

 Packt Publishing
 Print
 Add Notes
 Bookmark this page
Ruby on Rails - Models

Model.new   # creates a new empty model
Model.create( :field ⇒ 'value', :other_field ⇒ 42 )
# creates an object with the passed parameters and saves it

Model.find_or_create_by_field( value )  
# searches for a record where "field = value", creates
# a new record if not found

User.find_or_create_by_name_and_email( 'ramjoe', 'ram@example.com')
There are four ways of associating models. has_one, has_many, belongs_to and has_and_belongs_to_many. Assuming the following four entities −
def Order < ActiveRecord::Base
   has_many :line_items
   belongs_to :customer 
end

def LineItem < ActiveRecord::Base
   belongs_to :order
end

def Customer < ActiveRecord::Base
   has_many :orders
   has_one :address
end

def Address < ActiveRecord::Base
   belongs_to :customer
end
Consider following relationship −
def Category < ActiveRecord::Base 
   has_and_belongs_to_many :products
end

def Product < ActiveRecord::Base
   has_and_belongs_to_many :categories  
end
Consider the following relationship now. This depicts how we can use joins while defining relationship.
class Author < ActiveRecord::Base
   has_many :authorships
   has_many :books, :through ⇒ :authorships
end

class Authorship < ActiveRecord::Base
   belongs_to :author
   belongs_to :book
end

class Book < ActiveRecord::Base
   has_one :authorship
end

@author = Author.find :first
# selects all books that the author's authorships belong to.

@author.authorships.collect { |a| a.book }
selects all books by using the Authorship join model
@author.books 
Check Associations for more details.
 Print
 Add Notes
 Bookmark this page
Parse XML using Minidom in Python

10 Jul, 2020
DOM (document object model) is a cross-language API from W3C i.e. World Wide Web Consortium for accessing and modifying XML documents. Python enables you to parse XML files with the help of xml.dom.minidom, which is the minimal implementation of the DOM interface. It is simpler than the full DOM API and should be considered as smaller.
Steps for Parsing XML are – 
Import the module
import xml.dom.minidom

Let say, your XML  files will have the following things, 
Use the parse function to load and parse the XML file. In the below case docs stores the result of the parse function
docs = xml.dom.minidom.parse("test.xml")

Let’s print the child tagname and nodename of the XML file. 
Python3
import xml.dom.minidom  docs = xml.dom.minidom.parse("test.xml")  print(docs.nodeName)print(docs.firstChild.tagName)
Output:
#document
info
Now to get the information from the tag-name, you need to call dom standard function getElementsByTagName and getAttribute for fetching the required attributes. 
Python3
import xml.dom.minidom    docs = xml.dom.minidom.parse("test.xml")  print(docs.nodeName)print(docs.firstChild.tagName)  skills = docs.getElementsByTagName("skills")  print("%d skills" % skills.length)for i in skills:    print(i.getAttribute("name"))
Output:
#document
info
4 skills
Machine learning
Deep learning
Python
Bootstrap

Python-XML
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Stack machine in Computer Organisation

19 Feb, 2020
Instruction formats are classified into different types depending upon the CPU organization. CPU organization is again classified into three types based on internal storage: Stack machine, Accumulator machine, General purpose organization or General register. In this article, we will learn about the stack machine in computer organizations.
Stack Machine:In the stack machine, data is available at the top of the stack by default. The stack acts as a source and destination, push and pop instructions are used to access instructions and data from the stack. There is no need to pass the source and destination address because the default address is top of the stack. In the stack machine, there is no need to pass explicit addresses in the instruction. Therefore the instruction format consists only of the OPCODE (Operation Code) field. This instruction format is known as Zero address instruction.
The two operations of the stack are insertion (push) and deletion (pop) of items in the Stack. However, nothing is pushed or popped in a computer stack.
Example:Perform the following set of instructions intended for execution on a stack machine:
PUSH B, 
PUSH X, 
ADD, 
POP C, 
PUSH C, 
PUSH Y, 
SUB, 
POP Z 
First PUSH B and X in a stack, then to add first POP X then B, ADD (B+X), POP C=B+X (no data with name C, so the data present is stored in variable C) then POP C.Similarly, to perform SUB (Y-C) first perform POP operation POP as Z. See in figure below for better understanding:
Technical Scripter 2019
Computer Organization & Architecture
GATE CS
Stack
Technical Scripter
Stack
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
PostgreSQL – LIKE operator

28 Aug, 2020
The PostgreSQL LIKE operator is used query data using pattern matching techniques. Its result include strings that are case-sensitive and follow the mentioned pattern.It is important to know that PostgreSQL provides with 2 special wildcard characters for the purpose of patterns matching as below:
Percent ( %) for matching any sequence of characters.
Underscore ( _) for matching any single character.
Syntax: string LIKE pattern;
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 make a query to find the customer in the “customer” table by looking at the “first_name” column to see if there is any value that begins with “K” using the LIKE operator in our sample database.
SELECT
    first_name,
        last_name
FROM
    customer
WHERE
    first_name LIKE 'K%';
Output:
Notice few things in the above example, the WHERE clause contains a special expression: the first_name, the LIKE operator, and a string that contains a percent (%) character, which is referred to as a pattern.
Example 2:Here we will query for customers whose first name begins with any single character, is followed by the literal string “her”, and ends with any number of characters using the LIKE operator in our sample database.
SELECT
    first_name,
    last_name
FROM
    customer
WHERE
    first_name LIKE '_her%';
Output:
postgreSQL-operators
PostgreSQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
JavaScript - Math max Method

This method returns the largest of zero or more numbers. If no arguments are given, the results is –Infinity.
Its syntax is as follows −
Math.max(value1, value2, ... valueN ) ;

value1, value2, ... valueN : Numbers.
Returns the largest of zero or more numbers.
Try the following example program.
<html>   
   <head>
      <title>JavaScript Math max() Method</title>
   </head>
   
   <body>      
      <script type = "text/javascript">
         var value = Math.max(10, 20, -1, 100);
         document.write("First Test Value : " + value ); 
         
         var value = Math.max(-1, -3, -40);
         document.write("<br />Second Test Value : " + value ); 
         
         var value = Math.max(0, -1);
         document.write("<br />Third Test Value : " + value ); 
         
         var value = Math.max(100);
         document.write("<br />Fourth Test Value : " + value ); 
      </script>   
   </body>
</html>
First Test Value : 100
Second Test Value : -1
Third Test Value : 0
Fourth Test Value : 100 


    25 Lectures 
     2.5 hours 

 Anadi Sharma

    74 Lectures 
     10 hours 

 Lets Kode It

    72 Lectures 
     4.5 hours 

 Frahaan Hussain

    70 Lectures 
     4.5 hours 

 Frahaan Hussain

    46 Lectures 
     6 hours 

 Eduonix Learning Solutions

    88 Lectures 
     14 hours 

 Eduonix Learning Solutions
 Print
 Add Notes
 Bookmark this page
C# Any Method

The Any method checks whether any of the element in a sequence satisfy a specific condition or not.
If any element satisfy the condition, true is returned.
Let us see an example.
int[] arr = {5, 7, 10, 12, 15, 18, 20};
Now, using Any() method, we will check whether any of the element in the above array is greater than 10 or not.
arr.AsQueryable().All(val => val > 5);
If any of the element satisfies the condition, then True is returned.
Let us see the complete example.
 Live Demo
using System;
using System.Linq;
class Demo {
   static void Main() {
      int[] arr = {5, 7, 10, 12, 15, 18, 20};
      // checking if any of the array elements are greater than 10
      bool res = arr.AsQueryable().Any(val => val > 10);
      Console.WriteLine(res);
   }
}
True
How do I insert a JPEG image into a Python Tkinter window?

Python provides the Pillow (PIL) package to support, process, and display the images in tkinter applications. A Tkinter application generally supports image files such as, ppm, png, and gif.
Let us suppose we want to embed and display a JPEG or JPG image in our application.
Tkinter Label widgets are generally used to display the text or images on the window and thus by passing the img value, we can display the JPEG image in the window.
#Import required libraries
from tkinter import *
from PIL import ImageTk, Image

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

#Define the geometry of the window
win.geometry("650x400")

#Initialize the file name in a variable
path = "file.jpg"

#Create an object of tkinter ImageTk
img = ImageTk.PhotoImage(Image.open(path))

#Create a Label Widget to display the text or Image
label = tk.Label(win, image = img)
label.pack(fill = "both", expand = "yes")

win.mainloop()
The code will display a JPEG image that is passed as the image value in the Label widget.
How to use ORDER BY field and sort by id in a single MySQL field?

For this, you can use ORDER BY FIELD. Let us first create a table −
mysql> create table DemoTable
   -> (
   -> Id int,
   -> Name varchar(20)
   -> );
Query OK, 0 rows affected (1.78 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(101,'Chris');
Query OK, 1 row affected (0.38 sec)
mysql> insert into DemoTable values(201,'Mike');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values(110,'Adam');
Query OK, 1 row affected (0.52 sec)
mysql> insert into DemoTable values(250,'John');
Query OK, 1 row affected (0.33 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------+-------+
| Id   | Name  |
+------+-------+
|  101 | Chris |
|  201 | Mike  |
|  110 | Adam  |
|  250 | John  |
+------+-------+
4 rows in set (0.00 sec)
Here is the query to use order by field as well sort by id &miuns;
mysql> select *from DemoTable
   -> order by field(Name,'Mike') desc,Id desc;
This will produce the following output −
+------+-------+
| Id   | Name  |
+------+-------+
| 201  | Mike  |
| 250  | John  |
| 110  | Adam  |
| 101  | Chris |
+------+-------+
4 rows in set (0.01 sec)
How to explicitly call base class constructor from child class in C#?

Make use of this keyword in c# to call one constructor from another constructor To call a constructor which is present in parent class make use of base keyword
To call a constructor which is present in another class make use of base keyword
class DemoBase{
   public DemoBase(int firstNumber, int secondNumber, int thirdNumber){
      System.Console.WriteLine("Base class Constructor");
      System.Console.WriteLine($"{firstNumber} {secondNumber} {thirdNumber}");
   }
}
class Demo : DemoBase{
   public Demo(int firstNumber, int secondNumber, int thirdNumber) : base(firstNumber, secondNumber, thirdNumber){
      System.Console.WriteLine("Derived class Constructor");
      System.Console.WriteLine($"{firstNumber} {secondNumber} {thirdNumber}");
   }
}
class Program{
   static void Main(){
      Demo obj = new Demo(1, 2, 3);
      Console.ReadLine();
   }
}
Base class Constructor
1 2 3
Derived class Constructor
1 2 3
Bash program to check if the Number is a Palindrome?

To check whether a number is palindrome or not, we have to reverse the number, and then if the actual number and the reversed number are same, then this is palindrome. In Bash, performing the reverse operation is very easy. We have to use the ‘rev’ command to do that. Let us see the program to understand clearly.
#!/bin/bash
# GNU bash Script
n=12321
rev=$(echo $n | rev)
if [ $n -eq $rev ]; then
   echo "Number is palindrome"
else
   echo "Number is not palindrome"
fi
Number is palindrome
What is setTimeout() Method in javascript?

This is one of the many timing events. The window object allows the execution of code at specified time intervals. This object has provided SetTimeout() to execute a function after a certain amount of time. It takes two parameters as arguments. One is the function and the other is the time that specifies the interval after which the function should be executed.
window.setTimeout(function, milliseconds);
In the following example, the time passed to the setTimeout() function is 2 seconds. Therefore the function will be executed after two secs and display the output as shown.
Live Demo
<html>
<body>
<p>wait 2 seconds.</p>
<script>
   setTimeout(function(){
      document.write("Tutorix is the best e-learning platform");
   }, 2000);
</script>
</body>
</html>
wait 2 seconds
Tutorix is the best e-learning platform
In the following example, the time passed to the setTimeout() function is 3 seconds. Therefore the function will be executed after three secs and display the output as shown.
Live Demo
<html>
<body>
<p id = "time"></p>
<script>
   setTimeout(function(){
      document.getElementById("time").innerHTML = "Tutorix is the product of Tutorialspoint";
   }, 3000);
</script>
</body>
</html>
Tutorix is the product of Tutorialspoint.