Skip to content

Instantly share code, notes, and snippets.

@rkatic
rkatic / isNativeObject.js
Created June 3, 2011 10:25
A robust isNativeObject()
var isNativeObject = (function( window ){
var a = "Boolean Number String Function Array Date RegExp Object".split(" "),
natives = {},
hostTypes = {
"object": 1,
"function": 1
},
@rkatic
rkatic / private.js
Last active September 25, 2015 23:08
Private members hack...
function Private() {
var val, NADA = {};
return {
open: function( safe, ret ) {
val = NADA;
safe();
if ( val !== NADA ) {
ret = val;
val = NADA;
@rkatic
rkatic / isArguments.js
Created April 30, 2011 07:00
isArguments
// Cross-browser but not absolutely strong.
function isArguments( obj ) {
return typeof obj === "object" && ( "callee" in obj ) && typeof obj.length === "number";
}
// Ideally strong, but broken on Opera...
var isArguments = (function( undefined ) {
jQuery._Deferred = function() {
var // callbacks list
callbacks = [],
// stored [ context , args ]
fired,
// to avoid firing when already doing so (or it is halted)
firing,
// flag to know if the deferred has been cancelled
cancelled,
// the deferred itself
@rkatic
rkatic / debounce-example.md
Created January 21, 2011 12:00
Timer with less clear/setTimeout calls...
$(window).bind('mousemove mousedown mouseup scroll keydown keyup focus', debounce(10E3, function() {
	// idle
}));
@rkatic
rkatic / Readme.md
Created September 22, 2010 12:12
Userscript that auto appends things in reddit.

###Reddddit

Auto appends things scrolling down the page eliminating the need to click the next link.

##Install/Update

To toggle Auto Appending, click on the respective link near your username (above the login form). The asteriks near that toggler opens this page so you can easily check for new versions (specially if reddit changes).

Script will also check daily if there is a new version of it worth of user attention.

@rkatic
rkatic / jQuery.checkVersion.js
Created July 1, 2010 04:22
jQuery.checkVersion
jQuery.checkVersion = function( min, max ) {
var current = jQuery.fn.jquery + 'zz';
max = ( max || min ) + 'zz';
min += '0.0.0zz'.substr( min.length );
return min <= current && current <= max;
};
// This one will also handle 'pre' suffix as minor of 'alpha' and 'beta'.
jQuery.checkVersion = (function(){
@rkatic
rkatic / gist:316506
Created February 27, 2010 05:48
jQuery.data( object )
(function($){
var expando = "jQuery" + (new Date).getTime(),
hasOwnProperty = Object.prototype.hasOwnProperty,
_data = $.data,
_removeData = $.removeData;
$.data = function( obj, name, data ) {
if ( obj.nodeType ) {
return _data( obj, name, data );
(function($){
$.each(["live", "die"], function( i, name ) {
var method = $.fn[ name ];
$.fn[ name ] = function( types, data, fn, origSelector ) {
if ( typeof types === "object" && !types.preventDefault ) {
for ( var key in types ) {
method.call( this, key, data, types[key], origSelector );
}
@rkatic
rkatic / jquery.eachproperty.js
Created February 17, 2010 01:11
eachProperty
(function($){
var hasOwnProperty = Object.prototype.hasOwnProperty
$.eachProperty = function( obj, func, context ) {
for ( var i in obj ) {
// Own properties are enumerated firstly, so no need to continue on first not own.
if ( !hasOwnProperty.call(obj, i) || func.call( context, i, obj[i] ) === false ) {
break;
}