This file contains hidden or 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 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); | |
} | |
} |
This file contains hidden or 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
// 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); | |
} |
This file contains hidden or 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
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() { |
This file contains hidden or 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
// 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; | |
} |
This file contains hidden or 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
#!/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 |
NewerOlder