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 | wycats/merb-extlib | https://github.com/wycats/merb-extlib | spec/hash_spec.rb | Ruby | mit | 19 | master | 16,266 | require File.dirname(__FILE__) + '/spec_helper'
require "date"
require 'bigdecimal'
describe Hash, "environmentize_keys!" do
it "should transform keys to uppercase text" do
{ :test_1 => 'test', 'test_2' => 'test', 1 => 'test' }.environmentize_keys!.should ==
{ 'TEST_1' => 'test', 'TEST_2' => 'test', '1' =... |
github | wycats/merb-extlib | https://github.com/wycats/merb-extlib | spec/string_spec.rb | Ruby | mit | 19 | master | 4,213 | require File.dirname(__FILE__) + '/spec_helper'
describe String, "#to_const_string" do
it "swaps slashes with ::" do
"foo/bar".to_const_string.should == "Foo::Bar"
end
it "replaces snake_case with CamelCase" do
"foo/bar/baz_bat".to_const_string.should == "Foo::Bar::BazBat"
end
it "leaves constant s... |
github | wycats/merb-extlib | https://github.com/wycats/merb-extlib | spec/object_spec.rb | Ruby | mit | 19 | master | 3,982 | require File.dirname(__FILE__) + '/spec_helper'
class Foo
end
describe Object do
it "should treat an empty string as blank" do
"".should be_blank
end
it "should treat a string with just spaces as blank" do
" ".should be_blank
end
it "should treat an empty array as blank" do
[].should be_blan... |
github | wycats/merb-extlib | https://github.com/wycats/merb-extlib | spec/time_spec.rb | Ruby | mit | 19 | master | 454 | require File.dirname(__FILE__) + '/spec_helper'
require 'json'
describe Time, "#to_json" do
before do
@expected = "\"2008-03-28T22:54:20Z\""
end
it "should transform itself into a ISO 8601 compatible string" do
Time.utc(2008, 3, 28, 22, 54, 20).to_json.should == @expected
Time.xmlschema("2008-0... |
github | wycats/merb-extlib | https://github.com/wycats/merb-extlib | spec/set_spec.rb | Ruby | mit | 19 | master | 523 | require File.dirname(__FILE__) + '/spec_helper'
describe Merb::SimpleSet do
before do
@s = Merb::SimpleSet.new("Foo")
end
it "should support <<" do
@s << "Hello"
@s.should be_include("Hello")
end
it "should support merge" do
@s.should include("Foo")
@t = @s.merge(["Bar"])
@t.... |
github | hibariya/ruremai | https://github.com/hibariya/ruremai | ruremai.gemspec | Ruby | mit | 19 | master | 816 | # -*- encoding: utf-8 -*-
require File.expand_path('../lib/ruremai/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ['hibariya']
gem.email = ['hibariya@gmail.com']
gem.description = %q{Object.method(:name).rurema!}
gem.summary = %q{Open ruby reference manual by browser.}
... |
github | hibariya/ruremai | https://github.com/hibariya/ruremai | lib/ruremai.rb | Ruby | mit | 19 | master | 689 | require 'launchy'
require 'ruremai/version'
require 'ruremai/ext/method'
require 'ruremai/ext/object'
module Ruremai
autoload :Locator, 'ruremai/locator'
autoload :Mean, 'ruremai/mean'
class NoReferenceManualFound < StandardError; end
class << self
attr_writer :locators
def launch(method)
i... |
github | hibariya/ruremai | https://github.com/hibariya/ruremai | lib/ruremai/locator.rb | Ruby | mit | 19 | master | 1,003 | require 'uri'
require 'net/http'
module Ruremai
module Locator
autoload :Rurema, 'ruremai/locator/rurema'
class Base
class << self
def locate(method)
new(method).located
end
end
attr_reader :name, :receiver, :owner
def initialize(method)
@method ... |
github | hibariya/ruremai | https://github.com/hibariya/ruremai | lib/ruremai/mean.rb | Ruby | mit | 19 | master | 207 | class Ruremai::Mean
attr_accessor :receiver
def initialize(receiver)
@receiver = receiver
end
def method_missing(method_name, *args, &block)
@receiver.method(method_name).rurema!
end
end |
github | hibariya/ruremai | https://github.com/hibariya/ruremai | lib/ruremai/ext/object.rb | Ruby | mit | 19 | master | 220 | require 'ruremai/mean'
class Object
def mean?(*args)
if args.empty?
return Ruremai::Mean.new(self)
else
args.each do |method|
self.method(method.to_sym).rurema!
end
end
end
end |
github | hibariya/ruremai | https://github.com/hibariya/ruremai | lib/ruremai/locator/rurema.rb | Ruby | mit | 19 | master | 958 | require 'cgi'
module Ruremai
module Locator
class Rurema < Base
URI_BASE = 'https://docs.ruby-lang.org/ja/'
major, minor, teeny = *RUBY_VERSION.split('.').map(&:to_i)
PATH_VERSION_PART = [major, minor, major >= 2 ? 0 : teeny].join(".")
def candidates
method_owner.ancestors.inject... |
github | hibariya/ruremai | https://github.com/hibariya/ruremai | spec/locator/rurema_spec.rb | Ruby | mit | 19 | master | 2,071 | require 'spec_helper'
describe Ruremai::Locator::Rurema do
describe '#candidates' do
PATH_VERSION_PART = (/\A1\./ =~ RUBY_VERSION ? RUBY_VERSION : RUBY_VERSION[/\A\d+\.\d+/] + ".0").freeze
let(:locator) { Ruremai::Locator::Rurema.new(target) }
subject { locator.candidates.map(&:to_s) }
describe 'Ca... |
github | feedbin/opml_saw | https://github.com/feedbin/opml_saw | Rakefile | Ruby | mit | 19 | master | 211 | #!/usr/bin/env rake
require "bundler/gem_tasks"
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << "test"
t.test_files = FileList['test/**/*_test.rb']
t.verbose = true
end
task :default => :test |
github | feedbin/opml_saw | https://github.com/feedbin/opml_saw | opml_saw.gemspec | Ruby | mit | 19 | master | 737 | # -*- encoding: utf-8 -*-
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'opml_saw/version'
Gem::Specification.new do |gem|
gem.name = "opml_saw"
gem.version = OpmlSaw::VERSION
gem.authors = ["Ben Ubois"]
gem.email = ["ben... |
github | feedbin/opml_saw | https://github.com/feedbin/opml_saw | test/opml_saw/parser_test.rb | Ruby | mit | 19 | master | 433 | require "test_helper"
require "pp"
class ParserTest < Test::Unit::TestCase
def setup
sample_opml = File.join(File.expand_path(File.dirname(File.dirname(__FILE__))), 'sample_opml')
file = File.open(File.join(sample_opml, 'subscriptions_with_folder.xml'), 'r')
@opml = OpmlSaw::Parser.new(file.read)
@op... |
github | feedbin/opml_saw | https://github.com/feedbin/opml_saw | lib/opml_saw/parser.rb | Ruby | mit | 19 | master | 765 | module OpmlSaw
class Parser
attr_reader :feeds
def initialize(xml)
@xml = xml
@feeds = []
end
def document
@document ||= Nokogiri::XML.parse(@xml).css("body").children
end
def has_children?(node)
node.children.length > 0
end
def is_outlin... |
github | feedbin/opml_saw | https://github.com/feedbin/opml_saw | lib/opml_saw/outline.rb | Ruby | mit | 19 | master | 699 | module OpmlSaw
class Outline
attr_reader :hash
def initialize(node, tag)
@node = node
@tag = tag
@hash = {}
end
def to_hash
@node.attributes.each do |attribute|
key = underscore(attribute[0]).to_sym
@hash[key] = @node.attr(attribute[0])
e... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | Rakefile | Ruby | mit | 19 | master | 1,450 | require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |s|
s.name = "statisticus"
s.summary = %Q{Statistics in Ruby through RSRuby, but more graceful.}
s.email = "davidlamontrichards@gmail.com"
s.homepage = "http://github.com/davidrichards/statisticus"
s.description = "Statisticus is a be... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | statisticus.gemspec | Ruby | mit | 19 | master | 1,942 | # -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{statisticus}
s.version = "0.3.8"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["David Richards"]
s.date = %q{2009-04-29}
s.default_executable = %q{stats}
s.descripti... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | features/steps/statisticus_steps.rb | Ruby | mit | 19 | master | 287 | Given /^a class, GeometricMean$/ do
class GeometricMean; include Statisticus end
@klass = GeometricMean
@params = [1,2,3]
@lib_name = 'geometric_mean.r'
end
When /^I call it$/ do
@result = @klass.call(@params)
end
Then /^it uses code from (.+)$/ do |lib_name|
pending
end |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | spec/statisticus_spec.rb | Ruby | mit | 19 | master | 2,001 | require File.dirname(__FILE__) + '/spec_helper'
describe "Statisticus" do
it "should require rubygems" do
defined?(Gem).should eql('constant')
end
it "should require activesupport" do
defined?(ActiveSupport).should eql('constant')
end
it "should require rsruby" do
defined?(RSRuby).should... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | spec/lib/overrides/symbol_spec.rb | Ruby | mit | 19 | master | 1,010 | require File.join(File.dirname(__FILE__), "/../../spec_helper")
describe Symbol do
it "should have a shortcut for to_proc" do
[1,2,3].map(&:succ).should eql([2,3,4])
end
it "should have [], which is a method to call :some_method on SomeObject" do
creator = :new[Array]
# Longhand
creator.c... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | spec/lib/overrides/hash_spec.rb | Ruby | mit | 19 | master | 2,095 | require File.join(File.dirname(__FILE__), "/../../spec_helper")
describe Hash do
it "should infuse_with defaults" do
h = {:this => :that}.infuse_with({:this => 1, :that => 1})
h[:this].should eql(:that)
end
end
# class Hash
# # Maybe I need some aliases so that this makes more sense.
# # But, an infu... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | spec/lib/overrides/tegu_gears_spec.rb | Ruby | mit | 19 | master | 270 | require File.join(File.dirname(__FILE__), "/../../spec_helper")
describe TeguGears do
it "should convert a Range to an Array" do
class A
include Statisticus
def process(x)
x
end
end
A.call(1..3).should eql([1,2,3])
end
end |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | spec/lib/overrides/array_spec.rb | Ruby | mit | 19 | master | 330 | require File.join(File.dirname(__FILE__), "/../../spec_helper")
describe Array do
it "should be able to use a list of parameters for include?" do
[1,2,3].include?(1, 2).should be_true
end
it "should be able to convert values to symbols" do
%w(one two three).to_sym.should eql([:one, :two, :three])
en... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | spec/lib/overrides/module_spec.rb | Ruby | mit | 19 | master | 1,036 | require File.join(File.dirname(__FILE__), "/../../spec_helper")
describe Module do
it "should have alias_method_chain" do
class A
def go
'go'
end
def go_with_flair
go_without_flair + " flair"
end
alias_method_chain :go, :flair
end
a = A.new
a.go.should eq... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | lib/statisticus.rb | Ruby | mit | 19 | master | 4,344 | require 'rubygems'
require 'activesupport'
require 'rsruby'
require 'log4r'
begin
require 'tegu_gears'
rescue Exception => e
false
end
require File.expand_path(File.join(File.dirname(__FILE__), 'overrides'))
module Statisticus
# Use log4r for my logging.
Log = Log4r::Logger.new("statisticus")
Log.add Log4... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | lib/overrides/tegu_gears.rb | Ruby | mit | 19 | master | 672 | module TeguGears::Memoize::InstanceMethods
def function(*x)
x = infer_r_values(*x)
self.memoize ? memoized(*x) : process(*x)
end
def infer_r_values(*x)
x.inject([]) { |list, e| list << infer_r_value(e) }
end
private :infer_r_values
# Come up with any modifications that should be general an... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | lib/overrides/hash.rb | Ruby | mit | 19 | master | 1,760 | class Hash
# Maybe I need some aliases so that this makes more sense.
# But, an infusion enhances or adds to the base. This method
# will usually be used in the initialize methods of classes,
# or in similar circumstances. Here, it is important to keep
# the explicit parameters, but to infuse them with some... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | lib/overrides/rs_ruby.rb | Ruby | mit | 19 | master | 650 | class RSRuby
class << self
# def RSRuby.convert_method_name(name)
# if name.length > 1 and name[-1].chr == '_' and name[-2].chr != '_'
# name = name[0..-2]
# end
# name.gsub!(/__/,'<-')
# name.gsub!(/_/, '.')
# return name
# end
alias :orig_convert_method_name :conver... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | lib/overrides/symbol.rb | Ruby | mit | 19 | master | 1,434 | class Symbol
def to_proc
lambda {|receiver, *args| receiver.method(self)[*args]}
end
# Add [] and []= operators to the Symbol class for accessing and setting
# singleton methods of objects. Read : as "method" and [] as "of".
# So :m[o] reads "method m of o".
# Return the Method of obj named by this sy... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | lib/overrides/array.rb | Ruby | mit | 19 | master | 255 | class Array
def to_sym
map {|a| a.to_s.underscore.to_sym }
end
alias :single_include? :include?
# Adjusted to see if all values are included.
def include?(*args)
args.inject(true) {|val, x| val = self.single_include?(x)}
end
end |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | lib/overrides/module.rb | Ruby | mit | 19 | master | 2,569 | class Module
# Stolen wholesale out of active_support. I didn't want the whole gem
# in this gem.
def alias_method_chain(target, feature)
# Strip out punctuation on predicates or bang methods since
# e.g. target?_without_feature is not a valid method name.
aliased_target, punctuation = target.to_s.s... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | lib/featured_libs/distributions.rb | Ruby | mit | 19 | master | 8,309 | class BetaDistribution
include Statisticus
def process(shape1, shape2)
r.dbeta(shape1, shape2)
end
end
class BetaProbability
include Statisticus
def process(shape1, shape2)
r.pbeta(shape1, shape2)
end
end
class BetaQuantile
include Statisticus
def process(shape1, shape2)
r.qbeta(shape1,... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | examples/fishers_f.rb | Ruby | mit | 19 | master | 713 | # Sets up a two-tailed Fishers F test on two lists. This tests whether
# the variance of the two samples are the same. The p value will return
# this number. You should reject the NULL hypothesis if p < 0.025,
# typically, and conclude that the variances are different.
class FishersF
include Statisticus
def run... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | examples/t_test.rb | Ruby | mit | 19 | master | 730 | # Sets up a two-tailed Student's T test. Basically, if the variance in
# the samples is acceptable (Fisher's F), and the p value of this test
# is below some threshold (0.05), then we reject the null hypothesis and
# conclude that the mean of the two samples are significantly different.
class TTest
include Stati... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | examples/inverse_matrix.rb | Ruby | mit | 19 | master | 418 | # This creates an inverse of a matrix (A^-1) that is:
# 1) square
# 2) with |A| != 0
class InverseMatrix
include Statisticus
# For now, I'm converting a list into a square matrix.
# TODO: Make this more general.
def run(list, rows)
raise "Cannot make a square matrix out of #{list.size} elements and #{... |
github | davidrichards/statisticus | https://github.com/davidrichards/statisticus | examples/wilcox.rb | Ruby | mit | 19 | master | 847 | # This is similar to the Student's T Test, except that it is used for
# data such as ranks (ordinal data). Basically, if the variance in
# the samples is acceptable (Fisher's F), and the p value of this test
# is below some threshold (0.05), then we reject the null hypothesis and
# conclude that the mean of the two s... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | revolve.rb | Ruby | mit | 19 | master | 626 | module Revolve end
require File.join(File.dirname(__FILE__), "lib", "erk")
require File.join(File.dirname(__FILE__), "lib", "variable")
require File.join(File.dirname(__FILE__), "lib", "argument")
require File.join(File.dirname(__FILE__), "lib", "method")
require File.join(File.dirname(__FILE__), "lib", "program")
r... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | examples/subtraction.rb | Ruby | mit | 19 | master | 1,397 | require File.join(File.dirname(__FILE__), "..", "revolve")
class Integer
def protected_division(divisor)
return 1 if divisor == 0
self / divisor
end
end
def cases(num, step, first, second)
(1..num).map do |i|
lambda do |program|
my_first = first + step*i
program.run( Revolve::Argument.ne... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | examples/polynomial.rb | Ruby | mit | 19 | master | 1,271 | require File.join(File.dirname(__FILE__), "..", "revolve")
class Integer
def protected_division(divisor)
return 1 if divisor == 0
self / divisor
end
end
def cases(num, value)
(1..num).map do |i|
lambda do |program|
argument = value + i*2
program.run( Revolve::Argument.new(:x, argument) )... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | examples/variable.rb | Ruby | mit | 19 | master | 1,417 | require File.join(File.dirname(__FILE__), "..", "revolve")
class Integer
def protected_division(divisor)
return 1 if divisor == 0
self / divisor
end
end
# x
population = Revolve::Population.initialized( 200, {
:size_limit => 20,
:instructions => [ Revolve::ERK.new(-5, -4, -3, -2, -1, 1, 2, 3, 4, 5),... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | examples/trivariate.rb | Ruby | mit | 19 | master | 1,493 | require File.join(File.dirname(__FILE__), "..", "revolve")
class Integer
def protected_division(divisor)
return 1 if divisor == 0
self / divisor
end
end
def cases(num, value)
(1..num).map do |i|
lambda do |program|
argument = value + i
program.run( Revolve::Argument.new(:x, argument), Re... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | examples/increment_cubed.rb | Ruby | mit | 19 | master | 1,335 | require File.join(File.dirname(__FILE__), "..", "revolve")
puts "Warning: This converges but takes long due to cubic operations."
class Integer
def protected_division(divisor)
return 1 if divisor == 0
self / divisor
end
end
def cases(num, value)
(1..num).map do |i|
lambda do |program|
a... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | examples/squared.rb | Ruby | mit | 19 | master | 1,243 | require File.join(File.dirname(__FILE__), "..", "revolve")
class Integer
def protected_division(divisor)
return 1 if divisor == 0
self / divisor
end
end
def cases(num, value)
(1..num).map do |i|
lambda do |program|
argument = value + i
program.run( Revolve::Argument.new(:x, argument) ).t... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | examples/constant.rb | Ruby | mit | 19 | master | 951 | require File.join(File.dirname(__FILE__), "..", "revolve")
class Integer
def protected_division(divisor)
return 1 if divisor == 0
self / divisor
end
end
# 120
population = Revolve::Population.initialized( 200, {
:size_limit => 20,
:instructions => [ Revolve::ERK.new(-5, -4, -3, -2, -1, 1, 2, 3, 4, 5... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | examples/constant_multiplication.rb | Ruby | mit | 19 | master | 1,251 | require File.join(File.dirname(__FILE__), "..", "revolve")
class Integer
def protected_division(divisor)
return 1 if divisor == 0
self / divisor
end
end
def cases(num, value)
(1..num).map do |i|
lambda do |program|
argument = value + i
program.run( Revolve::Argument.new(:x, argument) ).t... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/spec_helper.rb | Ruby | mit | 19 | master | 385 | Spec::Runner.configure do |config|
config.mock_with :mocha
end
require File.join(File.dirname(__FILE__), "..", "revolve") unless defined? Revolve
def new_population(options={})
Revolve::Population.initialized(options.delete(:size) || 3,
{:instructions => ["kitteh", 2, 8, Revolve::Method.new(:+)],
:ge... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/argument/value_spec.rb | Ruby | mit | 19 | master | 254 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Argument, "#value" do
before { @argument = Argument.new(:x, 1337) }
it "should be the initialized object" do
@argument.value.should == 1337
end
end
end |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/argument/inspect_spec.rb | Ruby | mit | 19 | master | 295 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Argument, "#inspect" do
before { @argument = Argument.new(:x, 1337) }
it "should be the name and value wrapped in 'argument'" do
@argument.inspect.should == "(:x => 1337 argument)"
end
end
end |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/argument/name_spec.rb | Ruby | mit | 19 | master | 250 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Argument, "#name" do
before { @argument = Argument.new(:x, 1337) }
it "should be the initialized symbol" do
@argument.name.should == :x
end
end
end |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/erk/value_spec.rb | Ruby | mit | 19 | master | 311 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe ERK, "#value" do
before do
@instructions = [1, 2, 3]
@erk = ERK.new(*@instructions)
end
it "should return one of its initialized instructions" do
@instructions.should include(@erk.value)
end
end
end |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/erk/new_spec.rb | Ruby | mit | 19 | master | 219 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe ERK, ".new" do
before { @erk = ERK.new }
it "should be a kind of Array" do
@erk.should be_kind_of(Array)
end
end
end |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/method/name_spec.rb | Ruby | mit | 19 | master | 236 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Method, "#name" do
before { @method = Method.new(:+) }
it "should be the initialized symbol" do
@method.name.should == :+
end
end
end |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/method/callable_spec.rb | Ruby | mit | 19 | master | 1,302 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Method, "#callable?, without a stack" do
before { @method = Method.new(:+) }
it "should be false" do
@method.should_not be_callable
end
end
describe Method, "#callable?, with a stack" do
before do
@method = Meth... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/method/inspect_spec.rb | Ruby | mit | 19 | master | 259 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Method, "#inspect" do
before { @method = Method.new(:+) }
it "should be the name wrapped in 'method'" do
@method.inspect.should == "(:+ method)"
end
end
end |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/method/call_spec.rb | Ruby | mit | 19 | master | 932 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Method, "#call!" do
before do
@method = Method.new(:+)
end
describe "with arity of 0" do
before do
@method.name = :next
@method.stack = ["kitteh", 1336]
end
it "should return ... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/program/new_spec.rb | Ruby | mit | 19 | master | 407 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Program, ".new" do
it "should be a kind of Array" do
Program.new.should be_kind_of(Array)
end
it "should contain any values given" do
Program.new(3).first.should == 3
end
it "should pick a value from an ER... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/program/run_spec.rb | Ruby | mit | 19 | master | 1,434 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Program, "#run" do
describe "with objects" do
before { @program = Program.new(4) }
it "should return the object on top of the stack" do
@program.run.should == 4
end
it "should empty the stack" do
... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/program/crossover_spec.rb | Ruby | mit | 19 | master | 633 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Program, "#crossover" do
before do
@parent = Program.new(1, 2, 3, 4, 5)
@mate = Program.new("one", "two", "three", "four", "five")
@child = @parent.crossover(@mate)
end
it "should produce a new Program" do
... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/program/mutate_spec.rb | Ruby | mit | 19 | master | 1,213 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Program, "#mutate" do
describe "with an ERK" do
before do
@parent = Program.new(1, 2, 3, 4, 5)
@instructions = [1337]
@child = @parent.mutate(@instructions, 20)
end
it "should produce a new Progra... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/program/randomized_spec.rb | Ruby | mit | 19 | master | 1,096 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Program, ".randomized" do
describe "without an ERK" do
before do
@instructions = ["kitteh", Method.new(:+), " "]
@program = Program.randomized(4, @instructions)
end
it "should be of length s... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/variable/inspect_spec.rb | Ruby | mit | 19 | master | 271 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Variable, "#inspect" do
before { @variable = Variable.new(:x) }
it "should be the name wrapped in 'variable'" do
@variable.inspect.should == "(:x variable)"
end
end
end |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/variable/name_spec.rb | Ruby | mit | 19 | master | 244 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Variable, "#name" do
before { @variable = Variable.new(:x) }
it "should be the initialized symbol" do
@variable.name.should == :x
end
end
end |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/population/select_program_spec.rb | Ruby | mit | 19 | master | 1,482 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Population, "#select_program" do
before do
fitness_cases = [lambda {|program| program.run.to_i - 10 }]
error_function = lambda{|cases| cases.first.abs }
@population = new_population(:size => 0, :fitnes... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/population/evolve_spec.rb | Ruby | mit | 19 | master | 1,209 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Population, "#evolve!" do
before do
error_function = lambda{|cases| cases.inject{|x, y| x.abs + y.abs } }
@population = new_population(
:size => 7,
:size_limit => 10,
:generations_limit => 2,
:in... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/population/error_spec.rb | Ruby | mit | 19 | master | 1,048 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Population, "#error" do
before do
fitness_cases = [lambda {|program| program.run.to_i - 10 }]
error_function = lambda{|cases| cases.first.abs }
@population = new_population(:size => 0, :fitness_cases =... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/population/evolve_generation_spec.rb | Ruby | mit | 19 | master | 2,136 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Population, "#evolve_generation!" do
before do
error_function = lambda{|cases| cases.first.abs }
@population = new_population(
:size => 7,
:size_limit => 10,
:instructions => [1, 2, 3,
... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/population/initialized_spec.rb | Ruby | mit | 19 | master | 2,023 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Population, ".initialized" do
before do
@population = new_population(:size => 3, :generations_limit => 20, :size_limit => 10)
end
it "should be generation 0" do
@population.generation.should == 0
end
it "s... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/population/elitism_spec.rb | Ruby | mit | 19 | master | 1,061 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Population, "#elitism" do
before do
error_function = lambda{|cases| cases.first.abs }
@population = new_population(
:size => 0,
:fitness_cases => [ lambda{|program| program.run - 10 } ],
:error_functio... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | spec/population/update_fittest_spec.rb | Ruby | mit | 19 | master | 1,248 | require File.join(File.dirname(__FILE__), "..", "spec_helper")
module Revolve
describe Population, "#update_fittest!" do
before do
fitness_cases = [lambda {|program| program.run.to_i - 10 }]
error_function = lambda{|cases| cases.first.abs }
@population = new_population(:size => 0, :fitness_cases =... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | lib/argument.rb | Ruby | mit | 19 | master | 249 | module Revolve
class Argument
attr_accessor :name, :value
def initialize(name, value)
@name, @value = name, value
end
def inspect
"(:#{name} => #{value} argument)"
end
alias_method :to_s, :inspect
end
end |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | lib/population.rb | Ruby | mit | 19 | master | 3,344 | module Revolve
class Population < Array
attr_accessor :generation, :error_memory, :fittest
def initialize(*args)
@generation = 0
@error_memory = {}
block_given? ? super(*args) : super(args)
end
SUPPORTED_PARAMETERS = {:size_limit => nil, :instructions => nil, :generations_limit ... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | lib/variable.rb | Ruby | mit | 19 | master | 207 | module Revolve
class Variable
attr_accessor :name
def initialize(name)
@name = name
end
def inspect
"(:#{name} variable)"
end
alias_method :to_s, :inspect
end
end |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | lib/program.rb | Ruby | mit | 19 | master | 1,668 | # TODO: pass in stack copy for thread safety
module Revolve
class Program < Array
attr_accessor :stack
def initialize(*args)
@stack = []
result = block_given? ? super(*args) : super(args)
result.each_with_index{|instruction, index| result[index] = instruction.value if instruction.is_a?(ERK) ... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | lib/method.rb | Ruby | mit | 19 | master | 554 | module Revolve
class Method
attr_accessor :name, :stack
def initialize(name)
@name = name
end
def callable?
return false unless stack
stack.first.respond_to?(name) && (stack.size - 1 >= stack.first.method(name).arity)
end
def call!
target = stack.pop
argumen... |
github | larrytheliquid/revolve | https://github.com/larrytheliquid/revolve | lib/erk.rb | Ruby | mit | 19 | master | 213 | module Revolve
# Ephemeral Random Constant
class ERK < Array
def initialize(*args)
block_given? ? super(*args) : super(args)
end
def value
self[ rand(self.size) ]
end
end
end |
github | logdna/ruby | https://github.com/logdna/ruby | logdna.gemspec | Ruby | mit | 19 | master | 1,039 | # frozen_string_literal: true
lib = File.expand_path("lib", __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
version = File.open("lib/logdna/version.rb").read.scan(/"([^"]*)"/).first.first
Gem::Specification.new do |spec|
spec.name = "logdna"
spec.version = version
spec.authors = "Gun Woo ... |
github | logdna/ruby | https://github.com/logdna/ruby | lib/logdna.rb | Ruby | mit | 19 | master | 3,386 | # frozen_string_literal: true
require "logger"
require "socket"
require "uri"
require_relative "logdna/client"
require_relative "logdna/resources"
require_relative "logdna/version"
module Logdna
class ValidURLRequired < ArgumentError; end
class MaxLengthExceeded < ArgumentError; end
class Ruby < ::Logger
... |
github | logdna/ruby | https://github.com/logdna/ruby | lib/logdna/client.rb | Ruby | mit | 19 | master | 6,597 | # frozen_string_literal: true
require "etc"
require "net/http"
require "socket"
require "json"
require "concurrent"
require "date"
require "securerandom"
module Logdna
Message = Struct.new(:source, :running_size)
class Client
def initialize(request, uri, opts)
@uri = uri
# NOTE: buffer is in mem... |
github | logdna/ruby | https://github.com/logdna/ruby | lib/logdna/resources.rb | Ruby | mit | 19 | master | 796 | # frozen_string_literal: true
module Resources
LOG_LEVELS = %w[DEBUG INFO WARN ERROR FATAL TRACE].freeze
DEFAULT_REQUEST_HEADER = { "Content-Type" => "application/json; charset=UTF-8" }.freeze
DEFAULT_REQUEST_TIMEOUT = 180_000
MS_IN_A_DAY = 86_400_000
MAX_REQUEST_TIMEOUT = 300_000
MAX_LINE_LENGTH = 32_000
... |
github | logdna/ruby | https://github.com/logdna/ruby | test/tests.rb | Ruby | mit | 19 | master | 2,734 | # frozen_string_literal: true
require "minitest/autorun"
require_relative "../lib/logdna"
require_relative "../lib/logdna/client"
require_relative "test_server"
class TestLogDNARuby < Minitest::Test
LOG_LINE = "log line"
def get_options(port)
{
hostname: "rubyTestHost",
ip: "75.10.4.81",
m... |
github | logdna/ruby | https://github.com/logdna/ruby | test/test_server.rb | Ruby | mit | 19 | master | 516 | # frozen_string_literal: true
require "socket"
class TestServer
def start_server(port)
TCPServer.new(port)
end
def accept_logs_and_respond(server, res)
data = ""
Thread.start(server.accept) { |client|
headers = {}
while line = client.gets.split(" ", 2)
break if line[0] == ""
... |
github | hobodave/nagios-probe | https://github.com/hobodave/nagios-probe | Rakefile | Ruby | mit | 19 | master | 1,573 | require 'rubygems'
require 'rake'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "nagios-probe"
gem.summary = "A very simple tool to assist with creating custom nagios probes in Ruby"
gem.description = "Provides an easy to use API for generating custom probes and communicating probe suc... |
github | hobodave/nagios-probe | https://github.com/hobodave/nagios-probe | lib/nagios-probe.rb | Ruby | mit | 19 | master | 1,163 | module Nagios
OK = 0
WARNING = 1
CRITICAL = 2
UNKNOWN = 3
class Probe
attr_reader :retval, :message
def initialize(opts = {})
@opts = opts
@retval = Nagios::OK
@message = "OK: #{ok_message}"
end
def crit?
return false unless check_crit
@retval = Nagios::CRITICA... |
github | hobodave/nagios-probe | https://github.com/hobodave/nagios-probe | test/test_nagios-probe.rb | Ruby | mit | 19 | master | 1,074 | require 'helper'
class TestNagiosProbe < Test::Unit::TestCase
context "A probe" do
setup do
@crit = CriticalProbe.new
@warn = WarnProbe.new
@ok = OKProbe.new
end
should "have retval of 2 when critical" do
@crit.run
assert_equal 2, @crit.retval
end
should "have retv... |
github | hobodave/nagios-probe | https://github.com/hobodave/nagios-probe | test/helper.rb | Ruby | mit | 19 | master | 765 | require 'rubygems'
require 'test/unit'
require 'shoulda'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'nagios-probe'
class Test::Unit::TestCase
end
class CriticalProbe < Nagios::Probe
def check_crit
true
end
end
class WarnProbe < Nagio... |
github | expajp/reredos | https://github.com/expajp/reredos | reredos.gemspec | Ruby | mit | 19 | master | 1,106 | lib = File.expand_path("../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require "reredos/version"
Gem::Specification.new do |spec|
spec.name = "reredos"
spec.version = Reredos::VERSION
spec.authors = ["expajp"]
spec.email = ["expajp@gmail.com"]
spec.su... |
github | expajp/reredos | https://github.com/expajp/reredos | lib/reredos.rb | Ruby | mit | 19 | master | 1,827 | require "reredos/version"
module Reredos
class Error < StandardError; end
EMAIL_MAX_LENGTH = 254 # メールアドレスの最大長
DOMAIN_MAX_LENGTH = 253 # ドメインの最大長
DOMAIN_LABEL_MAX_LENGTH = 63 # ドメインラベルの最大長
USERNAME_MAX_LENGTH = 64 # ユーザネームの最大長
class << self
def valid_email?(str)
return false i... |
github | expajp/reredos | https://github.com/expajp/reredos | spec/spec_helper.rb | Ruby | mit | 19 | master | 363 | require "bundler/setup"
require "reredos"
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_patching!
config.expect_with :rsp... |
github | expajp/reredos | https://github.com/expajp/reredos | spec/reredos_spec.rb | Ruby | mit | 19 | master | 5,122 | RSpec.describe Reredos do
it "has a version number" do
expect(Reredos::VERSION).not_to be nil
end
describe '#valid_email?' do
describe 'length' do
context 'valid total, username, and domain-label length' do
let(:email){ 'user'*16 + '@' + ('a'*63+'.')*2 + 'a'*61 }
it 'accept what has... |
github | wowaudit/core | https://github.com/wowaudit/core | wowaudit.gemspec | Ruby | mit | 19 | master | 1,201 | # coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'wowaudit/version'
Gem::Specification.new do |spec|
spec.name = "wowaudit"
spec.version = Wowaudit::VERSION
spec.authors = ["Emiel van Lankveld"]
spec.email = ... |
github | wowaudit/core | https://github.com/wowaudit/core | Gemfile | Ruby | mit | 19 | master | 320 | source 'https://rubygems.org'
ruby ">= 3.0"
gem 'rbattlenet', git: "https://github.com/wowaudit/rbattlenet.git", branch: 'master'
gem 'mysql2'
gem 'typhoeus'
gem 'sequel'
gem 'aws-sdk-s3'
gem 'tzinfo'
gem 'require_all'
gem 'redis'
gem 'rollbar'
gem 'oj'
gem 'json'
gem 'rexml'
group :development do
gem 'byebug'
end |
github | wowaudit/core | https://github.com/wowaudit/core | bin/deploy.rb | Ruby | mit | 19 | master | 952 | REGISTER = false
TYPE = "deployer"
require_relative('../lib/core')
system("kubectl config use-context do-nyc3-wowaudit-scrapers")
system("kubectl delete deployments wcl-deployment")
system("kubectl delete deployments blizzard-deployment")
system("kubectl delete deployments keystones-deployment")
system("kubectl delet... |
github | wowaudit/core | https://github.com/wowaudit/core | lib/wowaudit.rb | Ruby | mit | 19 | master | 1,805 | # Ultimately this module should replace the old Audit module.
# For now it's only meant for usage as a gem wihin other projects.
require 'typhoeus'
require 'json'
require 'require_all'
require_rel './models/data.rb'
require_rel './utils/audit.rb'
require_rel './utils/season.rb'
require_rel './utils/bonus_ids.rb'
requ... |
github | wowaudit/core | https://github.com/wowaudit/core | lib/core.rb | Ruby | mit | 19 | master | 2,792 | # Dependencies
require 'require_all'
require 'sequel'
require 'redis'
require 'rbattlenet'
require 'typhoeus'
require 'aws-sdk-s3'
require 'date'
require 'mysql2'
require 'yaml'
require 'tzinfo'
require 'csv'
require 'rollbar'
require 'oj'
MAX_OCCURRENCES = {
blizzard: 2,
wcl: 1,
raiderio: 3,
keystones: 1,
}
... |
github | wowaudit/core | https://github.com/wowaudit/core | lib/constants/timeline_constants.rb | Ruby | mit | 19 | master | 29,705 | TIMELINE_EVENTS = {
1 => {
from: Date.new(2005, 2, 11), # In US it was 2004-11-23
to: Date.new(2007, 1, 15),
title: 'Vanilla',
criteria: [
{ achievement_id: 433, quality: :legendary, name: 'Grand Marshal', icon: 'achievement_pvp_a_14' },
{ achievement_id: 443, quality: :legendary, name: 'H... |
github | wowaudit/core | https://github.com/wowaudit/core | lib/constants/profession_constants.rb | Ruby | mit | 19 | master | 35,168 | EXPANSION_PROFESSIONS = {
2906 => "Alchemy",
2907 => "Blacksmithing",
2909 => "Enchanting",
2910 => "Engineering",
2912 => "Herbalism",
2913 => "Inscription",
2914 => "Jewelcrafting",
2915 => "Leatherworking",
2916 => "Mining",
2917 => "Skinning",
2918 => "Tailoring"
}
BASE_PROFESSIONS = {
171 ... |
github | wowaudit/core | https://github.com/wowaudit/core | lib/constants/class_constants.rb | Ruby | mit | 19 | master | 1,993 | CLASSES = {
1 => 'Warrior',
2 => 'Paladin',
3 => 'Hunter',
4 => 'Rogue',
5 => 'Priest',
6 => 'Death Knight',
7 => 'Shaman',
8 => 'Mage',
9 => 'Warlock',
10 => 'Monk',
11 => 'Druid',
12 => 'Demon Hunter',
13 => 'Evoker',
nil => ''
}
DEFAULT_ROLES = {
'Death Knight' => 'Melee',
'Demon Hun... |
github | wowaudit/core | https://github.com/wowaudit/core | lib/constants/mop_constants.rb | Ruby | mit | 19 | master | 256,048 | MOP_TIER_ITEMS_BY_SLOT = {
'14' => {
'head' => [86717, 86676, 86636, 86656, 86702, 86710, 86697, 86651, 86681, 86721, 86673, 86666, 86726, 86691, 86641, 86736, 86631, 86626, 86705, 86661, 86647, 86730, 86686, 85396, 85386, 85370, 85311, 85351, 85362, 85390, 85377, 85357, 85336, 85365, 85333, 85286, 85291, 853... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.