code
stringlengths
1
1.73M
language
stringclasses
1 value
# 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
# 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
require 'socket' require 'thread' require 'pp' class HTTPServerStub attr_accessor :port, :thread def initialize(response, &block) server = TCPServer.new('127.0.0.1', 0) self.port = server.addr[1] self.thread = Thread.new(server, block) do |server, blk| sess = server.accept re...
Ruby
require 'rake' require 'rake/gempackagetask' require 'rake/rdoctask' require 'rake/testtask' require 'fileutils' include FileUtils NAME = "zeep-messaging" REV = `svn info`[/Revision: (\d+)/, 1] rescue nil VERS = ENV['VERSION'] || "0.1" + (REV ? ".#{REV}" : "") PKG = "#{NAME}-#{VERS}" BIN = "*.{bundle,jar,so,obj,pdb,l...
Ruby
require 'net/http' class Exception def is_zeep_response? false end end class Net::HTTPResponse def to_zeep clazz = Zeep.responses[self.code] || Zeep::UnexpectedError clazz.new(response.body) end end module Zeep def self.responses if @responses.nil? @responses = {} self.constants...
Ruby
#require 'zeep/auth' require 'net/http' require 'net/https' require 'zeep/auth' require 'zeep/responses' module Zeep module Base @@base_url = 'https://api.zeepmobile.com/' @@api_key = '' @@secret_key = '' def self.configure_credentials(api_key, secret_key) @@api_key = api_key @@secr...
Ruby
require 'openssl' require 'base64' require 'time' require 'cgi' require 'zeep/responses' module Zeep module Auth MESSAGE_WINDOW = 10 # seconds @digest = OpenSSL::Digest::Digest.new('sha1') def self.split(auth) zeep, auth = auth.split(' ') api_key, *signature = auth.split(':') [zeep...
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
# Install jruby 1.2.0 or newer and put it on the path # $ gem install twitter (0.6.8) # $ gem install jruby-openssl (0.4) # set JSOAR_HOME # $ jruby twagent.rb user pass soar-file # # see twagent.soar for output command details. # Add lib to load path $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '....
Ruby
# Add lib to load path $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') require 'rsoar' import org.jsoar.kernel.SoarProperties agent = RSoar::RAgent.new do |a| a.name = "Hello" #a.properties[SoarProperties::WAITSNC] = true a.eval "waitsnc --on" a.sp 'hello (state <s> ^sup...
Ruby
# Add lib to load path $LOAD_PATH.unshift File.dirname(__FILE__) require 'java' # If we're in a normal JSoar distribution, then JSOAR_HOME should be # two directories up if !ENV['JSOAR_HOME'] ENV['JSOAR_HOME'] = File.join(File.dirname(__FILE__), '..', '..') end if ENV['JSOAR_HOME'] Dir.glob(File.join...
Ruby
module RSoar class InputId attr_reader :char attr_reader :map def initialize(tree, char = 'Z') @tree = tree @char = char @map = Hash.new { |hash, key| hash[key] = [] } end def add_attribute(name, value = nil, &block) value = new_id(name.to_s) if value...
Ruby
class Java::OrgJsoarUtilProperties::PropertyManager def [] (key) get key end def []= (key, value) set key, value end end
Ruby
module RSoar OutputCommand = Struct.new("OutputCommand", :handler, :options) class OutputId def initialize(agent, id) @agent = agent @id = id end def [](name) w = org.jsoar.kernel.memory.Wmes.matcher(@agent).attr(name.to_s).find(@id) if !w.nil? v =...
Ruby
module RSoar class RubyCommand import org.jsoar.util.commands.SoarCommand def initialize(binding) @binding = binding end # Implement SoarCommand.execute(String[] args) throws SoarCommand def execute(args) begin if args.length > 1 eval args.to_a[1..-1].jo...
Ruby
module RSoar class RAgent attr_reader :agent attr_reader :input attr_reader :output def initialize(&block) super @agent = org.jsoar.runtime.ThreadedAgent.create org.jsoar.kernel.io.CycleCountInput.new @agent.input_output org.jsoar.kernel.io.TimeIn...
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
# 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 'data_mapper', '~> 1.2' gem 'dm-postgres-adapter' gem 'google-api-client', '>= 0.4.3' group :development do gem 'dm-sqlite-adapter', '~> 1.2' gem 'do_sqlite3', '~> 0.10' end
Ruby
require 'gserver' class MyServer < GServer def initialize(port, file, *args) super(port, *args) File.open(file,"r") do |f| @lines = f.read end end def serve(io) begin io.puts(@lines) end rescue Exception=>e io.puts e end end server = MyServer.new(10000,"./cviceni4/serve...
Ruby
class Person def initialize(name) @name = name end def to_s "Person named #{@name}" end end pers = Person.new("Honza") puts pers
Ruby
class Parent end class Child < Parent end puts "Child superclass is #{Child.superclass}" puts "Parent superclass is #{Parent.superclass}" puts "Object superclass is #{Object.superclass}" puts "BasicObject superclass is #{BasicObject.superclass}"
Ruby
module Summable def sum inject(:+) end end
Ruby
require 'enumerator' require 'cviceni4\Summable.rb' class VowelFinder include Enumerable include Summable def initialize(string) @string = string end def each(&blk) vowels = @string.scan(/[aeiouyAEIOUY]/) vowels.each &blk end end puts ">> Start" v = VowelFin...
Ruby
class Graph def initialize(nodes=[]) @nodes=nodes; end def dfs(id) open_all node = get_node(id) node.dfs print "\n" end def bfs(id) open_all que = [] start_node = get_node(id) que.push(start_node) while !que.empty? do n = que.firs...
Ruby
class Graph def initialize(nodes=[]) @nodes=nodes; end def dfs(id) open_all node = get_node(id) node.dfs print "\n" end def bfs(id) open_all que = [] start_node = get_node(id) que.push(start_node) while !que.empty? do n = que.first print n.id print ...
Ruby
class Node attr_accessor(:id,:neighbors,:flag) def initialize(id) @id=id @neighbors = []; @flag = :opened; end def dfs if(@flag != :opened) return; end print "#{@id} " @flag=:closed; go_through = @neighbors.select {|v| v.flag==:opened} if go_through == nil ret...
Ruby
require "./Graph.rb" require "./Node.rb" class Solver def initialize(file,debug = false) @debug = debug; lines = [] File.open(file,"r") do |f| lines = f.readlines analyze_lines(lines) end end def analyze_lines(lines) @n = Integer(lines[0]); if @debug==true puts "Found #...
Ruby
require "./Solver.rb" puts "\n>> Start\n\n" if ARGV[0] == nil puts "PLease provide input file as argument!" else s = Solver.new(ARGV[0],false) end puts "\n<< Stop\n\n"
Ruby
class Account attr_accessor :balance def initialize(balance=0) @balance = balance end def to_s "Account has balance #{@balance}" end end class Transaction def initialize (account_a , account_b) @account_a = account_a @account_b = account_b end def debit(account , am...
Ruby
require_relative '../lib/roman.rb' require 'test/unit' require 'test/unit/autorunner' class TestRomanInit < Test::Unit::TestCase def test_init assert_raises RuntimeError { Roman.new(-1) } assert_raises RuntimeError { Roman.new(0) } assert_raises RuntimeError { Roman.new(5000) } end end
Ruby
require_relative '../lib/roman.rb' require 'test/unit' require 'test/unit/autorunner' require 'test/unit/ui/console/testrunner' class TestRoman < Test::Unit::TestCase def test_simple assert_equal("i", Roman.new(1).to_s) assert_equal("ii", Roman.new(2).to_s) assert_equal("iii", Roman.new(3).to_s) asse...
Ruby
class Roman MAX_ROMAN = 4999 def initialize(value) if value <= 0 || value > MAX_ROMAN fail "Roman values must be > 0 and <= #{MAX_ROMAN}" end @value = value end FACTORS = [["m", 1000], ["cm", 900], ["d", 500], ["cd", 400], ["c", 100], ["xc", 90], ["l", 50], ["xl", 40], ...
Ruby
class TennisScorer def initialize @server = 0 @receiver = 0 @deuce = false @advantageServer = false @advantageReceiver = false end def scoreServer if @server == 0 || @server == 15 @server = @server + 15; end if @server == 30 @server = @server + 10 if @server ==...
Ruby
#Jaroslav Crhonek (crhonjar@fit.cvut.cz) def oddElements(i) mojePole = [] i.each_with_index do |x,j| if !j.odd? mojePole << x if block_given? yield(x) end end end mojePole end puts ">> Start" puts "original field:" pole = [ 1 , 3 , 5 , 7 , 9 , 11, 13 ] puts ...
Ruby
#Jaroslav Crhonek (crhonjar@fit.cvut.cz) def count(file) stat = {} File.open(file,"r") do |f| f.readlines.each do |line| line = line.downcase line = line.gsub(/[.,"'!$%^&*()?:;]/,'') line.split(" ").each do |word| if stat.include?(word) stat[word] = stat[word]+1 ...
Ruby
#Jaroslav Crhonek (crhonjar@fit.cvut.cz) def sameword(file) #puts "Calling sameword with parameter: #{file}" lines = [] File.open(file,"r") do |f| #puts "Reading lines:" lines = f.readlines #puts "Loaded file:" #puts lines lines.each_with_index() do |line,line_no| #puts "A...
Ruby
# This is a copy of the latest ZipDirectory, from jagregory/albacore/master # Delete this file if/when albacore gets these changes integrated require 'albacore/support/albacore_helper' require 'zip/zip' require 'zip/zipfilesystem' include Zip class ZipDirectory extend AttrMethods include YAMLConfig i...
Ruby
puts "Testing: " + Zee.property("test.value")
Ruby
puts 'Test' puts Zee.appname
Ruby
# swank.rb --- swank server for Ruby. # # This is my first Ruby program and looks probably rather strange. Some # people write Scheme interpreters when learning new languages, I # write swank backends. # # Only a few things work. # 1. Start the server with something like: ruby -r swank -e swank # 2. Use M-x slime-...
Ruby
class CreateSprints < ActiveRecord::Migration def self.up create_table :sprints do |t| t.string :title t.date :start_time t.date :end_time t.integer :user_id t.string :status t.timestamps end end def self.down drop_table :sprints end end
Ruby
class CreateUsers < ActiveRecord::Migration def self.up create_table "users", :force => true do |t| t.column :login, :string, :limit => 40 t.column :name, :string, :limit => 100, :default => '', :null => true t.column :email, :string, ...
Ruby
class CreateStories < ActiveRecord::Migration def self.up create_table :stories do |t| t.string :title t.text :text t.string :weight t.integer :sprint_id t.integer :user_id t.string :status t.timestamps end end def self.down drop_table :stories end end
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
#!/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
#!/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' $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" 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' $LOAD_PATH.unshift "#{RAILTIES_PATH}/builtin/rails_info" 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
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper # get select from collection def select_from_collection(obj, field, collection) options = collection.collect {|p| [p.name, p.id]} options.unshift( ["Please Select", ""] ) # passing {:prompt => tr...
Ruby
module SprintsHelper end
Ruby
module SessionsHelper 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 StoriesHelper end
Ruby
class UserMailer < ActionMailer::Base def signup_notification(user) setup_email(user) @subject += 'Please activate your new account' @body[:url] = "http://YOURSITE/activate/#{user.activation_code}" end def activation(user) setup_email(user) @subject += 'Your account has been ac...
Ruby
class UserObserver < ActiveRecord::Observer def after_create(user) UserMailer.deliver_signup_notification(user) end def after_save(user) UserMailer.deliver_activation(user) if user.recently_activated? end end
Ruby
class Story < ActiveRecord::Base belongs_to :sprint, :class_name => 'Sprint', :foreign_key => 'sprint_id' belongs_to :user validates_presence_of :title validates_length_of :title, :within => 3..50 validates_uniqueness_of :title validates_presence_of :text ...
Ruby
require 'digest/sha1' class User < ActiveRecord::Base include Authentication include Authentication::ByPassword include Authentication::ByCookieToken include Authorization::StatefulRoles has_many :story has_many :strings validates_presence_of :login validates_length_of :login, :withi...
Ruby
class Sprint < ActiveRecord::Base has_many :story belongs_to :user validates_presence_of :title validates_length_of :title, :within => 3..50 validates_uniqueness_of :title validates_presence_of :start_time validates_presence_of :end_time validates_presence_of :user_...
Ruby
class SprintsController < ApplicationController # GET /sprints # GET /sprints.xml SPRINT_STATUSES = [[ "Open", "open" ], ["Closed", "closed"]] def index @sprints = Sprint.find(:all, :include => :user ) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @s...
Ruby
class StoriesController < ApplicationController # GET /stories # GET /stories.xml STORY_STATUSES = [[ "Open", "open" ], ["Closed", "closed"]] def index @stories = Story.find(:all, :include => { :sprint, :user }) #list #render :action => 'list' respond_to do |format| format.htm...
Ruby
class UsersController < ApplicationController # Be sure to include AuthenticationSystem in Application Controller instead include AuthenticatedSystem # Protect these actions behind an admin login # before_filter :admin_required, :only => [:suspend, :unsuspend, :destroy, :purge] before_filter :find_user, :o...
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
# This controller handles the login/logout function of the site. class SessionsController < ApplicationController # Be sure to include AuthenticationSystem in Application Controller instead include AuthenticatedSystem # render new.rhtml def new end def create logout_keeping_session! user = User....
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
# 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. 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