Skip to content

Instantly share code, notes, and snippets.

Avatar
🇨🇦

Steven Black StevenBlack

🇨🇦
View GitHub Profile
View gist:522643
/**
* `and` plugins for jQuery
* ---
* Pretty intuitive. Enables stuff like:
* $('a').andChildren();
* Quicker & easier than:
* $('a').children().andSelf()
*/
(function(){
View gist:641692
// allow $('elem').css({ 'left' : '+=10px' });
// so you dont need to do:
// $('elem').animate({ 'left' : '+=10px' }, 0);
// by paul irish
// for ralph holzmann
// http://github.com/paulirish/lazyweb-requests/issues#issue/10
@cowboy
cowboy / ba-whatevcache.js
Created Nov 1, 2010
whatevCache: a simple localStorage-if-you-got-it, otherwise not-at-all-persistent data object cache.
View ba-whatevcache.js
/*!
* JavaScript whatevCache - v0.2pre - 12/30/2010
* http://benalman.com/
*
* Copyright (c) 2010 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
// whatevCache.set( key, value [, ttl ] );
@cowboy
cowboy / jQuery immediate ready.js
Created Nov 5, 2010 — forked from ralphholzmann/jQuery immediate ready.js
Bind DOM ready event handlers before jQuery is loaded
View jQuery immediate ready.js
// Create a "fake" jQuery function that accepts function arguments to be
// queued as DOM ready callbacks.
(function(window){
var fake = window.jQuery = window.$ = function( fn ) {
if ( Object.prototype.toString.call( fn ) === '[object Function]' ) {
fake.queue.push( fn );
}
};
@remy
remy / gist:726930
Created Dec 3, 2010
Quick sessionStorage polyfill
View gist:726930
if (!sessionStorage && JSON) {
sessionStorage = (function () {
var data = window.name ? JSON.parse(window.name) : {};
return {
clear: function () {
data = {};
window.name = '';
},
getItem: function (key) {
@cowboy
cowboy / this-propagation.js
Created May 19, 2011
JavaScript: A few ways to work around the lack of `this` propagation in inner functions
View this-propagation.js
var value = 'FAIL!!';
var obj = { value: 9000 };
// This is totally broken, because inner functions don't "inherit" the outer
// function's `this` value. Instead, their `this` value is the global object.
obj.broken = function() {
function addToValue(n) {
return this.value + n;
}
return addToValue(1);
View gist:1269763
var circleCenterPt = new paper.Point(150, 300);
var circleRadius = 75;
var sineWaveLength = 300;
var cosineWaveLength = 300;
paper.setup($('canvas')[0]);
var sineWaveStep = sineWaveLength/360;
var cosineWaveStep = cosineWaveLength/360;
var angle = 0;
@HenrikJoreteg
HenrikJoreteg / JS Util solution using underscore.js
Created Oct 22, 2010
Rather than creating some other util global, just extend underscore.js with any additional methods you want.
View JS Util solution using underscore.js
// If you don't use underscore.js, use it (http://documentcloud.github.com/underscore/)
// Then, use underscore's mixin method to extend it with all your other utility methods
// like so:
_.mixin({
escapeHtml: function () {
return this.replace(/&/g,'&')
.replace(/>/g,'>')
.replace(/</g,'&lt;')
.replace(/"/g,'&quot;')
.replace(/'/g,'&#39;');
View blacklist
# Clickbait news sources
0.0.0.0 cnn.com
0.0.0.0 nypost.com
0.0.0.0 www.dailykos.com
0.0.0.0 www.dailymail.co.uk
0.0.0.0 www.drudgereport.com
0.0.0.0 www.foxnews.com
0.0.0.0 www.huffingtonpost.com
0.0.0.0 www.mirror.co.uk
@cowboy
cowboy / jquery.ba-whenthen.js
Created Mar 12, 2011
jQuery's "when" and "then" all rolled up together.
View jquery.ba-whenthen.js
/*!
* jQuery whenthen - v0.2 - 3/12/2011
* http://benalman.com/
*
* Copyright (c) 2011 "Cowboy" Ben Alman
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/