code
stringlengths
1
1.73M
language
stringclasses
1 value
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.action_controller.consider_all_reque...
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
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying do debug a probl...
Ruby
# Be sure to restart your server when you modify this file. # Your secret key for verifying cookie session data integrity. # If you change this key, all old sessions will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Act...
Ruby
# Be sure to restart your server when you modify this file. # 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. ActiveReco...
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
# 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
# Be sure to restart your server when you modify this file # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.2' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') ...
Ruby
module ZepFrog class PaymentError < ZepFrog::CustomError; end end
Ruby
module ZepFrog module Utils def nvl_str(option) return (option.nil? ? "" : option.to_s) end def nvl_num(option) return (option.nil? ? 0 : option.to_i) end def self.requires!(hash, *params) params.each do |param| if param.is_a?(Array) raise ArgumentError.ne...
Ruby
module ZepFrog module PaymentGateway def authorize(amount) gateway = payment_gateway # ActiveMerchant is configured to use cents so we need to multiply order total by 100 response = gateway.authorize((amount * 100).to_i, self, gateway_options) gateway_error(response) unles...
Ruby
module ZepFrog # Singleton class to access the configuration object (AppConfiguration.first by default) and it's preferences. # # Usage: # ZepFrog::Config[:foo] # Returns the +foo+ preference # ZepFrog::Config[] # Returns a Hash with all the application preferences ...
Ruby
module ZepFrog class CustomError < RuntimeError @err_hash = Hash.new end end
Ruby
module ZepFrog module PreferenceAccess def self.included(base) class << base def get(key = nil) key = key.to_s if key.is_a?(Symbol) return nil unless config = self.instance # preferences will be cached under the name of the class including this module (ex. Spree::Config)...
Ruby
module ZepFrog #:nodoc: module BillingValidation #:nodoc: # Convenience methods that can be included into a custom Credit Card object, such as an ActiveRecord based Credit Card object. module CreditCardMethods CARD_COMPANIES = { 'visa' => /^4\d{12}(\d{3})?$/, 'master' ...
Ruby
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). # # Examples: # # cities = City.create([{ :name => 'Chicago' }, { :name => 'Copenhagen' }]) # Mayor.create(:name =>...
Ruby
class CreatePickups < ActiveRecord::Migration def self.up create_table :pickups do |t| t.integer :avid t.string :wname t.string :uname t.string :reason t.text :bak t.integer :ptype t.integer :status, :default => 0 t.timestamps end end def self.down dro...
Ruby
class CreatePickupLogs < ActiveRecord::Migration def self.up create_table :pickup_logs do |t| t.integer :pickup_id t.string :uname t.integer :otype t.timestamps end end def self.down drop_table :pickup_logs end end
Ruby
class CreatePickupPasswords < ActiveRecord::Migration def self.up create_table :pickup_passwords do |t| t.integer :pickup_id t.string :password end end def self.down drop_table :pickup_passwords end end
Ruby
source 'http://rubygems.org' gem 'rails', '3.0.6' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'pg' # Use unicorn as the web server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)...
Ruby
module ApplicationHelper include BilibiliApi #options: name, part def bili_video_link wid, options={} name = options[:name] part = options[:part] url = %[http://#{BILI_PATH}/video/av#{wid}/#{"index_#{part}.html" if part.to_i > 1}] link_to (name ? h(name) : "av#{wid}"), url, :target => "_blank...
Ruby
module IndexHelper end
Ruby
module ApiHelper end
Ruby
module PickupHelper end
Ruby
class KeyUser < ActiveRecord::Base establish_connection :user belongs_to :key validates_uniqueness_of :uname, :scope=>:key_id, :message => 'same' validates_presence_of :uname, :message => 'uname is null' end
Ruby
class WeeklyResultWork < ActiveRecord::Base establish_connection :weekly end
Ruby
class PickupLog < ActiveRecord::Base belongs_to :pickup DEFAULT_TYPE = {0 => '通过', 1 => '启用', 2 => '忽略', 3 => '代提交'} end
Ruby
class Pickup < ActiveRecord::Base has_one :pickup_password validates_presence_of :avid, :message => '请填写推荐投稿' validates_presence_of :reason, :message => '请填写推荐理由' DEFAULT_STATUS = {0 => '未审核', 1 => '审核通过', 2 => '启用', 3 => '忽略'} DEFAULT_TYPE = {0 => '正常', 1 => '高人气', 2 => '自推荐', 3 => '超长理由', 4 => '新投稿推荐', 5 =>...
Ruby
class Key < ActiveRecord::Base establish_connection :user has_many :key_users end
Ruby
class PickupPassword < ActiveRecord::Base validates_uniqueness_of :pickup_id, :message => 'avid same' end
Ruby
class App < ActiveRecord::Base establish_connection :user end
Ruby
class Work < ActiveRecord::Base establish_connection :work end
Ruby
class WeeklyResult < ActiveRecord::Base establish_connection :weekly belongs_to :weekly_result_work ['wid', 'name', 'wtype', 'author'].each do |n| unless self.column_names.include?(n) eval "attr_reader(:#{n});def #{n};@#{n} ||= weekly_result_work.#{n};end" end end end
Ruby
class ApiController < ApplicationController def info begin pickup_password = PickupPassword.find_by_password params[:password] return render :text => nil unless pickup_password pickup = Pickup.find pickup_password.pickup_id, :select => "avid, wname, uname, reason" work = Work.find_by_wid ...
Ruby
class ApplicationController < ActionController::Base protect_from_forgery include BilibiliApi end
Ruby
class ManaController < ApplicationController before_filter :correct_bili_name?, :limit_bili_users layout "need_bili_name" require 'digest/md5' #默认查看正常的新推荐 def index @pickups = Pickup.all :conditions => "status = 0 and (ptype = 0 or ptype = 5)", :order => "id" render :action => :list end def lis...
Ruby
class PickupController < ApplicationController before_filter :correct_bili_name?, :except => :index layout "need_bili_name" def index if current_bili_user redirect_to :action => :new else render :layout => "application" end end def new @pickup = Pickup.new end def create ...
Ruby
class IndexController < ApplicationController def logout super end end
Ruby
BILI_PATH = "www.bilibili.us" APP_ID = 4
Ruby
# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attac...
Ruby
# Be sure to restart your server when you modify this file. Bilidanmaku::Application.config.session_store :cookie_store, :key => '_bilidanmaku_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table wi...
Ruby
Bilidanmaku::Application.routes.draw do get "pickup/index" #get "index/index" # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match 'products/:id' => 'catalog#view' # Keep in mind you can assign values other than :controller and :actio...
Ruby
require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Ruby
require File.expand_path('../boot', __FILE__) require 'rails/all' # If you have a Gemfile, require the gems listed there, including any gems # you've limited to :test, :development, or :production. Bundler.require(:default, Rails.env) if defined?(Bundler) module Bilidanmaku class Application < Rails::Application ...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Bilidanmaku::Application.initialize!
Ruby
Bilidanmaku::Application.configure do # Settings specified here will take precedence over those in config/application.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turne...
Ruby
Bilidanmaku::Application.configure do # Settings specified here will take precedence over those in config/application.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 w...
Ruby
Bilidanmaku::Application.configure do # Settings specified here will take precedence over those in config/application.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 t...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Bilidanmaku::Application
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.expand_path('../config/application', __FILE__) require 'rake' Bilidanmaku::Application.load_tasks
Ruby
#!/usr/bin/env ruby # encoding: utf-8 project = 'battery-indicator' user = `cat ~/.netrc | awk '{print $4;}'`.strip pass = `cat ~/.netrc | awk '{print $6;}'`.strip version = `grep "android:versionName=" AndroidManifest.xml`.split('"')[1] apk_location = "BatteryIndicatorPro-#{version}.apk" system("cp bin/*-release.ap...
Ruby
#!/usr/bin/env ruby require 'net/http' require 'uri' LANGS_URI = 'http://ath.darshancomputing.com/bi/langs/' langs = Net::HTTP.get(URI.parse(LANGS_URI)).split() langs.each do |lang| if lang.length == 2 dir = 'res/values-' << lang else dir = 'res/values-' << lang[0,2] << '-r' << lang[2,2] end if ! D...
Ruby
require 'RMagick' class NumberImageGenerator @@IMAGE_DIR = 'numbers-hdpi/' def generate(text, fs=18) #filename = "b" + sprintf("%03d", text) + ".png"; filename = "" + sprintf("%03d", text) + ".png"; font_size = fs; height = 35; width = 35; image = Magick::Image.new(width, height) {self.ba...
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
# Be sure to restart your server when you modify this file. # 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. ActiveReco...
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
# Be sure to restart your server when you modify this file. # Your secret key for verifying cookie session data integrity. # If you change this key, all old sessions will become invalid! # Make sure the secret is at least 30 characters and all random, # no regular words or you'll be exposed to dictionary attacks. Act...
Ruby
# Be sure to restart your server when you modify this file. # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } # You can also remove all the silencers if you're trying do debug a probl...
Ruby
# Settings specified here will take precedence over those in config/environment.rb # The production environment is meant for finished, "live" apps. # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.action_controller.consider_all_reque...
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 # Specifies gem version of Rails to use when vendor/rails is not present RAILS_GEM_VERSION = '2.3.11' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') ...
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| map.logout '/logout', :controller => 'sessions', :action => 'destroy' map.login '/login', :controller => 'sessions', :action => 'new' map.register '/register', :controller => 'users', :action => 'create' map.signup '/signup', :controller => 'users', :action => 'ne...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def img_tag file_name image_tag %[#{IMG_PATH}#{file_name}], :alt => " " end def point point point_s = point.to_s fushu = point_s.first == '-' ? true : false size = point_s.size - ( fus...
Ruby
module UsersHelper # # Use this to wrap view elements that the user can't access. # !! Note: this is an *interface*, not *security* feature !! # You need to do all access control at the controller level. # # Example: # <%= if_authorized?(:index, User) do link_to('List all users', users_path) end %> ...
Ruby
module SessionsHelper end
Ruby
module WeekliesHelper end
Ruby
module IndexHelper end
Ruby
class Key < ActiveRecord::Base establish_connection :user has_many :key_users end
Ruby
class WeeklyExcept < ActiveRecord::Base establish_connection :weekly validates_uniqueness_of :wid, :scope=>:weekly_id, :message => 'same wid' end
Ruby
class VegasVideoTime attr_accessor :h, :m, :s, :l def self.new h0=0, m0=0, s0=0, l0=0 vvm_time = super() vvm_time.h = h0; vvm_time.m = m0; vvm_time.s = s0; vvm_time.l = l0 vvm_time end def self.nl l h = l / 108000 m = l % 108000 / 1800 s = l % 108000 % 1800 / 30 l0 = l % 108000 % 1...
Ruby
class App < ActiveRecord::Base establish_connection :user end
Ruby
class WeeklyResult < ActiveRecord::Base establish_connection :weekly belongs_to :weekly def work Work.find_by_wid wid end #0 = 'new' #-1 = except #>0 #nil ?? def last_score_rank unknown_ids = nil return nil if unknown_ids && unknown_ids.include?(wid) if last_weekly = weekly.last re...
Ruby
class Scan < ActiveRecord::Base has_many :results, :dependent => :destroy def self.search ac_types, php=false require 'net/http/persistent' pages = [] http = Net::HTTP::Persistent.new(nil, (PROXY ? URI.parse(PROXY) : nil)) @protect_num = 0 #防ban IP对策 ac_types.each do |ac_type| date_now ...
Ruby
class PgWeeklyExcept < ActiveRecord::Base establish_connection :pgweekly end
Ruby
require 'rexml/document' require 'net/http' class FlashVar < ActiveRecord::Base belongs_to :work validates_uniqueness_of :vid, :scope=>:work_id, :message => 'same' validates_presence_of :vid, :message => 'vid is null' has_many :d_results belongs_to :space_type def add_result( scan = Scan.find(:first, :orde...
Ruby
class PgWeekly < ActiveRecord::Base establish_connection :pgweekly end
Ruby
class PgWeeklyResult < ActiveRecord::Base establish_connection :pgweekly belongs_to :weekly, :class_name => "PgWeekly" def work Work.find_by_wid wid end end
Ruby
class User < ActiveRecord::Base establish_connection :user include Authentication include Authentication::ByPassword include Authentication::ByCookieToken validates_presence_of :login validates_length_of :login, :within => 3..40 validates_uniqueness_of :login validates_format_of :l...
Ruby
class KeyUser < ActiveRecord::Base establish_connection :user belongs_to :key end
Ruby
class Weekly < ActiveRecord::Base establish_connection :weekly has_many :weekly_results, :dependent => :destroy belongs_to :last, :foreign_key => :parent_id, :class_name => 'Weekly' def self.latest find :first, :conditions => "wid is not null", :order => '"index" desc' end end
Ruby
class Author < ActiveRecord::Base has_many :works end
Ruby
class VegasVideoMaker require 'rexml/document' @project = nil @medias = [] @video_event_count = 0 @audio_event_count = 0 def self.create vvm = self.new() doc = REXML::Document.new("<?xml version=\"1.0\"?><Vegas/>") vegas = doc.root project = vegas.add_element "Project" project.add_...
Ruby
class AcType < ActiveRecord::Base has_many :works has_many :scans validates_uniqueness_of :name end
Ruby
class Work < ActiveRecord::Base belongs_to :ac_type has_many :results belongs_to :author has_many :flash_vars, :conditions => "space_type_id is not null" has_many :youku_and_tudou, :class_name => "FlashVar", :conditions => "space_type_id in (4,6)" validates_uniqueness_of :wid, :message => 'wid same' valid...
Ruby
class SpaceType < ActiveRecord::Base end
Ruby
#bilibili排名算法 v2.1(2010.11.15) #没有实质性的变化,添加一些分析用数据 class Results::R21 < Results::R20 def get_es self.get_es nil, self.scan_id end def self.get_es scan_id_from=nil, scan_id_to=nil #scan_id1和scan_id2可以是scans的id,也可以是查询后的数组 if scan_id_to.class == Array results1 = scan_id_from else ...
Ruby
#bilibili排名算法 v2.3(2011.4.5) #评论分: 评论数*(50,50*(收藏数*100/(点击数+评论数*50))).min #收藏分: 收藏数*(100,24000/收藏数 + 20).min class Results::R23 < Results::R21 def self.version self.to_s.split('::R').last.to_f / 10 end def self.get_comment_revised clicks, comments, stows if comments <= 0 E_C.to_f else [f...
Ruby
#bilibili排名算法 v2.0(2010.9) #点击分 = 点击数 * (2/(P+1)) #评论分 = 评论数 * 50*(点击分/(点击分+评论数*50)) #收藏分 = 收藏数 * 100 #总分 = 点击分 + 评论分 + 收藏分 class Results::R20 < Results::Base #评论倍值 E_C = 50 #收藏倍值 E_S = 100 @space_fix = nil def get_ranking_point clicks_point = clicks * click_revised comment_point = commen...
Ruby
class Results::Base < ActiveRecord::Base set_table_name :results belongs_to :work belongs_to :scan #排行总分 def get_ranking_point end end
Ruby
#bilibili排名算法 v2.2(2011.1.5) #收藏分不超过5W分 class Results::R22 < Results::R21 def get_ranking_point clicks_point = clicks * click_revised comment_point = comments * comment_revised format("%.2f", (clicks_point + comment_point + (stows > 500 ? 50000 : stows * E_S)) * space_fix).to_f end end
Ruby
#bilibili排名算法 v90.0(2010.11.15) #版本号9x.x是特殊榜单的专用版本号 #此版本专为『周刊哔哩哔哩排行榜SP』所用 class Results::R900 < Results::R20 def get_ranking_point clicks_point = clicks * click_revised comment_point = comments * comment_revised ((clicks_point + comment_point + stows * 50) * space_fix ).to_i end def space_fix sup...
Ruby
class Syn def self.cron_syn print "Syn to sqlite to postgres\n" print "vacuum...\n" Weekly.connection.execute "vacuum;" print "weekly\n" PgWeekly.transaction do Weekly.all(:conditions => ["id > ? and wid is not null", PgWeekly.maximum('id') || 0]).each do |weekly| PgWeekly.connection.ex...
Ruby
class BiliRankingMaker < VegasVideoMaker attr_accessor :vt, :pa, :ut, :ops #:ut => usual_time alias :vvmtime :vt alias :vvmtime= :vt= TIME_30 = VegasVideoTime.ns(1) TIME_25 = VegasVideoTime.nl(25) TIME_20 = VegasVideoTime.nl(20) TIME_15 = VegasVideoTime.nl(15) TIME_10 = VegasVideoTime...
Ruby
class DResult < ActiveRecord::Base belongs_to :scan belongs_to :flash_var validates_uniqueness_of :flash_var_id, :scope=>:scan_id, :message => 'same' end
Ruby
class WeekliesController < ApplicationController before_filter :login_required layout "need_login" def edit @weekly = Weekly.find params[:id] end def index @weeklies = Weekly.all :limit => 5, :order => '"index" desc' end def update weekly = Weekly.find params[:id] weekly.update_attrib...
Ruby
class VegasController < ApplicationController def index end def ops if [6, 9].include?(params[:id].to_i) params[:id] = 2 end end def xml render :xml => eval("xml_#{params[:id]}") end #part2,6,9: normal list def xml_2 list1 = params[:ops][:list1].to_i list2 = params...
Ruby
class SessionsController < ApplicationController # render new.html.erb def new end def create logout_keeping_session! user = User.authenticate(params[:login], params[:password]) if user # Protects against session fixation attacks, causes request forgery # protection if user resubmits a...
Ruby
class DataController < ApplicationController caches_page :search def search begin if request.post? if params[:ops][:card] == '1' @html_title = "你是个好人 - 河童子" render :action =>'card', :layout => 'simple', :status => 500 else redirect_to searchget_path(params[:ops]...
Ruby