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
Array.prototype._compact = function(iterator) { | |
var position = 0; | |
for (var index = 0, length = this.length; index < length; index++) { | |
if (this[index] != null) | |
this[position++] = this[index]; | |
} | |
this.length = position; | |
return this; | |
}; |
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
def do_stuff(enumerator) | |
# stuff | |
end | |
do_stuff([1,3,5].reverse_each) | |
do_stuff([1,3,5].each) |
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
class PostController < ActionController::Base | |
require_login | |
end |
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
class ProfileController < ActionController::Base | |
private | |
def current_user | |
@current_user ||= User.find_by_username(session[:username]) if session[:username] | |
end | |
helper_method :current_user | |
end |
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
belongs_to :session, :class_name => "Statistics::Session" |
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
namespace :cache do | |
desc 'Clear memcache' | |
task :clear => :environment do | |
Rails.cache.clear | |
end | |
end |
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
module ActionControllerExtra | |
module UserLogger | |
def self.included(base) | |
base.extend(ClassMethods) | |
end | |
module ClassMethods | |
# Logs that a user requested the current action: | |
# | |
# MyController < ApplicationController |
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
google_paths = { | |
'prototype' => 'http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/', | |
'controls' => 'http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/', | |
'dragdrop' => 'http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/', | |
'effects' => 'http://ajax.googleapis.com/ajax/libs/scriptaculous/1.8.1/' | |
} | |
config.action_controller.asset_host = Proc.new do |source, request| | |
google_asset = google_paths.keys.detect { |asset| source.starts_with?("/javascripts/#{asset}") } | |
google_asset ? google_paths[google_asset] : "#{request.protocol}#{request.host_with_port}" |
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
class Post < ActiveRecord::Base | |
def title=(value) | |
self[:title] = value.presence || 'Untitled' | |
end | |
end |
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
class Post < ActiveRecord::Base | |
def title=(value) | |
self[:title] = value.present? ? value : 'Untitled' | |
end | |
end |