Skip to content

Instantly share code, notes, and snippets.

View deanhume's full-sized avatar
🎮
Gaming

Dean deanhume

🎮
Gaming
View GitHub Profile
@deanhume
deanhume / fetch-api-get.js
Created August 19, 2015 10:47
A simple HTTP request using the fetch API
// url (required), options (optional)
fetch('/some/url', {
method: 'GET'
}).then(function(response) {
// success
}).catch(function(err) {
// something went wrong
});
@deanhume
deanhume / XHR-request.js
Created August 19, 2015 10:46
A simple XHR request
function successListener() {
var data = JSON.parse(this.responseText);
console.log(data);
}
function failureListener(err) {
console.log('Request failed', err);
}
var request = new XMLHttpRequest();
@deanhume
deanhume / service-worker-notification.js
Created August 3, 2015 10:20
Service Worker Notification Click
self.addEventListener('notificationclick', function(event) {
console.log('On notification click: ', event.notification.tag);
// Android doesn't close the notification when you click on it
// See: http://crbug.com/463146
event.notification.close();
// This looks to see if the current is already open and
// focuses if it is
event.waitUntil(
clients.matchAll({
@deanhume
deanhume / service-worker-push.js
Created August 3, 2015 10:19
Service Worker Push Event
self.addEventListener('push', function(event) {
debugger;
console.log('Received a push message', event);
var title = 'Notification';
var body = 'There is newly updated content available on the site. Click to see more.';
var icon = 'https://raw.githubusercontent.com/deanhume/typography/gh-pages/icons/typography.png';
var tag = 'simple-push-demo-notification-tag';
event.waitUntil(
@deanhume
deanhume / manifest.json
Created August 3, 2015 10:18
manifest-file
{
"name": "Push Demo",
"short_name": "Push Demo",
"icons": [{
"src": "https://raw.githubusercontent.com/deanhume/typography/gh-pages/icons/typography.png",
"sizes": "192x192",
"type": "image/png"
}],
"start_url": "/index.html",
"display": "standalone",
@deanhume
deanhume / service-worker.js
Last active March 16, 2016 15:03
Register Service Worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('service-worker.js').then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
registration.pushManager.subscribe({userVisibleOnly: true}).then(function(subscription){
isPushEnabled = true;
console.log("subscription.subscriptionId: ", subscription.subscriptionId);
console.log("subscription.endpoint: ", subscription.endpoint);
// TODO: Send the subscription subscription.endpoint
@deanhume
deanhume / gruntfile.js
Created May 29, 2015 14:46
A Gruntfile for the Zopfli Compression Library plugin
var path = require('path');
module.exports = function (grunt) {
grunt.initConfig({
zopfli: {
compress: {
files: {
'processed.js.gz': 'original.js'
}
},
@deanhume
deanhume / npm-list
Last active August 29, 2015 14:18
Npm List - Critical
// Grunt Critical
├─┬ [email protected]
│ ├─┬ [email protected]
│ │ └── [email protected]
│ ├─┬ [email protected].
│ │ └── [email protected]
│ └── [email protected]
├─┬ [email protected]
│ └─┬ [email protected]
│ └── [email protected]
@deanhume
deanhume / Animator-Example.html
Last active August 29, 2015 14:18
Dom Animator Example
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>title</title>
<script src="dom-animator.min.js"></script>
</head>
<body>
<script>
var domAnimator = new DomAnimator();
@deanhume
deanhume / criticalCSS.js
Created March 9, 2015 16:37
Critical CSS - Grunt File
module.exports = function (grunt) {
grunt.initConfig({
critical: {
test: {
options: {
base: './',
css: [
'css/style.css'
],