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
592ed44063a6f91a7e35ab38057b78d875781409
Ruby
ytrrty/Ruby
/14_array_extensions/array_extensions.rb
UTF-8
197
3.515625
4
[]
no_license
class Array def sum s = 0 self.each {|a| s += a } return s end def square self.map {|a| a ** 2 } end def square! self.each_index {|index| self[index]**=2 } end end
true
7c4e8c8e2a92cc54cee956d951e1c43689bb90c5
Ruby
ravenwijaya/Final_Project_Social_Media_API
/models/tag.rb
UTF-8
1,893
2.96875
3
[]
no_license
require './db/db_connector' class Tag attr_reader :id, :name def initialize(params) @id = params["id"] @name = params["name"]? params["name"].downcase : nil end def save return false unless valid? client = create_db_client client.query("insert into tags(name) values ('#{name}')") r...
true
785bb3f979d81ba813db6b1843e8194f0d8b40c0
Ruby
SaraMSchwarz/knit-purl-cli-gem
/lib/knit_purl/patterns.rb
UTF-8
412
3.421875
3
[ "MIT" ]
permissive
class Pattern attr_accessor :name, :price, :category @@all = [] def initialize(category, attrb) attrb.each do |attrb_name, attrb_value| self.send("#{attrb_name}=", attrb_value) end @category = category @@all << self end def self.all @@all end def self.print_all all.each_w...
true
29cfaf9d3078c81b33091af1210c3ab08300c203
Ruby
aleksposte/railway
/app/models/train.rb
UTF-8
2,203
3.03125
3
[]
no_license
class Train < ActiveRecord::Base # Принадлежит route belongs_to :route # Принадлежит railway_station # belongs_to :railway_station # Принадлежит railway_station, переделано в current_station + указание RailwayStation belongs_to :current_station, class_name: 'RailwayStation', foreign_key: :current_stati...
true
72e7b5af4a49101ca603ff4808f5ded25d027413
Ruby
thisdata/example-rails-app
/app/misc/user.rb
UTF-8
532
2.828125
3
[]
no_license
# This is a plain old ruby object, which behaves like a regular User model # might. class User attr_accessor :id, :name, :email, :mobile, :balance def initialize(**args) args.each { |key, value| send "#{key}=", value } set_default_id_from_email end def display_name name || email end def as_j...
true
0f16f585e34a30e79ae14f0bb66181d76172d3af
Ruby
nepalez/query_builder
/lib/query_builder/cql/operators/cql_tuple_value.rb
UTF-8
448
2.828125
3
[ "MIT" ]
permissive
# encoding: utf-8 require_relative "cql_literal" module QueryBuilder::CQL::Operators # Returns value of CQL tuple # # @example # fn = Operators[:cql_tuple_value] # # fn[:tiger, 1] # # => "('tiger', 1)" # # @param [Array<#to_s>] values # # @return [String] # def self.cql_tuple_value(*v...
true
8b343f545b6472d6ec7c730f900524e1fb8951f7
Ruby
juangb/leetcode
/datastructures/trees/rigth_pointer.rb
UTF-8
2,358
4.125
4
[]
no_license
=begin Populating Next Right Pointers in Each Node You are given a perfect binary tree where all leaves are on the same level, and every parent has two children. The binary tree has the following definition: struct Node { int val; Node *left; Node *right; Node *next; } Populate each next pointer to point to ...
true
bca86addedbb333688f0358d842f121957c2d10f
Ruby
vincent585/linked_list
/linked_list.rb
UTF-8
2,337
3.78125
4
[]
no_license
require_relative 'node' class LinkedList attr_accessor :name, :head, :tail, :size def initialize @head = nil @tail = nil @size = 0 end def append(value) new_node = Node.new(value) @head.nil? ? @head = new_node : @tail.next_node = new_node @tail = new_node @size += 1 end def pr...
true
f6a54bc8b125af5373f60d4e168848fa6a70223d
Ruby
geidies/puresence
/models/status.rb
UTF-8
1,070
2.953125
3
[]
no_license
require 'redis_implementation' require 'singleton' class Status include Singleton def initialize @@redis = Redis::Implementation.connect( :url => ENV["REDISTOGO_URL"] ) if @@redis.get("status") == nil @@redis.set "status", false end end def get status = @@redis.get("status") if sta...
true
b52f9f3a5cde14c1692042a47aad1ede82a60e56
Ruby
olichka12/RubyTestProjects
/Antipatterns/public_morozov.rb
UTF-8
234
3.015625
3
[]
no_license
FINANCIAL = 100 class Parent protected attr_accessor :financial def financial_parent @financial = FINANCIAL end end class Child < Parent def output financial_parent end end child = Child.new puts child.output
true
10a06f1c5b0f70c5ef41102f03e9e417814f8b86
Ruby
Sinetheta/poker_tracker
/lib/tasks/migrate_guest.rake
UTF-8
1,047
2.515625
3
[]
no_license
namespace :account do desc "Migrate an exisiting guest to an existing user with the same name" task migrate_guests: :environment do Guest.all.each do |guest| user = User.find_by_name(guest.name) if user.nil? user = User.create(name: guest.name, email: "#{guest.name.gsub(/ /, '_').downcase}@s...
true
3ecd5f8e2f49ed00234680d89121b43ae6697125
Ruby
nkpart/prohax
/lib/prohax/box.rb
UTF-8
71
2.5625
3
[ "MIT" ]
permissive
class Object def box self.is_a?(Array) ? self : [self] end end
true
0b8237e2f15dc40b309ed19c2b25d1f8fbeebc94
Ruby
yonipacheko/my_flex_prototype
/app/models/user.rb
UTF-8
1,375
2.5625
3
[]
no_license
class User < ActiveRecord::Base include Tokenable # this a concern taking care of generation of tokens validates :email, :password, :full_name, presence: true validates_uniqueness_of :email has_secure_password validations: false has_many :queue_items, ->{order(:position)} has_many :reviews, -> {order(...
true
8300630d7b35c3b6a47175a0a9143f16dbfea8fd
Ruby
sussurro/Metasploit-Tools
/scripts/meterpreter/screenshot.rb
UTF-8
3,480
2.703125
3
[]
no_license
# Thie script will create an animated gif of activity on a remote machine # You are required to be migrated to a process which has access to the desktop # Provided by Ryan Linn <sussurro@happypacket.net> require 'fileutils' begin require 'RMagick' rescue ::LoadError print_status("RMagick library not found, it must ...
true
b65ef97412ac5fac27629aef19bec211bb9d853c
Ruby
lemonmade/docks-gem
/spec/lib/processors/join_with_blanks_spec.rb
UTF-8
692
2.75
3
[ "MIT" ]
permissive
require 'spec_helper' describe Docks::Processors::JoinWithBlanks do subject { Docks::Processors::JoinWithBlanks } it 'correctly joins an array with blanks' do array = %w(one two three) expect(subject.process(array)).to eq array.join('') end it 'correctly returns a non-array argument' do non_array...
true
7925abe19d08bac10f7254411be3b2c4715f59b7
Ruby
johneckert/ruby-collaborating-objects-lab-web-121117
/lib/artist.rb
UTF-8
585
3.234375
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
require_relative 'song' require_relative 'mp3_importer' class Artist attr_accessor :name attr_reader :songs @@all = [] def initialize(name) @name = name @songs = [] self.save end def add_song(song) @songs << song end def save @@all << self end def self.all @@all end ...
true
0c3e9d8fd2ea8c9afdd3a8614d8c15841608515c
Ruby
peterjacobson/reddit-jr
/app/story.rb
UTF-8
394
2.890625
3
[]
no_license
require_relative 'db' class Story def self.add(args) q = <<-SQL INSERT INTO stories(title, user_id, score, contents) VALUES (?, ?, ?, ?); SQL $db.execute(q, [args[:title], args[:user_id], args[:score], args[:contents]]) end def self.delete(title) q = <<-SQL DELE...
true
348055ece2cc503b914dc0625f864d90db4e4cab
Ruby
luxiar/local_alignment
/lib/text_alignment/glcs_required.rb
UTF-8
2,786
2.921875
3
[]
no_license
#!/usr/bin/env ruby module TextAlignment; end unless defined? TextAlignment class << TextAlignment def glcs_required?(str1, mappings = []) raise ArgumentError, "nil string" if str1.nil? raise ArgumentError, "nil mappings" if mappings.nil? # character mappings can be safely applied to the strings withoug...
true
4fc7b734b84961bec877a500ba6e85a536deac5e
Ruby
paulodiniz/adventofcode-2019
/day-1/pt1.rb
UTF-8
188
3.21875
3
[]
no_license
class FuelCalculator def self.calculate(mod) (mod / 3.0).floor - 2 end end require 'csv' puts CSV.read('data.txt').flatten.map(&:to_f).map { |m| FuelCalculator.calculate(m) }.sum
true
410d2585c8fb8b2e58b6b3b8e75494206c4f8401
Ruby
Bandice/intro_to_programming
/7_hashes/map_flatten.rb
UTF-8
335
3.90625
4
[]
no_license
#make new array that has strings containing one word # i.e. ['white snow', etc..] -> ['white', 'snow', etc] # use arrays map and flatten methods # use strings split method a = ['white snow', 'winter wonderland', 'melting ice', 'slippery sidewalk', 'salted roads', 'white trees'] a = a.map { |pairs| pairs.split } a ...
true
82d33c9cde55ffad89fa55db6fe5216d53c9e0fc
Ruby
abhiram25/LS_120_exercises
/lesson_1_exercises/chapter1.rb
UTF-8
537
4.3125
4
[]
no_license
# How do we create an object in Ruby? Give an example of the creation of an object. # What is a module? What is its purpose? How do we use them with our classes? # Create a module for the class you created in exercise 1 and include it properly. # A module is a set of behaviors used in other classes- via mixins # We ...
true
9216320b72cb6e5b224fca1642e241e98c7d2988
Ruby
DidsyTurbo/learn_ruby
/02_calculator/calculator.rb
UTF-8
357
3.609375
4
[]
no_license
def add (n1, n2) n1 + n2 end def subtract (n1, n2) n1 - n2 end def sum (array) sum = 0 array.each do |i| sum += i end return sum end def multiply(array) result = 1 array.each do |i| result *= i end return result end def power(b, p) b ** p end def factorial(num) result = 1 num.times do |i| resul...
true
87b94ef248ca00567d352d48d470479ef64bab0c
Ruby
manibi/plattform
/db/seed_helpers.rb
UTF-8
2,517
2.796875
3
[]
no_license
require "securerandom" def generate_student_licences(company, profession, licences_num) (0...licences_num).to_a.map do |i| { username: "#{company.name.downcase}-#{profession.downcase}-#{SecureRandom.hex[0..6]}", password: SecureRandom.hex[0..10], company_id: company.id, first_na...
true
244ee84b027c9c87d7f3a7d7c04bba562d1a5f22
Ruby
homelinen/ld25-a-game-of-pirate
/a-game-of-pirates
UTF-8
4,545
2.9375
3
[ "MIT" ]
permissive
#!/usr/bin/env ruby require "chingu" Dir["#{File.dirname(__FILE__)}/lib/*.rb"].each {|f| require f} include Gosu include Chingu class Game < Chingu::Window def initialize super(800, 600, false) end def setup retrofy self.factor = 1 switch_game_state(Pirates.new) end end class Pira...
true
7ea22d92d1da7738d9af0c5bd8dbeac66bf6ddeb
Ruby
sorah/infra_operator
/lib/infra_operator/platforms/base.rb
UTF-8
2,784
2.53125
3
[ "MIT" ]
permissive
module InfraOperator module Platforms class Base class BackendRequiredToDetermine < StandardError; end class NotYetDetermined < StandardError; end def initialize(options={}) @options = options @services = {} @service_classes = self.class.services.dup override_se...
true
208fc47e842c8269336430be8945f6cdbbd34245
Ruby
rhythm29/Bootcamp-Geometry
/lib/geometry/rect.rb
UTF-8
412
2.96875
3
[ "MIT" ]
permissive
class Geometry::Rectangle def self.create_square(side) self.new(side, side) end def initialize(length, width) @length = length @width = width end def perimeter if(@length >= 0 && @width >= 0) 2 * (@length + @width) else Float::INFINITY end end def area if(@length >...
true
8f7522175f71e6a0fdb90568ff04b779ca3ee7ef
Ruby
stupied4ever/ruby-tapas-downloader
/lib/ruby_tapas_downloader/downloadables/catalog.rb
UTF-8
1,055
3
3
[ "WTFPL" ]
permissive
module RubyTapasDownloader # Catalog is the set of all Ruby Tapas Episodes. class Downloadables::Catalog < Downloadable # @return [Set<RubyTapasDownloader::Downloadables::Episode>] the Episodes. attr_reader :episodes def initialize(episodes) @episodes = episodes end # Download the Catalo...
true
861435c94ba47daa42705835aba3951465aa849a
Ruby
cincospenguinos/AdventOfCode2020
/lib/AdventOfCode2020/day_six/group.rb
UTF-8
418
3.421875
3
[ "MIT" ]
permissive
class Group attr_reader :string, :individuals def initialize(string) @string = string.gsub(/\s+/, '') @individuals = string.split(/\s+/) end def unique string.split('').to_set.count end def every letters = individuals[0].split('') individuals[1...(individuals.size)].each do |individual| letters =...
true
5358ae2796c16c16fb2a60eb347c46a9fb16505f
Ruby
Azdaroth/active_model_attributes
/spec/active_model_attributes_spec.rb
UTF-8
8,529
2.640625
3
[ "MIT" ]
permissive
require "spec_helper" require "active_model" describe ActiveModelAttributes do class ModelForAttributesTest include ActiveModel::Model include ActiveModelAttributes attribute :integer_field, :integer attribute :string_field, :string attribute :decimal_field, :decimal attribute :string_with_d...
true
4862805660da6626521835843deea046c8ecea10
Ruby
gabrielnvian/Jupiter
/server/agents/hashcracker.rb
UTF-8
1,758
2.734375
3
[ "MIT" ]
permissive
class Fulfillment def hashcracker(req, userinfo) hashtoc = req[:Cont][:Hash].to_s.downcase hashtype = req[:Cont][:Hashtype] ? req[:Cont][:Hashtype].downcase : 'md5' chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' indexes = [0] if File.exist?("agents/files/hashcracker/#{ha...
true
2c6a6e0baa479c9c64b7892cae0fb3d0f497843d
Ruby
xlunchxbox/TEAM5OAGS
/app/models/user.rb
UTF-8
2,635
2.515625
3
[]
no_license
# == Schema Information # # Table name: users # # id :integer not null, primary key # first_name :string(255) # last_name :string(255) # street :string(255) # city :string(255) # zip :integer # state :string(255) # area_code :integ...
true
3aa1fd36f5491f7c9cf517bb72e361ed472f707c
Ruby
whois-api-llc/whois
/password/ruby/whois_api.rb
UTF-8
1,677
2.84375
3
[]
no_license
require 'erb' require 'json' require 'net/https' require 'rexml/document' require 'rexml/xpath' require 'uri' require 'yaml' url = 'https://www.whoisxmlapi.com/whoisserver/WhoisService' ######################## # Fill in your details # ######################## username = 'Your whois api username' password = 'Your who...
true
f9a80a2dd7f4ddf1ad9050eff9c73dbe985c0c5c
Ruby
wli6/app3_on_linux
/app/models/card.rb
UTF-8
3,497
2.703125
3
[]
no_license
class Card < ActiveRecord::Base belongs_to :user attr_accessible :day_phone, :email, :paid, :stripe_card_token attr_accessible :cardholder_name, :billing_address, :city, :postal_code, :state attr_accessible :discount_code attr_accessor :bliggino attr_reader :email validates_presence_of :cardholder_name, ...
true
df10d2785d9e6e4a71965a0b9024454deb7cca59
Ruby
gengogo5/atcoder
/ABC/abc120/abc120_A.rb
UTF-8
70
2.90625
3
[]
no_license
A,B,C = gets.split.map(&:to_i) d = B/A if d > C d = C end puts d
true
093cac32a0209bbe9b359452917ed199d87c2e17
Ruby
Thomascountz/learn_ruby
/06_timer/timer.rb
UTF-8
822
3.375
3
[]
no_license
class Timer def seconds @seconds = 0 end def seconds= seconds @seconds = seconds end def time_string while @seconds.to_i > 60 @minutes = @minutes.to_i + 1 @seconds = @seconds - 60 end while @minutes.to_i > 60 @hours = @hours.to_i + 1 ...
true
179a8e7481aef71953f5a72a789a14484410b0a9
Ruby
kristenmills/magician
/spec/math_spec.rb
UTF-8
2,622
3.421875
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') describe Math do it 'should solve quadratic formulas' do Math.quadratic(1, 2, 1).should == [-1.0, -1.0] Math.quadratic(1, 1, 0).should == [-1.0, 0.0] Math.quadratic(1, 0, 0).should == [0.0, 0.0] Math.quadratic(0, 1, 2).should == nil #Math.qu...
true
e0b9cdf739f2a6269e7e30247ee479bfa563051e
Ruby
loganhasson/jukebox
/jukebox.2.0.rb
UTF-8
2,416
3.515625
4
[]
no_license
songs = [ "Phoenix - 1901", "Tokyo Police Club - Wait Up", "Sufjan Stevens - Too Much", "The Naked and the Famous - Young Blood", "(Far From) Home - Tiga", "The Cults - Abducted", "Phoenix - Consolation Prizes" ] def rock_out(song_to_play, song_list) normalized = [] song_list.each do |song| strip...
true
be62b5c70e19e191b2c392beba936e09d0325e17
Ruby
littletonito/got
/lib/got/api.rb
UTF-8
475
2.75
3
[ "MIT" ]
permissive
require 'pry' class Api BASE_URL = "https://www.anapioficeandfire.com/api/characters" def self.get_got res = RestClient.get(BASE_URL) data = JSON.parse(res.body) data['results'].each do |got| name = got["name"] id = got["url"].split("/")[-1] Got.new(name, id) end end def...
true
7780abeee7853517fcaac32efd085b4bfa500426
Ruby
Stajor/telegram-ruby
/lib/telegram/bot/types/venue.rb
UTF-8
366
2.5625
3
[ "MIT" ]
permissive
module Telegram::Bot::Types class Venue attr_accessor :location, :title, :address, :foursquare_id def initialize(attributes) attributes.each { |k, v| self.send("#{k}=", v) if self.respond_to? k } end def location=(attributes) @locatio...
true
ce1f26572bdf4c483af75388f7b9a0354065dbc9
Ruby
eirvandelden/dm-adventure-book
/lib/assets/importer.rb
UTF-8
2,472
2.84375
3
[]
no_license
# frozen_string_literal: true class Importer def self.import! Spell.transaction do i = Importer.new CharacterClass.delete_all Spell.delete_all # i.classes.each { |name| CharacterClass.create(name: name) } i.spells.each(&:import!) end end class SpellData attr_reader :n...
true
4d642c0a0b3a02b1d50fefeca6c4d4a90c58d60a
Ruby
Serge716/Ruby-Intro-Codes
/exercises.rb
UTF-8
1,983
3.75
4
[]
no_license
nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] # nums.each do |num| # puts num # end # nums.each do |num| # if num > 5 # puts num # end # end # new_nums = nums.select do |number| # number % 2 != 0 # end # puts new_nums # nums << 11 # puts nums # nums.unshift(0) # puts nums # nums.pop # puts nums # nums << 3...
true
85a781df6032618ce68db70af9f464e90cb8521e
Ruby
olegokunevych/codewars
/sum_by_factor.rb
UTF-8
1,112
3.34375
3
[]
no_license
require 'prime' def sumOfDivided(lst) combinations = lst.repeated_combination(lst.length).map(&:uniq).map{ |el| el.inject(:+) }.sort puts "Combs: #{combinations.uniq.inspect}" puts "Lst: #{lst}" prime_numbers = lst.map do |el| Prime.prime_division(el).map(&:first) end.inject(:+).uniq.sort puts "Prime ...
true
248ed148cd78b0b6f4ed58973f515e6695e35aa4
Ruby
mattweldon/yoround
/infra/repositories/in_memory/base_repository.rb
UTF-8
2,023
3.203125
3
[]
no_license
module Repositories module InMemory class BaseRepository def initialize @id_counter = 0 @records = [] end def unique?(object, attr_name) @records.values.none? do |member| object.id != member.id && member.public_send(attr_name) == objec...
true
d6f67432ff58f631176b965655233aef20093041
Ruby
HPulahi/coding-tests
/hp_submission/lib/main.rb
UTF-8
4,941
3.375
3
[]
no_license
require "rubygems" require 'json/pure' require 'traveller' require 'support/string_extend' class Main class Config @@actions = ['list', 'find', 'search', 'quit'] def self.actions @@actions end end def initialize @travellers = Traveller.process end def execute introduction res...
true
d289e453398b7e466bd194d56bb00cfb55dc8c51
Ruby
blnkt/surveys
/lib/answer.rb
UTF-8
361
2.515625
3
[]
no_license
class Answer < ActiveRecord::Base belongs_to :history belongs_to :question def total History.where(answer_id: self.id).count end def percentage grand_num = self.grand_total total_num = self.total ((total_num.to_f / grand_num.to_f) * 100).to_i end def grand_total History.where(questi...
true
990abe68eb7546ef99b8542983bc4a1e1b83a972
Ruby
pablitosanchez/wgit
/lib/wgit/url.rb
UTF-8
15,952
3.078125
3
[ "MIT" ]
permissive
# frozen_string_literal: true require_relative 'utils' require_relative 'assertable' require 'uri' require 'addressable/uri' module Wgit # Class modeling a web based URL. # Can be an internal/relative link e.g. "about.html" or a full URL # e.g. "http://www.google.co.uk". Is a subclass of String and uses # 'ur...
true
6c24270b07a8644020ade28c20dbc02f2884fed7
Ruby
phaedryx/elevate
/lib/passenger_generator.rb
UTF-8
952
3.53125
4
[]
no_license
require_relative 'passenger' # generates a passenger at a rate of frequency (decimal between 0-1), # starting on the given floor and going to a different floor (assume a # passenger doesn't want to go to the same floor.) class PassengerGenerator attr_reader :frequency, :origin_floor, :number_of_floors def initia...
true
ca1f988ca06d89b7655815c772011efdb4b02fee
Ruby
danspencer/advent_of_code
/2015/day03/part2.rb
UTF-8
1,833
3.765625
4
[ "MIT" ]
permissive
# The next year, to speed up the process, Santa creates a robot version of himself, Robo-Santa, to deliver presents with him. # # Santa and Robo-Santa start at the same location (delivering two presents to the same starting house), then take turns moving based on instructions from the elf, who is eggnoggedly reading fr...
true
a06888548733fe7feeb72f2bc6f41d0ea7b6b114
Ruby
xiurongy3506/01-default-optional-values-lab
/default_optional.rb
UTF-8
224
3.0625
3
[]
no_license
def student_school (name, school = "HSTAT") return "#{name.capitalize} is a student at #{school}." end def student_interests (student, *interests) return "#{student.capitalize} is interested in #{interests}." end
true
771576ff0092d407d85fd7f3385abfdebe157b7c
Ruby
drahosj/midi-project
/midi-project.rb
UTF-8
2,660
3.125
3
[]
no_license
require 'bundler' require 'serialport' require 'unimidi' class MidiAdaptor def initialize @output = UniMIDI::Output.gets end def shutdown 24.times do |n| shepard_off n end @output.close end def note_on note, velocity @output.puts(0x90, note, velocity) end def note_off note, vel...
true
97efdc11e1567cd8d946d4fc2c6e539f9c137330
Ruby
thilo/faker
/lib/faker.rb
UTF-8
562
2.828125
3
[ "MIT" ]
permissive
$:.unshift File.dirname(__FILE__) require 'faker/address' require 'faker/company' require 'faker/internet' require 'faker/lorem' require 'faker/name' require 'faker/phone_number' require 'faker/isbn' require 'faker/version' require 'extensions/array' require 'extensions/object' module Faker def self.numerify(numbe...
true
240fd1e3623225b5f8bb1c5688b851700839e990
Ruby
danielribeiro/RubyCraft
/lib/rubycraft/byte_converter.rb
UTF-8
835
3.1875
3
[ "MIT" ]
permissive
require 'stringio' module RubyCraft # Utils for manipulating bytes back and forth as strings, strings and numbers module ByteConverter def toByteString(array) array.pack('C*') end def intBytes(i) [i >> 24, (i >> 16) & 0xFF, (i >> 8) & 0xFF, i & 0xFF] end def stringToByteArray(str)...
true
76e5c1dcbc5acd4a6528a5dcf6afd000ff8e62d3
Ruby
TerryQu3k/Todo
/todo.rb
UTF-8
1,451
3.5625
4
[]
no_license
require 'csv' require 'byebug' class Todolist attr_accessor :list, :task def initialize(file) @list = [] CSV.foreach(file) do |row| unless row[0] == "id" @list << Task.new(row) end end end def list_task # list1 = CSV.read('todoli...
true
b48c6891c88afa79ed31d938309af468ae7bbb54
Ruby
machamp0714/chery_book
/atcoder/train4.rb
UTF-8
882
3.046875
3
[]
no_license
# frozen_string_literal: true # イルミネーションの調査 class Input def self.base gets.chomp.split.map(&:to_i) end end tree_count, safty_zone = Input.base lights = Input.base split_count = gets.chomp.to_i split_array = [] split_count.times { split_array << Input.base } s = split_array.each_with_object(lights) do |split,...
true
253eb2307280653df57894da4ee47a347216f895
Ruby
smlparry/Payd
/app/models/string_helpers.rb
UTF-8
175
2.6875
3
[]
no_license
module Helpers # A little class to help with handling strings class StringHelpers def self.random_string(length = 8) rand(36**length).to_s(36) end end end
true
9dff9b03fd06816504c3361d91d82862851875fd
Ruby
devopnik/cligen
/lib/commands/example/first/tasks/tasks.rb
UTF-8
599
2.75
3
[]
no_license
module Example module First def self.role_description "Description of Example First Role" end def self.included(base) base.class_eval do desc "case", "task command of role in a namespace that uses case" def case case_example = ask 'What is your grade: ' Case...
true
8b51045ecb505dacf9b9bdd2f5a462e84d8e21d1
Ruby
miraissan/dxruby_blocks
/block_prime/pri_05.rb
UTF-8
354
2.671875
3
[ "Unlicense" ]
permissive
# 基本機能だけでブロック崩し:壁を描く require 'dxruby' $screen = Image.new(640, 480) Window.loop do x0 = 0 y0 = 0 width = 0 while width < 20 height = 0 while height < 480 $screen[x0 + width, y0 + height] = C_WHITE height = height + 1 end width = width + 1 end Window.draw(0, 0, $screen) end
true
a717799cd71cace53a6026011c7858e0ad158e7e
Ruby
ajseemar/The-Nature-of-Code-Examples-in-Ruby
/chp02_forces/NOC_2_7_attraction_many/attractor.rb
UTF-8
2,675
3.34375
3
[]
no_license
# NOC_2_7_attraction_many # The Nature of Code # http://natureofcode.com # A class for a draggable attractive body in our world class Attractor include Processing::Proxy G = 1 def initialize(width, height) @location = Vec2D.new(width / 2, height / 2) @mass = 20 @drag_offset = Vec2D.new @dragging ...
true
7a289aa8526a75760964bbce5047e231fbe31e1b
Ruby
gturner-archive/learn_ruby
/04_pig_latin/pig_latin.rb
UTF-8
462
3.578125
4
[]
no_license
def translate(str) str = str.downcase.split(' ') str = str.map do |word| if word[0] == 'a' || word[0] == 'e' word << "ay" elsif word[0..2] == 'thr' || word[0..2] == 'sch' || word[0..2] == 'squ' x = word.slice! 0..2 word << x + 'ay' elsif word[0..1] == 'ch' || word[0..1] == 'qu' || word[0..1] == 'th' ||...
true
968e0d7aa7085e72abecb4979968f691288ab813
Ruby
rcjara/project-euler
/59-Problem/ruby/solve.rb
UTF-8
517
2.84375
3
[]
no_license
text = File.read(File.dirname( File.expand_path( __FILE__) ) + "/../downloaded/cipher1.txt") codes = text.split(",").collect(&:to_i) (97..122).each do |a| (97..122).each do |b| (97..122).each do |c| new_text = "" sum = 0 key = [a, b, c] codes.each_with_index do |code, i| conv_cod...
true
8210f88d91c64a51e80343aed14bf5ec157254b5
Ruby
tmertens/intermittent_test_failures
/spec/examples/data_pollution_spec.rb
UTF-8
969
2.609375
3
[ "MIT" ]
permissive
RSpec.describe "failures due to data pollution" do let(:fake_cache) do Class.new do def self.cache @cache ||= [] end def self.where(*_args) cache end def self.insert(something) cache << something end end end it "passes when the cache is empty"...
true
7f617153d1c9a74c3313022eefe1f4969b618805
Ruby
bobolinks-2014/Amozin
/app/models/cart.rb
UTF-8
1,028
2.84375
3
[]
no_license
class Cart < ActiveRecord::Base belongs_to :user has_many :item_to_buys, dependent: :destroy def add_product(product_id) current_item = item_to_buys.find_by(product_id: product_id) if current_item current_item.quantity += 1 current_item.save else current_item = item_to_buy...
true
af8cfc53c8c762481a5bebc11c16266c7ed36b59
Ruby
alexisspa9/name-cli-app
/lib/parospages/cli.rb
UTF-8
743
3.34375
3
[ "MIT" ]
permissive
class Parospages::CLI def call puts "Recommended accommodation in Paros Island " list menu goodbye end def list @accommodations = Parospages::Accommodation.show @accommodations.each.with_index(1) do |acco, i| puts "#{i}. #{acco.name} - #{acco.type}" end end def menu input = nil while input !...
true
be258b61cdf0962628375370e55ef965245f184c
Ruby
ulyssesb/HackerRank-Ruby
/algorithms/1_warmup/angry_children.rb
UTF-8
1,137
3.890625
4
[]
no_license
#!/usr/bin/ruby ### # SOLUTION ### # First we have to order the array of packets and then loop through it comparing # the n[i] element with n[i+k] element, from i=0 until i=n-k. # For each interaction n[i] holds min(xi...xk) and n[i+k] holds max(xi...xk). # When i=0 we set MIN_UNFAIRNESS = n[k]-n[0], and for i >= 1 we...
true
fb65c3bc4b3b9a0491a102203ced8b54db30d00b
Ruby
gasgit/Ruby
/map.rb
UTF-8
196
3.203125
3
[]
no_license
#!/usr/bin/ruby # add key values myMap = hours = { "1" => "one", "2" => "two", "3" => "three"} # for each extarct k, v myMap.each do |key,value| print key, " is key ", value, " is value \n" end
true
87b6aacc97e9625769a0c757d9ffc5ad504d1812
Ruby
TaylorMills2/ruby-objects-has-many-through-readme-online-web-sp-000
/lib/waiter.rb
UTF-8
303
2.8125
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
class Waiter attr_accessor :name, :yrs_experience @@all = [ ] def initialize (name, yrs_experience) @name = name @yrs_experience = yrs_experience @@all << self end def self.all @@all end def new_meal(customer, total, tip=0) Meal.new(self, customer, total, tip) end end
true
535388afa8b03bf28410a336eddff4d2c92af516
Ruby
konstankinollc/music-loader
/utils.rb
UTF-8
907
2.578125
3
[]
no_license
class ObjectFacade def self.get(key, facades) facades.detect do |facade| facade.respond_to?(:selector) && facade.selector.intern == key.intern end end end class Collector attr_accessor :storage, :facades, :processor def initialize(processor, facades) self.processor = processor self.fa...
true
f1a7ca7140e3a6ac3ed6cc596e151ff63a786275
Ruby
andydna/stripext
/spec/strip_spec.rb
UTF-8
1,533
2.84375
3
[]
no_license
require_relative '../strip_ext.rb' RSpec.describe Strip do context 'Unit' do context 'class methods' do it 'strips filename extensions' do expect(Strip.extension("hello.rb")).to eq "hello" expect(Strip.extension("hello.c")).to eq "hello" end it "can tell if input is filename wi...
true
5b80f1abfb249ad36b60c2e36f718b1f2989f609
Ruby
BomDia12/Processo_trainee
/2020-01/Lista_semana_1/11.rb
UTF-8
77
2.53125
3
[]
no_license
lista = ['Jorge', 'Arthur', 'Astrid', 'Hedvig', 'Sigrid'] puts lista.sample
true
a1572dfb8b20b691959b4c5b0b650f2edbba6cf3
Ruby
arirusso/midi-fx
/lib/midi-fx/limit.rb
UTF-8
636
2.984375
3
[ "Apache-2.0" ]
permissive
module MIDIFX class Limit attr_reader :limit_to, :name, :property alias_method :range, :limit_to def initialize(property, limit_to, options = {}) @limit_to = limit_to @property = property @name = options[:name] end def process(message) val = message.send(@property) ...
true
1e297e1fb7e9ad4e66120183aa68e26876bc37ee
Ruby
lukinski/job_sequence
/app/models/job.rb
UTF-8
350
2.625
3
[]
no_license
class Job include ActiveModel::Model validates_presence_of :name validate :check_dependency attr_accessor :name, :dependency def initialize(name, dependency = nil) @name, @dependency = name, dependency end private def check_dependency errors.add(:dependency, "can’t be the same as Job") if d...
true
02a9fa71fec04194efb2d88edbad95a707389f9a
Ruby
I-Valchev/puts_team_name_2014
/oop_ftw_mess/HomeworkChecker.rb
UTF-8
6,573
2.875
3
[ "Unlicense" ]
permissive
require 'yaml' require 'csv' require_relative 'presentations' class HomeworkChecker attr_reader :data, :HOMEWORK_NUMBERS_FLOG_FLAY, :HOMEWORK_NAMES def initialize repo_folder, how_many_to_check @repo_folder = repo_folder @how_many_to_check = how_many_to_check homeworks_configuration = YAML.load_file('config...
true
54cfa57db024bf217dd11e7f68d7c3a574bf6b94
Ruby
Rodion13/ProjectEuler
/done/11_largest_product_in_a _grid.rb
UTF-8
1,506
4
4
[]
no_license
# Largest product in a grid # Problem 11 # In the 20×20 grid in the file grid_20by_20.txt, four numbers along a diagonal line have been marked in red. # The product of these numbers is 26 × 63 × 78 × 14 = 1788696. # What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or d...
true
ce0336971f383e9862566491b9e7a117dbd7b934
Ruby
meilke/bewildr
/lib/bewildr/control_type_additions/combo_box_additions.rb
UTF-8
2,321
3.015625
3
[ "BSD-2-Clause" ]
permissive
#Copyright (c) 2010, Nathaniel Ritmeyer. All rights reserved. module Bewildr module ControlTypeAdditions #:nodoc: module ComboBoxAdditions #Returns a string array containing the element's item names def items list_items.collect {|item| item.name} end #Returns an array c...
true
5f5e1678218b9a9e3854612d47766a79fef1780b
Ruby
kindkid/euler
/027.rb
UTF-8
512
3.359375
3
[]
no_license
PRIMES = {} begin n = 1_000_000 marked = [false] * n (2..n).each do |i| next if marked[i] PRIMES[i] = true (i..n).step(i) do |j| marked[j] = true end end end max_primes = 0 max_result = 0 (-999 .. 999).each do |a| (-999 .. 999).each do |b| n = 0 loop do v = n*n + a*n + b ...
true
422624ecff5a9b5fae813eb10d8300e1a153ce0e
Ruby
Volland/xmindoc
/lib/xmindoc.rb
UTF-8
4,076
2.6875
3
[ "MIT" ]
permissive
# -*- coding: utf-8 -*- require "xmindoc/version" require "optparse" require 'pp' # my libraries require "xmindoc/exporter" require "xmindoc/parser" module Xmindoc DEBUG = false class Core attr_reader :result def initialize(option) @option = option @parser = Parser.new(option[:file_input])...
true
cafaf4312ab53e12b2d81f6bf722dac652e29858
Ruby
SpencerB3/launch_school
/RB101_programming_foundations/lesson_3/easy_1/question_5.rb
UTF-8
135
3.3125
3
[]
no_license
# Programmatically determine if 42 lies between 10 and 100. (11..100).include?(42) # => also may use range.cover?(obj) method # true
true
6c91700662b7eed60380343efebd0bac5afeb6c4
Ruby
sdjukic/gitmate
/lib/gitmate/zen.rb
UTF-8
232
2.8125
3
[ "MIT" ]
permissive
require 'net/http' require 'uri' class Zen def initialize @zen_uri = URI.parse("https://api.github.com/zen") end def message response = Net::HTTP.get_response(@zen_uri) "\e[32m #{response.body} \e[0m" end end
true
189c8ce9256150c5be77d34d1e7cfd1a1a1a986d
Ruby
nathanielrhoda/studio_game
/attributes.rb
UTF-8
352
3.765625
4
[]
no_license
class Player attr_accessor :name attr_reader :health end class Player def score @health + @name.length end def to_s "I'm #{@name} with a health of #{@health} and a score of #{score}" end end player2 = Player.new("larry", 60) puts player2.name player2.name = "Lawrence" puts player2.name puts player2.health...
true
91f5bd3b06b8271461d226c7da09f1d092075d55
Ruby
concord-consortium/rigse
/rails/app/models/security_question.rb
UTF-8
3,410
2.984375
3
[ "MIT", "LicenseRef-scancode-public-domain" ]
permissive
class SecurityQuestion < ApplicationRecord belongs_to :user validates_presence_of :user_id validates_presence_of :question validates_presence_of :answer QUESTIONS = [ "What is your favorite color?", "What is your favorite food?", "What is your favorite ice cream flavor?", "...
true
718502abd4d2367b94f925e7f1afc4dbab8dd54b
Ruby
dcutting/strut
/lib/strut/report_pretty_formatter.rb
UTF-8
2,343
2.8125
3
[ "MIT" ]
permissive
require "rubygems" require "term/ansicolor" include Term::ANSIColor require "strut/report" module Strut class ReportPrettyFormatter def initialize(lines) @lines = lines end def format(report) begin out = StringIO.new $stdout = out print_report_to_stdout(report) ...
true
8aa8dca9f8bb4e4aa2cc71ff05d4e1e2aef2e81d
Ruby
mikeymurph77/the_murphy_network
/db/seeds.rb
UTF-8
673
2.53125
3
[]
no_license
require 'csv' csv_text = File.read(Rails.root.join('murph-fam.csv')) csv = CSV.parse(csv_text, :headers => true, :encoding => 'ISO-8859-1') csv.each do |row| person_data = row.to_hash first_name, last_name = person_data['Name'].split(' ') phone = person_data['Primary Phone #'].try(:tr, '^0-9', '') Contact.cr...
true
0f5b22c41319288a40b88a7a55aaa4cb4328e6f2
Ruby
digitalronin/ruby-automated-market-maker
/v5/bin/amm.rb
UTF-8
1,051
3.203125
3
[]
no_license
#!/usr/bin/env ruby require "./lib/requires" amm = Amm.new alice = Counterparty.new(name: "alice", ether: 10) bob = Counterparty.new(name: "bob", ether: 10) zoe = Counterparty.new(name: "zoe", ether: 10, tokens: 1000) counterparties = Counterparties.new([alice, bob, zoe]) loop do print "> " case STDIN.gets.to...
true
975c5fc347d1668e1229235ce7ffc2af5f0896eb
Ruby
ericgj/puzzlenode_circuits
/circuits.rb
UTF-8
3,479
3.15625
3
[]
no_license
module Circuits extend self RESULTS = %w(off on) def evaluate(filename) parse(filename).map {|board| RESULTS[board.evaluate]}.join("\n") end def parse(filename) File.open(filename) do |f| parse_data(f.read) end end def parse_data(data) split_boards(data).inject([]) do |...
true
a460d28c17f1049fcd27f73c5e86d76c512ef766
Ruby
kimchikimchi/ruby
/rubyprograms/p060usemodule.rb
UTF-8
117
2.546875
3
[]
no_license
# p060usemodule.rb require 'p058mytrig' require 'p059mymoral' Trig.sin(Trig::PI/4) Moral.sin(Moral::VERY_BAD)
true
b837e9358b7cbccf0eddab135bdf9e8951b238ea
Ruby
ravishwetha/mercury
/lib/mercury/cucumber/support/mercury_contents.rb
UTF-8
1,111
2.53125
3
[ "MIT" ]
permissive
module MercuryContentsHelpers def contents_for(name) case name when 'simple content' then "this is <span>simple</span> <b>content</b>" when 'justifiable content' then "<div>first line</div><br/>this is <span>justifiable</span><b>content</b>" when 'wrapped content' then "<span>this <a href='http:...
true
fa813f25c6463b0851e8eeeb71b519dd6695cdee
Ruby
jiana3/TheDegistWeb
/app/models/news/importer.rb
UTF-8
1,618
3.15625
3
[]
no_license
# module News class Importer # A news scrape is initialised with the start and end date, it # then validates that the required methods are provided def initialize start_date, end_date @start = start_date @end = end_date @articles = [] end # Method to return news articl...
true
d6bce7ad8aa0cf1b501a3e86ab043ab01a96685a
Ruby
foxnewsnetwork/iomatic
/lib/iomatic/validatable/validator.rb
UTF-8
363
2.71875
3
[ "LicenseRef-scancode-unknown-license-reference", "MIT" ]
permissive
module IOMatic module Validatable # Default implementation of something that can be used as a validator class Validator # Must return an array of presumably errors def call object [] end # returns a boolean if there are errors present def valid? object self.call...
true
37bb2ea373dcd5fd5705bedda199990b49030392
Ruby
fguerra92/Ejercicios-Ruby
/mayor_menor_o_igual2.rb
UTF-8
276
4.125
4
[]
no_license
puts "ingrese valor1" valor1 = gets.chomp.to_i puts "ingrese valor2" valor2 = gets.chomp.to_i if valor1 > valor2 puts "valor1 #{valor1} es mayor" elsif valor1 == valor2 puts "son iguales" else puts "valor1 #{valor1} es menor" end
true
ee1389286e62230ee34fad5ed959de1c6bd876d7
Ruby
8titi8/lecteur-flux-rss
/app/models/articles_scraper.rb
UTF-8
713
2.59375
3
[]
no_license
require 'nokogiri' require 'open-uri' class ArticlesScraper < ApplicationRecord def get_last_feed # get the last added feed feed = Feed.last end def get_page # Open the rss xml feed doc = Nokogiri::XML(open(get_last_feed[:url])) end def get_articles i = 0 # Get all info to add in D...
true
801cf97b929dba37f0743b2958a7dc571d5c17cc
Ruby
k-gavrilov/ruby_basic
/railway_road/labelable.rb
UTF-8
381
2.953125
3
[]
no_license
module Labelable MANUFACTURER = /\S+/ attr_reader :manufacturer def manufacturer=(manufacturer) validate_manufacturer! @manufacturer = manufacturer end def validate_manufacturer!(manufacturer) raise 'Manufacturer is not a string' unless manufacturer.instance_of? String raise "Manufacturer c...
true
9b9ad60a61bee63c24810ff6c2c0b4507712fcc9
Ruby
MrComputingHound/quiz_master
/app/controllers/quizzes_controller.rb
UTF-8
3,874
2.5625
3
[]
no_license
class QuizzesController < ApplicationController def index @questions = Question.all end def new end def create_query recent_query = Question.new(question: params[:question], exam: params[:q_type]) if recent_query.valid? recent_query.save if recent_query.exam == "id" redi...
true
fb2d773a85f3a9fff36d92f7420aa98325ed408a
Ruby
qbahers/google-code-jam
/2012/qualification-round/dancing-with-the-googlers/dancing-with-the-googlers.rb
UTF-8
1,274
3.0625
3
[]
no_license
class Problem def solve(dataset) File.open(dataset, 'r') do |input| File.open(dataset.sub(/\.in/, '.out'), 'w') do |output| # t = input.readline.chomp.to_i t.times do |i| line = input.readline.chomp.split.map { |e| e.to_i } n = line[0] s = li...
true
1e055deb06a1763ad18f3eb7c0efbbcd7b3912cd
Ruby
highgroove/glymour
/lib/scratch.rb
UTF-8
492
2.546875
3
[]
no_license
class WeightNet attr_accessor :net # Use a DAG generated by StructureLearning to create an unweighted Bayes net def initialize(dag) vars = {} @net = Sbn::Net.new(title) vertices.each do |v| vars[v] = Sbn::Variable.new(@net, v.name.to_sym) end edges.each do |e| vars[e.s...
true
e751fa03d6d04f8da1a0bb04b2b8ca3c0ab125c3
Ruby
port49/dsq
/lib/array.rb
UTF-8
417
3.421875
3
[]
no_license
class Array def sum self.inject{|sum, n| sum + n} end def shave!(&block) indeces_to_delete = [] self.each_with_index do |element, index| if(block.call(element)) indeces_to_delete << index end end # Need to be careful about index reordering. indeces_to_delete.reverse.e...
true
10d5f42c89597be08c11c5ba85e73c918538fc7f
Ruby
Kohei-Suzuki22/to_rot13
/spec/answer_spec.rb
UTF-8
7,547
2.84375
3
[]
no_license
RSpec.describe "Answer" do let(:answer){Answer.new(input)} describe "入力の検証" do describe "入力エラー" do context "空の文字列を入力する" do let(:input){" "} it "エラー" do expect{answer}.to raise_error InvalidTextError end end context "ASCIIで印字不可能の文字が入ってる" do l...
true
d03c4b4ef01cc322c005799af40e3742de92af9d
Ruby
Gevanstron/ruby-collaborating-objects-lab-v-000
/lib/song.rb
UTF-8
466
3.15625
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
require 'pry' class Song attr_accessor :name, :artist, :file, :artist_name, :files def initialize(name) @name = name end def artist_name=(artist_name) self.artist = Artist.find_or_create_by_name(artist_name) artist.add_song(self) end def self.new_by_filename(file) values = file.split(" ...
true
9b94acced88790340867234b0e8287c913f1fdf0
Ruby
mojotron/recursion
/binary_search.rb
UTF-8
580
3.890625
4
[]
no_license
require_relative 'merge_sort' def binary_search(array, target) start = 0 stop = array.size - 1 middle = array.size / 2 return target if array[middle] == target#base case return nil if array.size == 0 #if array is empty or doesn't contain target #prepare array for recursion by sliceing depending on middle (array...
true
5c6a5b62efa8fecaf999c24931e505ba56276a9b
Ruby
NathanBang/classlion.coderbyte
/ExOh.rb
UTF-8
193
3.453125
3
[]
no_license
def ExOh(str) x = 0 o = 0 str.split("").each do |letter| x += 1 if letter == "x" o += 1 if letter == "o" end return x == o ? true : false end ExOh(STDIN.gets)
true
23e684c2535a43d5c70917f651c3b3b307d7be3c
Ruby
cj11489/cfapp
/app/models/product.rb
UTF-8
231
2.53125
3
[]
no_license
class Product < ActiveRecord::Base has_many :orders has_many :comments validates :name, presence: true def average_rating comments.average(:rating).to_f end def price_in_cents (self.price[1..-1].to_f * 100).to_i end end
true