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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
8f28b5961ce48850f0558f71dc40304f0f2bc526 | Ruby | meishijie/ruby-geci | /test多线程.rb | UTF-8 | 1,569 | 2.5625 | 3 | [] | no_license | #-*- code:utf-8 -*-
require 'nokogiri'
require 'open-uri'
require 'rest-client'
require 'sqlite3'
require 'json'
require 'timeout'
require 'enumerator'
@nowarray = []
@alllist = []
@database = 1
$queue = []
@data={}
def insert(i)
# 转成字符串存入数据库
@data["_lrcname"] = '1'
@data["_album"] = '1'
... | true |
cdbabc4e87c3fb9784672c41d7800ea318190c93 | Ruby | stavfx/misy-backend | /lib/menuItems.rb | UTF-8 | 1,840 | 3 | 3 | [] | no_license | require 'mongo_mapper'
require File.join(File.dirname(__FILE__), './utils')
# Class that represents a menu item.
# Each item has a Menu Category which defines the category within the menu:
# Main Course, Desserts etc...
class MenuItem
include MongoMapper::EmbeddedDocument
key :name, String
key :des... | true |
a937e28930443040247ec519da4af3a8b7b9be58 | Ruby | akuhn/euler | /problem_64.rb | UTF-8 | 1,687 | 3.328125 | 3 | [] | no_license | require_relative 'euler'
class Integer
def sqrt_as_continued_fraction
arr = []
state = []
sqrt = Math.sqrt(self)
# (i*sqrt+r)/(j*sqrt+q)
i,r = 1,0
j,q = 0,1
loop do
raise if not i == 1
raise if not j == 0
return [arr,[]] if q == 0
arr << ((i*sqrt+r)/q... | true |
cc03ad26da9be9095f67d440108a7bdecbb1a6c2 | Ruby | jmaddenco/methods2 | /methods2.rb | UTF-8 | 1,104 | 3.34375 | 3 | [] | no_license | module Methods2
def elevenish(num)
quotient, modulus = num.divmod(11)
if modulus == 0 || modulus == 1
true
else
false
end
end
def ice_cream_party(ice_cream, candy)
if ice_cream < 5 || candy < 5
0
elsif ice_cream >= candy*2 || candy >= ice_cream*2
2
elsif ice_cream >= 5 && candy >= 5
... | true |
4edfc4783daf5066f61208ff447c682c1126460d | Ruby | drosenfeld87/ruby_fundamentals2 | /exercise4.rb | UTF-8 | 113 | 3.265625 | 3 | [] | no_license | def length (word)
if (word.length < 8)
return false
else
return true
end
end
puts length ("this")
| true |
6f46969a1e7076ca252ecbbbe27c5b582fa734d6 | Ruby | thanos982/rbnd-udacitask-part2 | /lib/udacilist.rb | UTF-8 | 2,171 | 3.078125 | 3 | [] | no_license | class UdaciList
include CommandLineReporter
attr_reader :title, :items
@@item_class_names = {"todo" => "TodoItem", "event" => "EventItem", "link" => "LinkItem"}
def initialize(options={})
@title = options.key?(:title) ? options[:title] : "Untitled List"
@items = []
end
def add(type, description, op... | true |
d712babd2d5ab4d7dd43f3b654ec1cb95f07539a | Ruby | nikokozak/rc-badges-rewrite | /spec/buster_spec.rb | UTF-8 | 5,735 | 2.609375 | 3 | [] | no_license | require_relative '../framework/buster.rb'
require 'fileutils'
describe Buster do
describe "initialize" do
it "should throw on wrong input" do
expect { Buster.new("abc") }.to raise_error(Exception)
end
it "should create a new instance with a list of files" do
files = ["hello.css", "/test/ano... | true |
2be99e6cd18b65fc14e1ff64467122f8c9e4eab5 | Ruby | ccropper/ls-rb101 | /lesson_5_advanced_ruby_collections/lesson_5_pp8.rb | UTF-8 | 459 | 4.3125 | 4 | [] | no_license | # Using the each method, write some code to output all of the vowels from the strings.
hsh = {first: ['the', 'quick'], second: ['brown', 'fox'], third: ['jumped'], fourth: ['over', 'the', 'lazy', 'dog']}
vowels = %w(a e i o u) # can also be vowels = 'aeiou'
hsh.each do |_ , words| # we don't care about the keys, so ... | true |
efbc47ccb97fa8424c9c7059f235962c76e915ff | Ruby | shahriarb/bitmap_editor | /spec/initialize_command_spec.rb | UTF-8 | 2,743 | 3.125 | 3 | [] | no_license | require 'initialize_command'
describe InitializeCommand do
describe '#initilize' do
context 'With wrong initial values' do
it 'should raise ArgumentError with no initial argument' do
expect {InitializeCommand.new}.to raise_error(ArgumentError)
end
it 'should raise ArgumentError with one initial argume... | true |
03cb230f993c832360253a0fb5cb56befd59b2e8 | Ruby | ConorHolland/apcsp-lq | /list_quiz.rb | UTF-8 | 729 | 3.9375 | 4 | [] | no_license | def three_even(list)
(list.size - 1).times do |n|
if list[n + 1] % 2 == 0 && list[n] % 2 == 0 && list[n + 2] % 2 == 0
return true
end
end
return false
end
# puts three_even([2, 1, 3, 5]) #false
# puts three_even([2, 4, 12, 5]) #true
# puts three_ev... | true |
f58f50c78c018fbd3104e0f4d2cc63a683d8a365 | Ruby | masukomi/mobtvse | /vendor/bundle/gems/activesupport-3.2.0/lib/active_support/tagged_logging.rb | UTF-8 | 2,081 | 2.75 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | require 'active_support/core_ext/object/blank'
require 'active_support/deprecation'
require 'logger'
module ActiveSupport
# Wraps any standard Logger class to provide tagging capabilities. Examples:
#
# Logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
# Logger.tagged("BCX") { Logger.info "Stuf... | true |
9b10db75f3e8ad38157c84356703cfe2543c6247 | Ruby | potatoHVAC/project_euler | /046.rb | UTF-8 | 948 | 3.671875 | 4 | [] | no_license |
def is_prime?(num)
(2..num**0.5).each { |i| return false if num % i == 0 }
true
end
def populate_primes(top)
(2..top).select { |i| i if is_prime?(i) }
end
def arr_to_hash(arr)
arr.map { |i| [i, true] }.to_h
end
def is_composit?(num, prime_lst)
return false if num % 2 == 0
second = false
prime_lst.each... | true |
83cfe3643be8ae76334dd9e8ac6c220e28e6075d | Ruby | tomnatt/first-gem | /bin/first_gem | UTF-8 | 145 | 3.1875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'first_gem'
if ARGV[0] == "hi"
FirstGem.hi
elsif ARGV[0] == "bye"
FirstGem.bye
else
puts "usage: hi bye"
end
| true |
5e6799630a7adf38820264f0574dd64325bf4a32 | Ruby | amirrf/aerospike-redis-ruby | /spec/aerospike-redis/strings_spec.rb | UTF-8 | 12,036 | 2.640625 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | # Copyright (c) 2014 Amir Rahimi Farahani
#
# All tests are based on tests provided in Redis Ruby Client (https://github.com/redis/redis-rb)
# with the following license:
# ######################################################################
# Copyright (c) 2009 Ezra Zygmuntowicz
# Permission is hereby granted... | true |
646caa3b17194882098060f605568e948a4d123b | Ruby | chippy65/Blackjack_WIP | /app/models/cardtable.rb | UTF-8 | 6,540 | 2.734375 | 3 | [] | no_license | class Cardtable < ActiveRecord::Base
belongs_to :game
belongs_to :player_record, :class_name => "User", :foreign_key => 'player_id'
belongs_to :dealer_record, :class_name => "User", :foreign_key => 'dealer_id'
serialize :player
serialize :dealer
serialize :deck
def startup(thisplayer)
# Setup its ... | true |
c1d5f8f504db7eec4bb0ebe5e7f45bb19f0969a7 | Ruby | peterjmorgan/rbkb | /bin/experimental/fmagic.rb | UTF-8 | 1,378 | 2.671875 | 3 | [
"MIT"
] | permissive | #----------------------------------------------------------------------
# Optional extensions based on dependencies below:
#----------------------------------------------------------------------
begin
# magick signatures: attempt to identify a buffer with magic(5)
# using the same library as file(1)
#
# Extend... | true |
39e9572842427f725db8063ea8d828dc688c770e | Ruby | KompeNnet/Courses | /2nd_capybara/someMail.rb | UTF-8 | 2,284 | 2.515625 | 3 | [] | no_license | require 'capybara/dsl'
require 'selenium-webdriver'
require 'open-uri'
require 'securerandom'
class DemoCapybara
include Capybara::DSL
Capybara.default_driver = :selenium
Capybara.register_driver :selenium do |app|
options = {
:js_errors => false,
}
Capybara::Selenium::Driver.new(app, :browser... | true |
b0646a30bcde62879d844bf367a57361f0dcfd18 | Ruby | generall/SkNN-ruby | /tests/reader_test.rb | UTF-8 | 2,062 | 2.703125 | 3 | [] | no_license | require 'test/unit'
require_relative '../reader.rb'
require_relative '../cluster_seq.rb'
require_relative '../loader.rb'
require_relative '../model.rb'
require 'pry'
CSV_TEST_FILE = '../data/test.csv'
class ReaderTest < Test::Unit::TestCase
def setup
@reader = CSVReader.new(CSV_TEST_FILE, MapCSVSchema.new( { :... | true |
a40f11183f2e500b86ee3e0bc8d014c1e8c2b1a0 | Ruby | rafie/classico1-bento | /Classico/Bento/lib/Test.rb | UTF-8 | 1,355 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'minitest'
module Bento
#----------------------------------------------------------------------------------------------
# The basic idea is to provide test-class-level before/after methods (in addition to test-method
# level setup/teardown methods).
class Test < Minitest::Test
@@objects = Hash.new
class... | true |
46ff43ce230a52a33e0f2f19a0ba244aca40f495 | Ruby | datajanitor/diaries | /small_arms_ammo_data/convert_to_csv.rb | UTF-8 | 903 | 3 | 3 | [] | no_license | require 'json'
require 'csv'
DATA_FILE = File.expand_path('../data-source/all.json', __FILE__)
CSV_FILE = File.expand_path('../data-munged/all.csv', __FILE__)
USA_EXPS_CSV_FILE = File.expand_path('../data-munged/usa-exports.csv', __FILE__)
USA_IMPS_CSV_FILE = File.expand_path('../data-munged/usa-imports.csv', __FILE... | true |
5d4ebe5b2c06efdf73dfc8a263939f8c9a466e29 | Ruby | pinge/rubyquiz.com | /rubyquiz/1_the_solitaire_cipher/solitaire.rb | UTF-8 | 4,166 | 3.359375 | 3 | [] | no_license | require File.dirname(__FILE__) + '/../base'
module Rubyquiz
module Solitaire
class Deck
def initialize
@deck = (1..52).to_a + ('A'..'B').to_a
end
def move_A
move_down('A')
end
def move_B
2.times{ move_down('B') }
end
def triple_cut
t... | true |
78f0c8aa24e2790c8213195252a40a82aa2adc24 | Ruby | JohnZBurnett/badges-and-schedules-prework | /conference_badges.rb | UTF-8 | 663 | 3.921875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def badge_maker(name)
"Hello, my name is " + name + "."
end
def batch_badge_creator(name_arr)
badge_arr = []
name_arr.each do |name|
badge_arr << badge_maker(name)
end
badge_arr
end
def assign_rooms(speaker_list)
room_list = []
speaker_list.each_with_index do |name, idx|
... | true |
8da7638559a6f36da3d449af7ef2bfb3f6d154d6 | Ruby | greenjoshua/RB101 | /small_problems/easy4/multiples.rb | UTF-8 | 212 | 3.359375 | 3 | [] | no_license | def multisum(num)
numbers = Array(1..num).keep_if { |number| number % 3 == 0 || number % 5 == 0 }
numbers.reduce(:+)
end
p multisum(3) == 3
p multisum(5) == 8
p multisum(10) == 33
p multisum(1000) == 234168
| true |
4dcf4cc5f0c2ddf615e95d2d651c44f5dbd3734e | Ruby | noctrl-capstone2017/geogem | /app/helpers/students_helper.rb | UTF-8 | 2,933 | 2.90625 | 3 | [] | no_license | module StudentsHelper
# return a ux/view string for the last session data of a student
# sessions - a list of sessions, presumably controller prepared
# student - the student
def ux_last_session_date( sessions, student)
this_session = sessions.where(session_student: student.id).last
if this_session &&... | true |
e2a4742a10ae183abe9db2b30e8398d79382e41a | Ruby | mje113/sideband | /test/test_sideband.rb | UTF-8 | 789 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'helper'
class TestSideband < Minitest::Test
def test_autoinitialization
assert Sideband.queue << -> { 'work' }
end
def test_has_queue
Sideband.initialize!
assert_kind_of Sideband::Queue, Sideband.queue
end
def test_can_access_queue_or_send_jobs
Sideband.initialize!
assert Side... | true |
9efd27a56b2ce42b9335e3f79661d88985642cd3 | Ruby | rash-pro/drowned | /game_states.rb | UTF-8 | 7,702 | 2.625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'rubygems' rescue nil
$LOAD_PATH.unshift File.join(File.expand_path(__FILE__), "..", "..", "lib")
require 'chingu'
require_relative 'fruit'
require_relative 'player'
require_relative 'obstruction'
include Gosu
include Chingu
class Intro < GameState
trait :timer
def setup... | true |
251d9d5c04a28b3e1b9d6518757720f6602af425 | Ruby | dansmiricky/run_rabbit_run | /lib/run_rabbit_run/loadbalancer/worker_stats.rb | UTF-8 | 346 | 2.625 | 3 | [
"MIT"
] | permissive | module RRR
module Loadbalancer
class WorkerStats
def initialize
@stats = Array.new(30, 0)
end
def push(number_of_messages)
@stats << number_of_messages
@stats = @stats[-30,30]
@stats
end
def average
@stats.inject(0) {|sum,x| sum + x }/30
... | true |
e8acaa4187b75417fd8db7742b72b952a23913ff | Ruby | Kimbeaux/Learn-Ruby-Ex-14 | /ex14.rb | UTF-8 | 661 | 3.90625 | 4 | [] | no_license | user = ARGV.first
prompt = 'Your Answer: '
puts "Hi #{user}, I'm the #{$0} script."
puts "I'd like to ask you a few questions."
puts "Do you like me #{user}?"
print prompt
likes = STDIN.gets.chomp()
puts "Where do you live #{user}?"
print prompt
lives = STDIN.gets.chomp()
puts "What kind of computer do you have?"
p... | true |
d1fc56bbcd0ce883e07534ebdeb8b63e0e65455a | Ruby | Wil-McC/war_or_peace | /test/game_test.rb | UTF-8 | 1,645 | 3.484375 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/deck'
require './lib/card'
require './lib/player'
require './lib/game'
class GameTest < Minitest::Test
def test_it_exists
game = Game.new('Frank', 'Joe')
assert_instance_of Game, game
end
def test_it_reads_player_attributes
card1 = ... | true |
5cca84b651104f58aed985330401fc07a723985d | Ruby | hiroaki-iwase/to_array | /lib/to_array.rb | UTF-8 | 365 | 3.296875 | 3 | [
"MIT"
] | permissive | class String
def to_array
if self[0] != "[" || self[-1] != "]"
raise ArgumentError.new("invalid value for `str_to_array': '#{self}'")
end
begin
arr = self.chomp.gsub(/"|^\[|\]$/, '')
arr = arr.split(/,[\s]*/)
return arr
rescue
raise ArgumentError.new("invalid value for `... | true |
091135ea336d4c52b29d2e006f6378df3f88975a | Ruby | kisonecat/curriculum-vitae | /cv.rb | UTF-8 | 35,547 | 2.890625 | 3 | [] | no_license | # coding: utf-8
# I think in the professional activities you should put the steam
# factory thing. I also feel like you should be putting some mention
# of your supremacy at the MOOC, being number one on itunes, listed on
# blogs. I just dont believe you haven't gotten any awards since
# college. You didn't get any te... | true |
d85850d01aa19c2a1dbf0d2715b3c2091e820d95 | Ruby | Fukkatsuso/AtCoder | /JoinedContest/ABC134C.rb | UTF-8 | 217 | 3.203125 | 3 | [] | no_license | n = gets.chomp.to_i
a = []
n.times do
a << gets.chomp.to_i
end
b = a.sort.reverse # 降順
max = b[0]
(0..n-1).each do |i|
if a[i] != max
puts max
else
puts b[1]
end
end | true |
ed5f3ecefda1775bb2e639e088f6090a0f6cd747 | Ruby | dumbo-flatiron-labs/prime-ruby-prework | /prime.rb | UTF-8 | 207 | 3.25 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def prime?(number)
if number < 3
return false
end
divisors = Array(2..Math.sqrt(number).floor)
divisors.each do |divisor|
if number % divisor == 0
return false
end
end
true
end
| true |
4150ce2e18b15091d555a30b530927dd17eca54d | Ruby | chrismccord/ruby_enumerable_presentation | /slide6_examples.rb | UTF-8 | 493 | 3.53125 | 4 | [] | no_license | require './document'
# ==============================================================
# Examples
# ==============================================================
doc = Document.new("This is some document text for Dayton Ruby")
doc.each{|word| puts word }
doc.include? "Ruby"
# => true
doc.grep(/ruby/i)
# => ["Ruby"... | true |
2141166e7b7f95329d215bbdef6920c9e075502a | Ruby | cielavenir/procon | /codeeval/tyama_codeeval63.rb | UTF-8 | 132 | 2.6875 | 3 | [
"0BSD"
] | permissive | #!/usr/bin/ruby
require 'prime'
a=Prime.each(10**5).to_a
while gets
b=$_.split(',').map(&:to_i)
p a.count{|e|b[0]<=e&&e<=b[1]}
end | true |
283c177c20b9edfa652c7772f4ecf603009d7385 | Ruby | aquileiagirotto/my-repository | /ruby/add-item-lista.rb | UTF-8 | 154 | 3.375 | 3 | [] | no_license | #!/usr/bin/ruby
lista = []
for x in 1..10
puts "digite o item para add na lista"
item = gets("> ")
lista << item
end
puts lista
puts "obrigado!"
| true |
91b85f40b2fe13f1d759c319476efc557e228161 | Ruby | shibani/minesweeper-refactor | /lib/minesweeper_2pl/end_game.rb | UTF-8 | 261 | 2.640625 | 3 | [
"MIT"
] | permissive | module Minesweeper
class EndGame
def run(game, cli, io)
result = game.check_win_or_loss
cli.print_board(game, io)
game_over_message = cli.build_game_over_message(result, io)
io[:output].display(game_over_message)
end
end
end | true |
5f918ab9b9fdb0f3c7eb718656a4ba160a723e13 | Ruby | JHutsell/deli-counter-ruby-apply-000 | /deli_counter.rb | UTF-8 | 791 | 3.859375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def line(deli_line)
if deli_line.empty?
line_order = "The line is currently empty."
else
line_order = "The line is currently: "
line_positions = deli_line.map.with_index {|customer, idx| "#{idx + 1}. #{customer}" }
line_string = line_positions.join(" ")
line_order ... | true |
b781f1c2f87ac026c5f399bc3ed56598d3152106 | Ruby | DrAmaze/appacademy | /W1D3/recursive.rb | UTF-8 | 5,672 | 3.515625 | 4 | [] | no_license |
def range(start, last)
return [] if last < start
return [start] if start == last-1
[start] + range(start+1, last)
end
def iter_range(start, last)
i = start
arr = []
while i < last
arr << i
i += 1
end
arr
end
def sum(arr)
return 0 if arr.length == 0
return arr.last if arr.length == 1
a... | true |
1ad8520b5f37af02ebad70cae28568d3a3ae533f | Ruby | zpalmquist/flashcards | /test/round_test.rb | UTF-8 | 3,156 | 3.1875 | 3 | [] | no_license | require_relative 'test_helper'
require_relative '../lib/round'
require_relative '../lib/card'
require_relative '../lib/deck'
require_relative '../lib/guess'
class RoundTest < Minitest::Test
def test_that_round_can_take_a_deck
card_1 = Card.new("What is the capital of Alaska?", "Juneau")
card_2 = Card.new(... | true |
3b5135c122191da971803d2995545ab6bd4d51b3 | Ruby | tomiyoshi0602/furima-34263 | /spec/models/user_spec.rb | UTF-8 | 5,504 | 2.578125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
describe 'ユーザー新規登録' do
before do
@user = FactoryBot.build(:user)
end
context '内容に問題がない場合' do
it '全ての値が正しく入力されていれば保存できること' do
expect(@user).to be_valid
end
end
context '内容に問題がある場合' do
it 'nicknameが空だと保存でき... | true |
a2de1bbec8e2ae57725923253097e792117feef8 | Ruby | dtan4/chartroom | /lib/chartroom/image.rb | UTF-8 | 1,957 | 2.703125 | 3 | [
"MIT"
] | permissive | module Chartroom
class Image
class << self
def generate_diagram(images)
images_description = []
images.select { |image| image.tagged? }.each do |image|
current_image = image
parent_images = ["image_#{current_image.id}"]
loop do
images_description <... | true |
a55cd2382bbc54bb7af725e2b0ac69590a8c98d2 | Ruby | M45t3rJ4ck/Ruby | /PyStudent - Copy/NameWhile.rb | UTF-8 | 341 | 3.625 | 4 | [] | no_license | # Defining containers:
names = []
name = "hyper"
nameCount = 0
userName = ""
# Collecting user input:
while userName != name
print ("Please enter a name: ")
userName = gets.chomp.to_s
names.append(userName)
nameCount += 1
if userName == name
puts (nameCount)
elsif nameCount == 10
... | true |
bf284d9eeed82e79370a7b1d7f06d863a8a4d489 | Ruby | lyntco/wdi_melb_homework | /gumballs/joshua_richardson/homework:quiz/roman_new_convert/romans.rb | UTF-8 | 1,895 | 3.875 | 4 | [] | no_license | def less_than_5(number, total_i)
number.times { |n| total_i << "I" }
total_i.join("")
end
def less_than_50(number, total_i)
number.times { |n| total_i << "X" }
total_i.join("")
end
def convert(number)
total_i = []
if number >= 1 && number < 5
less_than_5(number, total_i)
elsif number >= 5 && number... | true |
224c4a3b2b4bfad3d891dca4aaf5bd612bd5ccd2 | Ruby | tyrbo/sales_engine_davis_dennis | /test/merchant_repository_test.rb | UTF-8 | 1,098 | 2.6875 | 3 | [] | no_license | require './test/test_helper'
require_relative '../lib/merchant_repository'
require_relative '../lib/sales_engine'
class MerchantRepositoryTest < Minitest::Test
def setup
engine = SalesEngine.new('test/fixtures')
engine.startup
@repo ||= MerchantRepository.new(engine, 'test/fixtures')
end
def test_it... | true |
13d96cd173ab356fd4bd018fa5e384ab3251e63f | Ruby | acochenour/xml2mongo | /xml2mongo.rb | UTF-8 | 356 | 2.53125 | 3 | [] | no_license | # bare bones arbitrary XML file to MongoDB
require 'crack'
require 'open-uri'
require 'mongo'
# Mongo connection
conn = Mongo::Connection.new("my_mongo_server", 27017)
db = conn.db('my_db')
col = db.collection('my_collection')
# Open and parse XML file
data = open("/path/to/file").read
data = Crack::XML.parse(dat... | true |
a5d375f1d2d1feda6f04f8e0201ecc1c1ab4e14e | Ruby | lacresni/101_programming_foundations | /small_programs/easy_3/squaring_argument.rb | UTF-8 | 523 | 4.625 | 5 | [] | no_license | # Using the multiply method from the "Multiplying Two Numbers" problem,
# write a method that computes the square of its argument
# (the square is the result of multiplying a number by itself).
def multiply(a, b)
a * b
end
def square(n)
multiply(n, n)
end
def power_to_n(x, exponent)
return 1 if exponent == 0
... | true |
eaa876e48ffe93a6b494e58a8953669cb87de894 | Ruby | uchihara/word-finder | /lib/word_finder/dict.rb | UTF-8 | 198 | 2.953125 | 3 | [] | no_license | require 'set'
class Dict < Set
def initialize length
File.open("data/words-#{length}.txt") do |f|
super f.read.split(/\n/)
end
end
def exists? word
include? word
end
end
| true |
818367fc0e9aefa61bfc5a29ec6f157a011551a3 | Ruby | cmpt376edits/radiodns-uk | /bin/convert-txparams.rb | UTF-8 | 2,631 | 2.8125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'bundler/setup'
Bundler.require(:default)
class String
def titleize_if_caps
if self =~ /^[A-Z\W]+$/
self.titleize
else
self
end
end
end
def clean_column_names(sheet, header_column=1)
sheet.row(header_column).map do |col|
col.to_s.strip.downcase.gsub(/\W+... | true |
125d97f78a0357857f631f8bb9559744f5c15c8a | Ruby | emritcey/data-structures | /linked_list/node_two.rb | UTF-8 | 235 | 2.859375 | 3 | [
"MIT"
] | permissive | class Node
attr_accessor :element
attr_reader:next
def initialize(element)
@element = element
@next = nil
end
def insert_after(other_node)
@next = other_node
end
def remove_after
@next = nil
end
end
| true |
968e33eeb5bad2ec62626b49222707b4917760c9 | Ruby | tuanlv1206/algorithm-code | /maximize_number_of_0s_by_flipping_a_subarray/maximize_number.rb | UTF-8 | 954 | 3.546875 | 4 | [] | no_license | def maximize_number(arr)
n = arr.length
original_zero_count = 0
max_diff = 0
for i in (0..n-1)
original_zero_count += 1 if arr[i] == 0
count_1 = 0
count_0 = 0
for j in (i..n-1)
(arr[j] == 1) ? (count_1 += 1) : (count_0 += 1)
if max_diff < count_1 - count_0
max_diff = count_1... | true |
3b550c63d4306b41231c45f15b8767cedb8248b0 | Ruby | dalspok/exercises | /small_problems/easy_4/7.rb | UTF-8 | 1,227 | 4.0625 | 4 | [] | no_license | =begin
input: string
output: integer
rules: no validation, no signs, just coversion
algorithm:
- traversign using pointer
- iterating using each
- transforming + join
- lookup x ord
=end
# def string_to_integer(str) #pointer
# pointer = 0
# final_int = 0
# while pointer < str.size
# final_int *= 1... | true |
f551d54e45db58f730aa9ff8eeffdf62cfdc7fc5 | Ruby | mcollie007/gitstashcleaner | /gitstashcleaner.rb | UTF-8 | 794 | 3.390625 | 3 | [] | no_license | def list_stash
system("git stash list")
end
def drop_stash(num)
system("git stash drop stash@{#{num}}")
end
def clean_stash(a, b)
(a..b).reverse_each do |n|
drop_stash(n)
end
end
def start
puts "Listing your git stash."
puts "====================================================================="
li... | true |
358f1963dd7f52a9a36ffe71ed5c9c6ac644a25a | Ruby | tofugear/tgios | /lib/tgios/custom_method.rb | UTF-8 | 843 | 2.703125 | 3 | [
"BSD-2-Clause"
] | permissive | module Tgios
module CustomMethod
def self.included(base)
base.class_eval do
extend ClassMethods
end
end
def on(event_name, &block)
@events[event_name]=block.weak!
end
def off(*event_names)
event_names.each {|event_name| @events.delete(event_name) }
end
m... | true |
96222836941ba1fb6db79a7b772bfd319e6b10db | Ruby | hideo-srai/asia-insight-news | /app/services/new_subscribers_email_notifier.rb | UTF-8 | 869 | 2.71875 | 3 | [] | no_license | require 'csv'
class NewSubscribersEmailNotifier
def initialize(date_from=1.day.ago)
@date_from = date_from
end
def notify
users = User.where('created_at > ?', @date_from)
if users.count > 0
csv_content = prepare_csv(users)
ApplicationMailer.daily_new_subscribers_list(csv_content).deliv... | true |
30b7c713f65b435245a472623797bd34e01e20ed | Ruby | bishiboosh/static-tweets | /static_tweets.rb | UTF-8 | 4,549 | 2.640625 | 3 | [] | no_license | require 'twitter'
require 'open-uri'
require 'erb'
require 'date'
require 'storify'
require 'dotenv'
Dotenv.load
SEARCH_DEFAULTS = { count: 100 }
TIMELINE_DEFAULTS = { count: 200 }
FAVORITES_DEFAULTS = { count: 100 }
# handles tasks required to write a static tweets document
module StaticTweets
def self.download_f... | true |
164b8bd5fbebda553d57a869c0d532143c3e6f73 | Ruby | wcmatthews/COMP3220 | /Assignment1/TinyTest.rb | UTF-8 | 767 | 3.328125 | 3 | [] | no_license | load "TinyToken.rb"
load "TinyScanner.rb"
# Test for Token Class
#EOF token
tok = Token.new(Token::EOF, "eof")
puts "Token type: #{tok.type}"
puts "Token text: #{tok.text}"
#LPAREN token
tok = Token.new(Token::LPAREN, "(")
puts "Token type: #{tok.type}"
puts "Token text: #{tok.text}"
#RPAREN token
tok = Token.new(T... | true |
5acf96f872c3b9d7477bc180df53cf45ac444a31 | Ruby | mromphf/rails-blackjack | /spec/card_spec.rb | UTF-8 | 3,823 | 3.5625 | 4 | [
"MIT"
] | permissive | require_relative "../lib/card.rb"
describe Card do
let(:card) { Card.new(2, :hearts) }
describe "constructor" do
it "takes in a suit and a value" do
expect(card).to be_a Card
end
it "will throw an exception if given a value greater than thirteen" do
expect { Card.new(14, :diamonds) }.to r... | true |
4479a7eef9a08e5885dfe3056d225fd093610152 | Ruby | nysol/doc | /olddoc/mcmd/jp/examples/field_io.rb | UTF-8 | 1,339 | 2.953125 | 3 | [] | no_license | #!/usr/bin/env ruby
# coding: utf-8
require "./mkTex.rb"
File.open("dat1.csv","w"){|fpw| fpw.write(
<<'EOF'
ブランド,数量
A,10
B,20
C,30
D,40
EOF
)}
############## 例1
title="基本例"
comment=<<'EOF'
「数量:売上数量」の指定により、項目名が「数量」から「売上数量」に変換されて出力される。
EOF
scp=<<'EOF'
more dat1.csv
mcut f=ブランド,数量:売上数量 i=dat1.csv o=rsl1.csv
more rsl1.cs... | true |
639b1ba54ce032c1f6b6e6e7dbd17027dc74b94e | Ruby | omise/omise-ruby | /test/omise/test_customer.rb | UTF-8 | 2,105 | 2.578125 | 3 | [
"MIT"
] | permissive | require "support"
class TestCustomer < Omise::Test
setup do
@customer = Omise::Customer.retrieve("cust_test_4yq6txdpfadhbaqnwp3")
end
def test_that_we_can_create_a_customer
customer = Omise::Customer.create
assert_instance_of Omise::Customer, customer
assert_equal "cust_test_4yq6txdpfadhbaqnwp3... | true |
52dd2f1ed085e8090dfe33da1982f037d822a155 | Ruby | i-norden/project_euler | /ruby/prob23.rb | UTF-8 | 1,820 | 4 | 4 | [] | no_license | =begin
Non-abundant sums
Problem 23
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 prope... | true |
d4660ed8a9cd1eb2e29d4385f5380ad23f3bc6dd | Ruby | soroz30/Launch | /101/lesson_2/rpsls.rb | UTF-8 | 3,205 | 3.78125 | 4 | [] | no_license | CHOICES_LIST = { "r" => "rock",
"p" => "paper",
"sc" => "scissors",
"l" => "lizard",
"sp" => "spock" }
WINNING_COMBINATIONS = {
'rock' => %w(scissors lizard),
'paper' => %w(rock spock),
'scissors' => %w(paper lizard),
'lizard' => %w(spock paper... | true |
3c63f757325a864a3646058547498316cfdaa002 | Ruby | Aalto-LeTech/stops | /script/noppa.rb | UTF-8 | 2,924 | 2.8125 | 3 | [] | no_license | # https://wiki.aalto.fi/pages/viewpage.action?pageId=71895449
require 'date.rb'
require 'open-uri'
require 'json'
class Spider
def initialize
@api_url = 'http://noppa-api-dev.aalto.fi/api/v1/'
end
def get_api_url(path, params = {})
params_string = ''
params.each do |key, value|
params_string... | true |
0d5ef867ef16a39607068af19eed020e8f507393 | Ruby | lekiert/quickstep-api | /test/models/exercise_test.rb | UTF-8 | 1,244 | 2.609375 | 3 | [] | no_license | require 'test_helper'
class ExerciseTest < ActiveSupport::TestCase
def setup
@test = Test.create(name: "Test",
description: "test description",
code: "A")
@exercise = Exercise.new(name: "Test",
command: "test command",
... | true |
d8b7d4eaf561c3f86ab15d32d000e93f740034e8 | Ruby | vijayaprakash1407/watir_helper | /lib/watir_helper/link_helper.rb | UTF-8 | 872 | 2.765625 | 3 | [] | no_license | #******************************************************
#Link methods
#******************************************************
require '../lib/watir_helper/common_helpers'
module LinkHelper
#Click a link.
def click_link(browser_handle, property, property_value)
browser_handle.link(property.intern, /#{property_va... | true |
d36a0b922bd604b69143daeb2e1a3901a41f4e4a | Ruby | AlessandroMinali/quantum_ruby | /examples/backward_control_gate_examples.rb | UTF-8 | 1,196 | 3.109375 | 3 | [
"MIT"
] | permissive | require_relative '../lib/quantum_ruby'
# In classical computing a control bit only affects the target bit
# These can also be done with a quantum circuit
# Circuit:
# x ----- | C_NOT | ----- x
# y ----- | GATE | ----- y flipped
x = Qubit.new(0, 1) # the control bit, 1
y = Qubit.new(1, 0) # the target bit, 0
C_N... | true |
aebeabb4e823449fe6b6c1367eddc754bca0dada | Ruby | zenizh/resonance | /lib/resonance.rb | UTF-8 | 2,348 | 2.65625 | 3 | [
"MIT"
] | permissive | require 'inflexion'
module Resonance
class ArgumentError < StandardError; end
module ClassMethods
def resonate(source, target: nil, action: nil, foreign_key: {})
roles = [source, target, action]
roles.each do |role|
if role.nil?
raise Resonance::ArgumentError, 'Passed argument i... | true |
3b82e5cc5cb945db1303d5b1bec76d8158989cd7 | Ruby | rgeyer/right_support | /lib/right_support/stats/helpers.rb | UTF-8 | 22,673 | 3.109375 | 3 | [
"MIT"
] | permissive | # Copyright (c) 2009-2012 RightScale Inc
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,... | true |
c9b029300c86a6b33d36219b470f5a74fb892a9c | Ruby | MariahAcacia/assignment_polymorphism | /db/seeds.rb | UTF-8 | 1,501 | 2.796875 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
e8ab76f09bb5d7f5b39a537526dcd119a4d5e554 | Ruby | aarroz/androgee-ruby | /lib/log_parser.rb | UTF-8 | 1,109 | 2.71875 | 3 | [
"MIT"
] | permissive | # Yes, linter
class LogParser
attr_reader :players
def initialize(games)
@players = games
end
def parse
@players.each do |key|
logs = get_logs(key.first())
logs.each_line do |log_line|
match = game_switch(key.first(), log_line)
@players[key.first()].push(match) if match.nil?... | true |
e3889a9c2cf83244d23b19a2738ab67afedfdc25 | Ruby | isabella232/anony | /lib/anony/field_level_strategies.rb | UTF-8 | 5,233 | 3.078125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require "securerandom"
module Anony
# This class is a singleton, containing all of the known strategies that Anony can use
# to anonymise individual fields in your models.
module FieldLevelStrategies
# Registers a new Anony strategy (or overwrites an existing strategy) of a giv... | true |
c9cec390f256e3c20ef8a0bab5d38e13d6a6f461 | Ruby | zjwhitehead/iterable-api-client | /lib/iterable/metadata_table.rb | UTF-8 | 2,263 | 2.75 | 3 | [
"MIT"
] | permissive | module Iterable
##
#
# Interact with /metadata/{table} API endpoints
#
# @example Creating metadata table endpoint object
# # With default config
# templates = Iterable::MetadataTable.new "table-name"
# templates.get
#
# # With custom config
# conf = Iterable::Config.new(token: 'new-toke... | true |
4e421bf1c38577f093fec8d5f8f6bead1563526f | Ruby | dskuang/developer-exercise | /exercise.rb | UTF-8 | 1,692 | 4.4375 | 4 | [] | no_license | require 'byebug'
class Exercise
# Assume that "str" is a sequence of words separated by spaces.
# Return a string in which every word in "str" that exceeds 4 characters is replaced with "marklar".
# If the word being replaced has a capital first letter, it should instead be replaced with "Marklar".
def self.... | true |
b35235708baf24f933e30f753dd48295789350be | Ruby | mikeblatter/automation_object | /lib/automation_object/driver/appium_adapter/element.rb | UTF-8 | 1,719 | 2.65625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative '../common_selenium/element'
module AutomationObject
module Driver
module AppiumAdapter
# Element proxy for Appium
# Conform Appium element interface to what's expected of the Driver Port
class Element < AutomationObject::Proxy::Proxy
incl... | true |
3bb13fa125a1f9f5e55212965e2cc7499c7f278f | Ruby | 09a-Abukar/RUBY-1 | /Recipe Task/RecipeCode.rb | UTF-8 | 172 | 2.703125 | 3 | [] | no_license | puts ("Ingredient calculator for Pasta Bake")
print("How many people are you serving: ")
NumberOfPeople = gets.chomp
Ingredient_file = File.open("Recipe Task - Sheet1.csv") | true |
1db361ba472371f9732836b62aa178ebee0b60d5 | Ruby | powersjcb/notes | /w1d2/rps.rb | UTF-8 | 819 | 4.21875 | 4 | [] | no_license | class RPS
attr_reader :computer_hand
HANDS = [:rock, :paper, :scissors]
def initialize
@computer_hand = HANDS.shuffle[0]
end
def valid?(string)
HANDS.include?(string)
end
def determine_winner(hand, computer_hand)
if (hand == :paper && computer_hand == :rock) ||
(hand == :scis... | true |
e679153ca992cb3bceac8ec449686d12bf12a331 | Ruby | rogueminx/anagrams | /lib/anagram.rb | UTF-8 | 1,261 | 4.15625 | 4 | [
"Ruby"
] | permissive | #!/usr/bin/env ruby
class AnagramMaker
def initialize (phrase1, phrase2)
@phrase1 = phrase1
@phrase2 = phrase2
end
def anagram_maker()
letter_array1 = @phrase1.downcase.gsub(/[^a-zA-Zs]/, '').split("").sort
letter_array2 = @phrase2.downcase.gsub(/[^a-zA-Z]/, '').split("").sort
vowel_check_ar... | true |
b727b2fdce9550eb6a165dd5583185ae6a7303ee | Ruby | iandelible/firehose_challenges | /linked_list1.rb | UTF-8 | 2,216 | 4.46875 | 4 | [] | no_license | class LinkedListNode
attr_accessor :value, :next_node
def initialize(value, next_node=nil)
@value = value
@next_node = next_node
end
end
def print_values(list_node)
if list_node
print "#{list_node.value} --> "
print_values(list_node.next_node)
else
print "nil\n"
return
... | true |
8ce31e13b0ba0e466b415185b5907ef74eaf5a9d | Ruby | akingabramson/activerecord-lite | /lib/active_record_lite/associatable.rb | UTF-8 | 2,643 | 2.890625 | 3 | [] | no_license | require 'active_support/core_ext/object/try'
require 'active_support/inflector'
require_relative './db_connection.rb'
class AssocParams
attr_reader :other_class_name, :primary_key, :foreign_key
def other_class
@other_class_name.constantize
end
def other_table
other_class.table_name
end
end
class B... | true |
8ce2a926db67b594ff266f6c4b17306f4acf8ebb | Ruby | baccigalupi/g-assign-api | /app/models/collection_serializer.rb | UTF-8 | 184 | 2.53125 | 3 | [] | no_license | class CollectionSerializer < Struct.new(:collection)
def to_json(*args)
as_json.to_json
end
def as_json
collection.map{|model| model.attributes.slice(*keys) }
end
end
| true |
5fd7246592f368ee40a9a1e8f53954a52d336703 | Ruby | ashleygwilliams/pokemon_refactor_lab | /inheritance/trainer.rb | UTF-8 | 385 | 3.25 | 3 | [] | no_license | require_relative './pokemon'
require_relative './pokemon/bulbasaur'
require_relative './pokemon/charmander'
require_relative './pokemon/squirtle'
class Trainer
attr_accessor :name, :team
def initialize name="Ash"
@name = name
@team = []
@team << [Bulbasaur.new, Charmander.new, Squirtle.new].sample
e... | true |
639e452fb19275678d3eaa80640890a750f5ba24 | Ruby | rameshbaskar/gauge-ruby-test | /step_implementations/parse_words_steps.rb | UTF-8 | 340 | 2.890625 | 3 | [] | no_license | require_relative 'base_steps.rb'
include WordManager
step 'Vowels in English language are <vowels>' do |vowels|
init_vowels(vowels)
end
step 'The word <word> has <vowel_count> vowels' do |word, vowel_count|
print_vowel_count(word, vowel_count)
end
step 'Almost all words have vowels <table>' do |table|
parse_wo... | true |
c162970a7b88a6036bda3b38819fb90f50ec2d89 | Ruby | marialobillo/intro-to-programming | /loop/6.rb | UTF-8 | 104 | 3.109375 | 3 | [] | no_license | numbers = [7, 9, 13, 25, 18]
i = 0
len = numbers.length
until i == len
puts numbers[i]
i += 1
end
| true |
a82e7a17831fe899a3a04704053b8e02ea57322f | Ruby | mgrigoriev8109/ruby_projects | /stock_picker.rb | UTF-8 | 2,074 | 3.734375 | 4 | [] | no_license |
def stock_picker(array_of_days)
#reduce would probably be best for this
#it starts at the first value as the accumulator [0, 0, 0] for [buy, sell, possible_buy]
#for each iteration, if current<accumulator[0] && accumulator[0]==accumulator[2] then accumulator[0][1][2] all = current
#iterate through array look... | true |
8fd161d4efbda39cbd9de92c0a33fdc095d7187d | Ruby | kazunetakahashi/atcoder-ruby | /0709/ARC039_A.rb | UTF-8 | 249 | 2.9375 | 3 | [
"MIT"
] | permissive | s = gets.chomp
ans = -1100
7.times{|i|
if i == 3
next
end
10.times{|j|
temp = s[i]
s[i] = j.to_s
a, b = s.split(" ").map{|x| x.to_i}
if a >= 100 && b >= 100
ans = [ans, a-b].max
end
s[i] = temp
}
}
puts ans
| true |
4647633205250898b4f838b568fe519678612672 | Ruby | newtonry/app_academy | /w1d1/array_exercises.rb | UTF-8 | 1,297 | 3.875 | 4 | [] | no_license |
class Array
def my_uniq
uniques = []
self.each do |element|
uniques << element unless uniques.include?(element)
end
uniques
end
def two_sum
pairs =[]
self.each_with_index do |num1, ind1|
# ind2 = ind1 + 1
#
# while ind2 < self.length
# pairs << [ind1, ind2] if (num + self[ind2] == 0)
# in... | true |
c525a03265ffd24e8163d83d18a1da8076a7e3d5 | Ruby | wisetara/3.1FizzBuzzWhatNot | /title_case/lib/title_case.rb | UTF-8 | 352 | 3.71875 | 4 | [] | no_license | def title_case(string)
exceptions = ["the", "an", "of", "is", "as", "at", "by", "for", "in", "on", "per", "to", "and", "but", "nor", "or"]
words = string.downcase.split
words.each do |word|
unless exceptions.include?(word)
word.capitalize!
end
words[0].capitalize!
end
words.join(" ")
end
pu... | true |
df50bb0a61dd927cc91b71f9b1eb36dd580f66fd | Ruby | catmando/broken-jquery-demo | /app/hyperloop/components/error_demo.rb | UTF-8 | 1,420 | 2.796875 | 3 | [] | no_license |
module EventError
def self.included(component)
component.before_update do
if (last_error = @__event_error_last_error)
@__event_error_last_error = nil
raise last_error
end
end
end
def raise_error(e)
@__event_error_last_error = e
force_update!
end
def guard_exception... | true |
ba8a5b067a3faab83d45b7ee8d2a080c9fca260a | Ruby | Wendyv510/ruby-object-attributes-lab-onl01-seng-pt-100619 | /lib/person.rb | UTF-8 | 564 | 2.84375 | 3 | [] | no_license | class Person
def name = (persons_name)
@name
end
def instance_variable_set (:@name)
@instance_variable_set
end
def name
@name
@instance_variable_set
end
beyonce = Person.new
beyonce.name
beyonce.instance_variable_set
class Job
def job = (occupation)
... | true |
23a4b2fd55eb080c6a1fb37952fdef077a81bc95 | Ruby | jennli/codecorejan2016 | /ruby_lec_lab/week2/recursion.rb | UTF-8 | 672 | 4 | 4 | [] | no_license | # def sum(array)
# if array.empty?
# 0
# else
# array[0] + sum(array[1..-1])
# end
# end
#
# my_array = (1..6000).to_a
#
# p sum(my_array)
#
# def factorial(n)
# if n == 0
# 1
# else
# n * factorial(n-1)
# end
# end
#
# p factorial(5)
# def multiply_arr(arr)
# if arr.empty?
# 0
# ... | true |
861d017ed1cb371d9661d1949d853e103b2012d9 | Ruby | GratefulGarmentProject/StockAid | /app/models/permission_error.rb | UTF-8 | 819 | 3.234375 | 3 | [
"MIT"
] | permissive | class PermissionError < StandardError
def initialize(msg = "You do not have proper permission!")
super msg
end
class << self
def check(user, options)
return check_all(user, options) if options.is_a?(Array)
return check_single(user, options) if options.is_a?(Symbol)
return check_any(user... | true |
3e20d0b197b6e0b7af813d03720e4b459e0f9b09 | Ruby | patrickshobe/battleshift | /spec/models/space_spec.rb | UTF-8 | 626 | 2.546875 | 3 | [] | no_license | require 'rails_helper'
describe 'Space Model' do
it '#attack! and hits' do
ship = Ship.new(2)
space = Space.new('A1')
allow_any_instance_of(Space).to receive(:contents).and_return(ship)
space.attack!
expect(space.status).to eq("Hit")
end
it '#attack! and sinks' do
ship = Ship.new(1)
... | true |
d00d3eb9a00788390a03bb8ca5fe6bb3c1526a4d | Ruby | sigitas-janusauskas/pick_a_card-1 | /main.rb | UTF-8 | 675 | 3.0625 | 3 | [] | no_license | # encoding: utf-8
# tai programa apie kortas
# Подключаем класс колоды
require_relative 'lib/deck'
# Выводим приветствие
# apie progr pradzia
puts 'Pick a Card. (c) goodprogrammer.ru'
puts " programa sudetinga"
puts 'kodas su OOP'
# Создаем новую колоду и сразу её перемешиваем
deck = Deck.new.shuffle
# Спрашиваем ... | true |
8667f9fd6ca04f6eb341dfbba55a71aec715ee68 | Ruby | epitron/epitools | /spec/term_spec.rb | UTF-8 | 1,175 | 2.84375 | 3 | [
"WTFPL",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'epitools/term'
describe Term do
it "sizes" do
width, height = Term.size
width.class.should == Integer
height.class.should == Integer
end
it "tables" do
table = Term::Table[ (1..1000).to_a ]
#p [:cols, table.num_columns]
#p [:rows, table.num_rows]
#puts "columns"
#puts t... | true |
7c2aa2f7437adca1c149a3e4d296564c8bce43c1 | Ruby | grant-mc/LaunchSchool-RB101-Programming-Foundations | /Lesson_6/twenty_one.rb | UTF-8 | 2,615 | 3.9375 | 4 | [] | no_license | CARDS = ['Ace', 2, 3, 4, 5, 6, 7, 8, 9, 10, 'Jack', 'Queen', 'King']
FACE_CARDS = ['Jack', 'Queen', 'King']
def prompt(msg)
puts "=> #{msg}"
end
def intialize_deck
deck = []
4.times { CARDS.each { |card| deck << card } }
deck.shuffle!
end
def deal_hand(deck)
hand = []
2.times { hand << deck.pop }
hand
... | true |
0f2f5b36cc66f60e386896e7aa062ab801e609be | Ruby | Esgeri/blackjack-ruby-samurai | /lib/player.rb | UTF-8 | 165 | 2.671875 | 3 | [] | no_license | class Player < User
attr_reader :name
def initialize(name)
if @name == ''
@name = 'Таинственная персона'
else
@name = name
end
super()
end
end
| true |
820415684baba040aa34f442da9dea59276e5793 | Ruby | matthewgiem/shoe_stores_rb | /spec/brand_spec.rb | UTF-8 | 599 | 2.609375 | 3 | [] | no_license | require('spec_helper')
describe(Brand) do
describe("#name") do
it("returns the name of the brand captolized") do
test_brand = Brand.create({:name => "matthew"})
expect(test_brand.name()).to(eq("Matthew"))
end
end
describe("#stores") do
it("tells which stores they are sold in") do
... | true |
57c14732ba3ef4343b9212f3417f312be72e7491 | Ruby | turadg/whois | /lib/whois/errors.rb | UTF-8 | 3,517 | 2.75 | 3 | [
"MIT"
] | permissive | #--
# Ruby Whois
#
# An intelligent pure Ruby WHOIS client and parser.
#
# Copyright (c) 2009-2011 Simone Carletti <weppos@weppos.net>
#++
module Whois
# The base error class for all <tt>Whois</tt> error classes.
class Error < StandardError
end
# Raised when the connection to the WHOIS server fails.
class... | true |
df4277439e3813c25d4ad9199506ff18282fe333 | Ruby | drewmoore/partybassics | /app/helpers/events_helper.rb | UTF-8 | 1,249 | 2.921875 | 3 | [] | no_license | module EventsHelper
def event_date date
year = date.split("-")[0].to_i
month = date.split("-")[1].to_i
day = date.split("-")[2].to_i
Date.new(year, month, day)
end
def date_suffix date
day = date.split("-")[2].to_i
suffix = ""
case day
when 1, 31
suffix = "st"
when 2
... | true |
25764fdb7be56356acb4a76610e8bf246bd5ba74 | Ruby | christianheise/freifunk_ios | /app/01_models/node_repository.rb | UTF-8 | 647 | 3.15625 | 3 | [] | no_license | class NodeRepository
def initialize(nodes)
@nodes = nodes
end
def reset
@nodes = nil
end
def sorted
all.sort_by { |node| node.name.downcase }
end
def online
all.select(&:online?)
end
def offline
all.select(&:offline?)
end
def find(query)
sorted.select do |node|
t... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.