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 Array | |
# does a kind of ZIP compression for integer arrays | |
# examples: | |
# [0,1,2,3].compress! => [[0, 4]] | |
# [1,2,3,8,9,10,11].compress! => [[1, 3], [8, 4]] | |
# [1,3,5].compress! => [1, 3, 5] | |
# [1,3,5,6].compress! => [1, 3, [5, 2]] | |
def compress! | |
compact! | |
return [] if empty? |
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
# rake app:test:file file=sample_test,other_test,third_test,etc_test | |
# rake app:test:file file=sample name=method_to_test | |
# rake app:test:monitor | |
namespace :app do | |
namespace :test do | |
# accepts ARGV[1] as parameter for test file patterns. Format: | |
# ARGV[1] = "file=[pattern]" (pattern can be a comma list of multiple files) | |
# ARGV[2] = "name=[method]" name of method to run in test file | |
desc "Run a single test without preparing database first. Smart about finding the test file.\n Syntax: rake app:test file=[basename] where basename matches (globbed) test(s).\n Will accept multiple comma delimted file patterns. " |
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 File_ext | |
# Adds some methods to a file handle so that it looks like a file upload | |
def as_upload(content_type = nil, fname = nil) | |
content_type ||= 'text/comma-separated-values' | |
# Make some JIT methods that make us look like an uploaded Tempfile | |
class << self | |
attr_reader :original_filename, :content_type | |
def local_path; path; end | |
def size; File.size(path); 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 ApplicationController < ActionController::Base | |
# rescue_from ActionController::RoutingError... do |exception| | |
# render :template => 'shared/404', :status => :not_found | |
# end | |
# | |
# OR | |
# | |
def render_optional_error_file(status_code) | |
if status_code == :not_found |
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
require 'fastercsv' | |
def download | |
filename = 'accounts.csv' | |
headers.merge!( | |
'Content-Type' => 'text/csv', | |
'Content-Disposition' => "attachment; filename=\"#{filename}\"", | |
'Content-Transfer-Encoding' => 'binary' | |
) | |
@performed_render = false |
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
# Need to know which method called you ? Its as simple as: | |
# caller = CallChain.caller_method | |
class CallChain | |
def self.caller_method(depth=1) | |
parse_caller(caller(depth+1).first).last | |
end | |
private |
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 :translations do | |
desc "Show available locales" | |
task :available => :environment do | |
puts "Available locales: #{I18n.available_locales.join(', ')}" | |
end | |
desc "Show missed translations depending on default language environment (:#{I18n.default_locale} by default). You can change it providing LOCALE argument" | |
task :missed => :environment do | |
locale = ENV['LOCALE'] || I18n.default_locale | |
puts "Using :#{locale} as default locale" |
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
# *params* holding a ref_name | |
# *session*, *cookies* - ref_tracker.tocken | |
# *check_referral* method only need to handle params ref_name, create ref_tracker and assign it's tocken to session and cookies | |
def check_referral | |
return if params[ReferralTracker::REF_KEY].blank? || logged_in? | |
ref_name = params[ReferralTracker::REF_KEY] | |
ref_data = RefData.find_by_ref_name(ref_name) | |
return unless ref_data # referrer is not exists. return |
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
Processing Admin::ExperimentsController#get_stat (for 127.0.0.1 at 2010-06-08 05:10:36) [POST] | |
Parameters: {"authenticity_token"=>"qGu1YU26HRW+NT4zF5VIOHtg41Z7nbgwJJ5UfjkJxSw=", "experiment"=>{"name"=>"Name", "offer_if_not_raise"=>"", "inactive_from_start"=>"100", "offer_everyone"=>"1", "offer_not_activated_users"=>"0", "raise_vcash_to"=>"", "inactive_group"=>"1", "inactive_from_end"=>"", "inactive_between_start"=>"", "offer_group"=>"1", "vested_cents_skip"=>"", "limit_to"=>"10", "inactive_between_end"=>""}} | |
[4;36;1mUser Load (0.0ms)[0m [0;1mSELECT * FROM `users` WHERE (`users`.`id` = 63703) LIMIT 1[0m | |
[4;35;1mExperimentUser Load (2.0ms)[0m [0mSELECT * FROM `experiment_users` WHERE (`experiment_users`.`user_id` = 63703) AND (`experiment_users`.`checked` = 0) LIMIT 1[0m | |
[4;35;1mUser Load (0.0ms)[0m [0mSELECT `users`.* FROM `users` INNER JOIN `traits` ON `traits`.id = `users`.trait_id WHERE (((users.id NOT IN(select user_id from experiment_users)) AND (Date(traits.last_activity_on) <= ' |
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
<div id="container" style="height: 400px"></div> |