Skip to content

Instantly share code, notes, and snippets.

View oliverturner's full-sized avatar
😀
Doing the thing

Oliver Turner oliverturner

😀
Doing the thing
View GitHub Profile
@oliverturner
oliverturner / index.html
Created February 2, 2024 12:56 — forked from davidwhitney/index.html
The Worlds Smallest UI Binding Library
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Home</title>
<script type="module">
function someClick() {
alert("hello");
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@oliverturner
oliverturner / totalCacheSize.js
Created October 11, 2019 19:46 — forked from jeffposnick/totalCacheSize.js
Snippet to get the total size of everything in the Cache Storage API for the current origin
async function totalCacheSize() {
let size = 0;
const cacheNames = await caches.keys();
for (const cacheName of cacheNames) {
const cache = await caches.open(cacheName);
const cachedRequests = await cache.keys();
for (const cachedRequest of cachedRequests) {
const cachedResponse = await cache.match(cachedRequest);
const responseBlob = await cachedResponse.blob();
size += responseBlob.size;

Keybase proof

I hereby claim:

  • I am oliverturner on github.
  • I am oliverturner (https://keybase.io/oliverturner) on keybase.
  • I have a public key ASD59tAQzQ1b7Hv9SGHUb873dztQRwY4dFIvC9DEv-Is1Qo

To claim this, I am signing this object:

@oliverturner
oliverturner / loadcss.js
Created June 29, 2018 10:20
Async CSS loader
const loadcss = (href, media = '') =>
new Promise(r =>
document.head.appendChild(Object.assign(
document.createElement('link'),
{
onload() { this.media = media; r() },
rel: 'stylesheet', media: 'only x', href
})
)
)
@oliverturner
oliverturner / extensions.txt
Created June 9, 2018 18:20
VSCode extensions for general web dev
Orta.vscode-jest
Shan.code-settings-sync
christian-kohler.npm-intellisense
christian-kohler.path-intellisense
codezombiech.gitignore
dbaeumer.vscode-eslint
esbenp.prettier-vscode
jasonlhy.vscode-browser-sync
jpoissonnier.vscode-styled-components
kumar-harsh.graphql-for-vscode
@oliverturner
oliverturner / extensions.sh
Created April 4, 2018 12:19
VS Code extensions
code --install-extension Orta.vscode-jest
code --install-extension PKief.material-icon-theme
code --install-extension Shan.code-settings-sync
code --install-extension TeddyDD.fish
code --install-extension bungcip.better-toml
code --install-extension capaj.vscode-exports-autocomplete
code --install-extension christian-kohler.npm-intellisense
code --install-extension christian-kohler.path-intellisense
code --install-extension codezombiech.gitignore
code --install-extension dbaeumer.vscode-eslint
function getBatteryLevel() {
navigator.bluetooth
.requestDevice({ filters: [{ services: ["battery_service"] }] })
.then(device => device.gatt.connect())
.then(server => server.getPrimaryService("battery_service"))
.then(service => service.getCharacteristic("battery_level"))
.then(characteristic => characteristic.readValue())
.then(value => {
console.log(`> Battery Level is ${value.getUint8(0)}%`);
})
@oliverturner
oliverturner / coverage.js
Created February 28, 2018 11:37 — forked from ebidel/coverage.js
CSS/JS code coverage during lifecycle of page load
/**
* @author ebidel@ (Eric Bidelman)
* License Apache-2.0
*
* Shows how to use Puppeeteer's code coverage API to measure CSS/JS coverage across
* different points of time during loading. Great for determining if a lazy loading strategy
* is paying off or working correctly.
*
* Install:
* npm i puppeteer chalk cli-table
const stream = require('stream')
const cache = new Map() // you might wanna use an lru here
function createCacheStream (url) {
const buf = []
return stream.Transform({
transform: function (data, enc, cb) {
buffer.push(data)
cb(null, data)
},