Skip to content

Instantly share code, notes, and snippets.

View padolsey's full-sized avatar

James Padolsey padolsey

View GitHub Profile
@padolsey
padolsey / gist:7990476
Created December 16, 2013 17:08
Get notified when you're attempting jQuery method calls on an empty collection
for (var i in $.fn) (function(method, name) {
// ignore traversal/selection methods
if (typeof method != 'function' || [
'constructor', 'init', 'find', 'add', 'next', 'nextUnil', 'prevUntil',
'parents', 'closest', 'eq', 'filter', 'has', 'first', 'siblings',
'last', 'map', 'not', 'slice', 'addBack', 'andSelf', 'contents', 'prev',
'end', 'not', 'children', 'nextAll', 'prevAll', 'parent', 'parentsUntil'
].indexOf(name) > -1) {
return;
}
@padolsey
padolsey / jQStyleThrower.js
Last active February 21, 2024 11:50
jQuery style watcher/thrower
jQuery.throwOnStyle = (function($) {
var watchers = [];
$.style = (function(_style) {
return function(elem, name, value) {
for (var i = 0, l = watchers.length; i < l; ++i) {
var w = watchers[i];
if (
(w.styleMatcher.test ?
'use strict';
var CLIENT_ID = 'CLIENT ID';
var API_KEY = 'YOUR SECRET API KEY (Test or Live)';
var TOKEN_URI = 'https://connect.stripe.com/oauth/token';
var AUTHORIZE_URI = 'https://connect.stripe.com/oauth/authorize';
var qs = require('querystring');
var request = require('request');
@padolsey
padolsey / jquery.genSelector.js
Created October 15, 2013 22:56
Cheap jQuery Selector Generation
jQuery.fn.genSelector = function() {
// Generate a selector for the given elements
// Note: Selector is not guarenteed to be unique
return this.map(function() {
var out = [], p = this;
switch (true) {
case this.id: return '#' + this.id;
case this === document.body: return 'body';
case this === document.documentElement: return 'html';
}
@padolsey
padolsey / friday.js
Created August 16, 2013 09:26
Utilities for Friday
function isItFriday() {
return new Date().getDay() === 5 ?
'It is!' :
'It is not.';
}
function whenWillItBeFriday() {
var d = 5 - new Date().getDay();
return d === 0 ?
'Right now!' :
@padolsey
padolsey / makeInterpolator.js
Last active February 21, 2024 11:50
Dead simple straight-up performant interpolation
/**
* Outputs a new function with interpolated object property values.
* Use like so:
* var fn = makeInterpolator('some/url/{param1}/{param2}');
* fn({ param1: 123, param2: 456 }); // => 'some/url/123/456'
*/
var makeInterpolator = (function() {
var rc = {
'\n': '\\n', '\"': '\\\"',
'\u2028': '\\u2028', '\u2029': '\\u2029'
@padolsey
padolsey / recruiter_call.md
Last active February 21, 2024 11:50
This happened.

"Do you know JavaScript?"

"Uhh, yes."


"Do you know Object-orientated JavaScript?"

"Yes."

@padolsey
padolsey / gist:5830966
Last active December 18, 2015 19:09
Reload stylesheets every 2s
(function() {
var all = document.querySelectorAll('link[rel=stylesheet]');
var i = setInterval(function() {
for (var l = all.length; l--;) {
var href = all[l].href;
href = href.replace(/[&\?]__reloader__=\d+/, '');
href += (href.indexOf('?') > -1 ? '&' : '?') + '__reloader__=' + +new Date;
all[l].href = href;
@padolsey
padolsey / a.md
Last active December 18, 2015 04:49
$(window).load(function() {
var h = $('#header');
setInterval(function() {
var d = new Date;
h.css('backgroundColor', 'hsl('+(0| (d.getSeconds()*1000 + d.getMilliseconds()) / 60000 * 360)+',100%,50%)');
}, 100);
});