Skip to content

Instantly share code, notes, and snippets.

View tobie's full-sized avatar

Tobie Langel tobie

View GitHub Profile
Element.addMethods({
clone: function(element) {
var clone = $(element).cloneNode(true);
$(clone).select('*[id]').concat(clone).invoke('writeAttribute', { id: null });
return clone;
}
});
var element = document.getElementById('foo');
try {
element.removeAttribute.apply(element, ['title']);
// using apply to simulate what Enum#invoke does.
} catch (e) {
alert(e.name + ': ' + e.message);
}
// in IE alerts: TypeError: Object doesn't support this property or method
function Point(x, y) {
function getX() {
return x;
}
function getY() {
return y;
}
function getOriginDistance() {
function concat() {
var array = slice.call(this, 0), item;
for (var i = 0, length = arguments.length; i < length; i++) {
item = arguments[i];
if (Object.isArray(item) && !('callee' in item)) {
for (var j = 0, arrayLength = item.length; j < arrayLength; j++)
array.push(item[j]);
} else {
array.push(item);
}
var ES_3_1_STRICT_MODE = (function(){
try {
arguments.callee;
} catch(e) {
return true;
}
return false;
})();
/*
Simpler, more robust super keyword for Prototype.
Given the following parent class:
var Person = Class.create({
initialize: function(name) {
this.name = name;
},
Object.extend = Object.extend.wrap(function(proceed, destination, source, safe) {
if (!safe) return proceed(destination, source);
for (var property in source) {
if (!(property in destination))
destination[property] = source[property];
}
return destination;
});
Object.extend({foo: 123}, {foo: 456}, true).foo
(function() {
var toString = Object.prototype.toString;
function isNumber(object) {
return toString.call(object) === "[object Number]";
}
})();
@tobie
tobie / gist:78355
Created March 12, 2009 23:33
Ruby p() of common types
p(nil)
#-> nil
p(false)
#-> false
p(true)
#-> true
p('foo')
@tobie
tobie / gist:78424
Created March 13, 2009 04:02
Python repr of common types
repr(False)
#-> False
repr(True)
#-> True
repr(None)
#-> None
repr('foo')