blob_id
stringlengths
40
40
language
stringclasses
1 value
repo_name
stringlengths
4
137
path
stringlengths
2
355
src_encoding
stringclasses
31 values
length_bytes
int64
11
3.9M
score
float64
2.52
5.47
int_score
int64
3
5
detected_licenses
listlengths
0
49
license_type
stringclasses
2 values
text
stringlengths
11
3.93M
download_success
bool
1 class
724cf55f17548a94837026bd17215fa35e1a46c1
Ruby
cesareferrari/programming-foundations
/exercises/101-109_small_problems/easy4/previous3/04_leap_years2.rb
UTF-8
787
3.96875
4
[]
no_license
def evenly_divisible_by?(dividend, divisor) (dividend % divisor == 0) ? true : false end def leap_year?(year) return false if year < 1 return false if !evenly_divisible_by?(year, 4) # if year > 1752 if year > 1752 && evenly_divisible_by?(year, 100) return false unless evenly_divisible_by?(year, 400) e...
true
6507f1a9fc1ffddb9a85ce4ddb8ac822f0c181a7
Ruby
khotta/Nekonote-Framework
/lib/nekonote/env.rb
UTF-8
1,272
2.875
3
[ "MIT" ]
permissive
module Nekonote class Env private_class_method :new @rackenv = {} # Get values in a specified field # @param string|synbol|nil field # @return mixed|nil in the case of that missing specified key or missing fields will return nil def self.get(field = nil) ...
true
7f93101f14d6c7d3298eef7381c3e27af61e6dbc
Ruby
romperstomper/ruby
/ex13.rb
UTF-8
182
2.9375
3
[]
no_license
first, second, third = ARGV #puts "first is : #{first}" #puts "second is : #{second}" #puts "third is : #{third}" puts "input please" args = STDIN.gets.chomp puts "i got #{args}"
true
68ec0bcd442afa44124c74fb3fc3336bca0a945c
Ruby
emilywelsch/surfguru
/lib/beach.rb
UTF-8
581
2.953125
3
[ "MIT" ]
permissive
class Beach attr_accessor :name, :url, :surf_height, :tide, :wind, :wind_direction, :swell_direction, :water_temp, :outside_temp, :ideal_surf_height, :ideal_tide, :ideal_wind, :ideal_swell_direction, :country, :continent @@all = [] def initialize(beach_hash) beach_hash.each do |key, value| self.send("#...
true
1ec3bfd48f58bf376f23584e4a0b1b77bfe0d47f
Ruby
ThinkSalat/Topographical-Sort
/lib/topological_sort.rb
UTF-8
1,373
3.234375
3
[]
no_license
require_relative 'graph' # Implementing topological sort using both Khan's and Tarian's algorithms # BFS # def topological_sort(vertices) # return [] if cyclical_or_unconnected?(vertices) # sorted = [] # queue = [] # vertices.each do |v| # queue.unshift(v) if v.in_edges.empty? # end # until queue.emp...
true
c06d12b7aab384fd8ceb50b13d522207f9ceb60e
Ruby
laierr/addressbook
/lib/addressbook.rb
UTF-8
403
3.234375
3
[]
no_license
class Addressbook def put(name, address) storage[name] = address end def get(name) storage[name] end def has? (name) storage.has_key?(name) end def list storage.keys end def near (address) storage.select do |key, value| value.include?(address) end.keys end def bu...
true
5872dad82f14eed86a1c3bc5e9de72c025a64976
Ruby
miguelcastilho/TeNOR
/hot-generator/models/vnfd_to_hot.rb
UTF-8
9,229
2.546875
3
[ "Apache-2.0" ]
permissive
# # TeNOR - HOT Generator # # Copyright 2014-2016 i2CAT Foundation, Portugal Telecom Inovação # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 ...
true
966c9c33ad37f021780db3204691e2c38049c56a
Ruby
RicardoSBEncora/aspiration_api_task
/spec/people_spec.rb
UTF-8
1,130
2.78125
3
[]
no_license
require 'people' require 'airborne' require 'pry' describe People do describe "INDEX" do before(:each) do get 'https://swapi.dev/api/people' @people = [] total_pages = (1 + json_body[:count] / 10) for i in 1..total_pages do get "https://swapi.dev/api/people/?page=#{i}" @pe...
true
68846ff16cbd8696142343b0f3a10181f27f5831
Ruby
namusyaka/rom
/lib/rom/env.rb
UTF-8
1,307
2.640625
3
[ "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
module ROM # Exposes defined repositories, schema, relations and mappers # # @api public class Env include Adamantium::Flat include Equalizer.new(:repositories, :schema, :relations, :mappers, :commands) attr_reader :repositories, :schema, :relations, :mappers, :commands # @api private def...
true
13f67e0e904ba6c4c93341fb6d322359d0be157f
Ruby
TvL2386/feed_torrents
/lib/feed_torrents/mail.rb
UTF-8
1,251
2.5625
3
[ "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
module FeedTorrents class Mail include LogFunctions PREFIX = "[FeedTorrents] " def send_test_email mail(subject: "#{PREFIX}Test email", body: 'test email') end def send_email(subject, body) return unless FeedTorrents.configuration.email[:enabled] mail(subject: "#{PREFIX}#{sub...
true
29151b2055f06eff9f27c17bc2f3637fa4e8059a
Ruby
RafaelFS/compiladores-p2
/lex.rb
UTF-8
1,137
3.203125
3
[ "Unlicense" ]
permissive
require './token' require "set" require "./tokenTest" def tokenTypesTests [ LabelDeclarationTest.new, RegisterTest.new, OperationTest.new, ReferenceTest.new, LabelTest.new, NumberTest.new ] end def startsComment?(word) word =~ /\/\/.*/ end def classify(word) tokenType = "" tokenType...
true
ccb522311380e9aee30a2b127839822db31c84aa
Ruby
djmetzle/project_euler
/110/solve.rb
UTF-8
1,005
3.28125
3
[]
no_license
#!/usr/bin/ruby require 'set' require 'prime' MAX=1000 MAX=4e6 def n_solutions n return 1 if n <= 2 primes, powers = Prime.prime_division(n).transpose divisor_size = powers.map { |p| p + 1 }.reduce(:*) return (divisor_size - 1) / 2 + 1 end $prod = 1 Prime.each do |p| $prod *= p n = n_solutions($p...
true
f592f34333dbad298df59cbb0515d794d5db5ca8
Ruby
ahirugumi/Ruby-Study
/thread_local.rb
UTF-8
355
2.875
3
[]
no_license
#!/usr/bin/env ruby test="test1" Thread.current[:foo]="foo" th=Thread.start do test="test2" puts "sub thread foo: #{Thread.current[:foo]}" Thread.current[:foo]="bar" puts "sub thread foo: #{Thread.current[:foo]}" end th.join puts "main thread foo: #{Thread.current[:foo]}" puts "sub thread foo: #{th[:foo]}"...
true
1e898d3cea882262825a5951dfef3a8961a2458f
Ruby
aimee-liang/Mod2-Final-Project-Financial-App
/app/models/investment.rb
UTF-8
762
2.609375
3
[]
no_license
class Investment < ApplicationRecord has_many :transactions has_many :users, through: :transactions # def total_price(quantity) # total = 0 # total += self.stock_quote.delayed_price * quantity # return total # end # # helper method # def update_balance # @user.t...
true
977e69297e963cf3074ae16c361c862957039bf2
Ruby
Milstein/mutant
/lib/mutant/actor/receiver.rb
UTF-8
927
2.796875
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
module Mutant module Actor # Receiver side of an actor class Receiver include Concord.new(:mutex, :mailbox) # Receives a message, blocking # # @return [Object] # # @api private # def call 2.times do message = try_blocking_receive ret...
true
53bc8b5fc1d47b12692ff1e27269c0c76dfe98ad
Ruby
abhinav098/string_parser
/app/models/parse.rb
UTF-8
715
2.953125
3
[]
no_license
class Parse < ApplicationRecord validates :text, presence:true, length: { maximum: 5000 } PARAMETERS = %w[c_plus_plus c_sharp vb c java ruby rails physics chemistry mathematics social_science history science geography bus train rickshaw bike car] PARAMETERS.each do |parameter| define_method(:"count_#{pa...
true
8c8cadcafa159ef71d2c539d7f045ed3b0c0f891
Ruby
KhingKY/Custom-Snake-Game
/snake.rb
UTF-8
3,646
3.671875
4
[]
no_license
class Snake attr_accessor :direction, :x, :y, :speed, :length, :segment, :ticker def initialize(window,segment) @window=window @x=rand(320) @y=rand(200) @segments=[] @direction="right" @first_segment=segment.new(@window,[@x,@y])#creates the first segment of the s...
true
632fe06643f4a43fd31bc7ce62bb992398ffd2a9
Ruby
paraviking/git_prac_1
/main.rb
UTF-8
105
3.078125
3
[]
no_license
def new_method puts 'new stuff' end def another_method puts 'more stuff' end def wow puts 'wow' end
true
2647d0691a525ec5ef6b36a621661790f03ac99a
Ruby
dc3671/lkp-tests
/lib/common.rb
UTF-8
3,956
2.53125
3
[]
no_license
LKP_SRC ||= ENV['LKP_SRC'] ## common utilities require "pathname" require "fileutils" require "stringio" LKP_DATA_DIR = '/data' def deepcopy(o) Marshal.load(Marshal.dump(o)) end # Take a look at class Commit for usage module AddCachedMethod def add_cached_method(method_name, prefix = 'cached_') define_method("...
true
fed44d258310bc927aa68472c2f2bde0968dd424
Ruby
Huluk/vim-pomodoro
/autoload/weekplan.rb
UTF-8
1,499
3.0625
3
[]
no_license
# encoding: UTF-8 require_relative 'entry.rb' require_relative 'entry_array.rb' COMMAND_SEPARATOR = /[\n;]/ COUNT_STRING = "- counting result: " # TODO pass as command def weekplan_parse(lines) lines = lines.drop_while{|line| not line =~ TITLE_REGEX} exit if lines.empty? # TODO error message entry = Entry.new(...
true
e2e128e6af4f316d12dbea5df78a240ece034a93
Ruby
sarmadbokhari/weather_app_rails
/app/models/weather_lookup.rb
UTF-8
535
2.75
3
[]
no_license
class WeatherLookup attr_accessor :temperature, :icon def fetch_weather HTTParty.get("http://api.wunderground.com/api/7ca492154b75d353/hourly/q/92882.xml") end def initialize weather_hash = fetch_weather assign_values(weather_hash) end def assign_values(weather_hash) hourly_forecast_respo...
true
fc79eadcab6d851906786d79e49aabd3ea8ef2f1
Ruby
lukeivers/deckbuilder
/cards/abusive_sergeant.rb
UTF-8
310
2.53125
3
[]
no_license
require './minion' class AbusiveSergeant < Minion def initialize super self.name = 'Abusive Sergeant' self.description = 'Give a minion +2 attack this turn' self.cost = 1 self.attack = 2 self.max_health = 1 end def battlecry super owner.add_temporary_attack_to_minion 2 end end
true
03afe8bb25a7bc648653365f278718b8e74c93fc
Ruby
unobliged/EDICT2_Parser
/parse_edict.rb
UTF-8
2,012
3.015625
3
[ "MIT" ]
permissive
# This is a test script for parsing EDICT2U # A rake task will load to postgres edict = 'edict2u' lines = IO.readlines(edict)[165683..165690] lines.each do |line| # this tests for the dictionary version line, which is not a real entry next if line.include? "EDICT2" # All entries end with a unique sequence number of...
true
d53f905aa950ed6681ff617a29a591e2f81d37a4
Ruby
kmcd/refactoring_ruby
/answers/csv_formatter_test.rb
UTF-8
1,025
2.890625
3
[]
no_license
require 'csv_formatter' require 'test/unit' class CsvFormatterTest < Test::Unit::TestCase def setup @csv = CsvFormatter.new end def test_no_lines assert_equal("", @csv.format([])) end def test_no_quotes_or_commas assert_equal("", @csv.format([[]])) assert_equal("only one fiel...
true
48a40fbdb7ad7497005217479f5c55f04bf3a64f
Ruby
nickcen/leetcode
/p260.rb
UTF-8
192
3.875
4
[]
no_license
def single_number(nums) map = {} nums.each do |c| if map.has_key?(c) map.delete(c) else map[c] = 1 end end map.keys end puts single_number([1, 2, 1, 3, 2, 5])
true
401fced28c75949d6c37ed80ef42539e2b165138
Ruby
jonasschneider/ark
/lib/ark/chain.rb
UTF-8
1,444
2.703125
3
[]
no_license
module Ark class Chain include Enumerable attr_reader :path def initialize(path) @path = path @backups = [] while File.exists?(dir = "#{path}.#{@backups.length}") @backups << Ark::Backup.new(dir) end raise "Bogus directory structure - Backup 0 missi...
true
2eee29bb3b1e9588b441b00e78f15fe642aa4193
Ruby
sumnerjj/antcat
/spec/lib/parsers/common_grammar_spec.rb
UTF-8
8,214
2.546875
3
[]
no_license
# coding: UTF-8 require 'spec_helper' describe Parsers::CommonGrammar do before do @parser = Parsers::CommonGrammar end describe "parsing a year" do it "should not consider a five digit number a year" do expect {@parser.parse('18345', :root => :year, :consume => false)}.to raise_error Citrus::Pars...
true
4c726eb9e8d7c2bd0615e7345ef5aaca07368a87
Ruby
arpnetworks/portal
/app/models/vlan.rb
UTF-8
1,560
2.515625
3
[ "BSD-2-Clause" ]
permissive
class Vlan < ApplicationRecord belongs_to :location def self.next_available(opts = {}) start_at = (opts[:start_at] || 100).to_i limit = (opts[:limit] || 1).to_i location = opts[:location] || 'lax' location_id = Location.find_by_code(location).id start_at = 1 if start_at < 1 limit ...
true
4f6f32ce6619568ca32e82083178c04f8b743f09
Ruby
savethatname/stn-ruby
/lib/stn/cache.rb
UTF-8
941
2.515625
3
[ "MIT" ]
permissive
module Stn module Cache def cache(key, options = {}, &block) return block.call unless cache_available? options[:expires_in] ||= 3600 #3600 seconds == 1.hour options.delete(:expires_in) if options[:expires_in].to_i < 1 cache_service.fetch(key, options) { block.call } end def cache_...
true
cfe6b1be9f3952090856ce6f6c82d99e2e65f18e
Ruby
quis/collections-1
/test/models/topic_test.rb
UTF-8
4,154
2.625
3
[ "MIT", "LicenseRef-scancode-proprietary-license" ]
permissive
require "test_helper" describe Topic do setup do @api_data = { "base_path" => "/topic/business-tax/paye", "content_id" => "uuid-23", "title" => "PAYE", "description" => "Pay As You Earn", "details" => { }, "links" => { "parent" => [{ "title" => "Busines...
true
c3987652f3d167de724afff173ce449b90aae556
Ruby
TDobbert/App-Academy
/Ruby/big_o/two_sum.rb
UTF-8
731
3.796875
4
[]
no_license
require 'byebug' def bad_two_sum?(arr, target_sum) arr.each_with_index do |num1, i1| arr.each_with_index do |num2, i2| return true if num1 + num2 == target_sum && i2 > i1 end end false end def okay_two_sum?(arr, target_sum) sorted = arr.sort y = 0 x = sorted.length - 1 while y < x cas...
true
5fb51d715d0156adead0059e4bd200b679ee7d8a
Ruby
Akhilesh4995/tictactoe_ruby
/tic_tac_toe.rb
UTF-8
4,298
4.21875
4
[]
no_license
#Implementation of Two Player Tic-Tac-Toe game in Ruby. =begin We will make the board using Hash in which keys will be the location(i.e : top-left,mid-right,etc.) and initialliy it's values will be empty space and then after every move we will change the value according to player's choice of move. =end def pri...
true
45036c9a7f25bc05fbf4a5b8944dc3ca585179ba
Ruby
scottejames/SevenLanguagesSevenWeeks
/DayTwo/Range.rb
UTF-8
206
3.578125
4
[]
no_license
#!/usr/bin/ruby b=[] print("using each\n") (1..16).each do |a| b.push(a) if b.length == 4 print("#{b} \n") b=[] end end print("using slice\n") (1..16).each_slice(4) do |a| print("#{a} \n") end
true
75e8f00648a805f0bc6e25c95fd25f29565d955c
Ruby
xorgnak/friendly-chainsaw
/lib/nomadic/seed.rb
UTF-8
217
2.671875
3
[]
no_license
module NOMADIC class SEED def initialize @seeds = Redis::List.new("SEED") end def current @seeds[-1] end def valid? s @seeds.include? s end def values @seeds.values end end def seed SEED.new end end
true
a22394f931a3500bf5d7a3a8c53d8e4f8a46df0d
Ruby
legiar/rchart
/lib/layout.rb
UTF-8
9,189
2.734375
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
module Layout # A call to this function is mandatory when creating a graph. # The upper left and bottom right border positions are used as arguments. # This area will be used to draw graphs, grid, axis & more. # Calling this function will not draw anything this will only set the graph area boundaries. def set...
true
7666ffb39330eb69929941be0cf0f3d85c228cd3
Ruby
laney-practice/gedcom
/lib/gedcom/repository_citation_record.rb
UTF-8
2,054
2.8125
3
[ "Ruby", "LicenseRef-scancode-public-domain" ]
permissive
require 'gedcom_base.rb' #Internal representation of a reference to the GEDCOM REPO citation record type #The actual REPO record is stored in the Repository_record class. # #=SOURCE_REPOSITORY_CITATION:= # # n REPO @XREF:REPO@ {1:1} # +1 <<NOTE_STRUCTURE>> {0:M} # +1 CALN <SOURCE_CALL_NUM...
true
e589e5044d6eda10a3ea1812132c97db423a3213
Ruby
Elffers/advent_of_code
/2017/ruby/day05.rb
UTF-8
249
3.140625
3
[]
no_license
jumps = File.readlines('day5.in').map { |x| x.to_i } finish = jumps.size i = 0 steps = 0 while i < finish j = i jump = jumps[i] i += jump if jump > 2 jumps[j] = jump - 1 else jumps[j] = jump + 1 end steps += 1 end p steps
true
85c7aef528fb1f1556d5da1523e6037f896f3de7
Ruby
ProCode2/saas-201-pradipta-ghoshal
/hash/hash-task-2.rb
UTF-8
513
3.171875
3
[]
no_license
todos = [ ["Send invoice", "money"], ["Clean room", "organize"], ["Pay rent", "money"], ["Arrange books", "organize"], ["Pay taxes", "money"], ["Buy groceries", "food"], ] todo_hash = todos.map { |todo| todo[1] }.uniq.inject({}) do |memo, category| memo[category.to_sym] = [] memo end todos.map do |tod...
true
948c61271be8a42def023e8c0f211cebd3be9f5e
Ruby
NStephenson/playlister-sinatra-v-000
/app/models/song.rb
UTF-8
337
2.765625
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
class Song < ActiveRecord::Base belongs_to :artist has_many :songs_genres has_many :genres, through: :songs_genres def slug self.name.downcase.split(" ").join("-") end def self.find_by_slug(slug) unslug = slug.split("-").join(" ") self.all.detect do |song| song.name.downcase == unslug ...
true
91e8266a80f58a173399b5add75d5070317bbba2
Ruby
oneortwo/windchecker
/lib/populator.rb
UTF-8
595
3.390625
3
[]
no_license
require_relative 'weather' require 'date' class Populator def populate(fc) sanity_check(fc) temp = fc['temperature'][0]['value'].to_i wind = fc['windSpeed'][0]['mps'].to_i sunny = fc['symbol'][0]['number'].to_i w = Weather.new(temp, wind, sunny) w.symbol_text = fc['symbol'][0]['name'] w....
true
f2a52f42b184872a78dcec173a9ff99c698d2e00
Ruby
CDL-Dryad/dryad-app
/spec/models/stash-wrapper/version_spec.rb
UTF-8
2,202
2.65625
3
[ "CC-BY-SA-4.0", "MIT" ]
permissive
module Stash module Wrapper describe Version do describe '#initialize' do attr_reader :params before(:each) do @params = { number: 1, date: Date.today, note: 'I am a note' } end it 'sets fields from arguments' do ...
true
ad8eea2d0defb7daa057ae99da3278d2048a8252
Ruby
SantiSorriba/EscuelaMusica-Ruby
/musician.rb
UTF-8
530
3.40625
3
[]
no_license
class Musician attr_accessor :name, :instrument, :age def initialize(name_param, instrument_param) @name = name_param @instrument = instrument_param end def instrument_info "Nombre: " + @instrument.name + ", Tipo: " + @instrument.type end def style if @instrument.type == "Viento" && @age ...
true
fdd95d9f7aad9db4fd1a28a8f18cb2447abefae4
Ruby
wwwjscom/email-features-exp
/features/email_volume_by_day.rb
UTF-8
1,397
2.796875
3
[]
no_license
require_relative 'feature' class VolumeByDay < Feature self.table_name = "email_volume_by_day" # Reset the table def self.reset VolumeByDay.delete_all reset_counter(self.table_name) end # Recalculate the stats def self.recalc mailbox_names.each do |mailbox| volume = {} emails_by_...
true
01f0bb7748c8f7e63ea36f53b925c345c9a2b1c0
Ruby
babelian/rspec_extensions
/lib/rspec_extensions/formatters/suite_formatter.rb
UTF-8
3,179
2.828125
3
[ "MIT" ]
permissive
# https://ieftimov.com/how-to-write-rspec-formatters-from-scratch require 'rspec/core/formatters/console_codes' module RSpecExtensions module Formatters class SuiteFormatter RSpec::Core::Formatters.register self, #:dump_pending, ...
true
65f17dd80982dc18564ff2e9c932d793336cc778
Ruby
sandman8654/OpenStudent
/app/jobs/precompute_student_hashes_job.rb
UTF-8
1,722
2.734375
3
[ "LicenseRef-scancode-warranty-disclaimer", "MIT" ]
permissive
class PrecomputeStudentHashesJob < Struct.new :log include StudentsQueryHelper # Runs the job for a particular day, querying for all educators' authorizations, # precomputing the `student_hashes` for them and writing them to the database. def precompute_all!(date_timestamp) log.puts 'Querying for jobs...' ...
true
a92657d96e2ab96727194a1ebd693751cc31cbf1
Ruby
michaelsabo/ci
/app/services/build_runner_service.rb
UTF-8
1,658
2.59375
3
[ "MIT" ]
permissive
require_relative "../features/build_runner/fastlane_build_runner" module FastlaneCI # Responsible for # - Manage all `TestRunner` objects that are active (either in queue or actually running) # - Provide helper methods to make it easy to find currently running/queued BuildRunners # # TODO: move github specif...
true
4a3c6bdc9a391efb911d3cc8b6588c491f9b8f2b
Ruby
colebusby/assignments
/prepwork/ltp_chapter_7/99bottles.rb
UTF-8
348
3.65625
4
[]
no_license
i = 99 container = "bottles" while i >= 1 puts "#{i} #{container} of beer on the wall!" puts "#{i} #{container} of beer!" puts "Take one down, pass it around," container = "bottle" if i - 1 < 2 if i - 1 == 0 puts "No bottles of beer on the wall!" else puts "#{i - 1} #{container} of beer on the wall!...
true
85b334a97c4dd0a10a809df9bdad5917cfa40a60
Ruby
n3r0-b1n4ry/PDFNetWrappers
/Samples/EncTest/RUBY/EncTest.rb
UTF-8
4,672
2.734375
3
[]
no_license
#--------------------------------------------------------------------------------------- # Copyright (c) 2001-2020 by PDFTron Systems Inc. All Rights Reserved. # Consult LICENSE.txt regarding license information. #--------------------------------------------------------------------------------------- require '../../.....
true
20e3dc65f1ed32a4c12f8e352d688fdbf4da39e3
Ruby
GuyHadas/custom-orm
/lib/has_one_through_associatable.rb
UTF-8
1,048
2.5625
3
[]
no_license
require_relative 'associatable' module Associatable def has_one_through(name, through_name, source_name) define_method name do self_table = self.class.to_s.downcase + "s" through_options = self.class.assoc_options[through_name] through_primary_key = through_options.send(:primary_key) th...
true
007b9e7e1099eaa48726cce236d1866568891c2c
Ruby
aleksacastle/calculator-kata
/lib/variant3.rb
UTF-8
2,155
3.390625
3
[]
no_license
class Array # Splits or iterates over the array in groups of size +number+, # padding any remaining slots with +fill_with+ unless it is +false+. def in_groups_of(number, fill_with = nil) if number.to_i <= 0 raise ArgumentError, "Group size must be a positive integer, was #{number.inspect}" e...
true
e7f456b297582ee0a5194a3acf99ab16a192bf06
Ruby
fdm1/advent_of_code
/ruby/lib/advent_of_code/input_loader.rb
UTF-8
1,334
2.75
3
[ "MIT" ]
permissive
# frozen_string_literal: true require 'fileutils' require 'httparty' module AdventOfCode class InputLoader attr_reader :year, :day, :input_path, :suffix def initialize(year, day, input_path = nil, suffix = nil) @year = year @day = day @input_path = input_path || '../inputs' @suffix ...
true
b73f08e223b104710dea3915755e90a20eae8cd8
Ruby
lucasbonner/RB120-129
/lesson_3/variable_scope/example1.rb
UTF-8
2,072
4.125
4
[]
no_license
class Person def initialize(n) @name = n end end bob = Person.new('bob') joe = Person.new('joe') puts bob.inspect # => #<Person:0x007f9c830e5f70 @name="bob"> puts joe.inspect # => #<Person:0x007f9c830e5f20 @name="joe"> #--------------------------------------------------------- cla...
true
19045190779cf6ef32bfbe0d96690fb00abb8fbc
Ruby
haikulearning/aeries-net-api
/lib/aeries_net_api/support.rb
UTF-8
978
2.5625
3
[ "MIT" ]
permissive
# rubocop: disable Lint/NestedMethodDefinition module AeriesNetApi # Adds useful methods to Object class module Support # Overrides parent#included. Used to avoid re-define these methods when running under Rails def self.included(base) unless base.respond_to?(:blank?) base.class_eval do ...
true
e1379d06c724d36926d54faf80f152352e297f3a
Ruby
speedyray/RubyPrograms
/ifElseTests/my_times.rb
UTF-8
81
2.796875
3
[]
no_license
class Integer def my_times c=0 until c == self yield(c) c += 1 end self end end
true
e4d9c33e134c9d213c58b1f9f662071e3fe57235
Ruby
lmuhammad1/ruby_study
/hard_way/ex36.rb
UTF-8
3,285
3.65625
4
[]
no_license
def prompt() print "==> " end def die(why) puts "#{why} Game Over!" Process.exit(0) end def start() print "Your name is: " prompt; $name = gets.chomp print "Your age is: " prompt; $age = gets.chomp print "Your gender is (enter 'male' or 'female'): " prompt; $gender = gets.chomp until $gender == 'male' or $g...
true
a6a1e257e6245fe772e0a9254a0adc5fdd37f701
Ruby
dry-rb/dry-transaction
/lib/dry/transaction.rb
UTF-8
2,860
2.921875
3
[ "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
# frozen_string_literal: true require "dry/core" require "dry/events" require "dry/monads" require "dry/matcher" require "dry/transaction/version" require "dry/transaction/step_adapters" require "dry/transaction/builder" require "dry/transaction/errors" module Dry # Business transaction DSL module Transaction ...
true
e7c17df9e1e41d380828a9b81c84024aa426ade6
Ruby
RJ-Ponder/RB101
/exercises/easy_6/5_reverse2.rb
UTF-8
806
3.78125
4
[]
no_license
def reverse(array) reversed = array.dup range = 0..(array.length/2 - 1) for num in range reversed[num], reversed[-(num + 1)] = reversed[-(num + 1)], reversed[num] end reversed end p reverse([1,2,3,4]) == [4,3,2,1] # => true p reverse(%w(a b e d c)) == %w(c d e b a) # => true p reverse(['abc']) ...
true
a68c3131956caef033fa7566beb9afeacca0b29c
Ruby
Saicheg/bsuir-courses
/2016/Vlad-Gutkovsky/calculator
UTF-8
550
3.421875
3
[]
no_license
#!/usr/bin/env ruby def binary(n, bin) bin.to_i.to_s(2).reverse.chars.map do |b| if n > 0 n -= 1 if b == '1' '0' else b end end.join.reverse.to_i(2) end stck = [] loop do tmp = gets tmp.chomp! if tmp =~ /\A[+-]?^\d+(?:\.\d+|)$+\z/ stck.push(tmp.to_f) elsif ['+', '-', '*'...
true
9b99024c258e17af2c11326a133091e8e197dce0
Ruby
kernelsmith/workbook
/test/test_column.rb
UTF-8
2,342
2.75
3
[ "MIT", "GPL-3.0-only", "LGPL-2.0-or-later", "GPL-2.0-only", "Ruby" ]
permissive
# frozen_string_literal: true require File.join(File.dirname(__FILE__), "helper") class TestColumn < Minitest::Test def new_table Workbook::Table.new([ ["a", "b", "c", "d"], [true, 3.2, "asdf", 1], [true, 3.2, "asdf", 1], [false, 3.2, "asdf", 1], [true, 3.2, "asdf", 1], ]) en...
true
61288a4e3c29f2f6cfb638200c9edd807155f176
Ruby
MrBeean/reverse_string
/reverse_string.rb
UTF-8
198
3.21875
3
[]
no_license
def reverse_string(string) return 'String too big' if string.size >= 255 split_string = string.split("") reversed = [] string.size.times { reversed << split_string.pop } reversed.join end
true
de632caf0a5995f6d4aad2868503eae11f413ffa
Ruby
kryptykphysh/virus_total_api
/lib/virus_total_api/url_report.rb
UTF-8
689
2.625
3
[ "MIT" ]
permissive
#! # coding: utf-8 # frozen_string_literal: true require_relative './report' module VirusTotalApi # A response object from the VirusTotal API for a URL report query class URLReport < Report self.report_path = '/url/report' # @return [String] the URL being queried attr_reader :resource # Returns ...
true
c4e4b2cb4e32e4249cc136d35126f00e9a699e58
Ruby
jeffjiang8/deli-counter-ruby-apply-000
/deli_counter.rb
UTF-8
173
2.5625
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
# Write your code here. katz_deli = [] take_a_number(katz_deli,"Jeff") take_a_number(katz_deli,"Tim") take_a_number(katz_deli,"Jimmy") line(katz_deli) now_serving(katz_deli)
true
77f594da99f014fb026042968ba1bd0ab86d60fd
Ruby
rvaddadi/puzzles
/project-euler/euler26.rb
UTF-8
867
3.59375
4
[]
no_license
# This one was so nice to solve! # I made an attempt a long time ago # and only now I've been able to solve it! # The main reason is because, after trying brute # force in many ways and being frustrated many times, # I found this http://www.lrz.de/~hr/numb/period.html # In the end, all that got me going was this phra...
true
416fd061232ce6baa877d06561bde086bd869a24
Ruby
SolomonRFeldman/good-writes
/good-writes-server/spec/models/user_spec.rb
UTF-8
2,663
2.53125
3
[ "MIT" ]
permissive
require 'rails_helper' RSpec.describe User, :type => :model do let(:valid_user) { create(:valid_user) } let(:hush_hash) { { :username => "Hello", :email => "Hello@Hush.com", :password => "hush" } } let(:group_1) { Group.create( name: "Sunshine Friends", form: "Poetr...
true
74f1e607eac13c7fd93e6f007eb9c5c9c5feeef8
Ruby
PolinaSkrobot/ar-exercises
/exercises/exercise_6.rb
UTF-8
711
2.671875
3
[]
no_license
require_relative '../setup' require_relative './exercise_1' require_relative './exercise_2' require_relative './exercise_3' require_relative './exercise_4' require_relative './exercise_5' puts "Exercise 6" puts "----------" # Your code goes here ... @store1.employees.create(first_name: "Khurram", last_name: "Virani",...
true
b0114a6efe1d546dc6e0df5c472d022b85171d90
Ruby
EmilReji/twenty_one
/twenty_one.rb
UTF-8
3,966
3.796875
4
[]
no_license
class Player WINNING_SCORE = 21 attr_accessor :name, :cards def initialize @name = self.class @cards = [] end def busted? total > WINNING_SCORE end def total cards.map(&:value).sum end def <<(card) if card.face == 'Ace' card.value = if total + 11 <= WINNING_SCORE ...
true
844388283212cdc68c5a352d69d8d0d0b5503714
Ruby
koko/ttt-8-turn-cb-gh-000
/lib/turn.rb
UTF-8
982
4.03125
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
# code your #valid_move? method here def valid_move?(board,index) index > -1 and index < 9 and !(position_taken?(board,index)) end # re-define your #position_taken? method here, so that you can use it in the #valid_move? method above. def position_taken?(board,index) board[index] != "" and board[index] != " " and ...
true
563521f9cf63c407ffac4b69111b3bc8eb07813e
Ruby
jordido/ironhackmdb
/Movie.rb
UTF-8
310
3.109375
3
[]
no_license
class Movie attr_accessor :title, :rating def initialize (title) @title = title @rating = get_rating end def push_film_stars film_stars = "" film_stars << "*" * self.rating + " " * (10 - self.rating) end private def get_rating rating = Imdb::Search.new(@title).movies.first.rating end end
true
20cc8c5a5cd0eef70dc5e4c44d05c4c9a583c6e7
Ruby
TheSaltMines/dashboard
/lib/bookings.rb
UTF-8
1,920
2.953125
3
[]
no_license
require 'icalendar' class Bookings def initialize(params) @params = params end def run SCHEDULER.every '1m', :first_in => 0 do |job| cal_file=(Net::HTTP.get 'booking.saltmines.us', @params[:ical_path]) calendar = Icalendar::Calendar.parse(cal_file).first events = filter(calendar.event...
true
6c7322f064921b871f38de17f4d6c94f0a2bb383
Ruby
BradleyTesterSpratt/RubyTextAdv
/lib/key.rb
UTF-8
161
2.703125
3
[]
no_license
class Key < Item def initialize(name, weight, door, desc = nil) super(name, weight, desc) @door = door @type = 'key' end attr_reader :door end
true
1798b2db5d8942d2595a7fa59bb9397a0dac6103
Ruby
rasensio1/interviewcake
/cake_theif.rb
UTF-8
540
3.34375
3
[]
no_license
cake_arrays = [[7, 160], [3, 90], [2, 15], [0, 10]] capacity = 20 def max_duffel_bag_value(cake_arrays, capacity) max_values = Hash.new(0) cake_arrays.reject! { |w, v| w.zero?} for cap in (1..capacity) do cake_arrays.each do |w, v| if w <= capacity if w <= cap r = cap - w ...
true
6699c786a4ac4d957a8c405af05844f3d4d58492
Ruby
curiousily/naughty-maze
/lib/naughty_maze/path_finder.rb
UTF-8
2,833
3.171875
3
[]
no_license
module NaughtyMaze class PathFinder def initialize(maze) @start_point = maze.start_point @end_point = maze.end_point @maze = maze end def execute if @start_point == @end_point return Path.new(@start_point.num) end unless @maze.include?(@start_point) rai...
true
adb1fda7f97f3ca2fcb9163b623760e5cd67cf29
Ruby
cyrillefr/task-grades
/spec/student_spec.rb
UTF-8
2,286
2.765625
3
[]
no_license
require '../app.rb' require 'rspec' require 'rack/test' describe 'MyStudentsGradesApp' do include Rack::Test::Methods def app MyStudentsGradesApp end describe "Try student creation without last_name parameter " do it "Should return a 500 status code and a non empty return json e...
true
55b4c2a7463383166b54cd13e2631c3a104e929e
Ruby
GowtherGit/HackerRank-Solutions-1
/tllm.rb
UTF-8
290
3.171875
3
[]
no_license
#The Love-Letter Mystery ------------------------ nlines = $stdin.readline.to_i $stdin.take(nlines).each do |line| numbers = line.strip.chars.map(&:ord) pairs = numbers.zip(numbers.reverse).take(numbers.size / 2) puts(pairs.map { |n1, n2| (n1 - n2).abs }.reduce(0, :+)) end
true
bed7586b787de8187db4a3f9a3a88823a9bd61ea
Ruby
JustJace/ProjectEuler
/p017.rb
UTF-8
2,137
4.25
4
[]
no_license
# Problem 17 : If all the numbers from 1 to 1000 (one thousand) inclusive were written out in words, how many letters would be used? $zero = 0 $and = "and".length $one = "one".length $two = "two".length $three = "three".length $four = "four".length $five = "five".length $six = "six".length $seven = "seven".length $eig...
true
0ee8a3b309bace01ec9fde9eba3a1249ed020bf7
Ruby
jhammer/twofactorauth
/tests/validate-images.rb
UTF-8
1,130
2.578125
3
[ "MIT" ]
permissive
#!/usr/bin/env ruby # frozen_string_literal: true require 'json' @status = 0 PNG_SIZE = [[32, 32], [64, 64], [128, 128]].freeze seen_sites = [] def error(msg) puts "::error file=#{@file}:: #{msg}" @status = 1 end Dir.glob('entries/*/*.json') do |file| @file = file website = JSON.parse(File.read(file)).value...
true
eef44032c1dbe9581d6aa144fccd5c74b8dab1b4
Ruby
flexe-inc/queue-model
/queue.spec.rb
UTF-8
4,581
2.78125
3
[]
no_license
require "minitest/autorun" require "./queue.rb" require "./queue_bucket.rb" describe BucketedQueue do describe "when empty" do before do @queue = BucketedQueue.new end describe "and the queue is stepped" do before do @queue.step end it "has no buckets" do @queue...
true
e25107a55021826728b297000716a2ed434f98e3
Ruby
GerryG/card-mods
/csv_import/lib/card/import_manager.rb
UTF-8
1,121
2.6875
3
[]
no_license
class Card # ImportManager coordinates the import of a Card::ImportCsv. It defines the conflict and error # policy. It collects all errors and provides extra data like corrections for row fields. class ImportManager attr_reader :conflict_strategy, :corrections, :status def initialize csv_file, conflict_s...
true
dc7f19fe95499e3484d6ddc914f3b614a610cadf
Ruby
tomleman/sudoku
/lib/board.rb
UTF-8
827
3.5625
4
[]
no_license
require '../lib/box' class Board def initialize(input) @grid = input.split('').map{|n| Cell.new(n.to_i)} end def rows(cell_index) column_no = cell_index % 9 first = cell_index - column_no return @grid[first,9] end def columns(cell_index) column_no = cell_index % 9 result = [column_no] 8.tim...
true
4b6d9b7188e4ddb219659e6e3b59d1cb3c3eef10
Ruby
jdashton/glowing-succotash
/daniel/pine/pine133.rb
UTF-8
270
3.78125
4
[ "MIT" ]
permissive
# frozen_string_literal: true # Simple Die class, rolls 1 in 6 class Die def roll @number_showing = rand(1..6) end def showing @number_showing end end die = Die.new die.roll puts die.showing puts die.showing die.roll puts die.showing puts die.showing
true
7d136cecb4175475dc7b2c65923424af97f39427
Ruby
guti12/object_oriented_ruby
/inheritance.rb
UTF-8
1,536
3.921875
4
[]
no_license
# class Car # def initialize # @speed = 0 # @direction = 'north' # end # def brake # @speed = 0 # end # def accelerate # @speed += 10 # end # def turn(new_direction) # @direction = new_direction # end # def honk_horn # puts "Beeeeeeep!" # end # end # class Bike # def ...
true
5805690431c0bec8dedbed708c0be5fd3e4533bd
Ruby
guoyu07/stagger-ruby-em
/lib/stagger/delta.rb
UTF-8
295
2.953125
3
[ "MIT" ]
permissive
module Stagger class Delta attr_reader :value def initialize @value = nil end def delta(value) if @value && (delta = value - @value) >= 0 @value = value return delta else @value = value return nil end end end end
true
e22863a3dab9a3b6e717c0e38a9d8ac386579626
Ruby
Verivox/simple_rewriter
/lib/simple_rewriter/rewriters/float_rewriter.rb
UTF-8
322
2.75
3
[ "MIT" ]
permissive
class SimpleRewriter::Rewriters::FloatRewriter < SimpleRewriter::Rewriters::Base def generate random_float end private # rand generates pseudo random from 0-1 # rand(10) generates pseudo random from 0-10 # we use it to get something like 4.41445946155691 def random_float rand * rand(10) end en...
true
242bb0249786eb1cc9292ff70f652cfee01fbc46
Ruby
hanfak/Ruby-Code
/codeWars/5-Kyu/anagrams.rb
UTF-8
82
3.109375
3
[]
no_license
def anagrams(word, words) words.select {|z| word.chars.sort == z.chars.sort} end
true
ac8fe0a0b25e12ba299f435f4c4d69efb418e656
Ruby
NabilleH/bank
/lib/statement.rb
UTF-8
763
3.5
4
[]
no_license
# frozen_string_literal: true # Class for statement class Statement HEADER = "date || credit || debit || balance\n" def generate_statement(transactions) entries = [] transactions.each do |trans| entries.unshift("#{trans[:date]} ||#{credit_amount(trans[:type], ...
true
417f1fa0938a4de8c8e96a911ea288694d40dbbf
Ruby
lionellionel/Intro_to_Ruby
/Lesson2/blackjack_OOP.rb
UTF-8
4,846
3.984375
4
[]
no_license
# Blackjack OOP version FACES = ['2','3','4','5','6','7','8','9','10','A','J','Q','K'] SUITS = ['H','C','D','S'] class Deck attr_accessor :cards def initialize(size) @cards =[] size.times do FACES.each do |face| SUITS.each do |suit| @cards << Card.new(face,suit) end ...
true
271d02ee445f6e07ba8e5545063dd7de9c00cb76
Ruby
ThunderKey/RubyHelper
/AllHelpers/StringHelpers/StringSymbolComparison.rb
UTF-8
215
3.25
3
[]
no_license
class String def == other (self.eql?(other) || self.eql?(other.to_s)) end end class Symbol alias :eql? :== def == other if other.respond_to? :to_sym self.eql?(other.to_sym) else false end end end
true
e37cb0c5b10adca63afb8c489875a6f800a1b975
Ruby
compwron/liquidFeedback
/lib/vote.rb
UTF-8
121
2.609375
3
[]
no_license
class Vote attr_reader :assigned_to def initialize(purpose, original_vote_owner=self) @assigned_to = purpose end end
true
a28a939bdd1372c9d539fce4938b6661a22be32a
Ruby
hugobarauna/forca
/bin/forca
UTF-8
441
2.8125
3
[]
no_license
#!/usr/bin/env ruby $LOAD_PATH.prepend File.join(__dir__, "../lib") require "game_flow" def create_game word_raffler = create_word_raffler Game.new(word_raffler) end def create_word_raffler if ARGV.first words = ARGV.pop words = words.split WordRaffler.new(words) else WordRaffler.new end e...
true
7113bf13184e1b0f74d92819a2db2d774c60b05f
Ruby
vilmes21/web_equation_simplifier
/simplifier/def_master_transform.rb
UTF-8
465
2.53125
3
[]
no_license
require_relative "./def_final_beautify.rb" require_relative "./def_screen.rb" module Transformation include FinalBeautification include Screen def transform(str) return screen(str) if screen(str) ugly_str = initial_uglify(str) terms = to_terms(ugly_str) count = count_terms(terms) polynomial...
true
5aca26c1c146ffdfafad4d76b073356a44cb9482
Ruby
IcaroAdao/Iniciando-com-Ruby
/iniciando_com_Ruby/trabalhando_com_arquivos/writeTeste.rb
UTF-8
228
2.6875
3
[]
no_license
if ARGV.size > 0 File.open(ARGV[0], 'w') do |arq| arq.puts "teste" arq.puts "teste" arq.puts "teste" end else File.open("teste.txt", 'w') do |arq| arq.puts "Ícaro" arq.puts "teste" arq.puts "quarentena" end end
true
53104a075c1f45fbbf1c24f91ac8f59e80a7be54
Ruby
slimecog/black_thursday
/lib/merchant_repo.rb
UTF-8
1,380
3.015625
3
[]
no_license
require_relative "merchant" require_relative "sales_engine" class MerchantRepo attr_reader :merchants, :sales_engine def initialize(sales_engine, filename) @merchants = [] @sales_engine = sales_engine load_merchants(filename) end def load_merchants(filename) merchant_csv = CS...
true
e4c6b920dd416c8bf207b9e4e8343f9befb70785
Ruby
randomorganizer/BackEndDevelopment
/120/reduce_method.rb
UTF-8
336
3.65625
4
[]
no_license
def reduce(array, initial=0) counter = 0 result = initial while counter < array.size result = yield(result, array[counter]) counter += 1 end result end array = [1, 2, 3, 4, 5] p reduce(array) { |acc, num| acc + num } p reduce(array, 10) { |acc, num| acc + num } p reduce(array) { |acc, num| acc + num...
true
7727384719f523e9eeafbb9b5dc8da4c14846748
Ruby
RonaldoFaustino/ruby
/testes.rb
UTF-8
447
4.25
4
[]
no_license
# chutes = [176, 100, 150, 175] # chutes [3] = 199 # puts chutes [0] # puts chutes [1] # puts chutes [2] # puts chutes [3] # chutes = [] # chute = 176 # chutes << chute # chute = 170 # chutes << chute # chute = 175 # chutes << chute # puts chutes.size # for chute in chutes # puts chute # end nome = gets.stri...
true
e7d30efb34c4e560e0d31d70326876bb473b677a
Ruby
NazarovSV/ruby_course
/Lesson8/passenger_wagon.rb
UTF-8
247
2.5625
3
[]
no_license
# frozen_string_literal: true require_relative 'wagon' class PassengerWagon < Wagon def initialize(number, space) self.space = space super number, space end def take_volume super 1 end validate :space, :type, Integer end
true
c3649e3d00f27fd38668fa5e904bb2336954e1a2
Ruby
zooniverse/zoo_stream
/lib/zoo_stream/kinesis_publisher.rb
UTF-8
534
2.515625
3
[ "MIT" ]
permissive
require 'aws-sdk' module ZooStream class KinesisPublisher attr_reader :stream_name, :client def initialize(stream_name: ENV.fetch("ZOO_STREAM_KINESIS_STREAM_NAME"), client: Aws::Kinesis::Client.new) @stream_name = stream_name @client = client end def publish(event, shard_by: nil) ...
true
4ae19c31a56cfab3b14b3f372ff78791c16768be
Ruby
cowplow/Project-Euler
/38.rb
UTF-8
578
4.03125
4
[]
no_license
nums = [1,2,3,4,5,6,7,8,9] def pandigital(arr) arr.each do |x| if arr.count(x) != 1 || arr.count("0") > 0 return false end end return true end @results = [] @answer = [0] def products(number) holder = [] x = 1 until holder.length >= 9 do temp = number * x arr = temp.to_s.split("").collect.to_a ar...
true
5d2efbb7d83a2d5c0f6d818d73723ae90ae68671
Ruby
VenkatNan/programming-univbasics-2-statement-repetition-with-while-atx01-seng-ft-042020
/lib/count_down.rb
UTF-8
86
3.203125
3
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference" ]
permissive
count = 10 while count >= 1 do puts count count -=1 end puts "Happy New Year!"
true
c1e6edce2e7eaf4b240f2b7a2904a7cd30d4271f
Ruby
maanderz/two_player_game
/questions.rb
UTF-8
238
3.4375
3
[]
no_license
class Questions attr_accessor :correct_answer, :show def initialize @number1 = rand(1...20) @number2 = rand(1...20) @correct_answer = @number1 + @number2 @show = "What is #{@number1} + #{@number2}?" end end
true
4ad6f829de319b8f2aeab6a41620c8a7497349c8
Ruby
Stearnzy/sweater_weather
/spec/poros/hourly_weather_spec.rb
UTF-8
3,154
2.6875
3
[]
no_license
require 'rails_helper' describe 'HourlyWeather' do before(:each) do VCR.use_cassette('ForecastService/returns_weather_from_coordinates') do lat = 39.738453 long = -104.984853 data = ForecastService.complete_weather_report(lat, long) @weather = data[:hourly][0..7].map do |hourly_report| ...
true