code
stringlengths
1
1.73M
language
stringclasses
1 value
source 'http://rubygems.org' gem 'rails', '3.0.5' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' gem 'oauth' gem 'json' gem 'fastercsv' # Use unicorn as the web server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger (ruby-debug fo...
Ruby
module ContactHelper end
Ruby
module ApplicationHelper end
Ruby
class DataFile < ActiveRecord::Base def self.save(upload) name = upload['datafile'].original_filename directory = "public/data" # create the file path path = File.join(directory, name) # write the file File.open(path, "wb") { |f| f.write(upload['datafile'].read) } path end end
Ruby
class ApplicationController < ActionController::Base protect_from_forgery end
Ruby
require 'oauth/consumer' require 'yaml' require 'json' require 'fastercsv' class ContactController < ApplicationController CONSUMER_KEY = "m9vE-mbQW4LaFhLGOfm_tB--r4gwiUCOQbtFxSYEKFr7NE5VVdC0LqVfPYq-RjFU" CONSUMER_SECRET = "5yMG_DkglLGvJM5zkE2rg8XSN9KZXmk7PHG9OJC79TI2di7AEhgqq_8bpn3lQ8JX" def index end def...
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. # 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 to debug a probl...
Ruby
# Be sure to restart your server when you modify this file. # Your secret key for verifying the integrity of signed cookies. # If you change this key, all old signed cookies 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 attac...
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. Raidtacs::Application.config.session_store :cookie_store, :key => '_raidtacs_session' # Use the database for sessions instead of the cookie-based default, # which shouldn't be used to store highly confidential information # (create the session table with "ra...
Ruby
Raidtacs::Application.routes.draw do get "contact/index" get "contact/linkedin" get "contact/csv" post "contact/output" # The priority is based upon order of creation: # first created -> highest priority. # Sample of regular route: # match 'products/:id' => 'catalog#view' # Keep in mind you can as...
Ruby
require 'rubygems' # Set up gems listed in the Gemfile. ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
Ruby
require File.expand_path('../boot', __FILE__) require 'rails/all' # If you have a Gemfile, require the gems listed there, including any gems # you've limited to :test, :development, or :production. Bundler.require(:default, Rails.env) if defined?(Bundler) module Raidtacs class Application < Rails::Application ...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Raidtacs::Application.initialize!
Ruby
Raidtacs::Application.configure do # Settings specified here will take precedence over those in config/application.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 o...
Ruby
Raidtacs::Application.configure do # Settings specified here will take precedence over those in config/application.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 webs...
Ruby
Raidtacs::Application.configure do # Settings specified here will take precedence over those in config/application.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...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Raidtacs::Application
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.expand_path('../config/application', __FILE__) require 'rake' Raidtacs::Application.load_tasks
Ruby
require 'rubygems' require 'oauth' require 'yaml' require 'json' # Convert this to a YAML file for your rails app, and load your configuration in an # environment-specific way, eg YAML.load_file('config/oauth.yml')[Rails.env] config = YAML.load(<<EOS linkedin-example: api_host: https://api.linkedin.com ...
Ruby
## # Create individual pages for each icon in the FontAwesome set require 'yaml' require 'debugger' module Jekyll class IconPage < Page ## # Take a single icon and render a page for it. def initialize(site, base, dir, icon) @site = site @base = base @dir = dir @name = "#{icon....
Ruby
## # Provide an icons attribute on the site object require 'yaml' require 'forwardable' module Jekyll class Icon attr_reader :name, :id, :unicode, :created, :categories def initialize(icon_object) @icon_object = icon_object # Class name used in CSS and HTML @icon_object['class'] = icon...
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module ContactshuffleHelper end
Ruby
# Copyright (C) 2009 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
# add some documentation to this code you slacker # scott lee davis skawtus@gmail.com # require 'gdata' class ContactshuffleController < ApplicationController # before_filter :setup_client CONTACTS_FEED = CONTACTS_SCOPE + 'contacts/default/full/' APPS_DOMAIN = 'contactshuffle.com' CONTACTS_MAX = '1...
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
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
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
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
require 'sinatra/activerecord/rake' require './main'
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 =~ /(:?mswin|mingw)/ require 'pathname' root_path = Pathname.new(root_path).cleanpath(true).to_s end ...
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 include CalendarHelper def logged_in? current_user != :false end def current_user @current_user ||= (session[:user] && User.find_by_id(session[:user])) || :false end def is_admin? re...
Ruby
require 'date' # CalendarHelper allows you to draw a databound calendar with fine-grained CSS formatting module CalendarHelper VERSION = '0.2.2' # Returns an HTML calendar. In its simplest form, this method generates a plain # calendar (which can then be customized using CSS) for a given month and year. # Ho...
Ruby
module EventHelper end
Ruby
module CourseHelper end
Ruby
module AccountHelper end
Ruby
class UserNotifier < ActionMailer::Base def signup_notification(user) setup_email(user) @subject += ' Activa tu cuenta.' body( :user => user, :url => url_for(:host => StringSetting.find_by_name("site-host").value, :controller => :account, :action => :activate, :id => user.activation_code)) end...
Ruby
class AssignmentAnswer < ActiveRecord::Base belongs_to :assignment belongs_to :grader, :class_name => "User", :foreign_key => "grader_id" belongs_to :user has_one :answer_blob, :dependent => :destroy validates_presence_of :due_date validates_presence_of :duration end
Ruby
class Event < ActiveRecord::Base belongs_to :course belongs_to :user has_one :event_blob, :dependent => :destroy validates_presence_of :course validates_presence_of :name validates_presence_of :due_date end
Ruby
class EventBlob < ActiveRecord::Base belongs_to :event belongs_to :assignment, :class_name => 'Assignment', :foreign_key => 'event_id' validates_presence_of :data validates_presence_of :kind end
Ruby
class Assignment < Event belongs_to :user belongs_to :course has_many :assignment_answers, :dependent => :destroy has_one :event_blob, :foreign_key => 'event_id', :dependent => :destroy validates_presence_of :course def average return @average if not @average.nil? sum = 0 count = 0 assignm...
Ruby
class SystemSetting < ActiveRecord::Base end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base has_one :profile, :dependent => :destroy has_many :created_courses, :class_name => "Course" has_and_belongs_to_many :courses # Usar polimorfismo sigue siendo una chinga en Rails 1.2 (espero que en Rails # 2.0 esto mejore). Es más fácil si separamos eventos...
Ruby
class StringSetting < SystemSetting end
Ruby
class Profile < ActiveRecord::Base belongs_to :user validates_format_of :telephone, :with => /\d+(-|\d)*/, :message => 'sólo puede tener dígitos y guiones', :if => Proc.new {|profile| profile.telephone != nil && profile.telephone != '' && profile.telephone.length > 0 } validates_presence_of :real_name, ...
Ruby
class AnswerBlob < ActiveRecord::Base belongs_to :assignment_answer end
Ruby
class Course < ActiveRecord::Base belongs_to :creator, :class_name => "User", :foreign_key => "user_id" has_and_belongs_to_many :users has_many :events, :conditions => "type IS NULL OR type = ''", :dependent => :destroy, :order => "due_date DESC" has_many :assignments, :dependent => :destroy validates_presen...
Ruby
class IntegerSetting < SystemSetting def value read_attribute(:value).to_i end def value=(val) write_attribute(:value, val.to_s) end end
Ruby
class CourseController < ApplicationController before_filter :login_required, :only => [ :show, :enroll, :add_event, :list_own ] before_filter :admin_required, :only => [ :create, :new, :destroy ] before_filter :instructor_required, :only => [ :edit, :update ] # Mismo que list def index list render :...
Ruby
class EventController < ApplicationController before_filter :login_required before_filter :instructor_required, :only => [:add_assignment] def list_own @to_list = self.current_user.events end # Recibe un ID, y muestra el Evento con id ID a detalle: # NOMBRE del evento # Curso relacionado (nombre...
Ruby
class SettingController < ApplicationController #Solo puede ser accesados por el administrador before_filter :admin_required, :only => [ :index, :list, :def_changes ] #Muestra todos los parametros configurables por el administrador def index list render :action=>'list' end def list @title = "O...
Ruby
class AccountController < ApplicationController # If you want "remember me" functionality, add this before_filter to Application Controller #before_filter :login_from_cookie # Los siguientes requieren un usuario logeado (cualquiera) before_filter :login_required, :only => [:index, :list, :edit, :view, :logout]...
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 => '_contenid-o...
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
#!/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
class CreateGlobalCourse < ActiveRecord::Migration def self.up u = User.new(:login => 'global_events', :password => 'globBal_eVent_', :password_confirmation => 'globBal_eVent_', :email => 'changeme@example.com', :kind => 'Instructor') u.save! p = Profile.new(:real_name => 'Este usuario puede editar los ev...
Ruby
class AddUserActivation < ActiveRecord::Migration def self.up add_column :users, :activation_code, :string end def self.down remove_column :users, :activation_code end end
Ruby
class OopsForgotToAddEndDateToCourse < ActiveRecord::Migration def self.up add_column :courses, :end_date, :datetime end def self.down remove_column :courses, :end_date end end
Ruby
class GenerateConfigurations < ActiveRecord::Migration def self.up create_table :system_settings do |t| t.column :name, :string, :null => false t.column :description, :text t.column :value, :text, :null => false t.column :type, :string end StringSetting.create( :name => "admin-mai...
Ruby
class AddUsersStylesheetColumn < ActiveRecord::Migration def self.up add_column :users, :stylesheet, :string User.find(:all).each { |u| u.stylesheet = 'principalEs.css' u.save! } end def self.down remove_column :users, :stylesheet end end
Ruby
class EventDurationToExpireDate < ActiveRecord::Migration def self.up add_column :events, :expire_date, :datetime, :null => false Event.find(:all).each { |event| event.expire_date = event.due_date + event.duration.tv_secs } remove_column :events, :duration end def self.down add_column :events, :d...
Ruby
#Motivación: El pinche ActiveRecord hace un "select * from blahblah" cada vez #que le pides datos sobre algun evento / respuesta a una tarea. Esto significa #que lee todo el blob, así sea de 16Megas incluso si no lo vas a usar. Hay dos #soluciones que se me ocurren: # *usar :select => ... en las opciones de find - se p...
Ruby
#Esta migración crea el usuario 'root' con un password default ('rootroot') class CreateUsers < ActiveRecord::Migration def self.up root = User.create( :login => 'root', :password => 'rootroot', :email => 'root@localhost.localdomain', :password_confirmation =>...
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 ||= (ses...
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
#!/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/dispatcher" -- otherwise performance is severely impaired re...
Ruby
#!/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/dispatcher" -- otherwise performance is severely impaired re...
Ruby