code
stringlengths
1
1.73M
language
stringclasses
1 value
# 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
# Be sure to restart your server when you modify this file. # Add new mime types for use in respond_to blocks: # Mime::Type.register "text/richtext", :rtf # Mime::Type.register_alias "text/html", :iphone
Ruby
SETTINGS = {} SETTINGS["feed"] = {} SETTINGS["feed"]["username"] = "edwyn2" SETTINGS["feed"]["password"] = "234567" # filter settings SETTINGS["sport.filter.popular.limit"] = 6 SETTINGS["sport.filter.most_bets.limit"] = 6 # rss settings SETTINGS["rss.cache.time"] = 1.hour # 多长时间输出一次 SETTINGS["rss.size"] = 10 # 每次输出...
Ruby
require 'mongrel_cluster/recipes' set :application, "13wins" set :repository, "http://13wins.googlecode.com/svn/trunk/" # If you aren't deploying to /u/apps/#{application} on the target # servers (which is the default), you can specify the actual location # via the :deploy_to variable: # set :deploy_to, "/var/www/#{a...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # In the development environment your application's code is reloaded on # every request. This slows down response time but is perfect for development # since you don't have to restart the webserver when you make code changes. config.ca...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between...
Ruby
# Be sure to restart your server when you modify this file # Uncomment below to force Rails into production mode when # you don't control web/app server and can't set it the proper way # ENV['RAILS_ENV'] ||= 'production' # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.2...
Ruby
# Don't change this file! # Configure your app in config/environment.rb and config/environments/*.rb RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT) module Rails class << self def boot! unless booted? preinitialize pick_boot.run end end def booted? ...
Ruby
ActionController::Routing::Routes.draw do |map| # The priority is based upon order of creation: first created -> highest priority. # Sample of regular route: # map.connect 'products/:id', :controller => 'catalog', :action => 'view' # Keep in mind you can assign values other than :controller and :action ...
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
load 'deploy' if respond_to?(:namespace) # cap2 differentiator Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) } load 'config/deploy'
Ruby
atom_feed :language=>"en_US"do |feed| feed.title(SETTINGS['rss.title']) feed.updated(Time.now) cache "rss_feed_for_most_comment_matches",SETTINGS['rss.cache.time'].from_now do for match in @most_comment_matches feed.entry(match,:url=>"http://apps.facebook.com/13wins") do |entry| entry.title(ma...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper # 格式化时间 def format_time(time,format=:date,timezone=0) return '' if time.blank? case format when :date timezone.hours.since(time).strftime "%d-%m-%Y" when :datetime #ti...
Ruby
module UsersHelper end
Ruby
module MatchesHelper def point_spread(match,team) case match.bet_type when "total" if team == match.home_team "total over #{match.total_point}" else "total under #{match.total_point}" end else home_point_spread = away_point_spread = match.point_sprea...
Ruby
module BuyWinsHelper end
Ruby
module TeamsHelper def team_pic(team) image_tag(team.pic || "team.gif",:alt=>h(team.name)) end def team_detail(team) str = content_tag(:p,team_pic(team),:style=>"text-align:center") str << content_tag(:p,h(team.displayed_name),:style=>"text-align:center") end end
Ruby
module WinstreaksHelper def winstreak_count(winstreak) if winstreak.goal? content_tag(:div,winstreak.streak_count,:class=>"winstreak-goal") else winstreak.streak_count end end end
Ruby
module WelcomeHelper end
Ruby
module SportsHelper end
Ruby
module BetsHelper def bet_status(bet) if bet.played? str = case bet.win when nil image_tag("draw.png") when true if bet.winstreak_value == 0.5 image_tag("half_win.png") else image_tag("win.png") end when false ...
Ruby
module Admin::UsersHelper end
Ruby
module Admin::MatchesHelper end
Ruby
module Admin::TeamsHelper end
Ruby
module Admin::SportsHelper end
Ruby
module Admin::BetsHelper end
Ruby
module Admin::LeaguesHelper end
Ruby
module Admin::CountriesHelper end
Ruby
module Admin::PrizesHelper end
Ruby
module PointConfigsHelper end
Ruby
module LeaguesHelper end
Ruby
module PrizesHelper def prize_pic(prize) image_tag(prize.pic) end def prize_desc(prize) content_tag(:p,prize.name,:style=>"font-weight:bold") + content_tag(:p,prize.description) end end
Ruby
class Football < Sport end
Ruby
class Prize < ActiveRecord::Base end
Ruby
class WinstreakPublisher < Facebooker::Rails::Publisher helper TeamsHelper,BetsHelper,MatchesHelper,ApplicationHelper def self.default_url_options {:host=>"apps.railser.com"} end def update_profile(user) send_as :profile recipients user.facebook_user profile_main render(:partial=>"profile_mai...
Ruby
class Country < ActiveRecord::Base validates_presence_of :name validates_uniqueness_of :name has_many :sports has_many :leagues end
Ruby
class League < ActiveRecord::Base belongs_to :country belongs_to :sport validates_presence_of :sport_id def find_or_create_team(team_name,league) team = Team.find_or_initialize_by_name(team_name) team.sport = league.sport team.save! team end def fetch_results urls = [ "http:...
Ruby
class TeamNotFoundInMatch < Exception def initialize(team) super "#{team && team.name} not found in match" end end class Match < ActiveRecord::Base validates_presence_of :away_team_id,:home_team_id,:sport_id,:point_spread after_save :calc_challenge def calc_challenge logger.info('===================...
Ruby
class BuyWin < ActiveRecord::Base end
Ruby
class TeamMapping < ActiveRecord::Base validates_presence_of :team_name1,:team_name2 validates_uniqueness_of :team_name1 end
Ruby
class PointHistory < ActiveRecord::Base after_create :add_user_invited_num belongs_to :user def add_user_invited_num if self.action == "invite friend" and self.user self.user.invitation_sent_number = self.user.invitation_sent_number.to_i + 1 self.user.save end end end
Ruby
class Team < ActiveRecord::Base validates_presence_of :name,:sport_id validates_uniqueness_of :name belongs_to :sport def pic pic = read_attribute :pic if pic.blank? "team_no_pic.png" else pic end end def displayed_name if self.display_name.to_s.size>0 self.display_nam...
Ruby
class NotificationPublisher < Facebooker::Rails::Publisher def challenge_email(ch) send_as :email recipients(ch.to_user_id.to_s) from(Facebooker::User.new(ch.from_user_id)) title "You have received a 13wins challenge!" fbml render :partial=>'friends_bet/email',:locals=>{:ch=>ch} end def challenge_notify(ch...
Ruby
class UserPrize < ActiveRecord::Base belongs_to :prize belongs_to :user end
Ruby
class User < ActiveRecord::Base has_many :bets has_many :user_actions has_many :got_challenges,:class_name=>"Challenge",:foreign_key=>:to_user_id,:conditions=>["mode = ?","bet_0"],:order=>'id desc' has_many :sent_challenges,:class_name=>"Challenge",:foreign_key=>:from_user_id,:conditions=>["mode =?","bet_0"],:o...
Ruby
class FetchLog < ActiveRecord::Base def self.last_fetched_at fetch_log = FetchLog.first fetch_log && fetch_log.last_fetched_at end def self.update_last_fetched_at fetch_log = FetchLog.first unless fetch_log fetch_log = FetchLog.new end fetch_log.last_fetched_at = Time.now fetch_...
Ruby
class Challenge < ActiveRecord::Base belongs_to :sender, :class_name=>"User",:foreign_key=>:from_user_id belongs_to :goter,:class_name=>"User",:foreign_key=>:to_user_id belongs_to :match named_scope :placed_bet,:conditions=>["mode=?","bet_1"] named_scope :not_accept_bet,:conditions=>["mode=?","bet_0"] end
Ruby
class Bet < ActiveRecord::Base belongs_to :user,:counter_cache=>true belongs_to :match,:counter_cache=>true belongs_to :team belongs_to :winstreak validates_presence_of :user_id,:match_id,:team_id validates_uniqueness_of :match_id,:scope=>:user_id,:on=>:create named_scope :played,lambda { |played| { :cond...
Ruby
class Basketball < Sport end
Ruby
class PointConfig < ActiveRecord::Base end
Ruby
require "open-uri" class Sport < ActiveRecord::Base belongs_to :country has_many :leagues has_many :matches has_many :teams def fetch_matches cid = leagues.collect(&:cid) * "," username = SETTINGS["feed"]["username"] password = SETTINGS["feed"]["password"] url = "http://xml.sportspunter...
Ruby
# acts like a history class Winstreak < ActiveRecord::Base belongs_to :user belongs_to :prize has_many :bets,:order=>"#{Bet.table_name}.updated_at ASC" do def win scoped( :conditions=>"win = true" ) end end has_many :matches,:through=>:bets,:source=>:match # 比赛结束了,需要重新计算 # 比如 ...
Ruby
class UserAction < ActiveRecord::Base serialize :feed end
Ruby
class BetsController < ApplicationController def index flash[:notice]= CGI.unescape(params[:notice]) if params[:notice] flash[:error]= CGI.unescape(params[:error]) if params[:error] i = 0 if ids = params[:ids] ids.each do |id| unless PointHistory.find(:first,:conditions=>["user_id =? and a...
Ruby
class HelpController < ApplicationController # show index , user first install this app will show this page def index logger.error "--------------------" logger.error facebook_session.user.timezone logger.error "--------------------" end end
Ruby
class TeamsController < ApplicationController def index end def show end end
Ruby
class LeaguesController < ApplicationController def show end def index end end
Ruby
class InviteController < ApplicationController # show index , user first install this app will show this page def index end end
Ruby
class WelcomeController < ApplicationController # show index , user first install this app will show this page def index end end
Ruby
class SportsController < ApplicationController # 显示 sport def show flash[:notice]= params[:notice] if params[:notice] and !flash[:notice] flash[:error]= params[:error] if params[:error] and !flash[:error] @sport = Sport.find params[:id] @league = League.find_by_id(params[:league_id]) # exclude ...
Ruby
class FriendsBetController < ApplicationController def index @sid = params[:sid] metch = Match.find(@sid) uid = params[:fb_sig_user] @user = User.find(uid) @home_friends = metch.bets.home_friends(@user.all_friends).map{|b| b.user} @away_friends = metch.bets.away_friends(@user.all_friends).map{...
Ruby
class MatchesController < ApplicationController skip_before_filter :ensure_authenticated_to_facebook,:update_friends,:only=>:index def index @most_comment_matches = Match.all(:limit=>SETTINGS['rss.size'],:order=>"comment_count desc",:include=>[:home_team,:away_team]) @most_bet_matches = Match.all(:limit=>S...
Ruby
class CommentsController < ApplicationController def index @sid = params[:sid] if params[:fb_sig_xid_action] == "post" params[:sid] = params[:fb_sig_xid].split("_").last m = Match.find(params[:sid].to_i) m.comment_count = m.comment_count.to_i + 1 m.save current_user.add_point(PointConfi...
Ruby
class WinstreaksController < ApplicationController def history @winstreaks = current_user.winstreaks.paginate :order=>"#{Winstreak.table_name}.id desc", :include=>[:bets], :page=>params[:page], :per_page=>3 end def show @winstreak = Winstreak.find params[:id] end end
Ruby
class Admin::BetsController < Admin::BaseController def index Bet.paginate :page=>params[:page] end def destroy @bet = Bet.find params[:id] @bet.destroy flash[:notice] = 'successful deleted.' redirect_to @bet end end
Ruby
class Admin::TeamsController < Admin::BaseController def index @teams = Team @teams = @teams.scoped(:conditions=>{:alias_done=>false}) if params[:no_alias] @teams = @teams.paginate :page=>params[:page] end def edit @team = Team.find params[:id] end def update @team = Team.find params[:id...
Ruby
class Admin::LeaguesController < Admin::BaseController def index @leagues = League.paginate :page=>params[:page] end def edit @league = League.find params[:id] end def update @league = League.find params[:id] if @league.update_attributes params[:league] flash[:notice]='created successf...
Ruby
class Admin::CountriesController < Admin::BaseController def index @countries = Country.paginate :page=>params[:page] end def edit @country = Country.find params[:id] end def destroy @country = Country.find params[:id] @country.destroy flash[:notice] = "country was deleted." redirect...
Ruby
class Admin::SportsController < Admin::BaseController def index @sports = Sport.paginate :page=>params[:page],:order=>"position asc" end def update @sport = Sport.find params[:id] if @sport.update_attributes params[:sport] flash[:notice] = 'updated successful' redirect_to admin_sports_pat...
Ruby
class Admin::MatchesController < Admin::BaseController def index @search = Match.new_search params[:search] do |search| search.conditions.home_team.name_contains = params[:name] search.conditions.played = !!params[:played] #search.conditions.away_team.or_name_contains = params[:name] end ...
Ruby
class Admin::BaseController < ApplicationController before_filter :require_admin protected def require_admin unless current_user.admin? flash[:error] = "Access Denied" redirect_to root_path end end end
Ruby
class Admin::PointConfigsController < ApplicationController # GET /point_configs # GET /point_configs.xml def index @point_configs = PointConfig.find(:all) end # GET /point_configs/1 # GET /point_configs/1.xml def show @point_config = PointConfig.find(params[:id]) respond_to do |format| ...
Ruby
class Admin::PrizesController < Admin::BaseController def new @prize = Prize.new end def index @prizes = Prize.paginate :page=>params[:page] end def edit @prize = Prize.find params[:id] end def create @prize = Prize.new params[:prize] if @prize.save flash[:notice]='successful ...
Ruby
class Admin::UsersController < Admin::BaseController def index if params[:order] == "point" @users = User.paginate :page=>params[:page],:order=>'point' else @users = User.paginate :page=>params[:page],:order=>'created_at desc' end end def destroy @user = User.find params[:id] @u...
Ruby
require 'md5' class SrpointController < ApplicationController skip_before_filter def buy_point secret_key = "6b19357c2267cc221a3e013d01306267" sig = MD5.new(params[:id] +":"+ params[:new] +":"+ params[:uid] +":"+ secret_key).to_s result = 0 if not PointHistory.exists?(["user_id = ? and action = ?",p...
Ruby
class ForumController < ApplicationController # show index , user first install this app will show this page def index end end
Ruby
# Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base helper :all # include all helpers, all the time # See ActionController::RequestForgeryProtection for details...
Ruby
class PrizesController < ApplicationController # 用户选择这个奖品 # 当 prize 的 streak 小于 当前的 streak_count 的时候才允许 def select @prize = Prize.find params[:id] if current_user.winstreak.streak_count.to_i >= @prize.streak flash[:error] = "You cannot change to this prize." else current_user.prize = @priz...
Ruby
class InvitedController < ApplicationController def index if i = params[:i] flash[:notice] = "You earned #{i*PointConfig.find_by_name("invite_sent").point} WinPoints via your invite request(s)." end redirect_to buy_wins_path end def from_chat uid = params[:id] #unless PointHistory.exi...
Ruby
class UsersController < ApplicationController # 似乎是应该选出winstreak#streak_count最大的几个winstreak def index @filter = params[:filter] || "current" case @filter when "current" # @winstreaks = Winstreak.scoped(:include=>:user,:order=>"#{User.table_name}.win_percentage DESC") @users = User.scoped(:i...
Ruby
class BuyWinsController < ApplicationController # GET /buy_wins # GET /buy_wins.xml def index if count = params[:sent_count] flash[:notice] = "#{} invitation(s) sent. You earn #{count * 50} WinPoints!" end @buy_wins = BuyWin.find(:all) @level = current_user.current_winstreak_count.round + 1 ...
Ruby
# Add your own tasks in files placed in lib/tasks ending in .rake, # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. require(File.join(File.dirname(__FILE__), 'config', 'boot')) require 'rake' require 'rake/testtask' require 'rake/rdoctask' require 'tasks/rails'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby FETCHER_ROOT = File.dirname(__FILE__) RAILS_ENV = "production" require "#{FETCHER_ROOT}/../config/environment" require "fetcher" while true begin Fetcher.start rescue Exception=>e File.open(File.join(Rails.root,"tmp","fetcher_error"),"w+") {|f| f.write(e.message + e.backtrace.join("\n"))} ...
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/runner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/benchmarker'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/request'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/profiler'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/performance/request'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
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' $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby FETCHER_ROOT = File.dirname(__FILE__) RAILS_ENV = "production" require "#{FETCHER_ROOT}/../config/environment" require "fetcher" while true begin Fetcher.start rescue Exception=>e File.open(File.join(Rails.root,"tmp","fetcher_error"),"w+") {|f| f.write(e.message + e.backtrace.join("\n"))} ...
Ruby