code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# 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
protect_from_forgery # See ActionController::RequestForgeryP... | Ruby |
class BiliApiController < ApplicationController
before_filter :login_required
layout "need_login"
def index
@apps = App.all
end
def app_add
App.create params[:app]
redirect_to :action => :index
end
def app_remove
App.destroy params[:id]
redirect_to :action => :index
end
def keys... | Ruby |
class IndexController < ApplicationController
caches_page :qa
def index
unless read_fragment({})
@latest = PgWeekly.last
@results = PgWeeklyResult.find_all_by_weekly_id @latest.id, :order => "score_rank", :limit => @latest.rank_from
end
end
end
| Ruby |
class PgWeekliesController < ApplicationController
def edit
@pg_weekly = PgWeekly.find params[:id]
end
def index
@weeklies = PgWeekly.all
end
def search
end
end
| Ruby |
class UsersController < ApplicationController
# render new.html.erb
def new
@user = User.new
end
def create
logout_keeping_session!
@user = User.new(params[:user])
success = @user && @user.save
if success && @user.errors.empty?
# Protects against session fixation attacks, causes requ... | 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.expand_path('../../config/boot', __FILE__)
require 'commands/dbconsole'
| 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/runner'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/profiler'
| Ruby |
#!/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 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 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 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 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 |
# 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 |
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 :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 to CSV"
task :export_to_csv => :environment do
puts time = 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)
... | Ruby |
namespace :bld do
desc "Get data"
task :get_acr_data => :environment do
date_now = Time.now
ac_types = ENV['codes'] ? AcType.find_all_by_page_code(ENV['codes'].split(',')) : AcType.find_all_by_code_type(0)
pages = Scan.search ac_types
puts "#{Time.now - date_now} second complete"
date_now = Ti... | 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
Rake::Task['bld:get_work_info'].invoke
Rake::Task['bld:ranking_work_info_fixed'].invoke
Rake::Task['bld:export_to_csv'].invoke
puts "#{Time.now - time} second!... | 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 |
# 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.5' unless defined? RAILS_GEM_VERSION
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')
r... | 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 |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
| Ruby |
class WeeklyExcept < ActiveRecord::Base
establish_connection :weekly
validates_uniqueness_of :wid, :scope=>:weekly_id, :message => 'same wid'
end
| Ruby |
class Result < ActiveRecord::Base
belongs_to :work
belongs_to :scan
#评论倍值
E_COMMENT = 50
def get_ranking_point
clicks_point = clicks.to_f * click_revised(true)
comment_point = comments.to_f * comment_revised
(clicks_point + comment_point + danmu.to_f) * space_fix
format("%.2f", (clicks_po... | Ruby |
class WeeklyResult < ActiveRecord::Base
establish_connection :weekly
belongs_to :weekly
#nil = 'new'
#-1 = except
#>0
def last_score_rank
return -1 if wid == weekly.last.last.wid
last_weekly = weekly.last
if last_weekly
last_result = WeeklyResult.find_by_wid_and_weekly_id wid, last_weekly... | Ruby |
class Scan < ActiveRecord::Base
has_many :results, :dependent => :destroy
def self.search ac_types
require 'net/http/persistent'
pages = []
http = Net::HTTP::Persistent.new
http.connection_for(URI.parse('http://bilibili.us/'))
ac_types.each do |ac_type|
date_now = Time.now
head_u... | 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 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, :order => '"index" desc'
end
end
| Ruby |
class Author < ActiveRecord::Base
has_many :works
end
| Ruby |
class AcType < ActiveRecord::Base
has_many :works
has_many :scans
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 |
class DResult < ActiveRecord::Base
belongs_to :scan
belongs_to :flash_var
validates_uniqueness_of :flash_var_id, :scope=>:scan_id, :message => 'same'
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
protect_from_forgery # See ActionController::RequestForgeryPr... | 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.expand_path('../../config/boot', __FILE__)
require 'commands/dbconsole'
| 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/runner'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/benchmarker'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../../config/boot', __FILE__)
require 'commands/performance/profiler'
| Ruby |
#!/usr/bin/env ruby
require File.expand_path('../../config/boot', __FILE__)
require 'commands/plugin'
| Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.