Skip to content

Instantly share code, notes, and snippets.

View padolsey's full-sized avatar

James Padolsey padolsey

View GitHub Profile
/* Taken from http://wave.google.com/maintenance/index.html / Google */
var cloudMoved = false;
var cloud2Moved = false;
var cloud3Moved = false;
var WAVE_TIME = 6000;
$(init);
function init()
// "elem" is an element within the document, visible to the user
elem.style.display = "none";
elem.style.display = "block";
/**
* Random number generator, never returns the same number
* more than once, only returns integers.
* @param min minimum number, inclusive
* @param max maximum number, inclusive
* Both @params are optional
*/
var generateRandomNumber = (function(){
var used = {};
var script = document.createElement('script');
var code = "alert('foo');";
try{
script.appendChild(document.createTextNode(code))
} catch(e) {
// IE
script.text = code;
}
jQuery(yourNodes).append(jQuery('<a>Click</a>').click(function(){
var self = this.parentNode, // parentNode is a single element within yourNodes
loading = $('<div>LOADING</div>').appendTo(self),
id = self.id.replace(/^edit/,'');
// Retrieve textarea from server
jQuery.get('/getDataForTextArea?id=' + id, function(textareaValue){
loading.remove();
/// Run this code in any browser
function RegularConstructor () {
}
RegularConstructor.prototype = {
meth1: function(){},
meth2: function(){},
meth3: function(){},
function getSomething( a, b, c ) {
// Multiple return points aren't always bad ya' know!
if ( !(a && b && c) ) { return; }
// Continue with function,
// we know a, b and c are truthy values!
return /* whatever */;
new SiteTraverser({
limit: 100,
check: function(source){
return /<title>/.test(source) ?
new SiteTraverser.Success("Title Found!") : new SiteTraverser.Failure("No Title!");
},
httpError: function(xhr){
return new SiteTraverser.Failure("Request failed.", 'Error code: ' + xhr.status);
}
}).go();
// @author James Padolsey
// originally posted @ http://stackoverflow.com/questions/1837056
Array.prototype.binarySearch = function(v) {
/* ARRAY MUST BE SORTED */
if ( !this.length ) { return false; }
if ( this[0] === v ) { return true; }
$(ELEMENT).animate({
left: [ 200, 'easeInOut' ],
top: [ 100, 'easeInSine' ],
width: 500
}, 1000, 'linear');
// The "linear" easing will only be used for the
// "width" property as the other two ("top" & "left")
// have their own easing functions to follow.