Skip to content

Instantly share code, notes, and snippets.

@buzzedword
Created October 26, 2011 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save buzzedword/1317261 to your computer and use it in GitHub Desktop.
Save buzzedword/1317261 to your computer and use it in GitHub Desktop.
Useful plugins found in my travels...
// Array Remove - By John Resig (MIT Licensed)
Array.prototype.remove = function(from, to) {
var rest = this.slice((to || from) + 1 || this.length);
this.length = from < 0 ? this.length + from : from;
return this.push.apply(this, rest);
};
// usage: log('inside coolFunc', this, arguments);
// paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/
window.log = function(){
log.history = log.history || []; // store logs to an array for reference
log.history.push(arguments);
if(this.console) {
arguments.callee = arguments.callee.caller;
var newarr = [].slice.call(arguments);
(typeof console.log === 'object' ? log.apply.call(console.log, console, newarr) : console.log.apply(console, newarr));
}
};
// make it safe to use console.log always
(function(b){function c(){}for(var d="assert,count,debug,dir,dirxml,error,exception,group,groupCollapsed,groupEnd,info,log,timeStamp,profile,profileEnd,time,timeEnd,trace,warn".split(","),a;a=d.pop();){b[a]=b[a]||c}})((function(){try
{console.log();return window.console;}catch(err){return window.console={};}})());
/*
* $.inJSON utility
*
* Searches arbitrary JSON for a key and returns an array of all matches.
* Intended for use with jQuery 1.4.2
*
* Copyright (c) 2010 Dan Connor
* www.danconnor.com
*
* Dual-licensed under the MIT and GPL licenses:
* http://www.opensource.org/licenses/mit-license.php
* http://www.gnu.org/licenses/gpl.html
*/
(function($, undefined){
$.extend($, {
inJSON: function(json, key){
var hit, hits = [];
$.each(json, function(k,v){
if (k === key)
hits.push(v);
if (typeof(v) === "string"){
return true;
} else if ($.isArray(v) || $.isPlainObject(v)) {
var r = $.inJSON(v, key);
if (r.length > 0)
hits = hits.concat(r);
}
});
return hits;
}
});
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment