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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
ad563580aeb89e951c29660e88b9fb8837b1cf17 | Ruby | rstacruz/embassy | /test/factories.rb | UTF-8 | 1,124 | 2.796875 | 3 | [] | no_license | require 'ffaker-ext'
# Returns a word that matches the given block's condition
def word(options={}, &blk)
while true
word = Faker::Lorem.word
break if yield(word)
end
word
end
def User.spawn(hash={})
hash[:email] ||= Faker::Internet.email
hash[:password] ||= 'password'
hash[:profile_na... | true |
1d6a4d52a95f0fb61e80a4c2025713ba997c764d | Ruby | kmamykin/funfair | /lib/funfair/pub_sub/publish_request.rb | UTF-8 | 2,101 | 2.890625 | 3 | [
"MIT"
] | permissive | module Funfair
module PubSub
# Represents an asynchronous request to publish event to an exchange.
# Usage:
# request = publisher.publish(exchange_name, message_data)
# request.callback { puts "Succeeded" }
# request.errback { |error_message| puts error_message }
# See: http://eventmachine.rub... | true |
b0fb1c6d2d9914922d3cbc9f1c2dbe8a9037d1ea | Ruby | RichardLW6/Tealeaf_Week2 | /oop_paper_rock_scissors/oop_prs2.rb | UTF-8 | 2,123 | 4.25 | 4 | [] | no_license | #OOP Paper, Rock, Scissors - Second Version (May/June 2015)
class Player
attr_accessor :player_choice
def initialize
@player_choice = ""
end
def player_chooses
begin
puts "Please choose Paper (P), Rock (R), or Scissors (S)..."
self.player_choice = gets.chomp.upcase
end until ['P', '... | true |
b881257b4c4e4b70b654aaeb7d5abaa5dbe17f9f | Ruby | kanon2580/tot | /app/models/tag.rb | UTF-8 | 408 | 2.671875 | 3 | [] | no_license | class Tag < ApplicationRecord
validates :name, presence: true
has_many :taggings
has_many :issues, through: :taggings
def self.search(team, q)
return team.tags if q == ""
splited_q = q.split(/[[:blank:]]+/)
tags = []
splited_q.each do |q|
next if q == ""
tags += team.tags.where('L... | true |
ddbf99e2796731b476b34d18f6bdcf4a701c5de8 | Ruby | bhatarchanas/add_ons_for_mcsmrt | /get_singletons_and_utax.rb | UTF-8 | 1,094 | 2.734375 | 3 | [] | no_license | require 'trollop'
require 'bio'
#ruby ../mcsmrt_mod/parse_all_info_file.rb -a all_bc_reads_info_first_few_lines.txt -o parsed_all_bc_reads_info.txt
opts = Trollop::options do
opt :allreadsfile, "File with all the reads", :type => :string, :short => "-r"
opt :allinfofile, "File with all the reads and information r... | true |
f99cb9ee5f841fa2624ddb41e3d1793687d80c2c | Ruby | camillesk/test_cr_api | /app/models/cart.rb | UTF-8 | 259 | 2.578125 | 3 | [] | no_license | class Cart < ApplicationRecord
belongs_to :customer
has_many :cart_items
def total_cart_price
total = 0
CartItem.all.map do |item|
med = Medicine.find(item.medicine_id)
total = item.quantity * med.value
end
total
end
end
| true |
6047295311a3b5b623c79af073a23aeba33195d4 | Ruby | josekim/phase-0-tracks | /databases/build_82/college_students.rb | UTF-8 | 1,062 | 2.78125 | 3 | [] | no_license | # require gems
require_relative 'build_database'
require_relative 'prompts'
done = false
puts WELCOME
input = gets.chomp
database = College_Students.new(input)
until database.database_done
end
until done
puts CMD_PROMPTS
input = gets.chomp
if input.to_i == 1
puts SEARCH_STUDENT_PROMPT
option = g... | true |
79a8b868bf08587fd60f0292319fcd69bfd31ca3 | Ruby | osak/Contest | /Euler/46.rb | UTF-8 | 556 | 3.453125 | 3 | [] | no_license | #!/usr/bin/ruby
def infinite_odd
n = 3;
while true do
yield n;
n += 2;
end
end
primes = Array.new;
isprime = Hash.new;
primes.push(2);
isprime[2] = true;
infinite_odd { |n|
root = Math.sqrt(n);
ok = true;
primes.each { |p|
break if p > root;
if n % p == 0 then
ok = false;
break;
end
}
if ok t... | true |
140ec2ff3e1269bfd5b46f4f46cdd60fceefeff6 | Ruby | KrakatoaComCafe/codefights | /Arcade/Intro/01 - The Journey Begins/2 - centuryFromYear/centuryFromYear.rb | UTF-8 | 180 | 3.203125 | 3 | [] | no_license | def centuryFromYear(year)
rest = year % 100
oldCentury = rest == 0
if oldCentury
return (year / 100)
else
return (year / 100 + 1)
end
end
| true |
da741aa8b0d96fc956f74da83b926045f5cfba01 | Ruby | BrentOnRails/App_Academy | /Feb11 - SQL/tag.rb | UTF-8 | 1,524 | 2.96875 | 3 | [] | no_license | require './QuestionsDatabase'
require './SQL.rb'
class Tag < Sql
attr_reader :id
attr_accessor :name
def self.all
users = QuestionsDatabase.instance.execute("SELECT * FROM tags")
users.map { |user| Tag.new(user) }
end
def self.find_by_id(id)
question = QuestionsDatabase.instance.execute(<<-SQL... | true |
ed26ff1571dbf4c84569f1753885d513813199ec | Ruby | CodeGrade/hourglass | /app/models/term.rb | UTF-8 | 1,422 | 2.765625 | 3 | [] | no_license | # frozen_string_literal: true
# A university Term, which consists of many courses.
class Term < ApplicationRecord
has_many :courses, dependent: :destroy
# these underscores make .humanize create a space ( ).
# rubocop:disable Naming/VariableNumber
enum semester: { fall: 10, spring: 30, summer_1: 40, summer: 5... | true |
822835488c679d92cc236e923b193e0bdf4d3358 | Ruby | victortyau/CodeEval | /Capitalize Words/cap.rb | UTF-8 | 394 | 3.65625 | 4 | [] | no_license | class CapWords
def initialize
@lines = ""
archivo()
end
def archivo
file_name = ARGV[0]
if File.exist?(file_name)
@lines = IO.readlines(file_name);
end
end
def mayusc
@lines.each do |line|
if !line.nil?
array_line = line.delete("\n").split(" ")
data = array_line.map(&:capitaliz... | true |
5127b1888eca4bb44cec8a0ac9baf26af6941d98 | Ruby | JNEdrozo/hotel | /lib/hotel_admin.rb | UTF-8 | 3,799 | 3.09375 | 3 | [] | no_license | require 'date'
require 'date_range'
require_relative 'room'
require_relative 'reservation'
require_relative 'BookingSystem_Errors'
module BookingSystem
class HotelAdmin
attr_reader :room_list, :reservation_list, :block_list
def initialize
#hotel admin knows all reservations (non-block and block)
... | true |
a7d35e2ba26e555b36346550fe92a3087e39ff3a | Ruby | Vwampage/dev-installday | /helloworld.rb | UTF-8 | 229 | 3.53125 | 4 | [] | no_license | # Hello World in Ruby -- Install day 12/17/12
puts "David Michaels"
puts "a potato in the oven"
puts "a potato on the counter"
puts "...but only once it's ready. that is when you puts a potato out of the oven."
puts "LINE LINE LINE" | true |
5a6958449176d85524f4ce95a1704bdcd81aa35f | Ruby | fela/rlid | /lib/rlid/misc/web_page.rb | UTF-8 | 2,156 | 3.375 | 3 | [
"MIT-0"
] | permissive | class NetworkError < StandardError
end
class WebPage
attr_reader :url
def initialize(url)
@url = url
end
# not really random, finds the most central link
def random_link
dump = `lynx -dump #{@url}`
# the second part contains the visible links
links = get_links_from_lynx_output(dump).split(... | true |
828199a97a6d252215bee618007982c408a9d526 | Ruby | kim2214/Datastructure | /atcoder/20_04_04/A - ABC Swap.rb | UTF-8 | 264 | 3.28125 | 3 | [] | no_license | X = gets.chomp.split(' ').map(&:to_i)
def swap_first(arr)
tmp = 0
tmp = arr[0]
arr[0] = arr[1]
arr[1] = tmp
end
def swap_second(arr)
tmp = 0
tmp = arr[0]
arr[0] = arr[2]
arr[2] = tmp
end
swap_first(X)
swap_second(X)
print X[0]," ",X[1]," ",X[2] | true |
28b89a389389279efcda28ab55932417e7673391 | Ruby | phlipper/ach | /lib/ach/records/nines.rb | UTF-8 | 476 | 2.78125 | 3 | [
"MIT"
] | permissive | module ACH::Records
# The number of records must be a multiple of ten (that is, complete 940
# character blocks). If needed, rows that consist of the digit "9" may be
# used to pad the the file.
#
# "Nines" records thus consist of a single constant field containing the digit
# "9" 94 times.
#
# ... | true |
001947c5e0f86de2f30ecdc5d8d6944f0a610bbe | Ruby | jeff-sherling/posh-o-matic | /test/unit/user_factory_address_test.rb | UTF-8 | 1,246 | 2.703125 | 3 | [] | no_license | $LOAD_PATH.push 'lib/data'
$LOAD_PATH.push 'lib/log'
require 'user_factory'
require 'minitest/autorun'
require 'minitest/reporters'
require 'console'
# UserFactory address-related unit tests
class UserFactoryAddressTest < Minitest::Test
Minitest::Reporters.use! [Minitest::Reporters::SpecReporter.new,
... | true |
8db21982ef15dcde4d1a75318cd82cf1a2664b4f | Ruby | johngrayau/jg_piawe | /spec/piawe_spec.rb | UTF-8 | 13,258 | 3.078125 | 3 | [] | no_license | require 'spec_helper'
describe Piawe::Person do
let (:valid) do
Piawe::Person.played_by ( {
"name" => "Ebony Boycott",
"hourlyRate" => 75.0030,
"overtimeRate" => 150.0000,
"normalHours" => 35.0,
"overtimeHours" => 7.3,
"injuryDate" => "2016/05/01"
} )
end
let... | true |
454976ec4b3ffa081f124f5118d3344a51e742a6 | Ruby | JuniorJoanis/CDD | /periodicity.rb | UTF-8 | 300 | 3.4375 | 3 | [] | no_license | class Periodicity
attr_accessor :number, :type
def initialize (number, type = "weekly")
@number = number
@type = type
end
def to_i
if @type == "day"
return @number * 3600 * 24
else
#the type is weekly
return @number * 3600 * 24 * 7
end
end
end
| true |
962bfc944c6daa2c3e2853707aee41f41143d700 | Ruby | iamnotnader/tinder_bot | /run_tinder.rb | UTF-8 | 2,072 | 3.03125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require_relative 'lib/pyro.rb'
require 'json'
# Get this using Charles Proxy
# http://nickfishman.com/post/50557873036/reverse-engineering-native-apps-by-intercepting-network
FACEBOOK_TOKEN = 'XXX'
FACEBOOK_ID = 'XXX'
# We need to sleep when we get rate-limited by Tinder.
SLEEP_SECONDS = 1800... | true |
d8942e73fd2360a8cf71fe71cd232c016c07c143 | Ruby | tmate/mdocker | /lib/mdocker/config/volumes_expansion.rb | UTF-8 | 1,479 | 2.703125 | 3 | [] | no_license | module MDocker
class VolumesExpansion
def self.expand(volumes=[], root:'')
Util::assert_type(Array, value: volumes)
volumes.inject([]) do |result, image|
result << expand_volume(image, root)
end
end
private
def self.expand_volume(volume, root)
Util::assert_type(Hash,... | true |
ed330b58a4f968208feabe10bc9035fa54a7142f | Ruby | dwnzhao/Sups | /app/models/user.rb | UTF-8 | 2,187 | 2.828125 | 3 | [] | no_license | class User < ActiveRecord::Base
has_many :items
acts_as_tagger
attr_accessor :password
EMAIL_REGEX = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
validates_presence_of :first_name
validates_length_of :first_name, :maximum => 25
validates_presence_of :last_name
validates_length_of :last_name, :maxim... | true |
10279978d23e2345b6920675300e05feeb22b427 | Ruby | devdevi/scrapingRuby | /scraping.rb | UTF-8 | 275 | 2.765625 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
# lista de todos los articulos de hackernews
html = open('https://news.ycombinator.com/')
doc = Nokogiri::HTML(html)
# buscamos todos lo elementos de clase title
doc.search('.title a').map do |element|
puts element.inner_text
end
| true |
fddfcac6e5ef78cb5b2b6c55e5a7b422da7471ba | Ruby | translation-gang/ru.hanami.github.io | /bundle/ruby/2.3.0/gems/middleman-deploy-1.0.0/lib/middleman-deploy/methods/sftp.rb | UTF-8 | 1,587 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'net/sftp'
require 'ptools'
module Middleman
module Deploy
module Methods
class Sftp < Ftp
def process
puts "## Deploying via sftp to #{self.user}@#{self.host}:#{path}"
# `nil` is a valid value for user and/or pass.
Net::SFTP.start(self.host, self.user, passwo... | true |
c50fa9d243ef3521970a56e603f47bc6c81c5380 | Ruby | softscienceprojects/OO-Get-Swole-london-web-080519 | /tools/console.rb | UTF-8 | 835 | 3.03125 | 3 | [] | no_license | # You don't need to require any of the files in lib or pry.
# We've done it for you here.
require_relative '../config/environment.rb'
# test code goes here
goldsgym = Gym.new(name: "Gold's Gym")
puregym = Gym.new(name: "Puregym")
virgin = Gym.new(name: "Virgin")
hulk = Lifter.new(name: "Inredible Hulk", lift_total: ... | true |
91b8e4e12831cab4f62c8866fb99a715f081b21a | Ruby | 10dollars/tendollars.github.io.raw | /_plugins/date_page_generator.rb | UTF-8 | 1,512 | 2.6875 | 3 | [] | no_license | module Jekyll
class DatePage < Page
def initialize(site, base, dir, title, posts)
@site = site
@base = base
@dir = dir
@name = 'index.html'
self.process(@name)
self.read_yaml(File.join(base, '_layouts'), 'interview_date.html')
self.data['title'] = title
self.da... | true |
a4203a4c3667a2e1c6266720c737a5803d7f16ea | Ruby | ambreenhasan/bookshelf | /app/models/book_ownership.rb | UTF-8 | 745 | 2.859375 | 3 | [
"MIT"
] | permissive | class BookOwnership < ActiveRecord::Base
belongs_to :user
belongs_to :book
def time_difference
seconds_since = (Time.now.to_i - self.updated_at.to_i)
if seconds_since >= 86400 #seconds per day
return days(seconds_since)
elsif seconds_since >= 3600 #seconds per hour
return hours(seconds_si... | true |
4ccf46e05eb41ea2426fe64df778d65fa4b203d4 | Ruby | rdallasgray/digestive | /lib/digestive/auth/service.rb | UTF-8 | 2,007 | 2.671875 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"MIT"
] | permissive | # encoding: UTF-8
module Digestive
module Auth
# Handles authentication of a credentialed object, using a given provider.
# The credentialed object will normally be a user, and the provider
# `ActionController::HttpAuthentication::Digest::ControllerMethods`.
# @!attribute [r] user
# @return [Ob... | true |
6879fd03d3ed5b7242cd75858045350937dc9e4a | Ruby | Coding-Knights/chess | /app/models/game.rb | UTF-8 | 8,253 | 3 | 3 | [] | no_license | class Game < ApplicationRecord
has_many :pieces, dependent: :destroy
has_many :users
has_many :moves, dependent: :destroy
validates :name, presence: true
scope :available, -> { where(black_player_id: nil)}
# after_create :populate_game!
def opponent(current_user)
current_user.id == white_player_... | true |
75c799f8f9f885792cd56858b18657e8c05bf03f | Ruby | chanhpark/in-theaters | /in-theaters1.rb | UTF-8 | 904 | 3.765625 | 4 | [] | no_license | require 'pry'
require 'json'
movie_data = JSON.parse(File.read("in_theaters.json"))
movies = movie_data["movies"] ###array of hashes
puts "In Theaters Now:\n "
def get_title(movie)
###returns movie title
return movie["title"]
end
def get_mpaa(movie)
###returns mpaa rating
return movie["mpaa_rating"]
end
d... | true |
9ba1c63e662487a8ff06ee2e771cee4099874dad | Ruby | dinnosaur/sinatra-mvc-lab-london-web-021720 | /models/piglatinizer.rb | UTF-8 | 1,103 | 3.625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class PigLatinizer
attr_accessor :word
# def initialize(word)
# @word = word
# end
def a_word(word)
letters = word.split("")
new_word = nil
new_letters = letters.dup
if letters[0] =~ /[aeiouAEIOU]/
letters.push("way")
new_word= lette... | true |
612cca11afdc5e9bbf31e3a323f075be5d78115b | Ruby | sadjehwty/pythonchallenge-solver | /ruby/level_8.rb | UTF-8 | 443 | 2.546875 | 3 | [] | no_license | # http://www.pythonchallenge.com/pc/def/integrity.html
require 'tempfile'
require 'rbzip2'
a={'user'=>"BZh91AY&SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07<]\xc9\x14\xe1BA\x06\xbe\x084",
'pwd'=>"BZh91AY&SY\x94$|\x0e\x00\x00\x00\x81\x00\x03$ \x00!\x9ah3M\x13<]\xc9\x14\xe1BBP\x91\xf08"}
a.each_ke... | true |
504a7cee962954d0b8333257095e08fb35254198 | Ruby | sabman83/leetcode | /komodo_health.rb | UTF-8 | 1,262 | 3.8125 | 4 | [] | no_license | #
# Your previous Plain Text content is preserved below:
#
# 99 fair coins, 1 biased coin (double sided heads)
# select 1 at random - flip it 10 times - record 10 heads in a row
#
# Probability that you selected the biaed coin?
#
# a => the coin is biased
# b => event of getting 10 heads
#
# P(a|b)
#
# P(b|a) = 1
#
# ... | true |
10cb1db53fc197cf98c855f358e41a65796fad8b | Ruby | patrickdavey/AoC | /2015/day12/json_walker_test.rb | UTF-8 | 1,334 | 3.65625 | 4 | [] | no_license | =begin
--- Day 12: JSAbacusFramework.io ---
Santa's Accounting-Elves need help balancing the books after a recent order. Unfortunately, their accounting software uses a peculiar storage format. That's where you come in.
They have a JSON document which contains a variety of things: arrays ([1,2,3]), objects ({"a":1, "... | true |
9e2050a9b9af9e397c9d162239d40fe9eb216e51 | Ruby | mholyoak/CardGame | /Game.rb | UTF-8 | 449 | 3.484375 | 3 | [] | no_license | require_relative 'deck'
require_relative 'Player'
class Game
def initialize (num_players)
@deck = Deck.new
@players = Array.new (num_players) {Player.new}
end
def deal (count)
count.times do
@players.each do |player|
player.receive (@deck.deal)
end
end
end
def play
... | true |
df442928bbfe5899d06e8b2e75daf48de9289cb9 | Ruby | ZnWen/Script.NET | /Src/Interps/Ruby/ruby-1.8.6/lib/ruby/1.8/wx/classes/image.rb | UTF-8 | 946 | 2.671875 | 3 | [
"MIT"
] | permissive | class Wx::Image
# Load a new image from an IO-like object that supports "read"
def self.read(an_io, type_or_mime, index = -1)
img = new
img.load_stream(an_io, type_or_mime, index)
img
end
# Create a new image from Wx::Bitmap, preserving mask information
def self.from_bitmap(bmp)
bmp.convert_t... | true |
1f56e8c5a2760c93a42522726af3f2dc012c67e6 | Ruby | kweic/grails_blog | /src/test/acceptanceTest/features/step_definitions/editing_a_post.rb | UTF-8 | 877 | 2.5625 | 3 | [] | no_license | require_relative "../../features/workflows/create_blog_post"
require_relative "../../features/workflows/edit_blog_post"
require_relative "../../features/workflows/page_interactions"
require_relative "../../features/workflows/main_page_elements"
include CreatePost
include EditPost
include PageInteractions
inclu... | true |
c1f1826790c5ea5b37b77557efaceab6cdc77c73 | Ruby | JoeQuattrone/intro-to-simple-array-manipulations-online-web-prework | /lib/intro_to_simple_array_manipulations.rb | UTF-8 | 486 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_push(x, y)
x = []
x.push(y)
end
def using_unshift(x, y)
x.unshift(y)
end
def using_pop(x)
x.pop()
end
def pop_with_args(x)
x.pop(2)
end
def using_shift(x)
x.shift()
end
def shift_with_args(a)
a.shift(2)
end
def using_concat(x, y)
x.concat(y)
end
def using_insert(x, y)
x.insert(4, y)... | true |
d27306701cce6e4f9e93325f854515fb267ac025 | Ruby | AaronD87/wagefinder | /app/services/inflation_service.rb | UTF-8 | 168 | 3.078125 | 3 | [] | no_license | class InflationService
def initialize(wage, years)
@years = years
@wage = wage
end
def inflation
((@wage * 1.024**@years) - @wage).to_i
end
end
| true |
ae2bcde1f6b2cc457add636c7ec0035da48fe027 | Ruby | brendanboyle87/seal-cori | /app/models/petition_generator.rb | UTF-8 | 2,146 | 2.59375 | 3 | [] | no_license | class PetitionGenerator
attr_reader :personal_information, :pdftk, :user
attr_accessor :info_hash
def initialize(personal_information)
@pdftk ||= PdfForms.new(ENV['PDFTK_PATH'] || '/usr/local/bin/pdftk')
@personal_information = personal_information
@user = personal_information.user
@info_hash = ... | true |
b3190065d37a2e011a4af09e4c3753e7806b26d7 | Ruby | Jonesyd/ls_101_programming_foundations | /03_lessons/05_02_duplication.rb | UTF-8 | 283 | 3.484375 | 3 | [] | no_license | # def color_valid(color)
# ["blue", "green"].include?(color.downcase) ? true : false
# end
# solution
def color_valid(color)
color == "blue" || color == "green"
end
p color_valid("blue")
p color_valid("green")
p color_valid("Blue")
p color_valid("Green")
p color_valid("red")
| true |
3f2d43273ad8d1573af39c42d39095413dcb9445 | Ruby | AssetoTrones/asset-o-tron | /db/seeds.rb | UTF-8 | 5,760 | 2.6875 | 3 | [] | no_license | # project_list = [
# ["Redradix Posters", "Technology posters created by redradix.", "", []],
# ["Asset-O-Tron", "Final project of Talentum Empleo developed by Ronald Romero, Nerea Díaz, Diego Sánchez, Lucas Gómez y Marco Antonio López de la Nieta.", "", [1,2,3,4,5,6]]
# ]
#
# project_list.each do |name,description... | true |
8b13383005c306d21cb3c59fce9809dc1a8ac54f | Ruby | benjpac/volunteer_tracker | /spec/volunteer_spec.rb | UTF-8 | 1,132 | 2.890625 | 3 | [] | no_license | require('spec_helper')
describe(Volunteer) do
describe('.all') do
it('returns all instances of Volunteer class, starts off with no projects') do
expect(Volunteer.all()).to eq([])
end
end
describe('#name') do
it('tells you the the volunteers name') do
test_volunteer = Volunteer.new({:nam... | true |
dffe315d9f8097047a43a454591cbcc40affcf02 | Ruby | sota1235/AOJ-Answers | /answers/Introduction/ALDS/alds1_2_a.rb | UTF-8 | 261 | 3.453125 | 3 | [] | no_license | #!/usr/bin/ruby
# AOJ
# ALDS1_2_A
# Buble Sort
gets
n = gets.split(' ').map{|i| i.to_i}
nl = n.length
ct = 0
nl.times do
(nl-1).downto(1) do |j|
if n[j-1] > n[j]
n[j-1], n[j] = n[j], n[j-1]
ct += 1
end
end
end
puts n.join ' '
puts ct
| true |
7e3bb9eaceaed84a63207a84bf172495e5959bc4 | Ruby | rezanrezano/reverse-each-word-re-coded-000 | /reverse_each_word.rb | UTF-8 | 221 | 3.671875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # sentence1="Hello there, and how are you?"
def reverse_each_word(sentence1)
index=0
result=[]
s=sentence1.split(" ")
while index<=s.length-1
result<<s[index].reverse
index+=1
end
result.join(" ")
end
| true |
773faa46b40efcd6ce4202c3ad8136ef4d6de3b6 | Ruby | taka9/Practice | /ruby/logger.rb | UTF-8 | 787 | 3.84375 | 4 | [] | no_license | # -*- encoding: utf-8 -*-
class Logger
def print message, level, &block
puts "\t" * level + '開始' + message
res = block.call
puts "\t" * level + '終了' + message + ', 戻り値' + res.to_s
return res
end
end
def checkNumber array, &block
count = 0
array.each do |item|
if block.call item
count ... | true |
233f0e137a64b6ffc25119aff45a67fb6abd8b0f | Ruby | snarf24/backend_module_0_capstone | /day_1/ex4.rb | UTF-8 | 1,945 | 3.96875 | 4 | [] | no_license | # Assigns the cars variable value to the integer 100
cars = 100
# Assigns the space_in_a_car variable value to the float 4.0
space_in_a_car = 4.0
# Assigns the drivers variable value to the integer 30
drivers = 30
# Assigns the passengers variable value to the integer 90
passengers = 90
# Assigns the cars_not_driven va... | true |
612bea5bc028e241df8b351c903d026f9ba4f1ab | Ruby | igorsimdyanov/ruby | /arrays/clear.rb | UTF-8 | 43 | 2.6875 | 3 | [] | no_license | arr = [1, 2, 3, 4, 5]
arr.clear
p arr # []
| true |
808e7c4359c0af39f590084d016c5bd7b1b57247 | Ruby | MasatoraAtarashi/Programming-Competition | /atCoder/ABC/172/d.rb | UTF-8 | 242 | 3.328125 | 3 | [] | no_license | require 'prime'
N = gets.to_i
answer = 0
1.upto(N) do |n|
prime_factors = n.prime_division
dividors_num = 1
prime_factors.map{|prime_factor| dividors_num *= (prime_factor[1] + 1) }
answer += dividors_num * n
end
print answers | true |
1e9372cdbfc67aab67f39615c3832407e309d294 | Ruby | danwyryunq/eis | /kata2/model/jugada.rb | UTF-8 | 400 | 2.90625 | 3 | [] | no_license | require_relative 'elemento'
class Jugada
def initialize(jugador, tipo_elemento)
@jugador = jugador
@elemento = tipo_elemento.new()
end
def empata_con? jugada
return @elemento.empata_con? jugada.elemento
end
def le_gana_a? jugada
return @elemento.le_gana_a? jugada.elemento
end
def ju... | true |
b38b8d2b4cb7872058fad08228e802bf66cfffb1 | Ruby | fashion-data-exchange/s3_client | /lib/fde/s3_client.rb | UTF-8 | 2,278 | 2.53125 | 3 | [
"Apache-2.0"
] | permissive | require 'aws-sdk-s3'
require "fde/s3_client/version"
module FDE
module S3Client
class AWSAccessKeyIDNotDefinedError < StandardError; end
class AWSSecretAccessKeyNotDefinedError < StandardError; end
class AWSRegionNotDefinedError < StandardError; end
class AWSS3BucketNameNotDefinedError < StandardErr... | true |
5d2751e0f6028717139e955bd0f8c5f969df9fef | Ruby | drdrongo/rails-reddit | /db/seeds.rb | UTF-8 | 922 | 2.953125 | 3 | [] | no_license | def populate_comments(user, post)
rand(0..2).times do
comment = Comment.new(
content: Faker::TvShows::MichaelScott.quote
)
comment.user = user
comment.post = post
comment.save
end
end
def populate_posts(user)
rand(0..10).times do
post = Post.new(
title: Faker::Hacker.noun,
... | true |
aeda5408ace8c75e2fdaddf0246b8b4cfacd7ad7 | Ruby | adamsb6/time-series-data | /test/test_time_series_bucket.rb | UTF-8 | 3,292 | 3.234375 | 3 | [
"MIT"
] | permissive | require "test/unit"
require "lib/time_series"
require 'set'
class TestTimeSeriesBucket < Test::Unit::TestCase
# Create a series of test objects,
# one for each allowed grouping period.
def setup
@test_start_point = "2010-01-01T00:45:30+00:00"
@start_time = Time.parse( @test_start_point )
@period =... | true |
f439bdb7ddad0cd9e376a064f909394565c524a0 | Ruby | rajatagrawal/Data-Structures | /node.rb | UTF-8 | 99 | 2.9375 | 3 | [] | no_license | class Node
attr_accessor :value, :next
def initialize(value=nil)
@value = value
end
end
| true |
9c0600acb74a7ef745b38a375469cfc5ed6652a1 | Ruby | bcorner13/chef-couchbase | /libraries/clustercheck.rb | UTF-8 | 3,028 | 3.15625 | 3 | [
"MIT"
] | permissive | require 'net/http'
require 'json'
# I know this is a bit of a mess to begin with
# This whole thing needs to be rewritten as a class
# rubocop:disable Metrics/MethodLength
def get_node_json(ipaddress, username, password)
uri = URI("http://#{ipaddress}:8091/pools/default")
check = Net::HTTP::Get.new(uri)
check.ba... | true |
a14439c567e889394522e5ddab81ac8185a207fd | Ruby | phoffmann/BP01 | /app/models/training.rb | UTF-8 | 3,349 | 3.21875 | 3 | [] | no_license | class Training
attr_accessor :items
@items
def initialize
@items = []
end
def add_activity(activity)
@items << activity
end
def find_activity(id)
@result = nil
if @items.size > 0
i = 0
for item in @items do
if item.id == id
@result = i
end
... | true |
3bbd23d331f8fb18a608fda3e4f8c15255cba2e9 | Ruby | kgrz/string_dup | /without_freeze.rb | UTF-8 | 973 | 2.625 | 3 | [] | no_license | require 'allocation_tracer'
class WithoutFreeze
IM_A_CONSTANT = "a string"
ANOTHER_CONSTANT = "This is a string"
def run
1000.times do
ANOTHER_CONSTANT.gsub(IM_A_CONSTANT, ''.freeze)
end
end
end
ObjectSpace::AllocationTracer.setup(%i{path line type})
object_without_freeze = WithoutFreeze.new
... | true |
63f0f011c152fc0d00b07b0d67daa0ff69a46c93 | Ruby | eli-zbth/DL_Fundamentos_Ruby | /02_Ciclos_y_metodos/pptijera2.rb | UTF-8 | 976 | 4.125 | 4 | [] | no_license | def jugada_to_string(jugada)
if jugada ==1
return "Piedra"
elsif jugada ==2
return "Papel"
else
return "Tijera"
end
end
def jugada(numero_jugador)
inicio = "Turno jugador #{numero_jugador}:
1. Piedra
2. Papel
3. Tijeras
4. Salir
Ingrese opción a jugar:"... | true |
d4665d2d19ab5c42633da74a2d04b413d021af05 | Ruby | foondar/freebooterbot | /lib/generator.rb | UTF-8 | 1,178 | 2.890625 | 3 | [] | no_license | class Generator
def self.table_generate contents, top = true, modifier = -1
options = []
contents.split("\n")[0..modifier].each{|o| option, weight = o.split("*"); weight = 1 unless weight; weight.to_i.times {options << option}}
description = roll_dice(reroll(inject_sub_generators(options[rand(options.size... | true |
5c0f8dca991e35539f45fdb1d1528f749392aa4d | Ruby | Bis87/goodprogrammers_2 | /lesson_6_7/Shop/product.rb | UTF-8 | 641 | 3.484375 | 3 | [] | no_license | class Product
def initialize(price, quantity)
@quantity = quantity
@price = price
end
def self.show_products(products)
puts "Что вы хотите купить?"
puts ""
products.each_with_index do |product, index|
puts "#{index}: #{product.show}"
end
end
def buy
if ... | true |
a586cc15ee5121e7f3b777ec17970884965c6245 | Ruby | misturfixit/tictac | /tests/marktest.rb | UTF-8 | 7,773 | 2.8125 | 3 | [] | no_license | require "minitest/autorun"
require_relative "pc_seq.rb"
require_relative "pc_ran.rb"
require_relative "pc_unbeets.rb"
require_relative "console.rb"
require_relative "board.rb"
class Test_marker < Minitest::Test
###((((((1)))((((((()))))((((((MarkTest))))))(((((()))(((((())))))))))###
def test_marker
player = Play... | true |
62f376ae537f3d20e9661b2fe36195dca3f2d710 | Ruby | rumman07/rubyonrails | /ruby_code_sample/array_any_all.rb | UTF-8 | 144 | 3.15625 | 3 | [] | no_license | numbers = [3, 5, 7, 9, 11, 12]
p result = numbers.any? { |num| num.even? }
result2 = numbers.all? do |num|
num.even?
end
p result2 | true |
3f08eac86b217a90c7585d008ff71e4e46e72a6e | Ruby | Flora-manda/Two_player_game | /players.rb | UTF-8 | 232 | 3.296875 | 3 | [] | no_license | class Players
attr_reader :name
attr_accessor :highest_life
def initialize(name)
@name = name
@highest_life = 3
end
def looses_life
@highest_life -= 1
end
def dead?
@highest_life <= 0
end
end
| true |
d6fcd87009500b1e372713c7096dd05b0ba0e91e | Ruby | sassafracas/programming_languages-nyc-web-042318 | /programming_languages.rb | UTF-8 | 386 | 2.90625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
def reformat_languages(languages)
new_hash = {}
languages.each do |style, style_data|
style_data.each do |prog_lang, type_hash|
if new_hash[prog_lang] == nil
new_hash[prog_lang] = type_hash
new_hash[prog_lang][:style] = [style]
else
new_hash[prog_... | true |
23417e6f69f742b6f7343f2b33ea15c138ad1104 | Ruby | ChewbaccaJerky/Code-Challenges | /practice-thy-algorithms/CTCI/lib/chapter5/5_3_flip_bit_to_win.rb | UTF-8 | 565 | 3.90625 | 4 | [] | no_license | =begin
You have an integer and you can flip exactly one bit from a 0 to 1.
Write code to find the length of the longest sequence of 1s you could create.
=end
def flip_bit_to_win(num)
num_str = num.to_s(2)
max = 0
num_str.each_char.with_index do |bit, i|
if bit == '0'
test_str... | true |
18dbc8a58cad3c2821b2fe8884175a250191147d | Ruby | inspec/train-aws | /test/unit/transport_test.rb | UTF-8 | 1,928 | 2.5625 | 3 | [
"Apache-2.0"
] | permissive | # This is a unit test for the AWS Train Plugin.
# Its job is to verify that the Transport class is setup correctly.
# Include our test harness
require_relative "../helper"
# Load the class under test, the Plugin definition.
require "train-aws/transport"
# Because InSpec is a Spec-style test suite, we're going to use... | true |
540250649a27b6dd56a2b5ce3b35fdd1ac2e3409 | Ruby | artjomjuferov/simple_test_rails | /lib/group_event/all_fields_are_required.rb | UTF-8 | 347 | 2.5625 | 3 | [] | no_license | class GroupEvent::AllFieldsAreRequired
def initialize group_event
@group_event = group_event
end
def call
%w[user_id name description location duration date_start].each do |field|
return unless present? field
end
true
end
private
def present? key
value = @group_event.send(key)
... | true |
e1174c09c2c9d9a8c057bbcde3e50cf97b33bfe6 | Ruby | sarat1669/h264_bitstream_parser | /scantype.rb | UTF-8 | 3,796 | 2.5625 | 3 | [] | no_license | require 'tempfile'
require 'posix/spawn'
def run_cmd_with_response(cmd, return_exit_code=false)
include POSIX::Spawn
raw_response = `#{cmd}`
successful = true
exit_status = $?.exitstatus
if exit_status != 0
puts "cmd failed: \n#{raw_response}"
successful = false
end
return exit_status, raw_respo... | true |
249806c510413fc3f73daa4ca190ff6b208af18b | Ruby | tomasc/hashtags | /lib/hashtags/builder.rb | UTF-8 | 2,017 | 2.703125 | 3 | [
"MIT"
] | permissive | module Hashtags
class Builder < Struct.new(:options)
def self.to_markup(str, options = {})
new(options).to_markup(str)
end
def self.to_hashtag(str, options = {})
new(options).to_hashtag(str)
end
def self.dom_data(options = {})
new(options).dom_data
end
def self.help(op... | true |
f8bd0efa722dd79a841b709661d27a1d094130bc | Ruby | pmacaluso3/BumpBoysServer | /app/models/user.rb | UTF-8 | 555 | 2.625 | 3 | [
"MIT"
] | permissive | class User < ActiveRecord::Base
has_many :contacts
has_secure_password
def contacts_who_are_also_users
self.contacts.select do |contact|
User.find_by(stored_phone_number: contact.phone_number)
end
end
def has_as_contact?(test_contact)
self.contacts.select do |contact|
contact.phone_n... | true |
08991dc770819bef41ec7199bf2aba079f5ff43f | Ruby | alinadin09/phase-0-tracks | /calculator.rb | UTF-8 | 949 | 4.1875 | 4 | [] | no_license |
def interface
puts "Push ENTER to run program (Type exit to quit)"
user_input = gets.chomp
until user_input == "done"
# Prompt the user for a calculation that the user would like to perform, and make each character an element of an array:
puts "Please enter your desired equation:"
equation = gets.chomp... | true |
0f47e8aa669edafe95e5b4d36f622ebf6eed2c55 | Ruby | tmck-code/codeeval | /easy/Ruby/SetIntersection/SetIntersection.rb | UTF-8 | 716 | 3.390625 | 3 | [
"MIT"
] | permissive | File.open(ARGV[0]).each_line do |line|
tmp = line.rstrip.split(';')
l1 = tmp[0].split(',')
l2 = tmp[1].split(',')
str = ""
n = (l1.length * l2.length)
n1 = l1.first
n2 = l2.first
for i in 1..n
if n1 == n2
str << "#{n1},"
l1.shift
l2.shift
... | true |
c74b65037a8ec9b5a0fc2f6aa0b27275bb3f5e41 | Ruby | ayafujiaya/ofxHuez | /bin/tweet_to_txt.rb | UTF-8 | 1,295 | 2.875 | 3 | [] | no_license | # -*- coding: utf-8 -*-
require 'oauth'
require 'JSON'
require 'uri'
path_to_txt = "/Users/Yuki/work/ofxHuez/search_result.txt"
class TwitterConnects
@@CONSUMER_KEY = ''
@@CONSUMER_SECRET = ''
@@ACCESS_TOKEN = ''
@@ACCESS_TOKEN_SECRET = ''
def getTweets(encodedQuery)
consumer = OAuth::Consumer.new(
@@CONSU... | true |
e884c5f72329baec44306ed62e30f9e9579216b9 | Ruby | marcioaleson/Ruby | /threads/thread3.rb | UTF-8 | 226 | 3.078125 | 3 | [] | no_license | # encoding: utf-8
proc = Proc.new do |parametro|
parametro.times do |valor|
print "[#{valor+1}/#{parametro}]"
sleep 0.5
end
end
thread = nil
5.times do |valor|
thread = Thread.new(valor,&proc)
end
thread.join
puts "Terminado!" | true |
56be8ecf4295ac5217ca144cdcc9811720a6608d | Ruby | achempion/appsignal-ruby | /lib/appsignal/marker.rb | UTF-8 | 704 | 2.90625 | 3 | [
"MIT"
] | permissive | module Appsignal
class Marker
attr_reader :marker_data, :config
ACTION = "markers"
def initialize(marker_data, config)
@marker_data = marker_data
@config = config
end
def transmit
transmitter = Transmitter.new(ACTION, config)
puts "Notifying AppSignal of deploy with: "\
... | true |
45d4368b9748ee63b4fef28c99095fac0e795077 | Ruby | sshpm/sshpm-ruby | /lib/sshpm/tasks/builder.rb | UTF-8 | 463 | 2.609375 | 3 | [
"MIT"
] | permissive | module SSHPM
module Tasks
# A helper entity whose intent is to provide and idiom to task
# creation DSL
class Builder
def initialize
@attributes = {}
end
attr_reader :attributes
def method_missing(name, *args)
attributes[name] = args[0]
end
def self.b... | true |
8e295ce0d9544cd531993db46c31011f69e0efff | Ruby | sprax/ruby | /fibonacci.rb | UTF-8 | 373 | 3.75 | 4 | [] | no_license | #!/usr/bin/ruby
#
# Sprax Lines 2007 ?
# naive recursion
def fib_rec(n)
return n if (0..1).include? n
fib_rec(n-1) + fib_rec(n-2) if n > 1
end
count = 36
if ARGV.length > 0
count = ARGV[0].to_i
end
puts "First #{count} Fibonacci numbers using naive recursion:"
count.times do |i|
f = fib_rec(i)
printf... | true |
315eb31aa1e9d502cf29efdbd63bd68adda004db | Ruby | syounger-ut/exercism | /ruby/roman-numerals/roman_numerals.rb | UTF-8 | 1,041 | 4.03125 | 4 | [] | no_license | require 'pry'
class Fixnum
ROMAN_NUMERALS = {
'1' => 'I',
'5' => 'V',
'10' => 'X',
'50' => 'L',
'100' => 'C',
'500' => 'D',
'1000' => 'M'
}
def to_roman
# Break the number into Thousands, Hundreds, Tens and Ones, and write down each in turn.
n = self
number_of_chars... | true |
e68e2f5067e77578e05938cb1a5814f030f322c8 | Ruby | iandeth/trials | /ruby/basics/cgi/erb.cgi | UTF-8 | 903 | 2.78125 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/local/bin/ruby -w
require 'cgi'
require 'erb'
include ERB::Util # enable <%=h %> and <%=u %>
cgi = CGI.new 'html4'
puts cgi.header( 'charset'=>'UTF-8' )
text = '@a << 2'
url = 'http://.../?prm=あいう'
tmpl = %q{
<?xml version="1.0" encoding="euc-jp"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
... | true |
275238b0a908154d73bfd2a77405fc50ef34f9f3 | Ruby | twblalock/jsondiff | /main.rb | UTF-8 | 659 | 2.90625 | 3 | [] | no_license | # the goal: print both jsons side-by-side and highlight the differences
# test representation doesn't matter -- only the JSON objects are compared
require "json"
require "./jsondiff"
def readJson(filename)
begin
return JSON.parse(File.read(filename))
rescue Exception => e
puts "error parsing ... | true |
7e0f102cf6fffb717ca9736f521356c63922a542 | Ruby | belette06/ruby | /pyramide.rb | UTF-8 | 156 | 3.359375 | 3 | [] | no_license |
puts "Combien d'étages veux-tu ?"
n = Integer(gets.chomp)
diese = "#"
espace = " "
(n-1).downto(0) do |k|
puts "#{espace*k}#{diese*(n-k)}"
end | true |
eed37b1be4131ad9232978461158a7f0a29677f2 | Ruby | danivcupples/ruby_practice | /crayon.rb | UTF-8 | 222 | 4.1875 | 4 | [] | no_license | # Write a program that asks for your favorite Crayola crayon and then takes the string and yells it back in all caps and in reverse.
puts "What is your favorite Crayola crayon?"
fav = gets.chomp.upcase
puts fav.reverse
| true |
14197fda2dd4587cb79ada19e2a0a3fda059e4f0 | Ruby | jmoses/pages-to-pdf | /app/models/page.rb | UTF-8 | 563 | 2.59375 | 3 | [] | no_license | require 'open-uri'
class Page
TARGET = "QuickLook/Preview.pdf"
attr_accessor :url
def initialize( url = nil )
@url = url
end
def pdf
tempfile = fetch_file
preview( tempfile.path ).tap do
tempfile.close
end
end
protected
def fetch_file
Tempfile.new("pdfzip", Rails.root.... | true |
acc9ee4a6dc3f8d2b1749ebe807021cb2e1602fc | Ruby | lorenzograndi4/bootcamp | /buy.rb | UTF-8 | 1,216 | 3.90625 | 4 | [] | no_license | # selection method
def selection
puts "Which drink would you like? (1-4)"
drink_id = gets.chomp.to_i
if drink_id != 1 && drink_id != 2 && drink_id != 3 && drink_id != 4
puts "Sorry, this is not available."
selection
end
return drink_id
end
#confirmation method
def confirmation(drink_id)
puts "Add #{$dri... | true |
3c5cb3eb87666f4e78a44966e8bfe1bf4285cef5 | Ruby | dehormazah/test | /app/models/history.rb | UTF-8 | 2,570 | 2.71875 | 3 | [] | no_license | # == Schema Information
#
# Table name: histories
#
# id :integer not null, primary key
# description :text
# genre :string
# birth_date :date
# age :integer
# weight :integer
# height :integer
# start :datetime
# num_achi... | true |
e95cbb61e401a38a8f696d6ba1391dfa54e196bd | Ruby | Kamiichi/tryToRuby | /Chapter1/comment_sample.rb | UTF-8 | 392 | 3.15625 | 3 | [] | no_license | # coding: utf-8
=begin
「たのしいRuby 第6版」サンプル
コメントの使い方の例
2006/06/16 作成
2006/07/01 一部コメントを追加
2006/01/01 第6版用に更新
=end
x = 10 #横
y = 20 #縦
z = 30 #高さ
#表面積と体積を計算する
area = (x*y + y*z + z*x) * 2
volume = x * y * z
# 出力する
print "表面積=", area, "\n"
print "体積=", volume, "\n"
| true |
12f528890558d3c5c5ea444eabde4b85447b3525 | Ruby | devmicka/Mardi-Week2-THP-Exo-Ruby | /exo_04.rb | UTF-8 | 164 | 3.71875 | 4 | [] | no_license | puts "Quel est votre année de naissance?"
print "> "
birth_year = gets.chomp
age= 2021-birth_year.to_i
print "Dans 100 ans vous aurez "
print age + 100
print" ans" | true |
bc067681fd4dde916a983b0eeac8fa4c5ea331ac | Ruby | ben-harvey/Small-problems-Ruby | /more topics/medium1/2.rb | UTF-8 | 1,254 | 3.40625 | 3 | [] | no_license | TEXT = "Eiusmod non aute commodo excepteur amet consequat ex elit. Ut excepteur ipsum
enim nulla aliqua fugiat quis dolore do minim non. Ad ex elit nulla commodo
aliqua eiusmod aliqua duis officia excepteur eiusmod veniam. Enim culpa laborum
nisi magna esse nulla ipsum ex consequat. Et enim et quis excepteur tempor ea
... | true |
e31b1356ebf5ac766ab9eae6a86546f01df4100d | Ruby | molotof/ear | /app/models/object_mapping.rb | UTF-8 | 848 | 2.578125 | 3 | [
"BSD-2-Clause"
] | permissive | class ObjectMapping < ActiveRecord::Base
belongs_to :task_run
def get_child
EarLogger.instance.log "Trying to find #{child_type}:#{child_id}"
begin
eval "#{child_type}.find #{child_id}"
rescue ActiveRecord::RecordNotFound => e
EarLogger.instance.log "Oops, couldn't ... | true |
165bf8e65315088372262b5c6bdff3254546e250 | Ruby | hashrocket/clearance | /test/rails_root/vendor/plugins/facebooker/lib/facebooker/models/friend_list.rb | UTF-8 | 299 | 2.625 | 3 | [
"MIT"
] | permissive | require 'facebooker/model'
module Facebooker
##
# A simple representation of a photo album.
class FriendList
include Model
attr_accessor :flid, :name
# We need this to be an integer, so do the conversion
def flid=(f)
@flid= ( f.nil? ? nil : f.to_i)
end
end
end | true |
4e3c1d5b705455f876f90ade6191b4433e7b74fd | Ruby | piecedigital/learn-ruby-projects | /02_calculator/calculator.rb | UTF-8 | 352 | 3.71875 | 4 | [] | no_license | def add(a,b)
a+b
end
def subtract(a,b)
a-b
end
def sum(numbers)
numbers.inject(0) { |sums, number| sums + number }
end
def multiply(numbers)
numbers.inject { |sum, number| sum * number }
end
def power(numbers)
numbers.inject { |sum, number| sum ** number }
end
def factorial(numbers)
(1.... | true |
ca3b4e7d3983fc9b5e280ce4b41746d97fd3cefe | Ruby | cristobalparedesn/Desarrollo-de-aplicaciones-web-con-Rails | /Desafio2/Ejercicio1/usuario.rb | UTF-8 | 534 | 3.328125 | 3 | [] | no_license | require_relative('./cuentabancaria.rb')
class Usuario
attr_accessor :name_user, :cuentas
def initialize(name_user, cuentas =[])
@name_user = name_user
@cuentas = cuentas
end
def saldo_total
puts @cuentas.map {|cuentas| cuentas.saldo}.sum
end
end
cuentas_bancarias = [CuentaBancaria.new(... | true |
e79aa7560d0729ebb5a1998d738a94646875f128 | Ruby | beccalou/ga-lab-rspec-geometry | /lib/triangle.rb | UTF-8 | 302 | 3.1875 | 3 | [] | no_license | module Geometry
class Triangle
def initialize(sideA, sideB, sideC)
@sideA = sideA
@sideB = sideB
@sideC = sideC
end
def perimeter
@sideA + @sideB + @sideC
end
def area
(0.5*(@sideA)) * @sideB
end
def angle
end
def is_triangle
end
end
end
| true |
3faf21a7a7abd5232a484e7cf2d6b1728f865ca9 | Ruby | nnnnon/rails | /activemodel/lib/active_model/validations/confirmation.rb | UTF-8 | 2,562 | 2.796875 | 3 | [] | no_license | module ActiveModel
module Validations
module ClassMethods
# Encapsulates the pattern of wanting to validate a password or email address field with a confirmation. Example:
#
# Model:
# class Person < ActiveRecord::Base
# validates_confirmation_of :user_name, :password
... | true |
840fac8c536871f84c3a4bb7ba3fbee3d9c20305 | Ruby | junkmechanic/SciSWING | /src/Features/Tf_idf.rb | UTF-8 | 6,034 | 2.90625 | 3 | [] | no_license | #/usr/bin/ruby
# encoding: UTF-8
### 25/05/2014 - Ankur
# TODO: This script
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/..')
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../..')
require 'json'
require 'set'
require 'lib/ptb_tokenizer'
require 'lib/stopwords/StopList'
$IDF = Hash.new
def prepare_IDF
idf_dir =... | true |
e7edfda037098a43160e904684ecce219c132088 | Ruby | juliansample/ProgrammingClass2015-2016 | /asighnment4 | UTF-8 | 330 | 3.75 | 4 | [] | no_license | # puts "How many hours do you work?"
# diameter = gets.to_i
# radius = diameter / 2
# puts "The radius is #{radius}"
puts "How many hour do you work?"
hours = gets.to_i
puts "How much do you make per hour?"
money = gets.to_i
puts "How many weeks did you work?"
weeks = gets.to_i
puts "I would make #{hours,mone... | true |
9fa686345621a0bc90478b99838ff5b54b9b7155 | Ruby | wintonpc/funzip | /spec/funzip_spec.rb | UTF-8 | 1,265 | 2.859375 | 3 | [] | no_license | require 'rspec'
require 'funzip'
require 'tmpdir'
describe Funzip do
describe '::unzip' do
it 'unzips' do
%w(test windows).each do |name|
Dir.mktmpdir do |dir|
Funzip.unzip(zip_path(name), dir)
expect(content_of(dir, 'a.txt')).to eql 'a'
expect(content_of(dir, 'b/c.txt... | true |
e21d459dfc3b780738963b9bf8be5d102cbb3268 | Ruby | AmanziTel/cpn | /lib/cpn/observable.rb | UTF-8 | 1,005 | 2.59375 | 3 | [
"Apache-2.0"
] | permissive | require 'observer'
module CPN
module Observable
def on(ops, &block)
ops = [ ops ] unless ops.respond_to?(:each)
@observers ||= {}
ops.each do |op|
raise "Unsupported op #{op}" unless observable_event_type?(op)
@observers[op] ||= []
@observers[op] << block
end
... | true |
0dffb73703308b6da3c78612129630d393e1eb72 | Ruby | jigneshkapuriya/ruby_learning | /The_fetch_method.rb | UTF-8 | 169 | 3.203125 | 3 | [] | no_license | names = ["Pooja","Jignesh","Ravi"]
p names[2]
p names[100]
p names.fetch(2)
p names.fetch(100, "Monika")
numbers = [1,3,5,7,9,15,21,19]
p numbers[2,4]
p numbers[2..4]
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.