Skip to content

Instantly share code, notes, and snippets.

@brentsowers1
brentsowers1 / gist:2907639
Created June 10, 2012 23:10
jQuery attachment types test case 2
function generate10KRandomClass(attachEventDirectly) {
var generateFunction = function() {
var containerElement = $("#container");
containerElement.html("");
if (!attachEventDirectly) {
// There will be 100 possible classes, call .on for each
for (var i=0; i < 100; i++) {
containerElement.on('click', ".randomClassItem" + i, callbackFunction);
}
}
@brentsowers1
brentsowers1 / gist:2907631
Created June 10, 2012 23:07
jQuery attachment types test case 1
// Some action that triggers generating 10,000 elements
function generate10KElements(attachEventDirectly) {
var generateFunction = function() {
var containerElement = $("#container");
containerElement.html("");
if (!attachEventDirectly) {
// This is the magic, all items within the container div that have a CSS class
// of sameClassItem get the callbackFunction handler.
containerElement.on('click', ".sameClassItem", callbackFunction);
}
@brentsowers1
brentsowers1 / gist:2907597
Created June 10, 2012 22:59
jQuery attachment types common code
var clickStartTime;
function timeAction(localThis, actionFunction) {
var startTime = new Date();
actionFunction.call(localThis);
var endTime = new Date();
alert("Took " + (endTime.getTime() - startTime.getTime()) + " ms to run");
}
function callbackFunction() {
@brentsowers1
brentsowers1 / gist:2907372
Created June 10, 2012 21:21
jQuery attachment types common code
// Used for measuring performance
var clickStartTime;
function callbackFunction() {
var doneDate = new Date();
var diff = doneDate.getTime() - clickStartTime.getTime();
alert("It took " + diff + " ms");
return false;
}
@brentsowers1
brentsowers1 / pre-commit.bash
Created May 3, 2012 18:24
Git pre-commit hook to prevent non-ascii characters
#!/bin/bash
# Save these contents to .git/hooks/pre-commit in your project
# folder, and give it executable permissions with
# "chmod u+x .git/hooks/pre-commit"
# Git will abort a commit if you have non ASCII characters in
# the commit, and output the non ASCII characters.
output=`git diff HEAD | tr -d "\000-\011\013-\177" | tr -d '\n'`
cnt=${#output}
if [ -n "$output" ]; then