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
contentful-labs/gqli.rb
https://github.com/contentful-labs/gqli.rb
lib/gqli/validation.rb
Ruby
mit
210
master
6,047
# frozen_string_literal: true module GQLi # Validations class Validation attr_reader :schema, :root, :errors def initialize(schema, root) @schema = schema @root = root @errors = [] validate end # Returns wether the query is valid or not def valid? errors.empty? ...
github
contentful-labs/gqli.rb
https://github.com/contentful-labs/gqli.rb
lib/gqli/introspection.rb
Ruby
mit
210
master
2,129
# frozen_string_literal: true require_relative './dsl' require_relative './validation' module GQLi # Introspection schema and validator class Introspection extend DSL # Specific type kind introspection fragment TypeRef = fragment('TypeRef', '__Type') { kind name ofType { kin...
github
contentful-labs/gqli.rb
https://github.com/contentful-labs/gqli.rb
lib/gqli/clients/github.rb
Ruby
mit
210
master
416
# frozen_string_literal: true module GQLi # Module for creating a Github GraphQL client module Github # Creates a Github GraphQL client def self.create(access_token, validate_query: true) GQLi::Client.new( 'https://api.github.com/graphql', headers: { 'Authorization' => "Bear...
github
contentful-labs/gqli.rb
https://github.com/contentful-labs/gqli.rb
lib/gqli/clients/contentful.rb
Ruby
mit
210
master
616
# frozen_string_literal: true module GQLi # Module for creating a Contentful GraphQL client module Contentful # Creates a Contentful GraphQL client def self.create(space, access_token, environment: nil, validate_query: true, options: {}) api_url = "https://graphql.contentful.com/content/v1/spaces/#{s...
github
contentful-labs/gqli.rb
https://github.com/contentful-labs/gqli.rb
spec/spec_helper.rb
Ruby
mit
210
master
533
require 'simplecov' SimpleCov.start require 'rspec' require 'vcr' Dir[File.join('..', File.dirname(__FILE__), 'lib', '**', '*.rb')].each { |f| require f } require 'gqli' RSpec.configure do |config| config.filter_run :focus => true config.run_all_when_everything_filtered = true end VCR.configure do |c| c.cass...
github
contentful-labs/gqli.rb
https://github.com/contentful-labs/gqli.rb
spec/lib/gqli/dsl_spec.rb
Ruby
mit
210
master
10,641
require 'spec_helper' class MockGQLInterface include GQLi::DSL end describe GQLi::DSL do subject { described_class } describe 'module level methods' do describe '::query' do it 'can create a query without name' do query = subject.query { someField } expect(query).to...
github
contentful-labs/gqli.rb
https://github.com/contentful-labs/gqli.rb
spec/lib/gqli/response_spec.rb
Ruby
mit
210
master
1,376
require 'spec_helper' describe GQLi::Response do let(:errors) { nil } let(:data) { {"testkey" => "test val"} } let(:query) { double(:query) } subject { described_class.new(data, errors, query) } describe "#data" do it "returns correct data Hashie" do expect(subject.data).to be_kind_of(Hashie::Mash...
github
contentful-labs/gqli.rb
https://github.com/contentful-labs/gqli.rb
spec/lib/gqli/introspection_spec.rb
Ruby
mit
210
master
10,751
require 'spec_helper' describe GQLi::Introspection do let(:dsl) { GQLi::DSL } let(:client) do vcr('client') { space_id = 'cfexampleapi' token = 'b4c0n73n7fu1' GQLi::Contentful.create(space_id, token) } end subject { client.schema } describe 'introspection schema' do it 'querie...
github
contentful-labs/gqli.rb
https://github.com/contentful-labs/gqli.rb
spec/lib/gqli/client_spec.rb
Ruby
mit
210
master
4,646
require 'spec_helper' describe GQLi::Client do let(:space_id) { 'cfexampleapi' } let(:token) { 'b4c0n73n7fu1' } let(:default_timeout) { 60 } let(:timeout) { 10 } let(:client) do vcr('client') { GQLi::Contentful.create(space_id, token) } end let(:client_no_validations) do vcr('client')...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
tracking_number.gemspec
Ruby
mit
210
main
2,502
# frozen_string_literal: true lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'tracking_number/version' Gem::Specification.new do |s| s.name = 'tracking_number' s.version = TrackingNumber::VERSION s.platform = Gem::Platform::RUBY s.required_rubygems_versi...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
Rakefile
Ruby
mit
210
main
603
# frozen_string_literal: true require 'rubygems' require 'bundler' Bundler::GemHelper.install_tasks require 'rake' require 'rake/testtask' Rake::TestTask.new(:test) do |test| test.libs << 'lib' << 'test' test.pattern = 'test/**/*_test.rb' test.verbose = true end task default: :test require 'rdoc/task' RDoc::T...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
test/tracking_number_test.rb
Ruby
mit
210
main
8,285
require 'test_helper' class TrackingNumberTest < Minitest::Test context "a tracking number" do should "return unknown when given invalid number" do t = TrackingNumber.new("101") assert_equal TrackingNumber::Unknown, t.class assert_equal :unknown, t.carrier assert_equal :unknown, t.courier...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
test/test_helper.rb
Ruby
mit
210
main
2,013
require 'simplecov' SimpleCov.start require 'rubygems' require 'minitest/autorun' require 'minitest/reporters' require 'shoulda' require 'active_model' $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'tracking_number' Minitest::Reporters.use! [Mini...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
test/active_model_validator_test.rb
Ruby
mit
210
main
1,037
require 'test_helper' class TrackingNumberValidatorTest < Minitest::Test class Validatable include ActiveModel::Validations attr_accessor :tracking_number ERROR_MESSAGE = "must be valid, or 'magic' to prevent inclusion in confirmation email" validates :tracking_number, :presence => true, ...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
test/tracking_number_meta_test.rb
Ruby
mit
210
main
5,830
require 'test_helper' def load_courier_data(name = :all) if name == :all Dir.glob(File.join(File.dirname(__FILE__), "../lib/data/couriers/*.json")).collect do |file| JSON.parse(File.read(file)).deep_symbolize_keys! end else return JSON.parse(File.join(File.dirname(__FILE__), "../lib/data/couriers...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
lib/tracking_number.rb
Ruby
mit
210
main
1,688
# Identify if tracking numbers are valid, and which service they belong to require 'json' require 'tracking_number/checksum_validations' require 'tracking_number/loader' require 'tracking_number/base' require 'tracking_number/info' require 'tracking_number/partnership' require 'tracking_number/unknown' require 'active...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
lib/tracking_number/checksum_validations.rb
Ruby
mit
210
main
3,176
module TrackingNumber module ChecksumValidations class << self def validates_s10?(sequence, check_digit, extras = {}) weighting = [8,6,4,2,3,5,9,7] total = 0 sequence.chars.to_a.zip(weighting).each do |(a,b)| total += a.to_i * b.to_i end remainder = total ...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
lib/tracking_number/base.rb
Ruby
mit
210
main
8,962
module TrackingNumber class Base attr_accessor :tracking_number, :original_number, :partner, :partner_data PartnerStruct = Struct.new(:shipper, :carrier) def initialize(tracking_number) @original_number = tracking_number @tracking_number = tracking_number.strip.gsub(' ', '').upcase end ...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
lib/tracking_number/unknown.rb
Ruby
mit
210
main
494
module TrackingNumber class Unknown < Base COURIER_CODE = :unknown def carrier COURIER_CODE end def courier_name "Unknown" end def valid? false end def valid_format? false end def valid_checksum? false end def shipper? false ...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
lib/tracking_number/info.rb
Ruby
mit
210
main
499
module TrackingNumber class Info def initialize(info_hash = {}) info_hash.keys.each do |key| self.instance_variable_set("@#{key}", info_hash[key]) self.class_eval { attr_accessor key } end if info_hash.keys.size == 1 @default = info_hash[info_hash.keys.first] end ...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
lib/tracking_number/active_model_validator.rb
Ruby
mit
210
main
473
class TrackingNumberValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) return unless value.present? if options[:exception] == value || options[:except] == value # magic valid value (an exception that says "not really shipped" or something) elsif TrackingNumber.new(val...
github
jkeen/tracking_number
https://github.com/jkeen/tracking_number
lib/tracking_number/loader.rb
Ruby
mit
210
main
2,883
module TrackingNumber module Loader class << self def load_tracking_number_data(couriers_path = File.join(File.dirname(__FILE__), '../data/couriers/')) mapping_data = [] tracking_number_types = [] Dir.glob(File.join(couriers_path, '/*.json')).each do |file| courier_info = r...
github
avdi/hammertime
https://github.com/avdi/hammertime
hammertime.gemspec
Ruby
mit
209
master
1,858
# Generated by jeweler # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = "hammertime" s.version = "0.0.3" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubyg...
github
avdi/hammertime
https://github.com/avdi/hammertime
Rakefile
Ruby
mit
209
master
1,598
require 'rubygems' require 'rake' begin require 'jeweler' Jeweler::Tasks.new do |gem| gem.name = "hammertime" gem.summary = %Q{Exception debugging console for Ruby} gem.description = <<END When this library is required, it replaces the default Ruby exception-raising behavior. When an error is raised, ...
github
avdi/hammertime
https://github.com/avdi/hammertime
example.rb
Ruby
mit
209
master
261
require 'lib/hammertime' $broken = true def faulty_method raise "Oh no!" if $broken end 3.times do |n| puts "Attempt (#{n+1}/3)" begin faulty_method puts "No error raised" rescue => error puts "Error raised: #{error.inspect}" end end
github
avdi/hammertime
https://github.com/avdi/hammertime
examples/loaderror.rb
Ruby
mit
209
master
306
# IN A WORLD... where ruby-debug and IRB is not in the load # path... one man will raise an exception. require 'rubygems' require '../lib/hammertime' # Clear out load path. Now LoadError will be raised when # Hammertime tries to load IRB or the debugger. $:.clear include Hammertime raise "Holy smokes!"
github
avdi/hammertime
https://github.com/avdi/hammertime
lib/hammertime.rb
Ruby
mit
209
master
4,238
require 'thread' require 'highline' module Hammertime def self.ignored_errors @ignored_errors ||= [LoadError] end def self.ignored_lines @ignored_lines ||= [] end def self.stopped @stopped ||= false end def self.stopped=(value) @stopped = value end def self.debug_supported? re...
github
avdi/hammertime
https://github.com/avdi/hammertime
spec/hammertime_spec.rb
Ruby
mit
209
master
204
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe "Hammertime" do it "fails" do fail "hey buddy, you should probably rename this file and start specing for real" end end
github
avdi/hammertime
https://github.com/avdi/hammertime
spec/spec_helper.rb
Ruby
mit
209
master
212
$LOAD_PATH.unshift(File.dirname(__FILE__)) $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) require 'hammertime' require 'spec' require 'spec/autorun' Spec::Runner.configure do |config| end
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch07/student1.rb
Ruby
mit
210
master
7,468
$:.unshift File.join(File.dirname(__FILE__), '..', 'ch05') $:.unshift File.join(File.dirname(__FILE__), '..', 'ch06') require 'eliza1' require 'pat_read' require 'pat_match' Pattern.match_abbrev(:"?x*", %w(?* ?x)) Pattern.match_abbrev(:"?y*", %w(?* ?y)) def exp_rhs(exp) exp[2] end def exp_op(exp) exp[1] end de...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/problem7.rb
Ruby
mit
210
master
434
require 'gps' gps = GPS.new([:son_at_home, :car_needs_battery, :have_money], GPS::SCHOOL_OPS + [ GPS::Op.new(:ask_phone_number, [:in_communication_with_shop], [:know_phone_number], ...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/gps2_problem1.rb
Ruby
mit
210
master
222
require 'gps2' require 'pp' gps = GPS2.new([:son_at_home, :car_needs_battery, :have_money, :have_phone_book], GPS::SCHOOL_OPS) pp gps.solve(:son_at_school)
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/maze.rb
Ruby
mit
210
master
693
require 'gps2' require 'pp' module Maze class << self def make_ops(pair) [make_op(pair[0], pair[1]), make_op(pair[1], pair[0])] end def make_op(here, there) GPS2::op([:move, :from, here, :to, there], :preconds => [[:at, here]], :add_list => [[:at, there]]...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/problem6.rb
Ruby
mit
210
master
271
require 'gps_no_clobber' gps = GPS.new([:son_at_home, :car_needs_battery, :have_phone_book, :have_money], GPS::SCHOOL_OPS) if gps.solve(:have_money, :son_at_school) puts "Solved" else puts "Not solved" end
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/blocks_problem1.rb
Ruby
mit
210
master
305
require 'blocks' require 'pp' gps = GPS2.new([[:a, :on, :table], [:b, :on, :table], [:space, :on, :a], [:space, :on, :b], [:space, :on, :table]], Blocks.make_ops([:a, :b])) pp gps.solve([:a, :on, :b], [:b, :on, :table])
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/find_path.rb
Ruby
mit
210
master
497
require 'maze' require 'gps3' module Maze class << self def find_path(start, finish) results = GPS2.new([[:at, start]], Maze::Ops). solve([:at, finish]) unless results.empty? [start] + ((results - [[:start]]).map do |action| destination(action) end) end end...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/gps.rb
Ruby
mit
210
master
2,053
class GPS Op = Struct.new(:action, :preconds, :add_list, :del_list) def initialize(state, ops) @state = state @ops = ops end # General Problem Solver main interface: achieve all goals using # defined operations def solve(*goals) goals.all? do |goal| achieve goal end end # A ...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/blocks_problem3.rb
Ruby
mit
210
master
295
require 'blocks' require 'pp' gps = GPS2.new([[:a, :on, :b], [:b, :on, :c], [:c, :on, :table], [:space, :on, :a], [:space, :on, :table]], Blocks.make_ops([:a, :b, :c])) pp gps.solve([:c, :on, :b], [:b, :on, :a])
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/problem4.rb
Ruby
mit
210
master
220
require 'gps' gps = GPS.new([:son_at_home, :have_money, :car_works], GPS::SCHOOL_OPS) if gps.solve(:have_money, :son_at_school) puts "Solved" else puts "Not solved" end
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/problem5.rb
Ruby
mit
210
master
260
require 'gps' gps = GPS.new([:son_at_home, :car_needs_battery, :have_phone_book, :have_money], GPS::SCHOOL_OPS) if gps.solve(:have_money, :son_at_school) puts "Solved" else puts "Not solved" end
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/gps2_problem3.rb
Ruby
mit
210
master
233
require 'gps2' require 'pp' gps = GPS2.new([:son_at_home, :car_needs_battery, :have_money, :have_phone_book], GPS::SCHOOL_OPS) pp gps.solve(:have_money, :son_at_school)
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/blocks_problem2.rb
Ruby
mit
210
master
246
require 'blocks' require 'pp' gps = GPS2.new([[:a, :on, :b], [:b, :on, :table], [:space, :on, :a], [:space, :on, :table]], Blocks.make_ops([:a, :b])) pp gps.solve([:b, :on, :a])
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/gps2_problem7.rb
Ruby
mit
210
master
557
require 'gps3' require 'pp' gps = GPS2.new([:son_at_home, :have_money, :have_works], GPS::SCHOOL_OPS + [ GPS2::op(:taxi_son_to_school, :preconds => [:son_at_home, :have_money...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/problem1.rb
Ruby
mit
210
master
249
require 'gps' gps = GPS.new([:son_at_home, :car_needs_battery, :have_money, :have_phone_book], GPS::SCHOOL_OPS) if gps.solve(:son_at_school) puts "Solved" else puts "Not solved" end
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/gps2.rb
Ruby
mit
210
master
1,702
require 'gps' require 'gps_no_clobber' require 'dbg' module Enumerable def some? self.each do |v| result = yield v return result if result end end end class GPS::Op def convert! unless self.add_list.any? do |l| l.is_a?(Array) && l.first == :executing end self.add_li...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/blocks_problem6.rb
Ruby
mit
210
master
378
require 'blocks' require 'pp' gps = GPS2.new([[:c, :on, :a], [:a, :on, :table], [:b, :on, :table], [:space, :on, :c], [:space, :on, :b], [:space, :on, :table]], Blocks.make_ops([:a, :b, :c])) pp gps.solve([:a, :on, :b], ...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/gps3.rb
Ruby
mit
210
master
243
require 'gps2' class GPS2 def action?(x) x == [:start] || (x.is_a?(Array) && x.first == :executing) end def solve(*goals) achieve_all([[:start]] + @state, goals, []).find_all do |state| action?(state) end end end
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/problem2.rb
Ruby
mit
210
master
216
require 'gps' gps = GPS.new([:son_at_home, :car_needs_battery, :have_money], GPS::SCHOOL_OPS) if gps.solve(:son_at_school) puts "Solved" else puts "Not solved" end
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/gps2_problem4.rb
Ruby
mit
210
master
233
require 'gps2' require 'pp' gps = GPS2.new([:son_at_home, :car_needs_battery, :have_money, :have_phone_book], GPS::SCHOOL_OPS) pp gps.solve(:son_at_school, :have_money)
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/blocks_problem5.rb
Ruby
mit
210
master
339
require 'blocks' require 'pp' gps = GPS2.new([[:c, :on, :a], [:a, :on, :table], [:b, :on, :table], [:space, :on, :b], [:space, :on, :c], [:space, :on, :table]], Blocks.make_ops([:a, :b, :c])) pp gps.solve([:c, :on, :tabl...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/blocks_problem4.rb
Ruby
mit
210
master
324
require 'blocks' require 'pp' gps = GPS2.new([[:c, :on, :a], [:a, :on, :table], [:b, :on, :table], [:space, :on, :b], [:space, :on, :c], [:space, :on, :table]], Blocks.make_ops([:a, :b, :c])) pp gps.solve([:c, :on, :tabl...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/dbg.rb
Ruby
mit
210
master
346
$dbg_ids = [] def dbg(id, format, *args) if $dbg_ids.include?(id) $stderr.puts(format%args) end end def debug(*ids) $dbg_ids = ($dbg_ids + ids).uniq end def undebug(*ids) $dbg_ids -= ids end def dbg_indent(id, indent, format, *args) if $dbg_ids.include?(id) $stderr.print " "*indent $stderr.pu...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/gps2_monkey1.rb
Ruby
mit
210
master
1,773
require 'gps2' require 'pp' $banana_ops = [ GPS2::op(:climb_on_chair, :preconds => [:chair_at_middle_room, :at_middle_room, :on_floor], :add_list => [:at_bananas, :on_chair], ...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/blocks.rb
Ruby
mit
210
master
865
require 'gps3' module Blocks class << self def make_ops(blocks) ops = [] blocks.each do |a| blocks.each do |b| unless a == b blocks.each do |c| unless [a, b].include?(c) ops << move_op(a, b, c) end end o...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch04/gps_no_clobber.rb
Ruby
mit
210
master
448
require 'gps' class Array def subset_of?(other) (self - other) == [] end end class GPS def solve(*goals) achieve_all goals end def apply(op) if achieve_all(op.preconds) puts "Executing #{op.action}" @state -= op.del_list @state += op.add_list return true end fa...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/plan_flight2.rb
Ruby
mit
210
master
1,864
require 'plan_flight' class Path attr_accessor :state, :previous, :cost_so_far, :total_cost def initialize(state = nil, previous = nil, cost_so_far = 0, total_cost = 0) self.state = state self.previous = previous self.cost_so_far = cost_so_far s...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/beam_search.rb
Ruby
mit
210
master
780
require 'guiding' module Search class << self def beam(start, successors, cost_fn, beam_width, &goal_p) tree_search([start], successors, proc do |old, new| sorted = sorter(&cost_fn)[old,new] if beam_width > sorted.length sorted ...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/a_star.rb
Ruby
mit
210
master
2,113
require 'graph_search' module Search class << self def a_star(paths, successors, cost_fn, cost_left_fn, state_eq = proc { |a, b| a == b}, old_paths = [], &goal_p) dbg :search, ";; Search: %s", paths retur...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/search_gps.rb
Ruby
mit
210
master
1,146
$:.unshift '../ch04' require 'gps3' require 'blocks' require 'beam_search' class GPS2 def successors(state) applicable_ops(state).map do |op| state.select do |x| !op.del_list.include?(x) end + op.add_list end end def applicable_ops(state) @ops.select do |op| op.preconds.su...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/search_all.rb
Ruby
mit
210
master
435
require 'beam_search' module Search class << self def all(start, successors, cost_fn, beam_width, &goal_p) solutions = [] beam(start, successors, cost_fn, beam_width, &(proc do |x| ...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/search.rb
Ruby
mit
210
master
1,087
$:.unshift '../ch04' require 'dbg' module Search class << self def tree_search(states, successors, combiner, &goal_p) dbg :search, ";; Search %p", states return nil if !states || states.empty? if goal_p[states.first] states.first else tree_search(combiner[successors[states...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/plan_flight.rb
Ruby
mit
210
master
2,225
require 'beam_search' City = Struct.new(:name, :long, :lat) class City CITIES = [ ['Atlanta', 84.23, 33.45], ['Boston', 71.05, 42.21], ['Chicago', 87.37, 41.50], ['Denver', 105.00, 39.45], ['Eugene', 123.05, 44.03], ['Flagstaff', 111.41, 35....
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/inter.rb
Ruby
mit
210
master
571
def interactive_interpreter(prompt) while true print prompt puts(yield(gets)) end end def ruby interactive_interpreter '> ' do |str| eval(str) end end $:.unshift '../ch05' require 'eliza2' def eliza interactive_interpreter 'eliza> ' do |str| Eliza.eliza_rule(str.downcase.split, ...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/inter2.rb
Ruby
mit
210
master
615
def interactive_interpreter(prompt, transformer = nil, &block) transformer ||= (block || proc { |arg| arg }) while true begin case prompt when String print prompt when Proc prompt.call end puts(transformer[ge...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/guiding.rb
Ruby
mit
210
master
855
require 'search' module Search class << self def diff(num) lambda do |x| (x - num).abs end end def sorter(&cost_fn) lambda do |new, old| (new + old).sort_by do |n| cost_fn[n] end end end def best_first(start, successors, cost_f...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/pat_match.rb
Ruby
mit
210
master
4,203
class Pattern def initialize(pattern) @pattern = pattern end def match(input, bindings = {}, pattern = @pattern) case when !bindings nil when variable?(pattern) match_variable(pattern, input, bindings) when pattern == input bindings when segment_pattern?(pattern) s...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/pat_read.rb
Ruby
mit
210
master
959
# Allows translation from strings like this: # I think that (?is ?n numberp) flurg # into something like this: # ["I", "think", "that", ["?is", "?n", "numberp"], "flurg"] class Pattern def initialize(pattern) @pattern = pattern end class << self def from_string(str) result = [] str.scan(/...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/graph_search.rb
Ruby
mit
210
master
1,277
require 'iter_widening' module Search class << self def graph(states, successors, combiner, state_eq = proc{ |a, b| a == b}, old_states = [], &goal_p) dbg :search, ";; Search: %p", states return nil if states.empty? retu...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch06/iter_widening.rb
Ruby
mit
210
master
605
require 'plan_flight2' module Search class << self def iter_wide(start, successors, cost_fn, width = 1, max = 100, &goal_p) dbg :search, "; Width: %d", width unless width > max beam(start, successors, cost_fn, width, &goal_p) || iter_wi...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch05/pat4.rb
Ruby
mit
210
master
1,283
require 'pat3' class Pattern # Match pattern against input in the context of the bindings def match(input, variables = {}, pattern = @pattern) case when variables.nil? nil when variable?(pattern) match_variable(pattern, input, variables) when pattern == input variables when se...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch05/pat5.rb
Ruby
mit
210
master
558
require 'pat4' class Pattern def match_segment(pattern, input, bindings, start = 0) var = "?#{pattern[0][1..-1]}" pat = pattern[1..-1] if pat.nil? || pat.empty? match_variable(var, input, bindings) else pos = input[start..-1].index(pat[0]) return nil unless pos b2 = match(inp...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch05/pat2.rb
Ruby
mit
210
master
563
require 'enumerator' class Pattern def initialize(pattern) @pattern = pattern.map do |p| variable?(p) ? p : p.downcase end end # Does pattern match input? Any variable can match anything def match(input, variables = [], pattern = @pattern) pattern.enum_for(:zip, input).all? do |p, i| ...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch05/pat3.rb
Ruby
mit
210
master
573
require 'pat2' class Pattern # Match pattern against input in the context of the bindings def match(input, variables = {}, pattern = @pattern) pattern.enum_for(:zip, input).all? do |p, i| match_recurse(p, i, variables) || match_variable(p, i, variables) || p == i end && variables en...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch05/eliza1.rb
Ruby
mit
210
master
2,329
require 'pat5' module Enumerable def some? self.each do |v| result = yield v return result if result end nil end end class Array def random_elt self[rand(self.length)] end end class Rule attr_reader :pattern, :responses def initialize(pattern, *responses) @pattern, @respo...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch05/pat.rb
Ruby
mit
210
master
496
require 'enumerator' class Pattern def initialize(pattern) @pattern = pattern.map do |p| variable?(p) ? p : p.downcase end end # Does pattern match input? Any variable can match anything def match(input, pattern = @pattern) pattern.enum_for(:zip, input).all? do |p, i| (p.is_a?(Array...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch05/eliza2.rb
Ruby
mit
210
master
6,325
require 'eliza1' class Rule ELIZA_RULES2 = ELIZA_RULES + [ Rule.new(Pattern.new(%w(*x computer *y)), "Do computers worry you?", "What do you think about machines?", "Why do you mention computers", "What do you think machines have to do with your probl...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch02/bigger_grammar.rb
Ruby
mit
210
master
612
require 'rule_based' $bigger_grammar = { :sentence => [[:noun_phrase, :verb_phrase]], :noun_phrase => [[:Article, :'Adj*', :Noun, :'PP*'], [:Name], [:Pronoun]], :verb_phrase => [[:Verb, :noun_phrase, :'PP*']], :'PP*' => [[], [:PP, :'PP*']], :'Adj*' => [[], [:Adj, :'Adj*']], :PP => [[:Prep, :noun_phrase]],...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch02/generate_all.rb
Ruby
mit
210
master
401
require 'rule_based' def generate_all(phrase) case phrase when [] [[]] when Array combine_all(generate_all(phrase[0]), generate_all(phrase[1..-1])) when Symbol rewrites(phrase).inject([]) { |sum, elt| sum + generate_all(elt) } else [[phrase]] end end def combine_all(xlist,...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch02/generate_tree.rb
Ruby
mit
210
master
225
require 'bigger_grammar' def generate_tree(phrase) case phrase when Array phrase.map { |elt| generate_tree(elt) } when Symbol [phrase] + generate_tree(rewrites(phrase).random_elt) else [phrase] end end
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch02/rule_based.rb
Ruby
mit
210
master
684
require 'common' # A grammar for a trivial subset of English $simple_grammar = { :sentence => [[:noun_phrase, :verb_phrase]], :noun_phrase => [[:Article, :Noun]], :verb_phrase => [[:Verb, :noun_phrase]], :Article => %w(the a), :Noun => %w(man ball woman table), :Verb => %w(hit took saw liked)} # The gram...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch02/simple2.rb
Ruby
mit
210
master
332
require 'simple' def adj_star return [] if rand(2) == 0 adj + adj_star end def pp_star return [] if rand(2) == 0 pp + pp_star end def noun_phrase; article + adj_star + noun + pp_star; end def pp; prep + noun_phrase; end def adj; one_of %w(big little blue green adiabatic); end def prep; one_of %w(to in by wit...
github
olabini/paipr
https://github.com/olabini/paipr
lib/ch02/simple.rb
Ruby
mit
210
master
268
require 'common' def sentence; noun_phrase + verb_phrase; end def noun_phrase; article + noun; end def verb_phrase; verb + noun_phrase; end def article; one_of %w(the a); end def noun; one_of %w(man ball woman table); end def verb; one_of %w(hit took saw liked); end
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
.deep_cover.rb
Ruby
mit
210
master
474
# frozen_string_literal: true # This file is executed only when deep_cover is covering itself. DeepCover.configure do tracker_global '$_dcg' ignore_uncovered :warn, :raise, :default_argument # Statement analyser is only used for Istanbul output and is undertested. # Ignore for now. TODO: test this, or get rid...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
Rakefile
Ruby
mit
210
master
2,684
# frozen_string_literal: true ### Release tasks namespace :global do require 'bundler/gem_tasks' end namespace :core do Bundler::GemHelper.install_tasks(dir: Pathname.pwd.join('core_gem')) desc 'Compile sass stylesheet' task 'sass' do require 'sass' dest = "#{__dir__}/core_gem/lib/deep_cover/reporter/...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
Gemfile
Ruby
mit
210
master
574
# frozen_string_literal: true source 'https://rubygems.org' git_source(:github) { |repo_name| "https://github.com/#{repo_name}" } # Specify your gem's dependencies in deep_cover.gemspec gemspec eval_gemfile File.expand_path('Gemfile.local', __dir__) if File.exist?('Gemfile.local') # This is a workaround for rubymi...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
deep_cover.gemspec
Ruby
mit
210
master
1,572
# frozen_string_literal: true require_relative 'core_gem/lib/deep_cover/version' Gem::Specification.new do |spec| spec.name = 'deep-cover' spec.version = DeepCover::VERSION spec.authors = ['Marc-André Lafortune', 'Maxime Lapointe'] spec.email = ['github@marc-andre.ca', 'hunter_spa...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/bin_spec.rb
Ruby
mit
210
master
440
# frozen_string_literal: true require_relative 'spec_helper' RSpec.describe 'bin/cov', :slow do params_sets = ['case 0', 'exception_ensure 0', 'if 0'] params_sets.each do |params_set| it "run `bin/cov #{params_set}` successfully" do command_success = clean_env_system({'DISABLE_PRY' => '1'}, "bin/cov #...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/cli_spec.rb
Ruby
mit
210
master
10,595
# frozen_string_literal: true require_relative 'spec_helper' module DeepCover RSpec.describe 'CLI', :slow do let(:expected_errors) { /^$/ } let(:expected_status) { 0 } let(:options) { '' } let(:path) { 'covered_trivial_gem' } let(:full_path) { "spec/code_fixtures/#{path}" } let(:extra) { '' ...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/simple_rails42_app/Gemfile
Ruby
mit
210
master
1,517
source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.10' # Use sqlite3 as the database for Active Record gem 'sqlite3', '~> 1.3.6', platform: :ruby # 1.3 is for Rails < 5.0 gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3.25', platform: :jruby # Use SCSS for s...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/simple_rails42_app/test/models/user_test.rb
Ruby
mit
210
master
227
require 'test_helper' class UserTest < ActiveSupport::TestCase def test_foo u = User.new(name: 'hi') assert_equal 42, u.foo end def test_hello u = User.new(name: 'hi') assert_equal 42, u.baz end end
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/simple_rails42_app/db/schema.rb
Ruby
mit
210
master
938
# This file is auto-generated from the current state of the database. Instead # of editing this file, please use the migrations feature of Active Record to # incrementally modify your database, and then regenerate this schema definition. # # Note that this schema.rb definition is the authoritative source for your # dat...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/simple_rails42_app/config/application.rb
Ruby
mit
210
master
1,123
require File.expand_path('../boot', __FILE__) require 'rails/all' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module SimpleRails42App class Application < Rails::Application # Settings in config/environments/* t...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/covered_trivial_gem/covered_trivial_gem.gemspec
Ruby
mit
210
master
1,022
# coding: utf-8 lib = File.expand_path("../lib", __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "covered_trivial_gem/version" Gem::Specification.new do |spec| spec.name = "covered_trivial_gem" spec.version = CoveredTrivialGem::VERSION spec.authors = ["Marc-Andre La...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/covered_trivial_gem/Gemfile
Ruby
mit
210
master
240
source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } gem 'deep-cover', path: File.expand_path(__dir__ + '/../../../') # Specify your gem's dependencies in covered_trivial_gem.gemspec gemspec
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/covered_trivial_gem/spec/spec_helper.rb
Ruby
mit
210
master
396
require "bundler/setup" require "deep-cover" require "covered_trivial_gem" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure config.example_status_persistence_file_path = ".rspec_status" # Disable RSpec exposing methods globally on `Module` and `main` config.disable_monkey_pat...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/covered_trivial_gem/spec/trivial_gem_spec.rb
Ruby
mit
210
master
335
require "spec_helper" RSpec.describe CoveredTrivialGem do it "has a version number" do expect(CoveredTrivialGem::VERSION).not_to be nil end it "does something useful" do expect(CoveredTrivialGem.hello).to eq(:world) end it "runs a bunch of branches" do expect(CoveredTrivialGem.branches(1)).to e...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/covered_trivial_gem/lib/covered_trivial_gem.rb
Ruby
mit
210
master
561
require_relative "covered_trivial_gem/version" module CoveredTrivialGem def self.hello 'hello' && :world end def self.branches(used = 42, unused = 666) if true 42 end if false 42 end (1..2).each do |i| if i == 1 42 else 43 end end if ...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/rails_like_gem/Gemfile
Ruby
mit
210
master
454
source "https://rubygems.org" git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } if ENV["DEEP_COVER"] # Not in clone mode # Because we use a relative path for the tests, we can't leave it there in clone mode as this directory # gets moved around then bundler gets mad that it can't find the gem...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/rails_like_gem/rails_like_gem.gemspec
Ruby
mit
210
master
1,070
# coding: utf-8 version = File.read(File.expand_path("RAILS_LIKE_VERSION", __dir__)).strip Gem::Specification.new do |spec| spec.name = "rails_like_gem" spec.version = version spec.authors = ["Marc-Andre Lafortune"] spec.email = ["github@marc-andre.ca"] spec.summary = %q{R...
github
deep-cover/deep-cover
https://github.com/deep-cover/deep-cover
spec/code_fixtures/rails_like_gem/Rakefile
Ruby
mit
210
master
421
FRAMEWORKS = %w[component_gem another_component_gem] desc "Run all tests by default" task default: %w(spec) %w(spec).each do |task_name| desc "Run #{task_name} task for all projects" task task_name do errors = [] FRAMEWORKS.each do |project| system(%(cd #{project} && #{$0} #{task_name} --trace)) ||...