code
stringlengths
1
1.73M
language
stringclasses
1 value
ActionController::Routing::Routes.draw do |map| map.resources :posts map.root :controller => "posts" # Install the default routes as the lowest priority. map.connect ':controller/:action/:id', :controller => 'posts' #map.connect ':controller/:action/:id.:format' end
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 # 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 = '2.0...
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
# 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
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 != :false end # Accesses the current user from the session. def current_user @current_user ||= ...
Ruby
module AuthenticatedTestHelper # Sets the current user in the session from the user fixtures. def login_as(user) @request.session[:user] = user ? users(user).id : nil end def content_type(type) @request.env['Content-Type'] = type end def accept(accept) @request.env["HTTP_ACCEPT"] = accept en...
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): # Inflector.inflections do |inflect| # inflect.plural /^(ox)$/i, '\1en' # inflect.singular /^(ox)en/i, '\1' # inflect.irregular 'person', 'people' # i...
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
# 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 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 = '2.0...
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 THUMBNAIL_DEFAULT = "no_picture.gif" def show_flash content_tag 'div', flash[:notice], :id=>'notice' if flash[:notice] content_tag 'div', flash[:error], :id=> 'error' if flash[:error] end ...
Ruby
module VideosHelper end
Ruby
module CommentsHelper end
Ruby
class Video < ActiveRecord::Base has_many :comments validates_presence_of :title, :description, :file_url end
Ruby
class Comment < ActiveRecord::Base belongs_to :video validates_presence_of :body, :name end
Ruby
class HomeController < ApplicationController end
Ruby
class CommentsController < ApplicationController # layout 'thickbox.html.erb' # GET /comments def index @comments = Comment.find(:all) render :action => :index, :layout => 'application.html.erb' end # GET /comments/1 def show @comment = Comment.find(params[:id]) end # GET /comments/new de...
Ruby
class VideosController < ApplicationController # GET /videos # GET /videos.xml def index @videos = Video.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @videos } end end # GET /videos/1 # GET /videos/1.xml def show @video = Video.f...
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 # See ActionController::RequestForgeryProtection for details...
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/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/request'
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/performance/request'
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 $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib")) require 'spec' exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
Ruby
#!/usr/bin/env ruby $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn $LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin require 'rubygems' require 'drb/drb' require 'rbconfig' require 'spec' require 'optparse' # This is based on Florian We...
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 $LOAD_PATH.unshift File.dirname(__FILE__) + '/../../rspec/lib' # For svn $LOAD_PATH.unshift File.dirname(__FILE__) + '/../vendor/plugins/rspec/lib' # For rspec installed as plugin require 'rubygems' require 'drb/drb' require 'rbconfig' require 'spec' require 'optparse' # This is based on Florian We...
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/inspector'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/reaper'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../../config/boot' require 'commands/process/spawner'
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' require 'commands/about'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/plugin'
Ruby
#!/usr/bin/env ruby $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../vendor/plugins/rspec/lib")) require 'spec' exit ::Spec::Runner::CommandLine.run(::Spec::Runner::OptionParser.parse(ARGV, STDERR, STDOUT))
Ruby
class AddVideoDimensions < ActiveRecord::Migration def self.up add_column :videos, :width, :integer add_column :videos, :height, :integer end def self.down remove_column :videos, :width remove_column :videos, :height end end
Ruby
class CreateVideos < ActiveRecord::Migration def self.up create_table :videos do |t| t.string "title" t.text "description" t.string "file_url" t.string "thumbnail_url" t.timestamps end end def self.down drop_table :videos end end
Ruby
class CreateComments < ActiveRecord::Migration def self.up create_table :comments do |t| t.text "body" t.string "name" t.integer "video_id" t.timestamps end end def self.down drop_table :comments end end
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'spec/rails/story_adapter'
Ruby
dir = File.dirname(__FILE__) Dir[File.expand_path("#{dir}/**/*.rb")].uniq.each do |file| require file end
Ruby
# This file is copied to ~/spec when you run 'ruby script/generate rspec' # from the project root directory. ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'spec' require 'spec/rails' Spec::Runner.configure do |config| # If you're not using ActiveRecord ...
Ruby
namespace :svn do desc "Adds all files with an svn status flag of '?'" task(:add) { system %q(svn status | awk '/\\?/ {print $2}' | xargs svn add) } desc "Deletes all files with an svn status flag of '!'" task(:delete) { system %q(svn status | awk '/\\!/ {print $2}' | xargs svn delete) } desc "Writes...
Ruby
namespace :js_spec do desc("Executes js spec in browser") task :run_spec do puts "Please specify a file using SPEC=name without _spec.html" unless ENV['SPEC'] system "open jsspec/specs/#{ENV['SPEC']}_spec.html" end desc("Executes entire folder of js specs in browser") task :run_all_specs do sp...
Ruby
desc "Adds valid videos without comments to the development database." task (:videos_push => :environment) do Video.delete_all() video = Video.new() video.title = "William Hung" video.description = "She Bangs featuring William Hung." video.file_url = "/flv/william_hung.flv" begin video.save! rescue...
Ruby
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispat...
Ruby
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispat...
Ruby
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the Fast...
Ruby
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispat...
Ruby
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby require File.dirname(__FILE__) + "/../config/environment" unless defined?(RAILS_ROOT) # If you're using RubyGems and mod_ruby, this require should be changed to an absolute path one, like: # "/usr/local/lib/ruby/gems/1.8/gems/rails-0.8.0/lib/dispat...
Ruby
#!/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby # # You may specify the path to the FastCGI crash log (a log of unhandled # exceptions which forced the FastCGI instance to exit, great for debugging) # and the number of requests to process before running garbage collection. # # By default, the Fast...
Ruby
ENV["RAILS_ENV"] = "test" require File.expand_path(File.dirname(__FILE__) + "/../config/environment") require 'test_help' class Test::Unit::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 datab...
Ruby
# Require any additional compass plugins here. # Set this to the root of your project when deployed: http_path = "/" css_dir = "theme/css" sass_dir = "theme/scss" images_dir = "images" javascripts_dir = "js" # You can select your preferred output style here (can be overridden via the command line): output_style = :co...
Ruby
load File.dirname(__FILE__) + '/Rakefile' gem_spec
Ruby
module XbrlTest class SchemaValidator def self.validate (xml_file, xsd_file) return end end end
Ruby
require 'test/unit' require 'xbrlware' require 'edgar' require 'tmpdir' begin require 'java' require File.dirname(__FILE__) + '/schema_validator_jruby' rescue Exception ENV["SCHEMA_VALIDATION"]="False" require File.dirname(__FILE__) + '/schema_validator_ruby' end $LOG.level = Logger::INFO
Ruby
def first(name, &block) block = lambda{ puts "lambda"} if block.nil? second &block end def second(&block) yield end first("blk") { puts "Hello"} first("blk") def dummy(count, snipet=StringIO.new, &block) return snipet.string if count > 5 yield snipet count += 1 dummy(count, snipet, &block) end dummy(...
Ruby
java_import javax.xml.XMLConstants java_import javax.xml.parsers.DocumentBuilder java_import javax.xml.parsers.DocumentBuilderFactory java_import javax.xml.transform.Source java_import javax.xml.transform.dom.DOMSource java_import javax.xml.transform.stream.StreamSource java_import javax.xml.validation.Schema java_impo...
Ruby
module LinkbaseTestUtil def print_arc(arcs, indent=0) arcs.each do |arc| if arc.items.nil? || arc.items.size==0 puts " " * indent * 2 + arc.item_id + "[" + (arc.label if arc.respond_to?(:label)).to_s+"][role "+arc.role.to_s+"][order "+arc.order.to_s+"] = None .. ctx undefined.." else ...
Ruby
#!/usr/bin/ruby # # Author:: xbrlware@bitstat.com # # Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved. # # License:: 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...
Ruby
require 'rubygems' # you need this when xbrlware is installed as gem require 'xbrlware' instance_file="c-20091230.xml" instance = Xbrlware.ins(instance_file) # Create parser instance item_name="NetIncomeLoss" # This is the item we are interested in. net_incomes = instance.item(item_name) # Extracts "NetIncomeLoss" i...
Ruby
require 'edgar' require 'xbrlware' d=Edgar::HTMLFeedDownloader.new url="http://www.sec.gov/Archives/edgar/data/1281761/000119312510036446/0001193125-10-036446-index.htm" download_dir=url.split("/")[-2] # download dir is : 000119312510036446 d.download(url, download_dir) ins=Xbrlware.ins(Xbrlware.file_grep(download_di...
Ruby
require 'rubygems' # you need this when xbrlware is installed as gem require 'edgar' require 'xbrlware' dl=Edgar::HTMLFeedDownloader.new() url="http://www.sec.gov/Archives/edgar/data/843006/000135448809002030/0001354488-09-002030-index.htm" download_dir=url.split("/")[-2] # download dir is : 000135448809002030 dl.dow...
Ruby
require 'rubygems' # you need this when xbrlware is installed as gem require 'xbrlware' instance=Xbrlware.ins("foo.xml") items=instance.item("ProfitLoss") puts "Profit-Loss \t Context" items.each do |item| puts item.value+" \t "+item.context.id end
Ruby
require 'rubygems' # you need this when xbrlware is installed as gem require 'edgar' require 'xbrlware' dl=Edgar::HTMLFeedDownloader.new() url="http://www.sec.gov/Archives/edgar/data/843006/000135448809002030/0001354488-09-002030-index.htm" download_dir=url.split("/")[-2] # download dir is : 000135448809002030 dl.dow...
Ruby
require 'xbrlware' ## Assuming you have table "calculations" with below structure # id # element_name # element_value # element_label # period_start_date # period_end_date # parent_id def format_timeline(timeline) ## date format function return Xbrlware::DateUtil.stringify_date(timeline.value) unless timeline.is_du...
Ruby
require 'xbrlware' def format_timeline(timeline) ## date format function return Xbrlware::DateUtil.stringify_date(timeline.value) unless timeline.is_duration? header = StringIO.new header << Xbrlware::DateUtil.stringify_date(timeline.value["end_date"]) << " : " header << Xbrlware::DateUtil.months_between(timel...
Ruby
require 'xbrlware' r=Xbrlware::Report.new class << r public :xbrl_files end files=r.xbrl_files("../../../xbrlware-wiki/sample_reports/edgar_data") output = StringIO.new output << "|| *Instance + Taxonomy file size (KB)* || *Time (Seconds)* ||" output << "\n" files.each do |file_map| m=Benchmark.measure do in...
Ruby
$:.push('gen-rb') require 'thrift' require 'thrift/transport/server_socket' require 'thrift/transport/buffered_transport' require 'thrift/server/simple_server' require 'rating' require 'rating-impl' # Thrift provides mutiple communication endpoints # - Here we will expose our service via a TCP socket # - Web-serv...
Ruby
# provide an implementation of Rating service class RatingImpl def piotroski(entity_name) # Code that use xbrlware goes here return 1 # return some dummy value end def altman_z(entity_name) # Code that use xbrlware goes here return 2.2567 # return some dummy value end end
Ruby
#!/usr/bin/ruby # # Author:: xbrlware@bitstat.com # # Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved. # # License:: 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...
Ruby
# # setup.rb # # Copyright (c) 2000-2005 Minero Aoki # # This program is free software. # You can distribute/modify this program under the terms of # the GNU LGPL, Lesser General Public License version 2.1. # unless Enumerable.method_defined?(:map) # Ruby 1.4.6 module Enumerable alias map collect end end un...
Ruby
#!/usr/bin/ruby # # Author:: xbrlware@bitstat.com # # Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved. # # License:: 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...
Ruby
#!/usr/bin/ruby # # Author:: xbrlware@bitstat.com # # Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved. # # License:: 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...
Ruby
#!/usr/bin/ruby # # Author:: xbrlware@bitstat.com # # Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved. # # License:: 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...
Ruby
#!/usr/bin/ruby # # Author:: xbrlware@bitstat.com # # Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved. # # License:: 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...
Ruby
#!/usr/bin/ruby # # Author:: xbrlware@bitstat.com # # Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved. # # License:: 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...
Ruby
#!/usr/bin/ruby # # Author:: xbrlware@bitstat.com # # Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved. # # License:: 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...
Ruby
#!/usr/bin/ruby # # Author:: xbrlware@bitstat.com # # Copyright:: 2009, 2010 bitstat (http://www.bitstat.com). All Rights Reserved. # # License:: 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...
Ruby