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
| # from http://drawingablank.me/blog/ruby-boolean-typecasting.html | |
| class Fixnum | |
| def to_bool | |
| return true if self == 1 | |
| return false if self == 0 | |
| raise ArgumentError.new("invalid value for Boolean: \"#{self}\"") | |
| end | |
| end |
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
| # From: http://www.jacklmoore.com/notes/rounding-in-javascript/ | |
| round = (value, decimals) -> | |
| Number(Math.round(value + 'e' + decimals) + 'e-' + decimals) |
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
| git clone [email protected]:[templateUser]/[templateRepo].git [yourNewRepoName] | |
| cd [yourNewRepoName] | |
| rm -rf .git | |
| git init | |
| git remote add origin [email protected]:[yourUserName]/[yourNewRepoName].git | |
| git add -A | |
| git commit -m "initial commit" |
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
| Math.floor((new Date()).getTime()) |
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
| class Team < ActiveRecord::Base | |
| has_many :users | |
| validates :name, presence: true, uniqueness: true | |
| before_destroy :clear_team_members | |
| private | |
| # Clear team members when a team is destroyed |
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
| AllCops: | |
| Include: | |
| - '**/Rakefile' | |
| - '**/config.ru' | |
| Exclude: | |
| - 'db/**/*' | |
| - 'bin/**/*' | |
| - 'config/**/*' | |
| - 'node_modules/**/*' | |
| - '**/rails_helper.rb' |
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
| // BAD | |
| setInterval(function(){ | |
| doStuff(); | |
| }, 100); | |
| // GOOD | |
| (function loopMe(){ | |
| doStuff(); | |
| setTimeout(loopMe, 100); | |
| })(); |
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
| //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 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
| // 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 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
| // 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(); | |
| }()) |
OlderNewer