This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function useGoBackBrowserSync() { | |
useEffect(() => { | |
return history.listen((newLocation, action) => { | |
if (action === 'POP') { | |
history.goBack(); | |
} | |
}); | |
}, [history]); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sleep = (ms: number) => new Promise(r => setTimeout(r, ms)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1. Add or subtract the percentage given in the problem from 100% to determine what percentage we have. | |
2. Find 1% by dividing by the percentage found in the previous step. | |
3. Find 100% (original amount) by multiplying your answer in step 2 by 100. | |
<100% Example: | |
A shop is having a sale where all items are 30% off. | |
An item is on sale for $84. | |
What was the original price of the item? | |
100% - 30% = 70% of the original price |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Safely execute browser only code. | |
* | |
* @param fn - The function to execute. | |
* @param fallback - Optional default return value. | |
* | |
*/ | |
function browserOnly<T>( | |
fn: (window: Window, document: Document) => T, | |
fallback?: T |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare global { | |
interface Window { | |
someSDK: SomeSDKType | undefined; | |
} | |
} | |
/** | |
* Wrap a script-added SDK so it is usable in server and client contexts. | |
* This allows it to be freely used without errors related to undefined `window` | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type FooContextType = { some: 'type' }; | |
export const FooContext = React.createContext<FooContextType | undefined>( | |
undefined | |
); | |
export function FooProvider(props: { children: React.ReactNode }): JSX.Element { | |
const value = useFoo(); | |
return ( | |
<FooContext.Provider value={value}>{props.children}</FooContext.Provider> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SomeEnum = { | |
SomeValue: 'SomeValue', | |
SomeOtherValue: 'SomeOtherValue' | |
} as const; | |
type SomeEnumKey = keyof typeof SomeEnum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type City = CityName | CityCoordinates; | |
type CityName = 'New York' | 'Mumbai' | 'Lagos'; | |
type CityCoordinates = { | |
x: number; | |
y: number; | |
}; | |
type User = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://www.youtube.com/watch?v=eWEgUcHPle0 | |
___ | |
https://dev.to/hemanth/explain-csrf-like-im-five | |
CSRF (Cross Site Request Forgery) is also known as Sea-Surf or Session Riding. It's is a form of trick that bad folks play on the browser in order to get it to do unexpected things in applications that you're already logged in. | |
For example, imagine you were logged into your Supercell game on the internet. You get an e-mail saying "Click here to get 500 gems for free!". Clicking on the text, on the contrary, will actually initiate a request to Supercell to transfer all your gems to the hacker's account. Now, along with the request, the browser always sends the cookies to Supercell as well. Supercell verifies if the cookies are valid (which they are because you just logged in!), Supercell will trust the browser and the request and doesn't know that this is not what you wanted. They will go ahead and execute this instruction thinking this is what you wanted to do. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html |
OlderNewer