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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
6d5ef8ed5e2846cc41efdc06fa1035efe4ed9845 | Ruby | GabeP9195/ruby-challenges | /case.rb | UTF-8 | 427 | 3.53125 | 4 | [] | no_license | puts "What's the weather like?"
weather = gets.chomp
case weather
when "sunny"
puts "Sunny out, go for a cruise in the convertible, top down time!"
when "cloudy"
puts "Grab an umbrella, it might rain"
when "foggy"
puts "Careful, it's foggy out"
when "rainy"
puts "Grab the umbrella, it's pouring cats and dogs out th... | true |
5dcbe0c9d4467187e1dcb81aa8768e58c4233895 | Ruby | sushengloong/market_data | /lib/market_data.rb | UTF-8 | 323 | 2.609375 | 3 | [
"MIT"
] | permissive | require "market_data/version"
module MarketData
class ResponseData
attr_reader :status, :data
def initialize status, data
@status = status
@data = data
end
end
def self.for_symbol symbol
ResponseData.new 200, { :open => 1, :high => 2, :low => 3, :close => 4, :volume => 5 }
end
e... | true |
0e578d16543004a61e2f0977e30d994f5ade3761 | Ruby | JotaSe/undecided | /lib/undecided/decider.rb | UTF-8 | 663 | 3.046875 | 3 | [
"MIT"
] | permissive | module Undecided
class DeciderError < StandardError
end
# Evaluate boolean expression
class Decider
# Given a boolean expression and data to replace, return result
def decide(rule, values, strict = true)
rule = rule.clone
values = values.clone
error unless Undecided::Evaluator.valid?(r... | true |
432e9ab0f681097150ad9a89c37ca86a454520ff | Ruby | z010155/portable-markov | /portable-markov.rb | UTF-8 | 13,175 | 2.90625 | 3 | [
"MIT"
] | permissive | ## Patent Portable Markov-in-a-box Generator
#
# This tool generates portable Markov chain-in-a-box scripts.
# Essentially, this program generates self-sufficient scripts that quote
# parts from their built-in chains. They could be used as motivational tools,
# generating endless sentences of philosophical nature a... | true |
86ba2b3e1573fef24080eaf7eb408f19b0999495 | Ruby | MichaelMacLeod/w2d3_homework | /win_checker_runner.rb | UTF-8 | 436 | 3.296875 | 3 | [] | no_license | # require_relative('win_checker')
# win_checker = WinChecker.new
# empty_board = [ [nil,nil,nil],[nil,nil,nil],[nil,nil,nil] ]
# symbol = :o
# puts "check that empty board doesn't win: expect that: #{win_checker.has_won?(symbol, board)} is false."
# board_with_horizontal = [ [:o,:o,:o],[nil,nil,nil],[nil,nil,nil] ]... | true |
75224d42a485accd3587f062d3df8a1ee5a675d0 | Ruby | annamm77/FarMar | /specs/farmar_product_spec.rb | UTF-8 | 1,638 | 2.6875 | 3 | [] | no_license | require_relative './spec_helper'
describe FarMar::Product do
before do
@test_market = FarMar::Market.find(1)
@test_product = FarMar::Product.find(1)
end
describe "self.all" do
it "returns an array" do
FarMar::Product.all.must_be_instance_of Array
end
it "returns an array of FarMar::Products instance... | true |
f0124640f640e1d69cca3217a79dd69723c13b8b | Ruby | hungryed/email_thing | /find_bad_emails.rb | UTF-8 | 176 | 2.5625 | 3 | [] | no_license | class FindBadEmails
def initialize(filename)
@filename = filename
end
def read_file
f = File.new(@filename, "r")
@results=f.readlines
@results
end
end
| true |
3dd5dbcd6ec0aa1ebcf1a2f09fa030530b00d96c | Ruby | sideshowbandana/beautiful_pairs | /lib/beautiful_pairs.rb | UTF-8 | 590 | 3.359375 | 3 | [
"MIT"
] | permissive | require "beautiful_pairs/version"
module BeautifulPairs
def solve
puts run(gets.chomp.to_i, gets.chomp.split.map(&:to_i), gets.chomp.split.map(&:to_i))
end
module_function :solve
def run(length, a, b)
counter = 0
a_hash = Hash.new(0)
a.each do |n|
a_hash[n] += 1
end
b.each do |n|... | true |
30a080faa163f6542a8c800b9c2d6eeef3bfabfe | Ruby | Annabanana80/redditClone | /db/seeds.rb | UTF-8 | 1,457 | 2.6875 | 3 | [] | no_license | require 'random_data'
5.times do
User.create!(
name: RandomData.random_name,
email: RandomData.random_email,
password: RandomData.random_sentence
)
end
users = User.all
15.times do
Topic.create!(
name: RandomData.random_sentence,
description: RandomData.random_paragrap... | true |
c34bdc560833fb0bf20594ad8379570a97b92822 | Ruby | FotoVerite/babygitter | /lib/babygitter/output_helpers/html_output.rb | UTF-8 | 6,117 | 2.78125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'cgi'
require 'markaby'
module Babygitter
module HtmlOutput
#Pluralizes the authors of a branch in a readable and gramatically correct manner
#
#authors_list([Matt, Allen]) => Matt and allen have
#authors_list([Matt]) => Only Matt has
def authors_list(array_of_authors)
case arra... | true |
16ba75bef65b41af036441f659e1f58a385d3c36 | Ruby | rnovick13/advanced-hashes-hashketball-dc-web-111918 | /hashketball.rb | UTF-8 | 4,984 | 3.21875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here!
require "pry"
def game_hash
game = {
:home => {
:team_name => "Brooklyn Nets",
:colors => ["Black", "White"],
:players => {
"Alan Anderson" => {
number: 0, shoe: 16, points: 22, rebounds: 12, assists: 12, steals: 3, blocks: 1, slam_dunks: 1},
"R... | true |
c7ad87c1a46daceb3e9cb771269f128752524154 | Ruby | jasonchilcott/ruby-enumerables-hash-practice-emoticon-translator-lab-nyc01-seng-ft-082420 | /lib/translator.rb | UTF-8 | 1,112 | 3.5 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # require modules here
require "yaml"
require "pry"
def load_library(file_path)
# code goes here
emoticons = YAML.load_file(file_path)
labeled_hash = {}
emoticons.each do |key, value|
# for each key, if it doesnt exist in labeled hash, create it, key value for each.
labeled_hash[key] = {}
labeled... | true |
bba0406b9b3ef53fac20122df43a16ca87d1c79c | Ruby | ccgamble/black_thursday | /lib/invoice_item.rb | UTF-8 | 698 | 2.765625 | 3 | [] | no_license | require 'pry'
require 'bigdecimal'
require 'time'
class InvoiceItem
attr_reader :id, :item_id, :invoice_id, :quantity, :unit_price,
:created_at, :updated_at, :invoice_item_repository
def initialize(column, parent = nil)
@id = column[:id].to_i
@item_id = column[:item_id].to_i
@invoice_id ... | true |
86eacd74e7f1a40552848a7d4231737ff1cd5366 | Ruby | uchennaanya/UCLinter | /lib/read_file.rb | UTF-8 | 436 | 3.15625 | 3 | [
"MIT"
] | permissive | require 'colorize'
class FileRead
attr_reader :err_msg, :file_lines, :file_path, :file_lines_count
def initialize(file_path)
@err_msg = ''
@file_path = file_path
begin
@file_lines = File.readlines(@file_path)
@file_lines_count = @file_lines.size
rescue StandardError => e
@file_lin... | true |
7603b21189ea877fdadeb8f12d180e281ad5b261 | Ruby | GabeHaff/tic-tac-toe-rb-online-web-sp-000 | /lib/tic_tac_toe.rb | UTF-8 | 2,569 | 4.0625 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts " #{board[6]} | #{board[7]} | #{board[8]} "
end
def input_to_index(input)
input.to_i-1
end
def move(display_board, index, character="X")
dis... | true |
dbe4ad287f9454c1fd231c29e8d24c4bfd50cf99 | Ruby | unepwcmc/SAPI | /config/initializers/active_record_protected_deletion.rb | UTF-8 | 606 | 2.515625 | 3 | [
"BSD-3-Clause"
] | permissive | module ProtectedDeletion
# ideally override this
def can_be_deleted?
dependent_objects.empty?
end
# used to return informative error message on failed destroy
def dependent_objects
dependent_objects_map.map do |k, v|
v.limit(1).count > 0 ? k : nil
end.compact
end
protected
# return... | true |
45670b3a8423dbbfeb238d242ccb71b606dc7cc3 | Ruby | yana-gi/atcoder | /abc187/b/main_ans.rb | UTF-8 | 224 | 3.25 | 3 | [] | no_license | n = gets.to_i
# transpose
x,y = n.times.map { gets.split.map(&:to_i) }.transpose
ans = 0
(0..(n - 2)).each do |i|
((i + 1)..(n - 1)).each do |j|
ans += 1 if (x[i] - x[j]).abs >= (y[i] - y[j]).abs
end
end
puts ans
| true |
3f2dacab7d01301629bf60c36db6bc74b8786a9d | Ruby | alialsaihaty/augest-2015-ruby | /occurring_letter.rb | UTF-8 | 517 | 3.796875 | 4 | [] | no_license | #Find a way that will return the letter that occurred most in a given string. For instance if you give it: Hello it will give back the letter:l
puts "Please write any Word ?"
sentence = gets.chomp
#
characters = sentence.chars
hash = Hash.new(0)
characters.each do |letter|
hash[letter] += 1
end
print hash.sortb... | true |
b2e923713fda768c91d67cced754302636808b5d | Ruby | emckean/quickscripts | /get_trending_concepts.rb | UTF-8 | 736 | 2.59375 | 3 | [] | no_license |
require 'csv'
require 'cgi'
require 'uri'
api_token = 'REFRESH ME'
#read in lists CSV file
File.open(ARGV[0]) do |list_file|
list_file.each do |line|
guid = line.chomp
# puts ""
# puts "#{guid}"
article = system ("curl https://api.helloreverb.com/v1/articles/id\\?guid=#{guid}\\&relatedArticleLimi... | true |
b524a57b300c504583b12d8f57670c2f521f09be | Ruby | cichlidx/ronco_et_al | /age_determination/ortholog_identification/src/get_rate_variation_from_log.rb | UTF-8 | 2,159 | 3.0625 | 3 | [] | no_license | # m_matschiner Tue Jul 24 13:02:25 CEST 2018
module Enumerable
def sum
self.inject(0){|accum, i| accum + i }
end
def mean
if self.length == 0
nil
else
self.sum/self.length.to_f
end
end
end
# Get the command line arguments.
log_file_name = ARGV[0]... | true |
383d69aa29e286c44184cf14d418b88a393f2023 | Ruby | hdgarrood/school_shop | /app/controllers/sales_controller.rb | UTF-8 | 1,114 | 2.515625 | 3 | [] | no_license | require 'csv'
class SalesController < ApplicationController
before_filter :find_garment,
:only => [:create, :new]
# show a list of sales. Will soon also export CSV
def index
@sold_garments = Garment.sold
respond_to do |format|
format.html # show.html.haml
format.csv { render... | true |
f2b1a7d1821e14f657caec2b0b94a9eb3d90ee6f | Ruby | raw1z/parchemin | /lib/parchemin/models/static.rb | UTF-8 | 830 | 2.875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # coding: utf-8
module Parchemin
# This class represents a static content such as an about page
class Static
attr_reader :filename, :id
# initializes the static content with its name
def initialize(id)
@id = id
@filename = "#{Parchemin::Config.statics_path}/#{@id}.markdown"
end
... | true |
469a383390288b12a3fe38a335886aa22ec4e037 | Ruby | jasoncomes/Random-Liquid-Filter | /rand.rb | UTF-8 | 364 | 2.890625 | 3 | [] | no_license | # frozen_string_literal: true
# rand / https://github.com/jasoncomes/Random-Liquid-Filter
# Provides a randomized number up to the max number provided.
# {{ max_number | rand }}
module Rand
def rand(input)
max = input.to_i
# Return 0
return max if max === 0
# Return
Random.new.rand(max)
end
... | true |
2b9f066f64d64fcc0ba169bbf978550d79f76a94 | Ruby | cnix/handy_capper | /lib/handy_capper/handy_capper.rb | UTF-8 | 7,290 | 3.34375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # Public: Various methods for scoring sailing regattas.
# All methods are instance methods.
# Currently only PHRF Time on Time and PHRF Time on Distance are supported.
module HandyCapper
# Public: Applies position and points to a group of results
#
# sort - Result attribute to sort by. (default: :corrected_time... | true |
221f0dac2f6cae3c2fba3ca7d6256b6b54a45d3b | Ruby | mfliedner/codeeval-challenges | /string_permutations.rb | UTF-8 | 299 | 2.953125 | 3 | [] | no_license | # Sample code to read in test cases:
File.open(ARGV[0]).each_line do |line|
# Do something with line, ignore empty lines
#...
line.chomp!
unless line.empty?
characters = line.split("")
permutations = characters.permutation.to_a.map(&:join).sort
puts permutations.join(",")
end
end
| true |
22658159b6b071ad1dfea1eafbefa329af02d753 | Ruby | wesmangum/ruby-scavenger-hunt | /lib/integer_class.rb | UTF-8 | 373 | 3.65625 | 4 | [] | no_license | require 'Prime'
class Integer
def factors
a = (2..self).to_a
a.keep_if { |x| self%x == 0 && x != self }
# factors= []
# 2.upto(self) do |i|
# if self%i == 0
# if i != 1
# factors << i
# end
# end
# end
# factors
end
def prime_factors
self.facto... | true |
18d79fee9f8512b05f08cb63113db089fe7a0569 | Ruby | johncorderox/dojo | /learn/random_ruby/math.rb | UTF-8 | 443 | 3.4375 | 3 | [] | no_license | class MathDojo
def initialize
@total = 0
end
def add(*arguments)
a = arguments.flatten
@total += a.reduce(:+)
self
end
def subtract(*arguments)
a = arguments.flatten
@total -= a.reduce(:+)
self
end
def result
puts "#{@total}"
end
end
challenge1 = MathDojo.new.add(2).add(2, 5).subtract(3, ... | true |
052fbdcf5ad583a4841581bc174f84d7e890c399 | Ruby | logstash-plugins/logstash-codec-cef | /lib/logstash/codecs/cef/timestamp_normalizer.rb | UTF-8 | 4,879 | 2.734375 | 3 | [
"Apache-2.0"
] | permissive | # encoding: utf-8
require 'java'
# The CEF specification allows a variety of timestamp formats, some of which
# cannot be unambiguously parsed to a specific points in time, and may require
# additional side-channel information to do so, namely:
# - the time zone or UTC offset (which MAY be included in a separate fie... | true |
6c5a46172e08d8768d7a331b166ba4aae096a4f2 | Ruby | toraritte/why_practice | /dwemthy.rb | UTF-8 | 1,647 | 3.796875 | 4 | [] | no_license | class Creature # reimplementing in module?
# trying it with method_missing?
def self.mc
class << self; self; end
end
# creates the class methods for storing the traits and attributes
def self.traits( *attrib )
return @traits if attrib.empty?
# storing the traits and values in a ha... | true |
64ad6be9fa0405058ced1dded96a98868ce286a6 | Ruby | TIY-ATL-ROR-2016-Feb/lectures | /wk03-internets/tue/student.rb | UTF-8 | 550 | 3.375 | 3 | [] | no_license | require "pry"
require "./puppies"
module Example
class Student
def initialize(first, last)
@name = "#{first} #{last}"
end
def to_s
"#<Student Name: #{@name}>"
end
end
# Student here refers to the definition inside the module
binding.pry
end
class Student
def feed_me
puts "S... | true |
7b3aafa4fbf3404d06498ee1f2ff5cfca6571bf9 | Ruby | ssamuel56/fizzbuzz_array | /fizzbuzz_array_tdd.rb | UTF-8 | 1,303 | 3 | 3 | [] | no_license | require_relative 'fizzbuzz_array.rb'
require 'minitest/autorun'
class Testing < Minitest::Test
def test_array1
assert_equal(Array, fizz_array().class)
end
def test_array2
assert_equal([], fizz_array)
end
def test_buzz1
assert_equal([1], buzz(1, fizz_array))
end
def test_buzz2
assert_equal... | true |
92fe9fc86f7e73bb8be5901672fdad0775679862 | Ruby | naiginod/Foundations | /level3/medium2.rb | UTF-8 | 1,660 | 3.984375 | 4 | [] | no_license | Question 1
munsters = {
"Herman" => { "age" => 32, "gender" => "male" },
"Lily" => { "age" => 30, "gender" => "female" },
"Grandpa" => { "age" => 402, "gender" => "male" },
"Eddie" => { "age" => 10, "gender" => "male" }
}
age_sum = 0
munsters.each do |name, details|
if details["gender"] == "male"
age_sum... | true |
7867950b1e5d769acb3d05441e2aaf06482585df | Ruby | FarazPatankar/Ironhack | /week_0/ruby/Boggle_Board_One/boggle_board_one.rb | UTF-8 | 1,531 | 3.375 | 3 | [] | no_license | #end
class BoggleBoard
attr_accessor :array_of_dices
def initialize
@array_of_dices = []
end
def push_to_board
@array_of_dices.push("AAEEGN")
@array_of_dices.push("ELRTTY")
@array_of_dices.push("AOOTTW")
@array_of_dices.push("ABBJOO")
@array_of_dices.push("EHRTVW")
@array_of_dices.push("EHRTVW")
@a... | true |
e3a3dff559939d654b60b3c24ae0d16e555d0848 | Ruby | efertsch/phase-0-tracks | /boosters/week6_booster/classy_house.rb | UTF-8 | 1,453 | 4.1875 | 4 | [] | no_license | require_relative 'classy_rooms'
require_relative 'classy_items'
class House
attr_reader :rooms
def initialize
@rooms = []
end
def add_room(room)
if rooms.length < 11
@rooms << room
true
else
false
end
end
def total_value
end
def to_s
house_str = ""
@rooms.each do |room|
... | true |
45528aa147958eb7eb3fe8081e0c55e871d9963e | Ruby | kaljt/intermediate_quiz_3 | /Ex4.rb | UTF-8 | 873 | 3.828125 | 4 | [] | no_license | def tricky_method_two(a_string_param, an_array_param)
puts "a_string_param id #{a_string_param.object_id}"
puts "an_array id #{an_array_param.object_id}"
a_string_param.gsub!('pumpkins', 'rutabaga')
puts "after gsub a_string id is #{a_string_param.object_id}"
an_array_param = ['pumpkins', 'rutabaga']
puts "... | true |
421d55194edecafab4790a3bf40c1ab3f66eb818 | Ruby | regularfry/ducks | /lib/ducks/protocol.rb | UTF-8 | 1,963 | 2.984375 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
module Ducks
# We subclass Module so that Ruby knows to pick out the constant
# name for #inspect
class Protocol < Module
def initialize( &blk )
@methods = []
instance_exec &blk
end
def defines( *args )
@methods << args
end
def implemented_by?( potentia... | true |
070ea332526727603eb6bca1b22e910a7eebcdf0 | Ruby | zachlp2016/market_1901 | /lib/market.rb | UTF-8 | 1,503 | 3.46875 | 3 | [] | no_license | class Market
attr_reader :name,
:vendors
def initialize(name)
@name = name
@vendors = []
end
def add_vendor(vendor)
@vendors << vendor
end
def vendor_names
vendor_name_arr = []
@vendors.each do |vendor|
vendor_name_arr << vendor.name
end
return vendor_name... | true |
20c7aa690ab30300287db0350ae6d9554d53c227 | Ruby | CharlesABlum/CS214 | /10/ruby/Bird.rb | UTF-8 | 543 | 3.6875 | 4 | [] | no_license | # Bird.rb | Defines a Bird superclass to be extended by specific bird
# sub-classes.
#
# Begun by: Dr. Adams, for CS 214 at Calvin College.
# Completed by:Charles Blum
# Date:29 April 2014
####################################################
class Bird
attr_reader :name
def initialize(name)
@name = name
... | true |
bae3d6f5d30151346b149d21d2c8e68eb8d042f1 | Ruby | AlexNimoy/RubyPatterns | /structural/flyweight/main.rb | UTF-8 | 1,159 | 3.609375 | 4 | [] | no_license | # frozen_string_literal: true
# Unit
class Unit
attr_accessor :x, :y
def initialize(shared, unit_type)
@shared = shared
@unit_type = unit_type
end
end
# Shared data for Cavalry
class UnitCavalryShared
def initialize
@name = 'cavalry'
@sprite = 'sp.jpg'
@sound = 'igogo.mp3'
@speep = 10
... | true |
fd5e176c13ab21973d4be42e341223cde8108d6f | Ruby | httplab/insales_app_core | /lib/insales_app_core/account_setting.rb | UTF-8 | 1,369 | 2.578125 | 3 | [] | no_license | class InsalesAppCore::AccountSetting
attr_accessor :name, :title, :description, :type, :control, :required
def initialize(&block)
block.call(self) if block_given?
end
def get_value(raw_value, acc)
if raw_value.nil?
val = @default_value.respond_to?(:call) ? @default_value.call(acc) : @default_val... | true |
26b246f1505e47b75b448b17b68f68804e32e7e1 | Ruby | cowboy-cod3r/sandbox | /00-tests/03/reverse/exec.rb | UTF-8 | 204 | 3.25 | 3 | [] | no_license | #!/opt/apps/ruby/ruby/bin/ruby
def reverse_words_and_letters(sentence)
return sentence.reverse
end
sentence = "Reverse this sentence along with the letters."
puts reverse_words_and_letters(sentence)
| true |
38f67d8e75cf6fc7c1accd2b3d510b2ba30babc6 | Ruby | celluloid/celluloid | /lib/celluloid/task/threaded.rb | UTF-8 | 1,515 | 2.546875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Celluloid
class Task
# Tasks with a Thread backend
class Threaded < Task
# Run the given block within a task
def initialize(type, meta)
@resume_queue = Queue.new
@exception_queue = Queue.new
@yield_mutex = Mutex.new
@yield_cond = ConditionVariable.new
... | true |
2573fac7c9a54b1d55e7559a60b0b669cdcc620a | Ruby | ogom/grant-front | /lib/grant-front/diagram.rb | UTF-8 | 1,064 | 2.65625 | 3 | [
"MIT"
] | permissive | module GrantFront
class Diagram
class << self
def draw(options={})
puts self.new(options).create
end
end
def initialize(options={})
@options = options
end
def create
policies = []
GrantFront::Policy.all(@options).each do |policy|
if @options[:classes... | true |
203903ca177ba573acf9f6e91d62f0c6d7e662a6 | Ruby | B-Graziani/blog | /db/seeds.rb | UTF-8 | 1,195 | 2.765625 | 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 bin/rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# ... | true |
1221ddd4c7c9e97540f3018841b9dcd81b3f8688 | Ruby | zhimin/rwebunit | /lib/rwebunit/driver.rb | UTF-8 | 24,732 | 2.8125 | 3 | [
"MIT"
] | permissive | # convenient methods to drive the browser.
#
# Instead of
# browser.click_button("submit")
# You can just use
# click_button("submit")
#
require File.join(File.dirname(__FILE__), 'itest_plugin')
require File.join(File.dirname(__FILE__), 'popup')
require 'timeout'
require 'uri'
module RWebUnit
module Driver
... | true |
cfe086bc45c0758975fd2ec94f361d39ffea9177 | Ruby | jsoong1962/square_array-nyc-web-080618 | /square_array.rb | UTF-8 | 124 | 3.015625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def square_array(array)
# your code here
arr = []
array.each do |element|
arr.push(element**2)
end
arr
end
| true |
bcc2abe5bee52baa5b4b79921f81715cc13f675b | Ruby | acook/logsaber | /lib/logsaber/log.rb | UTF-8 | 1,875 | 2.984375 | 3 | [
"MIT"
] | permissive | module Logsaber
class Log
class << self
def create *args
default_options = {
output: $stdout,
level: :info,
appname: nil,
formatter: Logsaber::Formatter.new
}
options = Options.extract_from args, default_options, :output
self.new *opti... | true |
75809483de818eaebd64ff869c1c252949d2c6bf | Ruby | jamesclarkson97/W2D2_homework_bear_river_fish_classes | /river.rb | UTF-8 | 426 | 3.71875 | 4 | [] | no_license | class River
attr_reader :name
def initialize(name)
@name = name
@fish = []
end
def fish_population()
return @fish
end
def add_fish(new_fish)
@fish.push(new_fish)
end
def add_fishes(river, new_fishes)
for fish in new_fishes
river.ad... | true |
60cd7748852b5c2e9a4706699095291312b7044c | Ruby | sabind/learn-2-code-ruby | /strings_arrays/encode_chars.rb | UTF-8 | 2,588 | 3.90625 | 4 | [
"MIT"
] | permissive | # The logic here is used all the time by web applications. There are certain
# characters that cannot be placed in a URL. However sometimes it's required
# that they get sent as URL parameters. The process of replacing these characters
# in the URL is called URL Encoding. for this example we're going to replace the
#... | true |
53db7bfde9bee7e42dd0620d0e7c813a43ff3005 | Ruby | nick-zhang/ruby-practice | /user.rb | UTF-8 | 585 | 3.171875 | 3 | [] | no_license | require 'Virtus'
class User
include Virtus.model
attribute :name, String
attribute :age, Integer
attribute :birthday, DateTime
end
user = User.new(:name => 'Piotr', :age => 31)
user.attributes # => { :name => "Piotr", :age => 31, :birthday => nil }
puts user.name # => "Piotr"
puts user.age
user.age = '31' ... | true |
383dfb54e085cbfc34e4d7c5901e1ba8dbe88a6d | Ruby | codejlo/phase-0-tracks | /ruby/arrays_drill.rb | UTF-8 | 845 | 3.484375 | 3 | [] | no_license | # arrays_drill.rb
# Jason Lorentzen, Brett Buller
### Release 2-1 and 2-2 ###
def build_array(a, b, c)
x = []
return x.push(a, b, c)
end
def add_to_array(my_new_array, a)
my_new_array.push(a)
end
### Release 1-1 to 1-8 ###
yosemite = []
yosemite.push("half dome", "sequoia", "tent", 17, "San Francisco")
p yo... | true |
1f8c59470b1b776d7b8b0a6f2200ee14bfc74799 | Ruby | thiagogabriel/Zine | /app/models/user.rb | UTF-8 | 655 | 2.71875 | 3 | [] | no_license | class User < ActiveRecord::Base
attr_accessible :encoded_password, :login, :password
validates_length_of :login, :within => 3..20
validates_presence_of :encoded_password, :message => "can't be blank"
validates_uniqueness_of :login
def self.login(login, password)
user = User.find_by_login login
if u... | true |
dc997a578b68a11ab39977af91e3ce4ff6225f00 | Ruby | madking55/ruby_exercises | /initialize/lib/quail.rb | UTF-8 | 92 | 2.875 | 3 | [] | no_license | class Quail
attr_reader :name
def initialize(name)
@name = name.capitalize
end
end | true |
45c2288ea84cd3db8446dd38270057a286489ca3 | Ruby | dishapatelcodes/ttt-10-current-player-q-000 | /lib/current_player.rb | UTF-8 | 241 | 3.234375 | 3 | [] | no_license | def turn_count(board)
player_turns = 0
board.each do |character|
if character == "X" || character == "O"
player_turns +=1
end
end
player_turns
end
def current_player(board)
turn_count(board).even? ? "X" : "O"
end
| true |
0c4dcdba2dda10e18c52d563b9462a9516e46a08 | Ruby | HollyM021980/wdi_1_ruby_assessment_objects | /objects.rb | UTF-8 | 1,379 | 4.5625 | 5 | [] | no_license | #### Question 1
# Define a class called `Pet`, and a class `Dog` that inherits from `Pet`.
# Got this wrong, the inheritance syntax should only be 1 "<"
class Pet
end
class Dog < Pet
end
#### Question 2
# Copy your class definitions from question 1 here.
# Then add an initializer to the `Pet` class that accepts a "n... | true |
2f941edda3311d9f0154b684c8f41db8613f62d1 | Ruby | natey37/leetcode-problems | /merge_arrays.rb | UTF-8 | 994 | 4.46875 | 4 | [] | no_license | =begin
Interview Cake - Merge Arrays
We have our lists of orders sorted numerically already, in arrays. Write a method to merge our arrays of orders into one sorted array.
For example:
my_array = [3, 4, 6, 10, 11, 15]
alices_array = [1, 5, 8, 12, 14, 19]
puts merge_arrays(my_array, alices_array)
# Pr... | true |
7b2aff24ba3704d0c7cf6d8c636c2be0705acd39 | Ruby | JArthurJohnston/Parser | /lib/syntax_tree/argument_node.rb | UTF-8 | 370 | 2.65625 | 3 | [] | no_license | require_relative 'abstract_syntax_tree_node'
module Parser
module ParseTrees
class ArgumentNode < AbstractSyntaxTreeNode
attr_reader :name,
:value
def initialize(name, value = nil)
super()
@name = name
@value = value
end
def has_default_value?
... | true |
13ed5c152c13126350d7fc74fb7a0c548f938d8e | Ruby | ChenningZhang/OskiMart | /spec/controllers/conversations_controller_spec.rb | UTF-8 | 3,974 | 2.765625 | 3 | [] | no_license | require 'rails_helper'
#ConversationsController includes:
#GET #new renders the page for creating a new conversation
#POST #create creates a new conversation and redirects to the conversation's show path
#GET #show renders a conversation's path
#GET #index renders the view that manages all conversations
#POST #re... | true |
f8c635150adbdf9455879f51bcfc0252a4b91157 | Ruby | frostmark/railway_ror | /app/models/station.rb | UTF-8 | 830 | 2.578125 | 3 | [] | no_license | class Station < ApplicationRecord
validates :name, presence: true
has_many :routes_stations
has_many :routes, through: :routes_stations
has_many :trains, foreign_key: :current_station_id
def update_position(route, position)
station_route = station_route(route)
station_route.update(position: positio... | true |
3041da1ec7630ed9a4b2ca523ad39da1a24bea65 | Ruby | danielgrigg/sandbox | /langs/ruby/read_lines.rb | UTF-8 | 497 | 3.125 | 3 | [
"WTFPL"
] | permissive | counter = 1
file = File.new("read_lines.rb", "r")
while (line = file.gets)
puts "#{counter}: #{line}"
counter = counter + 1
end
file.close
File.open("read_lines.rb", "r") do |infile|
while (line = infile.gets)
puts "#{counter}: #{line}"
counter = counter + 1
end
end
counter = 1
begin
file = File.new... | true |
d7d774ae3d337f5a5237c9bbfce4dc44f7b2b97e | Ruby | postazure/Ruby-Practice | /CH9/mooMethod.rb | UTF-8 | 84 | 2.515625 | 3 | [] | no_license | def say_moo
puts 'mooooo....'
end
say_moo
say_moo
puts 'coin-coin'
say_moo
say_moo | true |
851eebb6c05102a250f34fa7a383375618fa26c1 | Ruby | yazinsai/algorithms | /largest-number.rb | UTF-8 | 597 | 4.46875 | 4 | [] | no_license | =begin
Given a list of non negative integers, arrange them such that they
form the largest number.
For example:
Given [3, 30, 34, 5, 9], the largest formed number is 9534330.
Note: The result may be very large, so you need to return a string
instead of an integer.
Source: https://www.interviewbit.com/problems/larg... | true |
ec8db891f7d0e3743ffc34a1f35dcd68709cf990 | Ruby | Coderdotnew/intro_web_apps_bs | /03_class/01_conditionals/code/01_math_conditionals/spec/math_conditionals_spec.rb | UTF-8 | 895 | 3.453125 | 3 | [] | no_license | require_relative './spec_helper'
require_relative '../math_conditionals.rb'
describe "#less_than" do
it "return the expected string if the input is not less than 100" do
expect(how_big(100)).to eq("That's a large number.")
end
it "return the expected string if the input is less than 100" do
expect(how_b... | true |
0acb28e6e2af59d342b95913e17ceb8772203cf0 | Ruby | tomoasleep/yoda | /lib/yoda/model/parameters/multiple.rb | UTF-8 | 1,269 | 2.828125 | 3 | [
"MIT"
] | permissive | module Yoda
module Model
module Parameters
class Multiple < Base
# @return [Array<Base>]
attr_reader :parameters, :post_parameters
# @return [Array<Base>]
attr_reader :keyword_parameters
# @return [Base, nil]
attr_reader :rest_parameter, :keyword_rest_parame... | true |
f424c978551e996f604310e6abcedecd9fd0e351 | Ruby | change/lita-totems | /lib/lita/handlers/stats.rb | UTF-8 | 1,862 | 2.53125 | 3 | [
"MIT",
"Apache-2.0"
] | permissive | require 'signalfx'
module Stats
module_function
SIGNALFX_TOTEMS_METRICS_DASHBOARD = "https://app.signalfx.com/#/dashboard/FNSkEUVAYAA"
def signalfx_client
@signalfx_client ||= SignalFx.new ENV['LITA_SIGNALFX_TOKEN']
end
def send_gauges_to_signalFX(metric, value)
signalfx_client.send(
gauges:... | true |
5800ec5405ef6dfd5bff57baf60a6e51b5e85122 | Ruby | torpedo-t/recipe-book | /app/models/user.rb | UTF-8 | 1,292 | 2.78125 | 3 | [] | no_license | class User < ApplicationRecord
has_secure_password
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.freeze
has_many :recipes
has_many :ratings
has_many :rated_recipes, through: :ratings, source: :recipe
validates :email, presence: true, format: { with: VALID_EMAIL_REG... | true |
87b1a6ecf2f579550c2ae399ad07ccd3e644951b | Ruby | TylerBrock/books | /Agile Web Development with Rails/work/depot/rake/ruby/1.9.1/gems/activesupport-3.0.10/lib/active_support/gzip.rb | UTF-8 | 695 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'zlib'
require 'stringio'
module ActiveSupport
# A convenient wrapper for the zlib standard library that allows compression/decompression of strings with gzip.
module Gzip
class Stream < StringIO
def initialize(*)
super
set_encoding "BINARY" if "".encoding_aware?
end
... | true |
6fe468765b3fc91f912cc702d80e6018fc5ef130 | Ruby | bcarreno/blog | /test/models/message_test.rb | UTF-8 | 662 | 2.5625 | 3 | [] | no_license | require 'test_helper'
class MessageTest < ActiveSupport::TestCase
test 'required attributes' do
message = Message.new
refute message.valid?
assert_equal 'is invalid', message.errors[:email].first
assert_equal "can't be blank", message.errors[:body].first
message.email = 'dummy'
refute messa... | true |
b57defb86ae21c1d21bf1afc38a9f3f333f1316c | Ruby | equivalentideas/westconnex_M4_East_Air_Quality_Monitoring | /lib/models/monitor.rb | UTF-8 | 752 | 2.75 | 3 | [] | no_license | # frozen_string_literal: true
# The Air Quality Monitor that readings belong to
class Monitor
attr_accessor :name
def self.count
AqmRecord.distinct(:location_name).count
end
def self.all
AqmRecord.distinct(:location_name).select(:location_name).order(:location_name).collect do |record|
new(name... | true |
84ee180ab0f9b07151a679bf876d5b8a8a788992 | Ruby | ekene966/hackerrank | /ruby/xor_and_sum.rb | UTF-8 | 274 | 3.796875 | 4 | [
"MIT"
] | permissive | # Xor and Sum
class XorAndSum
UPPER_BOUND = 314_159
MODULO_VAL = (10**9) + 7
def self.calculate(a, b)
sum = 0
(0..UPPER_BOUND).each { |i| sum += (a ^ (b << i)) }
sum % MODULO_VAL
end
end
a = gets.to_i(2)
b = gets.to_i(2)
puts XorAndSum.calculate(a, b)
| true |
a0475ae2ed867e35b928a4dad71ecd5939210fce | Ruby | colinyoung/mongoid_to_csv | /lib/mongoid_to_csv.rb | UTF-8 | 1,703 | 2.859375 | 3 | [] | no_license | require 'mongoid'
require 'csv'
module MongoidToCSV
# Return full CSV content with headers as string.
# Defined as class method which will have chained scopes applied.
def to_csv
documents_to_csv all
end
module_function
def documents_to_csv(documents, fields = nil)
return documents.to_csv unless... | true |
14086e38c2919a91789f1c2451346cadad19576b | Ruby | ShawnAukstak/problems | /elements_of_programming_interviews/16_1_tower_of_hanoi.rb | UTF-8 | 1,167 | 4.25 | 4 | [] | no_license | =begin
Have three pegs (stacks).
Rings are on stack 0 in size order, with largest at the bottom.
Only operation you can do it place one peg from top of on stack to another
You cannot place a larger ring ontop of a smaller ring.
input number of rings on stack[0]
output - print sequence of moves.
Create stacks + rings
... | true |
bc33a81f5d17ce09b94c6d91ef07c430119e2354 | Ruby | garweim/Homuch | /app/services/detailed_estimate.rb | UTF-8 | 611 | 2.578125 | 3 | [] | no_license | class DetailedEstimate
def call(project)
@project = project
return unless market_price_estimate
total_estimate
end
# private
attr_reader :project
def total_estimate
market_price_estimate - renovation_price
end
def registration_fees
market_price_estimate * 0.15
end
def market... | true |
7ab9f5efb8ac86e2e3238e229ac820404f46ec15 | Ruby | batfrog/Ruby | /no_escape.rb | UTF-8 | 124 | 3.5625 | 4 | [] | no_license |
while 1
puts "Who are you?"
user_name = gets.chomp
puts "You'll NEVER ESCAPE, #{user_name}!! MUAHAHAHAHAHAHAHAHAHA!"
end | true |
0460f60bde140cb3835d5114d8e48132930d17c6 | Ruby | sebglazebrook/dank | /spec/dank_spec.rb | UTF-8 | 1,822 | 2.984375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Dank do
describe '.parse' do
subject { Dank }
context 'when given a valid regular expression' do
let(:regular_expression) { /[a-z]*/ }
it 'converts it to dank' do
expect(subject.parse(regular_expression)).to eq Dank.any_lowercase_letters
end
e... | true |
78419672095b7d36e7b8cbfe0cac29578142118c | Ruby | RajaomalalaSendra/ruby_quiz | /test.rb | UTF-8 | 2,325 | 3.703125 | 4 | [] | no_license | # Notre test
score = 0
def run_test(questions,i)
answer = ""
score = 0
i = i.to_i
for question in questions
puts "The question ##{i + 1}"
puts question.prompt
enter()
answer = gets.chomp()
if answer == question.answer
score += 1
end
i +... | true |
6ad09915460b9070b68bf9bf497c13c27fde5830 | Ruby | weyewe/scrap_avax | /scrap_animephile.rb | UTF-8 | 1,324 | 2.6875 | 3 | [] | no_license | require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'cgi'
homepage = 'http://www.animephile.com/hentai'
# 'http://www.animephile.com/hentai/birthday.html?ch=Volume+01'
page = Nokogiri::HTML(open( homepage ))
result_filename = "animephile_last.txt"
results = page.css("#newesthentai div.boxhigh... | true |
6d0ea87e9be1310338208389ac6d950b46505420 | Ruby | gonyolac/ls_ruby_course | /OO_programming/lesson_4/easy_exercises.rb | UTF-8 | 5,676 | 4.1875 | 4 | [] | no_license | module Speed
def go_fast
puts "I am a #{self.class} and going super fast!"
end
end
class Car
include Speed
def go_slow
puts "I am safe and driving slow."
end
end
class Truck
include Speed
def go_very_slow
puts "I am a heavy truck and like going very slow."
end
end
test_car = Car.new("As... | true |
914b3295943946cee88a1e7e97e8c932b2835f55 | Ruby | fluxfederation/squash_repeater | /lib/squash_repeater/exception_queue.rb | UTF-8 | 3,818 | 2.5625 | 3 | [
"MIT"
] | permissive | require "time"
require "timeout"
require "backburner"
module SquashRepeater
WORKER_ERRORS = [
Beaneater::NotConnected,
Beaneater::InvalidTubeName,
Beaneater::JobNotReserved,
Beaneater::UnexpectedResponse
]
class CaptureTimeoutError < SquashRepeater::Error
def to_s
original_message = su... | true |
8ed8299f8962eeb9e9f2c256f560ddd2e69bc963 | Ruby | singhanilk1959/rpl | /intro_1/bk/ex1.rb | UTF-8 | 260 | 2.6875 | 3 | [] | no_license | #!/usr/bin/ruby
out=`cat ex1.rb`
puts out
print "Press Enter:"
out1 = gets
#######################################################
hello = "hello world"
print hello
print hello,"\n"
puts hello
########################################################
| true |
f1d1f8302d84474c91c7fb30eb28069f5b5cbe4f | Ruby | Jacobus-afk/ruby-linkedlist | /lib/linked_list.rb | UTF-8 | 1,954 | 3.96875 | 4 | [] | no_license | # frozen_string_literal: true
# https://commandercoriander.net/blog/2012/12/23/reversing-a-linked-list-in-ruby/
# ruby implementation of linked list
class LinkedList
include Enumerable
attr_reader :head, :tail
def initialize
@head = nil
@tail = nil
end
def append(value)
node = Node.new(value)... | true |
59b90cea5b7d457ebb29913e1c717c59037f8336 | Ruby | steve-alex/module-one-final-project-guidelines-london-web-082619 | /app/search.rb | UTF-8 | 7,262 | 3 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Search
attr_reader :origin_code, :destination_code, :outbound_date, :inbound_date, :cabin_class
#Sets the maximum number of results returned by any search
@@max_results = 5
###### Instance methods ######
def initialize(origin_code:, destination_code:, outbound_date:, inbound_date: "", cabin_class:)
... | true |
65bdb62760adb0f1fe647e1936f0721dab943643 | Ruby | gonecd/subsmgr | /vendor/bundle/ruby/1.8/gems/i18n-0.6.0/test/locale/tag/simple_test.rb | UTF-8 | 998 | 2.796875 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
require 'test_helper'
class I18nLocaleTagSimpleTest < Test::Unit::TestCase
include I18n::Locale
test "returns 'de' as the language subtag in lowercase" do
assert_equal %w(de Latn DE), Tag::Simple.new('de-Latn-DE').subtags
end
test "returns a formatted tag string from #to_s" do
assert_equal ... | true |
0f71d13724d7e3689b2f67789dd8fb298dd118fb | Ruby | Muelletie/G16_Schuldata_TAM | /eup_fit4h/ruby/Code/AG_11.rb | UTF-8 | 3,362 | 3.765625 | 4 | [] | no_license | # 1. Klasse Kunde
class Kunde
# 1a.Legen Sie eine Eigenschaft name und adresse in der Klasse Kunde an. Für die Eigenschaft
# name gibt es einen Lese- und Schreibzugriff, fuer die Eigenschaft adresse einen Schreibzugriff.
attr_accessor :name
attr_accessor :gehalt
attr_writer :adresse
# b. Die Eigenschaft name en... | true |
af41c23bdf94c07bec38b40e5d4f425037147db8 | Ruby | SpOOnman/puzzles | /stripectf3/level0/second | UTF-8 | 562 | 2.625 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
# Our test cases will always use the same dictionary file (with SHA1
# 6b898d7c48630be05b72b3ae07c5be6617f90d8e). Running `test/harness`
# will automatically download this dictionary for you if you don't
# have it already.
path = ARGV.length > 0 ? ARGV[0] : '/usr/share/dict/words'
entries = File.r... | true |
f7615f5d5ab1447a4379ad2eb9cf8519c3d9dd1c | Ruby | w11th/ruby_scripts | /open_safely.rb | UTF-8 | 277 | 2.75 | 3 | [] | no_license | require 'fileutils'
require 'tempfile'
class File
def self.open_safely(path)
result = nil
temp_path = nil
Tempfile.open("#{$0}-#{path.hash}") do |f|
result = yield f
temp_path = f.path
end
FileUtils.move(temp_path, path)
result
end
end
| true |
b2b5c117d5c85a824ae142d474c2bf838f8cab19 | Ruby | jonnymoore12/student-directory | /exercises/8-3count.rb | UTF-8 | 993 | 4.21875 | 4 | [] | no_license | def input_students
puts "Please enter the names of the students"
puts "To finish, just hit return twice"
students = []
name = gets.chomp
while !name.empty? do
students << {name: name, cohort: :november}
puts "We now have #{students.count} students"
name = gets.chomp
end
students
e... | true |
e081492ba84b18247b7ef2d721a8c2ffbdcba582 | Ruby | oscarlanca/fase1 | /re.rb | UTF-8 | 1,223 | 3.40625 | 3 | [] | no_license | class account
def initialize (account)
@string = account
@match_account = /\(\d{4}\)-\d{3}-\d{4}/
end
def account?
@string =~ @match_account ? true : nil
end
def numero_valido
@string =~ @match_account ? p "#{@match_account}" : nil
end
def array_account
@empty_array = []
if @string.numero_valido... | true |
bb6b16bf91e08b870dcf4b60e570158d9b1e27a4 | Ruby | antoniomachine/bigml-ruby | /test/test_22_source_args.rb | UTF-8 | 1,521 | 2.84375 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative "../lib/bigml/api"
require "test/unit"
class TestSourceArgs < Test::Unit::TestCase
def setup
@api = BigML::Api.new
@test_name=File.basename(__FILE__).gsub('.rb','')
@api.delete_all_project_by_name(@test_name)
@project = @api.create_project({'name' => @test_name})
end
def teardown
... | true |
eabe0ed4045f880713c6256e1afacd905106f3ea | Ruby | depaolif/green_grocer-web-0217 | /grocer.rb | UTF-8 | 1,580 | 3.515625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
def consolidate_cart(cart)
# code here
res = {}
cart.each do |item|
name = item.keys[0]
if !res.keys.include?(name)
res[name] = item[name]
res[name][:count] = 1
else
res[name][:count] += 1
end
end
res
end
def apply_coupons(cart, coupons)
# code here
# first create ... | true |
91cf7f8afbdbfb6f3febce3b6735d8ed49055d2e | Ruby | mgalibert/geonames | /parent_and_child.rb | UTF-8 | 1,016 | 2.84375 | 3 | [] | no_license | require "csv"
require "colorize"
require_relative './lib/constants'
require_relative './lib/utils'
STATIONS = load_csv("stations2.csv")
STATIONS_BY_ID = STATIONS.inject({}) { |hash, station| hash[station[:id]] = station; hash }
CSV.open(POLISHED_STATIONS_FILE, 'w', CSV_PARAMS) do |csv|
# Copy headers from original... | true |
8972db4476c6bf6b5d9c2d0c4155dd411e1dc117 | Ruby | digital-fabric/polyphony | /examples/performance/thread_switch.rb | UTF-8 | 758 | 3.53125 | 4 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'fiber'
class Fiber
attr_accessor :next
end
# This program shows how the performance of Fiber.transfer degrades as the fiber
# count increases
def run(num_threads)
count = 0
GC.start
GC.disable
threads = []
t0 = Time.now
limit = 10_000_000 / num_threads
num_th... | true |
788bf424208c35bec723492e175c1229f73862a0 | Ruby | hquenin/mapel | /lib/mapel/engine/image_magick.rb | UTF-8 | 4,999 | 2.609375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Mapel
class Engine
class ImageMagick < Engine
module ClassMethods
def info(source)
new.with_command("identify", source.inspect).run.to_info_hash
end
def exif(source)
new.with_command("identify -format %[exif:*]", source.inspect).run.to_exif_hash
en... | true |
b7fa9f963fe9ee6a78e55c7584fa5fde8603fe46 | Ruby | mchmilar/squeeze-play | /lib/flipper.rb | UTF-8 | 6,017 | 3.125 | 3 | [] | no_license | #! /usr/bin/ruby
require_relative 'player_page'
require 'byebug'
require 'pry-byebug'
class Flipper
attr_reader :page,
:starting_potential_profit,
:starting_sellable,
:starting_min_sell_price,
:starting_max_buy_price
class EmptyBuyOrdersError < StandardError; end
class EmptySellOrdersError < St... | true |
714384bcecef2b819fc201f12c13da9854d3bced | Ruby | mintona/flash_cards | /lib/card_generator.rb | UTF-8 | 712 | 3.25 | 3 | [] | no_license | class CardGenerator
attr_reader :filename
def initialize(filename)
@filename = filename
end
def cards
lines = []
File.readlines(@filename).each do |line|
lines << [line.chomp]
end
lines
split_lines = []
lines.each do |line|
split_lines << line.join.split(',')
end
... | true |
17c33d0206a430ac7721bdff71025e379bc89491 | Ruby | jkappers/datetime_format_testing | /app/validators/date_or_time_validator.rb | UTF-8 | 370 | 2.53125 | 3 | [] | no_license | # Validates an attribute to ensure the value is a Date, Time, or DateTime
# TODO: Can we specify the friendly_x_format in the message?
class DateOrTimeValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless [DateTime, Date, Time].any? { |kind| value.is_a? kind }
record.erro... | true |
e891f276147da0b85e665bb13126717a1d801ff7 | Ruby | MikeyC24/CSVtest | /upload_backed_up_tasks_with_new_ids.rb | UTF-8 | 580 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'csv'
oldids_newids = {}
CSV.foreach("livecsv/Oldidswithnewids.csv" ) do |row|
oldid = row[1]
newid = row[0]
oldid_newid = {
oldid => newid
}
oldids_newids.merge!( oldid_newid)
end
rows = []
CSV.foreach("livecsv/Task.csv" ) do |row|
contactsoldid = row[1]
task = []
ta... | true |
7f33b783c2a02e32a5b8640530847e01fa885612 | Ruby | kandalf/funky-world-cup | /lib/map.rb | UTF-8 | 994 | 2.875 | 3 | [
"MIT"
] | permissive | module FunkyWorldCup
class Map
COLORS_SCALE = ["#ff9059", "#7559ff", "#59ff90"].freeze
SCALE = {
"groups" => 1,
"16_round" => 3,
"quarter_finals" => 5,
"semi_finals" => 7,
"third_place" => 9,
"final" => 12,
"champion" => 20,
}.f... | true |
d8282838fa24826b1db67bbea5ddad7aca8a2805 | Ruby | PurplePineapple123/connect-four | /lib/game.rb | UTF-8 | 1,109 | 3.484375 | 3 | [] | no_license | # lib/connect_four.rb
require_relative 'board.rb'
class Game
def initialize(game_board = Board.new)
@game_board = game_board
@player_turn = 1
@player = 0
end
def player_selection
loop do
puts "Choose a column, Player #{@player_turn}:"
@user_input = gets.chomp
if @user_inpu... | true |
b4ddc3d1db89b755f7efe79cf74df57878b763fb | Ruby | 1ulce/adventofcode2020 | /day8/day8b.rb | UTF-8 | 1,509 | 3.09375 | 3 | [] | no_license | f = File.open("day8_input")
s = f.read # 全て読み込む
f.close
lines = s.split("\n")
map = {}
lines.each_with_index do |line, idx|
words = line.split(" ")
info = {nop: false, next: idx + 1, used: false, acc: 0}
case words[0]
when "acc"
info[:acc] = words[1].to_i
when "jmp"
info[:next] = idx + words[1].to_i
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.