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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
2794debb67d1036691346d7923d3f9193575cb3f | Ruby | dcparker/dcas-ruby | /lib/dcas.rb | UTF-8 | 7,679 | 2.65625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'ftools'
module DCAS
TESTING = false
BUCKET_HOST = 'ftp.ezpaycenters.net'
DEFAULT_OUTGOING_BUCKET = 'outgoing' # The return files coming back to us.
DEFAULT_INCOMING_BUCKET = 'incoming' # The payment files we're sending TO dcas.
STAGING_BUCKET = 'staging'
DEFAULT_CACHE_LOCATION = 'EFT'
class <<... | true |
67b80b72c87dad0cb7ae6d55a68aaafd794d2354 | Ruby | chrislo/data_intensive_blog | /app.rb | UTF-8 | 817 | 2.890625 | 3 | [] | no_license | require 'sinatra'
require 'json'
def logfile
File.join(File.dirname(__FILE__), 'log', 'event.log')
end
def event_log
@event_log ||= Logger.new(logfile)
@event_log.formatter = proc do |severity, datetime, progname, msg|
{time: datetime}.merge(msg).to_json + "\n"
end
@event_log
end
def log(data)
even... | true |
7d7dd54452c721972efc8e0ff32840de4256b231 | Ruby | MFQ/citibike-nyc | /lib/citibikenyc/station_information.rb | UTF-8 | 786 | 2.6875 | 3 | [] | no_license | class StationInformation
attr_reader :station_id, :name, :short_name, :lat, :lon, :region_id, :rental_methods, :capacity, :rental_url, :eightd_has_key_dispenser, :has_kiosk
def initialize()
@station_id = @name = @short_name = @lat = @lon = @region_id = @rental_methods = @capacity = @rental_url = @eightd_has_ke... | true |
3a5c36786152a1f63fe46c25647bdd5a1e7e5e0a | Ruby | willryan/pattern-proc | /spec/lib/object_method_spec.rb | UTF-8 | 2,655 | 3.296875 | 3 | [
"MIT"
] | permissive | require 'pattern-proc'
include PatternProc::TestMethods
class TestObjectClass
include PatternProc::ClassMethods
def my_func(a,b,c)
raise "don't call me"
end
pattern(:p_func).with(3,2).returns(5)
pattern(:p_func).with do |x,y| x * y end
end
class TestSingletonClass
class << self
include PatternPro... | true |
b5e1455f61e84ecf3e12d8a4cbb3c42d723b56a5 | Ruby | howardbdev/ruby-music-library-cli-v-000 | /lib/song.rb | UTF-8 | 1,886 | 3.234375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Song
include Concerns::Findable
attr_accessor :name, :genre
attr_reader :artist
@@all = []
def initialize(name, artist = nil, genre = nil)
@name = name
self.artist=(artist) unless artist == nil
self.genre = genre unless genre == nil
end
def artist=(artist)
... | true |
e84dbe26ebce5ce0462e8dc49f70a80ae101db3e | Ruby | colinpetruno/olympus_framework | /app/models/companies/finder.rb | UTF-8 | 677 | 2.5625 | 3 | [] | no_license | module Companies
class Finder
def self.by_domain(domain)
new(domain: domain).by_domain
end
def self.open_for_signups(domain)
new(domain: domain).open_for_signups
end
def initialize(domain: nil)
@domain = domain
end
def by_domain
Company.find_by(hashed_email_domai... | true |
47baa9f21c232aa2efa4702e22b1d50c7d517666 | Ruby | nathanielgreen/battleships | /spec/ship_spec.rb | UTF-8 | 1,061 | 3.125 | 3 | [] | no_license | require 'ship'
# has a position when created /
# can be hit
# will record number of hits
# can be missed
# will not be hit when it is missed
# is not sunk initially /
# can be sunk
describe Ship do
let(:player) { Player.new }
it 'should not be initially sunk' do
ship = Ship.new
expect(ship... | true |
164797bfed239b55014e36c93bc665cee24e7e9b | Ruby | lkhedlund/lighthouse-labs | /activerecord_store/exercises/exercise_6.rb | UTF-8 | 904 | 2.96875 | 3 | [] | no_license | require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
require_relative './exercise_4'
require_relative './exercise_5'
puts "Exercise 6"
puts "----------"
# Your code goes here ...
@store1.employees.create(first_name: "Jim", last_name: "Tank", hourl... | true |
3616465a552dcc7c5ac3c8f488c93b865d486740 | Ruby | eric2523/aA_homework | /w3d5/diy_adts.rb | UTF-8 | 1,283 | 3.65625 | 4 | [] | no_license | class Stack
attr_reader :stack
def initialize
@stack = []
end
def push(el)
stack.push(el)
end
def pop
stack.pop
end
def peek
stack.first
end
end
class Queue
attr_reader :queue
def initialize
@queue = []
end
def enqu... | true |
84ed3d9cc57cde25b09a9d081059bce7d3cd00ea | Ruby | nog/atcoder | /contests/arc140/b/main.rb | UTF-8 | 1,203 | 3.078125 | 3 | [] | no_license | N = gets.to_i
S = gets.chomp
s = S.dup
list = s.scan(/A+RC+/)
counts = list.map do |str|
if str.size == 3
next 1
end
ac = str.count('A')
cc = str.count('C')
next ac < cc ? ac : cc
end
hash = {}
counts.each do |c|
hash[c] ||= 0
hash[c] += 1
end
counts = hash.to_a.sort
# warn counts.inspect
result =... | true |
69fb30c7f104bbbac7f10660bb16a66c64223d67 | Ruby | dwarfmaster/rss_feeds | /eldair/next | UTF-8 | 631 | 2.953125 | 3 | [] | no_license | #!/usr/bin/ruby
require 'open-uri'
$stream = open(ARGV[0])
$url = ""
$title = "No title"
$desc = "No description"
while (line = $stream.gets)
mt = /<a href="(.*?)"> <img src=".[^"]*" alt="next page" \/> <\/a>/.match(line)
if not mt.nil?
$url = "http://eldair.com/#{mt[1]}"
next
end
mt... | true |
45a0c3b438a1e9a9a3a3303c884dd1b3b8e8a05a | Ruby | yui-knk/infrataster | /lib/infrataster/server.rb | UTF-8 | 2,959 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'tmpdir'
require 'net/ssh'
require 'net/ssh/gateway'
require 'ipaddr'
module Infrataster
class Server
Error = Class.new(StandardError)
class << self
@@servers = []
def define(*args)
@@servers << Server.new(*args)
end
def find_by_name(name)
server = @@servers... | true |
47ed75cd1cc285ffca6e8b0f12dd731d33827cfa | Ruby | railsfactory-pavani/mp1 | /factorial/factorial.rb | UTF-8 | 152 | 3.796875 | 4 | [] | no_license | puts "Enter a number to calculate it's factorial"
n=gets.chomp.to_i
fact = 1
for c in 1..n
fact = fact * c
end
puts "Factorial of #{n} is #{fact}"
| true |
4c7dc9735d066b317ba9b33152d8cc9dfac9a1aa | Ruby | raghus/codewars | /minimum_sum_of_array.rb | UTF-8 | 776 | 3.890625 | 4 | [] | no_license | # https://www.codewars.com/kata/5a523566b3bfa84c2e00010b
# 7 kyu
def min_sum(arr)
# the approach here to get the smallest sum is to take the
# largest and smallest numbers and multiply them together
# then take the next largest and next smallest and multiply them
# and so on, and finding the sum of each of t... | true |
b1de900b3197486a0f6dec7ef7756cf8257f7daf | Ruby | djhenderson/ddochargen | /trunk/lib/RaceDependency.rb | UTF-8 | 539 | 2.96875 | 3 | [] | no_license |
require "lib/Dependency.rb"
require "lib/Race.rb"
module DDOChargen
class RaceDependency < Dependency
attr_accessor :race, :level, :strict
def initialize ( race = nil, level = 0, strict = false )
@race = race
@level = level
@strict = strict
end
def meets ( level )
return... | true |
430682b5191bd418b63a9784b9cfd30b89d02735 | Ruby | carolinecollaco/RubyCodeAcademy | /Downcase.rb | UTF-8 | 75 | 2.71875 | 3 | [] | no_license | print "Thtring, por favor!: "
user_input = gets.chomp
user_input.downcase!
| true |
f01730b27a66001851c532774f96feea5b636c5a | Ruby | peoplenamed/hue | /lib/hue/sensor.rb | UTF-8 | 2,244 | 2.578125 | 3 | [
"MIT"
] | permissive | module Hue
class Sensor
include TranslateKeys
# Unique identification number.
attr_reader :id
# Bridge the sensor is associated with
attr_reader :bridge
# A unique, editable name given to the sensor.
attr_accessor :name
# A fixed name describing the type of sensor.
attr_reader ... | true |
80b7f084b993d7b4c3697b8c2c989a7478918616 | Ruby | KatherineMcConnell/dealership_2105 | /lib/car.rb | UTF-8 | 489 | 3.359375 | 3 | [] | no_license | class Car
attr_reader :make,
:model,
:monthly_payment,
:loan_length,
:color
def initialize(make_and_model, monthly_payment, loan_length)
@make = make_and_model.split(" ").first
@model = make_and_model.split(" ").last
@monthly_payment = monthly_pay... | true |
5204ace69fd297145dc163537dc97670365d966a | Ruby | mmabraham/Games | /hangman/lib/computer_player.rb | UTF-8 | 1,607 | 3.234375 | 3 | [] | no_license | module Hangman
class ComputerPlayer
attr_reader :dictionary, :board, :candidate_words, :wrong_guesses
def initialize()
path = __FILE__.sub("hangman/lib/computer_player.rb", "utils/dictionary.txt")
@dictionary = File.readlines(path)
@dictionary.map! { |word| word.chomp.strip }
@candida... | true |
82b04e9057bc906565841dba13d41ef718c5260d | Ruby | stevoDEEBO/whiskypicker-cli-app | /lib/whisky_picker/cli.rb | UTF-8 | 6,775 | 3.375 | 3 | [
"MIT"
] | permissive | require 'pry'
require_relative "whisky.rb"
require 'colorize'
#CLI Controller
class WhiskyPicker::CLI
#include base path to append urls of respective whisky type webpages
BASE_PATH = "https://www.thewhiskyexchange.com/"
#welcome user to gem and call list search options
def call
greet
pick_whiskies
... | true |
b363a1a35256318bfa2f54203fb25c29bf4e5d30 | Ruby | dojorio/dojo-centro | /2013/20131016 - paintball - ruby/paintball_spec.rb | UTF-8 | 891 | 3 | 3 | [] | no_license | # -*- coding: utf-8 -*-
require './paintball.rb'
describe "Paintball" do
it "quadrado degenerado" do
paintball(0, 0, [], []).should be_false
end
it "quadrado de area 1" do
paintball(1, 1, [1], []).should eq 1
end
it "outro quadrado de area 1" do
paintball(1, 1, [], [1]).should eq 1
end
it ... | true |
06c353d534536bab81d765aba3bd226a78ddd3e0 | Ruby | open-telemetry/opentelemetry-ruby | /api/lib/opentelemetry/context/propagation.rb | UTF-8 | 3,087 | 2.609375 | 3 | [
"Apache-2.0",
"Ruby",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0
require 'opentelemetry/context/propagation/composite_text_map_propagator'
require 'opentelemetry/context/propagation/noop_text_map_propagator'
require 'opentelemetry/context/propagation/rack_env_getter'
require... | true |
95dc7afb868d0415ec21c470e557cc73d7b04d43 | Ruby | KahTim/pairbnb_rails | /app/models/reservation.rb | UTF-8 | 932 | 2.84375 | 3 | [] | no_license | class Reservation < ApplicationRecord
belongs_to :user
belongs_to :listing
before_save :duration_method
validate :date_logic, :past_date, :check_overlapping_dates
def check_overlapping_dates
# compare this new booking againsts existing bookings
listing.reservations.each do |old_booking|
if over... | true |
e167650cd4b8ea2317251f6fd338255cd722aab9 | Ruby | ogijun/project_euler_solve | /26-50/41.rb | UTF-8 | 781 | 2.734375 | 3 | [] | no_license | primes = eval(open(File.dirname(__FILE__) + '/primes_to_1000000.rb').read)
digits = %w(1 2 3 4 5 6 7)
def div_test n, primes
answer = true
for p in primes
break if p*p > n
answer = false if n%p == 0
end
answer
end
def felmat_test n, a
pow_mod(a, n - 1, n) == 1
end
def pow_mod a, m, n
i = 1
whil... | true |
204dacac295a5fd49f90966797128f08d2e591fb | Ruby | ehayon/NeuralNetwork | /NeuralNetwork.rb | UTF-8 | 4,742 | 3.375 | 3 | [] | no_license | require 'pp'
class NeuralNetwork
def self.activation(x)
# Sigmoid activation function
1.0/(1.0+Math.exp(-1.0 * x))
end
def self.activation_derivative(x)
# Derivative of the sigmoid activation function
self.activation(x) * (1.0-self.activation(x))
end
def self.create_matrix(rows, column... | true |
249ce1f22a04d0cb32868e9db73c9557de3c5b3b | Ruby | atombender/rspec-partial-hash | /lib/rspec-partial-hash/partial_hash.rb | UTF-8 | 859 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'active_support/core_ext/hash/slice'
PartialHashMatcher = Class.new {
def self.partial_match?(expected, actual)
actual_slice = actual.slice(*expected.keys)
if actual_slice.keys == expected.keys
actual_slice.each do |key, value|
if value.respond_to?(:to_h) or value.is_a?(Hash)
... | true |
d0d2db85c23543902016e612152708de21689ee5 | Ruby | Matoking/RailsKurssiApp | /app/models/concerns/rating_average.rb | UTF-8 | 253 | 2.578125 | 3 | [] | no_license | module RatingAverage
extend ActiveSupport::Concern
def average_rating
if ratings.empty?
nil
else
ratings.inject(0) { |sum, rating| sum + (rating.score) }.to_f / ratings.count.to_f
end
end
end
| true |
2c49cad4817e3038746fbbdbd5fdecaaee669020 | Ruby | dbvn1280/Ruby | /blocks2.rb | UTF-8 | 206 | 3.375 | 3 | [] | no_license | def dbvn(name)
if block_given?
yield name
else
puts "Không có Blocks"
end
end
#dbvn {puts "Tìm hiểu về blocks - tieuchuanvietnam.com"}
dbvn ("Dai Hieu") {|name| puts "Xin chào #{name}"} | true |
9bc8a861c92176a219e6d6226b8a3e2f1317d391 | Ruby | vineethsomanchi/Algorithms-Practice | /General Practice/valid_parentheses.rb | UTF-8 | 405 | 3.703125 | 4 | [] | no_license | def is_valid(str)
stack = []
dir = {"("=> ")", "{"=> "}", "["=> "]"}
str.each_char do |char|
if dir.has_key?(char)
stack.push(char)
else
if stack.length > 0
top_ele = stack.pop
else
top_ele = "#"
end
... | true |
7796704b476c88b0fbb33ab9470bd68e1d3111d9 | Ruby | Joe-noh/yao | /lib/yao/resources/restfully_accessible.rb | UTF-8 | 2,273 | 2.515625 | 3 | [
"MIT"
] | permissive | require "forwardable"
module Yao::Resources
module RestfullyAccessible
def self.extended(base)
base.class_eval do
class << self
attr_accessor :resource_name, :resources_name
extend Forwardable
%w(get post put delete).each do |method_name|
def_delegator :cl... | true |
4d90d6ab2d0dff9bd2a36b66ea65447770f9e7aa | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/src/3318.rb | UTF-8 | 172 | 3.265625 | 3 | [] | no_license | def compute(a,b)
count = 0
a.split("").map.with_index do |letter, i| # only works on equally long strings
count += 1 if letter != b[i]
end
count
end | true |
084410243f670955754f62f16b588eada0cffc0c | Ruby | aniarya82/rip | /bin/rip-fsck | UTF-8 | 984 | 2.515625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# usage: rip-fsck
#
# Verify integrity of .packages/ and .cache/
require 'rip/script'
status = 0
Dir["#{Rip.packages}/*"].each do |package|
metadata = "#{package}/metadata.rip"
if !File.exists?(metadata)
status = 1
warn "#{package} is missing metadata"
elsif !File.readable?(metadata... | true |
2561b774365ba349f116ae421ef2deba9bc2bca7 | Ruby | danmayer/reek | /lib/reek/smells/utility_function.rb | UTF-8 | 1,630 | 2.796875 | 3 | [
"MIT"
] | permissive | require 'reek/smells/smell_detector'
require 'reek/smell_warning'
module Reek
module Smells
#
# A Utility Function is any instance method that has no
# dependency on the state of the instance.
#
# Currently +UtilityFunction+ will warn about any method that:
#
# * is non-empty, and
... | true |
3f38ca2412ac62b74e48dc9d600656c937ee452d | Ruby | justinwkcheung/learn_ruby-1 | /01_temperature/temperature.rb | UTF-8 | 83 | 3.109375 | 3 | [] | no_license | def ftoc(fahr)
(fahr - 32) * (5/9.0)
end
def ctof(cel)
(cel * 9/5.0) + 32
end
| true |
e08593662bdbc1e0eda125962409e5812b0b8d8e | Ruby | edatrix/honeycrisp | /db/fixtures/apples.rb | UTF-8 | 382 | 2.546875 | 3 | [] | no_license | Apple.seed_once do |a|
a.type = "honeycrisp"
a.color = "mixed"
a.description = "crunchy"
end
Apple.seed_once do |a|
a.type = "red delicious"
a.color = "red"
a.description = "mealy"
end
Apple.seed_once do |a|
a.type = "pink lady"
a.color = "pink"
a.description = "tart"
end
Apple.seed_once do |a|
a... | true |
ce41b73686797281023dccc1571de7f0058131e0 | Ruby | joyvuu-dave/comeals-backend | /app/serializers/resident_birthday_serializer.rb | UTF-8 | 955 | 2.53125 | 3 | [
"MIT"
] | permissive | class ResidentBirthdaySerializer < ActiveModel::Serializer
include ApplicationHelper
attributes :id,
:type,
:title,
:description,
:start,
:end,
:color
def id
object.cache_key_with_version
end
def type
"Birthday"
end
... | true |
49dcf203821331122bd7a495799c40553ae4cc23 | Ruby | dmagliola/regex_game_of_life | /regex_gol_v1.rb | UTF-8 | 3,517 | 4.03125 | 4 | [
"MIT"
] | permissive | # "Regex implementation" of Game of Life, v1 (intermediate step)
#
# This version uses a Mega-Regex to find all the cells that need to change,
# but uses a Ruby block to "flip" each cell, instead of being fully Regex-based.
#
# When run, this will output the mega-regex it's using to `mega_regex.txt`,
# so you can see w... | true |
df6a040ee121e5ddee6c0057b79c0680b5e5d054 | Ruby | KingsleyMcSimon/TicTacToe-Project | /lib/board.rb | UTF-8 | 799 | 3.671875 | 4 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
class Board
# Board object should know which spaces are taken and which are not
# it should also know if it's full or not
attr_accessor :inner, :full
def initialize
@inner = [1, 2, 3, 4, 5, 6, 7, 8, 9]
@full = false
end
def take_place(inpt, player)
@inner[inpt - 1... | true |
4dbc7a26f41b29780a0072349e3f3d93d31eb283 | Ruby | alexbeeken/Word_Frequency | /lib/word_frequency.rb | UTF-8 | 682 | 3.09375 | 3 | [
"MIT"
] | permissive | class String
define_method(:word_frequency) do |input_findme|
final_count = 0
findme = input_findme.downcase()
if !(findme.length() > self.length())
self.split().each() do |input_word|
word = input_word.downcase()
if (((word[0].match(/^[[:alpha:]]$/)) == nil))
word[0] = ""
... | true |
249d57f0cb51a5ccc1c2381d94897463332f10cf | Ruby | pyer/pi | /ruby/base.rb | UTF-8 | 1,296 | 2.609375 | 3 | [
"MIT"
] | permissive |
require './ruby/error.rb'
require './ruby/mime_type.rb'
require './ruby/response.rb'
require './ruby/tree.rb'
class Base
class << self
@@routes = Hash.new { |hash, key| hash[key] = [] }
['DELETE', 'GET', 'HEAD', 'OPTIONS', 'PATCH', 'POST', 'PUT'].each do |verb|
define_method(verb.downcase) do... | true |
38b777dfffd70ee11d649bf62c9474fdfce208c6 | Ruby | ivannovosad/neo4j-core | /lib/neo4j-core/index/unique_factory.rb | UTF-8 | 2,305 | 2.828125 | 3 | [
"MIT"
] | permissive | module Neo4j
module Core
module Index
# A Utility class that can be used to make it easier to create unique entities. It uses {Neo4j::Core::Index::Indexer#put_if_absent}.
#
# @see Indexer#put_if_absent
#
# @example
# index = index_for_type(:exact)
# Neo4j::Core::Ind... | true |
908c8934edcd8a5b205cb2bf66c99d1ccbafc4a8 | Ruby | soam/ruby_pattern_match | /lib/pattern_match/attr.rb | UTF-8 | 592 | 2.890625 | 3 | [] | no_license | require 'blox'
require 'pattern_match/pattern'
require 'pattern_match/matchbinding'
require 'pattern_match/matchfunc'
module PatternMatch
class Attr < Pattern
def check_args
if ((@args.length != 1) and !(@args[0].is_a? Hash))
raise "Attr needs one argument, which should be a Hash"
end
end
# Att... | true |
88b4d4d69d056523459f5adb0dd79e94cd59d827 | Ruby | brownmike/project-euler | /29.rb | UTF-8 | 691 | 4.1875 | 4 | [] | no_license | # Distinct powers
# Problem 29
# Consider all integer combinations of a^b for 2 ≤ a ≤ 5 and 2 ≤ b ≤ 5:
# 2^2=4, 2^3=8, 2^4=16, 2^5=32
# 3^2=9, 3^3=27, 3^4=81, 3^5=243
# 4^2=16, 4^3=64, 4^4=256, 4^5=1024
# 5^2=25, 5^3=125, 5^4=625, 5^5=3125
# If they are then placed in numerical order, with any repeats removed, we ge... | true |
452a5e7c9d6e0e16ab2996e52a3e24ea6029ac32 | Ruby | nickbdyer/web-battleships | /lib/player.rb | UTF-8 | 147 | 3.140625 | 3 | [] | no_license | class Player
attr_accessor :name, :board
def has_board?
!@board.nil?
end
def receive_shot(coordinate)
board.shoot_at(coordinate)
end
end | true |
cbe352971bd056a3817bc0cfe4d0971bced1e80f | Ruby | wilkie/hacketyhack | /samples/Fractal.rb | UTF-8 | 349 | 3.03125 | 3 | [
"MIT",
"Ruby"
] | permissive | # A simple _/\_ Fractal
def base scale
forward scale
end
ANGLE = 70
def fractal scale
method = scale < 3 ? :base : :fractal
scale /= 3.0
send method, scale
turnleft ANGLE
send method, scale
turnright ANGLE*2
send method, scale
turnleft ANGLE
send method, scale
end
Turtle.draw do
goto 20, 300
... | true |
e2fe1a300ec23d2ec8b835ee9928eeb9a18c2a46 | Ruby | attack/barometer | /lib/barometer/weather_services/wunderground_v1/response/forecasted_weather.rb | UTF-8 | 2,640 | 2.53125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Barometer
module WeatherService
class WundergroundV1
class Response
class ForecastedWeather
def initialize(payload, response)
@payload = payload
@response = response
@predictions = Barometer::Response::PredictionCollection.new
end
... | true |
716dbf39abf20e97f20d57cd3e4f1f4006517149 | Ruby | michelovesdr/ctd | /week1/user_input_program/user_input_statistics.rb | UTF-8 | 460 | 3.25 | 3 | [] | no_license | def main
# we need an array to store our data
['Hello', 'Goodbye']
# how do we assign an array to a variable?
sharks = ["Hammerhead", "Great White", "Tiger"]
loop do
# continue to ask for a number
# challenge: how do I check that may input is an integer and not a string?
brea... | true |
39953ca8d84af3bc0a29355325b974add126f205 | Ruby | eballhysa/unyt-eawa-c12-ex1 | /student.rb | UTF-8 | 708 | 3.375 | 3 | [] | no_license | class Student
include Comparable
attr_accessor :id, :name, :surname, :department_code, :gender, :email, :grades
GENDERS_MAP = {'F' => :female, 'M' => :male}
def initialize(line)
tokens = line.chomp.split(', ')
@id = tokens[0].to_i
@name = tokens[1]
@surname = tokens[2]
@department_code = t... | true |
9fec1d01ab90b2ab81b6dcf65abce4a036aa97bc | Ruby | Vicstorovich/Eatry | /app/models/order.rb | UTF-8 | 487 | 2.578125 | 3 | [] | no_license | class Order < ApplicationRecord
has_many :line_items, dependent: :destroy
validates :name, :address, :email, presence: true
validates :email, email: true
def add_line_items_from_cart(cart)
cart.line_items.each do |item|
item.cart_id = nil
line_items << item
end
end
def total_price
... | true |
f6b38385a1c20f06de7a243831ac690f57868d18 | Ruby | bobop/noughts_and_crosses | /app/models/game.rb | UTF-8 | 2,950 | 3.125 | 3 | [] | no_license | class Game < ApplicationRecord
has_many :game_turns
def self.start_game(game_uuid, player_uuid)
@game = Game.find_by(game_uuid: game_uuid)
# Save host_uuid if not already saved
if @game.host_uuid.nil?
@game.update(host_uuid: player_uuid, host_piece: 'cross')
else
# Save opponent_uuid an... | true |
73762c295a02f53fbf56c47122ea01414fe3a24e | Ruby | Ayukito/Ruby-File-Loader | /Ruby File Loader/Project/pokemonsdk/scripts/01200 PFM/00100 Global Systems/00300 Bag.rb | UTF-8 | 4,569 | 2.890625 | 3 | [] | no_license | module PFM
# InGame Bag management
#
# The global Bag object is stored in $bag and $pokemon_party.bag
# @author Nuri Yuri
class Bag
# Last socket used in the bag
# @return [Integer]
attr_accessor :last_socket
# Last index in the socket
# @return [Integer]
attr_accessor :last_index
... | true |
5743d63bbacc214dcecba5dda9258d2578a7938b | Ruby | jd-erreape/authority | /spec/authority_spec.rb | UTF-8 | 1,728 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'support/ability_model'
require 'support/user'
describe Authority do
it "should have a default list of abilities" do
Authority.abilities.should be_a(Hash)
end
it "should not allow modification of the Authority.abilities hash directly" do
expect { Authority.abilities[:excha... | true |
5e4708b441273ec3fb4d02a4532d8dcf0512591d | Ruby | zenterp/sendthembitcoins | /lib/ripple/payment.rb | UTF-8 | 748 | 2.71875 | 3 | [] | no_license | module Ripple
class Payment
def initialize(opts)
@destination = opts[:destination]
@currency = opts[:currency]
@amount = opts[:amount]
end
def submit_with(ripple_client)
unless ripple_client.class == Ripple::Abstract
raise TypeError, 'Must submit with a Ripple::Abstract'
... | true |
dab1fca91edd3ca6d773be85ceb2cf10eb9913a6 | Ruby | pbosetti/rnc2017 | /lessons/lesson4.rb | UTF-8 | 1,569 | 3.953125 | 4 | [] | no_license | #!/usr/bin/env ruby -wKU
class String
ANSI_COLORS = {
black: 30,
red: 31,
green: 32,
brown: 33,
blue: 34,
magenta: 35,
cyan: 36,
gray: 37
}
# enable this writing: "some text".fg(:red)
def fg(c)
return self unless ANSI_COLORS[c]
... | true |
c67043386ab0d5be88a415b3bba107c46e06c901 | Ruby | kaiosilveira/expense-tracker | /lib/domain/builders/transaction/index.test.rb | UTF-8 | 3,157 | 2.796875 | 3 | [] | no_license | require "minitest/autorun"
require "date"
require_relative "./index.rb"
require_relative "../../entities/transaction/index.rb"
describe TransactionBuilder do
it "should build a default transaction" do
transaction = TransactionBuilder.new.build
assert_equal 0.0, transaction.amount
assert_equal "BRL", tran... | true |
3c0493df6641a2aa7c7335b23488538c3eceef48 | Ruby | milafrerichs/geo_transformer | /lib/geo_transformer.rb | UTF-8 | 293 | 2.8125 | 3 | [] | no_license | require 'geo_transformer/gauss_krueger'
module GeoTransformer
def self.parse_gauss_krueger(gk_string)
right, height = gk_string.split(",")
if right && height
GaussKrueger.new(right, height)
else
raise ArgumentError.new "invalid arg: #{gk_string}"
end
end
end
| true |
47784888218a8b1af9c348af45353757aa55c981 | Ruby | mlankenau/ant_attack_ai | /client.rb | UTF-8 | 692 | 2.75 | 3 | [] | no_license | require 'rubygems'
require 'websocket-client-simple'
require './deep_struct'
require './channel'
require 'json'
require './base_client'
class Client < BaseClient
def initialize(name, password)
super(name, password)
end
def play
neutrals = planets.select { |p| p.player != player_num }
my = planets.se... | true |
eeee24cc1e0df7f73594baedff75d8cb11e0c8d0 | Ruby | epistrephein/netatmo-ruby | /lib/netatmo/dashboard_data/pressure.rb | UTF-8 | 855 | 2.65625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'forwardable'
module Netatmo
module DashboardData
class Pressure
extend Forwardable
attr_accessor :time
attr_accessor :value
attr_accessor :absolute_pressure
attr_accessor :trend
attr_accessor :unit
def initialize(data)
se... | true |
622e0a52e439b4df4707be428522166dd52a14f0 | Ruby | goochlap/Medium-clone | /db/seeds.rb | UTF-8 | 780 | 2.515625 | 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 |
826c0d63e922ad29cc03724926a7288140496d15 | Ruby | sergeych/universa_tools | /lib/universa_tools/semantic_version.rb | UTF-8 | 653 | 3.046875 | 3 | [
"MIT"
] | permissive | module UniversaTools
class SemanticVersion
attr :parts
include Comparable
def initialize string
@parts = string.split('.').map(&:to_i)
@parts.any? { |x| x < 0 } and raise ArgumentError, "version numbers must be positive"
end
def <=> other
if other.is_a?(SemanticVersion)
... | true |
ba67c9e823bbfeeb0b63e6d3abefcbc465882857 | Ruby | cmaggard/trueskill | /lib/trueskill/player.rb | UTF-8 | 279 | 2.9375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Trueskill
class Player
attr_accessor :mu, :sigma, :id
def initialize(params = {})
@id = params[:id]
@mu = params[:mu]
@sigma = params[:sigma]
end
def pi
1.0 / (@sigma ** 2)
end
def tau
@mu * pi
end
end
end
| true |
7e2baa633fcf72749b88e1ab30b3bd93b2d25994 | Ruby | rkommineni/week2-homework | /directions.rb | UTF-8 | 716 | 3.140625 | 3 | [] | no_license | require 'open-uri'
require 'json'
puts "Enter an origin address: "
origin = gets
origin = origin.chomp
origin = origin.squeeze(' ')
origin = origin.gsub(' ','+')
puts "Enter a destination address: "
destination = gets
destination = destination.chomp
destination = destination.squeeze(' ')
destination = destination.g... | true |
c5f58567924ea9ee356c1cb476a095cb12846d04 | Ruby | andyrow123/student-directory | /directory.rb | UTF-8 | 1,984 | 2.9375 | 3 | [] | no_license | # puts File.read($0)
require './classes/menu.rb'
require './classes/list.rb'
require './classes/student.rb'
def try_load_students
filename = ARGV.first # load the first argument from the command line
return Student.log(:screen, :info, 'Command-line filename is nil. Load file manually') if filename.nil? # get out ... | true |
769cb0460d42510b6cde18122a2417a74a55010f | Ruby | gushul/fetching_tweet | /app/models/fetch_tweet.rb | UTF-8 | 866 | 2.515625 | 3 | [] | no_license | class FetchTweet < ActiveRecord::Base
validates :twitter_id, uniqueness: true
scope :names, ->(name) { where("name LIKE ?" , name) }
def self.fetch_all_tweets(twitter_name)
tweets = $twitter.get_all_tweets("#{twitter_name}")
tweets.each do |tweet|
tweet = { text: tweet.text, twitter_name: twitter_... | true |
f922bf0a830f8a5a03caf5a11d5c5152ca5672b0 | Ruby | etdev/algorithms | /0_code_wars/hamming_numbers.rb | UTF-8 | 1,519 | 3.921875 | 4 | [
"MIT"
] | permissive | # https://www.codewars.com/kata/hamming-numbers
# attempt #1 - correct answers but not fast enough
require "set"
def hamming(n)
base, m, count = 1, 1, 1
candidates = []
seen = Set.new([1])
until count == n
cand2 = base * 2
cand2_pt = candidates.index(candidates.bsearch{ |x| x > base * 2 }) || candidat... | true |
89e2fe5de33727028ef048a48d837f11283f478e | Ruby | flaviomahoney/lol-tv-mahoney | /db/seeds.rb | UTF-8 | 3,536 | 2.734375 | 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 |
75c56e5a98f043cf27bda8573fc18bf002b82876 | Ruby | SebaRaimondi/ProyectoRuby | /app/models/student.rb | UTF-8 | 1,183 | 2.703125 | 3 | [] | no_license | class Student < ApplicationRecord
belongs_to :course
has_many :results
has_many :exams, through: :results
number_regex = /\A[1-9]\d{0,6}.[\/][1-9]\d{0,2}\z/
number_message = 'El legajo ingresado no es valido.'
email_message = 'El email ingresado no es valido.'
validates :surname, presence: true, length... | true |
c43ac1cadbe043e01a8b66b16e472e1a3d397b7e | Ruby | KevSeenan/music_collection_homework | /console.rb | UTF-8 | 648 | 2.765625 | 3 | [] | no_license | require('pry-byebug')
require_relative('./models/albums.rb')
require_relative('./models/artists.rb')
Album.delete_all()
Artist.delete_all()
artist1 = Artist.new(
{
'name' => 'Alice In Chains'
}
)
artist2 = Artist.new(
{
'name' => 'Bob Marley'
}
)
artist1.save()
artist2.save()
album1 = Album.new(
... | true |
2a56a053aaff547c1b8cf8e86e41927ad96db0a2 | Ruby | adelekyriacou/playground | /calculator/calculator_spec.rb | UTF-8 | 663 | 3.03125 | 3 | [] | no_license | require_relative './calculator'
describe Calculator do
let(:calc) { Calculator.new }
context '#sum' do
it 'should return 2 given 1 and 1' do
expect(calc.sum(1, 1)).to eq(2)
end
it 'should return 5 given 2 and 3' do
expect(calc.sum(2, 3)).to eq(5)
end
end
context '#diff' do
it... | true |
1957eb47f64419ded31eceb072564b8d83ce3e2f | Ruby | SeanWelshBrown/programming-univbasics-3-labs-with-tdd-dumbo-web-120919 | /calculator.rb | UTF-8 | 227 | 3.359375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Add your variables here
first_number = 5
second_number = 3
sum = (first_number + second_number)
difference = (first_number - second_number)
product = (first_number * second_number)
quotient = (first_number / second_number)
| true |
660ec6510ab2855212d84ab648ae03f60714bab1 | Ruby | snmgian/rvim | /lib/rvim/curses/screen.rb | UTF-8 | 1,039 | 2.890625 | 3 | [] | no_license | require 'curses'
require_relative 'cursor'
module RVim
module Curses
class Screen
def advance_cursor
x, y = @cursor.x, @cursor.y
x += 1
if x >= columns
x = 0
y += 1
end
@cursor.position = x, y
end
def advance_line
y = @curso... | true |
b7ab0c3ec7e49ba3991716923edbcb3c4ccd877a | Ruby | BBartosz/tdd_katas | /spec/scanner_spec.rb | UTF-8 | 901 | 3.296875 | 3 | [] | no_license | require './lib/scanner'
describe Scanner do
context 'creating new Scanner' do
context 'when input is specified' do
it "with input '1,2' , variable @tokens is array of proper tokens" do
scanner = Scanner.new('1,2')
expect(scanner.tokens).to eq([Token.new('1', 'NUMBER'),Token.new(',', 'COMMA'... | true |
a125b47a99d0fdeb1cc5230861c3b015d6f76b60 | Ruby | akramhelil/blood-oath-relations | /app/models/bloodoath.rb | UTF-8 | 614 | 2.859375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class BloodOath
@@all = []
attr_reader :cult, :follower
def initialize(cult, follower, join_date)
@cult = cult
@follower = follower
@join_date = join_date
@@all << self
end
def self.all
@@all
end
def self.first_oath
@@all.first.follower
end
end
... | true |
2f9c18e76e1c76a00587ac0ca5af8b58b1f8e5ac | Ruby | GijuAmbrose/ruby-programs | /Cipher.rb | UTF-8 | 1,120 | 3.234375 | 3 | [] | no_license | class Cipher
puts("Enter the string to be decoded")
string = gets.chomp
c = []
d = []
r = []
string3 = ""
string2 = "DWJXH YRFDG TMSHP UURXJ"
alpha_map = {1=>"A",2=>"B",3=>"C",4=>"D",5=>"E",6=>"F",7=>"G",8=>"H",9=>"I",10=>"J",11=>"K",12=>"L",13=>"M",
14=>"N",15=>"O",16=>"P",17=>"Q",18=>"R",19=>"S",20=>"T",21=>"... | true |
d7ecdf3a2b886e49219493bcc68e0ac7c9199fb3 | Ruby | zlw5009/launch_school | /Backend/OOP120/Lesson_Four/Easy1/Q6.rb | UTF-8 | 201 | 3.671875 | 4 | [] | no_license | # We can add in attr_reader to have a getter method for :volume.
class Cube
attr_reader :volume
def initialize(volume)
@volume = volume
end
end
big_cube = Cube.new(13)
puts big_cube.volume | true |
316599f825d34ff0a6103deaa0c558cee46077ab | Ruby | r-osoriobarra/ejercicios_ciclos | /password_validation.rb | UTF-8 | 269 | 2.84375 | 3 | [] | no_license | #Validar una contraseña dad por el usuario
puts "Ingresar contraseña"
user_pass = gets.chomp
pass = "password"
until user_pass == pass
puts "La contraseña no válida. Por favor ingresa la contraseña correcta"
user_pass = gets.chomp
end
puts "Entraste!"
| true |
909c31bd2f4d9e82fca8e6602009d48135613982 | Ruby | Parthaghosal/Udacity-CS-101 | /ranger.rb | UTF-8 | 598 | 4.125 | 4 | [] | no_license | # The range of a set of values is the maximum value minus the minimum
# value. Define a procedure, set_range, which returns the range of three input
# values.
# Hint: the procedure, biggest which you coded in this unit
# might help you with this question. You might also like to find a way to
# code it using some built... | true |
7daf80ccd63363727b1b965dc36371c064245a7e | Ruby | norm-framework/p4 | /test/ba_speak/parser_spec.rb | UTF-8 | 5,627 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'ba_speak/parser'
module BaSpeak
describe Parser do
it "must parse an empty file" do
output = parse ""
nodes = RootNode.new
output.must_equal nodes
end
it "must parse an empty group" do
output = parse <<-EOF
Create a Project
... | true |
1fae343f30a01c9727bfa0b1f16658b7e64f3ec4 | Ruby | pauldambra/adventofcode2016 | /day_6/spec/part_two.rb | UTF-8 | 1,396 | 3.578125 | 4 | [
"CC-BY-4.0"
] | permissive | require_relative('../error_correcting_reader.rb')
# --- Part Two ---
# Of course, that would be the message - if you hadn't agreed to use a modified repetition code instead.
# In this modified code, the sender instead transmits what looks like random data, but for each character, the character they actually want to ... | true |
ba3deed0628e1445b647830b07ad9f10b7d96cc6 | Ruby | Tonito135/collections_practice-onl01-seng-pt-081720 | /collections_practice.rb | UTF-8 | 807 | 3.84375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def sort_array_asc(integers)
integers.sort
end
def sort_array_desc(integers)
integers.sort do |left, right|
right <=> left
end
end
def sort_array_char_count(strings)
strings.sort do |left, right|
left.length <=> right.length
end
end
def swap_elements(arrays)
arrays[1], arrays[2] = arrays[2], ar... | true |
39a586b2cd370f7fde7601f3dab606fe361adce7 | Ruby | jrochkind/bento_search | /app/search_engines/bento_search/journal_tocs_for_journal.rb | UTF-8 | 7,028 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'nokogiri'
require 'httpclient'
require 'httpclient/include_client'
require 'htmlentities'
module BentoSearch
# Powered by JournalTocs (http://www.journaltocs.hw.ac.uk/index.php?action=api)
# This is NOT actually a typical Bento Search engine, it does not let you
# search for keywords, there ... | true |
141f1c95656f16278de2a75784092c2e9f26ba54 | Ruby | asbeane/RubyTetris | /O.rb | UTF-8 | 3,912 | 3.203125 | 3 | [] | no_license | class O
# Takes an x coord, y coord, board and orientation - and finds the orientation, if any
# Where an O piece can be found - given that orientation
# normalized orientation value to the single orientation of this piece
def can_place(start_x, start_y, board, orientation)
current_orientation = (orientation % ... | true |
6d56b046fa6549c57675cbbff759ba01cdc89d25 | Ruby | cse-bristol/sorting_office | /lib/sorting_office/models/street.rb | UTF-8 | 1,390 | 3.296875 | 3 | [] | no_license | class Street
def self.calculate(address, location)
nearby_streets = Street.where({
"lat_lng" => {
"$near" => location.to_a,
"$maxDistance" => 0.01262945188
}
})
matches = []
nearby_streets.each do |street|
matches << street if address.gsub(/[^0-9A-Za-z ]/, '').matc... | true |
94b93f1ec9f16580bbdbf6d94522d34def158e49 | Ruby | FerPerales/ruby-workshop | /examples/chapter_02/04_class_variables.rb | UTF-8 | 279 | 3.109375 | 3 | [] | no_license | class Counter
@@count = 0
def initialize
@@count += 1
end
def count
@@count
end
end
counter1 = Counter.new
puts counter1.count
counter2 = Counter.new
puts counter2.count
counter3 = Counter.new
puts counter3.count
counter4 = Counter.new
puts counter4.count
| true |
01b3a6a38f94d4b6f51670e0d43e1e17f7fae871 | Ruby | ybakos/middleman | /middleman-core/lib/middleman-core/core_extensions/builder.rb | UTF-8 | 1,319 | 2.578125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Convenience methods to allow config.rb to talk to the Builder
module Middleman::CoreExtensions::Builder
# Extension registered
class << self
# @private
def registered(app)
app.define_hook :after_build
app.extend ClassMethods
app.send :include, InstanceMethods
app.delegate :build... | true |
4591901fde60a286d6de39f1f8e0d5e6a01a54fb | Ruby | agata-anastazja/mars_copy | /spec/integration_tests/rover_test_spec.rb | UTF-8 | 274 | 2.609375 | 3 | [] | no_license | require 'rspec'
require_relative "../../lib/rover.rb"
require 'pry'
describe 'Rover' do
it 'coordinates should change following nasa instructions' do
rover = Rover.new([0, 0, "N"], ["M"])
rover.move
expect(rover.current_position).to eq([1, 0, "N"])
end
end
| true |
7b2b0c728f4b1e6b48be3bc9e714124b58edc0a1 | Ruby | duritong/facter | /spec/unit/util/fact_spec.rb | UTF-8 | 4,459 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
require 'facter/util/fact'
describe Facter::Util::Fact do
it "should require a name" do
lambda { Facter::Util::Fact.new }.should raise_error(ArgumentError)
end
it "should always downcase the name and conv... | true |
33cbdb3694167f263d1cfffc9f7ec8336cb33ed7 | Ruby | Amberganda/todo-ruby-basics-online-web-prework | /lib/ruby_basics.rb | UTF-8 | 368 | 3.5625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def division(num1, num2)
division = num1 / num2
end
def assign_variable(value)
value
end
def argue(phrase)
phrase
end
def greeting(greeting, name)
greeting
end
def return_a_value(phrase = "Nice")
phrase
end
def last_evaluated_value(phrase = "expert")
phrase
end
def pizza_party(pizza_party = "cheese")
... | true |
4d8c0ce17d29224c7969f4c79a09fea9ec70f24a | Ruby | kiwala22/website | /app/models/student.rb | UTF-8 | 706 | 2.8125 | 3 | [] | no_license | class Student < ActiveRecord::Base
validates :name, :presence => true
validates :registration_number, :presence => true, :uniqueness => true
validates :amount, :presence => true
validates :receipt_number, :presence => true, :uniqueness => true
def self.search(search)
where("registration_number LIKE ? OR rece... | true |
985c7f10846141c38c6f88416dd01cdfe1bab7de | Ruby | alexdaesikkim/clearvoltex | /app/models/vote.rb | UTF-8 | 478 | 2.609375 | 3 | [
"MIT"
] | permissive | class Vote < ApplicationRecord
belongs_to :comment
belongs_to :user
def user_votes
return self.votes.where("upvote = true").count - self.votes.where("downvote = true").size
end
def upvoted_by(user)
vote = self.votes.where("user_id = ?", user.id).first
if vote.nil?
return false
end
return vote.upvot... | true |
66b7952716ce16da12417a51e74a6dff76ea7972 | Ruby | jaronson/screeng | /lib/screeng/parser.rb | UTF-8 | 2,691 | 2.625 | 3 | [
"MIT"
] | permissive | class Screeng::Parser
attr_reader :runner
attr_reader :filename
attr_reader :options
attr_reader :screen_group
attr_reader :group
def initialize(runner)
@runner = runner
@filename = runner.filename
@options = runner.options
end
def parse
@screen_group = Screeng::ScreenGroup.new... | true |
05450a29c45f2325411cc9cfff422a7cb1e68803 | Ruby | de-farias/exercism-ruby | /clock/clock.rb | UTF-8 | 611 | 3.75 | 4 | [] | no_license | class Clock
attr_reader :hour, :minute
def initialize(hour: 0, minute: 0)
extra_hour, @minute = minute.divmod(60)
@hour = (hour + extra_hour) % 24
end
def to_s
"#{normalized(hour)}:#{normalized(minute)}"
end
def +(other)
self.class.new(
hour: hour + other.hour,
minute: minute ... | true |
fa7399edc26e88e8cca02439b8771e9417c37997 | Ruby | scotidodson/crud-with-validations-lab-nyc-web-091718 | /app/models/song.rb | UTF-8 | 627 | 2.578125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song < ActiveRecord::Base
validates :title, presence: true
validates :released, inclusion: { in: [true,false] }
validates :title, uniqueness: {
scope: [:release_year, :artist_name],
message: 'already released this year'}
validates :artist_name, presence: true
validate :release_year_validations
... | true |
7fe258da59e78a270420d33d99637a040cf6c5c5 | Ruby | SephoraM/LS-Challenges | /medium1/circular_buffer.rb | UTF-8 | 700 | 3.359375 | 3 | [] | no_license | module BufferExceptions
class BufferFullException < StandardError; end
class BufferEmptyException < StandardError; end
end
class CircularBuffer
include BufferExceptions
def initialize(buffer_size)
@buffer_size = buffer_size
@buffer = []
end
def read
@buffer.empty? ? raise(BufferEmptyExceptio... | true |
a9163b7f7486960bc8b997020f8d140e150d7340 | Ruby | outsmartin/ispconfig3 | /vendor/bundler/ruby/2.0.0/gems/listen-1.0.2/lib/listen/adapter.rb | UTF-8 | 9,294 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'rbconfig'
require 'thread'
require 'set'
require 'fileutils'
module Listen
class Adapter
attr_accessor :directories, :callback, :stopped, :paused,
:mutex, :changed_directories, :turnstile, :latency,
:worker, :worker_thread, :poller_thread
# The list of existing o... | true |
8958fbae0bc7f6539ecfcca0c95b7832008107d7 | Ruby | averybroderick/ruby-music-library-cli-v-000 | /lib/Genre.rb | UTF-8 | 584 | 2.9375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Genre
extend Concerns::Findable
attr_accessor :name, :songs
@@all = []
#Instance Methods
def initialize(name)
@name = name
@songs = []
end
def save
@@all << self
end
def artists
artist_collection = []
self.songs.each do |song|
artist_collection.include?(song.arti... | true |
8e427985342c33fb77f6352c13030b239202b7e5 | Ruby | kowalix-pl/cartoon-collections-onl01-seng-pt-120819 | /cartoon_collections.rb | UTF-8 | 539 | 3.4375 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def roll_call_dwarves (dwarves)
dwarves.each_with_index {|dwarf, index|
puts "#{index + 1}. #{dwarf}"}
end
def summon_captain_planet (planeteer_calls)
planeteer_calls.map { |call| call.capitalize + '!' }
end
def long_planeteer_calls (planeteer_calls)
planeteer_calls.any? { |call| call.length > 4 }
end
def f... | true |
b9f08cd2792be532c9ffe84fcd41ba587d141570 | Ruby | coduery/savings_organizer_mongodb | /app/controllers/entries_controller.rb | UTF-8 | 8,366 | 2.609375 | 3 | [] | no_license | # Class for controlling actions related to "entries" web page views
class EntriesController < ApplicationController
# Method for handling get and post actions for entries "add" web page
def add
if request.get?
if !session[:current_user_id].nil?
get_account_category_info
if @account_names.... | true |
48e1f6ef820646278f85b99b037a8ea2485578b0 | Ruby | ernest-ns/shorty | /lib/shortcode_validator.rb | UTF-8 | 103 | 2.59375 | 3 | [] | no_license | module ShortcodeValidator
def self.valid? shortcode
/^[0-9a-zA-Z_]{4,}$/ === shortcode
end
end
| true |
718990cb73ac1915c6ca8279a3490093ef9e641b | Ruby | syhsyh9696/Ruby | /Tools/numberlist.rb | UTF-8 | 301 | 2.90625 | 3 | [] | no_license | # encoding: utf-8
io_temp = File.open("list.txt", "w")
File.open("allnum.txt", "r") do |io|
while line = io.gets
line.chomp!
if line[0..3] == "2010"
io_temp << "2#{line}\n"
p "done!"
elsif line[0..3] == "2011"
io_temp << "2#{line}\n"
end
end
end
io_temp.close()
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.