'How to set the sameSite: 'none', secure: true on ReactJS
I want to embed an iframe from google map on my website and I get an error from google chrome
Because a cookie’s SameSite attribute was not set or is invalid, it defaults to SameSite=Lax, which prevents the cookie from being sent in a cross-site request. This behavior protects user data from accidentally leaking to third parties and cross-site request forgery.
How I can handle this problem? I tried to set cookies to none and secures but it does not work!
Solution 1:[1]
I modified your code with a bit of refactoring in order to fix the bugs and improve its readability and performance. I also added another overloaded function that is significantly faster and uses 0 heap allocations. It does the same thing though but in a far more optimized way.
Here:
#include <iostream>
#include <string>
#include <string_view>
// this is basically your function but is more efficient now
void removeDuplicateChars( const std::string& str )
{
if ( str.length( ) == 1 )
{
std::cout << str;
return;
}
const char firstChar = str[ 0 ];
const std::string&& restOfStr { str.substr( 1 ) };
if ( restOfStr.find( firstChar ) == std::string::npos )
{
std::cout << firstChar;
}
else
{
std::cout << "";
}
removeDuplicateChars( restOfStr );
}
// this one is far superior to the above one
void removeDuplicateChars( std::string_view&& strView )
{
if ( strView.length( ) == 1 )
{
std::cout << strView;
return;
}
const char firstChar = strView[ 0 ];
strView.remove_prefix( 1 );
if ( strView.find( firstChar ) == std::string_view::npos )
{
std::cout << firstChar;
}
else
{
std::cout << "";
}
removeDuplicateChars( std::move( strView ) );
}
int main( )
{
std::cout << "Enter the string: ";
std::string str;
std::cin >> str;
removeDuplicateChars( str ); // this calls the first overload
std::cout << '\n';
removeDuplicateChars( std::string_view( "ababcdc" ) ); // this calls the
// second overload
return 0;
}
Sample input/output:
Enter the string: ababcdc
abdc
abdc
I would highly recommend you to ditch the 1st overload and only use the 2nd one. Not only it's faster but also supports the types std::string, std::string_view, and C-style strings.
Here are some useful links to improve your knowledge:
std::string_view
std::string::substr
std::string::find
Solution 2:[2]
The below line:
if (((s.substr(1)).find(c)) >= 0)
should be changed to:
if (s.substr(1).find(c) != std::string::npos)
It basically means that c is found in s.substr(1).
find returns std::string::npos if the character is not found.
Solution 3:[3]
I have tried to solve this problem of yours.
What I have done is, I have replaced duplicate characters with whitespace.
if you want to remove whitespace you can find the code easily on internet.
C++ Code:
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
void RemoveDuplicateChar(string inputString)
{
if(inputString.length() == 1){
cout << inputString;
cout << "\nIt has only one character";
}else{
int stringLength = inputString.length();
cout<< "Original string: ";
cout << inputString;
cout << "\n";
for(int i =0 ; i<stringLength; i++){
for(int j = i+1; j< stringLength; j++){
if(inputString[i] == inputString[j]){
inputString[j] = ' ';
}else{
continue;
}
}
}
cout << "Duplicate character removed\n";
cout << "New String: ";
cout << inputString;
}
}
int main()
{
string input;
cout << "Enter a string with repeated characters: ";
cin >> input;
RemoveDuplicateChar(input);
return 0;
}
Output:
Enter a string with repeated characters: ababcdc
Original string: ababcdc
Duplicate characters removed
New String: ab cd
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | kiner_shah |
| Solution 3 | Dwij Siyal |
