Skip to content

Instantly share code, notes, and snippets.

@iAmNathanJ
iAmNathanJ / README.md
Last active March 27, 2024 17:14
Debounced Promise

debounced-promise.ts

Provides a debounced function that returns a handle to a Promise which can be awaited by contextually separate callers and resolves only after the last non-debounced async operation is settled.

By default, if a given call gets debounced, subsequent call(s) will ignore the previous arguments that were provided. This can be overridden by providing a mergeArguments function that allows for the finally exectuted function to batch arguments from all invocations.

Usage in React

https://stackblitz.com/edit/debounce-promise?file=src%2FApp.tsx

@iAmNathanJ
iAmNathanJ / update-all-repos.sh
Created August 24, 2017 12:33
Recursively scan git repos and install git-secrets
#!/bin/bash
# Usage examples:
# ./update-all-repos.sh
# ./update-all-repos.sh ~/Sites ~/Projects
HIGHLIGHT="\e[01;34m"
NORMAL='\e[00m'
function update {
@iAmNathanJ
iAmNathanJ / pub-sub.md
Last active May 11, 2016 16:49
Pub Sub Notes

Publish Subscribe

  • Some similarities to Observer and Observable pattern(s)
  • Could you use an Oberserver implementation as the middle of a pub/sub implementation? ie Publisher -> Observer -> Subscribers

Problems

  • Order of subscribes and publish makes for bootstrapping/bootup order requirements. Inexplicit coupling that's hard to debug
  • Data is the coupling - how to version?
@iAmNathanJ
iAmNathanJ / simple-cb.js
Last active May 9, 2016 18:36
How To "callback"
function doSomethingWithTextFile(filePath, doThing) {
var text = readFile(filePath);
doThing(text);
}
doSomethingWithTextFile(‘my-file.txt’, console.log);
@iAmNathanJ
iAmNathanJ / math-constants.js
Created April 17, 2016 23:19
Map all the Math functions to immutable properties directly on another object
function addMathTo(obj) {
Object.getOwnPropertyNames(Math).forEach((prop) => {
let constName = String(prop).toUpperCase();
Object.defineProperty(obj, constName, {
value: Math[prop],
writable: false,
configurable: false
});
});
}
@iAmNathanJ
iAmNathanJ / index.jade
Last active August 29, 2015 14:13
CSS Animations
main.col
.row.row-top
h1.animated HELLO
.row.row-bottom
.row.toolbar
.row.select-bar
select.animation-selector
option zoomInFlip
option springOutEntrance
option springInExit
@iAmNathanJ
iAmNathanJ / canvas-backgrounds.html
Last active August 29, 2015 14:10
Multiple Canvas Backgrounds
<!-- HTML -->
<div class="background">
<div class="canvas back">
<canvas id="canvas-back"></canvas>
</div>
<div class="canvas mid">
<canvas id="canvas-mid"></canvas>
@iAmNathanJ
iAmNathanJ / canvas-backgrounds.js
Last active August 29, 2015 14:10
Multiple Canvas Backgrounds
// JavaScript
(function(){
$(document).ready(function(){
var $background = $('div.background'),
backgroundWidth = $background.width(),
backgroundHeight = $background.height(),
canvasBack = document.getElementById('canvas-back'),