Skip to content

Instantly share code, notes, and snippets.

View Wizyma's full-sized avatar
🎯
Focusing

André Gomes Wizyma

🎯
Focusing
View GitHub Profile
export const intersperse = <T>(arr: T[], separator: (n: number) => T): T[] =>
arr.flatMap(arr, (a, i) => i > 0 ? [separator(i-1), a] : [a]))
@gaearon
gaearon / uselayouteffect-ssr.md
Last active May 2, 2024 13:42
useLayoutEffect and server rendering

If you use server rendering, keep in mind that neither useLayoutEffect nor useEffect can run until the JavaScript is downloaded.

You might see a warning if you try to useLayoutEffect on the server. Here's two common ways to fix it.

Option 1: Convert to useEffect

If this effect isn't important for first render (i.e. if the UI still looks valid before it runs), then useEffect instead.

function MyComponent() {
import PropTypes from 'prop-types';
type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
type Defined<T> = T extends undefined ? never : T;
/**
* Get the type that represents the props with the defaultProps included.
*
* Alternatively, we could have done something like this:
@bvaughn
bvaughn / index.md
Last active April 3, 2024 07:41
Interaction tracing with React

This API was removed in React 17


Interaction tracing with React

React recently introduced an experimental profiler API. After discussing this API with several teams at Facebook, one common piece of feedback was that the performance information would be more useful if it could be associated with the events that caused the application to render (e.g. button click, XHR response). Tracing these events (or "interactions") would enable more powerful tooling to be built around the timing information, capable of answering questions like "What caused this really slow commit?" or "How long does it typically take for this interaction to update the DOM?".

With version 16.4.3, React added experimental support for this tracing by way of a new NPM package, scheduler. However the public API for this package is not yet finalized and will likely change with upcoming minor releases, so it should be used with caution.

@madbean
madbean / gist:291c43630b9adce3275f0116987d90f5
Created July 29, 2018 16:57
scaleway docker - rancher/agent
Info
Scaleway est livré actuellement avec docker-engine 1.12.2
Rancher lui a besoin de version précise docker-engine
http://docs.rancher.com/rancher/v1.5/en/hosts/
update rancher-engine
enter your pass phrase used with your ssh key generated on your laptop.
@gaearon
gaearon / prepack-gentle-intro-1.md
Last active February 13, 2024 14:30
A Gentle Introduction to Prepack, Part 1

Note:

When this guide is more complete, the plan is to move it into Prepack documentation.
For now I put it out as a gist to gather initial feedback.

A Gentle Introduction to Prepack (Part 1)

If you're building JavaScript apps, you might already be familiar with some tools that compile JavaScript code to equivalent JavaScript code:

  • Babel lets you use newer JavaScript language features, and outputs equivalent code that targets older JavaScript engines.
@montanaflynn
montanaflynn / CONCURRENCY.md
Last active April 20, 2024 17:00
Examples of sequential, concurrent and parallel requests in node.js

Concurrency in JavaScript

Javascript is a programming language with a peculiar twist. Its event driven model means that nothing blocks and everything runs concurrently. This is not to be confused with the same type of concurrency as running in parallel on multiple cores. Javascript is single threaded so each program runs on a single core yet every line of code executes without waiting for anything to return. This sounds weird but it's true. If you want to have any type of sequential ordering you can use events, callbacks, or as of late promises.

import Ember from 'ember';
export default Ember.Component.extend({
tagName: '', // Does not let Ember inject HTML into the component.
routing: Ember.inject.service('-routing'),
breadcrumbs: Ember.computed('routing.currentRouteName', function () {
console.log('--> current route: %s', this.get('routing.currentRouteName'));
Ember.getOwner(this).lookup('route:' + this.get('routing.currentRouteName')).label;
this.get('routing.router');
}),
@lukas-h
lukas-h / license-badges.md
Last active May 1, 2024 10:20
Markdown License Badges for your Project

Markdown License badges

Collection of License badges for your Project's README file.
This list includes the most common open source and open data licenses.
Easily copy and paste the code under the badges into your Markdown files.

Notes

  • The badges do not fully replace the license informations for your projects, they are only emblems for the README, that the user can see the License at first glance.

Translations: (No guarantee that the translations are up-to-date)

@staltz
staltz / introrx.md
Last active May 2, 2024 12:31
The introduction to Reactive Programming you've been missing