code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# = Test : Amazon SimpleDB Test
# A simple component designed to verify that
# the ActiveSdb bindings are working properly and to do a littel benchmark
# to transfer a 1000 items back and forward to Amazon SimpleDb. Run with
#
# ruby runner.rb -t test/active_sdb -a your_access_key -s your_secret_key
#
# Additional fl... | Ruby |
# = Test : Blender
# A unit test for the BayesBlender, which is complex enough to
# require a dedicated effort to get it right.
#
# Refer to test/unittests.rb on how to run unit tests.
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm project.
# Licensed under th... | Ruby |
# = Unit
# The 'unit' folder contains unit tests.
#
# == Copyright
# Copyright(c) 2008 - bayes-swarm project.
# Licensed under the GNU General Public License v2. | Ruby |
# = Test : ActiveRecord No-Op
# A simple component designed to verify that
# the ActiveReport bindings are working properly. Run with
#
# ruby runner.rb -c swarm_shoal_options.yml -f test/arnoop
#
# If everything is fine, it should print the list of pages stored in
# the database
#
# == Author
# Riccardo Govoni [batt... | Ruby |
# = Test : No-Op
# A simple component designed to verify that
# the Runner and component system are setup properly. Run with
#
# ruby runner.rb -c swarm_shoal_options.yml -f test/noop
#
# If everything is fine, it should just print a log line saying +NoOp.+
#
# == Author
# Riccardo Govoni [battlehorse@gmail.com]
#
# ... | 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 |
class Date
def self.from_interval(string)
string = string.to_s.strip.downcase
if string =~ /^(\d+)(\s*(d|w|m|y))?$/
n = $1.to_i
units = $2
case units
when 'd'
n.days.ago
when 'w'
n.weeks.ago
when 'm'
n.months.ago
when 'y'
n.years.ago
... | Ruby |
class Sdb
# domains: enumerable
# entities: enumerable
# conditions : hash
def select(domains, entities, conditions, limit=2500)
start = Time.now
items = []
condition_keys = []
condition_values = []
conditions.each_pair do |k, v|
if v.is_a?(Range)
condition_keys << "#{k} >= ... | 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 |
QuasarConfig = {
:sdb_access_key => '',
:sdb_secret_key => '',
:sdb_port => 443,
:sdb_protocol => 'https'
} | Ruby |
QuasarConfig = {
:sdb_access_key => '',
:sdb_secret_key => '',
:sdb_port => 443,
:sdb_protocol => 'https'
} | 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.2' 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|
# 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 Page < ActiveRecord::Base
belongs_to :source
belongs_to :kind
def self.fill_pages(params)
params[:source] && params[:source] != '0' ? Source.find(params[:source]).pages.map { |p| p.id } : nil
end
end | Ruby |
class Intword < ActiveRecord::Base
belongs_to :language
@@entities = [ 'count', 'bodycount', 'titlecount' , 'keywordcount' , 'anchorcount', 'headingcount' ]
@@lowest_date = Date.civil(2007, 1, 1)
def self.fill_intwords(params)
unless params[:id].blank?
iws = Intword.find_all_by_name(
... | Ruby |
class Language < ActiveRecord::Base
set_table_name "globalize_languages"
def name
iso_639_1
end
end | Ruby |
class Kind < ActiveRecord::Base
has_many :pages
def self.fill_kind(params)
kind = Kind.find_by_kind(params[:kind])
if kind
kind.kind
else
nil
end
end
end | Ruby |
require 'csv'
# This class implements a Google Visualization APIs Datasource, as defined
# here: http://code.google.com/intl/it/apis/visualization/documentation/dev/implementing_data_source.html.
#
# It is expected to be used inside a Rails application, as it relies on some
# Rails-specific methods (such as +to_json+)... | Ruby |
class Aggregate
@@entities = [ 'count', 'bodycount', 'titlecount' , 'keywordcount' , 'anchorcount', 'headingcount' ]
@@lowest_date = Date.civil(2007, 1, 1)
def self.motion(sdb, from_date, to_date, intwords, kind=nil, entity='count', pages=nil)
validate_entity(entity)
low_date, high_date = validate_d... | Ruby |
class Source < ActiveRecord::Base
has_many :pages
end | Ruby |
class HomeController < ApplicationController
def intro
end
end | Ruby |
# Helper class that simplifies the work of producing a Rails controller
# capable of exposing Google Visualization APIs datasources, as defined here:
# http://code.google.com/intl/it/apis/visualization/documentation/dev/implementing_data_source.html.
#
# This class requires +gviz.rb+ model class to work.
# A controller... | Ruby |
class InfoController < ApplicationController
def developers
end
def contacts
end
end | Ruby |
class IntwordController < ApplicationController
# TODO: should be removed or transformed into a 'pre-configured' visualization
# def show
# @gviz_url = request.request_uri.gsub(/\/intword\/show/,"/gviz/#{params[:type]}").gsub(/&type=[^&]+/,'')
# @sources = Source.find(:all).sort_by { |s| s.name }
# end... | Ruby |
class GvizController < GvizBaseController
def ts
sdb = Sdb.new
gvizifier do |gviz|
pages = Page.fill_pages(params)
iws = Intword.fill_intwords(params)
kind = Kind.fill_kind(params)
csv_filename(iws.map { |iw| iw.id }.join('-'),
pages ? pages.join('-') : ni... | 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.dirname(__FILE__) + '/../config/boot'
require 'commands/dbconsole'
| 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'
$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
require File.dirname(__FILE__) + '/../config/boot'
require 'commands/runner'
| 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/destroy'
| 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/server'
| 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/plugin'
| Ruby |
ENV["RAILS_ENV"] = "test"
require File.expand_path(File.dirname(__FILE__) + "/../config/environment")
require 'test_help'
class ActiveSupport::TestCase
# Transactional fixtures accelerate your tests by wrapping each test method
# in a transaction that's rolled back on completion. This ensures that the
# test da... | Ruby |
require 'rsruby'
require 'rsruby/dataframe'
module R_Config
R = RSRuby.instance
end
| Ruby |
class Array
def sum
inject( nil ) { |sum,x| sum ? sum+x : x }
end
def mean
sum=0
self.each {|v| sum += v}
sum/self.size.to_f
end
def variance
m = self.mean
sum = 0.0
self.each {|v| sum += (v-m)**2 }
sum/self.size
end
def stdev
Math.sqrt(self.variance)
end
def c... | 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 |
# Add date string parser class method to Date class.
#
class Date
# Parse date string with one of the following formats:
#
# * -n[units]: Date from self: examples: '1d', '2d', '1m', '2y'
#
# The string argument is first converted to a string with #to_s.
# Returns nil if passed nil or an empty string.
# Ra... | 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
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
unless defined?(Rails::Initializer)
if File.directory?("#{RAILS_ROOT}/vendor/rails")
require "#{RAILS_ROOT}/vendor/rails/railties/lib/init... | 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 Admin::HomeHelper
end
| Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def font_size_for_tag_cloud_new( weight, lowest_w, highest_w, steps=5, size_max=26)
return nil if weight.nil? or lowest_w.nil? or highest_w.nil?
# work out the font size
size_min =... | Ruby |
module WikiHelper
end
| Ruby |
module SourceHelper
end
| Ruby |
module IgHelper
end
| Ruby |
module OfcHelper
end
| Ruby |
module IntwordHelper
end
| Ruby |
module HomeHelper
end
| Ruby |
module FeaturedHelper
end
| Ruby |
module PageHelper
end
| Ruby |
module PagestoreHelper
end
| Ruby |
module LoginHelper
end
| Ruby |
class Page < ActiveRecord::Base
belongs_to :source
belongs_to :kind
belongs_to :language
has_many :word, :dependent => :destroy
validates_presence_of :url
def before_create
self.created_at = Time.now()
end
end
| Ruby |
class Intword < ActiveRecord::Base
belongs_to :language
has_many :words
attr_accessor :corr
validates_presence_of :name, :language_id
validates_uniqueness_of :name, :scope => :language_id
def self.find_popular(l_id, interval='1m', n=999999, order_column="imp", visible=1, like=nil)
first_date = Date.to... | Ruby |
class PageStore
attr_reader :counts, :words, :pages, :total
def initialize
@counts = {}
@words = {}
@total = 0
end
def add(intword,page_id,count)
@words[intword] ||= intword.id
page ||= Page.find(page_id)
@counts[page] ||= {}
@counts[page][intword.name] ||= 0
@count... | Ruby |
require "digest/sha1"
class User < ActiveRecord::Base
attr_accessor :password
attr_accessible :name, :password, :fullname, :email
def before_create
self.hashed_password = User.hash_password(self.password)
end
def after_create
@password = nil
end
def self.hash_password(password)
Diges... | Ruby |
class Kind < ActiveRecord::Base
end
| Ruby |
class Word < ActiveRecord::Base
belongs_to :intword
belongs_to :page
end
| Ruby |
class Source < ActiveRecord::Base
has_many :pages, :dependent => :destroy
has_many :words, :through => :pages
validates_presence_of :name
def before_create
self.created_at = Time.now()
end
end
| Ruby |
class HomeController < ApplicationController
layout "standard"
def index
@n_intwords = Intword.count(:conditions => "visible=1")
@n_languages = LOCALES.length
@n_sources = Source.count()
@attr = 'imp'
@action = 'show'
@intwords = Intword.find_popular(Locale.language.id, '7d', 50, @attr, 1)... | Ruby |
class IntwordController < ApplicationController
layout "standard"
# FIXME: add delete
before_filter :authorize, :only => [:edit, :notvisible_cloud, :csv]
def index
# cloud
@attr = 'imp'
@action = 'show'
@intwords = Intword.find_popular(Locale.language.id, '1m', 999999, @attr, 1)
end
... | Ruby |
class SourceController < ApplicationController
layout "standard"
before_filter :authorize, :only => [:edit, :new, :destroy, :csv]
def index
list
render :action => 'list'
end
def list
sources_with_pages_in_cur_locale = Page.find(:all,
:conditions... | Ruby |
class AdminController < ApplicationController
#layout "admin"
layout "standard"
before_filter :authorize
def index
end
def translate_new
#@view_translations = ViewTranslation.find(:all, :conditions => [ 'built_in = 1 AND language_id = ?', Locale.language.id ], :order => 'text')
# untranslated ... | Ruby |
class OfcController < ApplicationController
DEFAULT_OPTIONS = {
:kind => :default,
:graph_colors => [ '#fffc23' , '#616BDB' , '#65AB45' , '#BE4F3C' , '#824D7D' ],
:bg_color => '#000000',
:pie_bg_color => '#222222',
:inner_background => ["#000000", "#444444"],
:x_axis => '#ffffff',
:x_axis... | Ruby |
require 'hpricot'
require 'open-uri'
class WikiController < ApplicationController
layout "standard"
BASE_URL = "http://www.bayesfor.eu"
def view
url = ([] << params[:path]).flatten.join("/")
doc = Hpricot(open(BASE_URL + "/wiki/" + url))
# Some smart image resizing to comply with the limi... | Ruby |
class PageController < ApplicationController
layout "standard"
before_filter :authorize, :only => [:edit, :new, :destroy, :csv]
def index
list
render :action => 'list'
end
def list
@page_pages, @pages = paginate(:page,
:per_page => 20,
... | Ruby |
class LoginController < ApplicationController
#layout "admin"
layout "standard"
before_filter :authorize, :except => :login
def login
if request.get?
session[:user_id] = nil
@user = User.new
else
@user = User.new(params[:user])
logged_in_user = @user.try_to_login
if logg... | Ruby |
require 'pagestore'
class PagestoreController < ApplicationController
layout "standard" , :only => "disclaimer"
def show
intword_ids = params[:id].split("-")
@date = Date.strptime(params[:date])
@store = PageStore.new
#FIXME(battlehorse): warning! this performs N+1 queries
intword_... | 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 => '_website_se... | Ruby |
class IgController < ApplicationController
def elections
# def interesting words for usprimary2008
@candidate={"all" => "330-331-333-321-332",
"rep" => "333-335-340-341-331",
"dem" => "321-330-332-348-338",
"ita" => "98-115-118-3370" }
if ( params[:id] == nil )
... | Ruby |
class FeaturedController < ApplicationController
layout "standard"
def index
end
def usprimary2008
# def interesting words for usprimary2008
@candidate={"all" => "330-331-333-321-332",
"rep" => "333-335-340-341-331",
"dem" => "321-330-332-348-338" }
if ( params[:id] ==... | 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 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.