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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
c5f6b14c84e7359a4d7996a599b541f6ad2193c8 | Ruby | fishermanswharff/interview-cake | /question-13-rotation-point/spec/cake_question_spec.rb | UTF-8 | 1,569 | 3.296875 | 3 | [] | no_license | require 'spec_helper'
require_relative '../lib/cake_question.rb'
RSpec.describe 'Interview Cake Question 13 Find Rotation Point' do
let(:words) {
[
'ptolemaic',
'retrograde',
'supplant',
'undulate',
'xenoepist',
'asymptote', # <-- rotates here!
'babka',
'banoffee'... | true |
9725d7d30fc7f484e46eb0c44f34495cc5aec5d4 | Ruby | dgopstein/gkv | /spec/gkv_spec.rb | UTF-8 | 3,699 | 2.90625 | 3 | [
"WTFPL"
] | permissive | require 'spec_helper'
describe Gkv do
let(:db) { Gkv::Database.new }
def clear_db
$ITEMS = {}
end
before(:each) { clear_db }
# context "as a gem" do
# it 'has a version number' do
# expect(Gkv::VERSION).not_to be nil
# end
# end
context "on set" do
# it 'sets a key' do
# db.set('... | true |
9a1a0d3e4328a3d0bd211dbdc652ddaabefb929d | Ruby | Doode1524/legends-project | /app/models/hack.rb | UTF-8 | 916 | 2.828125 | 3 | [] | no_license | # class Hack < ActiveRecord::Base
# @sums = []
# @sum_total = []
# def hack
# Champion.all.collect do |champ|
# @sums << {:id =>champ.id, :total => Hash[champ.attributes.except("Name", "Title").sort_by{|k,v| -v}].values.sum}
# end
# @sums.collect do |i|
# ... | true |
fe6cb7e9e1dea9557dba0a0ad66793f92122b7aa | Ruby | snowistaken/slack-cli | /lib/slack.rb | UTF-8 | 1,995 | 2.71875 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'httparty'
require 'dotenv'
require 'table_print'
require 'tty-prompt'
require_relative 'workspace'
Dotenv.load
BASE_URL = "https://slack.com/api/"
KEY = ENV["SLACK_TOKEN"]
def main
workspace = Slack::Workspace.new
prompt = TTY::Prompt.new
continue = true
# active_selection = nil... | true |
f3c9edcab890ec2e9908678ea692ef895247793d | Ruby | LoganBrannan/kwk-l1-ruby-strings-kwk-students-l1-phil-072318 | /invitation.rb | UTF-8 | 417 | 2.921875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
# Code your prompts here!
puts "Hi, you've been invited to a party! What is your name?"
guest_name = gets.chomp
party_name = "Best Halloween Party Ever"
date = "October 31"
time = "6pm"
host_name = "Harry Potter"
# Try starting out with puts'ing a string.
puts "Dear #{guest_name},
you are cordially invit... | true |
63c7a5e7b799fc5eaba77449f4cf752e2b64f73c | Ruby | oren/oren.github.io | /adoption-programs/adoption-program-1/coach.rb | UTF-8 | 1,056 | 3.109375 | 3 | [] | no_license | # encoding: UTF-8
require 'forwardable'
class Ctnr
extend Forwardable
attr_accessor :dict, :length, :it
def initialize()
@dict = {}
@length = 0
@it = -1
end
def push(*args)
args.each do |arg|
@dict[@length.to_s] = arg
@length += 1
... | true |
69f7c13317c343470e35c3d88c118e78f54c82b3 | Ruby | xuanrljp/learn-ruby | /ZBSearch.rb | UTF-8 | 316 | 2.90625 | 3 | [] | no_license | #!/usr/bin/ruby
arr = (1..100000).to_a
#2016-08-31-11:23:31.731920000
#2016-08-31-11:23:31.841111000
#puts Time.now.strftime('%Y-%m-%d-%H:%M:%S.%9N')
s = Time.now
i = 0
while i < 100000
arr.bsearch {|x| x == i }
i = i + 1;
end
e = Time.now
#puts Time.now.strftime('%Y-%m-%d-%H:%M:%S.%9N')
puts e - s | true |
dc8caef2c732f7d6542c622fc2151b55564211bb | Ruby | mattsan/RubyGLUT | /glut.rb | UTF-8 | 3,007 | 2.734375 | 3 | [] | no_license | require 'fiddle/import'
class GLUT
module Lib
extend Fiddle::Importer
dlload '/System/Library/Frameworks/GLUT.framework/GLUT'
GLUT_STROKE_ROMAN = import_symbol 'glutStrokeRoman'
GLUT_STROKE_MONO_ROMAN = import_symbol 'glutStrokeMonoRoman'
extern 'void glutInit(int *argcp, char **argv)'
exte... | true |
85659f258e0ea455e9ccb24aafb1a1cd3d3de7f1 | Ruby | khriskempis/ls_ruby_exercises | /flow_control/conditional.rb | UTF-8 | 244 | 4.15625 | 4 | [] | no_license | puts "Put in a number"
a = gets.chomp.to_i
if a == 3
puts "a is 3"
elsif a == 4
puts "a is 4"
else
puts "a is neither 3, nor 4"
end
if a == 3 then puts "a is 3" end
# or
puts "a is 5" if a == 5
puts "a is not 6" unless a == 6 | true |
4b3c0203d437f7a9016131995de35a2a1e005c9c | Ruby | iseem/dnsimple-ruby | /lib/dnsimple/client/templates.rb | UTF-8 | 2,998 | 2.640625 | 3 | [
"MIT"
] | permissive | module Dnsimple
class Client
module Templates
# Lists the templates in the account.
#
# @see http://developer.dnsimple.com/templates/#list
#
# @return [Array<Struct::Template>]
# @raise [RequestError] When the request fails.
def templates
response = client.get("... | true |
2b1a2532c492fa7ac6b3fab976b1ae100468996e | Ruby | patchcr/ruby_project | /text_analyzer/sandbox/patricksandbox/Rule.rb | UTF-8 | 1,103 | 2.53125 | 3 | [] | no_license | class Rule
require 'Violation.rb'
def initialize table
@table = table
end
def check
# placeholder
end
end
class RuleWait < Rule
def initilize table
super.new(table)
end
def check
i = 0
collection = Violation.new(:wait, @table.path)
@table.table.each_with_index {... | true |
6cc82257f31a3752d6af93af1db8399a925bae8a | Ruby | ltl237/ruby-intro-to-arrays-lab-dumbo-web-career-040119 | /lib/intro_to_arrays.rb | UTF-8 | 475 | 3.75 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def instantiate_new_array
return Array.new
end
def array_with_two_elements
array_two = ['Hello','World']
return array_two
end
def first_element(array)
return array[0]
end
def third_element(array)
return array[2]
end
def last_element(array)
return array[-1]
end
def first_element_with_array_methods(arra... | true |
aa5723e3febfdfbd00a90473885fa806ef138225 | Ruby | kluzny/FizzBuzz | /fizz_buzz_9.rb | UTF-8 | 208 | 2.578125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'open-uri'
sleep 2 # github isn't a cdn
url = "https://raw.githubusercontent.com/kluzny/FizzBuzz/master/fizzbuzz.txt"
open(url) do |file|
file.each_line { |line| puts line }
end
| true |
f01902b9da25842dfb3f09300df2b5732fea69fb | Ruby | atomicobject/minilab | /spec/unit/minilab_wrapper_spec.rb | UTF-8 | 787 | 2.640625 | 3 | [
"MIT"
] | permissive | require_relative "../spec_helper"
describe Minilab::MinilabWrapper do
before { @mox = create_mocks(:minilab_hardware) }
subject { described_class.new(@mox) }
it "forwards methods to the hardware and gives the result" do
@minilab_hardware.razzle(1, 2, "three").returns({ :value => 5 })
assert_equa... | true |
39da28f90fc25104c4ae79732c907b61f2042f4a | Ruby | OmarSkalli/pivotal-cli | /bin/pivotal | UTF-8 | 7,539 | 2.6875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'gli'
require 'git'
require 'launchy'
require 'rainbow'
require 'pivotal_cli'
require 'highline/import'
# Welcome message
puts Rainbow("\nPivotal CLI #{PivotalCli::VERSION}\n").yellow
# Application high level settings
include GLI::App
program_desc 'Pivotal Tracker CLI'
version PivotalCli:... | true |
19ce12c6d823a6bf94b89ea829f6156d79668696 | Ruby | MSCI-245-342/hw-wordgame-codio-guides | /.guides/secure/hw-sinatra-saas-hangperson-ci/autograder/rspec_gradescope_formatter.rb | UTF-8 | 4,412 | 2.78125 | 3 | [] | no_license | require 'rspec/core/formatters/base_text_formatter'
require 'json'
# @see https://gradescope-autograders.readthedocs.io/en/latest/specs/
class RSpecGradescopeFormatter < RSpec::Core::Formatters::BaseTextFormatter
RSpec::Core::Formatters.register(self,
:example_started, # collect points from example n... | true |
de09241ea184c3850346fa6317525148dc1e73b9 | Ruby | rom1te/S2D2_rb | /exo_11.rb | UTF-8 | 131 | 3.015625 | 3 | [] | no_license | puts "Combien de fois veux-tu écrire ?"
number_repetitions = gets.to_i
number_repetitions.times do
puts "Salut, ça farte ?"
end
| true |
aa3875037a6dad27ea3820b3e9c75ab971ddb5b2 | Ruby | caius/BinFiles | /brightbox-usage | UTF-8 | 1,424 | 3.046875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
#
# brightbox-usage
# Figure out how much a brightbox cloud account is using.
#
# Usage:
# Pipe the output of `brightbox-servers list` into the script.
# `brightbox-servers list | brightbox-usage`
#
# Created by Caius Durling on 2011-09-11.
# Copyright 2011 SwedishCampground. All rights... | true |
ebca4b46c033c4f0e4908cbcd05ea177a52f5750 | Ruby | phoozle/toyrobot | /lib/toy_robot.rb | UTF-8 | 824 | 3.375 | 3 | [] | no_license | require './lib/table'
class ToyRobot
VALID_ACTIONS = %w[MOVE LEFT RIGHT REPORT PLACE]
def initialize(options={table: {x_size: 5, y_size: 5}})
@table = Table.new(options[:table])
end
def run
loop do
get_action
end
end
def get_action
# <ACTION> [X,Y,DIRECTION]
match_data = STDIN.... | true |
2b350e0f40b8ca91e617e3d88185c848790966d7 | Ruby | mikkel250/my-collect-online-web-prework | /lib/my_collect.rb | UTF-8 | 155 | 3.203125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
def my_collect(arr)
coll_arr = []
i = 0
while i < arr.length
new_i = yield arr[i]
coll_arr << new_i
i = i + 1
end
coll_arr
end
| true |
e04ef708e24fbd36fba4490ae9dc0d2097c5e88a | Ruby | mikadamsterdam/vins-9mars-2016 | /db/seeds.rb | UTF-8 | 1,492 | 2.609375 | 3 | [] | no_license |
Wine.create!([
{name: "gros plant nantais", description: "dry white wine", origin: "nantaise"},
{name: "corbiere", description: "wine for table", origin: "corbiere"},
{name: "champagne", description: "wine for export and used for special occasion. Particularity: a sparkling wine", origin: "Champagne"},
{name: ... | true |
70e5101549e16f657a61a9269d5935dfee65a35d | Ruby | peterloron/Bunker | /secret.rb | UTF-8 | 675 | 2.640625 | 3 | [] | no_license | require 'rubygems' if RUBY_VERSION < '1.9'
require './jsonable'
require 'sequel'
class Secret < JSONable
@path = ''
@desc = ''
@value = ''
@in_db = false
attr_accessor :path
attr_accessor :desc
attr_accessor :value
def save
if @in_db
$db[:secret].where('path = ?', @path).update(:path => @path, :desc => ... | true |
c6ee572c041cafda3fdb761a4db01b6b6febd81d | Ruby | sanchito59/park_findr_api | /db/seeds.rb | UTF-8 | 1,672 | 2.890625 | 3 | [
"MIT"
] | permissive | class Seed
def self.begin
seed = Seed.new
seed.generate_locations
end
def generate_locations
rand(75..150).times do
locations = []
locations.push(Location.create!(
continent: ["Asia", "Africa", "North America", "South America", "Europe", "Australia"].sample,
... | true |
8193ba220991c880bb9af6f58f44db1916542a1e | Ruby | irevived1/collections_practice-wdf-000 | /collections_practice.rb | UTF-8 | 570 | 3.5625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive |
def sort_array_asc (ar)
ar.sort
end
def sort_array_desc (ar)
ar.sort.reverse
end
def sort_array_char_count (ar)
ar.sort do | a , b |
a.length <=> b.length
end
end
def swap_elements (ar)
ar[1], ar[2] = ar[2], ar[1]
ar
end
def reverse_array (ar)
ar.reverse
end
def kesha_maker (ar)
ar.each do | item |
i... | true |
eccffd82ac1046a8ad636680b7c6cbea579ec546 | Ruby | rangeoshun/wromoror | /spec/shared/entity_spec.rb | UTF-8 | 2,211 | 2.5625 | 3 | [] | no_license | require 'matrix'
require 'shared/entity'
RSpec.describe Entity do
context "is instantiable" do
it "without crashing" do
expect(Entity.new).to be_truthy
end
it "and generates an id for itself" do
entity = Entity.new
expect(entity.id).to be_truthy
expect(entity.id).to be_instance_... | true |
bff373cc5a759178948bd44b314a0bbff1df9dc7 | Ruby | ginoiseau/firehose | /convertemp.rb | UTF-8 | 130 | 3.859375 | 4 | [] | no_license | puts "Enter the degrees in celcius:"
tempc = gets.to_f
tempf = (tempc * 9) / 5 + 32
puts "The temperature is #{tempf} farenheit" | true |
cdc58cf7e950f1d3c954de91cd5a1cf26058ee2c | Ruby | aromsa/garden_center | /tools/console.rb | UTF-8 | 1,085 | 2.65625 | 3 | [] | no_license | require_relative '../config/environment.rb'
zz = Plant.new("ZZ Plant", "tropical")
phlox = Plant.new("Plox", "perennial")
pothos = Plant.new("Pothos", "ivy")
fig = Plant.new("Fig Tree", "woody")
customer1 = Customer.new("Brad")
customer2 = Customer.new("Anitha")
customer3 = Customer.new("Casey")
customer4 = Customer.... | true |
7a3ccfc8abafe443dee08918498192db27d24b4c | Ruby | cheald/srp-bill-calculator | /lib/plans/aps/saver_choice_plus.rb | UTF-8 | 1,050 | 2.53125 | 3 | [
"MIT"
] | permissive | module Plans
module APS
class SaverChoicePlus < Base
include AverageDemandConcern
def self.solar_eligible
true
end
def fixed_charges
13
end
def demand_usage(date, kwh)
case date.wday
when 1..5
case date.hour
when 15...20
... | true |
edf096e64828c96f0411126b6d916e52ee776f99 | Ruby | AmyCohen/my-select-seattle-web-career-012819 | /lib/my_select.rb | UTF-8 | 333 | 3.34375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_select(collection)
# your code here!
if collection.length == 0
return collection
end
count = 0
mod_collection = []
while count < collection.length
if yield(collection[count])
mod_collection << collection[count]
end
count += 1
end
mod_col... | true |
5d47f22008f706ef1de61b215a756124d644ffd8 | Ruby | donrestarone/roll-of-the-die | /exercises/rolls_sorted.rb | UTF-8 | 273 | 3.359375 | 3 | [] | no_license | roll_results =[]
puts "how many times would you like to roll the die?"
roll_times = gets.chomp.to_i
roll_times.times do |number|
roll_result = rand(1..6)
roll_results << roll_result
puts "the result of the roll is #{roll_result}"
end
p roll_results.sort | true |
8427c99f5cc02c92464dd79c5b016cc972769265 | Ruby | mkunkel/board_game_capstone | /spec/models/friend_spec.rb | UTF-8 | 1,418 | 2.859375 | 3 | [] | no_license | require 'spec_helper'
require_relative '../../lib/environment'
describe Friend do
before(:each) do
Environment.test_prepare
@friend = Friend.new(name: "John Doe")
end
context 'class methods' do
describe '.new' do
it "Should initialize an instance of class Friend" do
@friend.class.shoul... | true |
4eb3004edc9cd7027efb7aa97ff90fe859c0c2bc | Ruby | biglam/gfc | /app/models/game.rb | UTF-8 | 5,239 | 3.296875 | 3 | [] | no_license | class Game < ActiveRecord::Base
#game methods go here
# validate :move_is_in_correct_range
# validates :move, :inclusion => 0..8
validates :p1_id, presence: true
validates :p2_id, presence: true
# validates_inclusion_of :move, :in => 0..8
has_and_belongs_to_many :users
WINNING_LINES = [ [0,1,2], [3,4,5], [6,7,8], [0,... | true |
fa0919a5bbce5b294744aa62c67fa050659393d8 | Ruby | athlaliel/ruby-learning | /rindokukai/sample_test.rb | UTF-8 | 862 | 3.125 | 3 | [] | no_license | # minitestとtest-unit
# rubyのインストールと共にインストールされる。
# 実務ではRspecが今は一般的
# Rspecだけはデフォルトでないので、gemのインストールが必要
# 主な検証メソッド
# ①assert_equal b,a
# aがbと等しければパスする
# ②assert a
# aが真であればパスする
# ③refute a
# aが偽であればパスする
# テスト失敗の場合はF(failure)が表示される
# 実行中のエラーはE(error)が表示される
require 'minitest/autorun'
class SampleTest < Minitest::Test
... | true |
760040998113b9dee2dd6f393726f6bb9cb956c4 | Ruby | christian-blades-cb/lazy_high_charts | /spec/options_key_filter_spec.rb | UTF-8 | 1,512 | 2.546875 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + '/spec_helper'
describe LazyHighCharts::OptionsKeyFilter do
it "should filter :pointInterval from seconds to milliseconds" do
hash = LazyHighCharts::OptionsKeyFilter.filter(pointInterval: 1)
hash[:pointInterval].should == 1000
end
describe "filters :pointStart from a Dat... | true |
39267d0ddbed3391f35fa1fb799900175d1cf29e | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/gigasecond/9057d40206ae4a2485486dc0ccccf76a.rb | UTF-8 | 505 | 3.515625 | 4 | [] | no_license | class Gigasecond
ONE_GIGASECOND = (10**9)
def self.from(date)
date_in_seconds = ConvertDate.new(date).to_seconds
ConvertSeconds.new(date_in_seconds + ONE_GIGASECOND).to_date
end
class ConvertDate
def initialize(date)
@date = date
end
def to_seconds
@date.strftime("%s").to_i
... | true |
4c6ad8761c89c2774356ff9067b0a076657b9745 | Ruby | tvaroglu/ruby-exercises | /mythical-creatures/lib/hydra.rb | UTF-8 | 301 | 3.09375 | 3 | [] | no_license | class Hydra
attr_accessor :name, :heads, :immortal, :stomach
def initialize(name='Lernaean Hydra', heads=9)
@name = name
@heads = heads
@immortal = true
@stomach = Array.new
end
def consume(person)
self.stomach << person
person.status = 'dead'
self.heads += 1
end
end
| true |
2eec093765dbc5766714453591610cb54243558e | Ruby | bryanschoeff/financial-app-csharp-scaffolding | /application.rb | UTF-8 | 8,807 | 2.546875 | 3 | [] | no_license | require 'fileutils'
require 'csv'
require 'erb'
require_relative 'EntityFiling.rb'
require_relative 'EditCheck.rb'
require_relative 'EditChecks.rb'
require_relative 'CheckField.rb'
SourceFilter = "Library"
RunDate = Time.new.strftime("%Y.%m.%d")
ApplicationName = "Online_Financial_Statements"
DatabaseName = "OnlineFi... | true |
589b1cb0b331b6b8ada08b7df2fdef5f2444f8d5 | Ruby | roschaefer/story.board | /app/decorators/event_decorator.rb | UTF-8 | 398 | 2.625 | 3 | [
"MIT"
] | permissive | class EventDecorator
def initialize(event)
@event = event
end
def last_started_date_before(moment)
date = @event.activations.before(moment).first&.started_at
if date
date.strftime(Report::DATE_FORMAT)
else
"(Sorry, leider habe ich gerade keine Daten für dich!)"
end
end
def ... | true |
dbacf052f246fd287a963c62c2e9cf60eac37eca | Ruby | BJSummerfield/Prework | /prework/Episode23/Exercise3.rb | UTF-8 | 130 | 3.0625 | 3 | [] | no_license | year = 1996
251.times do
year = year + 4
if year % 400 == 0
puts year
elsif year % 100 == 0
else puts year
end
end | true |
c4481afdb631a2656a85e4cff3f0c14cd1f4d9fd | Ruby | Alippok/Homeworkweek2d1 | /bear_class.rb | UTF-8 | 180 | 2.78125 | 3 | [] | no_license | class Bear
attr_reader(:name, :type, :roar)
attr_accessor(:tummy)
def initialize(name, type, roar, tummy)
@name = name
@type = type
@roar = roar
@tummy = tummy
end
end | true |
bd26a8ff047b21731b442236957c9a0ee5ecd7df | Ruby | dball1126/Coding_problems | /ruby/house_robber_3.rb | UTF-8 | 866 | 3.5625 | 4 | [] | no_license | def rob(root)
return 0 if !root
return root.val if !root.left && !root.right
order = []
queue = [root]
while (queue.length != 0)
node = queue.shift
order.push(node.val)
queue.push(node.left) if node.left
queue.push(node.right) if node.right
end
order[1] =... | true |
5e9abf506aea4a1371183749bd9ad218303e9969 | Ruby | mfusillo/wk_2_hw_karaoke | /guest.rb | UTF-8 | 253 | 2.859375 | 3 | [] | no_license | class Guest
attr_reader :name, :wallet, :favorite_song
def initialize(name, wallet, favorite_song)
@name = name
@wallet = wallet
@favorite_song = favorite_song
end
def pays_fee(bartab)
@wallet -= bartab.entry_fee
end
end
| true |
f11b42d6ea6745266813f0bddc06d1307e4a34c9 | Ruby | cjjones22/RubyLearning | /1_week/3e_age_of_teacher.rb | UTF-8 | 625 | 4.5625 | 5 | [] | no_license | # Write a Ruby program that displays how old I
# am, if I am 979000000 seconds old. Display
# the result as a floating point (decimal)
# number to two decimal places (for example,
# 17.23). Note: To format the output to say 2
# decimal places, we can use the Kernel's
# format method. For example, if x = 45.5678 t... | true |
802d6cc8997f762dbff87d8c9ba4f8829d8b7240 | Ruby | drewundone/development | /ownmethod.rb | UTF-8 | 299 | 3.5625 | 4 | [] | no_license | =begin
def double_number num
num_times_2 = num*2
puts num.to_s + ' doubled is ' + num_times_2
end
double_number 22
=end
tough_var = 'You can\'t even touch my variable'
def little_pest tough_var
tough_var = nil
puts 'HAHA! I ruined your variable'
end
little_pest tough_var
puts tough_var
| true |
efb121b54fdb2024cae60db8feb15d33cce12039 | Ruby | plasticity-dev/JoeRisdonMusic | /app/models/album.rb | UTF-8 | 436 | 2.5625 | 3 | [
"MIT"
] | permissive | class Album < ApplicationRecord
def year
self.release_date.year
end
def self.orderedCollection
collection = {}
Album.all.reverse.each { |album|
if !collection[album.artist]
collection[album.artist] = [album]
else
collection[album.artist].push(album)
end
... | true |
4fa08db35c1416ebca7cbb0cc6d43c1e484b31df | Ruby | JoshTheBlack/Odin_Ruby_Projects | /Bubble_Sort/bubble_sort.rb | UTF-8 | 449 | 3.4375 | 3 | [] | no_license | def bubble_sort(list)
n = list.length
not_sorted = true
while not_sorted do
not_sorted = false
list.each_with_index do |x,i|
next if i == 0
break if i > n
if x < list[i-1]
not_sorted = true
list[i-1], list[i] = x, list[i-1]
... | true |
57492b83d414c57c5a4c31eb9e2f3734c6eee63a | Ruby | nla-asia/barometer | /lib/barometer/utils/time.rb | UTF-8 | 1,942 | 2.875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Barometer
module Utils
module Time
def self.parse(*args)
return unless args.compact.size > 0
if args.first.is_a? ::Time
args.first
elsif args.first.is_a? DateTime
::Time.parse(args.first.to_s)
elsif args.first.respond_to?(:to_time)
args.f... | true |
34aba7895a151d71c8929650d3444c4d75c7e882 | Ruby | akcshing/wk1_d3_homework_quiz | /quiz_answers.rb | UTF-8 | 5,615 | 4.0625 | 4 | [] | no_license | # Homework
## Exercise A
### Given the following data structure:
```ruby
stops = [ "Croy", "Cumbernauld", "Falkirk High", "Linlithgow", "Livingston", "Haymarket" ]
```
### Complete these tasks:
Answers are cumulative..?
1. Add `"Edinburgh Waverley"` to the end of the array
stops << "Edinburgh Waverley"
2. Add `... | true |
cc09a092d6793bc81002de3878e09b58c935e5c2 | Ruby | TejaswiR/coding_practice_problems | /16_identify_merge_point_of_2_linked_lists.rb | UTF-8 | 205 | 2.578125 | 3 | [] | no_license | # You are give 2 linked lists (not necessarily of the same length),
# that merge some where in between. Write a method that takes in
# 2 linked list and identifies the point of merge
def find_merge
end | true |
62910527606d575f6811d09a9801dd5731762e63 | Ruby | Gerula/interviews | /CareerCup/surpasser.rb | UTF-8 | 212 | 3.625 | 4 | [
"MIT"
] | permissive | class Array
def max_surpasser
self.map.with_index { |x, i|
self[i..-1].nil? ? 0 : self[i..-1].count { |y| y > x }
}.max
end
end
puts [2, 7, 5, 5, 2, 7, 0, 8, 1].max_surpasser
| true |
7e3eb25d214c5dd3e9bf8e0d6414474847230035 | Ruby | MakarovCode/RubyWarriorGUI | /lib/ruby_warrior/abilities/rescue.rb | UTF-8 | 855 | 2.828125 | 3 | [] | no_license | module RubyWarrior
module Abilities
class Rescue < Base
def description
"Rescue a captive from his chains (earning 20 points) in given direction (forward by default)."
end
def perform(direction = :forward)
verify_direction(direction)
voice = []
... | true |
34ecd918878489afe58aab39eaff6ad9e5ea2315 | Ruby | egamasa/study | /ruby-cherry-book/Section2/2-4-1_compare_operator.rb | UTF-8 | 166 | 3.265625 | 3 | [] | no_license | # ==比較演算子==
p 1 < 2 # => true
p 1 <= 2 # => true
p 1 > 2 # => false
p 1 >= 2 # => false
p 1 == 2 # => false
p 1 == 1 # => true
p 1 != 2 # => true
| true |
1046f477891b65146c0f6112d48c201a00855dc8 | Ruby | SamWegs/Intro_to_programming_Ruby | /the_basics/exercises.rb | UTF-8 | 765 | 4.03125 | 4 | [] | no_license | # The Basics Exercises
a = "Samuel"
b = "Wegleitner"
puts a + " " + b
n = 3445
thousands = n / 1000
hundreds = n % 1000 / 100
tens = n % 1000 % 100 / 10
ones = n % 1000 % 100 % 10
puts thousands
puts hundreds
puts tens
puts ones
movies_hash = {:Avatar => 1975,
:Forest_Gump => 2004,
:Jaws => 2013,
:Blackfish =>... | true |
b26762b31cc8ac44ff1e95b64a18335fa749a975 | Ruby | louissobel/secret-santa | /make_random_list.rb | UTF-8 | 374 | 3.453125 | 3 | [] | no_license | # ARGV[0] is list of:
# name|email
# Will output a random cycle, eacho line being a
# {name|email}SEPARATOR{name|email}
SEPERATOR = "\t"
list = []
File.readlines(ARGV[0]).each do |line|
line.chomp!
list.push line
end
shuffled = list.shuffle
shuffled.zip(shuffled.rotate).each do |participant, assigned_to|
... | true |
6022879a1d067d884fda1b62256bad2768be796b | Ruby | BrandonTat/Practice-Problems | /leetcode/problems/unique_morse_code_words.rb | UTF-8 | 2,049 | 4.1875 | 4 | [] | no_license | # International Morse Code defines a standard encoding where each letter is mapped to a
# series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c"
# maps to "-.-.", and so on.
#
# For convenience, the full table for the 26 letters of the English alphabet is given below:
#
# [".-","-...","-.-.","... | true |
9daae5e44235c675d0a8d771eec64ca7af823999 | Ruby | mdudzinski/sugarcube | /lib/osx/sugarcube-ui/nsview.rb | UTF-8 | 1,815 | 2.75 | 3 | [
"BSD-2-Clause"
] | permissive | class NSView
class << self
def attr_updates(*attrs)
attr_accessor(*attrs)
attrs.each do |attr|
define_method("#{attr}=") do |value|
if instance_variable_get("@#{attr}") != value
setNeedsDisplay
end
willChangeValueForKey(attr)
instance_varia... | true |
bcf27d3a4375146010d6fcdb6333e793c0a73384 | Ruby | Mikeydlane/exercism-exercises | /ruby/raindrops/raindrops.rb | UTF-8 | 309 | 2.875 | 3 | [] | no_license | class Raindrops
DROPS = {
3 => "Pling",
5 => "Plang",
7 => "Plong"
}
def self.convert(raindrop)
ret = ''
DROPS.each do |num, drop|
if raindrop % num == 0
ret += drop
end
end
ret != '' ? ret : raindrop.to_s
end
end
module BookKeeping
VERSION = 3
end
| true |
7c76f863a22248f871e3cfa42c45d2c98cc6c36e | Ruby | JoePeterson51/auction_2102 | /test/item_test.rb | UTF-8 | 1,544 | 2.9375 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/item'
require './lib/attendee'
require './lib/auction'
class ItemTest < Minitest::Test
def test_it_exists
item1 = Item.new('Chalkware Piggy Bank')
assert_instance_of Item, item1
end
def test_it_has_attributes
item1 = Item.new('Chalk... | true |
d265be89d552eb0cad79416e96d6e9f37bba7d1f | Ruby | vivlock/advent_of_code_2018 | /02/part_one.rb | UTF-8 | 659 | 3.46875 | 3 | [] | no_license | filename = "input.txt"
puts "Going to open '#{filename}'"
ids = Array.new
twos = Array.new
threes = Array.new
#read in the file
fh = open filename
while (id = fh.gets)
char_counts = Hash.new
in_twos = false
in_threes = false
id.each_char do |char|
#use the hash to only count each char once
if (char_c... | true |
ad033f3ed0972f3d47cc2651bdd12a5df2d4eca8 | Ruby | workatbest/coding | /maxSumContiguous.rb | UTF-8 | 972 | 4.3125 | 4 | [] | no_license | # Find the contiguous subarray within an array, A of length N which has the largest sum.
# Input Format: The first and the only argument contains an integer array, A.
# Output Format: Return an integer representing the maximum possible sum of the contiguous subarray.
# Constraints:
# 1 <= N <= 1e6
# -1000 <= A[i] <= 1... | true |
22181a9b659356e57ca046bdb6aa5ebf63317292 | Ruby | lewiseason/yavm | /lib/yavm/stores/gem_spec.rb | UTF-8 | 1,241 | 2.703125 | 3 | [] | no_license | require 'rubygems'
require 'yavm/version'
require 'yavm/stores/base'
module YAVM
module Stores
class GemSpec < YAVM::Stores::Base
REGEX = /(Gem::Specification\.new do \|([^\|]+)\|.*)(\2.version\s+=\s+("|'))(\S+)\4(.*)/m
def name
"gemspec: #{filename}"
end
def glob
'./*.g... | true |
b8916fe6f0f72eb5331e5b77b5a218ea83151628 | Ruby | projecttacoma/bonnie | /lib/ext/patient.rb | UTF-8 | 8,507 | 2.875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module CQM
class Patient
RACE_NAME_MAP={'1002-5' => 'American Indian or Alaska Native','2028-9' => 'Asian','2054-5' => 'Black or African American','2076-8' => 'Native Hawaiian or Other Pacific Islander','2106-3' => 'White','2131-1' => 'Other'}.freeze
ETHNICITY_NAME_MAP={'2186-5'=>'Not Hispanic or Latino', '21... | true |
bdf222eee468cc53f1c3bb8ef46e8de6fdfec186 | Ruby | makandra/Viewpoint | /lib/ews/item_accessors.rb | UTF-8 | 7,252 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive | =begin
This file is part of Viewpoint; the Ruby library for Microsoft Exchange Web Services.
Copyright © 2011 Dan Wanek <dan.wanek@gmail.com>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License ... | true |
0b018ae3029210bb8191931f5aa82dc417bd0ca9 | Ruby | AfonsoTsukamoto/football_api | /lib/football_api/comment.rb | UTF-8 | 416 | 2.703125 | 3 | [
"MIT"
] | permissive | module FootballApi
class Comment < FootballApi::BaseRequest
attr_accessor :id, :important, :is_goal, :minute, :comment
def initialize(hash = {})
@id = hash[:id]
@important = hash[:important]
@is_goal = hash[:isgoal]
@minute = parse_minute(hash)
@comment = hash[:com... | true |
61977fae7b083d058e6a4331302b2dccfb929f58 | Ruby | maxjustus/cool.io-websocket | /examples/echo.rb | UTF-8 | 598 | 2.734375 | 3 | [
"MIT"
] | permissive | # WebSocket echo server
require 'rubygems'
require 'cool.io-websocket'
class EchoConnection < Cool.io::WebSocket
def on_open
puts "WebSocket opened from '#{peeraddr[2]}': request=#{request.inspect}"
send_message("server: Hello, world!")
end
def on_message(data)
puts "WebSocket data received: '#{data}'"
se... | true |
01ab3ebef97a8fd798e3d1864213bb2ca175c3bb | Ruby | knut1027/benchmark | /ruby/sum.rb | UTF-8 | 59 | 3.03125 | 3 | [] | no_license | sum = 0
for num in 1..500000000
sum += num
end
print sum
| true |
9e8dad895776bcd1526e9e1f22f3ef908584c611 | Ruby | denispolicarpocampos/currency_graph | /lib/tasks/save_currencies.rake | UTF-8 | 1,079 | 3.03125 | 3 | [] | no_license | namespace :save_currencies do
desc "Insert all currencies in the database"
task seed: "db:seed" do
begin
res = CurrencyApiService.call
insert_currencies(res)
rescue ActiveRecord::StatementInvalid
end
end
end
def insert_currencies(currencies)
save_values = select_values(currencies... | true |
30b14af4cde60546a71d7f9137ada5789b3f67a1 | Ruby | gwlee1991/extra_projects | /lib/p07_practical.rb | UTF-8 | 368 | 3.46875 | 3 | [] | no_license | require_relative 'p05_hash_map'
def can_string_be_palindrome?(string)
map = HashMap.new
chars = string.chars
chars.each do |char|
if map.include?(char)
map[char] += 1
else
map[char] = 1
end
end
count = 0
map.each do |k, v|
if v == 1
count += 1
if count > 1
... | true |
bb460106406084b9bf3d2ea8e5faca09fc1b6434 | Ruby | RodrigoRGRB/Exercicio_uri | /2791.rb | UTF-8 | 74 | 2.546875 | 3 | [] | no_license | #Exercicio do feijao
entrada = gets.split
puts entrada.find_index('1')+1
| true |
3535046b089b741bf4639b42d212be1148c3fc56 | Ruby | zlw241/adt_w1d5 | /abstract_data_types.rb | UTF-8 | 791 | 3.390625 | 3 | [] | no_license |
class Stack
attr_accessor :stack
def initialize
@stack = []
end
def push(el)
stack << el
end
def pop
stack.pop
end
def show
stack.dup
end
end
class Queue
attr_accessor :queue
def initialize
@queue = []
end
def enqueue(el)
queue << el
end
def dequeue
... | true |
8ce5a11cf11907dba81d2c9178d862f831588f2f | Ruby | RockstarSteph/ar-exercises | /exercises/exercise_6.rb | UTF-8 | 760 | 3.078125 | 3 | [] | no_license | require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
require_relative './exercise_4'
require_relative './exercise_5'
puts "Exercise 6"
puts "----------"
# Your code goes here ...
@store1.employees.create(first_name: "Khurram", last_name: "Virani"... | true |
b4c5017352cbd338c2731eb9ff0349fad7852e45 | Ruby | piotrmurach/necromancer | /lib/necromancer/converters/boolean.rb | UTF-8 | 2,522 | 3.046875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
require_relative "../converter"
require_relative "../null_converter"
module Necromancer
# Container for Boolean converter classes
module BooleanConverters
TRUE_MATCHER = /^(yes|y|on|t(rue)?|1)$/i.freeze
FALSE_MATCHER = /^(no|n|off|f(alse)?|0)$/i.freeze
# An object that ... | true |
e44c75fa072c919b874f7cde17ce8db74e7bd2a1 | Ruby | asengupta/Snail-MapReduce | /map_reduce.rb | UTF-8 | 829 | 3.125 | 3 | [] | no_license | class Partitioner
def run(space)
partitions = {}
space.each do |i|
key = i[:key]
partitions[key] = [] if partitions[key].nil?
partitions[key] << i[:value]
end
partitions
end
end
class Reducer
def initialize(&block)
@function = block
end
def run(pairs)
partitions = Partitioner.new.run(pairs)
... | true |
70f1591733ddc650466da18161524afdd2c5aa4f | Ruby | JS-716/universaly | /app/controllers/flashcards_controller.rb | UTF-8 | 1,663 | 2.5625 | 3 | [] | no_license | class FlashcardsController < ApplicationController
def show
# get all flashcards' ids
@flashcard = Flashcard.find(params[:id])
@exercise = Exercise.find(params[:exercise_id])
# get all flashcards from the exercise session
@exercise_flashcards = @exercise.flashcards
# previous button
if @ex... | true |
bf73e8efc9cf8821ccc210013acdbe50465f6498 | Ruby | jsanchy/launch-school-rb101 | /lesson_3/medium_2/question_4.rb | UTF-8 | 748 | 4.34375 | 4 | [] | no_license | def tricky_method_two(a_string_param, an_array_param)
a_string_param << 'rutabaga'
an_array_param = ['pumpkins', 'rutabaga']
end
my_string = "pumpkins"
my_array = ["pumpkins"]
tricky_method_two(my_string, my_array)
puts "My string looks like this now: #{my_string}"
puts "My array looks like this now: #{... | true |
48acdf7c0f84ef2a5cfa81cbeda867f51abd6bc0 | Ruby | PuzzleFlow/activerecord-postgres-composite-types | /lib/activerecord-postgres-composite-types/active_record_3_2.rb | UTF-8 | 3,844 | 2.65625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # ActiveRecord 3.X specific extensions.
module ActiveRecord
module ConnectionAdapters
class PostgreSQLAdapter
# Quotes the column value to help prevent {SQL injection attacks}
def quote_with_composite_types(value, column = nil)
if value.class < PostgresCompositeType
"'#{PostgreSQLColumn.c... | true |
f2d9ed3fc2db62b74690d7f5e2ae489845dece39 | Ruby | enhua1/MyRecipes | /test/models/recipe_test.rb | UTF-8 | 1,675 | 2.65625 | 3 | [] | no_license | require "test_helper"
class RecipeTest <ActiveSupport::TestCase
def setup
@chef = Chef.create(chefname: "bob", email: "bob@example.com")
@recipe = @chef.recipes.build(name: "Chinese Chicken", summary: "best chinese chicken", description: "Hot oils and chives, add tomato sauce")
#only addin... | true |
224e4efbd105309d8ddececa34153cc919a4d747 | Ruby | datastax/ruby-driver | /lib/cassandra/time.rb | UTF-8 | 3,256 | 3.1875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | # encoding: utf-8
#--
# Copyright DataStax, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agree... | true |
2c68e0b2d0fed3d1783f44a098391d9492587ab2 | Ruby | jirapave/RedisXmlConcept | /lib/redxml/transformer/collection_service.rb | UTF-8 | 9,387 | 2.828125 | 3 | [
"BSD-2-Clause-Views"
] | permissive | require_relative "key_builder"
require_relative "../red_xml_api/collection"
module Transformer
# Class represents an abstraction layer which provides basic functionality to work with Collections.
# It is possible to create, delete or rename collections and much more.
class CollectionService
# C... | true |
b10a609d6a096e8ef5d4537bc4103c2e45bbd311 | Ruby | digineo/rosemary | /lib/rosemary/errors.rb | UTF-8 | 1,824 | 2.75 | 3 | [
"MIT",
"LicenseRef-scancode-proprietary-license",
"CC-BY-4.0",
"CC-BY-SA-2.0",
"CC-BY-3.0",
"LicenseRef-scancode-public-domain",
"ODbL-1.0"
] | permissive | module Rosemary
# Unspecified OSM API error.
class Error < StandardError
attr_reader :data
def initialize(data)
@data = data
super
end
end
# This error occurs when the request send to the server could not be parsed.
class ParseError < StandardError; end
# This error occurs when Ro... | true |
f5d6f2691e0f5fe0a78621145bb1604e9decfc0a | Ruby | carlosgomez2/exercise_rb | /modules.rb | UTF-8 | 306 | 3.421875 | 3 | [] | no_license | module AnotherModule
def do_stuff
puts "this is a test"
end
end
# 'include' takes the module and include the content in to the current scope
include AnotherModule
do_stuff
# module methods can be included into the current scope, even if is not directly within a class, example:
AnotherModule.do_stuff | true |
e9e3d9480bcb50dab7a16c066b0da46254496fac | Ruby | Tanit1/exercices_ruby | /pyramide_while.rb | UTF-8 | 292 | 3.453125 | 3 | [] | no_license | # INIT NUMBER
number = 0
# TANT QUE NOMBRE N'EST PAS ENTRE 1 ET 25 DEMANDE À L'UTILISATEUR
begin
puts "Entrez un nombre entre 1 et 25 : "
print ">"
number = gets.to_i
end while number < 1 or number > 25
i = 1
while 0 < number
print "#" * i + "\n"
number -= 1
i += 1
end | true |
11eaaf880b4e555467f9d647b318ba19c78d6b26 | Ruby | mepsmike/ruby-exercise | /hash/ex2.rb | UTF-8 | 179 | 2.859375 | 3 | [] | no_license | h1 = { "a" => 100, "b" => 200 }
h2 = { "b" => 254, "c" => 300 }
h3 = { "a" =>1000, "b" => 2000}
h1.merge(h2)
puts h1.to_s+"h1 not change"
h1.merge!(h3)
puts h1.to_s+"h1 changed" | true |
8c8b22ccac1083d9dea9ef83b85606d70e9451f0 | Ruby | stevenvoyles/RubyTheHardWay | /ex21.rb | UTF-8 | 1,241 | 4.625 | 5 | [] | no_license | def add(a, b)
puts "ADDING #{a} + #{b}"
a + b
end
def subtract(a, b)
puts "SUBTRACTING #{a} - #{b}"
a - b
end
def multiply(a, b)
puts "MULTIPLYING #{a} * #{b}"
a * b
end
def divide(a, b)
puts "DIVIDING #{a} / #{b}"
a / b
end
puts "Let's do some math with just functions!"
age = add(30, 5)
height = s... | true |
087e2e30439a982e1c577f1c73faf0a57ae53ff0 | Ruby | dawid-sklodowski/game_of_life | /spec/world_spec.rb | UTF-8 | 1,722 | 2.9375 | 3 | [] | no_license | require 'spec_helper'
require 'game_of_life'
describe World do
it 'can be initialized' do
expect{World.new([Cell.new(1,2), Cell.new(2,2)])}.to_not raise_error
end
describe '#length' do
it 'returns proper length' do
World.new([Cell.new(1,2), Cell.new(2,2)]).length.should == 2
end
end
descr... | true |
9cd67e2160cb9fa27a1f07eec48ed704ba708450 | Ruby | Senjai/SCPRv4 | /app/importers/rss_program_importer.rb | UTF-8 | 1,659 | 2.59375 | 3 | [] | no_license | require 'rss'
# We assume that the RSS feeds (podcast) contain an entire episode in each
# item. I don't know if this is always necessarily true.
class RssProgramImporter
include ::NewRelic::Agent::Instrumentation::ControllerInstrumentation
class << self
def sync(external_program)
self.new(external_pro... | true |
28adcae0cc222a72f9614c46cc3667f1dc8102b6 | Ruby | Gerula/Books | /Understanding_Computation/ChapterTwo/simple.rb | UTF-8 | 3,387 | 4.03125 | 4 | [
"ISC"
] | permissive | #simple intepreter
class Thing < Struct.new(:value)
def +(other)
Thing.new(value + other.value)
end
def inspect
"thingy #{value}"
end
end
t = Thing.new(2)+Thing.new(3)
puts t.inspect
#playing around with this struct shit first
class Number < Struct.new(:value) # what the shit is this?
# ha found it http:/... | true |
4998593025a423795ce5028c94c2acd26c0299ce | Ruby | ajriggs/Learning_To_Program_exercises | /shuffle_algorithm.rb | UTF-8 | 602 | 3.421875 | 3 | [] | no_license | def loop_shuffle an_list
not_shuffled = an_list
shuffled = Array.new
# i=10
# while i > 0
# i -= 1
while not_shuffled.count > 1 do
current_rand = rand(not_shuffled.count)
shuffled.push(not_shuffled[current_rand])
#need to delete by index, not value, so that no value is randomly pushed m... | true |
f8e6636b285cb7a5de5b812c555ee69db7b8250a | Ruby | dpholbrook/ruby_small_problems | /challenges/medium_1/nth_prime.rb | UTF-8 | 1,539 | 4.21875 | 4 | [] | no_license | =begin
input: the nth prime
output: the nth prime number
rules:
- input must be 1 or more or raise an argument error
- to find nth prime we check to see if any numbers less than the square root
of the cantidate go into the cantidate evenly
- nth is a class method
algorithm:
- if input is ... | true |
b9b730e07168e4d7c5882b0449513b4e67b4ce05 | Ruby | kerrizor/geocoder | /test/test_helper.rb | UTF-8 | 1,467 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'rubygems'
require 'test/unit'
require 'active_support/core_ext'
$LOAD_PATH.unshift(File.dirname(__FILE__))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
##
# Simulate enough of ActiveRecord::Base that objects can be used for testing.
#
module ActiveRecord
class Base
def initia... | true |
afc52edc4f6d2b55763973af5aec03ef1ed90b22 | Ruby | Arkner/buket | /app/models/father.rb | UTF-8 | 175 | 2.5625 | 3 | [] | no_license | class Father < ActiveRecord::Base
validates :name, :surname, :job, presence: true
attr_accessible :name, :surname, :job
def sum ()
return surname * job;
end
end
| true |
9e11d9d420afd67105ef7c19e213c66feed7e43d | Ruby | SebastianBethell/jungle-rails | /spec/models/user_spec.rb | UTF-8 | 5,198 | 2.765625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
describe 'Validations' do
it 'should create a new user if given all five required fields' do
@user = User.create!(first_name: 'Billy', last_name: 'Bob', email: 'email@email.com', password: 'qweqwe', password_confirmation: 'qweqwe')
e... | true |
f32db4eab8f7adacc34f0d2a98cf7d1cf0022fad | Ruby | pablotarga/project-euler | /00002_fibonacci_even_sum.rb | UTF-8 | 530 | 3.484375 | 3 | [] | no_license | module Math
# plain modulo checking
def self.fibo upto:4_000_000
a, b, sum = 1,1,0
while b < upto
a, b = b, a + b
sum += b if b % 2 == 0
end
sum
end
# getting the next 2 odd numbers to sum
# 1+1=2, 3+5=8, 13+21=34
def self.fibo2 upto:4_000_000
a, b, sum = 1,1,0
while b ... | true |
f597db849853e6403ef507380648f9f16ead5518 | Ruby | w11th/ruby_scripts | /db_preview | UTF-8 | 1,888 | 2.734375 | 3 | [] | no_license | #!/usr/bin/env ruby -w
require 'erubis'
require 'active_record'
require 'optparse'
options = {}
opt = OptionParser.new do |opts|
opts.banner = "Usage: #{$0} [options] hostname.com file1 file2 file3..."
opts.on('-a', '--adapter ADAPTER', 'adapter') do |a|
options[:adapter] = a
end
opts.on('-H', '--host HO... | true |
ee4684a6a616fb8d97baed47328050acd530c084 | Ruby | rednblack99/Oystercard-Mon | /lib/oyster.rb | UTF-8 | 718 | 3.421875 | 3 | [] | no_license | class Oystercard
attr_reader :balance
attr_reader :in_journey
attr_reader :entry_station
MAX_BALANCE = 90
MIN_FARE = 1
def initialize
@balance = 0
@in_journey = false
end
def top_up(amount)
raise 'Max balance exceeded' if (amount + @balance) > MAX_BALANCE
@balance += amount
end
d... | true |
38e5a7dd4645da00b6cef7da9ca398230423974a | Ruby | stephaniemhelm/market_ic_2108 | /spec/vendor_spec.rb | UTF-8 | 1,817 | 3.234375 | 3 | [] | no_license | require 'rspec'
require './lib/item'
require './lib/vendor'
RSpec.describe Item do
it 'exists' do
vendor = Vendor.new("Rocky Mountain Fresh")
expect(vendor).to be_an_instance_of(Vendor)
end
it 'has attributes' do
vendor = Vendor.new("Rocky Mountain Fresh")
expect(vendor.name).to eq("Rocky Mount... | true |
22719b93297689975697a0872d2d87b3df6e1909 | Ruby | Grinner28/tic-tac-toe | /messages.rb | UTF-8 | 850 | 2.90625 | 3 | [] | no_license | module Messages
def display_intro
'Lets play tic-tac-toe'
end
def display_how_many_players
'Are you playing with one or two human players?'
end
def display_ask_name
'Plese enter your name'
end
def display_current_player
"Current player is #{@currentplayer.name}."
end
def display_se... | true |
89c24f7bba7ffcc36622397fe387a61f041a96d8 | Ruby | simcap/cruchot_hq | /lib/token_authentication.rb | UTF-8 | 360 | 2.546875 | 3 | [] | no_license | class TokenAuthentication
FORBIDDEN = [401, {"Content-Type" => "text/html"}, []].freeze
AUTH_TOKEN_PARAM = 'auth_token'.freeze
def initialize(app)
@app = app
end
def call(env)
req = Rack::Request.new(env)
token = req.params[AUTH_TOKEN_PARAM]
if token && ENV[token]
@app.call(env)
e... | true |
53c06d7ba9534e7f6999145e79308b646d40b3fe | Ruby | avertrees/programming-univbasics-4-square-array-dumbo-web-071519 | /lib/square_array.rb | UTF-8 | 180 | 3.390625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive |
def square_array(array)
# your code here
squared = Array.new(array.length)
i = 0
while i < array.length do
squared[i] = array[i]**2
i+=1
end
return squared
end | true |
0334cacec0388a83904ea56ffb38fd34ef46a07d | Ruby | Mattlk13/maglev | /src/kernel/post_prims/IO.rb | UTF-8 | 1,645 | 2.765625 | 3 | [] | no_license | class IO
def self.__cfunctions
unless const_defined?(:CFunctions, false)
transient_const_set(:CFunctions) do
Module.new do
extend FFI::Library
ffi_lib FFI::Library::CURRENT_PROCESS
attach_function :pipe, [:pointer], :int
end
end
end
const_get(:CFu... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.