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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
727a3d32a7e65e72a48fbb8e4c65667c72e886cc | Ruby | Michael3434/fullstack-challenges | /02-OOP/05-Food-Delivery-Day-One/01-Food-Delivery/app/controllers/meal_controller.rb | UTF-8 | 508 | 2.6875 | 3 | [] | no_license |
class MealController
attr_reader :meal_repo
def initialize(meal_repo)
@meal_repo = meal_repo
@view = MealView.new
end
def list_meals
meals = @meal_repo.meals
@view.display_meals(meals)
end
def add_meal
name = @view.ask_for_name_meal
price = @view.ask_for_price_meal
new_meal ... | true |
254ec0d842003bcef93d6ffd27507fb0fa0da1de | Ruby | idegn/playground | /euler/55.rb | UTF-8 | 333 | 3.359375 | 3 | [] | no_license | class Integer
def reverse_add
self + self.to_s.reverse.to_i
end
def palindromic?
self.to_s == self.to_s.reverse
end
def lychrel?
num = self
50.times do
num = num.reverse_add
return false if num.palindromic?
end
true
end
end
N = 10000
p (1...N).select { |i| i.lych... | true |
a35831bb2acc09cd9374ed60d6316956b0025f28 | Ruby | salex/take | /lib/take/render_helper.rb | UTF-8 | 8,896 | 2.671875 | 3 | [
"MIT"
] | permissive | module Take
class AssessmentRenderer
def initialize(assmnt, post, template)
@assmnt = assmnt
@post = post
@template = template
end
def render_assessment
result = <<-HERE
<div id="take">
#{h_make_instruction(@assmnt["instructions"])}
<div class="take-questi... | true |
eaf5d5351198c44c51d545dd44260c2022c1710f | Ruby | notnotdrew/student-scrape | /index-scrape.rb | UTF-8 | 1,290 | 3.265625 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
require 'pry'
# link posts.search("div.blog-title a").attr("href").value
# name posts.search("div.blog-title a").text
# tagline posts.search("p.home-blog-post-meta").text
# excerpt posts.search("div.excerpt").text
# photo posts.search("div.blog-thumb a img").attr('src').value
class... | true |
aeb87fb5ac8fd965a0322bc3499c78b2eb2b732a | Ruby | 40grivenprog/homeworks | /HW_04/Egor_Alekseychik/egor_alekseychik_hw_04_t_02.rb | UTF-8 | 930 | 2.921875 | 3 | [] | no_license | require 'yaml'
def task_4_2(input)
return {} if input.empty?
hash = YAML.safe_load(input)
remove_n_add(hash)
array = []
hash.each do |key, value|
buffhash = {}
buffhash[key] = value
array << buffhash
end
array
end
def remove_n_add(bighash)
changekeys(bighash)
bighash.map do |_, value|
... | true |
ab3fb3ab85015ac9cd2981dc5871d6b5e9b79f9e | Ruby | chipojaya1/ruby--task1 | /janken.rb | UTF-8 | 4,514 | 4.28125 | 4 | [] | no_license |
require "byebug"
# Write the logic to let the player (self) input "0 ~ 2".
class Player
def hand
# Display “Sentence that allows the player to enter 0 to 2”.
puts " Please enter a number. "
puts " 0: goo, 1: joki, 2: par "
# Get the value entered by the player in the variable "input_han... | true |
6417e3d898703f69341ce9b217a36287ee3ec647 | Ruby | Projamming/Practice | /lilgoody/1000miles_intro.rb | UTF-8 | 2,360 | 2.9375 | 3 | [] | no_license | # TITLE: A Thousand Miles intro (Vanessa Carlton)
# FILE: 1000miles_intro.rb
# AUTHOR: lilgoody
# DATE: 8/30/18
# DESC: Attempt to recreate the well-known intro to Vanessa Carlton's A Thousand Miles
use_bpm 95
use_synth :piano
#piano sounds most like the original, but lacks the ability to sustain the note
#another sy... | true |
632d1574af6589e3e13295ed91f8edb11244783a | Ruby | mrYakamoto/phase-0 | /week-5/die-class/my_solution.rb | UTF-8 | 2,184 | 4.15625 | 4 | [
"MIT"
] | permissive | # Die Class 1: Numeric
# I worked on this challenge by myself.
# I spent .5 hours on this challenge.
# 0. Pseudocode
# Input: object initialization and number of sides
# Output: object of class 'Die'
# Steps:
# Create class 'Die'
# have initialize take one parameter for number of sides
# create method inside 'Die'... | true |
c0c3efe503a10ca663c32e750accb9ac2351461e | Ruby | giathang/demo_ruby | /cerealBox.rb | UTF-8 | 520 | 3.578125 | 4 | [] | no_license | class CerealBox
def initialize(ounces,contains_toy)
@ounces = ounces
@contains_toy = contains_toy
end
def self.from_s(s)
ounces = 0
contains_toy = false
s.each_line do |field|
value = field.split(":")[1].strip
ounces = value.to_i if field.include?("ounces")
contains_toy = to_boolean(value) if fi... | true |
f270e1bb38a28f061cfe68a0c4dafa04cdec1138 | Ruby | mohammadaliawan/launch_school_RB101 | /small_problems_3/easy_5/letter_counter_2.rb | UTF-8 | 2,557 | 4.4375 | 4 | [] | no_license | =begin
Write a method that takes a string with one or more space separated words and returns a hash that
shows the number of words of different sizes. Exclude non-letters when determining word size.
Words consist of any string of characters that do not include a space.
For instance, the length of "it's" is 3, not 4.
... | true |
1a13be5679a878002474b76ed0e6ad58d7cc9302 | Ruby | KevinMcHugh/ubiquitous-invention | /policy.rb | UTF-8 | 576 | 3.28125 | 3 | [] | no_license | class Policy
attr_reader :subject, :consequence
def initialize(world)
@subject = world.species.sample
@consequence = Consequence.all.sample
end
def inspect
"#{subject.inspect} => #{consequence.inspect}"
end
end
class Consequence
def self.all
[new(:death, 100), new(:imprisonment, 75), new(... | true |
c8c03e8db1c4b9526e315088bb145de95b85a0e1 | Ruby | CSC-440-Sp2017-NKU/team-project-the-borne-collective | /app/helpers/users_helper.rb | UTF-8 | 1,229 | 2.578125 | 3 | [] | no_license | module UsersHelper
# Returns the Gravatar for the given user.
def gravatar_for(user, size: 80, img_class: "gravatar")
gravatar_id = Digest::MD5::hexdigest(user.email.downcase)
gravatar_url = "https://secure.gravatar.com/avatar/#{gravatar_id}?s=#{size}"
image_tag(gravatar_url, alt: user.name, class: img... | true |
58744147ba493a9afe6d511f2732f838137cca92 | Ruby | MaxMillington/sales_engine | /lib/merchant.rb | UTF-8 | 1,648 | 2.9375 | 3 | [] | no_license | require 'bigdecimal'
require 'bigdecimal/util'
class Merchant
attr_reader :id,
:name,
:created_at,
:updated_at,
:repository
def initialize(data, repository)
@id = data['id']
@name = data['name']
@created_at = data['created_at']
@updated_at =... | true |
133f7f0003987abd3adfbef55bb002967ae141a8 | Ruby | kat3185/green-door-twilio-final | /spec/models/game_spec.rb | UTF-8 | 904 | 2.734375 | 3 | [] | no_license | require 'spec_helper'
describe Game do
describe "#new" do
let!(:game) { Game.new(title: "Instant Human, Just Add Coffee", url: "http://www.yep.com", short_title: "caffiene")}
it "is a game object with a title, url and short title" do
expect(game.title).to eq("Instant Human, Just Add Coffee")
exp... | true |
160c8104048bf9769c804d3a9c5ea170338da1b9 | Ruby | Brian-Triplett/tts_wilmington | /samples/yield.rb | UTF-8 | 206 | 3.703125 | 4 | [] | no_license | def passive_method(&block)
puts "At the start of the method"
block.call(5) if block_given?
puts "At the end of the method"
yield 8 if block_given?
end
passive_method {|s| puts "I'm in a #{s} block!"}
| true |
f9014406404321b0ea3b1af237038b8abdbf8d28 | Ruby | andrefisch/RubyScripts | /angleBetweenHands.rb | UTF-8 | 492 | 4 | 4 | [] | no_license | def angleBetweenHands(hours, minutes)
# Make sure we mod 360 both angles so we end up with 0 instead of 360 for 12 hours and 60 minutes
minuteAngle = (minutes * 6) % 360
hourAngle = (hours * 30 + minutes / 2) % 360
puts "angle of hour hand at #{hours} hours is #{hourAngle}"
puts "angle of minute han... | true |
446ff636addcc54c2698631c84014ce28b7daab2 | Ruby | tett23/rahmen | /lib/rahmen/camera.rb | UTF-8 | 552 | 2.625 | 3 | [] | no_license | module Rahmen
class Camera
def initialize(out_dir='./out')
@out_dir = out_dir
end
attr_reader :out_dir
def capture(out_path=nil)
out_path = default_out_path if out_path.blank?
capture = ::OpenCV::CvCapture.open
mat = capture.query.to_CvMat
mat.save(out_path)
out_... | true |
91a85527e39cad46843d2f88743281496a86210d | Ruby | sebastienrombaut/movies | /app/services/search_movie.rb | UTF-8 | 582 | 2.984375 | 3 | [] | no_license | # Appelle la gem dotenv
require 'dotenv'
require 'themoviedb'
# Ceci appelle le fichier .env grâce à la gem dotenv, et enregistre toutes les données enregistrées dans une hash ENV
Dotenv.load
class SearchMovie
attr_accessor :title
def initialize(research)
@title = research
end
def perform
login
research
... | true |
334f5637a285d9354279786562cbaee9a758df44 | Ruby | GersonRevatta/project-euler | /1.rb | UTF-8 | 88 | 3.375 | 3 | [] | no_license | s = 0
for i in 1..999 do
if i % 3 == 0 or i % 5 == 0
s = s + i
end
end
puts(s)
| true |
dee2e713b9ddc04674ec5136475d257d21266f1b | Ruby | TCarter3/casino-project | /wallet.rb | UTF-8 | 206 | 2.71875 | 3 | [] | no_license |
require 'pry'
require 'colorize'
require 'sounder'
class Wallet
attr_accessor :amount
def initialize
# random generation of contents from $1 to $1000
@amount = rand(1000) + 1
end
end | true |
9653bcd488249b45d8b5e597a86bcbe1c1c5cc54 | Ruby | UCSF-MS-DCC/project-submissions | /app/controllers/predss_controller.rb | UTF-8 | 11,543 | 2.65625 | 3 | [] | no_license | class PredssController < ApplicationController
=begin
In brief:
CONTROLLER Validate APIKey exists
CONTROLLER Attempt to retrieve redcap dataset from API using APIKey
CONTROLLER If no dataset, return error
CONTROLLER If dataset:
CONTROLLER use mapping from redcap variables to predss variables to create... | true |
d4f32acb5fb7b1913b8801f73c7b177303cc2d91 | Ruby | andrewfader/Tetronimo | /game_window.rb | UTF-8 | 1,535 | 2.90625 | 3 | [] | no_license | require 'rubygems'
require 'gosu'
require './piece'
class GameWindow < Gosu::Window
attr_accessor :piece
def initialize
super 1024, 960, false, 48
self.caption = "Tetronimo"
@background_image = Gosu::Image.new(self, "bg.png", true)
@menu = Gosu::Image.new(self, "menu.png", true)
@game_start = f... | true |
d1ce255b18985b5181bd28b54101169693477c1c | Ruby | ozyborg/advent-of-code | /2021/day-20/part-01.rb | UTF-8 | 974 | 3.078125 | 3 | [] | no_license | def process(data)
alg, image = data
min_x, max_x = image.keys.map(&:first).minmax
min_y, max_y = image.keys.map(&:last).minmax
deltas = [
[-1, -1], [-1, 0], [-1, 1],
[0, -1], [0, 0], [0, 1],
[1, -1], [1, 0], [1, 1]
]
2.times do |i|
min_x, max_x = min_x - 1, max_x + 1
min_y, max_y = mi... | true |
7babb6b68d7f84d94d06dd23a4218ac3b776f17f | Ruby | igordeoliveirasa/genetics | /main.rb | UTF-8 | 925 | 3.640625 | 4 | [] | no_license |
class ChromossomesRandomizer
def initialize(genes_count, seed = Random.new_seed)
srand seed
@genes_count = genes_count
end
def create
Array.new(@genes_count).map { |item| rand.round(2) }
end
end
class BeingFactory
def self.build(chromossomes_randomizer)
Being.new(chromossomes_randomizer.cr... | true |
cd3215d71eb08785c795d4d633f283fce138b120 | Ruby | businessph/rubyfundamentaltraining | /rubyfundamentals/examples/a10-entire-application-saving-data/music_database_application.rb | UTF-8 | 3,964 | 4.25 | 4 | [] | no_license | ### an entire application including saving data
### require external yaml file
puts "Required built-in module returned: #{require 'yaml'}"
###global array equals create new array
$album_array = Array.new
###global fn equals this yaml file name
$fn = 'album_database.yml' # data file
class Album
##... | true |
c0d0a4d9e5ae25b2764f7f50a5104b8d67ab16fc | Ruby | reid-andrew/exercism_ruby | /bowling/bowling.rb | UTF-8 | 988 | 3.4375 | 3 | [] | no_license | class Game
attr_reader :score
def initialize
@score = 0
@prior_one = 0
@prior_two = 0
@rolls = 0
@strikes = 0
end
def roll(pins)
validate_score(pins)
@rolls += 1
@strikes += 1 if pins == 10
@score += pins
if prior_spare?(@prior_one, @prior_two) && @rolls < 20
@sc... | true |
b1d6b2da6b99ba182a29ad82f1f06e9b6932fe15 | Ruby | robhurring/bingo | /app/models/game.rb | UTF-8 | 1,405 | 3.125 | 3 | [] | no_license | class Game
include Mongoid::Document
include Mongoid::Timestamps
MinimumWords = 9
field :name, type: String
field :token, type: String
field :words, type: Array
field :active, type: Boolean, default: true
attr_accessible :name, :words
embeds_many :cards
validates :name, presence: true, length: {... | true |
ad6e44dc6d5130f392d50c991953f4bc043bf4cb | Ruby | jaremkivv/stubb | /lib/stubb/sequence_match_finder.rb | UTF-8 | 1,711 | 2.578125 | 3 | [
"MIT"
] | permissive | module Stubb
class SequenceMatchFinder < SequenceFinder
private
def sequenced_path(sequence_index)
built_path = []
last_is_dir = false
request.path_parts.each_with_index do |level, index|
if match = literal_directory(built_path, level)
last_is_dir = true
elsif mat... | true |
48a3af07369576e55967a52d9eb5aa4eef6122f7 | Ruby | asellitt/lunch | /lunch.rb | UTF-8 | 1,581 | 2.828125 | 3 | [] | no_license | require 'sinatra/base'
require 'json'
class Lunch < Sinatra::Base
set :bind, '0.0.0.0'
set :raise_errors, false
set :show_exceptions, false
before do
content_type 'application/json'
end
get '/' do
restaurants.to_json
end
get '/random' do
random_restaurant(restaurants).to_json
end
ge... | true |
427977f101a84a0669b4009efe13c9793ffd0c5f | Ruby | ArcadG/task | /task_7/cargo_wagon.rb | UTF-8 | 653 | 3.09375 | 3 | [] | no_license | class CargoWagon < Wagon
attr_accessor :overall_volume, :loading_volume
def initialize(manufacturer, overall_volume)
super('cargo', manufacturer)
@overall_volume = overall_volume
@loading_volume = 0
end
def show
{
total_volume: "Общий объем: #{ overall_volume }",
occupied_volume:... | true |
fe396983a083282a30c75ee1b77a0bd9e285136d | Ruby | jcampbell18/rubyOnRails | /ruby/2_EssentialTraining/Ex_Files_Ruby_EssT_2_Classes/Exercise Files/Chapter_06/06_04/ruby_project/errors.rb | UTF-8 | 374 | 3.578125 | 4 | [] | no_license | #!/usr/bin/env ruby
def divide(x,y)
puts x/y
rescue ZeroDivisionError => e
puts "Cannot divide by zero"
puts "#{e.class}: #{e.message}"
rescue TypeError
puts "Requires two integer arguments"
rescue => e
puts "No worries"
end
begin
divide(4,2)
divide(4,0)
divide(4,"2")
divide(4)
# rescue Argumen... | true |
f9afabcc616294294ebfd2208e117329e5de2694 | Ruby | leafhouse/W1D5 | /PolyTreeNode/lib/00_tree_node.rb | UTF-8 | 1,233 | 3.78125 | 4 | [] | no_license | class PolyTreeNode
attr_accessor :value, :parent, :children
def initialize(value)
@value = value
@parent = nil
@children = []
end
def parent=(passed_parent)
if @parent != nil
@parent.children.delete(self)
end
@parent = passed_parent
if passed_parent != nil
if !(pas... | true |
d13fbd6ca97a903349b0163b312fd6a1ef8de3af | Ruby | UltimateCoder00/Project-Euler-Problems | /lib/problem9.rb | UTF-8 | 625 | 3.546875 | 4 | [] | no_license | require 'common'
def special_pythagorean_triplet(limit)
(1..limit).each do |a|
(1..limit).each do |b|
break if obviously_not_pythagorean_triplet?(a, b, limit)
c_2 = squared_sum(a, b)
next unless square_root_natural_number?(c_2)
c = integer_square_root(c_2)
return a * b * c if pythag... | true |
e9f06acd9a2b0761f689548068a2f5e553f3b3a1 | Ruby | Roderik88/Desafio_Modulos_Mixins_Rack | /metodo2.rb | UTF-8 | 812 | 4.09375 | 4 | [] | no_license | module Formula
def perimetro(a, b)
2*(a+b)
end
def area(a, b)
a*b
end
end
class Rectangulo
attr_accessor :largo, :ancho
include Formula
def initialize(largo, ancho)
@largo = largo
@ancho = ancho
end
def lados
print "#{@largo} , #{ancho}"
end
end
class C... | true |
38fa937cdec9a2e0e90663a0ffde9154c27b0bb0 | Ruby | klumbe/wiki_validator | /spec/validator/helper_spec.rb | UTF-8 | 3,343 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe WikiValidator::Helper do
describe 'self#find_element_class' do
it 'takes a template_item of type comment and returns nil' do
# Comment is ignored and can't be checked then -> can be added anytime
ti = TemplateItem.new('+comment')
clss = Helper.find_elem... | true |
64036f754c09b6e1a6e550bdac9be340413b1486 | Ruby | PSzyszka/basics | /spec/models/article_spec.rb | UTF-8 | 3,062 | 2.828125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Article do
describe 'initialization' do
it '' do
Timecop.freeze(Time.now + 5.seconds) do
article = Article.new('naked heat', 'castle')
aggregate_failures 'article attributes' do
expect(article.title).to eq('naked heat')
expect(arti... | true |
66db26b7148b5d0c8c686f26474e445dd969d1ef | Ruby | Hives/codewars-katas | /ruby/7kyu/printer-errors-7kyu.rb | UTF-8 | 194 | 3 | 3 | [] | no_license | def printer_errors(s)
sum = 0
"nopqrstuvwxyz".chars.each { |l|
sum += s.count(l)
}
return "#{sum}/#{s.length}"
end
puts printer_errors "abcdefn"
| true |
d8f2407417f593fc937f293d4d2bd601f62c55b7 | Ruby | jmheyd/ruby-music-library-cli-v-000 | /lib/music_importer.rb | UTF-8 | 404 | 2.984375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class MusicImporter
attr_accessor :path, :files
#initialized with a file path
def initialize(path)
@path = path
@files = files
end
def files
@files = Dir.entries("#{@path}").reject {|f| File.directory?(f) || f[0].include?('.')}
#@files = Dir["#{@path}/*"]
#binding.pry
end
def import
... | true |
5ce3e0751afcffe7a8d521e4f402a2b0d12192ed | Ruby | Kite0301/atcoder | /tenkaici2016/B/a.rb | UTF-8 | 66 | 3.109375 | 3 | [] | no_license | def f(n)
m=(n*n+4.0)/8.0
return m.floor
end
puts f(f(f(20)))
| true |
651d8a6b7f805dfe1043d81b9e7b481f73fc97d9 | Ruby | chrisdb/CoReMite | /lib/coremite/rss_feed_reader.rb | UTF-8 | 1,566 | 2.8125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'rss'
require 'open-uri'
require 'htmlentities'
class RssFeedReader
@@PROJECT_REGEX = /.*Projekt:<\/strong>/
@@ACTIVITY_REGEX = /.*Leistung:<\/strong>/
@@COMMENT_REGEX = /.*Bemerkung:<\/strong>/
@@TIME_REGEX = /.*Stunden:<\/strong>/
@@CLOSING_REGEX = / <.*/
@mite_key
@mite_account
def initia... | true |
929019b896099212db182b0ef59135e2c7d03afa | Ruby | mongomapper/mongomapper | /spec/functional/pagination_spec.rb | UTF-8 | 2,458 | 2.53125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'spec_helper'
describe "Pagination" do
before do
@document = Doc do
key :first_name, String
key :last_name, String
key :age, Integer
def self.per_page; 1 end
end
@doc1 = @document.create(:first_name => 'John', :last_name => 'Nunemaker', :age => '27')
@doc2 = @docume... | true |
37e2657a27555fb55b6658f301996bb2f14ba511 | Ruby | acasarsa/data_spider | /lib/zillow.rb | UTF-8 | 1,855 | 2.578125 | 3 | [
"MIT"
] | permissive | # require "housing_scraper/version"
# module HousingScraper
# class Error < StandardError; end
# # Your code goes here...
# end
require 'kimurai'
require "selenium-webdriver"
require 'byebug'
class Zillow < Kimurai::Base
@name = 'zillow'
@engine = :selenium_chrome
@start_urls = ["https://www.zillow.com/"]... | true |
4a2f04c8ea90299547ab9d3ced8dbdb6ad806131 | Ruby | framgia1023/rails-elearning-akiho-naoto | /app/helpers/answers_helper.rb | UTF-8 | 117 | 2.6875 | 3 | [] | no_license | module AnswersHelper
def answer_correct?(choice)
if choice.correct == true
"◯"
else
"×"
end
end
end
| true |
046d9f7f0568e73540ee4e1f8bc2879ba34f81f0 | Ruby | camiha/aoj | /ITP1/ITP1_4_A.rb | UTF-8 | 117 | 3.125 | 3 | [
"MIT"
] | permissive | a,b = gets.split.map &:to_f
print a.to_i / b.to_i
print " "
print a.to_i % b.to_i
print " "
puts "%.8f" % "#{a / b}" | true |
49002f1e33a2101119da4e7fecd002af8bc40aa1 | Ruby | Automatic365/headcount | /lib/enrollment.rb | UTF-8 | 961 | 3 | 3 | [] | no_license | require_relative 'helper_methods'
class Enrollment
include HelperMethods
attr_reader :attributes
def initialize(attributes)
@attributes = attributes
end
def kindergarten_participation_by_year
attributes[:kindergarten_participation].reduce({}) do |result, pair|
result.merge!(pair.first => trun... | true |
004ba4221ae534cdc0626cba4c3beecd57e29ccb | Ruby | h4ck3rm1k3/shawnee-county-osm-landuse | /house_map.rb | UTF-8 | 1,236 | 3.28125 | 3 | [] | no_license | require 'street_address'
class HouseMap
def initialize
@address = Hash.new()
end
def addresses
@address
end
# def new ()
# end
def print()
#puts self
#puts @address
for s in @address.keys.sort
k = @address[s].keys
if k.nil?
puts "#{s};"
els... | true |
eb31a7aa4dc05ad627a16c69e0a78d10621c0a77 | Ruby | cfcosta/event_emitter | /benchmark/benchmark.rb | UTF-8 | 960 | 2.625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require File.expand_path 'benchmark_helper', File.dirname(__FILE__)
class Bench
class Foo
include EventEmitter
end
def bench_1on_100Kemit
foo = Foo.new
count = 0
foo.on :bar do |num|
count += num
end
100000.times do
foo.emit :bar, 1
end
raise Erro... | true |
b17762618661983a80a9015848c4515ae0ac7b13 | Ruby | FKnottenbelt/Practicing_Ruby | /ruby_practice/are_they_the_same.rb | UTF-8 | 2,737 | 4.4375 | 4 | [] | no_license | # are_they_the_same.rb 6 kyu
=begin
Given two arrays a and b write a function comp(a, b)
that checks whether the two arrays have the "same" elements, with the same
multiplicities. "Same" means, here, that the elements in b are the elements
in a squared, regardless of the order.
Examples
Valid arrays
a = [121, 144, 19... | true |
bd072ae254ed2e79a6c26cb105fe19dcb56ebeeb | Ruby | dougsko/digital_blender | /bin/sts_grapher.rb | UTF-8 | 1,054 | 2.515625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/env ruby
#
#
data = {}
File.open('experiments/AlgorithmTesting/finalAnalysisReport.txt') do |f|
f.readlines.each do |line|
if line.chomp.match(/^((\s\d)|\d+)/)
line.gsub(/^\s/,'')
data[line.chomp.split(' ')[12]] = line.chomp.split(' ')[0..9]
end
end
end
File.... | true |
02bc7e68bd312b7b051af1b2c142e1f039512c7f | Ruby | jmettraux/ruote | /lib/ruote/exp/fe_given.rb | UTF-8 | 4,117 | 2.8125 | 3 | [
"MIT"
] | permissive | #--
# Copyright (c) 2005-2013, John Mettraux, jmettraux@gmail.com
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy... | true |
5cf2bf7045e01437bffda4f402daf87e2e16376d | Ruby | tdeo/advent_of_code | /2019/test/07.rb | UTF-8 | 710 | 2.640625 | 3 | [] | no_license | # frozen_string_literal: true
require 'minitest/autorun'
require_relative('../lib/07_amplification_circuit')
describe AmplificationCircuit do
before { @k = AmplificationCircuit }
def test_part1
assert_equal 43_210, @k.new('3,15,3,16,1002,16,10,16,1,16,15,15,4,15,99,0,0').part1
assert_equal 54_321, @k.new... | true |
5fbdbd94b75687f7a7b0be218a9fca4f51b6255c | Ruby | 007oscar/demo2 | /db/seeds.rb | UTF-8 | 2,326 | 2.609375 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
0d7066f576f47435a85ec7b27102c68ae5d6ffa2 | Ruby | reddragon010/RisingGuilds | /lib/arsenal.rb | UTF-8 | 2,949 | 2.734375 | 3 | [
"MIT"
] | permissive | module Arsenal
class TalentSpec
attr_reader :trees,:active,:group,:icon,:prim
def initialize(elem)
@trees = []
@trees[1] = elem[:treeOne].to_i
@trees[2] = elem[:treeTwo].to_i
@trees[3] = elem[:treeThree].to_i
@active = elem[:active].nil? ? false : true
@group = elem[:group].to_i
... | true |
20c6f6deaf1ecfd392feb1d718819587f62e7603 | Ruby | chapatt/autotracker | /geo.rb | UTF-8 | 363 | 2.765625 | 3 | [] | no_license | require 'geokit'
module Geo
Geokit::default_units = :miles
Geokit::default_formula = :sphere
def self.get_current_heading
# We're heading due east
return 90
end
def self.get_bearing_to_station
a = Geokit::LatLng.normalize(28.409465, -80.590945)
b = Geokit::LatLng.normalize(28.381275, -80.54... | true |
c5cda4654041ecbdac33170903f80bc23fb18a04 | Ruby | mikedao/module0 | /ruby-exercises/command-query/pills.rb | UTF-8 | 155 | 2.953125 | 3 | [
"MIT"
] | permissive | class Pills
attr_accessor :number
def initialize
self.number = 60
end
def count
number
end
def pop
self.number -= 1
end
end
| true |
e51cb92bf170ba9c4c0819b3dcb62d966d0b09f7 | Ruby | Sonia4Code/AIRBNB | /app/models/reservation.rb | UTF-8 | 1,093 | 2.65625 | 3 | [] | no_license | class Reservation < ApplicationRecord
belongs_to :listing
belongs_to :user
before_save :set_total_price
# validates_presence_of :check_in, :check_out
# validate :check_out_is_after_check_in
# validate :overlap_dates
# validate :check_in_after_today
# def overlap_dates
# if self.listi... | true |
836dd7889807742a418c84f3c64bc1e893312f9a | Ruby | MikelSage/homework | /insertion_sort.rb | UTF-8 | 770 | 4.03125 | 4 | [] | no_license | class InsertionSort
def sort(unsorted)
sorted =[]
unsorted.length.times do
to_insert = unsorted.shift
sorted.empty? ? sorted << to_insert : inserter(sorted, to_insert)
end
sorted.inspect
end
def inserter(to_sort, to_insert)
index = 0
sorted_length = to_sort.length
while in... | true |
2d4e0b1c7868b6f1345e5f0b820479ab21dba079 | Ruby | mudasobwa/rmagick-screwdrivers | /lib/rmagick/screwdrivers/sobel.rb | UTF-8 | 2,475 | 2.953125 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
module Magick
module Screwdrivers
# based on http://blog.saush.com/2011/04/20/edge-detection-with-the-sobel-operator-in-ruby/
module Sobel
attr_reader :options
@options = {
:roughly => false
}
def self.yo image, options = {}
options = Magick::Sc... | true |
59a2e1e7a451882ab763e536a2859a3a7f23f07b | Ruby | fadam00/Ironhack | /Javascript/Week3/array of colors/app.rb | UTF-8 | 395 | 3.484375 | 3 | [] | no_license | require_relative("lib/color_counter.rb")
color_array = ["lilac","indigo","teal","periwinkle","black","periwinkle","baby blue","teal"]
color = ColorCounter.new
color.count_color("indigo", color_array) == 1
color.count_color("periwinkle", color_array) == 2
color.count_color("teal", color_array) == 0
caps_color... | true |
1a8971e4e47594abf8ca4a682560ef944d3a854b | Ruby | ShaunMackie/RB101 | /Lesson_2/Loan_Calculator/assignment_loan_calculator.rb | UTF-8 | 2,052 | 3.546875 | 4 | [] | no_license | require 'yaml'
MESSAGES = YAML.load_file('loan_calc_messages.yml')
loan = ''.to_i
apr = ''
loan_dur = ''
def prompt(message)
Kernel.puts("=> #{message}")
end
def monthly_rate(rate)
rate / 12 / 100
end
def monthly_loan_dur(years)
years * 12
end
def monthly_payment(loan, monthly_rate, monthly_loan_dur)
loan ... | true |
419a423d4b4f44ddd4b78f8568994e34ea6c0efa | Ruby | drkitsch/oystercard-2 | /spec/oystercard_spec.rb | UTF-8 | 2,143 | 3.34375 | 3 | [] | no_license | require './lib/oystercard.rb'
describe Oystercard do
it 'should respond to #balance' do
oyster = Oystercard.new
expect(oyster).to respond_to(:balance)
end
it 'has an initial balance of 0' do
oyster = Oystercard.new
expect(oyster.balance).to eq(0)
end
it 'should respond to #top_up' ... | true |
13a15a850d4150f8a0d2e623697c507e310c9d78 | Ruby | gadial/project-euler | /problem45.rb | UTF-8 | 829 | 3.9375 | 4 | [] | no_license | # Triangle Tn=n(n+1)/2 1, 3, 6, 10, 15, ...
# Pentagonal Pn=n(3n-1)/2 1, 5, 12, 22, 35, ...
# Hexagonal Hn=n(2n-1) 1, 6, 15, 28, 45, ...
#
# It can be verified that T285 = P165 = H143 = 40755.
#
# Find the next triangle number that is also pentagonal and hexagonal.
require 'common'
class Inte... | true |
1b42a2caab3c07061edaee7a3f181ef5d316f7f5 | Ruby | AG2791/programming_languages-online-web-prework | /programming_languages.rb | UTF-8 | 289 | 2.875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reformat_languages(languages)
new_hash = {}
languages.each do |style, lang|
lang.each do |name, type|
new_hash[name] ||= type
new_hash[name][:style]=[]
new_hash[name][:style]<<style
end
end
return new_hash
end
puts reformat_languages(languages)
| true |
4b4c0884ee414ec9ef83692a08d122e9ab1c35a2 | Ruby | KyosukeUryu/vending_training | /lib/VendingMachine.rb | UTF-8 | 2,908 | 3.78125 | 4 | [] | no_license | require './lib/User'
require './lib/Juice'
class VendingMachine
# 10円玉、50円玉、100円玉、500円玉、1000円札を1つずつ投入できる。
MONEY = [10, 50, 100, 500, 1000].freeze
attr_reader :sale, :juice_name_list, :juice_price_list
attr_accessor :stock
attr_writer :slot_money
# (自動販売機に投入された金額をインスタンス変数の @slot_money に代入する)
def initializ... | true |
e4c337879a6dd82cb02b7b77d2c544e303c210d7 | Ruby | necsanuradu/chitter-challenge | /lib/string.rb | UTF-8 | 228 | 3.03125 | 3 | [] | no_license | require 'digest/sha1'
class String
def hash_1
Digest::SHA1.hexdigest(self.to_s)
end
def clean_value
"'" << self.to_s.gsub(/[']/, "'") << "'"
end
def clean_key
self.to_s.gsub(/[^a-z_]/,'')
end
end | true |
913d156fab47f1c927c79ba9dbbfdde8fdb6b623 | Ruby | ildomm/graphql-kalender | /lib/crawler/crawler.rb | UTF-8 | 404 | 3.140625 | 3 | [] | no_license | module Crawler
def self.run(number)
puts "number : #{number}"
# loop de 12 meses
#
# formatar url por padrao do source
# criar pool para processar uma url por thread
end
end
module TimeSplitter
def self.call(time_start, time_end)
seconds = ((time_end - time_start)).round
... | true |
c9a7eaf3b5b27376fb1adca4601254f160b23aff | Ruby | Bhuser/exercism | /ruby/anagram/anagram.rb | UTF-8 | 282 | 3.0625 | 3 | [] | no_license | #!/usr/bin/env ruby
hash = Hash.new { |hash, key| hash[key] = [] }
File.open("wordlist.txt", "r") do |f|
f.each_line do |line|
hash[line.strip.downcase.chars.sort.join] << line.strip
end
end
hash.values.reject{|a| a.length == 1}.each{|i| puts i.join(' ')}
| true |
0ea419821df5f43efbee74f008451122da51e261 | Ruby | ems2141/intro_to_tdd | /lib/leap_year_calc.rb | UTF-8 | 149 | 3.125 | 3 | [] | no_license | class LeapYearCalc
def initialize(year)
@year = year
end
def yes?
(@year%4 == 0 && !(@year%100 == 0)) || ((@year%400 == 0))
end
end | true |
15d724d96ebf1fdae63d9405206f1fa4b491b78f | Ruby | benjaminoakes/snippets | /ruby/jumble_map.rb | UTF-8 | 684 | 3.125 | 3 | [] | no_license | # Author: Benjamin Oakes <hello@benjaminoakes.com>
LATIN_SQUARE = [
'JUMBLE',
'BJLUEM',
'LMJEBU',
'UBEJML',
'MEULJB',
'ELBMUJ',
]
MAPPING = {
'J' => 1,
'U' => 2,
'M' => 3,
'B' => 4,
'L' => 5,
'E' => 6,
}
# MAPPING = {
# 'J' => 2,
# 'U' => 3,
# 'M' => 5,
# 'B' => 7,
# 'L' => 11,
# ... | true |
6541869b634dacaaf523a0c774feab5c7e383578 | Ruby | SplashGordonMD/deliberate_practice | /15d.rb | UTF-8 | 128 | 3.21875 | 3 | [] | no_license | numbers = [3, 5, 8, 12, 13, 14]
median = (numbers[numbers.length / 2] + numbers[numbers.length / 2 - 1]) / 2.0
puts median
| true |
c31ac9a6906ae05dfb782685ae18e860cbcc077b | Ruby | mesarikaya/codility | /Tape-Equilibrium.rb | UTF-8 | 2,643 | 3.703125 | 4 | [] | no_license | #A non-empty zero-indexed array A consisting of N integers is given. Array A represents numbers on a tape.
# Any integer P, such that 0 < P < N, splits this tape into two non−empty parts: A[0], A[1], ..., A[P − 1] and... | true |
c2b9a948a7319f9f9e9e414f88cdca3b0abe1acd | Ruby | MScottWold/coding_challenges | /rails_lite/lib/flash.rb | UTF-8 | 735 | 2.515625 | 3 | [] | no_license | require 'json'
class Flash
def initialize(req)
flash = req.cookies["_rails_lite_app_flash"]
if flash
@flash = { session: JSON.parse(flash, :symbolize_names => true), now: Hash.new }
@new_flash = false
else
@flash = { session: Hash.new, now: Hash.new }
end
end
def [](key)
@f... | true |
3152a85e2cb6a16f287e9d3e67f17e6366a5b836 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/robot-name/e23018a5b65d43989be9f48b93aee737.rb | UTF-8 | 230 | 3.328125 | 3 | [] | no_license | def rand_char
rand('A'.ord..'Z'.ord).chr
end
class Robot
attr_accessor :name
def initialize
reset
end
def reset
@name = ""
2.times { @name << rand_char }
3.times { @name << rand(0..10).to_s }
end
end
| true |
f65f4b6ab00c61a36c51042030e56b0257fdd629 | Ruby | ciax/ciax-xml | /script/libprompt.rb | UTF-8 | 2,520 | 2.671875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'libvarx'
module CIAX
# For server status through all layers
# This instance will be assigned as @sv_stat in other classes
class Prompt < Varx
attr_reader :db
# type = site,mcr
def initialize(type, id)
super(['server', type].compact.join('_'), id)
@db = {}
... | true |
5994833639a96f088243a1cfc9ae5fe634321891 | Ruby | langerkirill/Active-Ruby | /lib/01_sql_object.rb | UTF-8 | 2,711 | 3 | 3 | [] | no_license | require 'byebug'
require_relative 'db_connection'
require 'active_support/inflector'
# require_relative '02_searchable'
# NB: the attr_accessor we wrote in phase 0 is NOT used in the rest
# of this project. It was only a warm up.
class SQLObject
# extend Searchable
def self.columns
return @syms if @syms
na... | true |
9d56bb267793c4d60b0c1bfdb6eab8914e0dd8c6 | Ruby | iamtraviscole/oxford-comma-v-000 | /lib/oxford_comma.rb | UTF-8 | 325 | 3.515625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # array = ["peter", "piper", "pan"]
def oxford_comma(array)
new_array = []
if array.size == 2
array.join(" and ")
else
array.each do |name|
if array.size > 1 && array[-1] == name
new_array << "and #{name}"
else
new_array << name
end
end
new_array.join(", ")
end... | true |
d919ae9e355371ea08513c3c9a1f3de32f27823f | Ruby | Ems-codes/ruby-music-library-cli-online-web-sp-000 | /lib/Song.rb | UTF-8 | 1,925 | 3.78125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
require_relative "../lib/concerns/modules.rb"
class Song
attr_accessor :name
attr_reader :artist, :genre
@@all = []
def initialize(name, artist = nil, genre = nil)
@name = name
#if there is no artist entered, then set artist through the artist= method
if artist ... | true |
99fa26e77130ce3ca5b7938aeb1556c9a4a15916 | Ruby | NialtoServices/push_kit-apns | /lib/push_kit/apns/push_client.rb | UTF-8 | 7,333 | 2.578125 | 3 | [] | no_license | # frozen_string_literal: true
module PushKit
module APNS
# The PushClient class provides an interface for delivering push notifications using HTTP/2.
#
class PushClient
# @return [Hash] The default hosts for each of the environments supported by APNS.
#
HOSTS = {
production: 'ap... | true |
3417cb0eca616e446049a5189553bb3b0345c1b4 | Ruby | ShanoBueno/Aa-Projects | /W4D2/class_inheritance.rb | UTF-8 | 1,281 | 3.515625 | 4 | [] | no_license | class Employee
attr_reader :title, :salary
def initialize(name, title, salary, boss = nil)
@name = name
@title = title
@salary = salary
self.boss = boss
end
def boss=(node)
@boss = node
if node != nil
node.add_employee(self)
end
end
def bonus(multiplier)
if @title ... | true |
3db9c93d95e251bc7a2a5ac3bba9f4b37916fe2e | Ruby | Mahfood/ffaker | /lib/ffaker/phone_number_nl.rb | UTF-8 | 1,879 | 2.796875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # encoding: utf-8
module FFaker
module PhoneNumberNL
extend ModuleUtils
extend self
COUNTRY_CODE = '+31'.freeze
AREA_CODE_PREFIX = '0'.freeze
PHONE_NUMBER = {
2 => ['#######', '### ####', '#### ###'],
3 => ['######', '#### ##', '## ## ##']
}.freeze
AREA_CODES = %w[10 111 113 ... | true |
349850e347276de957949c7962a587c80f7cf178 | Ruby | siakaramalegos/assignment_sinatra_blackjack | /app.rb | UTF-8 | 2,998 | 2.703125 | 3 | [] | no_license | require 'sinatra'
require 'erb'
require 'pry' if development?
require 'json'
require 'sinatra/partial'
require 'sinatra/reloader' if development?
require_relative 'card_deck'
require_relative 'player'
require_relative 'helpers/blackjack_helper'
helpers BlackjackHelper
# saves deck and hands
enable :sessions
# optio... | true |
56b9545c5840905471f12e8c9e3c3575e6292661 | Ruby | compsciacademy/fulltime-program-2021-Q2 | /Week04/Day17/homework_review/homework.rb | UTF-8 | 260 | 3.03125 | 3 | [] | no_license | # Write methods on the Order and OrderItem
# classes that will return the last saved
# item of each.
order = Order.last
order_item = OrderItem.last
puts "This should be the last order: #{order.id}"
puts "This should be the last order item: #{order_item}" | true |
8ff09ca41dd6b332fa63597cc900cb13a4032d69 | Ruby | bdantoni/sonicpi | /washingclothes.rb | UTF-8 | 357 | 2.75 | 3 | [] | no_license | # Welcome to Sonic Pi v.26
def wear(smell)
sample :ambi_haunted_hum, rate: smell
sleep(2)
end
def wash(temp)
play temp
sleep(1)
end
def dry(dryer)
sample dryer
sleep(1)
end
def dirty?
1 == [1,2].choose
end
def treat_stain
sample :ambi_drone
sleep(1)
end
5. times do
wear(1)
treat_stain if dirt... | true |
3138327f4c4fac8c1aae35cfdd75396dc5b61afa | Ruby | hexdigest/ruby-nfc | /test/apdu_request_test.rb | UTF-8 | 1,961 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'test_helper'
require 'ruby-nfc/apdu/request'
class APDURequestTest < MiniTest::Unit::TestCase
def test_raise_apdu_error_if_length_too_small
e = assert_raises(APDU::Error) {APDU::Request.from_string("123")}
assert_match e.message, /too short/
end
def test_raise_apdu_error_if_wrong_command_data_l... | true |
c50a75ad8cb5dd2e28e7f89720c1590a21191488 | Ruby | sul-dlss/exhibits | /app/models/exhibit_bot.rb | UTF-8 | 970 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
##
# A wrapper class around the Slack Web Client.
# All public methods are delegated through the class itself so things like
# ExhibitBot.message(text: 'My Message Content') will simply work anywhere.
class ExhibitBot
class << self
delegate :message, to: :new
end
def message(ch... | true |
60e646d294e9c538c5f033f99f956f8a9c9f0634 | Ruby | levidsmith/timelapsemaker | /fixnames.rb | UTF-8 | 605 | 2.6875 | 3 | [] | no_license | # Timelapse Maker
# 2015 Levi D. Smith
# Web: levidsmith.com
# Twitter: @GaTechGrad
# This is for adding an extra zero if only three numbers
# are specified in the image filenames
# The new encode.rb should generate filenames with four
# numbers by default
require 'fileutils'
files = Dir.entries(".")
files.select!... | true |
a9c0c16b9d657eb807b344c84bad8b8149edb485 | Ruby | IsaacGonRam/anagrama | /nuevo_anagrama.rb | UTF-8 | 345 | 3.90625 | 4 | [] | no_license | def canonical(word)
word= word.split(//).sort
end
def are_anagrams?(word1, word2)
canonical(word1) == canonical(word2)
end
def anagrams_for(palabra, arreglo)
palabra = palabra.split(//).sort
arreglo.select {|valor| valor.split(//).sort == palabra}
end
p are_anagrams?("hola","alho")
p anagrams_for("rey", ["hola... | true |
5e28a1eb00601fc02350fe652401613300f6b4a1 | Ruby | sleepepi/lofthf.study | /app/models/slice/slice/send_json.rb | UTF-8 | 1,543 | 2.640625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "openssl"
require "net/http"
require "json"
module Slice
# Generates JSON web requests for POST and PATCH.
class SendJson
class << self
def get(url)
new(url).get
end
def post(url, *args)
new(url, *args).post
end
def patch(ur... | true |
7742bef015d8f03ac8dd2b64ae193c19316791aa | Ruby | lnmunhoz/playground | /ruby-quake-parser/lib/parser.rb | UTF-8 | 985 | 3.3125 | 3 | [] | no_license | require './lib/line'
require './lib/game'
require './lib/kill'
class Parser
attr_accessor :games
def initialize
@games = []
end
def parse (path)
File.open(path, "r") do |f|
f.each_line do |line|
if Line.initGame? (line)
self.add_game(Game.new)
end
if Line.kill?... | true |
84a5f4cdbcc821e67e54214cc38b52e032ea6d97 | Ruby | ytti/oxidized | /extra/nagios_check_failing_nodes.rb | UTF-8 | 856 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
## contrib via https://github.com/ytti/oxidized/issues/67
require 'open-uri'
require 'json'
critical = false
pending = false
critical_nodes = []
pending_nodes = []
json = JSON.parse(open("http://localhost:8888/nodes.json").read)
json.each do |node|
next if !ARGV.empty? && (ARGV[0] != node['nam... | true |
b73a17b195b67e7de509d76051ee824c5a9dafa1 | Ruby | ShaheensWeb/CodeWars-Ruby | /Jan19thCodeWars-Ruby.rb | UTF-8 | 996 | 4.40625 | 4 | [] | no_license | #PROBLEM #2
''' Create a method zip that accepts two lists, and combines their result into a single array, like so:
first = [\'a\', \'c\', \'e\']
second = [\'b\', \'d\', \'f\']
zip(first, second)
#=> [\'a\', \'b\', \'c\', \'d\', \'e\', \'f\']
If you need help, here\'s a reference:
http://www.rubycuts.com/enum-zip... | true |
04a3a46d296210d30eb48385c2813833d1bb58b4 | Ruby | carolyny/launchschool | /Backend/101/Exercises/lights2.rb | UTF-8 | 658 | 3.8125 | 4 | [] | no_license | def determine_on_lights(array)
on_lights =[]
array.each_with_index do |value, index|
on_lights << index+1 if value == 1
end
on_lights
end
def lights(number_of_lights)
light_array = Array.new(number_of_lights){-1}
round_number = 1
loop do
light_array.each_with_index do |value, index|
lig... | true |
28d63aceee9a564e17bc81c29047c27a076cb78c | Ruby | marcelorxaviers/ruby | /algorithms/challenges/number_solitaire.rb | UTF-8 | 3,041 | 4.09375 | 4 | [] | no_license | puts """
NumberSolitaire: https://codility.com/demo/results/training6AUWBA-VSG/
A game for one player is played on a board consisting of N consecutive squares, numbered from 0 to N − 1. There is a number written on each square. A non-empty zero-indexed array A of N integers contains the numbers written on the squares.... | true |
5f80e63ea9bc54dbb39a92e830b41b050d006b50 | Ruby | Jhoan/QueueSim | /src/Server.rb | UTF-8 | 968 | 3.046875 | 3 | [] | no_license |
#Class Server: It Holds the task during the service
#
#
class Server
def initialize(newServiceRate,distribution = "Exponential",newSink)
@serviceRate = newServiceRate
@task = nil
@attendedTasks = 0
@sink = newSink
@serviceTime = RandomTime.new(distribution,@serviceRate)
@busy = false
end
def free(... | true |
fe2574aad063503f958f2391b10e9cd114f33993 | Ruby | dneverov/headfirstpatterns-ruby | /ch02/WeatherStation03/weather_station.rb | UTF-8 | 737 | 3.046875 | 3 | [] | no_license | # cd /your/project/dir
# ruby -I lib weather_station.rb
require 'weather_data'
require 'current_conditions_display'
require 'statistics_display'
require 'forecast_display'
#require 'heat_index_display'
class WeatherStation
def main
weather_data = WeatherData.new()
current_display = CurrentConditionsDisplay... | true |
bf063b518783ce3e2628375d5e5c69c4225a50d9 | Ruby | schucode/pig_latin | /spec/pig_latin_spec.rb | UTF-8 | 1,324 | 3.046875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe 'PigLatin' do
it "exists" do
expect(PigLatin).to be_a(Module)
end
it "can see if input starts with a vowel" do
input = "apple"
output = PigLatin.starts_with_vowel(input)
expect(output).to eq(true)
input = "cow"
output = PigLatin.starts_with_vowel(inpu... | true |
39f6259d5b46d7cbb91108449adbb3a1974a9c2a | Ruby | danielbush/beerbot-modules | /Beer/beer.rb | UTF-8 | 4,703 | 2.6875 | 3 | [] | no_license | require 'date'
require 'beerbot'
module BeerBot; module Modules; end; end
module BeerBot::Modules::Beer
require 'beerbot'
require_relative '../utils/datafile'
require_relative '../utils/param_expand'
require_relative '../utils/sentence_expand'
Job = BeerBot::Scheduler::CronR::CronJob
def self.in... | true |
cb885801826bc85169abba5040add51e4a90507c | Ruby | damilola-dealdey/AdvanceRuby | /AdvEx-3/bin/main.rb | UTF-8 | 194 | 3.078125 | 3 | [] | no_license | print "Method name ? : "
method_name = gets
print "Line of code ? : "
line_of_code = gets
Object.define_singleton_method(method_name) do
puts eval(line_of_code)
end
Object.send(method_name) | true |
0f43841883f779d44060c76a8a8d6274ba628a6c | Ruby | bgalladian/high_card | /high_card.rb | UTF-8 | 747 | 3.671875 | 4 | [] | no_license |
# require "pry"
# Use these two arrays to generate a deck of cards
ranks = ["A", 2, 3, 4, 5, 6, 7, 8, 9, 10, "J", "Q", "K" ]
ranks.push(ranks.shift)
suits = [ "hearts", "spades", "clubs", "diamonds" ]
players = []
deck = []
ranks.each_with_index do |rank, index|
suits.each do |suit|
deck << [rank, index, suit]
e... | true |
42d477f1114eaca59b3b277789c56e9ec93f0b2d | Ruby | firechicago/advent-of-code | /Day-3-Problem-2/parse.rb | UTF-8 | 818 | 3.3125 | 3 | [] | no_license | raw_data = File.read(ARGV[0])
class Santa
attr_accessor :santas_location
def initialize(coordinates = [0,0])
@santas_location = coordinates
end
def self.gifts_given
@@gifts_given ||= Hash.new(0)
end
def give_gift
Santa.gifts_given[santas_location.to_s] += 1
end
def move(direction)
c... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.