code-rag-bench/online-tutorials huggingface dataset:
Java Examples - Solving Tower of Hanoi

How to use  method for solving Tower of Hanoi problem?
This example displays the way of using  method for solving Tower of Hanoi problem( for 3 disks).
public class MainClass {
   public static void main(String[] args) {
      int nDisks = 3;
      doTowers(nDisks, 'A', 'B', 'C');
   }
   public static void doTowers(int topN, char from, char inter, char to) {
      if (topN == 1) {
         System.out.println("Disk 1 from " + from + " to " + to);
      } else {
         doTowers(topN - 1, from, to, inter);
         System.out.println("Disk " + topN + " from " + from + " to " + to);
         doTowers(topN - 1, inter, from, to);
      }
   }
}
The above code sample will produce the following result.
Disk 1 from A to C
Disk 2 from A to B
Disk 1 from C to B
Disk 3 from A to C
Disk 1 from B to A
Disk 2 from B to C
Disk 1 from A to C

The following is an another sample example of Tower of Hanoi
public class TowersOfHanoi {
   public static void move(int n, int startPole, int endPole) {
      if (n == 0) {
         return;
      } 
      int intermediatePole = 6 - startPole - endPole;
      move(n-1, startPole, intermediatePole);
      System.out.println("Move " +n + " from " + startPole + " to " +endPole);
      move(n-1, intermediatePole, endPole);
   } 
   public static void main(String[] args) {
      move(5, 1, 3);
   }
}
The above code sample will produce the following result.
Move 1 from 1 to 3
Move 2 from 1 to 2
Move 1 from 3 to 2
Move 3 from 1 to 3
Move 1 from 2 to 1
Move 2 from 2 to 3
Move 1 from 1 to 3
Move 4 from 1 to 2
Move 1 from 3 to 2
Move 2 from 3 to 1
Move 1 from 2 to 1
Move 3 from 3 to 2
Move 1 from 1 to 3
Move 2 from 1 to 2
Move 1 from 3 to 2
Move 5 from 1 to 3
Move 1 from 2 to 1
Move 2 from 2 to 3
Move 1 from 1 to 3
Move 3 from 2 to 1
Move 1 from 3 to 2
Move 2 from 3 to 1
Move 1 from 2 to 1
Move 4 from 2 to 3
Move 1 from 1 to 3
Move 2 from 1 to 2
Move 1 from 3 to 2
Move 3 from 1 to 3
Move 1 from 2 to 1
Move 2 from 2 to 3
Move 1 from 1 to 3

 Print
 Add Notes
 Bookmark this page
How to implement interface in anonymous class in C#?

No, anonymous types cannot implement an interface. We need to create your own
type.
Anonymous types provide a convenient way to encapsulate a set of read-only
properties into a single object without having to explicitly define a type first.
The type name is generated by the compiler and is not available at the source code
level. The type of each property is inferred by the compiler.
You create anonymous types by using the new operator together with an object
initializer.
class Program{
   public static void Main(){
      var v = new { Amount = 108, Message = "Test" };
      Console.WriteLine(v.Amount + v.Message);
      Console.ReadLine();
   }
}
108Test
Convert elements of a Vector to Strings in R Language - toString() Function - GeeksforGeeks

25 Oct, 2021
toString() function in R Programming Language is used to produce a single character string describing an R object.
Syntax: toString(x, width = NULL)
Parameters: 
x: R object
width: Suggestion for the maximum field width. Values of NULL or 0 indicate no maximum. The minimum value accepted is 6 and smaller values are taken as 6  
R
# R program to illustrate# toString function # Initializing a string vectorx <- c("GFG", "Geeks", "GeeksforGeekss") # Calling the toString() functiontoString(x)
Output : 
[1] "GFG, Geeks, GeeksforGeekss"
R
# R program to illustrate# toString function # Initializing a string vectorx <- c("GFG", "Geeks", "GeeksforGeekss") # Calling the toString() functiontoString(x, width = 2)toString(x, width = 8)toString(x, width = 10)
Output: 
[1] "GF...."
[1] "GFG, ...."
[1] "GFG, G...."
R
# Matrix having 3 rows and 3 columns# filled by a single constant 5mat <- (matrix(5, 3, 3))print(mat)str <- toString(mat)print("String")print(str)
Output:
     [,1] [,2] [,3]
[1,]    5    5    5
[2,]    5    5    5
[3,]    5    5    5
[1] "String"
[1] "5, 5, 5, 5, 5, 5, 5, 5, 5"
kumar_satyam
R String-Functions
R Vector-Function
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Replace specific values in column in R DataFrame ?
How to change Row Names of DataFrame in R ?
Filter data by multiple conditions in R using Dplyr
Change Color of Bars in Barchart using ggplot2 in R
Loops in R (for, while, repeat)
Printing Output of an R Program
How to Change Axis Scales in R Plots?
Group by function in R using Dplyr
How to Split Column Into Multiple Columns in R DataFrame?
K-Means Clustering in R Programming
VB.Net - Nested Select Case Statement

It is possible to have a select statement as part of the statement sequence of an outer select statement. Even if the case constants of the inner and outer select contain common values, no conflicts will arise.
Module decisions
   Sub Main()
      'local variable definition
      Dim a As Integer = 100
      Dim b As Integer = 200
      Select a
         Case 100
            Console.WriteLine("This is part of outer case ")
            Select Case b
               Case 200
                  Console.WriteLine("This is part of inner case ")
            End Select
         End Select
      Console.WriteLine("Exact value of a is : {0}", a)
      Console.WriteLine("Exact value of b is : {0}", b)
      Console.ReadLine()
   End Sub
End Module
When the above code is compiled and executed, it produces the following result −
This is part of outer case
This is part of inner case
Exact value of a is : 100
Exact value of b is : 200


    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
C++ Program to Find the Number of Vowels, Consonants, Digits and White Spaces in a String

A string is a one dimensional character array that is terminated by a null character. There can be many vowels, consonants, digits and white spaces in a string.
For example.
String: There are 7 colours in the rainbow
Vowels: 12
Consonants: 15
Digits: 1
White spaces: 6
A program to find the number of vowels, consonants, digits and white spaces in a string is given as follows.
 Live Demo
#include <iostream>
using namespace std;
int main() {
   char str[] = {"Abracadabra 123"};
   int vowels, consonants, digits, spaces;
   vowels = consonants = digits = spaces = 0;
   for(int i = 0; str[i]!='\0'; ++i) {
      if(str[i]=='a' || str[i]=='e' || str[i]=='i' ||
      str[i]=='o' || str[i]=='u' || str[i]=='A' ||
      str[i]=='E' || str[i]=='I' || str[i]=='O' ||
      str[i]=='U') {
         ++vowels;
      } else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z')) {
         ++consonants;
      } else if(str[i]>='0' && str[i]<='9') {
         ++digits;
      } else if (str[i]==' ') {
         ++spaces;
      }  
   }
   cout << "The string is: " << str << endl;
   cout << "Vowels: " << vowels << endl;
   cout << "Consonants: " << consonants << endl;
   cout << "Digits: " << digits << endl;
   cout << "White spaces: " << spaces << endl;
   return 0;
}
The string is: Abracadabra 123
Vowels: 5
Consonants: 6
Digits: 3
White spaces: 1
In the above program, the variables vowels, consonants, digits and spaces are used to store the number of vowels, consonants, digits and spaces in the string. A for loop is used to examine each character of a string. If that character is a vowels, then vowels variable is incremented by 1. Same for consonants, digits and spaces. The code snippet that demonstrates this is as follows.
for(int i = 0; str[i]!='\0'; ++i) {
if(str[i]=='a' || str[i]=='e' || str[i]=='i' ||
str[i]=='o' || str[i]=='u' || str[i]=='A' ||
str[i]=='E' || str[i]=='I' || str[i]=='O' ||
str[i]=='U') {
   ++vowels;
   } else if((str[i]>='a'&& str[i]<='z') || (str[i]>='A'&& str[i]<='Z')) {
      ++consonants;
   } else if(str[i]>='0' && str[i]<='9') {
      ++digits;
   } else if (str[i]==' ') {
      ++spaces;
   }
}
After the occurrences of the vowels, consonants, digits and spaces in the string are calculated, they are displayed. This is shown in the following code snippet.
The string is: Abracadabra 123
Vowels: 5
Consonants: 6
Digits: 3
White spaces: 1
How to serialize a JavaScript array?

The serializeArray( ) method serializes all forms and forms elements like the .serialize() method but returns a JSON data structure for you to work with.
Let’s say the following is the content in PHP file serialize.php −
<?php
   if( $_REQUEST["name"] ) {
      $name = $_REQUEST['name'];
      echo "Welcome ". $name;
      $age = $_REQUEST['age'];
      echo "<br />Your age : ". $age;
      $sex = $_REQUEST['sex'];
      echo "<br />Your gender : ". $sex;
   }
?>
The following is the code to implement serializeArray() method in JavaScript −
Live Demo
<html>
   <head>
      <title>The jQuery Example</title>
         <script type = "text/javascript"
            src = "https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js">
         </script>
         <script type = "text/javascript" language = "javascript">
            $(document).ready(function() {
               $("#driver").click(function(event){
                  $.post(
                     "/jquery/serialize.php",
                     $("#testform").serializeArray(),
                     function(data) {
                        $('#stage1').html(data);
                     }
                  );
                  var fields = $("#testform").serializeArray();
                  $("#stage2").empty();
                  jQuery.each(fields, function(i, field){
                     $("#stage2").append(field.value + " ");
                  });
               });
            });
         </script>
   </head>
   <body>
      <p>Click on the button to load result.html file:</p>
      <div id = "stage1" style = "background-color:blue;">
         STAGE - 1
      </div>
      <br />
      <div id = "stage2" style = "background-color:blue;">
         STAGE - 2
      </div>
      <form id = "testform">
         <table>
           <tr>
             <td><p>Name:</p></td>
             <td><input type = "text" name = "name" size = "40" /></td>
           </tr>
           <tr>
             <td><p>Age:</p></td>
             <td><input type = "text" name = "age" size = "40" /></td>
           </tr>
           <tr>
             <td><p>Sex:</p></td>
             <td> <select name = "sex">
                <option value = "Male" selected>Male</option>
                <option value = "Female" selected>Female</option>
             </select></td>
           </tr>
           <tr>
             <td colspan = "2">
               <input type = "button" id = "driver" value = "Load Data" />
             </td>
           </tr>
         </table>
      </form>
   </body>
</html>
Create a Range of Colors between the Specified Colors in R Programming - colorRampPalette() Function - GeeksforGeeks

30 Jun, 2020
colorRampPalette() function in R Language is used to create a color range between two colors specified as arguments to the function. This function is used to specify the starting and ending color of the range.
Syntax:colorRampPalette(c(“color1”, “color2”))
Parameters:color1, color2: starting and ending colors of the range.
Returns: color range between specified colors
Example:
# R program to create a color range  # Apply colorRampPalette Functionfun_color_range <- colorRampPalette(c("Green", "darkgreen"))   my_colors <- fun_color_range(100)    # Plotting a graphplot(1:100, pch = 20, col = my_colors)
Output:
Example 2:
# R program to create a color range  # Apply colorRampPalette Functionfun_color_range <- colorRampPalette(c("blue", "orange"))   my_colors <- fun_color_range(100)    # Plotting a graphplot(1:100, pch = 40, col = my_colors)
Output :
R-Functions
R Language
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Change Color of Bars in Barchart using ggplot2 in R
How to Change Axis Scales in R Plots?
Group by function in R using Dplyr
How to Split Column Into Multiple Columns in R DataFrame?
How to filter R DataFrame by values in a column?
How to filter R dataframe by multiple conditions?
R - if statement
Replace Specific Characters in String in R
Time Series Analysis in R
How to import an Excel File into R ?
5 Different methods to find the length of a string in C++?

A sequence of characters or a linear array of character is known as String. Its declaration is same as define other arrays.
Length of array is the number of characters in the String. There are many in-built method and other methods to find the length of string. Here, we are discussing 5 different methods to find the length of a string in C++.
1) Using the strlen() method of C − This function returns an integer value of the C. For this you need to pass the string in the form of character array.
#include <iostream>
#include <cstring>
using namespace std;
int main() {
   char charr[] = "I Love Tutorialspoint";
   int length = strlen(charr);
   cout << "the length of the character array is " << length;
   return 0;
}
the length of the character array is 21
2) Using the size() method of c++ − It is included in the string library of C++. The return an integer value of the number of characters in the string.
#include <iostream>
#include <string>
using namespace std;
int main() {
   string str = "I love tutorialspoint";
   int length = str.size();
   cout << "the length of the string is " << length;
   return 0;
}
The length of the string is 21
3) Using the for loop − This method does not require any function. It loops through the array and counts the number of elements in it. The loop runs until the ‘/0’ is encountered.
#include <iostream>
#include <string>
using namespace std;
int main() {
   string str = "I love tutorialspoint";
   int i;
   for(i=0; str[i]!='\0'; i++){ }
      cout << "the length of the string is " << i;
   return 0;
}
The length of the string is 21
4) Using the length() method − In C++ their is a method length() in the string library that returns the number of characters in the string.
#include <iostream>
#include <string>
using namespace std;
int main() {
   string str = "I love tutorialspoint";
   int length = str.length();
   cout << "the length of the string is " << length;
      return 0;
}
The length of the string is 21
5) Finding length of string using the while loop − You can count the number of characters in a string using the while loop also. To count the number of characters, you have to use a counter in the while loop and specify the end condition as != ‘\0’ for the string.
#include <iostream>
#include <string>
using namespace std;
int main() {
   string str = "I love tutorialspoint";
   int length = 0;
   while(str[length] !='\0' ){
      length++;
   }
   cout<<"The length of the string is "<< length;
   return 0;
}
The length of the string is 21
Dynamic Programming - GeeksforGeeks

04 May, 2020
l(i,j) = 0, if either i=0 or j=0
       = expr1, if i,j > 0 and X[i-1] = Y[j-1]
       = expr2, if i,j > 0 and X[i-1] != Y[j-1] 
1) The last characters of two strings match. 
   The length of lcs is length of lcs of X[0..i-1] and Y[0..j-1]
2) The last characters don't match.
   The length of lcs is max of following two lcs values
   a) LCS of X[0..i-1] and Y[0..j]
   b) LCS of X[0..i] and Y[0..j-1]

Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Best Time to Buy and Sell Stock
Must Do Coding Questions for Product Based Companies
Converting Epsilon-NFA to DFA using Python and Graphviz
C++ Program For Inserting A Node In A Linked List
CBSE Notes for Class 10 Physics
Largest value of K such that both K and -K exist in Array in given index range [L, R]
BigInt (BIG INTEGERS) in C++ with Example
Different Ways to Run Applet in Java
How to Install Flutter on Visual Studio Code?
How to calculate MOVING AVERAGE in a Pandas DataFrame?
How do I convert (or scale) axis values and redefine the tick frequency in Matplotlib?

To convert or scale the axis values and redefine the tick frequency in matplotlib, we can make a list of xticks and xtick_labels using xticks() method. Place the axis scale and redefine the tick frequency.
Set the figure size and adjust the padding between and around the subplots.
Set the figure size and adjust the padding between and around the subplots.
Initialize a variable, n, for the number of data points.
Initialize a variable, n, for the number of data points.
Create x and y data points using numpy.
Create x and y data points using numpy.
Plot x and y data points using plot() method.
Plot x and y data points using plot() method.
Make lists of ticks and tick labels.
Make lists of ticks and tick labels.
Use xticks() method to place axis scale and redefine tick frequency.
Use xticks() method to place axis scale and redefine tick frequency.
To display the figure, use show() method.
To display the figure, use show() method.
import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.50, 3.50]
plt.rcParams["figure.autolayout"] = True
n = 10
x = np.linspace(-2, 2, n)
y = np.exp(x)
plt.plot(x, y)
xticks = [i for i in range(int(n/2))]
xtick_labels = ["x"+str(i) for i in range(int(n/2))]
plt.xticks(xticks, xtick_labels)
plt.show()
Covariant return types in Java

Covariant return type refers to return type of an overriding method. It allows to narrow down return type of an overridden method without any need to cast the type or check the return type. Covariant return type works only for non-primitive return types.
From Java 5 onwards, we can override a method by changing its return type only by abiding the condition that return type is a subclass of that of overridden method return type.
Following example showcases the same.
 Live Demo
class SuperClass {
   SuperClass get() {
      System.out.println("SuperClass");
      return this;
   }
}
public class Tester extends SuperClass {
   Tester get() {
      System.out.println("SubClass");
      return this;
   }
   public static void main(String[] args) {
      SuperClass tester = new Tester();
      tester.get();
   }
}
Output
Subclass
What is the scope of variables in JavaScript

The scope of a variable is the region of your program in which it is defined. JavaScript variables have only two scopes.
Global Variables − A global variable has global scope which means it can be defined anywhere in your JavaScript code.
Local Variables − A local variable will be visible only within a function where it is defined. Function parameters are always local to that function.
Within the body of a function, a local variable takes precedence over a global variable with the same name. If you declare a local variable or function parameter with the same name as a global variable, you effectively hide the global variable.
You can try to run the following code to learn how to work with scope of variables in JavaScript:
<html>
   <body onload = checkscope();>
      <script>
         <!--
         var myVar = "global"; // Declare a global variable
         function checkscope( ) {
            var myVar = "local"; // Declare a local variable
            document.write(myVar);
         }
         //-->
      </script>
   </body>
</html>
What is JavaScript Bitwise XOR (^) Operator?

If both the bits are different, then 1 is returned when Bitwise OR (|) operator is used.
You can try to run the following code to learn how to work with JavaScript Bitwise XOR Operator.
<!DOCTYPE html>
<html>
   <body>
      <script>
         document.write("Bitwise XOR Operator<br>");

         // 7 = 00000000000000000000000000000111
         // 1 = 00000000000000000000000000000001
         document.write(7 ^ 1);
      </script>
   </body>
</html>
What is the difference between method overloading and method hiding in Java?

method hiding − When super class and the sub class contains same methods including parameters, and if they are static and, when called, the super class method is hidden by the method of the sub class this is known as method hiding.
 Live Demo
class Demo{
   public static void demoMethod() {
      System.out.println("method of super class");
   }
}
public class Sample extends Demo{
   public static void demoMethod() {
      System.out.println("method of sub class");
   }
   public static void main(String args[] ){
      Sample.demoMethod();
   }
}
method of sub class

method overloading − When a class contains two methods with same name and different parameters, when called, JVM executes this method based on the method parameters this is known as method overloading.
 Live Demo
public class Sample{
   public static void add(int a, int b){
      System.out.println(a+b);
   }
   public static void add(int a, int b, int c){
      System.out.println(a+b+c);
   }
   public static void main(String args[]){
      Sample obj = new Sample();
      obj.add(20, 40);
      obj.add(40, 50, 60);
   }
}
60 
150
Fetching rows added in last hour with MySQL?

You can use date-sub() and now() function from MySQL to fetch the rows added in last hour.
The syntax is as follows −
select *from yourTableName
where yourDateTimeColumnName <=date_sub(now(),interval 1 hour);
The above query gives the result added last hour. To understand the above concept, let us first create a table. The query to create a table is as follows −
mysql> create table LastHourRecords
-> (
-> Id int,
-> Name varchar(100),
-> Login datetime
-> );
Query OK, 0 rows affected (0.67 sec)
Insert records in the form of datetime using insert command. The query to insert record is as follows −
mysql> insert into LastHourRecords values(1,'John',' 2018-12-19 10:00:00');
Query OK, 1 row affected (0.17 sec)

mysql> insert into LastHourRecords values(2,'Carol','2018-12-19 10:10:00');
Query OK, 1 row affected (0.15 sec)

mysql> insert into LastHourRecords values(3,'Sam','2018-12-19 10:05:00');
Query OK, 1 row affected (0.13 sec)

mysql> insert into LastHourRecords values(4,'Mike','2018-12-18 12:10:00');
Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from LastHourRecords;
+------+-------+---------------------+
| Id   | Name  | Login               |
+------+-------+---------------------+
| 1    | John  | 2018-12-19 10:00:00 |
| 2    | Carol | 2018-12-19 10:10:00 |
| 3    | Sam   | 2018-12-19 10:05:00 |
| 4    | Mike  | 2018-12-18 12:10:00 |
+------+-------+---------------------+
4 rows in set (0.00 sec)
Let us see the query to fetch rows added in the last hour −
mysql> select *from LastHourRecords
-> where Login <=Date_sub(now(),interval 1 hour);
+------+-------+---------------------+
| Id   | Name  | Login               |
+------+-------+---------------------+
| 1    | John  | 2018-12-19 10:00:00 |
| 2    | Carol | 2018-12-19 10:10:00 |
| 3    | Sam   | 2018-12-19 10:05:00 |
+------+-------+---------------------+
3 rows in set (0.00 sec)
Java program to print Fibonacci series of a given number.

Recursion is the process of repeating items in a self-similar way. In programming languages, if a program allows you to call a function inside the same function, then it is called a recursive call of the function.
Following is an example to find Fibonacci series of a given number using a recursive function
public class FibonacciSeriesUsingRecursion {
   public static long fibonacci(long number) {
      if ((number == 0) || (number == 1)) return number;
         else return fibonacci(number - 1) + fibonacci(number - 2);
      }
      public static void main(String[] args) {
         for (int counter = 0; counter <= 10; counter++){
            System.out.print(" "+fibonacci(counter));
         }
      }
   }
0 1 1 2 3 5 8 13 21 34 55
Go - The Select Statement

The syntax for a select statement in Go programming language is as follows −
select {
   case communication clause  :
      statement(s);      
   case communication clause  :
      statement(s); 
   /* you can have any number of case statements */
   default : /* Optional */
      statement(s);
}

The following rules apply to a select statement −
You can have any number of case statements within a select. Each case is followed by the value to be compared to and a colon.
You can have any number of case statements within a select. Each case is followed by the value to be compared to and a colon.
The type for a case must be the a communication channel operation.
The type for a case must be the a communication channel operation.
When the channel operation occured the statements following that case will execute. No break is needed in the case statement.
When the channel operation occured the statements following that case will execute. No break is needed in the case statement.
A select statement can have an optional default case, which must appear at the end of the select. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case.
A select statement can have an optional default case, which must appear at the end of the select. The default case can be used for performing a task when none of the cases is true. No break is needed in the default case.
package main

import "fmt"

func main() {
   var c1, c2, c3 chan int
   var i1, i2 int
   select {
      case i1 = <-c1:
         fmt.Printf("received ", i1, " from c1\n")
      case c2 <- i2:
         fmt.Printf("sent ", i2, " to c2\n")
      case i3, ok := (<-c3):  // same as: i3, ok := <-c3
         if ok {
            fmt.Printf("received ", i3, " from c3\n")
         } else {
            fmt.Printf("c3 is closed\n")
         }
      default:
         fmt.Printf("no communication\n")
   }    
}   
When the above code is compiled and executed, it produces the following result −
no communication


    64 Lectures 
     6.5 hours 

 Ridhi Arora

    20 Lectures 
     2.5 hours 

 Asif Hussain

    22 Lectures 
     4 hours 

 Dilip Padmanabhan

    48 Lectures 
     6 hours 

 Arnab Chakraborty

    7 Lectures 
     1 hours 

 Aditya Kulkarni

    44 Lectures 
     3 hours 

 Arnab Chakraborty
 Print
 Add Notes
 Bookmark this page
How to create PowerShell alias permanently?

PowerShell alias can be created permanently by 2 methods below.
To export all the aliases, you need to use Export-Alias cmdlet. When you use this command it will ask you the path for the file to import.
To export the newly created alias, you need to give alias name and the name for the export, so later you can import it with the same name.
In the below example, we have created alias name Edit for the Wordpad and we will export all the aliases with the name Alias1, so the newly created alias will also be
stored and when you want to import your newly created aliases you need to write Import-Alias command.
Now, we will export all the aliases.
Export-Alias -Path D:\Temp\Alias1
You can check the exported aliases and manipulate them as well with the proper format.
Notepad D:\Temp\Alias1
Next, whenever you run the new PowerShell console, you won’t find the new aliases so you need to import the exported aliases.
Import-Alias -Path D:\Temp\Alias1
But when you run the above command, you will get an error that inbuilt aliases are already existed but we have remediation for it, we can use –Force parameter to forcefully overwrite those aliases.
Import-Alias -Path D:\Temp\Alias1 -Force
Now you see the newly created aliases as well in the PowerShell console.
Another option but easier than Import/Export option is to create a profile script so every time PowerShell opens it loads a startup profile and all the commands and
scripts are loaded which resides inside that profile folder.
Here, we will create a profile file Profile.ps1 using below command on the $PROFILE path of your PowerShell.
notepad $((Split-Path $profile -Parent) + "\profile.ps1")
The above command will prompt to the user to create Profile1.ps1 on the $Profile path if it doesn’t exist and if it is already created then it will open the file to allow the user to
manipulate.
Once a file is opened, edit the file to set your aliases. Here we will set two aliases in the file. Type the following two commands in notepad and save it.
Set-Alias edit notepad.exe
Set-Alias edit1 "C:\Program Files\Windows NT\Accessories\wordpad.exe"
Launch the PowerShell console again and when you type edit, it will open Notepad and when you type edit1, it will open Wordpad.
With this simple method, you can add as many aliases in the profile script and launch them through the PowerShell console.
Object initializer in JavaScript

An object initializer is an expression that allow us to initialize a newly created object. It is a comma-separated list of zero or more pairs of property names and associated values of an
object enclosed in a pair of curly braces {}.
Following is the code for object initializer in JavaScript.
 Live Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<style>
   body {
      font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
   }
   .result {
      font-size: 20px;
      font-weight: 500;
      color: blueviolet;
   }
</style>
</head>
<body>
<h1>Object initializer in JavaScript</h1>
<div class="result"></div>
<br />
<button class="Btn">CLICK HERE</button>
<h3>Click on the above button to initialize an object with object initializer and display it</h3>
<script>
   let resEle = document.querySelector(".result");
   let BtnEle = document.querySelector(".Btn");
   let name = "Rohan";
   let age = 22;
   let place = "Delhi";
   const person = { name, age, place };
   BtnEle.addEventListener("click", () => {
      resEle.innerHTML = "person.name = " + person.name + "<br>";
      resEle.innerHTML += "person.age = " + person.age + "<br>";
      resEle.innerHTML += "person.place = " + person.place + "<br>";
   });
</script>
</body>
</html>
On clicking the ‘CLICK HERE’ button −
How to work with array variable in MySQL?


MySQL does not support array variables. To get the same result, use the table DUAL. Following is the syntax:
SELECT yourValue1 AS ArrayValue FROM DUAL
UNION ALL
SELECT yourValue2 FROM DUAL
UNION ALL
SELECT yourValue3 FROM DUAL
UNION ALL
SELECT yourValue4 FROM DUAL
UNION ALL
.
.
.
.
.
.
SELECT yourValueN FROM DUAL;
Let us create a sample table:
mysql> SELECT 1 AS ArrayValue FROM DUAL
      UNION ALL
      SELECT 2 FROM DUAL
      UNION ALL
      SELECT 3 FROM DUAL
      UNION ALL
      SELECT 4 FROM DUAL
      UNION ALL
      SELECT 5 FROM DUAL
      UNION ALL
      SELECT 6 FROM DUAL
      UNION ALL
      SELECT 7 FROM DUAL
      UNION ALL
      SELECT 8 FROM DUAL
      UNION ALL
      SELECT 9 FROM DUAL
      UNION ALL
      SELECT 10 FROM DUAL ;
This will produce the following output
+------------+
| ArrayValue |
+------------+
| 1          |
| 2          |
| 3          |
| 4          |
| 5          |
| 6          |
| 7          |
| 8          |
| 9          |
| 10         |
+------------+
10 rows in set (0.00 sec)
Python Program for Heap Sort

In this article, we will learn about the solution to the problem statement given below.
Problem statement − We are given an array, we need to sort it using the concept of heapsort.
Here we place the maximum element at the end. This is repeated until the array is sorted.
Now let’s observe the solution in the implementation below−
 Live Demo
# heapify
def heapify(arr, n, i):
   largest = i # largest value
   l = 2 * i + 1 # left
   r = 2 * i + 2 # right
   # if left child exists
   if l < n and arr[i] < arr[l]:
      largest = l
   # if right child exits
   if r < n and arr[largest] < arr[r]:
      largest = r
   # root
   if largest != i:
      arr[i],arr[largest] = arr[largest],arr[i] # swap
      # root.
      heapify(arr, n, largest)
# sort
def heapSort(arr):
   n = len(arr)
   # maxheap
   for i in range(n, -1, -1):
      heapify(arr, n, i)
   # element extraction
   for i in range(n-1, 0, -1):
      arr[i], arr[0] = arr[0], arr[i] # swap
      heapify(arr, i, 0)
# main
arr = [2,5,3,8,6,5,4,7]
heapSort(arr)
n = len(arr)
print ("Sorted array is")
for i in range(n):
   print (arr[i],end=" ")
Sorted array is
2 3 4 5 5 6 7 8
All the variables are declared in the local scope and their references are seen in the figure above.
In this article, we have learned about how we can make a Python Program for Heap Sort
SQLAlchemy Core - Multiple Table Deletes

In this chapter, we will look into the Multiple Table Deletes expression which is similar to using Multiple Table Updates function.
More than one table can be referred in WHERE clause of DELETE statement in many DBMS dialects. For PG and MySQL, “DELETE USING” syntax is used; and for SQL Server, using “DELETE FROM” expression refers to more than one table. The SQLAlchemy delete() construct supports both of these modes implicitly, by specifying multiple tables in the WHERE clause as follows −
stmt = users.delete().\
   where(users.c.id == addresses.c.id).\
   where(addresses.c.email_address.startswith('xyz%'))
conn.execute(stmt)
On a PostgreSQL backend, the resulting SQL from the above statement would render as −
DELETE FROM users USING addresses
WHERE users.id = addresses.id
AND (addresses.email_address LIKE %(email_address_1)s || '%%')
If this method is used with a database that doesn’t support this behaviour, the compiler will raise NotImplementedError.

    21 Lectures 
     1.5 hours 

 Jack Chan
 Print
 Add Notes
 Bookmark this page
Tk - Basic Widgets

Basic widgets are common widgets available in almost all Tk applications. The list of available basic widgets is given below −
Widget for displaying single line of text.
Widget that is clickable and triggers an action.
Widget used to accept a single line of text as input.
Widget for displaying multiple lines of text.
Widget for displaying and optionally edit multiple lines of text.
Widget used to create a frame that is a new top level window.
A simple Tk example is shown below using basic widgets −
#!/usr/bin/wish

grid [label .myLabel -text "Label Widget" -textvariable labelText] 
grid [text .myText -width 20 -height 5]
.myText insert 1.0 "Text\nWidget\n"
grid [entry .myEntry -text "Entry Widget"]
grid [message .myMessage -background red -foreground white -text "Message\nWidget"]
grid [button .myButton1  -text "Button" -command "set labelText clicked"]
When we run the above program, we will get the following output −
 Print
 Add Notes
 Bookmark this page
How do you get selenium to recognize that a page loaded?

We can get Selenium to recognize that a page is loaded. We can set the implicit wait for this purpose. It shall make the driver to wait for a specific amount of time for an element to be available after page loaded.
driver.manage().timeouts().implicitlyWait();
After the page is loaded, we can also invoke Javascript method document.readyState and wait till complete is returned.
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("return document.readyState").toString().equals("complete");
After this, verify if the URL matches the one we are looking for.
Code Implementation with implicit wait.
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 Pageload{
   public static void main(String[] args) {
      System.setProperty("webdriver.chrome.driver",
      "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      String url = "https://www.tutorialspoint.com/index.htm";
      driver.get(url);
      // wait of 12 seconds
      driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS);
      // identify element, enter text
      WebElement m=driver.findElement(By.id("gsc-i-id1"));
      m.sendKeys("Selenium");
   }
}
Code Implementation with Javascript Executor.
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.JavascriptExecutor;
public class PagaLoadJS{
   public static void main(String[] args) {
      System.setProperty("webdriver.chrome.driver",
      "C:\\Users\\ghs6kor\\Desktop\\Java\\chromedriver.exe");
      WebDriver driver = new ChromeDriver();
      String url = "https://www.tutorialspoint.com/index.htm";
      driver.get(url);
      // Javascript executor to return value
      JavascriptExecutor j = (JavascriptExecutor) driver;
      j.executeScript("return document.readyState")
      .toString().equals("complete");
      // get the current URL
      String s = driver.getCurrentUrl();
      // checking condition if the URL is loaded
      if (s.equals(url)) {
         System.out.println("Page Loaded");
         System.out.println("Current Url: " + s);
      }
      else {
         System.out.println("Page did not load");
      }
      driver.quit();
   }
}
DAX Statistical - PERCENTILEX.EXC function

Returns the percentile number of an expression evaluated for each row in a table.
DAX PERCENTILEX.EXC function is new in Excel 2016.
PERCENTILEX.EXC (<table>, <expression>, <k>) 

table
The table containing the rows for which the expression will be evaluated.
expression
The expression to be evaluated for each row of the table.
k
A number, 0 < k < 1.
The percentile number of an expression evaluated for each row in a table.
If k <= zero, or k >= 1, then it is out of range and an error is returned.
If k <= zero, or k >= 1, then it is out of range and an error is returned.
If k is non-numeric, an error is returned.
If k is non-numeric, an error is returned.
If k is blank, percentile rank of 1 / (n+1) returns the smallest value.
If k is blank, percentile rank of 1 / (n+1) returns the smallest value.
If k is not a multiple of 1 / (n + 1), PERCENTILEX.EXC will interpolate to determine the value at the kth percentile.
If k is not a multiple of 1 / (n + 1), PERCENTILEX.EXC will interpolate to determine the value at the kth percentile.
PERCENTILEX.EXC will interpolate when the value for the specified percentile is between two values in the array. If it cannot interpolate for the k percentile specified, an error is returned.
= PERCENTILEX.EXC (Sales,Sales[Sales Amount],0.25) 

    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
Bootstrap alert-success class

The .alert-success class in Bootstrap indicates a positive action.
You can try to run the following code to implement the alert-success class in Bootstrap −
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>
      <div class = "alert alert-success alert-dismissable">
         <button type = "button" class = "close" data-dismiss = "alert" aria-hidden = "true">
            ×
         </button>
         Success!
      </div>
   </body>
</html>
Sorting a vector of custom objects using C++ STL

You can sort a vector of custom objects using the C++ STL function std::sort. The sort function has an overloaded form that takes as arguments first, last, comparator. The first and last are iterators to first and last elements of the container. The comparator is a predicate function that can be used to tell how to sort the container. 
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;
struct MyStruct {
   int key;
   string data;
   MyStruct(int key, string data) {
      this -> key = key;
      this -> data = data;
   }
};
int main() {
   std::vector<MyStruct> vec;
   vec.push_back(MyStruct(4, "test"));
   vec.push_back(MyStruct(2, "is"));
   vec.push_back(MyStruct(3, "a"));
   vec.push_back(MyStruct(1, "this"));
   
   // Using lambda expressions in C++11
   sort(vec.begin(), vec.end(), [](const MyStruct& lhs, const MyStruct& rhs) {
      return lhs.key < rhs.key;
   });
   for(auto it = vec.begin(); it != vec.end(); it++) {
      cout << it -> data << endl;
   }
}
This will give the output −
this is a test
If you're working on older C++ versions, you can pass a function reference as well −
//define the function:
bool comparator(const MyStruct& lhs, const MyStruct& rhs) {
   return lhs.key < rhs.key;
}
// pass it to sort:
sort(vec.begin(), vec.end(), &comparator);
You can also overload the < operator in the class/struct and use the sort(first, last) form directly. So when sorting, it will take this function to compare the items.
Pointer to an Array in Objective-C

It is most likely that you would not understand this chapter until you are through the chapter related to Pointers in Objective-C.
So assuming you have a bit understanding on pointers in Objective-C programming language, let us start: An array name is a constant pointer to the first element of the array. Therefore, in the declaration −
double balance[50];
balance is a pointer to &balance[0], which is the address of the first element of the array balance. Thus, the following program fragment assigns p the address of the first element of balance −
double *p;
double balance[10];

p = balance;
It is legal to use array names as constant pointers, and vice versa. Therefore, *(balance + 4) is a legitimate way of accessing the data at balance[4].
Once you store the address of first element in p, you can access array elements using *p, *(p+1), *(p+2) and so on. Below is the example to show all the concepts discussed above −
#import <Foundation/Foundation.h>

int main () {
   
   /* an array with 5 elements */
   double balance[5] = {1000.0, 2.0, 3.4, 17.0, 50.0};
   double *p;
   int i;

   p = balance;
 
   /* output each array element's value */
   NSLog( @"Array values using pointer\n");
   for ( i = 0; i < 5; i++ ) {
      NSLog(@"*(p + %d) : %f\n",  i, *(p + i) );
   }

   NSLog(@"Array values using balance as address\n");
   for ( i = 0; i < 5; i++ ) {
      NSLog(@"*(balance + %d) : %f\n",  i, *(balance + i) );
   }
 
   return 0;
}
When the above code is compiled and executed, it produces the following result −
2013-09-14 01:36:57.995 demo[31469] Array values using pointer
2013-09-14 01:36:57.995 demo[31469] *(p + 0) : 1000.000000
2013-09-14 01:36:57.995 demo[31469] *(p + 1) : 2.000000
2013-09-14 01:36:57.995 demo[31469] *(p + 2) : 3.400000
2013-09-14 01:36:57.995 demo[31469] *(p + 3) : 17.000000
2013-09-14 01:36:57.995 demo[31469] *(p + 4) : 50.000000
2013-09-14 01:36:57.995 demo[31469] Array values using balance as address
2013-09-14 01:36:57.995 demo[31469] *(balance + 0) : 1000.000000
2013-09-14 01:36:57.995 demo[31469] *(balance + 1) : 2.000000
2013-09-14 01:36:57.995 demo[31469] *(balance + 2) : 3.400000
2013-09-14 01:36:57.995 demo[31469] *(balance + 3) : 17.000000
2013-09-14 01:36:57.995 demo[31469] *(balance + 4) : 50.000000

In the above example, p is a pointer to double, which means it can store address of a variable of double type. Once we have address in p, then *p will give us value available at the address stored in p, as we have shown in the above example.

    18 Lectures 
     1 hours 

 PARTHA MAJUMDAR

    6 Lectures 
     25 mins

 Ken Burke
 Print
 Add Notes
 Bookmark this page
Bokeh - Plot Tools

When a Bokeh plot is rendered, normally a tool bar appears on the right side of the figure. It contains a default set of tools. First of all, the position of toolbar can be configured by toolbar_location property in figure() function. This property can take one of the following values −
"above"
"below"
"left"
"right"
"None"
For example, following statement will cause toolbar to be displayed below the plot −
Fig = figure(toolbar_location = "below")
This toolbar can be configured according to the requirement by adding required from various tools defined in bokeh.models module. For example −
Fig.add_tools(WheelZoomTool())
The tools can be classified under following categories −
Pan/Drag Tools
Click/Tap Tools
Scroll/Pinch Tools
BoxSelectTool
Name : 'box_select'
LassoSelectTool
name: 'lasso_select
PanTool
name: 'pan', 'xpan', 'ypan',
TapTool
name: 'tap
WheelZoomTool
name: 'wheel_zoom', 'xwheel_zoom', 'ywheel_zoom'
WheelPanTool
name: 'xwheel_pan', 'ywheel_pan'
ResetTool
name: 'reset'
SaveTool
name: 'save'
ZoomInTool
name: 'zoom_in', 'xzoom_in', 'yzoom_in'
ZoomOutTool
name: 'zoom_out', 'xzoom_out', 'yzoom_out'
CrosshairTool
name: 'crosshair'
 Print
 Add Notes
 Bookmark this page
How to add binary numbers using Python?

If you have binary numbers as strings, you can convert them to ints first using int(str, base) by providing the base as 2. Then add the numbers like you'd normally do. Finally convert it back to a string using the bin function. For example,
a = '001'
b = '011'
sm = int(a,2) + int(b,2)
c = bin(sm)
print(c)
This will give the output:
0b100
How to hide a navigation menu on scroll down with CSS and JavaScript?

Following is the code for hiding navigation menu when scrolling using CSS and JavaScript −
 Live Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
body{
   margin:0px;
   margin-top:60px;
   padding: 0px;
}
nav{
   position: fixed;
   top: 0px;
   width: 100%;
   background-color: rgb(39, 39, 39);
   overflow: auto;
   height: auto;
   transition: 0.5s;
}
.links {
   display: inline-block;
   text-align: center;
   padding: 14px;
   color: rgb(178, 137, 253);
   text-decoration: none;
   font-size: 17px;
}
.links:hover {
   background-color: rgb(100, 100, 100);
}
.selected{
   background-color: rgb(0, 18, 43);
}
.sample-content{
      height: 150vh;
}
</style>
</head>
<body>
<nav>
<a class="links selected" href="#">Home</a>
<a class="links" href="#"> Login</a>
<a class="links" href="#"> Register</a>
<a class="links" href="#"> Contact Us</a>
<a class="links" href="#">More Info</a>
</nav>
<div class="sample-content">
<h1>Here are some headers</h1>
<h2>Here are some headers</h2>
<h3>Here are some headers</h3>
<h4>Here are some headers</h4>
<h1>Here are some headers</h1>
<h2>Here are some headers</h2>
<h3>Here are some headers</h3>
<h4>Here are some headers</h4>
</div>
<script>
window.onscroll = scrollShowNav;
function scrollShowNav() {
   if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
      document.getElementsByTagName("nav")[0].style.top = "-50px";
   } else {
      document.getElementsByTagName("nav")[0].style.top = "0px";
   }
}
</script>
</body>
</html>
The above code will produce the following output −
On scrolling down the navbar will disappear as follows −
Split a column after hyphen in MySQL and display the remaining value?

To split a column after hyphen, use the SUBSTRING_INDEX() method −
select substring_index(yourColumnName,'-',-1) AS anyAliasName from yourTableName;
Let us first create a table −
mysql> create table DemoTable
   -> (
   -> StreetName text
   -> );
Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Paris Hill St.-CA-83745646') ;
Query OK, 1 row affected (0.32 sec)

mysql> insert into DemoTable values('502 South Armstrong Street-9948443');
Query OK, 1 row affected (0.20 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------------------------------+
| StreetName                         |
+------------------------------------+
| Paris Hill St.-CA-83745646         |
| 502 South Armstrong Street-9948443 |
+------------------------------------+
2 rows in set (0.00 sec)
Following is the query to split a column after specific characters −
mysql> select substring_index(StreetName,'-',-1) AS Split from DemoTable;
This will produce the following output −
+----------+
| Split    |
+----------+
| 83745646 |
| 9948443  |
+----------+
2 rows in set (0.00 sec)