Skip to content

Instantly share code, notes, and snippets.


Phil Wolstenholme philwolstenholme

View GitHub Profile
DragorWW / storybook-config-auto-title.js
Created Nov 26, 2019
Storybook: auto title base on file path
View storybook-config-auto-title.js
Read the
1) open ./storybook/config.js
2) remove configure(require.context('../src', true, /\.stories\.js$/), module);
3) replace with the code below
4) change path prepare in to getTitle function
5) remove in story files export default.title
jeffposnick / app.js
Created Oct 5, 2017
Example of staleWhileRevalidate + broadcastCacheUpdate
View app.js
const HN_URL = '';
function updateUI(hnData) {
// Update the DOM.
async function init() {
const channel = new BroadcastChannel('hn-updates');
channel.addEventListener('message', async (event) => {
if ( === HN_URL) {
v0lkan / invalidate.js
Created Mar 13, 2017
Invalidates ServiceWorkers so that you can fetch your assets freshly.
View invalidate.js
* Invalidates the current `ServiceWorker` running on the page.
* Why? Because managing a cache is damn hard; and sometimes due to race conditions
* your assets might get out-of-sync.
* This mini snippet checks the version of the app against an uncached resource and
* invalidates the workers if it finds a mismatch.
if ( navigator.serviceWorker && navigator.serviceWorker.getRegistrations ) {
mikecrittenden / IntegerDropdownWidget.php
Created Oct 17, 2016
Drupal 8 form widget example: creates a select dropdown for integer fields. Place in src/Plugin/Field/FieldWidget
View IntegerDropdownWidget.php
* @file
* Defines a dropdown widget for integer fields.
namespace Drupal\nba_content_core\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldFilteredMarkup;
use Drupal\Core\Field\FieldItemListInterface;
sndrs / guardian-browser-stats.txt
Last active Mar 7, 2017
Guardan browser stats, for the past 7 days
View guardian-browser-stats.txt
This has moved:
adactio / aria-controls.js
Last active Oct 30, 2020
Show and hide content with "aria-controls" buttons.
View aria-controls.js
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
(function (win, doc) {
'use strict';
if (!doc.querySelectorAll || !win.addEventListener) {
// doesn't cut the mustard.
var toggles = doc.querySelectorAll('[aria-controls]');
var togglecount = toggles.length;
Paul-Browne / index.html
Created Mar 29, 2015
JS Bin [resize width only] // source
View index.html
<!DOCTYPE html>
<meta name="description" content="[resize width only]">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>JS Bin</title>
beporter /
Last active Jan 9, 2020
Make the process of testing a `composer create-project` command easier by operating against your local working copy.
#!/usr/bin/env bash
# Allows you to test the create-project process using your local
# checked-out copy of the skeleton as the source. You MUST commit the
# changes you want to test to a git branch! You MUST name that branch
# as the first argument and the destination path to set up the fresh
# copy into as the second.
# Usage:
# - Place this script in your package's root directory and make it executable.
# - Set the PACKAGE_NAME variable below to match your composer.json's `name`.
addyosmani / package.json
Last active Jan 7, 2021
npm run-scripts boilerplate
View package.json
"name": "my-app",
"version": "1.0.0",
"description": "My test app",
"main": "src/js/index.js",
"scripts": {
"jshint:dist": "jshint src/js/*.js",
"jshint": "npm run jshint:dist",
"jscs": "jscs src/*.js",
"browserify": "browserify -s Validating -o ./dist/js/build.js ./lib/index.js",
benvium / resizer.txt
Last active Sep 3, 2018 — forked from gingertom/
Resize all @3x images in a folder to @2x and @1x sizes. Using this script you need only ever edit the @3x images. Drop this script into the folder containing your images and double-click it in Finder to run. Note it will destructively overwrite the @2x and @1x-sized images, so be careful. Don't run this script in a folder that's not under versio…
View resizer.txt
#!/bin/bash -e
# Ensure we're running in location of script.
cd "`dirname $0`"
for f in *; do
if [[ $f == *@3x* ]];
echo "$f -> ${f//@3x/@2x}, ${f//@3x/}"
convert "$f" -resize 66.66666% "${f//@3x/@2x}"