Skip to content

Instantly share code, notes, and snippets.

View SaneMethod's full-sized avatar

Christopher Keefer SaneMethod

View GitHub Profile
@SaneMethod
SaneMethod / fetchCacheBlogEmbed.js
Last active September 30, 2016 19:41
Gist for embedding fetchCache source in blog post.
/**
* Copyright (c) Christopher Keefer, 2016.
* https://github.com/SaneMethod/fetchCache
*
* Override fetch in the global context to allow us to cache the response to fetch in a Storage interface
* implementing object (such as localStorage).
*/
(function (fetch) {
/* If the context doesn't support fetch, we won't attempt to patch in our
caching using fetch, for obvious reasons. */
@SaneMethod
SaneMethod / hup.js
Created November 24, 2015 20:09
Gist for embedding in post re: HUp plugin.
/**
* Copyright (c) 2013 Christopher Keefer. All Rights Reserved.
* See https://github.com/SaneMethod/HUp/
* jQuery plugin for reading in files or uploading them with the HTML5 file api and xhr2.
*/
"use strict";
(function($){
var filters = {},
fileTypes = [];
/**
@SaneMethod
SaneMethod / django-python-social-auth-monkey.py
Created July 21, 2015 21:03
Email validation pipeline monkey patch for python-social-auth and Django.
# Monkey patching - an occasionally necessary evil.
from social import utils
from social.exceptions import InvalidEmail
from django.core import signing
from django.core.signing import BadSignature
from django.contrib.sessions.models import Session
from django.conf import settings
@SaneMethod
SaneMethod / canvasToBlobShim.js
Last active April 4, 2017 16:35
Canvas toBlob Shim, adapated with thanks from https://code.google.com/u/105701149099589407503/.
/**
* Canvas toBlob shim, adapted with thanks from https://code.google.com/u/105701149099589407503/,
* from this chrome bug thread: https://code.google.com/p/chromium/issues/detail?id=67587
*/
(function(){
/**
* Convert a base64 image dataURL from a canvas element, to a blob.
* @param {function} callback
* @param {string} type
* @param {number} quality
@SaneMethod
SaneMethod / backboneMarionetteSocketSync.js
Created June 24, 2014 20:35
Socket.io Websockets for Backbone+Marionette
/**
* Copyright (c) Christopher Keefer. All Rights Reserved.
*
* Overrides the default transport for Backbone syncing to use websockets via socket.io. Includes marionette
* convenience code, specifically for sending socket-related events along the global event aggregator.
*/
(function(app, Backbone, Marionette, $, _, io){
var urlError = function(){
throw new Error('A "url" property or function must be specified.');
},
@SaneMethod
SaneMethod / backboneSocketSync.js
Created June 24, 2014 20:23
Socket.io Websockets for Backbone
/**
* Copyright (c) Christopher Keefer. All Rights Reserved.
*
* Overrides the default transport for Backbone syncing to use websockets via socket.io.
*/
(function(Backbone, $, _, io){
var urlError = function(){
throw new Error('A "url" property or function must be specified.');
},
eventEmit = io.EventEmitter.prototype.emit,
@SaneMethod
SaneMethod / elideOptions.js
Last active August 29, 2015 14:00
jQuery plugin workaround for chrome bug which prevents display of visible options when some options are hidden. Also handles hiding/showing of options in apple webkit and internet explorer, which don't respect display:none for option elements (as of 06/2014).
(function($){
var userAgent = window.navigator.userAgent,
needsWrap = (userAgent.indexOf('Trident') !== -1 || userAgent.indexOf('AppleWebKit') !== -1);
/**
* Workaround for browsers that respect hidden options elements, but then fail to resize the select dropdown
* to display any visible elements beyond those that appear before any hidden elements - namely, Chrome.
* Based on the filter function, we either select all options that match (or, if invert is true, all that
* don't match), set them to disabled (with the expectation that there's a css rule hiding disabled options
* somewhere), and then pull the disabled options out of the DOM and insert them back in at the end of the
* select - this is tested as working in the most recent version of Chrome (as of this writing, v34).
@SaneMethod
SaneMethod / customwindow.js
Created February 21, 2014 19:20
Custom google maps info window, no jquery. See also http://www.artandlogic.com/blog/2014/02/custom-google-maps-info-windows for details.
/**
* Create a custom overlay for our window marker display, extending google.maps.OverlayView.
* This is somewhat complicated by needing to async load the google.maps api first - thus, we
* wrap CustomWindow into a closure, and when instantiating CustomNativeWindow, we first execute the closure
* (to create our CustomNativeWindow function, now properly extending the newly loaded google.maps.OverlayView),
* and then instantiate said function.
* @type {Function}
* @see _mapView.onRender
*/
(function(){
@SaneMethod
SaneMethod / customwindow.jquery.js
Created February 21, 2014 18:50
Google Maps custom info window overlay, using jQuery. See also http://www.artandlogic.com/blog/2014/02/custom-google-maps-info-windows for details.
/**
* Create a custom overlay for our window marker display, extending google.maps.OverlayView.
* This is somewhat complicated by needing to async load the google.maps api first - thus, we
* wrap CustomWindow into a closure, and when instantiating CustomWindow, we first execute the closure (to create
* our CustomWindow function, now properly extending the newly loaded google.maps.OverlayView), and then
* instantiate said function.
* Note that this version uses jQuery.
* @type {Function}
*/
(function(){
@SaneMethod
SaneMethod / jquery-ajax-blob-arraybuffer.js
Last active March 14, 2022 17:57
Ajax transports to allow the sending/receiving of blobs and array buffers via the familiar jquery ajax function.To send, set data to the blob or arraybuffer to be sent, and add 'processData:false' to the ajax options.To receive, specify the 'dataType' as blob or arraybuffer in the ajax options.
(function($){
/**
* Register ajax transports for blob send/recieve and array buffer send/receive via XMLHttpRequest Level 2
* within the comfortable framework of the jquery ajax request, with full support for promises.
*
* Notice the +* in the dataType string? The + indicates we want this transport to be prepended to the list
* of potential transports (so it gets first dibs if the request passes the conditions within to provide the
* ajax transport, preventing the standard transport from hogging the request), and the * indicates that
* potentially any request with any dataType might want to use the transports provided herein.
*