code
stringlengths
1
1.73M
language
stringclasses
1 value
class CreateJobs < ActiveRecord::Migration def self.up create_table :jobs do |t| t.string :name t.integer :rank t.timestamps end names = %w(fetch_reports parse_reports run_searches apply_autoscans release_batches clear_old_crawls) names.each_index{|i| Job.create(:name => ...
Ruby
class DropPlaces < ActiveRecord::Migration def self.up drop_table :places end def self.down end end
Ruby
class AddStuffToSources < ActiveRecord::Migration def self.up add_column :sources, :source_type_id, :integer add_column :sources, :pull_interval, :integer add_column :sources, :pulled_at, :datetime add_column :sources, :keywords, :text add_column :sources, :is_enabled, :boolean add_column :sources, ...
Ruby
class RemoveUrlsAndTaggings < ActiveRecord::Migration def self.up drop_table :urls drop_table :url_refs drop_table :taggings drop_table :tags end def self.down end end
Ruby
class AddAuthorToReports < ActiveRecord::Migration def self.up add_column :reports, :author, :string execute("update reports r, authors a set r.author=a.name where r.author_id=a.id") add_index(:reports, [:author]) drop_table(:authors) end def self.down end end
Ruby
class AddTitleContentIndicesToReports < ActiveRecord::Migration def self.up add_index(:reports, [:title],:length => 128) execute("create index index_content_on_reports on reports(content(128))") end def self.down remove_index(:reports, [:title],:length => 128) execute("drop index index_content_on...
Ruby
class DropFilters < ActiveRecord::Migration def self.up drop_table :filters end def self.down end end
Ruby
class RemoveAuthorFromReport < ActiveRecord::Migration def self.up remove_column :reports, :author end def self.down add_column :reports, :author, :string end end
Ruby
class CreateTaggings < ActiveRecord::Migration def self.up create_table :taggings do |t| t.integer :report_id t.integer :tag_id t.timestamps end end def self.down drop_table :taggings end end
Ruby
class CreateEntityAssocs < ActiveRecord::Migration def self.up create_table :entity_assocs do |t| t.integer :report_id t.integer :entity_id t.timestamps end add_index(:entity_assocs, [:report_id, :entity_id], :unique => true) end def self.down drop_table :entity_assocs e...
Ruby
class CreateSearches < ActiveRecord::Migration def self.up create_table :searches do |t| t.string :query t.datetime :last_run_at t.timestamps end end def self.down drop_table :searches end end
Ruby
class CreateJobRunPieces < ActiveRecord::Migration def self.up create_table :job_run_pieces do |t| t.integer :job_run_id t.string :name t.datetime :finished_at t.timestamps end end def self.down drop_table :job_run_pieces end end
Ruby
class CreateJanitorSweeps < ActiveRecord::Migration def self.up create_table :janitor_sweeps do |t| t.datetime :started_at t.integer :findtwitter_time t.integer :scrape_db_time t.integer :scrape_twitter_stream_time t.integer :run_search_time t.integer :autoscan_time t.dat...
Ruby
class RemoveEntities < ActiveRecord::Migration def self.up drop_table :entities end def self.down create_table :entities do |t| t.string :type t.string :content t.timestamps end add_index(:entities, [:type]) add_index(:entities, [:content]) end end
Ruby
class DropJanitorSweeps < ActiveRecord::Migration def self.up drop_table(:janitor_sweeps) if defined?(JanitorSweep) end def self.down end end
Ruby
class CreateSourceEvents < ActiveRecord::Migration def self.up create_table :source_events do |t| t.string :level t.string :msg t.integer :source_id t.timestamps end end def self.down drop_table :source_events end end
Ruby
class AddIsDayToTimespan < ActiveRecord::Migration def self.up add_column :timespans, :is_day, :boolean end def self.down remove_column :timespans, :is_day end end
Ruby
class AddQueryToSource < ActiveRecord::Migration def self.up add_column :sources, :query, :text end def self.down remove_column :sources, :query end end
Ruby
class AddUpdateFreqToSources < ActiveRecord::Migration def self.up add_column :sources, :update_freq, :integer Source.all.each{|s| s.update_freq = s.default_update_freq; s.save(:validate => false)} end def self.down remove_column :sources, :update_freq end end
Ruby
class CreateCrawls < ActiveRecord::Migration def self.up create_table :crawls do |t| t.integer :crawler_id t.datetime :finished_at t.timestamps end end def self.down drop_table :crawls end end
Ruby
class AddPlaceNameToIncident < ActiveRecord::Migration def self.up add_column :incidents, :place_name, :string end def self.down remove_column :incidents, :place_name end end
Ruby
class CreateTimespans < ActiveRecord::Migration def self.up create_table :timespans do |t| t.datetime :after_date t.datetime :before_date t.integer :after_offset t.integer :before_offset t.boolean :is_common t.timestamps end end def self.down drop_table :timespans...
Ruby
class DropGroupingAnalytics < ActiveRecord::Migration def self.up drop_table :grouping_analytics end def self.down end end
Ruby
class AddLatestAuthoredAtToSources < ActiveRecord::Migration def self.up add_column :sources, :latest_authored_at, :datetime end def self.down remove_column :sources, :latest_authored_at end end
Ruby
class AddOffsetToSources < ActiveRecord::Migration def self.up add_column :sources, :offset, :integer end def self.down remove_column :sources, :offset end end
Ruby
class CreateGroupingAnalytics < ActiveRecord::Migration def self.up create_table :grouping_analytics do |t| t.string :name t.string :search_term t.text :sql t.timestamps end # add a few (put limit 1, which will be replaced) GroupingAnalytic.create(:name => "Top Tags", :se...
Ruby
class CreateCrawlers < ActiveRecord::Migration def self.up create_table :crawlers do |t| t.timestamps end end def self.down drop_table :crawlers end end
Ruby
class AddNameIndexToTags < ActiveRecord::Migration def self.up add_index(:tags, [:name]) end def self.down remove_index(:tags, [:name]) end end
Ruby
class DropIncidentStatusChanges < ActiveRecord::Migration def self.up drop_table :incident_status_changes end def self.down end end
Ruby
class AddCodeToIncident < ActiveRecord::Migration def self.up add_column :incidents, :code, :string end def self.down remove_column :incidents, :code end end
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.string :username t.string :password t.timestamps end User.create(:username => "root", :password => "freeNfair") end def self.down drop_table :users end end
Ruby
class AddFieldsToReport < ActiveRecord::Migration def self.up add_column :reports, :important, :string add_column :reports, :scanner_session_id, :string add_column :reports, :scan_started_at, :datetime add_column :reports, :is_autoscanned, :boolean end def self.down remove_column :reports, :i...
Ruby
class AddIndexToUrls < ActiveRecord::Migration def self.up add_index(:urls, [:address]) end def self.down remove_index(:urls, [:address]) end end
Ruby
class CreateJobRuns < ActiveRecord::Migration def self.up create_table :job_runs do |t| t.integer :job_id t.integer :crawl_id t.datetime :finished_at t.string :error t.timestamps end end def self.down drop_table :job_runs end end
Ruby
class CreateFilters < ActiveRecord::Migration def self.up create_table :filters do |t| t.integer :timespan_id t.string :ref t.timestamps end end def self.down drop_table :filters end end
Ruby
class CreateSettings < ActiveRecord::Migration def self.up create_table :settings do |t| t.string :timezone t.string :webmaster_email t.timestamps end end def self.down drop_table :settings end end
Ruby
class CreateBatches < ActiveRecord::Migration def self.up create_table :batches do |t| t.timestamps end end def self.down drop_table :batches end end
Ruby
class AddOrigIdToReports < ActiveRecord::Migration def self.up add_column :reports, :orig_id, :string end def self.down remove_column :reports, :orig_id end end
Ruby
class CreateIncidentStatusChanges < ActiveRecord::Migration def self.up create_table :incident_status_changes do |t| t.integer :incident_id t.string :old_status t.string :new_status t.timestamps end add_index(:incident_status_changes, [:incident_id]) end def self.down rem...
Ruby
class AddDuplicatesToScrape < ActiveRecord::Migration def self.up add_column :scrapes, :duplicates, :integer end def self.down remove_column :scrapes, :duplicates end end
Ruby
class CreateSourceTypes < ActiveRecord::Migration def self.up create_table :source_types do |t| t.string :name t.string :code t.string :method t.boolean :requires_url t.timestamps end SourceType.create(:name => "RSS", :method => "pull") SourceType.create(:name...
Ruby
class AddImportantIndexToReports < ActiveRecord::Migration def self.up add_index(:reports, [:important]) end def self.down end end
Ruby
class CreateAutoscans < ActiveRecord::Migration def self.up create_table :autoscans do |t| t.integer :search_id t.timestamps end end def self.down drop_table :autoscans end end
Ruby
class AddIsPuToPlace < ActiveRecord::Migration def self.up add_column :places, :is_pu, :boolean execute("update places set is_pu = 1"); end def self.down remove_column :places, :is_pu end end
Ruby
class RemovePlaceIdFromIncident < ActiveRecord::Migration def self.up remove_column :incidents, :place_id end def self.down end end
Ruby
class CreateIncidents < ActiveRecord::Migration def self.up create_table :incidents do |t| t.string :title t.integer :category_id t.integer :place_id t.text :notes t.string :status t.decimal :lat, :precision => 20, :scale => 15 t.decimal :lng, :precision => 20, :scale => ...
Ruby
class CreateTags < ActiveRecord::Migration def self.up create_table :tags do |t| t.string :name t.boolean :is_hash t.timestamps end end def self.down drop_table :tags end end
Ruby
class AddCodeToPlace < ActiveRecord::Migration def self.up add_column :places, :code, :string end def self.down remove_column :places, :code end end
Ruby
class RemoveOffsetFromSources < ActiveRecord::Migration def self.up remove_column :sources, :offset end def self.down add_column :sources, :offset, :integer end end
Ruby
class RemoveOldCrawlerClasses < ActiveRecord::Migration def self.up drop_table :crawls drop_table :jobs drop_table :job_runs drop_table :job_run_pieces drop_table :source_events end def self.down end end
Ruby
class DropSourceType < ActiveRecord::Migration def self.up drop_table :source_types end def self.down end end
Ruby
class AddAltCodeToPlace < ActiveRecord::Migration def self.up add_column :places, :short_code, :string end def self.down remove_column :places, :alt_code end end
Ruby
class CreateCategories < ActiveRecord::Migration def self.up create_table :categories do |t| t.string :name t.integer :parent_id t.timestamps end end def self.down drop_table :categories end end
Ruby
class CreatePlaces < ActiveRecord::Migration def self.up create_table :places do |t| t.string :name t.string :short_name t.string :kind t.integer :parent_id t.decimal :lat, :precision => 20, :scale => 15 t.decimal :lng, :precision => 20, :scale => 15 t.timestamps end...
Ruby
class AddIsActiveAndIsSavedToSearch < ActiveRecord::Migration def self.up add_column :searches, :is_active, :boolean add_column :searches, :is_saved, :boolean end def self.down remove_column :searches, :is_saved remove_column :searches, :is_active end end
Ruby
class UpdateAuthorAnalytic < ActiveRecord::Migration def self.up GroupingAnalytic.find_by_name("Top Authors").update_attributes(:search_term => "author", :sql => "select reports.id as id, author as name, count(*) as num from reports group by author order by num desc limit 1") end def self.down ...
Ruby
class AddDigestToReports < ActiveRecord::Migration def self.up add_column :reports, :digest, :string add_index :reports, [:digest] end def self.down #remove_column :reports, :hash end end
Ruby
class CreateAuthors < ActiveRecord::Migration def self.up create_table :authors do |t| t.string :name t.timestamps end end def self.down drop_table :authors end end
Ruby
class CreateScrapes < ActiveRecord::Migration def self.up create_table :scrapes do |t| t.string :url t.integer :additions t.timestamps end end def self.down drop_table :scrapes 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' }]) # Mayor.create(:name =>...
Ruby
STDOUT.sync = true # get rails root RAILS_ROOT = File.expand_path(File.dirname(__FILE__) + "/../..") LOCAL_CONF = File.read(File.join(RAILS_ROOT, "config/initializers/conf-local.rb")) # get rake path from local-config RAKE_PATH = LOCAL_CONF.match(/rake_path\s*=\s*"(.+)"/)[1] # get crawler PID file pid_file = File.j...
Ruby
#!/usr/local/bin/ruby RAILS_ROOT = File.expand_path(File.dirname(__FILE__) + "/../..") # hack to get local config server_url = "" File.open("#{RAILS_ROOT}/config/initializers/conf-local.rb") do |f| f.read.match(/server_root_path = "(.+)"/) server_url = $1 end tempfile = "#{RAILS_ROOT}/tmp/emailtemp" # redirect s...
Ruby
# lib/tasks/cron_print.rake # prints a set of cron jobs that should be installed by the admin using crontab -e namespace :cron do desc "Print cron jobs to be installed." task :print => :environment do every_5 = "0,5,10,15,20,25,30,35,40,45,50,55" jobs = ["#{every_5} * * * * cd #{Rails.root}; export GEM_HO...
Ruby
namespace :db do desc "Seed the current environment's database." task :seed_it => :environment do ActiveRecord::Base.transaction do find_or_create(User, :username, :username => "root", :password => "freeNfair") end end end def find_or_create(klass, key_field, attribs) key_val = attribs[key_field...
Ruby
STDOUT.sync = true namespace :crawler do desc "Background task that runs continuously and does all the gathering." task :go => :environment do Crawler::Crawler.generate.go end end
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Aggie::Application
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path('../../config/environment', __FILE__) require 'rails/test_help' class ActiveSupport::TestCase # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. # # Note: You'll currently still have to declare fixtures explicitly in integrati...
Ruby
require 'sinatra/activerecord/rake' require './main'
Ruby
source :gemcutter gem 'sinatra', :require => 'sinatra/base' gem 'thin', '~> 1.3' gem 'pg' gem 'sinatra-activerecord' gem 'google-api-client', '>= 0.4.4', :require => 'google/api_client' group :development do gem 'rake' gem 'sqlite3-ruby' end
Ruby
class CreateUsers < ActiveRecord::Migration def up create_table :users do |t| t.string :profile_id t.string :email t.string :refresh_token end add_index :users, :profile_id end def down drop_table :users end end
Ruby
# Copyright (C) 2012 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writ...
Ruby
require 'sinatra.rb' # Sinatra defines #set at the top level as a way to set application configuration set :run, false set :env, (ENV['RACK_ENV'] ? ENV['RACK_ENV'].to_sym : :development) require './main' run Sinatra::Application
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
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module WikiHelper end
Ruby
class Page < ActiveRecord::Base end
Ruby
class WikiController < ApplicationController def index @page = Page.find_by_name( params[:name] || 'FrontPage' ) 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 # Pick a unique cookie name to distinguish our session data from others' session :session_key => '_wiki_sessi...
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/breakpointer'
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/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/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' require 'commands/about'
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/breakpointer'
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