code stringlengths 1 1.73M | language stringclasses 1
value |
|---|---|
# 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 |
# 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 |
require 'test/unit'
require_relative 'Factory'
class TCSingleton < Test::Unit::TestCase
def testSingetonNew
assert_raises (NoMethodError) do
ProductFactory.new
end
end
def testSingletonReferences
list = []
base_ref = ProductFactory.instance
list.push base_ref
list.push Mo... | Ruby |
#
# ABSTRACT FACTORY EXERCISE
#
# January, 2013
require 'singleton'
class Client
attr_accessor :factory
def initialize (factory)
@factory = factory.instance.register
end
def factory=(factory)
@factory = factory.instance.register
end
def foo
@prod_A = @factory.createProductA
@prod_A.perform
... | Ruby |
# Mel Ó Cinnéide, Jan 2013
# with thanks to Freeman&co. for the example
require "forwardable"
class Decaf
def description
"decaffinated coffee"
end
def cost
2.0
end
end
class Expresso
def description
"expresso coffee"
end
def cost
1.5
end
end
class CoffeeDecorator
extend F... | Ruby |
# Mel Ó Cinnéide, Jan 2013
# with thanks to Vince Huston for the example
class State_tran
attr_accessor :age
def initialize age
@age = age
@pool = {}
end
def set_age age
@age = age
end
def decide
if @age < 13
if !@pool.has_key?'Child'
@pool['Child'] = Child.new
end
... | Ruby |
require 'test/unit'
require_relative 'State_Exercise'
class TCState < Test::Unit::TestCase
def setup
@p = Person.new
assert @p
end
def testState
p = @p
assert_equal p.age, 0
assert_instance_of Child, p.state
for i in 1..80
p.incr_age();
assert_equal p.age, i
apply = p.apply_for_buspas... | 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 |
#!/usr/bin/env ruby
require "rubygems"
require "json"
require "yaml"
yamlfiles = Dir.glob("#{ File.dirname(__FILE__) }/*.yaml")
yamlfiles.each{ |file|
puts(file)
yaml = YAML.load_file(file)
json = JSON.pretty_generate(YAML.load_file(file))
File.open(file.gsub("\.yaml", "\.json"), 'w'){ |out| puts "writing #... | Ruby |
#!/usr/bin/env ruby
require "rubygems"
require "json"
require "yaml"
yamlfiles = Dir.glob("#{ File.dirname(__FILE__) }/*.yaml")
yamlfiles.each{ |file|
puts(file)
yaml = YAML.load_file(file)
json = JSON.pretty_generate(YAML.load_file(file))
File.open(file.gsub("\.yaml", "\.json"), 'w'){ |out| puts "writing #... | 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 |
# 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.
ActiveRecord::Base.include_root_in_json = true
# Store the full clas... | 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 |
# =============================================================================
# Receita de Capistrano 2.x para hospedagem compartilhada Linux
# utilizando estratégia de cópia sem servidor de versionamento
# =============================================================================
#
# 1. Esta receita é execu... | 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
# Enable threaded mode
# config.threadsafe!
# Use a different logger for distributed setups
# config.... | 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.3... | 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|
map.root :controller => "catalog"
map.resources :comments
map.resources :bosses
map.resources :rentals
map.resources :users
map.resources :books
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular r... | Ruby |
load 'deploy' if respond_to?(:namespace) # cap2 differentiator
Dir['vendor/plugins/*/recipes/*.rb'].each { |plugin| load(plugin) }
load 'config/deploy' # remove this line to skip loading any of the default tasks | Ruby |
require 'faker'
PUBLISHERS = ["ABU", "Vida", "Mundo Cristao", "Contemporanea"]
CATEGORIES = ["Vida Crista", "Apologetica", "Documentario", "Teologia", "Teologia Escatologia"]
1.upto(100).each do |m|
book = Book.new
book.title = Faker::Lorem.words(3).join(' ').capitalize
book.author = Faker::Name.name
... | Ruby |
module AdminHelper
end
| Ruby |
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
end
| Ruby |
module UsersHelper
end
| Ruby |
module CatalogHelper
end
| Ruby |
module BossesHelper
end
| Ruby |
module RentalsHelper
end
| Ruby |
module CommentsHelper
end
| Ruby |
module BooksHelper
end
| Ruby |
require 'digest/sha1'
class Boss < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
attr_accessor :password_confirmation
validates_confirmation_of :password
validate :password_non_blank
def self.authenticate(name, password)
boss = self.find_by_name(name)
if bos... | Ruby |
class Rental < ActiveRecord::Base
belongs_to :user
belongs_to :book
validates_presence_of :pick_up
def brazilian_format
if self.day < 10
day = "0" + self.day.to_s
else
day = self.day.to_s
end
if self.month < 10
month = "0" + self.month.to_s
else
month = self.mon... | Ruby |
class Book < ActiveRecord::Base
has_many :rentals
has_many :comments
has_friendly_id :title, :use_slug => true,
:approximate_ascii => true,
:max_length => 50,
:sequence_separator => "_"
def self.find_books_available
find(:all, :order => "title")
... | Ruby |
class User < ActiveRecord::Base
has_many :rentals
validates_presence_of :name
validates_format_of :phone, :with => /\d{2}-?\d{4}-?\d{4}$/,
:message => 'O telefone deve estar no formato DD-DDDD-DDDD'
end
| Ruby |
class Comment < ActiveRecord::Base
belongs_to :book
validates_presence_of :user_name, :comment
end
| Ruby |
class RentalsController < ApplicationController
def list_rentals_by_book_or_user
@rental = Rental.new(params[:rental])
session[:rentals] = Rental.find(:all,
:conditions => ["book_title LIKE ? AND user_name LIKE ?",
"%#{@rental.bo... | Ruby |
class AdminController < ApplicationController
def login
session[:boss_id] = nil
if request.post?
boss = Boss.authenticate(params[:name], params[:password])
if boss
session[:boss_id] = boss.id
uri = session[:original_uri]
session[:original_uri] = nil
redirect_to(uri ... | Ruby |
class CatalogController < ApplicationController
def index
@books = Book.find_books_available
end
def list_books
@book = Book.new(params[:book])
session[:books] = Book.find(:all,
:conditions => ["title LIKE ? AND author LIKE ? AND
... | Ruby |
class BossesController < ApplicationController
# GET /bosses
# GET /bosses.xml
def index
@bosses = Boss.find(:all, :order => :name)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @bosses }
end
end
# GET /bosses/1
# GET /bosses/1.xml
def show
... | Ruby |
class CommentsController < ApplicationController
# GET /comments
# GET /comments.xml
def index
@comments = Comment.find(:all)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @comments }
end
end
# GET /comments/1
# GET /comments/1.xml
def show
... | Ruby |
class BooksController < ApplicationController
def select_user
@book = Book.find(params[:id])
session[:rental] = Rental.new
session[:rental].book_id = @book.id
session[:rental].book_title = @book.title
end
def rent
@user = User.find(params[:user][:id])
@rental = Rental.new
@rental... | 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
layout 'books'
before_filter :authorize, :except => :login
session :session_key => '_library_session_id'
... | Ruby |
class UsersController < ApplicationController
def list_users
@user = User.new(params[:user])
session[:users] = User.find(:all,
:conditions => ["name LIKE ? AND phone LIKE ? AND
cell LIKE ? AND email LIKE ?",
... | 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/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'
$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/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'
$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 |
class CreateBooks < ActiveRecord::Migration
def self.up
create_table :books do |t|
t.string :title
t.string :author
t.string :publisher
t.integer :first_edition_year
t.integer :copy_year
t.string :category
t.timestamps
end
end
def self.down
drop_table :books... | Ruby |
class CreateSlugs < ActiveRecord::Migration
def self.up
create_table :slugs do |t|
t.string :name
t.integer :sluggable_id
t.integer :sequence, :null => false, :default => 1
t.string :sluggable_type, :limit => 40
t.string :scope
t.datetime :created_at
end
add_index :slug... | Ruby |
class CreateUsers < ActiveRecord::Migration
def self.up
create_table :users do |t|
t.string :name
t.integer :phone
t.integer :cell
t.string :email
t.timestamps
end
end
def self.down
drop_table :users
end
end
| Ruby |
class AddUserData < ActiveRecord::Migration
def self.up
User.delete_all
User.create(:name => 'Igor',
:phone => 39477854,
:cell => 81116674,
:email => 'igoraquino@gmail.com')
User.create(:name => 'Bernardo',
:phone => 39393144,
... | Ruby |
class CreateSessions < ActiveRecord::Migration
def self.up
create_table :sessions do |t|
t.string :session_id, :null => false
t.text :data
t.timestamps
end
add_index :sessions, :session_id
add_index :sessions, :updated_at
end
def self.down
drop_table :sessions
end
end
| Ruby |
class AddQuantityToBook < ActiveRecord::Migration
def self.up
add_column :books, :quantity, :integer
end
def self.down
remove_column :books, :quantity
end
end
| Ruby |
class AddBookTitleToRental < ActiveRecord::Migration
def self.up
add_column :rentals, :book_title, :string
end
def self.down
remove_column :rentals, :book_title
end
end
| Ruby |
class CreateRentals < ActiveRecord::Migration
def self.up
create_table :rentals, :force => true do |t|
t.timestamp :pick_up
t.timestamp :return
t.integer :book_id, :null => false, :options =>
"CONSTRAINT fk_rental_books REFERENCES books(id)"
t.integer :user_id, :null => false, :opt... | Ruby |
class AddUserNameToRental < ActiveRecord::Migration
def self.up
add_column :rentals, :user_name, :string
end
def self.down
remove_column :rentals, :user_name
end
end
| Ruby |
class CreateBosses < ActiveRecord::Migration
def self.up
create_table :bosses do |t|
t.string :name
t.string :hashed_password
t.string :salt
t.timestamps
end
end
def self.down
drop_table :bosses
end
end
| Ruby |
class ChangeTimeFormat < ActiveRecord::Migration
def self.up
change_column :rentals, :pick_up, :date
change_column :rentals, :return, :date
end
def self.down
change_column :rentals, :pick_up, :datetime
change_column :rentals, :return, :datetime
end
end
| Ruby |
class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments do |t|
t.integer :book_id, :null => false, :options =>
"CONSTRAINT fk_comment_books REFERENCES books(id)"
t.string :book_title
t.string :user_name
t.text :comment
t.timestamps
end
end
... | Ruby |
class AddPeopleData < ActiveRecord::Migration
def self.up
Person.delete_all
Person.create(:name => 'Igor',
:phone => 39477854,
:cell => 81116674,
:email => 'igoraquino@gmail.com')
Person.create(:name => 'Bernardo',
:phone => 393... | Ruby |
class AddTestData < ActiveRecord::Migration
def self.up
Book.delete_all
Book.create(:title => 'O Príncipe e a Ilha Mágica',
:author => 'C. S. Lewis',
:publisher => 'ABU',
:first_edition_year => 1984,
:copy_year => 1984,
:category ... | Ruby |
class AddCachedSlugToBooks < ActiveRecord::Migration
def self.up
add_column :books, :cached_slug, :string
add_index :books, :cached_slug, :unique => true
end
def self.down
remove_column :books, :cached_slugs
end
end
| Ruby |
namespace :friendly_id do
desc "Make slugs for a model."
task :make_slugs => :environment do
FriendlyId::TaskRunner.new.make_slugs do |record|
puts "%s(%d): friendly_id set to '%s'" % [record.class.to_s, record.id, record.slug.name] if record.slug
end
end
desc "Regenereate slugs for a model."
t... | Ruby |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.