source
stringclasses
1 value
repo
stringlengths
5
63
repo_url
stringlengths
24
82
path
stringlengths
5
167
language
stringclasses
1 value
license
stringclasses
5 values
stars
int64
10
51.4k
ref
stringclasses
23 values
size_bytes
int64
200
258k
text
stringlengths
137
258k
github
customink/secondbase
https://github.com/customink/secondbase
secondbase.gemspec
Ruby
mit
219
master
1,254
$:.push File.expand_path('../lib', __FILE__) require 'second_base/version' Gem::Specification.new do |s| s.name = 'secondbase' s.version = SecondBase::VERSION s.platform = Gem::Platform::RUBY s.authors = ['Karle Durante', 'Hunter Madison', 'Ken Collins'] s.email = ['kdurante...
github
customink/secondbase
https://github.com/customink/secondbase
Appraisals
Ruby
mit
219
master
336
appraise 'rails40' do gem 'rails', '~> 4.0.0' gem 'mysql' end appraise 'rails41' do gem 'rails', '~> 4.1.0' gem 'mysql' end appraise 'rails42' do gem 'rails', '~> 4.2.0' gem 'mysql' end appraise 'rails50' do gem 'rails', '~> 5.0.0' gem 'mysql2' end appraise 'rails51' do gem 'rails', '~> 5.1.0' g...
github
customink/secondbase
https://github.com/customink/secondbase
test/test_helper.rb
Ruby
mit
219
master
1,155
ENV['RAILS_ENV'] ||= 'test' ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) require 'bundler/setup' Bundler.require :default, :development require 'second_base' require 'active_support/test_case' require 'active_support/testing/autorun' if Rails.version.to_i == 4 require 'dummy_apps/rails_four/...
github
customink/secondbase
https://github.com/customink/secondbase
test/dummy_apps/rails_five/config/init.rb
Ruby
mit
219
master
1,512
ENV['RAILS_ENV'] ||= 'test' ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) require 'bundler/setup' require 'rails/all' Bundler.require(:default, Rails.env) module Dummy class Application < ::Rails::Application # Basic Engine config.root = File.join __FILE__, '..', '..' confi...
github
customink/secondbase
https://github.com/customink/secondbase
test/dummy_apps/rails_five/db/secondbase/migrate/20151202075826_create_comments.rb
Ruby
mit
219
master
220
class CreateComments < ActiveRecord::Migration[4.2] def change create_table :comments, force: true do |t| t.text :body t.references :user, index: true t.timestamps null: false end end end
github
customink/secondbase
https://github.com/customink/secondbase
test/dummy_apps/rails_five/db/migrate/20141209165002_create_users.rb
Ruby
mit
219
master
200
class CreateUsers < ActiveRecord::Migration[4.2] def change create_table :users, force: true do |t| t.string :name t.string :email t.timestamps null: false end end end
github
customink/secondbase
https://github.com/customink/secondbase
test/dummy_apps/rails_five/db/migrate/20141214142700_create_posts.rb
Ruby
mit
219
master
234
class CreatePosts < ActiveRecord::Migration[4.2] def change create_table :posts, force: true do |t| t.text :title t.text :body t.references :user, index: true t.timestamps null: false end end end
github
customink/secondbase
https://github.com/customink/secondbase
test/dummy_apps/rails_four/init.rb
Ruby
mit
219
master
1,503
ENV['RAILS_ENV'] ||= 'test' ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __FILE__) require 'bundler/setup' require 'rails/all' Bundler.require(:default, Rails.env) module Dummy class Application < ::Rails::Application # Basic Engine config.root = File.join __FILE__, '..' config.cache_s...
github
customink/secondbase
https://github.com/customink/secondbase
test/dummy_apps/rails_four/db/secondbase/migrate/20151202075826_create_comments.rb
Ruby
mit
219
master
215
class CreateComments < ActiveRecord::Migration def change create_table :comments, force: true do |t| t.text :body t.references :user, index: true t.timestamps null: false end end end
github
customink/secondbase
https://github.com/customink/secondbase
test/dummy_apps/rails_four/db/migrate/20141214142700_create_posts.rb
Ruby
mit
219
master
229
class CreatePosts < ActiveRecord::Migration def change create_table :posts, force: true do |t| t.text :title t.text :body t.references :user, index: true t.timestamps null: false end end end
github
customink/secondbase
https://github.com/customink/secondbase
test/cases/forced_test.rb
Ruby
mit
219
master
1,516
require 'test_helper' class ForcedTest < SecondBase::TestCase setup do run_db :create run_db :migrate establish_connection end def test_shared_pool assert_equal SecondBase::Base.connection_pool.object_id, CommentForced.connection_pool.object_id end def test_shared_connecti...
github
customink/secondbase
https://github.com/customink/secondbase
test/cases/dbtask_test.rb
Ruby
mit
219
master
9,610
require 'test_helper' class DbTaskTest < SecondBase::TestCase def test_db_create refute_dummy_databases run_db :create assert_dummy_databases end def test_db_create_all refute_dummy_databases run_db 'create:all' assert_dummy_databases end def test_db_setup run_db :create ru...
github
customink/secondbase
https://github.com/customink/secondbase
test/cases/on_base_test.rb
Ruby
mit
219
master
885
require 'test_helper' class OnBaseTest < SecondBase::TestCase setup do run_db :create run_db :migrate establish_connection end def test_on_base refute SecondBase.is_on_base SecondBase.on_base do assert SecondBase.is_on_base assert_equal SecondBase::Base.connection.class, ActiveR...
github
customink/secondbase
https://github.com/customink/secondbase
test/cases/railtie_test.rb
Ruby
mit
219
master
783
require 'test_helper' class RailtieTest < SecondBase::TestCase def test_config expected_path = 'db/secondbase' assert_equal expected_path, railtie_inst.config.second_base.path assert_equal expected_path, railtie_klass.config.second_base.path expected_config_key = 'secondbase' assert_equal expect...
github
customink/secondbase
https://github.com/customink/secondbase
test/cases/generator_test.rb
Ruby
mit
219
master
1,885
require 'test_helper' class GeneratorTest < SecondBase::TestCase teardown do generated_migration_delete generated_migration_base_delete end def test_initialization_via_help output = Dir.chdir(dummy_root) { `rails g -h` } assert_match(/second_base\:migration/, output) end def test_descripti...
github
customink/secondbase
https://github.com/customink/secondbase
test/test_helpers/rails_version_helpers.rb
Ruby
mit
219
master
453
module SecondBase module RailsVersionHelpers extend ActiveSupport::Concern included { extend RailsVersionHelpers } private def rails_version Rails.version.to(2) end ['4.0', '4.1', '4.2', '5.0', '5.1'].each do |v| vm = v.sub '.', '' define_method :"rails_#{vm}?" do ...
github
customink/secondbase
https://github.com/customink/secondbase
test/test_helpers/stream_helpers.rb
Ruby
mit
219
master
790
module SecondBase module StreamHelpers private def silence_stream(stream) old_stream = stream.dup stream.reopen(IO::NULL) stream.sync = true yield ensure stream.reopen(old_stream) old_stream.close end def quietly silence_stream(STDOUT) do silenc...
github
customink/secondbase
https://github.com/customink/secondbase
test/test_helpers/dummy_app_helpers.rb
Ruby
mit
219
master
2,736
module SecondBase module DummyAppHelpers extend ActiveSupport::Concern private def dummy_app ::Dummy::Application end def dummy_root dummy_app.root end def dummy_config dummy_app.config end def dummy_tmp dummy_app.root.join 'tmp' end def dummy...
github
customink/secondbase
https://github.com/customink/secondbase
lib/second_base.rb
Ruby
mit
219
master
428
require 'rails' require 'active_record' require 'active_record/railtie' require 'second_base/version' require 'second_base/railtie' require 'second_base/on_base' require 'second_base/forced' module SecondBase extend ActiveSupport::Autoload autoload :Base def self.config(env = nil) config = Rails.applicati...
github
customink/secondbase
https://github.com/customink/secondbase
lib/second_base/databases.rake
Ruby
mit
219
master
6,027
namespace :db do namespace :second_base do namespace :create do desc 'Creates ALL DBs configured for Second base' unless SecondBase::Railtie.run_with_db_tasks? task :all => ['db:load_config'] do SecondBase.on_base { Rake::Task['db:create:all'].execute } end end desc 'Creates th...
github
customink/secondbase
https://github.com/customink/secondbase
lib/second_base/databases_rails_five.rake
Ruby
mit
219
master
645
namespace :db do namespace :second_base do task "drop:_unsafe" do SecondBase.on_base { Rake::Task['db:drop:_unsafe'].execute } end namespace :migrate do desc 'Resets SecondBase database using your migrations for the current environment' task :reset => ['db:second_base:drop:_unsafe', 'db...
github
customink/secondbase
https://github.com/customink/secondbase
lib/second_base/forced.rb
Ruby
mit
219
master
349
module SecondBase module Forced def connection_pool SecondBase::Base.connection_pool end def retrieve_connection SecondBase::Base.retrieve_connection end def connected? SecondBase::Base.connected? end def remove_connection(klass = self) SecondBase::Base.remove_c...
github
customink/secondbase
https://github.com/customink/secondbase
lib/second_base/railtie.rb
Ruby
mit
219
master
1,781
module SecondBase class Railtie < Rails::Railtie config.second_base = ActiveSupport::OrderedOptions.new config.second_base.path = 'db/secondbase' config.second_base.config_key = 'secondbase' config.second_base.run_with_db_tasks = true config.after_initialize do |app| secondbase_dir = app.r...
github
customink/secondbase
https://github.com/customink/secondbase
lib/second_base/on_base.rb
Ruby
mit
219
master
1,556
module SecondBase mattr_accessor :is_on_base, instance_accessor: false self.is_on_base = false def self.on_base already_on_base = is_on_base if already_on_base yield return end original_config = ActiveRecord::Tasks::DatabaseTasks.current_config original_configurations = Rails.app...
github
customink/secondbase
https://github.com/customink/secondbase
lib/second_base/test_help.rb
Ruby
mit
219
master
248
if defined?(ActiveRecord::Base) # Support test schema sync for Rails 4.2.x and up. if ActiveRecord::Migration.respond_to? :maintain_test_schema! SecondBase.on_base do ActiveRecord::Migration.maintain_test_schema! end end end
github
customink/secondbase
https://github.com/customink/secondbase
lib/second_base/databases_rails_four.rake
Ruby
mit
219
master
612
namespace :db do namespace :second_base do task :drop do SecondBase.on_base { Rake::Task['db:drop'].execute } end namespace :migrate do desc 'Resets SecondBase database using your migrations for the current environment' task :reset => ['db:second_base:drop', 'db:second_base:create', 'db...
github
customink/secondbase
https://github.com/customink/secondbase
lib/rails/second_base/generators/migration_generator.rb
Ruby
mit
219
master
798
require 'rails/generators' require 'rails/generators/active_record' require 'rails/generators/active_record/migration/migration_generator' module SecondBase class MigrationGenerator < ActiveRecord::Generators::MigrationGenerator source_root ActiveRecord::Generators::MigrationGenerator.source_root def self....
github
lifeparticle/Ruby-Cheatsheet
https://github.com/lifeparticle/Ruby-Cheatsheet
Scripts/omdbapi.rb
Ruby
mit
219
master
1,611
require 'net/http' require 'json' # http://www.omdbapi.com/ secret = "" movie_list = [ "127 Hours", "Life of Pi", "The Shallows", "The Impossible", "Buried", "Apocalypto", "Tunnel", "The Wave", "The Quake", "Thelma", "3 Idiots", "Ship of Theseus", "Zindagi Na Milegi Dobara", "Sahara", "Raiders of the Lost Ark", "Indi...
github
lifeparticle/Ruby-Cheatsheet
https://github.com/lifeparticle/Ruby-Cheatsheet
Scripts/duration_converter.rb
Ruby
mit
219
master
281
durations = [ "2:22", "1:57", "1:23", "2:39", "1:26", "2:00", "1:30", "2:13", "1:47"] durations.each do |duration| duration_array = duration.split(/:/) hour_min = duration_array[0].to_i * 60 mins = duration_array[1].to_i total_mins = hour_min + mins puts "#{total_mins}" end
github
lifeparticle/Ruby-Cheatsheet
https://github.com/lifeparticle/Ruby-Cheatsheet
Scripts/download_files.rb
Ruby
mit
219
master
1,649
require 'open-uri' fonts = [ "https://www.omicronlab.com/download/fonts/kalpurush.ttf", "https://www.omicronlab.com/download/fonts/kalpurush%20ANSI.ttf", "https://www.omicronlab.com/download/fonts/Siyamrupali.ttf", "https://www.omicronlab.com/download/fonts/Siyam%20Rupali%20ANSI.ttf", "https://www.omicronlab.com/downl...
github
lifeparticle/Ruby-Cheatsheet
https://github.com/lifeparticle/Ruby-Cheatsheet
Scripts/rm_dup_from_array.rb
Ruby
mit
219
master
425
a = [ "Drama", "Mystery", "Drama", "Mystery", "Drama", "Mystery", "Drama", "Crime", "Sci-FI", "Sci-fi", "Sci-Fi", "Disaster", "Thriller", "Action", "Drama", "Crime", "Drama", "Mystery", "Drama", "Mystery", "Drama" ] case_sensitive = a.uniq puts case_sensitive puts "\n" # Sci-FI will be in the case_insensitive array,...
github
lifeparticle/Ruby-Cheatsheet
https://github.com/lifeparticle/Ruby-Cheatsheet
Scripts/web_scraper/web_scraper.rb
Ruby
mit
219
master
970
require "selenium-webdriver" require 'uri' def init_selenium_webdriver options = Selenium::WebDriver::Chrome::Options.new options.add_argument('--headless') return Selenium::WebDriver.for :chrome, options: options end def navigate(driver, url, page_no) driver.navigate.to URI.join(url, page_no.to_s) end def get_d...
github
lifeparticle/Ruby-Cheatsheet
https://github.com/lifeparticle/Ruby-Cheatsheet
Scripts/csv/read_csv.rb
Ruby
mit
219
master
268
require 'csv' CSV.foreach("addresses.csv", headers: true) do |row| puts row['id'] puts row['location_id'] puts row['address_1'] puts row['address_2'] puts row['city'] puts row['state_province'] puts row['postal_code'] puts row['country'] puts '========' end
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
Rakefile
Ruby
apache-2.0
218
master
1,450
require "bundler/gem_tasks" require "rake/testtask" require "rake/extensiontask" require "ruby_memcheck" test_config = lambda do |t| t.pattern = "test/**/*_test.rb" end Rake::TestTask.new(&test_config) namespace :test do RubyMemcheck::TestTask.new(:valgrind, &test_config) end task default: :test Rake::Extension...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
or-tools.gemspec
Ruby
apache-2.0
218
master
615
require_relative "lib/or_tools/version" Gem::Specification.new do |spec| spec.name = "or-tools" spec.version = ORTools::VERSION spec.summary = "Operations research tools for Ruby" spec.homepage = "https://github.com/ankane/or-tools-ruby" spec.license = "Apache-2.0" spec.aut...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or-tools.rb
Ruby
apache-2.0
218
master
1,268
# ext require "or_tools/ext" # expressions require_relative "or_tools/expression" require_relative "or_tools/comparison" require_relative "or_tools/constant" require_relative "or_tools/product" require_relative "or_tools/variable" # bin packing require_relative "or_tools/knapsack_solver" # constraint require_relativ...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/cp_solver.rb
Ruby
apache-2.0
218
master
1,552
require "forwardable" module ORTools class CpSolver extend Forwardable def_delegators :@response, :objective_value, :num_conflicts, :num_branches, :wall_time def solve(model, observer = nil) @response = _solve(model, parameters, observer) @response.status end def value(var) #...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/utils.rb
Ruby
apache-2.0
218
master
2,900
module ORTools module Utils def self.index_constraint(constraint) raise ArgumentError, "Expected Comparison" unless constraint.is_a?(Comparison) left = index_expression(constraint.left, check_linear: true) right = index_expression(constraint.right, check_linear: true) const = right.delet...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/solver.rb
Ruby
apache-2.0
218
master
1,308
module ORTools class Solver def sum(arr) Expression.new(arr) end def add(expr) left, op, const = Utils.index_constraint(expr) constraint = case op when :<= self.constraint(-infinity, const) when :>= self.constraint(const, infinity) wh...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/routing_model.rb
Ruby
apache-2.0
218
master
1,049
module ORTools class RoutingModel def solve( solution_limit: nil, time_limit: nil, lns_time_limit: nil, first_solution_strategy: nil, local_search_metaheuristic: nil, log_search: nil ) search_parameters = ORTools.default_routing_search_parameters search_paramete...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/comparison.rb
Ruby
apache-2.0
218
master
339
module ORTools class Comparison attr_reader :left, :op, :right def initialize(left, op, right) @left = Expression.to_expression(left) @op = op @right = Expression.to_expression(right) end def inspect "#{@left.inspect} #{@op} #{@right.inspect}" end alias_method :to_s, ...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/tsp.rb
Ruby
apache-2.0
218
master
2,200
module ORTools class TSP attr_reader :route, :route_indexes, :distances, :total_distance DISTANCE_SCALE = 1000 DEGREES_TO_RADIANS = Math::PI / 180 def initialize(locations) raise ArgumentError, "Locations must have latitude and longitude" unless locations.all? { |l| l[:latitude] && l[:longitud...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/seating.rb
Ruby
apache-2.0
218
master
3,512
module ORTools class Seating attr_reader :assignments, :people, :total_weight def initialize(connections:, tables:, min_connections: 1) @people = connections.flat_map { |c| c[:people] }.uniq @connections_for = {} @people.each do |person| @connections_for[person] = {} end ...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/variable.rb
Ruby
apache-2.0
218
master
344
module ORTools module Variable include ExpressionMethods def inspect name end def vars @vars ||= [self] end end class MPVariable include Variable end class SatIntVar include Variable end class SatBoolVar include Variable end class RoutingIntVar inc...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/cp_solver_solution_callback.rb
Ruby
apache-2.0
218
master
456
module ORTools class CpSolverSolutionCallback attr_writer :response def value(expr) case expr when SatIntVar @response&.solution_integer_value(expr) when BoolVar @response&.solution_boolean_value(expr) else raise "Unsupported type: #{expr.class.name}" end...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/objective_solution_printer.rb
Ruby
apache-2.0
218
master
445
module ORTools class ObjectiveSolutionPrinter < CpSolverSolutionCallback attr_reader :solution_count def initialize super @solution_count = 0 @start_time = Time.now end def on_solution_callback current_time = Time.now obj = objective_value puts "Solution %i, time ...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/expression.rb
Ruby
apache-2.0
218
master
1,654
module ORTools module ExpressionMethods attr_reader :parts def +(other) Expression.new((parts || [self]) + [Expression.to_expression(other)]) end def -(other) Expression.new((parts || [self]) + [-Expression.to_expression(other)]) end def -@ -1 * self end def *(oth...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/cp_model.rb
Ruby
apache-2.0
218
master
889
module ORTools class CpModel def add(comparison) case comparison when Comparison method_name = case comparison.op when :== :add_equality when :!= :add_not_equal when :> :add_greater_than when :>= ...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/product.rb
Ruby
apache-2.0
218
master
607
module ORTools class Product < Expression attr_reader :left, :right def initialize(left, right) @left = left @right = right end def inspect if @left.is_a?(Constant) && @right.is_a?(Variable) && left.value == -1 "-#{inspect_part(@right)}" else "#{inspect_part(...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/knapsack_solver.rb
Ruby
apache-2.0
218
master
786
module ORTools class KnapsackSolver def self.new(*args) args = [:branch_and_bound, "KnapsackExample"] if args.empty? super(*args) end def solve(*args) return _solve if args.empty? values, weights, capacities = *args init(values, weights, capacities) computed_value = _...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/routing_index_manager.rb
Ruby
apache-2.0
218
master
274
module ORTools class RoutingIndexManager def self.new(num_nodes, num_vehicles, starts, ends = nil) if ends _new_starts_ends(num_nodes, num_vehicles, starts, ends) else _new_depot(num_nodes, num_vehicles, starts) end end end end
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/sudoku.rb
Ruby
apache-2.0
218
master
3,890
module ORTools class Sudoku attr_reader :solution def initialize(initial_grid, x: false, magic_square: false, anti_knight: false, anti_king: false, non_consecutive: false) raise ArgumentError, "Grid must be 9x9" unless initial_grid.size == 9 && initial_grid.all? { |r| r.size == 9 } raise Argument...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/var_array_and_objective_solution_printer.rb
Ruby
apache-2.0
218
master
575
module ORTools class VarArrayAndObjectiveSolutionPrinter < CpSolverSolutionCallback attr_reader :solution_count def initialize(variables) super() @variables = variables @solution_count = 0 @start_time = Time.now end def on_solution_callback current_time = Time.now ...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/var_array_solution_printer.rb
Ruby
apache-2.0
218
master
514
module ORTools class VarArraySolutionPrinter < CpSolverSolutionCallback attr_reader :solution_count def initialize(variables) super() @variables = variables @solution_count = 0 @start_time = Time.now end def on_solution_callback current_time = Time.now puts "Solut...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/basic_scheduler.rb
Ruby
apache-2.0
218
master
2,677
module ORTools class BasicScheduler attr_reader :assignments, :assigned_hours # for time blocks (shifts and availability) # could also use time range (starts_at..ends_at) or starts_at + duration # keep current format for now for flexibility def initialize(people:, shifts:) @shifts = shifts ...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/constant.rb
Ruby
apache-2.0
218
master
349
module ORTools class Constant < Expression attr_reader :value def initialize(value) @value = value end # simplify Ruby sum def +(other) @value == 0 ? other : super end def inspect @value.to_s end def -@ Constant.new(-value) end def vars @v...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/math_opt/variable.rb
Ruby
apache-2.0
218
master
224
module ORTools module MathOpt class Variable include ORTools::Variable def eql?(other) other.is_a?(self.class) && _eql?(other) end def hash id.hash end end end end
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
lib/or_tools/math_opt/model.rb
Ruby
apache-2.0
218
master
1,329
module ORTools module MathOpt class Model def add_linear_constraint(expr) left, op, const = Utils.index_constraint(expr) constraint = _add_linear_constraint left.each do |var, c| _set_coefficient(constraint, var, c) end case op when :<= _s...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/constraint_test.rb
Ruby
apache-2.0
218
master
7,938
require_relative "test_helper" class VarArraySolutionPrinter < ORTools::CpSolverSolutionCallback attr_reader :solution_count def initialize(variables) super() @variables = variables @solution_count = 0 end def on_solution_callback @solution_count += 1 # @variables.each do |v| # prin...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/expression_test.rb
Ruby
apache-2.0
218
master
3,615
require_relative "test_helper" class ExpressionTest < Minitest::Test def test_optimal model = ORTools::CpModel.new x = model.new_int_var(0, 1, "x") y = model.new_int_var(0, 1, "y") model.add(y == -x + 1) model.add(y == -x + 2 - 1) model.add(y * 2 == x * -2 + 2) solver = ORTools::CpSolver...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/basic_scheduler_test.rb
Ruby
apache-2.0
218
master
1,760
require_relative "test_helper" class BasicSchedulerTest < Minitest::Test def test_works people = [ { availability: [ {starts_at: Time.parse("2020-01-01 08:00:00"), ends_at: Time.parse("2020-01-01 16:00:00")}, {starts_at: Time.parse("2020-01-02 08:00:00"), ends_at: Time.parse("20...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/solution_printer_test.rb
Ruby
apache-2.0
218
master
1,889
require_relative "test_helper" class SolutionPrinterTest < Minitest::Test def test_objective_solution_printer model = ORTools::CpModel.new x = model.new_int_var(-7, 7, "x") y = model.new_int_var(0, 7, "y") model.add_max_equality(y, [x, model.new_constant(0)]) solver = ORTools::CpSolver.new s...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/integer_test.rb
Ruby
apache-2.0
218
master
751
require_relative "test_helper" class IntegerTest < Minitest::Test # https://developers.google.com/optimization/mip/mip_example def test_solver solver = ORTools::Solver.new("CBC") infinity = solver.infinity x = solver.int_var(0, infinity, "x") y = solver.int_var(0, infinity, "y") assert_equal ...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/shift_scheduling_sat_test.rb
Ruby
apache-2.0
218
master
10,829
require_relative "test_helper" class ShiftSchedulingSatTest < Minitest::Test def test_shift_scheduling_sat skip if valgrind? num_employees = 8 num_weeks = 3 shifts = %w[O M A N] # Fixed assignment: (employee, shift, day). # This fixes the first 2 days of the schedule. fixed_assignments ...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/solution_info_sat_test.rb
Ruby
apache-2.0
218
master
493
require_relative "test_helper" class SolutionInfoSat < Minitest::Test def test_solution_info_sat model = ORTools::CpModel.new x = model.new_int_var(0, 10, 'x') y = model.new_int_var(0, 10, 'y') z = model.new_int_var(0, 10, 'z') model.add_division_equality(x, y, z) solver = ORTools::CpSolve...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/scheduling_test.rb
Ruby
apache-2.0
218
master
5,958
require_relative "test_helper" class NursesPartialSolutionPrinter < ORTools::CpSolverSolutionCallback attr_reader :solution_count def initialize(shifts, num_nurses, num_days, num_shifts, solutions) super() @shifts = shifts @num_nurses = num_nurses @num_days = num_days @num_shifts = num_shifts ...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/tsp_test.rb
Ruby
apache-2.0
218
master
3,083
require_relative "test_helper" class TSPTest < Minitest::Test def test_works locations = [ {name: "Tokyo", latitude: 35.6762, longitude: 139.6503}, {name: "Delhi", latitude: 28.7041, longitude: 77.1025}, {name: "Shanghai", latitude: 31.2304, longitude: 121.4737}, {name: "São Paulo", latit...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/seating_test.rb
Ruby
apache-2.0
218
master
2,254
require_relative "test_helper" class SeatingTest < Minitest::Test def test_works connections = [ {people: ["A", "B", "C"], weight: 2}, {people: ["B", "C", "D", "E"], weight: 1} ] tables = [3, 2] seating = ORTools::Seating.new(connections: connections, tables: tables) assert_equal ["A"...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/sudoku_test.rb
Ruby
apache-2.0
218
master
3,136
require_relative "test_helper" class SudokuTest < Minitest::Test def test_works grid = [ [0, 6, 0, 0, 5, 0, 0, 2, 0], [0, 0, 0, 3, 0, 0, 0, 9, 0], [7, 0, 0, 6, 0, 0, 0, 1, 0], [0, 0, 6, 0, 3, 0, 4, 0, 0], [0, 0, 4, 0, 7, 0, 1, 0, 0], [0, 0, 5, 0, 9, 0, 8, 0, 0], [0, 4, 0...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/routing_test.rb
Ruby
apache-2.0
218
master
40,171
require_relative "test_helper" class RoutingTest < Minitest::Test # https://developers.google.com/optimization/routing/tsp def test_tsp data = {} data[:distance_matrix] = [ [0, 2451, 713, 1018, 1631, 1374, 2408, 213, 2571, 875, 1420, 2145, 1972], [2451, 0, 1745, 1524, 831, 1240, 959, 2596, 403,...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/linear_test.rb
Ruby
apache-2.0
218
master
4,638
require_relative "test_helper" class LinearTest < Minitest::Test # https://developers.google.com/optimization/lp/lp_example def test_solver solver = ORTools::Solver.new("GLOP") x = solver.num_var(0, solver.infinity, "x") y = solver.num_var(0, solver.infinity, "y") assert_equal 2, solver.num_variab...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/assignment_test.rb
Ruby
apache-2.0
218
master
5,398
require_relative "test_helper" class AssignmentTest < Minitest::Test # https://developers.google.com/optimization/assignment/assignment_example def test_assignment # create the data costs = [ [90, 80, 75, 70], [35, 85, 55, 65], [125, 95, 90, 95], [45, 110, 95, 115], [50, 100, ...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/test_helper.rb
Ruby
apache-2.0
218
master
775
require "bundler/setup" Bundler.require(:default) require "minitest/autorun" require "stringio" require "time" class Minitest::Test def setup @output = StringIO.new(+"") @output_checked = false GC.stress = true if stress? end def teardown GC.stress = false if stress? if !@output.string.emp...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/examples_test.rb
Ruby
apache-2.0
218
master
8,653
require_relative "test_helper" class WeddingChartPrinter < ORTools::CpSolverSolutionCallback attr_reader :num_solutions def initialize(seats, names, num_tables, num_guests) super() @num_solutions = 0 @start_time = Time.now @seats = seats @names = names @num_tables = num_tables @num_gue...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/bin_packing_test.rb
Ruby
apache-2.0
218
master
6,593
require_relative "test_helper" class BinPackingTest < Minitest::Test # https://developers.google.com/optimization/bin/knapsack def test_knapsack_simple values = [ 360, 83, 59, 130, 431, 67, 230, 52, 93, 125, 670, 892, 600, 38, 48, 147, 78, 256, 63, 17, 120, 164, 432, 35, 92, 110, 22, 42, 50, 323, 5...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/math_opt_test.rb
Ruby
apache-2.0
218
master
2,526
require_relative "test_helper" class MathOptTest < Minitest::Test # https://developers.google.com/optimization/math_opt/basic_example def test_basic model = ORTools::MathOpt::Model.new("getting_started_lp") x = model.add_variable(-1.0, 1.5, "x") y = model.add_variable(0.0, 1.0, "y") model.add_linea...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/network_flows_test.rb
Ruby
apache-2.0
218
master
3,841
require_relative "test_helper" class NetworkFlowsTest < Minitest::Test # https://developers.google.com/optimization/flow/maxflow def test_max_flow start_nodes = [0, 0, 0, 1, 1, 2, 2, 3, 3] end_nodes = [1, 2, 3, 2, 4, 3, 4, 2, 4] capacities = [20, 30, 10, 40, 30, 10, 20, 5, 20] max_flow = ORTools::...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
test/assumptions_sample_sat_test.rb
Ruby
apache-2.0
218
master
728
require_relative "test_helper" class AssumptionsSampleSat < Minitest::Test def test_assumptions_sample_sats model = ORTools::CpModel.new x = model.new_int_var(0, 10, 'x') y = model.new_int_var(0, 10, 'y') z = model.new_int_var(0, 10, 'z') a = model.new_bool_var('a') b = model.new_bool_var('b...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
ext/or-tools/vendor.rb
Ruby
apache-2.0
218
master
4,657
require "digest" require "fileutils" require "open-uri" require "tmpdir" version = "9.15.6755" arch = RbConfig::CONFIG["host_cpu"] arm = arch.match?(/arm|aarch64/i) if RbConfig::CONFIG["host_os"].match?(/darwin/i) if arm filename = "or-tools_arm64_macOS-26.2_cpp_v#{version}.tar.gz" checksum = "de0400a45939...
github
ankane/or-tools-ruby
https://github.com/ankane/or-tools-ruby
ext/or-tools/extconf.rb
Ruby
apache-2.0
218
master
1,136
require "mkmf-rice" $CXXFLAGS << " -std=c++17 $(optflags) -DUSE_CBC -DOR_PROTO_DLL=" # show warnings $CXXFLAGS << " -Wall -Wextra" # hide or-tools warnings $CXXFLAGS << " -Wno-sign-compare -Wno-ignored-qualifiers -Wno-unused-parameter -Wno-missing-field-initializers -Wno-deprecated-declarations" # hide Rice warning...
github
basecamp/easymon
https://github.com/basecamp/easymon
Gemfile
Ruby
mit
218
master
350
source "https://rubygems.org" # Declare your gem's dependencies in easymon.gemspec. # Bundler will treat runtime dependencies like base dependencies, and # development dependencies will be added by default to the :development group. gemspec gem "rubocop-37signals", github: "basecamp/house-style", require: false gem "...
github
basecamp/easymon
https://github.com/basecamp/easymon
easymon.gemspec
Ruby
mit
218
master
1,112
$:.push File.expand_path("../lib", __FILE__) # Maintain your gem's version: require "easymon/version" # Describe your gem and declare its dependencies: Gem::Specification.new do |s| s.name = "easymon" s.version = Easymon::VERSION s.authors = [ "Nathan Anderson" ] s.email = [ "nathan@basec...
github
basecamp/easymon
https://github.com/basecamp/easymon
Rakefile
Ruby
mit
218
master
798
#!/usr/bin/env rake begin require 'bundler/setup' rescue LoadError puts 'You must `gem install bundler` and `bundle install` to run rake tasks' end begin require 'rdoc/task' rescue LoadError require 'rdoc/rdoc' require 'rake/rdoctask' RDoc::Task = Rake::RDocTask end RDoc::Task.new(:rdoc) do |rdoc| rdoc.r...
github
basecamp/easymon
https://github.com/basecamp/easymon
config/routes.rb
Ruby
mit
218
master
203
# use `mount Easymon::Engine => "/up"` in the host application routes.rb if Gem::Version.new(Rails.version) >= Gem::Version.new("3.1") Easymon::Engine.routes.draw do Easymon.routes(self) end end
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon.rb
Ruby
mit
218
master
2,648
if Gem::Version.new(Rails.version) >= Gem::Version.new("3.0") require "easymon/engine" end require "easymon/checklist" require "easymon/repository" require "easymon/result" require "easymon/checks/active_record_check" require "easymon/checks/active_record_mysql_writeable_check" require "easymon/checks/multi_active...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/checklist.rb
Ruby
mit
218
master
1,629
require "benchmark" module Easymon class Checklist extend Forwardable def_delegators :@items, :size, :include?, :empty? attr_accessor :items attr_accessor :results def initialize(items = {}) self.items = items self.results = {} end def check self.results = items.injec...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/engine.rb
Ruby
mit
218
master
212
module Easymon class Engine < ::Rails::Engine # Rails Engines weren't isolated until v3.1 if Gem::Version.new(Rails.version) >= Gem::Version.new("3.1") isolate_namespace Easymon end end end
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/result.rb
Ruby
mit
218
master
758
module Easymon class Result attr_accessor :success attr_accessor :message attr_accessor :timing attr_accessor :critical def initialize(result, timing, is_critical = false) self.success = result[0] self.message = result[1] self.timing = timing self.critical = is_critical ...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/testing.rb
Ruby
mit
218
master
360
module Easymon module Testing extend self def stub_check(name) Easymon.const_get("#{name.to_s.capitalize}Check").any_instance.stubs(:check) end def stub_service_success(name) stub_check(name).returns([ true, "Up" ]) end def stub_service_failure(name) stub_check(name).retur...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/repository.rb
Ruby
mit
218
master
702
module Easymon class Repository attr_reader :repository def self.fetch(name) repository.fetch(name) rescue IndexError raise NoSuchCheck, "No check named '#{name}'" end def self.all Checklist.new repository end def self.names repository.keys end def self....
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/checks/active_record_check.rb
Ruby
mit
218
master
456
module Easymon class ActiveRecordCheck attr_accessor :klass def initialize(klass) self.klass = klass end def check check_status = database_up? if check_status message = "Up" else message = "Down" end [ check_status, message ] end private ...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/checks/redis_check.rb
Ruby
mit
218
master
639
require "redis" module Easymon class RedisCheck attr_accessor :config def initialize(config) self.config = config end def check check_status = redis_up? if check_status message = "Up" else message = "Down" end [ check_status, message ] end ...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/checks/http_check.rb
Ruby
mit
218
master
785
require "net/https" module Easymon class HttpCheck attr_accessor :url def initialize(url) self.url = url end def check check_status = http_up?(url) if check_status message = "Up" else message = "Down" end [ check_status, message ] end pri...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/checks/traffic_enabled_check.rb
Ruby
mit
218
master
263
module Easymon class TrafficEnabledCheck < SemaphoreCheck def check check_status = semaphore_exists? if check_status message = "ENABLED" else message = "DISABLED" end [ check_status, message ] end end end
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/checks/multi_active_record_check.rb
Ruby
mit
218
master
1,467
module Easymon class MultiActiveRecordCheck attr_accessor :block attr_accessor :results # Here we pass a block so we get a fresh instance of ActiveRecord::Base or # whatever other class we might be using to make database connections # # For example, given the following other class: # modu...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/checks/semaphore_check.rb
Ruby
mit
218
master
501
module Easymon class SemaphoreCheck attr_accessor :file_name def initialize(file_name) self.file_name = file_name end def check check_status = semaphore_exists? if check_status message = "#{file_name} is in place!" else message = "#{file_name} does not exist!"...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/checks/split_active_record_check.rb
Ruby
mit
218
master
1,307
module Easymon class SplitActiveRecordCheck attr_accessor :block attr_accessor :results # Here we pass a block so we get a fresh instance of ActiveRecord::Base or # whatever other class we might be using to make database connections # # For example, given the following other class: # modu...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/checks/active_record_mysql_writeable_check.rb
Ruby
mit
218
master
561
module Easymon class ActiveRecordMysqlWriteableCheck attr_accessor :klass def initialize(klass) self.klass = klass @query = "SELECT @@read_only for UPDATE" end def check check_status = database_writeable? if check_status message = "@@read_only is 0" else ...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/checks/memcached_check.rb
Ruby
mit
218
master
466
module Easymon class MemcachedCheck attr_accessor :cache def initialize(cache) self.cache = cache end def check check_status = memcached_up? if check_status message = "Up" else message = "Down" end [ check_status, message ] end private ...
github
basecamp/easymon
https://github.com/basecamp/easymon
lib/easymon/checks/redis_writeable_check.rb
Ruby
mit
218
master
717
require "redis" module Easymon class RedisWriteableCheck attr_accessor :config def initialize(config) self.config = config end def check check_status = redis_writeable? message = check_status ? "Writeable" : "Read Only" [ check_status, message ] end private d...