Skip to content

Instantly share code, notes, and snippets.

View steveworkman's full-sized avatar

Steve Workman steveworkman

View GitHub Profile
@steveworkman
steveworkman / offline-analytics.js
Last active May 25, 2017 17:29
Attempt to turn the offline-analytics example into a re-usable bit of code that is also testable. Each function now uses promises to keep state
// IndexedDB properties
var idbDatabase;
const IDB_VERSION = 1,
STOP_RETRYING_AFTER = (1000 * 60 * 60 * 24), // One day, in milliseconds.
STORE_NAME = 'urls',
IDB_NAME = 'offline-analytics';
// These URLs should always be fetched from the server, or page views don't count!
const analyticsDomains = [
{ host: 'omniture.adobe.com', pathStart: '/b/ss'}, // Omniture
@steveworkman
steveworkman / Request.formData.js
Last active April 26, 2017 14:13
Request.formData() is not implemented in Chrome, so here's a polyfill that will sort it out
// OK, Chrome (and all browsers apart from Firefox) don't support Request.formData(). So, we have to polyfill it
if (!Request.formData) {
Request.prototype.formData = function() {
return this.text().then(text => {
const fd = new FormData(),
contentType = this.headers.get('content-type');
// The text here may be a URIEncoded string, rather than multipart form
// Two different decoding strategies are needed
if (contentType.startsWith('multipart/form-data;')) {
// multipart/form-data encoding strategy
@steveworkman
steveworkman / gist:3097598
Created July 12, 2012 11:31 — forked from hileon/gist:1311735
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Windows)

General

Ctrl+KB toggle side bar
Ctrl+Shift+P command prompt
Ctrl+` python console
Ctrl+N new file

Editing