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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
1b949e901b629f30c235f2370e9aad73cf6df738 | Ruby | glecklernola/ruby | /loop.rb | UTF-8 | 489 | 3.859375 | 4 | [] | no_license | puts "1 bird on a wire - ha ha ha!"
# for n in 2...100
# puts "#{n} birds on a wire - ha ha ha!"
# end
# 5.times do |i|
# puts "#{i + 2} birds on a wire - ha ha ha!"
# end
# 3. times do
# puts "She loves me, yeah yeah yeah!"
# end
# 2.upto(10) { |n| puts "#[n} birds on a wire - ha ha ha }
x=2
# while x... | true |
4a2fc3abbe617ec4aeecbe082ac5eef079cfc1df | Ruby | wilsonokibe/BasicRuby | /name_raise/bin/main.rb | UTF-8 | 280 | 3.59375 | 4 | [] | no_license | require_relative '../lib/name.rb'
begin
puts "Enter firstname"
firstname = gets.chomp
puts "Enter lastname"
lastname = gets.chomp
name = Name.new(firstname, lastname)
puts "Your name is: #{name.names}"
rescue NameException => detail
puts "#{detail.message}"
end
| true |
b7e7937767356ac24668912df932bdc0c6d7a9fc | Ruby | rdblakemore/linguistics | /lib/linguistics.rb | UTF-8 | 6,355 | 2.609375 | 3 | [] | no_license | #!/usr/bin/ruby
# coding: utf-8
require 'loggability'
# An interface for extending core Ruby classes with natural-language methods.
module Linguistics
extend Loggability
Loggability.level = 0
# Loggability API -- set up a logger for Linguistics objects
log_as :linguistics
# Release version
VERSION = '2.0.4'
... | true |
fdcebf1c56238c0c8dc2665a85c1d94c4695346e | Ruby | krypt/FuzzBert | /spec/test_spec.rb | UTF-8 | 511 | 2.703125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'rspec'
require 'fuzzbert'
describe FuzzBert::Test do
describe "new" do
it "takes a mandatory proc argument" do
-> { FuzzBert::Test.new }.should raise_error
FuzzBert::Test.new( lambda { |data| data }).should be_an_instance_of(FuzzBert::Test)
end
end
describe "#run" do
it "execut... | true |
f2fd62eecd21b33bde85a42f8a4d9ba88367ec98 | Ruby | xiy/os-client-tools | /express/spec/rhc/helpers_spec.rb | UTF-8 | 4,428 | 2.765625 | 3 | [
"Apache-2.0"
] | permissive | require 'spec_helper'
require 'rhc/helpers'
require 'rhc/core_ext'
require 'highline/import'
require 'rhc/config'
describe RHC::Helpers do
before(:each) do
mock_terminal
RHC::Config.initialize
@tests = HelperTests.new()
end
subject do
Class.new(Object) do
include RHC::Helpers
end.new
... | true |
61d46151f5258e8ae2c9a89f8153e7611ad3b152 | Ruby | ivanacorovic/recommender | /app/helpers/application_helper.rb | UTF-8 | 2,107 | 2.703125 | 3 | [] | no_license | module ApplicationHelper
def sign(x)
if x == 0
return 0
else
if x < 0
return -1
else return 1
end
end
end
def entropy(elements)
sum = 0.0
elements.each do |element|
sum += element
end
result = 0.0
elements.each do |x|
zeroFlag = (x ==... | true |
b5426b1e684d72890284b231e73c031524cc688f | Ruby | jeffreychuc/aA-projects | /AA Questions/questionfollow.rb | UTF-8 | 1,506 | 2.828125 | 3 | [] | no_license | require_relative 'QuestionsDatabase'
require_relative 'User'
require_relative 'Question'
class QuestionFollow
def initialize(options)
@id = options['id']
@user_id = options['user_id']
@question_id = options['question_id']
end
def self.followers_for_question_id(question_id)
options =
Questions... | true |
38706b68370cfb3ef9c0f508042ab1b8bd0a95c4 | Ruby | pladdy/dijkstra | /bin/dijkstra | UTF-8 | 533 | 3.421875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'dijkstra'
graph = Dijkstra::Graph.new()
# argument 0 is the file path, argument 1 is the first node, argument 2 the
# second node
if ARGV[0]
graph.file_to_graph( ARGV[0] )
else
puts "please supply a file name"
exit
end
if ARGV[1] and ARGV[2]
short_path_data = graph.find_shortes... | true |
b49e831b41b8876bb8e34a491ebf1daf8a686fad | Ruby | Arepo/TDD-Student-directory | /spec/directory2_spec.rb | UTF-8 | 2,845 | 3.625 | 4 | [] | no_license | require 'directory2'
describe 'adding a student to the directory' do
it 'the directory is empty when first used' do
expect(students).to be_empty
end
it 'adds students to the directory' do
add_student('Bob')
expect(students).not_to be_empty
end
it 'checks that the student saved is the student entered' d... | true |
bab45cba93187d92c6cb75ace5d4fce535878bfc | Ruby | l3iodeez/aa_poker | /poker/spec/card_spec.rb | UTF-8 | 340 | 2.71875 | 3 | [] | no_license | require 'card'
describe Card do
let(:five_of_hearts) { Card.new(5, :hearts) }
describe "#value" do
it "returns the value of the card" do
expect(five_of_hearts.value).to eq(5)
end
end
describe "#suit" do
it "returns the suit of the card" do
expect(five_of_hearts.suit).to eq(:hearts)
... | true |
787c188480d688693bda5c293d35f85b4e6fb658 | Ruby | godspeedyoo/algorithms-practice | /coursera-algorithms-p1/lib/priority_queue/priority_queue.rb | UTF-8 | 285 | 3.453125 | 3 | [] | no_license | require_relative './lib/heap/max_heap.rb'
class PriorityQueue
def initialize(arr = [], max_size)
@mh = ::MaxHeap.new(arr, max_size)
end
def pop
mh.pop
end
def push(el)
mh.insert(el)
end
def <<(el)
push(el)
end
private
def mh
@mh
end
end
| true |
9c874c51d6a8f2b61b5ba8593fbcade1e40493e7 | Ruby | subeshb1/project-back-end | /app/form_objects/create_user_form.rb | UTF-8 | 768 | 2.515625 | 3 | [] | no_license | # frozen_string_literal: true
class CreateUserForm < FormObjects::Base
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z\d\-]+)*\.[a-z]+\z/i.freeze
attr_reader :params
def initialize(params = {})
@params = params
super()
end
def validate
validate_email
validate_password
validate_no_use... | true |
3979e2414f5dedd8c02f38860a452363cf50ccf6 | Ruby | yutoJ/ruby_samples | /test/color/RGBTest.rb | UTF-8 | 607 | 2.890625 | 3 | [] | no_license | require 'minitest/autorun'
require './lib/color/RGB'
class RGBTest < Minitest::Test
def test_hex_s
assert_equal '00', to_hex_rgb(0)
assert_equal 'ff', to_hex_rgb(255)
assert_equal '78', to_hex_rgb(120)
end
def test_hex
assert_equal '#000000', to_hex(0,0,0)
assert_equal '#ffffff', to_hex(255... | true |
41ad175de0028f7e3154021b36a3fb6b521a5d63 | Ruby | richbai90/elastic | /data/rubies/swrequest.rb | UTF-8 | 4,330 | 2.65625 | 3 | [] | no_license | def add_default_keys_to_event(event, keys)
keys.each do |name|
name = "@metadata" if name == "metadata"
name = name.split(".")
name[0] =~ /s$/ ? event.set(name[0], []) : event.set(name[0], {})
end
end
def handle_unamed_cols(message)
i = 1
message["query"].scan(/\w+\(.*?as '?([\w\.]+)'?/) do |name|
... | true |
675150b14cc60cb9123ef20965b980a38e3a40fb | Ruby | ThePhD/awesome-black-developers | /action/create-readme.rb | UTF-8 | 2,986 | 2.921875 | 3 | [
"CC0-1.0",
"LicenseRef-scancode-proprietary-license",
"LicenseRef-scancode-public-domain"
] | permissive | #!/usr/bin/env ruby
#/ Usage: ./action/update-photos
#/ Update the local README photo wall to reflect the current developers listed in
# bdougie/awesome-black-developers.
require "yaml"
class Readme
DEFAULT_README = "README.md"
def initialize(filename: DEFAULT_README)
@filename = filename
@developers = re... | true |
9f409d29ba12caed4a50de318e3a50b8101d6ddc | Ruby | jayshess/RM-academy | /wargame/gf_card.rb | UTF-8 | 507 | 3.28125 | 3 | [] | no_license |
#load '../card.rb'
require_relative 'card.rb'
class GfCard < Card
def initialize (name)
@rank, @suit = name.split
end
attr_reader :rank
def ranks
@@ranks
end
def has_rank?(test_rank)
rank == test_rank
end
def rank_to_num
(ranks.index(rank)+2)
end
def equivalent_to other
... | true |
dbd637643a48571d7950ada7b7d5b276417ca54c | Ruby | kimoto-naoki/original_app | /spec/models/user_spec.rb | UTF-8 | 2,192 | 2.546875 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
before do
@user = FactoryBot.build(:user)
end
describe 'ユーザー登録機能' do
context 'ユーザー登録できるとき' do
it '全ての項目を正しく入力すれば登録できる' do
expect(@user).to be_valid
end
end
context 'ユーザー登録できないとき' do
it 'player_nameが空では登録できない' ... | true |
221fe7ede61b7c6fdb03066bb0fe501ddb6aaaea | Ruby | DmitryBochkarev/mem_db | /lib/mem_db/out.rb | UTF-8 | 329 | 2.78125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
class MemDB
class Out
include Enumerable
def initialize
@arr = []
end
def add(res)
@arr.push(res)
true
end
def each(&block)
return to_enum unless block_given?
@arr.each do |values|
values.each(&block)
end
end
... | true |
a3323e2e4a7ed2929ef858f6ebdeb7938a817721 | Ruby | michaelstsnow/reverse-each-word-cb-000 | /reverse_each_word.rb | UTF-8 | 357 | 3.390625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def reverse_each_word(phrase)
broken_phrase=phrase.split(" ");
final_phrase="";
broken_phrase.each{ |word|
word_r = word.reverse();
final_phrase = "#{final_phrase}#{word_r} ";
}
final_phrase[0...-1]
final_phrase="";
broken_phrase.collect{ |word|
final_phrase = "#{final_phrase}#{word.reverse(... | true |
054f7f4a1ef79624aa23033eca7fbe8427634c15 | Ruby | agpiermarini/apicurious-github | /app/models/push_event.rb | UTF-8 | 695 | 2.796875 | 3 | [] | no_license | class PushEvent
attr_reader :created_at
def initialize(push_event_info)
@repo_info = push_event_info[:repo]
@payload_info = push_event_info[:payload]
@created_at = push_event_info[:created_at]
end
def repo_name
repo_info[:name].split("/")[1]
end
def commits
generate_commits
end
pr... | true |
0e2977d6d17936e3820c43d769087b1bbe951630 | Ruby | domtunstill/gilded-rose-ruby | /lib/gilded_rose.rb | UTF-8 | 959 | 3.234375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative 'item'
# GildedRose class is the default class and handles the list of items
class GildedRose
def initialize(items, **item_classes)
@items = items
@normal_item = item_classes[:normal_item] || NormalItem
@special_items = {
'Sulfuras, Hand of Ragnaros' ... | true |
5fa86258197fd4f0a138f3a8127c8e30b6d94117 | Ruby | GKhalsa/coding_exercises | /may_13/ruby/bst.rb | UTF-8 | 747 | 3.703125 | 4 | [] | no_license | require 'pry'
class Bst
attr_accessor :left, :right, :data
def initialize(data)
@data = data
@left = nil
@right = nil
end
def insert(num)
new_link = Bst.new(num)
if num > data
insert_right(new_link, num)
elsif num <= data
insert_left(new_link, num)
end
end
def inse... | true |
a824a2dccb86dea049e37a53bd70ae6b13802b53 | Ruby | embulk/embulk | /embulk-ruby/lib/embulk/data_source.rb | UTF-8 | 5,772 | 2.578125 | 3 | [
"MIT",
"Apache-2.0",
"LicenseRef-scancode-public-domain",
"BSD-2-Clause",
"NAIST-2003",
"BSD-3-Clause",
"LicenseRef-scancode-unicode",
"ICU",
"CC-PDDC",
"GPL-1.0-or-later",
"EPL-1.0",
"LicenseRef-scancode-free-unknown",
"LicenseRef-scancode-proprietary-license",
"LicenseRef-scancode-other-... | permissive | module Embulk
require 'json'
module Impl
# copied from https://github.com/intridea/hashie/blob/da232547c29673a0d7a79c7bf2670f1ea76813ed/lib/hashie/extensions/indifferent_access.rb
module IndifferentAccess
def self.included(base)
#Hashie::Extensions::Dash::IndifferentAccess::ClassMethods.tap d... | true |
98b5a056a8b7bf03512fa573f504c1ab57459693 | Ruby | jamesangie/Programming-Language-Projects | /Big projects/Language with Expresions(Ruby and F#)/a1t3p2-testing.rb | UTF-8 | 4,021 | 3.40625 | 3 | [] | no_license | # coding: utf-8
#---------------------------------------------------------------------
# Assignment 1, Task 3, Part 2
# Testing script
#
# Instructions: this testing script is provided to help ensure
# your program meets the expectations of the assignment.
#
# It will be run with the command
# irb a1t3p2-testing.rb
#... | true |
3df5d71f0483c0fab4de03c58b4151d1eb497ce5 | Ruby | SciMed/topographer | /lib/topographer/importer/strategy/import_status.rb | UTF-8 | 684 | 2.53125 | 3 | [
"MIT"
] | permissive | module Topographer
class Importer
module Strategy
class ImportStatus
attr_reader :errors, :input_identifier, :timestamp
attr_accessor :message
def initialize(input_identifier)
@input_identifier = input_identifier
@errors = {mapping: [],
validation: []... | true |
e6e9bac5b69caa25148fc6492ed3201d28764280 | Ruby | JustinData/GA-WDI-Work | /w03/d03/Ernie/morning/user.rb | UTF-8 | 270 | 2.84375 | 3 | [] | no_license | require "faker"
require_relative 'user_db'
class User
def initialize(name, id, address, email)
@name = name
@id = id
@address = address
@email = email
end
def to_s
"Name: #{@name} Id: #{@id} Street: #{@address} Email #{@email}"
end
end
| true |
bbc79ae8f5855bca690fc46d45c1ea1f6aa8b607 | Ruby | Fatheadedbaby/Ruby-Games | /numberchaingame.rb | UTF-8 | 1,797 | 3.6875 | 4 | [] | no_license | puts 'Welcome to puzzle game Guess the next number!'
rn = 1 + rand(10)
rn2 = 1 + rand(5)
rn3 = 1 + rand(15)
rn4 = 1 + rand(20)
non = 1
hp = 100
rhp = 75
life = 1
puts 'Welcome to level 1'
puts 'HP: ' + hp.to_s
puts 'What is the next number in the chain?'
rc = rn + rn2 - rn3
print rc.to_s + ', '
... | true |
fb2a4b268e34ac9b6d28feb2cc1ae98d93552e6e | Ruby | wharah/214 | /projects/06/ruby/script.ruby | UTF-8 | 1,370 | 3.78125 | 4 | [] | no_license | Script started on Tue 12 Mar 2019 10:24:07 PM EDT
smw42@gold29:~/CS214/projects/06$ cat print.rb
# print.rb creates and displays a user-specified array
# Output: the contents of the array
#
# Created by: Sarah Whitten
# Date: March 11, 2019
########################################################
#############... | true |
e8fff6cb08029fb8fe2f4c1f4caf7bd32b137fb3 | Ruby | fcarlosdev/the_odin_project | /chess_game/lib/modules/diagonals.rb | UTF-8 | 864 | 3.375 | 3 | [] | no_license | require_relative 'coordenates'
module Diagonals
include Coordenates
def diagonals_between(from,to)
positions = diagonals(from).select {|ps| ps.include?(to[1..2])}.flatten
select_from(positions,from[1..2],to[1..2])
end
def diagonals(from)
from_coordinates = map_to_axis(from)
positions = []
... | true |
a9d48742c6940fad480ca0b8f68b0879ef806d64 | Ruby | FcoJimenez/Intro-Ruby | /Ejercicio2.rb | UTF-8 | 324 | 3.828125 | 4 | [] | no_license | #mostrar numeros impares entre 1 y 255
#ejercicio n2 Coding dojo
# 1.upto(255) do |number|
# if number.odd?
# puts number
# end
# end
1.upto(255) do |number|
puts number if number.odd?
end
#1.upto(255) { |number| puts number if number.odd... | true |
b48b934f2f4c6e9cb05005a07b45853629cae4e8 | Ruby | joshpeterson/mos | /tools/newcs.rb | UTF-8 | 1,384 | 3.15625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
templateCs = %{namespace <namespace>
{
public class <class>
{
}
}
}
templateTest = %{using NUnit.Framework;
namespace <namespace>.Tests
{
[TestFixture]
public class <class>Tests
{
[Test]
public void TheTruth()
{
Assert.That(true, Is.True);
}
}
}
}
def replaceN... | true |
5d04c3d59680ee7bd0f35afa580ceb52b0e29f03 | Ruby | learn-co-students/dumbo-web-102918 | /05-many-to-many/tweet.rb | UTF-8 | 647 | 3.0625 | 3 | [] | no_license | class Tweet
attr_accessor :user, :content
@@all = []
def initialize(content, user)
@content = content
@user = user
@@all << self
end
def username
# self = tweet1 || tweet2.username
# in an instance method,
# self is always the instance
self.user.username
end
def self.all
... | true |
bb8b244925702daf451c3da23a00745f3d0c3d61 | Ruby | bspates/SE331_Fuzzers | /Fuzzers/StageFuzzer.rb | UTF-8 | 2,035 | 2.546875 | 3 | [] | no_license | require './Fuzzers/Fuzzer.rb'
require './Utility/WebSpecific.rb'
require './Utility/DvwaSetup.rb'
require './Fuzzers/XSSFuzzer.rb'
require './Fuzzers/SQLFuzzer.rb'
require './Fuzzers/InputFuzzer.rb'
class StageFuzzer < Fuzzer
def initialize(d, t, c, g, f)
super(d, t, c, f)
@logons = loadLogons
@vecto... | true |
66585fab96af1f2d65eaec032a3d037f8f59a713 | Ruby | Zannisdf/weather-roulette | /app/models/bet.rb | UTF-8 | 430 | 2.71875 | 3 | [] | no_license | class Bet < ApplicationRecord
belongs_to :player
belongs_to :game
after_create :handle_payments
def handle_payments
paying_odds = { green: 15, red: 2, black: 2 }
factor = choice == game.result ? paying_odds[choice.to_sym] : 0
update_player_wallet(factor)
end
def update_player_wallet(factor)
... | true |
f4ff0ce5c3bef5e70a6c3f92ee51e22c279ecfa3 | Ruby | Mimerme/RTermGame | /TerminalGame.rb | UTF-8 | 2,858 | 3.015625 | 3 | [] | no_license | #Library is powered entirely without the Curses library
#Allows for cross-platform support
#Graphics object
require './RenderFactory.rb'
require './RTermGame.rb'
require './keypress.rb'
require 'io/console'
class TerminalGame
def initialize(name, width, height)
@game_name = name
@game_width = width
@g... | true |
662419e0b082b4e3e1b19a85d18036a4469f55b9 | Ruby | lsaville/exercism | /ruby/raindrops/raindrops_v2.rb | UTF-8 | 431 | 2.9375 | 3 | [] | no_license | class Raindrops
def self.translation
number_to_word = Hash.new('')
number_to_word = {
3 => 'Pling',
5 => 'Plang',
7 => 'Plong'
}
end
def self.convert(number)
rain_speak = ''
translation.each do |test_number, rain_word|
rain_speak << rain_word if (number % test_number).... | true |
0aa3356e3ec2193d063c29f2bceb01d1513e222c | Ruby | Rooks-on-Rails/rooks_on_rails | /app/models/game.rb | UTF-8 | 1,947 | 2.75 | 3 | [] | no_license | class Game < ApplicationRecord
scope :available, -> { where('black_player_id IS NULL or white_player_id IS NULL') }
belongs_to :white_player, class_name: 'User', dependent: false, optional: true
belongs_to :black_player, class_name: 'User', dependent: false, optional: true
belongs_to :winning_player, class_name... | true |
dacb8169ddd82f7aca9afcda31d9bad20da2f33b | Ruby | murex/murex-coding-dojo | /Beirut/2016/2016-04-13-LRU-ruby - Continued/lru.rb | UTF-8 | 2,931 | 3.90625 | 4 | [
"MIT"
] | permissive | class LRU
attr_accessor :capacity, :hash, :list
def initialize
@capacity = 5
@hash = {}
@list = DoublyLinkedList.new
end
def get(key)
if !hash.has_key?(key)
return
end
node = list.delete(hash[key])
list.push(node)
return node.data.value
end
def set(key,value)
if... | true |
def2c069fdd519bba0b4359775b6f165d243506f | Ruby | chdezmar/test-jt-ruby | /spec/grid_spec.rb | UTF-8 | 522 | 2.796875 | 3 | [] | no_license | require 'grid'
describe Grid do
subject(:grid) { described_class.new }
it 'has a default x of 10' do
expect(grid.x).to eq(10)
end
it 'has a default y of 10' do
expect(grid.y).to eq(10)
end
it 'can be set with a custom x and y' do
grid = described_class.new(100,100)
expect(grid.x).to eq(10... | true |
4ba929510546c1a351f5bec4265b6b0885d25cb9 | Ruby | jilion/my.sublimevideo.net | /app/services/highcharts_graph_builder.rb | UTF-8 | 800 | 3.03125 | 3 | [] | no_license | # Simple DSL to build Highcharts graph
class HighchartsGraphBuilder
def initialize
@options = {}
@raw_options = []
yield self
end
def option(hash = {})
@options.update(hash)
end
def raw_option(string)
@raw_options << string
end
def draw(options = { on_dom_ready: true })
re... | true |
886ff3e4de556fc9099e6923bc7b9eb80c24f106 | Ruby | mjunaidi/slinky | /lib/slinky/errors.rb | UTF-8 | 2,308 | 2.875 | 3 | [
"MIT"
] | permissive | require 'continuation'
module Slinky
# Common base class for all Slinky errors
class SlinkyError < StandardError
class NoContinuationError < StandardError; end
attr_accessor :continuation
# Continue where we left off
def continue
raise NoContinuationError unless continuation.respond_to?(:ca... | true |
9f347824b1e12172bccf06ae51c8ebd3ce05f98a | Ruby | Federal-Aviation-Administration/faa_auth | /exe/faa_auth | UTF-8 | 1,551 | 2.90625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require_relative "../lib/faa_auth"
require 'highline/import'
result = []
domain = ask("Enter your faa domain: ") { |q| q.echo = true ; q.default = FaaInfo.domain }
login = ask("Enter your #{domain} username: ") { |q| q.echo = true }
passwd = ask("Enter your FAA Access pin : ") { |q| q.echo = "*" ... | true |
e1be41f96ab47731395f614e1340b6242f92876f | Ruby | ConjurTech/fingerpress-server | /app/models/payment_record_time_log.rb | UTF-8 | 2,381 | 2.515625 | 3 | [] | no_license | class PaymentRecordTimeLog < ActiveRecord::Base
belongs_to :payment_record_pay_scheme, dependent: :destroy
belongs_to :payment_record
before_save :calculate_pay, if: :payment_scheme_is_hourly_type?
def payment_scheme_is_hourly_type?
self.payment_record_pay_scheme.hourly?
end
def weekend?
self.dat... | true |
fad5c9d566cd5c7b574a6fc1e8557bef7541085c | Ruby | JoyJing1/W3D3_Associations_ActiveRecord_Partner-Yi-Ke | /URLShortener/app/models/shortened_url.rb | UTF-8 | 1,619 | 2.515625 | 3 | [] | no_license | require 'securerandom'
class ShortenedUrl < ActiveRecord::Base
validates :short_url, presence: true, uniqueness: true
validates :user_id, presence: true
validates :long_url, presence: true, length: {maximum: 1024}
validate :max_5_submissions
belongs_to :submitter,
class_name: :User,
foreign_key: :u... | true |
2a9289343c1e3a57e404c55424fb74b1a3664745 | Ruby | WonderDev21/hb-webapi | /spec/lib/markdown_renderer_spec.rb | UTF-8 | 1,023 | 2.609375 | 3 | [] | no_license | require 'rails_helper'
require 'markdown_renderer'
RSpec.describe MarkdownRenderer, type: :model do
describe '#render' do
let(:renderer) { MarkdownRenderer.new }
{
'# Header' => "<h1>Header</h1>\n",
'**bold text**' => "<p><strong>bold text</strong></p>\n",
'*italicized text*' => "<p><em>it... | true |
b3bcb7c861185faa039d185b0e7217a184695144 | Ruby | havocesp/dev-twofactorauth | /_deployment/regions.rb | UTF-8 | 1,415 | 2.671875 | 3 | [] | no_license | # frozen_string_literal: true
require 'yaml'
require 'fileutils'
data_dir = '../_data'
sections = YAML.load_file("#{data_dir}/sections.yml")
regions_data = YAML.load_file("#{data_dir}/regions.yml")
regions = regions_data['regions']
# Region loop
regions.each do |region|
puts region
dest_dir = "/tmp/#{region}"
... | true |
6f6ddffdf6d890afafe23d76d176207434d338fa | Ruby | wbzyl/rack-codehighlighter | /lib/rack/codehighlighter.rb | UTF-8 | 5,665 | 2.703125 | 3 | [
"MIT"
] | permissive | require 'rack/utils'
require 'nokogiri'
module Rack
class Codehighlighter
include Rack::Utils
# for logging use
FORMAT = %{%s - [%s] [%s] "%s %s%s %s" (%s) %d %d %0.4f\n}
def initialize(app, highlighter = :censor, opts = {})
@app = app
@highlighter = highlighter
@opts = {
... | true |
08900752f7ce8ee85ec704d3a0ad0ff3d7bd2340 | Ruby | 3WFH/ruby-challenges | /each.rb | UTF-8 | 141 | 3 | 3 | [] | no_license | all_tweets = [
"My first tweet",
"Another tweet",
"Yep, another one",
"Four",
"Meh"
]
all_tweets.each do |tweet|
puts tweet
end
| true |
26fe63ce07a74c8cdeea722665c7cc99ff0d8183 | Ruby | ttowncompiled/HackerRank | /Project-Euler+/large_sum.rb | UTF-8 | 729 | 3.6875 | 4 | [] | no_license | #!/bin/ruby
################################################################################
# This is a rather simple problem in most modern languages. Languages
# such as Ruby or Python will autobox integers to BigInt once the number
# becomes too large. However, most system languages such as C/C++, Java, etc.
# wil... | true |
7b8a3ecc78c41119252b1a66131c6184317d7c8f | Ruby | reddyonrails/sitemap-parser | /lib/sitemap-parser.rb | UTF-8 | 3,333 | 2.6875 | 3 | [
"MIT"
] | permissive | require 'nokogiri'
require 'typhoeus'
class SitemapParser
def initialize(url, opts = {})
@url = url
@options = {:followlocation => true, :recurse => false, url_limited_count: 500}.merge(opts)
@from_date = Date.parse(@options[:from_date]) rescue nil
end
def raw_sitemap
@raw_sitemap ||= begin
... | true |
a56b5c20386ea1a3d9ecafe59bb67c6aa18fd2c1 | Ruby | RebekkaRove/RebekkaRove | /Undervisning Rocketlab/christmas-list/wishlist.rb | UTF-8 | 478 | 3.09375 | 3 | [] | no_license | def display_options(input_options)
input_options.each_with_index do |option, index|
puts "#{index + 1} - #{option}"
end
end
def display_wishlist(wishlist)
wishlist.each_with_index do |item, index|
purchased_box = item[:purchased] ? "[X]" : "[ ]" # Ternary
puts "#{index + 1} - #{purchased_box} #{item[... | true |
63f69ab9748b962ad59668f20ea65d9c6aeef605 | Ruby | janlelis/harvester | /lib/harvester/generator/link_absolutizer.rb | UTF-8 | 1,056 | 2.6875 | 3 | [] | no_license | # encoding: utf-8
class Harvester; class Generator; end; end
# This module rewrites relative to absolute links
module Harvester::Generator::LinkAbsolutizer
def self.run(body, base, logger = nil)
logger ||= Logger.new(STDOUT)
require 'nokogiri'
require 'uri'
html = Nokogiri::HTML("<html><body>#{body}... | true |
e7e92866c9f6d75c94de578947b1eff465d53484 | Ruby | OmairRaza9/farm | /farm.rb | UTF-8 | 910 | 3.28125 | 3 | [] | no_license | require_relative 'field'
attr_accessor: :fields :total_harvest
class farm
def initialize()
@fields = []
@total_harvest = 0
end
def add_field(field)
@fields << @field
end
def harvest
@field.each do |field|
@total_harvest += field.production
puts "Harvesting #{field.pro... | true |
e05ce277400abb57dc8902e6159044ae22bb7c49 | Ruby | ArpanMaheshwari144/Complete-Ruby-Programming | /tut72.rb | UTF-8 | 514 | 4.0625 | 4 | [] | no_license | # Method Overriding
class ParentArea
# Constructor
def initialize(w, h)
@width = w
@height = h
end
# To calculate the area from parent class
def getArea
return "Area from Parent class is #{@width * @height}"
end
end
class ChildArea < ParentArea
# To calculat... | true |
7dabcf566845e07f0edeb6a37dad1aa92f98a9b6 | Ruby | GeoffPurdy/fifteen | /lib/fifteen.rb | UTF-8 | 843 | 4.3125 | 4 | [] | no_license | require "player"
class Fifteen
attr_accessor :player, :numbers
def initialize
puts "Hello! What is your name?"
@name = gets.chomp.capitalize
puts "Okay #{@name}, let's get started!"
@player = Player.new
@computer = Player.new
@numbers = [1,2,3,4,5,6,7,8,9]
start
end
def start
@h... | true |
30b959d4f3312c86a8cf12307be8e60bdfb581c4 | Ruby | lbvf50mobile/til | /20190810_Saturday/20190810countElements.rb | UTF-8 | 449 | 2.828125 | 3 | [] | no_license | p "alias x='ruby 20190810_Saturday/20190810countElements.rb'"
# Ruby countElements
require "minitest/autorun"
require_relative "countElements.rb"
require 'ostruct'
describe "countElements" do
it "Pass the tests" do
[
OpenStruct.new({
inputString: "[[0, 20], [33, 99]]",
... | true |
26dd97ae0aad6a87d5bd5638dc649fe5db452669 | Ruby | chaimoosh/sql-library-lab-v-000 | /lib/querying.rb | UTF-8 | 1,265 | 2.65625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def select_books_titles_and_years_in_first_series_order_by_year
"SELECT books.title, books.year
FROM books
JOIN series ON series.id = books.series_id
WHERE series.id = 1
GROUP BY books.year;"
end
def select_name_and_motto_of_char_with_longest_motto
"SELECT characters.name, characters.motto FROM characters... | true |
dc58e8c0346b6a28f305e635eb35a0b4bcaf3a0b | Ruby | Ladas/rjr | /lib/rjr/em_adapter.rb | UTF-8 | 4,412 | 2.921875 | 3 | [
"Apache-2.0"
] | permissive | # EventMachine Adapter
#
# Copyright (C) 2012 Mohammed Morsi <mo@morsi.org>
# Licensed under the Apache License, Version 2.0
require 'singleton'
require 'eventmachine'
# EventMachine wrapper / helper interface, ties reactor
# lifecycle to an instance of this class.
#
# TODO move to the RJR namespace
class EMManager
... | true |
5573ceaae23e3ceb3684037b613259ce23a7d21f | Ruby | thetron/cli | /lib/ninefold/services/runner.rb | UTF-8 | 385 | 2.609375 | 3 | [
"MIT"
] | permissive | # Runs stuff on remote hosts via ssh
require "shellwords"
module Ninefold
class Runner
def initialize(host, command)
print "\e[90mStarting the process, press ctrl+d when you're done:\e[0m\n"
begin
system "ssh -oStrictHostKeyChecking=no #{host} -t '#{command}'"
rescue Interrupt => e
... | true |
19286d9d9107435fd56f4ca9f69d7600d9b42dc6 | Ruby | franky-og/ruby-enumerables-hash-practice-green-grocer-lab-dumbo-web-82619 | /grocer.rb | UTF-8 | 1,773 | 3.0625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def consolidate_cart(cart)
# code here
consolidated_cart = {}
cart.map {|cart_item_hash|
if consolidated_cart.key?(cart_item_hash.keys.first) == true
consolidated_cart[cart_item_hash.keys.first][:count] += 1
else
consolidated_cart[cart_item_hash.keys.first] = cart_item_hash[cart_item_hash.key... | true |
9504bcbed312d1c8c8a3b431b1258eda661e10f5 | Ruby | Willgg/freshair | /lib/tasks/airbnb/cache_all.rake | UTF-8 | 2,032 | 2.671875 | 3 | [] | no_license | namespace :airbnb do
desc "Scrap Airbnb for all destinations supported by Amadeus"
task cache_all: :environment do
destinations = Scraper::european_airports
dates = Scraper::dates
durations = Scraper::DURATIONS
adults_range = Scraper::PEOPLE
puts "#####################################"
puts ... | true |
dee550d65ee2e5dd127c4c684b0fec604c8fc84b | Ruby | ElyKar/ElyKrawler | /TernarySearchTree.rb | UTF-8 | 2,352 | 3.53125 | 4 | [] | no_license | class TSTNode
attr_accessor :size
attr_accessor :c
attr_accessor :val
attr_accessor :left
attr_accessor :mid
attr_accessor :right
end
class TernarySearchTree
attr_accessor :root
attr_accessor :size
def initialize
@root = nil
@size = 0
end
def isEmpty?
return @size == 0
end
def size
return @s... | true |
898c30a9227c72776f4960b2d0628519bf8fb0cf | Ruby | pschwyter/mtg_json_api | /app/models/listed_card.rb | UTF-8 | 2,008 | 2.96875 | 3 | [] | no_license | class ListedCard < ActiveRecord::Base
belongs_to :card
belongs_to :list
after_save :destroy_if_amount_zero
after_save :reconcile_inventory_and_trade
def add(n)
self.amount += n
self.save!
end
def remove(n)
if self.amount > n
self.amount -= n
self.save
else
self.destroy
end
end
def trade... | true |
f715b40f4cc37fc7685f0c6df4e3bac04f8699d4 | Ruby | LewisYoul/ruby-kickstart | /session3/notes/07-hash-iterating.rb | UTF-8 | 710 | 4.4375 | 4 | [
"MIT"
] | permissive | # in 1.8, HASHES ARE NOT ORDERED, if you iterate through them,
# you don't know what order they will be passed
# in 1.9, they will passed to your block in the order they were inserted.
# When you iterate over the hash, you pass it a block, just like
# arrays. But this block takes two arguments, the key and value
stud... | true |
1f33e37f77ff16b31736c8e0977da0e08dbff055 | Ruby | jadamduff/ruby-objects-has-many-through-lab-v-000 | /lib/genre.rb | UTF-8 | 195 | 3.28125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Genre
attr_accessor :name, :songs, :artists
def initialize(name)
@name = name
@songs = []
end
def artists
self.songs.map {|song| song.artist if song.genre == self}
end
end
| true |
13e7480e63f2f78efe7af02d29f7f86f19500618 | Ruby | AjayKThakkar/News-aggregator-plus | /spec/features/user_posts_articles_spec.rb | UTF-8 | 1,312 | 2.546875 | 3 | [] | no_license | require "spec_helper"
feature "users can submit articles", %(
As a slacker
I want to be able to submit an incredibly interesting article
So that other slackers may benefit from my distraction
[x]the form accepts article, title, URL, and description.
[x]when I successfully post an article, it should be saved... | true |
c45d229eb05184a40520232e0cd7b8b694986110 | Ruby | skipjac/ruby-stuff | /generateGroups.rb | UTF-8 | 834 | 2.6875 | 3 | [] | no_license | require 'rubygems'
require 'httparty'
require 'pp'
require 'json'
require 'FileUtils'
require 'open-uri'
require 'nokogiri'
class Zenuser
include HTTParty
base_uri 'https://z3nofskip.zendesk.com'
headers 'content-type' => 'application/json'
def initialize(u, p)
@auth = {:username => u, :password => p}
... | true |
71511b895bdc274d7b3dbb0984ccfc57e4b695d8 | Ruby | feigningfigure/WDI_NYC_Apr14_String | /w01/d03/Keyan_Bagheri/Practice Problems/favorite_colors.rb | UTF-8 | 585 | 3.53125 | 4 | [] | no_license | def find_common_elements(array1,array2)
common_elements = []
array1.each do |item|
array2.each do |item2|
if item == item2
unless common_elements.include? item2
common_elements << item2
end
end
end
end
return common_elements
end
def array_plus(array1,array2)
arra... | true |
e786a37df005050d94392f366d70e3c1cdb31e83 | Ruby | codebar/planner | /lib/services/mailing_list.rb | UTF-8 | 1,699 | 2.546875 | 3 | [
"MIT"
] | permissive | class MailingList
SUBSCRIBED = 'subscribed'.freeze
MEMBER_EXISTS = 'Member Exists'.freeze
attr_reader :list_id
def initialize(list_id)
@list_id = list_id
end
def subscribe(email, first_name, last_name)
return if disabled?
begin
client.lists(list_id).members
.create(body: { ... | true |
9d861fb3ebda32cf2756f3878165e3f8bd494174 | Ruby | rizo/crystal | /spec/type_inference/c_enum_spec.rb | UTF-8 | 693 | 2.546875 | 3 | [] | no_license | require 'spec_helper'
describe 'Type inference: enum' do
it "types enum value" do
mod, type = assert_type("lib Foo; enum Bar; X, Y, Z = 10, W; end end Foo::Bar::X") { int32 }
end
it "allows using an enum as a type in a fun" do
assert_type(%q(
lib C
enum Foo
A
end
... | true |
e3d2e5dc8be9564ec7227b86c308ab2dec35b14a | Ruby | Troy76/Task-List | /task_list.rb | UTF-8 | 408 | 3.1875 | 3 | [] | no_license | task_list = Hash.new
puts "What do you want to put on your task list?"
task = gets.chomp
while task != "exit"
if task_list.has_key?(task)
puts "You already have that task"
else
task_list[task] = 1
end
puts "Do you want to add anything else on your task list. Type exit to find out what is on your list."... | true |
151fc88ddf7c9147768487f79bbdce791d178723 | Ruby | jievans/Chess | /employee.rb | UTF-8 | 1,158 | 3.9375 | 4 | [] | no_license | class Employee
attr_accessor :manager
attr_reader :name, :title, :salary
def initialize(name, title, salary, multiplier = 0.2)
@name = name
@title = title
@salary = salary
@multiplier = multiplier
end
def bonus
@salary * @multiplier
end
end
class Manager < Employee
attr_reader :empl... | true |
5aa576483459f36c3192ae4c8d7973bc13d33bda | Ruby | sjmog/battleships | /lib/ship.rb | UTF-8 | 177 | 2.875 | 3 | [] | no_license | class Ship
attr_reader :position, :size, :direction
def initialize(position, size, direction)
@position = position
@size = size
@direction = direction
end
end | true |
671998f60ce0a95e134cd6c9b79701f89d04b821 | Ruby | apotonick/gemgem | /app/concepts/rating.rb | UTF-8 | 4,953 | 2.828125 | 3 | [] | no_license | # ### Entity
# initialize
# populate
# save/sync
# update_attributes (save strategy)
# accessors
# why: to let the database layer be awesome but without business logic
# ActiveRecord/ActiveModel stuff is optional, so you can start working on a nested concept without having to implement the outer stuff (rateabl... | true |
acbb73e419b540cd9e91875762ba860745347c48 | Ruby | extreem-engineer/extreme-engineer3 | /Strategy/bucho.rb | UTF-8 | 313 | 2.953125 | 3 | [] | no_license | require_relative 'Yakushoku'
class Bucho < Yakushoku
def ask
puts "従来のやり方を踏襲しましょう。"
end
def settle_expense(expense)
puts "部長の東京大阪間の新幹線 グリーン席 #{expense} + 手当 #{teate} です。"
end
def teate
5000
end
end
| true |
016c24046df6c9858b230d1f228da4aa3d8a26dc | Ruby | heathercreighton/atl-ft-nov2016 | /Rails/heather_twitter/app/helpers/tweets_helper.rb | UTF-8 | 1,223 | 2.953125 | 3 | [] | no_license | module TweetsHelper
def get_tagged(tweet)
#Create an empty array to store an instance of our TweetTag data
tweet_tag = []
message_arr = tweet.message.split
message_arr.each_with_index do |word, index|
if word[0] == "#"
if Tag.pluck(:phrase).include?(word)
... | true |
818b27b99f36085d5b3a71e04c7ed558aed5837d | Ruby | unixpickle/PushProvider | /RKBKit/BinaryValue.rb | UTF-8 | 883 | 2.609375 | 3 | [] | no_license | #!/usr/bin/ruby
require 'StringValue'
module KeyedBits
class BinaryString < String
def kbHeader()
lenLen = KeyedBits.bytesRequiredForLength(self.bytesize)
Header.new(Header::TypeData, lenLen, false)
end
def kbWrite(stream)
header = kbHeader
stream.putc(header.encode)
# write length + data... | true |
8ec3a9cccc9a2d1e223676b34be323a661cc240f | Ruby | jmandala/epub_hero | /app/models/product.rb | UTF-8 | 1,242 | 2.8125 | 3 | [] | no_license | class Product < ActiveRecord::Base
module COMPLEXITIES
SIMPLE = :simple
IMAGE_RICH = :image_rich
COMPLEX = :complex
ALL = [SIMPLE, IMAGE_RICH, COMPLEX]
ALL.freeze
end
COMPLEXITIES.freeze
validates_presence_of :title, :print_isbn, :eisbn, :complexity
validates_length_of :title, :... | true |
a7d0704027963bf29d2f3dfbed5513069389672f | Ruby | weemanjz/pairguru | /app/services/movie_data_puller.rb | UTF-8 | 529 | 2.671875 | 3 | [] | no_license | class MovieDataPuller
BASE_URI = "https://pairguru-api.herokuapp.com/api/v1/movies".freeze
def call(title)
@title = title
do_request
parsed_response.dig("data", "attributes") || {}
end
private
attr_reader :title, :response
def do_request
@response = Rails.cache.fetch("#{title} API data",... | true |
3701f6b33956487f83cdaac708d8cd4de6c00ebb | Ruby | mhing/Quixo-Board-Game | /default_scene/players/pieces.rb | UTF-8 | 13,548 | 2.765625 | 3 | [] | no_license | require "game"
require "placement"
require "minimax"
require "ai"
module Pieces
prop_reader :board
prop_reader :victory
def mouse_clicked(e)
place = Placement.new
turn_bar = scene.find("turn_bar")
status_bar = scene.find("status_bar")
###Human vs Human
if production.game_type == ... | true |
31885d468188194adf109e049f4017f8b6ec757a | Ruby | rsupak/tc-challenges | /RubySnake/game.rb | UTF-8 | 2,248 | 3.21875 | 3 | [] | no_license | require 'ruby2d'
require_relative './lib/snake'
# window constants
set title: 'Ruby Snake'
set background: 'lime'
set fps_cap: 10
set width: 640
set height: 640
GRID_SIZE = 20
GRID_WIDTH = Window.width / GRID_SIZE
GRID_HEIGHT = Window.height / GRID_SIZE
# main class
class Game
attr_accessor :apple
attr_reader :fi... | true |
b0ef7cae1a9877140ecc7eeefdf1e8794724d5ad | Ruby | priscillashort/cs271 | /06/assembler/assembler.rb | UTF-8 | 968 | 3.015625 | 3 | [] | no_license | require_relative 'parser'
require_relative 'variable_manager'
require 'fileutils'
class Assembler
attr_reader :asm_file_name, :hack_file_name, :variable_manager
def initialize(asm_file_name)
@asm_file_name = asm_file_name
@hack_file_name = create_hack_file_name
@variable_manager = VariableManager.new
end
... | true |
efd571230c2dff53f7947b300e7ec8f0d4a887c0 | Ruby | djmetzle/project_euler | /113_ruby/solve.rb | UTF-8 | 1,451 | 3.796875 | 4 | [] | no_license | #!/usr/bin/ruby
puts "Euler 113"
def get_single_digit_array
single_digits = Array.new(10, 1)
single_digits[0] = 0
return single_digits
end
def print_out digit_array
digit_array.each_with_index do |x, i|
puts " #{i}: #{x}"
end
end
def iterate_inc digit_array
next_array = Array.new(10,0)
(1.... | true |
4e1667a907bdf4485a923fe895eb9fd1e40f7dc5 | Ruby | OMGDuke/takeaway-challenge | /lib/order.rb | UTF-8 | 970 | 3.484375 | 3 | [] | no_license | require_relative "message"
class Order
def initialize(menu, message_class=Message)
@my_order = []
@menu = menu
@message_class = message_class
end
def my_order
@my_order.dup
end
def add(item, number = 1)
message = "This item is not on the menu"
fail message unless on_menu?(item)
... | true |
c88ff9a02e119d210502c927e07d14a88dfede85 | Ruby | alexanderplotnikov/learn_ruby | /05_book_titles/book.rb | UTF-8 | 497 | 3.671875 | 4 | [] | no_license | class Book
# write your code here
attr_accessor :title
def title
@res = []
@littleWords = ['the', 'over', 'a', 'to', 'from', 'and', 'an', 'in', 'of']
@words = @title.split(" ")
@words.each do |word|
if(not @littleWords.include?(word))
@res.push(word.ca... | true |
d83863179973798445d6b4df987fa5b3e1a4af1e | Ruby | pierreboulanger/fullstack-challenges | /02-OOP/05-Food-Delivery-Day-One/Lars-01-Food-Delivery/app/models/employee.rb | UTF-8 | 431 | 3.078125 | 3 | [] | no_license | class Employee
attr_accessor :orders, :id
attr_reader :password, :status, :name
def initialize(attributes = {})
@id = attributes[:id]
@name = attributes[:name]
@password = attributes[:password]
@status = attributes[:status]
@orders = []
end
def password(password)
password_checker(pas... | true |
b4e906ce8c40939c361e2c67dcfa5bb81247105d | Ruby | Dequisa/dailyprogrammer | /projecteuler-ruby/p1_multiples_of_3_and_4.rb | UTF-8 | 548 | 4.15625 | 4 | [] | no_license |
# If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
# Find the sum of all the multiples of 3 or 5 below 1000.
def sumOfAllMultiples(multiples = [3,5], limit = 1000)
sum = 0
(0...limit).each do |element|
sum += isMultiple(element, ... | true |
63b05473ca25618c7f19bc34cec9b3e30ecd8f30 | Ruby | berto168/sinatra-mvc-lab-web-0916 | /models/piglatinizer.rb | UTF-8 | 530 | 3.796875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class PigLatinizer
VOWELS = "aeiou"
def piglatinize(word)
if VOWELS.include?(word[0].downcase)
word = word + "way"
else
split_word = word.split("")
first_vowel = split_word.find {|letter| VOWELS.include?(letter)}
first_vowel_index = split_word.index(first_vowel)
first_vowel_i... | true |
cc8dedf4ea84df65ca05d90509346b8365534c54 | Ruby | moebooru/moebooru | /lib/dtext.rb | UTF-8 | 4,504 | 2.78125 | 3 | [
"ISC"
] | permissive | # encoding: utf-8
module DText
def parse(str)
return "" unless str
state = ["newline"]
result = ""
# Normalize newlines.
str.strip!
str.gsub!(/(\r\n?)/, "\n")
str.gsub!(/\n{3,}/, "\n\n")
str = CGI.escapeHTML str
# Nuke spaces between newlines.
str.gsub!(/ *\n */, "\n")
... | true |
bdf42b30e74f1bd5ad666dfbaf200ed4cbe99bda | Ruby | jcarver989/kagglein-api | /test/score.rb | UTF-8 | 2,703 | 3.0625 | 3 | [] | no_license | require './test/test_helper'
describe Score do
before do
Score.delete_all
Team.delete_all
end
it "can calculate a score" do
score = Score.calculate_and_record_score("123", [1,0], [1,1])
assert_equal Score.all.size, 1
assert_equal score.api_key, "123"
assert_equal score.score, 0.5
end
... | true |
edd19b82a7bcedf8db3bffd541e4db576af2d76e | Ruby | kendrickbogan/mediblock-backend | /app/models/peer_reference.rb | UTF-8 | 510 | 2.546875 | 3 | [] | no_license | # frozen_string_literal: true
class PeerReference < ApplicationRecord
belongs_to :person
validates :person, presence: true
# The position field is being used on the front end to determine which peer
# reference to fetch, e.g., Peer Reference #1 or Peer Reference #3.
validates :position, presence: true, uni... | true |
b8bea14f9feef7accdf610400007e51a34698cb0 | Ruby | kev-kev/ruby-oo-self-cash-register-lab-nyc04-seng-ft-021720 | /lib/cash_register.rb | UTF-8 | 997 | 3.25 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class CashRegister
attr_accessor :total, :discount, :discounted_total, :cart, :last_transaction
def initialize(discount = 0)
@total = 0
@discount = discount
@cart = []
@last_transaction = 0
end
def total
return @total
end
def add_item(title, price, quant = 1)
# bin... | true |
2fa06a4bdfe9c4b4cc5a412f2c86d823bae116b3 | Ruby | amyamyx/chess | /stepable.rb | UTF-8 | 259 | 2.59375 | 3 | [] | no_license | module Stepable
def possible_end_pos(start_pos,move_set)
res = []
move_set.each do |move|
x,y = start_pos
x += move[0]
y += move[1]
res << [x,y] if x.between?(0,7) && y.between?(0,7)
end
res
end
end
| true |
407cf79353fa7a9514cdfd9670929a3c6988aaad | Ruby | shadchnev/Airpot-test | /lib/plane.rb | UTF-8 | 362 | 2.890625 | 3 | [] | no_license | class Plane
def fly
@flying = true
end
def initialize
@flying = true
end
def flying?
!!@flying
end
def land
@flying = false
end
# this method will always return true
# because you never change the value of @landing,
# so it's nil. Negating nil will return true.
def landing?
!@landing
end
... | true |
501a4328e86efeb46ccb50e1dc5edd9be8c41354 | Ruby | shadman-a/ttt-4-display-board-rb-ruby-intro-000 | /lib/display_board.rb | UTF-8 | 269 | 3.53125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | board = ["X", "O", "X", "O", "X", "X", "O", "X", "O"]
def display_board(spot)
puts " #{spot[0]} | #{spot[1]} | #{spot[2]} "
puts "-----------"
puts " #{spot[3]} | #{spot[4]} | #{spot[5]} "
puts "-----------"
puts " #{spot[6]} | #{spot[7]} | #{spot[8]} "
end
| true |
024771bb53932951a54dade0df0168a55b37cdc2 | Ruby | bruno248/pairprogram | /exo_12.rb | UTF-8 | 276 | 3.40625 | 3 | [] | no_license | puts "année"
annee=gets.chomp.to_i
annee.step(2021, +1) do |i|
puts i
if 2021-i == i-annee
puts "il y a #{2021-i} ans, tu avais la moitié de l'age que tu as aujourd'hui"
else
print "il y a #{2021-i} ans "
puts "tu avais #{i-annee} ans"
end
end | true |
fa170006494d4df10249337df957812b70200dd9 | Ruby | alphagov/e-petitions | /app/models/concerns/topics.rb | UTF-8 | 1,490 | 2.609375 | 3 | [
"LicenseRef-scancode-proprietary-license",
"MIT"
] | permissive | require 'active_support/concern'
module Topics
extend ActiveSupport::Concern
CODE_PATTERN = /\A[a-z][-a-z0-9]*\z/
included do
validate :topics_exist
end
class_methods do
def all_topics(*topics)
where(topics_column.contains(normalize_topics(topics)))
end
alias_method :for_topic, :all_... | true |
04cfb953719d11ec112b80aee1cef2758c527326 | Ruby | jcoleman/mercatorial | /lib/mercatorial/distance_matrix_response.rb | UTF-8 | 874 | 2.75 | 3 | [
"MIT"
] | permissive | class Mercatorial::DistanceMatrixResponse < Mercatorial::GoogleMapsResponse
class ResponseElement
attr_reader :status
attr_reader :success
attr_reader :element
def initialize(parsed_element_json)
@status = parsed_element_json['status']
@success = (@status == 'OK')
@element = parsed... | true |
8f676703a74f9a457e37e772fcc854ee2fcd98ad | Ruby | brunocordeiro180/Astar-algorithm-in-Ruby | /rua.rb | UTF-8 | 370 | 3.078125 | 3 | [] | no_license | class Rua
#Classe usada para armazenar informacao sobre a rua
# O nome e a velocidade nao estao sendo usados neste projeto
attr_accessor :name, :endX, :speed, :startX, :startY, :endY
def initialize(name, numbers)
@name = name
@startX = numbers[0]
@startY = numbers[1]
@endX = numbers[2]
@en... | true |
a9e8b76d53d16d2c5a515a51d95639cecfe7edf3 | Ruby | c1iff/album_organizer | /spec/album_spec.rb | UTF-8 | 1,087 | 2.96875 | 3 | [] | no_license | require('rspec')
require('album')
describe(Album) do
before() do
Album.clear()
@new_album = Album.new({:name =>'Revolver'})
end
describe('#name') do
it('creates a new album object and returns the album name') do
expect(@new_album.name).to(eq('Revolver'))
end
end
describe('.all') do
... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.