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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
64af47551df9960f70533af16b3f12cfd4ce364e | Ruby | DrFriendless/rmud | /wizards/lib/creatures.rb | UTF-8 | 4,870 | 2.546875 | 3 | [] | no_license | require 'eventmachine'
require_relative './body'
require_relative './soul'
require_relative './creature_util'
require_relative '../../src/shared/messages'
require_relative '../../src/server/events'
# tricks creatures have that players don't
class CreatureSoul < Soul
def after_properties_set
super
verb(["heal... | true |
165210659bda98cbb1d928c1dd9c103d59822e2f | Ruby | Billboz/Assignments | /assignment_22/assignment_22_Invoice_Class.rb | UTF-8 | 1,097 | 3.546875 | 4 | [] | no_license | #!usr/bin/ruby
#require 'pry'
require 'active_support/all'
class InvoiceItem
attr_accessor :name, :price, :quantity
end
class Invoice
attr_accessor :tax, :items
def total
items.sum { |i| (i.quantity * i.price)}
end
end
invoice = Invoice.new
puts 'What is the tax in your county?'
invoice.tax = $st... | true |
127ae3e26a69c0814d1a5a90cc995cf6f690986b | Ruby | sunyounghwang/ttt-with-ai-project-v-000 | /lib/players/computer.rb | UTF-8 | 541 | 3.3125 | 3 | [] | no_license | module Players
class Computer < Player
def move(board)
winning_move(board) || random_move(board)
end
def random_move(board)
rand(1..9).to_s
end
def winning_move(board)
winner = Game::WIN_COMBINATIONS.detect do |combo|
num_tokens = combo.count { |i| board.cells[i] == sel... | true |
ef3814dfc2a96b3eb78db04c4cad50f6660b901b | Ruby | paploo/scotland-yard-assistant-scala | /utils/board-data/lib/validator.rb | UTF-8 | 518 | 3.046875 | 3 | [] | no_license | module Validator
# This checks that for each forward
# route, there is a reverse route.
def self.bidirectional_integrity(routes)
routes.reject {|route| routes.include?(route.reverse)}
end
def self.station_list(routes)
stations = routes.flat_map {|route| [route.source, route.destination]}.uniq.sort
... | true |
a55b7ed643e7d63ac0111991397183033a45c688 | Ruby | willbach/AppAcademyPrepWork | /learn_ruby/01_temperature/temperature.rb | UTF-8 | 108 | 3.171875 | 3 | [] | no_license | def ftoc(farh)
(farh.to_f - 32.0) / 9.0 * 5.0
end
def ctof(celc)
celc.to_f / 5.0 * 9.0 + 32.0
end
| true |
35df59f0914cae87a4ff4b31e72a7b929b89920a | Ruby | gitalek/rubythink | /railway/tests/test_route.rb | UTF-8 | 626 | 2.84375 | 3 | [] | no_license | require 'minitest/autorun'
require_relative '../route'
require_relative '../station'
# class documentation
class TestStation < Minitest::Test
def test_validate_method
start_station = Station.new('vld')
end_station = Station.new('msk')
exception = assert_raises RuntimeError do
Route.new('start_stat... | true |
d9e7921f9dc5785eba897e6b00a4c0f315082978 | Ruby | gizmomogwai/ruby-jep | /lib/jep/frontend/problem_list.rb | UTF-8 | 758 | 2.765625 | 3 | [] | no_license | module JEP
module Frontend
class ProblemList
Problem = Struct.new(:file, :line, :message, :severity)
attr_reader :problems
def initialize
@problems = []
end
def update(message)
raise ArgumentError.new("not a ProblemUpdate message") \
unless message.type == "ProblemUpdate"
raise ArgumentError.new("can't h... | true |
fe03aa4c2d7ef533b14f026f15f008d1fea3de14 | Ruby | mcpenchel/batch-513 | /livecodes/food-delivery-day-1/app/models/employee.rb | UTF-8 | 700 | 3.25 | 3 | [] | no_license | class Employee
attr_accessor :id
attr_reader :username, :password, :role
def initialize(attributes = {})
@id = attributes[:id]
@username = attributes[:username]
@password = attributes[:password]
@role = attributes[:role]
end
def manager?
@role == 'manager'
end
def delivery_guy?
... | true |
df70489a365ebd1a2f6243266b866ac6d34d474f | Ruby | Naoyakaoru/practice | /ruby/ruby_HW_part1.rb | UTF-8 | 673 | 3.8125 | 4 | [] | no_license | # 1. my_map
class Array
def my_map
result = []
each do |x|
result << yield(x)
end
return result
end
end
p [1, 2, 3, 4, 5].my_map { |x| x * 2 }
# 印出 [2, 4, 6, 8, 10]
# 2,3,4. is_email? 目前僅先依題目需求,判定是否有單一個 "@" ,與在 "@" 後有至少1個 ".",尚無使用regexp
class String
def is_email?
if include?("@")
... | true |
d0303254e33959bce0afdb00bf56b5b030d5c451 | Ruby | orochidev/ProjetoErdos | /aresta.rb | UTF-8 | 465 | 2.875 | 3 | [] | no_license | class Aresta
attr_accessor :vertice1
attr_accessor :vertice2
attr_accessor :grafo
def initialize(vertice, vertice2, grafo)
self.grafo = grafo
if vertice.kind_of? String
self.vertice1 = grafo.searchVerticeByRotulo(vertice)
else
self.vertice1 = vertice
end
if vertice... | true |
bdb91b2b844ceecdf4f0debe53eae01080bf9523 | Ruby | loualrid/ruby_tic_tac_toe | /spec/ruby_tic_tac_toe/initializer_spec.rb | UTF-8 | 2,904 | 2.8125 | 3 | [] | no_license | require 'spec_helper'
describe RubyTicTacToe::Initializer, type: :initialization do
describe "#initialize_configuration" do
before do
@modes = [:skip_validation, :skip_execution]
end
it "should give players the choice of an x by x board" do
initialize_and_set_stdin_to(['3'], @modes)
e... | true |
14d276539cbd8a622c341fe34bcdc3a440f47487 | Ruby | kscotteng/employee-reviews | /employee.rb | UTF-8 | 334 | 2.671875 | 3 | [] | no_license |
class Employee
attr_reader :name, :email, :phone, :salary, :review, :satisfactorily
def initialize(name: nil, email: nil, phone: nil, salary: nil, review: nil, satisfactorily: nil)
@name = name
@email = email
@phone = phone
@salary = salary
@review = review
@satisfactorily = satisfactorily
... | true |
3a8e7d13d82ee5e4d6e907f395e88ba282d46986 | Ruby | bemurphy/pundit_helpers | /lib/pundit_helpers.rb | UTF-8 | 1,466 | 2.671875 | 3 | [
"MIT"
] | permissive | require "pundit_helpers/version"
module PunditHelpers
def self.included(base)
methods = [:authorized?, :can?]
if base.respond_to?(:helper_method)
methods.each { |m| base.helper_method(m) }
end
if respond_to?(:hide_action)
methods.each { |m| base.hide_action(m) }
end
end
# Pundi... | true |
7daf4603491d999a17ecf5d2dc7b9239130a4a71 | Ruby | atyenoria/digitalocean-useful-tool | /ssh_config_plus | UTF-8 | 2,665 | 2.53125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
#ssh-config setting useful tool by atyenoria
#if you have some problems with this, please contact me (eigotyoubunn30@gmail.com)
require 'fileutils'
require 'pp'
class MySTDOUT
def initialize(&proc)
@proc = proc
end
def execute
tmp_file = "/tmp/#{File.basename(__FILE__)}.#{$$}"
o... | true |
cce3cccc635d0247195c5d887bcc081f77b734ea | Ruby | maximsolopin/rails | /railwaystation/app/models/train.rb | UTF-8 | 1,652 | 2.5625 | 3 | [] | no_license | class Train < ActiveRecord::Base
TRAIN_SORT_TYPES = ["DESC", "ASC"]
validates :number, uniqueness: true
belongs_to :route
has_many :tickets
has_many :wagons
#scope :ordered, -> (train, direction) { where(train: train).order("number #{direction}") }
def compartment_wagon_count
se... | true |
b0bf4ee88cd1ee504fc801d4ba6da6d91a6710d8 | Ruby | takuminasu/rex | /third/3-1.rb | UTF-8 | 422 | 3.859375 | 4 | [] | no_license | $val = 0
class Count
def self.up
$val = $val + 1
$val == 3 ? true : false
end
end
[*1..10].any? do
Count.up
end
p $val
#=> 3
str = "1;2:3;4"
p str.split(";|:")
#=> ["1;2:3;4"]
def bar(n)
puts n
end
bar 5
#=> 5
def foo(n)
n ** n
end
puts foo (2) * 2
#=> 256 メソッドと引数の間に空白があると((2) * 2)になる
str... | true |
dcf092ac14bb314df0e25602984e722739fead91 | Ruby | paulalexrees/codewars-exercises | /lib/shorten_number.rb | UTF-8 | 530 | 3.6875 | 4 | [] | no_license | def shorten_number(suffixes, base)
Proc.new do |x|
next x.to_s if (x.to_s =~ (/\D|^$/)) != nil
basey = x.to_i / base
ind = 0
while basey > 0 && ind < suffixes.length - 1
basey = basey / base
ind += 1
end
puts ind
"#{x.to_i / base**ind}#{suffixes[ind]}"
end
end
f = ... | true |
e36c9ca1705dfbfa7bd77bd208d04dfee35de7b5 | Ruby | baob/sandbox-dcell | /dcell/scratchy.rb | UTF-8 | 316 | 2.5625 | 3 | [] | no_license | require 'dcell'
DCell.start :id => "scratchy", :addr => "tcp://127.0.0.1:9002"
itchy_node = DCell::Node["itchy"]
class Arbitrary
def initialize(something)
@something = something
end
end
puts "Fighting itchy! (check itchy's output)"
6.times do
itchy_node[:itchy].fight(Arbitrary.new(:jim))
sleep 1
end | true |
09a20038dc42a37af5c4675b96d8facdf97d5183 | Ruby | brianchiang-tw/RoR_Intro | /team.rb | UTF-8 | 531 | 3.75 | 4 | [] | no_license |
# definition of class Team
class Team
# adding a lot of functionality
include Enumerable
attr_accessor :name, :players
def initialize (teamName)
@name = teamName
# initialize team's player container to an empty array
@players = []
end
def add_players (*p)
... | true |
25bbef8056bd2ab1f35f6a74ee39af91cc9b2f20 | Ruby | StrongSad/ruby-rio-grande | /starter-code/spec/digitalitem_spec.rb | UTF-8 | 1,478 | 3.15625 | 3 | [] | no_license | require_relative 'spec_helper'
require_relative '../lib/DigitalItem'
describe DigitalItem do
before(:context) do
@digitalitem = DigitalItem.new("Generic Item",1.99)
end
describe "Initialization" do
it "is an instance of the Item class" do
expect(@digitalitem).to be_instance_of(DigitalItem)
e... | true |
7c7df1878a41e4ac570989889f0c51a9e63e9003 | Ruby | ravenwijaya/MyKattis | /leetcode/richestcustomer.rb | UTF-8 | 362 | 3.6875 | 4 | [] | no_license |
# def maximum_wealth(accounts)
# max=0
# accounts.each_with_index do |account,index|
# accountsum = account.inject(:+)
# if max < accountsum
# max = accountsum
# end
# end
# return max
# end
def maximum_wealth(accounts)
accounts.map {|account| account.sum }.max
... | true |
4c75c0ecaedc5e9e0a4f263e593aa17881de2b1e | Ruby | Ramya538/ruby-learning | /hash.rb | UTF-8 | 107 | 2.75 | 3 | [] | no_license | puts "enter the student name"
student=['mala' , 'riya' , 'priya']
i='priya'
for i in student do
puts i
end
| true |
0c8a2258d8dd91b4845645b0a93637856f5e7bf2 | Ruby | Rmole57/ruby-basics-exercises | /loops_1/control_the_loop.rb | UTF-8 | 384 | 3.78125 | 4 | [] | no_license | # Runs loop 5 times.
iterations = 1
loop do
puts "Number of iterations = #{iterations}"
iterations += 1
break if iterations > 5
end
=begin
FURTHER EXPLORATION:
loop do
puts "Number of iterations = #{iterations}"
break if iterations == 5
iterations += 1
end
ALTERNATIVE SOLUTION:
5.times do
puts "Nu... | true |
a1dd2ec480d4d8c5111c15a64b2d931170b71545 | Ruby | thrlstl/mod-1-mini-challenge-intro-to-oo | /run.rb | UTF-8 | 900 | 3.296875 | 3 | [] | no_license | require 'pry'
require_relative "./models/clown"
# test your code here!
# create a few new clown instances, for example:
#krusty = Clown.new("Krusty", 55, "Juggling Chainsaws", "Failure")
c1 = Clown.new("John Wayne Gacy", 52, "Pogo stick", "Prison")
c2 = Clown.new("Grock", 46, "Instruments", "Circus Environments")
c3 ... | true |
c071ca8512f56c7c9a798674961fdeb3ee9a77f1 | Ruby | takagotch/rb_lib | /delegate/decorator3.1.1.rb | UTF-8 | 173 | 2.859375 | 3 | [] | no_license | class ModelDecorator
attr_reader :object
delegate :age, to: :object
def initialize(object)
@object = object
end
def name
'Mr. ' + object.name
end
end
| true |
1f568311849ca924a80002479d728f8a11a814c7 | Ruby | AndrewHuntington/exercism_exercises | /ruby/series/series.rb | UTF-8 | 222 | 3.453125 | 3 | [] | no_license | class Series
def initialize(digits)
@digits = digits
end
def slices(n)
raise ArgumentError, "Argument passed is too large." if n > @digits.length
@digits.chars.each_cons(n).map { |a| a.join }
end
end
| true |
36c9dedd269f99d38bb97418d1f818caeb297158 | Ruby | NoahRGuy/exercism-hamming-attempt | /hamming.rb | UTF-8 | 379 | 3.25 | 3 | [] | no_license | class Hamming
def self.compute(a, b)
raise ArgumentError unless a.length == b.length
distance = 0
index_of_letter = 0
a_comp = a.split('')
b_comp = b.split('')
a_comp.each do |letter|
if !letter.eql? b_comp[index_of_letter]
distance += 1
end
index_of_letter += 1
end
return d... | true |
0e10bfccf1176b921cc16770f04d4fd0793a9ef0 | Ruby | jamontoya2/etapa2 | /semana1/Etapa_dos/sinatra_skeleton_users_bitly/app/models/url.rb | UTF-8 | 375 | 2.53125 | 3 | [] | no_license | class Url < ActiveRecord::Base
belongs_to :user
validates :long_url, presence: true
validates :long_url, format: {with: /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix , message: "Url Format not valid"}
before_create :create_short_url
def create_short_url
self.short_u... | true |
26979fc1dff37ac1f30061466defb481837603a7 | Ruby | foreverLoveWisdom/oop_sandi_practice | /patent_job.rb | UTF-8 | 652 | 3.125 | 3 | [] | no_license | # What may go wrong with this class?
# What if the ftp host/login/password changes?
# What if I need to create another job like this?
# In sum, it is not easy to change
# It downloads the file AND it updates into the db
# The word AND can give me a hint to move out the download functionality into a separate class
# Th... | true |
31e9f4ab996655aa5216db628b6c525e8322877d | Ruby | julienwat75/rails-calendar | /app/models/calendar.rb | UTF-8 | 741 | 2.671875 | 3 | [
"MIT"
] | permissive | class Calendar < ActiveRecord::Base
belongs_to :program
validates_presence_of :event, :description, :start_date, :end_date
attr_accessible :event, :description, :program_id, :start_date, :end_date
def self.all_events(page)
paginate(:page => page, :per_page => 10)
end
# Find all events fro... | true |
fdea688d866f371ebef4a5b7f7993dc52eef6ab7 | Ruby | learn-co-students/web-060517 | /3-nyc-pigeon-organizer/nyc_pigeon_organizer.rb | UTF-8 | 3,616 | 3.5 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry-byebug'
# pigeon_data = {
# :color => {
# :purple => ["Theo", "Peter Jr.", "Lucky"],
# :grey => ["Theo", "Peter Jr.", "Ms. K"],
# :white => ["Queenie", "Andrew", "Ms. K", "Alex"],
# :brown => ["Queenie", "Alex"]
# },
# :gender => {
# :male => ["Alex", "Theo", "Peter Jr.", "Andrew"... | true |
6cbcdf766204301fc3f6077deaed85f1b99380a4 | Ruby | kitwalker12/ruby-interview | /left_rotate_array.rb | UTF-8 | 492 | 3.34375 | 3 | [] | no_license | #!/bin/ruby
# Rotate an array by a given number of digits
n,d = gets.strip.split(' ')
n = n.to_i
d = d.to_i
a = gets.strip
a = a.split(' ').map(&:to_i)
def gcd(a,b)
if b==0
return a
else
return gcd(b, a%b)
end
end
for i in 0...gcd(n,d)
tmp = a[i]
j=i
while true
k = j+... | true |
a3fbf506403fb2fd3274b8ba5789ffe93b8fb4ed | Ruby | nateoh93/aA_classwork | /W4D5/execution_time_diff.rb | UTF-8 | 3,219 | 4.46875 | 4 | [] | no_license | require 'byebug'
#Given a list of integers find the smallest number in the list.
#Example:
# list = [ 0, 3, 5, 4, -5, 10, 1, 90 ]
# my_min(list) # => -5
# Phase I
# First, write a function that compares each element to every other element of the list.
# Return the element if all other elements i... | true |
76b6dcc8067f3fe7919874413412b6dc3791883b | Ruby | kelleyjenkins/reunion | /lib/reunion.rb | UTF-8 | 304 | 2.90625 | 3 | [] | no_license | require 'pry'
require './lib/activity'
class Reunion
attr_reader :activities
def initialize(location)
@location = location
@activities = []
end
def add_activity(activity)
@activities << activity
end
def total_cost_reunion
@activities[0].participants.values.sum
end
end
| true |
9877c3f0374b2dd16aaa8b600895c338aa7c462b | Ruby | groupdocs-conversion-cloud/groupdocs-conversion-cloud-ruby-samples | /Examples/Info/GetDocumentInformation.rb | UTF-8 | 539 | 2.625 | 3 | [
"MIT"
] | permissive | # Import modules
require 'groupdocs_conversion_cloud'
require './Common.rb'
# This example demonstrates how to get document info
class GetDocumentInformation
def self.Run()
infoApi = GroupDocsConversionCloud::InfoApi.from_config($config)
request = GroupDocsConversionCloud::GetDocument... | true |
d468fcdd2fc37cc4206d5a6417cfa3da961d499e | Ruby | yxia521/CodeWars | /Ruby/pairs_of_bears.rb | UTF-8 | 1,802 | 4.25 | 4 | [] | no_license | # 6 kyu
# Pairs of Bears
# In order to prove it's success and gain funding, the wilderness zoo needs
# to prove to environmentalists that it has x number of mating pairs of bears.
# You must check within string (s) to fid all of the mating pairs, and return
# a string containing only them. Line them up for inspecti... | true |
af9b2bbad3623ff82bad58bee62c3daca2fe6bce | Ruby | eggmantv/ruby_advanced | /09/07_method_missing.rb | UTF-8 | 289 | 3.59375 | 4 | [] | no_license | # method missing
# 1. how it works
# 2. ancestors
# 3. rails's AR
class User
def hello
'hello from User'
end
def method_missing(name, *args)
"method name is #{name}, parameters: #{args}"
end
end
user = User.new
puts user.hello
puts '-' * 30
puts user.hi('343', 19)
| true |
0ee4e6bad725d965844490bbcd0d6be915f126fe | Ruby | grenayd/area | /objarea/pager.rb | UTF-8 | 645 | 3.265625 | 3 | [] | no_license |
module Pager
@@pagesize = 23
@@page_prompt = "@G<(Q)uit or (M)ore? (ENTER = more, anything else = quit)>@d"
def self.show_text text # String Array
line = 0
len = text.size-1
opt = "m"
from = 0
to = 0
until to == len or opt == "q"
from = to+1
to += @... | true |
b31298bf63b7541dae110b78ff45da0678b94fc6 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/rna-transcription/1cecdb18a30f4a4c906ec83f512e38a2.rb | UTF-8 | 258 | 3.390625 | 3 | [] | no_license | class DNA
def initialize(sequence)
raise ArgumentError if invalid(sequence)
@strand = sequence
end
def to_rna
@strand.gsub "T", "U"
end
private
def invalid(sequence)
sequence.empty? || !sequence.is_a?(String)
end
end
| true |
436e9029710bb4e2c9f247087316602f65842bc4 | Ruby | usgo/gocongress | /spec/exporters/daily_plan_csv_exporter_spec.rb | UTF-8 | 1,843 | 2.53125 | 3 | [
"MIT"
] | permissive | require "rails_helper"
RSpec.describe DailyPlanCsvExporter do
describe '#render' do
it "renders one row per attendee, and one col. per plan" do
year = Date.current.year
csd = CONGRESS_START_DATE[year]
p1 = create :plan, daily: true, name: 'Plan 1'
p2 = create :plan, daily: true, disabled:... | true |
61a4d9088845849380864bf0f4a3bf40afb48308 | Ruby | aczid/facial-frontend | /app/models/image.rb | UTF-8 | 1,688 | 2.765625 | 3 | [] | no_license | require 'rubygems'
require 'fileutils'
require 'open3'
class Image
def initialize(args)
@args = args
end
def process
make_images_dir
if @args[:content_type].match(/image/)
puts "this is an image!"
process_as_image
#elsif @args[:content_type].match(/application\/(x-rar|x-tar|x-zip|x-7... | true |
9843724b6e7228bf6050cc05c5f492391989d902 | Ruby | jasnow/KariakooSales | /spec/models/commodity_spec.rb | UTF-8 | 935 | 2.703125 | 3 | [] | no_license | require 'spec_helper'
describe Commodity do
before(:each) do
@attr = {
:value => "Wheat"
}
end
it "should create a new instance given valid attributes" do
Commodity.create(@attr)
end
it "should require a value" do
no_commodity_value = Commodity.new(@attr.merge(:value => ""))
no_... | true |
daa78faa94b018f9fa1c54808094807d464a37de | Ruby | henrygarciaospina/challengers-ruby | /code_secret.rb | UTF-8 | 527 | 3.8125 | 4 | [] | no_license | system("clear")
print "Ingrese el código secreto : "
code = gets.chomp
print "Ingrese tú nombre : "
name = gets.chomp
code_is_valid = code == "123"
if code_is_valid && name = "Henry"
puts "!Muy bien¡, bienvenido #{name}"
elsif code == "Bloquear"
puts "Sistema bloqueado por #{name}"
else
puts "Código invali... | true |
44c8239794781f025d929f5bc5e97d8f12c47d82 | Ruby | garciaomar0203/learn_ruby | /05_book_titles/book.rb | UTF-8 | 623 | 3.765625 | 4 | [] | no_license | class Book
attr_accessor :title
$illegal_words = ["The", "A", "And","In", "Of", "An"]
def title=(num1)#"Inferno"
splittednum1 = num1.split # ["Inferno"]
for i in 0..splittednum1.length - 1 # will go from 0 index to the length of the splitted array - 1
splittednum1[i] = splittednum1[i].capitalize # s... | true |
fbe5a75aca5ee73def10b9ef8f45ec9748321d72 | Ruby | kaspernj/awesome_sql_admin | /lib/awesome_sql_admin/windows/run_sql.rb | UTF-8 | 4,868 | 2.671875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # This class controls the window, where the user can import SQL-files.
class AwesomeSqlAdmin::Windows::RunSQL
attr_accessor :gui # A reference to the GladeXML-object.
attr_accessor :dbpage # Reference to the DBPage-object.
attr_accessor :dbconn # Reference to the DBConn-object, which is used to write th... | true |
d3fe8cd8fcb3f276a90ed6690bf93bc5bef924b5 | Ruby | Casual3498/MovieCollection | /cashbox.rb | UTF-8 | 102 | 2.703125 | 3 | [] | no_license | module Cashbox
def cash
return @money
end
def pay(amount)
@money += amount
end
end | true |
38ba7d9096a12711e6da176e884e1d25a34f0f87 | Ruby | kohski/perfect_ruby | /11/3_file_format/11_3_3_csv.rb | UTF-8 | 317 | 3.140625 | 3 | [] | no_license | require 'csv'
p ['I','my','me','mine'].to_csv # => "I,my,me,mine\n"
p "I,my,me,mine\n".parse_csv #=>["I", "my", "me", "mine"]
csv = CSV.new(<<EOS)
foo,bar,baz
hoge,fuga,piyo
EOS
csv.each do |row|
puts row.join('|')
end
data = <<EOS
foo,bar,baz
hoge,fuga,piyo
EOS
CSV.parse(data) do |row|
p row.join('|')
end
| true |
fb5bdcb786f071f7f4cb41c3448ae548ce6a9712 | Ruby | rswillif/currency_converter | /currency_converter.rb | UTF-8 | 1,512 | 3.4375 | 3 | [] | no_license | class UnknownCurrencyCodeError < StandardError
end
class CurrencyConverter
require_relative 'currency'
attr_reader :conversion_rates
# conversion_rates must be a dictionary of conversion rates i.e. {'USD': 1.0, 'EUR': 0.74}
# conversion_rates ideally should be a nested hash with seperate libraries for e... | true |
751381aaa09641c674aceead302d405f4dc47dc2 | Ruby | genehsu/wp-euler | /problems/010.rb | UTF-8 | 262 | 3.765625 | 4 | [] | no_license | # Problem 10
# 08 February 2002
#
# The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.
#
# Find the sum of all the primes below two million.
require '../lib/primes'
pit = Prime::Iterator.new
sum = 0
while (p = pit.next) < 2_000_000
sum += p
end
puts sum
| true |
0c553c990f65dec5f995060cfbf89c354fe4c929 | Ruby | baxtjm/my-first-repo | /grading.rb | UTF-8 | 279 | 3.3125 | 3 | [] | no_license | country = "fr"
#
# if country == "us"
# puts "Hello"
# elsif country == "es"
# puts "Hola"
# elsif country == "fr"
# puts "Bonjour"
# else
# puts "Alo"
# end
case country
when "us"
puts "Hello"
when "es"
puts "Hola"
when "fr"
puts "Bonjour"
else
puts "Alo"
end
| true |
7c332bfc37995c97598dc2851663ff884b354147 | Ruby | mmyenny/mywanderland | /app/models/user.rb | UTF-8 | 878 | 2.515625 | 3 | [] | no_license | require 'net/http'
class User < ApplicationRecord
has_one_attached :profile_image
has_many :places, dependent: :destroy
has_many :albums, through: :places
has_many :photos, through: :albums
def self.from_auth_hash(payload)
User.find_or_create_by(auth_sub: payload["sub"]) do |user|
# This code will... | true |
b12f4e7e0535a1577465ecd484c6036493aeb1ff | Ruby | toppsdown/rampup-week-2 | /week2_scratch.rb | UTF-8 | 1,168 | 4.15625 | 4 | [] | no_license |
# def method(blarg2, blarg1)
# puts blarg1
# end
# arg = gets.to_i
# arg_2 = gets.to_i
# method(arg, arg_2)
# def new_func(given_numer)
# given_number multiple of 5 print "hello"
# given_number multiple of 3 print "goodbye"
# given_number multiple of 3 & 5 print "i'm staying where I am"
# end
... | true |
29abfde28ecccefe60270411a177cd86375c7920 | Ruby | edoardo90/swKnights-plp | /ruby/ese8mag-2-test.rb | UTF-8 | 1,156 | 3.515625 | 4 | [] | no_license | # === Exercise 4 ===
# A basic test framework
module Kernel
def describe(description, &block)
tests = Dsl.new.parse(description, block)
tests.execute
end
end
class Object
def should
self
end
end
class Dsl
def initialize
@tests = {}
end
def parse(description, block)
instance_eval(&block)
Execut... | true |
20cb003a938385a58508f7f3cef6444f2cd03f65 | Ruby | SaturdayAM/sinatra-mvc-lab-dc-web-031218 | /models/piglatinizer.rb | UTF-8 | 498 | 3.78125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class PigLatinizer
VOWELS = ['a', 'e', 'i', 'o', 'u',
'A', 'E', 'I', 'O', 'U']
#Adapted from:
#https://stackoverflow.com/questions/18857300/the-pig-latin-translation
def piglatinize(str)
word_arr = str.split(" ")
word_arr.each do |word|
#If word begins with vowel
if VOWELS.include?(word[0..0])
... | true |
472096888ec4074d3f24d68744083e5913a3075c | Ruby | Metal-Milonga/ttt-10-current-player-v-000 | /lib/anotated_current_player.rb | UTF-8 | 1,102 | 4.53125 | 5 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # I'm using "array" to help understand how arguments are passed.
def turn_count(array)
# Initialize my turn counter. turn_count is expected var name for rspec.
turn_count = 0
# cycle through the array elements with "position" as the iteration.
array.each do |position|
# I could not get it to do postion == "X" || ... | true |
c1a3ebe5f47787bbabea0c19f7b73c26c8f13de8 | Ruby | turingschool-projects/activerecord-obstacle-course | /spec/models/aroc_week_2_spec.rb | UTF-8 | 5,556 | 2.9375 | 3 | [] | no_license | require 'rails_helper'
describe 'ActiveRecord Obstacle Course, Week 2' do
# Looking for your test setup data?
# It's currently inside /spec/rails_helper.rb
# Not a very elegant solution, but works for this iteration.
# Here are the docs associated with ActiveRecord queries: http://guides.rubyonrails.org/active_recor... | true |
4be348ec757d7ae246d6c5b490236bc042c2c0a9 | Ruby | manne05/RubyKurs | /Woche3/metaprogramming/human.rb | UTF-8 | 505 | 3.53125 | 4 | [] | no_license | require_relative "./attrPredicate"
class Human
extend AttrPredicate
attr_predicate :first_name, :last_name
def initialize(name = "")
@first_name, @last_name = name.to_s.split(/\s+/, 2)
end
end
Human.new.first_name? # => something falsy
Human.new.last_name? # => something falsy
Human.new("John").first_n... | true |
871aa0b00b3f432804378e7e7c22f95600d54bd3 | Ruby | RHM-rhuberdeau/automated_tests | /test/pages/berkeley/concerns/seo.rb | UTF-8 | 920 | 2.515625 | 3 | [] | no_license | module BerkeleySeo
class Seo
include ::ActiveModel::Validations
validate :canonical_links
def initialize(args)
@driver = args[:driver]
end
def canonical_links
anchor_links = @driver.find_elements(:css, "a").select { |x| x.attribute('rel') == "canonical" }.compact
link_tags ... | true |
76147a9ad8a8160fe1fe0e3c64b8479fbe858455 | Ruby | sheedhet/sheedhet-server | /app/services/play_executor.rb | UTF-8 | 1,631 | 2.78125 | 3 | [] | no_license | class PlayExecutor
class InvalidPlayError < StandardError; end
attr_reader :game, :play
def initialize(game_id:, play_params:)
@game = GameStore.load(game_id)
@play = Play.from_json(play_params.to_json)
rescue JSON::ParserError
raise InvalidPlayError
end
def valid?
game.valid_plays.any? {... | true |
14da08b374b2caf1713cadc478c9efb922a13f4a | Ruby | vijay-chandar/ruby | /16.rb | UTF-8 | 236 | 3.1875 | 3 | [
"MIT"
] | permissive | filename = ARGV.first
puts "Ok! Here it is"
target = open(filename,'w')
target.truncate(0)
puts "Enter the contents"
line = $stdin.gets.chomp
target.write(line)
target.close
target = open(filename)
# target.read()
print target.read
| true |
3f4809dd97709f9b5644d415c0fff8c86e3b02f5 | Ruby | dpholbrook/ruby_small_problems | /more_topics/easy_1/1.rb | UTF-8 | 337 | 3.03125 | 3 | [] | no_license | class Tree
include Enumerable
def each
# implementation for Tree class
end
def <=>
# implementation for Tree class
end
end
# After including the Enumerable module, the Tree#each and Tree#<=> methods
# will provide the underlying functionality necessary for the Enumerable
# instance methods to work ... | true |
dfcf9d32adcfadf971ecc96291b10643d03f6d82 | Ruby | RandyG3/Udemy | /Ruby/Section 03 Numbers and Booleans/31-Comparison_With_Inequality.rb | UTF-8 | 305 | 3.578125 | 4 | [] | no_license | p 10 != 5 # Boolean true
p 10 != 10 # False
p "Hello" != "Goodbye"
p "Hello" != "hello" # Case matters! This is true
# Settle on common standard for string comparison
p "Hello".downcase != "hello".downcase #normalized the strings for comparison
p "123" != 123 # These are not equal for string & Fixnum | true |
697b1d2b1e81bc0b379a353895bec41b538f3b98 | Ruby | melkotoury/rubyCourse | /string_functions.rb | UTF-8 | 237 | 3.5 | 4 | [] | no_license | string = "\t Hello World\n"
string.inspect
puts string.inspect
puts string.chomp
puts string.chop
string.include?("world")
puts string.include?("World")
string.replace("Kato")
puts string
string.index("a")
puts string.index("K") | true |
78ccefda3d0efc8043bfb94697dd1b62238e115c | Ruby | brenthaas/tic_tac_web | /app/models/game.rb | UTF-8 | 491 | 2.78125 | 3 | [] | no_license | class Game < ActiveRecord::Base
has_many :moves, -> { order('created_at ASC') }
def make_move(player:nil, location:)
player ||= next_player
game.make_move(player: player, location: location)
moves.create(player: player, location: location)
end
def next_player
game.next_player
end
def boar... | true |
cc007960bc1ef3d12b1b6356be2fbcaf007a75b1 | Ruby | my0shym/yukicoder | /tmplates/README.rb | UTF-8 | 174 | 3.1875 | 3 | [] | no_license | # 入力について
## 標準入力1つ
## 標準入力
H, W = gets.split.map(&:to_i)
# 繰り返し
## indexと一緒にn回繰り返す
n.times do |i|
puts i
end
| true |
e34dc64a7467692b7190585d05860d57b0e1961c | Ruby | basiclabs/api.crunchinator.com | /spec/lib/crunchbase_api/worker_spec.rb | UTF-8 | 8,752 | 2.546875 | 3 | [] | no_license | require 'spec_helper'
describe ApiQueue::Worker do
describe 'class methods' do
describe 'initialize' do
it 'should set state based on default values' do
worker = ApiQueue::Worker.new
expect(worker.instance_variable_get(:@id)).to be_nil
expect(worker.instance_variable_get(:@superviso... | true |
01b4a79b408682a6b48c4a9cf244d54b0928d866 | Ruby | samwich/advent_of_code_2020 | /16/day16.rb | UTF-8 | 4,477 | 4.03125 | 4 | [] | no_license | # --- Day 16: Ticket Translation ---
#
# As you're walking to yet another connecting flight, you realize that one of the legs of your re-routed trip coming up is on a high-speed train. However, the train ticket you were given is in a language you don't understand. You should probably figure out what it says before you ... | true |
072c084ab10fa801dae65b1bc949efa2ce0d2476 | Ruby | chriskirkland/advent-of-code | /2022/23/sol.rb | UTF-8 | 1,960 | 3.484375 | 3 | [] | no_license | # https://adventofcode.com/2022/day/23
$data = File.read("input.txt").split("\n")
def vadd(v1, v2)
[v1, v2].transpose.map(&:sum)
end
N, S, E, W = [-1, 0], [1, 0], [0, 1], [0, -1]
NW, NE, SW, SE = vadd(N,W), vadd(N,E), vadd(S,W), vadd(S,E)
ALL_DIRS = [N, S, E, W, NW, NE, SW, SE]
DIR_TO_SYM = {N => :N, S => :S, E =... | true |
ec483d32efe07d8feb96696f23f7b70087f43481 | Ruby | dgryphon/lich | /ticketbuyer.rb | UTF-8 | 3,322 | 2.6875 | 3 | [] | no_license | require 'rubygems'
require 'mechanize'
# USE THIS SCRIPT AT YOUR OWN RISK - GMs have mentioned banning people for using scripts to purchase tickets
# Do not try to run this like a regular lich script, this has to be run from the command prompt.
# This script must be renamed to ticketbuyer.rb and ran from the command... | true |
94fbc67fdf78c58f88504f20bcceeef2caebe45d | Ruby | HeRoMo/rubocop-performance-measurements | /benchmarks/count.rb | UTF-8 | 1,731 | 2.6875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# rubocop-performance
# Performance/Count
# see https://github.com/rubocop-hq/rubocop-performance/blob/master/manual/cops_performance.md#performancecount
require 'benchmark_driver'
output = :gruff
versions = ['2.3.8', '2.4.6', '2.5.4', '2.6.3', '2.7.0-preview1']
Benchmark.driver(output... | true |
4feb9362a183c7de9f83c7c2a54e2e6ec95457e6 | Ruby | Brockz1412/ICS-Course | /ch02/minutesInDecade.rb | UTF-8 | 289 | 4 | 4 | [] | no_license | puts "In a decade there is 10 years. Therefore,
in order to find out how many minutes have passed
in a decade we have to do simple math:"
puts 10*365*24*60
puts "This is the number of minutes for a decade in a regular year"
puts "Likewise this is for a leap year"
puts 10*366*24*60
| true |
f0d3eddf7f7b701b5003bbc40c58bf96cffd0398 | Ruby | ZoharLiran/technical_interview_questions | /roman.rb | UTF-8 | 546 | 3.53125 | 4 | [] | no_license | $roman_mapping = {1000 => "M",
900 => "CM",
500 => "D",
400 => "CD",
100 => "C",
90 => "XC",
50 => "L",
40 => "XL",
10 => "X",
9 => "IX",
5 => "V",
4 => "IV",
1 => "I" }
def roman_num(n) #so we know the order for sure
$breakpoint_values = []
$roman_mapping.each_key{|k| $breakpoint_values << k}
$break... | true |
46dc5d991b2b25c0087cafb9a73dff77bb020ebc | Ruby | roberts1000/rspec_n | /exe/rspec_n | UTF-8 | 2,927 | 2.671875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# This script runs the rspec_n executable.
#
# EXECUTION
#
# rspec_n # Run the project's RSpec test suite 10 times.
# rspec_n N # Run the projects's test suite N times.
#
# EXIT STATUS
#
# See below for exit status codes and their meaning.
lib = File.expand_path('../lib', __dir__)
$LOAD_PATH... | true |
c0f27d4155fd18344fa9a086d373351794b1a99c | Ruby | dinnerTime/advent2016 | /02/part1.rb | UTF-8 | 525 | 3.46875 | 3 | [] | no_license | require 'io/console'
result = ""
keypad = [
[1,2,3],
[4,5,6],
[7,8,9]
]
x = 1
y = 1
raw_input = IO.binread('input.txt')
lines = raw_input.split("\n")
lines.each do |line|
from = keypad[x][y].to_s
line.split('').each do |instruction|
case instruction
when 'U'
y = [y - 1, 0].max
when 'D'
y = [y + 1,... | true |
117afb11e17043fcfc4dfc6d507bdc7aa8b0703e | Ruby | J-Y/RubyQuiz | /ruby_quiz/quiz69_sols/solutions/Brian Mattern/golden_fib_ratio.rb | UTF-8 | 3,088 | 3.875 | 4 | [
"MIT"
] | permissive | #
# A helper class to generate the fibonacci sequence
#
# To get the ith fibonacci number simply call Fibonacci[i]
# You can also get a range with Fibonacci[start..finish]
# So, Fibonacci[0..10] = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
#
# The class calculates only those numbers it needs, at caches them for
# future re... | true |
81be150049e611ef237d991762872379c035b182 | Ruby | sebyx07/master-xml | /1/parser.rb | UTF-8 | 583 | 2.953125 | 3 | [] | no_license | require 'nokogiri'
require 'pry'
require 'ostruct'
require 'saxerator'
class User < OpenStruct
end
parser = Saxerator.parser(File.new('persons.xml'))
doc = File.open('persons.xml') do |f|
Nokogiri::Slop(f)
end
persons = doc.css('person').map do |node|
attr_list = [:name, :age]
attrs = {}
attr_list.each do |... | true |
e3417aba026fe5f2ffcd298cc8464b13e5e5c815 | Ruby | DUSAEN052/collections_practice_vol_2-dumbo-web-career-010719 | /collections_practice.rb | UTF-8 | 1,175 | 3.4375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # your code goes here
def begins_with_r(arr)
for item in arr
if item.start_with?("r") == false
return false
end
end
return true
end
def contain_a(arr)
output = []
for item in arr
if item.index('a') != nil
output.push(item)
end
end
return output
end
def first_wa(arr)
arr.eac... | true |
c0418de050d693a2d1a1a217f123688ad4439933 | Ruby | mariastenquist/projects | /credit_check.rb | UTF-8 | 689 | 3.71875 | 4 | [] | no_license | puts "Enter a card number:"
card_input = gets.chomp
numbers = card_input.split(//)
doubled = numbers.map.with_index do |num, index|
if index.even?
num.to_i * 2
else
num.to_i
end
end
summed = doubled.map do |num|
if num > 9
num - 9
else num < 9
num
end
end
total_num = summed.in... | true |
3d659459f57a88e6b7abb71e2f289a9bcffd0a12 | Ruby | rasnom/phase-0-tracks | /ruby/game/play_game.rb | UTF-8 | 348 | 3.578125 | 4 | [] | no_license | require_relative 'wordgame'
game = WordGame.new
puts "Shall we play a game?"
sleep(1.5)
puts "Of course we shall. Enter a secret word"
game.new_round(gets.chomp)
puts "Now guess letters in the word #{game.progress}."
while game.keep_playing?
guess = gets.chomp
game.guess?(guess)
puts game.progres... | true |
7838dee1df3921f739051ffb13a52a5921a48053 | Ruby | JacobKorn/ruby-land | /models/player.rb | UTF-8 | 247 | 3.03125 | 3 | [] | no_license | class Player
attr_reader :collected_gems
def initialize
@collected_gems = []
@current_location = nil
end
def move_to_location(location)
@current_location = location
end
def newest_gem
@collected_gems.last
end
end
| true |
1fb0d7ff10d2b6244f432daf9a27abaf8e3ff59a | Ruby | hadibadjian/gitstrider | /lib/gitstrider.rb | UTF-8 | 2,945 | 2.890625 | 3 | [
"MIT"
] | permissive | require 'find'
require 'fileutils'
require 'parallel'
require 'gitstrider/html_composer'
class GitStrider
def initialize(workspace, processes_threads, report_path = "CodeQualityReports/GitStrider/git_contribution.html")
@root = workspace
in_threads = 20
in_processes = processes_threads[:max_threads]
... | true |
91c8c9309f5ced2d03535e09a7912a1e1a4f97e4 | Ruby | rjp/srt | /spec/srt_spec.rb | UTF-8 | 2,484 | 3.125 | 3 | [
"MIT"
] | permissive | require 'srt'
describe SRT do
context "A single line" do
let(:line) { SRT::Line.new }
it "should be empty" do
line.should be_empty
end
it "should not be empty" do
line.text = "This is a test"
line.should_not be_empty
end
it "should have the correct time string" do
li... | true |
a703e0304bfcb44cd06629db89c54ca9d6817662 | Ruby | MrJoy/normalize_ruby | /spec/fixtures/filters/bare_control_statements/input.rb | UTF-8 | 449 | 3.296875 | 3 | [] | no_license | if(foo)
end
if ( foo ) # meh
end
if foo
end
if foo # foo
end
if(foo||bar)
end
if ( foo ||
bar )
end
if ( foo || # meh
bar ) # bleah
end
if foo||bar
end
if foo ||
bar
end
if ( ( foo ||
bar ) )
end
if ( foo ) ||
( bar )
end
if ( ( foo ) ||
( bar ) )
end
foo if(bar)
foo if ( bar ) # meh
... | true |
e28a46bc49124ec11c7b5590563dbce46617a5af | Ruby | Gerula/Books | /Design_patterns_in_Ruby/7/Iterator/enumerable_mixin.rb | UTF-8 | 646 | 3.84375 | 4 | [
"ISC"
] | permissive | class Account
attr_accessor :name, :balance
def initialize(name, balance)
@name = name
@balance = balance
end
def <=>(other)
self.balance <=> other.balance
end
end
class Portfolio
include Enumerable
def initialize
@accounts = []
end
def <<(account... | true |
c09b8876cd48e55b3c45484007c1faa12215e209 | Ruby | neener/apples-and-holidays-v-000 | /lib/holiday.rb | UTF-8 | 2,112 | 3.765625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def second_supply_for_fourth_of_july(holiday_supplies)
# given that holiday_hash looks like this:
# {
# :winter => {
# :christmas => ["Lights", "Wreath"],
# :new_years => ["Party Hats"]
# },
# :summer => {
# :fourth_of_july => ["Fireworks", "BBQ"]
# },
# :fall =>... | true |
6a2f24b028f627291971035207a9480c00345ecf | Ruby | heartcombo/devise-encryptable | /test/support/swappers.rb | UTF-8 | 657 | 2.703125 | 3 | [
"Apache-2.0"
] | permissive | module Support
module Swappers
def swap_with_encryptor(klass, encryptor, options={})
klass.instance_variable_set(:@encryptor_class, nil)
swap klass, options.merge(:encryptor => encryptor) do
begin
yield
ensure
klass.instance_variable_set(:@encryptor_class, nil)
... | true |
c691107655bc70431a8a734f851817873176b63b | Ruby | kengho/webster-puzzle | /app/models/dictionary.rb | UTF-8 | 9,000 | 2.640625 | 3 | [
"MIT"
] | permissive | # Usage:
# Production:
# dict = Dictionary.import!(Rails.root.join('app', 'lib', 'dictionary', 'dictionary_with_known_typos_fixed.json'))
# dict.collect_all_data(true)
# dict.linkify_all(true)
# Puzzle.populate!(dict, 100000)
# Development:
# dict = Dictionary.import!(Rails.root.join('app', 'lib... | true |
bff14eb08ef9b375d85b63a470d9a7e2a0dfd320 | Ruby | SidharthNambiar/Launch-School | /backend_prep/intro_to_programming/loops_and_iterators/ex_3.rb | UTF-8 | 451 | 4.09375 | 4 | [] | no_license | # Introduction to Programming
# Loops and Iterators
# Exercise 3
# Use the each_with_index method to iterate through an array of your creation
# that prints each index and value of the array.
my_fruits = ["apple", "banana", "cherry", "grape", "orange"]
my_fruits.each_with_index {|item, index| puts "#{index} --> #{i... | true |
f74e9d95d224f365753935440a4e11f9a67342fa | Ruby | siuying/hearthstone | /lib/hearthstone/log/data/game_player.rb | UTF-8 | 461 | 2.703125 | 3 | [
"MIT"
] | permissive | module Hearthstone
module Log
class GamePlayer
attr_accessor :id, :name, :first_player
attr_accessor :hero, :hero_power
def initialize(id: nil, name: nil)
@name = name
@id = id
@first_player = false
end
def to_hash
{
id: id,
name... | true |
727d27f025d748fba66ce5d06792d175361dc535 | Ruby | mitsuhirookuno/slack_transit_notifyer | /slack_transit_notifyer.rb | UTF-8 | 3,334 | 2.671875 | 3 | [] | no_license | require 'google_drive'
require 'pry'
require 'date'
require 'faraday'
require 'nokogiri'
require 'webmock'
require 'vcr'
require 'slack-notifier'
require 'dotenv/load'
require 'holiday_jp'
exit if HolidayJp.holiday?(Date.today)
SCHEDULED = ARGV[0]
class Notification
attr_accessor :name, :scheduled_at, :route, :hol... | true |
2550d88f3b76981b9111d2358a336cce3fb2d974 | Ruby | challengerST/ltool | /tol/windows/Koala/rubygems/gems/chunky_png-1.2.7/benchmarks/decoding_benchmark.rb | UTF-8 | 1,399 | 2.625 | 3 | [
"Apache-2.0",
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'rubygems'
require 'bundler/setup'
require 'benchmark'
require 'chunky_png'
def image_file(name)
File.join(File.dirname(__FILE__), '..', 'spec', 'resources', name)
end
def image_data(name)
data = nil
File.open(image_file(name), 'rb') { |f| data = f.read }
data
end
no_filtering_stream... | true |
025911594da9136b094b43b4915a6f9fa2794c67 | Ruby | JeffBenton/oo-cash-register-online-web-sp-000 | /lib/cash_register.rb | UTF-8 | 732 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class CashRegister
attr_accessor :total, :discount, :items, :last_transaction
def initialize(discount=false)
@total = 0.00
@discount = 20 if discount
@items = []
@last_transaction = []
end
def add_item(title, price, quantity=1)
@total += price * quantity
(1..quantity).each { |x| @item... | true |
f0e9551e1bcdabab66ebf7f56a3bb4cad78f9d27 | Ruby | AliLynne/extras | /brokenSequence.rb | UTF-8 | 451 | 3.8125 | 4 | [] | no_license | def find_missing_number(sequence)
sequence = sequence.split(" ").map { |n| n.to_i }.sort!
if sequence.empty?
return 0
else
y = 1
sequence.each do |num|
if num == y
y = y + 1
else
return y
end
end
end
end
puts find_missing_number("1 2 3 5")
puts... | true |
207807dfa29b5e27d0422a196861aac820fa50c3 | Ruby | FasterRising01/Ruby_Study | /ruby-study/name.rb | UTF-8 | 103 | 3.40625 | 3 | [] | no_license | puts "I"+"am"+"Sam"
puts "Samの年齢は"+27.to_s+"です"
puts 100+"200".to_i
puts 100+200
| true |
3fec184978320321ceffd4a0be61e7385184f536 | Ruby | catima/catima | /app/lib/image_tools.rb | UTF-8 | 779 | 2.765625 | 3 | [
"Apache-2.0"
] | permissive | module ImageTools
include MiniMagick
module_function
def thumbnail(src, dest, size, mode=:fill, crop=[0, 0, 100, 100])
return nil unless File.file?(src)
i = Image.open src
sz = size.map { |s| s.to_s }.join('x')
cr = crop.map { |n| n / 100.0 }
if mode == :fill
# Convert cropping from i... | true |
780f47a96b41145609b69671a034432ae312834d | Ruby | polezo/oo-relationships-practice-dc-web-091619 | /app/models/bakery.rb | UTF-8 | 1,103 | 3.34375 | 3 | [] | no_license | class Bakery
attr_accessor :name
@@all = []
def initialize(name)
@name = name
@@all << self
end
def desserts
Dessert.all.select { | dessert | dessert.bakery == self }
end
def ingredients
i_arr=[]
desserts.each do |i|
i_arr << i.ingred... | true |
81ce7b9a4db7b3d453560b94e1ada6e721d26c60 | Ruby | betterplace/betterlog | /lib/betterlog/log/severity.rb | UTF-8 | 1,172 | 2.703125 | 3 | [
"Apache-2.0"
] | permissive | require 'logger'
module Betterlog
class Log
class Severity
include ::Logger::Severity
include Comparable
class << self
thread_local :shared
def new(name)
name = name.to_sym if self.class === name
name = name.to_s.upcase.to_sym
self.shared ||= {}
... | true |
553f529efc48f17c9a9a854a1cfaee9f482f374f | Ruby | philest/ST-messenger | /lib/api/helpers/authentication.rb | UTF-8 | 3,528 | 2.796875 | 3 | [] | no_license | require_relative '../constants/statusCodes'
module AuthenticationHelpers
include STATUS_CODES
# return a JWT config payload
def payload(user_id, exp, type, start_time = Time.now)
config = {
exp: start_time.to_i + exp.to_i,
iat: start_time.to_i,
iss: ENV['JWT_ISSUER'],
user: {
user_id: user_i... | true |
c849aa6418b9f74ef885f325ebce70950141e1c9 | Ruby | shumanpng/ProjectHub | /test/models/group_test.rb | UTF-8 | 4,327 | 2.828125 | 3 | [] | no_license | require 'test_helper'
class GroupTest < ActiveSupport::TestCase
fixtures :groups # temporarily includes users in test/fixtures/groups.yml for testing
# This test is needed because a lot of the implementation of Tasks relies on having
# unique group names
test 'no duplicate names' do
g = Group.new(:deadli... | true |
685b60cf1b867de74063f37a7aadb0ec0c58121c | Ruby | sounishnath003/instagram-bots | /auto_follow.rb | UTF-8 | 1,037 | 2.75 | 3 | [
"MIT"
] | permissive | require 'watir'
require 'awesome_print'
require_relative './_credentials'
# define your credentials
username = $username
password = $password
# followers name
to_follow = "justinbieber"
# openning browser
browser = Watir::Browser.new :chrome
browser.goto("https://www.instagram.com/accounts/login/")
#... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.