Skip to content

Instantly share code, notes, and snippets.


Jonathan M. Hollin PerpetualBeta

View GitHub Profile
Rich-Harris /
Last active Apr 12, 2021
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

adactio / basicServiceWorker.js
Last active Apr 1, 2021
A basic Service Worker, for use on, say, a blog.
View basicServiceWorker.js
'use strict';
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
(function() {
// Update 'version' if you need to refresh the cache
var staticCacheName = 'static';
var version = 'v1::';
AllThingsSmitty / css-not.scss
Last active Nov 28, 2018
Use CSS :not() instead of applying and unapplying borders on navigations
View css-not.scss
.nav-tab {
// instead of putting it on
border-right: 1px solid #424242;
&:last-child {
border-right: 0; // and then taking it off
// use CSS not() to only apply to the elements you want
&:not(:last-child) {
border-right: 1px solid #424242;
ImJasonH / markdown.css
Last active Apr 15, 2021
Render Markdown as unrendered Markdown (see
View markdown.css
* {
font-size: 12pt;
font-family: monospace;
font-weight: normal;
font-style: normal;
text-decoration: none;
color: black;
cursor: default;
lttlrck / gist:9628955
Created Mar 18, 2014
rename git branch locally and remotely
View gist:9628955
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
gruber / Liberal Regex Pattern for Web URLs
Last active Mar 30, 2021
Liberal, Accurate Regex Pattern for Matching Web URLs
View Liberal Regex Pattern for Web URLs
The regex patterns in this gist are intended only to match web URLs -- http,
https, and naked domains like "". For a pattern that attempts to
match all URLs, regardless of protocol, see:
# Single-line version:
jeroenjanssens /
Last active Dec 30, 2015
Simple chat server in bash, demonstrating websocketd.
# Hacked together by on 2013-12-10
# Requires:
# Run: websocketd --devconsole --port 8080 ./
echo "Please enter your name:"; read USER
echo "[$(date)] ${USER} joined the chat" >> chat.log
echo "[$(date)] Welcome to the chat ${USER}!"
tail -n 0 -f chat.log --pid=$$ | grep --line-buffered -v "] ${USER}>" &
while read MSG; do echo "[$(date)] ${USER}> ${MSG}" >> chat.log; done
WebReflection / Delayed.js
Last active Mar 4, 2020
whenever you need to execute something after an interaction that might happen many times (panning, scrolling, etc) … this simple mechanism makes simple to execute that maybe expensive operations only once when things are "quiet" and never before or in the middle, if an action start as "start panning" would be is fired and it's calling the clear(…
View Delayed.js
/*jslint browser: true, indent: 2 */
var Delayed = (function (delay) {
/*! Andrea Giammarchi - Mit Style License */
'use strict';
// method shared across all delayed wrappers
function clear() {
yaph / checkboxes.js
Last active Sep 11, 2019
Check or uncheck all check boxes using browser JavaScript console
View checkboxes.js
# JS snippet for email notification settings, e. g. Twitter
cb=document.querySelectorAll('input[type="checkbox"]');for(i in cb){cb[i].checked=false}
# for Drupal 4.x comment approval form
cbx=document.getElementsByClassName('form-checkbox');for(i in cbx){cbx[i].checked=true}
driscollwebdev / usefulStyles.css
Created Oct 8, 2012
CSS to horizontally center an IMG element
View usefulStyles.css
img.centered {
display: block;
margin-left: auto;
margin-right: auto;