code
stringlengths
1
1.73M
language
stringclasses
1 value
require 'modshogun' require 'pp' require 'load' traindat = LoadMatrix.load_numbers('../data/fm_train_real.dat') testdat = LoadMatrix.load_numbers('../data/fm_test_real.dat') parameter_list = [[traindat,testdat],[traindat,testdat]] def distance_canberra_modular(fm_train_real=traindat,fm_test_real=testdat) feats_tra...
Ruby
require 'modshogun' require 'pp' require 'load' traindat = LoadMatrix.load_numbers('../data/fm_train_real.dat') testdat = LoadMatrix.load_numbers('../data/fm_test_real.dat') label_traindat = LoadMatrix.load_labels('../data/label_train_twoclass.dat') parameter_list= [[traindat,testdat,label_traindat],[traindat,testdat,...
Ruby
require 'modshogun' require 'pp' require 'load' traindna = LoadMatrix.load_dna('../data/fm_train_dna.dat') parameter_list = [[traindna, 3, 0, false], [traindna, 4, 0, false]] def distribution_histogram_modular(fm_dna=traindna, order=3, gap=0, reverse=false) charfeat=Modshogun::StringCharFeatures.new(Modshogun::DNA...
Ruby
require 'load' require 'modshogun' require 'pp' data=LoadMatrix.load_numbers('../data/fm_train_real.dat') label=LoadMatrix.load_numbers('../data/label_train_twoclass.dat') parameter_list=[[data,label]] def features_io_modular(fm_train_real, label_train_twoclass) feats=Modshogun::SparseRealFeatures.new feats.set_f...
Ruby
require 'narray' require 'modshogun' # for debugging purposes... #require 'rubygems' #require "pry" def LoadMatrix(filename, type = :numbers) case type when :numbers x = LoadMatrix.load_numbers(filename) pp x when :dna LoadMatrix.load_dna(filename) when :cubes LoadMatrix.load_cubes(filename) ...
Ruby
require 'narray' require 'modshogun' require 'load' require 'pp' traindat = LoadMatrix.load_numbers('../data/fm_train_real.dat') testdat = LoadMatrix.load_numbers('../data/fm_test_real.dat') parameter_list=[[traindat,testdat, 1.3],[traindat,testdat, 1.4]] def kernel_gaussian_modular(fm_train_real=traindat,fm_test_re...
Ruby
require 'modshogun' require 'load' require 'narray' @num = 1000 @dist = 1 @width = 2.1 C = 1 puts "generating training data" traindata_real = gen_rand_ary @num testdata_real = gen_rand_ary @num puts "generating labels" trainlab = gen_ones_vec @num testlab = gen_ones_vec @num puts "doing feature stuff" feats_train =...
Ruby
environment = :production project_type = :stand_alone http_path = "/" css_dir = "../styles" sass_dir = "." images_dir = "images" sass_options = { :line_numbers => false, :debug_info => false } # output_style = :compressed # output_style = :compact output_style = :expanded
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
# 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
environment = :production project_type = :stand_alone http_path = "/" css_dir = "../styles" sass_dir = "." images_dir = "images" sass_options = { :line_numbers => false, :debug_info => false } # output_style = :compressed # output_style = :compact output_style = :expanded
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 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
# Simple Jobs # =========== require 'java' java_import Java::MyscheduleQuartzExtraJob::LoggerJob java_import Java::MyscheduleQuartzExtraJob::ScriptingJob java_import Java::MyscheduleQuartzExtra::SchedulerTemplate java_import Java::JavaUtil::Date java_import Java::JavaLang::System # Schedule hourly job scheduler.schedu...
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
class RubyLibraryExample def get_server_language 'ruby' end # Basic communication def passing end def failing(message) raise message end def logging(message, level='INFO') puts "*#{level}* #{message}" end def returning 'returned string' end # Logging def one_message_w...
Ruby
# Copyright 2008-2009 Nokia Siemens Networks Oyj # # 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...
Ruby
#!/usr/bin/env ruby class ExampleRemoteLibrary def count_items_in_directory(path) Dir.entries(path).find_all{|i| not i.match('^\.')}.length end def strings_should_be_equal(str1, str2) puts "Comparing '#{str1}' to '#{str2}'" if str1 != str2 raise RuntimeError, "Given strings are not equal" ...
Ruby
css_dir = "/public/css" sass_dir = "/public/scss" output_style = :compressed
Ruby
# Disable Rake-environment-task framework detection by uncommenting/setting to false # Warbler.framework_detection = false # Warbler web application assembly configuration file Warbler::Config.new do |config| # Features: additional options controlling how the jar is built. # Currently the following features are su...
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
require 'gdoc' require 'gdoc/document'
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. # 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
module CmsRails class Application < Rails::Application def self.sso_callback_url @@sso_callback rescue nil end def self.sso_callback_url=(url) @@sso_callback = url end end end
Ruby
# Be sure to restart your server when you modify this file. CmsRails::Application.config.session_store :cookie_store, :key => '_cms_session_id' # 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 "rail...
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
CmsRails::Application.configure do # Settings specified here will take precedence over those in config/application.rb config.cache_classes = true config.action_controller.perform_caching = true # Log error messages when you accidentally call methods on nil. config.whiny_nils = true # Show full error repo...
Ruby
CmsRails::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 turned o...
Ruby
CmsRails::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 ...
Ruby
CmsRails::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...
Ruby
# Load the rails application require File.expand_path('../application', __FILE__) # Initialize the rails application CmsRails::Application.initialize! Sass::Plugin.options[:template_location] = { 'app/stylesheets' => 'public/stylesheets' }
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 'yaml' CMS_CONFIG = { "SECRET_TOKEN" => "0123456789abcdefChangethistosomethingsecret", "COMPANY_LOGO" => nil } CMS_CONFIG["SECRET_TOKEN"] = ENV["SECRET_TOKEN"] if ENV["SECRET_TOKEN"] CMS_CONFIG["COMPANY_LOGO"] = ENV["COMPANY_LOGO"] if ENV["COMPANY_LOGO"] CMS_...
Ruby
CmsRails::Application.routes.draw do # Admin front page match 'admin' => 'admin/base#index' # Admin pages scope :module => "admin" do resources :accounts, :path => "/admin/accounts" resources :biz_processes, :path => "/admin/biz_processes" do collection do get 'controls' put 'cont...
Ruby
module ControlState VALUES = [ :green, :yellow, :red, :unknown ] STATE_WEIGHT = { :green => 10, :unknown => 15, :yellow => 20, :red => 30 } STATE_IS_GOOD = { :green => true, :unknown => true } end
Ruby
module FrequentModel FREQUENCIES = [:day, :week, :month, :quarter, :year] def frequency_type index = read_attribute(:frequency_type) || self.class.columns_hash['frequency_type'].default FREQUENCIES[index] end def frequency_type=(value) write_attribute(:frequency_type, FREQUENCIES.index(value...
Ruby
module StateModel def state index = read_attribute(:state) || self.class.columns_hash['state'].default ControlState::VALUES[index] end def state=(value) write_attribute(:state, ControlState::VALUES.index(value)) end def good_state? ControlState::STATE_IS_GOOD[state] end def self.include...
Ruby
module SearchableModel def self.included(model) model.extend(ClassMethods) end module ClassMethods def search(q) q = "%#{q}%" t = arel_table where(t[:title].matches(q).or(t[:slug].matches(q))) end end end
Ruby
module AuthoredModel # Typecast form parameters into the right primitive to work around a DataMapper dirty-detection bug. # # If we don't do this, the persistence layer thinks all non-strings params are modifications # where in fact we might just have changed false => 0, which is a no-op. This is important #...
Ruby
module SluggedModel def compact_slug return slug unless parent cslug = slug cslug[parent.slug] = '' return cslug end def self.included(model) model.extend(ClassMethods) end def slug_split_for_sort self.slug.split(/(\d+)/).map { |s| [s.to_i, s] } end module ClassMethods def s...
Ruby
module RoleModel ROLES = [:tech, :business] def role index = read_attribute(:role) || self.class.columns_hash['role'].default ROLES[index] end def role=(value) write_attribute(:role, ROLES.index(value)) end def self.included(model) model.validates :role, :presence => true end end
Ruby
module ApplicationHelper ADMIN_MODULES = %w(accounts biz_processes business_areas cycles sections controls documents document_descriptors programs people systems) WORKFLOW_MODULES = %w(programs_dash controls dashboard evidence testing testreport) class ProjectModule attr_accessor :name attr_accessor :pa...
Ruby
module NavigationHelper end
Ruby
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 uploaded with the title prefixed wi...
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 ProgramsHelper # Set up a program and relevant stats for display def program_stats(program) stats = {} stats[:sections_count] = Section.where(:program_id => program.id).count() stats[:sections_done_count] = Section.joins(:controls).where(:program_id => program.id).count(:distinct => true) sta...
Ruby
module UserSessionsHelper end
Ruby
module SlugfilterHelper # Generate list of slugs to autocomplete in the slugfilter widget. def gen_slugs(prefix) slugs = Section.all.map { |co| co.slug } slugs = slugs.find_all { |s| s.start_with?(prefix) } organize_slugs(slugs) end def organize_slugs(slugs) # Get all slugs that start with the ...
Ruby
module ProgramsDashHelper end
Ruby
module WelcomeHelper end
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 Admin::BizProcessesHelper def update_biz_process_relations(bp, params) sec_ids = params.delete("sec_ids") || [] bp.sections = [] sec_ids.each do |sec_id| sec = Section.find(sec_id) bp.sections << sec end control_ids = params.delete("control_ids") || [] bp.controls = [] ...
Ruby
module AutofilterHelper # Filter Sections by slug. # # This is used for the respective filtering widgets. The widgets store # their state in the session. def filtered_sections secs = Section.slugfilter(session[:slugfilter]) if @program secs = secs.where(:program_id => @program) end secs...
Ruby
module ManyHelper # Edit one to many relationship. # # Example: # edit_many(@control, :biz_process_controls, :biz_process) do |bpc| # # will edit the BizProcesses attached to a control. def edit_many(obj, association, other, options = {}) other_controller = options[:other_controller] || other.to_s....
Ruby
module ControlsHelper end
Ruby
module QuickHelper end
Ruby
module DashboardHelper def init_quick_find @quick_find ||= {} @quick_find[:controls] ||= Control.all @quick_find[:systems] ||= System.all @quick_find[:biz_processes] ||= BizProcess.all end end
Ruby
module MappingHelper end
Ruby
# A system to be audited class System < ActiveRecord::Base include AuthoredModel include SluggedModel before_save :upcase_slug validates :title, :slug, :presence => { :message => "needs a value" } validates :slug, :uniqueness => { :message => "must be unique" } # Many to many with Control has_m...
Ruby
class ControlSection < ActiveRecord::Base include AuthoredModel belongs_to :control belongs_to :section is_versioned_ext end
Ruby
require 'slugged_model' # A control objective (inverse of risk) # # The slug of a Section has to have the slug of the parent as prefix. class Section < ActiveRecord::Base include AuthoredModel include SluggedModel include SearchableModel before_save :upcase_slug before_save :update_parent_id validates :t...
Ruby
# Describes a type of Document. # # Mainly use to classify types of evidence so that they can be # organized when attached to Controls class DocumentDescriptor < ActiveRecord::Base include AuthoredModel def display_name title end is_versioned_ext end
Ruby
# System to Control many to many # # Some additional attributes are attached, including the state of the control # and a ticket (if state is not green). Since a control can apply to systems, # these attributes cannot be attached to it directly. class SystemControl < ActiveRecord::Base include AuthoredModel include...
Ruby
require 'slugged_model' # A company control # class Control < ActiveRecord::Base include AuthoredModel include SluggedModel include FrequentModel include SearchableModel before_save :upcase_slug validates :slug, :title, :program, :presence => { :message => "needs a value" } validates :slug, :un...
Ruby
# System to CO many to many relationship # `state` is the rolled up state from the System to Control association class SystemSection < ActiveRecord::Base include AuthoredModel include StateModel belongs_to :section belongs_to :system is_versioned_ext end
Ruby
class BizProcessDocument < ActiveRecord::Base include AuthoredModel belongs_to :biz_process belongs_to :policy, :class_name => 'Document' is_versioned_ext end
Ruby
# class to manage user accounts on CMS. Note that this class is different # than the Person class, because not all people responsible for compliance will # have an account. class Account < ActiveRecord::Base include AuthoredModel attr_accessor :password, :password_confirmation before_save :encrypt_password be...
Ruby
# A Regulatory Program # # The top of the Program -> CO -> Control hierarchy class Program < ActiveRecord::Base include AuthoredModel include SluggedModel include FrequentModel include SearchableModel before_save :upcase_slug validates :title, :slug, :presence => { :message => "needs a value" } vali...
Ruby
# Many to many relationship between BizProcess and Control # # Some additional attributes are attached, including the state of the control # and a ticket (if state is not green). Since a control can apply to multiple processes, # these attributes cannot be attached to it directly. class BizProcessControl < ActiveRecor...
Ruby
# A business area (used to classify Controls) class BusinessArea < ActiveRecord::Base include AuthoredModel def display_name title end is_versioned_ext end
Ruby
# An audit test result class TestResult < ActiveRecord::Base include AuthoredModel validates :title, :passed, :presence => true is_versioned_ext def display_name title end end
Ruby
# An Audit Cycle # # Used to group evidence for a particular audit of a program # start_at is the audit period start date. If missing, this is a continuous process. class Cycle < ActiveRecord::Base include AuthoredModel # The program being audited belongs_to :program validates :program, :presence => true v...
Ruby
class BizProcessPerson < ActiveRecord::Base include AuthoredModel include RoleModel belongs_to :person belongs_to :biz_process is_versioned_ext end
Ruby
class DocumentSystemControl < ActiveRecord::Base include AuthoredModel belongs_to :evidence, :class_name => 'Document' belongs_to :system_control is_versioned_ext end
Ruby
class ControlDocumentDescriptor < ActiveRecord::Base include AuthoredModel belongs_to :control belongs_to :evidence_descriptor, :class_name => 'DocumentDescriptor' is_versioned_ext end
Ruby
# A user session class UserSession < Authlogic::Session::Base extend ActiveModel::Naming authenticate_with Account cookie_key "_cms_cred" end
Ruby
class DocumentSystem < ActiveRecord::Base include AuthoredModel belongs_to :document belongs_to :system is_versioned_ext end
Ruby
class SystemPerson < ActiveRecord::Base include AuthoredModel include RoleModel belongs_to :person belongs_to :system is_versioned_ext end
Ruby
class BizProcessSystem < ActiveRecord::Base include AuthoredModel belongs_to :biz_process belongs_to :system is_versioned_ext end
Ruby
# A Person # # Normally an owner or otherwise responsbile for an audit function. class Person < ActiveRecord::Base include AuthoredModel validates :username, :presence => true is_versioned_ext def display_name username end def self.search(q) q = "%#{q}%" t = arel_table where(t[:name].m...
Ruby
class ControlControl < ActiveRecord::Base include AuthoredModel belongs_to :control belongs_to :implemented_control, :class_name => 'Control' is_versioned_ext end
Ruby
# A business process involves multiple systems and is controlled by multiple controls # and control objectives. class BizProcess < ActiveRecord::Base include AuthoredModel include SluggedModel extend SluggedModel::ClassMethods include SearchableModel before_save :upcase_slug validates :title, :slug, :...
Ruby
class BizProcessSection < ActiveRecord::Base include AuthoredModel belongs_to :biz_process belongs_to :section is_versioned_ext end
Ruby
# A Document # # Can either be linked by a URL or attached from Google Docs. # # Evidence is associated with a Document Descriptor class Document < ActiveRecord::Base include AuthoredModel VALID_SCHEMES = ['http', 'https'] validate :link do begin if link.nil? || VALID_SCHEMES.include?(link.scheme) ...
Ruby
class HelpController < ApplicationController layout 'help' # Render the requested partial under 'help' def show help_slug = params[:slug] respond_to do |format| format.html do if request.xhr? begin render :partial => "help/#{help_slug}", :layout => 'help_modal' ...
Ruby
# Author:: Miron Cuperman (mailto:miron+cms@google.com) # Copyright:: Google Inc. 2012 # License:: Apache 2.0 # Browse programs class ProgramsController < ApplicationController include ApplicationHelper include ProgramsHelper access_control :acl do allow :superuser, :admin, :analyst end layout 'dashboa...
Ruby
# Author:: Miron Cuperman (mailto:miron+cms@google.com) # Copyright:: Google Inc. 2012 # License:: Apache 2.0 class AccountsController < ApplicationController include ApplicationHelper access_control :acl do allow :superuser, :admin, :analyst end layout 'dashboard' def tooltip @account = Account.f...
Ruby
class NavigationController < ApplicationController include ApplicationHelper access_control :acl do allow :superuser, :admin, :analyst end def control_hierarchy unless session[:program_id] render :json => [] return end control_map = {} Control.where(:program_id => session[:pro...
Ruby
# Author:: Miron Cuperman (mailto:miron+cms@google.com) # Copyright:: Google Inc. 2011 # License:: Apache 2.0 # Handle data input for the testing phase of an audit class TestingController < ApplicationController include ApplicationHelper access_control :acl do allow :superuser, :admin, :analyst end befo...
Ruby
class UserSessionsController < ApplicationController before_filter :require_no_user, :only => [:new, :create] before_filter :require_user, :only => :destroy access_control :acl do allow all end def new @user_session = UserSession.new end def create @user_session = UserSession.new(params...
Ruby
# Author:: Miron Cuperman (mailto:miron+cms@google.com) # Copyright:: Google Inc. 2011 # License:: Apache 2.0 # Handle evidence collection class EvidenceController < ApplicationController include GdataHelper include DocumentHelper include EvidenceHelper include ApplicationHelper access_control :acl do ...
Ruby
class WelcomeController < ApplicationController skip_before_filter :require_user access_control :acl do allow all end def index session[:return_to] = login_dispatch_path if current_user redirect_to programs_dash_path end end def login_dispatch if current_user.nil? redirect...
Ruby
# Author:: Miron Cuperman (mailto:miron+cms@google.com) # Copyright:: Google Inc. 2012 # License:: Apache 2.0 # Programs overview class ProgramsDashController < ApplicationController include DashboardHelper layout 'dashboard' def index @programs = Program.all init_quick_find end end
Ruby
class QuickController < ApplicationController layout false def programs @programs = Program if params[:s] @programs = @programs.search(params[:s]) end @programs = @programs.all.sort_by(&:slug_split_for_sort) end def sections @sections = Section if params[:s] @sections = @se...
Ruby
# Author:: Miron Cuperman (mailto:miron+cms@google.com) # Copyright:: Google Inc. 2012 # License:: Apache 2.0 # HandleSystems class SystemsController < ApplicationController include ApplicationHelper access_control :acl do allow :superuser, :admin, :analyst end layout 'dashboard' def edit @system ...
Ruby