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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
e0ce46df63c0a05e9affb65ab7ced07c1a9b1e72 | Ruby | sekiya93/ProgramTracing | /exam/ruby_code/arr03.rb | UTF-8 | 123 | 3.28125 | 3 | [] | no_license | def arr03(c)
n = c.size
for i in 0..n/2-1
t = c[i]
c[i] = c[n-1-i]
c[n-1-i] = t
end
p c
end
| true |
285d8f255db5d8793568eefad793af18492a0380 | Ruby | koutaNakanishi/nazonazo_app | /app/helpers/sessions_helper.rb | UTF-8 | 741 | 2.5625 | 3 | [] | no_license | module SessionsHelper
def log_in(user)#渡されたユーザでログインする
session[:user_id]=user.id#一次cookiesに暗号化したユーザIDが生成される
end
def current_user #今のユーザ名を表示するやつ
@current_user ||= User.find_by(id:session[:user_id])
#@current_user= @current_user ||(otherwise) User.find_by(id: session[:user_id])
end
def logged_in?
!current_... | true |
af58f5a9f18b26bdbae4d40ae0f4e17a399054e3 | Ruby | ciara-picou/rack-responses-lab-atx01-seng-ft-082420 | /app/application.rb | UTF-8 | 494 | 3.203125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # initial attempt
# class Application
# def call(env)
# resp = Rack::Response.new
# current_hour = Time.now.hour
# if current_hour < 12
# resp.write "Good Morning!"
# else
# resp.write "Good Afternoon!"
# end
# resp.finish
# end
# end
# improved_attempt
class Application
... | true |
b56d551bf2e59d9266a3225cebf431d04a46fc29 | Ruby | graphiti-api/graphiti | /lib/graphiti/util/simple_errors.rb | UTF-8 | 2,098 | 2.546875 | 3 | [
"MIT"
] | permissive | # A minimal implementation of an errors object similar to `ActiveModel::Errors`.
# Designed to support internal Graphiti classes like the `RequestValidator` so
# that there does not need to be a dependency on activemodel.
module Graphiti
module Util
class SimpleErrors
include Enumerable
attr_reader :... | true |
ed68069952404216d6c938746832c06ea2587f51 | Ruby | Karlotcha/ludum24 | /Princess.rb | UTF-8 | 1,648 | 2.640625 | 3 | [] | no_license | class Princess
attr_reader :img, :l, :t, :r
def initialize(window)
@l = (rand 3).to_s
@t = (rand 4).to_s
@r = (rand 3).to_s
@img = "gfx/" + @l + "_" + @t + "_" + @r + ".bmp"
@image = Gosu::Image.new(window, @img, false)
@x = @y = 400
@hiii = [Gosu::Sample.new(window, "sfx/hiii.wav"),
Gosu::... | true |
45fc7e9b6d7b24488639583de4f870683953de49 | Ruby | Victorcorcos/Algoritmos-e-Grafos | /Grafos/MapaMeistre (1855)/mapameistre.rb | UTF-8 | 1,222 | 3.609375 | 4 | [] | no_license | require 'scanf'
linha = 0
coluna = 0
fim = 1000
mapa = []
valores = scanf('%d%d')
largura = valores.first
altura = valores.last
(0...altura).each do |i|
line = STDIN.gets.chomp
mapa[i] = line
end
passos_maximo = largura * altura
passos = 1
while passos <= passos_maximo
if mapa[linha][coluna] == '>'
colun... | true |
d2b2ff3e34660d5e0787d0027ab6e42d61db9670 | Ruby | erinnachen/exercism | /ruby/roman-numerals/roman_numerals.rb | UTF-8 | 569 | 3.546875 | 4 | [] | no_license | class Integer
VERSION = 1
def to_roman
roman = ''
number = self
roman_symbols.each_with_index do |(base, symbol), ind|
divided = number / base
puts "STEP: #{number}, #{divided}, #{base}, "
if ind > 0 && divided == 4
roman += symbol + roman_symbols[ind-1][1]
elsif ind > 0 ... | true |
82dd8936fe34e87f9f96c8226aeeebbb90c1ed7c | Ruby | ivncastillo/desafio_poo_cuenta_bancaria_2 | /cuenta_bancaria.rb | UTF-8 | 922 | 3.578125 | 4 | [] | no_license | class CuentaBancaria
attr_accessor :banco, :numero_de_cuenta, :saldo
def initialize(banco, cuenta, saldo=0)
@banco = banco
@numero_de_cuenta = cuenta
@saldo = saldo
end
def transferir(monto, cuenta_2)
@saldo -= monto
cuenta_2.saldo += monto
end
end
class ... | true |
8ead8cd491498d0af4d020082f0bb899d082d4d6 | Ruby | kikicat-meows/chess | /board_components/pieces/bishop.rb | UTF-8 | 342 | 2.984375 | 3 | [] | no_license | ### able to move in a straight line using slideable
require_relative "slideable"
require_relative "piece"
class Bishop < Piece
include Slideable
def symbol
if self.color == :white
symbol = "\u2657"
else
symbol = "\u265d"
end
symbol.encode('utf-8')
end
protected
def move_dirs
... | true |
e9f82e253d331f5f0259684e889db2b3ea7be102 | Ruby | ged/mues | /experiments/attic/wackyClass.rb | UTF-8 | 302 | 3.0625 | 3 | [] | no_license | #!/usr/bin/ruby -w
require 'pp'
class A
def test
puts "This is the old A"
end
end
20.times {|time|
klass = Class::new( A ) {
self.module_eval %{
def test
puts "This is the new A (#{time})"
super
end
}
}
A = klass
}
puts "A's ancestors"
pp A.ancestors
a = A::new
a.test
| true |
8d8d671e4a9d72f35058dd7cf9d31b09e81a18bd | Ruby | Xorcode/jekyll-bitly-plugin | /_plugins/bitly_fiter.rb | UTF-8 | 2,491 | 2.515625 | 3 | [
"BSD-2-Clause"
] | permissive | # Generate bit.ly links on the fly
# Can be used anywhere liquid syntax is parsed (templates, includes, posts/pages).
#
# Usage: [Bit.ly gem]({{ 'https://github.com/philnash/bitly' | bitly }})
#
# Copyright (c) 2012, Xorcode LLC.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or w... | true |
aa58e2c463c9a32036fb296a0965565549f37bcb | Ruby | laurieroy/learn-ruby-rails | /lib/todo/todoRepository.rb | UTF-8 | 2,070 | 3.046875 | 3 | [] | no_license | require_relative 'todo'
require 'JSON'
module Todo
# Todo respository used to persist todos to data file
class TodoRepository
attr_accessor :data_file_path, :todos
def initialize
@todos = []
end
def self.new_with_data_from(data_file_path)
todo_repo = TodoRepository.new
todo_repo... | true |
6e7f548c85c572a997164260e7032f6df89d6ae9 | Ruby | markpoon/genye | /lib/sequence.rb | UTF-8 | 1,906 | 2.921875 | 3 | [] | no_license | class Sequence
include DataMapper::Resource
property :id, Serial
has n, :chromosomes
belongs_to :user
def self.parse(txt)
snps={}
# creates a hash with 1 to 22, x, y and mitochondrial keys with empty hashes
[(1..22).collect(&:to_s), "X", "Y", "MT"].flatten.each{|chromosome|snps[chromosome.in... | true |
9e0912c7ce3bd842db6c37151671073c12d7f038 | Ruby | alenia/mathese | /spec/basic_recursive_methods_spec.rb | UTF-8 | 629 | 3.546875 | 4 | [] | no_license | require 'basic_recursive_methods'
describe 'basic recursive methods' do
include BasicRecursiveMethods
describe "#fib(n)" do
it "should return 0 if n = 0 and 1 if n = 1" do
fib(0).should == 0
fib(1).should == 1
end
it "should return fib(n-1) + fib(n-2) if n > 1" do
20.times do |n|
... | true |
186ac8654569b50e0099177fad028f009ebbaabd | Ruby | denisseai/stacks-queues | /lib/queue.rb | UTF-8 | 2,101 | 3.421875 | 3 | [] | no_license | class Queue
def initialize
@store = Array.new(20)
@front = -1
@back = -1
@size = 20
# @empty = true
# @front = @back = 0
end
def enqueue(element)
if ((@front == 0 && @back == @size - 1) || (@back == (( @front - 1) % ( @size - 1))))
raise ArgumentError
elsif (@front == - 1)
... | true |
14bb8d5225ec35632b58ccf7e27cfd3078b9fd76 | Ruby | zigvu/chia | /ruby/create_dataset_split.rb | UTF-8 | 1,425 | 3 | 3 | [] | no_license | #!/usr/bin/env ruby
require_relative 'classes/ConfigReader.rb'
require_relative 'classes/DatasetCreator.rb'
if __FILE__ == $0
if ARGV.count < 3
puts "Create data set for caffe training/testing"
puts " "
puts "Usage: ./create_dataset_split.rb config.yaml inputFolder outputFolder"
puts " "
puts " If th... | true |
ba51144084e426cc3d4063485defecd043e938fd | Ruby | EPrenzlin/ruby-objects-has-many-through-lab-onl01-seng-pt-030220 | /lib/doctor.rb | UTF-8 | 407 | 3.34375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
class Doctor
attr_accessor :name
@@all = []
def self.all
@@all
end
def initialize(name)
@name = name
@@all << self
end
def appointments
Appointment.all.select do |a|
a.doctor == self
end
end
def new_appointment(patient, date)
Appointment.new(date,patient, s... | true |
1fe9ec28e18b08653f5d224794af1712d3e2bb65 | Ruby | NU-CBITS/redcap | /test/test_redcap.rb | UTF-8 | 1,593 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class RedcapTest < Minitest::Test
REDCAP_HOST = "https://redcap.example.com"
REDCAP_TOKEN = "abcd1234"
def setup
ENV['REDCAP_HOST'] = REDCAP_HOST
ENV['REDCAP_TOKEN'] = REDCAP_TOKEN
@redcap = Redcap.new
end
def teardown
ENV['REDCAP_HOST'] = nil
ENV['REDCAP_TOKEN'] =... | true |
07acf74d3f5f10e6469175ac80d6c936dac98393 | Ruby | pharaonick/ls_101 | /prep/supplementary/chris_pine/gets_name_length.rb | UTF-8 | 790 | 4.28125 | 4 | [] | no_license | =begin
puts 'What\'s your full name?'
name = gets.chomp
puts 'Whoa, ' + name + ', you have ' + name.length.to_s + ' characters in your name!' # or...
puts "Whoa #{name}, you have #{name.length} characters in your name..."
=end
puts 'What\'s your first name?'
first_name = gets.chomp
puts 'What\'s your middle name?'
mid... | true |
3dcaa9b6e4e6baa5def516b554ee8da9d5e21620 | Ruby | lord-sumit/central_repo | /ruby/interest_difference.rb | UTF-8 | 253 | 3.046875 | 3 | [] | no_license | class Interest
attr_reader :rate
@rate = 10
def initialize(principal, time)
@principal = principal
@time = time
end
def simply
principal * rate * time
end
def compoundedly
principal * (1 + rate)**n - principal
end
end
| true |
92776a0443fd74f5614f22ab8aec84cc1a632575 | Ruby | traviswalkerdev/launch-school-intro | /more_stuff/ex5_argument_error.rb | UTF-8 | 217 | 3.140625 | 3 | [] | no_license | def execute(block)
block.call
end
execute { puts "Hello from inside the execute method!" }
# Gives an ArgumentError because the parameter is missing the ampersand
# necessay for a block to be used as a parameter.
| true |
c074794f279c8fe7c038bf45488540409a2c2266 | Ruby | GoodBoyNYC/collections_practice-v-000 | /collections_practice.rb | UTF-8 | 782 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def sort_array_asc(var)
var.sort
end
def sort_array_desc(var)
var.sort do |a,b|
b<=>a
end
end
def sort_array_char_count(var)
var.sort do |a,b|
a.length <=> b.length
end
end
def swap_elements(var)
one = var[1]
var[1] = var[2]
var[2] = one
return var
end
def reverse_array(var)
rav = []
r... | true |
e001487794e4f086ae355ce0e6bc106f3e99dda1 | Ruby | sovetnik/cooker | /app/models/item.rb | UTF-8 | 633 | 2.71875 | 3 | [] | no_license | class Item < ActiveRecord::Base
belongs_to :user
belongs_to :product
validates :quantity, numericality: { greater_than_or_equal_to: 0 }, presence: true
scope :owned, -> { where(user_id: User.current.id) }
def description
product = self.product
product.description
end
def name
product = sel... | true |
ce95c3c0380a160bb90af06b866db19fd548c3f4 | Ruby | camelpunch/bintray-resource | /lib/bintray_resource/upload.rb | UTF-8 | 1,132 | 2.71875 | 3 | [
"Apache-2.0"
] | permissive | require 'uri'
require_relative 'sleeper'
module BintrayResource
class Upload
FailureResponse = Class.new(StandardError)
SUCCESS = (0..399)
ALREADY_EXISTS = 409
attr_reader :http, :sleeper, :retries
private :http, :sleeper, :retries
def initialize(http:, sleeper: Sleeper.new, retries: 10)
... | true |
3ee074c1a0ce387d778ab081f4d7ecda152c7a32 | Ruby | MrRadish/salama | /lib/virtual/block.rb | UTF-8 | 2,563 | 3.265625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Virtual
# Think flowcharts: blocks are the boxes. The smallest unit of linear code
# Blocks must end in control instructions (jump/call/return).
# And the only valid argument for a jump is a Block
# Blocks form a graph, which is managed by the method
class Block
def initialize(name , method )
... | true |
0a74eda0f8e3d7ba8189399a3655f18645e07a42 | Ruby | jonathanbouren/LS_Ruby | /RB101/Lesson4_ruby_collections/l4_a7_3.rb | UTF-8 | 1,318 | 4.09375 | 4 | [] | no_license | question = "How to make a method that can count the number of characters."
def count_characters(string_variable, selected_character)
character_count = ''
count = 0
current_character = ''
loop do
break if count == string_variable.size
current_character = string_variable[count]
if current_character == s... | true |
08bb5f86c839b0d50331756d024992e84fb0c971 | Ruby | GregJMitchell/war_or_peace | /lib/game.rb | UTF-8 | 2,659 | 4.125 | 4 | [] | no_license | require './lib/deck'
require './lib/card'
require './lib/player'
require './lib/turn'
class Game
attr_reader :big_deck, :deck1, :deck2, :player1, :player2, :turn_count
def initialize
@big_deck = []
@deck1 = deck1
@deck2 = deck2
@player1 = player1
@player2 = player2
@turn_count = 0
end
... | true |
ae34f15b36957f4ad1db1d457ff6a8b0a11271ca | Ruby | smeds1/Ruby_Practice | /Unit1/isItATriangle.rb | UTF-8 | 318 | 3.625 | 4 | [] | no_license | #Sam Smedinghoff
#3/8/18
#isItATriangle.rb - determine if three numbers could be sides of a triangle
puts "Enter side A: "
a = gets.strip.to_f
puts "Enter side B: "
b = gets.strip.to_f
puts "Enter side C: "
c = gets.strip.to_f
small = [a,b,c].min
big = [a,b,c].max
middle = a + b + c - small - big
puts small + middle... | true |
ab1c44aefd541b2064ed60898564590b0612ec14 | Ruby | ghalley/advent_of_code | /2015/day_15.rb | UTF-8 | 3,437 | 3.515625 | 4 | [] | no_license | source_data = [{name: 'Sugar', capacity: 3, durability: 0, flavor: 0, texture: -3, calories: 2},
{name: 'Sprinkles', capacity: -3, durability: 3, flavor: 0, texture: 0, calories: 9},
{name: 'Candy', capacity: -1, durability: 0, flavor: 4, texture: 0, calories: 1},
{name: 'Choco... | true |
97be2dd5938641a0fa4edb153803b352ab0a0502 | Ruby | cartoloupe/census-data-sample | /lib/helpers.rb | UTF-8 | 394 | 2.6875 | 3 | [] | no_license | require_relative 'globals'
module Helpers
def format_number(number)
whole, decimal = number.to_s.split('.')
whole = whole.to_s.reverse.gsub(/([0-9]{3}(?=([0-9])))/, "\\1#{','}").reverse
if decimal.nil?
return whole
else
return whole + '.' + decimal
end
end
def get_concept(id)
... | true |
e91f1e22c605a2bcf9068329cc60217e0f370c0b | Ruby | prepor/green | /spec/green_spec.rb | UTF-8 | 874 | 2.5625 | 3 | [] | no_license | require 'spec_helper'
describe Green do
describe ".spawn" do
it "should spawn greens" do
g = Green.spawn do
:hello
end
g.join.must_equal :hello
end
end
describe "sleep" do
it "should set sleep" do
t = Time.now
Green.spawn do
Green.sleep 0.1
end.joi... | true |
190ee9abe0bb7051ca5830a3aaf87f5e2482eea9 | Ruby | bestwebua/codewars | /ruby/alphabet_war_airstrike_letters_massacre.rb | UTF-8 | 1,981 | 4.28125 | 4 | [] | no_license | =begin
Alphabet war - airstrike - letters massacre by Vladislav Trotsenko.
There is a war and nobody knows - the alphabet war!
There are two groups of hostile letters. The tension between left side letters
and right side letters was too high and the war began.
Write a function that accepts fight string consists of on... | true |
faf2f0b4455c076cf94216c3bc5656111b79506b | Ruby | xronos-i-am/rs_path_tokenizer | /lib/rs_path_tokenizer/tokenizer.rb | UTF-8 | 4,280 | 2.6875 | 3 | [
"MIT"
] | permissive | module RsPathTokenizer
class Tokenizer
PT_DEBUG = false
# PT_DEBUG = true
def initialize(tokens = nil)
return if tokens.nil?
@single_tokens = {}
tokens.keys.each do |t|
parts = url2token(t)
st = parts[0]
raise Error.new('Token cant starts with asterisk') if st ==... | true |
a9abb8b68b667c802317e237c5521947a425999a | Ruby | kellysouza/Word-Guess | /word_guess.rb | UTF-8 | 5,241 | 3.578125 | 4 | [] | no_license | # Monalisa and Kelly's word guess game
require 'colorize'
require 'colorized_string'
require 'rainbow'
class GameLevel
attr_accessor :easy, :medium, :difficult, :default
def initialize
@easy = ["Dog","Cat", "Bear", "zoo"]
@medium = ["Cake","Book","Smile"]
@difficult = ["Coconut","Pineapple"]
@defa... | true |
261709d9f4bfe81118d4bccde07435ed75889939 | Ruby | MaksimPW/hola_maksim | /spec/hola_maksim_spec.rb | UTF-8 | 385 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe 'SimpleTest' do
it 'should hi' do
Hola.hi.should == 'hello world'
end
it 'should hi with english' do
Hola.hi('english').should == 'hello world'
end
it 'should hi with spanish' do
Hola.hi('spanish').should == 'hola mundo'
end
it 'should hi with russian' do
... | true |
5b8a07e0e49d61f7c5dfefb6a4e8107fba83ff4c | Ruby | wlhood/RB100 | /basics_exercises/var_scope/var_scope2.rb | UTF-8 | 153 | 3.59375 | 4 | [] | no_license | a = 7
def my_value(a)
a+= 10
end
my_value(a)
puts a
#myvalue(a) = 17, but it doesn't get printed to console...
# a still equals 7, so 7 gets printed | true |
73529e105d74a8078db22aba92594c91633d74ca | Ruby | fabtasticwill/Bot | /test.rb | UTF-8 | 2,865 | 2.78125 | 3 | [] | no_license | require 'socket'
require_relative 'sandbox'
class SimpleIrcBot
def initialize(server, port, channel)
@channel = channel
@socket = TCPSocket.open(server, port)
say "NICK WillBot"
say "USER willbot 0 * WillBot"
say "JOIN ##{@channel}"
say_to_chan "#{1.chr}ACTION is here to help#{1.chr}"
end
... | true |
df50b7587732a880e7d6d5f6ca4a32559709795e | Ruby | sasdevs/ruby-course | /scratch.rb | UTF-8 | 981 | 3.734375 | 4 | [] | no_license | require 'pry'
x = ["cat", "hat", "bat"]
y = x.map do |word|
word.reverse
end
def z
"this"
"or this"
end
class A
def self.a_method
end
def a_method
end
end
A.a_method
A.new.a_method
VENUES = ['a', 'b', 'c']
class Ticket
VENUES = ["x", "y", "z"]
def self.show_venues
puts VENUES.object_id
p... | true |
b1b303cf0a7379aad190cb9eaa47a6930dcf196c | Ruby | takumiiwasaki1101/ruby_drill | /39.rb | UTF-8 | 311 | 3.796875 | 4 | [] | no_license | def near_ten(num)
remainder = num % 10
if remainder <= 2 || 8 <= remainder
puts "True"
elsif remainder <= 5
puts "10の倍数との差は#{remainder}です"
else
puts "10の倍数との差は#{10-remainder}です"
end
end
puts "数字を入力しよう!"
num = gets.to_i
near_ten(num) | true |
632fb96138075ec2fc6c50df35948034735196a3 | Ruby | chezou/pollynomial | /exe/text2mp3 | UTF-8 | 1,113 | 2.828125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'pollynomial'
require 'docopt'
doc = <<DOCOPT
text2mp3 is convert your text into mp3 using AWS Polly.
It is assumed to set AWS credentials in environmental variables.
Usage:
#{File.basename(__FILE__)} -h | --help
#{File.basena... | true |
6133cf97cf0a9a2bcabb9c532157ebbc89889ced | Ruby | IceDragon200/rm-macl | /lib/rm-macl/xpan/cube.rb | UTF-8 | 2,217 | 2.828125 | 3 | [
"MIT"
] | permissive | #
# rm-macl/lib/rm-macl/xpan/cube.rb
# by IceDragon
require 'rm-macl/macl-core'
require 'rm-macl/core_ext/module'
require 'rm-macl/xpan/surface'
module MACL #:nodoc:
class Cube
attr_reader :x, :y, :z, :width, :height, :depth
# all attributes should be forced to an integer :D
[:x, :y, :z, :width, :heig... | true |
9b35096503d1f1910b323a2a8b17e4f254fff7fc | Ruby | LiamCusack/nom_nom_nom | /lib/pantry.rb | UTF-8 | 758 | 3.25 | 3 | [] | no_license | require './lib/recipe'
class Pantry
attr_reader :stock
def initialize
@stock = {}
end
def stock_check(ingredient)
if @stock[ingredient] == nil
0
else
@stock[ingredient]
end
end
def restock(ingredient, amount)
if @stock.keys.include?(ingredient) == false
@stock[ingre... | true |
f7433469af9266872a3fc097c05ed450f12a0656 | Ruby | amacdougall/dungeon_fight | /map.rb | UTF-8 | 1,320 | 3.6875 | 4 | [] | no_license | # Classes defining rooms in the world model.
require 'pry'
require 'pry-nav'
# A map of the world, or at least an area.
class Map
attr_accessor :location
def initialize(data=nil)
@rooms = {}
@location = nil # current room
if data != nil
data["rooms"].each do |room_data|
room = Room.ne... | true |
93f27c3f0388971d1264e6453128c1760a65ca41 | Ruby | dsh0416/nano-weather | /web.rb | UTF-8 | 3,111 | 2.78125 | 3 | [
"MIT"
] | permissive | require 'json'
require 'mongo'
Mongo::Logger.logger.level = ::Logger::FATAL
while true
# puts 'INPUT PARAMETER'
# input = gets.chomp
# if input == '-1'
# exit(0)
# end
# if input == '0'
puts 'SENSITIVITY'
# input = gets.chomp.to_i
input = 3
db = Mongo::Client.new('mongodb://hacker:hack... | true |
33193e12ada376228e455a0fa3648351f5490891 | Ruby | AntonDementev/Thinknetica-Lessons | /Lesson 4/to_snake_case.rb | UTF-8 | 781 | 2.765625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'tempfile'
def snaked(str)
if str =~ /([a-z])([A-Z])/
upd_str = str.sub(/[a-z][A-Z]/, "#{$1}_#{$2}")
else
upd_str = str
end
upd_str.downcase
end
dir = Dir.new("./")
FileUtils.mkdir("old~") if !File.exist? "old~"
dir.each do |filename|
if filename =~ /.*\.rb/ && filename... | true |
19afc0500a6e6e7a9dfe0c126e3883462650bc94 | Ruby | alexgh123/ruby_on_the_web | /AAA_restart_webserver_asignment/server.rb | UTF-8 | 3,184 | 3.15625 | 3 | [] | no_license | require 'socket'
require 'json'
class Request
attr_accessor :method, :path, :protocol, :headers, :params
def initialize(client)
@client = client
@method, @path, @protocol = @client.gets.split(" ")
@headers = Hash.new
@body = ""
@params = Hash.new
read_headers
read_body
read_... | true |
aadfad7c3195e2e106924c25198cdf4d6cd0239f | Ruby | bruun-rasmussen/lazy_mapper | /lib/lazy_mapper/lazy_mapper.rb | UTF-8 | 10,504 | 3.453125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # frozen_string_literal: true
#
# Wraps a Hash or Hash-like data structure of primitive values and lazily maps
# its attributes to semantically rich domain objects using either a set of
# default mappers (for Ruby's built-in value types), or custom mappers which
# can be added either at the class level or at the insta... | true |
66009a8b00b6b0b3d1b92ba3b10ff164cd8de5e8 | Ruby | HarryCarton/Boris_bike | /spec/Bojo_docking_spec.rb | UTF-8 | 1,479 | 3.0625 | 3 | [] | no_license | require 'Bojo_docking'
describe DockingStation do
describe '#release_bike' do
it 'responds to release_bike' do
dock = DockingStation.new
bike = Bike.new
dock.dock_bike(bike)
expect(dock.release_bike).to respond_to()
end
it 'checking if .release_bike returns stored bike' d... | true |
167c658f409ded4c0dd72eb1a19b1207628ad876 | Ruby | RedCrow97/the-odin-project | /mastermind/mastermind.rb | UTF-8 | 2,770 | 3.71875 | 4 | [] | no_license | class Mastermind
require './colorize_terminal.rb'
def initialize
arr = []
colors = ["R","B","G","Y","C","P"]
computer = []
4.times { arr << rand(6) }
arr.each { |x| computer << colors[x] }
@master = computer
@color_blocks = {"R" => "#{redb(" ")}", "Y" => "#{yellowb(" ")}", "G" => "#{gre... | true |
1ba481b74f675cce87660c78afde7b0aaa7080fd | Ruby | ryanjkirkland/address-bloc | /models/entry.rb | UTF-8 | 363 | 3.28125 | 3 | [] | no_license | class Entry
#SRP: To wrap around 3 pieces of 'entry' data and provide an interface to
#access said data
attr_accessor :name, :phone_number, :email
def initialize(name, phone_number, email)
@name = name
@phone_number = phone_number
@email = email
end
def to_s
"Name: #{name}\nPhone Number: #... | true |
cb3833975181f5cbac65bc060dbb5ec4d5a4c84d | Ruby | square/debug_socket | /lib/debug_socket.rb | UTF-8 | 1,784 | 2.53125 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-generic-cla"
] | permissive | # frozen_string_literal: true
require "debug_socket/version"
require "socket"
require "time"
module DebugSocket
@thread = nil
@pid = Process.pid
def self.logger=(logger)
@logger = logger
end
def self.logger
return @logger if defined?(@logger)
require "logger"
@logger = Logger.new(STDERR)
... | true |
b3157053c70458c6c86e14a3a4467ed39a5bf432 | Ruby | ivaMm/ruby-challenges | /02-challenges/02-polydivisible/spec/polydivisible_spec.rb | UTF-8 | 428 | 2.640625 | 3 | [] | no_license | # frozen_string_literal: true
require 'polydivisible'
describe 'polydivisible?' do
it 'should take 2 parameter' do
expect(method(:polydivisible?).arity).to eq(2)
end
it 'should return true or false' do
expect(polydivisible?(1232, 10)).to eq(true)
expect(polydivisible?(1233, 10)).to eq(false)
ex... | true |
3a40fb2cfe59982665d78b652d96927ae2cf63c4 | Ruby | mehagel/phase_one_additional_stuff | /2013-06-14_fri/nested_array.rb | UTF-8 | 937 | 3.234375 | 3 | [] | no_license | # def tic_tac_toe
# a=["x", "o", "x", "o", "x", "x", "o", "x", "o"]
# 1.upto(10) do
# tic_tac_toe = a.sample(9)
# p board_grid = Array.new(3) { tic_tac_toe.shift(3) }
# end
# end
# tic_tac_toe
def convert_roster_format
roster = [["Number", "Name", "Position", "Points per Game"],
... | true |
c9e2231447e0da576405de27b9fe0c87dc4fc976 | Ruby | petersng/oliviacha.com | /_plugins/reel_generator.rb | UTF-8 | 4,009 | 2.796875 | 3 | [] | no_license | require "vimeo"
require "uri"
require "json"
module Jekyll
class ReelsPage < Page
def initialize(site, base, dir, name, sections)
super(site, base, dir, name)
@sections = sections
self.data['sections'] = sections
end
end
class ReelsGenerator < Generato... | true |
7ed22094c22aa8fd9dc64a921c68d0d729736b67 | Ruby | pablosky/poker | /spec/models/hand_spec.rb | UTF-8 | 5,055 | 2.5625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Hand, type: :model do
let(:straight) {[{"number"=>"10", "suit"=>"spades"}, {"number"=>"9", "suit"=>"hearts"}, {"number"=>"8", "suit"=>"hearts"},
{"number"=>"7", "suit"=>"spades"}, {"number"=>"6", "suit"=>"hearts"}]}
let(:edge_straight) {[{"number"=>"A", "suit"=... | true |
106a6e494a511d5f248c37507ac8bb4f4e698205 | Ruby | DamienRobert/dotfiles | /script/git/git-changelog.rb | UTF-8 | 2,276 | 2.90625 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"MIT"
] | permissive | #!/usr/bin/env ruby
#encoding: utf-8
#Stolen from http://felipec.wordpress.com/2012/10/14/progress-and-ruby/
#output a changelog format
#Usage: git-changelog [-va] [branch]
#-a: for each release add a summary of authors contributions
#-v: group commits by date and authors
require 'date'
require 'shellwords'
tags = {... | true |
ceaccc7fdbe793b6906ea49c597814831d7006aa | Ruby | miaoshan/ttt-8-turn-bootcamp-prep-000 | /lib/turn.rb | UTF-8 | 1,131 | 4.4375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def display_board(board)
return board
end
def display_board(board)
puts " #{board[0]} | #{board[1]} | #{board[2]} "
puts "-----------"
puts " #{board[3]} | #{board[4]} | #{board[5]} "
puts "-----------"
puts " #{board[6]} | #{board[7]} | #{board[8]} "
end
def move(board,input,player_characte... | true |
ca01fda628e86394ef81c502ad7a4d4b2d6a1b5d | Ruby | aaronrtrevino12/ttt-with-ai-project-v-000 | /lib/game.rb | UTF-8 | 2,567 | 3.921875 | 4 | [] | no_license | class Game
attr_accessor :board, :player_1, :player_2
WIN_COMBINATIONS = [
[0,1,2], # top row
[3,4,5], # center row
[6,7,8], # bottom row
[0,3,6], # left column
[1,4,7], # center column
[2,5,8], # right column
[0,4,8], # diagonal (top left to bottom right)
[6,4,2] # diagonal (botto... | true |
df9efd49d6558771c71eaf6931000ba498207388 | Ruby | rouxcaesar/bradfield-networking | /lab-parsing-network-packets/pcap-solution.rb | UTF-8 | 2,184 | 3.03125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'pcap'
require 'pry'
class HeaderParser
attr_accessor :file_handle, :endian, :header_length
def initialize(endian, file_handle)
@endian = endian
@file_handle = file_handle
end
def read_next(f, bytes, endian)
s = f.read(bytes).unpack('H*').first
if endian == :littl... | true |
40d245236d8680b91e781bca49573c249ec7d8df | Ruby | jtruong2/date_night | /lib/Node.rb | UTF-8 | 859 | 3.578125 | 4 | [] | no_license | class Node
attr_reader :left,
:right
attr_accessor :data,
:title
def initialize(data, title)
@data = data
@title = title
@left = nil
@right = nil
end
def insert_2(rating, title)
if rating > @data && @right == nil
@right = Node.new(rating, title)
els... | true |
051f83151a3b85f881b099fa7bf8a9506da09712 | Ruby | joy109lee/mastermind_project | /lib/mastermind.rb | UTF-8 | 462 | 3.453125 | 3 | [] | no_license | require_relative "code"
class Mastermind
def initialize(length)
@secret_code = Code.random(length)
end
def print_matches(code)
puts code.num_exact_matches(@secret_code)
puts code.num_near_matches(@secret_code)
end
def ask_user_for_guess
puts "Enter a code"
... | true |
da6d86b1ef1ffe0dc4b086d6aa2446e61fd321f5 | Ruby | nemestny/Geekbrains | /Ruby/05_homework/task03.rb | UTF-8 | 577 | 3.375 | 3 | [] | no_license | require_relative 'user'
##
# class for Group of Users
class Group
attr_accessor :users
def initialize(*users)
@users = users
end
def list
@users.map(&:to_s)
end
end
user1 = User.new(surname: 'Ivanov',
name: 'Ivan',
middle_name: 'Ivanovich')
user2 = User.new(surna... | true |
ae85523e8bf05b6c3e291c138b3b4f25f533628a | Ruby | smcabrera/katas | /ruby/nth-prime/nth_prime_test.rb | UTF-8 | 448 | 2.984375 | 3 | [] | no_license | require 'minitest/autorun'
require_relative 'primes'
class TestPrimes < MiniTest::Unit::TestCase
def test_first
assert_equal 2, Primes.nth(1)
end
def test_second
assert_equal 3, Primes.nth(2)
end
def test_sixth_prime
assert_equal 13, Primes.nth(6)
end
def test_big_prime
assert_equal 10... | true |
63b14c4397fd5f3ef9f5a6cdd91cd28c5876028f | Ruby | auranet/coloxchange | /app/models/colocation_quote.rb | UTF-8 | 1,133 | 2.59375 | 3 | [] | no_license | class ColocationQuote < Quote
has_many :quote_data_centers, :dependent => :destroy, :foreign_key => :quote_id
class << self
def bandwidth_options
# ["1 mbps", "2 - 5 mbps", "6 - 9 mbps", "10+ mbps", "50+ mbps", "100+ mbps", "250+ mbps", "500+ mbps"]
BandwidthQuote.internet_options
end
def ... | true |
6bdd316c8b2bb935ac82ef13dd9cd9bb55472298 | Ruby | billyott/programming-univbasics-nds-green-grocer-part-1-nyc01-seng-ft-091420 | /lib/grocer.rb | UTF-8 | 812 | 3.34375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def find_item_by_name_in_collection(name, collection)
# Implement me first!
#
# Consult README for inputs and outputs
item_data = nil
collection.each do |item|
if item[:item] == name
item_data = item
end
end
return item_data
end
def consolidate_cart(cart)
# Consult README f... | true |
52341507596706f482d5834762a84e2665c5c013 | Ruby | katorie/2min_coding | /desing_patterns/factory.rb | UTF-8 | 2,253 | 3.875 | 4 | [] | no_license | class Duck
def initialize(name)
@name = name
end
def eat
puts("アヒル #{@name} は食事中")
end
def speak
puts("アヒル #{@name} はガーガー鳴く")
end
def sleep
puts("アヒル #{@name} は寝ています")
end
end
class Frog
def initialize(name)
@name = name
end
def eat
puts("カエル #{@name} は食事中")
end
d... | true |
9a39234d0c01b81b82598056c5391edf1b369738 | Ruby | localshred/eventually | /examples/strict.rb | UTF-8 | 470 | 3.140625 | 3 | [] | no_license | $LOAD_PATH << File.expand_path('../lib', File.dirname(__FILE__))
require 'eventually'
class Door
include Eventually
enable_strict!
emits :opened, :closed
end
door = Door.new
door.on(:opened) do
puts 'door was opened'
end
door.on(:closed) do
puts 'door was closed'
end
begin
# This will raise an error!
... | true |
7549b187e3880f2e41dd1f41b656596b4ebe3eef | Ruby | JoshCheek/i_like_mustaches | /lib/i_like_mustaches/quick_note.rb | UTF-8 | 1,347 | 3.1875 | 3 | [
"WTFPL"
] | permissive | class ILikeMustaches
class QuickNote
class Collection
def initialize(notes=[])
@notes = notes
end
def add(*args)
notes << QuickNote.new(*args)
self
end
def filter(searches)
filtered_notes = notes.select do |note|
searches.all? do |search|
... | true |
709fc77db2583f9eebbfaa690fa704cfcfc16f14 | Ruby | piotrmurach/tty-progressbar | /spec/unit/render_spec.rb | UTF-8 | 601 | 2.625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
RSpec.describe TTY::ProgressBar, "#render" do
let(:output) { StringIO.new }
it "pads out longer previous lines" do
progress = TTY::ProgressBar.new ":current_byte" do |config|
config.output = output
end
progress.advance(1)
progress.advance(1_048_574)
progres... | true |
b27055840c1b9f1461b08a64511d52dd742f8277 | Ruby | patrick99e99/lpcinator | /lib/parameter_modifier.rb | UTF-8 | 1,314 | 3.125 | 3 | [] | no_license | module LPCinator
class ParameterModifier
def self.value_for(original, target, options)
return original unless target
new(original, target, options).return_value
end
def initialize(original, target, options)
@original = original
@target = target
@min = options.fetch(:... | true |
007dddcb49c8c4cdc7b2fc4359b0898dc590871b | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/8136394817ba431ea438df0cec989887.rb | UTF-8 | 779 | 4.03125 | 4 | [] | no_license | class Statement
def initialize(text)
@text = text
end
def _shouting?
_all_uppercase?(_alphabetic_characters_from)
end
def _questioning?
text.end_with?('?')
end
def _silent?
text.strip.empty?
end
private
attr_reader :text
def _alphabetic_characters_from
alphanumeric_chara... | true |
3d2288545909b56ee2b713db9b3d724e73f5efc7 | Ruby | Rosendito/rails-platzi-principiante | /app/controllers/welcome_controller.rb | UTF-8 | 180 | 2.5625 | 3 | [] | no_license | class WelcomeController < ActionController::Base
def hello
first_pet = Pet.first
@title = "Hola, soy #{first_pet.name} y soy un #{first_pet.breed}"
end
end | true |
1fe46aee0ea38aebd73d5466ce8af2df78f5455a | Ruby | Sergyurch/ruby_problems | /spec/caesar_cipher_spec.rb | UTF-8 | 1,118 | 3.578125 | 4 | [] | no_license | require './lib/caesar_cipher.rb'
describe "#caesar_cipher" do
it 'handles every letter of the alphabet' do
expect(caesar_cipher('abcdefghijklmnopqrstuvwxyz', 3)).to eql('defghijklmnopqrstuvwxyzabc')
end
it 'handles every uppercase letter of the alphabet' do
expect(caesar_cipher('abcdefghijklmnopqrstuvwx... | true |
86f6d561dd2f4aac64a2b22568f76d5e7ecdd305 | Ruby | c80609a/c80_push | /app/helpers/c80_push/page_dealers/dealers_left_list_helper.rb | UTF-8 | 2,839 | 2.640625 | 3 | [
"MIT"
] | permissive | module C80Push
module PageDealers
module DealersLeftListHelper
# Выдать html unordered nested list Дилеров (включая Офисы),
# разложенный по Регионам, построенный
# на основе данных +rdo+ - Regions-Dealers-Offices.
# Список выводится слева от карты.
# (**) Не выводим регионы, у кото... | true |
9f8955864fc21f2473b30b1af4515e3dcd7e3900 | Ruby | JArthurJohnston/Timekeeper_API | /app/models/activity.rb | UTF-8 | 1,834 | 2.75 | 3 | [] | no_license | require_relative 'date_range'
require_relative '../../app/models/modules/date_time_helper'
class Activity < ActiveRecord::Base
include DateTimeHelper
belongs_to :story_card
belongs_to :timesheet
belongs_to :user
BILLING_CYCLE = 15.0 * 60
class << self
def now
return self.new(start_time: Date... | true |
99b95039197092da13928eb14f3d9c5a274b1cd7 | Ruby | jameschen00/EMBC01 | /util/lib/Common.rb | UTF-8 | 7,683 | 2.96875 | 3 | [] | no_license | ##
# BeaconTool Utilities - common helper functions for BeaconTool modules
module BeaconTools
##
# Display the parameter values for one device on the console
#
# @param [CSV::Row] parameters - parameters from CSV file for this device
# @return nothing
def self.print_parameters(parameters)
... | true |
34c1c0df9b673436e6e031f9841852b137a19d08 | Ruby | Trishthedish/CSV-Sample-Code | /ReadPlanets.rb | UTF-8 | 668 | 2.828125 | 3 | [] | no_license | # ReadPlanets.rb
require 'csv'
require 'awesome_print'
require './SolarSystem.rb'
planets = []
counter = 1
CSV.open("planets.csv", 'r').each do |line|
if counter !=1
planets << Planet.new(:name, :distance, :mass, :moons, :diameter)
ap line[0]
end
counter += 1
end
puts planets
# also would work do us... | true |
15aabdff2b7faf7e750cee60e25dd6d0554e66b7 | Ruby | rtopitw/sport.db.ruby | /lib/sportdb/utils.rb | UTF-8 | 13,391 | 2.921875 | 3 | [
"LicenseRef-scancode-public-domain"
] | permissive | # encoding: utf-8
### note: some utils moved to worldbdb/utils for reuse
module SportDb::FixtureHelpers
def is_postponed?( line )
# check if line include postponed marker e.g. =>
line =~ /=>/
end
def is_round?( line )
line =~ SportDb.lang.regex_round
end
def is_group?( line )... | true |
b22e932e173be52843e08afa6fd2865d7f32eb3f | Ruby | stanwong86/Ruby | /learn_ruby-master/09_book_titles/book.rb | UTF-8 | 376 | 3.59375 | 4 | [] | no_license | class Book
attr_accessor :title
def initialize
end
def title=(title)
articles = ['the','a','an']
conjunctions = ['and']
prepositions = ['in','of']
books = title.split(" ")
books.map{|book| book.capitalize! unless articles.include?(book) || conjunctions.include?(book) || prepositions.include?(book) }
... | true |
4411da957f5a57f069b0e7003f1b08a5fe6fc63a | Ruby | PeterNet1/Ruby-course | /Task3/sample_spec.rb | UTF-8 | 1,745 | 3.34375 | 3 | [] | no_license | describe 'Third task' do
describe RationalSequence do
it 'can calculate the first rational number' do
expect(RationalSequence.new(1).to_a).to eq ['1/1'.to_r]
end
it 'can calculate the 4th rational number' do
expect(RationalSequence.new(4).to_a).to eq %w(1/1 2/1 1/2 1/3).map(&:to_r)
end
... | true |
5208ca95add7d90e6b7f9ffff3649528c7af3861 | Ruby | SaraSpink/sinatra_prime_sifter | /spec/sinatra_prime_spec.rb | UTF-8 | 454 | 2.875 | 3 | [] | no_license | require('rspec')
require('sinatra_prime')
describe('Prime#check') do
it("Returns true if number is prime") do
list = Prime.new(5)
expect(list.check?).to eq(true)
end
it("returns a boolean if you use the attribute variable") do
number = Prime.new(5)
expect(number.check?).to eq(true)
end
it("... | true |
11fba62ed122d3b3fdea8ab089dd63aa6339ad36 | Ruby | reedlaw/ruby-mmo | /players/cloud.rb | UTF-8 | 1,519 | 3.265625 | 3 | [] | no_license | module Cloud
HEALTH_INDEX = [100,110,125,145,170,195,225,260]
def to_s
"Z Cloud Strife"
end
def move
if full_health? && !winning
kill_or_leader
else
[:rest]
end
end
def opponents
Game.world[:players].select{|p| p!=self && health(p) > 0}
end
def lowest_hp
... | true |
6b14c6e13c74cff9b669f93da6194098acc6cb12 | Ruby | bhosley/2017-Fall_Flatiron_Bootcamp | /playlister-sinatra-v-000/app/models/song.rb | UTF-8 | 396 | 2.875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song < ActiveRecord::Base
belongs_to :artist
has_many :song_genres
has_many :genres, through: :song_genres
def slug
self.name.downcase.split(' ').join('-')
end
def self.find_by_slug(slug)
nocaps = ['the','with','and', 'a']
song_name = slug.split('-').map{|word| nocaps.include?(word) ? wo... | true |
70e3de467577ad4bd37bd39af7ccf0023f5855d2 | Ruby | teeaki/fix_tsv_conflict | /lib/fix_tsv_conflict/conflict.rb | UTF-8 | 1,805 | 2.890625 | 3 | [] | no_license | require 'csv'
require "fix_tsv_conflict/refinements/tsv"
require "fix_tsv_conflict/refinements/colored_string"
module FixTSVConflict
class Conflict
using Refinements::TSV
using Refinements::ColoredString
attr_reader :left, :lbranch, :right, :rbranch, :before
def initialize(left, lbranch, right, rbr... | true |
793835d7d9d15f99e12d8a7996096771fd3f32f9 | Ruby | ak2316-cam/website | /src/_plugins/random.rb | UTF-8 | 270 | 2.53125 | 3 | [] | no_license | # Plugin to let me randomly shuffle entries in a collection.
#
# See https://stackoverflow.com/a/27179386/1558022
module Jekyll
module ShuffleFilter
def shuffle(array)
array.shuffle
end
end
end
Liquid::Template.register_filter(Jekyll::ShuffleFilter)
| true |
285bfae1b26bcf45ac9960725f88557a923169bb | Ruby | watashi/AlgoSolution | /codeforces/ac/0/070/B.rb | UTF-8 | 236 | 3 | 3 | [] | no_license | n = gets.to_i
s = gets.scan(/.*?[\.?!]/).map{|_| _.strip.size}
x, y = 0, 0
s.each do |_|
if _ > n
puts :Impossible
exit
elsif x == 0
x = _
else
x += 1 + _
if x > n
x = _
y += 1
end
end
end
if x > 0
y += 1
end
p y
| true |
a5fc0fa1ef7049fd13240480010d4dedf9e32219 | Ruby | astathopoulos/adventofcode | /2015/day_14/quiz_2.rb | UTF-8 | 1,061 | 3.09375 | 3 | [] | no_license | $reindeers = {}
$last_second = 2503
File.open('input.txt', 'r').each_line do |line|
reindeer, speed, duration, rest =
line.strip.scan(
/(\w+) can fly (\d+) km\/s for (\d+) seconds, but then must rest for (\w+) seconds\./).flatten
$reindeers[reindeer] = {
speed: speed.to_i,
duration: duration.to_i... | true |
70e519b2dfe0fe70095adb2111b8ca86f79aed8a | Ruby | HoffsMH/sales_engine_sql | /lib/modules/find_by.rb | UTF-8 | 809 | 2.53125 | 3 | [] | no_license | module FindBy
def find_by_last_name(last_name)
find_by(:last_name, last_name)
end
def find_by_first_name(first_name)
find_by(:first_name, first_name)
end
def find_by_id(id)
id = id.to_i
find_by(:id, id)
end
def find_by_name(name)
find_by(:name, name)
end
def find_by_customer_id(cus... | true |
6515c2b2b92f4902f7e1dec5b325d257b4e23fab | Ruby | mooreniemi/infection | /spec/total_infection_spec.rb | UTF-8 | 1,488 | 2.828125 | 3 | [] | no_license | require 'spec_helper'
require 'user'
describe "total_infection" do
before(:each) do
# clear out our "database"
$users = []
end
let(:user) do
user = User.new
$users[user.id]
end
describe User do
it 'allows access to #id and #version' do
expect(user.id).to_not eq(nil)
expect(... | true |
b15f40c75498bb1b0f27d2b6fc604ee6fc05d26e | Ruby | myokoym/project_euler | /p034.rb | UTF-8 | 421 | 3.265625 | 3 | [] | no_license | #! ruby
def fact(n)
n == 0 ? 1 : n * fact(n - 1)
end
a = Array.new(10) {|i| i }.map {|v| [v.to_s, fact(v)] }
facts = Hash[*a.flatten(1)]
ans = 3.upto(9999999).select {|n| n.to_s.split(//).map {|v| facts[v] }.inject(:+) == n }
p ans
p ans.inject(:+)
__END__
1.upto(10000) do |n|
x = ("9" * n)
y = x.split(//)... | true |
fb15af924a9bf252d1b8f84ec24e0095bd70f7bc | Ruby | crest-cassia/oacis_nsga_module | /nsga/mutation.rb | UTF-8 | 2,361 | 3.140625 | 3 | [
"MIT"
] | permissive | module Mutation
# @myu = 0.5
#
def self.set_rate(myu=0.01, eta=15)
@myu = myu
@eta = eta
end
def self.mutate(chrom, random)
chrom.size.times.each{|i|
if random.rand < @myu
if chrom[i] == 0
chrom[i] = 1
else
chrom[i] = 0
end
end
}
... | true |
394ad10520c68c8c17035b2d7e84bfc4b7ea10ef | Ruby | Loic1204/wiki-starwars | /spec/perso_spec.rb | UTF-8 | 4,377 | 2.640625 | 3 | [
"MIT"
] | permissive | require_relative 'spec-helper'
require 'persos'
module Persos
describe Perso do
describe "#complete?" do
it "cree un personnage complet si tous les champs sont specifies" do
c = Perso.new( "Luke Skywalker",
"Tatooine",
"humain",
"Jedi",
"resistance",
... | true |
cb360da9309a18f38fde283cb89d31411551b326 | Ruby | svbarilov/PlayScanner | /GooglePlayScanner.rb | UTF-8 | 1,132 | 2.765625 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
process_pages = 15
start = 0
while(start < process_pages * 60)
# get "New Apps" HTML string
new_apps = Nokogiri::HTML(open('https://play.google.com/store/apps/collection/topselling_new_free?start=0')).to_s
# get array of app urls
app_urls = new_apps.scan(/href="(\/store\/ap... | true |
65619f6c74893dd0427210660688cd84fa40495b | Ruby | kradydal/Coder | /avg.rb | UTF-8 | 83 | 3.34375 | 3 | [] | no_license | array = [1,2,3]
sum = 0
array.each do |i|
sum += i
end
puts sum/array.count
| true |
6c082601a5d8d398e5408f0afda0b8b1ded1dcb4 | Ruby | hnaseem1/rubycodeacademy | /while.rb | UTF-8 | 43 | 2.953125 | 3 | [] | no_license | i = 0
while i < 5
i = i + 1
puts i
end
| true |
a47c1bd5a29e9d459bb641dd77e255ddef74da4e | Ruby | prabhakarbattula/selenium_web_driver | /test/helpers/common_methods.rb | UTF-8 | 1,977 | 2.625 | 3 | [] | no_license | module CommonMethods
def setup
@driver = Selenium::WebDriver.for :firefox
@base_url = "http://caregeneral.net/"
@accept_next_alert = true
@driver.manage.timeouts.implicit_wait = 30
end
def teardown
logout
@driver.quit
end
def element_present?(how, what)
@driver.find_element(how, w... | true |
53dedab68f7a7d7ecd71f2c541499fc0edf5cea3 | Ruby | swisscom/ruby-netsnmp | /lib/netsnmp/encryption/des.rb | UTF-8 | 2,038 | 2.6875 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
module NETSNMP
module Encryption
using StringExtensions
class DES
def initialize(priv_key, local: 0)
@priv_key = priv_key
@local = local
end
def encrypt(decrypted_data, engine_boots:, **)
cipher = OpenSSL::Cipher.new("des-cbc")
... | true |
4aa18e3a835b1be314f919c335efbf7af5fa5b8b | Ruby | Amanda-Katherine/120919-challenges | /challenge4.rb | UTF-8 | 960 | 3.953125 | 4 | [] | no_license | =begin
Use the method below that accepts an array
The method should return a hash where the keys are unique elements in the array
and the values are integers counting how often that element appeared in the array
=end
def frequency_count(a)
a.group_by{|element| element}.collect{|key, value| [key, value.length]}.to_h... | true |
95489439f8fafd183fc4795ea971ad608af7d276 | Ruby | azywong/p0_unit1_submission | /4_median_solo_challenge/my_solution.rb | UTF-8 | 2,726 | 4.15625 | 4 | [] | no_license | # U1.W3: SOLO CHALLENGE Calculate the Median!
# Complete each step below according to the challenge directions and
# include it in this file. Also make sure everything that isn't code
# is commented in the file.
# I worked on this challenge [by myself, with: ].
# 1. Pseudocode
# What is the input?
# an array
# ... | true |
01a3f4eedb3db87f9e53188c2c499e40a0b2e10d | Ruby | emacsway/ddd_sample_app_ruby | /domain/voyage/voyage_number.rb | UTF-8 | 190 | 2.546875 | 3 | [
"MIT"
] | permissive | require 'ice_nine'
require 'value_object'
class VoyageNumber < ValueObject
attr_reader :number
def initialize(number)
@number = number
IceNine.deep_freeze(self)
end
end
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.