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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
26547035256330a09722bb23e8e10258696ae9d7 | Ruby | codecraft-peru/sevenlanguages | /01-ruby/jersson/day-02/ex-01.rb | UTF-8 | 566 | 4.21875 | 4 | [] | no_license | # Print the contents of an array of sixteen numbers, four numbers at a time,
# using just each.
# Now, do the same with each_slice in Enumerable.
numbers = (0..15).to_a
puts 'Print four numbers at a time, using each'
numbers.each do |n|
if n % 4 == 0
puts "- Round #{1+ n / 4}: #{numbers[n..(n+3)]}"
... | true |
324892fe318cfa780bbf5bbae608da1f7ed12224 | Ruby | saramic/the-d-team-2017 | /scripts/scrape_pharma_compass_patent_expiry.rb | UTF-8 | 533 | 2.71875 | 3 | [] | no_license | #!/usr/bin/env ruby
# to run assuming you have gems installed
# scripts/scrape_pharma_compass_patent_expiry.rb > small_data/pharma_compass_patent_expiry.csv
require "csv"
require "open-uri"
require "nokogiri"
url = 'http://www.pharmacompass.com/patent-expiry-expiration'
doc = Nokogiri::HTML.parse(open(url))
puts C... | true |
9d8f3c07f5aec82bab3fee0e491f5df143c4079b | Ruby | Supernats/color_calculator | /lib/color_calculator/clump/rgb.rb | UTF-8 | 627 | 2.609375 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'abstract'
module ColorCalculator
module Clump
class Rgb < Abstract
class << self
def attributes
%i[red green blue]
end
end
def initialize(*attributes, normalized:)
@red, @green, @blue = attributes
@norma... | true |
84e082020fba564feaefc659ab025bf7c7e79003 | Ruby | alrivasp/herenciaPolimorfismoHerencia | /Ejercicio2/Main.rb | UTF-8 | 1,544 | 3.046875 | 3 | [] | no_license | require_relative 'Paloma'
require_relative 'Pato'
require_relative 'Pinguino'
require_relative 'Gato'
require_relative 'Perro'
require_relative 'Vaca'
require_relative 'Mosca'
require_relative 'Mariposa'
require_relative 'Abeja'
#Paloma
paloma = Paloma.new("bob")
puts paloma.nombre
puts "Habilidades"
puts paloma.volar... | true |
eb6509615857959b859fe75633f4e6d2a56a6dab | Ruby | hynsondevelops/TrakstarApplication | /TrakstarFizzbuzz.rb | UTF-8 | 354 | 3.765625 | 4 | [] | no_license | def TrakstarFizzbuzz()
rangeMin = 1
rangeMax = 100
for num in rangeMin..rangeMax do
if (num % 3 == 0 && num % 5 == 0) #divisible by 3 and 5
puts "Trakstar"
elsif (num % 3 == 0) #divisible by 3
puts "Trak"
elsif (num % 5 == 0) #divisible by 5
puts "Star"
else #otherwise print the number
puts num
... | true |
b10242cd26f9cb54e9393eeec2ab7142ffbd4da8 | Ruby | knollt/collections_practice-v-000 | /collections_practice.rb | UTF-8 | 825 | 3.921875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def sort_array_asc (integers)
integers.sort
end
def sort_array_desc (integers)
integers.sort { |a,b| b <=> a}
end
def sort_array_char_count (strings)
strings.sort { |left, right| left.length <=> right.length }
end
def swap_elements (array)
array[1], array[2] = array[2], array[1]
return array
end
def rever... | true |
ec6a18bbb3f8f2812458f5b26f3394b0aeeebd77 | Ruby | leandroperesbr/frontend | /exemplos-ruby/exceptions.rb | UTF-8 | 993 | 3.71875 | 4 | [] | no_license | #encoding: utf-8
=begin
print "Digite um numero:"
numero = gets.to_i
begin
resultado = 100 / numero
rescue
puts "Numero digitado inválido!"
exit
end
puts "100/#{numero} é #{resultado}"
=end
=begin
def verifica_idade(idade)
unless idade > 18
raise ArgumentError,
"Você precisa ser maior de idade para jogar jo... | true |
9bea95b07a1e5695632524c7de44f5ca32dce94b | Ruby | Vampire010/Pooja_Ruby_Demo | /Demo1/get_data_from_user.rb | UTF-8 | 171 | 2.8125 | 3 | [] | no_license | class Get_Data_From_User
# Num1 = gets
# Num2 = gets
puts " Enter Num1 To Display: "
puts Num1 = gets
puts " Enter Num2 To Display: "
puts Num2 = gets
end | true |
9fef695aaf83aad301a78121a2722f6bb5c4385c | Ruby | dmikhr/time_management | /sumtime.rb | UTF-8 | 1,223 | 3.5 | 4 | [] | no_license | # methods for calculating time based on time ranges supplied as string
class SumTime
include Format
attr_accessor :output_format
def initialize(time_str)
@time_str = time_str
@output_format = :float_hr
time_in_blocks
end
def calculate_time
@all_time_min = 0
@time_blocks.each { |time_bloc... | true |
758b4a9dc1073728562db2c483bbc95a3146028d | Ruby | brianbier/phase_0 | /week_5/grocery_list.rb | UTF-8 | 1,894 | 4.09375 | 4 | [
"MIT"
] | permissive | # def create_list
# puts "what is the name of the list?"
# list_name = gets.chomp
# hash = {"name"=>list_name,"item" =>{}}
# end
# def add_to_list
# puts "What items do you want to add to the list?"
# item_name = gets.chomp
# end
# def print_list(list)
# puts ""
# puts "\t#{list["name"]}"
# puts ""
... | true |
db2fbe922f9d0b42064b8d067a0d29bd655cd6de | Ruby | ortizjs/algorithms_ | /InterviewCakeProblems2/reverse_words.rb | UTF-8 | 738 | 4 | 4 | [] | no_license | def reverse_words(message)
message = reverse_str_in__place(message, 0, message.length - 1)
i = 0
startIdx = 0
until i == message.length + 1
char = message[i]
if char == " " || i == message.length
reverse_str_in__place(message, startIdx, i - 1)
startIdx = i + 1
... | true |
f134e9640d36b4f8384864d5dc25f0ad45b28892 | Ruby | banyan/config | /bin/misc/git-rel | UTF-8 | 1,143 | 2.75 | 3 | [] | no_license | #!/usr/bin/env ruby
def yellow s; "\033[33m#{s}\033[0m" end
def cyan s; "\033[36m#{s}\033[0m" end
`git fetch -q`
highlighted = 0
`git branch -v`.each do |line|
match = /(.*)(behind|ahead) ([0-9])+(.*)/.match(line)
next unless match
highlighted += 1
color = (match[2] == "behind") ? :yellow : :cyan
puts matc... | true |
a0613b3069066e42fcf26f7b18add973c6d7baaa | Ruby | reidiculous/actionwebservice-client | /lib/action_web_service/soap/property.rb | UTF-8 | 7,101 | 2.625 | 3 | [
"MIT"
] | permissive | # soap/property.rb: SOAP4R - Property implementation.
# Copyright (C) 2003 NAKAMURA, Hiroshi <nahi@ruby-lang.org>.
# This program is copyrighted free software by NAKAMURA, Hiroshi. You can
# redistribute it and/or modify it under the same terms of Ruby's license;
# either the dual license version in 2003, or any lat... | true |
2c8eb7cf8d5458c457ca26998eb227ff8f9416d1 | Ruby | lewcastles/RB101 | /small_problems/easy_8/double_char.rb | UTF-8 | 214 | 3.40625 | 3 | [] | no_license | def repeater(str)
result = ''
str.chars.each do |element|
result << element * 2
end
result
end
p repeater('Hello') == "HHeelllloo"
p repeater("Good job!") == "GGoooodd jjoobb!!"
p repeater('') == '' | true |
79428177fc28c12c79fd4025cb82b0b7ad504712 | Ruby | johncban/newsjournal | /lib/newsjournal/newsgreet.rb | UTF-8 | 908 | 2.75 | 3 | [
"MIT"
] | permissive | class Newsjournal::NewsGreet
def self.screen_clear
if Gem.win_platform?
system 'cls'
else
system 'clear'
end
end
def self.newsStartGreet
font = TTY::Font.new(:doom)
current_td = Time.now
screen_clear
puts "\n"
puts "TO... | true |
b9cbc43459172c15be02bb18ca9c944ea7428d65 | Ruby | akshaychanna/all | /data/data/study_material/akshay/ruby/case.rb | UTF-8 | 189 | 3.734375 | 4 | [] | no_license | print "enter any nubmber between 1-100:"
val=gets.chomp.to_i
p val
def call(val)
case val
when 1..10
p "bet 1-10"
when 11..20
p "bet 11-20"
else
p "other"
end
end
call(val)
| true |
da9625786d8ab7fbf9352778827123453fe38a5f | Ruby | MadBomber/experiments | /rake_task_parameters/rake_task_arguments.rb | UTF-8 | 586 | 2.8125 | 3 | [] | no_license | # rake_task_arguments.rb
require 'docopt'
class RakeTaskArguments
def self.parse(task_name, argument_spec, args)
arguments = {}
begin
args.delete_at(1) if args.length >= 2 and args.second == '--'
Docopt::docopt(argument_spec, {:argv => args}).each do |key, value|
arguments[key == "--" ... | true |
77932c683dc1f7b59f13d84f0d9a2e0d0f8cd043 | Ruby | seaify/magicfile | /lib/magicfile.rb | UTF-8 | 1,920 | 3.09375 | 3 | [] | no_license | require 'awesome_print'
require 'active_support'
require 'active_support/core_ext/string'
class MagicLine
attr_accessor :content, :space_num
def initialize(content='', space_num=0)
@content = content
@space_num = space_num
end
end
class Magicfile
def initialize(lines=[], current_line_index=-1, curre... | true |
b362d58d6efbd37f2281b2fcb61a5410197af66b | Ruby | 3scale/3scale_time_range | /test/granulate_test.rb | UTF-8 | 5,123 | 2.75 | 3 | [
"Apache-2.0"
] | permissive | require 'minitest/autorun'
require_relative '../lib/3scale_time_range'
class GranulateTest < Minitest::Test
def setup
range = DateTime.parse('2012-10-09 07:23')..DateTime.parse('2014-02-05 13:45')
@granulated_range = TimeRange.granulate(range)
end
def test_granulates_by_year
assert_equal @granulate... | true |
e97b51d848c0a00996f6b29ead1f5463d85b03e3 | Ruby | hich34/exo_ruby | /exo_11.rb | UTF-8 | 123 | 2.984375 | 3 | [] | no_license | txt = "salut, ça farte ? "
puts "choisis un nombre"
print "<"
user_number = gets.chomp.to_i
puts "#{txt * user_number}"
| true |
5d74998edbf273b489a502e35299c6f4450baf79 | Ruby | danielng09/App-Academy | /w2d1 Minesweeper/minesweeper.rb | UTF-8 | 4,115 | 3.5 | 4 | [] | no_license | class Board
attr_reader :rows
def self.blank_grid
Array.new(9) {Array.new(9)}
end
def initialize(rows = self.class.blank_grid)
@rows = rows
make_tiles
place_mines
end
def []=(pos, mark)
row, col = pos[0], pos[1]
@rows[row][col] = mark
end
def [](pos)
row, col = pos[0], pos... | true |
5bdb32a71a47d064869e8801c1640a657903f034 | Ruby | loverealm/srealm-rails | /lib/ext/array.rb | UTF-8 | 304 | 3.34375 | 3 | [] | no_license | class Array
# delete empty values (null, '') of current array
def delete_empty
self.delete_if{|v| !v.present? }
end
# convert all array values into integer values
def to_i
self.map{|v| v.to_i }
end
def empty_if_include_blank!
self.replace([]) if self.include? ''
end
end | true |
33f2a31c0b7c1d40921e0de1c3ed89848a8c8182 | Ruby | ayjlee/api-muncher | /lib/edamam_api_wrapper.rb | UTF-8 | 1,937 | 2.875 | 3 | [] | no_license | require 'httparty'
class EdamamApiWrapper
BASE_URL = "https://api.edamam.com/"
APP_ID = ENV["EDAMAM_ID"]
APP_KEY = ENV["EDAMAM_KEY"]
def self.search_recipe_results(search_term, app_id = nil, app_key = nil )
app_id ||= APP_ID
app_key ||= APP_KEY
q_url = BASE_URL + "search?q=#{search_term}" + "&app... | true |
ac36fc8cfc014011a93434fcaad98b88398a8641 | Ruby | arnaldoaparicio/food_truck_event_2110 | /spec/event_spec.rb | UTF-8 | 5,551 | 3.21875 | 3 | [] | no_license | require './lib/event'
require './lib/item'
require './lib/food_truck'
RSpec.describe Event do
it 'exists' do
event = Event.new('South Pearl Street Farmers Market')
expect(event).to be_an(Event)
end
it 'has a name' do
event = Event.new('South Pearl Street Farmers Market')
expect(event.name).to eq... | true |
3de92ff304d07169339374d81db528755f6c3f3a | Ruby | chalmagean/prime_tables | /lib/prime_tables/prime.rb | UTF-8 | 734 | 3.671875 | 4 | [
"MIT"
] | permissive | module PrimeTables
class Prime
def self.take(size)
primes = []
n = 2
while primes.size < size do
primes << n
n = next_prime(n)
end
primes
end
private
def self.next_prime(number)
next_number = number + 1
next_number += 1 until prime?(n... | true |
0668d9697b01efd344e058de3727e1d68d857508 | Ruby | mbarlow12/kodable-task | /data/loader.rb | UTF-8 | 564 | 2.796875 | 3 | [] | no_license | require 'models'
require 'date'
module Loader
def self.load_from_file(path)
fmt = '%Y-%m-%dT%H:%M:%S.%LZ'
csv = CSV.read(path, :headers => true)
csv.map { |row|
begin
person = Models::Person.create(name: row[0])
rescue Sequel::Error => e
person = Models::Person.first(name: row... | true |
326fea80adfe099815c53ddade7c2f996c588313 | Ruby | yuriyberezskyy/programming-univbasics-3-methods-scope-lab-dumbo-web-100719 | /lib/catch_phrases.rb | UTF-8 | 371 | 3.03125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def mario
$status = 'Thank You Mario! But Our Princess Is In Another Castle!'
def phrase
"It's-a me, Mario!"
end
puts phrase
end
puts mario
def toadstool
puts $status
end
puts toadstool
def link
puts "It's Dangerous To Go Alone! Take This."
end
puts link
phrase = "Do A Barrel Roll!"
def any_phrase(p... | true |
131ced37975e19a70ca14194f8df77abba5bdd38 | Ruby | avbrychak/heritage-cookbook | /app/models/textblock.rb | UTF-8 | 1,582 | 3.03125 | 3 | [] | no_license | class Textblock < ActiveRecord::Base
before_save :convert_text_to_html
attr_accessible :name, :description, :text, :text_html
# -- Validations ----------------------------------------------------------
validates_presence_of :name, :description
validates_uniqueness_of :name
# -- Callbacks ... | true |
3719125bf5a7300c5be44fbdd136060933b38968 | Ruby | ryenus/bloombroom | /lib/bloombroom/filter/bloom_filter.rb | UTF-8 | 1,782 | 3.328125 | 3 | [
"Apache-2.0"
] | permissive | require 'bloombroom/hash/ffi_fnv'
require 'bloombroom/bits/bit_field'
require 'bloombroom/filter/bloom_helper'
module Bloombroom
# BloomFilter false positive probability rule of thumb: see http://www.igvita.com/2008/12/27/scalable-datasets-bloom-filters-in-ruby/
# a Bloom filter with a 1% error rate and an optima... | true |
de9fb42c9415566b7ee05893c28a0615d8ab2b71 | Ruby | SuperLazyDog/Learning-Ruby | /programming_test/paiza/S009/a.rb | UTF-8 | 1,598 | 3.609375 | 4 | [] | no_license | def get_row(line)
line.chomp.split(' ').map { |s| s.to_i }
end
def get_patterns(n, opts, cur) ## => [[pattern1], [pattern2], ...]
if n == 0
return [cur]
else
tmp = []
opts.length.times do |i|
item = opts[i]
new_opts = opts.dup
new_opts.delete_at i
tmp += get_patterns(n-1, new... | true |
af31d53da4723bd425e7b0a1a09c27d0c2fedc9f | Ruby | kevindsteeleii/ruby-objects-has-many-through-lab-dumbo-web-080618 | /lib/doctor.rb | UTF-8 | 554 | 3.40625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Doctor
attr_reader :name
attr_accessor :appointments
@@all = []
def initialize(name)
@name = name
@appointments = []
@@all << self
end
def new_appointment(patient, date)
appointment = Appointment.new(self, patient, date)
@appointments << appointment
appointment
end
def s... | true |
bedb77182d273ddca48dce60122f558894e6ae42 | Ruby | nunsez/ruby-rush | /rubytut2/lesson08/01/expenses_reader.rb | UTF-8 | 1,251 | 3.046875 | 3 | [
"Apache-2.0"
] | permissive | require 'rexml/document'
require 'date'
file_name = 'expenses.xml'
file_path = File.join(__dir__, file_name)
abort "Извиняемся, файлик #{file_name} не найден." unless File.exist?(file_path)
file = File.open(file_path)
doc = REXML::Document.new(file)
file.close
amount_by_day = Hash.new(0)
sum_by_month = Hash.new(0)
... | true |
61062858727ab23570add5b346a303a320a9f5d6 | Ruby | andjd/chess | /king.rb | UTF-8 | 198 | 2.8125 | 3 | [] | no_license | class King < Piece
include Stepping
DIRS = [[1, 1], [1, 0], [0, 1], [1, -1], [-1, 0], [0, -1], [-1, -1], [-1, 1]]
def to_s
'♚'
end
def valid_moves
steps(pos, DIRS)
end
end | true |
5ae6c24581abf711709b409fc02bf6f39fccd43b | Ruby | cnorm88/oo-tic-tac-toe-onl01-seng-pt-090820 | /lib/tic_tac_toe.rb | UTF-8 | 3,314 | 4.4375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class TicTacToe
def initialize
@board = [" ", " ", " ", " ", " ", " ", " ", " ", " "]
end
WIN_COMBINATIONS = [
[0,1,2], # Top row
[3,4,5], # Middle row
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2... | true |
e804bd73fd46519970fcbf36b766c8bd660ce564 | Ruby | dmchoull/kata | /ruby/rover/simulation.rb | UTF-8 | 443 | 3.59375 | 4 | [] | no_license | require_relative 'lib/rover'
require_relative 'lib/command_factory'
puts 'Enter rover\'s initial direction and position:'
direction, x, y = gets.split(',').map(&:strip)
rover = Rover.new(direction.upcase, x.to_i, y.to_i)
puts 'Enter command string:'
commands = gets.chomp
commands.chars.map { |char| CommandFactory.c... | true |
06551aea960ad7e0e614c15af56c591e57dda261 | Ruby | OregonDigital/oregondigital | /lib/oregon_digital/ocr/bookreader_search_generator.rb | UTF-8 | 2,238 | 2.78125 | 3 | [
"Apache-2.0"
] | permissive | module OregonDigital::OCR
class BookreaderSearchGenerator
def self.call(document,query)
new(document,query).result
end
attr_reader :document, :query
def initialize(document, query)
@document = document
@query = query.to_s.downcase
end
def result
return not_indexed if... | true |
daf8a3173a2f38944ca4f8c6711d07c873be96ce | Ruby | sharanchavadi/Courier-ticketing-system | /tickets.rb | UTF-8 | 1,035 | 3.359375 | 3 | [] | no_license | require './ticket'
class Tickets
def initialize()
@tickets = []
end
def create_ticket(parcel_code, weight, slot_number)
ticket = Ticket.new(parcel_code, weight, slot_number)
@tickets << ticket
end
def delete_ticket(slot_number)
ticket = @tickets.find{|ticket| tick... | true |
f055e35d0b4d4b331e67ee8c9e856e162fd60b31 | Ruby | yasuyamakyosuke/HTML.CSS | /ruby_minituku2.rb | UTF-8 | 397 | 2.859375 | 3 | [] | no_license | profiles = [
{:name => "静岡鶴太郎", :age => 34, :address => "静岡県"},
{:name => "名古屋次郎", :age => 25, :address => "愛知県"},
{:name => "大津三郎", :age => 19, :adddress => "滋賀県"},
]
def saerch(profiles, key ,query)
profiles.each do |profile|
if query =~ profile|key|
return profile
end
end
end
saerch(pr... | true |
57a9a634344aa7cbe87dcdc82fb0e64ceb92c784 | Ruby | Abiaina/oo-ride-share | /lib/driver.rb | UTF-8 | 2,073 | 3.453125 | 3 | [] | no_license | require 'csv'
require_relative 'trip'
require 'pry'
module RideShare
class Driver
attr_accessor :status
attr_reader :id, :name, :vehicle_id, :trips
def initialize(input)
if input[:id] == nil || input[:id] <= 0
raise ArgumentError.new("ID cannot be blank or less than zero. (got #{input[:id... | true |
312e7a4222837765c201772333b32c17b9526b1e | Ruby | jns/AimsProject | /skeleton/config/tasks.rb | UTF-8 | 4,955 | 2.578125 | 3 | [] | no_license | require 'stringio'
# ====================================================
# These are capistrano tasks to help with queueing calculations
# on a remote computing-cluster, tracking their status
# and retreiving calculation outputs.
# ====================================================
def _cset(name, *args, &block)
... | true |
43220b70d0293b63759646d83010727d4f059b54 | Ruby | juan-gm/RB101 | /lesson_6/twenty_one.rb | UTF-8 | 4,852 | 3.6875 | 4 | [] | no_license | SUITS = %w(Hearts Diamonds Clubs Spades)
VALUES = %w(Ace 2 3 4 5 6 7 8 9 10 Jack Queen King)
DECK = VALUES.product(SUITS)
VALID_YES_NO_INPUTS = %w(yes y no n)
DEALER_MAX = 17
MAX_TOTAL = 21
def prompt(msg)
puts "=> #{msg}"
end
def clear
system("clear")
end
def joinor(arr, separator = ', ', final = 'and')
retur... | true |
5888518483a333c9172fd76ed0738da5d978064a | Ruby | FlowerWrong/acts_as_markable | /lib/acts_as_markable.rb | UTF-8 | 2,416 | 2.796875 | 3 | [
"MIT"
] | permissive | require 'models/mark'
require 'acts_as_markable/markable'
require 'acts_as_markable/marker'
require 'acts_as_markable/exceptions'
##
# Author:: FuSheng Yang (mailto:sysuyangkang@gmail.com)
# Copyright:: Copyright (c) 2015 thecampus.cc
# License:: Distributes under the same terms as Ruby
# ActsAsMarkable
module ActsAsM... | true |
57ae65bc5b0cbeb5aaefd49e6f3689d6174aecca | Ruby | textchimp/wdi-25 | /week11/tweeteater/lib/tasks/twitter.rake | UTF-8 | 1,359 | 2.671875 | 3 | [] | no_license | namespace :twitter do
desc "Remove all Users and Tweets from the database"
task :clear => :environment do
User.destroy_all
Tweet.destroy_all
Rake::Task['twitter:stats'].invoke
end
desc "Get stats about current user and tweet count"
task :stats => :environment do
puts "Current users: #{ User.... | true |
8f065f8d14f14652a49c67591a2ca885bc2a42fd | Ruby | ullet/nhs-tool-codegen | /poc/myth_buster/builder/questions.rb | UTF-8 | 303 | 2.96875 | 3 | [] | no_license | module MythBuster
module Builder
class Questions < Array
def first?(question)
self.index(question) == 0
end
def last?(question)
self.number(question) == self.size
end
def number(question)
self.index(question) + 1
end
end
end
end
| true |
bb55e6ded6750efe0b7bd9a0afb075389e12143c | Ruby | seemajune/Flatiron-Prework | /deaf_grandma.rb | UTF-8 | 2,137 | 4.28125 | 4 | [] | no_license | #Write a Deaf Grandma program. Whatever you say to grandma
#(whatever you type in), she should respond with
#HUH?! SPEAK UP, SONNY!, unless you shout it (type in all capitals).
#If you shout, she can hear you (or at least she thinks so)
# and yells back, NO, NOT SINCE 1938! To make your program
#really believable,... | true |
2b0d7d9eaa9506017caeca5d382bffd3639d4e45 | Ruby | redjoker011/bakery-cli-app | /bin/cli.rb | UTF-8 | 1,665 | 3.140625 | 3 | [
"Apache-2.0"
] | permissive | require 'tty-prompt'
require_relative '../lib/seed.rb'
require_relative '../lib/cart_item'
require_relative '../lib/cart'
require_relative '../lib/order'
# Initialize TTY Lib
# @author Peter John Alvarado <redjoker011@gmail.com>
@prompt = TTY::Prompt.new
# Method for handling purchase flow
# @author Peter John Alvarad... | true |
29e6c188fedb9b5e59089f8db0a22ad4fcf3623e | Ruby | dalspok/exercises | /small_problems_i2/easy_1/2.rb | UTF-8 | 792 | 4.375 | 4 | [] | no_license | # P:
# -method
# input:
# -int: + - 0
# output:
# -return true if abs() odd
# E:
# puts is_odd?(2) # => false
# puts is_odd?(5) # => true
# puts is_odd?(-17) # => true
# puts is_odd?(-8) # => false
# puts is_odd?(0) # => false
# puts is_odd?(7) # => true
# D: -
# A:
# - .abs: obtain abs value
# - ... | true |
981840cfa26fed1f46affda2d02a12fa19edb098 | Ruby | l-jdavies/covid_summary_app | /database_connection.rb | UTF-8 | 5,430 | 2.953125 | 3 | [] | no_license | require 'pg'
class CovidDatabase
def initialize
@db = if Sinatra::Base.production?
PG.connect(ENV['DATABASE_URL'])
else
PG.connect(dbname: 'covid')
end
end
def setup_tables_data
create_state_table
copy_all_files_from_csv
validate_column_contents
... | true |
5143d4b266b11efa91080c37108f99a1ae20d4d7 | Ruby | AnastasiyaGavrilik/homeworks-2020 | /HW02/Dzmitry_Neverov/task3/time_calculator.rb | UTF-8 | 888 | 3.421875 | 3 | [] | no_license | require 'time'
class TimeIntervalCalculator
attr_reader :found_rows
def initialize(found_rows)
@found_rows = found_rows
end
TIME_FORMAT = %r{/\d{4}\-\d{1,2}\-\d{1,2}
\s\d{1,2}\:\d{1,2}\:\d{1,2}\.\d{1,2}/}x.freeze
def search_time
found_rows.each { |rows| rows.match(TIME_FORMAT) }
end
def chec... | true |
054f8d567354536b499d2b658c932b0b0965bb51 | Ruby | takahide/ramen | /app/models/concerns/scraper.rb | UTF-8 | 487 | 2.578125 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
require 'kconv'
class Scraper
def debug str
method_name = caller[0][/`([^']*)'/, 1]
logger = Logger.new "log/runner/#{method_name.split(" ").last}.log"
logger.debug str
end
def access url
sleep(rand(1) + 1)
method_name = caller[0][/`([^']*)'/, 1]
log... | true |
00533fa0d3962a9cd70d0540bf7b5b27fa5d4a5c | Ruby | lihanlilyy/pollen | /app/helpers/welcome_helper.rb | UTF-8 | 280 | 2.75 | 3 | [] | no_license | module WelcomeHelper
def greet
case Time.now.hour
when 0..4 then 'Good evening,'
when 5..11 then 'Good morning,'
when 12..17 then 'Good afternoon,'
when 18..24 then 'Good evening,'
else
'Hello,'
end
end
end | true |
7dc4e0b689312e18c02b6e36d643ffdbbf6ef1d6 | Ruby | kiptubei/Enumerables | /my_enumerables.rb | UTF-8 | 3,286 | 3.25 | 3 | [] | no_license | # rubocop:disable Metrics/ModuleLength
# rubocop:disable Metrics/MethodLength
module Enumerable
def my_each
return to_enum(:my_each) unless block_given?
size.times { |item| yield(self[item]) }
self
end
def my_each_with_index
return to_enum(:my_each_with_index) unless block_given?
arr = to_a... | true |
6709754156440f7c6036f9156f03426f2f814fe6 | Ruby | Udayan81/lesson02 | /lab.rb | UTF-8 | 1,135 | 4.09375 | 4 | [] | no_license | # declare a hash representing the four suites of a deck of cards
# with an abbreviation for the keys and a full name for the values
suites = { :sp => "spades", :cl => "clubs", :di => "diamonds", he: "hearts"}
# display the rank and suit for each card, as "9 of Hearts", etc.
# don't worry about "jack" or "king... | true |
5963a87f516c6c0093cd78af6404616451d67610 | Ruby | Caitlin-cooling/bank_test | /lib/formatting.rb | UTF-8 | 180 | 2.796875 | 3 | [] | no_license | # Module to handle formatting of numbers and time
module Formatting
def decimals(amount)
format('%.2f', amount)
end
def time
Time.now.strftime('%d/%m/%Y')
end
end
| true |
df4a3d50d4ab9bbc01d82f9392c9d8adcfddaa74 | Ruby | dsawardekar/encase | /lib/encase/container.rb | UTF-8 | 2,045 | 2.78125 | 3 | [
"MIT"
] | permissive | require 'encase/container_item_factory'
module Encase
class Container
attr_accessor :parent
def initialize(parent = nil)
@parent = parent
@items = {}
end
def contains?(key)
@items.key?(key)
end
def inject(object)
klass = object.class
if klass.respond_to?(:need... | true |
04acef382d6d3ecf402dd2f544d76dae33f52df1 | Ruby | BitcoinBB/appacademy | /w2/w2d4/exercises/two_sum.rb | UTF-8 | 1,359 | 3.96875 | 4 | [] | no_license | def brute_two_sum?(arr, target_sum)
pairs = []
arr.each_with_index do |el, i|
((i + 1)...arr.length).each do |j|
pairs << [el, arr[j]]
end
end
pairs.any? { |pair| pair[0] + pair[1] == target_sum }
end
# arr = [0, 1, 5, 7]
# p brute_two_sum?(arr, 6) # => should be true
# p brute_two_sum?(arr, 10)... | true |
12fd3e46e121be06e098d0a8621ddbcd58a594bc | Ruby | mistercwood/ruby-basic-projects | /substrings.rb | UTF-8 | 1,403 | 4.75 | 5 | [] | no_license |
# Implement a method #substrings that takes a word as the first argument
# and then an array of valid substrings (your dictionary) as the second argument.
# It should return a hash listing each substring (case insensitive) that was
# found in the original string and how many times it was found.
# Example:
# > dic... | true |
d124d85972d156655b06041fec5bcf1f3424a9ec | Ruby | Elucidation/Project-Euler-As-one | /ProjectEuler_22.rb | UTF-8 | 854 | 3.703125 | 4 | [] | no_license | #~ Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing
#~ over five-thousand first names, begin by sorting it into alphabetical order. Then working
#~ out the alphabetical value for each name, multiply this value by its alphabetical position in the list to obtain a name score.
#~ Fo... | true |
9fc111b9ad951293d326a4a8d535fc68c8d49d7b | Ruby | ThomsonTang/Ruby-Practice | /pro-ruby/samples/intro_14.rb | UTF-8 | 303 | 2.859375 | 3 | [] | no_license | a = ['ant', 'cat', 'dog'];
a[0] # => "ant"
a[2] # => "dog"
#this is the same:
a = %w{ ant cat dog}
a[0] # => "ant"
a[2] # => "dog"
inst_section = {
'cello' => 'string',
'drum' => 'percussion',
'oboe' => 'woodwind'
}
p inst_section['cello']
p inst_section['drum']
p inst_section['basson']
| true |
98bed26cae78b876d3a1e97780b8e7ca09005b1d | Ruby | YouAG/JYR | /trader_du_DIMANCHE.rb | UTF-8 | 569 | 3.28125 | 3 | [] | no_license |
def stockPicker(prix)
meilleur_achat = 0
meilleur_vente = 0
meilleur_profit = 0
prix.each do |acheter|
prix.each do |vendre|
profit = vendre - acheter
if profit > meilleur_profit
meilleur_profit = profit
meilleur_achat = prix.index(acheter)
meilleur_vente =... | true |
b6da076563bec579b9d058ec5390683a0cdc5d7f | Ruby | snebel/project_euler | /97.rb | UTF-8 | 695 | 3.96875 | 4 | [] | no_license | # The first known prime found to exceed one million digits was discovered in 1999,
# and is a Mersenne prime of the form 26972593−1; it contains exactly 2,098,960
# digits. Subsequently other Mersenne primes, of the form 2p−1, have been found
# which contain more digits.
#
# However, in 2004 there was found a massive ... | true |
63074f6ad989482640174a905715e215ba03e7de | Ruby | mamluka/leadfinder | /tools/testing/convert-to-csv.rb | UTF-8 | 233 | 2.515625 | 3 | [] | no_license | require 'csv'
tab_file = ARGV[0]
csv_file = ARGV[1]
converted_csv = Array.new
CSV.foreach(tab_file, {:col_sep => "\t"}) { |csv|
converted_csv << csv
}
CSV.open(csv_file, 'wb') do |csv|
converted_csv.each { |x| csv << x }
end
| true |
7506ca9ba474f1aa22af03378baafac3ba6455e5 | Ruby | offscript/Exercises | /Stacks_and_Queues/tc_qu.rb | UTF-8 | 1,023 | 2.90625 | 3 | [] | no_license | require_relative "qu.rb"
require "test/unit"
class TestQu < Test::Unit::TestCase
def setup
@test_qu = Qu.new()
end
def test_enqueue
@test_qu.enqueue("string")
@test_qu.enqueue(4)
@test_qu.enqueue([234])
assert_equal(["string", 4, [234]], @test_qu.array)
@test_qu.array = []
end
def test_dequeue
@t... | true |
1520e746f1fe76356dbde5dcaa1bf37ddf6cb0e5 | Ruby | jmschles/codeeval | /moderate/number_pairs.rb | UTF-8 | 595 | 3.171875 | 3 | [] | no_license | File.open(ARGV[0]).each_line do |line|
# parse input
sequence, target = line.chomp.split(';')
sequence = sequence.split(',').map(&:to_i)
target = target.to_i
pairs = []
# find pairs
sequence.each_with_index do |n1, i|
sequence.each_with_index do |n2, j|
next if j <= i
if n1 + n2 == tar... | true |
b9a30e7909d93a6aacb5158f9607e7c2a6fffb40 | Ruby | jakesorce/canvas_portal | /lib/helpers/writer.rb | UTF-8 | 180 | 2.671875 | 3 | [] | no_license | module Writer
def write_file(file_path, contents, write_flag = 'w+')
File.open(file_path, write_flag) { |file| file.write(contents) }
end
module_function :write_file
end
| true |
5c829e818eef6e76f6b1544f514bb4e0a37a1d4a | Ruby | MargaretLangley/letting | /lib/tasks/import/import_cycle.rake | UTF-8 | 806 | 2.546875 | 3 | [] | no_license | require 'csv'
####
# Import Cycle
#
# Key value table: id, Cycle Name
#
# 1 Mar/Sep
# 2 Jun/Dec
# 3 Mar/Jun/Sep/Dec
# 4 Apr/July/Oct/Jan
# see definitive values in table cycles / file cycle.csv
#
####
namespace :db do
namespace :import do
filename = 'import_data/new/cycle.csv'
desc 'Import cycles from CSV f... | true |
83a7ec20d1e58e67aff8f0dd2374e53fed94c2e7 | Ruby | LalaDK/final-assignment | /test/models/tweet_test.rb | UTF-8 | 2,256 | 2.53125 | 3 | [] | no_license | require 'test_helper'
class TweetTest < ActiveSupport::TestCase
test "at 'Tweet.user_count' returnerer 659775" do
actual = Tweet.user_count
expected = 659775
assert_equal actual, expected
end
test "at 'Tweet.users_mentioning_most_users' returnerer korrekt" do
data = Tweet.users_mentioning_most_... | true |
e010fabeb82f3318bd0208cee6d05a7d642c20fe | Ruby | tadd/string_unescape | /test/test_string_unescape.rb | UTF-8 | 1,307 | 2.96875 | 3 | [
"BSD-2-Clause",
"Ruby"
] | permissive | require 'test-unit'
require_relative '../lib/string_unescape'
class TestUnescape < Test::Unit::TestCase
def test_unescape
assert_equal('foo', 'foo'.unescape)
assert_equal('foo#$bar#@baz#{quxx}', 'foo\#$bar\#@baz\#{quxx}'.unescape)
assert_equal('\\', '\\\\'.unescape)
assert_equal(%(\\"), '\\\\\"'.une... | true |
7091ef20214948d32ffb875830f47bdd3835b74d | Ruby | zmoazeni/numberwang.rb | /numberwang_service_spec.rb | UTF-8 | 4,073 | 2.765625 | 3 | [] | no_license | require_relative 'numberwang_service'
require 'byebug'
RSpec.describe NumberwangService do
context 'single assertions' do
before do
@numberwang = NumberwangService.new
@wangernumb = NumberwangService.new(wangernumb_round: true)
end
context 'numberwangs' do
it '50 is a safe first number... | true |
0721c8376e47d0172b558628aae4f0723885c6c5 | Ruby | tgraham777/test | /random_exercises/credit_check_1.rb | UTF-8 | 1,671 | 3.703125 | 4 | [] | no_license | card_number = "4929735477250543" # this number is the input
puts "Card Number - #{card_number}"
card_number.split("")
# Array1 = []?
# Put all numbers in array before summing?
# Put number calcs in loop that adds them together
number1a = card_number[-1].to_i
puts number1a
number1 = card_number[-2].to_i * 2
if num... | true |
437f86a7d2871662a094896c1040f343ff80eea4 | Ruby | makonishi/dragon_quest_program | /main.rb | UTF-8 | 1,565 | 4.0625 | 4 | [] | no_license | class Brave
attr_reader :name, :offense, :defense
attr_accessor :hp
# paramsで一括で受け取る
# 引数に**を記述:ハッシュしか受け取れなくなる
def initialize(**params)
# 各パラメータをハッシュで取得
@name = params[:name]
@hp = params[:hp]
@offense = params[:offense]
@defense = params[:defense]
end
# 勇者の通常攻撃
def attack(monster)... | true |
bbe1ed7583f78dc45647846419794c0f0eb35ba2 | Ruby | halorgium/reel | /lib/reel/request.rb | UTF-8 | 493 | 2.640625 | 3 | [
"MIT"
] | permissive | module Reel
class Request
attr_accessor :method, :version, :url
METHODS = [:get, :post, :put, :delete, :trace, :options, :connect, :patch]
def initialize(method, url, version = "1.1", headers = {})
@method = method.to_s.downcase.to_sym
raise UnsupportedArgumentError, "unknown method: #{me... | true |
0a6bbd5ec7822e5231eac42d21b0501b82dc4050 | Ruby | menor/dbc_flashcards_and_todos | /part3_ruby-todos-1-core-features-challenge/solutions/sample_04/todo.rb | UTF-8 | 3,349 | 3.609375 | 4 | [] | no_license | # What classes do you need?
# Remember, there are four high-level responsibilities, each of which have multiple sub-responsibilities:
# 1. Gathering user input and taking the appropriate action (controller)
# 2. Displaying information to the user (view)
# 3. Reading and writing from the todo.txt file (model)
# 4. Mani... | true |
3f7234fc99d0efb4dc0b59d94e33560b5d95a093 | Ruby | CUchack/Ruby-Assignment | /3 Word Count.rb | UTF-8 | 396 | 3.0625 | 3 | [] | no_license |
def count_words(string)
items = Hash.new(0)
string.downcase.gsub(/\W/,' ').split.each do |i|
items[i] +=1
end
puts items
end
count_words("A man, a plan, a canal -- Panama")
count_words "Doo bee doo bee doo"
# I found this example code on the Ruby forums at
# https://www.ruby-forum.com/topic/84374
puts g... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.