code-rag-bench/online-tutorials huggingface dataset:
Compress String in C++

Suppose we have a string s, we have to eliminate consecutive duplicate characters from the given string and return it. So, if a list contains consecutive repeated characters, they should be replaced with a single copy of the character. The order of the elements will be same as before.
So, if the input is like "heeeeelllllllloooooo", then the output will be "helo"
To solve this, we will follow these steps −
ret := a blank string
ret := a blank string
for initialize i := 0, when i < size of s, update (increase i by 1), do −if size of ret is non-zero and last element of ret is same as s[i], then −Ignore following part, skip to the next iterationret := ret concatenate s[i]
for initialize i := 0, when i < size of s, update (increase i by 1), do −
if size of ret is non-zero and last element of ret is same as s[i], then −Ignore following part, skip to the next iteration
if size of ret is non-zero and last element of ret is same as s[i], then −
Ignore following part, skip to the next iteration
Ignore following part, skip to the next iteration
ret := ret concatenate s[i]
ret := ret concatenate s[i]
return ret
return ret
Let us see the following implementation to get better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
class Solution {
   public:
   string solve(string s) {
      string ret = "";
      for(int i = 0; i < s.size(); i++){
         if(ret.size() && ret.back() == s[i]){
            continue;
         }
         ret += s[i];
      }
      return ret;
   }
};
int main(){
   Solution ob;
   cout << (ob.solve("heeeeelllllllloooooo"));
}
"heeeeelllllllloooooo"
helo
How to update an image in a Tkinter Canvas?

Canvas can be used to play with images, animating objects, 3D modeling, displaying text, and many more. Moreover, we can display an image file using the create_image() constructor.
Following this, let us build an application that can update the canvas images locally. We can add a button to trigger the event which when pressed will change the canvas image.
To change a particular image, we can configure the canvas by using the itemconfig() constructor. It takes image files which need to be updated and displayed them on the window.
Use three images of your choice and save them in the same project directory.
#Import the required library
from tkinter import *
from tkinter import ttk
from PIL import Image, ImageTk
#Create an instance of tkinter frame
win= Tk()
#Set the geometry
win.geometry("750x400")
#Define function to update the image
def update_image():
   canvas.itemconfig(image_container,image=img2)
#Create a canvas and add the image into it
canvas= Canvas(win, width=650, height= 350)
canvas.pack()
#Create a button to update the canvas image
button= ttk.Button(win, text="Update",
command=lambda:update_image())
button.pack()
#Open an Image in a Variable
img1= PhotoImage(file="logo.png")
img2= PhotoImage(file="logo2.png")
img3= PhotoImage(file="logo3.png")
#Add image to the canvas
image_container =canvas.create_image(0,0, anchor="nw",image=img1)
win.mainloop()
Running the above code will display a window with a canvas and a button to update the canvas image.
Now, click the "Update Image" button to update the canvas Image.
Powershell - Read HTML File

Get-Content cmdlet is used to read content of a html file.
In this example, we're reading content of test.html.
Get-Content D:\temp\test\test.html 

You can see following output in PowerShell console.
<html>Welcome to TutorialsPoint</html>


    15 Lectures 
     3.5 hours 

 Fabrice Chrzanowski

    35 Lectures 
     2.5 hours 

 Vijay Saini

    145 Lectures 
     12.5 hours 

 Fettah Ben
 Print
 Add Notes
 Bookmark this page
Abstraction in C++

Abstraction involves providing only the pertinent information to the outside world and hiding the background details. It relies on the separation of interface and implementation for programming.
Classes provide abstraction in C++. They provide public methods for the outside world to manipulate data and keep the rest of the class structure to themselves. So the users can use the class as required without knowing how it has been implemented internally.
A program to implement abstraction in C++ using classes is given as follows.
 Live Demo
#include <iostream>
using namespace std;
class Abstraction {
   private:
   int length, breadth;
   public:
   void setValues(int l, int b) {
      length = l;
      breadth = b;
   }
   void calcArea() {
      cout<<"Length = " << length << endl;
      cout<<"Breadth = " << breadth << endl;
      cout<<"Area = " << length*breadth << endl;
   }
};
int main() {
   Abstraction obj;
   obj.setValues(5, 20);
   obj.calcArea();
   return 0;
}
Length = 5
Breadth = 20
Area = 100
In the above program, the length and breadth in class Abstraction are private variables. There are public functions that initialize these variables and also calculate the area by multiplying length and breath. Hence, this class demonstrates abstraction. The code snippet for this is as follows.
class Abstraction {
   private:
   int length, breadth;
   public:
   void setValues(int l, int b) {
      length = l;
      breadth = b;
   }
   void calcArea() {
      cout<<"Length = " << length << endl;
      cout<<"Breadth = " << breadth << endl;
      cout<<"Area = " << length*breadth << endl;
   }
};
In the function main(), first an object of type Abstraction is defined. Then the function setValues() is called with the values 5 and 20. Finally, these values and the area are displayed using the function calcArea(). The code snippet for this is as follows.
Abstraction obj;
obj.setValues(5, 20);
obj.calcArea();
Convert a nested list into a flat list in Python

A nested list is a list whose elements are lists themselves. If we have a python data container which is a nested list, we may sometimes need to convert it into a flattened list so that each element can be processed further.
Even the inner elements can also be nested themselves. And there can be many layers of nesting. So we will approach this problem with recursion. We will keep checking if the element is nested and then keep going applying the function again and again until the element is no longer a list. Once it is found that element is not a list, we will append it to a new list which will hold all the non-nested elements of the list.
 Live Demo
listA = [[43, [0]],12, 19, [13,[8, 8]], 21 ]
print('Given nested list: \n', listA)
# Flat List
res = []
# function
def flatlist(l):
   for x in l:
      if type(x) == list:
         flatlist(x)
      else:
         res.append(x)
flatlist(listA)
print('Flattened List created: \n', res)
Running the above code gives us the following result −
Given nested list:
[[43, [0]], 12, 19, [13, [8, 8]], 21]
Flattened List created:
[43, 0, 12, 19, 13, 8, 8, 21]
Find the largest number in a series by using pointers in C language

Pointer is a variable that stores the address of another variable. We can hold the null values by using pointer. It can be accessed by using pass by reference. Also, there is no need of initialization, while declaring the variable.
The syntax for pointer is as follows −
pointer variable= & another variable;
For example,
p =&a;
Refer an algorithm given below for finding the largest number in a series with the help of pointers.
Step 1: Start
Step 2: Declare integer variables
Step 3: Declare pointer variables
Step 4: Read 3 numbers from console
Step 5: Assign each number address to pointer variable
Step 6: if *p1 > *p2if *p1 > *p3print p1 is largeelseprint p2 is largeStep 7: Else if *p2 > *p3
Print p2 is large
Else
Print p3 is large
Step 8: Stop
if *p1 > *p3print p1 is large
print p1 is large
elseprint p2 is large
print p2 is large
Following is the C program to find the largest number in a series by using pointers −
 Live Demo
#include <stdio.h>
int main(){
   int num1, num2, num3;
   int *p1, *p2, *p3;
   printf("enter 1st no: ");
   scanf("%d",&num1);
   printf("enter 2nd no: ");
   scanf("%d",&num2);
   printf("enter 3rd no: ");
   scanf("%d",&num3);
   p1 = &num1;
   p2 = &num2;
   p3 = &num3;
   if(*p1 > *p2){
      if(*p1 > *p3){
         printf("%d is largest ", *p1);
      }else{
         printf("%d is largest ", *p3);
      }
   }else{
      if(*p2 > *p3){
         printf("%d is largest ", *p2);
      }else{
         printf("%d is largest ", *p3);
      }
   }
   return 0;
}
When the above program is executed, it produces the following result −
Run 1:
enter 1st no: 35
enter 2nd no: 75
enter 3rd no: 12
75 is largest
Run 2:
enter 1st no: 53
enter 2nd no: 69
enter 3rd no: 11
69 is largest
Dart Programming - Map Property Length

Returns the size of the Map.
Map.length 

void main() {
   var details = {'Usrname':'tom','Password':'pass@123'};
   print(details.length);
}
It will produce the following output −
2


    44 Lectures 
     4.5 hours 

 Sriyank Siddhartha

    34 Lectures 
     4 hours 

 Sriyank Siddhartha

    69 Lectures 
     4 hours 

 Frahaan Hussain

    117 Lectures 
     10 hours 

 Frahaan Hussain

    22 Lectures 
     1.5 hours 

 Pranjal Srivastava

    34 Lectures 
     3 hours 

 Pranjal Srivastava
 Print
 Add Notes
 Bookmark this page
What are the allowed characters in Python function names? - GeeksforGeeks

22 Jun, 2021
The user-defined names that are given to Functions or variables are known as Identifiers. It helps in differentiating one entity from another and also serves as a definition of the use of that entity sometimes. As in every programming language, there are some restrictions/ limitations for Identifiers. So, is the case with Python, we need to take care of the following points before using an Identifier.
Rules for writing Identifiers:
The first and foremost restriction is that Identifiers cannot be the same as Keywords. There are special reserved keywords in every programming language that has its own meaning and these names can’t be used as Identifiers in Python.
Python3
# Python program to demonstrate# that keywords cant be used as# identifiers def calculate_sum(a, b):  return a + b x = 2y = 5print(calculate_sum(x,y)) # def and if is a keyword, so# this would give invalid# syntax errordef = 12  if = 2      print(calculate_sum(def, if))
 
 
Output:
 
 File "/home/9efd6943df820475cf5bc74fc4fcc3aa.py", line 15
    def = 12   
        ^
SyntaxError: invalid syntax
An identifier in Python cannot use any special symbols like !, @, #, $, % etc.
 
Python3
# Python code to demonstrate# that we can't use special# character like !,@,#,$,%.etc# as identifier # valid identifiervar1 = 46 var2 = 23 print(var1 * var2) # invalid identifier,# will give invalid syntax errorvar@ = 12 $var = 55 print(var@ * $var) # even function names can't# have special charactersdef my_function%():  print('This is a function with invalid identifier')   my_function%()
Output:
File "/home/3ae3b1299ee9c1c04566e45e98b13791.py", line 13
    var@ = 12  
         ^
SyntaxError: invalid syntax
Apart from these restrictions, Python allows Identifiers to be a combination of lowercase letters (a to z) or uppercase letters (A to Z) or digits (0 to 9) or an underscore (_). But variable name must not be started with digits. Names like myClass, var_3, and print_to_screen, are valid examples.
Python3
# Python program to demonstrate# some examples of valid identifiers var1 = 101ABC = "This is a string"fr12 = 20x_y = 'GfG'slp__72 = ' QWERTY' print(var1 * fr12) print(ABC + slp__72)
Output:
2020
This is a string QWERTY
anikaseth98
Python function-programs
Python-Functions
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
How to Install PIP on Windows ?
How to drop one or multiple columns in Pandas Dataframe
Selecting rows in pandas DataFrame based on conditions
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | os.path.join() method
Python | Get unique values from a list
Create a directory in Python
Defaultdict in Python
Python | Pandas dataframe.groupby()
Why do we need a pure virtual destructor in C++?

There are no ill-effects of allowing a pure virtual destructor in C++ program. It is must to provide a function body for pure virtual destructor as derived class’s destructor is called first before the base class destructor, so if we do not provide a function body, it will find out nothing to be called during object destruction and error will occur. We can make easily an abstract class by making a pure virtual destructor with its definition.
 Live Demo
#include <iostream>
using namespace std;

class B {
   public: virtual ~B()=0; // Pure virtual destructor
};

B::~B() {
   cout << "Pure virtual destructor is called";
}

class D : public B {
   public: ~D() {
   cout << "~Derived\n";
   }
};

int main() {
   B *b = new D();
   delete b;
   return 0;
}
~Derived
Pure virtual destructor is called
Python | Pandas Timestamp.month

08 Jan, 2019
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier.
Pandas Timestamp.month attribute is used to find the month value in the given Timestamp object.
Syntax : Timestamp.month
Parameters : None
Return : month
Example #1: Use Timestamp.month attribute to find the month value in the given Timestamp object.
# importing pandas as pdimport pandas as pd  # Create the Timestamp objectts = pd.Timestamp(2016, 1, 1, 12, 25, 16, 28)  # Print the Timestamp objectprint(ts)
Output :
Now we will use the Timestamp.month attribute to print the value of month in ts object.
# find the value of month ts.month
Output :
As we can see in the output, the Timestamp.month attribute has returned 1 indicating that the value of month in the ts object is set to 1. Example #2: Use Timestamp.month attribute to find the month value in the given Timestamp object.
# importing pandas as pdimport pandas as pd  # Create the Timestamp objectts = pd.Timestamp(year = 2009, month = 5, day = 31, hour = 4,                       microsecond = 15, tz = 'Europe/Berlin')  # Print the Timestamp objectprint(ts)
Output :
Now we will use the Timestamp.month attribute to print the value of month in ts object.
# find the value of month ts.month
Output :
As we can see in the output, the Timestamp.month attribute has returned 5 indicating that the value of month in the ts object is set to 5.
Python Pandas-Timestamp
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
PLSQL | GREATEST Function - GeeksforGeeks

15 Oct, 2019
The GREATEST is an inbuilt function in PLSQL which is used to return the greatest value from a given list of some expressions. These expressions may be numbers, alphabets etc.
Syntax:
GREATEST(exp1, exp2, ... exp_n)
Parameters Used:This function accept some parameters like exp1, exp2, ... exp_n. These each expression may be numbers or alphabets on which GREATEST() function is called.
Return Value:This function returns the greatest value from a given list of expressions.
Supported Versions of Oracle/PLSQL is given below:
Oracle 12cOracle 11gOracle 10gOracle 9iOracle 8i
Oracle 12c
Oracle 11g
Oracle 10g
Oracle 9i
Oracle 8i
Let’s see some examples which illustrate the GREATEST function:
Example-1:
DECLARE 
   Test_Number number1 := 1;
   Test_Number number2 := 2;
   Test_Number number3 := 5;
   Test_Number number4 := 30;
   
BEGIN 
   dbms_output.put_line(GREATEST(Test_Number number1, 
                                 Test_Number number2, 
                                 Test_Number number3, 
                                 Test_Number number4)); 
   
END; 
Output:
30
In the above example, some list of numbers is taken as the parameter out of which greatest number is returned as the output. for example, 1, 2, 5 and 30 is taken as the parameter out of which 30 is returned because it is the greatest number.
Example-2:
DECLARE 
   Test_Number number1 := 'a';
   Test_Number number2 := 'b';
   Test_Number number3 := 'c';
   
BEGIN 
   dbms_output.put_line(GREATEST(Test_Number number1, 
                                 Test_Number number2, 
                                 Test_Number number3)); 
   
END;
Output:
c
In the above example, some list of alphabets is taken as the parameter out of which greatest in count alphabet is returned as the output. for example, a, b and c is taken as the parameter out of which c is returned because it is the greatest in the count.
Example-3:
DECLARE 
   Test_Number number1 := 0;
   Test_Number number2 := -4;
   Test_Number number3 := 0.6;
   
BEGIN 
   dbms_output.put_line(GREATEST(Test_Number number1, 
                                 Test_Number number2, 
                                 Test_Number number3)); 
   
END; 
Output:
0.6
In the above example, some list of numbers is taken as the parameter out of which greatest number is returned as the output. for example, 0, -4 and 0.6 is taken as the parameter out of which 0.6 is returned because it is the greatest number.
Advantage:This function is used to find the greatest expression out of the given input expressions. This expression might be any numbers or alphabets.
SQL-PL/SQL
SQL
SQL
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
CTE in SQL
Difference between DELETE, DROP and TRUNCATE
How to Update Multiple Columns in Single Update Statement in SQL?
Difference between SQL and NoSQL
Difference between DDL and DML in DBMS
SQL Interview Questions
What is Temporary Table in SQL?
SQL Query to Find the Name of a Person Whose Name Starts with Specific Letter
Difference between Where and Having Clause in SQL
SQL - ORDER BY
C Language | Set 2 - GeeksforGeeks

27 Mar, 2017
Following questions have been asked in GATE CS exam.
1. Consider the following C program segment:
char p[20];char *s = "string";int length = strlen(s);int i;for (i = 0; i < length; i++)     p[i] = s[length — i];printf("%s",p);
The output of the program is (GATE CS 2004)a) gnirtsb) gnirtc) stringd) no output is printed
Answer(d)Let us consider below line inside the for loopp[i] = s[length — i];For i = 0, p[i] will be s[6 — 0] and s[6] is ‘\0’So p[0] becomes ‘\0’. It doesn’t matter what comes in p[1], p[2]..... as P[0] will not change for i >0. Nothing is printed if we print a string with first character ‘\0’
2. Consider the following C function
void swap (int a, int b){   int temp;   temp = a;   a = b;   b = temp;}
In order to exchange the values of two variables x and y. (GATE CS 2004)
a) call swap (x, y)b) call swap (&x, &y)c) swap (x,y) cannot be used as it does not return any valued) swap (x,y) cannot be used as the parameters are passed by value
Answer(d)Why a, b and c are incorrect?a) call swap (x, y) will not cause any effect on x and y as parameters are passed by value.b) call swap (&x, &y) will no work as function swap() expects values not addresses (or pointers).c) swap (x, y) cannot be used but reason given is not correct.
3. Consider the following C function:
int f(int n){   static int i = 1;   if (n >= 5)      return n;   n = n+i;   i++;   return f(n);}
The value returned by f(1) is (GATE CS 2004)a) 5b) 6c) 7d) 8
Answer (c)Since i is static, first line of f() is executed only once.
Execution of f(1) 
    i = 1
    n = 2
    i = 2
 Call f(2) 
    i = 2
    n = 4
    i = 3
 Call f(4) 
   i = 3
   n = 7
   i = 4
 Call f(7)
  since n >= 5 return n(7)

4. Consider the following program fragment for reversing the digits in a given integer to obtain a new integer. Let n = D1D2...Dm
int n, rev;rev = 0;while (n > 0) {   rev = rev*10 + n%10;   n = n/10;}
The loop invariant condition at the end of the ith iteration is:(GATE CS 2004)
a) n = D1D2....Dm-i and rev = DmDm-1...Dm-i+1b) n = Dm-i+1...Dm-1Dm and rev = Dm-1....D2D1c) n ≠ revd) n = D1D2....Dm and rev = DmDm-1...D2D1
Answer (a)
5. Consider the following C program
main(){   int x, y, m, n;   scanf ("%d %d", &x, &y);   /* x > 0 and y > 0 */   m = x; n = y;   while (m != n)   {       if(m>n)         m = m - n;      else         n = n - m;   }   printf("%d", n);}
The program computes (GATE CS 2004)a) x + y using repeated subtractionb) x mod y using repeated subtractionc) the greatest common divisor of x and yd) the least common multiple of x and y
Answer(c)This is an implementation of Euclid’s algorithm to find GCD
GATE-CS-2004
GATE-CS-C-Language
GATE CS
MCQ
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Differences between TCP and UDP
Data encryption standard (DES) | Set 1
Introduction of Operating System - Set 1
Types of Network Topology
Inter Process Communication (IPC)
Data Structures and Algorithms | Set 21
Practice questions on Height balanced/AVL Tree
Operating Systems | Set 1
Computer Networks | Set 1
Computer Networks | Set 2
Sum of the first N Prime numbers

The program to print the sum of the first N prime numbers uses the method to find n
prime numbers and then add them to find the sum. This sum is saved to an integer that
outputs the sum .
The code takes a number checks it for prime, if it is prime then adds it to the sum variable. Till n prime number it does the same and then after that it prints the sum.
 Live Demo
#include <stdio.h>
int isprime(int j) {
   int count=0;
   for(int i = 2 ; i <= j/2; i++) {
      if(j%i == 0) {
         count = 1;
      }
   }
   if(count == 0) {
      return 1;
   }
   else
      return 0;
}
int main(void) {
   int n = 5;
   int i=0, j= 1;
   int sum = 0;
   while(1) {
      j++;
      if(isprime(j)) {
         sum += j;
         i++;
      }
      if(i == n) {
         break;
      }
   }
   printf("The sum of first %d prime numbers is %d", n, sum);
   return 0;
}
The sum of the first 5 prime numbers is 28
Prototype - remove() Method

This method completely removes element from the document and returns it.
element.remove();

Returns removed HTML element.
<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "/javascript/prototype.js"></script>
      
      <script>
         function showResult() {
            var str = $('mutsu').remove();
            alert("Value of str : " + str.innerHTML );

            var str = $('ida-red').remove();
            alert("Value of str : " + str.innerHTML );
         }
      </script>
   </head>

   <body>
      <p>Click the button to see the result.</p>
      
      <ul>
         <li id = "golden-delicious">Golden Delicious</li>
         <li id = "mutsu">Mutsu</li>
         <li id = "mcintosh">McIntosh</li>
         <li id = "ida-red">Ida Red</li>
      </ul>
      
      <input type = "button" value = "Show Result" onclick = "showResult();"/>
   </body>
</html>
Click the button to see the result.
Golden Delicious
Mutsu
McIntosh
Ida Red

    127 Lectures 
     11.5 hours 

 Aleksandar Cucukovic
 Print
 Add Notes
 Bookmark this page
deque resize() function in C++ STL - GeeksforGeeks

30 Aug, 2018
The deque::resize() is an inbuilt function in C++ STL which changes the size of the deque.If the given size is greater than the current size, then new elements are inserted at the end of the deque.If the given size is smaller than the current size, then extra elements are destroyed.
Syntax:
deque_name.resize(n)
Parameter: The function accepts only one mandatory parameter n which specifies the size of the deque.
Return value: The function does not return anything.
Below program illustrates the above function:
Program 1:
// C++ program to illustrate the// deque::resize() function#include <bits/stdc++.h>using namespace std;  int main(){    deque<int> dq = { 10, 20, 30, 40, 50 };      cout << "Size before resize " << dq.size() << "\n";      // Prints the deque elements    cout << "The contents of deque :";    for (auto it = dq.begin(); it != dq.end(); ++it)        cout << *it << " ";      cout << endl;      // resize to 7    dq.resize(7);      // // Prints the deque elements after resize()    cout << "Size after resize " << dq.size() << "\n";      cout << "The contents of deque :";    for (auto it = dq.begin(); it != dq.end(); ++it)        cout << *it << " ";      return 0;}
Size before resize 5
The contents of deque :10 20 30 40 50 
Size after resize 7
The contents of deque :10 20 30 40 50 0 0

Program 2:
// C++ program to illustrate the// deque::resize() function#include <bits/stdc++.h>using namespace std;  int main(){    deque<int> dq = { 10, 20, 30, 40, 50 };      cout << "Size before resize " << dq.size() << "\n";      // Prints the deque elements    cout << "The contents of deque :";    for (auto it = dq.begin(); it != dq.end(); ++it)        cout << *it << " ";      cout << endl;      // resize to 3    dq.resize(3);      cout << "Size after resize " << dq.size() << "\n";      cout << "The contents of deque :";    for (auto it = dq.begin(); it != dq.end(); ++it)        cout << *it << " ";      return 0;}
Size before resize 5
The contents of deque :10 20 30 40 50 
Size after resize 3
The contents of deque :10 20 30

Time Complexity: O(N)
cpp-deque
CPP-Functions
STL
C++
STL
CPP
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Map in C++ Standard Template Library (STL)
Inheritance in C++
C++ Classes and Objects
Constructors in C++
Bitwise Operators in C/C++
Socket Programming in C/C++
Operator Overloading in C++
Copy Constructor in C++
Virtual Function in C++
vector erase() and clear() in C++
How to map the network drive using PowerShell?

You can map the network drive on the local and remote computers using several ways.
Using cmd command.
Using cmd command.
You can use the below command to map the network drive, here letter M, and the shared folder on the local computer.
net use M: "\\remoteshare\Shared Folder"

PS C:\WINDOWS\system32> net use M:
Local name        M:
Remote name       \\remoteshare\Shared Folder
Resource type     Disk
Status            OK
# Opens           1
# Connections     1
The command completed successfully.
To map on the remote computer.
Invoke-Command -ComputerName RemoteComputer -ScriptBlock{net use k: "\\remoteshare\shared"}

Using the New-PSDrive command.
Using the New-PSDrive command.
You can map a network drive using Powershell command New-PSDrive on local and remote computers both.
To map a drive on the local computer.
New-PSDrive -Name K -PSProvider FileSystem -Root \\remoteshare\shared -Persist
PS C:\WINDOWS\system32> Get-PSDrive -Name K

Name           Used (GB)     Free (GB) Provider      Root
----           ---------     --------- --------      ----
K                 318.16         47.24 FileSystem    \\remoteshare\shared


To map a drive on the remote computer.
Invoke-Command -ComputerName Remotecomputer -ScriptBlock {New-PSDrive -Name K -PSProvider FileSystem -Root \\remoteshare\shared -Persist}
DAX Information - CONTAINS function

Returns true if values for all referred columns exist, or are contained, in those columns. Otherwise, returns false.
CONTAINS (<table>, <columnName>, <value>, [<columnName>, <value>] ...) 

table
Any DAX expression that returns a table of data.
columnName
The name of a column, in a table.
It cannot be an expression.
value
Any DAX expression that returns a single scalar value.
The expression is to be evaluated exactly once and before it is passed as a parameter.
Value is what you find, if it exists or if contained in columnName.
TRUE or FALSE.
The parameters columnName and value must come in pairs. Otherwise, the function returns an error.
The parameters columnName and value must come in pairs. Otherwise, the function returns an error.
columnName must belong to the specified table, or to a table that is related to table.
columnName must belong to the specified table, or to a table that is related to table.
If columnName refers to a column in a related table, then it must be fully qualified. Otherwise, the function returns an error.
If columnName refers to a column in a related table, then it must be fully qualified. Otherwise, the function returns an error.
= CONTAINS (Results, [Country],"IND", [Medal],"Gold") 
This DAX formula returns TRUE, if there exists a Gold Medal for the Country India in the Results table. Otherwise, returns FALSE.

    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
Cloning in java - GeeksforGeeks

16 May, 2017
Object cloning means to create an exact copy of the original object.If a class needs to support cloning, it must implement java.lang.Cloneable interface and override clone() method from Object class. Syntax of the clone() method is :
protected Object clone() throws CloneNotSupportedException
If the object’s class doesn’t implement Cloneable interface then it throws an exception ‘CloneNotSupportedException’ . 
// Java code for cloning an object  class Test implements Cloneable{    int a;    int b;      // Parameterized constructor    Test(int a, int b)    {        this.a = a;        this.b = b;    }      // Method that calls clone()    Test cloning()    {        try        {            return (Test) super.clone();        }        catch(CloneNotSupportedException e)        {            System.out.println("CloneNotSupportedException is caught");            return this;        }    }}  class demo{    public static void main(String args[])    {        Test obj1 = new Test(1, 2);        Test obj2 = obj1.cloning();        obj1.a = 3;        obj1.b = 4;        System.out.println("Object2 is a clone of object1");        System.out.println("obj1.a = " + obj1.a + " obj1.b = " + obj1.b);        System.out.println("obj2.a = " + obj2.a + " obj2.b = " + obj2.b);    }}
Output :
Object2 is a clone of object1
obj1.a = 3 obj1.b = 4
obj2.a = 1 obj2.b = 2
 This article is published by Mehak Narang. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Java
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Hashtable in Java
Constructors in Java
Different ways of Reading a text file in Java
Comparator Interface in Java with Examples
Java Math random() method with Examples
HashMap containsKey() Method in Java
How to Create Array of Objects in Java?
Convert Double to Integer in Java
Iterating over ArrayLists in Java
Generating random numbers in Java
Java & MySQL - ResultSet

The SQL statements that read data from a database query, return the data in a result set. The SELECT statement is the standard way to select rows from a database and view them in a result set. The java.sql.ResultSet interface represents the result set of a database query.
A ResultSet object maintains a cursor that points to the current row in the result set.  The term "result set" refers to the row and column data contained in a ResultSet object.
The methods of the ResultSet interface can be broken down into three categories −
Navigational methods − Used to move the cursor around.
Navigational methods − Used to move the cursor around.
Get methods − Used to view the data in the columns of the current row being pointed by the cursor.
Get methods − Used to view the data in the columns of the current row being pointed by the cursor.
Update methods − Used to update the data in the columns of the current row. The updates can then be updated in the underlying database as well.
Update methods − Used to update the data in the columns of the current row. The updates can then be updated in the underlying database as well.
The cursor is movable based on the properties of the ResultSet. These properties are designated when the corresponding Statement that generates the ResultSet is created.
JDBC provides the following connection methods to create statements with desired ResultSet −
createStatement(int RSType, int RSConcurrency);
createStatement(int RSType, int RSConcurrency);
prepareStatement(String SQL, int RSType, int RSConcurrency);
prepareStatement(String SQL, int RSType, int RSConcurrency);
prepareCall(String sql, int RSType, int RSConcurrency);
prepareCall(String sql, int RSType, int RSConcurrency);
The first argument indicates the type of a ResultSet object and the second argument is one of two ResultSet constants for specifying whether a result set is read-only or updatable.
The possible RSType are given below. If you do not specify any ResultSet type, you will automatically get one that is TYPE_FORWARD_ONLY.
The possible RSConcurrency are given below. If you do not specify any Concurrency type, you will automatically get one that is CONCUR_READ_ONLY.
All our examples written so far can be written as follows, which initializes a Statement object to create a forward-only, read only ResultSet object −
try(
   Statement stmt = conn.createStatement(
      ResultSet.TYPE_FORWARD_ONLY,
      ResultSet.CONCUR_READ_ONLY);)
}
catch(Exception ex) {
   ....
}
finally {
   ....
}

    16 Lectures 
     2 hours 

 Malhar Lathkar

    19 Lectures 
     5 hours 

 Malhar Lathkar

    25 Lectures 
     2.5 hours 

 Anadi Sharma

    126 Lectures 
     7 hours 

  Tushar Kale

    119 Lectures 
     17.5 hours 

 Monica Mittal

    76 Lectures 
     7 hours 

 Arnab Chakraborty
 Print
 Add Notes
 Bookmark this page
How to repeat column values in R data frame by values in another column?

To repeat column values in R data frame by values in another column, we can follow the below steps −
First of all, create a data frame.
First of all, create a data frame.
Then, use rep function along with cbind function to repeat column values in the matrix by values in another column.
Then, use rep function along with cbind function to repeat column values in the matrix by values in another column.
Let’s create a data frame as shown below −
x<-1:10
y<-sample(1:5,10,replace=TRUE)
df<-data.frame(x,y)
df
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
    x y
1   1 1
2   2 5
3   3 5
4   4 5
5   5 3
6   6 2
7   7 1
8   8 2
9   9 3
10 10 3
Repeat a column values by values in another column
Using rep function along with cbind function to repeat column x values in the data frame df by values in column y −
x<-1:10
y<-sample(1:5,10,replace=TRUE)
df<-data.frame(x,y)
cbind(rep(df$x,times=df$y),rep(df$y,times=df$y))
     [,1] [,2]
[1,]   1   3
[2,]   1   3
[3,]   1   3
[4,]   2   5
[5,]   2   5
[6,]   2   5
[7,]   2   5
[8,]   2   5
[9,]   3   2
[10,]  3   2
[11,]  4   4
[12,]  4   4
[13,]  4   4
[14,]  4   4
[15,]  5   1
[16,]  6   4
[17,]  6   4
[18,]  6   4
[19,]  6   4
[20,]  7   1
[21,]  8   3
[22,]  8   3
[23,]  8   3
[24,]  9   1
[25,] 10   5
[26,] 10   5
[27,] 10   5
[28,] 10   5
[29,] 10   5
Arduino - Program Structure

In this chapter, we will study in depth, the Arduino program structure and we will learn more new terminologies used in the Arduino world. The Arduino software is open-source. The source code for the Java environment is released under the GPL and the C/C++ microcontroller libraries are under the LGPL.
Sketch − The first new terminology is the Arduino program called “sketch”.
Arduino programs can be divided in three main parts: Structure, Values (variables and constants), and Functions. In this tutorial, we will learn about the Arduino software program, step by step, and how we can write the program without any syntax or compilation error.
Let us start with the Structure. Software structure consist of two main functions −
Setup( ) function
Loop( ) function
Void setup ( ) {

}

PURPOSE − The setup() function is called when a sketch starts. Use it to initialize the variables, pin modes, start using libraries, etc. The setup function will only run once, after each power up or reset of the Arduino board.
PURPOSE − The setup() function is called when a sketch starts. Use it to initialize the variables, pin modes, start using libraries, etc. The setup function will only run once, after each power up or reset of the Arduino board.
INPUT −      -
INPUT −      -
OUTPUT −     -
OUTPUT −     -
RETURN −     -
RETURN −     -
Void Loop ( ) {

}

PURPOSE − After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.
PURPOSE − After creating a setup() function, which initializes and sets the initial values, the loop() function does precisely what its name suggests, and loops consecutively, allowing your program to change and respond. Use it to actively control the Arduino board.
INPUT −      -
INPUT −      -
OUTPUT −     -
OUTPUT −     -
RETURN −     -
RETURN −     -

    65 Lectures 
     6.5 hours 

 Amit Rana

    43 Lectures 
     3 hours 

 Amit Rana

    20 Lectures 
     2 hours 

 Ashraf Said

    19 Lectures 
     1.5 hours 

 Ashraf Said

    11 Lectures 
     47 mins

 Ashraf Said

    9 Lectures 
     41 mins

 Ashraf Said
 Print
 Add Notes
 Bookmark this page
C program to find the Euclidean distance between two points - GeeksforGeeks

04 Nov, 2021
Given four integers x1, y1, x2 and y2, which represents two coordinates (x1, y1) and (x2, y2) of a two-dimensional graph. The task is to find the Euclidean distance between these two points.
Euclidean distance between two points is the length of a straight line drawn between those two given points.
Examples: 
Input: x1, y1 = (3, 4)            x2, y2 = (7, 7)Output: 5
Input: x1, y1 = (3, 4)            x2, y2 = (4, 3)Output: 1.41421
Approach: Since the Euclidean distance is nothing but the straight line distance between two given points, therefore the distance formula derived from the Pythagorean theorem can be used. The formula for distance between two points (x1, y1) and (x2, y2) is We can get the above formula by simply applying the Pythagoras theorem 
 Below is the implementation of the above approach
C
// C program for the above approach  #include <math.h>#include <stdio.h>  // Function to calculate distancefloat distance(int x1, int y1, int x2, int y2){    // Calculating distance    return sqrt(pow(x2 - x1, 2)                + pow(y2 - y1, 2) * 1.0);}  // Driver Codeint main(){    printf("%.2f", distance(3, 4, 4, 3));    return 0;}
1.41
Time Complexity: O(1)Auxiliary Space: O(1)
C Programs
Mathematical
Mathematical
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
C Program to read contents of Whole File
Producer Consumer Problem in C
C program to find the length of a string
C / C++ Program for Dijkstra's shortest path algorithm | Greedy Algo-7
Regular expressions in C
Program for Fibonacci numbers
C++ Data Types
Write a program to print all permutations of a given string
Set in C++ Standard Template Library (STL)
Program to find GCD or HCF of two numbers
Changing Matplotlib subplot size/position after axes creation

To change subplot size or position after axes creation, we can take the following steps−
Create a new figure or activate an existing figure using figure() method.
Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot() method.
A grid layout to place subplots within a figure using GridSpec() class.
Set the position of the grid specs.
Set the subplotspec instance.
Add an '~.axes.Axes' to the figure as part of a subplot arrangement using add_subplot() method, with gridspec instance.
Adjust the padding between and around the subplots.
To display the figure, use show() method.
from matplotlib import pyplot as plt
from matplotlib import gridspec as gridspec
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
fig = plt.figure()
ax = fig.add_subplot(111)
gs = gridspec.GridSpec(3, 1)
ax.set_position(gs[0:2].get_position(fig))
ax.set_subplotspec(gs[0:2])
fig.add_subplot(gs[2])
fig.tight_layout()
plt.show()
Teradata - Primary Index

Primary index is used to specify where the data resides in Teradata. It is used to specify which AMP gets the data row. Each table in Teradata is required to have a primary index defined. If the primary index is not defined, Teradata automatically assigns the primary index. Primary index provides the fastest way to access the data. A primary may have a maximum of 64 columns.
Primary index is defined while creating a table. There are 2 types of Primary Indexes.
Unique Primary Index(UPI)
Non Unique Primary Index(NUPI)
If the table is defined to be having UPI, then the column deemed as UPI should not have any duplicate values. If any duplicate values are inserted, they will be rejected.
The following example creates the Salary table with column EmployeeNo as Unique Primary Index.
CREATE SET TABLE Salary ( 
   EmployeeNo INTEGER, 
   Gross INTEGER,  
   Deduction INTEGER, 
   NetPay INTEGER 
) 
UNIQUE PRIMARY INDEX(EmployeeNo);
If the table is defined to be having NUPI, then the column deemed as UPI can accept duplicate values.
The following example creates the employee accounts table with column EmployeeNo as Non Unique Primary Index. EmployeeNo is defined as Non Unique Primary Index since an employee can have multiple accounts in the table; one for salary account and another one for reimbursement account.
CREATE SET TABLE Employee _Accounts ( 
   EmployeeNo INTEGER, 
   employee_bank_account_type BYTEINT. 
   employee_bank_account_number INTEGER, 
   employee_bank_name VARCHAR(30), 
   employee_bank_city VARCHAR(30) 
) 
PRIMARY INDEX(EmployeeNo);
 Print
 Add Notes
 Bookmark this page
Design Patterns - Facade Pattern

Facade pattern hides the complexities of the system and provides an interface to the client using which the client can access the system. This type of design pattern comes under structural pattern as this pattern adds an interface to existing system to hide its complexities.
This pattern involves a single class which provides simplified methods required by client and delegates calls to methods of existing  system classes.
We are going to create a Shape interface and concrete classes implementing the Shape interface. A facade class ShapeMaker is defined as a next step.
ShapeMaker class uses the concrete classes to delegate user calls to these classes. FacadePatternDemo, our demo class, will use ShapeMaker class to show the results.
Create an interface.
Shape.java
public interface Shape {
   void draw();
}
Create concrete classes implementing the same interface.
Rectangle.java
public class Rectangle implements Shape {

   @Override
   public void draw() {
      System.out.println("Rectangle::draw()");
   }
}
Square.java
public class Square implements Shape {

   @Override
   public void draw() {
      System.out.println("Square::draw()");
   }
}
Circle.java
public class Circle implements Shape {

   @Override
   public void draw() {
      System.out.println("Circle::draw()");
   }
}
Create a facade class.
ShapeMaker.java
public class ShapeMaker {
   private Shape circle;
   private Shape rectangle;
   private Shape square;

   public ShapeMaker() {
      circle = new Circle();
      rectangle = new Rectangle();
      square = new Square();
   }

   public void drawCircle(){
      circle.draw();
   }
   public void drawRectangle(){
      rectangle.draw();
   }
   public void drawSquare(){
      square.draw();
   }
}
Use the facade to draw various types of shapes.
FacadePatternDemo.java
public class FacadePatternDemo {
   public static void main(String[] args) {
      ShapeMaker shapeMaker = new ShapeMaker();

      shapeMaker.drawCircle();
      shapeMaker.drawRectangle();
      shapeMaker.drawSquare();		
   }
}
Verify the output.
Circle::draw()
Rectangle::draw()
Square::draw()


    102 Lectures 
     10 hours 

 Arnab Chakraborty

    30 Lectures 
     3 hours 

 Arnab Chakraborty

    31 Lectures 
     4 hours 

 Arnab Chakraborty

    43 Lectures 
     1.5 hours 

 Manoj Kumar

    7 Lectures 
     1 hours 

 Zach Miller

    54 Lectures 
     4 hours 

 Sasha Miller
 Print
 Add Notes
 Bookmark this page
MVC Framework - Routing Engine

ASP.NET MVC Routing enables the use of URLs that are descriptive of the user actions and are more easily understood by the users. At the same time, Routing can be used to hide data which is not intended to be shown to the final user.
For example, in an application that does not use routing, the user would be shown the URL as http://myapplication/Users.aspx?id=1 which would correspond to the file Users.aspx inside myapplication path and sending ID as 1, Generally, we would not like to show such file names to our final user.
To handle MVC URLs, ASP.NET platform uses the routing system, which lets you create any pattern of URLs you desire, and express them in a clear and concise manner. Each route in MVC contains a specific URL pattern. This URL pattern is compared to the incoming request URL and if the URL matches this pattern, it is used by the routing engine to further process the request.
To understand the MVC routing, consider the following URL −
http://servername/Products/Phones

In the above URL, Products is the first segment and Phone is the second segment which can be expressed in the following format −
{controller}/{action} 

The MVC framework automatically considers the first segment as the Controller name and the second segment as one of the actions inside that Controller.
Note − If the name of your Controller is ProductsController, you would only mention Products in the routing URL. The MVC framework automatically understands the Controller suffix.
Routes are defined in the RouteConfig.cs file which is present under the App_Start project folder.
You will see the following code inside this file −
public class RouteConfig { 
   
   public static void RegisterRoutes(RouteCollection routes) { 
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}");  
      
      routes.MapRoute( 
         name: "Default", 
         url: "{controller}/{action}/{id}", 
         defaults: new { controller = "Home", action = "Index", 
            id = UrlParameter.Optional } 
      ); 
   } 
} 
This RegisterRoutes method is called by the Global.ascx when the application is started. The Application_Start method under Global.ascx calls this MapRoute function which sets the default Controller and its action (method inside the Controller class).
To modify the above default mapping as per our example, change the following line of code −
defaults: new { controller = "Products", action = "Phones", id = UrlParameter.Optional } 

This setting will pick the ProductsController and call the Phone method inside that. Similarly, if you have another method such as Electronics inside ProductsController, the URL for it would be −
http://servername/Products/Electronics 

    44 Lectures 
     4.5 hours 

 Kaushik Roy Chowdhury

    42 Lectures 
     18 hours 

 SHIVPRASAD KOIRALA

    57 Lectures 
     3.5 hours 

 University Code

    55 Lectures 
     4.5 hours 

 University Code

    40 Lectures 
     2.5 hours 

 University Code

    140 Lectures 
     9 hours 

 Bhrugen Patel
 Print
 Add Notes
 Bookmark this page