Skip to content

Instantly share code, notes, and snippets.

View flipflop's full-sized avatar

Rozario Chivers flipflop

View GitHub Profile
@psenger
psenger / with-cancel.js
Last active April 12, 2024 05:10
[Promise Design Patterns Timeout on Asynchronous Operations] #JavaScript #Promise
// ----------
// Cancel function!
// ----------
// NOTE:
// This allows us to externalize the cancel function..
// kind of like a inversion of control
let expensiveApplication = delayMs => new Promise(resolve => setTimeout(resolve, delayMs))
// Long Running Process - LRP with cancel function!
@jkrems
jkrems / index.md
Last active November 3, 2023 14:34
JavaScript: Classic Scripts vs. Modules vs. CommonJS

JavaScript File Format Differences

There's the pervarsive notion that all JS is created equal and that there's only minor and easily detectable differences between the various file formats used to author JavaScript. This is correct, from a certain point of view.

A certain point of view?

For many people writing JavaScript that gets passed into build tools,

@KidkArolis
KidkArolis / post.md
Last active November 17, 2020 11:21
Designing custom React hooks - sequencing of async effects

We've been building a hooks based REST API wrapper.

A specific use case discussed in this gist is – how do you close a modal after updating a remote resource completes succesfully?

Which of the following options seems best or is there a better approach altogether?

1. Async/Await

function EditNoteModal ({ id, onClose }) {
@kitze
kitze / store.js
Created January 24, 2018 13:14
simplified redux
import produce from 'immer';
import {createStore} from 'redux';
const handleActions = (actionsMap, defaultState) => (
state = defaultState,
{type, payload}
) =>
produce(state, draft => {
const action = actionsMap[type];
action && action(draft, payload);
@emeeks
emeeks / d3.sankey.js
Last active December 31, 2021 13:45
Sankey Particles
d3.sankey = function() {
var sankey = {},
nodeWidth = 24,
nodePadding = 8,
size = [1, 1],
nodes = [],
links = [];
sankey.nodeWidth = function(_) {
if (!arguments.length) return nodeWidth;
@paulirish
paulirish / what-forces-layout.md
Last active July 16, 2024 16:33
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Generally, all APIs that synchronously provide layout metrics will trigger forced reflow / layout. Read on for additional cases and details.

Element APIs

Getting box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
@PurpleBooth
PurpleBooth / README-Template.md
Last active July 13, 2024 23:36
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@remy
remy / peek.js
Last active August 29, 2015 14:23
Is this okay? The peek will just act as a benign through stream letting us see the first item. Would this add much overhead to the time do you think?
var peek = module.exports = function (fn) {
var peeked = false;
return through(function write(data) {
this.emit('data', data);
if (peeked) {
return;
}
peeked = true;
var stream = this;
var cont = function (end) {
@makmanalp
makmanalp / comparison.md
Last active June 10, 2024 14:24
Angular vs Backbone vs React vs Ember notes

Note: these are pretty rough notes I made for my team on the fly as I was reading through some pages. Some could be mildly inaccurate but hopefully not terribly so. I might resort to convenient fiction & simplification sometimes.

My top contenders, mostly based on popularity / community etc:

  • Angular
  • Backbone
  • React
  • Ember

Mostly about MVC (or derivatives, MVP / MVVM).

Development Contract Killer

A fork of the popular open-source contract for web designers and developers by Stuff & Nonsense, reworded for developers


Between us [company name] and you [customer name]