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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
6636a09f35e8358299097e245191ebd0f7552041 | Ruby | SlicingDice/slicingdice-ruby | /lib/rbslicer/core/requester.rb | UTF-8 | 1,732 | 2.765625 | 3 | [
"MIT"
] | permissive | # coding: utf-8
require 'net/https'
require 'uri'
require 'json'
module Core
# Public: Make full post request
class Requester
def initialize(timeout)
@timeout = timeout
end
# Public: Make a HTTP request.
#
# url(String) - A url String to make request
# headers(Hash) - A Hash with ou... | true |
5461ae81465daa118a7178ff9067d00d45835fa7 | Ruby | carolgreene/collections_practice-v-000 | /collections_practice.rb | UTF-8 | 665 | 3.78125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def sort_array_asc(array)
array.sort
end
def sort_array_desc(array)
array.sort.reverse
end
def sort_array_char_count(array)
array.sort{|left, right| left.length <=> right.length}
end
def swap_elements(array)
array[1], array[2] = array[2], array[1]
return array
end
def reverse_array(array)
array.reverse
en... | true |
e7b1e66fd8c920b5548beda47c50360682151500 | Ruby | khanhhuy288/Ruby-Aufgaben | /A4-Relationen und Abbildungen/RelationenGenerator.rb | UTF-8 | 1,453 | 3.5625 | 4 | [] | no_license | require './Relation'
class RelationenGenerator
def RelationenGenerator.generiere_relation(set_a,set_b,k)
# create new Relations from 2 Sets
relation = Relation.new(set_a, set_b)
# return empty Relation if k is not valid (k > max_tupels)
max_tupels = set_a.size * set_b.size
raise 'k muss <= maxim... | true |
9078929a9d794029aeb42100bae288a11b22c924 | Ruby | louiehchen/phase-0-tracks | /ruby/house.rb | UTF-8 | 2,020 | 4.34375 | 4 | [] | no_license | # HOUSE MAKER
# Allow user to create a house,
# then add rooms,
# then add items
# House can have up to 5 rooms
#Room can have an unlimited number of items
def add_room_to_house!(house, room_name) # house becomes a hash
if house.keys.length == 5 # limits number of rooms to 5. Rooms are keys.
false
else
house... | true |
5cbf5edbab4d02a4c5a242845aa1f0979fa8501f | Ruby | RomanADavis/challenges | /exercism/ruby/bracket-push/bracket_push.rb | UTF-8 | 478 | 3.078125 | 3 | [] | no_license | class Brackets
OPEN_TO_CLOSE = {'(' => ')', '[' => ']', '{' => '}'}
def self.paired?(string)
memory = []
string.each_char do |char|
memory << char if OPEN_TO_CLOSE.keys.include? char
if OPEN_TO_CLOSE.values.include? char
# If I don't put the parenthesis here it doesn't work; no idea why.... | true |
d44f1f4c846d5228158f6cb2457264081b4596e2 | Ruby | GBJim/ptt_push_demp | /data_preprocess/preprocessor.rb | UTF-8 | 2,399 | 2.8125 | 3 | [] | no_license | require 'csv'
require 'set'
CSV.foreach(filename, :headers => true) do |row|
User.create!(row.to_hash)
end
filename = "data_preprocess/pushList.csv"
CSV.foreach(filename, :headers => true) do |row|
user = User.find_or_create_by(name: row[:user_name])
user.pushes.create(body: row[:body])
user.save
end
... | true |
8b5b7b4d6639542150a134b0d4b529839d738965 | Ruby | justindelatorre/rb_101 | /small_problems/easy_3/easy_3_10.rb | UTF-8 | 532 | 4.625 | 5 | [] | no_license | =begin
Write a method that returns true if its integer argument is palindromic, false
otherwise. A palindromic number reads the same forwards and backwards.
Examples:
palindromic_number?(34543) == true
palindromic_number?(123210) == false
palindromic_number?(22) == true
palindromic_number?(5) == true
=end
def palind... | true |
b6f1a00a355b9f4346e5fb313bc2b61b66c94c83 | Ruby | andresgap/wc18 | /app/modules/position_board.rb | UTF-8 | 1,289 | 2.65625 | 3 | [
"MIT"
] | permissive | class PositionBoard
attr_reader :leaderboard
def initialize(leaderboard = nil)
@leaderboard = leaderboard
end
def members
@members ||= positions.sort_by { |position| [position.index, position.name.downcase] }
end
def title
@title ||= leaderboard ? leaderboard.name : 'general'
end
privat... | true |
06d997c31bd3a577bd5a335ef2c45b882254fc4c | Ruby | JMazzy/134141414kjkjfksjafsakfjl | /lib/battle_bot.rb | UTF-8 | 1,950 | 3.5625 | 4 | [] | no_license | class BattleBot
attr_reader :name, :health, :enemies, :weapon, :dead
@@count = 0
def self.count
@@count
end
def initialize(name,health=100)
raise ArgumentError, "no name given" if name == nil
@name = name
@health = health
@weapon = nil
@enemies = []
@dead = false
@@count += ... | true |
b868a5b4ef72846788aa789ecb3571b9f159388e | Ruby | 0100354256/Prct12M17 | /lib/Prct12M17/threads.rb | UTF-8 | 1,218 | 2.859375 | 3 | [
"MIT"
] | permissive | require "Prct12M17/naranjero.rb"
Thread.abort_on_exception = true
class Threads
attr_reader :naranjero
def initialize(mutex, cv, naranjero)
@mutex = mutex
@cv = cv
@naranjero = naranjero
end
def ejecucion
consumidor = Thread.new do
until (@naranjero.edad == Naranjero::EDAD_MUERTE)
... | true |
36fadc54f06f5fd9d4f4c8cf14dc85c27b8548f0 | Ruby | make-void/reactive_opal | /app.rb | UTF-8 | 1,145 | 2.796875 | 3 | [] | no_license | # required: opal + browser
`self.$require("browser");`
`self.$require("browser/http");`
class State
@@state = {}
def self.all
@@state
end
def self.all=(state)
@@state = state
end
end
# env.rb: initial state
State.all = { line: 1 }
# actions
def add_element
line.append_to $document["container... | true |
d656f1d3d22a0d075931ac5ae722c601d1d7c3bd | Ruby | tiy-austin-ror-jan2015/Third-Day | /blackjack.rb | UTF-8 | 1,804 | 4.25 | 4 | [] | no_license | # Blackjack
puts "Let's play Blackjack!"
puts "-" * 20
class Blackjack
def initialize
@player = player.new # You are calling .new on a variable (which has not been set, so it is nil) and not on the Class - JH
@dealer = dealer.new # You are calling .new on a variable (which has not been set, so it is nil) an... | true |
bcb9081a71954400215337c8759c009f8f874564 | Ruby | psytown/learn-ruby-the-hard-way | /ex31.rb | UTF-8 | 1,393 | 3.6875 | 4 | [] | no_license | # encoding: UTF-8
# author:ouyangzhiping
# title:learn the ruby the hard way
# website:https://github.com/ouyangzhiping/learn-ruby-the-hard-way
#Author:Zhangxi
#Title:Learn ruby the hard way
def prompt
print">"
end
puts"You enter a dark room with two doors.Do you go through door #1 or door #2?"
prompt;door =gets.... | true |
7a4d516384ce799608e08a26a93d6b09b3daf18b | Ruby | Friindel33/RubyLessons | /Myapp4/hash_demo2.rb | UTF-8 | 490 | 3.515625 | 4 | [] | no_license | @hh = {}
def add_person options
puts "Already in the list!" if @hh[options[:name]]
@hh[options[:name]] = options[:age]
end
def show_hash
@hh.keys.each do |key|
age = @hh[key]
puts "Name: #{key}, age: #{age}"
end
end
loop do
print "Enter name: "
name = gets.strip.capitalize
if name == ''
show... | true |
0b95c3b96b95f5fca11945c474c6c652333395a1 | Ruby | IQ-SCM/burgundy | /lib/burgundy/collection.rb | UTF-8 | 693 | 2.96875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Burgundy
class Collection
def initialize(items, wrapping_class = nil, *args)
@items = items
@wrapping_class = wrapping_class
@args = args
end
def method_missing(name, *args, &block) # rubocop:disable Style/MissingRespondToMissing
to_ary.send(n... | true |
2bae06658f30ec38b3f0106a526597ce31d76194 | Ruby | psyho/fun.rb | /spec/fun/curry_spec.rb | UTF-8 | 963 | 3.09375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Fun::Curry do
def ac(&block)
Fun.auto_curry(block)
end
describe "auto_curry" do
it "creates a lambda" do
sum = ac{|a,b,c| a + b + c}
expect(sum[1, 2, 3]).to eq(6)
end
it "creates an auto-curried lambda" do
sum = ac{|a,b| a + b}
inc = sum[1... | true |
b285e3483482881685a14ed70a723c91c7db9707 | Ruby | YuraPlinto/SeaBattle | /field.rb | UTF-8 | 20,014 | 3.25 | 3 | [] | no_license | class Field
=begin
Класс Field отвечает за представление поля.
Он инкапсулирует все методы ввода/вывода для экземпляра поля.
В классе описаны все возможные состояния поля.
В класс встроено распознавание координат.
Класс ведёт учёт количества живых кораблей и хранит информацию
сдался ли пользователь - владелец поля.
Н... | true |
49ab115c3df486ea928b359c3111f327343bfef9 | Ruby | kdaigle/ruby-for-doers | /case.rb | UTF-8 | 344 | 3.90625 | 4 | [
"CC-BY-4.0"
] | permissive | #!/usr/bin/env ruby
# Sometimes, a simple `if then` statement isn't useful enough. You may have mulitple branches
# that need to be considered. That's when a case statement is useful.
dog = "woof"
case dog
when "woof"
puts "Woof! Woof! ::grown::"
when "meow"
puts "Meow... meow... ::prrr::"
else
puts "I don't k... | true |
fd8dd3a1a801f087d14a5c16b065293fed936807 | Ruby | amine91480/J3-lib | /lib/01_pyramids.rb | UTF-8 | 1,434 | 3.453125 | 3 | [] | no_license | def half_pyramid
puts "Salut, bienvenue dans ma pyramide ! Combien d'étage veux tu entre ?"
etage = gets.to_i
if etage <= 0 || etage >= 25
puts "Le paramètre renseigner et incorrect"
else
a = 1
x = etage
etage.times do
b = " " * x
d = "#" * a
a = a + 1
x = x - 1
p... | true |
0f72533487f69763f6bbbeb8d0073656d931a043 | Ruby | Spakman/isoworks | /test/paginatable_test.rb | UTF-8 | 901 | 2.65625 | 3 | [
"MIT"
] | permissive | require_relative "test_helper"
describe Paginatable do
let(:object) { Array(1..100) }
let(:number_of_pages) { 34 }
before do
object.extend(Paginatable)
end
it "returns the number of pages in the paginated object" do
assert_equal number_of_pages, object.number_of_pages
end
it "returns the items... | true |
9608221eab909cdda2c528f0e565d2bb9685c950 | Ruby | edwinmonroy/rubycourse | /ch06/angryBoss.rb | UTF-8 | 303 | 3.4375 | 3 | [] | no_license | puts
puts
puts 'Whatchu up to my lovely favorite boss?'
puts
puts
puts 'Stop being a kiss ass and tell me what you want.'
puts
puts
puts 'uh...well...'
request = gets.chomp
puts
puts
puts '...you wasted my time for that?'
puts
puts
puts (request + ' is the stupidest request I have ever heard!').upcase
| true |
50c82236ecb6845dd662e7919f470a8650678830 | Ruby | jaclynj/Drill | /week02/distillery/distillery.rb | UTF-8 | 817 | 3.28125 | 3 | [] | no_license | class Distillery
def initialize(name)
@name = name
@cellar = {}
# When a new distillery is created, a new marketing department should be created at the same time
# and should be pointed to by an instance variable of the new distillery object.
@marketing_dept = Marketing_Department.new
end
de... | true |
f20469f6d632f1053c562ea20ebdb551b6afee8a | Ruby | Yashwanth-nr/RentBike | /app/models/booking.rb | UTF-8 | 574 | 2.609375 | 3 | [] | no_license | class Booking < ActiveRecord::Base
belongs_to :bike
belongs_to :user
validate :check_availability
private
def check_availability
bookings = self.bike.bookings.where('confirmed = ?', true)
new_booking_dates = ( self.start_datetime.to_date..self.end_datetime.to_date).to_a
bookings.each do |booking|
book... | true |
5cad1b5c2572d9979a15df8dbc22d76e329f5ea2 | Ruby | rbuda/phase-0 | /week-4/concatenate-arrays/my_solution.rb | UTF-8 | 336 | 3.59375 | 4 | [
"MIT"
] | permissive | # Concatenate Two Arrays
# I worked on this challenge [by myself].
# Your Solution Below
def array_concat(array_1, array_2)
if array_1.empty? && array_2.empty?
final_array = []
else
count = 0
while count < array_2.length
final_array = array_1.push array_2[count]
count += 1
end
end
return... | true |
83f26764435467f5eb0b8fed11f2ada80d9f6fd7 | Ruby | sfrasica/ruby-project-alt-guidelines-dumbo-web-010620 | /lib/models/command_line_interface.rb | UTF-8 | 216 | 2.640625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
class CommandLineInterface
# Inro message
def greet
puts "************** Welcome to the GifShoppe! ************************"
puts "World renowned one stop shop for all things GIF!"
end
end | true |
524184c64db5436f1cc760f0955049f5d483bb3c | Ruby | Vincelep/pyramide | /pyramide.rb | UTF-8 | 233 | 3.390625 | 3 | [] | no_license | puts "Hello, bienvenue dans ma super pyramide ! Combien d'étages tu veux ? "
i = gets.chomp.to_i
#j = "".to_s
k = 0
l = "#"
puts "voici la pyramide"
i.times do
#puts " #{j += "#"}"
#end
puts l*(k += 1)
end
#normalement c'est bon | true |
cbfeb58052a06427ef60be5cfbc7000b5d5c9380 | Ruby | davidlrnt/loqal | /app/data_fetchers/location.rb | UTF-8 | 231 | 2.625 | 3 | [] | no_license | require 'pry'
class Location
attr_reader :urlhash
def initialize
@urlhash = JSON.load(open("http://ipinfo.io/json"))
end
def coordinates
@urlhash["loc"]
end
def zipcode
@urlhash["postal"]
end
end
| true |
28d54c784ad8ae632302adf885a093d1a70d812d | Ruby | omahacodeschool/ruby-toy__phone-number-formatter | /lib/phone_number_formatter.rb | UTF-8 | 171 | 3.15625 | 3 | [] | no_license | # This method takes a string like `"4122226644"` and
# returns a properly formatted phone number.
def format_phone_number(phone_number_str)
return phone_number_str
end
| true |
ed4a18e858fe11235f256d156cdcc3f1350bc01b | Ruby | MLampa/ninety-nine-bottles-challenge | /beer.rb | UTF-8 | 1,891 | 4.125 | 4 | [] | no_license | counter = 99
until counter == 2
puts "#{counter} bottles of beer on the wall, #{counter} bottles of beer! You take one down, you pass it around, #{counter-1} bottles of beer on the wall!\n\n"
counter -= 1
if counter == 2
puts "#{counter} bottles of beer on the wall, #{counter} bottles of beer! You tak... | true |
9ff6081a63755a59817af9d93d5f7769cb1d1da3 | Ruby | haf/logirel | /spec/queries/bool_query_spec.rb | UTF-8 | 988 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | require 'logirel/queries'
module Logirel
module Queries
describe BoolQ, "when given input" do
before(:each) { @out = StringIO.new }
it "input says no, second time" do
io = StringIO.new "x\nn"
b = BoolQ.new "Yes or no?", true, io, @out
b.exec.should be_false
e... | true |
3a37cc999b33dcfe9b232e12626ba28636b3a2b2 | Ruby | athityakumar/ruby-chem-eqn | /helpers/get_elements/get_elements_helpers/order_by_syntax.rb | UTF-8 | 348 | 2.703125 | 3 | [
"MIT"
] | permissive | require_relative "get_index"
def order_by_syntax bracket_status , open_bracket , close_bracket , hash
while open_bracket.count != 0 do
key = close_bracket[0]
index = get_index(open_bracket,key)
value = open_bracket[index]
hash[key] = value
open_bracket.delete(value)
close_bracket.delete(key)... | true |
8fb4e6a7a6cb4c78800690ec75112dd7f0da6c59 | Ruby | jessicatriana/ruby-oo-self-cash-register-lab-austin-web-012720 | /lib/cash_register.rb | UTF-8 | 1,057 | 3.453125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class CashRegister
attr_accessor :total, :discount, :quantity
@@all = []
def initialize(discount= nil, quantity= 0)
@total = 0
@discount = discount
@quantity = quantity
@item_list = []
end
def add_item(title, price, quantity= 1)
@total += ... | true |
0da576ff2988f569b61b338164d6137863a01002 | Ruby | AJ8GH/ruby-udemy | /hashes/sort_and sort_by_methods_on_a_hash.rb | UTF-8 | 375 | 3.625 | 4 | [] | no_license | pokemon = {squirtle: 'Water', bulbasaur: 'Grass',
charizard: "Fire"}
p pokemon.sort
# converts to multi-dimensional array then sorts by keys, alphabetically
p pokemon.sort.reverse
puts
p pokemon.sort_by { |pokemon, type| type }
# just put the value or the key in the block to specify which you want to sort... | true |
1494a91e55f070afced83b9ac89b92f401d10d53 | Ruby | ryanmjacobs/room-thermostat | /discovery/listen.rb | UTF-8 | 836 | 2.6875 | 3 | [] | no_license | require "json"
require "socket"
require "colorize"
def netcolor(addr)
return :red if addr.map{|x| x.start_with?("192.168.")}.any?
return :yellow if addr.map{|x| x.start_with?("10.0.1")}.any?
return :blue
end
PORT = 31001
socket = UDPSocket.new
socket.bind("", PORT)
while true do
begin
dat... | true |
95cbfeabe6d78b7d4b6e281e4d2b79a5078a04fe | Ruby | nickjcarr/NicholasCarr_T1A3 | /company.rb | UTF-8 | 83 | 2.6875 | 3 | [
"MIT"
] | permissive | class Company
attr_accessor :name
def initialize(name)
@name = name
end
end | true |
3fa8a8bfe709c71edde43bb1fed8c6e89cfcb688 | Ruby | abosaudtech/Ruby_on_Rails | /Sololearn/class_constants.rb | UTF-8 | 571 | 3.5625 | 4 | [] | no_license | =begin
A class can also contain constants. Remember,
constants variables do not change their value and
start with capital letter. It is common to have
uppercase names for constants, as in:
=end
class Calc
PI = 3.14
end
# You can access constants using the class name,
# followed by two colo symbols (::... | true |
89f8cb647c213663c74f9f1959373eb219072ef6 | Ruby | smilesr/op-rb-rw-15-serverclient | /server.rb | UTF-8 | 1,561 | 2.9375 | 3 | [] | no_license | require 'socket'
require 'json'
server = TCPServer.open(2000)
puts "Server listening on port 2000"
loop {
client = server.accept
request = ""
while line = client.gets
request += line
break if request =~ /\r\n\r\n$/
end
request_arr = request.split(" ")
verb = request_arr[0]
uri = request_arr[1... | true |
9afeac30c3145d9c2a8e331c31d1de329f1f396b | Ruby | kilimchoi/teamleada.com | /db/seeds/projects/013_statricks_project.rb | UTF-8 | 20,300 | 3.171875 | 3 | [] | no_license | # @author: Guang Yang
# @editor: Tristan Tao
# @mktime: 2014/06/10
# @description: web scraper project for boattrader.com in python
main_page_content = [
['text', 'In this project, you are tasked with building a web scraper for Statricks, an analytics technology company that aggregates price d... | true |
178fb18e07f68ef8d9ba1c5ae2539774470504ad | Ruby | DocsWebApps/system-dashboard-rails | /test/models/company_test.rb | UTF-8 | 1,006 | 2.78125 | 3 | [
"MIT"
] | permissive | # == Schema Information
#
# Table name: companies
#
# id :integer not null, primary key
# name :string(255)
# created_at :datetime
# updated_at :datetime
#
require 'test_helper'
class CompanyTest < ActiveSupport::TestCase
def setup
@company=FactoryGirl.create :company
@name=@c... | true |
05becbf328798722ce6545effe210a92f530c884 | Ruby | bdisney/ror | /lesson_06/models/route.rb | UTF-8 | 1,607 | 3.59375 | 4 | [
"MIT"
] | permissive | class Route
attr_reader :stations
def initialize(start, finish)
@stations = [start, finish]
validate!
end
def is_valid?
validate!
rescue
false
end
def include(station)
raise "Станция уже содержится в маршруте" if in_route?(station)
include!(station)
end
def exclude(station)... | true |
d9343df0fb7592d22f7fd33c8861630ffa8555dd | Ruby | criacuervos/recursion-writing | /lib/recursive-methods.rb | UTF-8 | 1,783 | 3.875 | 4 | [] | no_license | # Authoring recursive algorithms. Add comments including time and space complexity for each method.
# Time complexity: O(n^2)
# Space complexity: O(n^2)
def factorial(n)
if n < 0
raise ArgumentError
elsif n <= 1
return 1
else
return n * factorial(n - 1)
end
end
# Time complexity: O(n)
# Space ... | true |
9a3843859c9a109dbe2a3b53598737edc739a441 | Ruby | Vorgnr/randstone | /spec/models/card_spec.rb | UTF-8 | 11,787 | 2.609375 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Card, type: :model do
describe '.random_numplet' do
context 'when users have enough cards' do
it 'should return uniq cards nuplet' do
cards = 5.times.map { create(:card) }
expect(cards.uniq { |c| c.id }.length).to eq 5
nuplet = Card.random_nuple... | true |
6e1478b5bf63bd4839258952b9969860b5f0a61c | Ruby | txus/kleisli | /test/kleisli/composition_test.rb | UTF-8 | 1,956 | 3.140625 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class CompositionTest < Minitest::Test
def test_one_method
f = F . first
result = f.call([1])
assert Fixnum === result, "#{result} is not a number"
assert_equal 1, result
end
def test_two_methods
f = F . first . last
result = f.call([1, [2,3]])
assert Fixnum ===... | true |
6a6d37c080c92845c02a9aa5f778ef0d35c3c2ce | Ruby | cider-load-test/decawell | /fusor_controller/duty_cycle_study.rb | UTF-8 | 445 | 3.140625 | 3 | [] | no_license | #http://en.wikipedia.org/wiki/Pulse-width_modulation
wavelength = 10.0 #length in seconds for the wavelength
duty_cycle = 0.7 # a float between 0 and 1
time_on = wavelength*duty_cycle
start_time = Time.now()
state = true
while true
time_now = Time.now()
(duration = (time_on) ) if state
(duration = (wavelength - tim... | true |
a6f0c3f4c8b61cb7745aeaf7cd0ad9bf95ba0674 | Ruby | BoTreeConsultingTeam/skill-hunt | /spec/models/user_spec.rb | UTF-8 | 5,986 | 2.59375 | 3 | [] | no_license | require 'spec_helper'
describe User do
include_context 'initialize_common_objects'
let(:user) { User.new }
let!(:errors) { user.save; user.errors }
it { should respond_to(:first_name) }
it { should respond_to(:last_name) }
it { should respond_to(:gender) }
it { should respond_to(:email) }
it { should... | true |
42365e48b11d47274140e7dde7b61bd2399bc599 | Ruby | jeremiahkellick/algorithms-coursework | /shell_sort.rb | UTF-8 | 273 | 3.03125 | 3 | [] | no_license | require_relative "insertion_sort"
def shell_sort(arr, &prc)
prc ||= Proc.new { |a, b| a <=> b }
interval = 1;
interval = interval * 3 + 1 while interval < arr.length / 3
while interval >= 1
insertion_sort(arr, interval, &prc)
interval /= 3
end
arr
end
| true |
07c484d4374f0def17d5ec6e9a2ef3cf8f7b8787 | Ruby | despino/Five_Problems | /alt.rb | UTF-8 | 184 | 3.15625 | 3 | [] | no_license | @l1 = [1,2,3]
@l2 = ['a','b','c']
@final_arr = []
def alternate
@l1.each do |i|
@final_arr << @l1[i-1]
@final_arr << @l2[i-1]
end
puts @final_arr.join ', '
end
alternate
| true |
ac5f6679d754153c0b823e8e77ffbca0ddc4a3ba | Ruby | vladfreel/primes | /prime.rb | UTF-8 | 278 | 3.625 | 4 | [] | no_license | require 'prime'
primes = []
Prime.take_while do |n|
if primes.sum + n < 1000000
primes.push(n)
end
end
until Prime.prime?(primes.sum)
primes.pop
end
puts
puts "Biggest sum of consecutive primes below million: #{primes.sum}"
puts
puts "Primes: #{primes.join(' , ')}"
| true |
584ab4e901636ff0660e6fa006d5cfad44b62664 | Ruby | ReseauEntourage/entourage-ror | /lib/mixpanel_tools.rb | UTF-8 | 1,583 | 2.53125 | 3 | [
"MIT"
] | permissive | module MixpanelTools
class ResponseError < RuntimeError; end
def self.request path, params={}
puts "GET #{path} #{params.inspect}"
response = HTTParty.get(
File.join("https://mixpanel.com/api/2.0/", path.to_s),
basic_auth: { username: ENV['MIXPANEL_SECRET'] },
query: params
)
body... | true |
870a40e9a6a1359c8c1bc739b0538af9ab172d12 | Ruby | schneems/repl_runner | /test/repl_runner_test.rb | UTF-8 | 2,227 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class ReplRunnerTest < Test::Unit::TestCase
def test_local_irb_stream
ReplRunner.new(:irb).run do |repl|
repl.run('111+111') {|r| assert_match '222', r }
repl.run("'hello' + 'world'") {|r| assert_match 'helloworld', r }
repl.run("a = 'foo'")
repl.run("b = '... | true |
4d0e5a2075a20ba43c3acccc897db8b32b685738 | Ruby | Lasiorhine/factorial | /lib/factorial.rb | UTF-8 | 374 | 3.71875 | 4 | [] | no_license |
require 'pry'
# Computes factorial of the input number and returns it
def factorial(number)
accumulator = 1
if number.nil?
raise ArgumentError.new("You can't factorialize 'nil.' ")
elsif
number == 0 || number == 1
return 1
else
until number == 0 do
accumulator = number * accumulator
... | true |
57583d4f0cd2f9db4ff827652a7ae518636c99ea | Ruby | amandaungco/api-muncher | /lib/edamam_api_wrapper.rb | UTF-8 | 1,456 | 2.96875 | 3 | [] | no_license | require 'httparty'
require 'awesome_print'
class EdamamApiWrapper
BASE_URL = "https://api.edamam.com/"
APP_KEY = ENV["app_key"]
APP_ID = ENV["app_id"]
RETURN_RECIPE= "http%3A%2F%2Fwww.edamam.com%2Fontologies%2Fedamam.owl%23"
def self.list_recipes(search_term)
url = BASE_URL + "search?q=#{search_term}... | true |
740b7f47b26d8924c794e4177a333af3007dd60c | Ruby | trschmitt/notes | /09/4-thursday-44/ancestors.rb | UTF-8 | 602 | 3.390625 | 3 | [] | no_license | require 'date'
class Elephant
def initialize(name, born_on)
@name = name
@born_on = born_on
end
attr_accessor :name
# attr_reader :name
# def name
# @name
# end
# attr_writer :name
# def name=(other)
# @name = other
# end
def a_method
self
end
def self.repopulate
3.t... | true |
3a2721e2e1f0b570c72ee64775445e9b65894ce4 | Ruby | samuelmolinari/dissertation | /ror/DissertationSystem/app/controllers/account_controller.rb | UTF-8 | 2,224 | 2.53125 | 3 | [] | no_license | =begin
Controller related to the account management
@version 06/06/2012
@author Samuel Molinari
=end
require 'fileutils'
require 'RMagick'
class AccountController < ApplicationController
# No need of authentification when creating an account
before_filter :require_auth, :except => [:create]
##
# Crea... | true |
a5cef4b229000f7835b058265dbff4d87bc53787 | Ruby | AhmedAmin90/indeed_web_scraper | /lib/scraper.rb | UTF-8 | 1,589 | 3.03125 | 3 | [
"MIT"
] | permissive | require 'httparty'
require 'nokogiri'
require 'rainbow'
require 'csv'
class Scraper
attr_accessor :all_jobs, :vacancies, :page_number, :posted_days, :url_date
def initialize
@vacancies = ['front+end+developer',
'back+end+developer&',
'full+sack+developer',
... | true |
e163b5c43d96b9067e13955b44d820d24a60e58c | Ruby | COASST/coasst-old | /vendor/plugins/deep_copy/lib/deepcopy.rb | UTF-8 | 159 | 2.59375 | 3 | [] | no_license | # Deep Copy
#
# ruby lacks deep copying, use marshal to create true duplicates
class Object
def m_dup
Marshal.load(Marshal.dump(self))
end
end
| true |
b81435fba1821ea13c2d6370a3932dbf3edecfd6 | Ruby | marcwright/WDI_ATL_1_Instructors | /REPO - DC - Students/w02/d02/Elaine/calculator/lib/calc.rb | UTF-8 | 456 | 3.71875 | 4 | [] | no_license | class Calculator
def add(number1, number2)
return number1 + number2
end
def subtract(number1, number2)
return number1 - number2
end
def power(number1, number2)
return number1**number2
end
def sum(array)
return array.reduce(0, :+)
end
def multiply(*nums)
return nums.reduce(:*)
... | true |
1368e5d74521ddc55330d09e09aedbcfa701345a | Ruby | harrybrown/vendor-import-export | /lib/extensions/ruby_patches.rb | UTF-8 | 1,824 | 2.9375 | 3 | [] | no_license | module Kernel
def caller_method_name
parse_caller(caller(2).first).last
end
def parse_caller(at)
if /^(.+?):(\d+)(?::in `(.*)')?/ =~ at
file = Regexp.last_match[1]
line = Regexp.last_match[2].to_i
method = Regexp.last_match[3]
[file, line, method]
end
end
end
class Hash
# Usag... | true |
78cf66db03b0bcfa1379cf373962db9e266349e3 | Ruby | softsprocket/async_tcpsocket | /test.rb | UTF-8 | 376 | 2.78125 | 3 | [] | no_license | #!/usr/bin/ruby
require 'async_tcpsocket'
socket = AsyncTCPSocket.new
socket.once :error, Proc.new { |err|
STDERR.puts "Error: #{err}"
socket.close
}
socket.once :close, Proc.new { |err|
socket.close
}
socket.on :data, Proc.new { |data|
puts "#{data}"
}
socket.connect 'localhost', 80
socket.puts "GET / HTTP... | true |
b684d7f4c13d659c400c44196c5549b1fb6339a2 | Ruby | AntonBarkan/tgt | /lib/CodeHolders/method_holder.rb | UTF-8 | 667 | 3.421875 | 3 | [] | no_license | class MethodHolder
attr_accessor :method_name
attr_accessor :method_return_type
attr_accessor :parameters
def initialize(method_name)
@method_name = method_name
@parameters = Array.new
end
def addParameter(field)
@parameters << field
end
def print
methodString = 'def ' + method_name
... | true |
e6b6c42ee037ecfecffcc5b7de2bcdecdf3d27c3 | Ruby | Zander2/BEWD11-ClassWork | /ruby/Array_loops/Lab2.rb | UTF-8 | 110 | 3.109375 | 3 | [] | no_license | array_copy = [1, 2, 3, 4, 5]
# your code
destination = array_copy.select {|i| i < 4 }
puts destination | true |
71374396017eb68c341ad7490dd2506cd00fd6b4 | Ruby | joyhuangg/oo-relationships-practice | /app/models/location.rb | UTF-8 | 454 | 2.84375 | 3 | [] | no_license | class Location
@@all = []
attr_accessor :location
def self.all
@@all
end
def initialize(location:)
@location = location
@@all << self
end
def self.least_clients
Location.all.min_by {|location| location.clients}
end
def trainers
Trainer.all.select {|trainer| trainer.locations.in... | true |
fadc5f9f2b196b296c658ecbb4c2d40ad03b08fd | Ruby | AnaTeresaDona/Cepas2 | /app/models/wine.rb | UTF-8 | 779 | 2.671875 | 3 | [] | no_license | class Wine < ApplicationRecord
has_many :wine_strains, dependent: :destroy
has_many :strains, through: :wine_strains
has_many :oenologist_wines, dependent: :destroy
has_many :oenologists, through: :oenologist_wines
def addStrainPercent(percents)
percents.each do |strain_id, percentage|
... | true |
920f1d463d6463c4dc573c0fc5df1cb9139f047c | Ruby | ozPop/reverse-each-word-001-prework-web | /reverse_each_word.rb | UTF-8 | 172 | 3.65625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reverse_each_word(s)
arrS = s.split(" ")
arrS.each { |el| el.reverse! }.join(" ")
end
def reverse_each_word2(s)
s.split.collect { |el| el.reverse }.join(" ")
end | true |
88e1bd44293774bb7c14a8ad9be8f2b63f25f832 | Ruby | andryjohn/ruby_concept- | /hashes.rb | UTF-8 | 176 | 3.125 | 3 | [] | no_license | states = {
:Pennsylvania => "PA",
"New York" => "NY",
"California" => "CA",
"Oregon" => "Oregon"
}
puts states[:Pennsylvania]
#or
#puts states[1] using index | true |
9e4a9943b47f1b180f622a20973b1659cbf48f07 | Ruby | BonbonLemon/Chess | /sliding_subclasses.rb | UTF-8 | 842 | 3.03125 | 3 | [] | no_license | require_relative 'sliding_pieces'
class Rook < SlidingPiece
MOVE_DIRECTIONS = [
[ 0, 1],
[ 1, 0],
[-1, 0],
[ 0, -1]
]
def to_s
' ♖ '.colorize(@color)
end
def move_dirs
MOVE_DIRECTIONS
end
def dup
Rook.new(@pos, @color, nil)
end
end
class Bishop < SlidingPiece
MOVE... | true |
9dad79a6b3b6e3d20f18651c7e2eaed8d754dd70 | Ruby | ensallee/the-bachelor-todo-nyc-web-042318 | /lib/bachelor.rb | UTF-8 | 1,799 | 3.5 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def get_first_name_of_season_winner(data, season)
data.each do |season_number, season_data|
if season_number == season
season_data.each do |keys|
keys.each do |person_key, person_value|
if person_value == "Winner"
full_name=keys["name"].split
return f... | true |
bb5314478ac858bd60af37d98bd8609666aa2f78 | Ruby | yui-knk/pycall | /lib/pycall/pyobject.rb | UTF-8 | 4,598 | 2.765625 | 3 | [
"MIT"
] | permissive | module PyCall
Py_LT = 0
Py_LE = 1
Py_EQ = 2
Py_NE = 3
Py_GT = 4
Py_GE = 5
RICH_COMPARISON_OPCODES = {
:< => Py_LT,
:<= => Py_LE,
:== => Py_EQ,
:!= => Py_NE,
:> => Py_GT,
:>= => Py_GE
}.freeze
module PyObjectMethods
def rich_compare(other, op)
opcode = RICH_COMPARI... | true |
72f6cca55265e9241ef97471a81dcfd403b1d003 | Ruby | locomote/translations_checker | /lib/translations_checker/locale_file_key_map.rb | UTF-8 | 1,070 | 2.65625 | 3 | [
"MIT"
] | permissive | module TranslationsChecker
class LocaleFileKeyMap
def initialize(content)
@content = content
end
def key_at(line_number)
key_map[line_number]
end
def key_line(key)
key_map.key(key)
end
private
attr_reader :content
def lines
content.yaml.lines
end
... | true |
8489531ea670820356f350d0c85bc4f73af6b623 | Ruby | chian88/course_120 | /exercise/easy3/5.rb | UTF-8 | 383 | 3.21875 | 3 | [] | no_license | class Television
def self.manufacturer
end
def model
end
end
tv = Television.new
tv.manufacturer # can't work because #manufacturer is a class method.
tv.model # will work because #model is a instance method.
Television.manufacturer # will work because #manufacturer is a class method.
Tel... | true |
a7cb01bb2f87258df70fbafcf5797a462a1dff07 | Ruby | MarioRoncador/blocitoff-rails | /db/seeds.rb | UTF-8 | 437 | 2.703125 | 3 | [] | no_license | include Faker
# Create Users
5.times do
User.create!(
email: Faker::Internet.email,
password: Faker::Internet.password,
)
end
User.create!(
email: "m@m.com",
password: "111111",
)
users = User.all
# Create Items
50.times do
Item.create!(
name: Faker::Lorem.sentence,
user: users.sample,
)
... | true |
f5db12d080a0beb6558b54e9b135fbc8dc2a13e5 | Ruby | 6twenty/project_euler | /ruby/problem_15/program.rb | UTF-8 | 532 | 3.6875 | 4 | [] | no_license | # Starting in the top left corner of a 2x2 grid, there are 6 routes (without backtracking) to the bottom right corner.
#
# How many routes are there through a 20x20 grid?
#
# THE MATRIX
@solutions = [[2], [3,6], [4,10,20]] # results of "1", "2" and "3"
# start at "4"
(4..20).to_a.each do |x|
array = []
index = ... | true |
b4ee797df7a5fd3da0a12aef001beb76d6023447 | Ruby | oriff/multiplier | /create_channel.rb | UTF-8 | 1,472 | 2.875 | 3 | [
"MIT"
] | permissive | require 'rubygems'
require 'json'
require 'yaml'
require 'rest_client'
$base_url = "www.pushray.com:8080/api/v1/"
# Function that create channel with rest_api and check if channel exsists first
def create_channel(channel)
puts "running create_channel, channel = #{channel.inspect}"
key_check = RestClient.get "#{... | true |
a0925435824779d41c19c682345624cac79bbf10 | Ruby | nrozmus/looping-for-online-web-prework | /for.rb | UTF-8 | 163 | 2.8125 | 3 | [] | no_license | def using_for
checklist = 1..10
def using_for
checklist = 1..10
#your code here
end
for checklist in checklist do
puts "Wingardium Leviosa"
end
end | true |
8b481362d4a97fef6a16addd584c2c0a77027fd9 | Ruby | nezetic/ruby-xbmc | /lib/ruby-xbmc.rb | UTF-8 | 15,671 | 2.84375 | 3 | [] | no_license | #!/usr/bin/env ruby
=begin
ruby-xbmc
ruby-xbmc is a ruby wrapper for the XBMC Web Server HTTP API.
It provides a remote access to any XBMC running on the local network,
in a simple way (methods follow the ones from XBMC API).
Example:
irb(main):001:0> xbmc = XBMC::XBMC... | true |
7063fde13cea30447b99882d16e5835430b61263 | Ruby | pv97/Poker | /spec/tdd_spec.rb | UTF-8 | 1,421 | 3.375 | 3 | [] | no_license | require "tdd"
require "rspec"
describe "#uniq"do
it "correctly removes duplicates" do
expect([1,1,2,3].my_uniq).to eq([1,2,3])
end
it "doesn't modifty a non duplicate array" do
expect([1,2,3].my_uniq).to eq([1,2,3])
end
it "doesn't modifty a non duplicate array" do
expect([1,2,3].my_uniq).to eq... | true |
cd34f28889871c1132fc0b592bde80e0973a6a7b | Ruby | tpkg/client | /lib/tpkg/thirdparty/net-ssh-2.1.0/lib/net/ssh/transport/cipher_factory.rb | UTF-8 | 3,677 | 2.8125 | 3 | [
"MIT"
] | permissive | require 'openssl'
require 'net/ssh/transport/identity_cipher'
module Net; module SSH; module Transport
# Implements a factory of OpenSSL cipher algorithms.
class CipherFactory
# Maps the SSH name of a cipher to it's corresponding OpenSSL name
SSH_TO_OSSL = {
"3des-cbc" => "des-ede... | true |
ee86a1718efc277292ed68e37895a1c4ca2058d2 | Ruby | Andrewglass1/texter | /app/models/station_matcher.rb | UTF-8 | 419 | 3.171875 | 3 | [] | no_license | class StationMatcher
require 'amatch'
def initialize(input)
@input = input
end
def match
station = Station.all.detect{|station| fuzzy_match(station.name)}
station ||= nickname_match
end
def nickname_match
Station.all.detect {|station| station.nicknames.any?{|nn| fuzzy_match(nn)}}
end
... | true |
48e6a4347c188436c0975feba9cc8b5c474efd2c | Ruby | serioja90/fleck | /examples/actions.rb | UTF-8 | 1,875 | 2.75 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# frozen_string_literal: true
require 'fleck'
user = ENV['USER'] || 'guest'
pass = ENV['PASS'] || 'guest'
CONCURRENCY = (ENV['CONCURRENCY'] || 2).to_i
SAMPLES = (ENV['SAMPLES'] || 10).to_i
QUEUE = 'actions.example.queue'
Fleck.configure do |config|
con... | true |
ea79cad08756f2708ed882ea0992a3f60182e6f7 | Ruby | buntine/bolverk | /lib/operations/or.rb | UTF-8 | 853 | 2.875 | 3 | [] | no_license | class Bolverk::Operations::Or < Bolverk::Operations::Base
map_to "0111"
parameter_layout [ [:register_a, 4], [:register_b, 4], [:destination, 4] ]
# Performs an OR operation on register_a and register_b and stores the result in "destination".
#
# Example:
# 725A => 0111001001011010=> OR the contents of... | true |
566b22a73b9655c3743609495961ea0fe0fe3c7a | Ruby | Michael-Gr/CodeKatas | /Can_santa_save_christmas.rb | UTF-8 | 1,182 | 3.953125 | 4 | [] | no_license | #################
# Link to kata: #
#################
#
# https://www.codewars.com/kata/5857e8bb9948644aa1000246
#
################
# Description: #
################
#
# Oh no! Santa's little elves are sick this year. He has to distribute the presents on his own.
# But he has only 24 hours left. Can he do it?
# Your jo... | true |
da24a6ba8a0f59d62d1940588c19e9fe82783f29 | Ruby | Lorenzo892/Ironhack-bootcamp | /Week1/Day3-Ironhack/gameofrooms.rb | UTF-8 | 2,057 | 4.15625 | 4 | [] | no_license |
class Room
def initialize(name, welcome)
@name = name
@welcome = welcome
end
def name
@name
end
def enter_room
puts @welcome
end
end
class Game_array
def initialize(x,y)
@x = x
@y = y
end
def position (game_array)
puts "Game is ON, try to get to the treasure as fas... | true |
42ab442b466f39e164e5e32be5d64b6946195730 | Ruby | leslieyi/postwork-data-structures-and-algorithms | /03-week-3--additional-practice/00-bonus-1--balancing-parenetheses/solutions/balancing_parentheses.rb | UTF-8 | 2,307 | 4.21875 | 4 | [] | no_license | def balancing_parentheses(string)
missing = 0
openings = 0
string.chars.each do |char|
if char == '('
openings += 1
next
end
if openings > 0
openings -= 1
else
missing += 1
end
end
missing + openings
end
if __FILE__ == $PROGRAM_NAME
puts "Expecting: 0"
puts... | true |
03cb1e9cf8ccd72ff3c51227477cd89e7b6d78c1 | Ruby | telwell/project_tdd_minesweeper | /lib/square.rb | UTF-8 | 1,135 | 3.703125 | 4 | [] | no_license | class Square
attr_accessor :mine, :flag, :displayed, :surrounding_mines
attr_reader :coords, :adjacent_squares
def initialize(coords, size)
# I know there are a bunch of instance
# variables here but I need most of them
# for this Square class.
@coords = coords
@size = size
@mine = false
@flag = fals... | true |
39a41e17504dddf9107aadc13e835bc7a9192684 | Ruby | misoton665/Calculator | /main.rb | UTF-8 | 200 | 2.53125 | 3 | [] | no_license | require 'treetop'
require './calculator_node_classes'
Treetop.load 'calculator'
loop {
print "$> "
input = STDIN.gets
tree = CalculatorParser.new.parse(input)
puts "=> #{tree.eval.to_s}"
}
| true |
2a497ad2922d0ca74f83f58b9af46a81c5f3e015 | Ruby | vanrails/Learn-To-Program | /chapter05/fullnamegreeting.rb | UTF-8 | 291 | 3.21875 | 3 | [] | no_license | # 5.6 page 25
# Full name greeting
puts 'Hello, what\'s first name?'
firstName = gets.chomp
puts 'And your middle name?'
middleName = gets.chomp
puts 'Finally your last name?'
lastName = gets.chomp
puts 'Pleased to meet you ' + firstName
+ middleName
+ lastName
| true |
3d0caee1c3ec67a8186f8cd7054aa98ebcaf0123 | Ruby | mattsan/withings | /lib/withings.rb | UTF-8 | 702 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'pathname'
require 'csv'
require 'ostruct'
require 'time'
require 'withings/version'
require 'withings/activity'
require 'withings/blood_pressure'
require 'withings/height'
require 'withings/sleep'
require 'withings/weight'
class Withings
MODELS = {
activity: Withings::Activity,
blood_pressure: With... | true |
2504127cf54c01addccc6fa3e0a1c1f468ad8db1 | Ruby | square/shuttle | /app/models/blob.rb | UTF-8 | 4,198 | 2.734375 | 3 | [
"Apache-2.0"
] | permissive | # Copyright 2014 Square Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed ... | true |
3069db69234abe55d9749ac1f505f162771e11a9 | Ruby | samwich/advent_of_code_2020 | /24/test_day24.rb | UTF-8 | 1,226 | 3 | 3 | [] | no_license | require 'test/unit'
require 'strscan'
require_relative 'floor'
class TestDay24 < Test::Unit::TestCase
def setup
@floor = Floor.new('./test_input')
end
def test_file_load
expected = [:se, :se, :nw, :ne, :ne, :ne, :w, :se, :e, :sw, :w, :sw, :sw, :w, :ne, :ne, :w, :se, :w, :sw]
assert_equal(expected, @... | true |
0f4302afc621ffdbae44dc663986bdff3fe679a1 | Ruby | gmccreight/mdpg | /spec/mdpg/services/page_links_spec.rb | UTF-8 | 2,697 | 2.53125 | 3 | [] | no_license | # frozen_string_literal: true
require_relative '../../spec_helper'
describe PageLinks do
before do
$data_store = memory_datastore
@user = create_user
@zebra_page = Page.create name: 'zebra-training',
text: 'page 1'
@alaska_page = Page.create name: 'alaska-crab',
text: "link to [[mdpgpage... | true |
c08c310b0818c097b9d5d381a6cefd2330055462 | Ruby | marynavoitenko/vinyls-collection | /db/seeds.rb | UTF-8 | 1,397 | 2.71875 | 3 | [] | no_license | # frozen_string_literal: true
require 'csv'
csv_text = File.read(Rails.root.join('lib', 'seeds', 'vinyls_collection.csv'))
csv = CSV.parse(csv_text, headers: true, encoding: 'ISO-8859-1')
csv.each do |row|
# get all values of artists_tracks columns for the row
artists_tracks = row.find_all do |i|
i[0] == 'art... | true |
b1b90f43bfdff034241e27c28b025fd8b1655ea6 | Ruby | eternal44/hacker_rank | /warm_up/library_fines.rb | UTF-8 | 504 | 3.3125 | 3 | [] | no_license | def fee(actual, expected)
if actual[2] > expected[2]
fine = 10_000
elsif actual[1] > expected[1] && actual[2] >= expected[2]
fine = (actual[1] - expected[1]) * 500
elsif actual[0] > expected[0] && actual[1] >= expected[1] && actual[2] >= expected[2]
fine = (actual[0] - expected[0]) * 15
else
... | true |
18de04425cbf1c69c2bb6d1e8fbfae636ed989ce | Ruby | funeace/Project-Euler | /Problem005_pattern1.rb | UTF-8 | 797 | 3.5 | 4 | [] | no_license | # 2520 は 1 から 10 の数字の全ての整数で割り切れる数字であり, そのような数字の中では最小の値である.
# では, 1 から 20 までの整数全てで割り切れる数字の中で最小の正の数はいくらになるか.
# 20の倍数であることは確定しているから 割り算の結果が0になればいい next = i * 20
# a % i == 0
# 動いたが重すぎ(答え232792560 もうちょっと小さいと思って回して後悔した)
# # 初期値を20に設定
number = 20
answer = 0
until number == 0
(1..20).each do |i|
# loopの数字で割り切れるか確認
... | true |
3907daa4e2bf4c4f906afb3aa3b0aa4713bcfdaf | Ruby | christian-marie/ns_connector | /lib/ns_connector/attaching.rb | UTF-8 | 1,249 | 2.6875 | 3 | [
"MIT"
] | permissive | # Provide attach! and detach! methods
module NSConnector::Attaching
# Attach any number of ids to klass
# Arguments::
# klass:: target class to attach to, i.e. Contact
# attachee_id:: internal id of the record to make the attach(s) to
# ids:: array of target ids
# attributes:: optional attributes for the... | true |
2ff10e9daae93c821c91edd37fb5d729225c5060 | Ruby | quentinbrasseur/rails-yelp-mvp | /db/seeds.rb | UTF-8 | 951 | 2.609375 | 3 | [] | no_license | puts 'Cleaning database...'
Restaurant.destroy_all
puts 'Creating restaurants...'
restaurants_attributes = [
{
name: "Epicure au Bristol",
address: "112 rue du Fg St-Honoré 75008 Paris",
phone_number: "01 75 16 78 98",
category: "french"
},
{
name: "The Waffle Factory... | true |
ccaa786ee845cfbb5108a5ef75f21cb9d3238ba9 | Ruby | tw-oocamp-201512/homework | /homework1/zhou xing/taximeter/lib/checker.rb | UTF-8 | 695 | 3.3125 | 3 | [] | no_license | require 'colorize'
class Checker
class << self
def check(theme, error="", &block)
begin
block.call
rescue InputError => e
puts ("\n")
puts ('-' * 60).colorize(:red)
puts error
puts ('-' * 60).colorize(:red)
exit
end
end
def check_input(in... | true |
569974912acde1387a79c69199fab9b5dc57fbb0 | Ruby | rafamorais/Curso-ruby | /app/hello-world.rb | UTF-8 | 278 | 3.109375 | 3 | [] | no_license | # puts "Hello World \n"
# print "Hello World" + "\n"
# printf("Hello World \n")
puts "What is your name:"
$name = STDIN.gets()
print "Hello World:" + $name + "from School of NET \n"
print "Hello " + "World\n"
$value = "Rafa"
# var - Local
# @var - Instance
# $var - Global | true |
8f93c406b11ae878ceb6a1714350ab5c9217354d | Ruby | kunishi/algebra-ruby2 | /sample/sample-set01.rb | UTF-8 | 272 | 3.078125 | 3 | [
"MIT"
] | permissive | require "algebra"
#intersection
p Set[0, 1, 2, 4] & Set[1, 3, 5] == Set[1]
p Set[0, 1, 2, 4] & Set[7, 3, 5] == Set.phi
#union
p Set[0, 1, 2, 4] | Set[1, 3, 5] == Set[0, 1, 2, 3, 4, 5]
#membership
p Set[1, 3, 2].has?(1)
#inclusion
p Set[3, 2, 1, 3] < Set[3, 1, 4, 2, 0]
| true |
b2461c3a4b5a015ec0a5510e63b4a9d328751163 | Ruby | frankmeszaros/ruby-gui | /lib/gui/selector.rb | UTF-8 | 1,655 | 2.90625 | 3 | [
"Apache-2.0"
] | permissive | # Copyright 2014 Noel Cower
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writ... | true |
96921933a45a85a94159560f69b4176f1c36c412 | Ruby | fenixchen/rubystudy | /operator.rb | UTF-8 | 565 | 3.15625 | 3 | [] | no_license | #!/usr/bin/ruby -w
a, b, c = 10, 20, 30
(1..10).each do |i|
printf "%d\t", i
end
puts
(1...10).each do |i|
printf "%d\t", i
end
puts
foo = 42
puts defined? foo # => "local-variable"
puts defined? $_ # => "local-variable"
puts defined? nil
puts defined? puts
puts defined? yield
MR_COUNT = 0 # 定义在主 O... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.