Skip to content

Instantly share code, notes, and snippets.

View philwolstenholme's full-sized avatar

Phil Wolstenholme philwolstenholme

View GitHub Profile
<?php
namespace Drupal\my_module\Plugin\Field\FieldFormatter;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\responsive_image\Plugin\Field\FieldFormatter\ResponsiveImageFormatter as ResponsiveImageFormatterCore;
/**
* Responsive image formatter that allow to force the format.
@DragorWW
DragorWW / storybook-config-auto-title.js
Created November 26, 2019 23:28
Storybook: auto title base on file path
/*
Read the https://storybook.js.org/docs/guides/guide-react/
Configure:
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
jeffposnick / app.js
Created October 5, 2017 20:06
Example of staleWhileRevalidate + broadcastCacheUpdate
const HN_URL = 'https://hackernewsapi.example.com/';
function updateUI(hnData) {
// Update the DOM.
}
async function init() {
const channel = new BroadcastChannel('hn-updates');
channel.addEventListener('message', async (event) => {
if (event.data.payload.updatedUrl === HN_URL) {
@v0lkan
v0lkan / invalidate.js
Created March 13, 2017 16:38
Invalidates ServiceWorkers so that you can fetch your assets freshly.
/**
* 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 ) {
@crittermike
crittermike / IntegerDropdownWidget.php
Created October 17, 2016 20:14
Drupal 8 form widget example: creates a select dropdown for integer fields. Place in src/Plugin/Field/FieldWidget
<?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
sndrs / guardian-browser-stats.txt
Last active March 7, 2017 17:34
Guardan browser stats, for the past 7 days
This has moved:
https://github.com/guardian/frontend/wiki/Browsers-on-theguardian.com
@adactio
adactio / aria-controls.js
Last active March 8, 2024 07:07
Show and hide content with "aria-controls" buttons.
// Licensed under a CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
// http://creativecommons.org/publicdomain/zero/1.0/
(function (win, doc) {
'use strict';
if (!doc.querySelectorAll || !win.addEventListener) {
// doesn't cut the mustard.
return;
}
var toggles = doc.querySelectorAll('[aria-controls]');
var togglecount = toggles.length;
@Paul-Browne
Paul-Browne / index.html
Created March 29, 2015 21:24
JS Bin [resize width only] // source http://jsbin.com/valoyi
<!DOCTYPE html>
<html>
<head>
<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>
</head>
<body>
@beporter
beporter / composer-create-project-test.sh
Last active January 9, 2020 20:28
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
addyosmani / package.json
Last active January 18, 2024 21:31
npm run-scripts boilerplate
{
"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",