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
1ba2b331739b4df07097d4dd8813afd98047808e
Ruby
artsy/dd-trace-rb
/spec/support/spy_transport.rb
UTF-8
1,585
2.875
3
[]
no_license
require 'ddtrace/encoding' require 'ddtrace/transport' # SpyTransport is a dummy HTTPTransport that tracks what would be sent. class SpyTransport < Datadog::HTTPTransport attr_reader :helper_sent def initialize(hostname, port) super(hostname, port) @helper_sent = { 200 => {}, 500 => {} } @helper_mutex...
true
d53011bbacb4b267ab3d8e0bbb2c4076d26a210b
Ruby
getoutreach/area_code_to_state
/lib/area_code_to_state.rb
UTF-8
1,237
3.265625
3
[]
no_license
# frozen_string_literal: true class AreaCodeToState class << self def area_code_to_region(area_code) state = two_char_states.slice((area_code - 200) << 1, 2) return state unless state[0] == '.' case state[1] when ',' then nil when '>' then other_regions[area_code] else; state...
true
62e46428c7e7ba57ee25ab149c091168b636ba89
Ruby
itsolutionscorp/AutoStyle-Clustering
/all_data/exercism_data/ruby/phone-number/88f165907a9642da8031ff20f06bb81c.rb
UTF-8
670
3.390625
3
[]
no_license
class PhoneNumber DEFAULT_NUMBER = "0000000000" def initialize(raw_number) @number = sanitize_number raw_number end def number @number end def area_code @number.slice(0, 3) end def to_s "(%3d) %3d-%4d" % [self.area_code, @number.slice(3,3), @number.slice(6,4)] end private def...
true
38372e762662b0cc8d4599a4860194b9a36c285e
Ruby
blueberryapps/useful_renderers
/lib/useful_renderers/zip_renderable.rb
UTF-8
596
2.671875
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
require 'rubygems' require 'zip' module UsefulRenderers module ZipRenderable # You need to call this on collection of File objects # or objects which provides :read & :path method def to_zip(*) return '' if empty? return '' unless first.respond_to?(:path) && first.respond_to?(:read) ...
true
50fdf29b75aa8155286a6fd2243775995b95cf86
Ruby
gatorjuice/acltc
/week0/week_1/FullName.rb
UTF-8
1,175
3.9375
4
[]
no_license
#Full Name assignment system("clear") puts "__________________" puts "| |" puts "| Jamie's |" puts "| EXTRA FANCY |" puts "| NAME PUTTER- |" puts "| TOGETHERER |" puts "|________________|" puts "Press enter to continue..." gets.chomp system("clear") puts "Why don't you go ahead and type ...
true
3f4f694906c1a4f8849bcc9c943ac99920ea58ad
Ruby
d-atkins/brownfield-of-dreams
/app/services/github_service.rb
UTF-8
634
2.6875
3
[]
no_license
class GithubService def get_repo_data(user) get_json(user, '/user/repos?sort=created&direction=asc') end def get_follower_data(user) get_json(user, '/user/followers') end def get_following_data(user) get_json(user, '/user/following') end def get_user_data(user, username) get_json(user, ...
true
6413161f5340ad746b4fbd4e779d5083ac65db0e
Ruby
stevepm/intro_to_tdd
/lib/numeric_calculator.rb
UTF-8
254
3.40625
3
[]
no_license
class Calc def initialize @saved = nil end def add(num1, num2) num1 + num2 end def subtract(num1, num2) num1 - num2 end def save(num) @saved = num end def get @saved end def clear @saved = nil end end
true
aee32356d999404e7caa5b8c4ab581c1d2a880eb
Ruby
GAV1N/on_the_spot
/lib/on_the_spot/controller_extension.rb
UTF-8
1,869
2.546875
3
[ "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
module OnTheSpot module ControllerExtension def self.included(base) base.extend ClassMethods end # if this method is called inside a controller, the edit-on-the-spot # controller action is added that will allow to edit fields in place module ClassMethods def can_edit_on_the_s...
true
b243553b7e372c73389ecefda281088844a31914
Ruby
femina-hip/feminadb
/app/models/reports.rb
UTF-8
6,766
2.5625
3
[]
no_license
module Reports class <<self # Returns rows of [ staff member, # school standing orders, # clubs, percent clubs ] def staff_schools_clubs result = Customer.connection.select_all <<-EOT SELECT regions.manager AS staff_member, SUM(( SELECT COUNT(*) FROM c...
true
b244e040e131a6c0ff10bb8342610830b4800f03
Ruby
benswift/benswift.github.io
/_plugins/livecoding-bib.rb
UTF-8
1,612
2.609375
3
[ "MIT" ]
permissive
require "yaml" def write_lc_set_md_files() site.data["livecoding-sets"]["references"].each do |lcset| a = lcset["issued"][0] date = "#{a['year']}-#{format('%02d', a['month'])}-#{format('%02d', a['day'])}" filename = "_livecoding-sets/#{date}-#{Jekyll::Utils.slugify(lcset["event"])}.md" frontmatter =...
true
a1db6af213bb893d0c4956e7e17e1bb190bfa3e2
Ruby
timle8n1/aoc2015
/day18/solve.rb
UTF-8
1,565
3.1875
3
[]
no_license
#! /usr/bin/env ruby module Solver def self.solve(input, apply_stuck) (1..100).each do |step| reference = input.map(&:clone) (0...100).each do |y| (0...100).each do |x| neighbor_on_count = 0 neighbor_on_count += 1 if x > 0 && y > 0 && reference[y-1][x-1] == "#" ...
true
c63ce7eae8f928d9e4f9d23a7fd47a433ce45051
Ruby
ferconde87/object-oriented-design
/tdd-tic-tac-toe/spec/board_spec.rb
UTF-8
545
2.65625
3
[]
no_license
require "board" RSpec.describe "Board" do context "when the board is initialize" do let(:board) { Board.new } it "has a matrix" do expect(board.matrix).not_to be_nil end it "has a size" do expect(board.size).not_to be_nil expect(board.size).to be > 0 end it "has the number...
true
0f771014f2205bf1796842a88fe610565c56a561
Ruby
mollynemerever/the-bachelor-todo-seattle-web-career-021819
/lib/bachelor.rb
UTF-8
1,431
3.625
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def get_first_name_of_season_winner(data, season) data[season].each do |contestants| #go directly into that season's value and go through array of contestants if contestants["status"] == "Winner" #located the winner of the season name = contestants["name"] first_name = name.split #winner name split...
true
ca7de2a3f1c0e4b6b8f9d64aa4f6420aa3ad6f0d
Ruby
kostya/confuddle
/lib/graft/lib/graft/model.rb
UTF-8
1,024
2.75
3
[ "MIT" ]
permissive
module Graft module Model module ClassMethods def attributes @attributes ||= [] end def collection_from(data_source, node) (data_from(data_source)/node).map {|n| new n } end def collection_from_block(data_source, node, &block) (data_from(data_source)/...
true
199be76ae0ab0a2853cb117e383aaeb4691ea455
Ruby
higepen/hige-command-launcher
/hige-command-launcher.rb
UTF-8
4,383
2.515625
3
[]
no_license
# -*- coding: utf-8 -*- ############################################################# # # HIGE-COMMAND-LAUNCHER 2012.06 # #入力欄にキーワードを入力しリターンキーを押すと、対応するコマンドが発動。自身は終了する。 #ブラウザでの検索機能付き。この場合はキーワードと検索語の間に空白を1つ入れる。 ############################################################ require 'gtk2' require 'yaml' DIR = File.dirnam...
true
ba933982295af0f3069f34e752fdea3d695f3cba
Ruby
rahul2501350/stock_quote
/lib/stock_quote/stock.rb
UTF-8
2,811
2.859375
3
[ "MIT" ]
permissive
require "rubygems" require "rest-client" require "hpricot" require "date" module StockQuote class Price attr_accessor :date, :open, :high, :low, :close, :volume def initialize(date,open,high,low,close, volume) date = date.split("-") @date = Time.utc(date[2],date[1],date[0].to_i) @open = o...
true
23c8f69c68eb03734d802ab93bad2593f49df640
Ruby
190701-revature/SENG-LIVE-071921
/phase-3/06_activerecord_associations_many_to_many/exercise/db/seeds.rb
UTF-8
1,737
2.8125
3
[]
no_license
# Once you have your models defined, uncomment the following 3 lines: Doctor.destroy_all Patient.destroy_all Appointment.destroy_all # # Sample data for doctors to use for seeds Doctor.create( name: "Dr. Miranda Bailey", specialization: "Chief of Surgery", hospital: "Grey Sloan", gives_lollipop: true ) Docto...
true
3d6f056155163854f02d727089677223d34352f9
Ruby
LuuuFan/daywork
/W3D1/lib/04a_countries_bonus.rb
UTF-8
2,409
3.03125
3
[]
no_license
# == Schema Information # # Table name: countries # # name :string not null, primary key # continent :string # area :integer # population :integer # gdp :integer require_relative './sqlzoo.rb' # BONUS QUESTIONS: These problems require knowledge of aggregate # functions. Attempt the...
true
4d4795bdfcaf8ee0103c628da78f4724b6da71d4
Ruby
charleslambert/CPTR-232-Lab-Hash
/myWidgets.rb
UTF-8
723
2.71875
3
[]
no_license
require 'Qt' class MyValueBox < Qt::Widget def initialize(label, mode) super() @mode = mode grid = Qt::GridLayout.new(self) @label = Qt::Label.new(label, self) if @mode == :spin @box = Qt::SpinBox.new do |i| i.range = 1..(1<<31-1) i.singleStep = 1 end elsif @mode == :te...
true
4d5e64edc26b7fdeaf3cf36fae0202749f15a58d
Ruby
scoophealth/health-data-standards
/lib/health-data-standards/import/c32/section_importer.rb
UTF-8
9,500
2.859375
3
[ "Apache-2.0" ]
permissive
module HealthDataStandards module Import module C32 # Class that can be used to create an importer for a section of a HITSP C32 document. It usually # operates by selecting all CDA entries in a section and then creates entries for them. class SectionImporter include HealthDataStandards::...
true
481f0fceda13605380f8b12941530d03ec4e2dc5
Ruby
suttonau/countdown-to-midnight-prework
/countdown.rb
UTF-8
269
3.671875
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def countdown(number) number = 10 while 0 < number puts "#{number} SECOND(S)!" number -= 1 break if number == 0 end return "HAPPY NEW YEAR!" end def countdown_with_sleep(count) while count > 0 count -= 1 sleep 1 end end
true
d7e2c49192e6ebd4d0b8b0d508ba530cefc980d7
Ruby
rer7891/book_review
/app/facades/book_search.rb
UTF-8
496
2.90625
3
[]
no_license
class BookSearch def initialize(title) @title = title end def book_title book.title end def book_author book.author.first end def book_genre book.genre end def get_reviews reviews end private def book service = BookService.new.get_book(@title) @book ||= Book....
true
cfbdbcfe836ef298b03a1dc97850141e646fb711
Ruby
pkellz6/Portfolio-2
/star_wars.rb
UTF-8
6,255
3.765625
4
[]
no_license
module Star_Wars # Displays your options def display_choices puts <<-END What would you like to do/say? Options: #{yield} Enter the letter corresponding to your choice. END end # This is yoour first option, answering (y) or (n) will take the user to the next set of ooptions while (a) ends ...
true
7c20510de5a9a71c0e938513680bd5712f1a1edf
Ruby
matled/tagfs
/spec/tag_reader_spec.rb
UTF-8
2,493
2.546875
3
[]
no_license
require 'spec_helper' describe TagReader do before(:all) do @tagfs = TagReader.new @base = Pathname.new(Dir.pwd + "/testfs") end def match(path, spec) @tagfs.match(@base + path, spec) end it "should tag one directory correctly" do match("a", { "foo" => true }).should be_true match("a", ...
true
34630498dfe057cc636f4877cadcf29a74d5eb4b
Ruby
pertrai1/exercism
/ruby/sieve/sieve.rb
UTF-8
337
3.703125
4
[ "Apache-2.0" ]
permissive
class Sieve def initialize(max) @max = max end def primes is_prime = Array.new(@max + 1, true) primes = [] (2..@max).each do |number| next unless is_prime[number] (number * 2..@max).step(number).each do |multiple| is_prime[multiple] = false end primes << number ...
true
b49ee021da014f188674eff4d728c9ad94a2e592
Ruby
tplusfive/Terminal-Clue
/tests/test_solution_envelope.rb
UTF-8
2,337
3.0625
3
[]
no_license
require "test/unit" require "terminal_clue/solution_envelope.rb" require "terminal_clue/suspects.rb" require "terminal_clue/weapons.rb" require "terminal_clue/rooms.rb" class TestSolutionEnvelope < Test::Unit::TestCase def test_assign_suspect puts " testing" suspects_tested = [] # keep track of randomly gen...
true
ab7405ede3d3b49670fd18cbbed3a9fe012850aa
Ruby
laboon/CS1632_Spring2019
/exercises/4/solution/wolf_pack_test.rb
UTF-8
1,629
3.03125
3
[ "MIT" ]
permissive
require 'minitest/autorun' require_relative 'wolf' require_relative 'wolf_pack' class WolfPackTest < Minitest::Test def setup @wolf_pack = WolfPack::new end # Test all_howl # If all_howl is called, every wolf should have # their .howl method called. def test_all_howl w1 = Minitest::Mock::new ...
true
590ec471abfce0ee1ee481a59df2ab4facbede41
Ruby
natey37/Project_euler
/3_largest_prime_factor.rb
UTF-8
425
4.28125
4
[]
no_license
#The prime factors of 13195 are 5, 7, 13 and 29. #What is the largest prime factor of the number 600851475143 ? require 'prime' def prime_factor(num) prime = 3 last_divisor = 0 while prime <= num if num % prime == 0 && Prime.prime?(prime) last_divisor = prime num = num / prime ...
true
d86d7742e517ccda681698e39805bcb6a71225a4
Ruby
PetePhx/challenges
/medium_2/09_simple_linked_list.rb
UTF-8
1,508
4.125
4
[]
no_license
=begin Simple Linked List Write a simple linked list implementation that uses Elements and a List. The linked list is a fundamental data structure in computer science, often used in the implementation of other data structures. The simplest kind of linked list is a singly linked list. Each element in the list contai...
true
f030a78330f8372c84fa20d33bc7c527399cf8c0
Ruby
weilandia/black_thursday
/spec/transaction_repository_spec.rb
UTF-8
3,032
2.71875
3
[]
no_license
require_relative 'test_helper' require_relative '../lib/transaction_repository' class TransactionRepositoryTest < Minitest::Test def test_transaction_repo_can_list_all_transaction t = TransactionRepository.new transaction_one = Transaction.new(test_helper_transaction_one_data) transaction_two = Transac...
true
577346a4673c469c80328546ce20e9c6baca2af9
Ruby
randycoulman/currencyfx
/spec/cli_spec.rb
UTF-8
4,428
2.9375
3
[ "MIT" ]
permissive
module Currencyfx RSpec.describe CLI do subject(:cli) { described_class.new(exchange: exchange, list_formatter: formatter) } let(:exchange) { instance_double(Exchange) } let(:formatter) { instance_double(ListFormatter) } before do allow(exchange).to receive(:convert) allow(exchange).to re...
true
23745ae598a741c5a061d203495a865d25b8e2b1
Ruby
domhnall/pe
/problem_29/problem_29.rb
UTF-8
142
2.765625
3
[]
no_license
terms = [] (2..100).each do |a| (2..100).each do |b| terms << a**b end end uniq_terms = terms.uniq puts "Answer: #{uniq_terms.size}"
true
509d59bd6d300858d2381eb87ac75c9056f5fdd1
Ruby
RiotGamesMinions/motherbrain
/lib/mb/mixin/attribute_setting.rb
UTF-8
9,258
2.609375
3
[ "Apache-2.0" ]
permissive
require 'mb/mixin/services' module MotherBrain module Mixin module AttributeSetting extend Forwardable include MB::Logging include MB::Mixin::Services # Set the appropriate attributes at the environment level to the desired version # for each component given # # @param ...
true
0d542549e91c6a369160404b6cf3145b0d56d8f1
Ruby
mauazua/system
/lib/person.rb
UTF-8
196
2.859375
3
[]
no_license
module Person def full_name if first_name && last_name [first_name, last_name].join(' ') else email.split('@').first.split('.').map(&:capitalize).join(' ') end end end
true
7a914b76d66416aeb0aa558221557276564f78f5
Ruby
fac/authoreyes
/lib/authoreyes/parser/priveleges_reader.rb
UTF-8
2,040
2.8125
3
[ "MIT" ]
permissive
module Authoreyes module Parser # The PrivilegeReader handles the part of the authorization DSL in # a +privileges+ block. Here, privilege hierarchies are defined. class PrivilegesReader # TODO: handle privileges with separated context attr_reader :privileges, :privilege_hierarchy # :nodoc: ...
true
12d92e4597f51bc317e1f460d2c40d0323a8d4b5
Ruby
james05/leetcode
/242.rb
UTF-8
1,409
4.09375
4
[]
no_license
# Link: https://leetcode.com/problems/valid-anagram/ # @param {String} s # @param {String} t # @return {Boolean} def is_anagram(s, t) return false if s.length != t.length count = Hash.new s.each_char do |character| if count[character].nil? count[character] = 0 end count[character] = count[char...
true
888babb4169cb90c6dfe9cdd9124644c56d94f8c
Ruby
celestelayne/CHI_BEWD1
/Week2/Lesson1/instructor_notes/arrays.rb
UTF-8
436
3.5
4
[]
no_license
# Create a new array and assign it to a variable # Check its class # !! A class tells you what things this object can respond to !! # Create a new array # Get size with count, size, length, empty? # Read from an array, zero indexing # Append to the array, with push, << and unshift # Show popping and shifting # Show how...
true
c5f3f1119952545face7a4dbd946f7adfebb6d59
Ruby
Meghannwalsh/ruby-enumerables-hash-practice-nyc-pigeon-organizer-lab-nyc-web-071519
/nyc_pigeon_organizer.rb
UTF-8
1,315
3.0625
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
def nyc_pigeon_organizer(data) pigeon_data = {} data.each do |k, v| v.each do |spac, names| names.each do |name| if !pigeon_data.include?(name) pigeon_data[name] = {:color => [], :gender => [], :lives => []} end end end end pigeon_data.each_key do |name| data[:color].each...
true
97fcccf7893b309c76cffa24998d1e0850ed1907
Ruby
toddt67878/Course_Ruby
/The_Time_Object/Add_Subtract_Time_by_Seconds.rb
UTF-8
367
3.453125
3
[]
no_license
#start_of_year = Time.new(2016, 1, 1) #p start_of_year #p start_of_year + 60 #p start_of_year - 180 #p start_of_year + (60 * 60 * 24 * 45) def find_day_of_year_by_number(number) current_date = Time.new(2019, 1, 1) one_day = 60 * 60 * 24 until current_date.yday == number current_date += one_day end curr...
true
9f361973e7d008a548f076c715ffe13387274e35
Ruby
hirohisa/file_crawler
/lib/file_crawler/finder/command/collect.rb
UTF-8
1,588
2.765625
3
[ "MIT" ]
permissive
module FileCrawler class Regex attr_accessor :regexp_start, :regexp_end def initialize(regexp_start, regexp_end) @regexp_start = regexp_start @regexp_end = regexp_end end def pattern /#{Regexp.escape(regexp_start)}([^#{Regexp.escape(regexp_end)}]+)#{Regexp.escape(regexp_end)}/ ...
true
cb64ca36d90b3a65e9ebdc7d5fd675b4f7c17148
Ruby
codevania/ProjectEuler
/Problem 12.rb
UTF-8
1,584
3.78125
4
[ "CC-BY-3.0" ]
permissive
def GetNthTriangleNumber( nth ) return nth * (nth + 1) / 2 end def IsPerfactSquare( num ) return 1 == Rational( Math.sqrt( num ) ).denominator end def GetDivisorsCount( num ) if ( num == 1 ) then return 1 end count = 0 i = 1 bound = num while ( i < bound ) if ( num % i == 0 ) #print "i : ", i, " ...
true
3d2598bf746b3b42f4c6be1a4eba81b71b78fa9d
Ruby
zhenyat/lmc_pilot
/app/models/user.rb
UTF-8
2,083
2.515625
3
[]
no_license
################################################################################ # Model: User # # Users authorized to sign in # # Handled via Admin # # Attributes: # store_id - Foregn Key # department_id - FK # positin_id - FK # level_id - FK # manager_id - FK (int...
true
0164b52f6181b1a3feff08fae892f8472af26d42
Ruby
sonata/mongoid
/lib/mongoid/associations/options.rb
UTF-8
1,444
2.609375
3
[ "MIT" ]
permissive
# encoding: utf-8 module Mongoid #:nodoc: module Associations #:nodoc: class Options #:nodoc: # Create the new +Options+ object, which provides convenience methods for # accessing values out of an options +Hash+. def initialize(attributes = {}) @attributes = attributes end ...
true
8723a9cd113bf8a657b743e50dd94f40fc7a7079
Ruby
alex-png/module-one-final-project-guidelines
/lib/question.rb
UTF-8
5,478
3.328125
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
require "pry" class EasyQuestion def self.q0 v1 = User.current.venues.all.sample puts "Hey, it's #{v1.name}. We mostly play #{v1.genres.map do |genre| genre.name end.join(" and ") }. Who have you got for us?" artist = treat_input_as_artist a = check_artist_genre_is_right_for_venue(ar...
true
75394dcd4d65e29c31d6f025117abea3414ae98e
Ruby
lakhanbrowserstack/greed_game_ruby
/utils/calculate_score.rb
UTF-8
777
3.453125
3
[]
no_license
class Score def self.score(dice) $result = 0 hash_score = { 1 => 100, 5 => 50, [1, 1, 1] => 1000, 2=>0, 3=>0, 4=>0, 6=>0 } dice_count = Hash.new(false) dice.each do |elem| if dice_count[elem] dice_count[elem] += 1 else ...
true
52bacdb16f38a7fd0be60a0cfeb8fa7c58149227
Ruby
ntuzer/autogarden
/Ruby/read2.rb
UTF-8
739
2.796875
3
[]
no_license
require "serialport" require "json" FILENAME = "test1.txt" device = Dir["/dev/tty.usb*"][0] #may be different for you baud_rate = 9600 portal = SerialPort.new(device, baud_rate, 8, 1, SerialPort::NONE) File.exist?(FILENAME) ? nil : File.open(FILENAME, "w") data_logs = File.open(FILENAME, "a") while true do while...
true
df43fd2d13ac0b07c371289e0379249d712dcd01
Ruby
cardo22/Ironhack
/week1/Day 2/Blog/lib/blog.rb
UTF-8
241
3.109375
3
[]
no_license
class Blog def initialize() @posts = [] #instance variable end def add_post(single_post) @posts.push(single_post) end def publish_front_page @posts.each do |post| post.display # puts "*"*post.title.length end end end
true
46b6ab21426dba5c5dd510a6b9b8c66a783a2a4a
Ruby
vibraniumforge/the-bachelor-todo-seattle-web-career-042219
/lib/bachelor.rb
UTF-8
1,106
3.609375
4
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
require "pry" def get_first_name_of_season_winner(data, season) winner = data[season].find do |person| person["status"] == "Winner" end winner["name"].split(" ").first end def get_contestant_name(data, occupation) data.each do |season, contestants| answer = contestants.each do |contestant| if contes...
true
9f890571ac5b5e528ebe68260770040ece189c81
Ruby
ashusvnath/misc
/1s.rb
UTF-8
1,556
3.78125
4
[]
no_license
def score(expr) ops = expr.scan(/[!+-\/*scf]/).count ones = expr.scan(/1/).count ops * ones end def c(x) (x*1.0).ceil end def f(x) (x*1.0).floor end def s(x) Math.sqrt(x) end class Fixnum @@facts = {0 => 1, 1 => 1, 2 => 2} def fact return 0 if self < 0 @@facts[self] ||= self * (self-1).fact e...
true
e78339ebf0141f1b115552a174e1995f2e0a7d9e
Ruby
kelvinjhwong/ruby-exercises
/ruby-small-problems/03_easy_3/03_07.rb
UTF-8
1,207
4.09375
4
[]
no_license
def oddities(array) result = [] array.each_with_index { |element, index| result << element if index.even? } result end def oddities2(array) result = [] 0.step(array.size-1, 2) { |i| result << array[i] } result end def oddities3(array) result = [] array.size.times { |i| result << array[i] if i.even?} ...
true
03a716a57fabf670bbd94bf023e74d188fbc6218
Ruby
zed-0xff/pedump
/lib/pedump/pe.rb
UTF-8
4,067
2.625
3
[ "MIT" ]
permissive
require 'pedump/composite_io' class PEdump class PE < Struct.new( :signature, # "PE\x00\x00" :image_file_header, :image_optional_header, # includes data directory :section_table ) alias :ifh :image_file_header alias :ifh= :image_file_header= alias :ioh :imag...
true
75c09f6387e55c09e747451df8cfdd62433aa75f
Ruby
juanferreira/learning-ruby
/loops.rb
UTF-8
368
3.84375
4
[]
no_license
# Testing while loop i = 0 while i <= 10 puts "i is now #{i}" i += 1 end puts "The final value of i is #{i}" # Testing until loop j = 0 until j > 10 do puts "The final value of j is #{j}" j += 1 end puts "The final value of j is #{j}" #Testing for loop for k in 0..10 do puts "k is now #...
true
e85a5b7a98b8d6675cd68e8d0c134ddfe4a9ab42
Ruby
AlanDai/aA_Classwork
/W4/D3/chess/rook.rb
UTF-8
250
2.90625
3
[]
no_license
require_relative "piece.rb" require_relative "slideable.rb" class Rook < Piece include Slideable def symbol "r" end def move_dirs axial = true diagonal = false return [axial, diagonal] end end
true
616ff17dcfd528b041f1e52119368758ef7b691f
Ruby
mrazicz/redis-model-extension
/test/redis_model_parts/test_attributes.rb
UTF-8
1,262
2.53125
3
[ "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
# -*- encoding : utf-8 -*- require 'helper' class AttributesTest < Test::Unit::TestCase context "Attributes" do setup do @time = Time.now @args = { "integer" => 12345, :string => "foo", :symbol => :bar, :boolean => true, :array => [1,2,3], :field_ha...
true
79e2950d721058fb9140c35da5e88475487a04a7
Ruby
CNBorn/ruby-cheatsheet-code
/oop2.rb
UTF-8
797
3.609375
4
[]
no_license
class Person def initialize(name, age) @name = name @age = age end attr_reader :name, :age attr_writer :name, :age end class Employee < Person def initialize(name, age, empno) super(name, age) @empno = empno end attr_reader :empno attr_writer :empno ...
true
507e9bb80ca570b61f82dd055f45c62502c5e625
Ruby
nysdin/AtCoder
/ABC/165/c.rb
UTF-8
470
3.265625
3
[]
no_license
$n, $m , q = gets.split.map(&:to_i) $ans = 0 $seq = [] q.times do |i| a, b, c, d = gets.split.map(&:to_i) $seq.push([a,b,c,d]) end def calc(seq) now = 0 $seq.each do |s| if seq[s[1]-1] - seq[s[0]-1] == s[2] now += s[3] end end $ans = now if now > $ans end # def dfs(seq) if seq.length == $n ...
true
730eef7aca730737ee02a194eccbb93d25d9a3e8
Ruby
jeremywinters/arbol
/lib/builder.rb
UTF-8
2,422
2.59375
3
[ "MIT" ]
permissive
require 'json' require 'pp' require 'erb' require_relative 'base.rb' # module used to handle the global class map module Arbol @@class_map = {} def self.class_map @@class_map end def self.add_mapped_class(type, mapped_class, code) @@class_map[type] = mapped_class @@libs << code if code end ...
true
b59ccc5b1c4fd685f16ff7e128246aae97e2ec9c
Ruby
EricJ-Flatiron/programming-univbasics-2-statement-repetition-with-while-hou01-seng-ft-042020
/lib/count_down.rb
UTF-8
125
3.21875
3
[ "LicenseRef-scancode-public-domain", "LicenseRef-scancode-unknown-license-reference" ]
permissive
# Write your code here countdown = 10 while(countdown != 0) do puts countdown countdown -= 1 end puts "Happy New Year!"
true
c59c5ea9b211c472755be5020eccf8dfdf408cd2
Ruby
atl-code-immersion/ruby-winter17
/animal_sounds.rb
UTF-8
520
4.0625
4
[]
no_license
# puts "Which do you prefer? Dog or Cat?" puts "What is your favorite animal?" animal = gets.chomp.downcase # if animal == "dog" # puts "Woof!" # elsif animal == "cat" # puts "Meow!" # elsif animal == "horse" # puts "Neigh!" # elsif animal == "snake" # puts "Hiss!" # elsif animal == "lion" # puts "Roar!" # else ...
true
6e8b0bd40069467443745f5f38c5e5de42296934
Ruby
Dexter1210/Rubyidea
/moreblocks.rb
UTF-8
292
3.53125
4
[]
no_license
#Passing proc and block together def repeat(x,yproc,&b) puts x puts yproc yproc.call if block_given? b.call if block_given? end #repeat 5,10 do # puts "I am in the default block" #end repeat 5,proc {puts "I am a custom proc"} do puts "I am in the default block" end
true
cd1bbb35d7c9657b47c2994c9fc03b602250f047
Ruby
Jaybraum/venue_2103
/lib/venue.rb
UTF-8
424
2.890625
3
[]
no_license
class Venue attr_reader :name, :capacity, :patrons def initialize(name, capacity) @name = name @capacity = capacity @patrons = [] @yell_at_patrons = [] end def name @name end def capacity @capacity end def add_patron(patrons) @patrons << pa...
true
dc7cdc596c6b7a18a5342c18476efe13b95acec0
Ruby
da99/i_love_u
/src/Uni_Lang/Noun/Code_Block.rb
UTF-8
6,560
2.640625
3
[ "MIT" ]
permissive
class Uni_Lang module Core # How to create a core code block: # Describe event: 'find file' Code_Block = Noun.create('Code Block'){ |n| n.create_event('before create of self') do |e| e.target.create_property { |prop| prop.name = 'nouns' prop.value...
true
cf4c9165c775cf37f652cf282f9b645d84860a57
Ruby
nickdraper8/ruby_chess
/pieces/king.rb
UTF-8
492
3.46875
3
[]
no_license
require_relative "piece" require_relative "stepable" class King < Piece include Stepable def symbol ' ♛ '.colorize(@color) end protected def move_diffs moves = [] # all possible moves of the knight x_moves = [0, 0, 1,-1, -1, -1, 1, 1] y_moves = [1,-1,...
true
aeceb78b41d0aac7a0d523978f8c04e5d2570c23
Ruby
kupolak/codewars
/Ruby/7 KYU/Ones and Zeros.rb
UTF-8
58
3.109375
3
[]
no_license
def binary_array_to_number(arr) arr.join("").to_i(2) end
true
412b18235e3360253b5d0aa19f1c085d5e3ba042
Ruby
jtherr/forkfile
/db/migrate/.svn/text-base/20090623224233_change_user_name.rb.svn-base
UTF-8
965
2.53125
3
[]
no_license
class ChangeUserName < ActiveRecord::Migration def self.up add_column :users, :name, :string, :null => false User.find(:all).each do |user| user.name = user.first_name + " " + user.last_name user.save end remove_column :users, :first_name remove_column :users, :middle_initial...
true
1e116c22095fd297956988c940acd182d59b75a5
Ruby
esteban90-dev/odinbook
/db/seeds.rb
UTF-8
2,793
2.625
3
[]
no_license
# This file should contain all the record creation needed to seed the database with its default values. # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup). # # Examples: # # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }]) # ...
true
737681a88bb771aa818458bc4d05f997a2e9e49e
Ruby
JLass6688/RestaurantApplication
/models/food.rb
UTF-8
220
2.75
3
[]
no_license
class Food < ActiveRecord::Base has_many(:orders) has_many(:parties, through: :orders) def price self.cents / 100 end def price=(new_price) self.cents = new_price * 100 end def to_s self.name end end
true
47a88707da4868a88e7ea79fa817462f12b65572
Ruby
ikwzm/iroha-ruby
/lib/iroha/iroha/i_register.rb
UTF-8
2,055
2.859375
3
[]
no_license
module Iroha class IRegister attr_reader :_id, :_name, :_class, :_type, :_value attr_reader :_owner_design, :_owner_module, :_owner_table def initialize(id, name, klass, type, value) @_id = id ## TYPE: number _set_name(name) ...
true
57166f8bba59acbd6f446bde77ebceebd149125a
Ruby
delphi911/tictactoe
/controller.rb
UTF-8
482
3.21875
3
[]
no_license
class Controller #defines user actions def initialize(players) @p1 = players[0] @p2 = players[1] end def selectmove(cell) end def play puts "Lets start the game" end def ai puts "Not impemented yet." end def quit puts "Goodbye." end ...
true
0b0717aab5ae026813efff1b1dc6df5a109795d2
Ruby
MatmaRex/crude
/crude.rb
UTF-8
8,324
2.71875
3
[]
no_license
require 'ruby_parser' require 'pp' class CrudeCompiler def initialize @stuffs = Hash.new{|h,k| h[k] = {} } # TODO: split into many hashes end def compile sexp type, *rest = *sexp this = rest[0] if rest.length==1 if self.respond_to? :"compile_#{type}" self.send :"compile_#{type}", rest else rais...
true
7ec9cd949a3bb6b6dcb786a8e54c5606018af574
Ruby
HisashiQ/RailsEarthquakeMapper
/lib/url_api.rb
UTF-8
966
2.9375
3
[]
no_license
require 'httparty' class UrlApi time = Time.new API_URL = "https://earthquake.usgs.gov/fdsnws/event/1/query?format=geojson&starttime=#{time.year}-#{time.month}-#{(time.day)-1}&endtime=#{time.year}-#{time.month}-#{(time.day)}" def initialize response = HTTParty.get(API_URL) json = JSON.parse(response.body) @f...
true
1841fbc293423fecfe2ad0c67992dc93c1703304
Ruby
BohanHsu/leetcode2
/expression_add_operators.rb
UTF-8
877
3.296875
3
[]
no_license
# @param {String} num # @param {Integer} target # @return {String[]} def add_operators(num, target) results = [] stack = [] (0...num.length).each do |i| val_str = num[0..i] val = val_str.to_i if val.to_s == val_str stack << [i, val_str, val, val] end end while !stack.empty? do last...
true
3d036c3aedb4ffd8c2c1501bfbb3cda5488c0ccf
Ruby
ATaylor1181/Choose-your-own-adventure
/pages/page5.rb
UTF-8
2,328
3.640625
4
[]
no_license
require_relative 'list' module Page5 def self.text puts """ Hauling yourself up, you cautiously move toward the sound of the person seemingly trapped in the wreckage. Climbing up the caved-in side of an overturned subway car you peer over to see a horrific sight. Train cars and bodies are smashed toge...
true
5b6ab058c32347e6a48e03c028c18ae6b4cb42fb
Ruby
Ascalon0823/SpellCraft
/character.rb
UTF-8
822
3.359375
3
[]
no_license
require "attribute.rb" class Character @@no_of_characters = 0 @@ha_charAttr = Hash.new @@ha_characters = Hash.new def self.load @@ha_charAttr.clear @@no_of_character = 0 @@ha_characters.clear if(Attribute.no_of_attributes == 0) Attribute.load end Attrib...
true
62bc0447082179e109e5776c2b500e141520764b
Ruby
KjellMorgenstern/rbclipper
/test/test_helper.rb
UTF-8
979
2.921875
3
[ "BSL-1.0" ]
permissive
# frozen_string_literal: true require 'clipper' require 'minitest/autorun' # Note: this would be for circle ci, but we have travis #require 'minitest-ci' require 'minitest/junit' # require 'minitest/reporters' # Helper class to mange rectangles class Rectangle def initialize(pos, size) @r = [[Float(pos[0]), Fl...
true
8881031666dfd5c2e42ce78550823ab24f171eb3
Ruby
katemorris/flash_cards
/lib/game.rb
UTF-8
1,561
3.828125
4
[]
no_license
require './lib/card' require './lib/turn' require './lib/deck' require './lib/round' class Game attr_reader :deck, :round def initialize card_1 = Card.new("What is the capital of Alaska?", "Juneau", :Geography) card_2 = Card.new("The Viking spacecraft sent back to Earth photographs and reports about the s...
true
ec588593d9d589ead098b0787569e1322bb343b5
Ruby
robbkidd/advent-of-code
/2019/ruby/lib/day13.rb
UTF-8
3,165
3.1875
3
[]
no_license
class Day13 def self.go puts "Part1: #{part1}" puts "\nPart2: #{part2}" end def self.part1 game = Breakout.new(software: break_out_software) game.run game.screen.filter{|_, tile| tile == :block}.count end def self.part2 game = Breakout.new(software: break_out_software, freeplay: true...
true
7dbf213761c6affeb7bcc47fb0904f43f443150d
Ruby
boctor/ruby-hackernews
/lib/ruby-hackernews/domain/user.rb
UTF-8
221
2.859375
3
[]
no_license
class User attr_reader :name def initialize(name) @name = name end def login(password) return LoginService.new.login(@name, password) end def logout return LoginService.new.logout end end
true
7fe7ae1f7896d23331ff970c1ef01c7e103172da
Ruby
sportngin/soyuz
/lib/soyuz/command.rb
UTF-8
602
2.78125
3
[ "MIT" ]
permissive
require 'highline/import' require_relative 'command_choice' require_relative 'command_env' module Soyuz class Command def initialize(cmd) raise ArgumentError, "Command must be a string" unless cmd.is_a?(String) @cmd = cmd end def self.build(cmd) return if cmd.nil? || cmd.empty? ...
true
e16df0ab59ea6031ca9c2c5b42cffc349383b539
Ruby
anacpg/Ironhack-pair_programming
/w1d4/shopping_card.rb
UTF-8
955
3.828125
4
[]
no_license
class ShoppingCart attr_reader :cart, :prices def initialize @cart = {} @prices = {} end def add_item_to_cart fruit #cart[fruit] = 1 if !@cart[fruit] @cart[fruit] = 1 else @cart[fruit] += 1 end end def update_prices list @prices = list end def calculate_prices total = 0 @ca...
true
acfa3d597c0e53c1aaf2b48b921f21e8ec962445
Ruby
varunnagpaal/vhdl-game-engine
/script/sprite-gen.rb
UTF-8
3,317
2.9375
3
[ "LicenseRef-scancode-public-domain", "Unlicense" ]
permissive
require 'chunky_png' if ARGV.size != 1 puts "Usage: #{File.basename($0)} sprite_filename.png" exit end sprite_filename = ARGV[0] output_filename = sprite_filename.sub('.png', '_paletted.png') palette = [ 0x00000000, 0x2f2a21ff, 0x4d462cff, 0xa39960ff, 0xa8ecb6ff, 0x060d45ff, 0x0d2185ff, 0x103cffff,...
true
90971d51119f869cd716a2ac4304264fe2086069
Ruby
wasmerio/wasmer-ruby
/tests/function_test.rb
UTF-8
3,087
2.96875
3
[ "MIT" ]
permissive
require "prelude" class FunctionTest < Minitest::Test def instance bytes = IO.read File.expand_path("tests.wasm", File.dirname(__FILE__)), mode: "rb" store = Store.new module_ = Module.new store, bytes Instance.new module_, nil end def assert_value_with_type_equal(value, (expected_value, expec...
true
fcee6f92f991833bb58c2ba13359d058d74a9882
Ruby
markbrocato/simplecov-console
/lib/simplecov-console.rb
UTF-8
3,010
2.65625
3
[ "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
require 'terminal-table' require 'ansi/code' class SimpleCov::Formatter::Console VERSION = IO.read(File.expand_path("../../VERSION", __FILE__)).strip ATTRIBUTES = [:table_options, :use_colors] class << self attr_accessor(*ATTRIBUTES) end # enable colors unless NO_COLOR=1 SimpleCov::Formatter::Consol...
true
881aec15d3879c021868ab1fcf4d2cca4d7ca777
Ruby
Codinglikethecoder/operators-onl01-seng-pt-050420
/lib/operations.rb
UTF-8
60
2.640625
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
speed = 40 puts speed < 60 or speed > 60? "unsafe" : "safe"
true
2f9d9fefb5c3a97ce72e603c60000ca4c8c340d9
Ruby
digideskio/ruby-retrospective-1
/solutions/01.rb
UTF-8
365
3.109375
3
[]
no_license
class Array def to_hash {}.tap do |hash| each { |el| hash[el[0]] = el[1] } end end def index_by(&block) zip(map(&block)).to_hash.invert end def subarray_count(sub_array) each_cons(sub_array.length).count(sub_array) end def occurences_count Hash.new(0).tap do |hash| e...
true
fc4b89441c3bc16dbf433270799e7acd311e5804
Ruby
cheezy/gem_dependency_example
/gem_dep_shine/lib/gem_dep_shine.rb
UTF-8
78
2.515625
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
class GemDepShine def self.shine puts "The Gem is Shining" end end
true
ff093471a3e06b74fca5e509f34535c92023b804
Ruby
ariane-h/cinema
/models/film.rb
UTF-8
1,930
3.03125
3
[]
no_license
require_relative('../db/sql_runner.rb') class Film attr_reader :id attr_accessor :title, :price def initialize ( options ) @id = options['id'].to_i if options['id'] @title = options['title'] @price = options['price'].to_i end def save sql = "INSERT INTO films (title, price) VALU...
true
0bf70f0a8797bacea329ff5e0344185934d28e9c
Ruby
mjonx/Ironhack
/WEEK-2/Ruby_practice/change_input.rb
UTF-8
202
3.75
4
[]
no_license
print "Your name please" user_input = gets.chomp user_input.downcase! if user_input.include? "s" user_input.gsub!(/s/, "th") else print "There's no S!" end puts "Your string is #{user_input}"
true
198a6cd4708afe80a328e2820a1d503f4c30b654
Ruby
hgsongra/simple-nosql-json-db
/lib/helper.rb
UTF-8
906
3.453125
3
[]
no_license
module Helper ARG_MISSING_ERROR = "Argument(s) missing" def help puts "Usage: hql [option] [arguments]" puts " eg. hql add name=anyname age=23 location=\"JP Nagar\" --> Will add new record" puts " eg. hql -l List all records" puts "Commands:" puts " help ...
true
9732b21a75ff3a209bd5e4f8ae496dfaafbac76c
Ruby
pradeepmakkuva/Ruby-Learning
/pangram.rb
UTF-8
318
2.890625
3
[]
no_license
class Pangram def self.pangram? (phrase) phrase=phrase.downcase @flag=true if phrase and phrase.length > 0 ('a'..'z').each do |letter| if ! phrase.include? letter @flag=false break; end end else @flag=false end return @flag end end module BookKeeping VERSION=6 end
true
37cb3e882aec7a934bf2fc9b51eb656340fb77eb
Ruby
sangeetha28/DynamoDB-createdata
/dynamodb.rb
UTF-8
1,843
2.640625
3
[]
no_license
require 'faker' require 'aws-sdk' class DynanoDB def dynanoDB_client_connection Aws::DynamoDB::Client.new( region: region, credentials: Aws::Credentials.new(access_key_id, secret_key_id), ) end def create_table attribute_defs = [ {attribute_name: 'title', attribute_type: 'S'}, ...
true
b2190c29e0a86a00bf7d67a26f28223219e109eb
Ruby
dwhite96/exercism
/ruby/robot-name/robot_name.rb
UTF-8
622
3.375
3
[]
no_license
module BookKeeping VERSION = 2 end class Robot LETTERS = [*('A'..'Z')] * 2 def initialize new_name end def reset new_name end def name @name end private def new_name @name = shuffle(LETTERS)[0, 2].join + rand(999).to_s.rjust(3, "0") end def shuffle(list) n = list.lengt...
true
adcffe5cc6ea181183fb2573e6d79a3aa44327f6
Ruby
likelionkonkuk/w4_material
/task_code/task6.rake
UTF-8
406
3.21875
3
[]
no_license
# 코드 재사용을 위해서 함수로 분리 namespace :fruit do task :random => :environment do puts random_fruit end task :first => :environment do puts first_fruit end task :last => :environment do puts last_fruit end def random_fruit Fruit.all.sample.name end def first_fruit Fruit.all.first.name ...
true
54e50e735c7e6c6e4dd7370ca2a36c9f38dd683f
Ruby
jwashke/battleship
/test/board_space_test.rb
UTF-8
1,752
3.078125
3
[]
no_license
require_relative 'test_helper' require_relative '../lib/battleship/board_space' require_relative '../lib/battleship/ship' class BoardSpaceTest < Minitest::Test def setup @board_space = Battleship::BoardSpace.new @ship = Battleship::Ship.new(2) end def test_it_can_have_a_ship @board_space.place_ship(...
true
71b303a8e4960ef700c66bdf69f03e121deae71e
Ruby
tectronics/taxon-name-processing
/webservices/ruby/spec/name_spec.rb
UTF-8
715
2.6875
3
[]
no_license
require File.expand_path(File.join(File.dirname(__FILE__), '..','lib','name')) describe "Name" do describe "initialize" do before :all do @name = Name.new('M[us] musculus', 7642, 100) end it "should accept a name, start_position and score" do lambda{Name.new('name', 9, 44)}.should_not raise_e...
true
6f8fc840e7963f27df79bc176abab05c2b1d53a5
Ruby
suiyujin/mark_infoclass_autumn
/src/mark_evaluation.rb
UTF-8
8,731
2.96875
3
[]
no_license
require "#{File.expand_path(File.dirname(__FILE__))}/constants" require "#{File.expand_path(File.dirname(__FILE__))}/student" require "#{File.expand_path(File.dirname(__FILE__))}/evaluation" require 'roo' require 'rubyXL' class MarkEvaluation include Constants ### 初期化 def initialize @reports_dir = REPORTS_D...
true
a272a5abc5ce526bbae00387a9224b6f37b180cd
Ruby
wsara/pragmatic_ruby
/studio_game/studio_game.rb
UTF-8
555
3.296875
3
[]
no_license
require_relative 'player' require_relative 'game' player1 = Player.new("Abby", 100, true) player2 = Player.new("Bregory", 100, true) player3 = Player.new("Coral", 100, true) game = Game.new("Interactive Play Party Adventure") game.load_players(ARGV.shift || "players.csv") loop do puts "\nHow many game rounds? ('...
true
8ca55a48cc1f7a279d1ed7050f16ec28bfa70c36
Ruby
wecanchangeit/Ruby-Projects
/Ruby Projects/example2.rb
UTF-8
390
4.09375
4
[]
no_license
class Person attr_reader :name, :age def initialize(name, age) @name = name @age = age puts self.greet end def greet num = random_number "Hola mundo! me llamo #{num}" end private def random_number rand(1..10) end end p1 = Person.new("Simon", 25) puts p1.greet puts p1.name puts...
true
0cf6beaf756fd56211a6d3919dc92bce9358042b
Ruby
sejinkim1904/credit_check
/lib/credit_card.rb
UTF-8
842
3.59375
4
[]
no_license
class CreditCard attr_reader :card_number, :limit def initialize(card_number, limit = 0) @card_number = card_number @limit = limit end def last_four @card_number[-4..-1] end def is_valid? number = @card_number[0..-2] check_digit = @card_number[-1] sum_digit = sum_digits(number.rev...
true
6a2f39ecf058a452d4912e9751434f150f8aa585
Ruby
drusellers/nu
/lib/nu/has_out_and_log.rb
UTF-8
169
2.921875
3
[ "Apache-2.0" ]
permissive
class HasOutAndLog def initialize(out, log) @out = out @log = log end protected def out(msg) @out.call(msg) end def log(msg) @log.call(msg) end end
true