Skip to content

Instantly share code, notes, and snippets.

@IUnknown68
IUnknown68 / DelegateCollection.js
Last active August 29, 2015 14:06
Array where you can add methods which will be called on each entry.
//==============================================================================
function DelegateCollection() {
for (var i = 0, m = arguments.length; i < m; i++) {
this.addCall(arguments[i]);
}
}
//------------------------------------------------------------------------------
DelegateCollection.prototype = new Array;
@IUnknown68
IUnknown68 / BlockSizeInBytes
Last active August 29, 2015 13:58
BlockSizeInBytes - block size, alignment
// ---------------------------------------------------------------------------
// BlockSizeInBytes
// Returns the number of bytes required to hold <aCount> objects of type <T>
// in blocks of <aBlockSize> bytes.
template <typename T> inline size_t BlockSizeInBytes(size_t aCount, size_t aBlockSize = 4)
{
return (((aCount * sizeof(T)) + aBlockSize - 1) / aBlockSize) * aBlockSize;
}
@IUnknown68
IUnknown68 / parseVersion.js
Last active August 29, 2015 13:57
Semantic Versioning: Extract version info
function parseVersion(s) {
var m = exp.exec(s);
return (m) ?
{
major: m[1],
minor: m[2],
patch: m[3],
pre: m[5] || '',
meta: m[7] || ''
} :
@IUnknown68
IUnknown68 / logWindowCalls.js
Last active December 31, 2015 01:29
Logs all calls on a DOM window (or any other object) to the console by replacing the functions with a wrapper. NOTE: This does not deal with errors, it is just for debugging purposes.
var target = window;
for (var i in target) {
if ("function" != typeof target[i]) continue;
target[i] = (function(name, fn) {
return function() {
console.log("" + name + " called");
return fn.apply(target, arguments);
}
})(i, target[i]);
}