code
stringlengths
1
1.73M
language
stringclasses
1 value
if (2>1) then k=5 end if (k==5) then c=0 end return c
Ruby
h = 1.0 while h < 3.0 do h=h+1.5 end return h
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
# Ruby example - fruits4 # Polyglot Language Project # http://groups.google.com/group/comp-lang-polyglot # File: fruits4.rb # Date: 12-Aug-2008 print "Ruby Version: " + RUBY_VERSION + "\n" print "OS Platform : " + RUBY_PLATFORM + "\n" print "---------------------- \n"; fruits = Array.new fruits[0] = "app...
Ruby
# Ruby example - fruits4 # Polyglot Language Project # http://groups.google.com/group/comp-lang-polyglot # File: fruits4.rb # Date: 12-Aug-2008 print "Ruby Version: " + RUBY_VERSION + "\n" print "OS Platform : " + RUBY_PLATFORM + "\n" print "---------------------- \n"; fruits = Array.new fruits[0] = "app...
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
# 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 config.action_controller.allow_forgery_protection = false # Enable threaded mode # config.threadsafe...
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.2...
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.resources :scores map.resources :labs map.auto_complete ':controller/:action', :requirements => { :action => /auto_complete_for_\S+/ }, :conditions => { :method => :get } # The priority is based upon order of creation: first created -> highest priority...
Ruby
module LabsHelper end
Ruby
# Methods added to this helper will be available to all templates in the application. module ApplicationHelper end
Ruby
module UserHelper end
Ruby
module ScoresHelper end
Ruby
module UploadHelper end
Ruby
class DataFile < ActiveRecord::Base def self.save(upload,path) Dir.chdir(path) if(upload['datafile'] != "") then name = upload['datafile'].original_filename if(name.index(/\.[zip|rar|tgz|tar\.gz]/).nil?) then false else path = File.join(path, name) File.open(path, ...
Ruby
class Score < ActiveRecord::Base belongs_to :user belongs_to :lab end
Ruby
require 'digest/sha1' class User < ActiveRecord::Base has_many :scores def self.auth(id,pass) u=find_by_ident(id) return nil if u.nil? return u if User.encrypt(pass)==u.pwd.upcase nil end protected def self.encrypt(pass) # Digest::SHA1.hexdigest(pass) pass.upcase end end
Ruby
class Lab < ActiveRecord::Base has_many :scores end
Ruby
class ScoresController < ApplicationController # GET /scores # GET /scores.xml def index @scores = Score.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @scores } end end # GET /scores/1 # GET /scores/1.xml def show @score = Score.f...
Ruby
require 'fileutils' require 'ftools' require 'tmpdir' require 'timeout' require 'find' require 'differ' class UploadController < ApplicationController before_filter :login_required attr_accessor :info def index end def msg(msg) render :juggernaut => {:type => :send_to_clients, :client_ids => [ses...
Ruby
class UserController < ApplicationController before_filter :login_required, :only => ['edit','home'] skip_before_filter :verify_authenticity_token, :only => [:auto_complete_for_user_ident] auto_complete_for :user,:ident def signup if request.post? @user = User.new(params[:user]) if @user...
Ruby
class LabsController < ApplicationController # GET /labs # GET /labs.xml def index @labs = Lab.find(:all) respond_to do |format| format.html # index.html.erb format.xml { render :xml => @labs } end end # GET /labs/1 # GET /labs/1.xml def show @lab = Lab.find(params[:id]) ...
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 skip_before_filter :verify_authenticity_token helper :all # include all helpers, all the time # See Actio...
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 'rake/clean' CLEAN.include('*.res') task :default => [:gen_res] SRC = FileList['*.c'] DST = SRC.ext('res') LAB2 = "/home/nate/compiler/public_html/labs/lab2/lab2" rule '.res' => '.c' do |t| sh "#{LAB2} #{t.source} > #{t.name}" end task :gen_res => DST do end
Ruby
pre = Proc.new do |orginal| orginal end post = Proc.new do |x,y| x=y # if (x.size-y.size).abs <50 then # true # else # false # end end [pre,post]
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 AddStoreToScore < ActiveRecord::Migration def self.up add_column :score,:store,:string end def self.down remove_column :score,:store end end
Ruby
class RenameLabPath < ActiveRecord::Migration def self.up rename_column(:labs,:path,:ext) end def self.down rename_column(:labs,:ext,:path) end end
Ruby
class RenameLabExec < ActiveRecord::Migration def self.up rename_column(:labs,:exec,:execfile) end def self.down rename_column(:labs,:execfile,:exec) end end
Ruby
class CreateDataFiles < ActiveRecord::Migration def self.up create_table :data_files do |t| t.timestamps end end def self.down drop_table :data_files end end
Ruby
#!/usr/bin/ruby1.8 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...
Ruby
#!/usr/bin/ruby1.8 # # 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 FastCGI crash log is RAILS_ROOT/log/fastcgi.crash.log #...
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
require 'mxx_ru/cpp' Mxx_ru::setup_target( Mxx_ru::Cpp::Composite_target.new( Mxx_ru::BUILD_ROOT ) { global_include_path( "." ) default_runtime_mode( MxxRu::Cpp::RUNTIME_RELEASE ) MxxRu::enable_show_brief required_prj( "Como/prj.rb" ) } )
Ruby
require 'mxx_ru/cpp/qt5' Mxx_ru::Cpp::lib_target { rtl_mode( Mxx_ru::Cpp::RTL_SHARED ) rtti_mode( Mxx_ru::Cpp::RTTI_ENABLED ) threading_mode( Mxx_ru::Cpp::THREADING_MULTI ) target( "lib/Como" ) qt = generator( MxxRu::Cpp::Qt5.new( self ) ) qt.use_modules( QT_CORE, QT_NETWORK ) sources_root( ...
Ruby
require 'rubygems' gem 'Mxx_ru', '>= 1.4.7' require 'mxx_ru/cpp' Mxx_ru::setup_target( Mxx_ru::Cpp::Composite_target.new( Mxx_ru::BUILD_ROOT ) { global_include_path( "." ) default_runtime_mode( MxxRu::Cpp::RUNTIME_RELEASE ) MxxRu::enable_show_brief # global_compiler_option '-Zi' # global_lin...
Ruby
require 'rubygems' gem 'Mxx_ru', '>= 1.4.7' require 'mxx_ru/cpp/qt4' Mxx_ru::Cpp::lib_target { rtl_mode( Mxx_ru::Cpp::RTL_SHARED ) rtti_mode( Mxx_ru::Cpp::RTTI_ENABLED ) threading_mode( Mxx_ru::Cpp::THREADING_MULTI ) target( "lib/Como" ) qt = generator( MxxRu::Cpp::Qt4.new( self ) ) qt.use_...
Ruby
require 'rubygems' gem 'Mxx_ru', '>= 1.4.7' require 'mxx_ru/cpp/qt4' Mxx_ru::Cpp::exe_target { rtl_mode( Mxx_ru::Cpp::RTL_SHARED ) rtti_mode( Mxx_ru::Cpp::RTTI_ENABLED ) threading_mode( Mxx_ru::Cpp::THREADING_MULTI ) screen_mode( Mxx_ru::Cpp::SCREEN_WINDOW ) required_prj( "Como/prj.rb" ) qt...
Ruby
require 'rubygems' gem 'Mxx_ru', '>= 1.4.7' require 'mxx_ru/cpp' MxxRu::Cpp::composite_target() { required_prj( "samples/server/prj.rb" ) required_prj( "samples/qtreeview_client/prj.rb" ) }
Ruby
require 'rubygems' gem 'Mxx_ru', '>= 1.4.7' require 'mxx_ru/cpp/qt4' Mxx_ru::Cpp::exe_target { rtl_mode( Mxx_ru::Cpp::RTL_SHARED ) rtti_mode( Mxx_ru::Cpp::RTTI_ENABLED ) threading_mode( Mxx_ru::Cpp::THREADING_MULTI ) required_prj( "Como/prj.rb" ) qt = generator( MxxRu::Cpp::Qt4.new( self ) ) ...
Ruby
require 'mxx_ru/cpp' Mxx_ru::setup_target( Mxx_ru::Cpp::Composite_target.new( Mxx_ru::BUILD_ROOT ) { global_include_path( "." ) default_runtime_mode( MxxRu::Cpp::RUNTIME_RELEASE ) MxxRu::enable_show_brief required_prj( "Como/prj.rb" ) } )
Ruby
require 'mxx_ru/cpp/qt5' Mxx_ru::Cpp::lib_target { rtl_mode( Mxx_ru::Cpp::RTL_SHARED ) rtti_mode( Mxx_ru::Cpp::RTTI_ENABLED ) threading_mode( Mxx_ru::Cpp::THREADING_MULTI ) target( "lib/Como" ) qt = generator( MxxRu::Cpp::Qt5.new( self ) ) qt.use_modules( QT_CORE, QT_NETWORK ) sources_roo...
Ruby
a = 2 b = 2.5 c = 3. + 2.5 * 8.5 d = c
Ruby
a = 10.2 * 3 b = 4 * 2.6 c = 4.5 / 2 d = 3 / 1.2 e = 4 / 3.4 * 2 f = 2 + 1.3 g = 2.3 + 1 h = 2.3 - 4 i = 1 - 0.6 j = 12 + 2.3 * 5 - 8.9 / 2
Ruby
puts 'Hello world'
Ruby
# -*- mode: ruby -*- # vi: set ft=ruby : # Vagrantfile API/syntax version. Don't touch unless you know what you're doing! VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| # All Vagrant configuration is done here. The most common configuration # options are documented and commen...
Ruby
# Helper methods defined here can be accessed in any controller or view in the application module GdataHelper # Transform a list of docs to a map by title def gdocs_by_title(docs) by_title = {} docs.values.each do |doc| by_title[doc.full_title] = doc end by_title end # Check if this is a...
Ruby
module SlugfilterHelper def walk_slug_tree(tree, options=nil, &block) options ||= {} depth = options[:depth] capture_haml do walk_slug_tree_children_helper(tree, nil, true, depth, options, &block) end end def walk_slug_tree_children_helper(tree, step=nil, odd=true, depth=nil, options=nil, ...
Ruby
module ApplicationHelper # Shorthand humanized text for admin pages def pat(sym) sym.to_s.humanize end # Default time display (localize at some point) def display_time(time) time.strftime("%Y-%m-%d %H:%M") rescue "-" end #:nocov: # FIXME: No obvious way to sanely test this. # Use instead of ...
Ruby
# Helper methods defined here can be accessed in any controller or view in the application module DocumentHelper # Transform a document URL for display purposes. # # Currently just transforms a Google Docs url to the editable document # version. def transform_document_url(url) gdoc_url = Gdoc.edit_url_fr...
Ruby
module BusinessObjectsHelper def related_objects(instance) if instance.is_a?(System) && instance.is_biz_process? instance.class.related_models("Process") else instance.class.related_models end end def arranged_related_objects(instance) end end
Ruby
module ImportHelper def trim_array(a) while !a.empty? && a.last.blank? a.pop end a end def validate_import_slug(object, object_name, expected_slug) raise ImportException.new("#{object_name} Code column does not exist") unless object["slug"] raise ImportException.new("#{object_name} Code...
Ruby
module AuthorizationHelper # Roles def access_control_roles [:user, :admin, :risk, :admin_risk, :no_access] end def allowed_objs(objects, ability) objects #Authorization::allowed_objects(ability, @current_user, objects) end def check_model_risk_authorization(models) if current_user.can_man...
Ruby
module MappingHelper end
Ruby
module FormHelper # Simple helper for repetitive form error spans def error_messages_inline(f, field_name) capture_haml do haml_tag :span, :class => 'help-inline' do f.object.errors[field_name].each do |error| haml_tag :span do haml_concat "#{error}" end en...
Ruby
require 'prawn_monkeypatch' module EvidenceHelper include ApplicationHelper # Capture evidence on Google Docs # # Convert the evidence document to PDF and watermark it with: # # * Acceptance date # * Who accepted the evidence # * Which system was the evidence attached to # # The PDF is then upload...
Ruby
module CyclesHelper def generate_default_title_for_cycle(program=nil) default_title = (program.nil? ? "" : program.title + " ") + "Audit" count = Cycle.where(Cycle.arel_table[:title].matches("%#{default_title}%")).count default_title += count > 0 ? " " + (count + 1).to_s : "" return "#{Date.today.ye...
Ruby
module DirectivesHelper # Set up a directive and relevant stats for display def directive_stats(directive) stats = {} stats[:sections_count] = Section.where(:directive_id => directive.id).count() stats[:sections_done_count] = Section.joins(:controls).where(:directive_id => directive.id).count(:distinct ...
Ruby
module DashboardHelper def init_quick_find @quick_find ||= {} @quick_find[:controls] ||= Control.all @quick_find[:systems] ||= System.where(:is_biz_process => false).all @quick_find[:biz_processes] ||= System.where(:is_biz_process => true).all end end
Ruby
module ManyHelper # Many to many AJAX page - show form. # # Example: # if request.put? # post_many2many(:left_class => Control, # :right_class => DocumentDescriptor, # :right_relation => :evidence_descriptors, # :right_ids => :evid...
Ruby
module ProgramsDashHelper end
Ruby
module ControlsHelper def control_params control_params = params[:control] || {} if control_params[:directive_id] # TODO: Validate the user has access to add controls to the directive control_params[:directive] = Directive.where(:id => control_params.delete(:directive_id)).first end %w(typ...
Ruby
module WelcomeHelper end
Ruby
class EmailValidator < ActiveModel::EachValidator EMAIL_RE = /([^@\s]+)(?:@((?:[-a-z0-9]+\.)+[a-z]{2,}))/i EMAILS_RE = /\A\s*#{EMAIL_RE}(?:\s*[, ]\s*#{EMAIL_RE})*\Z/i def validate_each(record, attribute, value) unless value =~ /^#{EMAIL_RE}$/ record.errors[attribute] << (options[:message] || "must be a...
Ruby