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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
4574476fd27e1d9fc944449496b4fd819af64ab7 | Ruby | naomisorbet/music-app | /app/models/user.rb | UTF-8 | 411 | 2.5625 | 3 | [] | no_license | require 'SecureRandom'
class User < ActiveRecord::Base
attr_accessible :admin, :email, :name, :password, :session_token
def self.validate(email, password)
user = self.find_by_email(email)
return nil if user.nil?
return user if user.password == password
nil
end
def update_token!
self.sessi... | true |
fd81ddae0138c5afaf13f25f91a6ee2748fb670f | Ruby | caxlsx/caxlsx | /lib/axlsx/drawing/hyperlink.rb | UTF-8 | 4,968 | 2.71875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Axlsx
# a hyperlink object adds an action to an image when clicked so that when the image is clicked the link is fecthed.
# @note using the hyperlink option when calling add_image on a drawing object is the recommended way to manage hyperlinks
# @see {file:README} README
cl... | true |
fea2c946197680daca0db0f202a6c1aa19003d2e | Ruby | D4L/projectEuler | /src/problem-12/jbkc.rb | UTF-8 | 629 | 3.203125 | 3 | [] | no_license | public
def jbkc
# create a list of factor for each int
factors = Array.new
factors.push 0
factors.push 1
factors.push 2
factors.push 2
d = 0
ndiv = 0
n = 3
# since the set of triagle numbers is a bijection to natural numbers it suffices to iterate through natural numbers
while d <= 500
n += 1... | true |
51f7571157558c96caf16d575c139772c1867f10 | Ruby | rcasias/adventure_2103 | /spec/park_spec.rb | UTF-8 | 6,019 | 3.265625 | 3 | [] | no_license | require "./lib/trail"
require "./lib/park"
RSpec.describe 'Park' do
it 'exists' do
park1 = Park.new('Capitol Reef')
expect(park1).to be_instance_of(Park)
end
context "initialize works" do
it 'has attributes' do
park1 = Park.new('Capitol Reef')
expect(park1.name).to eq('Capitol Reef')
... | true |
79be70cb14ca94a851632ab6fca229e22764efda | Ruby | mirhamasala/lw_city_guide | /db/seeds.rb | UTF-8 | 8,038 | 2.625 | 3 | [] | no_license | start_time = Time.now
puts "Wiping out civilizations..."
User.destroy_all
City.destroy_all
Category.destroy_all
Spot.destroy_all
puts "[1/6] 🚜 It's a clean slate."
puts "Adding city keepers and dwellers..."
# Mirha is the admin
mirha = User.create!(
email: "mirha@testing.com",
... | true |
00278b7a0526171adf12b6ff31a50fc707c737ec | Ruby | radu-constantin/small-problems | /easy4/short_long_short.rb | UTF-8 | 296 | 3.234375 | 3 | [] | no_license | def short_long_short (string1, string2)
string1.length > string2.length ? string2 + string1 + string2 : string1 + string2 + string1
end
puts short_long_short('abc', 'defgh') == "abcdefghabc"
puts short_long_short('abcde', 'fgh') == "fghabcdefgh"
puts short_long_short('', 'xyz') == "xyz"
| true |
646cc325fd1f9f3bec33f2e0ddfef8c4220fafa6 | Ruby | bPositiveAllDay/file_io | /file_i:o.rb | UTF-8 | 540 | 2.703125 | 3 | [] | no_license | require 'rubygems'
require 'rest-client'
wiki_url = "http://en.wikipedia.org/"
wiki_local_file_name = "wiki_sample.html"
File.open(wiki_local_file_name, "w") { |file| file.write(RestClient.get(wiki_url)) }
# contents = File.open("wiki_sample.html", "r") { |file| file.read}
hamlet_url = "http://ruby.bastardsbook.co... | true |
6a8f5149532ce149e12ba4591e537535c4dc2465 | Ruby | wingedmachine/sinatra-mvc-lab-online-web-sp-000 | /models/piglatinizer.rb | UTF-8 | 374 | 3.75 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class PigLatinizer
def piglatinize(phrase)
phrase.split(' ').map do |word|
piglatinize_word(word)
end.join(' ')
end
def piglatinize_word(word)
first_vowel_index = word.index(/[aeiouAEIOU]/)
if first_vowel_index == 0
"#{word}way"
else
"#{word[(first_vowel_index..word.length)]... | true |
c071b5585702301072cde6d3c0f0a82322f8c39d | Ruby | PaulCampbell/FestivalApp | /spec/models/festival_spec.rb | UTF-8 | 2,387 | 2.609375 | 3 | [] | no_license | require 'spec_helper'
describe Festival do
before(:each) do
@attr = {
:name => "here's the body of the post",
:description => "The Post Title",
:startdate => '2011-07-07',
:enddate => '2011-07-10'
}
end
it "should create a new instance given valid attribubtes" do
Festival.creat... | true |
69bd833e2a07cb97fca8c8328f8572796a3dbe01 | Ruby | SacHomeless/ohana-client | /spec/lib/food_dist_spec.rb | UTF-8 | 1,152 | 3.015625 | 3 | [] | no_license | require "food_dist"
describe FoodDist do
describe "#new" do
let(:food_dist) {FoodDist.new("./spec/support_files/Food_Dist.csv")}
it "returns two food_dist records" do
expect(food_dist.stores.count).to eql(111)
end
it "skips the first row" do
store = food_dist.stores.first
expect(st... | true |
484084ff0ed2921b45025caa8b197ea47135a850 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/word-count/d59636961a5d48f8bbd609b0e1ced694.rb | UTF-8 | 378 | 3.34375 | 3 | [] | no_license | class Phrase
def initialize(phrase)
@phrase = phrase
end
def word_count
count(words)
end
private
module Splitter
def self.words(phrase)
phrase.downcase.scan(/\w+/)
end
end
def words
Splitter.words(@phrase)
end
def count(words)
words.each_with_object(Hash.new(0))... | true |
affdf693fc9a8e2498fd2e154ac7e08d7aa973a5 | Ruby | PeterHajdu/sinoma | /lib/sinoma.rb | UTF-8 | 475 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'rubygems'
require 'ruby-notify-my-android'
class Sinoma
def initialize( event_source, api_key )
@event_source = event_source
@api_key = api_key
end
def start
loop do
while ( line = @event_source.gets ) do
send_notification line
end
end
end
private
def send_no... | true |
189671e078c0a3ec153bd6c7304c7a610cc04bfc | Ruby | MikeRuby/browserwar_plugin | /lib/.svn/text-base/browser_war_helper.rb.svn-base | UTF-8 | 3,345 | 2.875 | 3 | [
"MIT"
] | permissive | #Copyright (c) 2008 Peter Boling and Matt Long of Sagebit LLC, released under the MIT license
module BrowserWarHelper
def start_browser_war(settings)
fight_str = ""
settings[:broswers] = !settings[:broswers].blank? ? settings[:broswers] : browserwar_browsers_default
settings[:message] = !settings[:message... | true |
2d008b7b3e6eccce6cc1a9a2bac9964fc901874f | Ruby | LHJE/rails_engine | /app/models/invoice.rb | UTF-8 | 615 | 2.546875 | 3 | [] | no_license | require 'csv'
class Invoice < ApplicationRecord
has_many :invoice_items
has_many :items, through: :invoice_items
has_many :transactions
belongs_to :customer, optional: true
belongs_to :merchant, optional: true
validates :customer_id,
:merchant_id,
:status, presence: true
def se... | true |
6f5f76fdde589a04871d76822f51f8cbd68e144f | Ruby | usatiago/rubylearningsandbox | /rubyessentials/oop/bank_account.rb | UTF-8 | 1,452 | 3.609375 | 4 | [] | no_license | class BankAccount
attr_reader :name
def initialize(name = "")
@name = name
@transactions = []
add_transaction("beginning balance",0.0)
end
def add_transaction(description,amount)
@transactions.push(description: description, amount: amount)
end
def credit(descri... | true |
c39e663fa1cdbfd5b50322598a3cf6a6bf9cd26f | Ruby | rodders110/week2_day1_lab | /spec/student_spec.rb | UTF-8 | 1,065 | 3.109375 | 3 | [] | no_license | require("minitest/autorun")
require("minitest/rg")
require_relative("../Student")
class TestStudent < MiniTest::Test
def test_return_name
student = Student.new("Roddy", "G6", "Java")
student_name = student.get_name()
assert_equal("Roddy", student_name)
end
def test_return_cohort
student = Stu... | true |
275490413e2a95169f977e02c958096a87f43658 | Ruby | MagneticRegulus/learn_to_program | /chapters/chapter12/bday_spank.rb | UTF-8 | 546 | 3.8125 | 4 | [] | no_license | now = Time.new
puts 'Welcome to the birthday machine!'
puts 'In what year where you born?'
year = gets.chomp.to_i
puts 'What month?'
month = gets.chomp.to_i
puts 'What day?'
day = gets.chomp.to_i
birthday = Time.local(year, month, day)
age = ((((now - birthday)/60)/60)/24)/365
age = age.to_i
puts "You're #{a... | true |
93f63f18ab1b4a64246fa8ccf6f8417f50965652 | Ruby | var114/Episode11 | /api.rb | UTF-8 | 1,251 | 2.703125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'rubygems'
require 'bundler'
Bundler.require
require 'sinatra'
require 'active_support/all'
Rabl.register!
class LogRequest
attr_reader :text, :time, :execution_time, :user
def initialize(time, text, execution_time, user)
@text = text
@time = time
@execution_time = execution_time
@user = u... | true |
2cc45e638f111166eb80dc6c72e6b93303655683 | Ruby | ULL-ESIT-LPP-1718/modulos | /enumerable.rb | UTF-8 | 362 | 3.6875 | 4 | [] | no_license | #module Enumerable
#By default is included in Array class
r = [1,2,3,4,5,6].each{ |i| puts i}
puts r
r = [1,2,3,4,5,6].collect{ |i| i.to_s + "x"}
puts r
r = [1,2,3,4,5,6].detect{ |i| i.between?(2,3)}
puts r
r = [1,2,3,4,5,6].select{ |i| i.between?(3,5)}
puts r
r = [2,1,6,5,4,3].sort
puts r
r = [2,1,6,5,4,3].... | true |
f56c2d6cc32f8245bd50423c99d10c8db667733e | Ruby | vioif/reinforcjan5 | /exercise.rb | UTF-8 | 153 | 3.515625 | 4 | [] | no_license | def word_counter(num_words)
return (num_words.split.size)
end
puts "Place num_words"
input = gets.chomp
puts "This has #{word_counter(input)} words"
| true |
d00894bd966f3900a29bbfaec9ae48c067aab570 | Ruby | yunshun/git-svn-bridge | /app/newwc.rb | UTF-8 | 2,965 | 2.671875 | 3 | [] | no_license | require 'sqlite3'
require 'open3'
require 'crypt/gost'
require 'base64'
require 'pp'
@rootdir = "#{ENV['HOME']}/biocsync"
@dbfile = "#{ENV['HOME']}/app/data/gitsvn.sqlite3"
@db = SQLite3::Database.new @dbfile
def run(cmd)
`echo ""` # needed to reset $?
sin, sout, serr = Open3.popen3 cmd
res = $?
[sout... | true |
6cbe59238f3b6787fb0271f74de817448ad768a5 | Ruby | mdheller/rletters | /app/models/datasets/file.rb | UTF-8 | 1,845 | 2.625 | 3 | [
"BSD-3-Clause",
"MIT",
"Apache-2.0"
] | permissive | # frozen_string_literal: true
module Datasets
# A file full of results that belongs to a dataset task
#
# As analyses can generate multiple kinds of files, this class encapsulates
# the content of a database file and its basic description.
#
# @!attribute description
# @raise [RecordInvalid] if the des... | true |
31b653c34c42f0b20a7733878d042fc449cbff5d | Ruby | aki0fj/reversi | /boardtest.rb | UTF-8 | 2,021 | 3.515625 | 4 | [] | no_license | # -*- coding: utf-8 -*-
# boardtest.rb
require "board"
class ConsoleBoard < Board
def print_board
y_str = %w(1 2 3 4 5 6 7 8)
puts " abcdefgh"
for y in 1..8
print y_str.shift
for x in 1..8
case get_color(Point.new(x, y))
when Disc::BLACK
print "x"
when Di... | true |
918bc0f4a6d46de7b01c54ffed174cac4924e7c5 | Ruby | shakusbakus/shakusbakus | /analyzer.rb | UTF-8 | 1,201 | 4.5 | 4 | [] | no_license |
def multiply(first_number, second_number)
first_number.to_f * second_number.to_f
end
def divide(first_number, second_number)
first_number.to_f / second_number.to_f
end
def subtract(first_number, second_number)
first_number.to_f - second_number.to_f
end
def mod(first_number, second_number)
first_number.to_f % s... | true |
ef276bf8d58212e814d9e64e2c0d6ecf5b4dd97e | Ruby | Shunsuke-Nishida/DQ_app | /main.rb | UTF-8 | 1,065 | 4.125 | 4 | [] | no_license | class Brave
# ゲッターの代わりになる
attr_reader :name, :offense, :defense
# HP以外は書き換えられると困るので、HPのみセッターも定義
attr_accessor :hp
# newされたときに呼び出される
# initializeによりセッターが不要になる
# **引数 とすることでハッシュしか受け取れなくなる
def initialize(**params)
@name = params[:name]
@hp = params[:hp]
@offense = ... | true |
24db69f73d63356c349616fe6f61420b36398762 | Ruby | pixelpogo/dynameister | /spec/dynameister/collection_spec.rb | UTF-8 | 1,508 | 2.609375 | 3 | [
"MIT"
] | permissive | require_relative "../app/models/language"
describe Dynameister::Collection do
let(:items) do
[
{ "some_hash" => "here" },
{ "another" => "value" }
]
end
let(:serialized_entities) do
[
{ some_hash: "here" },
{ another: "value" }
]
end
let(:response) { double("res... | true |
636d1dafe316e75a7630ca435f2bb41e7946fd07 | Ruby | jacki890/apprenticeship | /beer_on_the_wall.rb | UTF-8 | 267 | 3.265625 | 3 | [] | no_license | beer_num = 99
while beer_num > 0
beer_num -= 1
puts beer_num.to_s + ' bottles of beer on the wall'
puts beer_num.to_s + ' bottles of beer.'
puts 'Take one down, pass it around.'
puts beer_num.to_s + ' bottles of beer on the wall!'
puts ''
end
| true |
c9a63c8eb329c1a3f74bae902629de1b8ffbd755 | Ruby | pepabo/codingdojo | /20131120-phonebook/hsbt/phone_book.rb | UTF-8 | 752 | 3.25 | 3 | [] | no_license | class PhoneBook
attr_reader :numbers
def initialize(str = nil)
@numbers = extracted_addresses(read_file(str))
end
def collision?(index)
master = @numbers[index]
subset = @numbers.dup
subset.delete(master)
subset.inject(false) do |r, num|
r || (master[1].match(/\A#{num[1]}/))
end
... | true |
f7cbafdc90b1ca0a1e3add5c6d76b7c313162909 | Ruby | tfisher21/advent_of_code_2020 | /lib/day_three.rb | UTF-8 | 900 | 3.265625 | 3 | [] | no_license | class DayThree
class << self
attr_reader :input_data
def input_data
@input_data ||= begin
data = []
File.open('inputs/day_three.txt').each_line do |l|
data << l.strip
end
data
end
end
def part_one(down: 1, right: 3)
h_index = 0
v_inde... | true |
3f128b9e2647447815dab5bac2bb5fa65281104a | Ruby | rpanachi/sandbox | /ruby/tail_call/factorial_looping.rb | UTF-8 | 144 | 3.34375 | 3 | [] | no_license | def factorial(n)
raise InvalidArgument, "negative input given" if n < 0
result = 1
for i in (1..n) do
result *= i
end
result
end
| true |
81c38b032ed560074c00ed201b64d3283ed183b0 | Ruby | mess110/ki | /lib/ki/utils/extra_ruby.rb | UTF-8 | 889 | 2.890625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
class String
# Converts a string to a class
#
# ==== Examples
#
# class User
# end
#
# "user".to_class == User
#
def to_class
chain = split '::'
klass = Kernel
chain.each do |klass_string|
klass = klass.const_get klass_string.split('_').map(&:ca... | true |
fe50a28d9ab053aaa8f476a98378e4e4bfc26bc1 | Ruby | janschrage/gsplan | /lib/tasks/db_assign_role.rake | UTF-8 | 487 | 2.640625 | 3 | [] | no_license | namespace :db do
desc "'Assigns a role to a user."
task :assign_role => :environment do
unless ENV.include?("user") && ENV.include?("role")
raise "usage: rake db:assign_role user=<user> role=<role>"
end
#Role
role = Role.find_by_name(ENV['role'])
raise "Role not found." unless role
... | true |
8a5cb8fbbd09c4533697dabc2e245a1cc28442ac | Ruby | jeremyf/project-euler | /problems/016-power-digit-sum.rb | UTF-8 | 223 | 3.65625 | 4 | [
"Apache-2.0"
] | permissive | # 2^15 = 32768 and the sum of its digits is 3 + 2 + 7 + 6 + 8 = 26.
#
# What is the sum of the digits of the number 2^1000?
# @see https://projecteuler.net/problem=16
puts (2**1000).to_s.split("").map(&:to_i).reduce(0, :+)
| true |
383904ed7fa94820c41445ddae03e8d99b90deea | Ruby | marcochavezf/ruby-patterns | /metaprogramming/attr_init.rb | UTF-8 | 315 | 2.6875 | 3 | [] | no_license | class Object
def self.attr_init(*args)
code = %Q{
def initialize(#{ args.join(', ') })
}
args.each do |arg_item|
code += %Q{
@#{ arg_item } = #{ arg_item }}
end
code += %Q{
end
attr_accessor :#{ args.join(', :') }
}
class_eval(code)
end
end
| true |
a9865595d4c0377dc608b6caef3fd8a91ff38f2b | Ruby | hmishinev/dcell | /lib/dcell/explorer.rb | UTF-8 | 2,100 | 2.71875 | 3 | [
"MIT"
] | permissive | require "dcell"
require "reel"
require "pathname"
require "erb"
module DCell
# Web UI for DCell
# TODO: rewrite this entire thing with less hax
class Explorer < Reel::Server
ASSET_ROOT = Pathname.new File.expand_path("../../../explorer", __FILE__)
def initialize(host = "127.0.0.1", port = 7778)
su... | true |
edcdf2500ff14678d48ca488d4b9b23cd5ccb03f | Ruby | faketrees/alpacaclasswork | /w4/w4d1/whiteboard.rb | UTF-8 | 367 | 2.8125 | 3 | [] | no_license | #CREPE
#E - execute the code
#- write legibly
#use proper indentation and formatting
#talk out loud - they want to know how you solve problems
#P - Prove that it works
# test cases (advisable to use another color)
#use comments and walk through the code, use edge cases
#E - Optomize for Effic... | true |
d33eab37d10c49f05fb320a9bafa6a44be256e3e | Ruby | DamienRobert/simplecolor | /test/test_rgb.rb | UTF-8 | 4,078 | 2.78125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'helper'
require 'simplecolor'
describe SimpleColor::RGB do
it "Should output truecolor code" do
_(SimpleColor::RGB.new(10,20,30).ansi).must_equal "38;2;10;20;30"
end
it "Can degrade to 256 colors" do
_(SimpleColor::RGB.new(10,20,30).convert(256).ansi).must_equal "38;5;234"
end
it "Can degrade to 16 c... | true |
5887a45d07cde03208beec59f0ceb3dfb94a7721 | Ruby | bear-metal/tunemygc | /lib/tunemygc/cli.rb | UTF-8 | 2,679 | 2.609375 | 3 | [
"CC-BY-3.0",
"MIT"
] | permissive | # encoding: utf-8
require 'tunemygc/network'
require 'optparse'
module TuneMyGc
class CLI
attr_reader :client, :options
def self.start(args)
args = ["-h"] if args.empty?
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: tunemygc [options]"
opts.on("-r ", "--re... | true |
4c6d57876c941d6491c1abd1085929387ce3b796 | Ruby | lucasbonner/RB120-129 | /lesson_4/easy_2/quest_9.rb | UTF-8 | 632 | 3.921875 | 4 | [] | no_license | #If we have this class:
class Game
def play
"Start the game!"
end
end
class Bingo < Game
def rules_of_play
#rules of play
end
def play
"We are playing bingo!"
end
end
#What would happen if we added a play method to the Bingo class,
#keeping in mind that there is already a method of this name ... | true |
1c42487da235884e50c0317184366b396b3e39ec | Ruby | trizen/sidef | /scripts/RosettaCode/zeckendorf_number_representation.sf | UTF-8 | 489 | 3.609375 | 4 | [
"Artistic-2.0"
] | permissive | #!/usr/bin/ruby
#
## http://rosettacode.org/wiki/Zeckendorf_number_representation
#
func fib(n) is cached {
n < 2 ? 1
: (fib(n-1) + fib(n-2));
}
func zeckendorf(n) {
n == 0 && return '0';
var i = 1;
++i while (fib(i) <= n);
gather {
while (--i > 0) {
var f = fib(i);
... | true |
7ca45ad6ce90acafcd80ecc4f9f484ec03fdab62 | Ruby | rer7891/ruby_exercises | /ruby-exercises/command-query/exercises/appointments.rb | UTF-8 | 331 | 2.84375 | 3 | [] | no_license | class Appointments
attr_accessor :earliest
def initialize
@earliest = []
end
def earliest
end
def at(t1)
end
end
class Time
attr_accessor :year, :month, :day, :hour, :min
def initialize(year, month, day, hour, min)
@year = year
@month = month
@day = day
@hour = hour
@min = min... | true |
69dcb6c476f17e96ec5804b5c2c948d2ab587161 | Ruby | pinkman84/oohotel_homework | /specs/people_spec.rb | UTF-8 | 508 | 2.734375 | 3 | [] | no_license | require( 'minitest/autorun' )
require( 'minitest/rg' )
require_relative( '../guest' )
class TestPeople < Minitest::Test
def setup
@guest = Guest.new("Mr Aidan Pinkman", 2, 2, 100)
end
def test_persons_name
assert_equal( "Mr Aidan Pinkman", @guest.guest_name)
end
def test_persons_stay_length
... | true |
97939b05058321432db487bb6953506a3f653d55 | Ruby | CodingDojoDallas/ruby_aug_2018 | /ObiFenix-RubyStack/Ruby-Stack/OOP/animal/Lion.rb | UTF-8 | 775 | 4.25 | 4 | [] | no_license | # =================
# Assignment: Lion
# =================
#
# => Objective:
# <> Utilize 'superclass' to create another class that inherits from mammal.rb,
# ==================================================
require_relative "mammal"
class Lion < Mammal
def initialize
@health = 170
self
... | true |
503000e6e0365218917b2b3c06832ebcb18abaf6 | Ruby | ben2d2/code-tests | /ruby/palindromes.rb | UTF-8 | 265 | 4.21875 | 4 | [] | no_license | def is_palindrome?(n)
n == n.to_s.reverse.to_i
end
def get_palindrones_in_range(min, max)
palindrones = []
(min..max).each do |n|
if is_palindrome?(n)
palindrones << n
end
end
palindrones
end
puts get_palindrones_in_range(0, 10000).sum | true |
2c5e6b450724a7e1eb3944bf3bd3329a25044023 | Ruby | MadBomber/scripts | /get_db_relationships.rb | UTF-8 | 3,183 | 2.765625 | 3 | [] | no_license | #!/usr/bin/env ruby
# encoding: utf-8
# frozen_string_literal: true
# warn_indent: true
##########################################################
###
## File: get_db_relationships.rb
## Desc: extract the has_ and belongs_ relationships for ActiveRecord::Base classes
## By: Dewayne VanHoozer (dvanhoozer@gmail.com)... | true |
d1ba5520ff7c14b988439ccf5d2efb41f5408fb4 | Ruby | stereosupersonic/fiusm.com | /app/models/radio/album.rb | UTF-8 | 467 | 2.578125 | 3 | [] | no_license | class Album
def initialize(artist_name, song_title)
@_artist_name = artist_name
@_song_title = song_title
raise album_art.inspect
end
def album_art
begin
uri = Amazon::RequestURI.for(Amazon::AWSECommerceService, {
'Operation' => 'ItemSearch',
'SearchIndex' => 'Musi... | true |
9f773f0f745e3c67d83e6f8b8185449a64969fee | Ruby | imclab/observed | /lib/observed/configurable.rb | UTF-8 | 1,218 | 2.5625 | 3 | [
"MIT"
] | permissive | module Observed
module Configurable
def initialize(args={})
configure(args)
end
def configure(args={})
if @attributes
@attributes.merge! args
else
@attributes ||= args.dup
end
self
end
module ClassMethods
# @param [String|Symbol] name
de... | true |
5b673a7ba8340f971da3bd0389b23c74637ff6be | Ruby | PhotosOfBlacklion/captain-hook | /test/photo_test.rb | UTF-8 | 715 | 2.59375 | 3 | [
"MIT"
] | permissive | require_relative "test_helper"
class PhotoTest < CaptainHook::Test
def setup
path = "/2017-01-17-mike-test/img-01.jpg"
@photo = Photo.new(path)
end
def test_s3_path
assert @photo.s3_path == "2017/01/mike-test/img-01.jpg",
"The s3 path is wrong"
end
def test_original
assert @photo.orig... | true |
c456e5348cde8cb07800fc075a13580ad7611494 | Ruby | SPBTV/might | /lib/might/result.rb | UTF-8 | 1,192 | 2.703125 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | # frozen_string_literal: true
module Might
# Marker module
module Result
end
# Represents fetching failure
class Failure
include Result
# @param errors [<String>]
def initialize(errors)
@errors = errors
end
# @param errors [<String>]
attr_reader :errors
# @return [true]
... | true |
0d2da2b329667ec9a4c9d55b6e4e271ddd27d5cb | Ruby | bhserna/guests | /helpers/form_helpers.rb | UTF-8 | 1,805 | 2.75 | 3 | [] | no_license | module FormHelpers
def form_group(form, field, label, opts = {})
FormGroupBuilder.form_group(form, field, label, opts)
end
def select_form_group(form, field, label, options)
FormGroupBuilder.select_form_group(form, field, label, options)
end
class FormGroupBuilder
def self.form_group(form, field... | true |
0e0aac806a5215d280dadd3811ef4e95aad19e59 | Ruby | freegenie/pwsafe-agent | /lib/pwsafe-agent/driver.rb | UTF-8 | 956 | 2.734375 | 3 | [
"MIT"
] | permissive | module Pwsafe
module Agent
class Driver
def initialize
@password = nil
end
def set
UNIXSocket.open(SOCKET_PATH) do |sock|
puts "type password"
begin
system 'stty -echo'
password = STDIN.gets.chomp
ensure
sys... | true |
3c37ad9d9c8cb7ef74ea3ad52206bb398a03a969 | Ruby | tohae/bower-rails | /lib/tasks/bower.rake | UTF-8 | 1,866 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'json'
require 'pp'
namespace :bower do
desc "install files from bower"
task :install do
#install to corresponding directories
perform_command do
sh 'bower install'
end
end
desc "update bower packages"
task :update do
#install to corresponding directories
perform_command fa... | true |
f12eab22120a9f86b4d029030d1e77d80052b86d | Ruby | lilaboc/euler_ruby | /27.rb | UTF-8 | 370 | 3.453125 | 3 | [] | no_license | require 'set'
def is_prime(n)
return false if n == 2
2.upto(n - 1) do |x|
return false if n % x == 0
end
true
end
ma = 0
mb = 0
greatest = 0
-999.upto(999) do |a|
-999.upto(999) do |b|
n = 0
while is_prime((n * n + a * n + b).abs)
n += 1
end
if n > greatest
ma = a
mb =... | true |
33eba08b6656064a551fee11933ac54a0c39caaf | Ruby | MefazM/md-server-v2 | /lib/battle/spells/abstract_spell.rb | UTF-8 | 2,379 | 2.53125 | 3 | [] | no_license | module Battle
class AbstractSpell
attr_reader :owner_uid
def initialize(opponents, caster_uid, target_uid, options)
@opponents = opponents
@source, @target = opponents[caster_uid], opponents[target_uid]
@position, @spell_name = options[:target], options[:name].to_sym
@complited = fa... | true |
e6fa04d87c5fca68ddf57f503094b64d350b9977 | Ruby | liamseanbrady/tealeaf-course-one | /Lesson2/BookExercises/ClassesAndObjects2Chapter/car_mileage_class_method.rb | UTF-8 | 833 | 4.59375 | 5 | [] | no_license | # Add a class method to your MyCar class that calculates the gas
# mileage of any car.
class MyCar
attr_accessor :year, :model, :color, :current_speed
def self.gas_mileage(gallons, miles)
puts "#{miles / gallons} miles per gallon of gas"
end
def initialize(year, model, color)
self.year = year
se... | true |
941a389e91465f457c4e4aa4f871870d0b91d643 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/a78dfdba0d324aa9868707d0bd9d6502.rb | UTF-8 | 557 | 3.890625 | 4 | [] | no_license | class Bob
def hey(s)
statement = Statement.new(s)
case
when statement.silence? then 'Fine. Be that way.'
when statement.question? then 'Sure.'
when statement.shouting? then 'Woah, chill out!'
else 'Whatever.'
end
end
private
class Statement
def initialize(statement)
@st... | true |
5cdae1e5b33aef3425f3a7d95b8dafba975ca1ec | Ruby | ianwhite/handbrake-batch-convert.rb | /handbrake-batch-convert.rb | UTF-8 | 1,197 | 2.609375 | 3 | [] | no_license | #!/usr/bin/env ruby
if !(2..3).include?(ARGV.length) || !File.exist?(ARGV[0])
puts "Usage: handbrake-batch-convert.rb SRC_PATH DEST_PATH [BASE_PATH]"
exit false
end
@src = File.expand_path(ARGV[0])
@target = File.expand_path(ARGV[1])
@base = (ARGV[2] && File.expand_path(ARGV[2])) || File.dirname(@src)
@exts = ['a... | true |
0aecf84ee219800c906a4de33763eded068ef070 | Ruby | pivotalmailbypass/fake_riak | /spec/fake_riak_client_spec.rb | UTF-8 | 1,897 | 2.546875 | 3 | [] | no_license | require './spec/spec_helper'
require 'tempfile'
describe FakeRiakClient do
attr_accessor :riak
shared_examples_for "a key-value store" do
it "gets an empty list when a key has no value" do
riak.get("missing_key").should == []
end
it "gets an empty list when there is data in riak but not for the... | true |
a928ca35c0dbdac2571d66fd180e9a0d19dcec25 | Ruby | concow/oo-counting-sentences-online-web-sp-000 | /lib/count_sentences.rb | UTF-8 | 648 | 3.890625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class String
def sentence?
self.end_with?(".") #'self' in the body of this method to refer to the string on which the method is being called
end
def question?
self.end_with?("?")
end
def exclamation?
self.end_with?("!")
end
def count_sentences
self.split(/[.!?]/)... | true |
49b684e6cab3d1a2b7754313ba0f83795be2fc92 | Ruby | dvingo/mvGraph | /test/test_mvGraph.rb | UTF-8 | 5,948 | 2.78125 | 3 | [
"MIT"
] | permissive | require 'minitest/autorun'
require_relative '../lib/mvGraph.rb'
class TestGraph < MiniTest::Unit::TestCase
def setup
@graph = Graph.new
@vertex = Vertex.new(1)
end
def test_create_graph
assert @graph
end
def test_create_vertex
assert @vertex
end
def test_vertex_id
@vertex.id = ... | true |
2f73247d9fa91046869ef501cd5d810315a29a53 | Ruby | ChengYurou/ruby_fizz_buzz | /fizz_buzz.rb | UTF-8 | 324 | 3.453125 | 3 | [] | no_license | class FizzBuzz
def judgeFB(n)
array = []
(1..n).each do |num|
if num%3 == 0 && num%5==0 then
array.push "FizzBuzz"
elsif num%3 == 0 then
array.push "Fizz"
elsif num%5 == 0 then
array.push "Buzz"
else
array.push num.to_s
end
end
array
end... | true |
45b835752c785eda1b383f7accd1131cc0a7bcac | Ruby | aina1205/virtualliverf1 | /lib/authorization_enforcement.rb | UTF-8 | 10,206 | 2.5625 | 3 | [] | no_license | #This file sets up enforcement for basic rules based on the 'can_edit?', 'can_view?', 'can_delete?', and 'can_manage?' methods
#It also provides macro style class methods for AR classes to describe common variations on the basic rules.
# 1. An instance of an AR class may not be destroyed unless instance.can_delete? re... | true |
df77c57e67f0bde239e4931b27db943b02b396e7 | Ruby | thejennywang/ma-takeaway-2 | /spec/dish_spec.rb | UTF-8 | 512 | 2.765625 | 3 | [] | no_license | require 'all_files'
describe 'Dish' do
it 'should be created with a price' do
dish = Dish.new
expect(dish.price).to eq 5
end
it 'should be created with a name' do
dish = Dish.new(name='a name')
expect(dish.name).to eq 'a name'
end
it 'should be able to have a different name' do
dish = D... | true |
4dddd4fda29e7cb4b0a8456aa80a9e1d208d6fac | Ruby | aapis/evertils | /lib/evertils/helpers/formatting.rb | UTF-8 | 1,544 | 2.578125 | 3 | [] | no_license | # frozen_string_literal: true
module Evertils
module Helper
class Formatting
# Template string for note title
def self.date_templates
current_date = Date.today
week_stub = current_date.strftime('%a')
start_of_week = Date.commercial(current_date.year, current_date.cweek, 1)
... | true |
b6678179723d0a927286c7471e40fd81092689bc | Ruby | chaoran/qianmo | /app/helpers/douban_helper.rb | UTF-8 | 583 | 2.921875 | 3 | [] | no_license | # encoding: utf-8
module DoubanHelper
def get_year_from_date(date)
year = date.split("-")[0]
end
def get_month_from_date(date)
month = date.split("-")[1]
month[1..-1] if month.start_with?("0")
end
def get_day_from_date(date)
day = date.split("-")[2].split("(")[0]
day[1..-1] if ... | true |
3b3233eb739fc81c86d12c87959aa013c09d1a88 | Ruby | trinityXmontoya/recipe-hash | /recipe.rb | UTF-8 | 618 | 3.640625 | 4 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Train < Struct.new(:current_city,:engines,:number_of_cars,:caboose)
end
train = Train.new("NYC",2,4,1)
puts "-----------"
puts "TRAIN INFO"
puts "-----------"
train.members.each do |attribute|
puts "#{attribute.to_s.capitalize.gsub('_',' ')} - #{train.send(attribute)}"
end
# ^^^^ I know this isn't particular... | true |
bf32b87c014d4fe6feb3f7accf799ba638e7902b | Ruby | Raudy2/Rubh | /menu.rb | UTF-8 | 148 | 3.328125 | 3 | [] | no_license | class Menu
option = 0
while option != 4
puts "Choose an Option \n1-Entrar \n2- Ver \n3- agregar \n4- Salir"
option = gets.chomp.to_i
end
end | true |
f4be237c58c2df60878986a289f68b881bae1d55 | Ruby | murtala/RubyTraining | /alias.rb | UTF-8 | 353 | 3.1875 | 3 | [] | no_license | # This gives alias to methods or global variables.
# Aliases can not be defined within the method body.
# The alias of the method keep the current definition of the method,
# even when methods are overridden.
def method_1
puts "method 1"
end
alias m1 method_1 # create alias for the method
#alias $values $val
m1 #... | true |
5e194cc375a81ae670333c4ecf89f8da917d5161 | Ruby | LucianoBandeiraCampos/rails-stupid-coaching | /app/controllers/questions_controller.rb | UTF-8 | 468 | 3 | 3 | [] | no_license | # frozen_string_literal: true
class QuestionsController < ApplicationController
def ask; end
def answer
@user_input = params[:question]
@coach = build_answer(@user_input)
end
private
def build_answer(input)
input = input.downcase
if input == 'i am going to work'
'Great!'
elsif i... | true |
aceb29b27965d29b754bef19fad029c66da69136 | Ruby | tpickett66/Project-Euler-Solutions | /bin/1-50/p15 | UTF-8 | 337 | 2.578125 | 3 | [] | no_license | #!/usr/bin/env ruby
# encoding: UTF-8
$:.unshift(File.dirname(__FILE__) + '/../../lib') unless $:.include?(File.dirname(__FILE__) + '/../../lib')
# Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.
#
#
# How many routes are there through a 2020 gri... | true |
d0636249907948063d6c03c23c812f5ffcc9a402 | Ruby | lukebayes/project-sprouts | /test/unit/files_param_test.rb | UTF-8 | 2,202 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class FilesParamTest < Test::Unit::TestCase
include Sprout::TestHelper
context "a new FilesParam" do
setup do
@input1 = File.join(fixtures, "executable", "params", "input.as")
@input2 = File.join(fixtures, "executable", "params", "input2.as")
@input3 = File.join(fixtur... | true |
aa175de58b814f793dd6a77267b372f38dc833ee | Ruby | 2019-b-gr2-fundamentos/fund-romero-meneses-daniela-alexandra | /Ruby/01-introduccion/02-numeros-strings.ru | UTF-8 | 246 | 2.6875 | 3 | [] | no_license | numerouno = 1
numerodos = 2
resultado = 0
#SUMAR
resultado = 1+2
#RESTAR
resultado = 1-2
#MULTIPLICAR
resultado = 1*2
#DIVIDIR
resultado = 1/2
#EXPONENTE
resultado = 1^2
#MOD
resultado = 4%2 #0 residuo
resultado = 4%3 #1 residuo
printf('pera'+ 2) | true |
e48143d441949d56af22ceefa2d044235e9ed79d | Ruby | innovationhero/corkboard_server_example | /corkboard.rb | UTF-8 | 3,075 | 2.578125 | 3 | [
"Apache-2.0"
] | permissive | require 'rubygems'
require 'sinatra'
require 'json'
require 'dm-core'
require 'dm-validations'
require 'dm-timestamps'
require 'dm-migrations'
# TODO:
# . logging
# . media types testing
# . test mode and development mode
# . put the database somewhere else
# . GET a range
# . tests
# . multi-user with authentication
... | true |
2515d2fc04b5973faa76d633ef8a9f7ee93186f3 | Ruby | mike981/snakes-and-ladders | /snakes ladders/runner.rb | UTF-8 | 341 | 3.21875 | 3 | [] | no_license | require_relative('game.rb')
require_relative('player.rb')
player = Player.new("purple")
game = Game.new()
game.add_player(player)
puts game.players
print player.inspect
# position = player.player_position()
result = game.player_move(player)
while result != "victory"
player.update_player_position()
end
puts gam... | true |
658503a08f06ddd87ea50885c8368a148d86fffc | Ruby | jasongoncalves/tealeaf | /intermediatequiz1/2.rb | UTF-8 | 240 | 3.375 | 3 | [] | no_license | statement = "The Flintstones Rock"
def letter_count(str)
counts={}
str.each_char do |char|
next if char == ""
counts[char] = 0 unless counts.include?(char)
counts[char] += 1
end
counts
end
puts letter_count(statement)
| true |
35796415c76424f2792f3c40768bc58b37a1cf55 | Ruby | Steveo00/launchschool | /course_101/small_problems/medium_2/unlucky_days.rb | UTF-8 | 536 | 4.15625 | 4 | [] | no_license | # Write a method that returns the number of Friday the 13ths in the year given by an
# argument. You may assume that the year is greater than 1752 (when the United Kingdom
# adopted the modern Gregorian Calendar) and that it will remain in use for the
# foreseeable future.
require 'date'
def friday_13th(year)
cou... | true |
1baa084ddbb7f1436331b8a709c25e4afeb87181 | Ruby | hidros3/moneybook | /moneybook.rb | UTF-8 | 3,715 | 2.703125 | 3 | [] | no_license | require 'base64'
require 'json'
require 'pg'
require 'sequel'
require 'nokogiri'
require 'google/api_client'
require 'google/api_client/client_secrets'
require 'google/api_client/auth/installed_app'
require 'google/api_client/auth/storage'
require 'google/api_client/auth/storages/file_store'
require 'fileutils'
APPLIC... | true |
d45331420ad000d2c0db1bed35ec89de9c6a70ca | Ruby | KirillKayumov/homework | /tests_for_minimalists/if_module_uses_another_module/carwash_locator.rb | UTF-8 | 891 | 2.859375 | 3 | [] | no_license | class CarwashLocator
MAX_DISTANCE = 3000
def self.nearest(coordinates)
washes = Carwash.with_coordinates
washes.select { |wash| wash.distance_to(coordinates) < MAX_DISTANCE }
end
end
----------------------------------------------------------------------------------------
require "rails_helper"
desc... | true |
0567b3e1de1ad81e57eafd644d3908ab5c94457e | Ruby | snex/poker_tools | /spec/models/poker_sessions_stats_spec.rb | UTF-8 | 10,532 | 2.5625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
RSpec.describe PokerSessionsStats do
let(:ps) { class_double(PokerSession) }
let(:hh) { class_double(HandHistory) }
before do
allow(PokerSession).to receive(:all).and_return(ps)
allow(HandHistory).to receive(:with_poker_sessions).with(ps).and_return(hh)
end
describe '.... | true |
40b375626b11a753cd273ab4a90b0e94b7d5785e | Ruby | Zipudhe/Petgato4-Back | /app/controllers/tag_posts_controller.rb | UTF-8 | 3,443 | 2.515625 | 3 | [] | no_license | class TagPostsController < ApplicationController
before_action :set_tag_post, only: [:show, :update, :destroy]
def index
@tag_posts = TagPost.all
render json:@tag_posts, status: 200
end
def show
render json:@tag_post, status: 200
end
def create
@tag_post = TagP... | true |
4b55e1c992a4c05b2e83fe61baecd217856fb0e4 | Ruby | harfangk/exercism | /ruby/queen-attack/queen_attack.rb | UTF-8 | 468 | 3.25 | 3 | [] | no_license | class Queens
def initialize(**queens)
validate_argument(queens)
@white = queens[:white]
@black = queens[:black]
end
def attack?
x1, y1 = @white
x2, y2 = @black
x1 == x2 || y1 == y2 || (x1 - x2).fdiv(y1 - y2).abs == 1
end
def validate_argument(queens)
queens.each do |k, v|
x... | true |
1087222f0adc09b8a0a242daa39dde4337e38c16 | Ruby | jmazrimas/phase-0-tracks | /ruby/solo.rb | UTF-8 | 2,404 | 4.5625 | 5 | [] | no_license |
# Creating a class: DBC Student
# Attributes: name, age, location, current_week, feeling_good
# Methods:
# Advance a week
# Change locations
# Get really pissed at [concept]
# Figure out [concept]
#
###########BUSINESS LOGIC
$students=[]
def numcheck(number)
while "#{number.to_i}"!=number
puts "I didn't u... | true |
ece73596f1ca1b61438977aa11367cb4f44b40a2 | Ruby | Consultancy-Project/frontend | /app/facades/be_facade.rb | UTF-8 | 387 | 2.59375 | 3 | [] | no_license | class BeFacade
class << self
def get_news
articles_json = BeService.recent_news
articles = articles_json[:data].map do |article|
Article.new(article)
end
articles
end
def get_tweets
tweets_json = BeService.recent_tweets
tweets = tweets_json[:data].map do |tweet... | true |
f3deb9ed68af2bf1cc38178f82cf87b5734cc8b2 | Ruby | markandrewj/launchkey-ruby | /lib/launchkey/configuration.rb | UTF-8 | 5,780 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'openssl'
module LaunchKey
##
# Defines and validates configuration options for {LaunchKey::Client}.
class Configuration
OPTIONS = [:domain, :app_key, :secret_key, :keypair, :passphrase, :endpoint,
:use_system_ssl_cert_chain, :http_open_timeout,
:http_read_timeout, :deb... | true |
2486c349de8cd8a35ad415fd7477a5a9925d9e56 | Ruby | nlim/Ruby_Misc | /container_blocks_iterators/procexample.rb | UTF-8 | 701 | 4.21875 | 4 | [] | no_license | class ProcExample
def pass_in_block(&action)
@stored_proc = action
end
def use_proc(parameter)
@stored_proc.call(parameter)
end
end
def create_block_object(&block)
block
end
def n_times(thing)
lambda {|n| thing * n }
end
proc1 = lambda do |a, *b, &block|
puts "a = #{a.inspect}"
puts "b = #{b.insp... | true |
468c2e5cf9ddb31263a6a52c843fc31eeed7358e | Ruby | angie1024/Five-Card-Poker | /poker/lib/deck.rb | UTF-8 | 321 | 3.25 | 3 | [] | no_license | class Deck
attr_reader :deck
SUIT = [ "D", "C", "H", "S" ]
VALUE = (2..14).to_a
def initialize
@deck = []
populate
end
def populate
SUIT.each do |suit|
VALUE.each do |value|
@deck << Card.new(value, suit)
end
end
end
def remove_card
@deck.shuffle.pop
end
end... | true |
9471c3f6bb8d2785f6008c574307dd8d94bd3fd8 | Ruby | kek/simple-ruby-web-server | /server.rb | UTF-8 | 592 | 2.921875 | 3 | [] | no_license | # http://docs.ruby-lang.org/en/2.2.0/TCPServer.html
require "socket"
port = ENV["PORT"] or raise "Must set PORT environment variable"
server = TCPServer.new port
loop do
begin
Thread.start(server.accept) do |socket|
request = []
while line = socket.gets
break if line =~ /^\s*$/
req... | true |
d819d8446a258cd0427121e910d17da3a7899c66 | Ruby | h20dragon/DataMgr | /lib/DataMgr/Model/data_model.rb | UTF-8 | 4,090 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'json'
module DataMgr
class DataModel
attr_accessor :_file
attr_accessor :app_model
attr_accessor :debug
def initialize(f=nil)
@debug=false
if !f.nil?
@_file=f
loadPages(@_file)
end
end
def getAppModel()
@app_model
end
def saveAs(_... | true |
c5c5f737560be83fb25bf46b7bce2a828d50d67d | Ruby | cocococosti/PaperRockScissorsLizardSpock | /juego.rb | UTF-8 | 21,023 | 3.3125 | 3 | [] | no_license | # Fuente: https://www.rubyguides.com/2016/05/weighted-random-numbers/
def random_weighted(weighted)
max = sum_of_weights(weighted)
target = rand(1..max)
weighted.each do |item, weight|
return item if target <= weight
target -= weight
end
end
def sum_of_weights(weighted)
weighted.inject(0) { |sum, (item, w... | true |
5855d05b1b267160fe2e9922a78dd38add763af6 | Ruby | rgreenjr/netcooler | /app/models/tagging.rb | UTF-8 | 1,184 | 2.78125 | 3 | [] | no_license | class Tagging < ActiveRecord::Base
belongs_to :user
belongs_to :tag
belongs_to :taggable, :polymorphic => true
validates_existence_of :user, :tag, :taggable
# Sets the tags on the taggable object. Only adds new tags and deletes old tags.
#
# Tagging.set_on(taggable, 'foo, bar')
#
def self.set_on(t... | true |
c689bfa93f360546eeca41d0989ebc351285258e | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/roman-numerals/4be12861975c4c6d9e8f4313cb556720.rb | UTF-8 | 502 | 3.375 | 3 | [] | no_license | class Fixnum
def to_roman
ones = %w[I X C M]
fives = %w[V L D]
digits = self.to_s.chars.map(&:to_i)
digits.reverse.each_with_index.reduce('') do |roman,(digit,i)|
if i > 2
roman.prepend ones.last * digit
else
case digit
when 4
roman.prepend ones[i] + five... | true |
8e6d7d89ac71080a308c6520042df4b10162af6a | Ruby | MiDeshay/aa_classwork | /W4D5/windows_max_range.rb | UTF-8 | 661 | 3.515625 | 4 | [] | no_license | def windowed_max_range(array, window)
current_max_range = nil
(0..array.length-window).each do |idx| # n
segment = array[idx...(idx+window)]
max = segment.max # m
min = segment.min # m
range = max - min
current_max_range = range if current_max_range.nil?
... | true |
2b265e5723e2125f72aa96843549cf626ef08d29 | Ruby | ucarion/winnow | /spec/fingerprinter_spec.rb | UTF-8 | 1,801 | 2.796875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Winnow::Fingerprinter do
describe '#initialize' do
it 'accepts :guarantee_threshold, :noise_threshold' do
fprinter = Winnow::Fingerprinter.new(
guarantee_threshold: 0, noise_threshold: 1)
expect(fprinter.guarantee_threshold).to eq 0
expect(fprinter.noise_t... | true |
7c5518740f69d3db1f22dc587db7f1f92c349d29 | Ruby | agpelliza/assigner | /lib/assigner.rb | UTF-8 | 1,067 | 2.96875 | 3 | [
"MIT"
] | permissive | class Assigner
def self.assign_each_other!(items, &block)
# Wrap Items to add assignation behavior
wrap(items, &block)
# Random assignation between items
items_copy = items.dup
items.each do |item|
item.assignation = items_copy.delete_at(rand(items_copy.size))
end
# Switch ... | true |
75f0bf10c22f68d53c208a9d243e0503c7bbcc43 | Ruby | shentianyi/warehouse | /demo/move.rb | UTF-8 | 842 | 2.5625 | 3 | [] | no_license | #require_relative 'action.rb'
=begin
class Movable #< Action
def start
before_start
puts ".....start move"
self.state = ActionState::PROCESSING
self.action_record.state = ActionState::PROCESSING
self.target.move_to self.destination_id
end_start
end
def finish
before_finish
puts ... | true |
d0f829101263545d5d9c3a78d02a7f40f61b77b1 | Ruby | upstill/RecipePower-source | /app/models/expression.rb | UTF-8 | 5,657 | 2.765625 | 3 | [] | no_license | class ExpressionValidator < ActiveModel::Validator
def validate(record)
if (record.tag_id)
tag = Tag.find record.tag_id
if record.referent_id
ref = Referent.find record.referent_id
if tag.tagtype != ref.typenum && (tag.tagtype > 0)
record.errors[:tag_id] << "#{tag.name} is a ... | true |
1e6382d1ff490bc19b87035515fe4cd8602cb636 | Ruby | ashbb/shoes_tutorial_html | /src/sample72-4.rb | UTF-8 | 434 | 2.640625 | 3 | [] | no_license | # sample72-4.rb
require 'observer'
class TimeServer
include Observable
def initialize
Thread.start do
[0, 5, 1, 5, 2, 10, 1].each do |ti|
sleep ti
changed
notify_observers ti
end
end
end
end
module TimeWatcher
def update ti
@msg.text += ti.to_s
end
end
Sho... | true |
9ef7ee222bb7c7d461259f9585e1c6929fbeb2c2 | Ruby | gabokappa/chitter-challenge | /lib/chitter_user.rb | UTF-8 | 699 | 2.921875 | 3 | [] | no_license | require 'pg'
require_relative './database_connection'
class ChitterUser
attr_reader :id, :email, :username
def initialize(id:, email:, username:, name:, password:)
@id = id
@email = email
@username = username
@name = name
@password = password
end
def self.add(email:, username:, name:, pa... | true |
07ded33859b8a62053b8e5b38bc1e4893219e259 | Ruby | griffifam/ride-share-rails | /app/controllers/trips_controller.rb | UTF-8 | 1,493 | 2.53125 | 3 | [] | no_license | require 'date'
class TripsController < ApplicationController
def index
@trips = (Trip.all).sort_by do |trip|
trip.id
end
end
def show
@trip = Trip.find_by(id: params[:id])
if @trip.nil?
head :not_found
end
end
def new
@trip = Trip.new
end
def self.find_available_dri... | true |
e836242e4fe47a3abaac9ed597752ba259151a16 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/hamming/5abe3423700e4847ab3c7967073a2ac0.rb | UTF-8 | 268 | 3.1875 | 3 | [] | no_license | class Hamming
def self.compute string_a, string_b
nucleotides_a = string_a.chars
nucleotides_b = string_b.chars
duplex = nucleotides_a.zip(nucleotides_b)
diffs = duplex.reject { |nucleotide| nucleotide[0] == nucleotide[1] }
diffs.size
end
end
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.