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(one, two) { | |
| // every function receives | |
| // an array of all the arguments | |
| // even those that your function doesn't "accept" | |
| return arguments; // ['first argument', 2, 'I am a third argument'] | |
| })('first argument', 2, 'I am a third argument'); |
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() { | |
| var page_count = 0, | |
| up_page_count = function () { | |
| page_count++; | |
| }; | |
| if ( up_page_count() ) { | |
| console.log('I will never run'); |
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() { | |
| var sorted_array = [1,22,13,4,5].sort(); | |
| console.log(sorted_array); | |
| // returns [1, 13, 22, 4, 5] | |
| })(); |
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() { | |
| var sorted_array = [1,22,13,4,5].sort(function(a, b) { | |
| // you get a and b to sort. | |
| // if the function returns a.. | |
| // negative number: a comes ahead in sort order | |
| // a positive number: b comes first | |
| return a-b; |
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() { | |
| if (true) { | |
| var foo = 'apple'; | |
| } | |
| // foo isn't local | |
| // block scope !== functional scope | |
| console.log(foo); // 'apple' |
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() { | |
| var available_sizes = { | |
| short: 2, | |
| medium: 5, | |
| long: 10 | |
| }; | |
| // in dumb browsers calling .long | |
| // throws an error | |
| console.log(available_sizes.long); |
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() { | |
| // convert a string to a number. | |
| // it uses base 10 by default | |
| var foo = parseInt('78'); // 78 | |
| // repeat, with a different number | |
| // this time it's base 8 by default? | |
| var wtf = parseInt('08'); // 0 |
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
| map.connect '/assets/*other', :controller => "assets", :action => "redirect_asset_to_S3" |
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
| def redirect_asset_to_S3 | |
| resource = params[:other].join('/') | |
| @url = AWS::S3::S3Object.url_for('assets/'+resource, ENV['S3_BUCKET']) | |
| redirect_to @url | |
| 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
| it "should queue the email for delivery" do | |
| ActionMailer::Base.deliveries.should_not be_empty | |
| end | |
| it "should set the recipients correctly" do | |
| ActionMailer::Base.deliveries[0].to.include?("email1@quickleft.com").should be_true | |
| ActionMailer::Base.deliveries[0].to.include?("email2@quickleft.com").should be_true | |
| end |