Skip to content

Instantly share code, notes, and snippets.

View AutoSponge's full-sized avatar

Paul Grenier AutoSponge

View GitHub Profile
@AutoSponge
AutoSponge / index.html
Created December 1, 2014 19:54
conditionally load webcomponent polyfills
<script>
if ('registerElement' in document
&& 'createShadowRoot' in HTMLElement.prototype
&& 'import' in document.createElement('link')
&& 'content' in document.createElement('template')) {
// We're using a browser with native WC support!
} else {
document.write('<script src="//cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/0.5.1-1/webcomponents.min.js"><\/script>');
}
</script>

Keybase proof

I hereby claim:

  • I am autosponge on github.
  • I am autosponge (https://keybase.io/autosponge) on keybase.
  • I have a public key whose fingerprint is 965C 5A63 1C5E 1BB8 D76C 252A DD8A 0FF0 AA8D 9752

To claim this, I am signing this object:

@AutoSponge
AutoSponge / bundle.js
Created April 30, 2015 19:50
jspm bundler error
(function(global) {
var defined = {};
// indexOf polyfill for IE8
var indexOf = Array.prototype.indexOf || function(item) {
for (var i = 0, l = this.length; i < l; i++)
if (this[i] === item)
return i;
return -1;
@AutoSponge
AutoSponge / args1.js
Created October 27, 2011 01:12
Arguments Speed Boost
//don't slice arguments just to iterate
//http://jsperf.com/handle-args
(function () {
var i, len;
for (i = 0, len = arguments.length; i < len; i += 1) {
console.log(arguments[i], i);
}
}(3, 2, 1));
//don't prepend arguments
@AutoSponge
AutoSponge / script_jwt.js
Created October 1, 2015 16:00
Babel npm scripts
#! /usr/bin/env babel-node
import dotenv from 'dotenv';
import program from 'commander';
import jwt from 'jsonwebtoken';
program
.usage('[options]')
.option('-u, --user <user id>', 'user id')
.option('-E, --env [value]', 'environment, defaults to development', 'development')
.parse(process.argv);
@AutoSponge
AutoSponge / util.js
Created April 13, 2012 19:13 — forked from pamelafox/util.js
JavaScript Utility Libraries (Scroll down!)
var ED = ED || {};
// Utility functions
ED.util = (function() {
// Data structure functions
function each(object, callback) {
if (object === null) return;
(function () {
var textarea;
function createTextArea() {
if (textarea) {
return textarea;
}
textarea = document.createElement('textarea');
textarea.style.position = 'absolute';
textarea.style.left = '-9999px';
textarea.style.top = (window.pageYOffset || document.documentElement.scrollTop) + 'px';
@AutoSponge
AutoSponge / sumArgs.js
Created September 18, 2012 23:37
sumArgs
function getPrecision(num) {
var split = (num + "").split(/([\.e\-]{1,2})/);
var i, len, token, next, nextNum, precision;
for (precision = 0, i = 1, len = split.length; i < len; i += 1) {
token = split[i];
next = split[i + 1];
nextNum = +next;
if (token === ".") {
precision += next.length;
} else if (token === "e-") {
@AutoSponge
AutoSponge / get.js
Last active October 10, 2015 22:17
simple get
/**
* null-safe retrieval of objects and their property values from context
* @function get
* @param {String|String[]} path
* @param {Object} [obj=this]
* @return
*/
(function (HEAD) {
var depthCache = {};
var cache = {};
@AutoSponge
AutoSponge / anti-loop.js
Last active October 12, 2015 20:18
an each implementation that caches unraveled loops
var each = (function () {
function each(arr, fn) {
var len = arr.length;
return (each[len] || (each[len] = each.factory(len), each[len]))(arr, fn);
}
each.factory = function (len) {
var body = "\tvar i = 0;\n";
while (len--) {
body += "\tfn(i, arr[i++]);\n";
}