Skip to content

Instantly share code, notes, and snippets.

View oieduardorabelo's full-sized avatar

Eduardo Rabelo oieduardorabelo

View GitHub Profile

finally-polyfill

A tiny ~150-byte polyfill for Promise.prototype.finally.

Useful for browsers that support Promise but not the .finally() method.

Usage

npm install finally-polyfill

@tannerlinsley
tannerlinsley / onWindowFocus.ts
Last active January 30, 2024 09:37
A utility function to detect window focusing without false positives from iframe focus events
type State = {
added: boolean;
interval: false | ReturnType<typeof setInterval>;
inFrame: boolean;
callbacks: Array<SetFocusedCallback>;
};
type EnrichedHTMLIFrameElement = HTMLIFrameElement & { ___onWindowFocusHandled: boolean };
type SetFocusedCallback = (focused?: boolean) => void;
/**
* @flow
*/
opaque type Ruleset = { [string]: string | number };
type CreateInput = {
[styleName: string]: CSSProperties
};
@vincentriemer
vincentriemer / VideoProgressSlider.js
Created July 21, 2019 18:29
The current (WIP) implementation of chonkit's video progress slider.
/**
* @flow
*/
import VisuallyHidden from "@reach/visually-hidden";
import instyle from "instyle";
import * as React from "react";
import { Focus } from "react-events/focus";
import { Drag } from "react-events/drag";
import { Press } from "react-events/press";
@Can-Sahin
Can-Sahin / cognito-idtoken-cli.sh
Last active February 14, 2023 21:22
Simple shell script to obtain a IdToken from Cognito User Pool. Just like logging in.
#!/bin/bash
username="COGNITO_USER_NAME"
password="PASSWORD"
clientid="APP_CLIENT_ID"
region="eu-west-1"
aws_profile="AWS_CLI_PROFILE"
response_json=""
json_field='IdToken'
@julianpitt
julianpitt / getAWSServiceRegions.js
Created May 4, 2019 03:47
[Get AWS Service Regions]Get a list of supported aws regions for a particular service #aws #javascript
const AWS = require('aws-sdk');
const ssm = new AWS.SSM();
function getRegionFromServiceRegionResponse(ServiceRegionResponse) {
return ServiceRegionResponse.Parameters
.map((serviceRegion => serviceRegion.Value));
}
function getServiceRegions(serviceName) {
let params = {
@johanalkstal
johanalkstal / example.js
Last active April 29, 2024 03:12
Basic Svelte Store Routing
/**
* Basic example of routerless store based routing.
* To understand what is going on check out
* https://svelte.dev/tutorial/writable-stores
* https://www.npmjs.com/package/feather-route-matcher
*/
// stores.js
@Rich-Harris
Rich-Harris / index.js
Last active January 22, 2020 22:21
whatwg stream utils
const fs = require('fs');
const { ReadableStream, TransformStream, WritableStream} = require('web-streams-polyfill/ponyfill/es2018');
function createReadStream(file, opts) {
return new ReadableStream({
start(controller) {
const stream = fs.createReadStream(file, opts);
stream.on('readable', () => {
const data = stream.read();
controller.enqueue(data);
@schettino
schettino / useUserReducer.ts
Created March 30, 2019 20:23
Better Reducers with React and Typescript 3.4
import { useReducer } from 'react'
export function updateName(name: string) {
return <const>{
type: 'UPDATE_NAME',
name
}
}
export function addPoints(points: number) {
@swyxio
swyxio / Optimistic, Offline-first apps using serverless functions and GraphQL.md
Last active November 7, 2020 11:11
Optimistic, Offline-first apps using serverless functions and GraphQL

now published as https://www.swyx.io/writing/svelte-amplify-datastore

Optimistic, Offline-first apps using serverless functions and GraphQL

Some thoughts on the challenges of the first 2 and possibly solving them with the latter 2.

Optimistic

In a world where API latency is unpredictable, the way to make user interactions seem instant is essentially by lying to the user. Most implementations of optimistic updates work like this: