Skip to content

Instantly share code, notes, and snippets.

View maraisr's full-sized avatar
:fishsticks:

marais maraisr

:fishsticks:
View GitHub Profile
@maraisr
maraisr / thingy.ts
Last active November 2, 2021 03:31
function makePromisibleStream(streamable) {
return {
async then(resolve) {
const stream = streamable();
const returns = [];
for await (const i of stream) {
returns.push(i);
}
@maraisr
maraisr / index.js
Created September 19, 2021 00:00
Clean Forks on GitHub
import { Octokit } from '@octokit/rest';
const client = new Octokit({
auth: process.env.GITHUB_TOKEN,
});
const repos = await client.repos.listForUser({
username: 'maraisr',
per_page: 200,
});
@maraisr
maraisr / index.d.ts
Last active August 9, 2021 00:57
swrt — Safe Write file
type FileType = string | Buffer | URL;
type DataType = string | Buffer;
declare function writeFile(path: FileType, body: DataType, content_type?: string): Promise<void>;
declare function writeFileSync(path: FileType, body: DataType, content_type?: string): void;
export { writeFile, writeFileSync };
@maraisr
maraisr / worker.js
Created July 28, 2021 03:10
GeoRedirect CF Worker
const localeMap = {
AU: "/au",
US: "/us",
GB: "/uk",
NZ: "/nz",
MX: "/es-mx",
"*": "/au",
};
addEventListener(
@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 / README.md
Last active April 7, 2021 10:04
Streaming React with Server Timings

Run

$ yarn
$ mkdir -p ssl/
$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ssl/foobar.key -out ssl/foobar.crt
$ node server
@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.

{
main: "cjs",
module: "esm node",
browser: "esm browser",
unpkg: "umd",
"exports": {
".": {
"browser": {
"import": "esm browser",
"require": "cjs browser"
@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 */