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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
e1251dcf1a4533c31dfeced2ccdb60ec21ae1005 | Ruby | scottzero/pantry_1906 | /lib/ingredient.rb | UTF-8 | 162 | 3.4375 | 3 | [] | no_license | class Ingredient
attr_reader :name, :unit, :calories
def initialize(name,unit,calories)
@name = name
@unit = unit
@calories = calories
end
end
| true |
c166b63f95da31340ed8b3e34a786f07656a5035 | Ruby | sparklemotion/http-cookie | /lib/http/cookie_jar.rb | UTF-8 | 9,811 | 3.046875 | 3 | [
"MIT"
] | permissive | # :markup: markdown
require 'http/cookie'
##
# This class is used to manage the Cookies that have been returned from
# any particular website.
class HTTP::CookieJar
class << self
def const_missing(name)
case name.to_s
when /\A([A-Za-z]+)Store\z/
file = 'http/cookie_jar/%s_store' % $1.downcas... | true |
19aabd2d12dd476d7499b4d09ba201a0c7c58527 | Ruby | maxnaxmi/Ruby | /variable.rb | UTF-8 | 139 | 3.34375 | 3 | [] | no_license | a = 4
puts a
# aに1足す
a += 1
puts a
# aから1引く
a -= 1
puts a
# aに2かける
a *= 2
puts a
# aを2で割る
a /= 2
puts a | true |
5128795b299f83ccf02ef32c35ce6644cb24b678 | Ruby | itiswhatitisio/rb101 | /small_problems/easy_7/multiply_lists.rb | UTF-8 | 1,020 | 4.53125 | 5 | [] | no_license | =begin
# Problem
# Requirements:
- product of each pair of numbers with the same index
- arguments contain the same number of elements
# Input:
- two arrays
# Output:
- new array
# Examples:
multiply_list([3, 5, 7], [9, 10, 11]) == [27, 50, 77]
# Data structure/Algorithm:
- array
- iterate over the first array
- ... | true |
9a699e56c6537bd973cd23e6900c75d1af1ee73c | Ruby | 8thlight/limelight_docs | /production/documentation/players/run_styles_button.rb | UTF-8 | 1,024 | 2.625 | 3 | [] | no_license | module RunStylesButton
def button_pressed(e)
begin
find_canvas
clear_errors
styles = styles_from_text_area
apply_styles_to_canvas(styles)
rescue Exception => e
add_error(e.message)
end
end
def find_canvas
@canvas = scene.find("canvas")
end
def clear_erro... | true |
15f935b8c980bb2e865d6949dd346775c49541a0 | Ruby | Kansei/hitoriGoto | /hitorigoto.rb | UTF-8 | 588 | 3.03125 | 3 | [] | no_license | #! /usr/bin/env ruby
load_path=File.expand_path("../",__FILE__)
require "#{load_path}/bin/command.rb"
def check_argv
file = $0.split("/")[-1]
com = file.split(".")[0]
if ARGV.size != 1
STDERR.print "Usage: #{com} w/v/l (write or view, list)\n"
exit
end
end
def main(argv)
com = Command.new
comman... | true |
e6a74a7a3c17f9438c7e58da74838fdd4c94f32d | Ruby | bhfailor/edibles | /app/services/food/calculator.rb | UTF-8 | 7,022 | 2.984375 | 3 | [] | no_license | ##
# TODO: update this class comment
# This class pulls specific nutrition data for a food that is present in the
# United States Department of Agriculture, Agricultural Research Service,
# National Nutrient Database (https://ndb.nal.usda.gov/ndb/doc/index)
class Food::Calculator
attr_reader :results
def initializ... | true |
3511196b8cbf3f4c7825c2dd4391d7a1e626d21e | Ruby | lolottetheclash/ruby | /exo_08.rb | UTF-8 | 195 | 3.3125 | 3 | [] | no_license | #Écris un programme exo_08.rb qui demande le prénom de l'utilisateur, et qui salue l'utilisateur
puts "Bonjour, quel est ton prénom ?"
user_name = gets.chomp
puts "Bonjour, #{user_name} !"
| true |
4a3d4c88bb0a33f1305442dbf20c1d3b88694196 | Ruby | Flare2B/YEARepo | /Battle/Lunatic_Objects.rb | UTF-8 | 15,674 | 2.765625 | 3 | [
"MIT"
] | permissive | #==============================================================================
#
# ▼ Yanfly Engine Ace - Lunatic Objects v1.02
# -- Last Updated: 2011.12.27
# -- Level: Lunatic
# -- Requires: n/a
#
#==============================================================================
$imported = {} if $imported.nil?
$imp... | true |
ebd7a012bb5c76de07f4917ef941340afe6a36bb | Ruby | szrharrison/guessing-cli-web-031317 | /guessing_cli.rb | UTF-8 | 528 | 4.25 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Code your solution here!
def get_user_input
puts "Guess a number between 1 and 6."
gets.chomp
end
def generate_number
rand(1..6).to_s
end
def reply_to_user( number, guess )
if number == guess
'You guessed the correct number!'
else
"The computer guessed #{number}."
end
end
def run_guessing_game... | true |
ae4e10d8fbcad0743ae93f33d0dab69fe965eb74 | Ruby | traviscrampton/Library_System | /lib/author.rb | UTF-8 | 1,223 | 2.9375 | 3 | [
"MIT"
] | permissive | class Author
attr_reader(:name, :id)
define_method(:initialize) do |attributes|
@name = attributes.fetch(:name)
@id = attributes.fetch(:id)
end
define_singleton_method(:all) do
returned_authors = DB.exec("SELECT * FROM authors;")
authors = []
returned_authors.each() do |author|
name ... | true |
055af71e269a89015a63dce825209cb994cf9cfd | Ruby | pbrudny/cron-parser | /lib/validator.rb | UTF-8 | 1,338 | 3.03125 | 3 | [] | no_license | require 'pry'
module CronParser
class Validator
def initialize(cron_expression)
self.cron_expression = cron_expression
self.args = cron_expression.split
self.minute = args[0]
self.hour = args[1]
self.day_of_month = args[2]
self.month = args[3]
self.day_of_week = args[4]
... | true |
d53f1989faa845dc6eac8562fed6e25483d9cf16 | Ruby | Muniek/market | /models/consumer.rb | UTF-8 | 181 | 2.875 | 3 | [] | no_license | class Consumer
def initialize(cash:, salary:)
p @cash = cash
p @salary = salary
end
def pay_salary
@cash += @income
end
def rise_salary
#TODO
end
end
| true |
58a4336ce0cd55f9a136827bd49ffe8e4e466fbb | Ruby | Takafumi-Kondo/WebcampRails | /sample_app/app/controllers/posts_controller.rb | UTF-8 | 2,167 | 2.875 | 3 | [] | no_license | class PostsController < ApplicationController
def new
#空のモデルをビューへ渡す
@post = Post.new #空モデル作成を左へ
end
#送信されたフォーム値をDBに。(postインスタンスを生成しtitle,bodyに値セット後、saveメソッド呼)
def create #privateより上に
#ストロングパラメーター使用
post = Post.new(post_params)#ローカル変数なので@なし。アクション内のみ使用可
#DBへ保存
post.save
... | true |
df11188b0271ea947de3abf05ba0280d1af41727 | Ruby | jenbeckham/weather_report | /conditions.rb | UTF-8 | 1,320 | 3.0625 | 3 | [] | no_license | require './requires.rb'
class Conditions
attr_reader :zipcode, :conditionspage
def initialize(zipcode)
@zipcode = zipcode
@conditionspage = get_data
end
private def get_data
HTTParty.get("http://api.wunderground.com/api/#{ENV["WUNDERGROUND_KEY"]}/conditions/q/CA/#{zipcode}.json")
end
def loca... | true |
1db59ffc7dd49a6bc36b845a0f6c459ecaef122e | Ruby | KevinKansanback/LS-101-Lesson2 | /lesson3/Easy1.rb | UTF-8 | 1,471 | 4.1875 | 4 | [] | no_license | # 1
# I would expect it to print [1,2,2,3] as "uniq" doesn't mutate the caller
#2
# the difference is ? is a ternary operator when part of Ruby syntax and ! is
# the bang operator which converts true to false etc.
# Else both characters used to potentially communicate information.
## 1 - != == "is not" or "not equal... | true |
f2751bde68bd962ed9c54ee12f5117e62da4b4f5 | Ruby | FernandaFranco/book-intro-programming | /flow_control/ternary.rb | UTF-8 | 115 | 3.296875 | 3 | [] | no_license | def cond(parameter)
parameter.length < 3 ? "less than 3 words" : "more than 3 words or equal"
end
puts cond("hey") | true |
cedd8e9c17f0efcbbaeafa7d99ff246f7b956cce | Ruby | jollopre/mps | /api/app/models/suppliers/csv_importer.rb | UTF-8 | 852 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'csv'
module Suppliers
module CSVImporter
def csv_importer(path_file)
logger = Logger.new(STDOUT)
CSV.foreach(path_file, headers: :first_row) do |row|
reference = row.field('Reference')
supplier = Supplier.new(
reference: reference,
company_name: row.field(... | true |
89d07a4692b3a7589de388308eff208d15d84aba | Ruby | schneider2100/exo_ruby | /lib/03_stairway.rb | UTF-8 | 1,140 | 3.71875 | 4 | [] | no_license |
def lancer_des
puts "Lance les dès !"
i= rand(1..6)
puts "@|*_*@| ~>#{i}<~"
puts
return i
end
def jeu
tour = 0
marche = 0
while marche <10
i = lancer_des
if i == 5 || i == 6
marche +=1
puts " :) Tu as avancé d'une case, tu es main... | true |
49de02fa002e83640222dbfb0b5babe0e710d6a2 | Ruby | innervisions/RB101 | /03_practice_problems/02_medium_1/04.rb | UTF-8 | 644 | 3.484375 | 3 | [] | no_license | def rolling_buffer1(buffer, max_buffer_size, new_element)
buffer << new_element
buffer.shift if buffer.size > max_buffer_size
buffer
end
def rolling_buffer2(input_array, max_buffer_size, new_element)
buffer = input_array + [new_element]
buffer.shift if buffer.size > max_buffer_size
buffer
end
# rolling_bu... | true |
52f7a6e01b757cb91c540e7517ddd10ee05886c7 | Ruby | qaz442200156/project-euler | /euler014.rb | UTF-8 | 1,242 | 3.453125 | 3 | [] | no_license | # coding: utf-8
=begin
Problem 14 「最長のコラッツ数列」 †
正の整数に以下の式で繰り返し生成する数列を定義する.
n → n/2 (n が偶数)
n → 3n + 1 (n が奇数)
13からはじめるとこの数列は以下のようになる.
13 → 40 → 20 → 10 → 5 → 16 → 8 → 4 → 2 → 1
13から1まで10個の項になる. この数列はどのような数字からはじめても最終的には 1 になると考えられているが, まだそのことは証明されていない(コラッツ問題)
さて, 100万未満の数字の中でどの数字からはじめれば最長の数列を生成するか.
注意: 数列の途中で100万以... | true |
26fd93239446d522b4c6ecf1d0e5cd8e6c72754c | Ruby | lumoslabs/txgh | /queue/spec/backends/sqs/history_sequence_spec.rb | UTF-8 | 1,937 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | require 'spec_helper'
require 'helpers/sqs/sqs_test_message'
describe TxghQueue::Backends::Sqs::HistorySequence do
let(:message) { SqsTestMessage.new('abc123', '{}', attributes_hash) }
let(:attributes_hash) do
{
'history_sequence' => {
'string_value' => [{
'status' => 'retry_without_del... | true |
2bba6b099d93ffd07743099d0989cf032cbe2584 | Ruby | N-Ibrahimi/launch-school-ruby-book | /07_loops/practice_each.rb | UTF-8 | 222 | 4.03125 | 4 | [] | no_license | # practice_each.rb
names = ['Bob', 'Joe','Steve','Susan','Helen','Jane']
names.each { |name| puts name }
puts "now we do the same loop with do end block"
x = 0
names.each do |name|
puts "#{x}. #{name}"
x += 1
end
| true |
1fec886bc018f5416e947c21af1f52f85cd5c175 | Ruby | jonesk79/AddressBookRuby | /lib/addressbook.rb | UTF-8 | 615 | 3.125 | 3 | [] | no_license | class Contact
@@all_contacts == []
def Contact.all
@@all_contacts
end
def Contact.clear
@@all_contacts = []
end
def Contact.create name
new_contact = Contact.new name
new_contact.save
new_contact
end
def initialize name
@name = name
end
def name
@name
end
def save
@@all_contacts << sel... | true |
e44bca3be02e05a0b8962d36b1ee6104f6a37dbd | Ruby | ShanaLMoore/array-CRUD-lab-v-000 | /lib/array_crud.rb | UTF-8 | 605 | 3.890625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def create_an_empty_array
array = []
end
def create_an_array
household = ["Eddie", "Diego", "Alex", "Shana"]
end
def add_element_to_end_of_array(array, element)
array.push(element)
end
def add_element_to_start_of_array(array, element)
array.unshift(element)
end
def remove_element_from_end_of_array(array... | true |
6d224882e57559d6c07b34817398dcea37aa0ae7 | Ruby | robert-laws/learning-apr-2019-ruby-files-formats-templates | /file-system/types-of-paths.rb | UTF-8 | 962 | 3.453125 | 3 | [] | no_license | # Types of File Paths
# absolute path - from root of harddrive /path/to/file.txt
# relative path - location relative to current location ../../files/file.txt
# __FILE__
# File.expand_path(__FILE__) - absolute path to file
# File.dirname(__FILE__)
# File.expand(File.dirname(__FILE__))
# __dir__ - same as ab... | true |
66a5b184f0e8b20a1231c8843e69ed3d2dbb5c2c | Ruby | enspirit/wlang | /spec/unit/dialect/test_render.rb | UTF-8 | 878 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
module WLang
describe Dialect, "render" do
U = Upcasing
let(:expected){ "Hello WHO!" }
it 'works as expected' do
U.render(hello_tpl).should eq(expected)
end
it 'do not eat extra blocks' do
U.render("Hello ${who}{world}").should eq("Hello WHO{world}")
end
... | true |
404f543d241c16e84484b8b42b9e6d06d4247a17 | Ruby | zhouruisong/elk | /logstash-all-2.4.0/vendor/bundle/jruby/1.9/gems/logstash-filter-elasticsearch-2.1.1/lib/logstash/filters/elasticsearch.rb | UTF-8 | 3,864 | 2.640625 | 3 | [
"Apache-2.0"
] | permissive | # encoding: utf-8
require "logstash/filters/base"
require "logstash/namespace"
require_relative "elasticsearch/client"
# Search elasticsearch for a previous log event and copy some fields from it
# into the current event. Below is a complete example of how this filter might
# be used. Whenever logstash receives an ... | true |
6d8c37a7b32673ad346bfd999ff703be93a1e037 | Ruby | elitenomad/email-delivery | /lib/email/delivery/sendgrid_client.rb | UTF-8 | 2,083 | 2.6875 | 3 | [
"MIT"
] | permissive | =begin
This class acts like a interface.
It will
- initialize default mail-client(MailGun)
- call 'do' method to send the emails.
- provide fail-over mechanism
=end
require 'net/http'
require 'uri'
require 'json'
module Email
module Delivery
class SendgridClient
def dispatch(from, to, ... | true |
6cb3f80820e198fb4cd3a2bee2caf219b8e9a8c1 | Ruby | dmbf29/super_character | /lib/tasks/character.rake | UTF-8 | 1,024 | 2.578125 | 3 | [] | no_license | require 'open-uri'
require 'nokogiri'
namespace :character do
desc "Try to steal the photo form the wiki"
task find_photos: :environment do
Character.find_each do |character|
next if character.photo.present?
url = URI.encode("https://simpsons.fandom.com/wiki/#{character.name.gsub("\"", "'").gsub... | true |
234a4a82e2b7bdc858ac173e2b9c188dc42b4b2c | Ruby | jhawthorn/mpvctl | /lib/mpvctl/mpv.rb | UTF-8 | 1,649 | 2.625 | 3 | [
"MIT"
] | permissive | require "mpvctl/socket"
require "mpvctl/playlist_item"
module MpvCtl
class Mpv
attr_reader :socket
def initialize
@socket = Socket.new('/tmp/mpvsocket')
end
def play(path, mode=:replace)
command 'loadfile', path, 'replace'
end
def add(path, mode=:replace)
command 'loadfil... | true |
fc00070184163607442cbb320b611c64256c5090 | Ruby | jsblaisdell/powerrangers | /powerranger.rb | UTF-8 | 1,567 | 3.90625 | 4 | [] | no_license | require 'modules.rb'
class Person
attr_accessor :name, :caffeine_level
def initialize(name)
@name = name
@caffeine_level = 0
end
def run
"#{@name} ran away."
end
def scream(string)
"#{string.upcase}!!!"
end
def drink_coffee
@caffeine_level += 1
end
end
class PowerRanger < Pers... | true |
91a4ee4f0468d2fc1dd13adcdf4567b0303916da | Ruby | Zacharae/spring16ruby | /rps.rb | UTF-8 | 847 | 4.25 | 4 | [] | no_license | # ROCK PAPER SCISSORS
require "pry"
class RockPaperScissors
PLAYS = ['rock', 'paper', 'scissors']
WINS = [
['rock', 'scissors'],
['paper', 'rock'],
['scissors', 'paper']]
def play
human_move = human_selection
computer_move = computer_selection
get_winner(human_move, computer_move)
#binding.pry
end
... | true |
89b3d46dda3100c3a1a72b231ed4fa7bda1b652b | Ruby | Ank13/socrates_prep | /letter_grade.rb | UTF-8 | 364 | 3.671875 | 4 | [] | no_license | def get_grade(scores)
sum = 0
scores.each do |score|
sum += score
end
average = sum/scores.length
case average
when 90..100
'A'
when 80..89
'B'
when 70..79
'C'
when 60..69
'D'
when 50..59
'E'
when 0..49
'F'
else
'Error'
end
end... | true |
828c1e03a68952f285f4359887ad3bd1027b1c4e | Ruby | hightowercorporation/voter_sim | /spec/records_spec.rb | UTF-8 | 3,283 | 2.921875 | 3 | [] | no_license | require './records.rb'
describe Records do
it "can create a voter and add it to a voter's array" do
records = Records.new
records.create_voter("Darth Vader", "Liberal")
expect(records.voters.count).to eq(1)
end
it "can create a politician and add it to a politician's array" do
records = Records.new
reco... | true |
f5e27b1492d72ff0f7f83f2e154e555e35652d09 | Ruby | percolator-io/percolator | /app/helpers/categories_helper.rb | UTF-8 | 519 | 2.796875 | 3 | [] | no_license | module CategoriesHelper
def categories_for_select
@_categories_for_select ||= _categories_array_from_tree(Category.hash_tree)
end
private
def _category_name_for_select(name, depth)
['-' * depth, name].select(&:present?).join(' ')
end
def _categories_array_from_tree(tree, depth = 0)
result = []
... | true |
d40b42dab884bd4616a84e65d53367bf5ab54cc0 | Ruby | MURATKAYMAZ56/RUBY | /3_OOP_Ruby_Fundamentals/ExerciseFile_ruby-object-oriented-fundamentals/05/demos/mixin.rb | UTF-8 | 1,135 | 4.15625 | 4 | [] | no_license | module Tagged
def tag(tag)
@tags ||= []
@tags << tag
end
def untag(tag)
@tags.delete(tag) if !@tags.nil?
end
attr_reader :tags
end
class Book
attr_reader :name
def initialize(name)
@name = name
end
# The spaceship operator in order to use Enumerable methods
# to sort books in a ... | true |
39162adda9c627b558ec3d0ef3cac540800976ce | Ruby | Claytonboyle/RubyPokerSim | /main.rb | UTF-8 | 696 | 3.5625 | 4 | [] | no_license | require './evaluate.rb'
# Each program being simulated
# will give out an input dependant
# on what is happening
# Any misunderstood input will
# be interpreted as a fold.
# To start a round each program
# will be given the input of their
# hand with standard format, i.e:
# H10 C1
# on each round of betting, if the... | true |
db27680540971874abd7fdca781636e8a1fa4cae | Ruby | Tsutomu19/StudyingAlgorithms | /0630.rb | UTF-8 | 82 | 3.25 | 3 | [] | no_license | D140:N番目の単語
num = gets.to_i
alf = gets.chomp.split(" ")
puts alf[num-1]
| true |
d55c65e29dfe15990dbb41b6e13fdac9ab7a97d9 | Ruby | westlakedesign/pbxproject | /lib/pbxproject/pbxtypes.rb | UTF-8 | 8,116 | 2.71875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'digest/sha1'
module PBXProject
module PBXTypes
class BasicValue
attr_accessor :value, :comment
def initialize(args = {})
@value = args[:value]
@comment = args[:comment]
end
def to_pbx ind = 0
pbx = ''
pbx += "#{@value}"
pbx +... | true |
d832ecbdf6e3762fa64a6649ce89f343a387a445 | Ruby | pioneertrack/rails-challenge-quiz-back-end | /app/models/user.rb | UTF-8 | 1,176 | 2.53125 | 3 | [] | no_license | class User < ApplicationRecord
has_secure_password
has_many :calendars
has_many :events
# TODO validate the presence of name and email
################################################
# TODO validate the format of the email with
# this regex
#
# /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
#
# ... | true |
ef0569a01cbc580b3c81ede1a580250ef3752847 | Ruby | JamieReid1/week_03_weekend_homework_codeclan_cinema | /console.rb | UTF-8 | 2,840 | 2.703125 | 3 | [] | no_license |
require('pry')
require_relative('models/customer')
require_relative('models/film')
require_relative('models/ticket')
require_relative('models/screening')
Customer.delete_all()
Film.delete_all()
Screening.delete_all()
customer1 = Customer.new({ 'name' => 'Woody', 'funds' => 100 })
customer1.save()
customer2 = Custo... | true |
6b8e99ab9fd26844036bf29e7342564380e7a687 | Ruby | mdhernandez/basic-games | /mastermind.rb | UTF-8 | 5,497 | 3.875 | 4 | [] | no_license | class Mastermind
@pegs
@solution
@colors
@player
@white
def initialize( player = true)
@pegs = { "Colored" => 0, "White" => 0 }
@colors = ["RED", "YELLOW", "WHITE", "PURPLE", "ORANGE", "GREEN"]
@solution = color_rand
@player = player
@white = Hash.new
end
def get_white
return @whit... | true |
85603d8ab062422e23e00235f9bdecfa32fa3664 | Ruby | shawnewallace/TheAlgorithmsStillCount | /src/ruby/spec/fibonacci_spec.rb | UTF-8 | 710 | 3.546875 | 4 | [] | no_license | require 'fibonacci'
describe Fibonacci do
@values = [
[0, 0],
[1, 1],
[2, 1],
[3, 2],
[4, 3],
[5, 5],
[17, 1597],
[45, 1134903170],
[83, 99194853094755497]
]
@values.each do |fib, expected|
it "is #{expected} for fib(#{fib}) computed iteratively" do
Fibonacci.ofIter... | true |
e21ff8be9e80ad1677fbf6e13395d15168f13ab0 | Ruby | UpAndAtThem/practice_kata | /titleize.rb | UTF-8 | 365 | 4.03125 | 4 | [] | no_license | def titleize(str)
str.split.map {|word| word.capitalize}.join" "
end
def titleize!(str)
counter = 0
str[0] = str[0].capitalize
loop do
str[counter + 1] = str[counter + 1].capitalize if str[counter] == ' '
counter += 1
break if counter == str.size
end
str
end
book = "the shinning"
title... | true |
2fe63dfb781001024796046cc9ee0487da1be51c | Ruby | Digory/week_3_day_3 | /db/console.rb | UTF-8 | 783 | 2.8125 | 3 | [] | no_license | require_relative('../models/album.rb')
require_relative('../models/artist.rb')
#
# Album.delete_all()
# Artist.delete_all()
#
artist1 = Artist.new({
'name' => 'Digory'
})
artist2 = Artist.new({
'name' => 'Emil'
})
artist1.save()
artist2.save()
album1 = Album.new({
'title' => 'Digory\'s greatest hits',
'g... | true |
f1dbbada2fe98a289ac46c7b030d0dffc4325c14 | Ruby | kamihiro0626/furima_28797 | /spec/models/user_spec.rb | UTF-8 | 4,502 | 2.625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
describe '#create' do
before do
@user = FactoryBot.build(:user)
end
it "nicknameとemail、passwordとpassword_confirmation、famiy_nameとfirst_name、family_name_kanaとfirst_name_kana、birthdayが存在すれば登録できる" do
expect(@user).to be_valid
... | true |
0a0a584d87c4f6e8722eef921e63aac810bdaa38 | Ruby | bajunio/phase_0_unit_2 | /week_6/1_assert_statements/my_solution.rb | UTF-8 | 2,307 | 4.375 | 4 | [] | no_license | # U2.W6: Testing Assert Statements
# I worked on this challenge by myself.
# 1. Review the simple assert statement
# method assert is attempting to yeild to blocks
=begin
def assert
raise "Assertion failed!" unless yield
end
name = "bettysue"
assert { name == "bettysue" }
assert { name == "billybob" }
=end
# 2. P... | true |
b75c6fa7f2b9e2de770493ffdc36311077346634 | Ruby | albertosaurus/power_enum_2 | /lib/generators/enum/enum_generator_helpers/migration_number.rb | UTF-8 | 782 | 2.578125 | 3 | [
"MIT"
] | permissive | # Helper logic for the enum generator
module EnumGeneratorHelpers
# Helper methods to figure out the migration number.
module MigrationNumber
# Returns the next upcoming migration number. Sadly, Rails has no API for
# this, so we're reduced to copying from ActiveRecord::Generators::Migration
# @return ... | true |
7ea16841c1c3c22e424a4a14c5671d9a02371422 | Ruby | dmateos/scratch | /code-tests/toy-robot/spec/toy_robot_integration_spec.rb | UTF-8 | 2,351 | 2.625 | 3 | [] | no_license | require_relative 'spec_helper'
describe "ToyRobot Integration" do
let(:stdin) { FakeStdin.new }
let(:toy_robot) { ToyRobot.new(stdin: stdin) }
it "runs example a in the PDF" do
stdin << "PLACE 0,0,NORTH" << "MOVE" << "REPORT"
toy_robot.run
expect(toy_robot.robot.report(false)).to eq("0,1,NORTH")
e... | true |
74135ca415c6a350006d85a83c424abda2888add | Ruby | Flipez/blumentopf | /lib/menu.rb | UTF-8 | 1,269 | 2.9375 | 3 | [] | no_license | # frozen_string_literal: true
require_relative './pot_manager'
class Blumentopf
class Menu
attr_accessor :active_item
attr_reader :display, :pot_manager
def initialize(display, pot_manager)
@active_item = 0
@display = display
@pot_manager = pot_manager
draw
end
def ite... | true |
8412d2d753c806033c06f41387b08ddb75916561 | Ruby | learn-co-students/nyc-web-students-021819 | /29-async-js/sync.rb | UTF-8 | 527 | 3.3125 | 3 | [] | no_license | require 'rest-client'
require 'json' #JavaScript Object Notation
require 'pry'
puts "brb"
# begin
# this_is_not_a_variable
# rescue NameError
# puts 'saved u'
# end
sleep(3)
puts "im back"
puts "Making an HTTP GET request with RestClient"
response = RestClient.get('https://swapi.co/api/planets')
puts "Request... | true |
099b0080ece20c15100322a766470a9da70776db | Ruby | PBODR/E6CP1A1 | /3 ciclos anidados/ejercicio3.rb | UTF-8 | 341 | 3.8125 | 4 | [] | no_license | # Construir un programa que permita ingresar un número por teclado e imprimir
# la tabla de multiplicar del número ingresado. Debe repetir la operación hasta
#que se ingrese un 0 (cero).
# Ingrese un número (0 para salir): _
num = gets.chomp.to_i
if num != 0
10.times do |i|
i +=1
puts i*num
end
else
puts ... | true |
55ebdb86b5642c763721bf454311830dd823ad37 | Ruby | TSimpson768/Chess | /lib/board.rb | UTF-8 | 5,327 | 3.21875 | 3 | [] | no_license | # frozen_string_literal: true
# The board class stores the current state of the board.
require_relative 'place'
require_relative 'constants'
require_relative 'pieces/piece'
require_relative 'pieces/king'
require_relative 'pieces/queen'
require_relative 'pieces/rook'
require_relative 'pieces/bishop'
require_relative 'p... | true |
f351fa14f67c759d71af3a24257829ad9a86f4c1 | Ruby | jennyjean8675309/module-one-final-project-guidelines-dc-web-100818 | /spec/trivia_game_spec.rb | UTF-8 | 2,920 | 3.515625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
require_relative '../lib/question.rb'
require_relative '../lib/category.rb'
require_relative '../lib/choice.rb'
require_relative '../lib/user.rb'
require_relative '../lib/user_question.rb'
#Question class tests
describe Question do
cat1 = Category.new(name: "Movies")
cat2 = Category.new(name: "Sci... | true |
751f436830003c2afc4df81a769c0f90148b898c | Ruby | shaina33/bloc_record | /lib/bloc_record/utility.rb | UTF-8 | 1,746 | 2.96875 | 3 | [] | no_license | module BlocRecord
module Utility
extend self
def underscore(camel_cased_word)
string = camel_cased_word.gsub(/::/, '/')
string.gsub!(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
string.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
string.tr!("-", "_")
stri... | true |
1b95cc9184eb1089736c15edaa53be57dcf4b03f | Ruby | daydreamboy/HelloRuby | /ruby_task/06_subcommand.rb | UTF-8 | 652 | 2.8125 | 3 | [
"MIT"
] | permissive | #encoding: utf-8
require 'optparse'
require_relative '../ruby_tool/dump_tool'
<<-DOC
The example for parsing multiple subcommands
@see https://stackoverflow.com/a/2737822
DOC
global = OptionParser.new do |opts|
opts.banner = "Usage: #{__FILE__} subcommand [-options] argument"
end
subcommands = {
'foo' => Opti... | true |
ef85524ff5baa755ce268435151396a53bd2b900 | Ruby | athonlab/peopletantra | /utilities/indigov_parser.rb | UTF-8 | 1,272 | 3.203125 | 3 | [] | no_license | # encoding: UTF-8
require 'rubygems'
require 'hpricot'
require 'net/http'
require 'uri'
class Parser
def self.extract_links_to_members stream
doc = Hpricot(stream)
doc.search('.middleColumn>ul li a').collect{|link| link.attributes['href'] }
end
# parse members biodata
def self.extract_member stream
... | true |
39c9e5435c6e34bf0cdc3ee75f026963dabbe80d | Ruby | amcaplan/project_euler | /21/problem_21.rb | UTF-8 | 163 | 2.859375 | 3 | [] | no_license | require_relative 'amicable_numbers_generator'
gen = AmicableNumbersGenerator.generator
nums = gen.take_while{|pair| pair[0] < 10_000}.flatten
puts nums.inject(:+) | true |
2bf2c8d01573abc5009dff9937277c7cd00fbca7 | Ruby | athurman/fetch | /models/shelter.rb | UTF-8 | 705 | 2.671875 | 3 | [] | no_license | class Shelter < ActiveRecord::Base
default_scope { order("name ASC") }
def self.calculate_popular_breed id
results = Shelterdog.find_by_sql("select shelterdogs.breed, Count(*) as total from shelterdogs where shelterdogs.shelter = '#{id}' group by shelterdogs.breed order by total desc")
results
end
def... | true |
3a487ca937059832d151824a989e038c7f4fe90a | Ruby | eduardopoleo/algorithm_1 | /week_4/scc_spec.rb | UTF-8 | 606 | 2.546875 | 3 | [] | no_license | require 'rspec'
require_relative './scc.rb'
describe Vertex do
describe '#push_edge' do
it 'stores other vertes in the edge attribute' do
vertex1 = described_class.new(1)
vertex2 = described_class.new(2)
vertex3 = described_class.new(3)
vertex1.push_edge(vertex2)
vertex1.push_edge(... | true |
f96ade3e0f039df5b5ef985c972b207a040409a1 | Ruby | jamgar/oo-cash-register-cb-000 | /lib/cash_register.rb | UTF-8 | 898 | 3.203125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class CashRegister
attr_accessor :total, :discount, :quantity, :message, :items
def initialize(discount = 0)
@total = 0
@discount = discount
@list = {}
end
def add_item(title, price, quantity = 1)
self.total += price * quantity
@list["#{title}"] = {
:price => price,
... | true |
ed202a5c8102672d4ba55e76375ebfd68fbb46f2 | Ruby | txus/gametheory | /ipdsim/lib/year.rb | UTF-8 | 506 | 2.96875 | 3 | [] | no_license | class Year
attr_reader :number
attr_reader :composition
attr_reader :food_level
def initialize
@number = World.current_year ? World.current_year.number + 1 : 1
@composition = {}
@food_level = nil
@growing_rate = {}
end
def consolidate
Strategy.types.each do |strategy|
@compositio... | true |
601741f4266e1b4df7e6097a9541c9a54fb7679e | Ruby | KGan/railslite | /lib/finalized/01_sql_object.rb | UTF-8 | 2,629 | 2.84375 | 3 | [] | no_license | require_relative 'db_connection'
require 'active_support/inflector'
class SQLObject
def self.columns
result = DBConnection.execute2(<<-SQL)
SELECT
*
FROM
#{table_name}
LIMIT
1
SQL
sym_arr = result.first.map do |arr|
arr.to_sym
end
sym_arr
end
... | true |
65e60e6122572af49548fd15487f5357aa089f37 | Ruby | IceDragon200/dragontk | /spec/dragontk/thread_pool_spec.rb | UTF-8 | 932 | 2.578125 | 3 | [] | no_license | require 'spec_helper'
require 'dragontk/thread_pool'
describe DragonTK::ThreadPool do
context "#spawn/0" do
it "should spawn and complete all threads" do
result = {}
10.times do |j|
result[j] = {}
subject.spawn do
5.times do |i|
result[j][i] = j * i
end... | true |
62c5a24af31f2f0a5c05fac576534029a744b93c | Ruby | khanhhuy288/Ruby-Aufgaben | /A5-Vertiefung/a5_3/matrix_methoden.rb | UTF-8 | 3,102 | 3.75 | 4 | [] | no_license | def matrix?(mat)
# make sure matrix is an Array of rows
return false unless mat.is_a?(Array) && mat[0].is_a?(Array)
cols = mat[0].size
# make sure all rows are Arrays and have same cols
(0...mat.size).all? {|z| mat[z].is_a?(Array) && mat[z].size == cols }
end
def gewichtet(mat)
# calculate sizes of... | true |
0297d5b255204b758d3f86dc384f208809bf388d | Ruby | jluong214/ProjectEuler | /problem23.rb | UTF-8 | 1,580 | 4.1875 | 4 | [] | no_license | #A perfect number is a number for which the sum of its proper divisors is exactly equal to the number. For example, the sum of the proper divisors of 28 would be 1 + 2 + 4 + 7 + 14 = 28, which means that 28 is a perfect number.
#A number n is called deficient if the sum of its proper divisors is less than n and it i... | true |
d885d4db226d9521c4cd31f33681d059535e3b33 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/1b5373b1a765460c9ab0992ea734e4fe.rb | UTF-8 | 504 | 3.71875 | 4 | [] | no_license | class Bob
def hey(message)
s = Statement.new(message)
case
when s.silent? then "Fine. Be that way!"
when s.forceful? then "Woah, chill out!"
when s.query? then "Sure."
else
"Whatever."
end
end
end
class Statement
def initialize(message)
@message = message
end
d... | true |
9b59d922f2cb5ca686996e4811f08277ec80e482 | Ruby | kojix2/charty | /test/vector/vector_equality_test.rb | UTF-8 | 2,845 | 2.765625 | 3 | [
"MIT"
] | permissive | class VectorEqualityTest < Test::Unit::TestCase
include Charty::TestHelpers
data(:adapter_type, [:array, :daru, :narray, :nmatrix, :numpy, :pandas], keep: true)
data(:other_adapter_type, [:array, :daru, :narray, :nmatrix, :numpy, :pandas], keep: true)
def test_equality(data)
vector = setup_vector(dat... | true |
c3569de28407305dd8ee80a82922ea5e674f1e2e | Ruby | tiy-dc-ror-2016-oct/notes | /3/1 monday/cli.rb | UTF-8 | 339 | 2.859375 | 3 | [] | no_license | require_relative "cohort"
require_relative "student"
oct_16 = Cohort.new
oct_16.add_student(Student.new("Ben"))
oct_16.add_student(Student.new("Allie"))
oct_16.add_student(Student.new("Alex"))
oct_16.add_student(Student.new("Farimah"))
picked_student = oct_16.fairly_pick_a_student!
puts picked_student.name
# lam... | true |
81f1e71f123e92e95a826d4693771d83b733cd93 | Ruby | zachchao/hw-ruby-intro | /lib/ruby_intro.rb | UTF-8 | 1,508 | 4 | 4 | [] | no_license | # When done, submit this entire file to the autograder.
# Part 1
def sum arr
arr.sum
end
def max_2_sum arr
if arr.length <= 1
return arr.sum
end
m1 = arr.max
arr.delete_at(arr.index(m1))
m1 + arr.max
end
def sum_to_n? arr, n
if arr.length <= 1
return false
end
for i in 0..arr.length - 1
... | true |
4eeaf6d265d9865cc6ac82b403b835f8200f9957 | Ruby | ckib16/drills | /z_past_practice/2017-09/2017-09-04.rb | UTF-8 | 454 | 3.09375 | 3 | [] | no_license | class Board
def initialize(board)
puts "-#{board[0]}-|-#{board[1]}-|-#{board[2]}-"
puts "-#{board[3]}-|-#{board[4]}-|-#{board[5]}-"
puts "-#{board[6]}-|-#{board[7]}-|-#{board[8]}-"
end
def update_board(board)
puts "-#{board[0]}-|-#{board[1]}-|-#{board[2]}-"
puts "-#{board[3]}-|-#{board[4]}-... | true |
c556b299c20ac6b8122ba7ea47211df26d021cb7 | Ruby | aspose-imaging/Aspose.Imaging-for-Java | /Plugins/Aspose_Imaging_Java_for_Ruby/lib/asposeimagingjava/images/convertingrasterimages.rb | UTF-8 | 2,484 | 3.0625 | 3 | [
"MIT"
] | permissive | module Asposeimagingjava
module ConvertingRasterImages
def initialize()
# Binarization with Fixed Threshold
binarization_with_fixed_threshold()
# Binarization with Otsu Threshold
binarization_with_otsu_threshold()
# Transform image to its grayscale representation
... | true |
cefe9a9f186588566af8c1584292ece2b2668e16 | Ruby | markhyams/coding-fun | /leetcode/0082_remove_dups2.rb | UTF-8 | 968 | 3.46875 | 3 | [] | no_license | # Definition for singly-linked list.
# class ListNode
# attr_accessor :val, :next
# def initialize(val = 0, _next = nil)
# @val = val
# @next = _next
# end
# end
# @param {ListNode} head
# @return {ListNode}
# DH->1->1
# p
# c
#
#
#
# 3 pointers, prev, current
# add a dumm... | true |
780e9a6d58a70efbcbcaca2a5cc5a7f6b749c882 | Ruby | vladutclp/Depot_Application | /app/models/concerns/current_cart.rb | UTF-8 | 440 | 2.84375 | 3 | [] | no_license | module CurrentCart
private
'The set_cart method starts by getting the :cart_id from the session object and then attempts
to find a cart corresponding to this ID. If the cart is not found, this method will create a new Cart
and then store the ID of the created cart into the session'
def set_cart
@cart = Cart.fi... | true |
48dd9a5400371b5fa31d38055830443b3a1b3d55 | Ruby | madmax/ruby_php_session | /spec/php_session/encoder_spec.rb | UTF-8 | 3,270 | 2.5625 | 3 | [
"MIT"
] | permissive | # -*- coding: utf-8 -*-
require 'spec_helper'
require 'date'
describe PHPSession::Encoder do
describe ".encode" do
context "when given string value" do
it "should return 'KEY|SERIALIZED_STRING'" do
expect(
PHPSession::Encoder.encode({:hoge => "nyan"})
).to eq('hoge|s:4:"nyan";')
... | true |
473988b14cb4459f0d790905d4886dcddb998302 | Ruby | Proskurina/inject-challenge | /lib/my_inject.rb | UTF-8 | 1,519 | 3.546875 | 4 | [] | no_license | class MyArray < Array
def my_inject(initial = nil, sym=nil, &block)
dup = self.dup
if initial == nil
initial = dup.shift
#When there is no block and only one argument,
#this argument is assigned to initial.
#but I need it to be symbol.
#The next 4 lines is the only way I could f... | true |
1e49432a6e112e30506cb017796040e5a02919b4 | Ruby | evansenter/wrnap | /lib/wrnap/package/heat.rb | UTF-8 | 365 | 2.578125 | 3 | [
"MIT"
] | permissive | module Wrnap
module Package
class Heat < Base
attr_reader :specific_heats
def post_process
@specific_heats = response.split(/\n/).map { |line| line.split(/\s+/).map(&:to_f) }.inject({}) do |hash, (temp, specific_heat)|
hash.tap do
hash[temp] = specific_heat
... | true |
cf1e3409f9a4e8e0a79258d114f3f34b5b85c1a4 | Ruby | redfit/hiki | /hiki/repos/plain.rb | UTF-8 | 2,411 | 2.5625 | 3 | [] | no_license | require 'hiki/repos/default'
require 'fileutils'
module Hiki
class HikifarmReposPlain < HikifarmReposBase
def setup
Dir.mkdir(@root) if not File.exists?(@root)
end
def imported?(wiki)
File.directory?("#{@root}/#{wiki}")
end
def import(wiki)
FileUtils.mkdir("#{@root}/#{wiki}")
... | true |
b9a18183b486f2423a7229f91174a6ad2c090d25 | Ruby | ChristopherDurand/Exercises | /ruby/small-problems/medium2/e05.rb | UTF-8 | 589 | 3.796875 | 4 | [
"MIT"
] | permissive |
def valid_triangle?(a, b, c)
a, b, c = [a, b, c].sort
a > 0 && b > 0 && c > 0 && a + b > c
end
def triangle(a, b, c)
if valid_triangle?(a, b, c)
sides = Hash.new(0)
[a, b, c].each { |n| sides[n] += 1 }
num_same = sides.max_by { |length, ct| ct }[1]
case num_same
when 1 then :scalene
when... | true |
00e67b23d68df7dc16abe205270aafe3ab0492f0 | Ruby | chi-grasshoppers-2015/StackOverthrow | /app/helpers/users_helper.rb | UTF-8 | 1,197 | 2.640625 | 3 | [] | no_license | helpers do
def logged_in?
session[:uid]
end
def current_user
User.find(session[:uid])
end
def user_is_author(user_id)
current_user.id == user_id
end
def ad_generator
ad_num = [*1..6].sample
case ad_num
when 1
"<h5>Nickle ads</h5>
<p>Need to spend extra money?</p>
... | true |
272c6d3fee6db268c034d9d475eaf9f157416f5c | Ruby | jacobdmartin/RoleModel_Prep_Work | /Intro-to-Ruby/ping-pong/lib/ping_pong.rb | UTF-8 | 238 | 3.21875 | 3 | [] | no_license | class ChangeNum
def ping_pong
arr = []
c=1
self.times do
if c%3 == 0
arr.push('ping')
elsif c%5 == 0
arr.push('pong')
else
arr.push(c)
end
c+=1
end
arr
end
end
| true |
594c528ab5eb49edf67d7804fec898e23c7934f2 | Ruby | 1debit/json_api_client | /lib/json_api_client/utils.rb | UTF-8 | 852 | 2.734375 | 3 | [
"MIT"
] | permissive | module JsonApiClient
module Utils
def self.compute_type(klass, type_name)
# If the type is prefixed with a scope operator then we assume that
# the type_name is an absolute reference.
return type_name.constantize if type_name.match(/^::/)
# Build a list of candidates to search for
... | true |
9975c4a42c94aa6af64f5022166126251f00181c | Ruby | FedericoEsparza/after_11_pm | /spec/models/trigonometry/functions/sine_spec.rb | UTF-8 | 783 | 3.59375 | 4 | [] | no_license | describe Sine do
describe '#initialize' do
it 'initialise with angle in degrees' do
exp = sin(60)
expect(exp.angle).to eq 60
end
it 'can init with array' do
exp = sin([60])
expect(exp.angle).to eq 60
end
end
describe 'setters for angle' do
it 'setter for angle' do
... | true |
6c62a592259ad3db46aa5537dd6165dd71998e0d | Ruby | rossmari/AccordionMan | /lib/message/processor.rb | UTF-8 | 879 | 2.734375 | 3 | [] | no_license | class Message::Processor
class << self
def process(message)
parsed_message = message(message)
parsed_message.user = Message::UserParser.parse(message.from)
links = Message::LinkParser.parse(message.text)
# check links on accordion alert and save them if all is safe
check_links(li... | true |
34fa97784b02d7fbcabcf88163f19ef67dd03050 | Ruby | gouf/pry-theme | /spec/rgb_spec.rb | UTF-8 | 2,625 | 3.171875 | 3 | [
"Zlib",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'helper'
describe PryTheme::RGB do
RGB = PryTheme::RGB
it "accepts Array as an argument" do
lambda { RGB.new([0, 0, 0]) }.should.not.raise
end
it "doesn't accept malformed Arrays" do
lambda { RGB.new([0, 0, 0, 0]) }.should.raise ArgumentError
lambda { RGB.new([256, 256, 256]) }.should.rai... | true |
c31a24dcaa66bd36dcc0c001c0b7980b1b711b3e | Ruby | telefactor/telefactor-fam-sourcerer-two | /spec/fam/family_spec.rb | UTF-8 | 6,727 | 2.65625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Fam::Family do
let(:family) { described_class.new }
before do
family.add_person(person_name: 'Bobby')
family.add_person(person_name: 'Hank')
family.add_person(person_name: 'Peggy')
family.add_person(person_name: 'Bill')
end
c... | true |
458d10026d4daf9948b4b42f247c56df70f866e2 | Ruby | SOWMYANARAYANA/ruby-practice | /file.rb | UTF-8 | 301 | 2.625 | 3 | [] | no_license | # aFile = File.new("input.txt", "r+")
# if aFile
# content = aFile.syswrite("niki")
# aFile.each_byte {|ch| putc ch; putc ?. }
# puts content
# else
# puts "Unable to open file!"
# end
a=[1,2,3,4]
h=Hash[*a]
puts h
a=[1,2,3,4]
p a=Array.new(5){Array.new(10){|index|}.map if{|i|i=even}} | true |
1c3f55e99eb3763bec5eaf5d61799f7dcfcd6bbe | Ruby | mdbhuiyan/w2d1 | /Chess/piece.rb | UTF-8 | 441 | 3.203125 | 3 | [] | no_license | require_relative 'board.rb'
require 'colorize'
class Piece
attr_reader :name, :color, :board
# def initialize(name, color)
def initialize(color, board, position)
@color = color
@board = board
@position = board.add_piece(self, position)
end
def to_s
symbol.colorize(color)
end
def symbo... | true |
0c81b256344f4c2f231d383df89227f7f8fb864d | Ruby | qbl/electives-solid-exercise | /ocp/shape_calculator.rb | UTF-8 | 269 | 3.28125 | 3 | [] | no_license | class ShapeCalculator
def initialize
end
def calculate_area(shape)
area = 0
if shape.name == "rectangle"
area = shape.width * shape.length
elsif shape.name == "triangle"
area = shape.base * shape.height * 0.5
end
area
end
end
| true |
210b72a15e840164341b80e49728872667854900 | Ruby | jtmr/lifecrawler | /lifecrawler.rb | UTF-8 | 1,801 | 2.609375 | 3 | [
"MIT"
] | permissive | # -*- coding: utf-8 -*-
require 'mechanize'
require 'httpclient'
sleep_sec = 5
agent = Mechanize.new
page = agent.get('http://www.tbsradio.jp/life/themearchive.html')
page.search('h5>a').each do |themes_link|
theme_dir = themes_link.text.gsub('/', '_')
FileUtils.mkdir(theme_dir) unless Dir.exist?(theme_dir)
pu... | true |
1569c711804fb901ca0f8e7da3dabf2a9ad8cec7 | Ruby | mcdermottjesse/Ruby-Exercises | /pig_latin.rb | UTF-8 | 246 | 4.03125 | 4 | [] | no_license | def pigLatin(string)
vowels = ["a", "e", "i", "o", "u"]
if vowels.include? string[0]
string + 'ay'
else
consonant = string[0]
new_word = string[1..-1]
"#{new_word}#{consonant}ay"
end
end
puts pigLatin("apple")
puts pigLatin("jesse") | true |
d7ab0bb80ab7883cbd08853c6e23343520934aea | Ruby | cappetta/CyberCloud | /puppet/modules/stdlib/spec/functions/join_keys_to_values_spec.rb | UTF-8 | 1,494 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | #! /usr/bin/env ruby -S rspec
require 'spec_helper'
describe "the join_keys_to_values function" do
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
it "should exist" do
expect(Puppet::Parser::Functions.function("join_keys_to_values")).to eq("function_join_keys_to_values")
end
it "should raise a Pars... | true |
3222ea8f12dc70a29fb70b26445c801ee4d0fa61 | Ruby | meranly8/cartoon-collections-onl01-seng-pt-090820 | /cartoon_collections.rb | UTF-8 | 448 | 3.328125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def roll_call_dwarves(names)
names.each_with_index do |name, position|
puts "#{position + 1} #{name}"
end
end
def summon_captain_planet(planeteer_calls)
planeteer_calls.collect {|element| element.capitalize + "!"}
end
def long_planeteer_calls(calls)
calls.any? { |call| call.length > 4}
end
def find_the_c... | true |
b3389b96a51e020ad3f72c12311d7c4c9eb39602 | Ruby | rsupak/appacademy2020 | /SoftwareEngineeringFundamentals/rspec_exercise_4/lib/part_1.rb | UTF-8 | 480 | 3.375 | 3 | [] | no_license | def my_reject(arr, &prc)
new_arr = []
arr.each { |el| new_arr << el unless prc.call(el) }
new_arr
end
def my_one?(arr, &prc)
arr.count(&prc) == 1
end
def hash_select(hash, &prc)
new_hash = {}
hash.each { |k, v| new_hash[k] = v if prc.call(k, v) }
new_hash
end
def xor_select(arr, prc1, prc2)
arr.selec... | true |
984596786996ef810ae4be10132a980cf71d62c2 | Ruby | elsonli/aA-classworks | /W6D5/ninety_nine_cats_project/app/models/cat.rb | UTF-8 | 530 | 2.609375 | 3 | [] | no_license | class Cat < ApplicationRecord
COLORS = [
"black",
"white",
"gray",
"hairless",
"blue",
"gold",
"red",
"rainbow",
"pizza",
"macandcheeseorange"
]
validates :birth_date, :color, :name, :sex, :description, presence: true
validates :color, inclusion: { in: COLORS }
valid... | true |
66dc101e3589c39e43799e05a975eb9791a66233 | Ruby | bramsey/euler-ruby | /prob40.rb | UTF-8 | 868 | 3.28125 | 3 | [] | no_license | #!/Users/spamram/.rvm/rubies/ruby-1.9.2-p180/bin/ruby
# problem: http://projecteuler.net/problem=40
def brute
str = '0'
1.upto(1000000) {|i| str += i.to_s}
prod = 1
mult = 1
while mult <= 1000000
prod *= str[mult].to_i
mult *= 10
end
prod
end
# start of optimization:
#1 * 1 * 5 * 3 *... | true |
3245dadc92ede9b59076755eed433e45ef15be43 | Ruby | wing-888/MOR_X5_FROM_VM | /upgrade/x4/sipchaning.rb | UTF-8 | 2,816 | 2.625 | 3 | [] | no_license | # Script by -Aurimas. S.- //2013//
require 'active_record'
require 'ipaddr'
require 'yaml'
# Configuration
ENV_DB = '/home/mor/config/database.yml'
DEBUG = ARGV.member?('-v')
FORCE = ARGV.member?('-f')
COLUMNS = %w{ peerip recvip sipfrom uri useragent peername t38passthrough }
# Exit handler
EXIT = Proc.new do |code... | true |
24444d8fd7fb8e770898c361fb0885326e3e21a0 | Ruby | postmodern/scm | /lib/scm/scm.rb | UTF-8 | 1,617 | 2.984375 | 3 | [
"MIT"
] | permissive | require 'scm/git'
require 'scm/hg'
require 'scm/svn'
require 'uri'
module SCM
# SCM control directories and the SCM classes
DIRS = {
'.git' => Git,
'.hg' => Hg,
'.svn' => SVN
}
# Common URI schemes used to denote the SCM
SCHEMES = {
'git' => Git,
'hg' => Hg,
'svn' => S... | true |
5c79214de472cf5d997b2d0d8ff70cf7f302452e | Ruby | jdaig/Maraton | /Online Store/Model.rb | UTF-8 | 609 | 2.578125 | 3 | [] | no_license |
class Store
def initialize
index_users
inventary
end
def inventary
CSV.foreach("Products.csv") do |product|
@list << Producto.new(product[0],product[1])
end
end
def index_users
CSV.foreach("User_Registrer.csv") do |usuario|
@list << User.new(usuario[0],usuario[1],usuario[2]... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.