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
2691a38f3949f119fb6291cbb17dcd76361ddd2a
Ruby
iancrystal/reo
/app/models/asset_company.rb
UTF-8
1,491
2.640625
3
[]
no_license
require 'digest/sha1' # Model for the asset_companies table class AssetCompany < ActiveRecord::Base # delete_all is for faster delete. this is safe since a company note has not other # dependencies and no callbacks has_many :asset_company_notes, :dependent => :delete_all validates_presence_of :email validat...
true
d8a58de96ec9927373a10403dde9b0d190e143db
Ruby
rickyveltri/phase-0-tracks
/ruby/solo_game/game_spec.rb
UTF-8
1,775
3.59375
4
[]
no_license
##### ### # GAME RSPEC # ### ##### #create relative link to game require_relative 'game' #create tests describe WordGuess do let(:wordguess) { WordGuess.new("Hangman") } #INITIAL SET UP it "converts the word to lowercase and stores letters within an array" do expect(wordguess.answer_arr).to eq ['h...
true
ae6a87dbc772eb7dd2da575d8de82c889df45753
Ruby
railscook/KungFuPanda
/guinea-pigs/SCRIPTS/RUBY/Agoda/current_transactions.rb
UTF-8
1,296
2.90625
3
[]
no_license
class HtmlToCsv attr_accessor :input_file, :output_file def initialize @input_file = get_file('Please type your input file with path') @output_file = get_file('Please type your output file with path') end def start page_sources= File.read(@input_file) page_sources.gsub!("\n","") rows = pag...
true
f13a72dfb1df276cdd86b9c5946fc3c7375c7cb2
Ruby
mhat/memcache
/lib/memcache/local_server.rb
UTF-8
2,238
2.609375
3
[ "MIT", "LicenseRef-scancode-unknown-license-reference" ]
permissive
class Memcache class LocalServer def initialize @data = {} @expiry = {} end def name "local:#{hash}" end def stats { # curr_items may include items that have expired. 'curr_items' => @data.size, 'expiry_count' => @expiry.size, } end def fl...
true
79495417db01a5e00534e77013c584cb0095aa7d
Ruby
hatt0519/negapoji
/lib/negapoji/sentence.rb
UTF-8
135
2.75
3
[ "MIT" ]
permissive
module Sentence KAIGYO = /(\r\n|\r|\n|\f)/ def remove_kaigyo(sentence) sentence_chomped = sentence.gsub(KAIGYO, '') end end
true
5fd562324320987161acc369d8aa5afe025aa49a
Ruby
ares/vzory
/pruby/e07/e07_client.rb
UTF-8
920
3.3125
3
[]
no_license
require 'socket' require 'timeout' def build_client sleep 1 TCPSocket.new ARGV[0] || 'localhost', ARGV[1] || 2000 end def check_reply(client, message) Timeout::timeout(3) do print "#{message} reply: " if client.gets == "#{message}\n" puts 'OK' else puts 'failed' end end end # happ...
true
7d21ca045595c0d755c9cb9df29a051722bcd000
Ruby
irongaze/iron-extensions
/lib/iron/extensions/class.rb
UTF-8
831
2.71875
3
[ "MIT" ]
permissive
class Class # Override #inspect to only include the specified def inspect_only(*methods) @inspect_field_set = methods alias_method :original_inspect, :inspect class_eval do def inspect fields = self.class.inspect_field_set vars = instance_variables field_vals = fields.coll...
true
7659d2ebade9456cfedad55be337a740ca634ba5
Ruby
vvlad/git-hooks
/commit-msg.rb
UTF-8
821
2.625
3
[]
no_license
#!/usr/bin/env ruby require 'pivotal-tracker' require 'highline/import' api_key = `git config --get pivotal.api-key`.strip project_id = `git config --get pivotal.project-id`.strip puts "git config --global --set pivotal.api-key <your api key>" if api_key.empty? puts "git config --local --set pivotal.project-id <p...
true
719abd9b1ae5bce3f0b71dc40059c227a77434e5
Ruby
apiology/bigfiles
/lib/bigfiles/inspector.rb
UTF-8
1,128
2.875
3
[ "MIT" ]
permissive
# frozen_string_literal: true require_relative 'config' require_relative 'file_with_lines' # Simple tool to find the largest source files in your project. module BigFiles # Investigate a project and generate a report on the n biggest files class Inspector def initialize(config: Config.new, ...
true
fa883148f3d6917b9eb0e44f4fdcbb40d27e06a0
Ruby
kelseybjames/assignment_rspec_ruby_tdd
/lib/human.rb
UTF-8
249
3.28125
3
[]
no_license
class Human < Player def set_dice(number) raise ArgumentError.new("Please enter a number") unless number.to_i.is_a?(Fixnum) raise ArgumentError.new("Please enter a positive number") unless number.to_i > 0 @dice = number.to_i end end
true
c699635b795f60f41b4f9902b22ee131e4c5d94c
Ruby
alex-metasploit/metasploit-clone
/rendered79-metasploit/lib/rex/post/meterpreter/packet_response_waiter.rb
UTF-8
1,552
2.921875
3
[ "BSD-3-Clause" ]
permissive
#!/usr/bin/env ruby require 'timeout' require 'thread' module Rex module Post module Meterpreter ### # # This class handles waiting for a response to a given request # and the subsequent response association. # ### class PacketResponseWaiter # # Initializes a response waiter instance for the supplied request # ...
true
f0e66240752af5fa4b08334937a1c377ccc21d64
Ruby
lontuku/subtitle-scraper
/app/controllers/scrapper.rb
UTF-8
3,048
3.0625
3
[]
no_license
require 'nokogiri' require 'open-uri' require 'pry' def separate(data) letters = ('a'..'z').to_a numbers = ('0'..'9').to_a elements = letters.concat(numbers) ans = [] keys = [] data.each_char do |char| if elements.include?(char.downcase) ans << char.downcase else if ans.length > 1 ...
true
e22ba2329df1eaaa4ec69f095ba22c81e28b71af
Ruby
psinnot/gitimmersion
/hello.rb
UTF-8
91
3.21875
3
[]
no_license
puts "what your favorite color?" your_color = gets.strip puts "My color is, #(your_color)"
true
4ccd10bf2ceb0498d459ecf4ce1b4b99027319ab
Ruby
realgoatish/shipped
/app/models/boat.rb
UTF-8
877
2.5625
3
[]
no_license
# Define Boat relationships to other models; define ability to attach avatar; required validations class Boat < ApplicationRecord belongs_to :user has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png" validates_attachment_content_type :avatar, con...
true
bb156fc2cc68c05d1f73bcedcee7605b50b5e6be
Ruby
MPRigby/bubble_sort
/lib/bubble_sort.rb
UTF-8
1,105
3.40625
3
[]
no_license
#lib/bubble_sort.rb class BubbleSort def self.bubble_sort(input) output = input if (output.length > 1) swapped = true while swapped == true swapped = false output.each_with_index.map do |value, index| break if (index+1) >= output.length if (((value.is_a? String...
true
2cdc1bf69a87d353a285f77cbf4d4fc81a251085
Ruby
joestephens/oystercard
/lib/oystercard.rb
UTF-8
909
3.28125
3
[]
no_license
class Oystercard attr_reader :balance, :journeys, :current_journey MAXIMUM_BALANCE = 90 MINIMUM_FARE = 1 def initialize @balance = 0 @journeys = [] @current_journey = {} end def top_up(money) fail "balance cannot exceed #{MAXIMUM_BALANCE}" if exceed(money) @balance += money end def to...
true
9b8e07c5543bec7d73a74d1fbc24696046500b2e
Ruby
amittauro/conways-game-of-life
/spec/starter_board_spec.rb
UTF-8
1,136
2.9375
3
[]
no_license
require './lib/starter_board' describe StarterBoard do describe '#create' do context 'when creating the started board' do it 'returns a 2d array of x and y' do cell = double('cell') starter_board = StarterBoard.new(3, 3, cell) expect(starter_board.show).to eq( [[cell, cell...
true
16a53dcef2cb69f53cc800f0e494c351b367abaf
Ruby
chanachein1/kwk-l1-fizzbuzz-kwk-students-l1-nyc-080618
/fizzbuzz.rb
UTF-8
110
3.296875
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
x=45 if x % 3==0 && x % 5==0 print "fizzbuzz" elsif x==3 print "fizz" elsif x==5 print "buzz" end
true
b04436b5c83a7fa659d57c7a17d39737a221a3e0
Ruby
golumber/golumber
/app/models/product.rb
UTF-8
18,383
2.734375
3
[]
no_license
class Product < ActiveRecord::Base attr_accessible :details, :is_active, :grade_id, :company_id, :species_id, :thickness_metric, :thickness_imperial, :thickness_actual, :width_metric, :width_imperial, :width_actual, :length_metric_lower, :length_metric_upper, :length_imperial_lower...
true
34485f37e2a5416684253e097e7f4661723e6708
Ruby
buzzdeee/gitlab-ce-old
/app/models/concerns/cache_markdown_field.rb
UTF-8
4,069
2.609375
3
[ "MIT" ]
permissive
# This module takes care of updating cache columns for Markdown-containing # fields. Use like this in the body of your class: # # include CacheMarkdownField # cache_markdown_field :foo # cache_markdown_field :bar # cache_markdown_field :baz, pipeline: :single_line # # Corresponding foo_html, bar_html an...
true
a9db6b201a378dd6cde5a51c52f4e1405586744b
Ruby
TravisGM92/rails_engine
/db/seeds.rb
UTF-8
1,876
2.59375
3
[]
no_license
require 'csv' require './app/models/customer.rb' require './app/models/invoice_item.rb' require './app/models/invoice.rb' require './app/models/item.rb' require './app/models/merchant.rb' require './app/models/payment.rb' CSV.foreach('db/data/customers.csv', :headers => true) do |row| Customer.create!({ first_na...
true
3e0c1bd8f54d34fd19e4002a4f6571ef10e28ca2
Ruby
tamanegilila/BCDice
/src/utils/table.rb
UTF-8
881
3.640625
4
[ "BSD-3-Clause" ]
permissive
# -*- coding: utf-8 -*- # 表を表すクラス class Table # @param [String] name 表の名前 # @param [String] type 表の振り方の種類 '1D6'など # @param [Array] table 表本体 def initialize(name, type, table) @name = name @table = table.freeze if (m = /(\d+)D(\d+)/i.match(type)) @type = :d @times = m[1].to_i @sid...
true
00dbb2e01b430ac43461502af737a8b0b52535ae
Ruby
danielmonroy/NFL_Family
/lib/tasks/count_week_points.rake
UTF-8
877
2.703125
3
[]
no_license
task :count_week_points, [:week, :season] => :environment do |task, args| week = args[:week].to_i season = args[:season].to_i data = JSON.load(open("http://static.nfl.com/liveupdate/scores/scores.json")) winners_hash = who_win(data) pools = Pool.where(week: week, season: season) pools.each do |pool| poi...
true
7dc5105dd182a04ae590d5484b1da55226afdd70
Ruby
cherub0526/ruby-practice
/chapter2/2.1.7.rb
UTF-8
80
2.875
3
[]
no_license
names = ["小林","林","高野","森林"] names.each do |x| print x,"\n" end
true
d0d1b4d46d3de73271388293c52ff92a34dad8d9
Ruby
darrencauthon/fieldy
/spec/fieldy/writer_spec.rb
UTF-8
4,833
3.1875
3
[ "MIT" ]
permissive
require_relative '../spec_helper' class AnotherFile include Fieldy::Writer field :first_name, 5 field :last_name, 5 end class AWriterWithASkip include Fieldy::Writer field :first_name, 5 skip 20 field :last_name, 5 end class AWriterWithAHardcodedValue include Fieldy::Writer field :first_name, 5 ...
true
6968f0f12e8c3d370324616dd4223bc10484eadc
Ruby
immorsh/Motherfuckingwebsite
/scrap/scrapping.rb
UTF-8
718
3.09375
3
[]
no_license
require 'rubygems' require 'nokogiri' require 'open-uri' require 'CSV' def get_the_email_of_a_townhal_from_its_webpage(mairie) page = Nokogiri::HTML(open(mairie)) page.xpath('/html/body/div/main/section[2]/div/table/tbody/tr[4]/td[2]').text #p pour return end def get_all_the_urls_of_val_doise_townhall...
true
555714646bc3539ee988b45048464d9889deb97c
Ruby
Wolox/fictium
/spec/rails/app/models/topic.rb
UTF-8
356
2.84375
3
[ "MIT", "Apache-2.0" ]
permissive
class Topic < ApplicationRecord attr_accessor :name class << self TOPICS = [ Topic.new(id: 1, name: 'Fables').freeze, Topic.new(id: 2, name: 'Horror').freeze, Topic.new(id: 3, name: 'Comedy').freeze ].freeze def all TOPICS end end def books Book.select { |book| boo...
true
fe258ceec92d744936ee8d1b606591e1857550a0
Ruby
dgullmarsvik/BDDArticleManager
/lib/articlemanager/controller.rb
UTF-8
4,945
3.015625
3
[]
no_license
module ArticleManager class Controller def initialize(output, article_parser, article_repository) @output = output @article_parser = article_parser @article_repository = article_repository end def start @output.puts(messages[:greeting]) @output.puts(messages[:help]) end ...
true
cae6090319307d6cc9134001dc1d33bfa6535a45
Ruby
ybur-yug/ruby_tutorial-zero-to-advanced
/test.rb
UTF-8
754
3.53125
4
[ "MIT" ]
permissive
require 'pry' time = 5 car_positions = [1, 1, 1] def move_cars(car_positions, time) { cars: car_positions.map { |pos| if Random.rand > 0.3 pos += 1 else pos end }, time...
true
88849879f7097ebd62d2fa2478782a60d6758562
Ruby
errordeveloper/californium-jruby
/lib/modules/local_resources.rb
UTF-8
1,436
2.53125
3
[]
no_license
class LocalResource < Cf::LocalResource # All of the arguments are being passed # to `LocalResource.new`, so we cannot # put more then just this one here :( def initialize (custom) @ep = Cf::LocalResource.new(custom) end # We got to wrap it this way for now, # which is not too bas anyway ... # If yo...
true
bd9da3ee9de28100d6ad974d11a02ad69cc8fc3f
Ruby
mtcameron5/Ruby--The_Basics
/flow_control/code_examples.rb
UTF-8
307
3.671875
4
[]
no_license
puts (4 == 4) && (5 == 5) puts ('abc' < 'z') && ('6' == '6') puts ('aBC' < 'abc') && ('zz' < 'zza') puts (4 < 5) || (4 < 3) puts (9 < 8) || (9 < 2) puts (4 == 5 ) && (5 == 6) if "" puts "an empty string, or anything besides nil and false, evaluates to true" else puts "does not evaluate to true" end
true
f3df78ce67ccd7052085a0c0479d605719a0fd72
Ruby
jheilema-nerdery/HaliteBot
/files/bot_mk3/MyBot.rb
UTF-8
1,264
2.703125
3
[]
no_license
$:.unshift(File.dirname(__FILE__)) require 'networking' network = Networking.new("RubyBotMk3") tag, map = network.configure MAX_STRENGTH = 255 def move(site, location, map, network) if site.strength < 5 || site.strength < 5 * site.production return Move.new(location, :still) end neighbors = map.neighbors(l...
true
fe42208e2fec68b4cb8d3fe0704dcb77394c0417
Ruby
Lion-D-Yovo/git-thp
/learn_ruby_rspec/02_calculator/calculator.rb
UTF-8
1,292
4.28125
4
[]
no_license
#calculator ############################################################ #adds 0 and 0" #adds 2 and 2" #adds positive numbers" def add(a,b) resultat = (a + b) end ############################################################# #subtracts numbers# def subtract(a,b) resultat = (a - b) end ###########################...
true
8d60b58c76afa7799a6e3d2281b4cac3f7903a2a
Ruby
schulzca/rubot
/plugins/roll.rb
UTF-8
1,923
2.890625
3
[]
no_license
class Roll < PluginBase include Cinch::Plugin $help_messages << ["roll","!roll Roll dice. Format: 4d6, 2*d12, 2d2d10 (Default 1d6). [-steps] to see each roll."] listen_to :channel listen_to :private def react_to_message(m) if active?(m,"roll") case m.message when /^!roll\s*$/ roll(m,"...
true
ec788e42fd58cef70d149739dcf45ec0239518f6
Ruby
greggroth/euler
/src/21.rb
UTF-8
232
3.25
3
[]
no_license
require "./lib/fixnum" require "./lib/enumerable" def amicable?(a, b) return false if a == b (a.factors.sum == b) and (b.factors.sum == a) end puts (1..1000).to_a.combination(2).to_a.keep_if { |com| amicable?(com[0], com[1]) }
true
804e61e7a8f0fdac8e1a27f1a19174444638bbf2
Ruby
BC-MAR-21-ROR/kata-07-rejoj-checador-equipo-04-k07
/app/models/employee_check.rb
UTF-8
802
2.703125
3
[]
no_license
# frozen_string_literal: true class EmployeeCheck < ApplicationRecord belongs_to :employee, optional: true attr_accessor :private_number enum check_type: %i[check_in check_out] validates :private_number, presence: true validate :employee_existence before_create :fill_info private def employee_exist...
true
bdec04f222c4eef38ba0caee129dff641ca275f5
Ruby
felp10/cookbook_review
/app/models/recipe.rb
UTF-8
589
2.734375
3
[]
no_license
class Recipe < ApplicationRecord validates :title, presence: true validates :recipe_type, presence: true validates :difficulty, presence: true validates :cuisine, presence: true validates :cook_time, presence: true validates :cook_time, numericality: { other_than: 0, message: 'Tempo de preparo tem que ser m...
true
e761ece6c111732007be6c51a61a7befcbee19fc
Ruby
rockdragon/rubyOnGuys
/statistics/practice/head_first/previously/practice_373.rb
UTF-8
148
2.53125
3
[]
no_license
u1 = 71 o1 = 20.25 u2 = 64 o2 = 16 u = u1 - u2 o = Math.sqrt(o1 + o2) x = 5 puts %Q{N(#{u}, #{o ** 2}), x=#{x}, 则 z = #{(x - u).fdiv(o)}}
true
f3eade4812cf342d826b9234a45caa1d23a7172e
Ruby
VanHau95/Ruby_Basic
/KhachHang.rb
UTF-8
603
3.6875
4
[]
no_license
# # class KhachHang # def dat_hang # p "so luong hang dinh dat" # yield # [1,2,3].each {|i|print i } # end # dat_hang {p "khach hang dinh dat 20"} # # end # # a=KhachHang.new # # a.dathang # def speak(&block) # puts block.call # end # speak { "Hello" } # class Monkey # # Monkey.tell_ape { "ook!" }...
true
234c0685ec711ff4c72528b5b97f205ff10177b7
Ruby
InteNs/circuit_app
/lib/validators/graph_validator.rb
UTF-8
1,073
3.03125
3
[]
no_license
class GraphValidator def initialize(connections) @connections = graph(connections) end def validate strongly_connected_components(@connections).select { |a| a.length > 1 }.none? end private def graph(connections) connections.each_with_object([]) do |(key, value), graph| value.each { |v|...
true
e3a703bf15d6606a700ffe753ecd3fa5e27ff51f
Ruby
jsbenning/jazz_nyc
/lib/jazz_nyc/cli.rb
UTF-8
2,434
3.703125
4
[ "MIT" ]
permissive
class JazzNyc::CLI def welcome Scraper.start #call all scrapers here trhough start class method #Scraper.van_scraper #Scraper.bird_scraper Event.sort # put after the scrapers to make sure Event class is organized by date, then venue puts "" puts " --------------------------------------...
true
d7467ea989190f7cb6e00d2b98f8f990acc2d44b
Ruby
Vaguery/Nudge
/spec/points/value_point_spec.rb
UTF-8
990
2.953125
3
[]
no_license
# encoding: UTF-8 require File.expand_path("../../nudge", File.dirname(__FILE__)) describe "ValuePoint" do describe ".new (value_type: Symbol, string: String)" do it "sets @value_type" do point = ValuePoint.new(:int, 5) point.instance_variable_get(:@value_type).should == :int end it "set...
true
496677c8c79d367379f9f4977b7a6681e4216485
Ruby
Adedee/ruby
/Exercise6/lib/BikeClass.rb
UTF-8
212
3.078125
3
[]
no_license
require_relative('VehicleClass.rb') class Bike < Vehicle attr_accessor :dealer def to_s() self.class.superclass.instance_method(:display).bind(self).call puts "Dealer name : #{dealer} " end end
true
73644274be2b74daa8a5f6fba8927e26629852ad
Ruby
bennacer860/adventofcode_ruby
/19/sol.rb
UTF-8
586
3.328125
3
[]
no_license
require "pry-byebug" require "set" TARGET = "HOH" transitions = {} File.readlines("input.txt").each do |line| from, to = line.scan(/(\w+) => (\w+)/).flatten transitions[from] ||= [] transitions[from] << to end puts "TARGET => '#{TARGET}'" # p transitions # Part 1 molecules = Set.new transitions.each d...
true
b69b12bd6b4a94c59dbf05ee06d7355b76694874
Ruby
bafraikin/alex_apprend_while
/exo/swap.rb
UTF-8
276
3.484375
3
[]
no_license
#swap est un algorithme de base. #L'objectif est uniquement d'intervertir 2 valeurs dans 2 variables #Ainsi si variable 'a' vaut 10 et variable 'b' vaut '40' #à la fin 'a' sera egale à 40 et 'b' 10 #ps: tu peux creer autant de variable que tu veux. a = 40 b = 15 #....
true
20009bf5a808f04d0e49657a59b9d5853841fbb8
Ruby
DownSpiral/random_projects
/battleship/battleships.rb
UTF-8
14,914
3.265625
3
[]
no_license
require 'set' require 'socket' require 'json' require 'optparse' require 'io/console' class Ship attr_accessor :type, :x, :y, :dir, :being_placed SHIP_SIZES = { 'carrier' => 5, 'battleship' => 4, 'cruiser' => 3, 'submarine' => 3, 'destroyer' => 2 } SHIP_CHARS = { 'carrier' => 'A', 'ba...
true
c27639aba41ca857cbc88c25cdce39d24311e581
Ruby
pikesley/neoclock
/hack.rb
UTF-8
1,194
2.65625
3
[ "MIT" ]
permissive
require 'date' begin require "pixel_pi" rescue LoadError lib = File.expand_path('../../lib', __FILE__) raise if $LOAD_PATH.include?(lib) $LOAD_PATH.unshift(lib) retry end LED_COUNT = 36 # Number of LED pixels. LED_PIN = 18 # GPIO pin connected to the pixels (must support PWM!). LED_FR...
true
fb4e7f78a1ec9796e59b183abe63dc1b0da60c17
Ruby
lacresni/LS_Intro_Programming
/01_Basics/exercise6.rb
UTF-8
179
3.484375
3
[]
no_license
# Write a program that calculates the squares of 3 float numbers # of your choosing and outputs the result to the screen. puts 3.5 * 3.5 puts 123.786 * 123.786 puts 4.567 * 4.567
true
1571fc633556d843d92b6790c628fe6aa0f98944
Ruby
HillaryOkello/ruby-linter
/spec/testing_spec.rb
UTF-8
990
2.65625
3
[]
no_license
require_relative '../lib/checks' describe ErrorCheck do let(:checker) { ErrorCheck.new('test.rb') } describe '#tag_error' do it "Checks for missing/unexpected tags eg '( )', '[ ]', and '{ }'" do checker.tag_error expect(checker.errors[0]).to eql("line:15 Lint/Syntax: Unexpected/Missing token ')' P...
true
2a9e95125895f2d27fc1ab6fac01d3c719771882
Ruby
npakk/LeetCode
/#13_Roman_to_Integer.rb
UTF-8
720
3.96875
4
[]
no_license
def roman_to_int(s) # ローマ数字に対応した数値を並べたハッシュを用意 hash = { "I"=>1, "V"=>5, "X"=>10, "L"=>50, "C"=>100, "D"=>500, "M"=>1000 } # ハッシュに対し引数の文字列1文字ずつを順番に検索する hash.values_at(*s.chars).each.with_index.inject(0) do |result, (n, index)| # 文字列の次の文字が現在の文字が表す数値の5倍もしくは10倍の場合、戻り値から現在の値を予め引いておく if hash[s[index+1]] == n...
true
78fc5525a236aa41c91b5a41e542bc7695595a2f
Ruby
yinm/ruby-book-codes
/sample-codes/chapter_06/code_6.05.01.rb
UTF-8
576
3.390625
3
[]
no_license
# /\d{3}-\d{4}/と書いた場合と同じ Regexp.new('\d{3}-\d{4}') # ---------------------------------------- # スラッシュで囲むと、スラッシュをエスケープする必要がある /http:\/\/example\.com/ # %rを使うとスラッシュをエスケープしなくてよい %r!http://example\.com! # !ではなく{}を区切り文字にする %r{http://example\.com} # ---------------------------------------- pattern = '\d{3}-\d{4}' # 変数が...
true
8747c73a9a4a1bd9d7f66d087b0eacf742970282
Ruby
jiji12874/furima-31963
/spec/models/user_spec.rb
UTF-8
5,824
2.578125
3
[]
no_license
require 'rails_helper' RSpec.describe User, type: :model do before do @user = FactoryBot.build(:user) end describe 'ユーザー新規登録' do context '新規登録がうまくいくとき' do it '全ての値が入っている場合、登録できる' do expect(@user).to be_valid end it 'nicknameが存在すれば登録できる' do @user.nickname = 'aaa' @...
true
2c6afe4f463b81616755e917afe9455e3e545ecb
Ruby
haveanicedavid/sales_engine
/lib/invoice_item_repository.rb
UTF-8
2,768
2.90625
3
[]
no_license
require_relative 'invoice_item' require_relative 'parser' class InvoiceItemRepository attr_reader :invoice_items, :engine def initialize(data, engine) @engine = engine @invoice_items = data.map { |line| InvoiceItem.new(line, self) } end def inspect "#<{self.class} #{@invoice_items.size} rows>" ...
true
01f8e857882187fbb691ebc2d2ed2f07563a2718
Ruby
DanielZwijnenburg/Daily-Kata
/2012/December/06-12-2012/bowling_game.rb
UTF-8
514
3.546875
4
[]
no_license
class BowlingGame attr_accessor :score_array def initialize @score_array = [] end def score(score_string) map_score_string_to_array(score_string.chars.to_a) score_array.inject(&:+) end private def map_score_string_to_array(score_string) score_string.each_with_index do |score, i| ...
true
63db4c8e9376b6e164d277b0037aef20d82e1f08
Ruby
qubbit/argonaut-cli
/lib/argonaut/cli.rb
UTF-8
1,667
2.53125
3
[ "MIT" ]
permissive
require_relative './gateway' module Argonaut class Cli attr_reader :gateway def initialize(gateway:) @gateway = gateway end def teams raw_data = @gateway.fetch(path: 'teams') raw_data['data'] end # Gets all the reservations for the given team def reservations(team_na...
true
b202d9f09ef0d10fcce796987125866dfd4199e8
Ruby
eric-to/W2D3
/TDD_Project/lib/tdd.rb
UTF-8
1,013
3.5625
4
[]
no_license
def my_uniq(arr) new_arr = [] arr.each { |el| new_arr << el unless new_arr.include?(el) } new_arr end class Array def two_sum pairs = [] (0...self.length).each do |i| (i + 1...self.length).each do |j| pairs << [i, j] if self[i] + self[j] == 0 end end pairs end ...
true
d329613a61d40d6f92c24cf0a4416ff3b0a3396c
Ruby
named-data-mobile/android-crew-staging
/library/extend/dir.rb
UTF-8
232
2.671875
3
[]
no_license
class Dir def self.empty?(path) Dir.exist?(path) and (Dir["#{path}/*", "#{path}/.*"] - ['.', '..']).empty? end def self.size(path) Dir["#{path}/**/*", "#{path}/**/.*"].map { |f| File.size(f) }.inject(0, :+) end end
true
7e013549216948a156d4b64620ba688aacdcf67f
Ruby
lynaghk/prote.cs
/writeup/compile_js.rb
UTF-8
961
2.71875
3
[ "MIT" ]
permissive
#!/usr/bin/env ruby #lil' script to concatenate and minify JavaScript require 'rubygems' require 'closure-compiler' Header = "// Kevin Lynagh // December 2010 // Check out the source on my Github page; // http://github.com/lynaghk/prote.cs/ // This is commit: #{`git rev-parse HEAD`}\n\n" def compile_js(input_fi...
true
425b4584673a63f2f4267cf6b17ebe813c5e7929
Ruby
ButchAnton/RubyAndBeagleBoneBlack
/bbb_shift_register_blink_leds.rb
UTF-8
540
2.71875
3
[ "Apache-2.0" ]
permissive
#!/usr/bin/env ruby require 'beaglebone' include Beaglebone # Power (+5v) P9_5, red # Ground P9_1, black clock = :P9_11 # yellow, pin 11 on 595 latch = :P9_12 # green, pin 12 on 595 data = :P9_14 # orange, pin 14 on 595 shiftreg = ShiftRegister.new(latch, clock, data) loop do # shift the LEDs in the forward dir...
true
fb0074820396435a9acbea17856a25e73a93d42f
Ruby
lennythomas-dev/launch_school_core
/lesson_4/selection_transformation/double_numbers.rb
UTF-8
397
3.875
4
[]
no_license
# Courses > RB101 Programming Foundations > Lesson 4: Ruby Collections > Selection and Transformation # double numbers def double_numbers!(numbers) counter = 0 numbers_length = numbers.size loop do break if counter == numbers_length numbers[counter] = numbers[counter] * 2 counter += 1 end ...
true
942df75daeffce9de6ff7919bfe3da5d62cfbf4e
Ruby
Naomi-Dennis/apprentice-tictactoe
/spec/main_io_spec.rb
UTF-8
1,464
2.953125
3
[]
no_license
# frozen_string_literal: true require 'spec_helper' require 'main_io' class FakeStdin attr_accessor :string def initialize(string: '') @string = string end def gets @string end end class FakeStdout def puts(*output) output.join("\n") end end class FakeSpy attr_accessor :times_called ...
true
9035abbdddb1b9530267557d893ba061e01f7b76
Ruby
duythangos/training
/Write_record_to_file.rb
UTF-8
675
2.65625
3
[]
no_license
require 'pg' puts "before connect" conn = PG.connect( :dbname => 'thangnpd_test', :user => 'postgres', :password => '123456') puts "after connect" conn.exec( "SELECT * FROM articles" ) do |result| result.each do |row| puts "Title of article #{row['id']} is #{row['title']}" file = F...
true
304d5e074e94d8adda407d5ad1cb78804b7b3f63
Ruby
samiequipo/ideallsite
/db/seeds/seed_company.rb
UTF-8
195
2.9375
3
[]
no_license
# Companies are all operators like vodafone, meo, nowo # FILLING COMPANIES ["MEO","NOS","VODAFONE","NOWO"].each do |company| Company.create! description: company end puts "Companies Filled!"
true
b8345747ea508041d8e03bfa993ee8f0bbfd58ff
Ruby
StephenArg/oo-cash-register-dumbo-web-111918
/lib/cash_register.rb
UTF-8
741
3.4375
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
class CashRegister attr_reader :items attr_accessor :total def initialize(discount = 0) @total = 0 @employee_discount = discount @items = [] end def discount @employee_discount end def add_item(title, price, quantity = 1) @last_transaction = price * quantity @total += @last_trans...
true
687e75103bf2b7dacee3507a3870393f2f62fad3
Ruby
nikraev/tcpdump
/main.rb
UTF-8
762
2.765625
3
[]
no_license
require 'socket' load './redis.rb' server = TCPServer.new('localhost', 3000) loop do Thread.start(server.accept) do |client| client.printf "Hello\n" session = Session.new('127.0.0.1', 6379) message = client.gets.chomp.split(';') message.size command = message[0] arg = message[1] ...
true
1ce51ca592620fea67d960b21a6bf51d739761c4
Ruby
sds/mock_redis
/spec/commands/move_spec.rb
UTF-8
3,248
2.53125
3
[ "MIT" ]
permissive
require 'spec_helper' RSpec.describe '#move(key, db)' do before do @srcdb = 0 @destdb = 1 @key = 'mock-redis-test:move' end context 'when key exists in destdb' do before do @redises.set(@key, 'srcvalue') @redises.select(@destdb) @redises.set(@key, 'destvalue') @redises.s...
true
7654711fd8eb4d79f04e8bf8fec0b156d950f2f9
Ruby
ssteeg-mdsol/openapi3-generator
/gems/gems/prawn-table-0.2.2/spec/extensions/mocha.rb
UTF-8
1,225
2.984375
3
[ "Apache-2.0", "GPL-3.0-only", "GPL-2.0-only", "Ruby" ]
permissive
# encoding: utf-8 # Allow speccing things when an expectation matcher runs. Similar to #with, but # always succeeds. # # @pdf.expects(:stroke_line).checking do |from, to| # @pdf.map_to_absolute(from).should == [0, 0] # end # # Note that the outer expectation does *not* fail only because the inner one # does; i...
true
3ba5c03a4989dee83f5764b35dfa2aaf5318d388
Ruby
EvilFaeton/adequack
/lib/adequack/proxy.rb
UTF-8
1,844
2.84375
3
[ "MIT" ]
permissive
module Adequack class Proxy def initialize(target, interfaces) self.target = target self.interfaces = interfaces end private attr_accessor :target, :interfaces def method_missing(name, *args, &block) check_interface_implementation name, args target.send name, *args, &bl...
true
17045c40dc31d80d7e920f3d511b0f2e42cf6102
Ruby
CaffeinatedDave/clicky-bars
/app.rb
UTF-8
6,328
2.53125
3
[]
no_license
require 'sinatra' require 'sinatra-websocket' require 'json' require './models/resource' require './models/users' set :server, 'thin' set :bind, '0.0.0.0' $to_close = [] $resource = {} tick = Proc.new { |cur, max, incr| cur + incr + (incr * 5 * (cur * 1.0 / (max * 0.8))) } $resource["wood"] = Resource.new("wood", 2...
true
3a664c34ba83cef0cb17a3234884cd8086e941a2
Ruby
samesystem/social_security_number
/lib/social_security_number/country/lt.rb
UTF-8
1,681
2.984375
3
[ "MIT" ]
permissive
module SocialSecurityNumber # SocialSecurityNumber::Lt validates Lithuania Personal Code (Asmens kodas) # https://en.wikipedia.org/wiki/National_identification_number#Lithuania class Lt < Country def validate @error = if !check_digits 'it is not number' elsif !check_lengt...
true
1352d64dbd73a44f8e92226058df07fb1a1ff9da
Ruby
UniqMartin/adventofcode-2015
/day-20/main.rb
UTF-8
1,717
3.921875
4
[ "BSD-2-Clause" ]
permissive
# Advent of Code 2015 - Day 20 require "prime" module Day20 INPUT_PRESENTS = 34_000_000 def self.factors_of(number) factors = [1] primes = Prime.prime_division(number) primes.each do |prime, max_power| count = factors.size 1.upto(max_power) do |power| factor = prime**power ...
true
d035ae3f0f07c418cfd7b00856bad69ee9a2d777
Ruby
zahidmitha/wallet
/spec/wallet_spec.rb
UTF-8
1,109
2.953125
3
[]
no_license
require './wallet' require 'spec_helper' describe Wallet do let(:wallet) {Wallet.new} describe '.new' do it 'has an initial balance of zero' do wallet.balance.should eq 0 end end # describe '#balance' do # context 'given wallet currently exists' do # it 'has a current balance' do #...
true
e03e6615a076d632efa544cddba610a76c3f405a
Ruby
meltar/todo_list_app
/todo_demo.rb
UTF-8
1,177
3.421875
3
[]
no_license
require 'rubygems' require 'bundler/setup' require "./models/task.rb" require "./models/list.rb" demo_list = List.new() puts "Welcome!" while true if demo_list.total_tasks > 0 puts "\nTo do list:" puts demo_list.to_s puts "Enter 'N' to add a new task, 'E' to edit a task, or 'Q' to quit." else puts...
true
1752d5696c890120d607f075d782e6225813146f
Ruby
SamGerber-zz/chess
/queen.rb
UTF-8
351
2.859375
3
[]
no_license
require_relative 'piece' require_relative 'sliding_piece' class Queen < Piece include SlidingPiece def initialize(color, position, board, move_history = nil) @directions = SlidingPiece::RANK_AND_FILE + SlidingPiece::DIAGONAL super(color, position, board, move_history) end def to_s color == :black...
true
620adbbddea092b56984a0e6551b7f36f839449b
Ruby
siwka/Chord_Interpreter
/spec/scanner_spec.rb
UTF-8
1,011
2.859375
3
[]
no_license
require 'scanner' describe Scanner do context "starting up" do let(:messenger) { messenger = mock("messenger").as_null_object } let(:scanner) { scanner = Scanner.new(messenger) } it "should send a welcome message (passing the code to start)" do messenger.should_receive(:puts).with("Welcome to note interpret...
true
da20475e5057983357ccdb7f3de19cd5bc151ac0
Ruby
Khinsu/autochess-bot
/player.rb
UTF-8
346
3.09375
3
[]
no_license
class Player @discord_id = -1 @name = "" @steam_id = -1 def initialize(discord_id, name, steam_id) @discord_id = discord_id @name = name @steam_id = steam_id end def discord2steam id @steam_id if @discord_id == id nil end def steam2discord id @discord_id if @steam_id ==...
true
a98a998391d934a43dfa0c65fd6550f18782c198
Ruby
greenonion/parodikos
/lib/parodikos/reaper.rb
UTF-8
865
2.796875
3
[ "MIT" ]
permissive
# frozen_string_literal: true module Parodikos # Deletes all tweets before a certain date for a certain user. # Allows for dry runs. class Reaper attr_reader :screen_name, :before def initialize(screen_name:, before:) @screen_name = screen_name @before = before end def dry! Ti...
true
78799974e2c196eb98ff69d6d3ea6c243776a920
Ruby
KnVerey/irc_bot
/weatherbot.rb
UTF-8
2,542
3.40625
3
[]
no_license
require "socket" require 'net/http' require 'curb' require "json" class Bot def initialize @port = "6667" @nick = "WeatherBot" @channel = "#bitmakerlabs" end def run connect until @server.eof? do @msg = @server.gets pong if @msg.include? "PING" respond if relevant? end...
true
a2b6877725d9d1f3849e790b79223921bab31d98
Ruby
JonJarGaa/intro-to-ruby-book
/9_exercises/9_13_array_delete_if_start_with.rb
UTF-8
786
4.6875
5
[]
no_license
=begin 13. STEP 1) Use Ruby's Array method delete_if and String method start_with? to delete all of the words that begin with an "s" in the following array. STEP 2) Then recreate the arr and get rid of all of the words that start with "s" or starts with "w". =end arr = ['snow', 'winter', 'ice', 'slippery', 'salt...
true
626a8ef4f07c10ded15616816255616f9cbe02c9
Ruby
douglasdeodato/ruby
/estudo/sum-array.rb
UTF-8
40
3.15625
3
[]
no_license
a = [6,7,29] puts a.inject(0){|b,i| b+i}
true
e1fd81d28362a3a967c1f69d19e0cae708028b11
Ruby
danangww/go-scholar-exercise
/deep_counter.rb
UTF-8
181
3.1875
3
[]
no_license
class DeepCounter def evaluate(data) count = 0 data.each do |x| count += 1 if x.is_a?(Array) count += evaluate(x) end end count end end
true
ee7decac519fb367eafb714229f3ad552599ad63
Ruby
playa/em_proxy_example
/lib/client.rb
UTF-8
532
2.515625
3
[]
no_license
module EMClient include EM::P::ObjectProtocol @@connection_number = 0 @@dissconnected = 0 #send request as the connection has been established def post_init @@connection_number += 1 send_object({'id'=> rand(10), 'text' => "req#{@@connection_number}"}) end def receive_object(obj) #disp...
true
9c88e15b7a74bb9f2c14182e05c35c3a5536cd29
Ruby
anastasiayurc/json-creator
/builder.rb
UTF-8
2,333
2.9375
3
[]
no_license
require 'getoptlong' require 'json' class Builder def initialize(options) @options = options @set = process_set end def build assets = [] @options[:asset_count].times { |i| assets << build_asset(i+1) } json = { 'assets' => assets }.to_json File.open(@options[:file_name], 'w+') { |f| f.wr...
true
4076c156f057709fe5b8eb5ef1acb2beb9f62731
Ruby
dlyn1110/ruby-collaborating-objects-lab-v-000
/lib/song.rb
UTF-8
377
3
3
[ "LicenseRef-scancode-unknown-license-reference", "LicenseRef-scancode-public-domain" ]
permissive
class Song attr_accessor :artist attr_reader :name def initialize(name) @name = name end def name=(name) @name = name end def artist_name=(name) self.artist = Artist.find_or_create_by_name(name) artist.add_song(self) end def self.new_by_filename(file) song = self.new(file.split(" - ")[1]) ...
true
6d3407690772f4cca02312b877c2e650d43d9d0e
Ruby
hitherjarl/2
/5.rb
UTF-8
126
2.875
3
[]
no_license
def double_this num num_times_2 = num*2 puts num.to_s+' doubled is '+num_times_2.to_s end double_this 44 puts num_times_2.to_s
true
8fb0486cd0bdabf2abaf8f5b861d9f3f8d9929c7
Ruby
graemeworthy/omnisearch
/spec/result_spec.rb
UTF-8
1,015
2.6875
3
[]
no_license
require './spec/spec_helper' describe Result do let(:the_class) {Result} subject { Result.new(:label => "A result", :score => 1) } describe "Instance Methods" do it {should respond_to :id} it {should respond_to :klass} it {should respond_to :raw_data} it {should respond_to :score} it {should...
true
3fa5ee2cf18ef8817ec7deb33933c381f9fe9175
Ruby
jdibling/ruby-decoder
/lib/fields/attributes/lookup.rb
UTF-8
957
2.65625
3
[]
no_license
require 'fields/attributes/basic' module Fields module Attributes # ------------------------- class LookUp < BasicAttribute def initialize(map={}, default_label=nil) @map = map @default_label = default_label end def evaluate field, decoder check field, decoder wire = decoder.decoded[field.id] ...
true
a08fa077923902c08f006cabb6e3f97a6aa62112
Ruby
yesentorres/hotel
/test/reservation_test.rb
UTF-8
1,289
2.9375
3
[]
no_license
require_relative "test_helper" describe "Reservation Class" do describe "initialize" do it "creates an instance of a Reservation object" do start_date = Date.new(2020, 8, 4) end_date = start_date + 5 @test_reservation = Hotel::Reservation.new(id: 1, room_num: 1, start_date: start_date, end_dat...
true
bb1ddb8e19fbdd21735873b6ac9fa5a8da13ecc0
Ruby
minaslater/MarvelCrossoverCLI
/url_builder.rb
UTF-8
675
2.671875
3
[ "MIT" ]
permissive
require_relative "api_param_builder" require "uri" class URLBuilder # def initialize(character_name) # @character_name = character_name # end def character_to_s(character_name) character_url = URI.escape(character_name) "&name=#{character_url}" end def build_with_name(character_name) params...
true
1a9edcddf7846c4a5ea8164c7dc1f5402189e1bb
Ruby
indirect/pfc
/vendor/plugins/wesabe_extensions/lib/rails_libraries/builder_dasherize.rb
UTF-8
524
2.53125
3
[ "Apache-2.0" ]
permissive
require 'builder' class Builder::XmlMarkup def dasherize! @dasherize = true end def undasherize! @dasherize = false end private def _start_tag_with_dasherize(sym, attrs, end_too=false) sym = sym.to_s.dasherize if @dasherize _start_tag_without_dasherize(sym, attrs, end_too) end alias_m...
true
1cc4d0ecceccb5e86bd583cdddc154920f582538
Ruby
preetness/phase-0-tracks
/ruby/secret_agents.rb
UTF-8
959
4.3125
4
[]
no_license
#Encrypt: #-Pass in a string and replace the letters of the string with the next letter in the alphabet # -Also make it lowercase #-Any space character should remain the same def encrypt(str) i = 0 while i < str.length if str[i] == " " str[i] = str[i] elsif str[i] == "z" str[i] = "a" ...
true
31469a16e9d067c037dbd35945243c55d1b879f8
Ruby
interror/pzks_2e
/app/controllers/system_model.rb
UTF-8
24,377
2.640625
3
[]
no_license
require_relative 'task_model.rb' require_relative 'controller_model.rb' require_relative 'analyze_model.rb' #require 'json' class ProcessorElement attr_accessor :id, :links, :task, :stay_time, :controller, :memory, :result, :wait_data, :active_forwards def initialize(top, physical_links, connection) @id = top ...
true
7bb864359437696e2d64b447489a9765e9b9f5a2
Ruby
namoricoo/Coderbyte-Ruby-Rspec
/spec/first_reverse_spec.rb
UTF-8
640
3.859375
4
[]
no_license
# # Using the Ruby language, have the function FirstReverse(str) take the str # parameter being passed and return the string in reversed order. require 'spec_helper' require_relative '../lib/first_reverse.rb' describe 'reverse method' do it "reverses a string Input = 'coderbyte' Output = 'etybredoc' " do string_i...
true
a30f54a304a37bf8511f1556edbdffa1162274b7
Ruby
betweenparentheses/the_list
/app/services/fun_cheap.rb
UTF-8
1,864
2.90625
3
[]
no_license
require 'mechanize' # require 'pry' require 'json' #required for activesupport require 'active_support/all' class FunCheap MECHANIZE = Mechanize.new SF_URL = "http://sf.funcheap.com" def initialize end def next_7_days @next_7_days ||= get_next_7_days end def today @today ||= events_on(Date.tod...
true
56ec46bb86722b73ff96170f9b8d18cfd30edbc3
Ruby
sjchakrav/MTACLI
/app/models/user.rb
UTF-8
389
2.65625
3
[]
no_license
# class User # attr_accessor :origin, :destination, :line, :name # ORIGIN = [] # def initialize # @name = name # end # def origin(start) # MTAcli.get_user_input(start) # subway_platforms = MTAParse.new.values # binding.pry # if start == # # ORIGIN << start # else # MTACli.invalid # end # ...
true
7d8040d4c4b233186323b12891a96d12caa39708
Ruby
PatreevIgor/bank
/app/helpers/main_helper.rb
UTF-8
805
2.90625
3
[]
no_license
module MainHelper def rounding(number) ((number/1000000.to_f).round(1)).to_s.gsub(/(\d)(?=(\d\d\d)+(?!\d))/, "\\1 ") end def color_text_red_or_green_and_rounding(number) "<font color=#{ number <= 0 ? "'red'> " : "'green' >+"}#{rounding(number)} </font>".html_safe # if number <= 0 # "<font colo...
true
28a19a2b529be0cdf289ad07a17370d5815d9954
Ruby
SpillChek2/opentpx
/ruby/tpx/lib/tpx/2_2/attribute_accessors.rb
UTF-8
1,033
2.953125
3
[ "Apache-2.0" ]
permissive
module TPX_2_2 module AttributeAccessors # Overrides default method_missing to alias method names to hash keys. # # @param [String] meth The name of the called method. # @param [Array<Symbol>] args Additional arguments. # @param [Proc] block Additional block. # # @raise [NoMethodError] Er...
true
a12a31319e96593f12363a71700e20438e45bb93
Ruby
shmztko/redshift-test-scripts
/redshift-ctl/lib/redshift_startup_runner.rb
UTF-8
1,980
2.796875
3
[]
no_license
# Command runner for redshift boot script. require File.expand_path('../redshift_cluster.rb', __FILE__) require File.expand_path('../redshift_snapshot.rb', __FILE__) class StartupRunner WAIT_TIME = 10 def initialize(client, cluster_conf, logger) @cluster_conf = cluster_conf @logger = logger ...
true
2ffa7a70b7ba61f8f15cf7f4000cc9b7469e46a2
Ruby
jegrieve/Memory-Puzzle
/human_player.rb
UTF-8
421
3.609375
4
[]
no_license
class Player attr_accessor :name, :memory def initialize(name) @name = name @memory = {} end def get_input(length) puts "Enter a valid guess (Ex: 0 0 for first position)" guess = gets.chomp.split(" ").map(&:to_i) end def store_memory(card, location)...
true
8f2d0f672380b753eaca86d4fddf498f12ca418e
Ruby
vitalyrubstein/Pictures
/test2.rb
UTF-8
2,181
3.125
3
[]
no_license
require 'rubygems' require 'date' #calls Date library require 'fileutils' require 'ftools' require 'exifr' require 'quick_magick' #require 'mysql' #require "dbi" class Report def initialize @title = 'Monthly Report' @text = ['Things are going', 'really well.'] end def output_report end end #FileUti...
true