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
2b235608548686c26db66ce25ba5a0909e0584af
Ruby
bromine0x23/Shining-Co-Wechat
/app/services/fortune_service.rb
UTF-8
860
2.625
3
[ "WTFPL" ]
permissive
# -*- coding: utf-8 -*- # frozen_string_literal: true class FortuneService FORTUNE_JUDGE = %w(大凶 凶 凶 凶 末吉 末吉 末吉 末吉 末吉 末吉 半吉 半吉 吉 吉 小吉 小吉 中吉 中吉 大吉 大吉 秀吉 溢出) def fortune(sender, time) level = random_service.pseudo_random(random_service.date_seed(time, 11111, 111, 1) ^ sender.sum, 11) % 102 - 1 format( I18n.t(...
true
2834008c7637a46168d2bcfbbab568edcdad6e57
Ruby
chenschel/bookshelf
/app/models/author.rb
UTF-8
291
2.578125
3
[]
no_license
class Author < ApplicationRecord validates :first_name, :last_name, presence: true def full_name [first_name, last_name].compact.join(' ') end def coordinates [rand(50), rand(90)] end def publication_years (1..rand(10)).to_a.map { rand(1900..2000) }.sort end end
true
1dff56716e0ff9871d06f9bb6a166d82e4fb04da
Ruby
evgeniy-kunitsa/fourier_transform
/app/util/wavelet/calculator.rb
UTF-8
934
3.375
3
[]
no_license
module Wavelet class Calculator attr_reader :direct_results, :reverse_results, :intermed_results def initialize(points) @intermed_results = [] @direct_results = direct(points) @reverse_results = reverse(@direct_results) end def direct(points) n = points.size if n == 1 ...
true
6892c93860361c63d738b213508f97b996fd0f46
Ruby
wimurphy/Haversine
/spec/haversine_spec.rb
UTF-8
1,043
2.796875
3
[]
no_license
require 'spec_helper' require_relative '../haversine' describe 'haversine' do it 'verifies all coordinates are valid' do expect(Haversine.valid_coords(90, 180)).to be true expect(Haversine.valid_coords(9, 18)).to be true expect(Haversine.valid_coords(-90, 180)).to be true expect(Haversine.valid_coord...
true
30b3a066b09f2c19b2ebe8657f0fb14fb94abc38
Ruby
teoucsb82/pokemongodb
/lib/pokemongodb/pokemon/parasect.rb
UTF-8
1,262
2.75
3
[]
no_license
class Pokemongodb class Pokemon class Parasect < Pokemon def self.id 47 end def self.base_attack 162 end def self.base_defense 170 end def self.base_stamina 120 end def self.buddy_candy_distance 2 end de...
true
5c01d2c1c9b031ede45c8f92ba6a01565ae6e1bb
Ruby
OscarVegaV/Ruby_practices
/4_solo_impares.rb
UTF-8
268
3.6875
4
[]
no_license
=begin Crea un programa llamado solo_impares.rb que dado n muestre en pantalla los primeros n números impares. Tip: el número siguiente a un par siempre es un impar :) Uso: ruby solo_impares.rb 5 1 3 5 7 9 =end n = ARGV[0].to_i (2*n).times {|i|puts i if i.odd? }
true
d2a3593ce6a91f089cf3b2f97b432a122a24731b
Ruby
PlasticLizard/wonkavision
/lib/wonkavision/plugins/analytics/query.rb
UTF-8
2,483
2.703125
3
[ "MIT" ]
permissive
module Wonkavision module Analytics class Query attr_reader :axes, :filters def initialize() @axes = [] @slicer = Set.new @filters = [] @measures = [] end def select(*dimensions) options = dimensions.extract_options! axis = options[:axis] |...
true
17d8be1fb2f24b646b987a48b34519326fa4bd2d
Ruby
pathbox/A-bit-of-ruby-code
/get_the_Mutex.rb
UTF-8
2,323
3.328125
3
[]
no_license
require 'thread' array = [] mutex = Mutex.new 5.times.map do Thread.new do mutex.synchronize do 1000.times do array << nil end end end end.each(&:join) puts array.size # 5000 # 无论何时你有多个线程共享一个对象引用时,并对其做了修改,你就要有麻烦了,除非有锁来阻止修改中的上下文切换。 # 使用了一个共享的互斥或者说锁。一旦一个线程进入mutex.synchronize内的代码块时,所有其他线...
true
c7f14776b8ac683b56c7c5865732018a3e79a76e
Ruby
addagger/html_slicer
/lib/html_slicer/cached_stuff.rb
UTF-8
1,989
2.96875
3
[ "MIT" ]
permissive
require 'digest/sha1' module HtmlSlicer # Object to be serialized and dumped as cache storage. # Include +resizing+ and +slicing+ objects, and original text's hexdigest hash value to provide authenticity. # During the runtime object is used as an +maps+ accessor too. class CachedStuff attr_reader :versi...
true
8aa1e3572fe7079c06afe06ba1a1d2eb0ad793eb
Ruby
LeeXGreen/sep2013
/chapters/02-ruby-the-basics/02-classes.rb
UTF-8
297
3.921875
4
[]
no_license
#!/usr/bin/env ruby class Car def initialize(speed) @speed = speed end def drive puts "#{self.class} is driving at #{@speed}..." end end class Ford < Car; end class Pontiac < Car; end c = Car.new 10 c.drive f = Ford.new 20 f.drive p = Pontiac.new 30 p.drive
true
45f0992d9d76711fa7f861fcf2155b0621e2f80a
Ruby
abrophy/exercisms
/ruby/roman-numerals/roman_numerals.rb
UTF-8
1,318
3.453125
3
[]
no_license
module BookKeeping VERSION = 2 end class Fixnum def to_roman numerals = [ [1000, "M"], [500, "D"], [100, "C"], [50, "L"], [10, "X"], [5, "V"], [1, "I"], ] running_value = self result_string = "" numerals.each_with_index do |item, index| if running_value >= item...
true
b5901f5819e001518060849b937d4d6f942bac13
Ruby
matthew-deluge/knights_travails
/node.rb
UTF-8
191
2.625
3
[]
no_license
# creates the node which is used to store positions and potential moves class Node attr_accessor :data, :neighbors def initialize(value) @data = value @neighbors = [] end end
true
017903c41a65a9b849aad0e1a5bf763525765a54
Ruby
Beckyrose200/oystercard
/spec/oystercard_spec.rb
UTF-8
1,991
3.140625
3
[]
no_license
require 'oystercard' require 'journey' describe Oystercard do let(:station){ double :station } let(:exit_station){ double :exit_station } let(:journey1){ {station => exit_station} } it 'has a balance' do expect(subject.balance).to eq(0) end describe '#top_up' do it { is_expected.to respond_to(:to...
true
ff883917f87c2fee0999d7e5e580869105ab3f77
Ruby
obiora22/launch_school
/exercises/letter_case_counter.rb
UTF-8
628
3.875
4
[]
no_license
def letter_counter(string) hash = Hash.new(0) string.each_char do |chr| if chr == chr.upcase && chr =~ /\w/ hash[:upper_case] += 1 elsif chr == chr.downcase && chr =~ /\w/ hash[:lower_case] += 1 else hash[:neither] += 1 end end hash end p letter_counter('Hello Amigos!') def le...
true
0700dbb511933878b8ce1e2d146b1898e4c86695
Ruby
v-tsvid/task_oop
/author.rb
UTF-8
309
3.125
3
[]
no_license
class Author attr_accessor :name, :biography def initialize (*params) @name = params[0] @biography = params[1] end # def inspect(sep) # str = String.new # if @name # str << @name # end # if @biography # str << sep # str << @biography # end # end end
true
2ddb4fe83c138831bdc5e85e0e7d69c21f3ec4c1
Ruby
josh-kramer-dev/triangle-classification-v-000
/lib/triangle.rb
UTF-8
716
3.484375
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
class Triangle # write code here attr_accessor :side_a, :side_b, :side_c def initialize(a, b, c) @side_a = a @side_b = b @side_c = c end def kind if @side_a > 0 && @side_b > 0 && @side_c > 0 if @side_a + @side_b <= @side_c || @side_a + @side_c <= @side_b || @side_b + @side_c <= @side_a...
true
919cd7c5d8a092676fea53c74d2a02757e213e4a
Ruby
l1ngoman/Rails-Pass-Checker
/app/controllers/password_controller.rb
UTF-8
1,097
2.765625
3
[]
no_license
class PasswordController < ApplicationController def check @user = params[:userid] @pass = params[:password] session[:permitted] = false if @pass == nil || @user == nil flash[:alert] = "" elsif !good_length?(@user) #should be true flash[:alert] = "Your username must be at least 6 chara...
true
68bcaa4b2308f43c5d0f39297e0cc2b5aa73e541
Ruby
deeptailor/homework
/w1d5/map.rb
UTF-8
747
3.65625
4
[]
no_license
class Map def initialize @var = [] end def assign(key, value) sub_array = [key, value] if includes?(key) @var.each do |s| s[1] = value if s[0] == key end else @var << sub_array end end def includes?(key) k = @var.map{|e| e[0]} k.include?(...
true
e12ef86d01c701166ef08011d5b48cd24da9ad10
Ruby
hianson/phase-0-tracks
/ruby/hamsters.rb
UTF-8
778
3.734375
4
[]
no_license
puts "Hamster Adoption Form" puts "What is your hamster's name?" hamster_name = gets.chomp.to_s puts "What is the volume level of your hamster? (1-10)" hamster_volume = gets.chomp.to_i puts "What fur color does your hamster have?" hamster_color = gets.chomp.to_s puts "Would you recommend this hamster for adoption? (Y/N...
true
3b9af5d71fa29ef9584f45245ffa3d671e24c81f
Ruby
Gaurav2728/font_awesome5_rails
/lib/font_awesome5_rails/parsers/parse_methods.rb
UTF-8
681
3.015625
3
[ "MIT" ]
permissive
module ParseMethods def icon_type(type) return "fas" if type.nil? case type.to_s when "far", "regular" "far" when "fal", "light" "fal" when "fab", "brand" "fab" when "fad", "duotone" "fad" else "fas" end end def prepend_fa(s...
true
979567016724b726caf03ffb6c31c75bad689ba2
Ruby
GitHubAdmin/MDS3Builder
/app/models/fields/a1500.rb
UTF-8
973
2.65625
3
[]
no_license
class A1500 attr_reader :title, :options, :name, :field_type, :node def initialize @title = "Preadmission Screening & Resident Review (PASRR)" @name = "Is the resident currently considered by the state level II PASRR process to have serious mental illness and/or intellectual disability or a related condi...
true
a433b9b77abbda891e25cd7354215facd0c8779e
Ruby
Uch-iha/Actualize
/Prework/Phase-1/Exercise22.rb
UTF-8
178
3.359375
3
[]
no_license
# Exercise: DON'T RUN THE CODE! Instead, predict what will happen when you run it. blood = 1 10.times do if blood == 1 blood = 2 else blood = 1 end p blood end
true
c23a47a39c5b85b58c5c28023a1e442149cf9db7
Ruby
dbesserman/LS_exercises
/small_problems/advanced_1/9.rb
UTF-8
1,035
4
4
[]
no_license
def bubble_sort!(array) loop do swapped = false 0.upto(array.size - 2) do |pointer| if array[pointer] > array[pointer + 1] array[pointer], array[pointer + 1] = array[pointer + 1], array[pointer] swapped = true end end break unless swapped end end def merge(array_1, ar...
true
7b4f620ccfd25a1fb3e50ec86dd50f428a538857
Ruby
MichaelTheTall/W2D3LAB
/specs/food_spec.rb
UTF-8
515
2.71875
3
[]
no_license
require("minitest/autorun") require("minitest/rg") require_relative("../pub.rb") require_relative("../drink.rb") require_relative("../customer.rb") require_relative("../food.rb") class FoodTest < MiniTest::Test def setup @chips = Food.new("Chips", 4, 1) @pie = Food.new("Pie", 5, 2) end def test_food_ha...
true
94cd38f499bfab4ae19047261317df9443ebaf67
Ruby
glv/morning-pages
/lib/morning-pages/text_reporter.rb
UTF-8
627
3.171875
3
[]
no_license
module MorningPages class TextReporter < Struct.new(:stats) def report [ target(stats), "You have written #{stats.count} words today.", average_word_length(stats) ].join("\n") end def average_word_length(stats) stats.count > 0 ? "Average word length: %.2f...
true
6bda7a61459d35fb3c3137d3cd1737b80c92e563
Ruby
ismayton/ttt-with-ai-project-online-web-sp-000
/lib/players/computer.rb
UTF-8
1,779
3.359375
3
[]
no_license
require 'pry' module Players class Computer < Player WIN_COMBINATIONS = [ [0,1,2], [0,3,6], [0,4,8], [1,4,7], [2,5,8], [2,4,6], [3,4,5], [6,7,8] ] CAN_WIN = [ ['X', 'X', ' '], ['O', 'O', ' '], ['X', ' ', 'X'], ['O', ' ', 'O'], [' ', 'X', 'X'], ...
true
783df1e99e3c536506a2d1ae5cbc35c001476dd2
Ruby
akbarratt/ruby_book
/Exercises/10.rb
UTF-8
130
3.390625
3
[]
no_license
# Hash values can be arrays. h = { array: [1, 2, 3, 4]} puts h # Array values can be hashes. arr = [1, 2, 3, {num: 4}] puts arr
true
7f5186d93f2e9337afdabce8918e7d0ecd037fd9
Ruby
adamin/jobs
/tests/tc_jobs_collection.rb
UTF-8
3,280
2.953125
3
[]
no_license
require 'test/unit' require_relative '../jobs_collection.rb' class TestJobsCollection < Test::Unit::TestCase # Tests empty jobs collection def test_empty collection = JobsCollection.new '' sequence = collection.get_sequence() assert_equal [], sequence end # Tests handling of self dependent jobs ...
true
b6d38810457ed2bf2983b644a9f1aff71a633c9e
Ruby
midwire/jsonapi_rspec
/lib/jsonapi_rspec/be_json_api_response_for.rb
UTF-8
5,646
2.84375
3
[ "MIT" ]
permissive
require 'rspec/matchers' require 'active_support/all' require_relative 'string' # Class BeJsonApiResponseFor provides custom RSpec matching for json:api # responses for a given object instance. It checks attributes and elements # iteratively and fails on the first mismatch that it finds. # # It expects a Rack::Respon...
true
67eed4eab67353f879dde5f79ee9113c6a84dde2
Ruby
sarisgar28/my-each-onl01-seng-ft-012120
/my_each.rb
UTF-8
87
2.875
3
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference" ]
permissive
collection =["1,2,3,4"] def my_each (collection) do |i| puts number {"i.1""i.2"} end
true
c629e476321ea0c09f2516e9d6dc48e7dbe6a834
Ruby
pmanko/slice
/app/models/validation/validators/time_duration.rb
UTF-8
2,155
2.71875
3
[ "MIT" ]
permissive
# frozen_string_literal: true module Validation module Validators class TimeDuration < Validation::Validators::Default def messages { blank: "", invalid: I18n.t("validators.time_duration_invalid"), out_of_range: I18n.t("validators.time_duration_out_of_range"), ...
true
c69e4a09d5edb2c1d5dbce0e452708f12e2637ba
Ruby
dtinianow/rush_hour
/test/models/payload_request_test.rb
UTF-8
4,361
2.515625
3
[]
no_license
require_relative '../test_helper.rb' class PayloadRequestTest < Minitest::Test include TestHelpers, DataProcessor def test_it_parses_the_payload payload_request = JSON.parse('{ "url": "http://jumpstartlab.com/blog", "requestedAt": "2013-02-16 21:38:28 -0700", "respond...
true
da26a4a43135b11a4f0d10ef65bfb87d6ccd3514
Ruby
blerou/Geoma
/lib/point.rb
UTF-8
275
3.078125
3
[ "MIT" ]
permissive
# To change this template, choose Tools | Templates # and open the template in the editor. require 'shape' class Point < Shape def initialize(x, y) @x = x @y = y end def move_to(x, y) @x = x @y = y notify_watchers(:watch_point, @x, @y) end end
true
a0962ba8d6f73bc5507ed7933b1979b63723784c
Ruby
dc79627n/oo-kickstarter-v-000
/lib/backer.rb
UTF-8
403
3.21875
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
#create class Backer class Backer #initialize with name, create attr_accessor name attr_accessor :name, :backed_projects, :backers #when initialize with name, also initialize new empty array def initialize(name) @name = name @backed_projects = [] end #each instance goes into new array def back_proje...
true
6518b9b1d8e0605904fd0b19b98b072a2b6226d0
Ruby
henriquegavabarreto/sokoban
/lib/game_objects/goal.rb
UTF-8
266
2.796875
3
[]
no_license
require 'ruby2d' require_relative './helpers/positioning' class Goal include Positioning attr_reader :sprite def initialize(x, y, size) @size = size @sprite = Square.new(x: x, y: y, z: 1, size: size, color: '#ffbdea') end end
true
7fdc0f054b0c621bc9171d9f377f9db6f1575509
Ruby
rafbgarcia/pseudo-compilador
/translator.rb
UTF-8
2,454
3.25
3
[]
no_license
class Translator def self.translate(operations) map = self.translations assembly = [] assembly << ".text" label_counter = 1 block = false operations.each_with_index do |o, i| if o # IF if o[:code] == :if # Comentário para saber qual a expressão assembly << "\t # #{o[:exp]}" # Ins...
true
25259b5976ca99ecfedef4d4fb6cde78618f3068
Ruby
josue804/library
/lib/patron.rb
UTF-8
2,361
2.921875
3
[ "MIT" ]
permissive
class Patron attr_reader(:name, :total_fine, :id) define_method(:initialize) do |attributes| @name = attributes[:name] @total_fine = attributes[:total_fine] @id = attributes[:id] end define_singleton_method(:all) do returned_patrons = DB.exec("SELECT * FROM patrons;") patrons...
true
21208bd7ba7ab954eef2f283b9351feee221b6f0
Ruby
kazjote/talks
/lib/talks.rb
UTF-8
1,255
2.734375
3
[ "MIT" ]
permissive
require File.expand_path('../talks/configuration.rb', __FILE__) require File.expand_path('../talks/hooks.rb', __FILE__) module Talks class << self VOICES = %w( agnes albert alex bad bahh bells boing bruce bubbles cellos deranged fred good hysterical junior kathy pipe princess ralph trinoids vi...
true
44498291cd9b646a9e21962cc29266bfbfbdc134
Ruby
yicheny001/method-scope-lab-web-0616
/lib/catch_phrase.rb
UTF-8
68
2.609375
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def catch_phrase(phrase) puts phrase end catch_phrase("saywhat")
true
33f87dfe9e525058908507a67b8d3c178857e0d3
Ruby
ajmarkow/sphinxriddles
/spec/riddles_spec.rb
UTF-8
1,203
3.171875
3
[]
no_license
require("rspec") require("riddles") describe ("get_riddle") do it("retrieves a riddle") do testriddle = Riddles.new() expect(testriddle.get_riddle(0, "riddle")).to(eq("What goes up but never comes down?")) expect(testriddle.get_riddle(1, "riddle")).to(eq("I shave every day, but my beard stays the same. W...
true
110ef7fa971219863e0ed30b3b8249c3a0f4cc36
Ruby
jlrodney/bookmarkmanager3
/spec/bookmark_spec.rb
UTF-8
1,581
2.703125
3
[]
no_license
require './lib/bookmark' describe Bookmark do describe ".all" do it "should returns a list of bookmarks" do connection = PG.connect(dbname: 'bookmark_manager_test') Bookmark.create(url: "http://www.makersacademy.com", title: "Makers Academy") Bookmark.create(url: "http://www.destroyallsoftware....
true
74546109c9143a818582ef399acc0c253b191c87
Ruby
micahredding/brick
/db/seeds/christiantranshumanist/11.rb
UTF-8
2,980
2.734375
3
[]
no_license
@ct11 = Episode.create( "title" => "Ep 11: Conversations: Singularity & Superheroes", "number" => 11, "recorded_at" => "2015-10-07 19:16:47", "published_at" => "2015-12-14 18:00:00", "media" => "http://cdn.brickcaster.com/christiantranshumanist/011_singularity_and_superheroes.mp3", "media_length" => 6470, "media_size" ...
true
51bae88c18107a963a915da6745bd55038ad97ca
Ruby
shugo/blog
/features/step_definitions/blog_steps.rb
UTF-8
832
2.796875
3
[]
no_license
PAGES = { "記事一覧" => "/articles/", "新規記事" => "/articles/new" } 前提(/^"(.*?)"というタイトルの記事が存在している$/) do |title| Article.create!(title: title, body: "") end 前提(/^"(.*?)"ページを表示している$/) do |name| visit PAGES[name] end もし(/^"(.*?)"に"(.*?)"と入力する$/) do |name, value| fill_in name, with: value end もし(/^"(.*?)"ボタンをクリックする...
true
5bdd848584445e903bea36e5a3008f33a2b6a04f
Ruby
meaghanjones/dealerships
/spec/vehicle_spec.rb
UTF-8
1,632
3
3
[ "MIT" ]
permissive
require('rspec') require('vehicle') describe(Vehicle) do before() do Vehicle.clear() end describe('#make') do it("returns the name of the vehicle") do test_vehicle = Vehicle.new({:make => "Mazda", :model => "Protege", :year => 2001}) expect(test_vehicle.make()).to(eq("Mazda")) end end ...
true
0c2be2a2cc37750003a282a308f991f53f0f457a
Ruby
adigitalnative/badges-and-schedules-dc-web-091718
/conference_badges.rb
UTF-8
584
3.84375
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
# Write your code here. def badge_maker(name) return "Hello, my name is #{name}." end def batch_badge_creator(names) names.map {|name| badge_maker(name)} end def assign_rooms(speakers) speakers.each_with_index.map do |speaker, index| room_assignment_maker(speaker, index+1) end end def printer(attendees)...
true
ce822e95f50061e85a74a198eb9f43792d26a8d3
Ruby
msucorey/aawork
/W2D4/two_sum.rb
UTF-8
1,283
3.96875
4
[]
no_license
arr = [0, 1, 5, 7] # O(n^2) def bad_two_sum?(arr, target_sum) (0...arr.length - 1).each do |i| (i + 1...arr.length).each do |j| return true if arr[i] + arr[j] == target_sum end end false end # O(nlogn) (quicksort is technically O(n^2)) def okay_two_sum?(arr, target_sum) sorted = arr.sort low...
true
23459341ce2fe5b5cb2c98577ed430b6ae28714e
Ruby
AL-Object-Programming/PPO1-Ruby
/lab05/lab05 - start/novel.rb
UTF-8
126
2.796875
3
[]
no_license
require './book.rb' class Novel < Book def initialize(title) super(title) end def get_type 'Novel' end end
true
c6f9a577ae770bc20ee1c53e0380cbe5984b1433
Ruby
Nadav35/W3D5-Project
/skeleton/lib/00_attr_accessor_object.rb
UTF-8
309
2.703125
3
[]
no_license
class AttrAccessorObject def self.my_attr_accessor(*names) names.each do |name| doc = <<-SQL def #{name} @#{name} end def #{name}=(value) @#{name} = value end SQL class_eval doc end # ... end end
true
6276e750f88d433a7ee25e75bb698d24564d0b4b
Ruby
potsbo/accidental-palindrome
/spec/models/palindrome_finder_spec.rb
UTF-8
3,955
3.03125
3
[]
no_license
require 'rails_helper' describe PalindromeFinder do let(:text) { '竹やぶ焼けた' } let(:cand) { PalindromeFinder.new(text: text) } cases = [ { input: '竹やぶ焼けた', output: '竹やぶ焼けた' }, { input: 'どうやら、竹やぶ焼けた', output: '竹やぶ焼けた' }, { input: '竹やぶ、焼けた', output: '竹やぶ、焼けた' }, { input: 'どうやら、竹やぶ焼けたようだ', output: '竹...
true
cb28c34d0f6c7d9a8edbf718bae8f87f2d81e056
Ruby
wenlilearn/leetcode
/min_depth_of_binary_tree/main.rb
UTF-8
1,168
3.984375
4
[]
no_license
=begin Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node. =end module Main # Definition for a binary tree node. class TreeNode attr_accessor :val, :left, :right def initialize(val, left = nil...
true
c6e048896227a8b035afb8364eb1ca93d2f14a92
Ruby
jordanwa1947/complete_me
/test/complete_me_test.rb
UTF-8
10,606
2.96875
3
[]
no_license
require './test/helper_test' require './lib/complete_me' require './lib/node' class CompleteMeTest < Minitest::Test def test_that_the_complete_me_class_exists completion = CompleteMe.new assert_instance_of CompleteMe, completion end def test_it_can_count completion = CompleteMe.new completion....
true
b51f829451b229c3fe2f9e4135cc16595fbd9a22
Ruby
sahilbathlaofficial/vinsolCodes
/Advanced Ruby/Exercise6-Exclude-String/bin/main.rb
UTF-8
199
3.171875
3
[]
no_license
#! /usr/bin/ruby require_relative "../lib/derived_string.rb" puts "Enter a string to test DeriveString class" object_derived_string = DerivedString.new(gets.chomp) object_derived_string.test_a_method
true
84c0fec0b909eea45438187e45631729eaef34f9
Ruby
nakamura999/ruby-book
/ruby-lesson/lesson7.rb
UTF-8
180
3.390625
3
[]
no_license
number = 48 if number % 3 == 0 && number % 5 == 0 # 15で割り切れる puts "15の倍数" elsif number % 5 == 0 puts "5の倍数" elsif number % 3 == 0 puts "3の倍数" end
true
fd1d7507c5c9f170fa622174551c0116ffa0f63a
Ruby
Vaultman/migrant
/lib/migrant/model_extensions.rb
UTF-8
3,104
2.53125
3
[ "MIT" ]
permissive
module Migrant module ModelExtensions attr_accessor :schema def belongs_to(*args) super create_migrant_schema @schema.add_association(self.reflect_on_association(args.first)) end def create_migrant_schema if self.superclass == ActiveRecord::Base @schema ||=...
true
ebf983546fad74c93fb105010a43bf56f3ef599b
Ruby
mrigdon44/studio_game
/SG_playerstats.rb
UTF-8
855
3.265625
3
[]
no_license
require_relative 'SG_player' require_relative 'SG_game' module PlayerStats def self.print_stats(player) strong, wimpy = players.partition {|player| player.strong?} puts "#{@title.capitalize} statistics:" puts "\n#{strong.size} strong players:" strong.each do |player| puts "#{player.name} #{p...
true
07a160381374dde1a52f56998ab1bbbfc1736ab3
Ruby
NekoQ/social
/app/models/person.rb
UTF-8
482
2.578125
3
[]
no_license
class Person < ApplicationRecord has_many :posts def self.filtered_by_lists(tags) people = [] Person.all.each do |person| present = true tags.each do |tag| unless person.lists.include? tag present = false end ...
true
47a5ed80c8038e754c173cb9be4e7372e451333d
Ruby
d-atkins/Battleship
/lib/game.rb
UTF-8
7,502
3.4375
3
[]
no_license
require './lib/computer_player' require './lib/human_player' require './lib/smart_computer' require './lib/ship' require_relative 'color_palette' class Game attr_reader :smart_mode def initialize @computer = ComputerPlayer.new("CPU") @human = HumanPlayer.new("PLAYER") @smart_computer = SmartComputer.n...
true
09792defb2c6292063e806376b497f34eedca434
Ruby
rubenportz/learn-to-code-ruby
/lists/grid.rb
UTF-8
205
2.859375
3
[ "MIT" ]
permissive
grid = [ ["X", "O", "O"], ["X", "X", "_"], ["O", "_", "X"], ] # columns # list indexes start at 0 for y in 0..2 do # rows for x in 0..2 do print grid[y][x] end # end of row puts end
true
272c18521d14aaa58e87a3e13718042f3bf9bb25
Ruby
robotspacefish/store_example
/lib/cli.rb
UTF-8
1,145
3.265625
3
[]
no_license
class CLI attr_accessor :type, :options def initialize(args) # TODO handle user not entering any args # args is an array of arguments the # user entered in the command line, or [] @type = args.first @options = args.length > 1 ? self.set_options(args) : [] end def set_options(options) # ...
true
f248132cafafeb768d9f234d27f3ab0ab4e22113
Ruby
SantiagoSalazarPavajeau/etl-project
/common.rb
UTF-8
592
3.046875
3
[]
no_license
require 'csv' require 'awesome_print' class CSVSource def initialize(filename:) @filename = filename end def each csv = CSV.open(@filename, headers: true) csv.each do |row| # load into kiba row by row yield(row.to_hash) end csv.close end end def ad...
true
c1c08d78c898cc6835c50ba27bb892cee66dd386
Ruby
kenosuda4/enjoy-ruby
/chapter-6/while.rb
UTF-8
247
3.640625
4
[]
no_license
i = 1 while i < 3 puts i i += 1 end =begin iに1が代入 i < 3の比較を行う 比較結果が真(iが3より小さい)場合、puts iを実行し 偽(iが3より大きい)場合、何も実行せずwhile分から抜けだす =end
true
85d4235817151974685e937d1c662b41af13ab28
Ruby
pmanni02/hotel
/lib/reservation.rb
UTF-8
717
3.375
3
[]
no_license
module Hotel class Reservation attr_reader :start_date, :end_date, :cost_per_night, :total_cost, :room def initialize(date_range, room, cost_per_night: 200) @start_date = date_range[:start_date] @end_date = date_range[:end_date] # @cost_per_night = 200 @cost_per_night = cost_per_nigh...
true
8a18c5fa6b3ac21531c79d88c4baefe1cb69483a
Ruby
christianlarwood/ruby_small_problems
/codewars_problems.rb/frequent_words.rb
UTF-8
1,503
3.96875
4
[]
no_license
=begin algorithm: - initialize a hash - downcase and split the string into words/chars - iterate through each word or char - count how many times char appears in the string add the key value pair to the hash - sort the hash by value - return the top 3 results by values =end def top_3_words(string) ...
true
2d3113ff202d52a91eaef76575c9c31e068e941e
Ruby
uhlig-it/spritwatch
/lib/sprit_watch/metrics_sender.rb
UTF-8
785
2.5625
3
[]
no_license
# frozen_string_literal: true module SpritWatch class MetricsSender def initialize(influxdb_client) @influxdb_client = influxdb_client end # TODO: Handle closed stations def update(prices) data = prices.map do |station| { series: 'diesel', values: { value: cen...
true
57cb46932fc0409bbb171c82b763abc294856b4f
Ruby
learn-co-students/nyc-web-022221
/09-active-record-associations/db/seeds.rb
UTF-8
774
2.859375
3
[]
no_license
# deletes all plants and people from the database Plant.destroy_all Person.destroy_all PlantParenthood.destroy_all # resets the ids of the plants and people table to 1 Plant.reset_pk_sequence Person.reset_pk_sequence PlantParenthood.reset_pk_sequence shamrock = Plant.create(name: "Shamrock", bought: 20210317, color: "...
true
836d9bb038d76ef1ba0cf9d449ad2392ac42a37b
Ruby
too-yang/BitRun-Abstractor-IDE_Extension
/nlpAPI/koona/tests.rb
UTF-8
1,273
2.9375
3
[ "MIT" ]
permissive
require './lib/compiler.rb' require 'tempfile' require 'test/unit' class TestVarDecl < Test::Unit::TestCase def result_test(input, exp_result) begin c = Koona::Compiler.new input_file = Tempfile.new('TestFile') input_file << input exp_result = exp_result input_file.read # ? Dunno w...
true
62c26343d610117f4cba936ce5394b8c9c261662
Ruby
santosh-1987/RubyScripts
/substring.rb
UTF-8
849
3.890625
4
[]
no_license
class Substring def initialize(name,substr) @name= name @substr = substr end def check_sub_str splitted_str = @substr.split("") indexes = get_index(splitted_str[0]) indexes.each do |index| start_point = index end_point = index + splitted_str.length puts "Start => #{start_po...
true
03035ac5c3ac1ca27079759eb7ed09d6d4e49dd1
Ruby
gesteves/caniuse-slack
/app.rb
UTF-8
8,317
2.609375
3
[ "BSD-3-Clause" ]
permissive
# encoding: utf-8 require "sinatra" require "json" require "httparty" require "dotenv" require "text" require "redis" configure do # Load .env vars Dotenv.load # Set up redis case settings.environment when :development uri = URI.parse(ENV["LOCAL_REDIS_URL"]) when :production uri = URI.parse(ENV["RE...
true
b29e0a3a85b15fba49c26b2489b1b93df47018ba
Ruby
softscienceprojects/OO-Art-Gallery-london-web-080519
/app/models/artist.rb
UTF-8
1,000
3.203125
3
[]
no_license
class Artist attr_reader :name, :years_experience @@all = [] def initialize(name:, years_experience:) @name = name @years_experience = years_experience @@all << self end def self.all @@all end def paintings Painting.all.select {|painting| painting.artist == self} end def galle...
true
7026501143390b332f997f298f6537302a007971
Ruby
rob4lderman/ruby-euler
/prob38.rb
WINDOWS-1252
1,980
4.09375
4
[]
no_license
#! /usr/bin/ruby # # http://projecteuler.net/problem=38 # # Take the number 192 and multiply it by each of 1, 2, and 3: # # 192 1 = 192 # 192 2 = 384 # 192 3 = 576 # # By concatenating each product we get the 1 to 9 pandigital, 192384576. We # will call 192384576 the concatenated product of 192 and (1...
true
e78159d431b940d24a6759a1b2164113b1adac0d
Ruby
AaronReyes-ML/Trail-Weather-Tracker
/vendor/bundle/ruby/2.3.0/gems/reek-1.6.2/lib/reek/source/sexp_extensions.rb
UTF-8
6,362
2.578125
3
[ "MIT" ]
permissive
require 'reek/source/sexp_node' module Reek module Source module SexpExtensions # Base module for utility methods for argument nodes. module ArgNodeBase def name children.first end # Other is a symbol? def ==(other) name == other end ...
true
18be7fccc64bacb87266e586d374911ed33536a8
Ruby
devryn/katas
/accumulate.rb
UTF-8
110
2.71875
3
[]
no_license
class Array def accumulate each_with_object([]) do |elem, ac| ac << yield(elem) end end end
true
0473d6c9b153c53a23ca13aca7059448da718746
Ruby
ledermann/enumlogic
/lib/enumlogic.rb
UTF-8
2,269
2.984375
3
[ "MIT" ]
permissive
require "active_record" # See the enum class level method for more info. module Enumlogic # Allows you to easily specify enumerations for your models. Specify enumerations like: # # class Computer < ActiveRecord::Base # enum :kind, ["apple", "dell", "hp"] # enum :kind, {"apple" => "Apple", "dell" =...
true
f344d838846d272ae1546659e410c61177790022
Ruby
marionzumbado/RepoKreaideas
/CMSKreaideas/app/models/kreaideasmail.rb
UTF-8
589
2.671875
3
[]
no_license
class Kreaideasmail < ActiveRecord::Base attr_accessible :email, :message, :name validates :name,:email,:message, :presence => {:message => "debe estar presente"} validates :email, :format => {:with => %r{\A[\w\.]+@\w+\.[A-Za-z]+\z}, :message => 'ingresado no es un formato válido'} validates :phone, :numerical...
true
aa70e64361247e0975e1357d3016c7a610a0188a
Ruby
yisroelm/ufc-cli-app
/lib/animation.rb
UTF-8
782
3
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def animation_solo 9.times do i = 1 while i < 13 print "\033[2J" File.foreach("hidden/ascii_animation/#{i}.rb") { |f| puts f } sleep(0.05) i += 1 end end end def animation_duo 6.times do i = 1 while i < 22 print "\033[2J" File.foreach("hidden/ascii_animation_2/...
true
8df1ddf5e02be22d5a505de237297623c432b7b6
Ruby
jazzyfresh/project-euler
/2_even_fibonacci.rb
UTF-8
166
3.21875
3
[]
no_license
#!/usr/bin/env ruby MAX = 4000000 sum = 0 n1 = 1 n2 = 2 while (n1 < MAX) sum += n1 if n1 % 2 == 0 new_n1 = n2 n2 = n2 + n1 n1 = new_n1 end print sum, "\n"
true
3706f7636422592f1d57a869072c37fa7ef8c016
Ruby
sdkclements/phase_0_unit_2-1
/week_5/1_die/my_solution.rb
UTF-8
1,792
4.96875
5
[]
no_license
# U2.W5: Die Class 1: Numeric # I worked on this challenge by myself. # 2. Pseudocode # Input: a number of sides for a die # Output: the value of the roll. # Steps: first intialize sides and set argument error for less than 1 #next define sides method based on what we initialize. # use the random method to get a nu...
true
af19b8fe32298aa3e9b772d67a2a5cddd873ba8a
Ruby
Higorsk147/nivelamento-aluno
/06-exercicio.rb
UTF-8
1,116
3.4375
3
[]
no_license
def fase_pandemica(vacinação,transmissão,ocupação) if vacinação >= 0 && vacinação <= 1 && transmissão >= 0 && ocupação >= 0 && ocupação <= 1 if vacinação >= 0.8 && vacinação <= 1.0 return "azul" elsif ocupação <= 0.5 && transmissão < 1.0 return "verde" ...
true
2a7224cba166176946ad6c60321b2ce878abf3e1
Ruby
ykominami/mdextab
/lib/mdextab.rb
UTF-8
19,639
2.625
3
[ "MIT" ]
permissive
# # MarkDownテーブル拡張モジュール # module Mdextab # # エラークラス # class Error < StandardError; end # # MarkDownテーブル拡張クラス # class Mdextab require "mdextab/version" require "mdextab/token" require "mdextab/table" require "mdextab/tbody" require "mdextab/td" require "mdextab/th" require "m...
true
e40750db96ed90788c417f5c2c78443807be5224
Ruby
adisney/bballbattle
/spec/manage_spec.rb
UTF-8
1,750
2.796875
3
[]
no_license
require 'manage.rb' describe "manage" do let ( :manager ) { Manager.new('picks_file', 'bracket_file') } let ( :bracket ) { double "bracket" } let ( :file ) { double "file" } before( :each ) do allow(Bracket).to receive(:new).and_return bracket allow(bracket).to receive(:get_teams).and_return({ "...
true
a4840e54d1a72bffed799acc889f588af221505a
Ruby
outoftime/harp
/bin/harp-server
UTF-8
1,339
2.578125
3
[]
no_license
#!/usr/bin/env ruby using_gems = false begin require 'sinatra' require 'haml' rescue LoadError => e if using_gems then raise(e) else using_gems = true require 'rubygems' retry end end module Harp module Server class ReportViewer def initialize(filename) @yaml = File.open(FILE...
true
8534346094f669539991ce292ec1f81e22f2fe18
Ruby
christopher-s-b/sandbox
/contuations/cont2.rb
UTF-8
370
2.90625
3
[]
no_license
require 'stacktrace' def foo puts "foo: enter" the_fn = lambda do puts "foo: count=#{$count}" show_stack $count -= 1 bar end res = callcc do |k| puts "pre" $k1 = k puts "post" end the_fn.call end def bar puts "bar: enter" if $count > 1 val = $k1.call end puts "ba...
true
a62ac86ffd61af1348aa845c05c07efcc35fdf4a
Ruby
gazdagandras/KeypadKata
/3/keypad.rb
UTF-8
1,283
3.921875
4
[]
no_license
class KeypadKata def initialize(dictionary_path) @words = File.readlines(dictionary_path).map { |word| word.strip } end def predict(input) find_in_dictionary convert_input_to_string(input) end private def convert_input_to_string(input) NumericToTextConverter.new.convert input end ...
true
fa4294d40f451ec81fc97f22900ff314704131e7
Ruby
linyows/vagrant-properties
/lib/vagrant-properties/config.rb
UTF-8
2,830
2.59375
3
[ "MIT" ]
permissive
require 'vagrant' require 'yaml' module VagrantProperties class Config < Vagrant.plugin('2', :config) attr_writer :properties_path def to_hash self.class.properties end def named(key) self.class.properties[key.to_sym] end class << self def properties @properties |...
true
301e67dbbb5eb7cc68d29ee98dfb6eeb8686fab7
Ruby
melair/struggle
/lib/struggle/arbitrators/realignment.rb
UTF-8
1,060
3.015625
3
[ "MIT" ]
permissive
module Arbitrators class Realignment < MoveArbitrator fancy_accessor :player, :ops_counter needs :countries, :defcon def initialize(player:, ops_counter:) super self.player = player self.ops_counter = ops_counter end def before_execute(move) country = countries.find(mo...
true
82c3c359419fff98ad5f0540eddaea07576d26cd
Ruby
spark-59/usercycle-api-ruby
/lib/usercycle/person.rb
UTF-8
473
2.515625
3
[ "BSD-3-Clause", "LicenseRef-scancode-unknown-license-reference" ]
permissive
module Usercycle module Person def person @person ||= Person.new self end class Person def initialize(client) @client = client end def find_by_id(id, options={}) @client.class.get("/people/#{id}.json", @client.options.merge(options)) end def find_by_i...
true
d5c540190bc4337b73de83c104e896ace06d6b85
Ruby
eramsey/stock_mentions
/lib/youtube_puller.rb
UTF-8
2,387
3.078125
3
[]
no_license
require 'httparty' require 'yaml' class YoutubePuller attr_accessor :channels attr_reader :api_key, :base, :verbose def check_channels raise 'No channels given' unless channels.is_a?(Array) && channels.size > 0 end def pull_configs config_file = ARGV[0] @config = YAML.load(File.read(config_file...
true
2636ec42a199efd15415cf1f159c23d65be713b5
Ruby
MelissaR3/BLOG
/app/views/aboutme/20q.rb
UTF-8
637
3.890625
4
[]
no_license
# writing a 20 question script # script should be run from the command line # script should ask # or false from the user # script should than tell the user if response was correct or not # after all questions and responses, script should output the "tally" # or total correct # questions # answers # score # ask que...
true
244f9cd76322c68c7ccadcadebf2cd795bcda9f8
Ruby
crisefd/TGA-HTGA-CCHTGA
/cchtga/features/step_definitions/mutation_steps.rb
UTF-8
2,710
2.796875
3
[]
no_license
mutation_test_vars = {} Given(/^the size twenty chromosome:$/) do |table| table = table.raw chromosome = Chromosome.new table.first.each{ |item| chromosome << item.to_f } mutation_test_vars[:chromosome] = chromosome end Given(/^the upper bounds:$/) do |table| table = table.raw upper_bounds = [] table.f...
true
3064b0475a2b2d5a639984b56b43046afe50e3ee
Ruby
shmulim/apples-and-holidays-001-prework-web
/lib/holiday.rb
UTF-8
1,077
3.359375
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def second_supply_for_fourth_of_july(holiday_hash) holiday_hash[:summer][:fourth_of_july][1] end def add_supply_to_winter_holidays(holiday_hash, supply) holiday_hash[:winter].each do |key, value| if key == :christmas || key == :new_years value << supply end end end def add_supply_to_memorial_day(...
true
1a445248694cfc2bf5e9b6ed7db4c2ff68996d1c
Ruby
Ramaze/ramaze
/lib/ramaze/log/logging.rb
UTF-8
2,737
3.125
3
[ "MIT" ]
permissive
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com # All files in this distribution are subject to the terms of the MIT license. module Ramaze ## # This module provides a basic skeleton for your own loggers to be compatible. # # @example # class MyLogger # include Logging # # ...
true
ca082c3d5e861942a2e9b3f3948fd84a8d6442da
Ruby
mgraonic/digit_match
/lib/digit_match.rb
UTF-8
363
3.546875
4
[]
no_license
# Returns count of digits matching in the two input non-negative integers def digit_match(number1, number2) match = 0 return match if number1 == nil || number2 == nil return match if number1 < 0 || number2 < 0 until number1 == 0 || number2 == 0 match += 1 if number1 % 10 == number2 % 10 number1 /= 10 ...
true
0c3b77900c78c2498c9d914f06218171d8d3852f
Ruby
Haz3/Soonzik
/RailsProject/app/controllers/API/news_controller.rb
UTF-8
10,029
2.515625
3
[]
no_license
module API # Controller which manage the transaction for the News objects # Here is the list of action available : # # * index [get] # * show [get] # * find [get] # * addcomment [post] - SECURITY # * getcomments [get] # class NewsController < ApisecurityController # Retrieve ...
true
1b9f9f67890bd76ae68fb6689fd8283a7d32ffad
Ruby
markdamobi/hack-night-sudoku-solver
/spec/cell_spec.rb
UTF-8
2,295
3.46875
3
[]
no_license
require_relative '../cell' describe 'Cell' do describe '#x and #y' do it 'initializes the cell with the given position' do cell = Cell.new(x: 0, y: 5) expect(cell.x).to eql 0 expect(cell.y).to eql 5 expect(cell.position).to match_array [0,5] end end describe '#value' do c...
true
82eeec21bd9dccedd2b39614893a59f08ae9755f
Ruby
mavesonzini/Veronica
/Ruby.rb
UTF-8
1,695
4.21875
4
[]
no_license
# 99 bottles of beer on the wall, 99 bottles of beer. # Take one down and pass it around, 98 bottles of beer on the wall. # 1 bottle of beer on the wall, 1 bottle of beer. # Take one down and pass it around, no more bottles of beer on the wall. # No more bottles of beer on the wall, no more bottles of beer. # Go t...
true
1b59a62ac1d5291419bda3be0b4b4c9a8ffa07c6
Ruby
tandibar/ass
/advanced/source/refactoring/tests/customer_test.rb
UTF-8
2,236
2.953125
3
[]
no_license
require File.dirname(__FILE__) + '/test_env' class CustomerTest < Test::Unit::TestCase def test_create_customer_with_name customer = Customer.new("Hans Wurst") assert customer assert_equal "Hans Wurst", customer.name end def test_add_rental assert Customer.new("Hans Wurst") << Rental.new(Mo...
true
45566b93c763e366025f807184acd9f5d28ce21a
Ruby
jordan-brough/buffering_logger
/spec/single_line_transform_spec.rb
UTF-8
674
2.671875
3
[]
no_license
require 'buffering_logger/single_line_transform' describe BufferingLogger::SingleLineTransform do it 'strips the string, replaces newlines with spaces and adds a newline at the end' do transform = BufferingLogger::SingleLineTransform.new string = " one\r\ntwo\nthree \n" expect(transform.call(string)).to...
true
f9f663f576bf5d1fa17d77005b47b72580d6c191
Ruby
techtronics/natural-english-script
/test/unit/observer_test.rb
UTF-8
1,488
2.703125
3
[]
no_license
require 'test_helper' #require '../test_helper' $use_tree=false #$use_tree=true #require_relative "../lib/english-script/english-parser" require_relative "../../lib/english-script/english-parser" class ObserverTestParser<EnglishParser def initialize @@testing=true super end def test_whenever pars...
true
e5db7ec62c67c2ec2fb8850e7ab7b3768882f5c5
Ruby
rupaliadvirkar/billing_system
/customer.rb
UTF-8
432
2.6875
3
[]
no_license
class Customer < User def initialize(p_created_at=Time.now) super(p_created_at) end def net_amount_payable(items) if is_customer_and_for_over_2yrs? super(CUSTOME_FOR_2_YRS_DISCOUNT_IN_PERCENTAGE,items) else super end end #This method will return whether user is customer from l...
true
b74fae7862feb6bca9964239df9a825206ff93cc
Ruby
JessicaG/the_pivot
/spec/models/vendor_spec.rb
UTF-8
1,638
2.59375
3
[]
no_license
require 'rails_helper' RSpec.describe Vendor, :type => :model do let(:vendor) { create(:vendor) } it 'is valid' do expect(vendor).to be_valid end it 'is invalid without a name' do vendor.name = nil expect(vendor).to_not be_valid vendor.name = "" expect(vendor).to_not be_valid end ...
true