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
function isInteger(num) { | |
num === Math.round(num); | |
} |
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
/* Sample JavaScript file added with ScriptTag resource. | |
This sample file is meant to teach best practices. | |
Your app will load jQuery if it's not defined. | |
Your app will load jQuery if jQuery is defined but is too old, e.g. < 1.7. | |
Your app does not change the definition of $ or jQuery outside the app. | |
*/ | |
(function(){ | |
/* Load Script function we may need to load jQuery from the Google's CDN */ |
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
// from: Eloquent JavaScript http://eloquentjavascript.net/08_error.html#p_CJKevweHV6 | |
// Define our own error type | |
function InputError(message) { | |
this.message = message; | |
this.stack = (new Error()).stack; | |
} | |
InputError.prototype = Object.create(Error.prototype); | |
InputError.prototype.name = "InputError"; |
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
var str = 'A&P Grocers, Inc.'; | |
str.replace(/\W/g, '').toLowerCase(); // apgrocersinc |
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
function generateUUID(){ | |
var d = new Date().getTime(); | |
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
var r = (d + Math.random()*16)%16 | 0; | |
d = Math.floor(d/16); | |
return (c=='x' ? r : (r&0x3|0x8)).toString(16); | |
}); | |
return uuid; | |
}; |
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
// From: http://stackoverflow.com/questions/16425520/angularjs-test-that-an-external-script-is-effectively-loaded | |
(function waiter(){ | |
if(!window.jQuery){ return setTimeout(waiter, 37); } | |
$("#myDiv").fadeOut(); | |
}()) |
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
// Summary from http://www.sitepoint.com/what-is-this-in-javascript/ | |
//// GLOBAL SCOPE | |
// If there's no current object, 'this' refers to the global object | |
window.WhoAmI = "I'm the window object" | |
console.log(window.WhoAmI) // "I'm the window object" |
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
//this function will work cross-browser for loading scripts asynchronously | |
//from: http://stackoverflow.com/questions/7718935/load-scripts-asynchronously | |
function loadScript(src, callback) | |
{ | |
var s,t,done; | |
done = false; | |
s = document.createElement('script'); | |
s.type = 'text/javascript'; | |
s.src = src; | |
s.onload = s.onreadystatechange = function() { |
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
// BAD | |
setInterval(function(){ | |
doStuff(); | |
}, 100); | |
// GOOD | |
(function loopMe(){ | |
doStuff(); | |
setTimeout(loopMe, 100); | |
})(); |
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
AllCops: | |
Include: | |
- '**/Rakefile' | |
- '**/config.ru' | |
Exclude: | |
- 'db/**/*' | |
- 'bin/**/*' | |
- 'config/**/*' | |
- 'node_modules/**/*' | |
- '**/rails_helper.rb' |