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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
752c66d6d20f6f123824b72dca376dee468b4b6d | Ruby | DaniG2k/coursera-data-structures-algorithms | /algorithmic-toolbox/dynamic-programming/edit_distance.rb | UTF-8 | 478 | 3.65625 | 4 | [] | no_license | #!/usr/bin/ruby
def levenshtein_distance str1, str2
m, n = str1.length, str2.length
return m if n == 0
return n if m == 0
d = Array.new(m+1) {Array.new(n+1)}
(0..m).each {|i| d[i][0] = i}
(0..n).each {|j| d[0][j] = j}
(1..n).each do |j|
(1..m).each do |i|
d[i][j] = str1[i-1] == str2[j-1] ? d[i... | true |
552aa378d9f41f445b8968697229da31721d01aa | Ruby | pramodsum/Cricket-Draft | /app/models/game_week.rb | UTF-8 | 2,225 | 2.71875 | 3 | [] | no_license | # -*- encoding : utf-8 -*-
class GameWeek < ActiveRecord::Base
include WithGameWeek
HOURS_UNTIL_5_PM = 17
HOURS_UNTIL_NOON = 12
# Final game week
WEEK_17 = 17
# Game week starts on a tuesday (after MNF)
DAYS_IN_WEEK_BEFORE_LOCK = 2
DAYS_IN_WEEK_BEFORE_SUNDAY_LOCK = 5
def self.find_unique_with(game... | true |
bd80fac63c3a0657c48dff858c1b05e5e934a940 | Ruby | easchwar/checkers | /dummy_player.rb | UTF-8 | 843 | 3.25 | 3 | [] | no_license | class DummyPlayer
def initialize(color)
@color = color
end
def play_turn(board)
begin
color_pieces = board.pieces.select { |piece| piece.color == @color }
moves = []
color_pieces.shuffle.each do |piece|
if !piece.jump_moves.empty?
moves << piece.pos
moves <... | true |
2c76062eefc806fae8140b21b57bec4022a30b5b | Ruby | okinawa0721/lesson | /lesson7.3.rb | UTF-8 | 3,124 | 3.734375 | 4 | [] | no_license | =begin
【問1】
以下のクラスを定義して下さい
・「自動車」クラス
・インスタンスの情報として「ナンバー」(ナンバープレートに表示されるやつ)を持つ
・インスタンスの情報として「ID」を持つ
・「ID」は自動車が生成された順番の数値をそのまま付ける
・例えば、1台目であれば「1」、2台目であれば「2」
【問2】
「自動車」クラスに、作成済みの自動車の台数を教えてくれるメソッドを追加して下さい
【問3】
以下のクラスを定義して下さい。
・「トラック」クラス
・「自動車」クラスを継承
・クラスの情報として「積める荷物の重さ」を持つ
・インスタンスの情報として「積んでいる荷物の重さ」を持つ
・以下の「荷物... | true |
888229795f08ed14378ee07832e92a1facbf07ad | Ruby | ashishra0/codewars | /lib/6kyu/duplicate_encode.rb | UTF-8 | 574 | 4.15625 | 4 | [] | no_license | # The goal of this exercise is to convert a string to a new string
# where each character in the new string is "("
# if that character appears only once in the original string,
# or ")" if that character appears more than once in the original string.
# Ignore capitalization when determining if a character is a duplicat... | true |
f43e68ee622f5c976480645384c0ee0db3cb983b | Ruby | abisekrkinfi/Tutorials | /Ruby/name_combine.rb | UTF-8 | 96 | 3.03125 | 3 | [] | no_license | def full_name(fname,*oname)
fname+ oname.join(" ")
end
puts(full_name("check","hi","hey")) | true |
0e9a3fc8d6455cb4d2c4afeaec53ce8b0c4af6c0 | Ruby | Ejo415/ruby-object-attributes-lab-onl01-seng-ft-072720 | /lib/person.rb | UTF-8 | 149 | 2.671875 | 3 | [] | no_license | class Person
def name
@name
end
def name=(new_name)
@name=new_name
end
def job
@job
end
def job=(new_job)
@job=new_job
end
end | true |
85f6fca49f6fd06293888efe05c6cce467bbf9a5 | Ruby | elanthia-online/cartograph | /maps/gsiv/string_procs/wayto/7477_7476.rb | UTF-8 | 91 | 2.578125 | 3 | [
"MIT"
] | permissive | if not kneeling?
fput 'kneel' if Char.race !~ /dwarf|halfling|gnome/i
end
fput 'southeast' | true |
1bedbc9ac6e58e3f2db10ed767dd94644335f6db | Ruby | mboros1/LaunchSchool | /RB101/lesson_5/Q12.rb | UTF-8 | 130 | 3.4375 | 3 | [] | no_license |
arr = [[1, 6, 7], [1, 4, 9], [1, 8, 3]]
arr.sort! do |a,b|
a.select {|x| x % 2 == 1} <=> b.select {|x| x % 2 == 1}
end
p arr
| true |
501878c6649f24eeb981c50c5d8308baec4cbcf6 | Ruby | haroldasai/sep-assignments | /01-data-structures/05-hashes-part-2/separate_chaining/separate_chaining.rb | UTF-8 | 2,119 | 3.65625 | 4 | [] | no_license | require_relative 'linked_list'
class SeparateChaining
attr_reader :max_load_factor
def initialize(size)
@max_load_factor = 0.7
@array = Array.new(size)
@items = 0
end
def []=(key, value)
i = index(key, size)
if @array[i] == nil
@array[i] = Node.new(key, value)
@items += 1
... | true |
16ba301f46d9ed18f365d45987f722d59ca99c56 | Ruby | plapicola/date_night | /lib/node.rb | UTF-8 | 523 | 3.4375 | 3 | [] | no_license | class Node
attr_accessor :title,
:rating,
:left,
:right
def initialize(rating, title)
@rating = rating
@title = title
@left = nil
@right = nil
end
def is_leaf?
return @left == nil && @right == nil
end
def children
children = 1
i... | true |
0aac244134ed75f31c75e1c142a677a34c0378db | Ruby | klr27/CRCP3310_Project4 | /songs.rb | UTF-8 | 2,759 | 3.640625 | 4 | [] | no_license | # Kali Ruppert
# Project 4
# Working with RDBMS
require "sqlite3"
DB_FILE_NAME = "songs.sqlite3.db"
db = SQLite3::Database.new(DB_FILE_NAME)
SQL_SELECT_SONGS = "SELECT songs.name, genres.name, artists.name, albums.name FROM songs, genres, artists, albums WHERE songs.genre_id = genres.id AND songs.album_id = albums.i... | true |
e25e22940191aee712bcc3c21c1007cd9f0a6884 | Ruby | pdbradley/acts_as_scriptural | /lib/acts_as_scriptural.rb | UTF-8 | 1,261 | 3.046875 | 3 | [
"MIT"
] | permissive | class ActsAsScriptural
attr_accessor :chapters, :parsed
def initialize
@chapters = Array.new
end
def parse(str)
unless str.nil?
references = str.split(',')
references.each do |ref|
parsed_reference = Parser.new.parse_reference(ref)
add_chapters(parsed_reference) if parsed... | true |
a95f7aa2cbf73bb157223c1117a45eb696e5e58c | Ruby | ding-an-sich/batch-447 | /livecode/food-delivery-reboot/app/views/customers_view.rb | UTF-8 | 365 | 3.34375 | 3 | [] | no_license | class CustomersView
def ask_user_for_name
puts "What's the name of your customer, chef?"
gets.chomp
end
def ask_user_for_address
puts "Where is your costumer living, chef?"
gets.chomp
end
def print(customers)
customers.each do |customer|
puts "#{customer.id}: #{customer.name}, livi... | true |
ddd2c8fc8b6277c53e4cfb7703f554372529951f | Ruby | btnggg/Homework | /ruby/lab7.rb | UTF-8 | 308 | 3.296875 | 3 | [] | no_license | #exercise 7
#exercise 7.1
arr = [
{:name=>"User1",:email=>"user1@mail.com",:address=>"address 1"},
{:name=>"User2",:email=>"user2@mail.com",:address=>"address 2"},
{:name=>"User3",:email=>"user3@mail.com",:address=>"address 3"}
]
puts arr.select{|n| n[:name]== "User2" }
#exercise 7.2
arr.each(){|n| puts n... | true |
fef0181e3e3710e4706e76e0f68ae97f03c77b9c | Ruby | shorrockin/adventofcode2017 | /05.rb | UTF-8 | 1,973 | 3.65625 | 4 | [] | no_license | require 'pry'
require '../advent2018/utils'
include Utils
part 1 do
def count_steps(instructions)
steps = 0
position = 0
while !instructions[position].nil?
steps += 1
previous_position = position
position += instructions[position]
instructions[previous_position] += 1
end
... | true |
01537624d7409ef61cf8d201fc0488507a68b130 | Ruby | t-townsend/Curiosities-and-fabulous-finds | /spec/models/review_spec.rb | UTF-8 | 931 | 2.578125 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Review, type: :model do
def valid_attributes(new_attributes)
attributes = {
body: "This product is amazing",
rating: 4
}
attributes.merge(new_attributes)
end
describe 'validations' do
it 'requires a rating to be present' do
review = Review.n... | true |
1b716725fd3f7e81fd52231d3d0b6fa5f4b7795b | Ruby | learn-co-students/seattle-web-082619 | /07-sql-and-ruby/cli/lib/note.rb | UTF-8 | 1,107 | 3.375 | 3 | [] | no_license | class Note
attr_accessor :text, :is_complete, :id
def initialize(text)
@id = nil
@text = text
@is_complete = false
end
# queries a database to select all notes
def self.all
# DB[:conn].execute will return array
# where each element in the array is a hash (basically)
notes = DB[:conn]... | true |
fb0b1e1d58502570c0f49c26bd83c771546633b3 | Ruby | cwy007/ruby_basic_tutorial | /part2/chapter5/5.3_unless.rb | UTF-8 | 56 | 3.15625 | 3 | [] | no_license | a = 10
b = 20
unless a > b
puts " a 不比 b 大"
end
| true |
9a25cc8c6d42f10c0d24eeb1b79e291279b8e988 | Ruby | misiu9091909/autocentrum | /config/initializers/string.rb | UTF-8 | 461 | 3.390625 | 3 | [] | no_license | class String
def get_int
return self.gsub(/[^0-9]/, '').to_i
end
def get_float
return self.gsub(/[^0-9,.]/, '').gsub(',','.').to_f
end
def latinize
polish = {'ą' => 'a', 'ć' => 'c', 'ę' => 'e', 'ł' => 'l', 'ń' => 'n', 'ó' => 'o', 'ś' => 's', 'ź' => 'z', 'ż' => 'z'}
return self.split(//).map{... | true |
9e158c3ce08e6331c9b339d0489b519556d11126 | Ruby | hyperstack-org/hyperstack | /ruby/hyper-store/spec/hyper-store/include_and_subclass_spec.rb | UTF-8 | 2,763 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
def class_of(x)
(class << x; self end)
end
# Just checks to make sure all methods are available when either subclassing or including
describe 'subclassing Hyperloop::Store' do
before(:each) do
class HyperStore
include Hyperstack::Legacy::Store
end
class Foo < HyperStore
... | true |
dfa005421e9090b8c1843ddd2b684ef995a13ad2 | Ruby | bfoz/eaglecad-ruby | /lib/eaglecad/layer.rb | UTF-8 | 1,027 | 2.9375 | 3 | [] | no_license | require 'rexml/document'
module EagleCAD
class Layer
attr_accessor :active, :color, :fill, :name, :number, :visible
def self.from_xml(element)
self.new(element.attributes['name'], element.attributes['number'], element.attributes['color'], element.attributes['fill']).tap do |layer|
element.attributes.each... | true |
7d74203aa0d8941286e06b41542bb7f86dabb1e5 | Ruby | sjv-vinsol/Learning | /ruby/exercise_12_character_count/bin/main.rb | UTF-8 | 114 | 3 | 3 | [] | no_license | require_relative '../lib/string'
p 'Enter a string'
input_string = gets.chomp
p input_string.count_chars_by_type | true |
d728680d251280899d7436124f6cf623efa2ac39 | Ruby | fifiteen82726/coda_gem | /lib/coda_gem.rb | UTF-8 | 404 | 2.703125 | 3 | [
"MIT"
] | permissive | require "coda_gem/version"
module CodaGem
# Your code goes here...
def self.create(path)
# A::B::C
# define root
root = Object
#split ::root
path.split('::').each do |name|
new_module = root.const_defined?(name)? root.const_get(name) : nil
unless new_module
new_module = Module.new
... | true |
2a60f94e75ebfdab43afc8d1e3cf4e332c743544 | Ruby | griffifam/grocery-store | /lib/order.rb | UTF-8 | 1,639 | 3.0625 | 3 | [] | no_license | #require_relative '..lib/customer'
class Order
@@orders = []
attr_reader :id
attr_accessor :products, :customer, :fulfillment_status
def initialize(id, products, customer, fulfillment_status=:pending)
@id = id
# if @id.class != integer
# puts "not a num"
# end
@products = products
#... | true |
0d14387010d86e7fe1b8de8be1c844a14c870c68 | Ruby | metaxy/ruby-stuff | /http_download.rb | UTF-8 | 1,506 | 3.03125 | 3 | [] | no_license | #encoding: UTF-8
require 'nokogiri'
require 'httparty'
require 'fileutils'
require 'cgi'
require 'optparse'
def main()
url = nil
path = "./"
optparse = OptionParser.new do|opts|
opts.banner = "Usage: download_http.rb [options]"
opts.on('--url URl', 'Which Site to download. Must end with /' ... | true |
b631eb55de6a6a63cf38d79eb14df62fdee7033c | Ruby | mabubakarAR/E-Commerce-With-ROR | /app/models/user.rb | UTF-8 | 1,447 | 2.546875 | 3 | [] | no_license | class User < ApplicationRecord
acts_as_token_authenticatable
extend Enumerize
enumerize :role, in: [:buyer, :seller, :admin]
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_many :products
validates :email, presence: true, uniqueness: true
validate... | true |
d30a59bae938f93d9fc6405abdc109549b578737 | Ruby | mfssanhueza/desafio_estructuras_control | /ej28.rb | UTF-8 | 199 | 3.5625 | 4 | [] | no_license | # '1impar 2par 3impar 4par 5impar 6par 7impar 8par 9impar 10par'
a = ' '
10.times do |i|
if (i+1).odd?
i = "#{i+1}impar "
else
i = "#{i+1}par "
end
a += i
end
puts a
| true |
72821c9234893bee86e2ea1887491177bd454d76 | Ruby | merhard/golf | /lib/scorecard.rb | UTF-8 | 354 | 2.984375 | 3 | [] | no_license | require 'csv'
class Scorecard
attr_reader :file_path, :player_scores
def initialize(file_path)
@file_path = file_path
end
def scorecard_data_loader
@player_scores = {}
CSV.foreach(@file_path) do |row|
row.map! { |x| x.strip }
@player_scores["#{row[1]} #{row[0]}"] = row[2..19]
e... | true |
061ce7ec51805803c883cc2aa9ddc161b8e49621 | Ruby | jaredjames2020/oo-tic-tac-toe-online-web-pt-090919 | /lib/tic_tac_toe.rb | UTF-8 | 2,782 | 4.15625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class TicTacToe
WIN_COMBINATIONS = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1,4,7],
[2,5,8],
[0,4,8],
[2,4,6]
]
def initialize
@board = Array.new(9, " ")
end
def display_board
puts " #{@board[0]} | #{@board[1]} | #{@board[2]} "
puts "-----------"
... | true |
8598cdba440f5714a9ed7abcadf10a8134c6f4d4 | Ruby | jrichter/flickr_party | /lib/flickr_party.rb | UTF-8 | 2,796 | 2.640625 | 3 | [] | no_license | require 'rubygems'
require 'httparty'
require 'digest/md5'
class FlickrParty
ENDPOINT = 'http://api.flickr.com/services/rest/'
class PhotoURLError < RuntimeError; end
include HTTParty
format :xml
attr_accessor :token
THIRD_LEVEL_METHODS = %w(add browse search delete create find echo login null... | true |
8ed193bac48053f7d849b5e60c770c03ea13eb3c | Ruby | bazwilliams/7langs7weeks | /ruby/exercises/day1/to_file.rb | UTF-8 | 387 | 3.171875 | 3 | [] | no_license | #!/usr/bin/ruby -w
# Version of to_file.rb without using a block
module ToFileNB
def filename
"object_#{self.object_id}.txt"
end
def to_f
f=File.open(filename, 'w')
f.write(to_s)
f.close()
end
end
class Person
include ToFileNB
attr_accessor :name
def initialize(name)
@name ... | true |
bfa17873a4c0528c9e59482f8c9916b0dbb2fcc8 | Ruby | rleber/bun | /lib/hyphenator/knuth_liang.rb | UTF-8 | 38,248 | 3.4375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# -*- encoding: us-ascii -*-
# Hyphenation, using Frank Liang's algorithm.
# This module provides a single function to hyphenate words. hyphenate_word takes
# a string (the word), and returns a list of parts that can be separated by hyphens.
#
# >>> h = Hyphenate::KnuthLiang.new... | true |
7e07dc268b839bdd4c41fdd67212e4bb96c8f018 | Ruby | as3contender/free-courses | /task2.rb | UTF-8 | 540 | 3.78125 | 4 | [] | no_license | # Task 2
def minRotation(str1, str2)
return -1 if str1.size != str2.size
i = str2.index(str1[0])
if (i == nil)
return -1
elsif (i == 0)
if (str1.include?(str2))
return 0
else
return -1
end
else
if ((i) > str1.size/2.to_i)
j = str1.size-i
else
j = i
end... | true |
d79cbfc99e06bc618fc09a58de99e0e173f9adf1 | Ruby | danfaeh/prime-ruby-001-prework-web | /prime.rb | UTF-8 | 154 | 3.421875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def prime?(int)
if int % 2 > 0 && int % 3 > 0 && int != 1 || int == 2 || int == 3
puts true
true
else
puts false
false
end
end
| true |
9684ec2f31a06765aa6486afbf1846209ae40c4e | Ruby | cdallasanta/ropes-sinatra | /db/seeds.rb | UTF-8 | 776 | 2.6875 | 3 | [
"MIT"
] | permissive | #create elements
catwalk = Element.create(name:"Catwalk")
pirates_crossing = Element.create(name:"Pirate's Crossing")
#create ropes
green_details = {
primary_color: "green",
pcord_color: "black",
element:catwalk
}
blue_details = {
primary_color: "blue",
pcord_color: "black",
element:catwalk
}
green_rope = ... | true |
d9439112717804f1c00695f30002298503d13d7f | Ruby | LVALL/html_maker | /lib/html_maker.rb | UTF-8 | 968 | 2.625 | 3 | [] | no_license | require 'nokogiri'
class MakeHtml
def make_html(content, bypass_html, file_name = 'index.html')
markup = content.gsub!(/[<>]/, '') if bypass_html == false
markup = content unless bypass_html == false
f = File.new("#{Dir.pwd}/#{file_name}", "w+")
f.puts "<!DOCTYPE html>"
f.puts " <head>"
f.p... | true |
e073b4b40f5ebc14ff67c54fe2e90da71942c66f | Ruby | mpokropowicz/mined_minds_kata | /pairs.rb | UTF-8 | 289 | 3.765625 | 4 | [] | no_license | letters = ["a","b","c","d","e", "f", "g"]
def random_Pairs(arry)
arry.shuffle!
arry = arry.each_slice(2).to_a
if arry.size % 2 == 0
arry[arry.size - 2] = arry[arry.size - 2] + arry.last #let's put the group of 3 at the end
arry.pop
end
arry
end
print random_Pairs(letters) | true |
3fe9bcecaf7540d72590b71fc0e0e465d009feaa | Ruby | cowplow/Project-Euler | /56.rb | UTF-8 | 233 | 3.265625 | 3 | [] | no_license | start = Time.now
answer = 0
2.upto(100) do |x|
1.upto(x-1) do |y|
sum = 0
num = x**y
arr = num.to_s.each_char do |a|
sum += a.to_i
end
if sum > answer
answer = sum
end
end
end
puts answer
puts Time.now - start
| true |
78cfeff926fb9dffa42d3c6a00c8109bd9a54011 | Ruby | dcrocco/aydoo-2018-ruby | /mail_merger/model/procesador_de_sum.rb | UTF-8 | 273 | 2.84375 | 3 | [] | no_license |
class ProcesadorDeSum
def procesar(template, datos)
suma_en_template = template.scan(/<sum\(\d+, \d+\)>/)
suma_en_template.each do |numeros|
template = template.gsub(numeros, numeros.scan(/\d+/).map(&:to_i).reduce(:+).to_s)
end
template
end
end | true |
0732b25c98ba1573755635a5aa399a961aec687e | Ruby | e-barr/key-for-min-value-prework | /key_for_min.rb | UTF-8 | 380 | 3.59375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # prereqs: iterators, hashes, conditional logic
# Given a hash with numeric values, return the key for the smallest value
def key_for_min_value(name_hash)
return nil if name_hash == {}
smallest_key = name_hash.first[0]
smallest_val = name_hash.first[1]
name_hash.each do |pair|
if pair[1] < smallest_val
... | true |
a5449968264d84bc710dfb445559547f2347ad10 | Ruby | bstiber/launch_school_exercises | /small_problems_2nd_round/ruby_basics/strings/10.rb | UTF-8 | 709 | 4.5 | 4 | [] | no_license | # Are You There? Using the following code, print true if colors includes the color 'yellow' and print
# false if it doesn't. Then, print true if colors includes the color 'purple' and print false if it
# doesn't.
colors = 'blue pink yellow orange'
# input
# string variable
# output
# string
# rules
# use existi... | true |
16c59ee3af5a8e6c6c22999eb32c88109845e253 | Ruby | ChadRehmKineticData/kinetic-agent-handler-execute | /handler/init.rb | UTF-8 | 3,826 | 2.78125 | 3 | [
"MIT"
] | permissive | # Require the dependencies file to load the vendor libraries
require File.expand_path(File.join(File.dirname(__FILE__), "dependencies"))
class KineticAgentHandlerExecuteV1
def initialize(input)
# Set the input document attribute
@input_document = REXML::Document.new(input)
# Retrieve all of the ... | true |
1a6612adb25ca9024cf65fd0dd27e67ca93caa23 | Ruby | RaeRachael/Oystercard | /spec/journey_spec.rb | UTF-8 | 2,380 | 2.984375 | 3 | [] | no_license | require_relative "../lib/journey.rb"
describe "Journey" do
let(:card_double) {double(:card)}
let(:station) {double(:station_a)}
let(:exit_station) {double(:station_b)}
before do
journey = Journey.new(card_double)
end
describe '#start(station, card = default)' do
it "should change #incomplete to ... | true |
17a564cb55dee4d78448497c3f83fa93fa63c942 | Ruby | FreeApophis/CodeChecker | /lib/TestResult.rb | UTF-8 | 500 | 3.015625 | 3 | [
"MIT"
] | permissive | class TestResult
attr_reader :file, :fails
Struct.new("TestFailed", :message, :line)
def initialize file
@done = false
@file = file
@fails = []
end
def status
if @fails.any?
:failed
else
if @done
:passed
else
:none
end
end
end
... | true |
d8c59f94f239b0d9b5ccbcd5eda7637cc935fdaa | Ruby | k-coffee/atcoder | /Beginner21/1.rb | UTF-8 | 170 | 3.046875 | 3 | [] | no_license | #!/usr/bin/ruby -Ku
mask = 0x01
ans = Array.new()
tmp = 1
x = gets.to_i
while x > 0
if x & mask == 1
ans << tmp
end
x /= 2
tmp *= 2
end
puts ans.size, ans
| true |
884ea69d05f327ef094427df1fa163f5d517d26a | Ruby | vosechu/exercism.io | /assignments/ruby/binary-search-tree-1/test.rb | UTF-8 | 1,261 | 2.890625 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require_relative 'bst'
class BstTest < MiniTest::Unit::TestCase
def test_data_is_retained
assert_equal 4, Bst.new(4).data
end
def test_inserting_less
skip
four = Bst.new 4
four.insert 2
assert_equal 4, four.data
assert_equal 2, four.lef... | true |
9233d87ddba9ca2693ea71e0006520d44c510f4f | Ruby | brady-robinson/ls-rb101 | /lesson_3/medium3.rb | UTF-8 | 330 | 3.84375 | 4 | [] | no_license | def factors(number)
divisor = number
factors = []
if number > 0
loop do
factors << number / divisor if number % divisor == 0
divisor -= 1
break if divisor == 0
end
factors
elsif number <= 0
"Invalid input. Please enter a number greater than 0."
end
end
puts factors(10)
puts ... | true |
1e4b901e62d415a5395d651b2a07e5378a468276 | Ruby | catrionameriel/Caraoke_lab | /specs/room_spec.rb | UTF-8 | 2,046 | 3.25 | 3 | [] | no_license | require("minitest/autorun")
require("minitest/rg")
require_relative("../room.rb")
require_relative("../guest.rb")
require_relative("../song.rb")
class TestRoom < MiniTest::Test
def setup
@guest1 = Guest.new("Charlie", 5, "Psycho Killer")
@guest2 = Guest.new("Pete", 20, "25 or 6 to 4")
@guest3 = Guest.ne... | true |
2fddd1230b36e5b37b717bd09fdccd4e1caa04af | Ruby | dmullek/dominion | /app/cards/ruin.rb | UTF-8 | 172 | 2.546875 | 3 | [] | no_license | class Ruin < Card
def starting_count(game)
case game.player_count
when 1
10
when 2
10
when 3
20
when 4
30
end
end
end
| true |
1fb8c9a0cee0bfe9227a24c53b933257fcc626a1 | Ruby | Gustavodacrvi/data-structures-and-algorithms | /data structures/Implementation/queue/ruby.rb | UTF-8 | 290 | 3.5625 | 4 | [] | no_license | class Queue
attr_accessor :arr
def initialize
@arr = []
end
def add(element)
@arr.push(element)
end
def remove
return @arr.shift
end
def peek
return @arr[0]
end
def isEmpty
if @arr.length != 0
return false
end
return true
end
end
| true |
b8134f2cc85ad324b3fc7605ee544b3bcaab4370 | Ruby | tarellel/ldap_query | /lib/ldap_query/query.rb | UTF-8 | 2,875 | 2.671875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'net-ldap'
module LdapQuery
# Used to build LDAP filters and query the host based on the configuration passed
class Query
REQUIRED_QUERY_ATTRS = %i[attr val].freeze
FILTER_METHODS = %i[cn displayname memberof object_class mail samaccountname person].freeze
# Esta... | true |
bf8791234cd725d5ff4658de20f57a9e24e056fd | Ruby | solomonpromon/insup | /lib/insup/locale_parser.rb | UTF-8 | 442 | 2.53125 | 3 | [
"MIT"
] | permissive | class Insup
module LocaleParser
def self.locale(locale = nil)
locale = locale || ENV['LANG'] || ENV['LANGUAGE']
rex = /^(?<primary>[a-z]{2})
(?:[\-_](?<region>[A-Z]{2})
(?:\.[a-zA-Z0-9\-_]+)?)?$/x
m = locale.match(rex)
if m
if m[:region]
"#{m[:pr... | true |
363a16def672a0927f7923a0a5a0bf783893df39 | Ruby | rosesz/subdomains-finder | /app/services/google_data/fetcher.rb | UTF-8 | 1,975 | 2.890625 | 3 | [] | no_license | require "faraday"
module GoogleData
class Fetcher
MAX_ELIMINATION_TRIES = ENV["MAX_ELIMINATION_TRIES"] || 10
RESULTS_LIMIT = ENV["RESULTS_LIMIT"] || 30
NUMBER_PER_PAGE = 10
attr_accessor :domain, :subdomains, :credentials
def initialize(domain, credentials = Credentials.new)
... | true |
3f09e9e40ac1837cce9419ec00288a54ab267c19 | Ruby | kishankpatel/RoRAssignments | /May/18/Ass3.rb | UTF-8 | 117 | 4.0625 | 4 | [] | no_license | puts "Enter a string : "
str = gets.chomp
puts "Your string is : #{str}"
puts "After swapcase : #{str.swapcase}"
| true |
410c1d4f5d6c365295028ee7598944c5821d82cc | Ruby | Eloi/ruby-challenge | /lib/loco2_route_searcher.rb | UTF-8 | 1,443 | 2.609375 | 3 | [] | no_license | class Loco2RouteSearcher
require 'nokogiri'
require_relative './loco2/search'
def initialize(file_path)
@file_path = file_path
@results = nil
end
def search
results_text = File.readlines(@file_path).join
results_xml = Nokogiri::XML::Document.parse results_text
@results = parse_xml_result... | true |
d6fc45988824042bc870b757eea1fc1661d19617 | Ruby | haleylikesrocks/RB130_ruby_foundations | /Exercises/prefect_numbers.rb | UTF-8 | 433 | 3.5625 | 4 | [] | no_license | class PerfectNumber
def initialize; end
def classify(number)
raise StandardError unless number > 0
sum_of_div = find_divivors(number)
return 'deficient' if sum_of_div < number
return 'perfect' if sum_of_div == number
return 'abundant' if sum_of_div > number
end
def find_divivors(number)
... | true |
3b40b2d5c25842d00ab6e96a6be494193998be60 | Ruby | Domofera/DomoferaApp | /seed.rb | UTF-8 | 1,809 | 2.75 | 3 | [] | no_license | require 'net/http'
def sendData(day, month, year, tam, tax, tfm, tfx, ham, hax, hfm, hfx, lm, lx)
params = {
"day" => day,
"month" => month,
"year" => year,
"ha" => rand(ham..hax),
"ta" => rand(tam..tax),
"hf" => rand(hfm..hfx),
"tf" => rand(tfm..tfx),
... | true |
62d470a9879c59891e5e31a9c0539fc82a34928b | Ruby | machvee/blackjack-strategy-simulator | /split_boxes.rb | UTF-8 | 1,961 | 3.203125 | 3 | [] | no_license | module Blackjack
class SplitBoxes
#
# the hand pair is taken from the parent_bet_box
# and two new bet_boxes are created right and left.
# the parent bet_box bet is moved in to the right, and
# the left bet box gets an equal bet taken from the player
# bank
attr_reader :player
attr_re... | true |
bd04070b1b0d3ae6570b73c14376446d0c59788b | Ruby | om3rta/RubyLearningMaterial | /iterators.rb | UTF-8 | 735 | 3.953125 | 4 | [] | no_license | #.each iterator
array = [1,2,3,4,5]
array.each do |x|
x += 10
print "#{x}"
end
#.times
22.times {print "Butts"} #<-- prints the word "Butts" 22 times
#iterate over an array:
nonsense_words = ["woot", "derp", "herp", "poopdiddy", "scoopdiddy"]
nonsense_words.each {|words| puts words}
#itterating over a 2D array:... | true |
71d4ccc32cc514bccb200fb6c53479ebd23ac27e | Ruby | kevonc/ProjectEuler | /009_special_pythagorean_triplet.rb | UTF-8 | 318 | 3.34375 | 3 | [] | no_license | solution = 0
num1 = 0
num2 = 0
num3 = 0
for i in (1..999)
for j in (2..999)
k = 1000 - i - j
if i**2 + j**2 == k**2
num1 = j
num2 = i
num3 = k
solution = num1 * num2 * num3
end
end
end
puts "Num1: " + num1.to_s
puts "Num2: " + num2.to_s
puts "Num3: " + num3.to_s
puts solution | true |
ded8fb12720fac3a7fb82a1f0bb9942a28a7b7fa | Ruby | oki/adfraud42 | /app/models/event.rb | UTF-8 | 795 | 2.53125 | 3 | [] | no_license | class Event < ActiveRecord::Base
attr_accessible :ad_gen_time, :ad_ident, :event_type, :ip, :uniqueuser, :user_agent
# event type: click
scope :click, where(:event_type => :c)
# events from last 24 hours
scope :one_day, where('created_at >= ?', 24.hours.ago)
# very simple rules to detect fraud even... | true |
1e56402d56e6452d35401ad25df03fbf1fdc1a65 | Ruby | zooliet/arm_fftw | /c_test/fftw_raw.rb | UTF-8 | 1,157 | 2.890625 | 3 | [
"MIT"
] | permissive | require 'arm_fftw'
FFT_SIZE = 2048
na = NArray.float(FFT_SIZE, 1)
# na = [0.3535, 0.3535, 0.6464, 1.0607, 0.3535, -1.0607, -1.3535, -0.3535]
na = (0...FFT_SIZE).map do |n|
32768 + 50 * Math.sin(2*Math::PI*1100*(n/8000.to_f)).round(2)
end
i = 0
fc = ARM::FFTW.fft(na)/FFT_SIZE # Math.sqrt(1024).to_f
# fc.each do |f... | true |
e8f174c9eebf81cbd495e816c39ab492ac74afd0 | Ruby | eggchop/w02_d2_classes_HW | /specs/bear_spec.rb | UTF-8 | 856 | 3.03125 | 3 | [] | no_license | require("minitest/autorun")
require("minitest/rg")
require_relative("../bear")
require_relative("../river")
require_relative("../fish")
class BearTest < MiniTest::Test
def setup
@bear = Bear.new('Brown')
@river = River.new('Nile')
@fish = Fish.new('Cod')
end
def test_bear_name
assert_equal('Br... | true |
c2b875dbbbe4d1c598105ea2faafedbe19722b55 | Ruby | laqinfan/Rent-A-Car | /test/models/address_test.rb | UTF-8 | 2,465 | 2.6875 | 3 | [] | no_license | # == Schema Information
#
# Table name: addresses
#
# id :integer not null, primary key
# street1 :string
# street2 :string
# city :string
# state :string
# zipcode :string
# created_at :datetime not null
# updated_at :datetime not null
#
#kbridson
require ... | true |
53ca1bc0814856ce4b26aa00a6b31538ea8a2da4 | Ruby | y0una/phase-0-tracks | /ruby/iteration.rb | UTF-8 | 1,647 | 4.40625 | 4 | [] | no_license | # 5.4 Pairing Youna Yang and Charles Chan
numbers = [1, 2, 3, 4, 5] # key
corresponders = {1=>'a', 2=>'b', 3=>'c', 4=>'d', 5=>'e'} # value
# .each
numbers.each do |num| #Array: Keys have to be numbers start with 0
puts num
end
corresponders.each do |num, letter| #Hashes: Key can be anything, value (name = key; inc... | true |
0b1b801aa41257a7a78cd97af7e878506cb8612a | Ruby | gusmattos1/march-26-OOP-pt-2 | /assignment2/exercise2.rb | UTF-8 | 1,097 | 3.375 | 3 | [] | no_license | #### BOOKS #####
class Book
@@on_shelf = []
@@on_loan = []
def initialize (title, author, isbn)
@title = title
@author = author
@isbn = isbn
end
def self.create (title, author, isbn)
book=Book.new(title, author, isbn)
@@on_shelf << book
return book
end
def self.av... | true |
d3d4a6662da6fac727858331356bfc1e16f30980 | Ruby | titanfat/Lita_thumb_bot | /lib/lita/handlers/whats_eating.rb | UTF-8 | 825 | 2.609375 | 3 | [] | no_license | require 'nokogiri'
module Lita
module Handlers
class WhatsEating < Handler
route /^whats eating$/i,
:eating,
command: true,
help: { "what eating" => "latest post from brad's food tumblr"}
BLOG_URL = 'https://whatsbradeating.tumblr.com'.freeze
def response
@_response ||= ht... | true |
336b3ea4e2587765e3e1202389ae829ec6618f95 | Ruby | atayebali/social_stream | /spec/lib/socialkit/filter_spec.rb | UTF-8 | 1,530 | 2.921875 | 3 | [
"MIT"
] | permissive | require 'socialkit'
describe "Filter" do
let(:filter) { Socialkit::Filter.new }
context "Initialize Filter" do
it "is valid" do
expect(filter).to be_a(Socialkit::Filter)
end
it "has stopwords" do
expect(Socialkit::STOPWORDS).to_not be_empty
end
end
context "Perform filtration" do
... | true |
b085ff9ab98b340d606a02ea7bd07e019423f887 | Ruby | irongaze/iron-console | /lib/iron/console/argument_specification_list.rb | UTF-8 | 1,544 | 3.015625 | 3 | [
"MIT"
] | permissive | class Console
# Maintains an array of argument specifications, used in DSL-like builder mode to specify
# arguments for a script or argument set.
class ArgumentSpecificationList < Array
# Set up our builder-ish handlers
[:wildcard, :bool, :const, :string, :int, :float, :email, :ip_address].each do |arg_... | true |
f18f8cad06c4354e0cdb0b30ed2fc39ca762e2e4 | Ruby | anais277792/THP_exo_S3_J2 | /spec/02_caesar_cipher_spec.rb | UTF-8 | 1,153 | 3.65625 | 4 | [] | no_license | require_relative '../lib/02_caesar_cipher.rb'
describe "letter_shift method" do
it "should shift source letter into an other letter based on shift number" do
expect(letter_shift("h",2)).to eq("j")
expect(letter_shift("z",4)).to eq("d")
expect(letter_shift("w",0)).to eq("w")
expect(letter_shift("y", 2... | true |
e87a92a8936534199a618b696d4eb399084187e6 | Ruby | dougsko/projecteuler.net | /178/solution.rb | UTF-8 | 599 | 3.40625 | 3 | [] | no_license | #!/usr/bin/env ruby
#
# projecteuler.net
#
# problem 178
#
# Consider the number 45656.
# It can be seen that each pair of consecutive digits of 45656 has a
# difference of one.
# A number for which every pair of consecutive digits has a difference
# of one is called a step number.
# A pandigital number contains every ... | true |
248629f77c2f733782b8fbe817bbb65f6022c4ba | Ruby | BerilBBJ/scraperwiki-scraper-vault | /Users/B/baldmark/garden-centres-not-started-yet.rb | UTF-8 | 2,208 | 2.703125 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
BASE_URL = 'http://www.gardencentreguide.co.uk'
def extract(page,css)
element = page.at_css(css)
if element
element.inner_text
else
nil
end
end
main_page = Nokogiri::HTML(open(BASE_URL))
main_page.css('div.SEO_links li a').collect do |county|
county_name = coun... | true |
1770abe27ca134dbd5c3c733205ee6fadc670010 | Ruby | blolol/wheaties | /lib/wheaties/blolol_user.rb | UTF-8 | 2,517 | 2.71875 | 3 | [
"MIT"
] | permissive | module Wheaties
class BlololUser
attr_reader :relay_label
def initialize(cinch_user)
@cinch_user = cinch_user
end
def [](key)
if response.ok?
response['user'][key]
end
end
def aliases
self['aliases'] || []
end
def authname_or_relayed_nick
if ci... | true |
99bd25456f462986b8218996593374064245bbf8 | Ruby | ithouse/lolita-translation | /lib/lolita-translation/record.rb | UTF-8 | 5,246 | 2.546875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'i18n'
require 'lolita-translation/translated_string'
require 'lolita-translation/utils'
module Lolita
module Translation
class Record
class AbstractRecord
attr_reader :orm_record
def initialize(orm_record,configuration = nil)
@configuration = configuration
@o... | true |
d90651a0f80e5545303661333c9449bcb5919954 | Ruby | alexglach/assignment_rails_connect4 | /game_center_on_rails/app/helpers/connect_four_helper.rb | UTF-8 | 3,125 | 2.90625 | 3 | [] | no_license | module ConnectFourHelper
# def initialize_board
# Board.new(session[:board]).board
# end
def play_out_rest_of_move
if check_winner?("R")
save_winner("player")
else
execute_computer_move
if check_winner?("B")
save_winner("computer")
else
session[:full_columns] =... | true |
dc339caec5fc0cee6267ca3c1baf29143f6a59bc | Ruby | tianyuduan/JS30 | /PracticeAssessment1.rb | UTF-8 | 1,761 | 4.40625 | 4 | [] | no_license | # Define a method that returns a boolean indicating whether its second argument is a substring of its first.
def substring?(long_string, short_string)
long_string.include?(short_string)
end
p substring?('long_string', 'short_string')
# Write a method that, given a string, returns a hash in which each key is a chara... | true |
a54541fbf65ecbddf63581d491487badeb1af1bf | Ruby | uecmma/ruby-freshman-seminar-2013 | /answer_2/alstamber_ruby/upper.rb | UTF-8 | 264 | 3.84375 | 4 | [] | no_license | def yamikin(n)
amount = 100000
n.times do
amount = ((amount * 1.05 / 1000).ceil) * 1000
end
amount
end
n = gets.to_i
puts "#{n}日後の借金は#{yamikin(n)}円です" # #{hoge}と書くことによって、hogeが文字列の中に展開される
| true |
e3adee018b6b223c58b1a369e3d21a0110088a62 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/word-count/5c677d2dd6a24bcab210d91fa241cd2a.rb | UTF-8 | 281 | 3.71875 | 4 | [] | no_license | class Phrase
IGNORED_PUNCTUATION = /[^\w\s]/
def initialize(string)
@words = string.downcase.gsub(IGNORED_PUNCTUATION, "").split
end
def word_count
@words.inject(Hash.new(0)) do |counts_hash, word|
counts_hash[word] += 1
counts_hash
end
end
end
| true |
7d0c46a8a9f8e9f195d4f87462ae0c99cd37ae1b | Ruby | inkredabull/MyRubyClassAssignments | /array_max.rb | UTF-8 | 464 | 3.40625 | 3 | [] | no_license | class ArrayMax
def max_sub_sum(arg)
@max_sum = 0
@sub_sum = 0
if arg.length > 0
summate(0, arg.first)
arg[1...-1].length.times.each { |idx|
summate( arg[idx], arg[idx+1] )
}
summate(arg.last, 0)
end
@max_sum
end
p... | true |
f366cf33824cb02dba46ea5cf99ca5ed20fd3e34 | Ruby | YongLiang24/ruby-objects-has-many-lab-seattle-web-career-012819 | /lib/author.rb | UTF-8 | 365 | 3.078125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Author
attr_accessor :name, :posts
def initialize (name)
@name=name
@posts =[]
end
def add_post(post_name)
self.posts << post_name
post_name.author = self
end
def add_post_by_title(name)
new_post = Post.new(name)
@posts << new_post
new_post.author = self
end
def self... | true |
ba7d788d109a55925fd017ec8d2a07b606e3d9c6 | Ruby | barbiecode/todo-ruby-basics-001-prework-web | /lib/ruby_basics.rb | UTF-8 | 436 | 3.453125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def division(num1,num2)
division= num1/num2
end
def assign_variable(value)
assign_variable = value
end
def argue(phrase="I'm right and you are wrong!")
argue = "#{phrase}"
end
def greeting(greeting, name)
"#{greeting}, #{name}!"
end
def return_a_value
return_a_value = "Nice"
end
def last_evaluated... | true |
e5162ce10f19cf78843fd0aec660b922f495f5c3 | Ruby | robinrob/quiz | /test_selector.rb | UTF-8 | 592 | 2.609375 | 3 | [] | no_license | require "test/unit"
load "record_builder.rb"
load "selector.rb"
class TestSelector < Test::Unit::TestCase
def test_should_select_1_item()
builder = RecordBuilder.new()
items = [builder.with_question("question").with_answers(["answer"]).build()]
item = Selector.new(items).select()
assert_not_nil(... | true |
257307c6485cc453269180af26f398c9f673a1ea | Ruby | elenagarrone/2faast_tube | /spec/station_spec.rb | UTF-8 | 1,722 | 3.09375 | 3 | [] | no_license | require 'station'
require 'passenger_container'
require 'passenger'
describe Station do
let(:station) { Station.new }
let(:station2) { Station.new }
let(:train) { Train.new }
let(:passenger) { Passenger.new }
let(:carriage) { Carriage.new }
it "should not be able to dock a train if it doesn't ha... | true |
0c226edcece2f5454926247e4eb36ae30bb3fa8d | Ruby | p-reznick/algorithm_exercises | /reverse.rb | UTF-8 | 506 | 4 | 4 | [] | no_license | # 344
# @param {String} s
# @return {String}
# Stack implementation -- Space: O(N) Time: O(N)
def reverse_string(s)
reverse = ''
stack = []
s.each_char { |char| stack.push char }
stack.each { |char| reverse.prepend char }
reverse
end
# In place two pointer implementation -- Space: O(1), Time: O(N... | true |
af420c99a78b6b98340e25688a1c83db9029dca4 | Ruby | shankar524/cf_assignment_2 | /spec/array_sort_spec.rb | UTF-8 | 356 | 2.78125 | 3 | [] | no_license | require 'array_sort'
describe ArraySort do
describe '.sort' do
subject {ArraySort.new.sort(input)}
let(:input) {[21,3,43,5454,23,1233]}
let(:sorted_array) {[3, 21, 23, 43, 1233, 5454]}
it 'should return sorted number array when unsorted number array is provided' do
expect(subject).to match_a... | true |
fa3e2fc788ff9a84f45e8fae9afd64c0d12b3278 | Ruby | savelbl4/ruby_lessons | /MyApp1/app1.rb | UTF-8 | 394 | 3.421875 | 3 | [] | no_license | salary = 3000 #переменная
tax = 0.40
final = salary - salary * tax
puts "Salary"
puts salary
puts "Tax"
puts tax
puts "Final for 1 month"
puts final
puts "Annual salary"
puts salary * 12
print "enter your name: "
myname = gets
puts "your name is #{myname}" #вставил значение переменной в строку
print "y... | true |
05c0188e72835ca27eb2ea1cdcffdcda29e9dd06 | Ruby | arthurSena/LearningRuby | /ProjectEuler/problem3.rb | UTF-8 | 203 | 3.21875 | 3 | [] | no_license | def largestPrimeFactor()
n = 600851475143
temp = 2
l = 0
while temp<=n do
if n % temp ==0
n = n / temp
if temp > l
l = temp
end
end
temp += 1
end
puts l
end
largestPrimeFactor() | true |
8c54ee570951d83f70974fe3418803cce981f676 | Ruby | marinacor1/BlackThursday | /test/item_repository_test.rb | UTF-8 | 2,739 | 2.78125 | 3 | [] | no_license | require_relative 'test_helper'
require 'minitest/autorun'
require 'minitest/pride'
require_relative '../lib/sales_engine'
require_relative '../lib/item_repository'
class ItemRepositoryTest < Minitest::Test
def test_item_repo_class_instantiates_an_item_repo
data = [{:name => "Pencil", :description => "You can us... | true |
abdf10d9212f9245f8b119b20b027549607d2389 | Ruby | richwynmorris/ruby_small_problems | /challenges/6kyu_title_case.rb | UTF-8 | 2,763 | 4.65625 | 5 | [] | no_license | # A string is considered to be in title case if each word in the string is either (a) capitalised (that is, only the first letter of the word is in upper case) or (b) considered to be an exception and put entirely into lower case unless it is the first word, which is always capitalised.
# Write a function that will co... | true |
00c9185e37ea808524460f55fed220e5d697561e | Ruby | Michael3434/fullstack-challenges | /01-Ruby/06-Parsing/02-Numbers-and-Letters/lib/longest_word.rb | UTF-8 | 1,618 | 3.421875 | 3 | [] | no_license | require 'open-uri'
require 'json'
def generate_grid(grid_size)
array = []
while array.length < grid_size do
random_letter = ('A'..'Z').to_a.sample
array << random_letter
end
array
end
def run_game(attempt, grid, start_time, end_time)
final_time = ( end_time.to_i - start_time.to_i )
score = atte... | true |
ddd3824687f9732997d4fb267951407206099e98 | Ruby | siwka/association_mtm | /app/helpers/students_helper.rb | UTF-8 | 1,073 | 3.109375 | 3 | [] | no_license | module StudentsHelper
def json_data
load_student_lib "#{Rails.root}/tmp/student_data.json"
end
def load_student_lib( filename )
JSON.parse( IO.read(filename) )
end
def sort_by_grade students
students = students_grade_order students
students_return_grades students.sort! { |a,b| (a["grade"] =... | true |
212527f3aeefa4af15c3540c4e2c87072ecca1e4 | Ruby | bruoliveir/forum-template | /app/models/discussion.rb | UTF-8 | 1,358 | 2.546875 | 3 | [] | no_license | class Discussion < ApplicationRecord
include ProfanityFilter
belongs_to :user, optional: true
validates :user_id, presence: true
validates :title, presence: true
validates :body, presence: true
PATH_DELIMITER = '.'
after_find do
self.title = clean(self.title)
self.body = clean(self.body)
end... | true |
688c31d23defc57316e03e75474d61e8727a9395 | Ruby | cored/levelup | /leetcode/ruby/find_min_value_hashes/find_min_value_hashes_spec.rb | UTF-8 | 515 | 3.046875 | 3 | [] | no_license | module FindMinValueHashes
extend self
def call(hashes, key)
hashes.each_with_object([]) do |hash, temp|
temp << [[key, hash[key]]]
end.min_by do |temp_hash|
temp_hash.last
end.to_h
end
end
describe FindMinValueHashes do
it "returns the minimum value from a list of hashes" do
expect... | true |
c62c076cf1f37264e07a745895a726132f5b2968 | Ruby | katebutler/ruby-array-flattener | /flattener_spec.rb | UTF-8 | 1,047 | 3.375 | 3 | [] | no_license | require_relative 'flattener'
describe Flattener do
it 'returns nil if input is an integer' do
input = 1234
expect(Flattener.flatten(input)).to eq(nil)
end
it 'returns nil if input is an object' do
input = {name: 'Kate'}
expect(Flattener.flatten(input)).to eq(nil)
end
it 'returns input array... | true |
6607f0398aee22f04b48b01a502d54be4038c861 | Ruby | danielkwon7/Algorithms | /skeleton/solutions/transpose_solution.rb | UTF-8 | 215 | 3.296875 | 3 | [] | no_license | def transpose(array)
x = array.length
standard = Array.new(x) {Array.new(x)}
array.length.times do |row|
array.length.times do |col|
standard[row][col] = array[col][row]
end
end
standard
end
| true |
1254ba14129a3c68906f95b006554d083e826795 | Ruby | david50407/UnknowBBS | /visual/line.rb | UTF-8 | 831 | 2.890625 | 3 | [] | no_license | # vim: set shiftwidth=2 tabstop=2 noexpandtab noautoindent
module Visual
class Line
attr_reader :cols
attr_reader :colMax
@cols = []
@colMax = 0
@dirty = false
@parent = nil
def initialize(parent = nil, cols = 79)
@colMax = cols
end
def [](k)
return nil if k >= @colMax
return nil if @co... | true |
e55a9917c885f07f7e69d40ea93d1e023a4da5ac | Ruby | moqingxinai/pujara-emnlp17 | /scripts/embeddings/computeEmbeddings.rb | UTF-8 | 5,616 | 2.5625 | 3 | [] | no_license | require_relative '../lib/constants'
require_relative '../lib/distance'
require_relative '../lib/embedding/constants'
require 'fileutils'
require 'open3'
SEED = 4
COMMAND_TYPE_TRAIN = 'train'
COMMAND_TYPE_EVAL = 'eval'
DEFAULT_EMETHOD = 'TransE'
DEFAULT_DATA_DIR = Constants::RAW_FB15K_PATH
DEFAULT_SIZE = 100
DEFAULT... | true |
9fda3d50b968999a7ab4138eada2915ced4fb1c9 | Ruby | KateMchughWestfall94/regex-lab-v-000 | /lib/regex_lab.rb | UTF-8 | 517 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def starts_with_a_vowel?(word)
if word.match(/\b[aeiouAEIOU]/)
true
else
false
end
end
def words_starting_with_un_and_ending_with_ing(text)
text.scan(/\b[un]+\w+[ing]/)
end
def words_five_letters_long(text)
text.scan(/\b\w{5}\b/)
end
def first_word_capitalized_and_ends_with_punctuation?(... | true |
b3dff95f47d765df456d7de754cda679f5a02e02 | Ruby | mdayaram/pingpong | /app/models/match.rb | UTF-8 | 2,333 | 2.796875 | 3 | [] | no_license | class Match < ActiveRecord::Base
attr_accessible :winner_next, :loser_next
attr_accessible :team1, :team2, :winner
attr_accessible :round, :schedule, :bracket
belongs_to :left_team, :class_name => "Team", :foreign_key => "team1"
belongs_to :right_team, :class_name => "Team", :foreign_key => "team2"
belongs... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.