code
stringlengths
1
1.73M
language
stringclasses
1 value
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby fetcher_command = `ps -A -f | grep "ruby ./script/fetcher" | grep -v grep` if fetcher_command != '' pid = fetcher_command.split(/\s+/)[1] puts "find pid #{pid}" puts "try to kill it" `kill #{pid}` if $?.success? puts "process killed" else puts "can not kill process" end else ...
Ruby
class AddFriendsToUsers < ActiveRecord::Migration def self.up add_column :users,:all_friends,:text end def self.down remove_column :users,:friends end end
Ruby
class AddWinstreakIdToBets < ActiveRecord::Migration def self.up add_column :bets, :winstreak_id, :integer end def self.down remove_column :bets, :winstreak_id end end
Ruby
class ChangePointSpreadToFloatFromMatches < ActiveRecord::Migration def self.up change_column :matches,:point_spread,:float end def self.down change_column :matches,:point_spread,:integer end end
Ruby
class AddWinstreakValueToBets < ActiveRecord::Migration def self.up add_column :bets, :winstreak_value, :float end def self.down remove_column :bets, :winstreak_value end end
Ruby
class AddSportIdToMatches < ActiveRecord::Migration def self.up add_column :matches, :sport_id, :integer end def self.down remove_column :matches, :sport_id end end
Ruby
class CreateFetchLogs < ActiveRecord::Migration def self.up create_table :fetch_logs do |t| t.datetime :last_fetched_at t.timestamps end end def self.down drop_table :fetch_logs end end
Ruby
class AddBetsCountToMatches < ActiveRecord::Migration def self.up add_column :matches, :bets_count, :integer,:default=>0 add_index :matches, :bets_count end def self.down remove_index :matches, :column => :bets_count remove_column :matches, :bets_count end end
Ruby
class CreatePointConfigs < ActiveRecord::Migration def self.up create_table :point_configs do |t| t.string :name t.integer :point t.integer :level t.timestamps end end def self.down drop_table :point_configs end end
Ruby
class AddHomePointAndAwayPointToMatches < ActiveRecord::Migration def self.up add_column :matches, :home_point, :integer add_column :matches, :away_point, :integer end def self.down remove_column :matches, :away_point remove_column :matches, :home_point end end
Ruby
class AddTypeToSports < ActiveRecord::Migration def self.up add_column :sports, :type, :string end def self.down remove_column :sports, :type end end
Ruby
class AddMessageToChallenges < ActiveRecord::Migration def self.up add_column :challenges,:message,:string end def self.down end end
Ruby
class AddNameAndAgeAndSexAndCountryAndSchoolAndFriendsCountAndPrizeIdToUsers < ActiveRecord::Migration def self.up add_column :users, :name, :string add_column :users, :age, :integer add_column :users, :sex, :string add_column :users, :country, :string add_column :users, :school, :string add_c...
Ruby
class AddInvitedStaticsToUsers < ActiveRecord::Migration def self.up add_column :users,:invitation_sent_number,:integer add_column :users,:invitation_accept_number,:integer end def self.down end end
Ruby
class AddPositionToWinstreaks < ActiveRecord::Migration def self.up add_column :winstreaks, :position, :integer,:default=>0 end def self.down remove_column :winstreaks, :position end end
Ruby
class RemoveWinTeamIdToMatches < ActiveRecord::Migration def self.up remove_column :matches, :win_team_id end def self.down add_column :matches, :win_team_id, :integer end end
Ruby
class AddAliasDoneToTeams < ActiveRecord::Migration def self.up add_column :teams, :alias_done, :boolean,:default=>false end def self.down remove_column :teams, :alias_done end end
Ruby
class CreateUserPrizes < ActiveRecord::Migration def self.up create_table :user_prizes do |t| t.integer :user_id t.integer :prize_id t.integer :streak t.timestamps end end def self.down drop_table :user_prizes end end
Ruby
class AddCidToLeagues < ActiveRecord::Migration def self.up add_column :leagues, :cid, :integer end def self.down remove_column :leagues, :cid end end
Ruby
class AddWinstreakValueToMatches < ActiveRecord::Migration def self.up add_column :matches, :winstreak_value, :float end def self.down remove_column :matches, :winstreak_value end end
Ruby
class CreateFacebookTemplates < ActiveRecord::Migration def self.up create_table :facebook_templates, :force => true do |t| t.string :template_name, :null => false t.string :content_hash, :null => false t.string :bundle_id, :null => true end add_index :facebook_templates, :template...
Ruby
class ChangeWinToDefaultFalseFromBets < ActiveRecord::Migration def self.up change_column :bets,:win,:boolean,:default=>false end def self.down change_column :bets,:win end end
Ruby
class AddPlayedToMatches < ActiveRecord::Migration def self.up add_column :matches, :played, :boolean,:default=>false end def self.down remove_column :matches, :played end end
Ruby
class Challenge < ActiveRecord::Migration def self.up create_table :challenges do |t| t.integer :match_id t.integer :from_user_id t.integer :to_user_id t.integer :amount t.string :mode end add_index :challenges,:mode end def self.down end end
Ruby
class CreateCountries < ActiveRecord::Migration def self.up create_table :countries do |t| t.string :name t.timestamps end end def self.down drop_table :countries end end
Ruby
class AddHomePointSpreadAndAwayPointSpreadToMatches < ActiveRecord::Migration def self.up add_column :matches, :home_point_spread, :float add_column :matches, :away_point_spread, :float end def self.down remove_column :matches, :away_point_spread remove_column :matches, :home_point_spread end e...
Ruby
class AddDescriptionToPrizes < ActiveRecord::Migration def self.up add_column :prizes, :description, :string end def self.down remove_column :prizes, :description end end
Ruby
class AddLeagueIdToMatches < ActiveRecord::Migration def self.up add_column :matches, :league_id, :integer end def self.down remove_column :matches, :league_id end end
Ruby
class RemoveHomePointSpreadAndAwayTeamSpreadAndAddPointSpreadAndWinTeamIdToMatches < ActiveRecord::Migration def self.up add_column :matches, :point_spread, :integer add_column :matches, :win_team_id, :integer remove_column :matches,:home_point_spread remove_column :matches,:away_point_spread end ...
Ruby
class CreateSports < ActiveRecord::Migration def self.up create_table :sports do |t| t.string :name,:feed_url t.timestamps end end def self.down drop_table :sports end end
Ruby
class AddGotPrizeToWinstreaks < ActiveRecord::Migration def self.up add_column :winstreaks, :got_prize, :boolean,:default=>false end def self.down remove_column :winstreaks, :got_prize end end
Ruby
class CreatePrizes < ActiveRecord::Migration def self.up create_table :prizes do |t| t.string :name t.integer :streak t.string :pic t.timestamps end end def self.down drop_table :prizes end end
Ruby
class AddBetsCountToUsers < ActiveRecord::Migration def self.up add_column :users, :bets_count, :integer,:default=>0 end def self.down remove_column :users, :bets_count end end
Ruby
class AddBirthdayToUsers < ActiveRecord::Migration def self.up add_column :users, :birthday, :datetime end def self.down remove_column :users, :birthday end end
Ruby
class AddBookmarkHowtoHideToUsers < ActiveRecord::Migration def self.up add_column :users,:hide_bookmark,:boolean add_column :users,:hide_howto,:boolean end def self.down remove_column :users,:hide_bookmark remove_column :users,:hide_howto end end
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.integer :facebook_id,:limit=>20 t.timestamps end end def self.down drop_table :users end end
Ruby
class CreateBuyWins < ActiveRecord::Migration def self.up create_table :buy_wins do |t| t.integer :user_id t.integer :point_config_id t.integer :winstreak_id t.timestamps end end def self.down drop_table :buy_wins end end
Ruby
class CreateTeams < ActiveRecord::Migration def self.up create_table :teams do |t| t.string :name t.string :pic t.string :description t.timestamps end end def self.down drop_table :teams end end
Ruby
class AddNameAliasToTeams < ActiveRecord::Migration def self.up add_column :teams, :name_alias, :string end def self.down remove_column :teams, :name_alias end end
Ruby
class CreateBets < ActiveRecord::Migration def self.up create_table :bets do |t| t.integer :user_id t.integer :match_id t.boolean :result t.string :status t.timestamps end end def self.down drop_table :bets end end
Ruby
class AddAppUserAndProfileUpdatedAtToUsers < ActiveRecord::Migration def self.up add_column :users, :app_user, :boolean,:default=>false add_column :users, :profile_updated_at, :datetime end def self.down remove_column :users, :profile_updated_at remove_column :users, :app_user end end
Ruby
class AddPositionToSports < ActiveRecord::Migration def self.up add_column :sports, :position, :integer end def self.down remove_column :sports, :position end end
Ruby
class AddWinToBets < ActiveRecord::Migration def self.up add_column :bets, :win, :boolean end def self.down remove_column :bets, :win end end
Ruby
class AddGotPrizeAtToWinstreaks < ActiveRecord::Migration def self.up add_column :winstreaks, :got_prize_at, :datetime end def self.down remove_column :winstreaks, :got_prize_at end end
Ruby
class AddPlayedToBets < ActiveRecord::Migration def self.up add_column :bets, :played, :boolean,:default=>false end def self.down remove_column :bets, :played end end
Ruby
class AddCountryIdToSports < ActiveRecord::Migration def self.up add_column :sports, :country_id, :integer end def self.down remove_column :sports, :country_id end end
Ruby
class AddCommentCountToMatches < ActiveRecord::Migration def self.up add_column :matches,:comment_count,:integer end def self.down remove_column :matches,:comment_count end end
Ruby
class AddMidToMatches < ActiveRecord::Migration def self.up add_column :matches, :mid, :integer end def self.down remove_column :matches, :mid end end
Ruby
class CreateUserActions < ActiveRecord::Migration def self.up create_table :user_actions do |t| t.integer :user_id t.text :feed t.timestamps end end def self.down drop_table :user_actions end end
Ruby
class AddSportIdToTeams < ActiveRecord::Migration def self.up add_column :teams, :sport_id, :integer end def self.down remove_column :teams, :sport_id end end
Ruby
class CreateLeagues < ActiveRecord::Migration def self.up create_table :leagues do |t| t.string :name t.integer :country_id t.timestamps end end def self.down drop_table :leagues end end
Ruby
class AddTeamIdToBets < ActiveRecord::Migration def self.up add_column :bets, :team_id, :integer end def self.down remove_column :bets, :team_id end end
Ruby
class AddPointToUsersIfNotExists < ActiveRecord::Migration def self.up unless User.column_names.include?("point") add_column :users,:point,:integer,:default=>0 end end def self.down if User.column_names.include?("point") remove_column :users,:point end end end
Ruby
class RemovePointSpreadAndResultFromMatches < ActiveRecord::Migration def self.up remove_column :matches,:point_spread remove_column :matches,:result end def self.down add_column :matches,:result add_column :matches,:point_spread end end
Ruby
class AddCountryIdAndSportIdAndFeedUrlToLeagues < ActiveRecord::Migration def self.up add_column :leagues, :sport_id, :integer add_column :leagues, :feed_url, :string end def self.down remove_column :leagues, :feed_url remove_column :leagues, :sport_id end end
Ruby
class ChangeStreakCountToFloatFromWinstreaks < ActiveRecord::Migration def self.up change_column :winstreaks,:streak_count,:float,:default=>0 end def self.down change_column :winstreaks,:streak_count,:integer end end
Ruby
class AddTimezoneToUsers < ActiveRecord::Migration def self.up add_column :users,:timezone,:string end def self.down end end
Ruby
class AddPrizeIdToWinstreaks < ActiveRecord::Migration def self.up add_column :winstreaks, :prize_id, :integer end def self.down remove_column :winstreaks, :prize_id end end
Ruby
class AddLeagueIdToFetchLogs < ActiveRecord::Migration def self.up add_column :fetch_logs, :league_id, :integer end def self.down remove_column :fetch_logs, :league_id end end
Ruby
class AddWinsCountLossesCountAndWinPercentageToUsers < ActiveRecord::Migration def self.up add_column :users, :wins_count, :integer,:default=>0 add_column :users, :losses_count, :integer,:default=>0 add_column :users, :percentage, :float,:default=>0 end def self.down remove_column :users, :percen...
Ruby
class AddLastFetchedAtToLeagues < ActiveRecord::Migration def self.up add_column :leagues, :last_fetched_at, :datetime end def self.down remove_column :leagues, :last_fetched_at end end
Ruby
class AddIndexes < ActiveRecord::Migration def self.up # bets add_index :bets,:user_id add_index :bets,:match_id add_index :bets,:team_id # leagues add_index :leagues,:sport_id add_index :leagues,:country_id # matches add_index :matches,:home_team_id add_index :matches,:away_...
Ruby
class AddDisplayNameToTeams < ActiveRecord::Migration def self.up add_column :teams,:display_name,:string end def self.down remove_column :teams,:display_name end end
Ruby
class RenamePercentageToWinPercentage < ActiveRecord::Migration def self.up rename_column :users,:percentage,:win_percentage end def self.down rename_column :users,:win_percentage,:percentage end end
Ruby
class CreateMatches < ActiveRecord::Migration def self.up create_table :matches do |t| t.integer :home_team_id t.integer :away_team_id t.string :bet_type t.float :point_spread t.datetime :begin_at t.boolean :result t.float :total_point t.timestamps end end ...
Ruby
class AddWinstreakIdToUsers < ActiveRecord::Migration def self.up add_column :users, :winstreak_id, :integer,:default=>false end def self.down remove_column :users, :winstreak_id end end
Ruby
class CreateWinstreaks < ActiveRecord::Migration def self.up create_table :winstreaks do |t| t.integer :user_id t.integer :streak_count t.timestamps end end def self.down drop_table :winstreaks end end
Ruby
class AddWinnerIdToMatches < ActiveRecord::Migration def self.up add_column :matches, :winner_id, :integer end def self.down remove_column :matches, :winner_id end end
Ruby
class RemoveFeedUrlAndTypeAndCountryIdFromSports < ActiveRecord::Migration def self.up remove_column :sports,:feed_url remove_column :sports,:country_id remove_column :sports,:type end def self.down add_column :sports,:type,:string add_column :sports,:country_id,:integer add_column :sport...
Ruby
class CreateTeamMappings < ActiveRecord::Migration def self.up create_table :team_mappings do |t| t.string :team_name1 t.string :team_name2 t.timestamps end end def self.down drop_table :team_mappings end end
Ruby
class ChangeIdToBignumFromUsers < ActiveRecord::Migration def self.up change_column :users,:id,:integer,:limit=>11 end def self.down change_column :users,:id,:integer end end
Ruby
class Fetcher def self.logger @@logger ||= Logger.new(File.join(RAILS_ROOT,"log","fetcher.log")) end def logger self.class.logger end def fetch_matches logger.info "#{Time.now} start fetch matches" matches_count = Sport.fetch_matches logger.info "#{matches_count} matches was fetched." ...
Ruby
namespace :counter_cache do desc "update matche counter cache" task :matches=>:environment do Match.all.each do |match| match.bets_count = match.bets.count match.save false end end end
Ruby
namespace :clear do desc "clear all" task :all=>[:leagues,:bets,:sports,:matches,:users,:winstreaks,:prizes,:countries] desc "clear leagues" task :leagues=>:environment do League.destroy_all end desc "clear bets" task :bets=>:environment do Bet.destroy_all end desc "clear countries" task ...
Ruby
require "open-uri" def valid_leagues file = File.join(Rails.root,"config","leagues.yml") yaml = YAML.load_file file yaml && yaml["leagues"] || {} end def league_name_to_id(content,league_name) regexp = %r{<tr><td>(\d+)<\/td><td>(.+?)<\/td><td>\s*#{Regexp.escape(league_name)}\s*<\/td><\/tr>}i if content =~ re...
Ruby
namespace :data do desc "导入默认数据" task :load=>:environment do [ # basketball {:type=>"Basketball",:country=>"America",:name=>"NBA",:feed_url=>"url"}, # football # England {:type=>"Football",:country=>"England",:name=>"Premier League"}, {:type=>"Football",:country=>"Engl...
Ruby
namespace :generate do task :ensure_user_selected_prize=>:environment do prize = Prize.first User.all.each do |user| unless user.prize user.prize = prize user.save end end end task :result=>:environment do match = Match.next_match if match puts "current matc...
Ruby
module Facebooker::Rails::DelayedUserAction def self.included(base) base.class_eval do alias_method_chain :send_message,:delayed end end def delayed(*args) if args.empty? @delayed else @delayed = args.first end end def send_message_with_delayed(message) @recipients...
Ruby
#!/usr/bin/ruby1.8 require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispatcher" -- otherwise performance is severely impaired...
Ruby
#!/usr/bin/ruby1.8 # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log #...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' require "flexmock/test_unit" class Test::Unit::TestCase # Transactional fixtures accelerate your tests by wrapping each test method # in a transaction that's rolled back on completion. This en...
Ruby
# Be sure to restart your server when you modify this file. # Add new inflection rules using the following format # (all these examples are active by default): # ActiveSupport::Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person',...
Ruby
require "facebooker/delayed_user_action"
Ruby
# These settings change the behavior of Rails 2 apps and will be defaults # for Rails 3. You can remove this initializer when Rails 3 is released. if defined?(ActiveRecord) # Include Active Record class name as root for JSON serialized output. ActiveRecord::Base.include_root_in_json = true # Store the full clas...
Ruby
# configure file for will paginate WillPaginate::ViewHelpers.pagination_options[:params] = { "_method" => nil, "fb_sig" => nil, "fb_sig_added" => nil, "fb_sig_expires" => nil, "fb_sig_api_key" => nil, "fb_sig_friends" => nil, "fb_sig_in_canvas" => nil, "fb_sig_locale" => nil, "fb_sig_position_fix" => ...
Ruby