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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
654c54b7340bb1bfb0bb26d6274d0a3ffb987e42 | Ruby | Sabari-code/Bookmark | /spec/unit/bookmark_spec.rb | UTF-8 | 570 | 2.53125 | 3 | [] | no_license | require './app/models/bookmark'
describe Bookmark do
describe '.all'do
it ' returns an array of bookmarks' do
connection = PG.connect :dbname => 'demo_bookmark_manager_test'
connection.exec("INSERT INTO bookmarks (url) VALUES('test_url')")
bookmarks = Bookmark.all
expect(bookmarks.first.url).to eq 'test... | true |
efef5e6679175ee0df1e3198a6e747d52dddc520 | Ruby | puppetlabs/puppetlabs-stdlib | /lib/puppet/functions/stdlib/end_with.rb | UTF-8 | 730 | 3.078125 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
# @summary
# Returns true if str ends with one of the prefixes given. Each of the prefixes should be a String.
#
Puppet::Functions.create_function(:'stdlib::end_with') do
# @param test_string The string to check
# @param suffixes The suffixes to check
# @example
# 'foobar'.st... | true |
f00e845d66db7e3358da6c2f0c940382156c324b | Ruby | johnglynn/Ironhack | /IH_Week_2/IH_Week_2_Day_1/Sinatra_TODO_(part_1)/sinatra_app.rb | UTF-8 | 135 | 2.609375 | 3 | [] | no_license | require_relative("lib/sinatra.rb")
task = Task.new("Buy the milk")
puts task.id
# 1
task2 = Task.new("Wash the car")
puts task2.id
# 2 | true |
dac9c16c64fd4730009b5394b977d7556b3f8253 | Ruby | djammli/Falcon_FuntionalValidation | /features/Pages/Common/details_page.rb | UTF-8 | 2,171 | 2.671875 | 3 | [] | no_license | require_relative 'base_page'
class DETAILS_PAGE < BASE_PAGE
text_field(:searchbox, xpath: "//input[@type = 'search']")
div(:totalNumOfRecords, css: ".dataTables_info")
element(:lastPageNumber, xpath:"(//div[@class='dataTables_paginate paging_simple_numbers']//a)[last()-1]")
elements(:numberOfRecordsInPage,xpat... | true |
b469e50a36dfeb15330ee0a7ea7963ae67ccff67 | Ruby | srMarquinho/oystercard | /lib/oystercard.rb | UTF-8 | 674 | 3.296875 | 3 | [] | no_license | require_relative 'journey'
class Oystercard
attr_reader :balance, :journey_log, :journey
MAXIMUM_BALANCE = 90
def initialize
@balance = 0
@journey = Journey.new
@journey_log = JourneyLog.new
end
def top_up(amount)
fail "ERROR: Balance limit is £ #{MAXIMUM_BALANCE}" if (balance + amount) > ... | true |
2ad8b048be94d12131e8dc1bc6cc4881f6697368 | Ruby | xenfinity/Intro-to-Programming-Exercises | /1 - Variables/5-x.rb | UTF-8 | 157 | 2.875 | 3 | [] | no_license | =begin
x = 0
3.times do
x += 1
end
puts x
#output ==> 3
y = 0
3.times do
y += 1
x = y
end
puts x
#output ==> Error - undefined variable
=end
| true |
2585d1b1b6abe931689b2f4c4e055a361c86fcf2 | Ruby | akallbold/GymFace | /GYMFACE-API/app/models/klass.rb | UTF-8 | 1,463 | 2.8125 | 3 | [] | no_license | require 'watir'
require 'webdrivers'
class Klass < ApplicationRecord
has_many :user_klasses
has_many :users, through: :user_klasses
def self.fetchKlasses(date = Date.today.strftime("%Y-%m-%d"), location_id=110)
# needs YYYY-MM-DD / YYYY-M-D format
url = 'https://www.equinox.com/classschedule?clubs=' + ... | true |
d5b0baaed16ed96c880fe9c53b5373af685736a0 | Ruby | Kenworthe/sushi-go-ruby | /game/cards/count_card.rb | UTF-8 | 183 | 2.890625 | 3 | [] | no_license | require_relative "card"
class CountCard < Card
def get_count(plate)
return plate.select{|card| card.name == @name}.length
end
def calculate_points(plate)
@points[0]
end
end | true |
7cfe668b35715b5ff4ccc088c51a112e8213afed | Ruby | haroldtreen/coding-problems | /hacker-rank/algorithms/search/connected-cells-in-a-grid.rb | UTF-8 | 520 | 3.375 | 3 | [] | no_license | width = gets.chomp
height = gets.chomp
rows = []
width.times do
rows.push gets.chomp.split ' '
end
def main matrix
matrix.each_with_index do |row, row_i|
row.each_with_index do |x, i|
if x == '1'
get_region row_i i matrix
end
end
end
end
def get_region x, y, matrix
get_region x y matrix
matrix[row... | true |
02b3253edc6c25a5529af9340b9133d119110ace | Ruby | alicial/advent-of-code-2020 | /2020-10/10.rb | UTF-8 | 506 | 3.59375 | 4 | [] | no_license | input = File.readlines('input.txt').map(&:to_i).sort!
prev = 0
ones = 0
threes = 0
input.each do |x|
case x - prev
when 1
ones += 1
when 3
threes += 1
end
prev = x
end
# Part 1
puts ones * (threes + 1)
input.unshift(0)
counts = [1] * input.length
input.each_with_index do |x, i|
next unless i > 0
... | true |
38ce46d17abd7e0cdb11208348f9e79abb056090 | Ruby | TheWayOfTheRob/bixby-manager | /lib/bixby/modules/crypto.rb | UTF-8 | 2,222 | 2.609375 | 3 | [
"MIT"
] | permissive |
require 'openssl'
require 'base64'
module Bixby
module Crypto
# Encrypt data using the agent's public key
#
# @param [Agent] agent
# @param [String] data data to encrypt
#
# @return [String] Base64 result
def encrypt_for_agent(agent, data)
# TODO replace master with server's ho... | true |
883a56b2d1cec26ae337b0939ca0c567ee13707a | Ruby | mustmodify/valuable | /test/valuable_test.rb | UTF-8 | 5,581 | 2.984375 | 3 | [
"MIT"
] | permissive | $: << File.expand_path(File.dirname(__FILE__) + '/../lib')
require 'test/unit'
require 'valuable.rb'
require 'mocha/setup'
class Cubical < String
def initialize(number)
super "Lives in Cubical #{number}"
end
end
class DevCertifications < Valuable
has_value :a_plus, :default => false
has_value :mcts, :def... | true |
6a105f6215e1b3ec5eecb87d6c3afd27211488cb | Ruby | alexrails/testguru | /app/services/get_badge_service.rb | UTF-8 | 981 | 2.59375 | 3 | [] | no_license | class GetBadgeService
def initialize(user_passed_test)
@user = user_passed_test.user
@test = user_passed_test.test
@user_passed_test = user_passed_test
end
def reward(badge)
@user.badges << badge
end
def call
Badge.select do |badge|
rule = "#{badge.rule}?"
reward(badge) if s... | true |
007c26c909b72d4a15bfa69953a213b12f05d440 | Ruby | forksaber/uc | /lib/uc/custom_logger.rb | UTF-8 | 477 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'logger'
module Uc
class CustomLogger < ::Logger
def initialize(file)
super(file)
@level = ::Logger::INFO
end
def format_message(severity, timestamp, progname, msg)
case severity
when "INFO"
"#{msg}\n"
when "ERROR"
"#{severity.bold.red} #{msg}\n"
... | true |
ad13838cea1c790ce4c795a58b35a8d2049f9ea7 | Ruby | roschaefer/rundfunk-mitbestimmen | /features/step_definitions/steps.rb | UTF-8 | 29,474 | 2.515625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
Pathname.new(__FILE__).join('../..')
def sanitize_amount(amount)
Float(amount.delete('€'))
rescue StandardError
nil
end
def login
stub_jwt(@user)
click_on 'Log in'
end
Given(/^I am logged in$/) do
visit '/'
@user = create(:user)
login
end
Given(/^(?:I|we) have (?:these|th... | true |
c78be0c645393281145adb1ef699ad4e71e31ec0 | Ruby | leannerivera/betsy | /test/models/order_product_test.rb | UTF-8 | 7,076 | 2.59375 | 3 | [] | no_license | require "test_helper"
describe OrderProduct do
let(:shirts) { order_products(:shirts) }
let(:dresses) { order_products(:dresses) }
let(:dress) { products(:dress) }
it "must be valid" do
value(shirts).must_be :valid?
end
it 'has required fields' do
fields = [:quantity, :order, :product, :status]
... | true |
eca73963fe7e56fa2837847ca383060263a09c62 | Ruby | hashrocket/clearance | /test/rails_root/vendor/plugins/facebooker/lib/facebooker/models/page.rb | UTF-8 | 951 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'facebooker/model'
module Facebooker
class Page
class Genre
include Model
FIELDS = [ :dance, :party, :relax, :talk, :think, :workout, :sing, :intimate, :raunchy, :headphones ]
attr_accessor *FIELDS
def initialize(*args)
super
# convert '1'/'0' to true/false
... | true |
75d2077b14e134984fd1127efc0bb6fbf1b54fce | Ruby | randland/tattletail | /lib/tattletail/demo.rb | UTF-8 | 1,792 | 3.421875 | 3 | [] | no_license | require 'tattletail'
module Tattletail
class Fib
def no_args
5
end
tattle_on :no_args
def fib x
return 1 if x <= 2
fib(x - 1) + fib(x - 2)
end
tattle_on_instance_method :fib
def self.fib x
return 1 if x <= 2
fib(x - 1) + fib(x - 2)
end
tattle_on :fi... | true |
fb105f9cc65589765c51ed65e82ce9448b86e7f8 | Ruby | IfeAkiWad/oo-cash-register-onl01-seng-pt-041320 | /lib/cash_register.rb | UTF-8 | 2,609 | 3.390625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class CashRegister
attr_accessor :discount, :total, :add_item
def initialize (discount=nil)
@total = total
@total = 0
@discount = discount
@items = []
end
def total
@total
end
def add_item (title, price, qty=1)
@item_price = price * qty
@to... | true |
3fe7e6d0def6cd94530e5e05512fd1e206c1d8a2 | Ruby | stonefishy/ruby-training | /hash/hash_other_methods.rb | UTF-8 | 1,420 | 3.875 | 4 | [] | no_license | #checking whether the specifies hash object has a key
hash = {"a" => "b", "c"=> "d"}
p hash.key?("a") #=> true
p hash.key?("x") #=> false
p hash.has_key?("c") #=> true
p hash.include?("a") #=> true
p hash.member?("x") #=> false
#checking whether the specifies hash object has a value
hash = {"a"=>"b", "c"=>"... | true |
c057822a9c54ad9d862be956e3536c3afc0871d0 | Ruby | peterbell215/CFSM | /lib/condition_optimisation/conditions_node.rb | UTF-8 | 2,285 | 3.265625 | 3 | [
"MIT"
] | permissive | # @author Peter Bell
# Licensed under MIT. See License file in top level directory.
module ConditionOptimisation
# Uses to represent a condition node within a directed graph of conditions.
# The directed graph shows the RETE decision tree.
class ConditionsNode
# Constructor for a condition node.
#
#... | true |
f4fcd964cd69457490cd8f30fce569df0f1b5698 | Ruby | jvranish/cauterize | /spec/builders_spec.rb | UTF-8 | 1,828 | 2.65625 | 3 | [
"MIT"
] | permissive | module Cauterize
describe Cauterize::Builders do
describe "#register and #get" do
let(:s) { Cauterize.scalar(:uint8_t) }
before do
class X; def initialize(i); end; end
class Y; def initialize(i); end; end
class Z; def initialize(i); end; end
# save the old list so that... | true |
9f76469b16881c79065d53cb9fd57f506a3fb912 | Ruby | connorjacobsen/anor-router | /lib/anor/routing/namespace.rb | UTF-8 | 605 | 2.5625 | 3 | [
"MIT"
] | permissive | module Anor
module Routing
class Namespace
attr_reader :router, :name
def initialize(router, name, &block)
@router = router
@name = name
instance_eval(&block) if block_given?
end
%i(get post patch put delete).each do |verb|
define_method(verb) do |url, op... | true |
f3468f2db209b40c0cd1e1700a3ad75e1ca1d93e | Ruby | abhayathapa/kudo | /app/controllers/concerns/csv_generator.rb | UTF-8 | 719 | 3 | 3 | [] | no_license | class CsvGenerator
# @param records{Object}
# @param attributes{Array}
def initialize(records, attributes)
@records = records
@attributes = attributes
@success = false
end
def to_csv
CSV.generate(headers: true) do |csv|
csv << @attributes
@records.find_each(batch_size: 50) do... | true |
eb27c7036930e906e9910e15c4b0656a91cc3fa9 | Ruby | phoenixtoday/meb | /test/unit/location_test.rb | UTF-8 | 529 | 2.828125 | 3 | [] | no_license | require 'test_helper'
class LocationTest < ActiveSupport::TestCase
def test_should_be_able_to_tell_neighours_in_for_direction
assert_equal Location.at(1, 0), Location.at(0, 0).east
assert_equal Location.at(-1, 0), Location.at(0, 0).west
assert_equal Location.at(0, 1), Location.at(0, 0).north
assert_... | true |
36d5a68fe81187adf75255b72be1e7fb0fc606e6 | Ruby | poshboytl/commands | /lib/rails/commands/tester.rb | UTF-8 | 934 | 2.515625 | 3 | [
"MIT"
] | permissive | module Rails
module Commands
class Tester
def test(what = nil)
"Completed"
end
private
def run(*test_patterns)
TestEnvironment.fork do
test_patterns.each do |test_pattern|
Dir[test_pattern].each do |path|
require File.expand_p... | true |
31e0a2d24a8b784906d4d17ce929a1d786885405 | Ruby | healthypackrat/duo_splitter | /lib/duo_splitter/models/sentence.rb | UTF-8 | 991 | 2.609375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module DuoSplitter
module Models
class Sentence
attr_reader :number, :start_pos, :end_pos, :section
attr_accessor :audio_path, :blank_audio_path, :source_audio_path
def initialize(number:, start_pos:, end_pos:, section:)
@number = number
@start_po... | true |
85d6f0abad0b26c71b0fe482ba94b603a5aacac9 | Ruby | seaneshbaugh/rosalind | /bin/dna-gen | UTF-8 | 253 | 3.34375 | 3 | [] | no_license | #!/usr/bin/env ruby
# https://en.wikipedia.org/wiki/Human_genome
# dna_length = 3095693981
if ARGV.length > 0
dna_length = ARGV.first.to_i
else
dna_length = 1024
end
bases = ['A', 'C', 'G', 'T']
puts (0...dna_length).map { bases[rand(4)] }.join
| true |
ccc2f5a46feea8b5e4e00e837c6af81714284ff1 | Ruby | kellycrowther/odin-project | /pine_chap5.rb | UTF-8 | 433 | 3.390625 | 3 | [] | no_license | puts "WHAT DO YOU WANT?!"
response = gets.chomp
puts "WHADDAYA MEAN \"#{response}\"?!? YOU'RE FIRED!!"
centerWidth = 50
leftWidth = 40
rightWidth = 10
puts ("Table of Contents".center(centerWidth))
puts ("Chapter 1: Numbers".ljust(leftWidth)) + ("page 1".rjust(rightWidth))
puts ("Chapter 2: Letters".ljust(leftWidth))... | true |
e3f434ea077b0f5bb3ad07cf4854127dab2d94df | Ruby | peterayeniofficial/aiport-model | /passenger.rb | UTF-8 | 660 | 3.28125 | 3 | [] | no_license | class Passenger
attr_accessor :name
attr_reader :hometown
@@all = []
def initialize(name, hometown)
@name = name
@hometown = hometown
@@all << self
end
def self.all
@@all
end
def flights
Flight.all.select {|flight| flight.passenger == self}
end
def flight_to_airport(airport,... | true |
023595b31eff2adc2bbcfd8b0b0b24273a382b61 | Ruby | abigezunt/ga-rspec-geometry | /lib/geometry.rb | UTF-8 | 896 | 3.734375 | 4 | [] | no_license | module Geometry
class Triangle
attr_accessor :a, :b, :c, :sides
def initialize(sideA, sideB, sideC)
@a = sideA
@b = sideB
@c = sideC
@sides = [@a, @b, @c]
sides.sort!
end
def valid?
if @sides[0] + @sides[1] <= @sides[2]
false
else
true
end
end
def perimeter
self.sid... | true |
d097e307147df3d1e2d7a46920c51b5f980b1b21 | Ruby | hanairo-129/furima-34401 | /spec/models/user_spec.rb | UTF-8 | 5,717 | 2.671875 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
before do
@user = FactoryBot.build(:user)
end
context "ユーザー新規登録ができる時" do
it "nick_nameが空でなければ登録できること" do
@user.nick_name = 'test'
@user.valid?
expect(@user).to be_valid
end
it 'passwordが6文字以上、かつ半角英数字であれば登... | true |
fc33a5ab750070b954f01f020b19a3590bb3e361 | Ruby | longthanhtran/ruby-meta | /classes/singleton_methods.rb | UTF-8 | 337 | 3.65625 | 4 | [
"MIT"
] | permissive | # Method belongs to a single object is called Singletone Method
#
str = "just a regular string"
def str.title?
self.upcase == self
end
# primary way - can also create Singleton Method to an object
class << str
def title?
self.upcase == self
end
end
puts str.title?
puts str.methods.grep(/title?/)
puts str.s... | true |
dba652733cfc301012a9c570ae831925509fefdf | Ruby | baezanat/Launch_School_bootcamp | /RB_100/Introduction_to_Programming/loops_and_iterators/useful_loop.rb | UTF-8 | 42 | 2.84375 | 3 | [] | no_license | i = 0
loop do
i += 1
puts i
break
end | true |
2562aeb79d65b8595ef81a80f2379fe6be796c30 | Ruby | Dromarch/EsteemSystem-VXAce | /Menu Scripts/ES - Menu HotKey.rb | UTF-8 | 4,002 | 2.5625 | 3 | [] | no_license | #==============================================================================
# ** Esteem - Menu HotKey
#==============================================================================
# ► Script por: Skyloftian
#------------------------------------------------------------------------------
# ► Atualizações: 16/06/18... | true |
11bea69412670504ed12d382117c5772f44b2df2 | Ruby | budikpet/SemestralWork_RUB | /spec/cli_logic/base_replace_spec.rb | UTF-8 | 14,625 | 2.5625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'rspec'
require 'renamer'
require 'fileutils'
require 'tmpdir'
require 'pathname'
require 'stringio'
require_relative '../spec_helper'
require_relative '../spec_utils'
describe 'Renamer::CLI_Logic, base_replace command: ' do
before(:all) do
@used_tmp_dirs = []
end
befo... | true |
c474c4c8ee20157e30c10d53f7e44f9dda9005d0 | Ruby | gvschaitanya93/Hacker-Rank | /hackerrank-master 3/domains/ruby/04-Enumerable/02-each_with_index/solution.rb | UTF-8 | 152 | 3.375 | 3 | [] | no_license | def skip_animals(animals, skip)
arr = []
animals.each_with_index do |item, index|
arr.push("#{index}:#{item}") if index >=skip
end
return arr
end
| true |
54c0182a75222d9e5a89eea67e8ad17a56505526 | Ruby | HaopengLiu-1992/leetcode-ruby | /leetcode/369_Plus_One_Linked_List.rb | UTF-8 | 514 | 3.25 | 3 | [
"ICU",
"Ruby"
] | permissive | require_relative 'helper'
# Leetcode 369
class PlusOneLinkedList
include Helper::LinkedListHelper
def plus_one(head)
arr = []
p = head
until p.next.nil?
arr << p
p = p.next
end
p.val = p.val + 1
arr << p
flag = 0
until arr.empty?
p = arr.pop
p.val = p.val + fl... | true |
0be6e1c2f12642ec5be49d234d224ad7af08778e | Ruby | gabrielecirulli/supernova | /lib/supernova/remote/common/features/feature.rb | UTF-8 | 1,588 | 2.65625 | 3 | [
"MIT"
] | permissive | module Supernova
module Remote
module Common
module Features
# The information about the feature that was defined.
class Feature
# The name of the feature.
#
# @return [Symbol]
attr_accessor :name
# The options of the feature.
#
... | true |
0cdeb84bc611e3afa71ec391a6740b4bcbca9120 | Ruby | ministryofjustice/c100-application | /app/presenters/summary/sections/c8_applicants_details.rb | UTF-8 | 3,027 | 2.515625 | 3 | [
"LicenseRef-scancode-proprietary-license",
"MIT"
] | permissive | module Summary
module Sections
class C8ApplicantsDetails < PeopleDetails
def name
:c8_applicants_details
end
def show_header?
true
end
def record_collection
c100.applicants
end
# Not using the superclass `PeopleDetails#answers` because, in the c... | true |
d4cf12b5a079ffac27cb2371d60e81c1996292ac | Ruby | marcusshepp/CardistryIO | /app/models/user_with_rating_permissions.rb | UTF-8 | 346 | 2.609375 | 3 | [] | no_license | class UserWithRatingPermissions < SimpleDelegator
def can_rate?(rateable)
not_already_rated(rateable) && not_rating_own_content?(rateable)
end
private
def not_rating_own_content?(rateable)
self != rateable.user
end
def not_already_rated(rateable)
!already_rated?(rateable, type: rateable.class... | true |
10330e6dae62f2d06c0b0d78684dc0e8e4ce4108 | Ruby | fargelus/ruby-oop-patterns | /behaviour_patterns/command.rb | UTF-8 | 4,433 | 3.34375 | 3 | [] | no_license | # frozen_string_literal: true
require 'singleton'
class Employee
attr_accessor :name, :number, :address
def initialize(args = {})
@name = args[:name]
@number = args[:number]
@address = args[:address]
end
def to_s
"Employee: name: #{name} number: #{number} address: #{address}"
end
def to... | true |
98eef8ea9e3e2000385efe9af6d04ab493e54ec6 | Ruby | StevenACZ/ruby-regex-StevenACZ | /24contact/contact_test.rb | UTF-8 | 637 | 2.6875 | 3 | [] | no_license | require_relative "../lib/io_test_helpers"
require "minitest/autorun"
require_relative "contact"
class ContactTest < Minitest::Test
def test_can_create_contact
# skip
contact = Contact.new("John Doe", "john@mail.com")
assert_instance_of(Contact, contact)
end
def test_contact_remember_they_name_and_e... | true |
b0041b5b2a1c54bfa412dc73aed669030671cbb5 | Ruby | jvidalba1/learn-ruby | /Semana 1/Problema 6/benitez.rb | UTF-8 | 185 | 3.296875 | 3 | [] | no_license | contador =0
natural=0
puts "entre el numero natural"
natural=gets.chomp.to_i
while(contador<natural)do
contador = contador+1
end
puts "en total hay #{contador} numeros naturales"
| true |
aa35e41da85ea62f176245b72241e5db2eed3c92 | Ruby | weymanf/myvegascraps | /spec/lib/unit/craps/bet_spec.rb | UTF-8 | 1,199 | 2.828125 | 3 | [] | no_license | require_relative '../../../spec_helper'
require_relative '../../../../lib/craps/bet'
describe Craps::Bet do
subject(:bet) { described_class.new(amount, player_guid) }
let(:amount) { 10 }
let(:player_guid) { 'random-guid' }
describe '#amount' do
it 'returns the amount of the bet' do
expect(bet.amount... | true |
4373669471d1a3fa9d7156a62489a5e6b823003b | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/gigasecond/689ae5e672864427bbb7e3529b38882d.rb | UTF-8 | 103 | 2.828125 | 3 | [] | no_license | class Gigasecond
def self.from(time)
gigasecond = 10**9
Time.at(time + gigasecond)
end
end
| true |
14f8abd7cd64f50de5a17c9b53cf9a7304c3d846 | Ruby | defunkt/rails | /activerecord/lib/active_record/associations/preloader.rb | UTF-8 | 8,656 | 2.828125 | 3 | [
"Ruby",
"MIT"
] | permissive | module ActiveRecord
module Associations
# Implements the details of eager loading of Active Record associations.
#
# Note that 'eager loading' and 'preloading' are actually the same thing.
# However, there are two different eager loading strategies.
#
# The first one is by using table joins. T... | true |
46e3eeb677f2d18a668cf5aed185281b2ab8aabf | Ruby | Mera-Stackhouse/collections_practice_vol_2-seattle-web-career-031119 | /prac3.rb | UTF-8 | 558 | 3.328125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def organize_schools(hash)
new_hash = Hash.new(0)
hash.each {|key, value|
key1 = key
value.each {|key, value|
if new_hash.has_key?(value)
new_hash[value] << key1
elsif !new_hash.has_key(value)
new_hash[value] = []
new_hash[value] << key1
end
}
}
end
hash = {... | true |
409f1aaf963a18cbfa8dc26b5cde2076c2560bd6 | Ruby | sarahyjja/RomanNumerals | /spec/roman-numerals_spec.rb | UTF-8 | 961 | 2.96875 | 3 | [] | no_license | require 'roman-numerals'
describe RomanNumerals do
it 'returns "I" when I have "1"' do
roman_numerals = RomanNumerals.new
expect(roman_numerals.calcul(1)).to eq 'I'
end
it 'returns "V" when I have "5"' do
roman_numerals = RomanNumerals.new
expect(roman_numerals.calcul(5)).to eq 'V'
end
it 're... | true |
638ab1e6db47e4e04e28677eea9f8a006645430a | Ruby | oguzcanbayyurt/Ruby-Ornekler | /OklidRecursive.rb | UTF-8 | 274 | 3.546875 | 4 | [] | no_license | def oklid(a, b)
if b == 0
return a
else
puts "#{a} = #{(a / b)} * #{b} + #{a % b}"
return oklid(b, a % b)
end
end
print "1.Sayıyı Giriniz: "
sayi1 = gets.to_i
print "2.Sayıyı Giriniz: "
sayi2 = gets.to_i
puts "\ngcd(a,b) = #{oklid(sayi1,sayi2)}" | true |
9efac1c15826f7450c79e89c0625044300fa5dff | Ruby | nickrobinson/cloudwatch_rails | /lib/cloudwatch_rails/async_queue.rb | UTF-8 | 1,061 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'thread'
require 'cloudwatch_rails/cloudwatch_helper'
require 'cloudwatch_rails/config'
module CloudwatchRails
class AsyncQueue
attr_reader :consumer, :queue, :cloudwatch_helper
def initialize
@cloudwatch_helper = CloudwatchRails::CloudwatchHelper.new
@queue = Queue.new
@consumer =... | true |
5c66919ab8661c0eb8e5b6a1d47adcec576c5b15 | Ruby | andrely/tag-annotator | /app/models/sentence.rb | UTF-8 | 3,133 | 2.703125 | 3 | [] | no_license | class Sentence < ActiveRecord::Base
has_many :words, :order => 'sentence_index', :dependent => :destroy
belongs_to :tagged_text
accepts_nested_attributes_for :words, :allow_destroy => true
def printable_string
words = self.words.sort_by {|w| w.sentence_index}
strings = words.collect {|w| w.printable_s... | true |
0324bd205da3bc01b938bebd3f5b126d47ed308a | Ruby | lizgene/rentmycat | /app/models/cat.rb | UTF-8 | 382 | 2.515625 | 3 | [] | no_license | class Cat < ActiveRecord::Base
has_many :cart_items
before_destroy :ensure_cat_not_in_any_cart
private
# ensure that no one has the cat in their cart before deleting
def ensure_cat_not_in_any_cart
if cart_items.empty?
return true
else
errors.add(:base, 'This cat is in a cart... | true |
f7bf5001df2cda77dab0d03a24befe131253fcec | Ruby | smcb1/week_four_day_one_homework | /models/game.rb | UTF-8 | 507 | 3.609375 | 4 | [] | no_license | class Game
def self.play(hand1, hand2)
return "It's a draw!" if hand1 == hand2
win_conditions = {
"rock" => "scissors",
"scissors" => "paper",
"paper" => "rock"
}
hand_one_beats = win_conditions[hand1]
if hand_one_beats == hand2
return... | true |
8862e6e074cffa476cb876c76b178fb14ca4847c | Ruby | ralam/diary | /db/seeds.rb | UTF-8 | 2,533 | 2.671875 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
2c96a9cf6f614017ea1a40308ba58d3cdc211829 | Ruby | didy400/tests-ruby | /lib/03_basics.rb | UTF-8 | 744 | 3.5625 | 4 | [] | no_license | def who_is_bigger(a = gets.chomp.to_f, b = gets.chomp.to_f, c = gets.chomp.to_i )
if a == nil
return "nil detected"
elsif b == nil
return "nil detected"
elsif c == nil
return 'nil detected'
elsif a > b
if a > c
return "a is bigger"
else
ret... | true |
c044d8e6fdf2d7423f86cce705975b613bf37176 | Ruby | OlegBandura/learn_ruby | /02_calculator/calculator.rb | UTF-8 | 382 | 3.625 | 4 | [] | no_license | def add(first_arg, second_arg)
first_arg + second_arg
end
def subtract(first_arg, second_arg)
first_arg - second_arg
end
def sum(arr)
arr.inject(0) { |sum, x| sum + x }
end
def multiply(*num)
num.inject(:*)
end
def power(first_arg, second_arg)
first_arg**second_arg
end
def factorial(args)
return 1 if a... | true |
534aa4000c79ddaafbfba2a75bd238a340273661 | Ruby | mateoconfeugo/capcom-cc | /interviews-ruby-financial_summary-0.4/app/models/financial_summary.rb | UTF-8 | 1,839 | 2.875 | 3 | [
"MIT"
] | permissive | require 'transaction'
class FinancialSummary < ApplicationRecord
@summary_totals = {}
belongs_to :user
def self.count(category)
@summary_totals[category][:count]
end
def self.amount(category)
cents = @summary_totals[category][:amount]
Money.us_dollar(cents)
end
def self.one_day(user:, curre... | true |
3e858cc6031fccab39275355f42c63cd7d5ef8eb | Ruby | takutakuta6/ruby_task | /01_2.rb | UTF-8 | 105 | 3.125 | 3 | [] | no_license | #inputs = gets.to_i
#p inputs
print "数値を入力して下さい > "
num = gets.to_i
puts num * 1000
| true |
46fd93845ea964eb592cb395a746d22a6bf8487d | Ruby | DaichiSakakibara/furima-31728 | /spec/models/user_spec.rb | UTF-8 | 4,058 | 2.609375 | 3 | [] | no_license | require 'rails_helper'
describe User do
before do
@user = FactoryBot.build(:user)
end
describe 'ユーザー新規登録' do
context '新規登録がうまくいくとき' do
it 'nicknameとemail、passwordとpassword_confirmation、last&first_name及びkanaが存在すれば登録できる' do
expect(@user).to be_valid
end
end
context '新規登録がうまくいかな... | true |
6fe462924eb85a0d5c0542a4f77361416b279942 | Ruby | ClementPain/Jour-7---Ruby-exercices | /text20.rb | UTF-8 | 193 | 3.046875 | 3 | [] | no_license | puts "Salut, bienvenue dans ma super pyramide ! Combien d'étages veux-tu ?"
print "> "
nb_floor=Integer(gets)
puts "Voici la pyramide :"
i=1
j=1
while i <= nb_floor
puts ("#"*i)
i+=1
end | true |
d221d2dfc1bea85052bb928bf663ba2d28f1df88 | Ruby | amrutatakawale/dsa | /sorting_algorithms/selection_sort.rb | UTF-8 | 420 | 4.03125 | 4 | [] | no_license | #Selection sort
#Finds minimum element from array and puts at newly created array or can be swapped with ith element of array
arr = [100, 10, 30, 90, 40, 50, 70, 10]
def selection_sort(arr)
len = arr.length - 1
(0..len).each do |i|
min_idx = i
((i + 1)..len).each do |j|
min_idx = j if arr[j] < arr[m... | true |
6d9d5f105f3d2bbc3877cd346d9d548bf6c28967 | Ruby | mattbrictson/tomo | /lib/tomo/cli/rules.rb | UTF-8 | 2,509 | 2.875 | 3 | [
"MIT"
] | permissive | module Tomo
class CLI
class Rules
autoload :Argument, "tomo/cli/rules/argument"
autoload :Switch, "tomo/cli/rules/switch"
autoload :ValueSwitch, "tomo/cli/rules/value_switch"
ARG_PATTERNS = {
/\A\[[A-Z_]+\]\z/ => :optional_arg_rule,
/\A[A-Z_]+\z/ => :requir... | true |
33e01933316c031fa9d8ef376d0b456e446f2bdf | Ruby | tmaeda/auto_ar | /test/auto_ar_test.rb | UTF-8 | 2,171 | 2.546875 | 3 | [] | no_license | require File.dirname(__FILE__) + '/test_helper.rb'
class AutoArTest < Test::Unit::TestCase
DBFILE = "test/auto_ar_test.sqlite3"
def setup
ActiveRecord::Base.establish_connection(:adapter => "sqlite3",
:database => DBFILE)
migrate = Class.new(ActiveRecord::Migrati... | true |
97e8d3ac4ebf134bba4c2055ffd7c39e856db17f | Ruby | kenrett/lacroix | /app/lib/slack.rb | UTF-8 | 5,165 | 2.890625 | 3 | [] | no_license | require 'faraday'
require 'faraday_middleware'
require 'json'
require 'mimemagic'
#
# Basic wrapper for Slack API to sending messages and files.
# You can either send messages via the Slack API, or format them for response _back_
# to Slack when interacting with Slash commands or other actions
# When responding back t... | true |
7f6f75ca0edada412dc7c33d77818cca8b89c4bc | Ruby | NikkiAlbon/smart-answers | /test/unit/erb_renderer_test.rb | UTF-8 | 11,406 | 2.546875 | 3 | [
"MIT",
"LicenseRef-scancode-proprietary-license"
] | permissive | require_relative "../test_helper"
module SmartAnswer
class ErbRendererTest < ActiveSupport::TestCase
test "#erb_template_path returns the combination of the template directory and name" do
erb_template = ""
with_erb_template_file("template-name", erb_template) do |erb_template_directory|
rend... | true |
fa2a58d6f2a07e807c87b2c0674a575f52b727b8 | Ruby | artzlt/bottle_rocket | /lib/bottle_rocket/containers/amount_container.rb | UTF-8 | 368 | 2.640625 | 3 | [
"MIT"
] | permissive | module BottleRocket
module Containers
class AmountContainer
include ::BottleRocket::ContentTags
attr_reader :value
def initialize(value)
@value = value
end
def to_html
ContentTag.new(:span, class: "amount amount-#{value}").to_s do
value.to_... | true |
d0002f255aa397d5e940a99528e3c36041dd9166 | Ruby | plukevdh/monet | /lib/monet/diff_strategy.rb | UTF-8 | 2,299 | 2.953125 | 3 | [
"MIT"
] | permissive | require 'monet/errors'
module Monet
class DiffStrategy
include ChunkyPNG::Color
attr_reader :score
def initialize(base_image, diff_image)
@base_image = base_image
@diff_image = diff_image
@score = []
raise Errors::DifferentDimensions unless dimensions_match?
end
def ca... | true |
ad17c5d90940a49b462506763ed5fd4ac771f0f6 | Ruby | yekyaw/StochasticSLDA | /parse_webkb.rb | UTF-8 | 1,646 | 2.90625 | 3 | [] | no_license | require 'set'
def parse_webkb(dir, output_train, output_test, labels_train, labels_test, vocab_file)
get_dirs = lambda do |dir|
Dir.entries(dir).select { |f| File.directory? File.join(dir, f) and !(f == '.' || f == '..') }
end
categories = get_dirs.call(dir)
o1 = File.open(output_train, 'w')
l1 = File.op... | true |
62d42fbc12c023ab321e0e0e6c3bd0a43a2e2827 | Ruby | sotoseattle/rosalind | /rosalind_fib.rb | UTF-8 | 141 | 3.109375 | 3 | [] | no_license | months = 28
litter = 2
fib = {1 => 1, 2 => 1}
(1..months).each { |n| fib[n] ||= fib[n-1] + fib[n-2]*litter }
puts "total: #{fib[months]}"
| true |
8ec8b8b1e81616540230013c0560f85413ab4543 | Ruby | Jonesyd/launchschool_exercises | /small_problems/93_m1_1000_lights.rb | UTF-8 | 457 | 3.671875 | 4 | [] | no_license | def lights_on(integer)
array = []
array.fill(false, 0, integer)
interval = 1
while interval <= array.count
array.each_with_index do |bool, index|
if (index + 1) % interval == 0
array[index] = !bool
end
end
interval += 1
end
new_array = []
array.each_with_index do |bool, i... | true |
f8de4bf56242566d1c6100b28aab6b851724c6bb | Ruby | gleuch/my-color-today | /gemcheck.rb | UTF-8 | 854 | 2.78125 | 3 | [
"MIT",
"LicenseRef-scancode-other-permissive"
] | permissive | require 'rubygems'
require 'gems'
gems = {}
File.open('Gemfile', 'r') do |f|
while l = f.gets
next unless l.match(/^([\s\t]+)?gem/i)
l = l.gsub(/\s|\t/m,'').gsub(/^([\s\t]+)?gem/,'').gsub(/\"/m,'\'')
if l.match(/^\'([A-Z0-9\_\-]+)\'(,\'([\=\~\>\<A-Z0-9\.]+)\'.*)?$/i)
n,v = l.gsub(/^\'([A-Z0-9\_\-]... | true |
8193e4d7eb54677ffb8c276fd8785812c66de460 | Ruby | matejuh/rub_html | /test/test_errors.rb | UTF-8 | 2,464 | 2.609375 | 3 | [] | no_license | #test some errors which are special handled
require 'test/unit'
require 'stringio'
require_relative '../lib/htmlparser/HtmlParser'
class TestHtmlParserErrors < Test::Unit::TestCase
def setup
ARGV.clear
@stdout_orig=$stdout.clone
$stdout=StringIO.new
@stderr_orig=$stderr.clone
$stderr=StringIO.ne... | true |
35bb0bc25e0639f46ca39d089f31e5091597f7c3 | Ruby | AliceBrunel/anagram-detector-online-web-sp-000 | /lib/anagram.rb | UTF-8 | 313 | 3.53125 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Anagram
attr_accessor :name
def initialize(name)
@name = name.split("")
@name
end
def match(array)
match = []
array.each do |word|
if word.split("").sort == name.sort
match << word
else
nil
end
end
match
end
end | true |
509eec679f64888979170f62eb5f281e928c11fd | Ruby | GreenRecycleBin/ProjectEuler | /Prob42/42.rb | UTF-8 | 758 | 3.640625 | 4 | [] | no_license | #!/usr/bin/ruby -w
class Triangle
attr_accessor :triangles, :n
def initialize
@triangles = []
@n = 0
end
def next_limit(limit)
until !@triangles.empty? && @triangles.last >= limit do
@n = @n.next
triangle = n * (n + 1) / 2
@triangles << triangle
end
end
def include?... | true |
e12a2354754d90fd5ef981b7f11d3b32f278f624 | Ruby | DesTodo/web_guesser | /lib/web_guesser.rb | UTF-8 | 1,182 | 3.40625 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/reloader'
S_NUMBER = rand(101)
@@count = 5
get '/' do
S_NUMBER = rand(101) if @@count == 0
@@count = 5 if @@count == 0
guess = params["guess"].to_i
message = check_guess(guess)
color = color_check(message)
result = result(message)
erb :index, :locals => {:guess => gues... | true |
01f3a4e527eaefde00519b4722b4a394160191a6 | Ruby | maksym-bielyshev/rubylearningcom-tutorial | /p014constructs.rb | UTF-8 | 409 | 3.984375 | 4 | [
"Apache-2.0"
] | permissive | # In Ruby, nil and false evaluate to false,
# everything else (including true, 0) means true
# nil is an actual object
# if else end
var = 5
if var > 4
puts "Variable is greater than 4"
puts "I can have multiple statements here"
if var == 5
puts "Nested if else possible"
else
puts "Too cool"
end
else
... | true |
b55876ff3e8ed609e206912450c20c208e2ca25f | Ruby | aitaro/csv_seeder | /lib/csv_seeder.rb | UTF-8 | 1,647 | 3.046875 | 3 | [
"MIT"
] | permissive | require "csv_seeder/version"
require "csv"
module CsvSeeder
class Error < StandardError; end
# Your code goes here...
def exec(folder_path: 'db/seeds', orders: [])
ins = CSVSeeder.new(folder_path, orders)
ins.dirs_loop!
end
module_function :exec
class CSVSeeder
def initialize(folder_path, o... | true |
9f9dc8040256ebb8d2de36d88c4cf1d80a48afed | Ruby | dwbutler/numeric | /lib/numeric.rb | UTF-8 | 1,095 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'rational'
require 'bigdecimal'
require 'complex'
class String
def numeric?
complex?
end
def complex?
!!Complex(self) rescue false
end
def rational?
!!Rational(self) rescue false
end
def integer?
!!Integer(self) rescue false
end
def float?
!!Float(self) rescue false
... | true |
393e2bfb82270193987973f1e1ac3d35deec8d2f | Ruby | vadumont/RubyIUT | /tp3/Creatures_binaire/lib/csv_serializer.rb | UTF-8 | 1,199 | 2.59375 | 3 | [] | no_license | # csv_serializer.rb
#
# Copyright 2017 Valentin Dumont <vadumont2@b12-233>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any ... | true |
a90499b8b43e07bf23b30f037170d241b40ba8d0 | Ruby | j-sm-n/black_thursday | /lib/merchant_repository.rb | UTF-8 | 779 | 3.078125 | 3 | [] | no_license | require_relative '../lib/merchant'
require_relative '../lib/repository'
class MerchantRepository
include Repository
attr_reader :repository,
:parent
def initialize(contents, parent)
@repository = contents.map { |row| Merchant.new(row, self) }
@parent = parent
end
def find_all_by_name... | true |
3572ebd7371d488d62ea191d3059f1764a21e5f2 | Ruby | shadow3x3x3/skyline-path | /structure/edge.rb | UTF-8 | 283 | 2.859375 | 3 | [
"Apache-2.0"
] | permissive | # Record Edge
class Edge
attr_accessor :id, :src, :dst, :attrs
def initialize(attrs)
@id = attrs.shift.to_i
@src = attrs.shift.to_i
@dst = attrs.shift.to_i
@attrs = attrs
end
def dist
@attrs.first
end
def min_value
@attrs.last
end
end
| true |
21552cdbd0713e29cfe4f583ecc6ca31fd12102f | Ruby | nemalipuri/adapter-api-simulator | /read_file.rb | UTF-8 | 143 | 2.75 | 3 | [] | no_license | def read_file(file_name)
file = File.open(File.join(File.dirname(__FILE__), "#{file_name}"), 'r')
data = file.read
file.close
data
end | true |
578ed47cff5783df85283cd530cbaf37da5f952d | Ruby | joshlock3/testrail-rails | /lib/testrail/suite.rb | UTF-8 | 580 | 2.578125 | 3 | [
"MIT"
] | permissive | module TestRail
class Suite
def initialize(api_client)
@api_client = api_client
end
def find(suite_name, project)
suite_path = "get_suites/#{project["id"]}"
suites = @api_client.send_get(suite_path)
suites.select{ |x| x["name"]== suite_name }.first
end
def create(suite_n... | true |
660b21007070b1c1dd1c0f57371a2dfa35cbfff3 | Ruby | reactormonk/magic_search | /mana-symbols/lib/mana_symbols/parse.rb | UTF-8 | 2,000 | 3.03125 | 3 | [] | no_license | require 'mana_symbols/advanced'
module ManaSymbols
def self.parse(string)
Parser.new(string).cost
end
def self.parse_string(string)
StringParser.new(string)
end
# screw reflection
LOOKUP = {
'W' => Basic::W,
'U' => Basic::U,
'B' => Basic::B,
'R' => Basic::R,
'G' => Basic::G,
... | true |
e6071035e468dba052e6cbd33e43df0f61d0a5b3 | Ruby | julianborrey/TabHub | /app/helpers/tournament_helper.rb | UTF-8 | 2,269 | 2.703125 | 3 | [] | no_license | module TournamentHelper
def get_user_attendence(user)
if user.nil? #if not signed in
return nil; #no user to be attending
end
user_list = {past: [], present: [], future: []};
#get most current if exists
user.tournament_attendees.each { |t| #check each tournament
... | true |
e3f4e71d7a0e8e7e85a01565e6ff9a2fad2767b1 | Ruby | aidamanna/food-to-fork | /features/support/pages/recipes_page.rb | UTF-8 | 614 | 2.546875 | 3 | [] | no_license | class RecipesPage
include PageObject
page_url ENV['RECIPES_URL']
text_field(:search_box, id:'typeahead')
spans(:recipes_name_list, css:'.item.masonry-brick .recipe-name')
def search_recipe(text)
self.search_box = text
self.search_box_element.send_keys(:enter)
end
def check_recipes_list(text)... | true |
dde645fc3299a2b8644c3ff8ef2f1c3582731e02 | Ruby | ycchen/batch_process_api | /spec/requests/authors_spec.rb | UTF-8 | 4,315 | 2.515625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe "Authors", :type => :request do
let(:headers) { {'Content-Type': 'application/json'}}
let(:who) {FFaker::Name.name}
describe "GET /authors" do
it "works! (now write some real specs)" do
FactoryGirl.create :author, name: "John Doe"
FactoryGirl.create :author,... | true |
e65c92fd10fc9cc5b814b9d158553b168bae6cd2 | Ruby | Lukeveille/sept13_reinforcement | /exercise2.rb | UTF-8 | 184 | 3.828125 | 4 | [] | no_license | top_names = ['Luke', 'Tish', 'Matt']
loop do
print 'Who goes there? '
name = gets.chomp
if top_names.include?(name)
puts "Hello #{name}!"
break
end
end | true |
458ebe58e8bad087652ebb1f38c758ddb0021ded | Ruby | teaton212/looping-loop-001-prework-web | /looping.rb | UTF-8 | 95 | 2.671875 | 3 | [] | no_license | def looping
#your code here
loop do
puts "Wingardium Leviosa"
end
end
looping
#call your method here
| true |
30aff983a8065eafeaa65bfc6f2463a442c16d45 | Ruby | takahide/ramen | /lib/tasks/cron.rb | UTF-8 | 4,073 | 2.578125 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
require 'openssl'
require 'kconv'
class Cron
def self.get_prefectures_and_cities
TsukemenRestaurant.find_each do |r|
prefecture = r.prefecture
city = r.city
p = Prefecture.where(name: prefecture).first_or_create
City.where(prefecture: prefecture, pre... | true |
e998e25209e4adbb7ab33b92aff4cd6d1b7267e4 | Ruby | eshull/riddles_sinatra | /spec/riddles_spec.rb | UTF-8 | 529 | 2.90625 | 3 | [] | no_license | require('rspec')
require('riddles')
describe('#riddles') do
it ("what is the sweetest thing? Rich or poor, refreshing, and one would die without its sweet embrace") do
riddle = Riddle.new("sleep", "time")
expect(riddle.riddle_method).to(eq("You shall PASS!"))
end
it ("What is the most precious resource? No... | true |
79d5a8eaa1970bb22b7cd99aca296c76de8fb225 | Ruby | christhede/LaunchSchool | /101_ProgrammingFoundations/Exercises/merge_sorted_lists.rb | UTF-8 | 1,258 | 4.28125 | 4 | [] | no_license | # Write a method that takes two sorted Arrays as arguments,
# and returns a new Array that contains all elements from both
# arguments in sorted order.
# You may not provide any solution that requires you to
# sort the result array. You must build the result array one
# element at a time in the proper order.
# Yo... | true |
e511867f77fdf29f85059ca87460bf989182b678 | Ruby | andreshp/NapakalakiRb | /lib/CardDealer.rb | UTF-8 | 15,327 | 2.96875 | 3 | [] | no_license | #encoding: utf-8
######################################################################
# Authors: Andrés Herrera Poyatos, Juan Luis Suárez Díaz
# Universidad of Granada, March, 2015
# Programación Dirigida y Orientada a Objetos - Ruby Napakalaki
#######################################################################
... | true |
edf88355512d02e428b92cf8d283f21d1ea229be | Ruby | 40ruby/ruby010 | /ruby010-7.rb | UTF-8 | 698 | 2.953125 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
# coding: utf-8
# filename: ruby010-7.rb
require 'json'
class File_CSV
def initialize(filename)
begin
@fp = File.open(filename)
rescue => e
abort "#{e.class} => #{e.message}"
end
@del = ','
end
def read
csv = @fp.each_line.map { |line|
line.chop.split(@... | true |
c6208fd5728cd75ac57aa617cfac3319f665b12c | Ruby | fndelacruz/AlgorithmsPractice | /AA/algorthims_projects/3_heap_heapsort/lib/heap.rb | UTF-8 | 2,717 | 3.734375 | 4 | [] | no_license | require "byebug"
class BinaryMinHeap
DEFAULT_PROC = Proc.new { |el1, el2| el1 <=> el2 }
def self.child_indices(len, parent_index)
[2 * parent_index + 1, 2 * parent_index + 2].select { |idx| idx < len }
end
def self.parent_index(child_index)
raise "root has no parent" if child_index.zero?
(child_in... | true |
1fe7213503cd84099875612ef4ec4c1e0016e0e6 | Ruby | buzzdeee/gitlab-ce-old | /lib/gitlab/database/migration_helpers.rb | UTF-8 | 9,149 | 2.828125 | 3 | [
"MIT"
] | permissive | module Gitlab
module Database
module MigrationHelpers
# Creates a new index, concurrently when supported
#
# On PostgreSQL this method creates an index concurrently, on MySQL this
# creates a regular index.
#
# Example:
#
# add_concurrent_index :users, :some_col... | true |
ca7986afca3914fc387ec4dfdd84f43671f89c08 | Ruby | heydanhey/oop | /tic_tac_toe.rb | UTF-8 | 2,002 | 4.4375 | 4 | [] | no_license |
class TicTacToe
attr_accessor :board, :player_x, :player_o
def initialize
@board = Board.new
@player_x = "X"
@player_o = "O"
end
def take_turn(player)
puts "It is now player #{player}'s turn:"
puts "Please selcet row (1,2 or 3):"
row = gets.chomp.to_i - 1
puts "Please selesct a co... | true |
7e8154eb9d7a4f57154654c673f75fc5e4c317d9 | Ruby | mfroment/rails-edumate | /app/models/booking.rb | UTF-8 | 326 | 2.546875 | 3 | [] | no_license | class Booking < ApplicationRecord
belongs_to :user
belongs_to :lesson
validates :lesson, presence: true
validates :user, presence: true, uniqueness: { scope: :lesson }
validate :student_not_teacher
def student_not_teacher
errors.add(:user, "cannot book a lesson they teach") if user == lesson.user
en... | true |
060f76615dd68b43f6f69bcb6a8b89a535ecf75a | Ruby | akerl/basiccache | /lib/basiccache.rb | UTF-8 | 725 | 2.59375 | 3 | [
"MIT"
] | permissive | ##
# This module provides a simple key/value cache for storing computation results
module BasicCache
class << self
##
# Insert a helper .new() method for creating a new Cache object
def new(*args)
self::Cache.new(*args)
end
##
# Provide a helper method to get the calling function name
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.