Skip to content

Instantly share code, notes, and snippets.

View maraisr's full-sized avatar
:fishsticks:

marais maraisr

:fishsticks:
View GitHub Profile
@maraisr
maraisr / useStorage.js
Created July 1, 2021 23:33 — forked from mjackson/useStorage.js
A React hook for persisting state between page refreshes (also SSR compatible)
import { useEffect, useRef } from 'react';
function getItem(storage, key) {
const value = storage.getItem(key);
if (!value) return null;
try {
return JSON.parse(value);
} catch (error) {
@maraisr
maraisr / react-scheduler.md
Created March 26, 2021 07:44 — forked from Jessidhia/react-scheduler.md
Implementation notes on react's scheduling model as of (shortly before) 16.8.0

Implementation notes on react's scheduling model as of (shortly before) 16.8.0

While the public API intended for users to use is the scheduler package, the reconciler currently does not use scheduler's priority classes internally.

ReactFiberScheduler has its own internal "mini-scheduler" that uses the scheduler package indirectly for its deadline-capable scheduleCallback.

This is kind of a documentation of implementation details that I suppose will be gone by the end of the year, but what can you do.

@maraisr
maraisr / makePushPullAsyncIterableIterator.ts
Created January 13, 2021 03:22 — forked from n1ru4l/makePushPullAsyncIterableIterator.ts
Without using Symbol.asyncIterator
type Deferred<T> = {
resolve: (value: T) => void;
reject: (value: unknown) => void;
promise: Promise<T>;
};
function createDeferred<T>(): Deferred<T> {
const d = {} as Deferred<T>;
d.promise = new Promise<T>((resolve, reject) => {
/*
Makes your remote containers low level API accessible via:
import accessFederatedContainer from "access-federated-containers";
accessFederatedContainer("app2")
*/
/** @typedef {import("webpack").Compiler} Compiler */
/** @typedef {import("webpack").Compilation} Compilation */
@maraisr
maraisr / AsyncIteratorUtilities.ts
Created November 24, 2020 09:33 — forked from n1ru4l/AsyncIteratorUtilities.ts
AsyncIteratorUtilities.ts
export const map = <T, O>(map: (input: T) => Promise<O> | O) =>
async function* mapGenerator(asyncIterable: AsyncIterableIterator<T>) {
for await (const value of asyncIterable) {
yield map(value);
}
};
export const filter = <T, U extends T>(filter: (input: T) => input is U) =>
async function* filterGenerator(asyncIterable: AsyncIterableIterator<T>) {
@maraisr
maraisr / useLocalQuery.tsx
Created December 16, 2019 01:12 — forked from sibelius/useLocalQuery.tsx
useLocalQuery hook to consume local data from a GraphQL Query
const useLocalQuery = <TQuery extends {response: any; variables: any}>(
environment: Environment,
query: any,
inVariables: TQuery['variables'] = {}
): TQuery['response'] | null => {
const variables = useDeepEqual(inVariables)
const [dataRef, setData] = useRefState<SelectorData | null>(null)
const disposablesRef = useRef<Disposable[]>([])
useEffect(() => {
const {getRequest, createOperationDescriptor} = environment.unstable_internal

Folder Structure

Motivations

  • Clear feature ownership
  • Module usage predictibility (refactoring, maintainence, you know what's shared, what's not, prevents accidental regressions, avoids huge directories of not-actually-reusable modules, etc)
@maraisr
maraisr / install_docker_centos.sh
Created September 1, 2017 01:03 — forked from opunbuds/install_docker_centos.sh
Install Docker & Docker Compose on Centos 7
#!/bin/bash
wget -qO- https://get.docker.com/ | sh
sudo usermod -aG docker $(whoami)
sudo systemctl enable docker.service
sudo systemctl start docker.service
sudo yum install -y epel-release
sudo yum install -y python-pip
sudo yum upgrade -y python*
sudo pip install docker-compose --force --upgrade