Skip to content

Instantly share code, notes, and snippets.

@abha57
abha57 / Npm registry change
Created February 1, 2022 12:22
Npm registry change
npm config ls -l --registry => to see the registry.
npm config set registry https://registry.npmjs.org => to set the desired registry.
@abha57
abha57 / .npmrc and .npmignore files
Last active January 10, 2022 11:39
.npmrc and .npmignore files
.npmignore
Blacklisting files with npmignore
The .npmignore file works the same way as a .gitignore file.
If a file is listed in the .npmignore file, the file will be excluded from the package.
Important note: If you have a .npmignore file, npm will use the .npmignore file. npm will ignore the .gitignore file altogether.
(Many developers mistakenly believe npm will use both .npmignore and .gitignore files. Don’t make the same mistake!).
.npmrc
This file is a configuration file for NPM, it defines the settings on how NPM should behave when running commands.
There are several ways to configure NPM. You can do it via:
@abha57
abha57 / jsconfig and babelrc eslintrc
Last active January 26, 2021 13:26
absolute paths resolve
//jsconfig ==> to make editor recognize absolute path.
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"~/*": ["/*"],
"@src/*": ["src/*"],
"@any-other-folder/*": ["src/client/../any-other-folder/*"] ==> absolute path to any other folder
}
},
@abha57
abha57 / document.visibilityState
Created January 25, 2021 18:39
document.visibilityState
How to check if a Browser Tab is active or not? 🔥
0. Stop video if the user changes the browser tab
1. Reduce Polling Rate of Data from API
2. Stop music if the user moves out
document.visibilityState
// 'visible'
document.addEventListener("visibilitychange", function() {
@abha57
abha57 / HTML attribute: crossorigin
Created December 4, 2020 09:31
HTML attribute: crossorigin
The crossorigin attribute, valid on the <audio>, <img>, <link>, <script>, and <video> elements, provides support for CORS, defining how the element handles crossorigin requests,
anonymous CORS requests for this element will have the credentials flag set to 'same-origin'.
By default (that is, when the attribute is not specified), CORS is not used at all. The "anonymous" keyword means that there will be no exchange of user credentials via cookies, client-side SSL certificates or HTTP authentication.
Example: crossorigin with the script element
You can use the following <script> element to tell a browser to execute the https://example.com/example-framework.js script without sending user-credentials.
<script src="https://example.com/example-framework.js" crossorigin="anonymous"></script>
@abha57
abha57 / disabling chrome for certificate check in dev mode
Last active November 29, 2020 16:53
disabling chrome for certificate check in dev mode
go to chrome://flags/
Allow invalid certificates for resources loaded from localhost. Choose enabled. Chrome will relaunch without certificate
verification.
@abha57
abha57 / nvm install
Created November 25, 2020 17:16
nvm install
Before installing nvm, run this in terminal: touch ~/.bash_profile
After, run this in terminal:
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.1/install.sh | bash
Important... - DO NOT forget to Restart your terminal OR use command source ~/.nvm/nvm.sh (this will refresh the available commands in your system path).
In the terminal, use command nvm --version and you should see the version
@abha57
abha57 / chrome sources code
Created November 20, 2020 17:04
chrome sources code
permutations
const possiblePermutations = (str) => {
const result = [];
let dupStr = '';
let tempStr = str;
result.push(str);
for(let i = 0; i < str.length; i++) {
// if(i === 0) {
// result.push(str);
// continue;
@abha57
abha57 / Page: DOMContentLoaded, load, beforeunload, unload
Created November 20, 2020 16:57
Page: DOMContentLoaded, load, beforeunload, unload
DOMContentLoaded – the browser fully loaded HTML, and the DOM tree is built, but external resources like pictures <img> and stylesheets may not yet have loaded.
load – not only HTML is loaded, but also all the external resources: images, styles etc.
beforeunload/unload – the user is leaving the page.
When the browser processes an HTML-document and comes across a <script> tag, it needs to execute before continuing building the DOM.
That’s a precaution, as scripts may want to modify DOM, and even document.write into it, so DOMContentLoaded has to wait.
So DOMContentLoaded definitely happens after such scripts.
There are two exceptions from this rule:
Scripts with the async attribute, that we’ll cover a bit later, don’t block DOMContentLoaded.
Scripts that are generated dynamically with document.createElement('script') and then added to the webpage also don’t block this event.
@abha57
abha57 / preload, prefetch, preconnect
Created October 27, 2020 17:28
preload, prefetch, preconnect
Preload
Generally it is best to preload your most important resources such as images, CSS, JavaScript, and font files.
preload is different from prefetch in that it focuses on fetching a resource for the current navigation.
prefetch focuses on fetching a resource for the next navigation. It is also important to note that preload does not block the window's onload event.
Allows the browser to set resource priority therefore allowing web developers to optimize the delivery of certain resources.
The browser can determine if the request is compliant with the content security policy by referencing what is defined in the as attribute.
An example of preloading fonts. If you are preloading links with CORS enabled resources you must also include the crossorigin attribute.
<link rel="preload" href="https://example.com/fonts/font.woff" as="font" crossorigin>.