Skip to content

Instantly share code, notes, and snippets.

@rkatic
rkatic / graph.py
Last active August 29, 2015 14:14
graph.py
def edgesFunc(G):
if callable(G):
return G
items = _itemsFunc(G)
return lambda v: items(G[v])
# (list of dictionaries)
def bgraph(x, dicttype=dict):
@rkatic
rkatic / isObjectLiteral.html
Created July 30, 2009 10:46 — forked from jeresig/isObjectLiteral.html
isObjectLiteral STRICT
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<!-- Online here: http://ejohn.org/files/bugs/isObjectLiteral/ -->
<title>isObjectLiteral</title>
<style>
li { background: green; } li.FAIL { background: red; }
iframe { display: none; }
</style>
@rkatic
rkatic / jquery.delegate.js
Created November 5, 2009 23:30
jquery.delegate.js
(function($){
var slice = Array.prototype.slice;
$.each({
delegate: "live",
undelegate: "die"
}, function( name, original ) {
$.fn[ name ] = function( selector ) {
var $t = $(null), args = slice.call( arguments, 1 );
@rkatic
rkatic / jquery.isObject.js
Created November 8, 2009 09:17
jquery.isObject.js
(function(jQuery){
var toString = Object.prototype.toString,
hasOwnProp = Object.prototype.hasOwnProperty;
jQuery.isObject = function( obj ) {
if ( toString.call(obj) !== "[object Object]" )
return false;
//own properties are iterated firstly,
@rkatic
rkatic / isPlainObject.html
Created November 8, 2009 13:27 — forked from jeresig/isObjectLiteral.html
isPlainObject
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>isPlainObject</title>
<style>
li.PASS { background: #02C500; } li.FAIL { background: red; }
iframe { display: none; }
</style>
</head>
;(function(jQuery){
// This jQuery.filter version handles selectors and callbacks.
//
// Selector - ( elems, selector, [not] )
// This is the original jQuery.filter signature with two first arguments swapped.
//
// Callback - ( elems, callback, [thisObject], [inv] )
// This is the old jQuery.grep signature enhanced to support the ECMA-262 filter signature.
@rkatic
rkatic / README.md
Created February 16, 2010 02:19
type() - a better typeof

type.js - offers an more consistent type checking of native values. It relays on the [[Class]] of objects instead on typeof results.

type2.js - variation that returns "object" for wrapped natives. This one is probably more noob-immune, avoiding some possible strange situations.

Consider something like this:

// Defined by third...

var foo = new String("foo");

@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;
}
(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 / 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 );