Skip to content

Instantly share code, notes, and snippets.

@ithinkihaveacat
ithinkihaveacat / cacheTools.js
Last active April 18, 2017 14:20
Simple functions for querying the SW cache
// Simple functions for querying the SW cache.
// Only approximate! (1) Only includes bodies. (2) Can't count opaque resources.
function cacheDump(c) {
return c.keys().then(a => {
return Promise.all(a.map(req =>
c.match(req).then(res => res.clone().blob().then(b => [req.url, b.size]))
)).then(a => new Map(a));
});
@cramforce
cramforce / on-idle.js
Created December 7, 2016 16:49
Wrapper around requestIdleCallback to wait for a minimum work budget
/**
* Delays calling the given function until the browser is notifying us
* about a certain minimum budget or the timeout is reached.
* @param {!Window} win
* @param {number} startTime When we started waiting for idle.
* @param {number} minimumTimeRemaining Minimum number of millis idle
* budget for callback to fire.
* @param {number} timeout in millis for callback to fire.
* @param {function()} fn Callback.
*/
@andreban
andreban / gifenc.sh
Last active January 15, 2021 12:31
Using ffmpeg to transform a video to an animated gif
#!/bin/sh
#Usage: ./gifenc.sh video.mkv anim.gif
palette="/tmp/palette.png"
filters="fps=30,scale=320:-1:flags=lanczos"
ffmpeg -v warning -i $1 -vf "$filters,palettegen" -y $palette
ffmpeg -v warning -i $1 -i $palette -lavfi "$filters [x]; [x][1:v] paletteuse" -y $2