Skip to content

Instantly share code, notes, and snippets.

View Jameswilliamquinn2016's full-sized avatar

Jameswilliamquinn2016

View GitHub Profile
@Jameswilliamquinn2016
Jameswilliamquinn2016 / checkWebpSupport.js
Created September 12, 2016 14:23 — forked from ymatuhin/checkWebpSupport.js
Check WebP Support in browser
function checkSupport(fn) {
var html = document.documentElement,
WebP = new Image();
WebP.onload = WebP.onerror = function() {
isSupported = (WebP.height === 2);
if (isSupported) {
if (html.className.indexOf('no-webp') >= 0)
html.className = html.className.replace(/\bno-webp\b/, 'webp');
@Jameswilliamquinn2016
Jameswilliamquinn2016 / generate-pushid.js
Created August 25, 2016 07:20 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@Jameswilliamquinn2016
Jameswilliamquinn2016 / ajax.js
Created August 22, 2016 16:24 — forked from skhatri/ajax.js
simple ajax - cors request, jsonp, xmlhttprequest
function Ajax() {
}
Ajax.prototype.jsonpHandler = function (url, callback) {
var scripturl = url + ((url.indexOf("?") !== -1) ? "&" : "?") + "callback=" + callback;
document.write('<script src="' + scripturl + '"></script>');
return scripturl;
};
Ajax.prototype.request = function (method, url, fallback, options) {