Skip to content

Instantly share code, notes, and snippets.

Paul Grenier AutoSponge

Block or report user

Report or block AutoSponge

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View tabbable.js
function createWalker(el = document.body) {
const walker = document.createTreeWalker(
el,
NodeFilter.SHOW_ELEMENT,
{ acceptNode: node => {
if (node.tabIndex > -1) {
if (!isVisible(node)) {
return NodeFilter.FILTER_REJECT;
}
return NodeFilter.FILTER_ACCEPT;
View keybase.md

Keybase proof

I hereby claim:

  • I am autosponge on github.
  • I am autosponge (https://keybase.io/autosponge) on keybase.
  • I have a public key ASBMNb8DiTIPYIougr8ILfSo8NgNS9hjLGo0Z9N5ASoFFQo

To claim this, I am signing this object:

@AutoSponge
AutoSponge / idle.js
Last active Oct 23, 2018
idle until urgent
View idle.js
const IDLE = Symbol('IDLE')
const idle = fn => {
let result = IDLE
const resolve = requestIdleCallback(() => {
result = fn()
})
return () => {
if (result === IDLE) {
cancelIdleCallback(resolve)
result = fn()
@AutoSponge
AutoSponge / emitter.js
Last active Jun 17, 2018
event emitter
View emitter.js
class Emitter {
constructor (data) {
this.data = data
this.events = new Map()
}
on (name, fn) {
const fns = this.events.get(name) || new Set()
fns.add(fn)
this.events.set(name, fns)
@AutoSponge
AutoSponge / a11y-observer.js
Last active Apr 27, 2018
Watch mutations for accessibility issues.
View a11y-observer.js
;(function (w, c) {
var s, o = new MutationObserver(d(a), 1000)
if (typeof axe === 'undefined') {
s = w.createElement('script')
s.src = 'https://cdnjs.cloudflare.com/ajax/libs/axe-core/3.0.2/axe.min.js'
s.onload = function () {
o.observe(w.body, c)
}
w.body.appendChild(s)
@AutoSponge
AutoSponge / better-nodejs-require-paths.md
Created Apr 27, 2018 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js
View better-nodejs-require-paths.md

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

var Article = require('../../../models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@AutoSponge
AutoSponge / handleError.js
Created Apr 24, 2018
Unhandled Rejection
View handleError.js
const PrettyError = require('pretty-error')
process.on('unhandledRejection', error => {
const err = new PrettyError()
console.log(err.render(error))
})
// OR
const createCallsiteRecord = require('callsite-record')
@AutoSponge
AutoSponge / lovable.md
Last active Apr 21, 2018
Making a "Lovable" Module
View lovable.md

Lovable

Lovable modules maximize developer trust.

To learn how to maximize trust, I studied developers I trust and some of their most popular modules. It's no coincidence that I ended up using some of their modules to build mine!

Dependencies

Dependencies introduce friction. Most of the modules I trust have a small number of dependencies (including siblings). This makes sense. Removing dependencies from your module will remove friction of adoption. I decided that my first lovable module should have zero dependencies.

View speech.js
async function speak(text) {
const msg = new SpeechSynthesisUtterance();
msg.text = text;
// msg.volume = 1; // 0 to 1
// msg.rate = 1; // 0.1 to 10
// msg.pitch = 1; //0 to 2
// msg.lang = this.DEST_LANG;
msg.voice = await new Promise(resolve => {
// Voice are populated, async.
speechSynthesis.onvoiceschanged = (e) => {
@AutoSponge
AutoSponge / deep-copy.js
Created Jan 27, 2018
deep copy of obj in browser
View deep-copy.js
function structuredClone(obj) {
const oldState = history.state
history.replaceState(obj, window.title)
const copy = history.state
history.replaceState(oldState, window.title)
return copy
}
You can’t perform that action at this time.