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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
f10c8d002d3a085a9197b69d901eb941f4ce3f1b | Ruby | b18168/Lesson-2 | /les-2.rb | UTF-8 | 372 | 3.65625 | 4 | [] | no_license | def priem?(mogelijk_priem)
alles_eronder = (2...mogelijk_priem)
for getal_eronder in alles_eronder
if mogelijk_priem % getal_eronder == 0
puts "#{mogelijk_priem} is geen priemgetal! #{getal_eronder}"
return false
end
end
puts "#{mogelijk_priem} is een priemgetal!"
return true
end
puts "Welk nummer moe... | true |
24d7e45eaea5b22d68f643f4418c0aeb6414a924 | Ruby | larahoya/IRONHACK-WEEK1 | /data2.rb | UTF-8 | 467 | 3.375 | 3 | [] | no_license | class Car
def initialize(sound,engine)
@sound = sound
@engine = engine
end
def make_car_noise
puts "#{@sound} #{@engine.sound}"
end
end
class Engine
attr_reader :sound
def initialize(sound)
@sound = sound
end
end
class ElectricEngine < Engine
def initialize(sound, battery)
super(sound)
@bat... | true |
9abc7540ccc11fa8b6dbc0c03060cce550f3266d | Ruby | MonitronicsSecurity/asaper-ruby | /lib/asaper/handlers/existing_room.rb | UTF-8 | 1,115 | 2.515625 | 3 | [] | no_license | module Asaper
module Handlers
class ExistingRoom
def initialize(token, api_wrapper)
@token = token
@api_wrapper = api_wrapper
yield self
end
def message(message)
message_args = { message: { content: message } }
@api_wrapper.new_message(@token, message_ar... | true |
1ffc7fe0736c1e59f30ee4680d76c3f30f488280 | Ruby | bmackin/Ruby_Fundamentals1 | /exercise2.rb | UTF-8 | 825 | 4.5625 | 5 | [] | no_license | # 1. How would you calculate a good tip for a 55 dollar meal? Use puts to print the answer onscreen.
if tip = 55 * 0.15
puts tip
end
# 2. Try adding a string and an integer. What happens? Find a way to convert the integer so that it works and use puts to print the answer onscreen.
puts 99.to_s + " Red Balloons"
#... | true |
95c1814b3edd06dc05665a109e7be49ddbad6bb6 | Ruby | flash00/phase-0-tracks | /ruby/list/todo_list.rb | UTF-8 | 240 | 3.0625 | 3 | [] | no_license | class TodoList
attr_accessor :items
def initialize(items)
@items = items
end
def get_items
@items
end
def add_item(item)
@items << item
end
def delete_item(item)
@items.delete(item)
end
def get_item(num)
@items[num]
end
end
| true |
f2842c16146165b5fcbebadb580349a3119663a6 | Ruby | lbirts/Hackerrank-Interview-Prep | /ruby/count_bytesize.rb | UTF-8 | 117 | 3.03125 | 3 | [] | no_license | def count_multibyte_char(str)
count = 0
str.each_char { |c| count+=1 if c.bytesize > 1}
return count
end
| true |
3b3333f5c55cdd802f309763a578766d86172a4f | Ruby | chqmvum1/smallC-compiler | /lexer.rb | UTF-8 | 1,622 | 3.078125 | 3 | [] | no_license | # coding: utf-8
#
# 字句解析メソッドlexscan
#
def lexscan(filename)
tokens = []
file = File.open(filename)
file.each_line do |line|
regexp = /([\w]+|\+|-|\*|\/|>=|<=|>|<|\(|\)|\[|\]|\{|\}|==|=|!=|,|;|&&|&|\|\|)/
ary = line.split(regexp).select {|s| !s.empty? }
i = 0
ary.each do |ob... | true |
94c61197cff743a6610824ddfe2fb4cc9b1aa316 | Ruby | xuebingli/toyrobot | /lib/geometry.rb | UTF-8 | 440 | 3.109375 | 3 | [
"MIT"
] | permissive | require_relative 'board'
class Geometry
attr_reader :x, :y, :orientation
def initialize(geometry = nil, overrides = {})
@x = overrides[:x] || geometry.x
@y = overrides[:y] || geometry.y
@orientation = overrides[:orientation] || geometry.orientation
end
def valid?
x_valid? && y_valid?
end
... | true |
911e7b18205e06244f3a91c6aae0dd9c1971c6b4 | Ruby | Maimer/ruby_racer | /Ruby Racer.app/Contents/Resources/lib/texplay-contrib.rb | UTF-8 | 3,400 | 2.9375 | 3 | [] | no_license | # to bring in String#each_char for 1.8
if RUBY_VERSION =~ /1.8/
require 'jcode'
end
# setup will be executed straight after Gosu::Image instantiation
TexPlay::on_setup do
@turtle_pos = TexPlay::TPPoint.new(width / 2, height / 2 )
@turtle_angle = 0
end
TexPlay::create_macro(:move_to) do |x, y|
ca... | true |
71ce1fe8b67c860b8b06e849114dd2f5b33df708 | Ruby | r0tiart/Rails-Portfolio-Project | /app/helpers/user_books_helper.rb | UTF-8 | 686 | 2.71875 | 3 | [
"MIT"
] | permissive | module UserBooksHelper
def user_books
current_user.books
end
def reading?
!!current_user.books
end
def finished_books
ids = current_user.user_books.where(page: "completed").pluck("book_id").flatten
books = ids.collect{|id| Book.where(id: id)}.flatten
end
def currently_reading
ids = current_user.user... | true |
a47d2fe9e03a958d2f31ad47b06fc0f6141606fc | Ruby | amcaplan/passive_record | /db.rb | UTF-8 | 160 | 2.53125 | 3 | [] | no_license | require 'singleton'
class DB
include Singleton
def call(str)
"Calling database: #{str}".tap do |str|
puts str if ENV['DEBUG']
end
end
end
| true |
2d02b5022a9c4741445f02eeaeecde4e0b4efb89 | Ruby | dml/resque-timeframe | /lib/resque-timeframe/timeframe.rb | UTF-8 | 1,910 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'time'
module Resque
module Plugins
module Timeframe
WEEK = [ :sunday, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday ].freeze
def week
WEEK
end
def settings
@options ||= WEEK.inject({:default => true, :recurrent => 60}) {|c,v| c.merge({v => true})... | true |
a66e2ae35b7ae3b5e4299b2366c3163c084946b3 | Ruby | equivalent/code_katas | /recruiter_tests/coditytest/example1.rb | UTF-8 | 1,054 | 3.328125 | 3 | [] | no_license | require 'minitest/autorun'
class Foo
ExceededMaximum = Class.new(StandardError)
attr_reader :maximum
def initialize(maximum = 1_000_000_000)
@maximum = maximum
end
def solution(a, b)
Array
.new(a > b ? a : b)
.zip(a.to_s.chars,b.to_s.chars)
.flatten
.compact
.join
... | true |
dfa9b2601c1c5d11fb45d6598dae92cdd8290a63 | Ruby | tamia/word-finder | /sorting/sort_in_place.rb | UTF-8 | 259 | 3.328125 | 3 | [] | no_license | list = [5,4,3,2,1]
list = ["Tamia", "Michael", "Tam", "Dylan", "Ruby", "Dove", "Faye", "Chubby", "Christine", "Mark"]
p list
(list.size - 1).times do |i|
n_smallest = list.delete(list.min(i + 1).last)
list.insert(i, n_smallest)
p "#{i} -- #{list}"
end
| true |
008c64d44f1a1a8b57a14086ef6aab58fba0d67a | Ruby | marlitas/classroom_2105 | /lib/classroom.rb | UTF-8 | 513 | 3.65625 | 4 | [] | no_license | require 'pry'
class Classroom
attr_reader :subject, :capacity, :students
def initialize (subject, capacity)
@subject = subject
@capacity = capacity
@students = []
end
def add_student(student)
@students << student
end
def yell_at_students
uppercase_students = []
@students.each do |na... | true |
142244f2633224bf30613120a61e8da3223ffbb4 | Ruby | christycui/blackjack-webapp | /main.rb | UTF-8 | 4,517 | 3.046875 | 3 | [] | no_license | require 'rubygems'
require 'sinatra'
use Rack::Session::Cookie, :key => 'rack.session',
:path => '/',
:secret => 'notgonnatellyou'
BLACKJACK_AMT = 21
DEALER_HIT_MIN = 17
helpers do
def calculate_total(cards)
# calculate initial total
total = 0
card... | true |
671afd2076fb74f8d1a4e379266fb709e14a2d97 | Ruby | akchalasani1/myruby | /examples/Hash_newer_faster.rb | UTF-8 | 516 | 3.71875 | 4 | [] | no_license | # simply sets a default value for all elements in the hash.
=begin
As you can see, where a "my_normal" hash always returns nil by default,
specifying a default(ex:brown) in the Hash constructor will always return your
custom default for any failed lookup's on that hash instance.
=end
my_normal = Hash.new
was_not_there... | true |
21941519e793326b7a3e972263f7de8a1a9c9462 | Ruby | aduterte/ruby-oo-practice-has-many-through-template-dc-web-030920 | /app/models/user.rb | UTF-8 | 1,221 | 3.40625 | 3 | [] | no_license | #class for Model1 goes here
#Feel free to change the name of the class
class User
attr_reader :name
attr_accessor :age
@@all = []
def initialize(name, age)
@name = name
@age = age
@@all << self
end
def all_bookmarks
Bookmark.all.select do |bookmark_instance|
... | true |
df4b2c0458f40e1b9ad83a0382efed7d10ab8008 | Ruby | Juantontaco/zoot_server | /app/models/scooter.rb | UTF-8 | 311 | 2.625 | 3 | [] | no_license | class Scooter < ActiveRecord::Base
has_many :rides
def self.available_scooters
all.select do |scooter|
scooter.available?
end
end
def available?
is_available = true
self.rides.each do |ride|
is_available = is_available && !ride.active?
end
is_available
end
end
| true |
4a1f7c68655836ed80a5a792aac90b7396e8ced0 | Ruby | tonyalbor/twerk-tower-garage-door | /test2.rb | UTF-8 | 1,348 | 2.578125 | 3 | [] | no_license | require 'rubygems'
require 'json'
require "simple_oauth"
require 'oauth'
require 'pp'
consumer_key = OAuth::Consumer.new(
"TF2MfJkWtjkJ5a0fBzTF0Q",
"zh5zvSrd9DHFyd7VQecnTu3iTuUwbheYj9hilsKgUeQ")
access_token = OAuth::Token.new(
... | true |
b23d3575a2f9ac680c72584289fd8fe0768558e3 | Ruby | eknovoa/Programming_Foundations | /Small_Problems/reverse_it_part1.rb | UTF-8 | 1,642 | 4.78125 | 5 | [] | no_license | =begin
Problem
-write a method that takes one argument, a string, and returns a new string with the words in reverse order
Input:
-string
Output:
-new string in reverse order
Rules:
-do not use the reverse function for more of a challenge
Examples/Test cases
-puts reverse_sentence('') == '' => true
... | true |
9e68c5cba1911d17127cbae9cd093ddac7dac071 | Ruby | eddmoura/ruby-advanced-class-methods-lab-v-000 | /lib/song.rb | UTF-8 | 954 | 3.34375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive |
class Song
attr_accessor :name, :artist_name
@@all = []
def self.all
@@all
end
def save
self.class.all << self
end
def self.create
song = self.new
song.save
song
end
def self.new_by_name(name)
song = self.new
song.name = name
song
end
def self.create_by_name(name)
song = self.new... | true |
0b06ea9ec26663566353bf77f4ad00828d3d77da | Ruby | destradax/seekit | /app/models/quest.rb | UTF-8 | 1,788 | 3.328125 | 3 | [] | no_license | # [Attributes]
# * latitude: decimal - the latitude coordinate of the quest
# * longitude: decimal - the longitude coordinate of the quest
# * name: string - the name of the place this quest points to
# * address: string - the address of the place this quest points to
# * hint: string - a hint to help users find t... | true |
fa392251ada008a5451d432c6f5478f58a91c8e2 | Ruby | adrianmess/Ruby | /simple_sort.rb | UTF-8 | 120 | 2.984375 | 3 | [] | no_license | fruits = ["orange", "apple", "banana", "pear", "grapes"]
fruits.sort! { |first, second|
second<=> first}
puts fruits | true |
10fbc9b3eba9a72074de6bccd798cd358e7fcb35 | Ruby | alexandrafren/buyconsoles-cli-app | /buyconsoles/lib/buyconsoles/cli.rb | UTF-8 | 2,439 | 3.34375 | 3 | [
"MIT"
] | permissive | class Buyconsoles::CLI
def call
puts "Welcome to Buy Consoles! Which console brand would you like to see prices for today?"
list_console_brands
end
def list_console_brands
input = nil
puts "1. Sony 2. Microsoft 3. Nintendo"
while input != "exit"
input = gets.chomp
case input
... | true |
f9d5f902ea545230511197427ac5c3e39c8b2a99 | Ruby | JohnGeigerWS/regroup-online | /lib/omniauth/strategies/chms/client.rb | UTF-8 | 1,205 | 2.71875 | 3 | [] | no_license | require_relative 'connection'
module Chms
class Client
attr_writer :username, :password, :api_key
def initialize(args)
@username = args[:username]
@password = args[:password]
@api_key = args[:api_key]
@authenticated = false
@connection = Connection.new(api_key: api_key)
en... | true |
d297c15996d015fabbce0d51bc5d3e43fabdf41f | Ruby | rubycop/virus_total | /spec/virus_total/base_spec.rb | UTF-8 | 684 | 2.625 | 3 | [
"MIT"
] | permissive | require "virus_total"
describe VirusTotal::Base do
let(:resource_param) { "first, second" }
let(:base) { VirusTotal::Base.new(resource_param, "invalid_key") }
it "raises AuthError "\
"if you do not have the required priviledges" do
expect { base.api_response("url/scan") }.
to raise_error(VirusTot... | true |
2d11ba3128d6264d5fa02c63f4de0051f1b99c7d | Ruby | aimtiaz/YogiTrack | /app/models/employee.rb | UTF-8 | 175 | 2.515625 | 3 | [] | no_license | class Employee < ActiveRecord::Base
belongs_to :manager
def employee_full_name
"#{self.e_first_name} #{self.e_last_name}".split.map(&:capitalize).join(' ')
end
end
| true |
73654267f9a89acfd698abb5610420d4c4c90514 | Ruby | mvassaramo/anagram-detector-london-web-071618 | /lib/anagram.rb | UTF-8 | 190 | 3.125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Anagram
attr_accessor :word
def initialize(word)
@word = word
end
def match(list)
list.select {|word_in_list| word_in_list.split("").sort == word.split("").sort }
end
end
| true |
65ac642351b62d27d899622fe6de872f2ac6fe8f | Ruby | JeffLutzenberger/advent-of-code-2015 | /day4.rb | UTF-8 | 369 | 3.265625 | 3 | [] | no_license | require 'digest'
def first_n_zeros(n, str)
count = 0
str.chars.each do |c|
if c == '0'
count += 1
return true if count == n
else
return false
end
end
false
end
hd = ""
num = -1
key = "iwrupvqb"
while(!first_n_zeros(6, hd)) do
num += 1
hd = Digest::MD5.hexdigest("#{key}#{num}... | true |
078e2191c759b09d8c6d6bb995cbb4ea62fd24bc | Ruby | Rodion13/ProjectEuler | /done/8_largest_product_in_a_series.rb | UTF-8 | 825 | 3.9375 | 4 | [] | no_license | # Largest product in a series
# Problem 8
# The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.
# Find the thirteen adjacent digits in the 1000-digit number that have the greatest product.
# What is the value of this product?
# Rodion Yaryy
# https://projecteuler.... | true |
60ac9e4239ed4bdbf24e62ed00ce68173c76a5c6 | Ruby | angiebui/surveygorilla | /app/helpers/helper.rb | UTF-8 | 1,057 | 2.90625 | 3 | [] | no_license | helpers do
def current_user
if session[:id]
@current_user ||= User.find(session[:id])
end
end
# how to use helper ex:
# <%= partial(:_survey_answer_completed, question: question) %>
def partial(template, locals = {}, layout=false)
erb(template, :layout => layout, :locals => locals)
end
... | true |
a9f31ab1a20509aa08b00da11f5a96af7ecab70b | Ruby | ksilin/with_tempdir | /lib/with_tempdir.rb | UTF-8 | 1,886 | 3 | 3 | [
"MIT"
] | permissive | require_relative 'with_tempdir/version'
module WithTempdir
def with_tempdir(*filenames)
Dir.mktmpdir do |dir|
make_tempfiles(dir, filenames)
yield dir
end
end
def with_tempdir_and_files(*filenames)
Dir.mktmpdir do |dir|
files = make_tempfiles(dir, filenames)
yield(dir, files... | true |
2dc02584c04321bc56190a4dd10614493416bdff | Ruby | BrightSlap/phase-0-tracks | /ruby/santa.rb | UTF-8 | 2,646 | 3.65625 | 4 | [] | no_license | # define santa class
# method speak
# print "ho,ho,ho! haaappy holidays!"
# end
# eat_milk_and_cookies(cookie_type)
# @cookie_type = cookie_type
# prints "That was a good #{cookie_type}!"
# end
# initialize
# prints "Initializing Santa..."
# end
# define santa class
# method speak
# print "ho,ho,ho... | true |
a2a1eaad009e8a68e1acc4c529ec4170bca74436 | Ruby | nailetitah/thp-j19-morpion | /lib/app/grid.rb | UTF-8 | 1,632 | 3.109375 | 3 | [] | no_license | class Grid
attr_accessor :grid, :grid_table
@@grid = []
def self.create_grid
puts "Voici la table de jeu :"
@@grid = [['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9']]
@@grid_table = Terminal::Table.new :rows => @@grid
puts @@grid_table
end
def self.grid_changes_kv(x, y, choice)
@@grid[x][y].r... | true |
cf51b086c498aa81202c59d02fc2fbe0307dc26c | Ruby | koara/koara-rb | /lib/koara/token.rb | UTF-8 | 534 | 2.53125 | 3 | [
"Apache-2.0"
] | permissive | # encoding: utf-8
module Koara
class Token
attr_accessor :kind
attr_accessor :begin_line
attr_accessor :begin_column
attr_accessor :end_line
attr_accessor :end_column
attr_accessor :image
attr_accessor :next
def initialize(kind = 0, begin_line = nil, begin_column = nil, end_line = nil... | true |
3943361942967c5e2a1c65759788c0492dd4afb2 | Ruby | jnsya/ruby_puzzle_solutions | /lib/substrings_finder.rb | UTF-8 | 717 | 4.09375 | 4 | [] | no_license | dictionary = ["below","down","go","going","horn","how","howdy","it","i","low","own","part","partner","sit"]
def substrings(text, dictionary)
# first, scan the given text with each word in the dictionary and push
# any matches to the matched_elements array.
matched_elements = []
dictionary.each do |element|
... | true |
86e44c348f9b53478ba978e24544ea6879ac340e | Ruby | marcelocampanelli/onebitcodeRailsPuro | /escopo/global.rb | UTF-8 | 204 | 3.171875 | 3 | [] | no_license | class Bar
def foo
$global = 0
puts $global
end
end
class Baz
def qux
$global += 1
puts $global
end
end
bar = Bar.new
baz = Baz.new
bar.foo
baz.qux
baz.qux
puts $global | true |
1f28eacbb4aec52293df08baab04d850daa025bd | Ruby | vivianheleem/ch4_wt | /app/controllers/movies_controller.rb | UTF-8 | 1,463 | 2.53125 | 3 | [] | no_license | # in app/controllers/movies_controller.rb
# This file is app/controllers/movies_controller.rb
class MoviesController < ApplicationController
def index
@movies = Movie.all
end
def show
id = params[:id] # retrieve movie ID from URI route
@movie = Movie.find(id) # look up movie by unique ID
# will r... | true |
81c9e5523fa7fc0178335fc9ab6b5e522c313faa | Ruby | s-a-u/lessons | /lesson09/railway_station.rb | UTF-8 | 886 | 3.359375 | 3 | [] | no_license | class RailwayStation
attr_reader :station
attr_accessor :trains
@@instances = []
class << self
def all_stations
@@instances
end
end
def initialize(station)
@station = station
@trains = []
@@instances << @station
end
def add_train(train)
@trains << train
validate!
end... | true |
bef5eff5b95d62345389f59b3d612f6fed82421f | Ruby | deepujohn/Whats-App | /app/models/contact.rb | UTF-8 | 377 | 2.515625 | 3 | [] | no_license | class Contact < ActiveRecord::Base
validates :name,:email,:message,presence:true
validates :email,format: {with: /[A-Za-z0-9._]*\@[A-Za-z]*\.[A-Za-z]{2,5}/,message: "Enter a valid email"}
validates :name,length:{in: 3..30,message:"Not a name"}
validates :name,format: {with: /\A[a-zA-Z]+\z/,message: 'Only... | true |
440a132569b660701c643d1ff49691463aa1bec3 | Ruby | breeshiaturner/code | /inventory.rb | UTF-8 | 1,372 | 3.75 | 4 | [] | no_license | hash = {"Nike" => 30, "Rebok" => 20, "Converse" => 10, "Sketchers" =>3}
hash.each do |key, value|
puts "#{key} has #{value} shoes."
end
puts "Which item would you like to see?"
answer = gets.chomp.capitalize
def correct_answer(answer)
until answer == "Nike" || answer == "Rebok" || answer == "Converse" || answe... | true |
3c9b442961cd555cb728c7fe16565c4610a71d0b | Ruby | AJFaraday/smiff_music | /app/helpers/synths_helper.rb | UTF-8 | 1,916 | 3.109375 | 3 | [] | no_license | module SynthsHelper
BASE_NOTE_NAMES = %w{C D E F G A B}
BASE_NOTE_NAME_INDEXES = {
'C' => 0, 'D' => 2, 'E' => 4, 'F' => 5,
'G' => 7, 'A' => 9, 'B' => 11
}
VALID_NOTE_NAMES = %w(
C D E F G A B
C# D# E# F# G# A# B#
CB DB EB FB GB AB BB
)
DISPLAY_NOTE_NAMES = %W{C C# D D# E F F# G... | true |
f08990805a3edde76b19e9254e313b8740bfc005 | Ruby | silvamariaj/testing-automationCuRu | /features/step_definitions/cleanData_steps.rb | UTF-8 | 3,863 | 2.515625 | 3 | [] | no_license | require_relative '../../page-object/division_nav_page'
require_relative '../../page-object/schedule_request'
require_relative '../../page-object/interview_profile_page'
require_relative '../../page-object/exercises_page'
require_relative '../../page-object/candidate_page'
Given(/^that I login into the InterviewApp as... | true |
dbb19b0be9e788e8a29297741ef56d8ee2813857 | Ruby | guneybilen/bzr | /app/models/article.rb | UTF-8 | 1,704 | 2.765625 | 3 | [] | no_license | class Article < ActiveRecord::Base
#validates_presence_of :title, :body
validates :title, :body, presence: true # there is nothing wrong here. Tested!
belongs_to :user
simple_search :body
before_save :clean_data, :remove_nbsp
has_attached_file :image1, :styles => {
:thumb => '50x50>',
:squ... | true |
9db420100d168722320f84653a6121522dc96150 | Ruby | EricRicketts/LaunchSchool | /exercises/Ruby/small_problems/easy/two/fifth_exercise.rb | UTF-8 | 505 | 4.5 | 4 | [] | no_license | require 'byebug'
=begin
Greeting A User
Write a program that will ask for user's name. The program will then greet the user. If the user writes "name!" then the computer yells back to the user.
Examples
What is your name? Bob
Hello Bob.
What is your name? Bob!
HELLO BOB. WHY ARE WE SCREAMING?
=end
def greet_user
... | true |
481acbab456f1972987e48d1961b50d4d718f0ff | Ruby | global-step/firebase_token_auth | /lib/firebase_token_auth/public_key_manager.rb | UTF-8 | 1,227 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'openssl'
require 'net/http'
module FirebaseTokenAuth
class PublicKeyManager
PUBLIC_KEY_URL = 'https://www.googleapis.com/robot/v1/metadata/x509/securetoken@system.gserviceaccount.com'.freeze
attr_accessor :public_keys, :expire_time
def initialize
fetch_publickeys_hash
end
def ref... | true |
a4f8e474e20e905fdff194e39de35df7ce4a26f8 | Ruby | Mariana-21/launchschool_v2 | /101_109_small_problems/easy_4/10_number_to_signed_string.rb | UTF-8 | 663 | 4.1875 | 4 | [] | no_license | # number_to_signed_string.rb
def integer_to_string(number)
string_arr = []
loop do
string_arr.unshift(number % 10)
number = number / 10
break if number <= 0
end
string_arr.join('')
end
def sign(number)
if number > 0
'+'
elsif number < 0
'-'
else
''
end
end
def signed_integer_t... | true |
f7f026aac901bb5e60e619cc15aef0d24fb53225 | Ruby | h4hany/yeet-the-leet | /algorithms/Hard/1326.minimum-number-of-taps-to-open-to-water-a-garden.rb | UTF-8 | 1,928 | 3.46875 | 3 | [] | no_license | #
# @lc app=leetcode id=1326 lang=ruby
#
# [1326] Minimum Number of Taps to Open to Water a Garden
#
# https://leetcode.com/problems/minimum-number-of-taps-to-open-to-water-a-garden/description/
#
# algorithms
# Hard (43.83%)
# Total Accepted: 12.5K
# Total Submissions: 28.5K
# Testcase Example: '5\n[3,4,1,1,0,0]'
... | true |
338ef59eb44d067561d6af3d42f174ca13411417 | Ruby | BeeHam/epicodus-contacts | /spec/email_spec.rb | UTF-8 | 972 | 2.875 | 3 | [] | no_license | require('rspec')
require('contacts')
require('email')
describe('Email') do
describe('#address') do
it("returns the email address of the contact") do
test_email = Email.new("johnsmith@123.com", "work")
expect(test_email.address()).to(eq("johnsmith@123.com"))
end
end
describe('#type') do
... | true |
40d8c29f8cb8912b92a6bea10515a8354fbf9f09 | Ruby | makandra/gemika | /lib/gemika/matrix/travis_config.rb | UTF-8 | 1,064 | 2.59375 | 3 | [
"MIT"
] | permissive | module Gemika
class Matrix
##
# Load `.travis.yml` files.
#
# @!visibility private
#
class TravisConfig
class << self
def load_rows(options)
path = options.fetch(:path, '.travis.yml')
travis_yml = YAML.load_file(path)
rubies = travis_yml.fetch('rvm... | true |
a17e1d007cbfc824456fd721ed014798edf2ae89 | Ruby | marmo002/how_to_test_robot | /test_robot.rb | UTF-8 | 2,183 | 2.90625 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './robot.rb'
class TestRobot < MiniTest::Test
def setup
@robot = Robot.new
end
def teardown
@robot = nil
end
def test_that_foreign_robot_needing_repairs_sent_to_station_1
# arrange
@robot.needs_repairs = true
@robot.foreign_m... | true |
68f4accccf2defb56c279eb02de7ff59eab7cba9 | Ruby | jdantonio/polyglot | /algorithms.rb/lib/algorithms/catalog.rb | UTF-8 | 15,723 | 3.390625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Algorithms
# A collection of key/value pairs similar to a hash but ordered.
# Access is via index (like an array) rather than by key (like a
# hash). Supports duplicate keys. Indexing starts at zero.
class Catalog
include Enumerable
# Create a new Catalog from the given data. When +data+ is nil... | true |
379ba86c98ed93a09d37d7ad0cf2b162b61f14a2 | Ruby | foxnewsnetwork/painful_translate | /lib/painful_translate/client.rb | UTF-8 | 751 | 2.671875 | 3 | [
"MIT"
] | permissive | class PainfulTranslate::Client
class NoTargetLanguage < StandardError; end
class << self
def instance
@instance ||= new
end
end
def translate(*keys, options)
opts = _normalize options
PainfulTranslate::GoogleTranslator.new.tap do |t|
t.strings = keys
t.to = opts[:to]
t.... | true |
4fc8d88d60b570d5d23115772d03353cc654324a | Ruby | praser/imoveis-caixa | /src/utils/file_manager.rb | UTF-8 | 313 | 2.90625 | 3 | [] | no_license | module Utils
# Manages a file directory
class FileManager
EXCEPT = ['.', '..', '.keep'].freeze
def initialize(path)
@path = path
end
def clear_folder
Dir.foreach(@path) do |file|
File.delete(File.join(@path, file)) unless EXCEPT.include? file
end
end
end
end
| true |
d0d5aed5abf87045b50d2fc2a463c94bca3ce2a7 | Ruby | Kapranov/health-data-standards | /lib/health-data-standards/import/cda/section_importer.rb | UTF-8 | 9,080 | 2.703125 | 3 | [
"Apache-2.0"
] | permissive | module HealthDataStandards
module Import
module CDA
class SectionImporter
attr_accessor :check_for_usable, :status_xpath, :code_xpath
include HealthDataStandards::Util
include LocatableImportUtils
def initialize(entry_finder)
@entry_finder = entry_finder
... | true |
11c60dcde924b53b9e00fb0adae74a41c8b221d9 | Ruby | DevonTubben/Nba_cli_project | /lib/nba_cli_project/cli.rb | UTF-8 | 2,681 | 3.484375 | 3 | [
"MIT"
] | permissive | class CLI
def start
puts " "
puts "Welcome NBA fan:"
puts " "
puts "What name would you like us to call you by?"
puts " "
API.get_nba_players
binding.pry
introduction(user_input)
end
def user_input
gets.strip
end
... | true |
21847055bad8245ec0fdc042e4645ce12ea164f3 | Ruby | rbarisic/rrpg | /lib/camera.rb | UTF-8 | 1,125 | 3.265625 | 3 | [] | no_license | module RRPG
class Camera
attr_accessor :x, :y, :z, :focus, :offset_x, :offset_y
def initialize(viewport_width, viewport_height)
@x = 0
@y = 0
@speed = 1
@viewport_width = viewport_width
@viewport_height = viewport_height
... | true |
edfe8de5fd50f71bc136213b2100dc1253bd2013 | Ruby | garyferns/ruby_fundamentals1 | /exercise4.rb | UTF-8 | 213 | 3.21875 | 3 | [] | no_license |
count = 1.0
while count<=100
if count % 15 == 0
puts "Bitmaker"
elsif count % 3 == 0
puts "Bit"
elsif count % 5 == 0
puts "maker"
else
puts "#{count}"
end
count += 1.0
end
| true |
ea308bcd7a85971a9994e1e412792f0e33eafab8 | Ruby | rlm33/ic_decrypt | /benchmark.rb | UTF-8 | 941 | 2.53125 | 3 | [] | no_license | require 'benchmark'
$decrypter = "./decrypter"
$to_test = %w{alpha gamma light pulse zoned}
def ic_decrypt to_test, domain, numthreads=nil, mpi=false
system("#{"mpirun -np #{numthreads} -machinefile hosts" if mpi} #{$decrypter} #{to_test} -d #{domain} #{"-p -n #{numthreads}" if numthreads} > log_benchmark.txt 2> er... | true |
1ba275da588295940ff0bd9181a1294bd140aa12 | Ruby | bk2204/adventofcode-work | /2015/d11 | UTF-8 | 928 | 3.046875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby
module AdventOfCode
module D11
class PasswordGenerator
def next(s)
s = s.dup
s.next!
while !valid?(s)
s.next!
end
s
end
def valid?(s)
%w(i o l).each { |c| return false if s.include? c }
return false unless three_... | true |
9fdd49c8e508bd03489a89d64cd97d4d987b29fd | Ruby | y0una/phase-0-tracks | /ruby/method_detective.rb | UTF-8 | 1,603 | 3.5625 | 4 | [] | no_license | # Replace in the "<???>" with the appropriate method (and arguments, if any).
# Uncomment the calls to catch these methods red-handed.
# When there's more than one suspect who could have
# committed the crime, add additional calls to prove it.
#########
"iNvEsTiGaTiOn".swapcase
# => “InVeStIgAtIoN”
"OoNaMaNaPiA".swap... | true |
f43d15434e217dfc5b79c310b0f4a4f886b969a0 | Ruby | Nims09/Problems | /Ruby/MissingNumbers.rb | UTF-8 | 861 | 3.21875 | 3 | [] | no_license | count_missing = 0
count_full = []
array_missing = 0
array_full = []
hash_missing = Hash.new
missing_values = Array.new
ARGF.each_with_index do |line, index|
if index == 0
count_missing = line.to_i
elsif index == 1
array_missing = line.split(" ")
elsif index == 2
count_full = line.... | true |
7330c5f4d8d3ee3526577cad81661d04ebdd9e80 | Ruby | skkmania/ctree | /ctree.rb | UTF-8 | 3,425 | 2.859375 | 3 | [] | no_license | #!/usr/bin/env ruby
# -*- coding:utf-8 -*-
# ctree.rb
require 'pathname'
require Pathname(__FILE__).expand_path.dirname.to_s + '/ctracer.rb'
class Node
attr_accessor :value, :child, :parent, :prev_move, :mylevel
def initialize value:nil, child:nil, parent: nil, prev_move:nil, mylevel:nil
@value = (value ? val... | true |
2de51decf9b84187e3c2a9ca91f8c8100230cfc8 | Ruby | kmccarthy623/wdi_kmcc | /ex13.rb | UTF-8 | 1,229 | 4.5625 | 5 | [] | no_license | # #Exercise 13
# first, second, third = ARGV
# puts "This script is called: #{($0)}"
# puts "Your first variable is: #{first}"
# puts "Your second variable is: #{second}"
# puts "Your third variable is: #{third}"
#Extra Credit
# Try giving fewer than three arguments to your script. What values are used for the m... | true |
967d0e4b57cad213239735d1198bbd9e913faa98 | Ruby | suryafn/GBE01164 | /Modul-4/sesi-3/app.rb | UTF-8 | 2,007 | 2.515625 | 3 | [] | no_license | require 'sinatra'
require_relative 'db_connector'
require_relative 'controllers/item_controller'
require_relative 'controllers/category_controller'
get '/' do
controller = Item_controller.new
controller.list_items
end
get '/items/new' do
controller = Item_controller.new
controller.new_item
end
post '... | true |
885817bb6a03bc1702fa9f33e87e79fde3fd1de6 | Ruby | jbaxter6/ruby-enumerables-hash-practice-emoticon-translator-lab-wdc01-seng-ft-060120 | /lib/translator.rb | UTF-8 | 945 | 3.359375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # require modules here
require 'pry'
require "yaml"
def load_library(file_path)
# code goes here
emoticon_library = YAML.load_file(file_path)
# binding.pry
emoticon_library.each_with_object({}) do |(key, value), final_hash|
# binding.pry
final_hash[key] = {
:english => value[0],
:japanes... | true |
7a277f2664c10866d7d69ddc8464a613dc7618d4 | Ruby | Arepo/rails-blog | /spec/features/tags_spec.rb | UTF-8 | 2,448 | 2.609375 | 3 | [] | no_license | require 'rails_helper'
describe "Tags", type: :feature do
context "Home page" do
before do
given_multiple_posts_exist
when_i_visit_the_homepage
end
scenario "Displaying all tags" do
then_i_should_see_all_their_tags
end
scenario "Linking to post by tag", js: true do
and_... | true |
956c276ad80b46c9d8be087f345f56fa43519d0e | Ruby | compwron/pairSee | /lib/pair_see/pair_recency.rb | UTF-8 | 881 | 2.640625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module PairSee
class PairRecency
def initialize(log_lines, card_prefixes, people)
@log_lines = log_lines
@card_prefixes = card_prefixes
@people = people
end
def pair_recency
pairing_events = @people.map do |current_person|
my_commits = @log_lines.select { |ll| ll.authored_... | true |
54f77bbe7a5a56f70d317c976389ebc858b68778 | Ruby | Davide1988/week_3_week_end_homework_codeclan_cinema_sql_modules_many_to_many | /modules/screening.rb | UTF-8 | 995 | 3.015625 | 3 | [] | no_license | require('pry')
require_relative('../db/sql_runner')
require_relative('./film')
class Screening
attr_reader :id
attr_accessor :timing, :film_id, :seating
def initialize( options )
@id = options['id'].to_i if options['id']
@timing = options['timing']
@seating = options['seating'].to_i
@film_id = ... | true |
7a593da959b69253faa43ba2a093ca99245cbed6 | Ruby | davidhuff2014/tlwebdevl3 | /main.rb | UTF-8 | 5,378 | 3.046875 | 3 | [] | no_license | # encoding: UTF-8
require 'rubygems'
require 'sinatra'
require 'sinatra/reloader'
# require 'pry'
set :sessions, true
BLACKJACK_AMT = 21
DEALER_MIN_HIT = 17
helpers do
def calc_total(cards)
arr = cards.map { |e| e[1] }
total = 0
arr.each do |value|
if value == 'A'
total += 11
elsif... | true |
398ec17ad6ac5808ee421c42cc8aceb82047d3fd | Ruby | wrumble/airport_challenge | /spec/weather_spec.rb | UTF-8 | 416 | 2.78125 | 3 | [] | no_license | require "weather"
describe Weather do
subject(:weather) { described_class.new }
describe "#stormy?" do
it "returns false when weather isnt stormy" do
allow(weather).to receive(:rand) { 0.5 }
expect(subject.stormy?).to be false
end
it "returns true when weather is stormy" do
allow(... | true |
cb7e9b919770e5740bc7fc18255aaecbf6ff1bda | Ruby | DannyBen/minichart | /lib/minichart/charts/line_chart.rb | UTF-8 | 543 | 2.78125 | 3 | [
"MIT"
] | permissive | module Minichart
class LineChart < Chart
def build
element :polyline, fill: :none,
stroke: options[:color],
stroke_width: options[:stroke],
stroke_linejoin: :round,
stroke_linecap: :round,
points: points
end
protected
def points
result = []
inv... | true |
17459c437f4bd440994700d3c80600124d100723 | Ruby | PoisonuosHeart/RubyLab | /Lab3/scrpt1.rb | UTF-8 | 1,753 | 3.796875 | 4 | [] | no_license | $f # Файловая переменная
def open_f(f_name) #true - если файл открыт, иначе - false
if(File.exists?(f_name))
$f = File.open(f_name)
return true
else return false
end
end
#Возвращает 3 слово из строки str или nil
def get3word(str)
howSpace = 0
i = 0
tmp_str = ""
str.size.t... | true |
ee624801a0f9c171fc1a243caf8ae8d3fefdebb4 | Ruby | clyeager/programming_foundations | /lesson_3/hard_1.rb | UTF-8 | 411 | 3.171875 | 3 | [] | no_license | #1
nil
#2
{:a=>"hi there"}
#3
A. "one is: one"
"two is: two"
"three is: three"
B. "one is: one"
"two is: two"
"three is: three"
C."one is: two"
"two is: three"
"three is: one"
#4
def dot_separated_ip_address?(input_string)
dot_separated_words = input_string.split(".")
while dot_separated_words.size == 4 do
... | true |
ccf5a2f58dcdf0cd7c6c9978331af7300103365c | Ruby | frc-frecon/frecon | /lib/frecon/base/object.rb | UTF-8 | 485 | 2.625 | 3 | [
"MIT"
] | permissive | # lib/frecon/base/object.rb
#
# Copyright (C) 2014 Christopher Cooper, Sam Craig, Tiger Huang, Vincent Mai, Sam Mercier, and Kristofer Rye
#
# This file is part of FReCon, an API for scouting at FRC Competitions, which is
# licensed under the MIT license. You should have received a copy of the MIT
# license with this ... | true |
b162fca944a5fb139ba65e90371c4447412b993e | Ruby | jbranham1/tee_vee | /lib/network.rb | UTF-8 | 902 | 3.515625 | 4 | [] | no_license | class Network
attr_reader :name,
:shows
def initialize(name)
@name = name
@shows = []
end
def add_show(show)
@shows << show
end
def main_characters
@shows.each_with_object([]) do |show, array|
array << show.get_main_characters
end.flatten
end
def actors_by_sho... | true |
ca4a8e543f924eb3cade2d74dc6979eb93d36d9a | Ruby | thitoribeiro/testing | /older/cucumber_test/tests/features/step_definitions/scenario.rb | UTF-8 | 555 | 2.953125 | 3 | [] | no_license | Dado("que eu tenho {int} laranjas") do |valor1|
puts valor1
@laranja = valor1
end
Quando("eu como {int} laranjas") do |valor2|
puts valor2
@comer = valor2
@resultado = @laranja - @comer
end
Então("eu vejo quantas laranjas sobraram.") do
puts @resultado
expect(@resultado).to eq 8
end
Quando("eu c... | true |
5812611e6258c7ffb13cd4e83c11b4d4a0189909 | Ruby | OPR-A-RUBY/I-m_student | /braun=split_abort_.rb | UTF-8 | 613 | 3.171875 | 3 | [] | no_license | # coding: utf-8
#
# system('reset') # Windows
system('clear') # Linux
print "Пожалуйста, введите температуру и шкалу (C или F): "
str = gets
exit if str.nil? or str.empty?
str.chomp!
temp, scale = str.split(" ")
abort "#{temp} - это недопустимое число." if temp !~ /-?\d+/
temp = temp.to_f
case scale
when "C", "... | true |
197d9b8c233b0992b24a76a4262c69aefa919640 | Ruby | dirtyhero/twitter_flow | /config.rb | UTF-8 | 251 | 2.703125 | 3 | [] | no_license | require 'json'
class Config
def initialize
open("config.json") do |io|
json = JSON.load(io)
@mail = json["mail"]
@pass = json["pass"]
end
end
def pass
return @pass
end
def mail
return @mail
end
end
| true |
834c0d99ef3cb2bfc21d0dfa1062c2828b232cf7 | Ruby | art-solopov/challenges | /arangodb_blog_ruby/lib/arangodb/collection.rb | UTF-8 | 335 | 2.546875 | 3 | [
"Unlicense"
] | permissive | module ArangoDB
class Collection
def initialize(name)
@name = name
res = ArangoDB.connection.get("collection/#{name}")
if res.success?
@persisted = true
@type = res.body['type']
end
end
attr_accessor :name, :persisted, :type
def persisted?
@persisted
... | true |
519bce6fcbbabfbd843f1cb206b552bce5f40c8e | Ruby | niklaslong/epicodus-lessons | /Ruby/train/lib/city.rb | UTF-8 | 741 | 2.625 | 3 | [] | no_license | require 'securerandom'
module City
def self.all
DB.exec("SELECT * FROM cities;").to_a
end
def self.timetable
stuff = DB.exec("SELECT * FROM trains_cities;")
end
def self.save(name)
uuid = SecureRandom.uuid
DB.exec("INSERT INTO cities (id, name) VALUES ('#{uuid}', '#{name}') RETURNING id;")[... | true |
09db763d9f6b05b4b95c50e1b2bd3713fe8d8cb5 | Ruby | vaginessa/Jekyll-v3.0.3-Portable | /ruby/lib/ruby/gems/2.1.0/gems/predicated-0.2.6/lib/predicated/string_utils.rb | UTF-8 | 614 | 2.75 | 3 | [] | no_license | module Predicated
module StringUtils
#Ripped from activesupport.
#If I start using a bunch of code from that project I'll create a dependency.
#I hope this is not bad form.
def self.underscore(camel_cased_word)
camel_cased_word.to_s.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1... | true |
fcf8df399c3e4b323349d6822a59befaccf1f70b | Ruby | RajinV/friendly-bakery | /cake.rb | UTF-8 | 747 | 3 | 3 | [] | no_license | class Cake
attr_accessor :name
attr_accessor :amount
attr_accessor :price
attr_accessor :status
attr_accessor :description
def initialize(name, amount, price, status, description)
@name = name
@amount = amount
@price = price
@status = status
@description = description
end
end
@@wedding = Cake... | true |
073c01ff27a1e19a2a8e0f5e304f280854c284a0 | Ruby | AlexRoadsign/Serie_exercices_Ruby | /exo_23.rb | UTF-8 | 556 | 3.28125 | 3 | [] | no_license | # Pyramide illuminati
puts "Combien d'étages voulez vous dans votre pyramide?"
print "> "
floor = "#"
number_floors = gets.to_i
number_spaces = number_floors - 1
lenght_spacing = " " * number_spaces
n = 0
if number_floors > 25
puts "La pyramide s'est effondrée, désolé"
exit
end
puts "Voici votre pyramide"
while ... | true |
2edd3407d00aa7392391291d2938890d2976607a | Ruby | Zamyatin/ProjectEuler | /2_recursive.rb | UTF-8 | 491 | 3.671875 | 4 | [
"MIT"
] | permissive | # def is_fibonacci?(num)
# fibonacci_array = [0,1]
# while (fibonacci_array[-1] < num)
# fibonacci_array << fibonacci_array[-1] + fibonacci_array[-2]
# end
# fibonacci_array[-1] == num ? true : false
# end
def sum_the_lies(max_num, fib_array = [0, 1])
next_num = fib_array[-1] + fib_array[-2]
if next_... | true |
cc1e4853b84f16905c0ebe278596e2cb7c7d2725 | Ruby | pezholio/tenk | /lib/configuration.rb | UTF-8 | 824 | 2.8125 | 3 | [
"MIT"
] | permissive | require 'logger'
module Tenk
# Holds the configuration for a Tenk client (API key and base URL, and logger)
class Configuration
attr_accessor :token
attr_writer :api_base
attr_writer :logger
# Intialize a Tenk::Configuration
# @param opts [Hash] the configuration options
def initialize(opt... | true |
340aed6aeafcbd36d7b7f2f2bb8f735a1ec027c7 | Ruby | digitaIfabric/21daycodingchallenge | /ruby/challenge10.rb | UTF-8 | 909 | 3.078125 | 3 | [] | no_license | # spots = [
# ['s', 's', 's', 'S', 'R', 'M'],
# ['s', 'M', 's', 'S', 'R', 'M'],
# ['s', 'M', 's', 'S', 'R', 'm'],
# ['S', 'r', 's', 'm', 'R', 'M'],
# ['S', 'r', 's', 'm', 'R', 'M'],
# ['S', 'r', 'S', 'M', 'M', 'S'],
# ]
# vehicle = 'regular'
def w... | true |
fe39634c459348b1ebfbd8fcd4fc4df670571e1d | Ruby | sbrauer/traversa | /demo/hello.rb | UTF-8 | 655 | 3.0625 | 3 | [
"MIT"
] | permissive | # A trivial single-file Traversa demo app.
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'traversa'
class HelloResource
attr_reader :name, :parent
def initialize(name, parent)
@name = name
@parent = parent
end
def get(app, request, params)
"<h1>Hello #{name}!</h1>"
end
end
... | true |
28be063180f80600c906f3756324e55cf34070a0 | Ruby | rsnorman/avengersassemble | /app/models/team.rb | UTF-8 | 1,089 | 2.5625 | 3 | [] | no_license | # Models a team and its stats
#
# Database
# t.string "name", null: false
# t.text "description"
# t.integer "total_experience", default: 0, null: false
# t.integer "total_fighting", default: 0, null: false
# t.integer "total_strength", default: 0, null: false
# ... | true |
0333ffda89d3ca17cce46643983d1097e03c9a7f | Ruby | amZotti/Ruby-challenges | /composite_pattern_implementation.rb | UTF-8 | 1,657 | 3.828125 | 4 | [] | no_license | #Component class
class JuicingRoutine
attr_reader :task
def initialize(task)
@task = task
end
def time
0.0
end
end
#Leaf class
class AssembleJuicer < JuicingRoutine
def initialize
super ("Assembling all parts into juicer")
end
def time
1
end
end
class JuiceVegetables < JuicingRouti... | true |
c0908e6841b59d2ad3ce9e5dc3559744ef225388 | Ruby | jeff-gosselin/ruby-objects-has-many-through-lab-dumbo-web-121018 | /lib/artist.rb | UTF-8 | 481 | 3.359375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Artist
@@all = []
attr_accessor :name
def initialize(name)
@name = name
@@all << self
end
def new_song(title, genre)
Song.new(title, self, genre)
end
def songs
Song.all.select do |song|
song.artist == self
end
end
def genres
Song.all.map do |song|... | true |
997e7a4b892f21ada6ce1f27e65a041dec7cfd0c | Ruby | niku/classx | /bench/attribute_get.rb | UTF-8 | 2,290 | 2.703125 | 3 | [
"Ruby"
] | permissive | require 'benchmark'
$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib' )))
require 'classx'
class PointWithClassX
include ClassX
has :x
has :y
has :z
end
class PointWithoutClassX
attr_reader :x, :y, :z
def initialize hash
@x = hash[:x]
@y = hash[:y]
@z = hash[:z... | true |
efb3e34c3dd7e835c72dc66da68f8c8523cf00d6 | Ruby | guorui9016/ruby | /task34.rb | UTF-8 | 247 | 3.53125 | 4 | [] | no_license | # Compare only last 10 characters of 2 strings
str1 = 'This is ABCD world'
str2 = 'My abcd World'
if str1.downcase.match?(str2.slice(-10..-1).downcase, -10)
p 'the last 10 characters are same'
else
p 'the last 10 characters are not same'
end
| true |
42338d9611ad34f8d93080bc0907c5f0b1441025 | Ruby | wrburgess/castle-1 | /scripts/timer | UTF-8 | 677 | 2.8125 | 3 | [] | no_license | #!/usr/bin/env ruby
begin
require 'terminal-notifier'
rescue LoadError
puts 'You need to gem install terminal-notifier'
exit 1
end
minutes = ARGV[0] || 15
seconds = minutes.to_i * 60
message = ARGV[1] || "You should probably make a commit right now"
if ARGV[0].nil? || ARGV[0] == "help"
puts "example:"
put... | true |
a4cfaaf5a242abda0c01cc78918fa081f06078fe | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/triangle/71a10ba38cf44970a58d4987c74a6a3c.rb | UTF-8 | 627 | 3.453125 | 3 | [] | no_license | class Triangle
def initialize(*args)
@sides = args
raise TriangleError if bad_input?
end
def kind
result = @sides.each_with_object(Hash.new(0)) {|side, sum| sum[side] += 1}
return :equilateral if result.values.include?(3)
return :isosceles if result.values.include?(2)
:scalene
end
... | true |
10430685fac6419a8d709a2ffa3447799628c46d | Ruby | phokz/ruby-agi | /lib/ruby-agi/return_status/answer.rb | UTF-8 | 552 | 3.296875 | 3 | [] | no_license | class ReturnStatus
end
#
# Usage: ANSWER
# Answers channel if not already in answer state. Returns -1 on
# channel failure, or 0 if successful.
#
class Answer < ReturnStatus
def to_s
result
end
def == (obj)
obj.to_s == result
end
private
def result
if @result.nil?
rgx = Regex... | true |
3ac4c32cc0e0b14058989ea821a85b4eeece8083 | Ruby | amitzur/Budget-Requests-New | /lib/tasks/bakasha_finalizer.rake | UTF-8 | 2,594 | 2.71875 | 3 | [] | no_license | desc "Find identical Bakashas and create FinalBakasha"
task :finalize => :environment do
puts "Finalizing Bakashas..."
log = { :skipped => [], :processed => {}}
scans = Scan.all
scans.each do |s|
if s.bakashas_count < 2
log[:skipped] << s.id
next
end
found = false
log_scan = log[:pr... | true |
af5438cbc1d07bd74b8ef2a334b72d7906b38395 | Ruby | leifand/Ruby-rails | /gold/app/controllers/rpg_controller.rb | UTF-8 | 1,340 | 2.8125 | 3 | [] | no_license | class RpgController < ApplicationController
def random_gold(min, max)
return rand(max-min) + min
end
def index
# not much to see here! so cool ...
session[:gold] ||= 0
session[:activities] ||= []
end
def process_gold
activity = params[:activity]
activity_string = ""
gold = 0;
... | true |
53c45b28e4d04f55d701dfc6b89d8d7b3b8a1c94 | Ruby | streadway/katas | /cameron/8/compounds/lib/compound_finder.rb | UTF-8 | 617 | 3.5 | 4 | [
"MIT"
] | permissive | class CompoundFinder
attr_reader :dictionary
def initialize(dictionary)
@dictionary = dictionary
end
def list
candidates = dictionary.words_of_exact_length(6)
candidates.select{|c| can_be_split?(c) }
end
def sub_words(word)
subs = []
subs << [word[0..0], word[1..-1]]
subs << [... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.