Skip to content

Instantly share code, notes, and snippets.

View jherax's full-sized avatar
👾
Performance focused

David Rivera jherax

👾
Performance focused
View GitHub Profile
@jherax
jherax / promise.allSettled.js
Last active July 16, 2024 17:17 — forked from davidbarral/promises.js
Promise.allSettled: polyfill
/**
* The Promise.allSettled() method returns a promise that resolves
* after all of the given promises have either resolved or rejected,
* with an array of objects that each describe the outcome of each promise.
*
* For each outcome object, a `status` string is present.
* If the status is "fulfilled", then a `value` is present.
* If the status is "rejected", then a `reason` is present.
* The value (or reason) reflects what value each promise
* was fulfilled (or rejected) with.
@jherax
jherax / dynamic-imports.js
Created July 4, 2024 23:59
Tricks with JS Async / Await
/**
* Dynamic imports allow you to import modules asynchronously.
* This can significantly improve the load time of web applications
* by splitting the code into smaller chunks and loading them on demand.
*/
async function loadModule(moduleName) {
try {
const module = await import(`./modules/${moduleName}.js`);
module.default(); // Assuming the module exports a default function
// module.namedExport();
@jherax
jherax / absmartly.config.json
Last active April 19, 2022 06:02
ABSmartly configuration test
{
"assignments": [
{
"experiment": "MEDICARE_REPLACEMENTS",
"pathName": "/",
"variant": 1,
"configs": [{
"apiTarget": "/content/landingpage/MEDICARE/",
"replacements": {
"data": {
@jherax
jherax / get-headers.ts
Last active April 19, 2021 15:34
Gets all Response Headers for the current document
/**
* Gets all Reponse Headers for the current document.
* @returns An object cointaining the key-value pairs for each header
*/
function getHeaders(url = document.location.href) {
const req = new XMLHttpRequest();
req.open("GET", url, false);
req.send(null);
let key: string;
@jherax
jherax / what-forces-layout.md
Created June 15, 2020 18:09 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@jherax
jherax / onScroll.rAF.js
Last active July 17, 2024 01:08 — forked from koistya/App.js
How to add `onscroll` event with requestAnimationFrame in ReactJS component
import React from 'react';
let lastScrollY = 0;
let ticking = false;
class App extends React.Component {
componentDidMount() {
window.addEventListener('scroll', this.handleScroll);
}
@jherax
jherax / README.md
Last active January 29, 2024 17:26
Debugging with VS Code

VS Code: Debugging

The way we usually debug JavaScript code, is through a web browser and typing the keyword debugger or console.log in our files, but switching between browser and VS Code can be annoying, and we also lose synchronization with the source code.

VS Code provides the extension Debugger for Chrome which enables you to edit, debug, and set breakpoints to your JavaScript

@jherax
jherax / configure.md
Last active June 13, 2024 18:10
VS Code: Debugging with Jest

VS Code: Debugging Jest

Sometimes, debugging with console.log is not enough to find out what is happening in the code, as console.log prints only plain objects but neither functions nor objects with circular references. Besides, it's possible you may need to know the context and flow of the code.

Read more about debugging with VS Code in VS Code: Debugging.

@jherax
jherax / disable-auto-zoom.html
Last active July 17, 2024 01:10
Disable auto-zoom in input elements - For Safari, iPhone
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0, shrink-to-fit=no" />
@jherax
jherax / git-ssh-auth-win-setup.md
Last active July 19, 2024 18:21 — forked from bsara/git-ssh-auth-win-setup.md
Setup SSH Authentication for Git Bash on Windows

Setup SSH Authentication for Git Bash on Windows

Prepararation

  1. Create a folder at the root of your user home folder (Example: C:/Users/username/) called .ssh.
    You can run something like: mkdir -p ~/.ssh
  2. Create the following files if they do not already exist (paths begin from the root of your user home folder):