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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
5c05dcf96b1e7553760d4f03a6a585963e04247d | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/grains/f1e8c9c918b3411cb033e1bcb12ab1e7.rb | UTF-8 | 172 | 3.375 | 3 | [] | no_license | class Grains
def initialize
@arr = Array.new(64) { |index| 2 ** index }
end
def square(count)
@arr[count-1]
end
def total
@arr.reduce(:+)
end
end
| true |
7b41414ff20304ee0f89865fe92be260665aec80 | Ruby | karthick-soolapani/code-problems | /120-oop/07-medium1/07_medium1_q03_students.rb | UTF-8 | 1,278 | 4.125 | 4 | [] | no_license | # LS Course - Exercises
# RB120 Object Oriented Programming
# Chapter - Medium 1, Question 3, Students
# QUESTION
# Below we have 3 classes: Student, Graduate, and Undergraduate. Some details for these classes are missing. Make changes to the classes below so that the following requirements are fulfilled:
# Graduate ... | true |
123ecc64c0938f7b4439d3f750592885a82baa54 | Ruby | alanvoss/advent_of_code | /2019/2/part1.rb | UTF-8 | 639 | 3.28125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
inputs = File.open('inputs.txt').first.split(',').map(&:to_i)
# restore the gravity assist program
inputs[1] = 12
inputs[2] = 2
(0..(inputs.length / 4)).each do |n|
opcode, operand1, operand2, position = inputs[n * 4, 4]
if opcode == 1
inputs[position] = inputs[operand1] + inputs[operand... | true |
b9c8c173b62405d9c48f0ab49ad1eecf6ca08aee | Ruby | nesro/fiveinarow | /lib/fiveinarow/cell.rb | UTF-8 | 412 | 3.828125 | 4 | [
"MIT"
] | permissive | class Cell
attr_accessor :value
attr_reader :row
attr_reader :col
EMPTY = 0
PLAYER_A = 1
PLAYER_B = 2
def initialize(row, col, val)
@row = row
@col = col
@value = val
end
def set(v)
return false if @value == v
@value = v
true
end
def e?
@value == Cell::EMPTY
end
... | true |
8e76e3f6b58c59ec06ebe72233dd084e9ecdf420 | Ruby | vitorkaio/controle-estoque-ruby | /models/estoque/estoque.rb | UTF-8 | 1,097 | 3.75 | 4 | [] | no_license | # Modela um estoque para o tipo celular
class Estoque
def initialize()
@celulares = []
end
# Adiciona um celular no banco.
def insereCelular(celular)
@celulares.push(celular)
end
# Remove um celular do estoque.
def removeCelular(modelo)
pos = getPosicao(modelo)
if pos != -1
@celul... | true |
7dd28e623655921fe8b0de1256b978af36b744c2 | Ruby | doniaa3710/02-fizzbuzz-lab | /fizzbuzz.rb | UTF-8 | 517 | 4.375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # The goal of FizzBuzz is to build a program that can take a number and if the number is evenly divisible by 3, it should return "Fizz",
# if it's divisible by 5, it should return "Buzz", and if it's divisible by both
# 3 and 5, it should return "FizzBuzz".
def fizzbuzz(num)
if (num % 3 == 0)
return "Fizz"
els... | true |
893daed61372f8b8d426ea1752e846410fb6c6fe | Ruby | kaisan-diary/furima-32990 | /spec/models/item_spec.rb | UTF-8 | 2,965 | 2.625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Item, type: :model do
before do
@item = FactoryBot.build(:item)
end
describe '商品情報入力' do
context '商品情報入力がうまくいく時' do
it '全ての値が正しく入力されていれば出品できること' do
expect(@item).to be_valid
end
end
context '商品情報の入力がうまく行かない時' do
it 'imageが空だと... | true |
9e0ab149136dba8bb5b9a2ed16553eb880e71145 | Ruby | dklingem/ProjectEuler | /Euler2.rb | UTF-8 | 472 | 3.953125 | 4 | [] | no_license | # Each new term in the Fibonacci sequence is generated by
# adding the previous two terms. By starting with 1 and 2,
# the first 10 terms will be:
# 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ...
# By considering the terms in the Fibonacci sequence whose
# values do not exceed four million, find the sum of the even-valued... | true |
93529167dd1bdba7b7fc1e726e472332cc29889f | Ruby | swifthand/adalog | /lib/adalog/web.rb | UTF-8 | 2,304 | 2.59375 | 3 | [
"BSD-3-Clause"
] | permissive | require 'sinatra/base'
module Adalog
class Web < Sinatra::Base
Config = Struct.new(:repo, :heading, :time_format)
attr_reader :config
def initialize(app = nil, web_options = {})
super(app)
options = default_options.merge(web_options)
@config = Adalog::Web::Config.new
determine_c... | true |
548c33a35ebb82f2c8f60d4fe52241db9b956a17 | Ruby | unixsuperhero/hero | /experiments/ruby/stdin.rb | UTF-8 | 565 | 2.71875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'awesome_print'
module H
extend self
def test(args=ARGV.dup)
[args].push(IO.new(IO.sysopen('experiments/ruby/stdin.rb'))).map do |a|
[:class, :any?, :count, :none?].map(&a.method(:send))
end
end
end
puts H.test($stdin).ai(raw: true, plain: false, index: false) # => ni... | true |
f242fcdf41dba29cd8992c6f86d24c1db24b5e7e | Ruby | gowtham-prudhvi/Compilers-Project | /asgn4/test/new8.rb | UTF-8 | 55 | 2.625 | 3 | [] | no_license | i = 0
while i <= 3
i = i+1
end
print(i)
i = 10
print(i) | true |
39d617f3612b380903ecaa72f5dab74651ea6eae | Ruby | XohoTech/RubyTest | /helpers/custom_error.rb | UTF-8 | 137 | 2.6875 | 3 | [
"MIT"
] | permissive | class CustomError < StandardError
attr_reader :custom
def initialize(custom)
super
@custom = custom
puts custom
end
end | true |
481854bb2bb0daeb68929f79d99a60df5069f9ca | Ruby | jonatas/churumelas | /app/challenges/all.rb | UTF-8 | 1,433 | 3.015625 | 3 | [] | no_license | require "sandbox"
Challenges = [ ]
def challenge opts
challenge = Class.new
opts[:level] = Challenges.size + 1
opts.each do |opt, with_value|
challenge.define_singleton_method opt, lambda { with_value }
end
challenge.define_singleton_method :to_s, lambda { [self.level,self.title].join(" - ") }
if not c... | true |
2ca49f2546447287e0f4748aa9382b2376397a7b | Ruby | suppy/CodeIQ | /CodeIQ-q713/CodeIQ-q713-3.rb | UTF-8 | 528 | 3.65625 | 4 | [] | no_license | # コード銀行:階段ピョンピョン123!
# 段数 n のときの上がり方の数
# n-1段から 1段を一歩で上がる
# n-2段から 2段を一歩で上がる
# n-3段から 3段を一歩で上がる
# 上記3パターンの和
#
# Step(n) = Step(n-1) + Step(n-2) + Step(n-3)
def Step(n)
step = [ 0, 1, 2, 4 ]
if n <= 3
return step[n]
end
for i in (4..n)
step[i] = step[i-1] + step[i-2] + step[i-3]
# p s... | true |
7427d3000b1e20e8a888e07b83e239596e19bc7d | Ruby | mikefieldmay/tech_test_bank | /lib/account.rb | UTF-8 | 913 | 3.21875 | 3 | [] | no_license | class Account
attr_reader :balance
DEFAULT_BALANCE = 0
def initialize(balance=DEFAULT_BALANCE, transaction_log, transaction_class)
@balance = balance
@transactions_log = transaction_log
@Transaction = transaction_class
end
def view_transactions
@transactions_log.transactions
end
def w... | true |
d43b8cabfdf6363754c99fbacdd6c27ab307587a | Ruby | DmitryKachalov/black_jack | /interface.rb | UTF-8 | 1,445 | 3.703125 | 4 | [] | no_license | require_relative 'black_jack.rb'
require_relative 'rules'
class Interface
include Rules
def introduction
print "Введите имя: "
gets.chomp
end
def show_money(player)
puts "#{player[:name]}, у вас #{player[:amount]} фишек"
end
def show_cards(players)
players.each do |player|
cards = ... | true |
e78ff9e7a4d0c9719276e8be988b129973c9c980 | Ruby | hukl/CCCB-Webdisplay | /display.rb | UTF-8 | 1,398 | 2.78125 | 3 | [] | no_license | raise "Ruby 1.9.x required" if '1.9' > RUBY_VERSION
require 'socket'
class Display
attr_reader :udp_socket
def initialize ip, port
@ip = ip
@port = port
@udp_socket = UDPSocket.new
end
def self.connect ip, port, &block
display = Display.new ip, port
begin
display.ins... | true |
cb86dafec6dada97f3af547ed71586aace2cad45 | Ruby | gipsyMartinez/codewars-katas | /test/tc_friend_or_foe.rb | UTF-8 | 840 | 4.125 | 4 | [] | no_license | # FRIEND OR FOE?
# Make a program that filters a list of strings and returns a list with only your friends name in it.
# If a name has exactly 4 letters in it, you can be sure that it has to be a friend of yours!
# Ex: Input = ["Ryan", "Kieran", "Jason", "Yous"], Output = ["Ryan", "Yous"]
require_relative "../src/fri... | true |
f98dc2f3bc4b89f2c036cc30f7bc3eea26539352 | Ruby | systemnate/exercism | /nucleotide-count/nucleotide_count.rb | UTF-8 | 421 | 3.625 | 4 | [] | no_license | class Nucleotide
attr_reader :dna
def initialize(dna)
@dna = dna
end
def self.from_dna(dna)
if dna =~ /[^ATCG]/
raise ArgumentError,
"valid characters are ATCG, but #{dna} was provided"
end
new(dna)
end
def count(char)
dna.count(char)
end
def histogram
{
... | true |
65b07888377956d39b33176115948717dfd3a602 | Ruby | yushch/assignment_association_practice | /db/seeds.rb | UTF-8 | 1,971 | 2.890625 | 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 rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
3d38d323e0d8645e58fffc5b6273dbdb13c5594a | Ruby | barmintor/ldpd-hyacinth | /lib/hyacinth/csv/header.rb | UTF-8 | 2,955 | 2.78125 | 3 | [] | no_license | module Hyacinth
module Csv
class Header
attr_accessor :fields
def initialize(fields = [])
self.fields = fields.map { |field| (field.is_a? String) ? Header.header_to_input_field(field) : field }
# Cache currently known boolean and integer DynamicField string keys at time of instance in... | true |
516ce8831c9e8bad8530f5beea42d9c7fcb5c135 | Ruby | ljnissen/rubycode | /008/file_05.rb | UTF-8 | 253 | 3.28125 | 3 | [] | no_license | print "Please enter the final score: "
final_score = gets.to_i - 1
touchdowns = final_score / 7
pushups = 0
(0..touchdowns).each do |i|
i = 7
i <= final_score
i = i + 7
pushups = pushups + i - 7
end
print "Number of pushups is: ", pushups | true |
1e59de75a1c693a5641015b9db91ebfc6c338c54 | Ruby | julweber/tesseract-experimentation | /experiments/test2.rb | UTF-8 | 240 | 3.03125 | 3 | [] | no_license | require 'rtesseract'
require 'byebug'
text = ""
image = RTesseract.new('../assets/01.png', lang: "deu")
text = image.to_s # Getting the value
byebug
puts text
words = RTesseract::Box.new('../assets/01.png', lang: 'deu').words
pp words
| true |
db69e4bf1ad35e050112d6c6a52ad42c47ef01af | Ruby | MartinRuiAndorsen/learn_ruby | /06_timer/timer.rb | UTF-8 | 795 | 3.5625 | 4 | [] | no_license | class Timer
attr_reader :seconds, :time_string
def initialize
@seconds = 0
end
def seconds= (seconds)
@seconds = seconds
finalMinutes = 0
finalHours = 0
if seconds > 59
finalSeconds = seconds % 60
minutes = seconds / 60
if minutes > 59
finalMinutes = minutes % 60
... | true |
d460a17bdb07fa9aa2ea5762d5d80373fcbd8cf9 | Ruby | inohiro/atcoder | /beginner_026/d.rb | UTF-8 | 464 | 3.65625 | 4 | [] | no_license |
include Math
def main
a, b, c = gets.split.map(&:to_i)
t = 0
while true do
# puts t
if f(a, b, c, t) >= 100
if t >= 0.9
puts t.to_f
break
end
end
t += 0.1
end
end
def f(a, b, c, t)
# puts '------------------------------------------'
# puts t
# puts a * t
# ... | true |
3082a455ed5afe01099c4a51f8315c4b124baf3f | Ruby | Fendev-repo/launch_school_120_object_oriented_programming | /assignment_OO_ttt_bonus_features/ex06_player_pick_marker/cli_display_module.rb | UTF-8 | 2,328 | 3.5625 | 4 | [] | no_license | # Provides CLI interactive functionality
module DisplayMessagesCli
def ask_human_for_name
puts 'What is your name?'
name = nil
loop do
name = gets.chomp.capitalize
break if name.match?(/[a-z]+/)
puts "You didn't enter a name: Please enter a name"
end
@human_name = name
end
d... | true |
e95cadaf95cc6898ab7636a509884c8a39234d18 | Ruby | jamesduncombe/paymo | /lib/paymo/cache.rb | UTF-8 | 374 | 3.15625 | 3 | [
"MIT"
] | permissive | class Cache
def initialize(instance, method)
@data = {}
@instance = instance
@method = method
end
def get(key)
begin
@data.fetch(key)
rescue KeyError
set(key)
get(key)
end
end
def set(key)
@data.store key, value(key)
end
private
def value(key)
... | true |
438960b739679726dc70a22948904dddb5fe3a55 | Ruby | Jonkavaliauskas/ruby-oo-practice-relationships-silicon-valley-exercise-yale-web-yss-052520 | /tools/console.rb | UTF-8 | 874 | 2.59375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative '../config/environment.rb'
def reload
load 'config/environment.rb'
end
# Insert code here to run before hitting the binding.pry
# This is a convenient place to define variables and/or set up new object instances,
# so they will be available to test and play around with in your console
airbnb = Star... | true |
e87eb77c399b827135d957149d26c0d6fd59c0c9 | Ruby | cbrenner04/advent_of_code | /2021/07/solution.rb | UTF-8 | 638 | 3 | 3 | [] | no_license | # frozen_string_literal: true
crab_positions = INPUT.split(",").map(&:to_i)
largest_position = crab_positions.max
total_fuels = []
(0..largest_position).each do |position|
total_fuels.push(crab_positions.map { |crab| (crab - position).abs }.reduce(:+))
end
p total_fuels.min
# we'll see if this completes in any rea... | true |
8c2d0218ba1466be4d7c8f6746bef07a8f0eb980 | Ruby | RajaomalalaSendra/gemfile_test | /spec/multiples_spec.rb | UTF-8 | 1,141 | 3.390625 | 3 | [] | no_license | require_relative '../lib/multiples'
describe "is_multiple_of_3_or_5?" do
it "should return TRUE when an integer is a multiple of 3 or 5" do
expect(is_multiple_of_3_or_5?(3)).to eq(true)
expect(is_multiple_of_3_or_5?(5)).to eq(true)
expect(is_multiple_of_3_or_5?(51)).to eq(true)
expect(is_multiple_of_... | true |
73919c56d9e02cfa66fb546213dad6d57f12102f | Ruby | sangiraldo/BootcampWeb | /Ruby/Edad.rb | UTF-8 | 90 | 2.8125 | 3 | [] | no_license | AnoActual = 2016
AnoNacimiento = 1995
Edad = 2016 - 1995
puts "Su edad es: " + Edad.to_s
| true |
e884af2a649fe9f999d7251477ee222d83995ee2 | Ruby | XAINI/base_questions | /160706/array/ruby/seven.rb | UTF-8 | 352 | 3.75 | 4 | [] | no_license | # 7. 实现一个方法,传入字符串数组,返回统计有字符串出现次数的Hash
str_ary = ["aad", "aad", "dddd", "ec", "ft"]
def statistics_ary(str_ary)
hash_str_ary = {}
str_ary.each do |ary|
hash_str_ary[ary] = str_ary.count(ary)
end
hash_str_ary
end
statistics_result = statistics_ary(str_ary)
p statistics_result | true |
bbc4456f951c5e25953056e4f2a3c38a3fbfa06f | Ruby | 7hoenix/sales_engine | /lib/invoice.rb | UTF-8 | 1,936 | 2.578125 | 3 | [] | no_license | class Invoice
attr_reader :invoice_data, :invoice_repository
def initialize(invoice_data, invoice_repository)
@invoice_data = invoice_data
@invoice_repository = invoice_repository
end
def id
invoice_data[:id].to_i
end
def customer_id
invoice_data[:customer_id].to_i
end
def merchant_i... | true |
bfcd35191057ca6adcc05c974465b1f20cac28ff | Ruby | ketwalters/Teenager | /teenager.rb | UTF-8 | 386 | 3.71875 | 4 | [] | no_license | #Write a method called is_a_teenager that takes age as a parameter and returns
#true/false depending on whether the age indicates that the person is a
#teenager
#To test your solution run `rspec teenager_spec.rb` in your terminal
def is_a_teenager? (age)
#age < 13 #first failing test
#age > 11 #second failing t... | true |
cc5d535ce34db305c07ed11df0d82a1cce33971d | Ruby | jmb488/hello-ruby | /learn/5.rb | UTF-8 | 342 | 3.578125 | 4 | [] | no_license | # Run the code in this file by typing:
# ruby 5.rb
# into your command-line interface.
better_with_bacon = ["burger", "tacos", "doughnuts", "sandwiches"]
# puts "Bacon #{better_with_bacon[0]}"
# puts "Bacon #{better_with_bacon[1]}"
# puts "Bacon #{better_with_bacon[2]}"
for food_item in better_with_bacon
puts "B... | true |
232f3f3f4f15c90f14fe37fb0372ea57dd79ee5b | Ruby | christiemolloy/porta | /app/lib/payment_gateways/adyen12_crypt.rb | UTF-8 | 3,179 | 2.53125 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
module PaymentGateways
class Adyen12Crypt < PaymentGatewayCrypt
CARD_DATA_ATTRIBUTES = %w[expiryMonth expiryYear number recurringDetailReference].freeze
private_constant :CARD_DATA_ATTRIBUTES
attr_reader :gateway_client, :authorize_response
def initialize(user)
... | true |
1125491da520dde301a9e0a37f42f336bf3e018b | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/grade-school/470d0741a2064a2baaac638b92c035ea.rb | UTF-8 | 364 | 3.390625 | 3 | [] | no_license | class School
def initialize
@grade_hash = {}
end
def to_hash
@grade_hash
end
def add(name, grade)
if @grade_hash[grade]
@grade_hash[grade] << name
else
@grade_hash[grade] = [name]
end
@grade_hash
end
def grade(grade)
if @grade_hash[grade]
@grade_hash[grade... | true |
17b3bd37d4f99826f46f504b8a456d93420a77ee | Ruby | tjp2021/battle_ship | /test/gameboard_test.rb | UTF-8 | 4,255 | 2.984375 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/gameboard.rb'
class GameBoardTest < MiniTest::Test
def test_it_exist
gameboard = GameBoard.new
assert_instance_of GameBoard, gameboard
end
def test_can_place_two_unit_ship_horizontal
gameboard = GameBoard.new
gameboard.place_tw... | true |
d5c5a950b2f86d9510abbad0dbb1bbbef957bac7 | Ruby | JLBrigham/bank_tech_test | /lib/transaction_history.rb | UTF-8 | 437 | 2.90625 | 3 | [] | no_license | # frozen_string_literal: true
class TransactionHistory
attr_accessor :record
DATE = Time.new.strftime('%d/%m/%Y')
def initialize(record = [])
@record = record
end
def deposit(amount, balance, date = DATE)
@record << { date: date, credit: amount, debit: nil, balance: balance }
end
def withdraw... | true |
10802af792202c5f3b198013e6907dcdb085921f | Ruby | NarendranKanagaraj/ruby_ds | /linked_list/quick_sort_of_linked_list.rb | UTF-8 | 1,635 | 3.453125 | 3 | [] | no_license | require 'singly_linked_list.rb'
#Quick sort of linked list
def create_list arr
list = SinglyLinkedList.new
arr.each do |i|
list.insert_at_end i
end
list
end
def quick_sort list
if !list || !list.root || !list.root.next_link
return list
end
list.root = quick_sort_helper list.root, get_last(list... | true |
2f4cc69651a4ae2a841caa5b359b4bf1b137f37b | Ruby | tetetratra/contest | /arc074/a/a.rb | UTF-8 | 1,988 | 3.140625 | 3 | [] | no_license | require 'pp'
# 0 4 2
h, w = gets.split.map(&:to_i).sort
# h < w
ans = []
a = (w/3.0).ceil*h
b = (w/3.0).ceil*h
c = w * h - a - b
ans << [a,b,c].sort.tap{|x|break x[2] - x[0]}
p [a,b,c]
a = (w/3.0).floor*h
b = (w/3.0).ceil*h
c = w * h - a - b
ans << [a,b,c].sort.tap{|x|break x[2] - x[0]}
p [a,b,c]
a = (w/3.0).ceil*h
... | true |
c72347d228fba563cedb0fae1986a453e0a55950 | Ruby | VoroninNick/unicycling-registration | /spec/lib/flatland_score_calculator_spec.rb | UTF-8 | 4,684 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe FlatlandScoreCalculator do
describe "when calculating the placement points of an event" do
before(:each) do
@competition = FactoryGirl.create(:competition)
@comp1 = FactoryGirl.create(:event_competitor, :competition => @competition)
@comp2 = FactoryGirl.create(:ev... | true |
992b0a70d154d470e7feb870eb19ec0e88a0801d | Ruby | MichaelrMentele/katas | /elevator_OO_design.rb | UTF-8 | 4,549 | 3.359375 | 3 | [] | no_license | # Designing an Elevator
# An OO design exercise
# Description:
# An elevator is a box that holds objects and goes up and down inside a building,
# carrying those objects to different levels or floors vertically. An elevator
# has two interfaces: an external interface that 'calls' the elevator to a
# given floor, and ... | true |
e9098be8212fb73fa88e0027a6eb828d98000836 | Ruby | karlverdiere/vendredigoweek | /exo_bonus1.rb | UTF-8 | 180 | 3.3125 | 3 | [] | no_license | def pair_or_not_pair(number)
if (number == 0)
return "0"
elsif (number % 2 == 0)
return "pair"
else
return "unpair"
end
end
number = 60
puts"#{pair_or_not_pair(number)}"
| true |
1275e2280daf68a479a25a9c5d2037e5a403c0ad | Ruby | chuck032/Sparta_oop_intro | /oop_lab/movie.rb | UTF-8 | 189 | 2.921875 | 3 | [] | no_license | # This is our movie class which will inherit from director
require_relative './director'
class Movie < Director
def self.title
puts "Movie1, Movie2, Movie3"
end
Movie.title
end
| true |
f36de762798620a7193c44e5122bd2f34370d0a7 | Ruby | jhlim90/coderbyte | /ArrayAdditionI.rb | UTF-8 | 330 | 3.25 | 3 | [] | no_license | def ArrayAdditionI(arr)
arr.sort!
num=arr.length-1
total=0
arr.each { |x| total+=x }
if total==2*arr[num]
# code goes here
return true
else
return false
end
end
# keep this function call here
# to see how to enter arguments in Ruby scroll down
ArrayAdditionI(STDIN.gets) ... | true |
c9d2fdba3519bb8eefac48c0c79af293caeae959 | Ruby | Frapso/Ruby_on_Rails2.1 | /Ruby2.1.0/lib/ruby/gems/2.1.0/gems/sprockets-3.0.0.beta.4/lib/sprockets/processing.rb | UTF-8 | 7,865 | 2.578125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'sprockets/engines'
require 'sprockets/lazy_processor'
require 'sprockets/legacy_proc_processor'
require 'sprockets/legacy_tilt_processor'
require 'sprockets/mime'
require 'sprockets/utils'
module Sprockets
# `Processing` is an internal mixin whose public methods are exposed on
# the `Environment` and `Cac... | true |
76f066754d5a74c6309e93429534b3f127241e2f | Ruby | sreid/aws-security-check | /lib/check_rule.rb | UTF-8 | 707 | 2.828125 | 3 | [] | no_license | class CheckRule
attr :results
def initialize
@results = []
end
def pass_single(resource_name)
@results = [CheckResult.new(:pass, resource_name)]
end
def fail_single(resource_name, parameters = {})
@results = [CheckResult.new(:fail, resource_name)]
end
def passed?
@results.each do |re... | true |
400c4acdb4b1450cf681d63b245626e0a2771795 | Ruby | BerilBBJ/scraperwiki-scraper-vault | /Users/E/Escudero/boesubvenciones2.rb | UTF-8 | 2,360 | 2.671875 | 3 | [] | no_license | #encoding:utf-8
#Este programa tiene por objetivo obtener las subfenciones a partidos políticos 2007-2012
#Se basa en un paso anterior: BOESubvenciones1
#LIBRERIAS
require 'mechanize'
#CONSTANTES
ScraperWiki::attach("boesubvenciones1")
agent = Mechanize.new
disposiciones = ScraperWiki::select("* from boesubvenciones... | true |
86b45ef323e626569427694ad27e182a03cae118 | Ruby | jasyl/algorithm-practice | /greedy/product-greedy2.rb | UTF-8 | 448 | 3.09375 | 3 | [] | no_license | def product_except_self(nums)
return nil if nums.length == 0
return nums[0] if nums.length == 1
result = Array.new(nums.length, 1)
product = 1
nums.each_with_index do |num, index|
result[index] = product
product *= num
end
i = nums.length - 1
product = 1
until i == 0
re... | true |
cd5afc11b44da6d1ae2491e63781e0df71190c6e | Ruby | elodiebhs/LearnRuby-Codacademy | /8_Create_an_historygram.rb | UTF-8 | 546 | 4.59375 | 5 | [] | no_license | #In this project, we’ll write a program that takes a user’s input, then builds a hash from that input.
#Each key in the hash will be a word from the user; each value will be the number of times that word occurs.
puts "here is your statement:"
text = gets.chomp
words = text.split #creates an array of the text
frequ... | true |
05c8e39f31c07d6301d337bdf833b4ff836b89b8 | Ruby | epunx2/anagram-detector-v-000 | /lib/anagram.rb | UTF-8 | 369 | 3.578125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Your code goes here!
class Anagram
attr_accessor :word
def initialize(word)
@word = word
end
def match(matches)
new_word = ""
old_word = @word.split("").sort
new_matches = []
matches.each do |word|
new_word = word.split("").sort
if old_word == new_word
new_matches << ... | true |
69998dea64b7e6bb8fb571079dd0d96c422ffaa2 | Ruby | sunny-b/backend_practice | /Programming_Foundations/Lesson_3_exercises/easy_3.rb | UTF-8 | 324 | 2.9375 | 3 | [] | no_license | #Q1
flintstones = %w(Fred Barney Wilma Better BamBam Pebbles)
#Q2
flintstones << "Dino"
#Q3
flintstones.insert(-1, "Dino", "Hoppy")
flintstones.concat(["Dino", "Hoppy"])
flintstones.push("Dino", "Hoppy")
#Q4
advice.splice!(0, advice.index("house"))
#Q5
statement.count 't'
statement.scan("t").count
#Q6
ti... | true |
722cc814f69dc6f9f03232b788c2f1dd06bd3f5c | Ruby | adamleet/ruby-workshop | /boolean_operators.rb | UTF-8 | 260 | 3.25 | 3 | [] | no_license | def truthiness(x,y)
puts 'AND:', x && y
puts 'OR:', x || y
puts '!AND:', !(x && y)
puts '!OR:', !(x || y)
end
truthiness(true,true)
truthiness(true,false)
truthiness(false,false)
truthiness(false,true)
truthiness(0,true)
truthiness(nil,false)
| true |
ca89504877eee911fc57d5db946ac54c4d4c3afd | Ruby | ArthurSpirke/vending_machine | /spec/lib/money_item_spec.rb | UTF-8 | 1,263 | 3.34375 | 3 | [] | no_license | require 'spec_helper'
RSpec.describe MoneyItem do
describe "initialization" do
context "when nil is given as argument" do
it "raises an error" do
expect { described_class.new(nil) }.to raise_error("cannot be nil")
end
end
context "when cents_amount is less than 0" do
it "raise... | true |
8fed8f137068398f7c7f13ac3270403cc529738f | Ruby | shiroyasha/rocker | /docker_hub/registry_client.rb | UTF-8 | 964 | 2.578125 | 3 | [] | no_license | module DockerHub
class RegistryClient
URL = "https://registry-1.docker.io/v1"
def initialize(access_token)
@access_token = access_token
end
def image_id(repository_name, tag)
path = "/repositories/#{repository_name}/tags/#{tag}"
get(path).body.gsub(/"/, "")
end
def image_... | true |
00ff8f58c865f97f696c7e5984f14efb6514d936 | Ruby | jlshaw117/oncue_coding_challenge | /app/models/job.rb | UTF-8 | 1,961 | 2.578125 | 3 | [] | no_license | # == Schema Information
#
# Table name: jobs
#
# id :bigint(8) not null, primary key
# truck_id :integer not null
# name_of_user :string not null
# date_of_move :date not null
# start_time :float not null
# est_end_time :float not null
# ... | true |
2fca454e7befaa7c018fb7b385897aaf258df45f | Ruby | twrodriguez/duct_tape | /lib/ext/object.rb | UTF-8 | 324 | 2.96875 | 3 | [
"BSD-2-Clause"
] | permissive | class Object
def deep_dup
Marshal.load(Marshal.dump(self))
end
def just_my_methods
ret = self.methods
(self.class.ancestors - [self.class]).each { |klass|
if Module === klass
ret -= klass.methods
elsif Class === klass
ret -= klass.new.methods
end
}
ret
end
... | true |
ae26aaa7bb45abbfd6ea9176d7c381e6878209a8 | Ruby | nounch/sinatra-rroute | /spec/rroute_spec.rb | UTF-8 | 7,702 | 2.640625 | 3 | [
"MIT"
] | permissive | require 'rspec'
require 'rack/test'
require 'sinatra/base'
require_relative '../lib/sinatra/rroute'
require_relative 'test_app'
RSpec.configure do |config|
config.include Rack::Test::Methods
end
describe "Rroute" do
# Setup
def app
TestApp
end
before(:each) do
@user = { :name => 'John', :age => 3... | true |
bf01ea3edf8989b80285b6e41650251352f89ae5 | Ruby | tim0414/ruby_practice | /super_example.rb | UTF-8 | 467 | 3.828125 | 4 | [] | no_license | class A
def method1(a,b)
puts a+b
end
def method2()
puts "method2 in class A"
end
end
class B < A
def method1(a,b)
super
end
end
class C < A
def method1(a,b,c)
super
end
end
class D < A
def method2(a,b)
super
end
end
b = B.new
b.m... | true |
723d9b18f13e9e672dbdaa34f02f1c4e1362d4d2 | Ruby | JaneCargill/music | /console.rb | UTF-8 | 1,615 | 2.765625 | 3 | [] | no_license | require('pry-byebug')
require_relative('models/artists')
require_relative('models/albums')
require_relative('models/song')
Song.delete_all()
Album.delete_all()
Artist.delete_all()
artist1 = Artist.new({
'name' => 'Bon Jovi'
})
artist2 = Artist.new({
'name' => 'Oasis'
})
artist3 = Artist.new({
'name' => '... | true |
6c7caf3a0be92dd811a5525893828d631d3464df | Ruby | DouglasAllen/code-Programming_Ruby_3rd_ed | /Part_IV--Ruby_Library_Reference/ch27_Built-in_Classes_and_Modules/Alphabetical_Listing/Object/display-i.rb | UTF-8 | 441 | 3.296875 | 3 | [] | no_license | =begin
Object#display
(from ~/.rdoc)
------------------------------------------------------------------------------
obj.display(port=$>) -> nil
------------------------------------------------------------------------------
Prints obj on the given port (default $>).
Equivalent to:
def display(port=$>)
po... | true |
486ca09be4969367ac5f3e7f03bb57101576180e | Ruby | dmitryjum/codewars | /ruby/tortoise_racing/solution.rb | UTF-8 | 274 | 3.265625 | 3 | [] | no_license | def race(v1, v2, g)
puts [v1, v2, g]
return nil if (v2 < v1)
exact_time = g/(v1-v2).to_f.abs
hours = exact_time.floor
minutes = ((exact_time - hours)*60).floor.abs
seconds = ((((exact_time - hours)*60).abs - minutes)*60).floor.abs
[hours, minutes, seconds]
end | true |
9be5c9e71635f2d24a76c028fc7d5d9030e5215a | Ruby | AShalysh/Lesson1 | /perfectWeight.rb | UTF-8 | 337 | 3.703125 | 4 | [] | no_license | print "What is your name? "
user_name = gets.chomp
user_name.capitalize!
print "Dear #{user_name}, what is your height? "
user_height = gets.chomp.to_f
perfect_weight = user_height - 110
if perfect_weight >= 0
puts "#{user_name}, your perfect weight is #{perfect_weight}kg."
else
puts "Your weight is already ... | true |
9703feda903b29c3e678b962a019994f95d2999c | Ruby | akbarratt/rb101 | /lesson_4/method_practice/09.rb | UTF-8 | 556 | 3.9375 | 4 | [] | no_license | # What is the return value of map in the following code? Why?
{ a: 'ant', b: 'bear' }.map do |key, value|
if value.size > 3
value
end
end
# |nil, bear|
# Map is an iterative method that transforms every object in a colletion. Because every item will be transformed, we can expect the return colleciton of map t... | true |
3d4a307aaa06fc3144b5c45a6bb193123b7f84e6 | Ruby | eyalcohen4/fastlane-plugin-set_target_binary_version | /lib/fastlane/plugin/set_target_binary_version/actions/set_target_binary_version_action.rb | UTF-8 | 4,083 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'semantic'
require 'tempfile'
require 'fileutils'
require 'fastlane/action'
require_relative '../helper/set_target_binary_version_helper'
# set_target_binary_version
module Fastlane
module Actions
class SetTargetBinaryVersionAction < Action
def self.run(params)
UI.message("The set_target_b... | true |
e681d46961ba5259e3f915e5e09b85008bb2638c | Ruby | dgalimi13/ruby-advanced-class-methods-lab-online-web-sp-000 | /lib/song.rb | UTF-8 | 1,116 | 3.390625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Song
attr_accessor :name, :artist_name
@@all = []
def self.all
@@all
end
def save
self.class.all << self
end
def self.create
song = Song.new
song.save
song
end
def self.new_by_name(name)
song = self.new
song.name = name
song
end
def self.create_by_name(name)
song = self.... | true |
2508299363834daacc2bab30e769fa9d2172e350 | Ruby | OSC/ondemand | /ood_auth_map/lib/ood_auth_map/helpers.rb | UTF-8 | 1,442 | 2.578125 | 3 | [
"MIT"
] | permissive | class OodAuthMap
# Module that provides many useful helper methods that can be reused in the
# varying CLIs
module Helpers
class << self
# Parse a grid-mapfile for a given authenticated user name
# The mapfile must follow rules here: http://toolkit.globus.org/toolkit/docs/2.4/gsi/grid-mapfile_v11.... | true |
78ddf1614e44cd9f4633d9fb5a2a58c182d668d0 | Ruby | brendan-mcgrady/w3_d2_hw | /models/property.rb | UTF-8 | 3,006 | 3.234375 | 3 | [] | no_license | require('pg')
class Property
attr_accessor :address, :value, :number_of_bedrooms, :year_built, :let_status,
:square_footage, :build
attr_reader :id
def initialize(info)
@id = info['id'] if info['id']
@address = info['address']
@value = info['value'].to_i()
@number_of_bedrooms =... | true |
933a5da76dc9eec7f0abcca93f68d71412237c3b | Ruby | aleibo92/LinkedListMutation | /linked_list_mutation.rb | UTF-8 | 2,392 | 4.03125 | 4 | [] | no_license | class LinkedListNode
attr_accessor :value, :next_node
def initialize(value, next_node=nil)
@value = value
@next_node = next_node
end
end
# Stack is a FILO data structure (first in last out)
class Stack
def initialize
@top_node = nil
end
# Push a value onto the stack
def push... | true |
d93bc618adb46bdf18e11110d8294935e98ed934 | Ruby | bodefuwa/ruby_play | /sample_code.rb | UTF-8 | 1,803 | 3.109375 | 3 | [] | no_license | # Sample taking advantage of single responsibility classes
module FileModifier
require 'thor'
class Append < Thor
include Thor::append
desc "Appends", "It appends a string to a file"
def append_to_file(file_name, string_to_append)
# To do
end
end
class Insert < Thor
include Thor::A... | true |
d3ec453a279be14196d0b9eb823a60ffef516f15 | Ruby | Hektve87/d-parse | /spec/d-parse/parsers/map_spec.rb | UTF-8 | 1,565 | 2.53125 | 3 | [
"MIT",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | describe DParse::Parsers::Map do
let(:inner_parser) { double(:parser) }
let(:parser) { described_class.new(inner_parser) { |data, res, orig_pos| [:mapped, data, res.class.to_s, orig_pos.index] } }
describe '#apply / #read' do
subject { parser.apply('a') }
context 'success' do
before do
exp... | true |
686d175067b1c30a12f8d9f10fec83aab0f8df9f | Ruby | jaj110/D3-1 | /truth.rb | UTF-8 | 1,693 | 2.890625 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/reloader'
# If a GET request comes in at /, do the following.
get '/' do
# Get the parameter named guess and store it in pg
tru = params['true']
fal = params['false']
size = params['size']
table = params['table']
@bad_param = false
@gen_table = nil
if table.nil?
@ge... | true |
1adf916e35eb5255381bf0ebfcaaebdb9595d84b | Ruby | manikafsgarg1/Ruby-Codes | /day_1/pro_9.rb | UTF-8 | 80 | 2.515625 | 3 | [] | no_license | #procedure
abc=lambda {|ab| puts "Hello "+ ab}
# calling lanbda
abc.call "Manik" | true |
76decc569e3ee99e9c52c2dcfd062115e73b0a76 | Ruby | mathieujobin/murky_waters | /lib/murky.rb | UTF-8 | 525 | 2.75 | 3 | [] | no_license | require 'murky/version'
require 'murky/dict'
require 'murky/proof'
require 'base64'
require 'openssl'
module Murky
module_function
def verify(root, siblings, value, digest: Digest::SHA256.new)
Proof.new(
root: root,
siblings: siblings,
signature: digest.digest(value.to_s),
d... | true |
4adac5a0f8338c7f24b7bc6651fc687dfdeef623 | Ruby | marshallshen/cache_spec | /lib/cache_spec/matchers.rb | UTF-8 | 941 | 2.59375 | 3 | [
"MIT"
] | permissive | require_relative 'matchers/cache'
module CacheSpec
module Matchers
def cache_action(action)
action = { :action => action } if action.is_a? Symbol
Cache.new(action, controller)
end
def cache(name)
Cache.new(name)
end
alias_method :cache_fragment, :cache
end
end
# http://rspe... | true |
599ce3d283d1dbd25603517d8a0dc24ab1cb60fb | Ruby | jennifer-yoo/oo-relationships-practice | /app/models/project.rb | UTF-8 | 1,618 | 3.171875 | 3 | [] | no_license | class Project
attr_accessor :name, :creator, :goal_amount
attr_reader :pledge_total, :pledge_count
@@all = []
def initialize(name, creator, goal_amount, pledge_total=0, pledge_count=0)
@name = name
@creator = creator
@goal_amount = goal_amount
@pledge_total = pledge_tot... | true |
98e6f17b6ff2b54c619daa687a1ec734dc5993fd | Ruby | ErinReames/module-2-project | /app/models/store.rb | UTF-8 | 413 | 2.671875 | 3 | [] | no_license | class Store < ApplicationRecord
# ActiveRecord Relationships
has_many(:pets)
has_many(:appointments, through: :pets)
# Validations
validates(:name, :address, presence: true)
validates(:address, uniqueness: true)
# Class Instance Methods
def pets_count
self.pets.count
end
... | true |
95fec6654cfc5da4efd2c0762098090fe9950142 | Ruby | adamberman/data_structures | /hash_map.rb | UTF-8 | 1,348 | 3.75 | 4 | [] | no_license | class HashMap
attr_reader :count
def initialize
self.store = Array.new(12) { [] }
self.count = 0
end
def include?(key)
bucket = self.bucket_for(key)
bucket.include?(key)
end
def [](key)
if self.include?(key)
bucket = self.bucket_for(key)
bucket.each do |item|
return item[1] if key == item[... | true |
7518c495ed7bbd748683102c5c6e10f04a839fb3 | Ruby | PlaustralCL/binary_search_tree | /lib/tree.rb | UTF-8 | 6,369 | 3.203125 | 3 | [] | no_license | # frozen_string_literal: true
require "pry"
require_relative "node"
# Builds and maintains a binary search tree
# rubocop: disable Metrics/ClassLength
class Tree
attr_accessor :root_node
def initialize(initial_array)
@root_node = build_tree(initial_array)
end
# rubocop:todo Metrics/AbcSize
def build_t... | true |
081647edfc6c99490ece5524de8e7e7e0756255c | Ruby | thamilton-rsg/autogenerate | /lib/autogenerate/common/generator.rb | UTF-8 | 533 | 2.8125 | 3 | [
"MIT"
] | permissive | module AutoGenerate
#
# This is the main class in which we interact with the
# Pool class to add/execute schedule jobs.
#
module Generator
#
# Create the initial pool size and schedule job.
#
# @param [Integer] pool_size
# @param [Integer] job_count
#
def self.execute(pool_size, jo... | true |
9addeb75dd42aef360063fbfdc8a777861d2abd2 | Ruby | Davidlago104/sneaker-store | /app/controllers/users_controller.rb | UTF-8 | 718 | 2.578125 | 3 | [] | no_license | class UsersController < ApplicationController
def new
@user = User.new
end
def create #creates a user then automatically logs them in so they can acess everything
@user = User.create(user_params)
if @user.save
session[:user_id] = @user.id
flash[:congrats] = "Welcome to the community!"
... | true |
807327fe1a0991e03caba822a6814524de554633 | Ruby | kengos/kumamoto | /lib/kumamoto/earthquake/epicenter/parser.rb | UTF-8 | 3,087 | 2.921875 | 3 | [] | no_license | module Kumamoto
module Earthquake
module Epicenter
class Parser
HEADER_FIELDS = {
"地震の発生日時" => :occured_at,
"震央地名" => :name,
"緯度" => :latitude,
"経度" => :longitude,
"深さ" => :depth,
"M" => :magnitude,
"最大震度" => :japanese_scale
... | true |
fce8ab3bcc6437b6e1e5873a633c04f68f76161d | Ruby | ybur-yug/paul_graham_quotes | /lib/marky.rb | UTF-8 | 357 | 2.71875 | 3 | [] | no_license | require 'marky_markov'
class PaulGrahamQuote
def initialize
@markov = MarkyMarkov::Dictionary.new('bernie_trump_dictionary') # Saves/opens dictionary.mmd
@prng = Random.new
@markov.parse_file "#{Rails.root}/paul_graham.txt"
end
def gen_quote(sentence_count = @prng.rand(1..5))
@markov.generate_... | true |
d2fe28662a27060465afb266125d715ee988bdc2 | Ruby | camachoh1/LS_prep_RB100 | /Exercises_review/loops1/loop10.rb | UTF-8 | 95 | 2.8125 | 3 | [] | no_license | friends = [ 'Sarah', 'John', 'Hannah', 'Dave']
for i in friends
puts "hello, #{i}!"
end | true |
36ddb4dcb61dec50de83122108b05a8966b46d6b | Ruby | fabiofons/ToDo-list | /ToDo_list.rb | UTF-8 | 970 | 2.765625 | 3 | [] | no_license | require 'sinatra'
require "make_todo"
get '/' do
unless params[:show]
erb :forms
end
end
post "/allitems" do
@message = ""
all_tasks = Tarea.all
all_tasks.each do |task|
@message += "#{task["id"]},#{task["title"]},#{task["done"]} "
end
erb :tables
end
post "/create" do... | true |
3cd01460f09c1cb4d5420a51e466fbc733a1d583 | Ruby | james-cape/sweater_weather | /app/facades/road_trip_facade.rb | UTF-8 | 521 | 2.796875 | 3 | [] | no_license | class RoadTripFacade
def initialize(origin, destination)
@origin = origin
@destination = destination
end
def get_road_trip_info
RoadTrip.new(forecast, @destination, duration[:value])
end
def coordinates
@coordinates ||= CoordinateService.new.get_results(@destination)
end
def duration
... | true |
475962ca967625ca10fc7f72b7419258f0702960 | Ruby | AdrianIlaga/Avion-Backend | /coding_exercises/count.rb | UTF-8 | 594 | 3.953125 | 4 | [] | no_license | arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15]
arr2 = [0,0,0,0,0]
arr3 = [1]
arr4 = [-1]
def count(arr)
array = []
hasInput = false
positive = 0
negative = 0
arr.each do |num|
if (num > 0)
positive += 1
hasInput = true
... | true |
a6b55a01e901abcb107802d3f8e01e603f038d6f | Ruby | ferbin17/fizzbuzz | /test/test_fizzbuzz.rb | UTF-8 | 387 | 2.53125 | 3 | [] | no_license | require 'minitest/autorun'
require 'fizzbuzz'
class FizzBuzzTest < Minitest::Test
# def test_english_hello
# assert_equal "hello world",
# FizzBuzz.hi("english")
# end
#
# def test_any_hello
# assert_equal "hello world",
# FizzBuzz.hi("ruby")
# end
#
# def test_spanish_hello
# ass... | true |
6744fa48ac817b7e7af7d0c47026e2d1924b1573 | Ruby | azzahrafz99/private-events | /app/models/user.rb | UTF-8 | 1,419 | 2.53125 | 3 | [] | no_license | class User < ApplicationRecord
before_save { self.email = email.downcase }
before_create :create_remember_token
validates :username, presence:true
validates :email, presence:true
validates :password, presence:true
validates :password_confirmation, presence:true
has_many :events
has_many :active_relati... | true |
2873d0952c3427a33ac432d4a60576eef6941fd7 | Ruby | bdombro/bdombro.github.io | /_plugins.archive/jekyll-auto-lazy-load.rb | UTF-8 | 1,038 | 2.515625 | 3 | [
"MIT"
] | permissive | # Will auto-Lazy youtube and vimeo links in <p></p>s
# Inspired by jekyll-mentions
require "jekyll"
module Jekyll
class Lazys
InvalidJekyllLazyConfig = Class.new(Jekyll::Errors::FatalException)
class << self
def Lazyify(doc)
return unless doc.output.include?("<img")
doc.output = doc.... | true |
f20ea23aaa97ddfbbeb02511b97d1e192959f5f7 | Ruby | luikore/zscan | /spec/zscan_spec.rb | UTF-8 | 2,230 | 2.8125 | 3 | [
"MIT"
] | permissive | require_relative "spec_helper"
describe ZScan do
before :each do
@z = ZScan.new 'ab你好'
end
it "random workflow" do
assert_equal 2, @z.match_bytesize('ab')
@z.pos = 4
assert_equal 8, @z.bytepos
@z.push
assert_equal nil, @z.scan(/ab你/)
@z.pos = 0
assert_equal 'ab你', @z.scan(/ab你/)
... | true |
288b019deb50a2a5c99e805726a4010ef1bc1db0 | Ruby | flippyhead/tweetable | /lib/tweetable/url.rb | UTF-8 | 1,199 | 2.78125 | 3 | [] | no_license | # require 'yajl'
require 'crack'
require 'crack/json'
require 'net/http'
require 'cgi'
module Tweetable
class URL
LONG_URL_API_URL = 'http://www.longurlplease.com/api/v1.1'
LONG_URL_TIMEOUT = 5
def self.headers
{ "Content-Type" => 'application/json' }
end
# the api can h... | true |
f936366992621d1547d0161320a4028beeadaac2 | Ruby | vmware-archive/team-edition | /lib/team-edition/tracker_api.rb | UTF-8 | 1,618 | 2.578125 | 3 | [
"MIT"
] | permissive | module TeamEdition
class TrackerApi
def initialize(api_key)
@api_key = api_key
end
def members(project_id)
uri = URI.parse("https://www.pivotaltracker.com/services/v5/projects/#{project_id}/memberships")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verif... | true |
bbf70fa6f5d7655b74d1717e3c84616473bddabf | Ruby | thomasv314/roku-ruby | /lib/roku/device/response.rb | UTF-8 | 404 | 2.609375 | 3 | [] | no_license | module Roku
class Device
class Response
attr_reader :response
def initialize(res)
@response = res
end
def ok?
response.success?
end
def struct_from_response_key(key)
hash = response.parsed_response[key].map do |k, v|
[k.to_sym, v]
en... | true |
95b9de8a2dfeaea70bb76d827e0aa87c0b8b3897 | Ruby | Jeff-Hostetler/vinohack | /server/app/services/pairing_service.rb | UTF-8 | 988 | 2.734375 | 3 | [] | no_license | class PairingService
# @param [Wine] wine
# @param [ActiveRecord::Relation<Flavor>] flavors
# @param [Region] region
# @param [Food] protein
#
# @return [WineRating]
def rating_for_wine(wine:, flavors:, region: nil, protein: nil)
points = WineFlavor
.where(wine: wine)
.wh... | true |
aee32a8122024ec6175fd21fa4c432c0c201831d | Ruby | aconstandinou/ls-exercises | /130_exercises/easy_one/encrypted_pioneers.rb | UTF-8 | 1,838 | 3.25 | 3 | [] | no_license | ROT13 = { 'A' => 'N', 'B' => 'O', 'C' => 'P', 'D' => 'Q', 'E' => 'R', 'F' => 'S',
'G' => 'T', 'H' => 'U', 'I' => 'V', 'J' => 'W', 'K' => 'X', 'L' => 'Y',
'M' => 'Z', 'N' => 'A', 'O' => 'B', 'P' => 'C', 'Q' => 'D', 'R' => 'E',
'S' => 'F', 'T' => 'G', 'U' => 'H', 'V' => 'I', 'W' => 'J', 'X' ... | true |
0ae636863527f307084bf3a0566f393363da4f5b | Ruby | ben-kirby/library | /library-ruby/spec/book_spec.rb | UTF-8 | 1,021 | 2.828125 | 3 | [] | no_license | require 'spec_helper'
describe(Book) do
describe('.all') do
it("should return all instances in an array") do
expect(Book.all()).to(eq([Book.new({:title => "Unknown", :author_id => "1", :id => 1})]))
end
end
describe('#save') do
it("should return an empty array when nothing is passed in") do
... | true |
a4b368138aef5d554a96a57215bc6d130fd3b66b | Ruby | belette06/ruby | /exo_15.rb | UTF-8 | 156 | 3.328125 | 3 | [] | no_license | puts "quel est ton annee de naissance"
a = gets.chomp.to_i
b = 2018
c = b += 1
d = 0
while c > a
puts a
a += 1
d += 1
puts "son age est #{d}"
end
| true |
a1a8f3bc45bd8962d9f11477f16ebb6cc7d79e51 | Ruby | Georjane/Ruby-Linters | /lib/naming.rb | UTF-8 | 1,519 | 3.03125 | 3 | [
"MIT"
] | permissive | class Naming < Department
@error_index = 0
def var_name
return unless !keywords.include?(line.split.first) && line =~ / = /
var_line = line[(0..(line =~ / = /) - 1)]
return if var_line.split.last.match?(good_snake_case)
error_index_snake_case
error_message + ": Naming/VariableName: Use snake_... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.