Skip to content

Instantly share code, notes, and snippets.

View mfrachet's full-sized avatar
💭
😊

Marvin Frachet mfrachet

💭
😊
View GitHub Profile
@mfrachet
mfrachet / .js
Created June 1, 2022 08:55
async
const getPokemon = async () => {
const response = await fetch();
const data = await response.json();
return data.results;
};
- In some countries people have only one name (https://www.liberation.fr/checknews/2019/06/17/referendum-adp-pourquoi-y-a-t-il-une-case-je-n-ai-pas-de-prenom_1734263/)
@mfrachet
mfrachet / wow.js
Last active April 21, 2021 08:47
I don't get the order
const { setTimeout: st } = require("timers/promises");
/*
* Permutating the call to the timers setTimeout and the regular setTimeout permutates the order of apparition
* HOWEVER, "Regular promise" will always be shown first, even if declared last (micro task)
* setTimeout is still a macrotask then?
*/
function main() {
st(0).then(() => {
console.log("With promise");
@mfrachet
mfrachet / Profiling react in tests.md
Last active March 6, 2023 06:20
Profiling react in tests.md

Create the HoC

import React from "react";

export const profile = (Component) => {
  const handleRender = (
    id, // the "id" prop of the Profiler tree that has just committed
    phase, // either "mount" (if the tree just mounted) or "update" (if it re-rendered)
    actualDuration, // time spent rendering the committed update

Supervised

4 importants notions:

  • dataset
    • target (y) which what we want to optimize
    • features (x1, x2, x3 etc...) that are the "inputs" or helpers to determine y
  • model: predicts Y depending on the Xs and some input
  • cost function: measure the errors between y and the predictions
  • minimize algorithm: minimize the errors
@mfrachet
mfrachet / gitalias.sh
Last active May 5, 2020 09:44
Git alias
# Time the last 50 files have been modified
git log --format=format: --name-only --since=12.month | egrep -v '^$' | sort | uniq -c | sort -nr | egrep -v '\.json$' | egrep -v '\.lock$' | egrep -v '\.md$' | head -50
@mfrachet
mfrachet / what-forces-layout.md
Created November 24, 2019 21:31 — 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.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()
@mfrachet
mfrachet / skills.md
Created November 23, 2019 10:07 — forked from branneman/skills.md
Front-End Software Craftsmanship

JavaScript knowledge

  • Operators, operands, operator precedence (unary, binary, ternary)
  • Dynamic Type system: types and conversion
    • Value type vs. Reference type
  • Expression vs. Statement
  • Scope
  • Hoisting
  • Overloading
  • Prototypal inheritance vs. Classical inheritance
  • Instancing
@mfrachet
mfrachet / accessibility.md
Last active September 10, 2021 04:44
accessibility cheatsheet

JS tricks

document.body.addEventListener('focusin', (event) => {
    console.log(document.activeElement)
})
export const getFocusableNodes = (node, includeNegativeTabIndex) => {
@mfrachet
mfrachet / react-lazy.js
Created July 26, 2019 17:41
React lazy implementation
import React from "react";
let IDS = 0;
const loaded = {};
export const lazy = modulePathResolver => {
const id = IDS++;
return props => {
const LoadedComponent = loaded[id];