This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Valuechange event and handler | |
* See: http://learn.jquery.com/events/event-extensions/ | |
*/ | |
(function($) { | |
var name = "valuechange"; | |
$.event.special[name] = { | |
// Event is bound |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Creates a function that executes with the given context and pushes the original context to the first argument of the function. | |
unshiftContext: function(func, thisArg) { | |
return function() { | |
var args = Array.prototype.slice.call(arguments); | |
args.unshift(this); | |
func.apply(thisArg, args); | |
}; | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function formatPostcode(postcode){ | |
return( | |
//if character fourth from the right is not space | |
postcode.slice(-4,-3) !== " " | |
//insert space three characters from the right | |
?postcode.slice(0,-3) + " " + postcode.slice(-3) | |
//otherwise use origional | |
:postcode | |
) | |
// upper case |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function wait(/* functions returning promises*/) { | |
return (function() { | |
return $.when.apply($, Array.prototype.map.call(actions, function(a) { return a(); })); | |
}).bind(Array.prototype.slice.call(arguments)); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function hash(s){ | |
return Array.prototype.reduce.call(s, function(a,b){ a = (( a << 5) -a ) + b.charCodeAt(0); return a&a }, 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onceMore(f) { | |
var isWorking = false, | |
isWaiting = false; | |
function execute() { | |
isWaiting = false; | |
isWorking = true; | |
f().then(complete); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: There is a bug in NServiceBus where registered callbacks that are not invoked remain in a static dictionary. | |
var asyncResult = _bus.Send(message).Register(ar => { }, null); | |
if (!asyncResult.AsyncWaitHandle.WaitOne(_timeout)) | |
{ | |
// Signal the async result so callback threads don't remain blocked | |
((EventWaitHandle)asyncResult.AsyncWaitHandle).Set(); | |
throw new OperationCanceledException(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class Has | |
{ | |
public static IResolveConstraint Attribute<T>() where T : class | |
{ | |
return new Constraints.AttributeConstraint<T>(new Dictionary<string, object>(), new object[0]); | |
} | |
public static IResolveConstraint Attribute<T>(IDictionary<string, object> namedConstructorArguments, params object[] constructorArguments) where T : class | |
{ | |
return new Constraints.AttributeConstraint<T>(namedConstructorArguments, constructorArguments); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Unpatch.js | |
// Sam Greenhalgh | |
// http://RadicalResearch.co.uk/ | |
// Example usage | |
// window.console.log = unpatch(window.console.log); | |
function unpatch(method) { | |
var _ = Function.prototype.apply; | |
var r; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Function.prototype.extends=function(base){ | |
var t = function () {} | |
t.prototype = base.prototype; | |
this.prototype = new t(); | |
this.prototype.constructor = this; | |
}; | |
var Animal = function(){ | |
this.isAlive = true; | |
} |
OlderNewer