Skip to content

Instantly share code, notes, and snippets.

View ithinkihaveacat's full-sized avatar

Michael Stillwell ithinkihaveacat

View GitHub Profile
function injectScript(src) {
return new Promise(resolve => {
const e = document.createElement("script");
e.src = src;
e.onload = resolve;
document.head.appendChild(e);
});
}
// Example usage
@ithinkihaveacat
ithinkihaveacat / service-worker.d.ts
Last active July 1, 2025 01:39 — forked from tiernan/service-worker.d.ts
Typings for using the Service Worker API with TypeScript
/**
* Copyright (c) 2016, Tiernan Cridland
*
* Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby
* granted, provided that the above copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
* INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR

Temporarily disable rules

foo(); // eslint-disable-line

/* eslint-disable no-alert, no-console */
alert('foo');
console.log('bar');
/* eslint-enable no-alert, no-console */
@ithinkihaveacat
ithinkihaveacat / google-signin.js
Created June 27, 2016 02:06
More sane version of some of the Google sign in libraries
/**
* Promise'd version of `gapi.load`.
*/
function gapiLoad<T>(s: string): Promise<T> {
return new Promise((resolve, reject) => {
if ("gapi" in window) {
gapi.load(s, () => resolve(gapi[s]));
} else {
reject("window.gapi not found");
}
function gapiLoad(s) {
return new Promise(r => {
gapi.load(s, () => r(gapi[s]));
});
}
function getClient(s, v) {
if (!v) v = 'v1';
return gapiLoad('client').then(client => {
client.load(s, v).then(function() {
@ithinkihaveacat
ithinkihaveacat / example.js
Last active March 7, 2017 17:06
"Globals" in service workers via the cache and Proxies
getGlobal('flags').then(flags => {
flags['debug'] = true;
flags['email'] = '[email protected]';
});
// sometime later
getGlobal('flags').then(flags => {
console.log(JSON.stringify(flags)); // -> {"debug":true,"email":"[email protected]"}
});
Promise.all([1, 2]).then(Object.apply.bind((a, b) => { console.log(`a = ${a}, b = ${b}`) }, null))
// -> a = 1, b = 2

Keybase proof

I hereby claim:

  • I am ithinkihaveacat on github.
  • I am ithinkihaveacat (https://keybase.io/ithinkihaveacat) on keybase.
  • I have a public key whose fingerprint is B468 8845 C785 40D2 21C7 EA63 48DB DBA1 A472 8398

To claim this, I am signing this object:

Create the project

In Google Developers Console:

  1. Create new project (myproject).
  2. Create a new git repository. (You can use the one described at Source Code | Browse.)

Install web-starter-kit dependencies

See .

@ithinkihaveacat
ithinkihaveacat / designer.html
Last active August 29, 2015 14:03
designer
<link rel="import" href="../paper-tabs/paper-tabs.html">
<link rel="import" href="../paper-tabs/paper-tab.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;