code-rag-bench/online-tutorials huggingface dataset:
Unix filename pattern matching in Python

Here we will see how we can get the UNIX shell style pattern matching techniques using Python. There is a module called fnmatch, which is used to do the work. This module is used to compare file name against a pattern, then returns True or False according to the matches.
To use it at first we need to import it the fnmatch standard library module.
import fnmatch
In the Unix terminal, there are some wildcards to match the patterns. These are like below −
‘*’ The asterisk is used to match everything.
‘?’ Question Mark is for matching a single character.
[seq] Sequences are used to match characters in sequence
[!seq] Not in Sequence are used to match characters which are not present in the sequence.
If we want to search asterisk or question marks as character, then we have to use them like this: [*] or [?]
The fnmatch() method takes two arguments, these are filename and pattern. This function is used to check whether the filename is matched with the given pattern or not. When the Operating System is case sensitive, then the parameters will be normalized to uppercase or lowercase letter before matching.
import fnmatch
import os
file_pattern = 'test_f*'
files = os.listdir('./unix_files')
for filename in files:
   print('File: {}\t: {}'.format(filename, fnmatch.fnmatch(filename, file_pattern)))
$ python3 310.UNIX_filename.py
File: test_file5.txt : True
File: test_file2.png : True
File: test_file1.txt : True
File: another_file.txt : False
File: TEST_FILE4.txt : False
File: abc.txt : False
File: test_file3.txt : True
$
The filter() method also takes two parameters. The first one is the names, and the second one is the pattern. This pattern finds the list of matched filenames from the list of all filenames.
import fnmatch
import os
file_pattern = 'test_f*'
files = os.listdir('./unix_files')
match_file = fnmatch.filter(files, file_pattern)
   print('All files:' + str(files))
      print('\nMatched files:' + str(match_file))
$ python3 310.UNIX_filename.py
All files:['test_file5.txt', 'test_file2.png', 'test_file1.txt', 'another_file.txt', 'TEST_FILE4.txt', 'abc.txt', 'test_file3.txt']
Matched files:['test_file5.txt', 'test_file2.png', 'test_file1.txt', 'test_file3.txt']
$
The translate() method takes one parameter. The parameter is a pattern. We can use this function to convert a shell style pattern to another type of pattern to match using regular expressions in Python.
import fnmatch, re
file_pattern = 'test_f*.txt'
unix_regex = fnmatch.translate(file_pattern)
regex_object = re.compile(unix_regex)
   print('Regular Expression:' + str(unix_regex))
      print('Match Object:' + str(regex_object.match('test_file_abcd123.txt')))
$ python3 310.UNIX_filename.py
Regular Expression:(?s:test_f.*\.txt)\Z
Match Object:<_sre.SRE_Match object; span=(0, 21), match='test_file_abcd123.txt'>
$
Thread Synchronization in C#

Synchronize access to resources in multithreaded applications using Synchronization.
A mutex can be used to synchronize threads across processes. Use it to prevent the simultaneous execution of a block of code by more than one thread at a time.
C# lock statement is used to ensure that a block of code runs without interruption by other threads. A Mutual-exclusion lock is obtained for a given object for the duration of the code block.
A lock statement gets an object as an argument. The parameter given to the “lock” should be an object based on a reference type −
public class Demo {
   private System.Object myLock = new System.Object();
   public void Process() {
      lock (myLock) {
      }
   }
}
The Mutex class in C# is a synchronization primitive that can also be used for interprocess synchronization.
Let us see how to create a new Mutex −
private static Mutex m = new Mutex();
Java Program to Print matrix in snake pattern - GeeksforGeeks

11 Jan, 2022
Given an n x n matrix .In the given matrix, you have to print the elements of the matrix in the snake pattern.
Examples : 
Input :mat[][] = { {10, 20, 30, 40},
                   {15, 25, 35, 45},
                   {27, 29, 37, 48},
                   {32, 33, 39, 50}};
              
Output : 10 20 30 40 45 35 25 15 27 29
         37 48 50 39 33 32 

Input :mat[][] = { {1, 2, 3},
                   {4, 5, 6},
                   {7, 8, 9}};
Output : 1 2 3 6 5 4 7 8 9
 
We traverse all rows. For every row, we check if it is even or odd. If even, we print from left to right else print from right to left. 
Java
// Java program to print matrix in snake orderimport java.util.*;class GFG{    static void print(int [][] mat)    {        // Traverse through all rows        for (int i = 0; i < mat.length; i++)        {              // If current row is even, print from            // left to right            if (i % 2 == 0)            {                for (int j = 0; j < mat[0].length; j++)                    System.out.print(mat[i][j] +" ");                // If current row is odd, print from            // right to left            }            else            {                for (int j = mat[0].length - 1; j >= 0; j--)                    System.out.print(mat[i][j] +" ");            }        }    }      // Driver code    public static void main(String[] args)    {        int mat[][] = new int[][]        {            { 10, 20, 30, 40 },            { 15, 25, 35, 45 },            { 27, 29, 37, 48 },            { 32, 33, 39, 50 }        };          print(mat);    }}/* This code is contributed by Mr. Somesh Awasthi */
Output : 
10 20 30 40 45 35 25 15 27 29 37 48 50 39 33 32 
Please refer complete article on Print matrix in snake pattern for more details!
Java
Java Programs
Matrix
Matrix
Java
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Different ways of Reading a text file in Java
Constructors in Java
Stream In Java
Exceptions in Java
Generics in Java
Convert a String to Character array in Java
Java Programming Examples
Implementing a Linked List in Java using Class
Convert Double to Integer in Java
How to Iterate HashMap in Java?
Python - Geographical Data

Many open source python libraries now have been created to represent the geographical maps. They are highly customizable and offer a varierty of maps depicting areas in different shapes and colours.
One such package is Cartopy. You can download and install this package in your local environment from Cartopy.
You can find numerous examples in its gallery.
In the below example we show a portion of the world map showing parts of Asia and Australia. You can adjust the values of the parameters in the method set_extent to locate
different areas of world map.
import matplotlib.pyplot as plt
import cartopy.crs as ccrs    

fig = plt.figure(figsize=(15, 10))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.PlateCarree())

    # make the map global rather than have it zoom in to
    # the extents of any plotted data

ax.set_extent((60, 150, 55, -25))

ax.stock_img()
ax.coastlines()

ax.tissot(facecolor='purple', alpha=0.8)

plt.show()
Its output is as follows −

    187 Lectures 
     17.5 hours 

 Malhar Lathkar

    55 Lectures 
     8 hours 

 Arnab Chakraborty

    136 Lectures 
     11 hours 

 In28Minutes Official

    75 Lectures 
     13 hours 

 Eduonix Learning Solutions

    70 Lectures 
     8.5 hours 

 Lets Kode It

    63 Lectures 
     6 hours 

 Abhilash Nelson
 Print
 Add Notes
 Bookmark this page
How to remove li elements on button click in JavaScript?

Let’s say the following is our Unordered List (ul) −
<ul>
   <li class="subjectName">JavaScript <button>Remove</button></li>
   <br>
   <li class="subjectName">MySQL <button>Remove</button></li>
   <br>
   <li class="subjectName">MongoDB <button>Remove</button></li>
   <br>
   <li class="subjectName">Java <button>Remove</button></li>
</ul>
Above, you can see the “Remove” button with every li element. On clicking this button, you can
remove any li element.
Following is the code to remove li elements on button click;
 Live Demo
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initialscale=1.0">
<title>Document</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.
css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
</head>
<body>
<h1>Remove the subjects</h1>
<h2>The Subjects are as follows:</h2>
<ul>
<li class="subjectName">JavaScript <button>Remove</button></li>
<br>
<li class="subjectName">MySQL <button>Remove</button></li>
<br>
<li class="subjectName">MongoDB <button>Remove</button></li>
<br>
<li class="subjectName">Java <button>Remove</button></li>
</ul>
<script>
   var allSubjectName = document.querySelectorAll(".subjectName");
   for (var index = 0; index <allSubjectName.length; index++){
      allSubjectName[index].addEventListener("click", function(){
         this.classList.toggle("active");
      });
      allSubjectName[index].querySelector("button").addEventListener("click",
      function(){
         this.closest(".subjectName").remove();
      });
   }
</script>
</body>
</html>
To run the above program, save the file name “anyName.html(index.html)” and right click on the
file. Select the option “Open with Live Server” in VS Code editor.
This will produce the following output −
Now, I am going to remove subject name “MySQL” and “MongoDB” from the list of subjects.
This will produce the following output after clicking the “Remove” button for subjects “MySQL”
and “MongoDB” −
What are immediate functions in JavaScript?

The immediate function executes as soon as it is defined. To understand the role of immediate function, let’s see the difference between a function and an immediate function −
Here’s immediate function −
(function() {
   var str = "display";
}());
function display() {
   // this returns undefined
   alert(str);
}
Here’s a function −
var str = "display";
function display() {
   // This returns "display"
   alert(str);
}
Let’s see another example of immediate functions −
var name = 'Amit';
(function(sName) {
   alert( 'Student name = ' + sName );
}(sName))
Spring - Injecting Inner Beans

As you know Java inner classes are defined within the scope of other classes, similarly, inner beans are beans that are defined within the scope of another bean. Thus, a <bean/> element inside the <property/> or <constructor-arg/> elements is called inner bean and it is shown below.
<?xml version = "1.0" encoding = "UTF-8"?>

<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

   <bean id = "outerBean" class = "...">
      <property name = "target">
         <bean id = "innerBean" class = "..."/>
      </property>
   </bean>

</beans>
Let us have working Eclipse IDE in place and follow the following steps to create a Spring application −
Here is the content of TextEditor.java file −
package com.tutorialspoint;

public class TextEditor {
   private SpellChecker spellChecker;
   
   // a setter method to inject the dependency.
   public void setSpellChecker(SpellChecker spellChecker) {
      System.out.println("Inside setSpellChecker." );
      this.spellChecker = spellChecker;
   }
   
   // a getter method to return spellChecker
   public SpellChecker getSpellChecker() {
      return spellChecker;
   }
   public void spellCheck() {
      spellChecker.checkSpelling();
   }
}
Following is the content of another dependent class file SpellChecker.java −
package com.tutorialspoint;

public class SpellChecker {
   public SpellChecker(){
      System.out.println("Inside SpellChecker constructor." );
   }
   public void checkSpelling(){
      System.out.println("Inside checkSpelling." );
   }
}
Following is the content of the MainApp.java file −
package com.tutorialspoint;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {
   public static void main(String[] args) {
      ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
      TextEditor te = (TextEditor) context.getBean("textEditor");
      te.spellCheck();
   }
}
Following is the configuration file Beans.xml which has configuration for the setter-based injection but using inner beans −
<?xml version = "1.0" encoding = "UTF-8"?>

<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

   <!-- Definition for textEditor bean using inner bean -->
   <bean id = "textEditor" class = "com.tutorialspoint.TextEditor">
      <property name = "spellChecker">
         <bean id = "spellChecker" class = "com.tutorialspoint.SpellChecker"/>
      </property>
   </bean>

</beans>
Once you are done creating the source and bean configuration files, let us run the application. If everything is fine with your application, it will print the following message −
Inside SpellChecker constructor.
Program for Fahrenheit to Celsius conversion in C

Given with temperature ‘n’ in Fahrenheit and the challenge is to convert the given temperature to Celsius and display it.
Input 1-: 132.00
Output -: after converting fahrenheit 132.00 to celsius 55.56
Input 2-: 456.10
Output -: after converting fahrenheit 456.10 to celsius 235.61
For converting the temperature from Fahrenheit to Celsius, there is a formula which is given below
T(°C) = (T(°F) - 32) × 5/9
Where, T(°C) is temperature in Celsius and T(°F) is temperature in Fahrenheit
Approach used below is as follows −
Input temperature in a float variable let’s say Fahrenheit
Apply the formula to convert the temperature into Celsius
Print celsius
Start
Step 1-> Declare function to convert Fahrenheit to Celsius
   float convert(float fahrenheit)
      declare float Celsius
      Set celsius = (fahrenheit - 32) * 5 / 9
      return Celsius
step 2-> In main()
   declare and set float fahrenheit = 132.00
   Call convert(fahrenheit)
Stop
 Live Demo
#include <stdio.h>
//convert fahrenheit to celsius
float convert(float fahrenheit) {
   float celsius;
   celsius = (fahrenheit - 32) * 5 / 9;
   return celsius;
}
int main() {
   float fahrenheit = 132.00;
   printf("after converting fahrenheit %.2f to celsius %.2f ",fahrenheit,convert(fahrenheit));
   return 0;
}
IF WE RUN THE ABOVE CODE IT WILL GENERATE FOLLOWING OUTPUT
after converting fahrenheit 132.00 to celsius 55.56
Python | Pandas Series.nunique()

17 Sep, 2018
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.
While analyzing the data, many times the user wants to see the unique values in a particular column. Pandas nunique() is used to get a count of unique values.
To download the CSV file used, Click Here.
Syntax: Series.nunique(dropna=True)
Parameters:dropna: Exclude NULL value if True
Return Type: Integer – Number of unique values in a column.
Example #1: Using nunique()In this example, nunique() method is used to get number of all unique values in Team column.
# importing pandas packageimport pandas as pd  # making data frame from csv filedata = pd.read_csv("employees.csv")  # storing unique value in a variableunique_value = data["Team"].nunique()  # printing valueprint(unique_value)
Output:The output of number of unique values is returned.
10
 Example #2: NULL value HandlingIn this example, length of array returned by unique() method is compared to integer returned by nunique() method.
# importing pandas packageimport pandas as pd  # making data frame from csv filedata = pd.read_csv("employees.csv")  # storing unique value in a variablearr = data["Team"].unique()  # storing unique value in a variableunique_value = data["Team"].nunique(dropna = True)  # printing valuesprint(len(arr), unique_value)
Output:The output is not same in both of the cases as dropna parameter is set to True and hence NULL values were excluded while counting unique values.
11 10
Python pandas-series
Python pandas-series-methods
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python Dictionary
Different ways to create Pandas Dataframe
Enumerate() in Python
Read a file line by line in Python
Python String | replace()
How to Install PIP on Windows ?
*args and **kwargs in Python
Iterate over a list in Python
Python Classes and Objects
Convert integer to string in Python
When to use virtual destructors in C++?

Scott Meyers in Effective C++ says −
If a class has any virtual function, it should have a virtual destructor, and that classes not designed to be base classes or not designed to be used polymorphically should not declare virtual destructors.
So you should declare destructors virtual in polymorphic base classes. This is because if you create an object of base class using a derived constructor −
Base *b = new Derived();
// use b
delete b;
If Base's destructor is not virtual then delete b has undefined behavior in this case. The call to the destructor will be resolved like any non-virtual code. So the destructor of the base class will be called but not the one of the derived class, this will result in a resources leak.
Find N distinct numbers whose bitwise Or is equal to K in Python

Suppose we have two integers N and K; we have to find N unique values whose bit-wise OR is same as K. If there is no such result, then return -1
So, if the input is like N = 4 and K = 6, then the output will be [6,0,1,2].
To solve this, we will follow these steps −
MAX := 32
MAX := 32
visited := a list of size MAX and fill with False
visited := a list of size MAX and fill with False
res := a new list
res := a new list
Define a function add() . This will take num
Define a function add() . This will take num
point := 0
point := 0
value := 0
value := 0
for i in range 0 to MAX, doif visited[i] is non-zero, thengo for next iterationotherwise,if num AND 1 is non-zero, thenvalue := value +(2^i)num := num/2 (take only integer part)
for i in range 0 to MAX, do
if visited[i] is non-zero, thengo for next iteration
if visited[i] is non-zero, then
go for next iteration
go for next iteration
otherwise,if num AND 1 is non-zero, thenvalue := value +(2^i)num := num/2 (take only integer part)
otherwise,
if num AND 1 is non-zero, thenvalue := value +(2^i)
if num AND 1 is non-zero, then
value := value +(2^i)
value := value +(2^i)
num := num/2 (take only integer part)
num := num/2 (take only integer part)
insert value at the end of res
insert value at the end of res
From the main method, do the following −
From the main method, do the following −
pow2 := an array of power of 2 from 2^0 to 2^31
pow2 := an array of power of 2 from 2^0 to 2^31
insert k at the end of res
insert k at the end of res
cnt_k := number of bits in k
cnt_k := number of bits in k
if pow2[cnt_k] < n, thenreturn -1
if pow2[cnt_k] < n, then
return -1
return -1
count := 0
count := 0
for i in range 0 to pow2[cnt_k] - 1, doadd(i)count := count + 1if count is same as n, thencome out from the loop
for i in range 0 to pow2[cnt_k] - 1, do
add(i)
add(i)
count := count + 1
count := count + 1
if count is same as n, thencome out from the loop
if count is same as n, then
come out from the loop
come out from the loop
return res
return res
Let us see the following implementation to get better understanding −
 Live Demo
MAX = 32
visited = [False for i in range(MAX)]
res = []
def set_bit_count(n):
   if (n == 0):
      return 0
   else:
      return (n & 1) + set_bit_count(n >> 1)
def add(num):
   point = 0
   value = 0
   for i in range(MAX):
      if (visited[i]):
         continue
      else:
         if (num & 1):
            value += (1 << i)
         num = num//2
   res.append(value)
def solve(n, k):
   pow2 = [2**i for i in range(MAX)]
   res.append(k)
   cnt_k = set_bit_count(k)
   if (pow2[cnt_k] < n):
      return -1
   count = 0
   for i in range(pow2[cnt_k] - 1):
      add(i)
      count += 1
      if (count == n):
         break
   return res

n = 4
k = 6
print(solve(n, k))
4, 6
[6, 0, 1, 2]
concat(), replace(), and trim() Strings in Java.

The concat() method of the String class appends one String to the end of another. The method returns a String with the value of the String passed into the method, appended to the end of the String, used to invoke this method.
public class Test {
   public static void main(String args[]) {
      String s = "Strings are immutable";
      s = s.concat(" all the time");
      System.out.println(s);
   }
}
Strings are immutable all the time
This replace() method of the String class returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.
public class Test {
   public static void main(String args[]) {
      String Str = new String("Welcome to Tutorialspoint.com");
      System.out.print("Return Value :" );
      System.out.println(Str.replace('o', 'T'));
      System.out.print("Return Value :" );
      System.out.println(Str.replace('l', 'D'));
   }
}
Return Value :WelcTme tT TutTrialspTint.cTm
Return Value :WeDcome to TutoriaDspoint.com
This trim() method of the String class returns a copy of the string, with leading and trailing whitespace omitted.
import java.io.*;
public class Test {
   public static void main(String args[]) {
      String Str = new String(" Welcome to Tutorialspoint.com ");
      System.out.print("Return Value :" );
      System.out.println(Str.trim() );
   }
}
Return Value :Welcome to Tutorialspoint.com
Special Binary String in C++

Suppose we have a spatial binary string. This string has following few properties −
There are same number of 0s and 1s
There are same number of 0s and 1s
Every Prefix in the binary string has at least as many 1s as 0s
Every Prefix in the binary string has at least as many 1s as 0s
Now suppose we have special string S, a move is actually choosing two consecutive, non-empty, special substrings of S, and swapping them.
We have to find the lexicographically largest resulting string possible, at the end of any number of moves.
So, if the input is like 11011000, then the output will be 11100100, this is because: The substrings "10" and "1100" are swapped. This is the lexicographically largest string possible after few moves.
To solve this, we will follow these steps −
Define a function makeLargestSpecial(), this will take s,
Define a function makeLargestSpecial(), this will take s,
ret := empty string
ret := empty string
Define an array v of strings
Define an array v of strings
i := 0
i := 0
for initialize j := 0, cnt := 0, when j < size of s, update (increase j by 1), do −if s[j] is same as '1', then −(increase cnt by 1)Otherwise(decrease cnt by 1)if cnt is same as 0, then −insert "1" + makeLargestSpecial(substring of s from index i + 1 to j - i - 1) at the end of vi := j + 1
for initialize j := 0, cnt := 0, when j < size of s, update (increase j by 1), do −
if s[j] is same as '1', then −(increase cnt by 1)
if s[j] is same as '1', then −
(increase cnt by 1)
(increase cnt by 1)
Otherwise(decrease cnt by 1)
Otherwise
(decrease cnt by 1)
(decrease cnt by 1)
if cnt is same as 0, then −insert "1" + makeLargestSpecial(substring of s from index i + 1 to j - i - 1) at the end of vi := j + 1
if cnt is same as 0, then −
insert "1" + makeLargestSpecial(substring of s from index i + 1 to j - i - 1) at the end of v
insert "1" + makeLargestSpecial(substring of s from index i + 1 to j - i - 1) at the end of v
i := j + 1
i := j + 1
sort the array v.r
sort the array v.r
for initialize i := 0, when i < size of v, update (increase i by 1), do −ret := ret + v[i]
for initialize i := 0, when i < size of v, update (increase i by 1), do −
ret := ret + v[i]
ret := ret + v[i]
return ret
return ret
From the main method call makeLargestSpecial() with the string.
From the main method call makeLargestSpecial() with the string.
Let us see the following implementation to get better understanding −
 Live Demo
#include <bits/stdc++.h>
using namespace std;
class Solution {
   public:
   string makeLargestSpecial(string s) {
      string ret = "";
      vector<string> v;
      int i = 0;
      for (int j = 0, cnt = 0; j < s.size(); j++) {
         if (s[j] == '1') {
            cnt++;
         }
         else
         cnt--;
         if (cnt == 0) {
            v.push_back("1" + makeLargestSpecial(s.substr(i + 1,
            j - i - 1)) + "0");
            i = j + 1;
         }
      }
      sort(v.rbegin(), v.rend());
      for (int i = 0; i < v.size(); i++)
      ret += v[i];
      return ret;
   }
};
main(){
   Solution ob;
   cout << (ob.makeLargestSpecial("11011000"));
}
11011000
11100100
CSS | rotateZ() Function - GeeksforGeeks

20 Aug, 2019
The rotateZ() function is an inbuilt function which is used to rotate an element around the z-axis.
Syntax:
rotateZ( angle )
Parameters: This function accepts single parameter angle which represents the angle of rotations. The positive and negative angles rotate the elements in clockwise and counter-clockwise respectively.
Below examples illustrate the rotateZ() function in CSS:
Example 1:
<!DOCTYPE html><html>  <head>    <title>CSS rotateZ() function</title>      <style>        body {            text-align: center;        }        h1 {            color: green;        }        .rotateZ_image {            transform: rotateZ(45deg);        }    </style></head>  <body>    <h1>GeeksforGeeks</h1>    <h2>CSS rotateZ() function</h2>      <br><br>      <img class="rotateZ_image" src="https://media.geeksforgeeks.org/wp-content/cdn-uploads/20190710102234/download3.png"         alt="GeeksforGeeks logo"></body>  </html>                                    
Output:
Example 2:
<!DOCTYPE html><html>  <head>    <title>CSS rotateZ() function</title>      <style>        body {            text-align: center;        }        h1 {            color: green;        }        .GFG {            font-size: 35px;            font-weight: bold;            color: green;            transform: rotateZ(45deg);        }    </style></head>  <body>    <h1>GeeksforGeeks</h1>    <h2>CSS rotateZ() function</h2>      <br><br>      <div class="GFG">Welcome to GeeksforGeeks</div></body>  </html>
Output:
Supported Browsers: The browsers supported by rotateZ() function are listed below:
Google Chrome
Internet Explorer
Firefox
Opera
Safari
CSS-Functions
CSS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Design a web page using HTML and CSS
Form validation using jQuery
How to set space between the flexbox ?
Search Bar using HTML, CSS and JavaScript
How to style a checkbox using CSS?
Top 10 Front End Developer Skills That You Need in 2022
Installation of Node.js on Linux
How to fetch data from an API in ReactJS ?
Difference between var, let and const keywords in JavaScript
Convert a string to an integer in JavaScript
C++ function call by value

The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.
By default, C++ uses call by value to pass arguments. In general, this means that code within a function cannot alter the arguments used to call the function. Consider the function swap() definition as follows.
// function definition to swap the values.
void swap(int x, int y) {
   int temp;

   temp = x; /* save the value of x */
   x = y;    /* put y into x */
   y = temp; /* put x into y */
  
   return;
}
Now, let us call the function swap() by passing actual values as in the following example −
#include <iostream>
using namespace std;
 
// function declaration
void swap(int x, int y);
 
int main () {
   // local variable declaration:
   int a = 100;
   int b = 200;
 
   cout << "Before swap, value of a :" << a << endl;
   cout << "Before swap, value of b :" << b << endl;
 
   // calling a function to swap the values.
   swap(a, b);
 
   cout << "After swap, value of a :" << a << endl;
   cout << "After swap, value of b :" << b << endl;
 
   return 0;
}
When the above code is put together in a file, compiled and executed, it produces the following result −
Before swap, value of a :100
Before swap, value of b :200
After swap, value of a :100
After swap, value of b :200

Which shows that there is no change in the values though they had been changed inside the function.

    154 Lectures 
     11.5 hours 

 Arnab Chakraborty

    14 Lectures 
     57 mins

 Kaushik Roy Chowdhury

    30 Lectures 
     12.5 hours 

 Frahaan Hussain

    54 Lectures 
     3.5 hours 

 Frahaan Hussain

    77 Lectures 
     5.5 hours 

 Frahaan Hussain

    12 Lectures 
     3.5 hours 

 Frahaan Hussain
 Print
 Add Notes
 Bookmark this page
Java Generics - Set

Java has provided generic support in Set interface.
Set<T> set = new HashSet<T>();

Where
set − object of Set Interface.
set − object of Set Interface.
T − The generic type parameter passed during set declaration.
T − The generic type parameter passed during set declaration.
The T is a type parameter passed to the generic interface Set and its implemenation class HashSet.
Create the following java program using any editor of your choice.
package com.tutorialspoint;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

public class GenericsTester {
   public static void main(String[] args) {

      Set<Integer> integerSet = new HashSet<Integer>();
  
      integerSet.add(Integer.valueOf(10));
      integerSet.add(Integer.valueOf(11));

      Set<String> stringSet = new HashSet<String>();
  
      stringSet.add("Hello World");
      stringSet.add("Hi World");
 

      for(Integer data: integerSet) {
         System.out.printf("Integer Value :%d\n", data);
      }

      Iterator<String> stringIterator = stringSet.iterator();

      while(stringIterator.hasNext()) {
         System.out.printf("String Value :%s\n", stringIterator.next());
      }
   }  
}
This will produce the following result −
Integer Value :10
Integer Value :11
String Value :Hello World
String Value :Hi World


    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
Python | TextBlob.sentiment() method - GeeksforGeeks

09 Sep, 2019
With the help of TextBlob.sentiment() method, we can get the sentiments of the sentences by using TextBlob.sentiment() method.
Syntax : TextBlob.sentiment()Return : Return the tuple of sentiments.
Example #1 :In this example we can say that by using TextBlob.sentiment() method, we are able to get the sentiments of a sentence.
# import TextBlobfrom textblob import TextBlob  gfg = TextBlob("GFG is a good company and always value their employees.")  # using TextBlob.sentiment methodgfg = gfg.sentiment  print(gfg)
Output :
Sentiment(polarity=0.7, subjectivity=0.6000000000000001)
Example #2 :
# import TextBlobfrom textblob import TextBlob  gfg = TextBlob("Sandeep Jain An IIT Roorkee alumnus and founder of GeeksforGeeks. He loves to solve programming problems in most efficient ways.")  # using TextBlob.sentiment methodgfg = gfg.sentiment  print(gfg)
Output :
Sentiment(polarity=0.5, subjectivity=0.5)
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
How To Convert Python Dictionary To JSON?
Check if element exists in list in Python
Python | Pandas dataframe.groupby()
Defaultdict in Python
Python | Get unique values from a list
Python Classes and Objects
Python | os.path.join() method
Create a directory in Python
How is a file read using a limited buffer size using Python?

You can read a file using a limited buffer by specifying the buffer size in the read function. It takes the number of bytes you want to read from the current position of the pointer in the file. 
with open('my_file.txt', 'r') as f:
    print(f.read(10))  # Read and print 10 bytes
This will give the output −
Hello worl
If the file contents were Hello world!
How to create Guid value in C#?

A Globally Unique Identifier or GUID represents a gigantic identification number — a number so large that it is mathematically guaranteed to be unique not only in a single system like a database, but across multiple systems or distributed applications.
The total number of unique keys (3.40282366×1038) is so large that the probability of the same number being generated twice is very small. For an application using 10 billion random GUIDs, the probability of a coincidence is approximately 1 in a quintillion.(1030)
For example, in Retail domain if we want to generate a unique for each transaction so that a customer can use that id to do post sale operations like return, adjustment etc., GUID can be used. GUIDs are most commonly written in text as a sequence of hexadecimal digits like 3F2504E0-4F89-11D3-9A0C-0305E82C3301.
Guid is present in System namespace in C#. It can be created like below.
Guid demoGuid = Guid.NewGuid();
 Live Demo
using System;
namespace DemoApplication{
   class Program{
      static void Main(string[] args){
         Guid demoGuid = Guid.NewGuid();
         Console.WriteLine(demoGuid);
         Console.WriteLine(Guid.NewGuid());
         Console.ReadLine();
      }
   }
}
The output of the above code is
3a251d82-e8ce-442f-9e42-5285653a5e8a
09081b06-26e2-49fa-8e96-93748a99defa
Each time when Guid.NewGuid() is called it will generate a random unique guid.
How to write retry logic in C#?

Retry logic is implemented whenever there is a failing operation. Implement retry
logic only where the full context of a failing operation.
It's important to log all connectivity failures that cause a retry so that underlying
problems with the application, services, or resources can be identified.
class Program{
   public static void Main(){
      HttpClient client = new HttpClient();
      dynamic res = null;
      var retryAttempts = 3;
      var delay = TimeSpan.FromSeconds(2);
      RetryHelper.Retry(retryAttempts, delay, () =>{
         res = client.GetAsync("https://example22.com/api/cycles/1");
      });
      Console.ReadLine();
   }
}
public static class RetryHelper{
   public static void Retry(int times, TimeSpan delay, Action operation){
      var attempts = 0;
      do{
         try{
            attempts++;
            System.Console.WriteLine(attempts);
            operation();
            break;
         }
         catch (Exception ex){
            if (attempts == times)
               throw;
            Task.Delay(delay).Wait();
         }
      } while (true);
   }
}
How to check if a variable is NaN in JavaScript?

NaN is a JavaScript property, which is "Not-a-Number" value. To find out whether value is NaN, use the Number.isNaN() or isNan() method.
Here’s an example to check if a variable in NaN in JavaScript
Live Demo
<!DOCTYPE html>
<html>
   <body>
      <button onclick="display()">Check</button>
      <p id="test"></p>
      <script>
         function display() {
            var a = "";
            a = a + isNaN(6234) + ": 6234<br>";
            a = a + isNaN(-52.1) + ": -52.1<br>";
            a = a + isNaN('Website') + ": 'Hello'<br>";
            a = a + isNaN(NaN) + ": NaN<br>";
            a = a + isNaN('') + ": ''<br>";
            a = a + isNaN(0) + ": 0<br>";
            a = a + isNaN(false) + ": false<br>";
            document.getElementById("test").innerHTML = a;
         }
      </script>
   </body>
</html>
Happy Number in Python

Here we will see how to detect a number n is one Happy number or not. So the happy number is a number, where starting with any positive integers replace the number by the sum of squares of its digits, this process will be repeated until it becomes 1, otherwise it will loop endlessly in a cycle. Those numbers, when the 1 has found, they will be happy number.
Suppose the number is 19, the output will be true as the number is happy number. As we can see from 19, we will get
12 + 92 = 82
82 + 22 = 68
62 + 82 = 100
12 + 02 + 02 = 1
To solve this, we will follow these steps −
Here we will use the dynamic programming approach, and solve this using recursion
Base case is, when n = 1, then return true
When n is already visited, return false
mark n as visited
n := n as string, l := list of all digits in n
temp := squared sum of all digits
return function recursively with parameter temp and visited list
Let us see the following implementation to get better understanding −
 Live Demo
class Solution(object):
   def isHappy(self, n):
      """
      :type n: int
      :rtype: bool
      """
      return self.solve(n,{})
   def solve(self,n,visited):
      if n == 1:
         return True
      if n in visited:
         return False
      visited[n]= 1
      n = str(n)
      l = list(n)
      l = list(map(int,l))
      temp = 0
      for i in l:
         temp += (i**2)
      return self.solve(temp,visited)
ob1 = Solution()
op = ob1.isHappy(19)
print("Is Happy:",op)
19
Is Happy: True
File and Directory Management

Here, we will learn the concepts of File and Directory Management −
File is nothing but a collection of information. The information can be of numbers, characters, graphs, images, etc. Every file should be stored under a unique name for its future reference. Every file should be saved along with an extension. Some of the extensions and their description are given below −
.avi
Microsoft videos for Windows movie
.dbf
dbase II, III, IV data file
.doc(x)
Microsoft word for windows
.gif
Graphics Interchange Format
.htm
Hypertext Markup Language
.html
Hypertext Markup Language
.jpg
JPEG graphics file
.mpg
MPEG video file
.mid
MIDI music file
.mov
QuickTime movie
File should be represented in address bar along with path of the file, filename and extension.
For example: C:\Windows\system32\Hello.html
In which C:\Windows\system32 → path
   Hello → filename
   .html → extension.

Directory is a place/area/location where a set of file(s) will be stored. It is a folder which contains details about files, file size and time when they are created and last modified. The different types of directories are discussed below −
Root Directory is created when we start formatting the disk and start putting files on it. In this, we can create new directories called "sub-directories". Root directory is the highest level directory and is seen when booting a system.
Subdirectory is a directory inside root directory, in turn, it can have another sub-directory in it.

    107 Lectures 
     13.5 hours 

 Arnab Chakraborty

    106 Lectures 
     8 hours 

 Arnab Chakraborty

    99 Lectures 
     6 hours 

 Arnab Chakraborty

    46 Lectures 
     2.5 hours 

 Shweta

    70 Lectures 
     9 hours 

 Abhilash Nelson

    52 Lectures 
     7 hours 

 Abhishek And Pukhraj
 Print
 Add Notes
 Bookmark this page
How to show shaking / wobble view animation in android?

This example demonstrate about How to show shaking / wobble view animation in android.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.
Step 2 − Add the following code to res/layout/activity_main.xml.
<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout
   xmlns:android = "http://schemas.android.com/apk/res/android"
   xmlns:tools = "http://schemas.android.com/tools"
   android:layout_width = "match_parent"
   android:layout_height = "match_parent">
   <Button
      android:id = "@+id/button"
      android:layout_centerHorizontal = "true"
      android:layout_marginTop = "100dp"
      android:layout_width = "150dp"
      android:text = "Click"
      android:layout_height = "wrap_content"/>
   <ImageView
      android:id = "@+id/imageView"
      android:src = "@mipmap/ic_launcher_round"
      android:layout_width = "match_parent"
      android:layout_height = "300dp" />
</RelativeLayout>
In the above code, we have taken button to show shake animation for image view.
Step 3 − Add the following code to src/MainActivity.java
package com.example.andy.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends AppCompatActivity {
   ImageView view;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      view = findViewById(R.id.imageView);
      findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            Animation animShake = AnimationUtils.loadAnimation(MainActivity.this, R.anim.shake);
            view.startAnimation(animShake);
         }
      });
   }
}
In the above code, when user click on button, it will shake imageview using shake animation for that we need to create a file called shake.xml in anim folder. Add the following code in shake.xml -
<?xml version = "1.0" encoding = "utf-8"?>
<set xmlns:android = "http://schemas.android.com/apk/res/android">
   <translate android:duration = "150"
      android:fromXDelta = "-10%"
      android:repeatCount = "5"
      android:repeatMode = "reverse"
      android:toXDelta = "10%"/>
</set>
Let's try to run your application. I assume you have connected your actual Android Mobile device with your computer. To run the app from android studio, open one of your project's activity files and click Run   icon from the toolbar. Select your mobile device as an option and then check your mobile device which will display your default screen −
Now click on button to shake background image as shown below -
Click here to download the project code
C library function - sqrt()

The C library function double sqrt(double x) returns the square root of x.
Following is the declaration for sqrt() function.
double sqrt(double x)
x − This is the floating point value.
x − This is the floating point value.
This function returns the square root of x.
The following example shows the usage of sqrt() function.
#include <stdio.h>
#include <math.h>

int main () {

   printf("Square root of %lf is %lf\n", 4.0, sqrt(4.0) );
   printf("Square root of %lf is %lf\n", 5.0, sqrt(5.0) );
   
   return(0);
}
Let us compile and run the above program that will produce the following result −
Square root of 4.000000 is 2.000000
Square root of 5.000000 is 2.236068


    12 Lectures 
     2 hours 

 Nishant Malik

    12 Lectures 
     2.5 hours 

 Nishant Malik

    48 Lectures 
     6.5 hours 

 Asif Hussain

    12 Lectures 
     2 hours 

 Richa Maheshwari

    20 Lectures 
     3.5 hours 

 Vandana Annavaram

    44 Lectures 
     1 hours 

 Amit Diwan
 Print
 Add Notes
 Bookmark this page
UGC NET CS 2018 Dec – II - GeeksforGeeks

03 Nov, 2021
R ≥ P(N − 1) + 1 
12 ≥ P(4 − 1) + 1
11 ≥ 3P
11/3 ≥ P
P ≤ 3.66 
Writers are given exclusive access to shared objectsReaders are given exclusive access to shared objectsBoth readers and writers are given exclusive access to shared objects.
Writers are given exclusive access to shared objects
Readers are given exclusive access to shared objects
Both readers and writers are given exclusive access to shared objects.
SRS is said to be correct if it covers all the requirements that are actually expected from the system.
Requirements in SRS are said to be consistent if there are no conflicts between any set of requirements. Examples of conflict include differences in terminologies used at separate places, logical conflicts like time period of report generation, etc.
An SRS is said to be unambiguous if all the requirements stated have only 1 interpretation.
An SRS is verifiable if there exists a specific technique to quantifiably measure the extent to which every requirement is met by the system.
(⌐ A ∨​ ⌐B ∨​ ⌐C ∨​ ⌐ ​D) 
Writing code in comment? Please use ide.geeksforgeeks.org, generate link and share the link here.
Must Do Coding Questions for Product Based Companies
How to Replace Values in Column Based on Condition in Pandas?
C Program to read contents of Whole File
How to Replace Values in a List in Python?
Spring - REST Controller
EPAM Interview Experience | On-Campus 2022
How to Read Text Files with Pandas?
Construct a DFA that Start With aa or bb
Python Data Structures and Algorithms
Data Science With Python Tutorial
What are variadic functions in Java?

Methods which uses variable arguments (varargs, arguments with three dots) are known as variadic functions.
Live Demo
public class Sample {
    void demoMethod(String... args) {
      for (String arg: args) {
         System.out.println(arg);
      }
    }

   public static void main(String args[] ){
      new Sample().demoMethod("ram", "rahim", "robert");
      new Sample().demoMethod("krishna", "kasyap");
   }
}
ram
rahim
robert
krishna
kasyap
Call methods of an object using reflection in Java

The methods of an object can be called using the java.lang.Class.getDeclaredMethods() method. This method returns an array that contains all the Method objects with public, private, protected and default access. However, the inherited methods are not included.
Also, the getDeclaredMethods() method returns a zero length array if the class or interface has no methods or if a primitive type, array class or void is represented in the Class object.
A program that demonstrates this is given as follows −
 Live Demo
import java.lang.reflect.Method;
class ClassA {
   private String name = "John";
   public String returnName() {
      return name;
   }
}
public class Demo {
   public static void main(String[] args) throws Exception {
      Class c = ClassA.class;
      Method[] methods = c.getDeclaredMethods();
      ClassA obj = new ClassA();
      for (Method m : methods) {
         Object result = m.invoke(obj, new Object[0]);
         System.out.println(m.getName() + ": " + result);
      }
   }
}
returnName: John
Explain Nested if-else statement in C language

A ‘nested if’ is an if statement that is the object of either if (or) an else. ‘if’ is placed inside another if (or) else.
Refer the syntax given below −
if (condition1){
   if (condition2)
      stmt1;
   else
      stmt2;
}
else{
   if (condition3)
      stmt3;
   else
      stmt4;
}
Given below is the C program to execute Nested If Else conditional operators −
 Live Demo
#include<stdio.h>
void main (){
   int a,b,c,d;
   printf("Enter the values of a,b,c: \n");
   scanf("%d,%d,%d",&a,&b,&c);
   if((a>b)&&(a>c)){//Work with 4 numbers//
      if(a>c){
         printf("%d is the largest",a);
      } else {
         printf("%d is the largest",c);
      }
   } else {
      if(b>c){
         printf("%d is the largest",b);
      } else {
         printf("%d is the largest",c);
      }
   }
}
You will see the following output −
Enter the values of a,b,c: 3,5,8
8 is the largest
Following is the C program to check the number is positive or negative −
 Live Demo
#include <stdio.h>
int main(){
   int num;
   printf("Enter a number:\n ");
   scanf ("%d ", &num);
   if(num > 0){
      printf("This is positive num:%d\n", num);
   }
   else if(num < 0){
      printf("This is a negative num:%d",num);
   } else {
      printf("This is a zero:%d",num);
   }
   return 0;
}
You will see the following output −
Run 1: Enter a number:
23
23=This number is positive
Run 2: Enter a number:
-56
-56=This number is negative