code
stringlengths
1
1.73M
language
stringclasses
1 value
#!/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
#!/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/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/destroy'
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/console'
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/about'
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/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/plugin'
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/spawner'
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/reaper'
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/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/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/request'
Ruby
#!/usr/bin/env ruby require File.dirname(__FILE__) + '/../config/boot' require 'commands/generate'
Ruby
module WelcomeHelper end
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module ForestHelper end
Ruby
module SessionsHelper end
Ruby
module HealerHelper end
Ruby
module UsersHelper # # Use this to wrap view elements that the user can't access. # !! Note: this is an *interface*, not *security* feature !! # You need to do all access control at the controller level. # # Example: # <%= if_authorized?(:index, User) do link_to('List all users', users_path) end %> ...
Ruby
module BankHelper end
Ruby
module AdminHelper end
Ruby
class Monster < ActiveRecord::Base def self.random_encounter # For a single random record I'm using the technique from here: # http://robzon.aenima.pl/2007/12/selecting-random-row-from-table.html random_monster = self.find(:first, :offset => (self.count * rand).to_i) # We'll set the number of hi...
Ruby
require 'digest/sha1' class User < ActiveRecord::Base include Authentication include Authentication::ByPassword include Authentication::ByCookieToken validates_presence_of :login validates_length_of :login, :within => 3..40 validates_uniqueness_of :login, :case_sensitive => false valid...
Ruby
class WelcomeController < ApplicationController skip_before_filter :login_required def index # Call the function current_user to get the user assigned to the # @current_user variable (if anyone is logged in). The # function comes with restful_authentication. current_user @title = "Welcome...
Ruby
class UsersController < ApplicationController skip_before_filter :login_required # render new.rhtml def new @user = User.new @title = "Sign Up" end def create logout_keeping_session! @user = User.new(params[:user]) success = @user && @user.save if success && @user.errors.empt...
Ruby
class ForestController < ApplicationController def index current_user # Get a random monster for us to encounter in the forest. @monster = Monster.random_encounter # Save the monster in our session. session[:monster_id] = @monster.id end def attack current_user # Pull...
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 include AuthenticatedSystem helper :all # include all helpers, all the time # See ActionController::Reque...
Ruby
class BankController < ApplicationController def index current_user end def do_some_banking if params[:commit] == "Deposit" amount = current_user.deposit(params[:amount].to_i) flash[:notice] = "You deposited #{amount} gold into your bank account. Your total in the bank is now #{@current_user...
Ruby
class AdminController < ApplicationController def index end private # By adding a function named "authorized?" and performing a test in it # we use one of the hooks provided by restful_authentication. def authorized? current_user.login == "Admin" end end
Ruby
class HealerController < ApplicationController def index end def do_some_healing # The amount we actually healed might be different than the amount requested # due to a variety of factors (i.e. they didn't need that much healing, they # didn't have enough gold, etc.) so we record the amount they actu...
Ruby
# This controller handles the login/logout function of the site. class SessionsController < ApplicationController skip_before_filter :login_required # render new.rhtml def new @title = "Log In" end def create logout_keeping_session! user = User.authenticate(params[:login], params[:password])...
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
# A Site key gives additional protection against a dictionary attack if your # DB is ever compromised. With no site key, we store # DB_password = hash(user_password, DB_user_salt) # If your database were to be compromised you'd be vulnerable to a dictionary # attack on all your stupid users' passwords. With a site...
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. # Include Active Record class name as root for JSON serialized output. ActiveRecord::Base.include_root_in_json = true # Store the full class name (including module namespa...
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
ActionController::Routing::Routes.draw do |map| map.logout '/logout', :controller => 'sessions', :action => 'destroy' map.login '/login', :controller => 'sessions', :action => 'new' map.register '/register', :controller => 'users', :action => 'create' map.signup '/signup', :controller => 'users', :action => 'ne...
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.1...
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 end # Accesses the current user from the session. # Future calls avoid the database because nil is not ...
Ruby
module AuthenticatedTestHelper # Sets the current user in the session from the user fixtures. def login_as(user) @request.session[:user_id] = user ? users(user).id : nil end def authorize_as(user) @request.env["HTTP_AUTHORIZATION"] = user ? ActionController::HttpAuthentication::Basic.encode_credentials...
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
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
# import java # class {"java":} # exec {"echo $(pwd)"} # exec { "puppet:///modules/load-paas-exec.rb":} create_resource :file, ["/opt", "/opt/miniPaaS/", "/opt/miniPaaS/loadtest"], :ensure => "directory" file ["/opt/miniPaaS/loadtest/rbe.jar"], :source => "puppet://modules/loadtest/rbe.jar" file ["/opt/miniPaaS/loadte...
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 =>...
Ruby
source 'http://rubygems.org' gem 'rails', '3.0.5' gem 'json' gem 'uuid' # Bundle edge Rails instead: # gem 'rails', :git => 'git://github.com/rails/rails.git' # Use unicorn as the web server # gem 'unicorn' # Deploy with Capistrano # gem 'capistrano' # To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 fo...
Ruby
module ApplicationHelper end
Ruby
module GetNumUsersHelper end
Ruby
class ApplicationController < ActionController::Base protect_from_forgery end
Ruby
require 'json' require 'uuid' class GetNumUsersController < ApplicationController def index render :text=>"hi" end def test render :text => "hi" end def get_current_workload agent_id = params[:agent_id] render :text => JSON.generate(platform_wokloads[:worload][1]) end def regist...
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. Coordinator::Application.config.session_store :cookie_store, :key => '_coordinator_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 wi...
Ruby
Coordinator::Application.routes.draw do # get "get_num_users/test" # 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 # Sample ...
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__) # Pick the frameworks you want: # require "active_record/railtie" require "action_controller/railtie" require "action_mailer/railtie" require "active_resource/railtie" require "rails/test_unit/railtie" # If you have a Gemfile, require the gems listed there, including any ...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application Coordinator::Application.initialize!
Ruby
Coordinator::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 turne...
Ruby
Coordinator::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 w...
Ruby
Coordinator::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 t...
Ruby
# This file is used by Rack-based servers to start the application. require ::File.expand_path('../config/environment', __FILE__) run Coordinator::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' Coordinator::Application.load_tasks
Ruby
#!/usr/bin/ruby require "erb" class LogWriter def get_log_file_content( step=15 , tt_scale = "0.05", www = "http://www.bademjoon.com", outputFile = "log.txt", context="/tpcw", workloadFraction = "1", ifGetImage="false", debug="1", workload=" 1 107 214 32") # Create template. template = %q{ step=<%=step...
Ruby
#!/usr/bin/ruby require "erb" class LogWriter def get_log_file_content( step=15 , tt_scale = "0.05", www = "http://www.bademjoon.com", outputFile = "log.txt", context="/tpcw", workloadFraction = "1", ifGetImage="false", debug="1", workload=" 1 107 214 32") # Create template. template = %q{ step=<%=step...
Ruby
require 'tempfile' require 'rubygems' require 'guid' require 'fog' require 'net/ssh' require 'puppet/network/http_pool' require 'net/ssh' require 'timeout' module Puppet::CloudPack require 'puppet/cloudpack/installer' class << self # Method to set AWS defaults in a central place. Lots of things need these ...
Ruby
require 'rake' require 'rake/clean' require 'rake/gempackagetask' require 'rake/rdoctask' require 'rake/testtask' require 'fileutils' include FileUtils NAME = "bulkmail" VERS = "0.3.1" CLEAN.include ['**/.*.sw?', '*.gem', '.config'] RDOC_OPTS = ['--quiet', '--title', "Bulkmail Documentation", "--opname", "index.html...
Ruby
require File.join(File.dirname(__FILE__), 'bulkmail/thread_pool') require File.join(File.dirname(__FILE__), 'bulkmail/dns_mx') require File.join(File.dirname(__FILE__), 'bulkmail/addresses') require File.join(File.dirname(__FILE__), 'bulkmail/message') require File.join(File.dirname(__FILE__), 'bulkmail/sender')
Ruby
require File.join(File.dirname(__FILE__), 'task') class Array def to_batches(batch_size) groups = [] while !empty? groups << slice!(0, batch_size) end groups end def shuffle sort_by {rand} end end module BulkMail # Sender instances perform the actual work of sending an email. Each...
Ruby
require 'rubygems' require 'net/smtp' require 'Net/DNS' module BulkMail # Performs a DNS query for a domain's MX records and returns an array # of SMTP servers for the domain ordered by preference. If no records # are found an error is raised. def self.smtp_servers_for_domain(domain) res = Net::DNS::Resol...
Ruby
require 'thread' # This class implements a pool of threads. The pool hands out blocks to be # processed to any available worker thread. If no worker thread is available, # the pool blocks until any of the workers have become available. The pool # size can be specified when constructing the pool. For exmaple: # # poo...
Ruby
require 'net/smtp' class Range def random rand * (last - first) + first end end module BulkMail class Task def initialize(domain, addrs, opts) @domain = domain @addrs = addrs @opts = opts end # Sends email to all addresses belonging to a domain. def run servers =...
Ruby
# Symbol extensions class Symbol # Returns the symbol as a header string def to_header return @to_header if @to_header s = to_s @to_header = (s.upcase == s) ? s : to_s.split('_').map{|w| w.capitalize}.join('-') end end class String alias_method :to_header, :to_s end module BulkMail # The M...
Ruby
module BulkMail def self.addresses_by_domain(list) list.inject({}) do |m, addr| if (addr =~ /<(.*)@(.*)>/) or (addr =~ /(.*)@(.*)/) domain = $2 m[domain] ||= [] m[domain] << addr end m end end end
Ruby
require 'rake' require 'rake/clean' require 'rake/gempackagetask' require 'rake/rdoctask' require 'rake/testtask' require 'fileutils' include FileUtils NAME = "bulkmail" VERS = "0.2" CLEAN.include ['**/.*.sw?', '*.gem', '.config'] RDOC_OPTS = ['--quiet', '--title', "Bulkmail Documentation", "--opname", "index.html",...
Ruby
require 'net/smtp' # Symbol extensions class Symbol # Returns the symbol as a header string def to_header to_s.split('_').map{|w| w.capitalize}.join('-') end end class String # Returns self def to_header self end # Returns the address part of a recipient def email_addr s = strip ret...
Ruby
require 'rake' require 'rake/clean' require 'rake/gempackagetask' require 'rake/rdoctask' require 'rake/testtask' require 'fileutils' include FileUtils NAME = "bulkmail" VERS = "0.1" CLEAN.include ['**/.*.sw?', '*.gem', '.config'] RDOC_OPTS = ['--quiet', '--title', "Bulkmail Documentation", "--opname", "index.html",...
Ruby
require 'action_mailer' # The BulkMail module contains the Job class, which does the actual # bulk-mailing, and a convenience method to start a job. module BulkMail class Mailer < ActionMailer::Base #:nodoc def msg(addr, sub, content, from_addr, c_type, additional_headers) recipients addr subject sub...
Ruby