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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
c7dbdf75b4051e57aa2873755f7975dbebe216ae | Ruby | vmlellis/hackerrank | /Algorithms/Warmup/Plus Minus/Ruby/solution.rb | UTF-8 | 258 | 3.1875 | 3 | [] | no_license | #!/bin/ruby
n = gets.strip.to_i
arr = gets.strip
arr = arr.split(' ').map(&:to_i)
size = arr.size
v = arr.each_with_object([0, 0, 0]) do |x, res|
x > 0 ? res[0] += 1 : x < 0 ? res[1] += 1 : res[2] += 1
end
puts v.map { |x| format('%.6f', x.to_f / size) }
| true |
847f02336840368512e46b72198458b1e9b49049 | Ruby | ngLawrence2/algorithms | /algorithm_2_sets/lib/p04_linked_list.rb | UTF-8 | 1,701 | 3.5 | 4 | [] | no_license |
class Node
attr_accessor :key, :val, :next, :prev
def initialize(key = nil, val = nil)
@key = key
@val = val
@next = nil
@prev = nil
end
def to_s
"#{@key}: #{@val}"
end
def remove
# optional but useful, connects previous node to next node
# and removes self from list.
end
... | true |
5f6cbe8aa50eca9b3fdb1f2b937486aa7707d8fd | Ruby | jjnewman/rps-challenge | /lib/game.rb | UTF-8 | 746 | 3.484375 | 3 | [] | no_license | class Game
attr_reader :player_one, :player_two
def add_player(player)
@player_one ? @player_two = player : @player_one = player
players << player
end
def players
@players ||= []
end
def winner(player1, player2)
if (player1.choice == :rock && player2.choice == :scissors)
player1.name
elsif (player2.ch... | true |
29a01177bde72c35ae5d0976b1486f86cee0d5af | Ruby | lamhaianh/openkh | /app/helpers_hooks/acts_as_tree_helper.rb | UTF-8 | 991 | 2.5625 | 3 | [
"MIT"
] | permissive | module ApplicationHelper
# Renders a node and its children. The caller must provide a block which
# actually renders each node.
def html_tree(node, level = 0, wrapper = :li, children_wrapper = :ul, &block)
ret, wrapper_options = block.call(node, level)
unless node.children.empty?
s = ''.html_safe
... | true |
8bc5605fd02db58482ed47a120d99337159aa36d | Ruby | JDumadag25/ruby-intro-to-arrays-lab-prework | /lib/intro_to_arrays.rb | UTF-8 | 518 | 3.609375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def instantiate_new_array
instantiate_new_array = @my_new_array
return @my_new_array = []
end
def array_with_two_elements
array = ["element1", "element2"]
return array
end
def first_element(array)
return array[0]
end
def third_element(array)
return array[2]
end
def last_element(array)
return array[-1]... | true |
c5692fe282eefb6dbf500e147fc9456019a583c0 | Ruby | GWitczak/RB101_programming_fundations | /RB101-RB109_exercises/easy_3/counting_characters.rb | UTF-8 | 184 | 3.875 | 4 | [] | no_license | puts "Please write word or multiple words: "
string = gets.chomp
string_array = string.chars
string_array.delete(" ")
puts "There are #{string_array.count} characters in '#{string}'."
| true |
8550636f88bc7289f2cb60efc233e9c08e5c7d94 | Ruby | suy/nanoc | /test/base/test_item_array.rb | UTF-8 | 1,841 | 2.734375 | 3 | [
"MIT"
] | permissive | class Nanoc::Int::IdentifiableCollectionTest < Nanoc::TestCase
def setup
super
@one = Nanoc::Int::Item.new('Item One', {}, '/one/')
@two = Nanoc::Int::Item.new('Item Two', {}, '/two/')
@items = Nanoc::Int::IdentifiableCollection.new({})
@items << @one
@items << @two
end
def test_change_... | true |
18a92323cfa3f59bb693eac84f7f34eefccb0550 | Ruby | MichelleNguy/ruby-enumerables-introduction-to-map-and-reduce-lab-dumbo-web-080519 | /lib/my_code.rb | UTF-8 | 1,061 | 3.546875 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # My Code here....
def map_to_negativize(source_array)
return_array = []
source_array.each do |num|
return_array << num * -1
end
return_array
end
def map_to_no_change(source_array)
return_array = []
source_array.each do |num|
return_array << num
end
return_array
end
de... | true |
7f749e845391796903be63561148e0b651ba123c | Ruby | j-chen/surveyor | /script/surveyor/survey_parser.rb | UTF-8 | 2,098 | 2.859375 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + '/survey'
class SurveyParser
# Children, Counters, Files
attr_accessor :surveys
attr_accessor :last_survey_id, :last_survey_section_id, :last_question_id, :last_answer_id
attr_accessor :surveys_yml, :survey_sections_yml, :question_groups_yml, :questions_yml, :answers_yml, :depe... | true |
93ab7eb5f0f7e5f170dffcd4251a8cabfcef95d5 | Ruby | ATL-WDI-Exercises/ruby-problems | /isPalindrome.rb | UTF-8 | 246 | 4.1875 | 4 | [
"MIT"
] | permissive | # Palindrome
# Write a function to check if a given string is a palindrome
def isPalindrome(string)
string == string.reverse
end
puts "is harry palindrome? #{isPalindrome('harry')}"
puts "is harryrrah palindrome? #{isPalindrome('harryrrah')}" | true |
2a41330009672623e635bee0661f03bede3bc56a | Ruby | AKROGIS/NP_Places_Sync | /osm_sync/setup_dev.rb | UTF-8 | 2,133 | 3 | 3 | [] | no_license | #!/usr/bin/ruby
# Get all the auth details you need
# You wouldn't actually do it this way, but hey.
# Normally you'd distribute the consumer stuff with your
# application, and each user gets the access_token stuff
# But hey, this is just a demo.
require 'rubygems'
require 'oauth'
require 'yaml'
# Format of auth.... | true |
1312e57ed799efa43e59c91a03c2d8316ab3cf36 | Ruby | sittercity/bureaucrat | /test/fields/multiple_choice_field_test.rb | UTF-8 | 1,994 | 2.671875 | 3 | [
"MIT"
] | permissive | require_relative '../test_helper'
require 'bureaucrat/fields/multiple_choice_field'
module MultipleChoiceFieldTests
class Test_on_clean < BureaucratTestCase
def setup
@choices = [['tea', 'Tea'], ['milk', 'Milk'], ['coffee', 'Coffee']]
@field = Bureaucrat::Fields::MultipleChoiceField.new(@choices)
... | true |
5c94439c9921bd4abfd272e18de05790c6ef99ef | Ruby | AaronCHH/B_RUBY | /鍛鍊你的數學腦/SF_RUBY/ch02/q21_01.rb | UTF-8 | 526 | 3.875 | 4 | [] | no_license | count = 0 # 「0」出現的次數
line = 1 # 目前的行數
row = [1] # 目前的行的值
while count < 2014 do
next_row = [1]
# 根據上一行的數字以及排他性邏輯和設定下一行的數字
(row.size - 1).times{|i|
cell = row[i] ^ row[i + 1]
next_row.push(cell)
count += 1 if cell == 0 # 若為「0」就納入計次
}
next_row.push(1)
line += 1 # 增加行... | true |
7437786aedbd28f47cf1c9943d603f6e1a60b478 | Ruby | tkdonut/snowman_homework | /specs/hiddenword_spec.rb | UTF-8 | 1,594 | 3.21875 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('../hiddenword')
class HiddenWordTest < MiniTest::Test
def test_obfuscates_word__word
@hiddenword = HiddenWord.new('banana')
assert_equal("******",@hiddenword.obfuscate)
end
def test_obfuscates_word__phrase
@hiddenword = HiddenWord... | true |
ed660689a33835de2cefc7b0ffc39a10d948dbbb | Ruby | Bdestasio33/FindMissingNumber | /findmissingnumber.rb | UTF-8 | 589 | 4.15625 | 4 | [] | no_license | keeplooping = true
puts "what is your string? input as 1,2,3, etc."
number_str = gets.chomp
number_arr = number_str.split(',')
number_arr.sort
maxvalue = number_arr.max
(maxvalue.to_i)
x=0
j=1
putsanswer = false
while (keeplooping)
if ((number_arr[j].to_i) != ((number_arr[x].to_i) + 1))
answer... | true |
05310ad86ea06219e9a744ad258753c1689512c2 | Ruby | aljazskrinjar/scraping | /scrapingWIPO.rb | UTF-8 | 1,773 | 2.65625 | 3 | [] | no_license | require 'rubygems'
require 'nokogiri'
require 'watir'
require 'json'
require 'open-uri'
def busy (browser)
if browser.text.include? "Sorry, the page is busy processing"
puts "Sorry the scraping page is having some problems. Please try later."
end
end
def check_if_zero_results (browser)
if browser.text.inclu... | true |
9af159a0bc86952639a6969920df6dc72198d8b5 | Ruby | zwarburg/ruby | /exercises/book-store/book_store_test.rb | UTF-8 | 2,030 | 2.90625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'minitest/autorun'
require_relative 'book_store'
# Common test data version: 1.1.0 a636903
class BookStoreTest < Minitest::Test
def test_only_a_single_book
# skip
assert_equal 8.0, BookStore.calculate_price([1])
end
def test_two_of_the_same_book
skip
assert_equal 16.0, BookStore.calculat... | true |
46888cad2ae63b38d7b683915694c74843f129e3 | Ruby | marcelgalang/oo-student-scraper-v-000 | /lib/scraper.rb | UTF-8 | 1,314 | 2.953125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'open-uri'
require 'pry'
require 'nokogiri'
class Scraper
def self.scrape_index_page(index_url)
doc = Nokogiri::HTML(open(index_url))
student_arr = []
all_students = doc.css("div.roster-cards-container")
students = all_students.css("div.student-card")
students.each do |student|
pr... | true |
5f602adb52073fd8c4249b59a78a9458c05a1cf7 | Ruby | consti/urbantakeover | /app/helpers/application_helper.rb | UTF-8 | 2,000 | 2.640625 | 3 | [] | no_license | # Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
def format_text text
h(text) # textile decided to go ape-shit. disable text formatting for now.
#RedCloth.new(text, [:filter_html]).to_html
end
def sparkline data
data = data.map {|d| d*12}
... | true |
23b6c061129a71a323f4cb1db596cc895223ae4a | Ruby | ariel-alvear/desafios-arrays-primerasesion | /visitas.rb | UTF-8 | 146 | 3.171875 | 3 | [] | no_license | def average(array)
results = (array.sum / array.size).to_f
results
end
visitas = [1000, 800, 250, 300, 500, 2500]
puts average(visitas) | true |
66fae49f958d7407082515f43a296bc3c9c1573f | Ruby | castillocera/Programacion-Ruby | /Ruby-MitoCode/tut23_POO/principal.rb | UTF-8 | 257 | 3.4375 | 3 | [] | no_license | require_relative "celular.rb" #llamamos al archivo que vamos a requerir
#creamos nuevo OBJETO
c1 = Celular.new("Samsung", "Negro")
c1.llamar()
#creamos otro OBJETO, estos dos unvocan el mismo metodo
c2 = Celular.new("Iphone" , "Blanco")
c2.llamar()
gets()
| true |
d1899bcfe16c40b2feda67c301747454f9da42e2 | Ruby | kkk2kkk/fairplay | /lib/digraph_encrypter.rb | UTF-8 | 1,809 | 3.5 | 4 | [] | no_license | require 'key_builder'
# This class encrypts digraphs.
class DigraphEncrypter
attr_accessor :table
# Initializes the object.
# @param fair_play [String] expects a fairplay compliant key
def initialize(fairplay_key)
@table = {}
@key = fairplay_key
split_fairplay_key( fairplay_key )
build_table
... | true |
051af5a37e8906ad2394a86687161eb995c90210 | Ruby | yivo/ccy-rates | /index.rb | UTF-8 | 4,741 | 2.796875 | 3 | [
"Apache-2.0"
] | permissive | # encoding: UTF-8
# frozen_string_literal: true
require "json"
require "date"
require "active_support/core_ext/string/filters"
require "active_support/core_ext/array/grouping"
require "nokogiri"
require "colorize"
require "faraday"
def useful_currencies
["USD", "EUR", "CAD", "RUB", "BTC"]
end
def normalize_currenc... | true |
c0eae24fde861be88a2f7acb502d97391ef0843c | Ruby | rubysolo/dentaku | /lib/dentaku/flat_hash.rb | UTF-8 | 1,110 | 2.9375 | 3 | [
"MIT"
] | permissive | module Dentaku
class FlatHash
def self.from_hash(h, key = [], acc = {})
return acc.update(key => h) unless h.is_a? Hash
h.each { |k, v| from_hash(v, key + [k], acc) }
flatten_keys(acc)
end
def self.from_hash_with_intermediates(h, key = [], acc = {})
acc.update(key => h) unless ke... | true |
1b6f2063d91649259f9688398f0dc8f4764aeec7 | Ruby | Haadsan/WeekTwo_DayOne_LabHomework | /Sports_team/sports_team.rb | UTF-8 | 860 | 3.296875 | 3 | [] | no_license | class SportsTeam
attr_accessor :team_name, :players,:coach, :points
def initialize(team_name, players, coach)
@team_name = team_name
@players = players
@coach = coach
@points = 0
end
# def team_name
# return @team_name
# end
#
# def players
# return @players
# end
#
# d... | true |
97f064411beede67d706b0f2bc40bf14a550f2b4 | Ruby | eldoy/paypal_statement_cleaner | /converter.rb | UTF-8 | 476 | 3.265625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'net/http'
require 'json'
def get_amount(amount, date, to = 'HKD', from = 'USD')
date = date.to_s.split('/').map(&:to_f)
date = Time.new(date[2], date[0], date[1])
date = date.strftime("%Y-%m-%d")
uri = URI("https://api.exchangeratesapi.io/#{date}?symbols=#{to}&base=#{from}")
res... | true |
bd6df9fadb2fc9d9e4c076cee7283ea5267f8a86 | Ruby | quintel/refinery | /spec/refinery/slot_collection_spec.rb | UTF-8 | 2,224 | 2.859375 | 3 | [] | no_license | require 'spec_helper'
module Refinery
describe SlotCollection do
let(:node) { Node.new(:node) }
let(:coll) { SlotCollection.new(node, :out) }
it 'is enumerable' do
gas = coll.add(:gas)
elec = coll.add(:electricity)
expect { |b| coll.each(&b) }.to yield_successive_args(gas, elec)
... | true |
1af338cbbd8a213ac2d3e38acfcf7dc1f63d27e7 | Ruby | lynrco/lynr.co | /lib/lynr/controller/component/paginated.rb | UTF-8 | 2,258 | 2.984375 | 3 | [] | no_license | require './lib/lynr/controller'
module Lynr::Controller
# # `Lynr::Controller::Paginated`
#
# Define methods to compute an array of page numbers to display.
#
module Paginated
# ## `Paginated::PER_PAGE`
#
# Number of items displayed per page.
#
PER_PAGE = 10
# ## `Paginated::SPREAD`... | true |
c74178c0d132a0222590d4980c8133a797dbfda7 | Ruby | DasATeam/Agreement-Integration-Platform | /app/models/user.rb | UTF-8 | 509 | 2.53125 | 3 | [] | no_license | class User < ActiveRecord::Base
has_one(:merchant)
has_one(:sales)
validates(:email, uniqueness: true, format: /\A[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$\z/i)
def set_password(input)
self.salt = BCrypt::Engine.generate_salt
self.pass = BCrypt::Engine.hash_secret(input, salt)
self.save
end
def ... | true |
efe572023f3b950ec5495e63f9b9c997274e7b78 | Ruby | svrrealism/ruby_algorithms | /online_priority_queue.rb | UTF-8 | 1,632 | 4.46875 | 4 | [] | no_license | #implement a priority queue
class PriorityQueue
attr_reader :elements
def initialize()
@elements = [nil]
end
def <<(element)
@elements << element
bubble_up(@elements.size - 1)
end
def pop
#exchange the root with the last element
exchange(1, @elements.size - 1)
#remove the last el... | true |
876b3a116ed3265c810920a4e85d39aa6ac4cf4a | Ruby | Alsmi/homework_4 | /triangle.rb | UTF-8 | 2,737 | 3.78125 | 4 | [] | no_license | require './figure.rb'
class Triangle < Figure
attr_accessor :x2, :y2, :x3, :y3
def initialize(name, x, y)
super
@x2 = -6
@y2 = 1
@x3 = 6
@y3 = -2
end
def perimeter
p = (Math.sqrt((x2-point.x)**2+(y2-point.y)**2)+
Math.sqrt((x3-point.x)**2+(y3-point.y)**2)+
Math.sqrt((x3-x2)**2+(y3-y2)**2))
pu... | true |
cfc304f8e2d5902764c37db7721489d5a5723c40 | Ruby | tdeo/advent_of_code | /2022/lib/12_hill_climbing_algorithm.rb | UTF-8 | 2,257 | 3.21875 | 3 | [] | no_license | # typed: strong
# frozen_string_literal: true
require 'sorbet-runtime'
class HillClimbingAlgorithm
extend T::Sig
sig { params(input: String).void }
def initialize(input)
@input = input
@start = T.let([-1, -1], [Integer, Integer])
@finish = T.let([-1, -1], [Integer, Integer])
@grid = T.let([], T... | true |
c706e3cfb5f9b79bde151a16d11e465b2c75b48d | Ruby | cha63506/Library-401 | /spec/books_spec.rb | UTF-8 | 4,089 | 3.0625 | 3 | [] | no_license | require('spec_helper')
describe(Books) do
# describe('.all') do
# it('is empty at first') do
# expect(Books.all()).to(eq([]))
# end
# end
describe('#==') do
it('is considered identical if two books are the same') do
book1 = Books.new({:name => "A Tale of Two Cities", :author => "Charles... | true |
ebbe0b71f2da673fda08d8389f244e71f6bac7aa | Ruby | ebon/my-emacs-config | /elisp/ruby/bin/rbtest | UTF-8 | 6,942 | 2.859375 | 3 | [] | no_license | #! /Users/nobeira/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
# Copyright (c) 2006-2007 rubikitch <rubikitch@ruby-lang.org>
#
# Use and distribution subject to the terms of the Ruby license.
USAGE = <<'XXX'
Usage: rbtest SCRIPT [-S RUBY_INTERPRETER] [Test::Unit OPTIONS]
Usage: rbtest [-h] [--help] [--example]
I am rbtest, e... | true |
5e841015e95553b3fcefdc67f7572622daea5e5e | Ruby | rapid7/ruby_smb | /examples/authenticate.rb | UTF-8 | 1,693 | 2.53125 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference",
"Ruby"
] | permissive | #!/usr/bin/ruby
# This script tests a full Authentication/Session Setup cycle
# including protocol negotiation and authentication.
require 'bundler/setup'
require 'ruby_smb'
def run_authentication(address, smb1, smb2, smb3, username, password)
# Create our socket and add it to the dispatcher
sock = TCPSocket.new... | true |
3a6e0c5a98923c4f2076efd666104a2f2c694138 | Ruby | niceking/500 | /game_env.rb | UTF-8 | 1,050 | 3.453125 | 3 | [] | no_license | require File.expand_path '../player', __FILE__
require File.expand_path '../bid', __FILE__
require File.expand_path '../bidding_manager', __FILE__
# ---------------------------------
# SETUP
puts 'Hi welcome to 500'
deck = Deck.new
deck.deal
rose = Player.new(dealt_hand: deck.north, name: 'North', position: :north)... | true |
0e151f11c5d021b3d5fb3829febb5f6e1fef40d8 | Ruby | Alequin/student_team_library_homework | /team/team.rb | UTF-8 | 1,231 | 4.375 | 4 | [] | no_license | # Now we would like you to make a class that represents a sports
# team.
#
# Make a class to represent a Team that has the properties Team
# name (String), Players (Array of strings) and a Coach (String).
#
# For each property in the class make a Getter method than can
# return them.
#
# Create a setter method to allow... | true |
03322311db6f35cde8dc14f3f98c6bbbd607e0a0 | Ruby | svenfuchs/travis-activity | /lib/crowd/record.rb | UTF-8 | 1,270 | 2.671875 | 3 | [] | no_license | require 'faraday'
require 'json'
require 'date'
class Crowd
class Record
attr_reader :package, :interval
def initialize(package, interval)
@package = package
@interval = interval
end
def data
json = JSON.parse(fetch)
data = json['facets']['stats']['entries']
data.injec... | true |
5eb09f69c50f6b7e939ae1b0027238408426b834 | Ruby | larfoley/nci-supermarket | /test/models/product_test.rb | UTF-8 | 1,242 | 2.75 | 3 | [] | no_license | require 'test_helper'
class ProductTest < ActiveSupport::TestCase
test 'valid product' do
product = Product.new(name: 'bread', stock: 1, price: 1.50)
assert product.valid?
end
test 'product is invalid without name' do
product = Product.new(stock: 1, price: 1.50)
assert_not product.valid?
end
... | true |
cafff67300595dca7830b1dfdf03ca9b3669ead6 | Ruby | johnjmarks4/n_queens | /backtracker/n_queens.rb | UTF-8 | 1,770 | 3.90625 | 4 | [] | no_license | require_relative 'board'
require_relative 'queen'
require 'benchmark'
def solution(n)
queens = []
solutions = []
possible = solution_size(n)
return error_message if !possible.is_a?(Integer)
while solutions.length < possible
queens = []
while queens.length < n
queens = []
queens = search(n... | true |
95aed2c7bb51a681e429a79ef114e247f2016636 | Ruby | uk-gov-mirror/communitiesuk.epb-register-api | /lib/gateway/postcodes_gateway.rb | UTF-8 | 1,116 | 2.71875 | 3 | [
"MIT"
] | permissive | module Gateway
class PostcodesGateway
def fetch(postcode)
response = db_response(postcode: postcode)
result = []
output(response, result)
if result.empty?
outcode_array = postcode.split(" ")
outcode = outcode_array[0]
response =
db_response(
... | true |
39d38203e0015792c3932bcb183a5826f9324695 | Ruby | matt-thomson/advent-of-code | /2017/spec/advent_of_code2017/day02_spec.rb | UTF-8 | 569 | 2.75 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'advent_of_code2017/day02'
RSpec.describe AdventOfCode2017::Day02 do
describe '.solve_part_one' do
subject { described_class.solve_part_one(input) }
let(:input) do
<<~INPUT
5 1 9 5
7 5 3
2 4 6 8
INPUT
end
it { is_expected.to... | true |
cce04ff49df6e2d29dd320c2cb9413f372dbe127 | Ruby | dinvlad/single_cell_portal_core | /app/models/report_time_point.rb | UTF-8 | 900 | 2.53125 | 3 | [] | permissive | class ReportTimePoint
###
#
# ReportTimePoint: generic container for storing time-based reporting data (for ReportsController graphs)
#
###
include Mongoid::Document
include Mongoid::Timestamps
field :name, type: String
field :date, type: Date
field :value, type: Hash
validates_presence_of :na... | true |
a3bd8f3634800b6e61e9718d7faf73ab20022998 | Ruby | Caleb1991/backend_mod_1_prework | /section1/exercises/ex4.rb | UTF-8 | 981 | 4 | 4 | [] | no_license | # Gives variable "cars" a number that can be drawn from.
cars = 100
# Givies variable "sapce in a car" a number.
space_in_a_car = 4
# Gives variable "drivers" a number.
drivers = 30
# Gives variable "passengers" a number.
passengers = 90
# Gives a computation to determine how many cars are not driven.
cars_not_driven =... | true |
412f064520329f17c6a68412303394c2bf976453 | Ruby | vertism/advent_of_code | /2019/Day4/part2.rb | UTF-8 | 426 | 3.0625 | 3 | [] | no_license | #!/usr/bin/env ruby
min = 168630
max = 718098
passwords = min.upto(max).select do |password|
array = password.to_s.chars
next if array.sort.join() != password.to_s
pairs = array.each_cons(2).select{ |pair| pair.uniq.count == 1 }.flatten.uniq
next if pairs.empty?
triplets = array.each_cons(3).select{ |trip| ... | true |
af0c3d36822db1d38d9444f698a1591f7c400620 | Ruby | kraft001/railsbox | /spec/support/test_helpers/zip_contents.rb | UTF-8 | 944 | 2.640625 | 3 | [
"MIT"
] | permissive | module TestHelpers
module ZipContents
def zip_list_of_files(data)
files = []
process_zip_data(data) do |zipfile|
files = zipfile.entries.map(&:name)
end
files
end
# the client is reponsible for deleting dir
def extract_zip(data)
dir = Dir.mktmpdir
process_z... | true |
4f8ffdd361396212fe56dc519233540f643f91cd | Ruby | jiikko/sandbox | /ruby/tree/tree_sorted_list/spec/tree_sorted_list_spec.rb | UTF-8 | 566 | 2.5625 | 3 | [] | no_license | require 'spec_helper'
describe TreeSortedList do
describe '#generate' do
context '素因数に重複がない時' do
it '重複のない配列を返すこと' do
# 5, 2
# 10
# 5 15
# 3 7 13 17
expect(TreeSortedList.new(10).generate).to eq [5, 3, 7, 15, 13, 17]
end
... | true |
79706efb07d3c5e498534db07809538c81f0c1bf | Ruby | MHickey394/tts_practice | /ruby/pet.rb | UTF-8 | 308 | 3.65625 | 4 | [] | no_license | class Pet
attr_accessor :type, :petname, :age, :sound
def initialize (animal_type, pet_name, pet_age, noise)
@type = animal_type
@petname = pet_name
@age = pet_age
@sound = noise
end
end
my_pet = Pet.new("dog", "Titus", 3, "woof")
puts "My pet #{my_pet.petname} says #{my_pet.sound}."
| true |
e60e34bb31a8519863274db510b032e2dce6deab | Ruby | critsmet/astroCLI | /lib/methods/compare.rb | UTF-8 | 2,456 | 3.171875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def compare
name1 = get_first_user_name
if name1 == "return"
clear
return
elsif !User.all_names.include?(name1)
clear
puts "Please enter a valid name"
puts_space
compare
else
name2 = get_second_user_name
if name2 == "return"
clear
return
elsif !User.all_names.in... | true |
c460a45ab46a7f2f35405974bfe81ff8247d428e | Ruby | RMCornell/command_query_exercises | /command-query/pills.rb | UTF-8 | 117 | 3.296875 | 3 | [] | no_license | class Pills
attr_accessor :count
def initialize(count = 60)
@count = count
end
def pop
@count -= 1
end
end | true |
41266ae2e1700e0b589972935d7eb24a3f99fdbd | Ruby | firechicago/challenges | /sinatra-lunar-kitchen/models/recipe.rb | UTF-8 | 1,401 | 2.984375 | 3 | [] | no_license | class Recipe
attr_reader :id, :name, :instructions, :description
def initialize(id, name, instructions, description)
@id = id
@name = name
@instructions = instructions
@description = description
@ingredients = []
end
def ingredients
get_all_ingredients.each do |ingredient|
@ingre... | true |
982ce17efd76d794ae8f3ec6acc9e528147bb5f9 | Ruby | mel-rob/enigma | /test/encrypt_test.rb | UTF-8 | 418 | 2.6875 | 3 | [] | no_license | require_relative './test_helper'
require './lib/encrypt'
require './lib/shift'
class EncryptTest < Minitest::Test
def setup
@encryption = Encrypt.new
end
def test_it_exists
assert_instance_of Encrypt, @encryption
end
def test_message_shift
message = "hello world!"
key = "02715"
date = ... | true |
58cc01eebdcb931ba5b18771dc53658a5121a565 | Ruby | boostjp/study_meeting_tool | /partake_to_pdf/make_name_plate.rb | UTF-8 | 2,108 | 2.75 | 3 | [] | no_license | # coding: UTF-8
#
# partakeの参加者リストから、Twitterアイコン入り名札のPDFを作る
require 'csv'
require 'open-uri'
require 'prawn'
require 'prawn/text'
# String -> Array[String]
# PartakeのCSVを読み込んでTwitter IDのリストを取得
def read_partake_csv(csv_filepath)
ids = []
CSV.foreach(csv_filepath) {|row|
ids << row[2]
}
return ids
end
# S... | true |
405e86aeb1f67abee88f6686ab2da9b1e27e9916 | Ruby | lsuman83/square_array-onl01-seng-pt-052620 | /square_array.rb | UTF-8 | 143 | 3.421875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def square_array(array)
index = 0
array.each do |numbers|
num = numbers * numbers
array[index] = num
index += 1
end
end | true |
dc05017b2f1724cdb9dba82185ce64a51a2bf4bb | Ruby | pytong/coding_challenges | /ruby/lost_in_translation.rb | UTF-8 | 2,207 | 3.75 | 4 | [] | no_license | # Challenge Description:
# https://www.codeeval.com/open_challenges/121
# We have come up with the best possible language called Codel. To translate text into Codel, we take any message and replace each English letter with another English letter. This mapping is one-to-one and onto, which means that the same input let... | true |
2fd0db663f1feaf89a8fbf1cbd96985646faa123 | Ruby | clyeager/oop | /lesson_4/practice_problems_easy2/easy2_9.rb | UTF-8 | 352 | 3.65625 | 4 | [] | no_license | class Game
def play
"Start the game!"
end
end
class Bingo < Game
def rules_of_play
#rules of play
end
end
#What would happen if we added a play method to Bingo class?
#Ruby would first look in the class of the calling object. So if the object was an instance
#of the Bingo class, then it would run the... | true |
6be59a5f7a0c438a533f96cf0f7ba0e4957d17a7 | Ruby | cnopens/sparql-code-examples | /ruby/sparql1.rb | UTF-8 | 732 | 2.515625 | 3 | [
"BSD-2-Clause"
] | permissive | # Ruby querying of the BioPortal triplestore using standard Ruby libraries and the JSON rubygem
require 'rubygems'
require 'json'
require 'open-uri'
require 'cgi'
apikey = ""
endpoint = "http://sparql.bioontology.org/sparql/"
query = <<-EOS
PREFIX omv: <http://omv.ontoware.org/2005/05/ontology#>
SELECT ?ont ?name ?a... | true |
95b924dbfeec002e23c3da92924dfd31bcc2d45d | Ruby | kenr16/Ruby-postgresql-train-station | /spec/cities_spec.rb | UTF-8 | 2,668 | 3.03125 | 3 | [] | no_license | require("spec_helper")
describe("City") do
describe(".all") do
it("starts off with no cities") do
expect(City.all()).to(eq([]))
end
end
describe("#name") do
it("tells you the city's name") do
city = City.new({:name => "Portland", :id => nil})
expect(city.name()).to(eq("Portland"))
... | true |
f3d8e7d15cf8df8dbd356c83fbc6d1df02944f17 | Ruby | anthony-hull/take-away | /spec/order_manager_spec.rb | UTF-8 | 773 | 2.6875 | 3 | [] | no_license | # frozen_string_literal: true
require 'order_manager'
describe OrderManager do
let(:order_str) { 'pizza,pizza,dog,2400' }
let(:basket_spy) { instance_spy('Basket') }
let(:basket_class) { double('Basket', new: basket_spy) }
subject { OrderManager.new(basket_class) }
it 'takes in a one line CSV string and retu... | true |
8c06d23d003c8a4565e307cc2c944d287486ca91 | Ruby | alexhendra/belajarruby | /gets_input_puts_output.rb | UTF-8 | 59 | 3.140625 | 3 | [] | no_license | puts "Halo nama kamu siapa?"
nama=gets
puts "Halo #{nama}" | true |
d1f6e36c9cc0846f890ece8084c96b3ca299be27 | Ruby | tleskin/sales-engine | /lib/invoice.rb | UTF-8 | 917 | 2.84375 | 3 | [] | no_license | class Invoice
attr_reader :id, :customer_id, :merchant_id,
:status, :created_at, :updated_at,
:repository
def initialize(data, repository)
@id = data[:id].to_i
@customer_id = data[:customer_id].to_i
@merchant_id = data[:merchant_id].to_i
@status = data[:status]
@cre... | true |
2110ba2b1ac83ef8ce30f20ea7232c70086aaae4 | Ruby | lucasmarqs/tictactoe-rb | /test/board_test.rb | UTF-8 | 690 | 2.921875 | 3 | [] | no_license | # frozen_string_literal: true
require 'minitest/autorun'
require_relative '../board'
describe Board do
describe '#play' do
describe 'when player wins' do
it 'results in :won' do
board = Board.new
[[:x, 2], [:o, 8], [:x, 6], [:o, 4], [:x, 0], [:o, 3]].each do |player, position|
a... | true |
6cf07b01459512210e5fcfbcd332a3ad3e6828dd | Ruby | mandyminh/ruby_student_teams | /HW_pig_latin.rb | UTF-8 | 651 | 4.40625 | 4 | [] | no_license | #Write a program that translates one word English word into Pig Latin.
# Because the rules for Pig Latin can vary, I'll be specific:
# If the given word starts with a consonant, move only that consonant to end and then add "ay" to the end (e.g.: coffee -> offeecay, blogger -> loggerbay)
# If the given word starts wit... | true |
3ebd2f9285137d5074968ec6aa9b8c02de25bb48 | Ruby | madebyhiro/codem-schedule | /bin/codem | UTF-8 | 3,504 | 2.828125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/env ruby
require 'optparse'
ARGV << '-h' if ARGV.empty?
def command?(command)
system("which #{ command} > /dev/null 2>&1")
end
class CodemCommand
attr_reader :host, :input, :output, :preset, :notify, :verbose, :silent, :status
def initialize
options = {}
optparse = OptionParser.new do |opt... | true |
5b9019e2a3cc170557a6d6d6f12f0b63195052bb | Ruby | easybiblabs/haproxyctl | /rhapr/spec/support/config_fixtures.rb | UTF-8 | 1,127 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'bundler'
module ConfigFixtures
attr_reader :config_fixtures
# @param [Symbol]
# @return [String]
def fixture_for(sym)
config_fixtures[sym][:fixture]
end
alias_method :config_for, :fixture_for
def path_for(sym)
config_fixtures[sym][:path]
end
# @see ConfigFixtures#create_fixture_ha... | true |
a80b280eb55eb54b6e581c4ca21fa54a89908a8b | Ruby | kinoshitaken123/coding-test | /SymmetricTree.rb | UTF-8 | 1,022 | 3.8125 | 4 | [] | no_license | # 二分木の根が与えられたら、それがそれ自体の鏡であるかどうかを確認します
# (つまり、その中心を中心に対称になります)。
# Input: root = [1,2,2,3,4,4,3]
# Output: true
class TreeNode
attr_accessor :val, :left, :right
def initialize(val = 0, left = nil, right = nil)
@val = val
@left = left
@right = right
end
end
t1 = TreeNode.new(1)
t2 = T... | true |
7199832ad8c00be1a1a0266aa036b45d6b616124 | Ruby | chrissyw247/ttt-8-turn-q-000 | /lib/turn.rb | UTF-8 | 1,338 | 4.0625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
board = [" ", " ", " ", " ", " ", " ", " ", " ", " "]
def display_board(anything)
puts " #{anything[0]} " + "|" + " #{anything[1]} " + "|" + " #{anything[2]} "
puts "-----------"
puts " #{anything[3]} " + "|" + " #{anything[4]} " + "|" + " #{anything[5]} "
puts "-----------"
puts " #{anything[6]} " + "|" +... | true |
479bd971ca0ee3070bddfc168c8f24e5e833633f | Ruby | SilentFlameCR/ruby_hangman | /hangman.rb | UTF-8 | 3,268 | 4.09375 | 4 | [] | no_license | #=begin
class Hangman
def self.load
#New game or Saved Game
puts "Lets start a new game!"
game = Hangman.new
game.start
end
def initialize
#track the important instance variables
@used_guesses ||= 0
@lives = 6
@word = pick_word(load_dictio... | true |
7348e4e147f791fc2d3b5e2d3c68de2a4fa69c8d | Ruby | kylietramle/ramen_types-webclient | /app/models/ramen_type.rb | UTF-8 | 1,206 | 2.609375 | 3 | [] | no_license | class RamenType
attr_accessor :id, :name, :soup_base, :flavor, :broth_color, :other_ingredients
def initialize(ramen_type_hash)
@id = ramen_type_hash["id"]
@name = ramen_type_hash["name"]
@soup_base = ramen_type_hash["soup_base"]
@flavor = ramen_type_hash["flavor"]
@broth_color = ramen_type_has... | true |
2849c7cd377d93daaf5ce1d7cb5dab13caf5a4fe | Ruby | bvsatyaram/project_euler | /lib/sum_of_proper_factors.rb | UTF-8 | 482 | 3.359375 | 3 | [] | no_license | require_relative "prime_factorization"
class SumOfProperFactors
def initialize(num)
@num = num
end
def get
return 0 if @num == 0
prime_factors = PrimeFactorization.new(@num).get
return 0 if prime_factors.keys.size == 1
sums_of_powers_of_primes = []
prime_factors.keys.each do |prime_factor|
sum... | true |
cb16f4292a879b37a7d41cebcfbc5e696e524ee0 | Ruby | way-key/exersize | /Rubyを学ぼう/第7章/lesson6.rb | UTF-8 | 480 | 3.109375 | 3 | [] | no_license | total_price = 200
if total_price > 100
puts "みかんを購入。所持金に余りあり"
end
if total_price == 100
puts "みかんを購入。所持金に余り無し"
end
if total_price <=100
puts "みかんを購入することができません"
end
if total_price > 100
puts "みかんを購入。所持金に余りあり"
elsif total_price == 100
puts "みかんを購入。所持金に余り無し"
else
puts "みかんを購入することができません"
end | true |
e50f2d9dfaec38894a9d04f3482fa8a8131c2c06 | Ruby | Viktorkosandyak/test_about_jealousy | /lib/test.rb | UTF-8 | 2,235 | 3.640625 | 4 | [] | no_license | class Test
# конструктор, в котором создаем поля для вопросов и подсчета результатов
def initialize
# массив вопросов, загружаем из файла questions.txt
current_path = File.dirname(__FILE__)
file_name = current_path + "/../data/questions.txt"
if !File.exist?(file_name)
abort "Невозможно загрузить вопросы т... | true |
76aae86d4ff33ca951c4108e2efa1d3324173712 | Ruby | strychemi/assignment_rspec_viking | /spec/viking_spec.rb | UTF-8 | 3,466 | 3.609375 | 4 | [] | no_license | require 'viking'
describe Viking do
let(:viking) { Viking.new("First") }
describe '#initialize' do
it 'passing name sets name attribute' do
viking = Viking.new("Bob")
expect(viking.name).to eq("Bob")
end
it 'passing health sets health attribute' do
viking = Viking.new(name = "bob" , health = 50)
... | true |
1072b18a24263be898f0dc59cfa00f3329d40289 | Ruby | iSarCasm/ebay_reg | /lib/app/account.rb | UTF-8 | 161 | 2.75 | 3 | [] | no_license | class Account
def initialize(user)
@email = user.email
@password = user.password
end
def to_h
{email: @email, password: @password}
end
end
| true |
e202aecb1f197fd69f39a583728f37d1359fae7f | Ruby | CJHunter91/vet_practice_management_system | /spec/appointment_spec.rb | UTF-8 | 957 | 2.828125 | 3 | [] | no_license | require('minitest/autorun')
require_relative('../models/pet')
require_relative('../models/owner')
require_relative('../models/appointment')
class TestAppointment < MiniTest::Test
def setup
@owner1 = Owner.new({
'name' => 'Chris',
'address' => 'Edinburgh',
'phone' => '01312281211'
})
... | true |
8da3ff39910e5b5059c98f5a27d0e742d577d8d4 | Ruby | Chebotarev/Code-Eval-Challenges | /easy/hex_to_decimal.rb | UTF-8 | 274 | 3.28125 | 3 | [] | no_license | def to_dec(hex)
dec = 0
hex.chomp.reverse.split(//).each_with_index do |hex_char, index|
hex_char = hex_char.hex
dec += (16 ** index) * hex_char.to_i
end
dec
end
input_lines = File.readlines ARGV[0]
input_lines.each do |inputs|
puts to_dec(inputs)
end
| true |
06b6a4c2f5dfefa6b4f540a6180d20f3f1c2be18 | Ruby | sprinkle-tool/sprinkle | /lib/sprinkle/installers/apt.rb | UTF-8 | 1,738 | 2.953125 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | module Sprinkle
module Installers
# The Apt package installer uses the +apt-get+ command to install
# packages. The apt installer has only one option which can be
# modified which is the +dependencies_only+ option. When this is
# set to true, the installer uses +build-dep+ instead of +install+
# t... | true |
9de6452b03d09f573247f6ba4b85da1ae251194e | Ruby | LichP/raspi-opengl | /examples/marquee.rb | UTF-8 | 4,443 | 2.5625 | 3 | [] | no_license | #!/usr/bin/ruby1.9.1
#
# Demonstrate a marquee effect using RMagick to render text
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
require 'raspigl'
require 'RMagick'
class Marquee < RaspiGL
def setup
marquee_text = "This is a marquee demo"
# Setup GL for 2D working
self.setup_gl_2d
... | true |
2dfe7331f8555485962d771ada5301fc70437928 | Ruby | ATOZ-TEAM/sellerdi-server | /app/models/concerns/default_column.rb | UTF-8 | 1,114 | 2.578125 | 3 | [] | no_license | module DefaultColumn
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
# Example:
# class Foo < ApplicationRecord # After
# make_default_value_of_column :requested_at, -> { Time.zone.now }
# end
#
# class Foo < ApplicationRecord # Before
# ... | true |
9f788b8736309e85efc73e21c26dfc157203c680 | Ruby | KatTsukuda/ruby-method-drills | /starter-code/strings.rb | UTF-8 | 2,419 | 4.40625 | 4 | [] | no_license | ##############################
#### MANIPULATING STRINGS ####
##############################
#first_char
def first_char word
word[0].downcase
end
# takes in a word
# returns the first letter of the word
# lowercases the first letter of the word
#polly_wanna
def polly_wanna word
word * 3
end
# takes in a wo... | true |
a0e035423ded122f4547f412e2fdac12e60a0ee4 | Ruby | ruivitorbaltazar/rails-longest-word-game | /app/controllers/games_controller.rb | UTF-8 | 646 | 3.03125 | 3 | [] | no_license | require 'open-uri'
class GamesController < ApplicationController
def new
@letters = Array.new(10) { ('a'..'z').to_a.sample }
end
def score
word = params[:word]
letters = params[:letters]
url = "https://wagon-dictionary.herokuapp.com/#{word}"
check = JSON.parse(open(url).read)
r1 = "Sorry... | true |
b73df7a507d1c309486062213952546fd24bd50f | Ruby | danbedford56/Birthday-web-app | /app.rb | UTF-8 | 499 | 2.703125 | 3 | [] | no_license | require 'sinatra/base'
require_relative 'bday_calculator'
require 'time'
class BirthdayApp < Sinatra::Base
run! if app_file == $0
enable :sessions
get '/' do
erb :index
end
post '/birthday' do
session[:name] = params[:name]
session[:is_bday] = calculate_bday(params[:da... | true |
2be3417464a578c0c97ed83853a04f915c6457bb | Ruby | geckoboard/everdeen | /ruby_client/lib/everdeen/expectation.rb | UTF-8 | 1,032 | 2.53125 | 3 | [
"MIT"
] | permissive | module Everdeen
class Expectation
attr_reader :uuid, :max_matches, :response, :request_criteria
def initialize(args = {})
args.each do |key, value|
next if ['response', 'request_criteria'].include?(key.to_s)
instance_variable_set("@#{key}", value)
end
add_response(args[:res... | true |
e4d37073ee2a798bdb640e1eb8566dd451c33d3b | Ruby | grant-madden/LearningRuby | /CarDealerRevised/classy_car_dealer.rb | UTF-8 | 3,285 | 3.5625 | 4 | [] | no_license | require_relative 'car_option'
require_relative 'car_model'
require_relative 'car_package'
require_relative 'menu_display'
# Main
class MainApp
def initialize(input: $stdin, output: $stdout)
@input = input
@output = output
# Creates new package class
@user_package = CarPackage.new(CarModel.new)
end... | true |
5568e6fc8195481329b8bbe30e30382d424a319a | Ruby | BloomAndWild/sightengine | /lib/sightengine/api/face_attributes.rb | UTF-8 | 931 | 2.75 | 3 | [
"MIT"
] | permissive | module Sightengine
module Api
module FaceAttributes
class Face
attr_accessor :x1, :y1, :x2, :y2
attr_accessor :features
attr_accessor :attributes
attr_accessor :celebrity
def initialize(hash)
hash.each do |k, v|
send("#{k}=", v)
end
... | true |
3d2fc98212a6973565b60c3e262e253493f09201 | Ruby | JohnLouisRumingan/refactored-algorithms | /exercises/ruby_leetcode/september_20_challenge/oo_contains_duplicate.rb | UTF-8 | 797 | 4.03125 | 4 | [] | no_license |
# Given an array of integers, find if the array contains any duplicates.
# Your function should return true if any value appears at least twice in the array,
# and it should return false if every element is distinct.
# Example 1:
# Input: [1,2,3,1]
# Output: true
# Example 2:
# Input: [1,2,3,4]
# Output: false
... | true |
e2dc47ae113b19d4f925054f995eb3564a18fe75 | Ruby | MsJennyGiraffe/hyde | /bin/hyde | UTF-8 | 398 | 2.734375 | 3 | [] | no_license | #!/usr/bin/env ruby
args = ARGV
puts "You ran Hyde with these arguments: #{args}"
# path = ARGV[1]
# if ARGV[0] == "new"
#we want to build the (new) base structure.
#FileMaker.new.build(path) ?
# if ARGV[0] == "build"
# we want to go through all folders and files and make sure everything is converted to HTML fr... | true |
37e58b1d3772f68a620b93bb8ab4ef8fd259ed8a | Ruby | jordansgrant/sample_app | /app/helpers/users_helper.rb | UTF-8 | 472 | 2.5625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"Beerware"
] | permissive | module UsersHelper
#returns the Gravatar for the given user
#takes User object as argument
def gravatar_for(user, options = { size: 80 })
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{options[:size]}"
# return image tag ... | true |
91e4ac334c43054136cee9c1bc4beb217d28a43e | Ruby | cfanpnk/launchschool | /backend/ruby_foundations/exercises/small_problems_101/easy_5/alphabetical_numbers.rb | UTF-8 | 477 | 3.953125 | 4 | [] | no_license | NUMBERS = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten', 'eleven',
'twelve', 'thirteen', 'fourteen', 'fifteen', 'sixteen', 'seventeen', 'eighteen', 'nineteen']
def alphabetic_number_sort(array)
sorted_numbers = NUMBERS.sort
array.map do |number|
NUMBERS.index... | true |
d9a218703ee9acc7d6e1bf9c78a875f1b662d3e7 | Ruby | RobbieDumbrell/week3-day3-music_collection | /db/console.rb | UTF-8 | 1,027 | 2.875 | 3 | [] | no_license | require_relative('../models/artist.rb')
require_relative('../models/album.rb')
eminem = Artist.new({
'name' => 'Eminem'
})
green_day = Artist.new({
'name' => 'Green Day'
})
# eminem.save()
# green_day.save()
curtain_call_album = Album.new({
'title' => 'Curtain Call',
'genre' => 'Rap',
'artist_id... | true |
8154422392eafff166089b033ec9e5f264bfacdb | Ruby | jasonng17/BookShare | /test/functional/books_controller_test.rb | UTF-8 | 1,890 | 2.609375 | 3 | [] | no_license | require 'test_helper'
#ActionController is a subclass of Test::Unit::TestCase => i.e. based on the Test::Unit framework
class BooksControllerTest < ActionController::TestCase
setup do
@user = users(:one)
@book = books(:one)
@book_attributes = {
title: "Ruby on Rails",
author: "Sam Rub... | true |
cabcb80b7062a2aea5fde32acd516fc65513a40b | Ruby | kbl/s10-int | /lib/maildo/list/tasks.rb | UTF-8 | 751 | 2.796875 | 3 | [] | no_license | module Maildo
module List
IllegalTaskIdentifierError = Class.new(RuntimeError)
class Tasks
ONLY_NUMBERS = /^\d+$/
include PersistencyAware
def initialize(list_id)
@list_id = list_id
end
def add(task)
store.add(:tasks, task)
end
def done(one_base... | true |
2e916521da8d40b6e8a7af96a1f8b801bfdfee30 | Ruby | excid3/bank_teller | /lib/bank_teller.rb | UTF-8 | 1,194 | 3.140625 | 3 | [] | no_license | require "bank_teller/version"
require 'bank_teller/engine' if defined?(Rails)
module BankTeller
@@currency = 'usd'
@@currency_symbol = '$'
@@format_currency_using = nil
def self.use_currency(currency, symbol = nil)
@@currency = currency
symbol = self.guess_currency_symbol(currency) if symbol.nil?
... | true |
10fc6cce2e6a34a42b5b41bbcdff49bd0f507970 | Ruby | Christine79/API_s | /spotify_post.rb | UTF-8 | 2,037 | 2.703125 | 3 | [] | no_license | require "httparty"
require 'dotenv'
require 'pry'
# Appelle la gem dotenv
# Ceci appelle le fichier .env grâce à la gem dotenv, et enregistre toutes les données enregistrées dans une hash ENV
Dotenv.load
# quelques lignes qui enregistrent les clés d'APIs
#client = Spotify::REST::Client.new do |config|
# config.c... | true |
48f6e97d9c453aaae884f54ea02504a95aa6169e | Ruby | renanmaringolo/dino | /session_5/lesson_9_2.rb | UTF-8 | 412 | 3.125 | 3 | [] | no_license | # escreve (truncate)
bancos = <<DINOSSAURO # string multi-line
310|Banco Itaú
42|Dinossauro Bank
DINOSSAURO
File.write('bancos.txt', bancos)
# abre no mode write (truncate)
File.open('bancos.txt', 'w') do |file|
file.write("42|Dinossauro Bank S/A\n")
file.write("310|Banco Itaú\n")
end
# abre no mode append (not ... | true |
c69f3ae061c38610d72afe01e6a04f443c64b8bc | Ruby | paulociecomp/auctionapp | /app/models/batch.rb | UTF-8 | 695 | 2.796875 | 3 | [] | no_license | class Batch < ApplicationRecord
include ConvertDecimalAttributes
include BatchStatus
convert_decimal :initial_bid
convert_decimal :finish_bid
PERCENTAGE = 10
def bid
return false unless self.open?
self.bid_count += 1
self.current_bid += calc_percent_bid
self.status = get_status
save
... | true |
87817c3315cd7dbcfd91914329d72642b96af612 | Ruby | sploving/shogun | /examples/undocumented/ruby_modular/kernel_fixed_degree_string_modular.rb | UTF-8 | 809 | 2.625 | 3 | [] | no_license | # this was trancekoded by the awesome trancekoder
require 'narray'
require 'modshogun'
require 'load'
require 'pp'
traindat = LoadMatrix.load_dna('../data/fm_train_dna.dat')
testdat = LoadMatrix.load_dna('../data/fm_test_dna.dat')
parameter_list=[[traindat, testdat,3],[traindat,testdat,4]]
def kernel_fixed_degree_str... | true |
f7c1d123393b8c2e7e6b4ad4943fe1ebabbcdd82 | Ruby | stevejk31/app_academy | /w1d5/minesweeper.rb | UTF-8 | 5,071 | 3.671875 | 4 | [] | no_license | require 'byebug'
require 'yaml'
class Tile
attr_reader :revealed, :flagged, :has_bomb
attr_accessor :neighbor, :neighbor_bombs
def initialize(has_bomb = false)
@has_bomb = has_bomb
@flagged = false
@revealed = false
@neighbor_bombs = 0 #num of neighbors who are bombs
@neighbor = [] #empty ... | true |
2952b2bfc698bb731ac128afa0908ee84c4dc842 | Ruby | AnkitaVerma4/git_basics1 | /greetings_method.rb | UTF-8 | 131 | 3.28125 | 3 | [] | no_license | /def greetings(name)
puts "Hello " +name+ ", How are You?"
end
greetings("Bob") /
x = [1, 2, 3, 4, 5]
x.each do |a|
a + 1
end | true |
10b7abdd37559c1e2dacf3a83c42b992e99e360f | Ruby | rglassett/data-structures | /binary_arithmetic/spec/add_spec.rb | UTF-8 | 507 | 2.921875 | 3 | [] | no_license | require 'rspec'
require 'add'
describe "#add" do
describe "zero addition" do
it "adds zero to zero" do
expect(add(0, 0)).to eq(0)
end
it "adds zero to another number" do
expect(add(0, 4)).to eq(4)
end
end
describe "nonzero addition" do
it "adds two numbers" do
expect(add(2... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.