Skip to content

Instantly share code, notes, and snippets.

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?("[email protected]").should be_true
ActionMailer::Base.deliveries[0].to.include?("[email protected]").should be_true
end
def redirect_asset_to_S3
resource = params[:other].join('/')
@url = AWS::S3::S3Object.url_for('assets/'+resource, ENV['S3_BUCKET'])
redirect_to @url
end
map.connect '/assets/*other', :controller => "assets", :action => "redirect_asset_to_S3"
(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
(function() {
var available_sizes = {
short: 2,
medium: 5,
long: 10
};
// in dumb browsers calling .long
// throws an error
console.log(available_sizes.long);
(function() {
if (true) {
var foo = 'apple';
}
// foo isn't local
// block scope !== functional scope
console.log(foo); // 'apple'
(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;
(function() {
var sorted_array = [1,22,13,4,5].sort();
console.log(sorted_array);
// returns [1, 13, 22, 4, 5]
})();
(function() {
var page_count = 0,
up_page_count = function () {
page_count++;
};
if ( up_page_count() ) {
console.log('I will never run');
(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');