code
stringlengths
1
1.73M
language
stringclasses
1 value
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
source 'https://rubygems.org' gem 'rails', '3.2.2' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3...
Ruby
#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands'
Ruby
module PollsHelper end
Ruby
module ApplicationHelper end
Ruby
module VotesHelper end
Ruby
class Poll < ActiveRecord::Base has_many :votes end
Ruby
class Vote < ActiveRecord::Base belongs_to :poll end
Ruby
class ApplicationController < ActionController::Base protect_from_forgery end
Ruby
class VotesController < ApplicationController # GET /votes # GET /votes.json def index @votes = Vote.all respond_to do |format| format.html # index.html.erb format.json { render json: @votes } end end # GET /votes/1 # GET /votes/1.json def show @vote = Vote.find(params[:id]) ...
Ruby
class PollsController < ApplicationController # GET /polls # GET /polls.json def index @polls = Poll.all respond_to do |format| format.html # index.html.erb format.json { render json: @polls } end end # GET /polls/1 # GET /polls/1.json def show @poll = Poll.find(params[:id]) ...
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: 'Emanuel...
Ruby
class CreatePhotos < ActiveRecord::Migration def change create_table :photos do |t| t.text :tags t.string :name t.integer :photoalbum_id t.integer :user_id t.timestamps end end end
Ruby
class AddPaperclipToPhotos < ActiveRecord::Migration def change add_column :photos, :image_file_name, :string add_column :photos, :image_content_type, :string add_column :photos, :image_file_size, :integer end end
Ruby
class DeviseCreateUsers < ActiveRecord::Migration def change create_table(:users) do |t| ## Database authenticatable t.string :email, :null => false, :default => "" t.string :encrypted_password, :null => false, :default => "" ## Recoverable t.string :reset_password_to...
Ruby
class CreatePhotoalbums < ActiveRecord::Migration def change create_table :photoalbums do |t| t.string :name t.integer :user_id t.timestamps end end end
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
source 'https://rubygems.org' gem 'rails', '3.2.2' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' gem 'sqlite3' # Gems used only for assets and not required # in production environments by default. group :assets do gem 'sass-rails', '~> 3.2.3' gem 'coffee-rails', '~> 3...
Ruby
#!/usr/bin/env ruby # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. APP_PATH = File.expand_path('../../config/application', __FILE__) require File.expand_path('../../config/boot', __FILE__) require 'rails/commands'
Ruby
module PhotoalbumsHelper def last_image_thumb(photo) if photo image_tag photo.image :thumb else "NO IMAGE" end end end
Ruby
module WelcomeHelper end
Ruby
module ApplicationHelper end
Ruby
module PhotosHelper end
Ruby
class Photo < ActiveRecord::Base belongs_to :photoalbum has_attached_file :image, :styles => { :thumb=> "100x100#", :small => "300x300>", :large => "600x600>" } end
Ruby
class User < ActiveRecord::Base # Include default devise modules. Others available are: # :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # Setup accessi...
Ruby
class Photoalbum < ActiveRecord::Base has_many :photos accepts_nested_attributes_for :photos end
Ruby
class ApplicationController < ActionController::Base protect_from_forgery before_filter :authenticate_user! end
Ruby
class PhotosController < ApplicationController # GET /photos # GET /photos.json def index @photos = Photo.all respond_to do |format| format.html # index.html.erb format.json { render json: @photos } end end # GET /photos/1 # GET /photos/1.json def show @photo = Photo.find(par...
Ruby
class PhotoalbumsController < ApplicationController # GET /photoalbums # GET /photoalbums.json def index @photoalbums = Photoalbum.all respond_to do |format| format.html # index.html.erb format.json { render json: @photoalbums } end end # GET /photoalbums/1 # GET /photoalbums/1.jso...
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. # # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters ...
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. Album::Application.config.session_store :cookie_store, key: '_album_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 "rails gener...
Ruby
# Use this hook to configure devise mailer, warden hooks and so forth. # Many of these configuration options can be set straight in your model. Devise.setup do |config| # ==> Mailer Configuration # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use yo...
Ruby
Album::Application.routes.draw do resources :photos resources :photoalbums devise_for :users # 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 assign values other than :con...
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 defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.requi...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Album::Application.initialize!
Ruby
Album::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_c...
Ruby
Album::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 web serv...
Ruby
Album::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 suit...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Album::Application
Ruby
#!/usr/bin/env rake # 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__) Album::Application.load_tasks
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. # # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters ...
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. Yana::Application.config.session_store :cookie_store, key: '_yana_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 "rails generat...
Ruby
Yana::Application.routes.draw do resources :votes resources :polls # 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 assign values other than :controller and :action # Samp...
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 defined?(Bundler) # If you precompile assets before deploying to production, use this line Bundler.require(*Rails.groups(:assets => %w(development test))) # If you want your assets lazily compiled in production, use this line # Bundler.requi...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Yana::Application.initialize!
Ruby
Yana::Application.configure do # Settings specified here will take precedence over those in config/application.rb # Code is not reloaded between requests config.cache_classes = true # Full error reports are disabled and caching is turned on config.consider_all_requests_local = false config.action_co...
Ruby
Yana::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 web serve...
Ruby
Yana::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 suite...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Yana::Application
Ruby
#!/usr/bin/env rake # 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__) Yana::Application.load_tasks
Ruby
require 'yaml_help'
Ruby
require 'rake' require 'rake/testtask' require 'rake/rdoctask' desc 'Default: run unit tests.' task :default => :test desc 'Test the yaml_help plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Generate documentation for the yaml_help plugin.' R...
Ruby
# desc "Explaining what the task does" # task :yaml_help do # # Task goes here # end
Ruby
puts open("#{File.dirname(__FILE__)}/README").read
Ruby
require 'erb' require 'yaml' class YamlHelp # default help files dir is app_root/help DEFAULT_HELP_FILES_DIR = defined?(RAILS_ROOT) ? "#{RAILS_ROOT}/help" : "../../../help" # w/o the controller_name all help files are loaded def initialize(controller_name = nil, help_files_dir = nil) @yaml_hash = {...
Ruby
# $ext_path: This should be the path of where the ExtJS SDK is installed # Generally this will be in a lib/extjs folder in your applications root # <root>/lib/extjs $ext_path = "../../" # sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder # Generally this will be in a resource...
Ruby
# include the utils rb file which has extra functionality for the ext theme dir = File.dirname(__FILE__) require File.join(dir, 'lib', 'utils.rb') # register ext4 as a compass framework Compass::Frameworks.register 'ext4', dir
Ruby
# $ext_path: This should be the path of the Ext JS SDK relative to this file $ext_path = "../../extjs" # sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder # Generally this will be in a resources/sass folder # <root>/resources/sass sass_path = File.dirname(__FILE__) # css_pat...
Ruby
# Compass configurations sass_path = File.dirname(__FILE__) css_path = File.join(sass_path, "..", "css") # Require any additional compass plugins here. images_dir = File.join(sass_path, "..", "img") output_style = :expanded environment = :production
Ruby
module ExtJS4 module SassExtensions module Functions module Utils def parsebox(list, n) assert_type n, :Number if !n.int? raise ArgumentError.new("List index #{n} must be an integer") elsif n.to_i < 1 raise ArgumentError.new("List index #{n} must...
Ruby
# Install hook code here
Ruby
require 'yaml_form_builder' ActionView::Base.send :include, YamlFormBuilder
Ruby
# desc "Explaining what the task does" # task :yaml_form_builder do # # Task goes here # end
Ruby
# Uninstall hook code here
Ruby
require 'rake' require 'rake/testtask' require 'rake/rdoctask' desc 'Default: run unit tests.' task :default => :test desc 'Test the yaml_form_builder plugin.' Rake::TestTask.new(:test) do |t| t.libs << 'lib' t.pattern = 'test/**/*_test.rb' t.verbose = true end desc 'Generate documentation for the yaml_form_bu...
Ruby
module YamlFormBuilder class YamlForm < ActionView::Helpers::FormBuilder def render_form(name) yaml_init('formconfig.yml') s = "<table> \n" @config[name].each do |w| s+="<tr><td>"+w['label'].to_s+"</td><td>" input = w['input'] case w['type'] ...
Ruby
#!/usr/bin/env ruby # Copyright 2007, Lloyd Hilaiel. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and t...
Ruby
#!/usr/bin/env ruby # Copyright 2007, Lloyd Hilaiel. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and t...
Ruby
#!/usr/bin/env ruby # Copyright 2007, Lloyd Hilaiel. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and t...
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
# Compass configurations sass_path = File.dirname(__FILE__) css_path = File.join(sass_path, "..", "css") # Require any additional compass plugins here. images_dir = File.join(sass_path, "..", "img") output_style = :expanded environment = :production
Ruby
# $ext_path: This should be the path of the Ext JS SDK relative to this file $ext_path = "../../extjs" # sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder # Generally this will be in a resources/sass folder # <root>/resources/sass sass_path = File.dirname(__FILE__) # css_pat...
Ruby
# include the utils rb file which has extra functionality for the ext theme dir = File.dirname(__FILE__) require File.join(dir, 'lib', 'utils.rb') # register ext4 as a compass framework Compass::Frameworks.register 'ext4', dir
Ruby
module ExtJS4 module SassExtensions module Functions module Utils def parsebox(list, n) assert_type n, :Number if !n.int? raise ArgumentError.new("List index #{n} must be an integer") elsif n.to_i < 1 raise ArgumentError.new("List index #{n} must...
Ruby
# $ext_path: This should be the path of where the ExtJS SDK is installed # Generally this will be in a lib/extjs folder in your applications root # <root>/lib/extjs $ext_path = "../../" # sass_path: the directory your Sass files are in. THIS file should also be in the Sass folder # Generally this will be in a resource...
Ruby
require "yaml" require "benchmark" require "rubygems" module Interpleter if RUBY_PLATFORM == "java" require "java" include_class "org.jruby.runtime.Constants" Info = { "name" => "jruby", "version" => Constants::VERSION, "banner" => `jruby -v`.chomp, "runtime" => { ...
Ruby
require "yaml" def run(filename) i = 0 open(filename) do |f| YAML.load_documents(f) { i += 1 } end i end __END__ name: ruby/syck library: name: syck version: (bundle) language: [C] native_library: name: syck version: 0.60
Ruby
require "rubygems" require "rbyaml" def run(filename) i = 0 open(filename) do |f| RbYAML.load_documents(f){ i += 1 } end i end __END__ name: ruby/rbyaml library: gem: RbYAML language: [ruby]
Ruby
require "yaml" class BenchmarkResult include Enumerable def initialize(all) @all = YAML.load_file(all).map{|name, y| Item.new(name, y) }.sort_by {|e| e.key } end def each(&block) @all.each(&block) end def result(target) self.map{|e| [e.interpreter, e.library, e.wallclock(targ...
Ruby
require "rubygems" require "rake" def tasks Rake.application.instance_eval { @tasks } end def current_scope Rake.application.instance_eval { @scope.last } end def task_defined?(task, ns = current_scope) tasks.key?([ns, task].compact.join(":")) end def rakecall(task) Rake::Task[task].invoke ...
Ruby
class Hash def recursive_update(other) recursive_updater = lambda{|k,a,b| case a when Hash a.update(b, &recursive_updater) a when Array b.each {|e| a << e} a else b end } self.update(other, &recursive_updater) end en...
Ruby
require "yaml" y = [] YAML.load_documents(open(ARGV[0])){|yy| y << yy} puts YAML.dump(y)
Ruby
def find_xyzzy if ENV["XYZZY"] ENV["XYZZY"] elsif ENV["XYZZYHOME"] File.join(ENV["XYZZYHOME"], "xyzzy.exe") else "xyzzy.exe" end end
Ruby
require "yaml" def run(filename) i = 0 open(filename) do |f| YAML.load_documents(f) { i += 1 } end i end __END__ name: jruby/jvyamlb library: name: JvYAMLb version: (bundle) language: [Java]
Ruby
# file: yamltunes.rb # author: davidfmiller http://www.fivevoltlogic.com/code/mytunes/yaml # version: v0.1 # about: a script that reads data from the command-line and translates it into itunes playlists # examples: ruby yamltuneimporter.rb playlist.yamltunes # cat playlist.yamltunes | ruby yamltunei...
Ruby
#!/usr/bin/ruby # file: yamltunesmail.rb # author: davidfmiller http://www.fivevoltlogic.com/code/mytunes/ # version: v0.1.2 # about: a script that reads in email messages stored on disk saved via # Apple's Mail.app and parses the message content to add any # attached files to iTunes and ...
Ruby