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
isNumber = (n) -> | |
not isNaN(parseFloat(n)) and isFinite(n) |
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
argArray = Array::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
String::trim = -> | |
@replace /^\s+|\s+$/g, "" |
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
generateRandomAlphaNum = (len) -> | |
rdmString = "" | |
while rdmString.length < len | |
rdmString += Math.random().toString(36).substr(2) | |
rdmString.substr 0, len |
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
numbers = [ | |
5 | |
458 | |
120 | |
-215 | |
228 | |
400 | |
122205 | |
-85411 | |
] |
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
numbersArray = [] | |
max = 100 | |
i = 1 # numbers = [1,2,3 ... 100] | |
while numbersArray.push(i++) < max |
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
x = Math.floor(Math.random() * (max - min + 1)) + min |
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
# Determine if an element is in the visible viewport | |
isInViewport = (element) -> | |
rect = element.getBoundingClientRect() | |
html = document.documentElement | |
rect.top >= 0 and rect.left >= 0 and rect.bottom <= (window.innerHeight or html.clientHeight) and rect.right <= (window.innerWidth or html.clientWidth) |
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
# Get image's max-width:100%; in pixels | |
getMaxWidth = (img) -> | |
maxWidth = undefined | |
# Check if naturalWidth is supported | |
if img.naturalWidth isnt `undefined` | |
maxWidth = img.naturalWidth | |
# Not supported, use in-memory solution as fallback | |
else |
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
# Select an element | |
element = document.querySelector(".class") | |
# Clone it | |
clone = element.cloneNode(true) | |
# Do some manipulation off the DOM | |
clone.style.background = "#000" | |
# Replaces the original element with the new cloned one |