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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
92a98899f07c682af3bc0b4a6b08c021cf51f7ed | Ruby | launchdarkly/ruby-eventsource | /lib/ld-eventsource/errors.rb | UTF-8 | 1,765 | 2.890625 | 3 | [
"Apache-2.0"
] | permissive |
module SSE
#
# Exception classes used by the SSE client.
#
module Errors
#
# An exception class representing an HTTP error response. This can be passed to the error
# handler specified in {Client#on_error}.
#
class HTTPStatusError < StandardError
def initialize(status, message)
... | true |
7d064940b21fad99d9738c7759fe272184a31249 | Ruby | MIKEALGEE/homework_weekend_week1 | /pet_shop_start/pet_shop.rb | UTF-8 | 2,750 | 3.78125 | 4 | [] | no_license |
def pet_shop_name(name) #this variable could be anything, it doesn't matter as long as the information
@pet_shop[:name] # is the same as the test is expecting.
end
def total_cash(sum) # again sum could actually be anything , as long as the information matches = 1000 which is what the test expects
sum = @pe... | true |
cb06eea67ce48ff13a12b11a22d173684a5746d0 | Ruby | luongm/ptc_spring13 | /proj/test_server_in_bud.rb | UTF-8 | 7,314 | 2.78125 | 3 | [] | no_license | require 'rubygems'
require 'bud'
require 'rest_bud'
require 'test/unit'
require 'rest-client'
require 'rest_bud_helper'
class TestRestBud < Test::Unit::TestCase
@@port = 3000
def error_message(msg, data=nil)
ret = "[#{@action} /#{@resource}]: #{msg}\n"
details = ""
if data
if data.include? 'erro... | true |
117f88fcc2d4226a84da6fb20c42d3999af70b51 | Ruby | leoroos/bptree | /bptree.rb | UTF-8 | 292 | 3.125 | 3 | [] | no_license | class Bptree
attr_reader :order
def initialize
@order = 7
@children = []
@value = {}
end
def is_leaf
true
end
def insert key,value
@value[key]=value
if @value.count >= @order
puts 'split'
end
end
def get key
@value[key]
end
end
| true |
cdb7c4edfbc008e90e0471d55fa8be8b343e0ecb | Ruby | danchoi/tracker | /lib/outln.rb | UTF-8 | 758 | 2.671875 | 3 | [] | no_license | require 'sequel'
DB = Sequel.connect 'postgres:///tracker'
FIELDS = {
title: "%-72s",
parent_id: "%9s",
depth: "%6s",
position: "%9s",
path: "%-30s",
task_id: "%9s",
}
def format(result_set)
template = FIELDS.values.join(" | ")
header = template % FIELDS.keys
divider_line = header.gsub(/\|/, "+").... | true |
1474aab24edbf018cda7b61bea6901af6e194e54 | Ruby | KlotzAndrew/algorithms | /lib/sort/bubble_sort.rb | UTF-8 | 274 | 3.734375 | 4 | [] | no_license | class BubbleSort
def call(arr)
loop do
swapped = false
(arr.length-1).times do |i|
if arr[i] > arr[i+1]
swapped = true
arr[i], arr[i+1] = arr[i+1], arr[i]
end
end
break if !swapped
end
arr
end
end
| true |
3569cfb2751c1c347105d3f7142d86d6147ecf66 | Ruby | botanicus/blog_example | /app/lib/adapters/pg_store.rb | UTF-8 | 1,963 | 2.515625 | 3 | [] | no_license | # frozen_string_literal: true
# TODO: Rename: this is not a generic data_store, this should be an adapter.
# Examples:
# SQL table_name -> id
#
# Directory with YAML files.
# data/posts.yml -> A list.
#
# Nested directories with YAML files.
# data/posts/1.yml
DB = import('registry').db
# TODO: Now you composition to... | true |
15bee1b29d92ae2edbc6934584e8c5099e3ee0df | Ruby | richardbobo1/programming-univbasics-4-square-array-dc-web-030920 | /lib/square_array.rb | UTF-8 | 268 | 3.265625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def square_array(numbers)
square_array = []
counter = 0
while counter < numbers.length do
square_array.push ( numbers[counter]*numbers[counter] )
counter += 1
end
square_array
end
square_array(numbers = [1,2,3])
square_array(numbers =[9,10,16,25])
| true |
a7e5c91578247c489c1768b8656e540d177294f0 | Ruby | josegonzalez/ruby-cimino | /_rake/helper.rb | UTF-8 | 1,832 | 3 | 3 | [
"MIT"
] | permissive | require 'erb'
require 'tilt'
require 'clipboard'
###################
# Helper Methods #
###################
def regenerate_site(relative)
puts "\n\n>>> Change Detected to: #{relative} <<<"
IO.popen('rake generate'){|io| print(io.readpartial(512)) until io.eof?}
puts '>>> Update Complete <<<'
end
def ok_failed... | true |
8e2cd21231cb28c45819aa9810dda1fcb6ab14a5 | Ruby | mihobo/Battle | /spec/player_spec.rb | UTF-8 | 497 | 2.921875 | 3 | [] | no_license | require 'player'
describe Player do
let(:player1) { described_class.new('Lily') }
let(:player2) { described_class.new('Dexter') }
it 'returns a name' do
expect(player1.player_name).to eq('Lily')
end
describe 'reduce hp' do
it 'reduces hp of player 2' do
player2.reduce_hp
expect(player2.... | true |
8697633873de044320cdb363205c671c6ba72521 | Ruby | dyama/mruby-rational | /mrblib/rational.rb | UTF-8 | 4,195 | 3.265625 | 3 | [
"MIT"
] | permissive | ##
# Kernel.#Rational
#
# http://docs.ruby-lang.org/ja/1.9.3/method/Kernel/b/Rational.html
#
def Rational(numer, denom = 1)
Rational.__send__ :convert, numer, denom
end
##
# Rational class
#
# http://docs.ruby-lang.org/ja/1.9.3/class/Rational.html
#
class Rational < Numeric
def *(other)
raise TypeError unless... | true |
33e9fdb1c16db16d547f2ac41de261cbf0d66b96 | Ruby | verdi327/sales_engine | /lib/sales_engine/merchant.rb | UTF-8 | 2,035 | 2.8125 | 3 | [] | no_license | module SalesEngine
class Merchant
extend Searchable
attr_accessor :id, :name, :created_at, :updated_at
def initialize(attributes)
self.id = attributes[:id]
self.name = attributes[:name]
self.created_at = attributes[:created_at]
self.updated_at = attributes[:updated_at]
end... | true |
5e277df976621b68f1fe744f3af92a929f4f6c0e | Ruby | Redvanisation/data-algorithm | /3-tree-and-graph/ex45-solution.rb | UTF-8 | 446 | 3.484375 | 3 | [
"MIT"
] | permissive | def bfs(graph)
# write your code here
queue = [0]
result = []
visited = []
until queue.empty?
head = queue.shift
result << head
visited << head
not_visited = graph[head].reject { |node| visited.include? node }
visited += not_visited
queue += not_visited
end
result
e... | true |
c55876fefeeccebdba2b7920c67702eab5d5290e | Ruby | tadiou/lambda_factory_girl | /spec/factories/user.rb | UTF-8 | 923 | 2.546875 | 3 | [] | no_license | FactoryGirl.define do
factory :user do
# works
# add_school_role = Proc.new do |user, role|
# School.find_or_create_by!(name: "Funtimes University").add_user(user, role)
# end
# works
# add_school_role = -> (user, role) { School.find_or_create_by!(name: "Funtimes University").add_user(user,... | true |
375d24e8160daafa6ee858cb60a6da014c0ea2ae | Ruby | fredriksa/SurvivalBox-2D | /src/Weapon.rb | UTF-8 | 1,089 | 3 | 3 | [] | no_license | class Weapon
attr_accessor :x, :y, :angle, :bullets, :ammo, :bullets, :damage, :particle, :loot, :name
def initialize(window, x, y, ammo, damage = 40, speed = 1, angle = 90, loot = false, particle = 10)
@window = window
@x, @y, @angle = x, y, angle
@ammo = ammo
@damage = damage
@particle = particle... | true |
6784f9b890bc38d0a74e6e496dfbf1c9d0747548 | Ruby | dlynam/request_trap | /app/services/create_request.rb | UTF-8 | 439 | 2.625 | 3 | [] | no_license | class CreateRequest
def initialize(trap_id, request, response)
@request = request
@response = response
@request_obj = new_request_obj(trap_id)
end
def create
SetRequestInfo.new(request_obj, request).set_info
request_obj.raw_response = response.body
request_obj.save
end
private
at... | true |
f90512da6e8e86000d3da6cf050a6a82fdf0b727 | Ruby | jocelynocelyn/rockpaperscissors | /rps.rb | UTF-8 | 2,570 | 3.890625 | 4 | [] | no_license | class Game
attr_accessor :user_score
def initialize(user_score = 0)
@user_score = user_score
@computer = ComputerAi.new
end
def play
puts "Pick rock paper or scissors!"
@choice = gets.chomp.downcase
case @choice
when "rock"
rock
when "paper"
paper
when "scissors"
... | true |
3065ca61e25b96c040ec6be23096c7f73473a83e | Ruby | katyjane8/battleship | /lib/messages.rb | UTF-8 | 1,000 | 3 | 3 | [] | no_license | require 'colorize'
module Messages
def welcome_message
#possible refactor here to add color and messages option "+="
puts "Welcome to BATTLESHIP\n\nWould you like to (p)lay, read the (i)nstructions, or (q)uit?.\n".light_blue
end
def instructions
puts "You will have ten guesses to try and hit my bat... | true |
bb4f07a5f9caa68de6a2554bbeb78adc5d80dc38 | Ruby | noelcurtis/Forbes | /db/seeds.rb | UTF-8 | 2,638 | 2.578125 | 3 | [] | no_license | def states_and_cities
{
'Andhra Pradesh' => ['Rajasthan', 'Visakhapatnam'],
'Bihar' => ['Patna'],
'Delhi' => ['Delhi'],
'Gujarat' => ['Ahmedabad', 'Surat', 'Vadodara', 'Rajkot'],
'Haryana' => ['Faridabad'],
'Karnataka' => ['Bangalore'],
'Madhya Pradesh' => ['Indore', 'Bhopal'],
'Mahara... | true |
a451677d4d3e98027fdbd90c01b9936f0e48dcaa | Ruby | erberger22/phase-0-tracks | /ruby/iteration.rb | UTF-8 | 1,670 | 3.578125 | 4 | [] | no_license | #Release 0
def farwell
puts "Bye-bye"
yield ("alligator")
puts "In a while, crocodile"
end
farwell { |phrase| puts "see you later, #{phrase}" }
#Release 1
birds = ["ostrich", "emuu", "penguin", "kiwi"]
bears = {"grizzley" => "scary", "polar" => "scary", "the pooh" => "not scary"}
p birds
birds.each do |bird|
... | true |
af2dd82cb895c1487dc13199ef8123a22ec3dc76 | Ruby | googleads/google-ads-ruby | /examples/error_handling/handle_keyword_policy_violations.rb | UTF-8 | 6,428 | 2.640625 | 3 | [
"Apache-2.0",
"MPL-2.0",
"BSD-2-Clause",
"MIT",
"BSD-3-Clause",
"LicenseRef-scancode-protobuf"
] | permissive | # Encoding: utf-8
#
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or ag... | true |
ba0b82e60816850f4019494871a03a644752add2 | Ruby | isabella232/cgla_case_chart_assister | /spec/lib/cgla_case_chart_assister/parsers/cook_county_parser_spec.rb | UTF-8 | 4,512 | 2.671875 | 3 | [
"MIT"
] | permissive | require_relative '../../../support/fixture_helper'
require 'cgla_case_chart_assister'
require 'json'
require 'date'
RSpec.describe CglaCaseChartAssister::CookCountyParser do
let(:cook_json) { JSON.parse(FixtureHelper.read_fixture('./spec/fixtures/cook_county.json')) }
describe 'parse_history' do
context 'when... | true |
37d56da5fed7d856b59a786820300c3e1bff11ef | Ruby | bagolol/takeaway-challenge | /spec/feature/feature_test_spec.rb | UTF-8 | 912 | 2.84375 | 3 | [] | no_license | require 'takeaway'
require 'customer'
feature 'as a customer I want to order from a takeaway' do
scenario 'a menu is available' do
customer = Customer.new { Takeaway.new }
expect(customer.see_menu).to eq ({ 'red curry' => 5, 'green curry' => 5 })
end
scenario 'an order can be placed' do
customer = C... | true |
fb864b7d4d952a99273a01230b75b76b0919a8db | Ruby | joshisaurabh/learn_ruby | /10_temperature_object/temperature_sj.rb | UTF-8 | 337 | 3.828125 | 4 | [] | no_license | class Temperature
def initialize(opty={})
@options = opty
end
def to_fahrenheit
if @options[:f]
@options[:f]
else
(@options[:c] * (9.0 / 5)) + 32
end
end
def to_celsius
if @options[:c]
@options[:c]
else
(@options[:f]-32)*5.0/9
end
end
end
ft=Temperature.new
puts ft.to_fahrenheit
pu... | true |
7a42e9ecf261fe2d6f313629378972d090b608d2 | Ruby | toririn/slack_on_rails | /app/helpers/application_helper.rb | UTF-8 | 243 | 2.75 | 3 | [] | no_license | module ApplicationHelper
# 文字列中の改行文字を改行として出力させるメソッド
# e.g. "hello\nworld" => "hello<br />world"
def br(text)
text = h(text).gsub(/(\r\n?)|(\n)/, "<br />")
text.html_safe
end
end
| true |
3f6531c39b4c180842287ac32d5c5a41f98cbc0e | Ruby | lisaar/inject | /spec/inject_spec.rb | UTF-8 | 2,719 | 3.75 | 4 | [] | no_license | require 'inject'
describe 'injection' do
let(:two_element_array) {[1, 2]}
context 'given a specified memo value' do
it 'accepts a block, returning the newly injected memo value' do
# if the array element is inlcluded in the memo then it puts array element
# else it assigns the array ... | true |
3a2d5a8d3c5f52c3b26964c3f350469906842756 | Ruby | sneakin/CooCoo | /spec/coo-coo/activation_functions.spec | UTF-8 | 4,822 | 2.5625 | 3 | [
"LicenseRef-scancode-warranty-disclaimer"
] | no_license | require File.join(File.dirname(__FILE__), '..', 'spec_helper')
require 'coo-coo/math'
require 'coo-coo/activation_functions'
shared_examples 'activation function' do
subject { described_class.instance }
let(:from_name_args) { nil }
it { expect(CooCoo::ActivationFunctions.named_classes).to include(subject.name) ... | true |
1f91afa5aab568acb464c41c89ea760eb418fc2b | Ruby | hirakazmi/ruby_fundamentals2 | /exercise6.rb | UTF-8 | 413 | 3.28125 | 3 | [] | no_license | grocery_list = [ "carrots", "toilet paper", "apples", "salmon"]
grocery_list << "rice"
grocery_list.delete("salmon")
grocery_list.sort!
has_bananas = false
grocery_list.each do |item|
puts "* #{item}"
if item == "bananas"
has_bananas = true
end
end
if has_bananas
puts " You need to pick up bananas"
else
... | true |
340f9f791fd415b88e830d0c8d11829caf55aca5 | Ruby | Chrisyee22/algoritms-and-complexity | /complex_problems/tsp_greed.rb | UTF-8 | 711 | 3.234375 | 3 | [] | no_license | require_relative 'city'
def nearest_neighbor(graph_of_cities, current_city)
while !current_city.visited
neighbor_cities = current_city.neighbors[0]
distance_to_next_city = neighbor_cities[1]
current_city.neighbors.each do |current_neighbor|
current_neighbor_city = current_neighbor[0]
d... | true |
ffd3e8d35d4f9933e30df7e209949e8300a111c7 | Ruby | daniel-certa-1228/Ruby-Wiki-Scraper | /csv_to_json.rb | UTF-8 | 891 | 3.109375 | 3 | [] | no_license | require 'json'
require 'csv'
# json 1, clean array of song tiles
beatles_songs = []
CSV.foreach('beatles_songs.csv') do |line|
beatles_songs.push(line[0])
end
beatles_songs.shift
File.open('beatles_songs.json', 'w') do |f|
f.write(beatles_songs.to_json)
end
#json 2, has more data
beatles_songs_2 = []
lines ... | true |
d2d8a34dabea8b5fcc3439552da4e35d0f42b808 | Ruby | boardfish/codewars | /counting_duplicates.rb | UTF-8 | 150 | 2.796875 | 3 | [] | no_license | # https://www.codewars.com/kata/54bf1c2cd5b56cc47f0007a1
def duplicate_count(t)
t.upcase.chars.group_by(&:itself).select {|k,v| v.size>1}.size
end
| true |
cb8ca400d0f9ef2e51cb8b00973f1f756de2931f | Ruby | tjroeder/car_dealership_2110 | /spec/dealership_spec.rb | UTF-8 | 4,524 | 3.375 | 3 | [] | no_license | require 'rspec'
require './lib/car'
require './lib/dealership'
RSpec.describe Dealership do
let(:dealership) {Dealership.new('Acme Auto', '123 Main Street')}
let(:car_1) {Car.new('Ford Mustang', 1500, 36)} # $54000
let(:car_2) {Car.new('Toyota Prius', 1000, 48)} # $48000
let(:car_3) {Car.new('Toyota Tercel', 5... | true |
24fcd95660f34f533496340e0b8facdadf465c16 | Ruby | autf/hw-sinatra-saas-hangperson | /lib/hangperson_game.rb | UTF-8 | 1,515 | 3.328125 | 3 | [] | no_license | class HangpersonGame
# add the necessary class methods, attributes, etc. here
# to make the tests in spec/hangperson_game_spec.rb pass.
# Get a word from remote "random word" service
# def initialize()
# end
def initialize(word)
@word = word.downcase
@guesses = ''
@wrong_guesses = ''
@... | true |
03e0f1341dc942bc8753b77338df0406b88c3520 | Ruby | sarahstandish/Learning-Ruby | /to_roman.rb | UTF-8 | 1,519 | 4.65625 | 5 | [] | no_license | # Method name: to_roman
# Inputs: A number
# Returns: A String representing the number in roman numerals
# Prints: Nothing
# to_roman takes a number as input and returns that number using Roman numerals
# See http://en.wikipedia.org/wiki/Roman_numerals
#from https://github.com/codeunion/ruby-exercises/... | true |
6d123994c6cf1ba657abe418d558f5eba23a2898 | Ruby | 8titi8/thp-projet-34-envoi-email-masse | /lib/app/townhalls_mailer.rb | UTF-8 | 3,074 | 3.046875 | 3 | [] | no_license | #Ce programme permet de récupérer de la data et de faire un envoi de
#mails en masse grace à google
require 'gmail' # on va chercher la gem gmail qui va nous permettre de transmettre nos messages
require 'dotenv' # permet de se servir du .env qui contient le password
require 'mail' # permet de mettre en format ht... | true |
542861480270e78226f6bec7c051e4c0adf4fcca | Ruby | PhilippePerret/Icare_AD_2018 | /_objet/admin/lib/module/operations_user/pause_module.rb | UTF-8 | 1,474 | 2.828125 | 3 | [] | no_license | # encoding: UTF-8
=begin
Pour interrompre un module d'apprentissage.
=end
class Admin
class Users
class << self
# Mise en pause d'un module d'apprentissage
#
# La mise en pause consiste à mettre le premier bit des
# options de l'icmodule à 2 (le remettre à 1 quand on redémarre)
#
def exec_pause_module
... | true |
bebc34a124b0a0ecf5f1c0fb847a18a7135103b6 | Ruby | sunrisemovement/events-map | /every_action.rb | UTF-8 | 5,327 | 2.765625 | 3 | [] | no_license | require_relative 'timeslot'
class EveryActionClient
attr_reader :api_key, :username
def initialize(api_key, username: "sunrise-movement")
# Currently default to "sunrise-movement" for the EA username, because it
# seems like this will be constant across keys, but may need to update if
# we add more ke... | true |
b60862bfae503a103cc2fc5bebea0a21328eff49 | Ruby | chestercun/projeuler | /5.rb | UTF-8 | 257 | 2.984375 | 3 | [] | no_license |
# No code for this one
# just find the minimum set of prime numbers
# that you can get products from different
# combos to get 1 to 20
# min set: 2,2,2,2,3,3,5,7,11,13,17,19
# multiply these together to get an
# answer of 232792560
puts 232792560
| true |
76a81613b0b46d315b2ad8b79c58d9fc250c0db1 | Ruby | Jacfem/phase-0 | /week-9/ruby-review-1/ruby-review.rb | UTF-8 | 3,940 | 4.46875 | 4 | [
"MIT"
] | permissive | # Create a Bingo Scorer
# I worked on this challenge with Ryan Dempsey
# I spent 3 hours on this challenge.
# Pseudocode
# input: bingo board
# output: boolean value and success/failure message
# - create a class
# -dealing with integers
# -convert to string for iteration?
# -check each row
# -iterate thro... | true |
49fb4a8882460b9da1658ebd0f35485c4ac13d41 | Ruby | hsamadi/jaxy-captcha | /lib/jaxy_captcha/generator.rb | UTF-8 | 589 | 2.75 | 3 | [] | no_license | module JaxyCaptcha
module Generator
def self.make_captcha
captcha = nil
begin
text = generate_random_text
key = Digest::SHA1.hexdigest(text + rand(100000).to_s)
captcha = JaxyCaptchaData.get_instance(key)
end while captcha.nil?
captcha.value = text
captcha.sav... | true |
ae849b3dda22cebe60bbf68b39b22b0d00b67002 | Ruby | Whatapalaver/exercism_solutions | /ruby/rna-transcription/rna_transcription.rb | UTF-8 | 248 | 3.171875 | 3 | [] | no_license | class Complement
def self.of_dna(dna_strand)
pairs = { 'A' => 'U', 'G' => 'C', 'T' => 'A', 'C' => 'G' }
complement = []
dna_strand.each_char { |nucleotide| complement << pairs.fetch(nucleotide, '') }
complement.join('')
end
end
| true |
a40eca21ecd9d4b0d77dbdf57692bac0e34cdc26 | Ruby | Duncan-Britt/Launch-School-Prep-Exercises | /The_Basics/3.rb | UTF-8 | 400 | 4.5625 | 5 | [] | no_license | # Write a program that uses a hash to store a list of movie titles with the year they came out. Then use the puts command to make your program print out the year of each movie to the screen. The output for your program should look something like this.
movie_titles = {:movie => 1975, :another => 2004, :title => 2013}
... | true |
61d7a1756ecc6890f342518461deddba0541d756 | Ruby | dennisvink/leveldb-curator | /examples/example_client.rb | UTF-8 | 892 | 2.859375 | 3 | [
"MIT"
] | permissive | require 'socket'
require 'bindata'
class Protocol < BinData::Record
endian :big
stringz :database
stringz :command_word
stringz :query_key
stringz :query_value
end
def get_answer(sock)
msg, sender = sock.recvfrom(1024)
msg
end
def send_request(sock, data)
sock.send(data, 0, "localhos... | true |
a7719a907f4d14dd5b94808faf51c52c5304fc95 | Ruby | Kukmedis/ruby-task | /turn_spec.rb | UTF-8 | 4,930 | 3.015625 | 3 | [] | no_license | require '~/ruby/turn'
require '~/ruby/table'
require '~/ruby/user'
require '~/ruby/matcher'
require 'simplecov'
SimpleCov.start
describe Turn, "when created" do
table = Table.new(5,2)
user1 = User.new("1","1","1")
user2 = User.new("2","2","2")
user3 = User.new("3","3","3")
user4 = User.new("4","4","4")
t... | true |
155b1737353648a57664aa7382a1ebda4e02bb60 | Ruby | piinkpantherpam/ruby-puppy-onl01-seng-pt-120819 | /spec/dog_spec.rb | UTF-8 | 472 | 2.609375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "spec_helper"
let!(:pluto) { Dog.new("Pluto") }
let!(:fido) { Dog.new("Fido") }
let!(:maddy) { Dog.new("Maddy") }
after(:each) do
Dog.class_variable_set(:@@all, [])
end
describe "Dog class variables" do
it "has a class variable, @@all, the points to an array" do
expect(Dog.class_variable_get(:@@all))... | true |
1794625a69a3c39e8d2fc6be84d2097a0b1b40fc | Ruby | adybas/oo-relationships-practice | /app/models/IMDB/actor.rb | UTF-8 | 327 | 2.9375 | 3 | [] | no_license | # .most_characters
# should return which actor has the most different characters played. (probably meryl streep)
class Actor
attr_reader :name
@@all = []
def initialize(name)
@name = name
@@all << self
end
def self.all
@@all
end
# def self.most_characters
# e... | true |
49aa0f1b1cccefa3804c2caf4be4f4cb87393b5e | Ruby | beenetown/Euler | /euler8.rb | UTF-8 | 1,031 | 3.703125 | 4 | [] | no_license | require_relative 'raw'
require_relative 'euler_help'
include EulerHelp
class EulerEight
def whatever(array)
sort_array = []
prod_hash = {}
array_of_arrays = []
# pushes each group of five into an array and multiplies each group together and pushes
# the array into a hash with the value of the ... | true |
4e0c8eb2c1e8609ec93ec4b81714234507ffe8f6 | Ruby | h4rr0d/tsd_utils | /lib/tsd_utils/smb.rb | UTF-8 | 1,254 | 2.703125 | 3 | [
"Apache-2.0"
] | permissive | require 'open3'
module TsdUtils
# Class resolving windows and unix paths
class SMB
class SMBReadError < StandardError
end
USER = ENV['SMB_USER']
PASSWORD = ENV['SMB_PASSWORD']
class << self
def read(path)
raise ArgumentError, 'Supply valid UNC path' unless unc?(path)
Ge... | true |
40c2092d243ce749874fe388cef714e60004ad30 | Ruby | lilhotpepper/my_ruby_programs | /week_3_exercise_4.rb | UTF-8 | 68 | 2.921875 | 3 | [] | no_license | # week_3_exercise_4.rb
a = (1930...1951).to_a
puts a[rand(a.size)]
| true |
0d1fe452d987d11f1adb2d3b215f53047442f469 | Ruby | andrewaganad/work | /lesson_4/practice_problems_2/exercise_one.rb | UTF-8 | 1,055 | 4.5 | 4 | [] | no_license | # PROBLEM:
# Given the array below, turn this array into a hash where the names are the keys
# and its positions are the values
# { 'Fred' => 0, 'Barney' => 1, 'Wilma' => 2, 'Betty' => 3, 'Pebbles' => 4,
# 'BamBam' => 5 }
# input: Array
# output: Hash
# rules:
# Explicit requirements:
# - Keys will be th... | true |
2eff662ca498750b3348423035001a75a1e530c3 | Ruby | CORE4/fulmar | /lib/fulmar/infrastructure/model/transfer/base.rb | UTF-8 | 2,035 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'fulmar/shell'
require 'digest'
module Fulmar
module Infrastructure
module Model
module Transfer
# Abstract class for all transfers, provides common methods
class Base
DEFAULT_CONFIG = {
debug: false,
user: '',
password: '',
... | true |
d0a0db2e1c65f78644794f62c4d61563aa7452fd | Ruby | briancox730/car_listing | /spec/features/user_can_add_a_new_car_spec.rb | UTF-8 | 2,605 | 2.8125 | 3 | [] | no_license | require 'rails_helper'
feature 'user adds a new car' do
# As a car salesperson
# I want to record a newly acquired car
# So that I can list it in my lots of cars found in the lot
# I must specify the manufacturer, color, year, and mileage of the car.
# Only years from 1920 and above can be specified.
# I... | true |
6ae76bf2d580e58e536d8a4e9c877e0d7099806a | Ruby | webdev1001/flashcardr | /db/seeds.rb | UTF-8 | 843 | 2.625 | 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 rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
e8cb85d2b7e68eb1fa6e14fed5082273b84c52d8 | Ruby | santoshkosgi/Desktop-files | /inter.rb | UTF-8 | 508 | 3.21875 | 3 | [] | no_license | a= Array.new
j=0,x=0,v=0,k=0,s=0,c=0,i=0
z= gets.split(" ")
b = gets.split(" ")
z.collect! {|i| i.to_i}
b.collect! {|i| i.to_i}
i=1
while i<z[1] do
if(z[1]%i == 0)
if(j!=0 && a[j-1] == i)
break
end
if(z[1]/i == i)
x=1
v=i
else
a[j] = i
j=j+1
a[j] = z[1]/i
j=j+... | true |
b669e0c95b48a2ee66b5d14b86aea4626e7c7dda | Ruby | bleavitt92/RB-130-Ruby-Foundations | /ruby_challenges/medium1/pig_latin.1.rb | UTF-8 | 542 | 3.375 | 3 | [] | no_license | class PigLatin
VOWELS = %w(a e i o u)
def self.translate(string)
converted_words = string.split.map do |word|
translate_word(word)
end
converted_words.join(' ')
end
def self.translate_word(word)
if start_with_vowel_sound(word)
word.concat('ay')
else
split(word)
end
... | true |
2951d2539d901b2c981cfc552cbb3bd187ed259c | Ruby | ChandraNalaani/Ruby | /pi-calculator/pi_calculator.rb | UTF-8 | 516 | 3.109375 | 3 | [] | no_license | class PiCalculator
def calculate
square_area = 1
points_in_circle = 0
num_points = 100000
origin = {:x => 0.5, :y => 0.5}
num_points.times do
point = {:x => rand, :y => rand}
distance = Math.sqrt((point[:x] - origin[:x])**2 + (point[:y] - origin[:y])**2)
... | true |
2e76fd28f5336e6f025d500c86155f7df6139777 | Ruby | catepillar/tyrant_card_creator | /tools/image_extractor.rb | UTF-8 | 2,342 | 2.5625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'nokogiri'
require 'open-uri'
# chdir allows this to work from anywhere.
Dir.chdir(File.dirname(__FILE__))
# might need to be changed by other users.
image_directory = "../html/images"
Dir.mkdir(image_directory) unless Dir.exists? image_directory
# get the newest cards xml file.
n = Noko... | true |
5447c50a32dcbb214ffbfb3baef189d9f3cd07d1 | Ruby | sagemlee/monster_shop_2003 | /app/models/merchant.rb | UTF-8 | 813 | 2.515625 | 3 | [] | no_license | class Merchant <ApplicationRecord
has_many :users, dependent: :destroy
has_many :items, dependent: :destroy
has_many :item_orders, through: :items
validates_presence_of :name,
:address,
:city,
:state,
:zip,
... | true |
a3800ebfc04734a71cce7dc2624dec7cd8c4f5b8 | Ruby | a-maas/deck_of_cards | /card.rb | UTF-8 | 486 | 3.390625 | 3 | [] | no_license | class Card
include Comparable
attr_reader :rank, :suit, :value
def initialize rank, suit, value
@rank = rank
@suit = suit
@value = value
end
def red?
( %w{Hearts Diamonds}.include? @suit ) ? true : false
end
def face_card?
( %w{J Q K}.include? @rank ) ? true : false
end
def ... | true |
7c82a134e2584c0ff89c4fd1c6f42119e840070f | Ruby | ahotchkin/dynamic-orms-readme-v-000 | /bin/run | UTF-8 | 678 | 2.90625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | #!/usr/bin/env ruby
require 'sqlite3'
require_relative "../lib/song.rb"
require_relative "../config/environment.rb"
song = Song.new(name: "Hello", album: "25")
puts "song name: " + song.name
puts "song album: " + song.album
song.save
song = Song.new(name: "22", album: "Red")
puts "song name: " + song.name
puts "son... | true |
8d33431c1c589ce5163bd3fb47f7201f0fbd68f1 | Ruby | sarahemm/ruby-fstui | /lib/fstui/menu.rb | UTF-8 | 1,459 | 3.03125 | 3 | [
"MIT"
] | permissive | module FSTui
class Menu
attr_accessor :title
def initialize(screen, title, subtitle)
@title = title
@subtitle = subtitle
@items = Array.new
@screen = screen
end
def add_item(key, desc)
@items.push MenuItem.new(key, desc)
end
def get_response
loop d... | true |
2b2541db2fcb33a92f2148d169e5c6c41aafacd3 | Ruby | Spherehunt/mqtt-chat | /app.rb | UTF-8 | 476 | 3.078125 | 3 | [] | no_license | require 'rubygems'
require 'mqtt'
puts "Input name please."
@name = gets.chomp
Thread.new do
# Publish example
puts "enter message"
@text = gets.chomp
MQTT::Client.connect('10.177.33.144') do |c|
c.publish('BABL', @name+ ': ' + @text)
end
end
# Subscribe example
MQTT::Client.connect('10.177.33.144')... | true |
8c58640064bf9a55dd04d1f2071ec480f40527a4 | Ruby | kixton/rock-paper-scissors-app | /db/migrate/20141001194816_games.rb | UTF-8 | 913 | 2.71875 | 3 | [] | no_license | class Games < ActiveRecord::Migration
def change
create_table :games do |col|
# has game.id
col.belongs_to :tourney
col.integer :round
col.belongs_to :player1
col.belongs_to :player2
col.string :p1move
col.string :p2move
col.belongs_to :winner
end
... | true |
35aabf1eb9eb44627d605b1d6c13d65ca12020bc | Ruby | M45t3rJ4ck/Ruby | /PyStudent - Copy/ListMe.rb | UTF-8 | 164 | 3.390625 | 3 | [] | no_license | listMe = []
for item in (0..4)
print ("Please enter any item: ")
u_in = gets.chomp.to_s
listMe.append(u_in)
end
puts ("Your list items are: #{listMe}")
| true |
b248ecac123f36114520acfc954e92e81a12fa2a | Ruby | ne006/ruby_practice | /sequel/sequel_test.rb | UTF-8 | 723 | 2.9375 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'sequel'
DB = Sequel.connect("postgres://postgres:postgres@localhost/ruby_practice")
contact = DB[:contact]
print_row = Proc.new do |row|
row.each_value do |col|
print "#{col} "
end
puts
end
puts "Initial select"
contact.each &print_row
puts "Conditional select with column orde... | true |
6416ef6678cd1c866ea79455e3c0a343c78c50ff | Ruby | UmaHani/kwk-l1-ruby-object-attributes-lab-kwk-students-l1-chi-080618 | /lib/dog.rb | UTF-8 | 52 | 2.53125 | 3 | [] | no_license | # dog.rb
class Dog(name)
@name = name
end
end | true |
410f12c831b2c1926d4a3530fa5dcc4a395aa8a9 | Ruby | juan-gm/ruby_basics | /opposites.rb | UTF-8 | 743 | 4 | 4 | [] | no_license | def valid_number?(number_string)
number_string.to_i.to_s == number_string && number_string.to_i != 0
end
first = nil
second = nil
loop do
loop do
puts ">> Enter an integer"
first = gets.chomp
if !valid_number?(first)
puts "Invalid input. Only non-zero integers are allowed"
next
end
... | true |
d119411beaadba22b0f04427cf8f1109e52aebe9 | Ruby | oscardydx/ruby_promociones | /Promocion.rb | UTF-8 | 511 | 3.15625 | 3 | [] | no_license | class Promocion
attr_accessor :cantidad_en_promocion
attr_accessor :fecha_vigencia
attr_accessor :cantidad_minima
attr_accessor :precio_minimo
def initialize (x)
@cantidad_en_promocion=x;
end
def set_cantidad_en_promocion ()
puts @cantidad_en_promocion;
end
def set_fecha_vigencia ()
puts @fecha_vigen... | true |
3dc1d2bb4fbdd928f2f820cc95a4b8eb07a8caba | Ruby | mikkorantalainen/html5lib | /ruby/lib/html5/filters/validator.rb | UTF-8 | 33,127 | 2.59375 | 3 | [
"MIT"
] | permissive | # HTML 5 conformance checker
#
# Warning: this module is experimental, incomplete, and subject to removal at any time.
#
# Usage:
# >>> from html5lib.html5parser import HTMLParser
# >>> from html5lib.filters.validator import HTMLConformanceChecker
# >>> p = HTMLParser(tokenizer=HTMLConformanceChecker)
# >>> p.parse('... | true |
d00a16473a4016d8dbd3114c7d37c39a4136c155 | Ruby | mindaslab/ilrx | /struct_wrong.rb | UTF-8 | 197 | 3.546875 | 4 | [] | no_license | # struct_wrong.rb
person = Struct.new :name, :age
p = person.new
p.name = "Karthik"
p.age = 30
p.profession = "Engineer"
puts "Hello, I am #{p.name}, age #{p.age}, and I am on a #{p.profession}"
| true |
5db81f17f0945e4e6833762b30b448031816ede7 | Ruby | macroexpanse/ttt-rb | /lib/game_state.rb | UTF-8 | 724 | 3.546875 | 4 | [] | no_license | class GameState
attr_reader :board, :human_player, :ai_player, :turn, :rules
def initialize(args)
@board = args[:board]
@ai_player = args[:ai_player]
@human_player = args[:human_player]
@rules = args[:rules]
@turn = Integer(args[:turn])
end
def fill_cell(id, value)
board.fill_cell(id, ... | true |
c907d54af60179ab44f654144326a446e23251bf | Ruby | thedeeno/synchrony | /spec/synchrony/models/employee_spec.rb | UTF-8 | 1,349 | 2.75 | 3 | [] | no_license | module Synchrony
describe Employee do
describe "#carrying?" do
it "returns true when possesses containers" do
e = Employee.create
e.containers << Container.create
expect(e).to be_carrying
end
it "returns false when no possessions" do
e = Employee.create
ex... | true |
01ca94c3b2b29ffe3e6aee694e7f0ae456f36dd9 | Ruby | ninachen99/problems | /AlphabetSoup.rb | UTF-8 | 561 | 4.21875 | 4 | [] | no_license | #Using the Ruby language, have the function AlphabetSoup(str) take the str string parameter being passed
#and return the string with the letters in alphabetical order (ie. hello becomes ehllo).
#Assume numbers and punctuation symbols will not be included in the string.
def AlphabetSoup(str)
if str =~ /[a-zA-Z]/
... | true |
f2b419315c59e437179548dcd4c7f8e9c937606f | Ruby | maxvia/Introduction_to_Programming | /Hashes/hashes_ex6.rb | UTF-8 | 974 | 3.796875 | 4 | [] | no_license | # anagrams
words = ['demo', 'none', 'tied', 'evil', 'dome', 'mode', 'live',
'fowl', 'veil', 'wolf', 'diet', 'vile', 'edit', 'tide',
'flow', 'neon']
def anagram?(word1, word2)
if word1.split(//).sort == word2.split(//).sort
return true
else
return false
end
end
anagrams = []
used = ... | true |
f107c1c25a7035fd6a90620ee8965663b2e758e7 | Ruby | stephenolson/reverse-each-word-v-000 | /reverse_each_word.rb | UTF-8 | 337 | 3.53125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reverse_each_word(sentence)
array = sentence.split(" ")
new_array = [ ]
array.each do |words|
new_array << words.reverse
end
new_array.join(" ")
end
def reverse_each_word(sentence)
array = sentence.split(" ")
new_array = [ ]
array.collect do |words|
new_array << words.reverse
end
new_ar... | true |
f8c55fc3488a5770236dc481ad7986826c851c3c | Ruby | aflatune/Aflatune2 | /config/initializers/string_utils.rb | UTF-8 | 112 | 2.640625 | 3 | [] | no_license | class String
def to_slug
self.to_ascii.downcase.gsub(/[^a-z0-9 ]/, ' ').strip.gsub(/[ ]+/, '-')
end
end
| true |
a8e77505ae1250ada38e03ec4dbc59fcee1b9f15 | Ruby | jhnnyk/ttt-with-ai-project-cb-000 | /bin/tictactoe | UTF-8 | 933 | 3.578125 | 4 | [] | no_license | #!/usr/bin/env ruby
require_relative '../config/environment'
puts ""
puts "-----------------------"
puts "Welcome to Tic Tac Toe!"
puts "-----------------------"
puts ""
game_type = nil
loop do
puts "Would you like to play a 0, 1, or 2 player game?"
game_type = gets.strip
break if game_type == "0" || game_typ... | true |
be94f49dc41ace570a04f0e078a8937bde6f50ca | Ruby | nadiaivannova/object_oriented_programming-2 | /people.rb | UTF-8 | 456 | 4.0625 | 4 | [] | no_license | class Person
attr_accessor :name
def initialize(name)
@name = name
end
def greeting
puts "Hi, my name is #{@name}"
end
end
class Instructor < Person
def teach
puts "Everything in Ruby is an Object"
end
end
class Student < Person
def learn
puts "I get it!"
end
end
i = Instructo... | true |
6c20e84c4e38f1de11de653e0f41f28f504af180 | Ruby | lucignolo/events1617 | /ugoRUNRicalcolaANNOMODIFICA.rb | UTF-8 | 4,787 | 2.859375 | 3 | [] | no_license | #!/usr/local/bin/ruby
require "./ugoLib/ugorunnerXUtil01.rb"
mioScript = "ugoRUNRicalcolaANNOMODIFICA.rb"
intestazione = "#{mioScript} - 08/09/2017: in books, ricalcola annomodifica per AI16"
puts intestazione
pippo = Konta.new(intestazione,"0")
def mostraSpiegazioni()
spiega = <<END_OF_STRING
\nAccede in LETTURA e S... | true |
ab0106941f66340f70c0f42def915be7f7b66718 | Ruby | Jaaga/VideoVolunteer-Ruby | /lib/forms.rb | UTF-8 | 13,969 | 2.78125 | 3 | [] | no_license | # Form generators for forms and showing database tables.
module Forms
# For displaying a tracker's information in get /show/:uid
def show(track, columns)
columns.map do |x|
value = track.send(:"#{ x }")
if x.include?("_date") && !value.blank?
"<tr><td class = 'show-head'>#{ name_modifier(x)... | true |
4d51a09e13aa44ccdea86c70b442a6f2c988ec13 | Ruby | rajcybage/google_book | /lib/google_book/book_item.rb | UTF-8 | 3,508 | 2.859375 | 3 | [
"MIT"
] | permissive | require_relative 'base.rb'
class BookItem
attr_reader :item
def initialize(item)
@item = item
end
# get the title of the book
def get_title
@item[:item]["volumeInfo"]["title"]
end
#get the sub title of the book
def get_sub_title
@item[:item]["volumeInfo"]["subtitle"]
end
#the author... | true |
7f73713bad82decb2f5dd6ca6ea4d182861e822d | Ruby | Jake0Miller/time-complexity | /test/duplicate_elements_test.rb | UTF-8 | 1,205 | 2.875 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require 'pry'
require './lib/duplicate_elements'
class DuplicateElementsTest < Minitest::Test
def setup
@small = DuplicateElements.new(100)
@mid = DuplicateElements.new(10_000)
@large = DuplicateElements.new(1_000_000)
end
def test_uniq_finds_num_d... | true |
488c86a0e6d120859116e54164fed720c3ada2a9 | Ruby | mzch/CSL_packunpack | /packunpack.rb | UTF-8 | 15,962 | 2.578125 | 3 | [] | no_license | # coding: utf-8
require 'optparse'
require 'pp'
Version = "1.1"
class SkylinesLocale
def initialize(file, opt)
@path = file
# Struct::Data (実データ用)
# name: String|Integer|nil (ポインタを指している場合は数値)
# index: Integer|nil
# key: String|Integer|nil (ポインタを指している場合は数値)
# value: String|In... | true |
ef7c65286facc1cf5ebf2df17c0ecdd628c68660 | Ruby | mwong068/data-structures-and-algorithms | /problems/easy/last_word.rb | UTF-8 | 818 | 4.75 | 5 | [] | no_license | # Given a string s consisting of some words separated by some number of spaces, return the length of the last word in the string.
# A word is a maximal substring consisting of non-space characters only.
# Example 1:
# Input: s = "Hello World"
# Output: 5
# Explanation: The last word is "World" with length 5.
# Examp... | true |
1ebe12c1de01de5b49974b4d43f1812622a1ffd2 | Ruby | nigelfloe/our-checkered-past | /app/models/louis.rb | UTF-8 | 1,969 | 3.265625 | 3 | [
"MIT"
] | permissive | class Louis
attr_accessor :player
P1 = 0
LOUIS = 1
P1_GUARD_ROW = 7
LOUIS_GUARD_ROW = 0
OFF_SQUARE = "-1"
EMPTY_SQUARE = "0"
P1_PIECE = "1"
LOUIS_PIECE = "2"
P1_KING = "3"
LOUIS_KING = "4"
def evaluate_board(board_state, player)
current_state = board_state.flatten
p1_pieces = current_... | true |
eb9e0547a409a5a892daab8bcb9a59e3fdb17341 | Ruby | ctaintor/tech-radar | /transform.rb | UTF-8 | 3,928 | 3.09375 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
require "csv"
require "json"
require "liquid"
class Hash
def remap(hash={})
each {|k, v| yield hash, k, v}
hash
end
end
ARCS = [
{name: 'ADOPT', r: 130},
{name: 'TRIAL', r: 220},
{name: 'ASSESS', r: 310},
{name: 'HOLD', r: 400}
]
class Layout
OFFSET = {
'Pla... | true |
96af4bcfdf1f2847a533292f133ebb119b323efc | Ruby | sabotatore/omniauth-untappd | /lib/oauth2/untappd_client.rb | UTF-8 | 715 | 2.5625 | 3 | [
"MIT"
] | permissive | module OAuth2
class UntappdClient < OAuth2::Client
def get_token(params, access_token_opts = {}, access_token_class = AccessToken)
response = request(options[:token_method], token_url, request_token_opts(params))
access_token_class.new(self, parse_token(response), access_token_opts)
end
priva... | true |
01abc175b912ba72ed9590967dce964c5f1956c8 | Ruby | jonathansayer/MVP_battleships | /spec/board_spec.rb | UTF-8 | 1,186 | 2.921875 | 3 | [] | no_license | require 'board'
describe Board do
it{ is_expected.to respond_to :place }
it 'can have a ship' do
ship = double :ship, position: "A1"
expect(subject.place(ship).length).to eq 1
end
it 'reports missed hit when no ship at position' do
expect(subject.strike "A1").to eq :miss
end
it 'can receive... | true |
34d31e5b9503dbf4008a0e2c8911a3ad4e15aba4 | Ruby | cbh808/RB120 | /RB120_OOP_exercises/OO_Basics_Classes_Objects2/public_secret.rb | UTF-8 | 453 | 4.46875 | 4 | [] | no_license | =begin
Using the following code, create a class named Person with
an instance variable named @secret. Use a setter method to
add a value to @secret, then use a getter method to print
@secret.
=end
class Person
attr_accessor :secret
end
person1 = Person.new
person1.secret = 'Shh.. this is a secret!'
puts person1.... | true |
a9e9d5043ffb9f6c435ce9dd97651e0613ee335d | Ruby | yielding/code | /ruby/macruby/flower.rb | UTF-8 | 1,807 | 2.9375 | 3 | [] | no_license | require 'hotcocoa/graphics'
include HotCocoa
include Graphics
# initialize canvas
canvas = Canvas.new :type => :image, :filename => 'particles.png', :size => [400,400]
canvas.background(Color.black)
# load images and grab colors
img = Image.new('Ballerina3.jpg').saturation(1.9)
redcolors = img.colors(100)
img = Image... | true |
9a9004a74a6fad1096f829aece8b04aa395b5116 | Ruby | voidsatisfaction/Project-Euler-in-Ruby | /121.rb | UTF-8 | 566 | 3.734375 | 4 | [] | no_license | # Ruby
=begin
Get the all posibilities player lose(using combination)
Then, get the winning rate of player for this game
Get maximum prize
=end
class Problem121
def self.find_ans
total_lose = 0
8.upto(15) do |lose|
total_lose += (1..15).to_a.combination(lose).to_a.map{ |e| e.reduce(:*) }.reduce(:+... | true |
0c652d0666614326d9488de62f47355734a3ebf9 | Ruby | slicksammy/food | /app/models/package.rb | UTF-8 | 990 | 2.765625 | 3 | [] | no_license | require 'uuid_helper'
class Package < ActiveRecord::Base
include UUIDHelper
serialize :products, Array
scope :active, -> { where(active: [nil, true]) }
validates :package_name, presence: true
def add_product(product, amount)
if has_product?(product)
update_amount(product, amount)
else
... | true |
a87b70f90544b8e81d2b478f64d92062a17af0b6 | Ruby | woodruffw/snippets | /reorient/reorient | UTF-8 | 1,436 | 2.734375 | 3 | [
"LicenseRef-scancode-proprietary-license",
"MIT"
] | permissive | #!/usr/bin/env ruby
# frozen_string_literal: true
# reorient: extract and remove orientation tags from images while rotating
require "json"
require "open3"
ORIENTATION_MAP = {
2 => %w[-flip horizontal],
3 => %w[-rotate 180],
4 => %w[-flip vertical],
5 => %w[-transpose],
6 => %w[-rotate 90],
7 => %w[-tran... | true |
4c9eb84537bbaf6d6f42d7d47429c4938985f9f9 | Ruby | jonathlan/proxyformatter | /spec/formatter_spec.rb | UTF-8 | 2,109 | 2.984375 | 3 | [] | no_license | require 'rspec'
require_relative '../Formatter.rb'
describe Formatter do
target = "https://sampleapis.com/countries/api/countries"
faiulre_target = ""
before {
path = "/formatr/https://sampleapis.com/countries/api/countries"
@formatter = Formatter.new(path)
}
#Specification... | true |
79d765be8c8b415f01ff19fe50893bb106f7148d | Ruby | Umnums/ruby-music-library-cli-online-web-sp-000 | /lib/music_importer.rb | UTF-8 | 378 | 2.921875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class MusicImporter
attr_accessor :path
def initialize(path)
@path = path
end
def files
path = @path + "/*.mp3"
@array = []
all = Dir[path]
all.each do |song|
@array << song.split("mp3s/")[1]
end
@array
end
def import
self.files
@array.each {|file| Song.create_fro... | true |
7e3b9e732457db2bb61a767c22440d15621eeb48 | Ruby | hkeefer18/RB101-and-Small-Problems | /small_problems/easy_5/10.rb | UTF-8 | 2,519 | 3.9375 | 4 | [] | no_license | =begin
Method takes a string and prints that string within a box
Explicit input
string
Implicit Input
string size
Algorithm
Five puts lines
1) +-(-*string.size)-+
2) | ( *string.size) |
3) | string |
4) same as 2
5) same as 1
=end
def print_in_box(string)
puts "+-#{'-' * string.size}-+"
puts "| #{' ' * str... | true |
c4f0fe05539cf26e4f6ed9f40ec885c5060635b9 | Ruby | pdandrey/LegendCC | /db/seeds.rb | UTF-8 | 8,082 | 2.796875 | 3 | [
"MIT"
] | permissive | # 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 rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
565a31982a26f4c85367aaaba79ef0ea3d4b5950 | Ruby | okinawa0721/lesson.6-1.rb | /lesson.6-1.rb | UTF-8 | 1,116 | 3.890625 | 4 | [] | no_license | class Shape
attr_accessor :color
protected :color=
def initialize(color)
@color = color
end
def color_change(shape)
if shape.is_a?(Shape) == true
@color,shape.color = shape.color,@color
end
end
def display_area
puts "色は#{@color}面積は#{@area}です。"
... | true |
26b52b2fa2bcd13429622fde2a6450fc3892a778 | Ruby | isabella232/rv-predict | /external/bsd/elftoolchain/test/tet/tet3.8/contrib/ruby_api/rbtet_demo/tests/tc2 | UTF-8 | 1,200 | 2.703125 | 3 | [
"Artistic-1.0",
"LicenseRef-scancode-warranty-disclaimer",
"BSD-3-Clause"
] | permissive | #!/usr/bin/env ruby
require "Rbtet"
class TestSet < Rbtet::SuperTestSet
@@testlist = Hash[1,"test1", 2,"test2", 3,"test3"]
def test1()
begin
var = Rbtet.tet_getvar("RBTET_TC2_VAR")
rescue
Rbtet.tet_infoline("Failed to get a value for RBTET_TC2_VAR")
Rbtet.... | true |
da7698cd684a4a77faef77deb21f6bf065b0bd38 | Ruby | EwenFin/pet_shop | /week_01/day_4/friends_solution/friends.rb | UTF-8 | 1,808 | 3.3125 | 3 | [] | no_license | def add_friend(name, person)
person[:friends] << name
end
def remove_friend(name, person)
result = nil
for friend in person[:friends]
result = friend if friend == name
end
if result != nil
person[:friends].delete(result)
end
end
def favourite_tv_show(person)
return person[:favourites][:tv_sho... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.