code
stringlengths
1
1.73M
language
stringclasses
1 value
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/plugin'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/dbconsole'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/runner'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/console'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/destroy'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/generate'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/server'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.expand_path('../../config/boot', __FILE__) require 'commands/plugin'
Ruby
class AddStowToResults < ActiveRecord::Migration def self.up add_column :results, :stows, :integer end def self.down remove_column :results, :stows end end
Ruby
class CreateResults < ActiveRecord::Migration def self.up create_table :results do |t| t.integer :work_id t.integer :scan_id t.integer :clicks t.integer :comments end end def self.down drop_table :results end end
Ruby
class CreateBangumiWorks < ActiveRecord::Migration def self.up create_table :bangumi_works do |t| t.integer :bangumi_id t.integer :work_id t.integer :index end end def self.down drop_table :bangumi_works end end
Ruby
class CreateSpaceTypes < ActiveRecord::Migration def self.up create_table :space_types do |t| t.string :name t.string :code end SpaceType.create :name => 'sina', :code => 'vid' SpaceType.create :name => 'bilibili', :code => 'avid' SpaceType.create :name => 'other', :code => 'id' Sp...
Ruby
class AddColumnPicToWork < ActiveRecord::Migration def self.up add_column :works, :pic_path, :string end def self.down remove_column :works, :pic_path end end
Ruby
class CreateScans < ActiveRecord::Migration def self.up create_table :scans do |t| t.integer :ac_type_id t.text :description t.timestamps end end def self.down drop_table :scans end end
Ruby
class CreateAuthor < ActiveRecord::Migration def self.up create_table :authors do |t| t.string :login_name t.string :nick_name end end def self.down drop_table :authors end end
Ruby
class CreateBangumis < ActiveRecord::Migration def self.up create_table :bangumis do |t| t.string :bangumi_type_id, :integer t.string :name t.string :nick_name t.string :pic_path t.integer :status end end def self.down drop_table :bangumis end end
Ruby
class AddTjAndYbToResults < ActiveRecord::Migration def self.up add_column :results, :tj, :integer add_column :results, :yb, :integer end def self.down remove_column :results, :tj remove_column :results, :yb end end
Ruby
class CreateFlashVars < ActiveRecord::Migration def self.up create_table :flash_vars do |t| t.string :vid t.integer :work_id end end def self.down drop_table :flash_vars end end
Ruby
class AddIndexToWorks < ActiveRecord::Migration def self.up add_index :works, :wid, :unique => true end def self.down remove_index :works, :wid end end
Ruby
class AddCodeTypeToAcTypes < ActiveRecord::Migration def self.up add_column :ac_types, :code_type, :integer AcType.all.each{|ac| ac.update_attribute :code_type, 0} end def self.down remove_column :ac_types, :code_type end end
Ruby
class CreateWorks < ActiveRecord::Migration def self.up create_table :works do |t| t.string :name t.datetime :cdate t.integer :wid t.integer :ac_type_id t.integer :author_id t.string :author_name t.integer :status, :default => 1 #1-正常 2-除外 t.integer :part_coun...
Ruby
class AddColumnDanmuToResult < ActiveRecord::Migration def self.up add_column :results, :danmu, :integer end def self.down remove_column :results, :danmu end end
Ruby
class CreateDResults < ActiveRecord::Migration def self.up create_table :d_results do |t| t.integer :scan_id t.integer :flash_var_id t.integer :d_count end end def self.down drop_table :d_results end end
Ruby
class CreateAcTypes < ActiveRecord::Migration def self.up create_table :ac_types do |t| t.string :name t.string :page_name t.string :page_code end end def self.down drop_table :ac_types end end
Ruby
class AddStatusToScans < ActiveRecord::Migration def self.up add_column :scans, :status, :integer end def self.down remove_column :scans, :status end end
Ruby
class CreateBangumiTypes < ActiveRecord::Migration def self.up create_table :bangumi_types do |t| t.string :name t.integer :index end end def self.down drop_table :bangumi_types end end
Ruby
class AddMidToAuthors < ActiveRecord::Migration def self.up add_column :authors, :mid, :integer end def self.down remove_column :authors, :mid end end
Ruby
class CreateKeysUsers < ActiveRecord::Migration def self.up create_table :key_users do |t| t.integer :key_id t.string :uname end end def self.down drop_table :key_users end end
Ruby
class AddAccessKeyToKeysUsers < ActiveRecord::Migration def self.up add_column :key_users, :access_key, :string end def self.down remove :key_users, :access_key end end
Ruby
class CreateApps < ActiveRecord::Migration def self.up create_table :apps do |t| t.string :name end end def self.down drop_table :apps end end
Ruby
class CreateKeys < ActiveRecord::Migration def self.up create_table :keys do |t| t.string :controller t.string :url t.string :sec_key t.string :bili_key t.integer :app_id end end def self.down drop_table :keys end end
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users, :force => true do |t| t.string :login, :crypted_password, :salt, :remember_token, :limit => 40 t.datetime :remember_token_expires_at t.string :name, :limit => 100, :default => '', :null => true ...
Ruby
class AddTjAndYbToWeeklyResults < ActiveRecord::Migration def self.up add_column :pg_weekly_results, :tj, :integer add_column :pg_weekly_results, :tj_rank, :integer add_column :pg_weekly_results, :yb, :integer add_column :pg_weekly_results, :yb_rank, :integer end def self.down end end
Ruby
class CreatePgWeeklies < ActiveRecord::Migration def self.up create_table :pg_weeklies do |t| t.string :name t.integer :wid t.integer :parent_id t.integer :index t.integer :rank_from t.string :rule end end def self.down drop_table :pg_weeklies end end
Ruby
class CreatePgWeeklyExcepts < ActiveRecord::Migration def self.up create_table :pg_weekly_excepts do |t| t.integer :weekly_id t.integer :wid end end def self.down drop_table :pg_weekly_excepts end end
Ruby
class CreatePgSpTypes < ActiveRecord::Migration def self.up create_table :pg_sp_types do |t| t.string :name t.string :code end end def self.down drop_table :sp_types end end
Ruby
class CreatePgWeeklyResults < ActiveRecord::Migration def self.up create_table :pg_weekly_results do |t| t.integer :weekly_id t.integer :wid t.string :name t.string :wtype t.string :author t.integer :clicks t.integer :clicks_rank t.integer :comments t.integer ...
Ruby
class ChangeSpaceFixToSpType < ActiveRecord::Migration def self.up space_fix_type = SpType.create! :name =>'娱乐版tudou和youku的0.5修正', :code => "tudou and youku" WeeklyResult.transaction do WeeklyResult.find_all_by_is_space_fix(true).each{|wr| wr.update_attribute :sp_type_id, space_fix_type.id} end end...
Ruby
class AddColumnSpTypeIdToWeeklyResults < ActiveRecord::Migration def self.up add_column :pg_weekly_results, :sp_type_id, :integer end def self.down remove_column :pg_weekly_results, :sp_type_id end end
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' }]) # Major.create(:name...
Ruby
class CreateWeeklies < ActiveRecord::Migration def self.up create_table :weeklies do |t| t.string :name t.integer :wid t.integer :parent_id t.integer :index t.integer :rank_from end end def self.down drop_table :weeklies end end
Ruby
class CreateWeeklyZeros < ActiveRecord::Migration def self.up WeeklyAttr.create :code => 'zero' create_table :weekly_zeros do |t| t.integer :weekly_result_work_id end end def self.down drop_table :weekly_zeros end end
Ruby
class AddTjAndYbToWeeklyResults < ActiveRecord::Migration def self.up add_column :weekly_results, :tj, :integer add_column :weekly_results, :tj_rank, :integer add_column :weekly_results, :yb, :integer add_column :weekly_results, :yb_rank, :integer end def self.down end end
Ruby
class CreateWeeklyResultTmp < ActiveRecord::Migration def self.up create_table :weekly_result_tmp do |t| t.integer :weekly_result_work_id t.string :name t.integer :wid t.string :wtype t.string :author t.integer :clicks t.integer :clicks_rank t.integer :part t...
Ruby
class CreateWeeklyExternals < ActiveRecord::Migration def self.up create_table :weekly_externals do |t| t.integer :weekly_id t.integer :weekly_attr_id t.string :value end end def self.down drop_table :weekly_externals end end
Ruby
class CreateWeeklyResultWorks < ActiveRecord::Migration def self.up create_table :weekly_result_works do |t| t.integer :wid t.string :name t.string :wtype t.string :author end add_column :weekly_results, :weekly_result_work_id, :integer end def self.down end end
Ruby
class WeeklyZerosSyn < ActiveRecord::Migration def self.up puts time = Time.now =begin while true do results = WeeklyResult.all :conditions => "clicks = 0 and comments = 0 and (stows = 0 or stows is null) " + "and (danmu = 0 or danmu is nu...
Ruby
class RemoveColumnFromWeeklyResults < ActiveRecord::Migration def self.up Weekly.connection.execute %[ALTER TABLE "main"."weekly_results" RENAME TO "t_weekly_results"] Weekly.connection.execute %[CREATE TABLE "main"."weekly_results" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,"weekly_id" integer,"clicks"...
Ruby
class ChangeSpaceFixToSpType < ActiveRecord::Migration def self.up space_fix_type = SpType.create! :name =>'娱乐版tudou和youku的0.5修正', :code => "tudou and youku" WeeklyResult.transaction do WeeklyResult.all(:conditions => "is_space_fix = 't'").each{|wr| wr.update_attribute :sp_type_id, space_fix_type.id} ...
Ruby
class CreateWeeklyExcepts < ActiveRecord::Migration def self.up create_table :weekly_excepts do |t| t.integer :weekly_id t.integer :wid end end def self.down drop_table :weekly_excepts end end
Ruby
class WeeklyResultWorksSyn < ActiveRecord::Migration def self.up fresult = WeeklyResult.first :conditions => "weekly_result_work_id is null", :order => "id" if fresult fid = fresult.id - 1 puts time = Time.now while true do results = WeeklyResult.all :offset => fid, :limit => 2500, :order =>...
Ruby
class CreateSpTypes < ActiveRecord::Migration def self.up create_table :pg_sp_types do |t| t.string :name t.string :code end end def self.down drop_table :pg_sp_types end end
Ruby
class AddColumnSpTypeIdToWeeklyResults < ActiveRecord::Migration def self.up add_column :weekly_results, :sp_type_id, :integer end def self.down remove_column :weekly_results, :sp_type_id end end
Ruby
class CreateWeeklyResults < ActiveRecord::Migration def self.up create_table :weekly_results do |t| t.integer :weekly_id t.integer :wid t.string :name t.string :wtype t.string :author t.integer :clicks t.integer :clicks_rank t.integer :comments t.integer :comm...
Ruby
class CreateWeeklyAttrs < ActiveRecord::Migration def self.up create_table :weekly_attrs do |t| t.string :code end end def self.down drop_table :weekly_attrs end end
Ruby
module AuthenticatedSystem protected # Returns true or false if the user is logged in. # Preloads @current_user with the user model if they're logged in. def logged_in? !!current_user end # Accesses the current user from the session. # Future calls avoid the database because nil is not ...
Ruby
namespace :bld do desc "stat current" task :stat => :environment do puts time = Time.now results = {} current_weekly = Weekly.last pre_weekly = current_weekly.last #当前期集计投稿数与增值 results[:current_work_count] = current_weekly.weekly_results.size results[:added_work_count] = current_weekly....
Ruby
#pa, id #list1 => true list1_count => 30 #list2 => true list2_count => 120 namespace :bld do desc "Export to image from database" task :export_to_img => :environment do require 'lib/tasks/bili_ranking_image.rb' pa = "#{BILI_PRO_PATH}#{ENV['pa']}\\" list1 = ENV['list1'] || true list1 = false if list1...
Ruby
namespace :acr do desc "Video auto copy" task :avi_copy => :environment do require 'csv' pa = "#{BILI_PRO_PATH}#{ENV['pa']}\\" csv_file = File.open "#{pa}_list.csv" csv_data = CSV::IOReader.new(csv_file) list_count = (ENV['list_count'] || 30).to_i data = [] csv_data.each do |row| d...
Ruby
#name, wid, pa namespace :bld do desc "Import scan result to database" task :save_history_data => :environment do date_now = Time.now pa = ENV['pa'] ? "#{BILI_PRO_PATH}#{ENV['pa']}/" : nil id1 = ENV['id1'] || (YAML.load(open(File.join "#{RAILS_ROOT}/config/last.yml")) rescue 0) id2 = ENV['id2'] || ...
Ruby
namespace :bld do desc "get data and export" task :fans => :environment do urlb = "http://interface.bilibili.tv/card/" fans = (YAML.load(open(%[#{Rails.root}/config/_fans.yml])) rescue []) fans_nil = (YAML.load(open(%[#{Rails.root}/config/_fans_nil.yml])) rescue []) fan_names = fans.collect{|fan| fa...
Ruby
namespace :bilibiliranking do desc "bilibili ranking example pickup" task :pickup => :environment do doc = BiliRankingMaker.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| vvm.pickup end doc.write File.open("#{BILI_PRO_PATH}#{ENV['pa']}\\" + "xml.xml", 'w') end end
Ruby
namespace :bilibiliranking do desc "bilibili ranking example over" task :over => :environment do doc = BiliRankingMaker.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| vvm.play_bgm("bilibili.mp3") do vvm.pics "over", 1..2, :length => 7 end end doc.write File.open("#{BILI...
Ruby
namespace :bilibiliranking do desc "bilibili ranking example pickup title" task :title => :environment do doc = BiliRankingMaker.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| vvm.title(4, true) end doc.write File.open("#{BILI_PRO_PATH}#{ENV['pa']}\\" + "xml.xml", 'w') end end
Ruby
namespace :bilibiliranking do desc "bilibili ranking example op" task :op => :environment do doc = BiliRankingMaker.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| vvm.op.pics("op", [1], {:length => 5, 2 => {:length => 9}, 4 => {:length => 3}} ).pics("rule", 0..4, {:length =>...
Ruby
namespace :bilibiliranking do desc "bilibili ranking example ed" task :ed => :environment do doc = BiliRankingMaker.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| vvm.ed_bgm do |length| vvm.ut[:pic_list] = VegasVideoTime.nl length - 21 if length > 21 #这句计算出每张排名图片停留的时间 vvm.tit...
Ruby
namespace :bilibiliranking do desc "bilibili ranking example history" task :history => :environment do doc = BiliRankingMaker.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| vvm.play_bgm('1.mp3') do vvm.pics('weekly', [1], :length => 6) vvm.pics "history", [1], :length => 6 ...
Ruby
namespace :bilibiliranking do desc "bilibili ranking example list" task :list => :environment do doc = BiliRankingMaker.create({:path => "#{BILI_PRO_PATH}#{ENV['pa']}\\"}) do |vvm| =begin vvm.play_bgm('bilibili-mubox.wav') do vvm.pics "rest", [1], :length => 4 end vvm.list1 [118] =end ...
Ruby
namespace :crp do desc "Migrate the database through scripts in db/user with database config session \"user\" in config/database.yml. Target specific version with VERSION=x" task :user_migrate => :environment do ActiveRecord::Base.establish_connection :user ActiveRecord::Migrator.migrate("db/user/", ENV["VE...
Ruby
require 'digest/sha1' require 'erb' def site_keys_file File.join("config", "initializers", "site_keys.rb") end def secure_digest(*args) Digest::SHA1.hexdigest(args.flatten.join('--')) end def make_token secure_digest(Time.now, (1..10).map{ rand.to_s }) end def make_site_keys_rb site_key = secure_digest(Time...
Ruby
#id1 前,default=0; id2 后,default=last.id; pa, 必须有except.yml namespace :bld do desc "Export" task :export => :environment do puts time = Time.now pa = ENV['pa'] ? "#{BILI_PRO_PATH}#{ENV['pa']}/" : "#{BILI_PRO_PATH}ranking/" id1 = ENV['id1'] || (YAML.load(open(File.join "#{Rails.root}/config/last.yml")) re...
Ruby
namespace :gumi do desc "get gumi@bilibili data" task :get_data => :environment do base_url = "http://www.bilibili.tv/sppage/" ad_recommend = "ad-recommend-345-" tag_hot = "tag-hot-345-" http = Net::HTTP::Persistent.new(nil, (PROXY ? URI.parse(PROXY) : nil)) #集计范围数组 wids = [] #ad-...
Ruby
namespace :bld do desc "Get data" task :get_acr_data => :environment do RAILS_DEFAULT_LOGGER.fatal "Start #{Time.now}" date_now = Time.now ac_types = ENV['codes'] ? AcType.find_all_by_page_code(ENV['codes'].split(',')) : AcType.find_all_by_code_type(0) scan = Scan.create! :description => "#{DateTim...
Ruby
namespace :bld do desc "Export to image from database" task :export_to_img_sp => :environment do require 'csv' require 'lib/tasks/bili_ranking_image_sp.rb' pa = "#{BILI_PRO_PATH}rankingSP1\\" list1_count = 100 list2_count = 13 img_maker = BiliRankingImage.new pa csv_file = File.open "...
Ruby
namespace :bld do desc "save data and stat" task :bat2 => :environment do Rake::Task['bld:save_history_data'].invoke Rake::Task['bld:stat'].invoke end end
Ruby
class BiliRankingImage require 'RMagick' include Magick require 'jcode' attr_accessor :path alias :pa :path alias :pa= :path= FONT_EXE = "#{RAILS_ROOT}/public/acfun_list_font_pic.exe" TMP_FILE = 'tmp.png' @@iconv ||= Iconv.new 'GB18030', 'UTF-8//IGNORE' FONT_FZZHY_GBK = @@iconv.iconv "方正准圆_GBK" F...
Ruby
class BiliRankingImage require 'RMagick' include Magick require 'jcode' attr_accessor :path alias :pa :path alias :pa= :path= FONT_EXE = "#{RAILS_ROOT}/public/acfun_list_font_pic.exe" TMP_FILE = 'tmp.png' @@iconv ||= Iconv.new 'GB18030', 'UTF-8//IGNORE' FONT_FZZHY_GBK = @@iconv.iconv "方正准圆_GBK" F...
Ruby
namespace :bld do desc "get data and export" task :bat => :environment do puts time = Time.now Rake::Task['bld:get_acr_data'].invoke GC.start Rake::Task['bld:get_work_info'].invoke GC.start Rake::Task['bld:ranking_work_info_fixed'].invoke GC.start Rake::Task['bld:export_to_csv'].invo...
Ruby
module AuthenticatedTestHelper def log_in user = User.make @request.session[:user_id] = user.id end def authorize user = User.make @request.env["HTTP_AUTHORIZATION"] = ActionController::HttpAuthentication::Basic.encode_credentials(user.login, user.password) end end
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 # Use a different logger for distributed setups # config.logger = SyslogLogger.new # Full error repor...
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 web 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 ...
Ruby
# Don't change this file. Configuration is done in config/environment.rb and config/environments/*.rb unless defined?(RAILS_ROOT) root_path = File.join(File.dirname(__FILE__), '..') unless RUBY_PLATFORM =~ /mswin32/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).to_s end RAILS...
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
module AdminHelper end
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper def menu(items) '<div id="sub-menu">' + items.join(' | ') + '</div>' end def icon_menu(items) '<div class="icon-menu">' + items.join + '</div>' end def items_menu(title, items) '<di...
Ruby
module UserHelper end
Ruby
module BillHelper end
Ruby
module HistoryHelper end
Ruby
module AccountsHelper end
Ruby
class Bill < ActiveRecord::Base acts_as_paranoid validates_presence_of :name, :amount, :due, :user, :account validates_numericality_of :amount has_many :payable_bills belongs_to :user belongs_to :account after_create :create_payable_bills def details "$#{amount} due on #{due.to_s(:short)...
Ruby
class PayableBill < ActiveRecord::Base acts_as_paranoid validates_presence_of :bill, :user, :amount validates_numericality_of :amount belongs_to :bill belongs_to :account belongs_to :user def name bill.name end def due bill.due end def details '$' + self.amount + ' d...
Ruby
class Account < ActiveRecord::Base acts_as_paranoid validates_presence_of :user, :name, :details belongs_to :user belongs_to :bill end
Ruby
class User < ActiveRecord::Base ROLES = ['user', 'admin'] acts_as_paranoid validates_presence_of :username, :password, :firstname, :lastname, :email validates_uniqueness_of :username validates_length_of :password, :minimum => 6 validates_confirmation_of :password validates_inclusion_of ...
Ruby