Skip to content

Instantly share code, notes, and snippets.

View greim's full-sized avatar

Greg Reimer greim

View GitHub Profile
// created by greg reimer ("gregreimer" at gmail) http://obadger.com/
function createHistogram(rFunc) {
var arr = [];
var size = 30;
for (var i=0; i<size; i++){
arr[i] = 0;
}
for (var i=0; i<1000000; i++){
arr[Math.floor(rFunc() * size)]++;
@greim
greim / soft-model.js
Created April 3, 2012 19:09
Backbone.SoftModel
/**
Extend Backbone.SoftModel and then bind to the 'soft:change' event.
It will only fire once given a sequence of rapid-fire changes.
This avoids for example having multiple redundant renders,
which can be a performance killer. That way you don't have to
splatter your code with speculative {silent:true}s.
Warning!
This code is untested. This is just exploring an idea.
*/
@greim
greim / tree.js
Created May 17, 2011 06:08
Nice ascii-art DOM trees
/**
tree.js - nice ascii-art DOM trees
usage: tree(element[, options]);
example:
var s = tree(document.body,{
serialize: function(element){...}, // return a string representation such as "div#foo.bar"
filter: function(element){...} // return false for any nodes to not include in tree
});
console.log(s);
*/