Skip to content

Instantly share code, notes, and snippets.

View richardscarrott's full-sized avatar

Richard Scarrott richardscarrott

View GitHub Profile
@acdlite
acdlite / coordinating-async-react.md
Last active March 20, 2022 12:27
Demo: Coordinating async React with non-React views

Demo: Coordinating async React with non-React views

tl;dr I built a demo illustrating what it might look like to add async rendering to Facebook's commenting interface, while ensuring it appears on the screen simultaneous to the server-rendered story.

A key benefit of async rendering is that large updates don't block the main thread; instead, the work is spread out and performed during idle periods using cooperative scheduling.

But once you make something async, you introduce the possibility that things may appear on the screen at separate times. Especially when you're dealing with multiple UI frameworks, as is often the case at Facebook.

How do we solve this with React?

@xialvjun
xialvjun / setIn.js
Last active February 23, 2021 18:23
immutable version of lodash/set
// https://github.com/lodash/lodash/issues/1696
import {clone, setWith, curry} from 'lodash/fp';
// export const setIn = curry((path, value, obj) =>
// setWith(clone, path, value, clone(obj)),
// );
export const setIn = curry((obj, path, value) =>
setWith(clone, path, value, clone(obj)),
);
@vktr
vktr / rule.js
Created February 10, 2018 18:54
Add Stripe Customer Id to Auth0 via custom rule
function (user, context, callback) {
user.app_metadata = user.app_metadata || {};
if ('stripe_customer_id' in user.app_metadata) {
context.idToken['https://example.com/stripe_customer_id'] = user.app_metadata.stripe_customer_id;
return callback(null, user, context);
}
var stripe = require('stripe')('sk_....');
var customer = {
@etagwerker
etagwerker / curl_to_ab.py
Last active April 11, 2020 11:15 — forked from ctolsen/curl_to_ab.py
"Copy to cURL" in Chrome to Apache Bench command -- Script for Python3
#!/usr/bin/env python3
import sys
import os
def curl_to_ab(curl_cmd: list, num: int=200, cur: int=4) -> str:
"""
Translate a cURL command created by Chrome's developer tools into a
command for ``ab``, the ApacheBench HTTP benchmarking tool.
cat urls.html | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*" | sort -u
grep -E : is the same as egrep
grep -o : only outputs what has been grepped
(http|https) : is an either / or
a-z : is all lower case
A-Z : is all uper case
. : is dot
/ : is the slash
? : is ?
import React from 'react';
function useCallbackOnce(callback: () => void) {
const once = React.useRef(false);
return React.useCallback(() => {
if (!once.current) {
once.current = true;
callback();
}
}, [callback]);