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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
8839dbb599cf0582e2305de6e6ee5c32500c7b32 | Ruby | kasper/ratetea | /spec/models/user_spec.rb | UTF-8 | 5,399 | 2.78125 | 3 | [] | no_license | require 'spec_helper'
def create_tea_with_ratings(*scores, user)
tea = FactoryGirl.create(:tea)
scores.each do |score|
FactoryGirl.create(:rating, :score => score, :tea => tea, :user => user)
end
tea
end
def create_tea_with_rating(score, user)
create_tea_with_ratings(score, user)
end
def create... | true |
f83f12821074edc4609a42b57c806c20d8033147 | Ruby | hyperloop-rails/study-replication | /db-generator/falling-fruit/populate/populateUsers.rb | UTF-8 | 480 | 2.828125 | 3 | [] | no_license | ARGV.each do|a|
puts "Argument#{ARGV.index(a)}: #{a}"
end
num = ARGV[0]
num = num.to_i
o = [('a'..'z'), ('A'..'Z')].map(&:to_a).flatten
begin
puts "create user"
for i in 1..num
email = (0...8).map { o[rand(o.length)] }.join + "@example.com"
address = (0...16).map { o[rand(o.length)] }.join
... | true |
ca8f9c0f48fffbb021dc12b7478832e58dea4ba4 | Ruby | shailendrarjpt/Calc | /app/models/quote_price.rb | UTF-8 | 379 | 2.6875 | 3 | [] | no_license | class QuotePrice
include ActiveModel::Model
attr_accessor :role, :hours, :rate, :total
def initialize
@role = 0
@hours = 0
@rate = 0
@total = 0
end
def role
@role
end
def hours
@hours
end
def rate
@... | true |
6de69dacbb33c76b43b71b528be8a8be3fe4c30c | Ruby | gusmattos1/how_to_test_robot | /test_robot.rb | UTF-8 | 2,547 | 3.125 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './robot.rb'
class TestRobot < MiniTest::Test
def test_that_foreign_robot_needing_repairs_sent_to_station_1
# arrange
foreign_robot = Robot.new
foreign_robot.foreign_model = true
foreign_robot.needs_repairs = true
# act
exp... | true |
05eda5b95384b6412cd83a4298369a1c768c5e05 | Ruby | tristanbes/devops-life | /_plugins/tweet_tag.rb | UTF-8 | 867 | 2.84375 | 3 | [
"MIT"
] | permissive | # Tweet Liquid Tag
#
# Example:
# {% tweet 464180168303456256 %}
#
require 'net/http'
require 'json'
module Jekyll
class TweetTag < Liquid::Tag
#
#
#
def render(context)
if tag_contents = determine_arguments(@markup.strip)
tweet_id = tag_contents #
tweet_script_tag(tweet_id... | true |
f926b4769aa86942584664f02dd8c4e1ae29b6d7 | Ruby | lukebayes/asunit-legacy | /ruby/src/template_resolver.rb | UTF-8 | 2,199 | 2.5625 | 3 | [] | no_license |
require 'settings'
require 'erb'
module AsUnit
class TemplateResolver
attr_reader :template, :fullclass, :interfaces, :test_cases
attr_accessor :superclass, :display_object
def initialize(fullclass)
@fullclass = fullclass;
@classname = fullclass.split('.').pop
@template = template
@pack... | true |
af49c16d38da8b496e103d567ed2d008f6bfe802 | Ruby | deloristhompson/leaderboard | /spec/lib/leaderboard_spec.rb | UTF-8 | 928 | 2.875 | 3 | [] | no_license |
require 'spec_helper'
RSpec.describe Leaderboard do
let(:leaderboard) { Leaderboard.new}
describe ".new" do
it "has a name" do
expect(leaderboard.teams).to eq(leaderboard.name)
end
it "returns Team name" do
expect(leaderboard.team_objects[0].name).to eq("Packers")
end
it "returns... | true |
299e4048ccb6ca3c01521b092f01e5a35793d375 | Ruby | Matevito/Basic-ruby-proyects | /hangman/GameObj.rb | UTF-8 | 1,033 | 4.03125 | 4 | [] | no_license | require_relative "logicMethods"
class Hangman
# Game methods
attr_reader :secret_word
attr_accessor :word_output, :turn, :guesses, :wrong_words
def initialize
@guesses = 8
@turn = 1
@secret_word = Hangman.get_secret_word.downcase.split('')
@word_output = ('-' * secret_word.le... | true |
f0a09e8121300e28d1d7fb71e665b959910cf805 | Ruby | nicksieger/xmlbench | /lib/xmlbench/nokogiri/reader.rb | UTF-8 | 718 | 2.84375 | 3 | [] | no_license | require 'nokogiri'
class Harness
module Nokogiri
class XPath
def perform(xml_input)
reader = ::Nokogiri::XML::Reader(xml_input)
titles = []
text = ''
grab_text = false
reader.each do |elem|
if elem.name == "title"
if elem.node_type == 1 # start... | true |
8d94c97696acbd6c963341c3a77e1ed209aea6d5 | Ruby | guspowell/till_test | /spec/till_spec.rb | UTF-8 | 1,708 | 3.0625 | 3 | [] | no_license | require 'till.rb'
require 'order.rb'
require 'shop.rb'
describe Till do
let(:shop) {Shop.new}
let(:till) {Till.new(shop)}
let(:order1) {Order.new(1)}
let(:order2) {Order.new(2)}
before(:each) do
shop.load_information
order1.add_item('Cafe Latte', 2)
end
it 'should be able to registe... | true |
20836298996b39699c1b6aa66afa5060be5c6d43 | Ruby | rackerlabs/design-system | /_plugins/helixKramdown.rb | UTF-8 | 1,245 | 2.625 | 3 | [] | no_license | # modeled after https://github.com/mvdbos/kramdown-with-pygments/blob/master/kramdown_pygments.rb
require 'kramdown/converter'
# Custom plugin for Kramdown. It's used by the custom converter, not by Jekyll.
module Kramdown
module Converter
class HelixHtml < Html
def convert_header(el, indent)
attr ... | true |
c414347a4e452621177090a507ca1a6c8302ae35 | Ruby | joshskeen/cursetank | /lib/cursetank.rb | UTF-8 | 2,712 | 3.171875 | 3 | [
"MIT"
] | permissive | require "cursetank/tank_objects/basic_fish"
require "cursetank/tank_objects/octopus"
require "cursetank/tank_objects/bubble"
require "cursetank/tank_objects/plant"
require "curses"
module Cursetank
include Curses
class Cursetank
def initialize
setup_curses
@win = Curses::Window.new(0, 0, 0, 0)
... | true |
e5cc6d5d139b1b1a633cdbdad3e428f230ad245d | Ruby | stlachman/intro-launch | /methods/exercise2.rb | UTF-8 | 213 | 3.421875 | 3 | [] | no_license | x = 2
# 2
puts x = 2
# Outputs 2
# => returns nil
p name = "Joe"
# "Joe" outputs argument and then returns argument
# "Joe"
four = "four"
# four
print something = "nothing"
# output = nothing
# return => nil | true |
2ded6f5ae64709777a27494e18f422e93ee704dd | Ruby | robbrit/ruby-worldgen | /generate.rb | UTF-8 | 1,758 | 3.28125 | 3 | [
"MIT"
] | permissive | require 'optparse'
require "worldgen"
options = {
verbose: true
}
OptionParser.new do |opts|
opts.on("--diamondsquare [FILE]", String, "Output a diamondsquare to FILE") do |file|
options[:diamondsquare] = file
end
opts.on("--platemap [FILE]", String, "Output a platemap to FILE") do |file|
options[:pl... | true |
740f91e8fda8daee70ae4bc6dda2f422bf529d85 | Ruby | brookezimm/RubyBook2 | /Arrays/exercise8.rb | UTF-8 | 186 | 3.921875 | 4 | [] | no_license | arr = [1, 2, 3]
new_arr = []
# a.each do |e|
# puts e + 2
# end
# p a
arr.each do |n|
new_arr << n + 2
end
# ... or...
# new_arr = arr.map do |n|
# n + 2
# end
p arr
p new_arr | true |
dd244371e9bfbbfd49af63d696a3c81aaea27fc0 | Ruby | dblem/ttt-7-valid-move-q-000 | /lib/valid_move.rb | UTF-8 | 353 | 3.296875 | 3 | [] | no_license | def valid_move?(board, position)
position = position.to_i - 1
if board[position] == " " || board[position] == ""
true
elsif position_taken?(board, position) == true
false
elsif position > 9
false
end
end
def position_taken?(board, position)
if board[position] == "X" || board[position] == "O"
... | true |
ac19983b38a00ff16d13c8b8620e09a6a0acd732 | Ruby | Jele0794/Encryption-Algorithms | /PlayFair/pldecipher.rb | UTF-8 | 4,990 | 3.5625 | 4 | [] | no_license | class Pldecipher
def initialize(matrizAbcd, cipherText)
@cipherText = cipherText
@matrizAbcd = matrizAbcd
@plainText = deciphering(@cipherText)
puts "Texto desencriptado por el algoritmo: #{@plainText}"
end
def deciphering(cipherText)
i = 0
j = cipherText.length
while i < j
primerasLetras = cipher... | true |
68e4851c88e15c3d709b3e98c7267384d2ba475b | Ruby | hashimoton/spelling_alphabet | /exe/spellout | UTF-8 | 1,703 | 3.828125 | 4 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# Usage: spellout [options] WORD
# Convert WORD to a sequence of spelling alphabet (phonetic alphabet)
#
# Options:
# -w WORD_SET Speify the word set for conversion (default: ITU)
# -i Interpret WORD instead of spellingout
#
# Supported word sets:
# ITU ITU Phonetic Alphabet ... | true |
f6f97785e433a2b26629dfbacdcea04b559debb5 | Ruby | JohnMarkLudwick/regex-lab-v-000 | /lib/regex_lab.rb | UTF-8 | 1,309 | 3.484375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def starts_with_a_vowel?(word)
if word.match(/^[aeiouAEIOU]\w+/)
true
else
false
end
end
def words_starting_with_un_and_ending_with_ing(text)
text.scan(/un+\w+ing\b/)
end
def words_five_letters_long(text)
text.scan(/\b\w{5}\b/)
#\b - Matches a word boundary, that is, the position #between a wor... | true |
6957c72bc4296da19ebd648ccfa1db99d11fa215 | Ruby | hyanezs/Ruby-Memcached-Server | /lib/validate_protocol.rb | UTF-8 | 2,963 | 3.203125 | 3 | [] | no_license | # frozen_string_literal: true
# validates write commands protocol
module ValidateProtocol
# key validation -> matches alphanumeric and underscore
KEY_REGEX = /^[a-zA-Z0-9_]*$/.freeze
# number validation -> matches positive numbers
UNSIGNED_INTEGER_REGEX = /\A\d+\Z/.freeze
def self.validate(tokens, no_reply,... | true |
4a5d9973421d342494e3039c3a5c61a737427872 | Ruby | TestingResearchIllinois/travistorrent-tools | /lib/buildlog_analyzer_dispatcher.rb | UTF-8 | 1,772 | 3.09375 | 3 | [] | no_license | require 'csv'
load 'lib/log_file_analyzer.rb'
load 'lib/languages/java_log_file_analyzer_dispatcher.rb'
load 'lib/languages/ruby_log_file_analyzer.rb'
load 'lib/csv_helper.rb'
# Takes a path to a directory of Travis CI logfiles (named *.log) and tries to dispatch the analysis of the logfiles
# to the most specific an... | true |
f8b664aedb2d58645c3069bf4fcd0ab95f4a2625 | Ruby | XGuGu/W2D3 | /remove_dups/spec/remove_dups_spec.rb | UTF-8 | 208 | 2.53125 | 3 | [] | no_license | require 'rspec'
require 'remove_dups'
describe '#remove_dups' do
it 'should remove dups in array' do
array = [1,2,1,3,3]
expect(remove_dups(array)).to eq([1,2,3])
# array.remove_dups
end
end
| true |
d2d765cbf365386df2ff75d7787adce63b0f64b9 | Ruby | furuya-tomoki/ruby-review | /add.rb | UTF-8 | 78 | 3.375 | 3 | [] | no_license | for add in 1..6 do
# 「1..6」は1~6までの範囲を表す
puts add
end | true |
82be65d24e23dee6bfbaf3d084d3e812c94e0ace | Ruby | David-Roark/code_practice | /exercism/triangle/triangle.rb | UTF-8 | 396 | 3.53125 | 4 | [] | no_license | class Triangle
def initialize(sides)
@a, @b, @c = sides
end
def is_triangle?(a,b,c)
a + b > c && a + c > b && b + c > a
end
def equilateral?
@a != 0 && @a == @b && @a == @c
end
def isosceles?
is_triangle?(@a, @b, @c) ? @a == @b || @b == @c || @c == @a : false
end
def scalene?
is... | true |
a31564d921ef8b63f90eff388f74fd41fae15668 | Ruby | ajth-work/codecademy-solutions | /Ruby/08 - Blocks, Procs, and Lambdas/Lessons/01 - You Know This!.rb | UTF-8 | 57 | 2.828125 | 3 | [] | no_license | # Write your code below!
5.times {puts "I'm a block!"} | true |
7a505ebdefd1d13f4c492dfb269a410b40482725 | Ruby | lpenzey/interview_exercises | /cracking_the_code_interview/chapter_1/1.6_string_compression/lib/string_compression.rb | UTF-8 | 971 | 3.953125 | 4 | [] | no_license | #Implement a method to perform basic string compression
#using the counts of repeated characters.
#For example, the string aabcccccaaa would become
#a2blc5a3. If the "compressed" string would not
#become smaller than the original string, your
#method should return the original string. You can
#assume the string ha... | true |
da785607951d4d02cd2238a54fbb6f009d61965b | Ruby | MasayukiU/furima-35825 | /spec/models/user_spec.rb | UTF-8 | 3,712 | 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 'emailとencrypted_passwordとnicknameとlast_nameとfirst_nameとlast_name_readingとfirst_name_readingとbirthdayが存在すれば登録できる... | true |
02733ae27b0f1a8de9cedb85852e5e1d005c5b12 | Ruby | reillywj/workout_log | /app/models/cycle.rb | UTF-8 | 662 | 2.640625 | 3 | [] | no_license | class Cycle < ActiveRecord::Base
belongs_to :user
has_many :workouts
validates :length_of_time, presence: true
validates :length_of_time_units, presence: true
validates :start_date, presence: true
validates_uniqueness_of :start_date, scope: :user_id
def end_date
start = self.start_date
time = se... | true |
92a2d30e2a9cd72b08aabd5eacf10b43f73e0cab | Ruby | ivan-leschinsky/dry-swagger | /lib/dry/swagger/documentation_generator.rb | UTF-8 | 4,464 | 2.625 | 3 | [
"MIT"
] | permissive | module Dry
module Swagger
class DocumentationGenerator
SWAGGER_FIELD_TYPE_DEFINITIONS = {
"string" => { type: :string },
"integer" => { type: :integer },
"boolean" => { type: :boolean },
"float" => { type: :float },
"datetime" => { type: :string, format: :da... | true |
fa7e00c9c7098c7bb95c72b94690c67da2ecc050 | Ruby | tenzin2017/ruby_fundamentals1 | /exercise6.2.rb | UTF-8 | 401 | 3.921875 | 4 | [] | no_license | energy = 100
while true do
puts "Would you like to walk or run ?"
user_choice = gets.chomp
if (user_choice == "walk")
energy += 1
puts " Your energy is #{energy} unit"
elsif (user_choice == "run")
if energy <= 0
puts "You don't have enough energy"
else
energy -= 1
puts " Your ener... | true |
7eb2d8494f3a054c433cd35b749aad47f23d8386 | Ruby | qinfeng8848/programming-exercise | /26-hash-filter.rb | UTF-8 | 912 | 4.09375 | 4 | [] | no_license | # 给定一个数组包含 Hash,请过滤和排序
arr = [
{ "name" => "Peter", "age" => 30 },
{ "name" => "John", "age" => 15 },
{ "name" => "David", "age" => 45 },
{ "name" => "Steven", "age" => 22 },
{ "name" => "Vincent", "age" => 6 },
]
# 去掉小于16
arr.each do |a|
a.each do |key, value|
if key == "age"
if value < 16
... | true |
54255596f13a5ae10dbe67f03bcbf0c975148d64 | Ruby | br0xen/upfront-bot | /plugins/SecretWord.rb | UTF-8 | 2,504 | 2.875 | 3 | [] | no_license | require 'cinch'
require 'date'
require 'rubygems'
require 'action_view'
include ActionView::Helpers::TextHelper
class SecretWord
include Cinch::Plugin
@@current_word = ""
@@last_update
@@secret_said_count = 0
set :prefix, /^!/
match /secretword new$/, method: :force_update_word
match /secretword count$... | true |
0488d7847f3e95aa1ba1502d43d527d8895d7a78 | Ruby | npolar/api.npolar.no | /lib/npolar/rack/response.rb | UTF-8 | 1,343 | 2.59375 | 3 | [] | no_license | module Npolar
module Rack
class Response < ::Rack::Response
## Force Content-Type
#unless response_headers["Content-Type"].nil?
# response["Content-Type"] = response_headers["Content-Type"]
#end
#
## Force UTF-8
#if response["Content-Type"] !~ /; charset=/
# res... | true |
5dcc37b2790adbd37f3ca49b1b56ba9d175e4aa2 | Ruby | Luisterpuntbibliotheek/sinatra_keycloak_example | /lib/session.rb | UTF-8 | 1,724 | 2.640625 | 3 | [] | no_license | require 'keycloak'
require 'json'
class Session
attr_accessor :redirect_login, :redirect_logout, :payload, :session_id
def initialize(payload = nil, session_id = nil, redirect_login ='http://127.0.0.1:9292/session', redirect_logout ='http://127.0.0.1:9292/')
@payload = payload
@redirect_login = redirect_l... | true |
9dc9943cc6c810de79ab06a8f9555e3d51cfe090 | Ruby | jD91mZM2/rust-lci | /tests/generate-quine.rb | UTF-8 | 1,092 | 3.28125 | 3 | [
"MIT"
] | permissive | def quote(input)
result = ""
for i in 0...input.length
c = input[i]
case c
when "\n" then
result += "\" NEWLINE \""
when '"' then
result += "\" QUOTE \""
when ':' then
result += "\" ESCAPE \""
else
result += c
... | true |
5d4afe973e597b595cec6d97af6bd2b305f8cd65 | Ruby | Joewebsta/tschool-lesson-exercises | /mod_01/nested_collections_1.rb | UTF-8 | 1,466 | 3.78125 | 4 | [] | no_license | require 'awesome_print'
# STATE CAPITALS
states = {
'Oregon' => 'OR',
'Alabama' => 'AL',
'New Jersey' => 'NJ',
'Colorado' => 'CO'
}
capitals = {
'OR' => 'Salem',
'AL' => 'Montgomery',
'NJ' => 'Trenton',
'CO' => 'Denver'
}
# Level 1: Write some code which given a state name (“Alabama”) outputs the sta... | true |
9153f8aa5b76b8311ea8707655d068397d0a434e | Ruby | sigabort/demo_app1 | /spec/models/user_spec.rb | UTF-8 | 3,367 | 2.734375 | 3 | [] | no_license | require 'spec_helper'
describe User do
before(:each) do
str = rand_str;
@attributes = {
:name => str,
:email => str,
:password => str,
:password_confirmation => str
}
end
it "should create a new instance given valid attributes" do
User.create!(@attributes)
end
it "... | true |
24a78f1bfaf8a5efd6275ba9ea97bcfa804f035d | Ruby | flatplanet/Intro-To-TKinter-Youtube-Course | /thing.rb | UTF-8 | 380 | 4 | 4 | [] | no_license | puts "What's your name?"
name = gets.chomp
puts "How many times have you revolved around the sun #{name}?"
number = gets.to_i
if number >= 2
puts "Oh? You are #{number} years older than me!"
elsif number == 1 || number == 0
puts "huh, we are the same age, you and I."
else
puts "I'm not sure that's the answer i was loo... | true |
d325b273c7a44e1f86501f7e5b4023718d304090 | Ruby | BenKettlewell/recommend_an_anime | /app/models/question.rb | UTF-8 | 411 | 2.546875 | 3 | [] | no_license | class Question < ActiveRecord::Base
has_many :responses
has_many :answers, through: :responses
attr_writer :all_answers
after_save :assign_answers
def all_answers
@all_answers || answers.map(&:answer).join(' ')
end
private
def assign_answers
byebug
if @all_answers
self.answers = @all_answers.split... | true |
fdffa8ab4683cccdb3b1a5b6e03372e0528a9d38 | Ruby | cielavenir/procon | /aizu/tyama_aizu0157.rb | UTF-8 | 281 | 2.6875 | 3 | [
"0BSD"
] | permissive | #!/usr/bin/ruby
while (n=gets.to_i)!=0
a=n.times.map{gets.split.map &:to_i}
m=gets.to_i
b=m.times.map{gets.split.map &:to_i}
a=(a+b).sort
d=[]
(n+m).times{|i|
d[i]=1
i.times{|j|
if a[j][0]<a[i][0]&&a[j][1]<a[i][1]
d[i]=[d[j]+1,d[i]].max
end
}
}
p d.max
end
| true |
7886a34c7285e14a626ca21cab0f96ff89538ddd | Ruby | yuemori/google_apps_manager | /lib/google_apps_manager/client.rb | UTF-8 | 1,097 | 2.53125 | 3 | [
"MIT"
] | permissive | require 'google/api_client'
require 'google_apps_manager/auth'
require 'google_apps_manager/downloader'
module GoogleAppsManager
##
# Google::ApiClient Wrapper
#
# Usage:
# auth = GoogleAppsManager::Auth.new(YAML.load_file('sample.yml'))
# auth.authorize #=> authorize to google api
#
# @param yaml_... | true |
3460f2916feeeff09e9ad5bba1079af1cc0ad88b | Ruby | bjyee/PartyMaster | /lib/tasks/populate.rake | UTF-8 | 5,436 | 2.78125 | 3 | [] | no_license | namespace :db do
desc "Erase and fill database"
# creating a rake task within db namespace called 'populate'
# executing 'rake db:populate' will cause this script to run
task :populate => :environment do
# Need two gems to make this work: faker & populator
# Docs at: http://populator.rubyforge.org/
... | true |
a55597fee331b0f01bc5d9740670442082340651 | Ruby | guardawallet/bitcoin.org | /_plugins/htmlescape.rb | UTF-8 | 540 | 2.734375 | 3 | [
"MIT"
] | permissive | # This file is licensed under the MIT License (MIT) available on
# http://opensource.org/licenses/MIT.
#htmlescape espaces special html characters. This is a replacement for
#CGI::escapeHTML, which has an inconsistent behavior with single quotes
#on different ruby versions ( 1.9 and 2.0 ).
#Example:
# {{ page.title |... | true |
b093951b49f48f3e6ed9b542a544d0565c6d0430 | Ruby | raquelstalcup/URL-shortener | /capital.rb | UTF-8 | 432 | 4.15625 | 4 | [] | no_license | #store the following data in a ruby data structure so that the question "What is the capital of capital <X>"
capital = {
"US" => "Washington DC",
"Brazil" => "Brasilia",
"China" => "Beijing"
}
family_names = {"Mom" => "Donna", "Dad" => "Ki", "Daughter1" => "Alexi", "Daughter2" => "Aliya", "Son" => "Jacob"}... | true |
b0cfab727a7eed070d735719de19970c7777194a | Ruby | baozoumanhua/elk-rtf | /logstash/vendor/bundle/jruby/1.9/gems/aws-sdk-v1-1.61.0/lib/aws/ec2/volume_collection.rb | UTF-8 | 3,642 | 2.53125 | 3 | [
"Artistic-1.0",
"Artistic-2.0",
"Apache-2.0"
] | permissive | # Copyright 2011-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" fil... | true |
4c019193d8bda449d21022a4a6ffd04887ee72d7 | Ruby | adriennepaquin/phase-3-active-record-theater-work | /db/seeds.rb | UTF-8 | 849 | 2.734375 | 3 | [] | no_license | puts "Clearing old data..."
Role.destroy_all
Audition.destroy_all
puts "Seeding auditions..."
30.times do
Student.create(actor: Faker::Name.name, role:)
end
puts "Seeding exams..."
10.times do
Exam.create(subject: Faker::Educator.subject,
total_questions: rand(1..100),
is_pop_quiz: [... | true |
8cc5563999c924fd4138bc04219ddac83486387d | Ruby | hamcodes/programming-univbasics-3-ruby-method-arguments-lab-online-web-prework | /lib/introduction.rb | UTF-8 | 444 | 3.15625 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def introduction(name)
"Hi, my name is #{name}."
end
puts Hi, my name is (name)
def introduction_with_language
"Hi, my name is #{name} and I am learning to program in #{language}."
end
puts Hi, my name is (name) and I am learning to program in (language).
def introduction_with_language_optional
"Hi, my name is ... | true |
02e1898bef087d2f76fe9e68481080dd62c663dd | Ruby | BurilloPolina/ruby_lab | /spec/unit/bus_spec.rb | UTF-8 | 762 | 3.0625 | 3 | [] | no_license | # frozen_string_literal: true
require_relative '../../lib/bus.rb'
RSpec.describe Bus do
before do
@bus_one = Bus.new(1, 2, 'Ivan', 'Ivanov', 4, 'Work')
@bus_two = Bus.new(3, 4, 'Petr', 'Petrov', 5, 'Stand')
@bus_three = Bus.new(1, 2, 'Ivan', 'Ivanov', 4, 'Work')
end
describe '#==' do
it 'should ... | true |
740752b713e22734cefb769d1782e6b05c30f914 | Ruby | DanyTlaw/LoLsite | /app/models/matchup.rb | UTF-8 | 7,455 | 2.6875 | 3 | [] | no_license | class Matchup < ActiveRecord::Base
acts_as_commontable
# champ validation
validates :champ_eins, presence: {:message => "Champion left can't be empty." }
validates :champ_zwei, presence: {:message => "Champion right can't be empty." }
validate :champ_cant_be_equal
# rune validation
validate :runes_has_to_be_full... | true |
632c12c3bbae9dec0dc959d6d3478e54f1b84591 | Ruby | camelskyscraper/launch-school-exercises | /ruby_basics/variable_scope/exercise_4.rb | UTF-8 | 372 | 4.40625 | 4 | [] | no_license | # What will the following code print, and why? Don't run the code until you have tried to answer.
a = "Xyzzy"
def my_value(b)
b[2] = '-'
end
my_value(a)
puts a
# Xyzzy
# the variable a is unaffected by the function
# the function would return "Xy-zy"
# WRONG! (about the output)
# Strings are mutable and the #[] ... | true |
606a6f969744574b402eb115c97bbc184b814a63 | Ruby | bleung9/ar-exercises | /exercises/exercise_9.rb | UTF-8 | 857 | 3.3125 | 3 | [] | no_license | require_relative '../setup'
require_relative './exercise_1'
require_relative './exercise_2'
require_relative './exercise_3'
require_relative './exercise_4'
require_relative './exercise_5'
require_relative './exercise_6'
require_relative './exercise_7'
require_relative './exercise_8'
puts "Exercise 9"
puts "... | true |
0f032e1fe4e5af990d2620cc2576be64f3f76a12 | Ruby | kevinpav/LaunchSchool | /Intro_To_Programming/07_Hashes/ex7.rb | UTF-8 | 141 | 3.015625 | 3 | [] | no_license | x = "hi there"
my_hash = {x: "some value"}
my_hash2 = {x => "some value"}
# First hash is "new" Ruby format. Second one is old (<1.9) format | true |
07e866a18d6d392040a99d0180ac2b64be87126c | Ruby | AaronH/email-veracity | /test/test_server.rb | UTF-8 | 920 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'helper'
class TestServer < Test::Unit::TestCase
def test_creating_a_new_blank_server_object
new_server = EmailVeracity::Server.new
assert_equal '', new_server.to_s,
'Should yield a blank string on call to to_s.'
assert_equal '', new_server.name,
'Should yield a blank string on call ... | true |
cb4c9784bdb6696cf0e4f822682be6dfb589c5f2 | Ruby | paulshu/programming-exercise | /26-hash-filter.rb | UTF-8 | 634 | 4 | 4 | [] | no_license | # 给定一个数组包含 Hash,请过滤和排序
arr = [
{ "name" => "Peter", "age" => 30 },
{ "name" => "John", "age" => 15 },
{ "name" => "David", "age" => 45 },
{ "name" => "Steven", "age" => 22 },
{ "name" => "Vincent", "age" => 6 },
]
answer = arr.select! {|c| c["age"] >=18}.sort_by {|a| a["age"]}
# select是数列找出对应条件的命令,sort_by 由... | true |
700cd9660282078fa30e2707712392f91f30f2e5 | Ruby | cfanpnk/launchschool | /backend/ruby_foundations/lesson_3/medium1/q8.rb | UTF-8 | 154 | 3.53125 | 4 | [] | no_license | def titleize(input)
title = input.split(' ')
title.map! do |word|
word.capitalize
end
title.join(' ')
end
puts titleize("this is nankai pan") | true |
1c771854c9de52251f24f4669ee1b9a86395a5d2 | Ruby | sakhtar-git/cucumber-ruby-api | /features/support/master.rb | UTF-8 | 650 | 2.671875 | 3 | [] | no_license |
=begin
/***************************************************************************
* Add all common methods in one place *
* Date Author Description *
* 11/11/2019 Sharique Initial *
**... | true |
5072202147bd159bb32363a37be2c3a18938dcf2 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/hamming/72bbdd7f77f04d53885b32d8ad4ce360.rb | UTF-8 | 539 | 3.515625 | 4 | [] | no_license | class Hamming
def self.compute(strand1, strand2)
num, diff = 0, 0
verify_array(strand1, strand2)
a = strand1.split('')
b = strand2.split('')
while num < a.length
if a[num] != b[num]
diff += 1
end
num += 1
end
return diff
end
def self.verify_array(strand1, st... | true |
708ee9b03d11c1eaed33d5e87a107edb847cd452 | Ruby | chef/mixlib-config | /lib/mixlib/config/configurable.rb | UTF-8 | 2,132 | 2.734375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | #
# Author:: John Keiser (<jkeiser@chef.io>)
# Copyright:: Copyright (c) 2013-2018, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
... | true |
89c40498997aafb0978bb80987adfc12c88661a5 | Ruby | NickRamsey6/prime_sifter | /lib/prime.rb | UTF-8 | 450 | 3.625 | 4 | [] | no_license | require 'pry'
class Primes
def initialize(number)
p number
@array =*(2..number)
end
def prime_counter
prime = 2
i = 0
while i < @array.length do
@array = @array.reject { |r| r % prime == 0 if r > prime }
i += 1
prime = @array[i]
end
p @array
p @array.length
... | true |
cea8032d5949ddc1485f0fa7271ca4cf32709b1e | Ruby | sfieux/chef-cookbook-ca-openldap | /libraries/global_config_options.rb | UTF-8 | 1,445 | 2.75 | 3 | [
"Apache-2.0"
] | permissive | module CaOpenldap
class GlobalConfigOptions
attr_reader :options
def initialize(path="/etc/openldap/slapd.d/cn=config.ldif")
@path = path
content = File.read(path).split(/\n/)
olc_lines = content.grep /^olc/
@options = olc_lines.inject({}) do |hash, line|
insert_option_to_ha... | true |
efb280e29ed60fed63e3c29c055a1658fcc56f62 | Ruby | colinsurprenant/fsqstalk | /lib/runner.rb | UTF-8 | 959 | 2.640625 | 3 | [] | no_license | require 'monitor'
require 'singleton'
require 'lib/stalker'
module FsqStalker
# TODO: this Runner singleton call need to be reworked.
# its a quick hack to be able to share the runner between both apps
class Runner
include Singleton
attr_reader :listener, :stalker
def setup(access_token... | true |
195ad7e1a8e517b7fd1d497fb140eaffef2467f7 | Ruby | greatday4april/design-practice | /randomized_set.rb | UTF-8 | 1,234 | 4.25 | 4 | [] | no_license | class RandomizedSet
# Initialize your data structure here.
def initialize
@number_index_map = {}
@number_list = []
end
# Inserts a value to the set. Returns true if the set did not already contain the specified element.
# :type val: Integer
# :rtype: Boolean
def insert(val)
re... | true |
80b0a54868bfb4bbb8a1e04c46678b35e0552c9a | Ruby | jillian13nicole/ttt-game-status-v-000 | /lib/game_status.rb | UTF-8 | 1,020 | 3.875 | 4 | [] | no_license | # Helper Method
def position_taken?(board, index)
!(board[index].nil? || board[index] == " ")
end
# Define your WIN_COMBINATIONS constant
WIN_COMBINATIONS = [
[0, 1, 2], # Top row
[3, 4, 5], # Middle row
[6, 7, 8], # Bottom row
[0, 4, 8]... | true |
8528dfb12a97c65971b6975fc72f9ec9951f5020 | Ruby | bespokoid/doodle | /spec/datatypes_spec.rb | UTF-8 | 9,462 | 2.6875 | 3 | [
"MIT"
] | permissive | require File.expand_path(File.join(File.dirname(__FILE__), 'spec_helper.rb'))
require 'doodle/datatypes'
describe Doodle, 'datatypes' do
temporary_constant :Foo, :Bar do
it "should create an Integer datatype with integer" do
class Foo < Doodle
doodle do
integer :number
end
... | true |
8092623b951c11b63891c72b98b872ebdaa80211 | Ruby | stepheneb/otrunk-examples | /index-builder-script/util.rb | UTF-8 | 1,694 | 2.9375 | 3 | [] | no_license | require 'time'
# == gmt_time_from_svn_time ==
#
# convert svn format times like this:
#
# "2008-07-02 10:40:26 -0400 (Wed, 02 Jul 2008)"
#
# to a GMT format like this:
#
# "Wed, 02 Jul 2008 14:40:26 GMT"
#
def gmt_time_from_svn_time(svn_time)
iso8601_time = "#{svn_time[/(.*) -/, 1].gsub(/ /, 'T')}"
Time.xmlsch... | true |
16ed24d4b9b8f97d5309d97d9aafdd710025606d | Ruby | pepeul1191/rails-5-boilerplate-v3 | /scripts/cipher.rb | UTF-8 | 330 | 2.65625 | 3 | [] | no_license | require 'openssl'
require_relative '../lib/assets/cipher'
require_relative '../config/initializers/constants'
def encrypt(plain_text)
Assets::Cipher.encrypt(CONSTANTS[:key], plain_text)
end
def decrypt(plain_text)
Assets::Cipher.decrypt(CONSTANTS[:key], plain_text)
end
puts encrypt('123')
puts decrypt('671B962CE... | true |
d32616882b54c3e10826bfc3d79f85718e11ce4c | Ruby | Godrl/study_ruby | /home_work/sort/heap.rb | UTF-8 | 975 | 4.03125 | 4 | [] | no_license | def heap_sort(array)
len = array.length - 1
arr = array
(len / 2).downto(0) do |i|
heapify(arr, i, len)
end
while len > 0
arr[0], arr[len] = arr[len], arr[0] # 가장 큰 값이 배열 첫번째 있으므로 바꿔준다.
len -= 1 # 가장 큰 값은 이미 정렬되었으므로 정렬할 배열의 숫자 -1
heapify(arr, 0, len)
end
end
def heapify(arr, parent, limit... | true |
8b703cabb41f2e6b1d69c67661bf8e1a08a7ff22 | Ruby | Devex/article_json | /lib/article_json/elements/text_box.rb | UTF-8 | 948 | 2.90625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module ArticleJSON
module Elements
class TextBox < Base
attr_reader :content, :float, :tags
# @param [Array[Paragraph|Heading|List]] content
# @param [Symbol] float
# @param [Array] tags
def initialize(content:, float: nil, tags: [])
@type = :text_box
@content = cont... | true |
0c66b2ed36ed72f309bda2c8a357afa2a8a7b23d | Ruby | seanbjornsson/connect_four_challenge | /grid_helpers.rb | UTF-8 | 2,312 | 3.375 | 3 | [] | no_license | require_relative 'grid'
module GridHelpers
# use this to determine available moves on the grid
def available_columns
x = 0
results = []
while x < @columns_size do
if !topped_column?(x)
results << x
end
x += 1
end
results
end
# col, row_height (0 indexed) to int ... | true |
88f72667697684702090f178e2855c82f740ff24 | Ruby | jonathanccalixto/atm_monorepo | /api/app/services/token_coder.rb | UTF-8 | 141 | 2.609375 | 3 | [
"MIT"
] | permissive | module TokenCoder
def self.encode(term)
Base64.encode64(term.to_s)
end
def self.decode(token)
Base64.decode64(token)
end
end | true |
a6463f2fb41296869e830dfa52851efd5fff8759 | Ruby | bphillips95/sinatra-basic-routes-lab-dumbo-web-111819 | /app.rb | UTF-8 | 624 | 2.8125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require_relative 'config/environment'
class App < Sinatra::Base
get '/name' do
"My name is Baruch"
end
get '/hometown' do
"My hometown is Worcester"
end
get '/favorite-song' do
"My favorite song is 'It's my life' "
end
end
# Basic Routes Lab
# GET '/name'
# ... | true |
9377a9962ec250609851978a9e1c861f349dae2b | Ruby | antman999/artistry-challenge | /db/seeds.rb | UTF-8 | 746 | 2.640625 | 3 | [] | no_license | Instrument.destroy_all
Artist.destroy_all
Music.destroy_all
artist1=Artist.create(name: "Michael Jackson", age: rand(50), title: "King of Pop")
artist2=Artist.create(name: "Stevie Wonder", age: rand(50), title: "Little Stevie Wonder")
artist4=Artist.create(name: "Elvis Presley", age: rand(50), title: "the King")
artist... | true |
fd16f7e4ee177a9832f813902cd363b18665b840 | Ruby | lalusaud/nepali_calendar | /lib/nepali_calendar/bs_calendar.rb | UTF-8 | 4,115 | 3.078125 | 3 | [
"MIT"
] | permissive | module NepaliCalendar
class BsCalendar < NepaliCalendar::Calendar
MONTHNAMES = %w{nil Baisakh Jestha Ashad Shrawn Bhadra Ashwin Kartik Mangshir Poush Magh Falgun Chaitra}
DAYNAMES = %w{nil Aitabar Sombar Mangalbar Budhbar Bihibar Sukrabar Sanibar}
class << self
def ad_to_bs(year, month, day)
... | true |
8a6430b94ac3510d8b292cbf77b28f8780f65a9a | Ruby | gamesrol/tomalared | /app/models/tag.rb | UTF-8 | 1,130 | 2.609375 | 3 | [] | no_license | class Tag < ActiveRecord::Base
has_and_belongs_to_many :posts
has_and_belongs_to_many :users
attr_accessible :name, :users, :posts
# get rid of any tags that aren't attached to a post
def self.prune_tags
find(:all, :include => [:posts]).each { |t| t.destroy if t.posts.size == 0 }
end
def self.find_mo... | true |
492c780a77e237270011c37a085a60f63826ab75 | Ruby | Mudasirrr/Courses- | /Johns Hopkins University - Ruby on Rails Web Development Specialization/Johns Hopkins University - Ruby on Rails/module2 - Ruby/Lecture11-MoreClasses/class_methods_and_variables.rb | UTF-8 | 445 | 4.28125 | 4 | [
"Apache-2.0"
] | permissive | class MathFunctions
def self.double(var) # 1. Using self
times_called; var * 2;
end
class << self # 2. Using << self
def times_called
@@times_called ||= 0; @@times_called += 1
end
end
end
def MathFunctions.triple(var) # 3. Outside of class
times_called; var * 3
end
# No instance... | true |
28a2a55668fc13c80b8bbfccb9d0aef63a7b4cc0 | Ruby | Jose-Isimeme/hw-ruby-intro | /lib/ruby_intro.rb | UTF-8 | 1,279 | 3.890625 | 4 | [] | no_license | # When done, submit this entire file to the autograder.
# Part 1
def sum arr
# YOUR CODE HERE
sum = 0
arr.each do |x|
sum += x
end
return sum
end
def max_2_sum arr
max_2_sum = 0
arr.sort!
if arr.length == 0
max_2_sum = 0;
elsif arr.length == 1
max_2_sum = arr[0]
else
max_2_sum =... | true |
c0dee19d0ce2011948043306dca34762d0a951bc | Ruby | dannycho7/Ruby_Apps | /hashes.rb | UTF-8 | 95 | 2.734375 | 3 | [] | no_license | hashes = Hash["a"=>2, "b"=>3, ["1","Jan"] => "Jan"]
puts hashes["b"]
puts hashes[["1","Jan"]] | true |
8e751cf438ffcc28e85d5d6fe52bca93e871966f | Ruby | thhermansen/google_static_maps_helper | /lib/google_static_maps_helper/path.rb | UTF-8 | 4,382 | 3.390625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # -*- encoding: utf-8 -*-
module GoogleStaticMapsHelper
#
# A Path is used to draw things in the map, either lines or Polygons.
# It is build up of points and if a fill color is set you'll get a Polygon.
#
class Path
include Enumerable
OPTIONAL_OPTIONS = [:weight, :color, :fillcolor]
attr_access... | true |
70289c468ca7086017c1613ece48ea1686a614ac | Ruby | jasonkaskel/projecteuler | /31/solution.rb | UTF-8 | 1,114 | 4.0625 | 4 | [] | no_license | # In England the currency is made up of pound, £, and pence, p,
# and there are eight coins in general circulation:
# 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
# It is possible to make £2 in the following way:
# 1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
# How many different ways can £2 be made using any nu... | true |
ee965f06672a96e7969c91a14c38e1fcf6a4b00c | Ruby | santiagosendon/OO-mini-project-dumbo-web-082718 | /tools/console.rb | UTF-8 | 359 | 2.515625 | 3 | [] | no_license | require 'pry'
require_relative '../config/environment.rb'
alex = User.new("Celestino")
santiago = User.new ("Santiago")
soup = Recipe.new("Soup")
sandwich = Recipe.new("Bacon_Egg_Cheese")
soupcard1 = RecipeCard.new(santiago, "Today", 6, soup)
soupcard2 = RecipeCard.new(alex, "Today", 7, soup)
sandwich = RecipeCar... | true |
40e0e597597a6654a7d8f50af57d3dbeda7e1cf1 | Ruby | JulaB/quizzes | /stack/stack_from_queues.rb | UTF-8 | 427 | 3.296875 | 3 | [] | no_license | #!/usr/bin/env ruby
require_relative '../queue/l_queue'
class StackFromQueues
def initialize
@q1 = LQueue.new
@q2 = LQueue.new
end
def peek
@q1.front
end
def empty?
@q1.empty? && @q2.empty?
end
def push(value)
@q2.enqueue(value)
@q2.enqueue(@q1.dequeue.value) until @q1.empty?
... | true |
700333512364bd4c4a77d11651f079606e0cb1ef | Ruby | MVictoriaV/aydoo-2018-tp-mail | /spec/parseador_contacto_spec.rb | UTF-8 | 1,206 | 2.75 | 3 | [] | no_license | require_relative '../model/parseador_contacto'
require 'yaml'
class ParseadorContactoSpec
describe 'ParseadorContacto' do
mi_parseador = ParseadorContacto.new()
un_archivo = "json_contactos_datos.txt"
def levantar_archivo_json(un_archivo, un_id)
mi_hash = YAML.load_fi... | true |
f3b3563a72fbd7f94d502315faf096a271c791ee | Ruby | waxnyc/Metis-Prework | /CP_LTP/Chapter9/ch9_local_variables.rb | UTF-8 | 484 | 3.515625 | 4 | [] | 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
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 #This is in the book but it gives an error so I've commented it out.
tough_var ... | true |
203f1d9e401a76db90027f82ba12bed2d355f13a | Ruby | haletothewood/LearnRubyTheHardWay | /Ex19.rb | UTF-8 | 1,047 | 4.59375 | 5 | [] | no_license | # creating a function with two arguments
def cheese_and_crackers(cheese_count, boxes_of_crackers)
puts "You have #{cheese_count} cheeses!"
puts "You have #{boxes_of_crackers} boxes of crackers!"
puts "Man that's enough for a party!"
puts "Get a blanket.\n"
end
puts "We can just give the function numbers directly:"... | true |
12dcbec989dfd28c54ee1d96ed5bd3b8bb2c4f56 | Ruby | RKobori/samidare | /lib/samidare.rb | UTF-8 | 1,602 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'samidare/version'
require 'samidare/embulk_utility'
module Samidare
class EmbulkClient
def generate_config(config)
Samidare::EmbulkUtility::ConfigGenerator.new(config).generate_config
end
def run(config)
db_infos = Samidare::EmbulkUtility::DBInfo.generate_db_infos
table_infos ... | true |
2f3f300f6932741baf8a392c3c61c78b68ed3973 | Ruby | mediasp/wirer | /test/service_test.rb | UTF-8 | 3,792 | 2.84375 | 3 | [] | no_license | require 'helpers'
describe Wirer::Service do
it "should be a convenience superclass which you can use which is extended with the DSL methods from Wirer::Factory::ClassDSL" do
assert Wirer::Service.is_a?(Wirer::Factory::ClassDSL)
end
it "should define initialize to store the supplied constructor_dependencie... | true |
bd92b6693d610bee51c7ce391aa356cdd48a6579 | Ruby | theerincollins/bands_venues | /spec/band_spec.rb | UTF-8 | 796 | 2.65625 | 3 | [
"MIT"
] | permissive | require('spec_helper')
describe Band do
describe('#venues') do
it('returns all venues at which the a band will play') do
venue1 = Venue.create(description: "Super Awesome Venue", address: "111 Edmond Rd. Portland, OR 90210")
venue2 = Venue.create(description: "The Other Super Awesome Venue", address:... | true |
226a15efa67c93d1c0ae8f06da4eab0e914a6fe4 | Ruby | bengroves1996/phase1_project_recipe_book | /lib/cli.rb | UTF-8 | 2,853 | 3.59375 | 4 | [] | no_license | require "pry"
class Cli
@@all = ["chicken","pasta","beef","pork","fish","rice","chocolate","beans"]
def self.all
@@all
end
def display_recipes
Cli.all.each_with_index{|ingredient, index| puts "#{index+1}. #{ingredient}"}
end
def greeting
puts "Welcome to the Modern F... | true |
e1628d56ad4ac04466851ea79dbaa34e33fa1a1f | Ruby | syamilmj/horizon | /lib/instrumentation.rb | UTF-8 | 2,335 | 2.9375 | 3 | [
"Apache-2.0"
] | permissive | #
# The instrumentation module provides a mechanism to simply
# instrument operations on the including class. It makes available
# and `instrument` class method which you can use to mark certain methods
# as instrumented. Any calls to that method will be measured with a timer
# and will be reporting into the overall... | true |
ead93fdf1d521ad7b2080b7f113e26fdd7888375 | Ruby | nanki/acts_like_git | /spec/unit/post_spec.rb | UTF-8 | 6,354 | 2.609375 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + '/../spec_helper'
context "A Post that versions a title and description field" do
before(:each) do
@hat = Hat.create!(:title => "Moo", :body => "RAR")
@repo_dir = File.join('/', 'tmp', '.data', 'git_store.git')
end
it "has the list of versioned fields, on the class" do... | true |
14afd1d7bacb20a378b1afdc80403119643e719b | Ruby | FerPerales/ruby-workshop | /examples/chapter_04/06_comparable.rb | UTF-8 | 202 | 3.828125 | 4 | [] | no_license | class MyArray < Array
include Comparable
def <=>(another_array)
self.length <=> another_array.length
end
end
a = MyArray.new [3,4,5]
b = MyArray.new [5,2]
puts a > b
puts a < b
puts a == b
| true |
b230b6ced47645b62ae42dfbd8c30c3f700692dd | Ruby | felipediesel/school | /test/models/concerns/decimal_formatter_test.rb | UTF-8 | 925 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'test_helper'
class DecimalFormatterTest < ActiveSupport::TestCase
test "should convert amount_formatted" do
plan = Plan.new
{
'1,50' => 1.5,
'01,50' => 1.5,
'1,05' => 1.05,
'1.05' => 105,
'12345,6789' => 12_345.68,
'11.22' => 1_122,
'11,15TEXT' => 11.15,
... | true |
2e6ab7da521430c5d26bb7332b8ce8220230e9d3 | Ruby | itarato/prototyper | /spec/type_def_spec.rb | UTF-8 | 1,640 | 2.84375 | 3 | [] | no_license | require_relative '../lib/thaip'
describe TypeDef do
describe 'flame test' do
it 'works with enum like classes' do
TypeDef['Color']
.with('Red')
.with('Yellow')
.with('Green')
expect(Red.is_a?(Color)).to(eq(true))
expect(Yellow.is_a?(Color)).to(eq(true))
expect(Gre... | true |
5cb7ac11d794d3351974329718d1bc5358128b43 | Ruby | chuckwagoncomputing/foac | /strategies/qualitativeThreeCouchCallerKeepFriend.rb | UTF-8 | 5,022 | 3.3125 | 3 | [] | no_license | # Keep track of who has three pseudonyms, forgetting one in order to remember a better one
class Strategy
def qualitativeThreeCouchCallerKeepFriend(name, team, position, pseudonym, calledName, calledTeam, calledPosition, calledPseudonym, callerName)
selection = $players.reject { |a| a == pseudonym or a == calledPseu... | true |
fe0946d1677a3a26a6ec1a7130b72309c14c5a60 | Ruby | popsun007/TDD_Ruby_LinkedList | /node.rb | UTF-8 | 105 | 3.140625 | 3 | [] | no_license | class Node
attr_accessor :element, :next
def initialize(item)
@element = item
@next = nil
end
end | true |
4f7932a54aa4a0f4b66d724497fe1ed9d6023d61 | Ruby | imonirr/utils | /bashScripts/rscripts/oldones/assets/build-removejunk.rb | UTF-8 | 1,141 | 2.78125 | 3 | [] | no_license | #! /usr/bin/ruby -w
# Script to remove unused parts and partial minification of frontend js application
#
$charMap =[*('A'..'Z')]
$miniMap = []
$stringList = []
$regex = Regexp.new('(?=[A-Z])[A-Z_0-9]{4,}\b')
def readStringList
file = File.open('all-constants.txt').read
# check for encoding issues
if ! file.va... | true |
847868583ed9d163f5cd01249f7fb741a99798d9 | Ruby | ijufumi/sandbox-ruby | /lib/q0/q06_01.rb | UTF-8 | 615 | 3.34375 | 3 | [] | no_license | #
# 全て自力
#
def calculate(n)
m = n
flag = false
while true
if flag
if m == n or m == 1 then
break
else
if m.modulo(2) == 0 then
m = m/2
else
m = m * 3 + 1
end
end
else
if m == n then
flag = true
m = m * 3 + 1
... | true |
5b07d93912d6418b912f1160a8cc14d7367b7b6e | Ruby | verg/jet_fuel | /jet_fuel/persisted_uri.rb | UTF-8 | 835 | 2.828125 | 3 | [] | no_license | class PersistedURI
@@database ||= []
attr_reader :short_urn, :long_uri, :created_at
attr_accessor :click_count
def initialize(args)
@click_count = args.fetch("click_count") { 0 }
@short_urn = args.fetch(:short_urn)
@long_uri = args.fetch(:long_uri)
@created_at = args.fetch(:created_at) { Time.... | true |
0259fa33adaf2f163894dcc8dce923e6bba25844 | Ruby | JoshCheek/ttt | /lib/ttt/interface/cli.rb | UTF-8 | 2,292 | 3.453125 | 3 | [
"MIT"
] | permissive | require 'ttt/interface/cli/players'
require 'ttt/interface/cli/views'
module TTT
module Interface
class CLI
Interface.register 'cli', self
X = 'X'
O = 'O'
attr_accessor :game, :filein, :fileout, :fileerr, :player1, :player2, :turn
def initialize(options={})
... | true |
f41095c13a85d25fd85a780dd42986fd88da9142 | Ruby | akcrono/recipes | /server.rb | UTF-8 | 948 | 2.625 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/reloader'
require 'pry'
require 'pg'
def db_connection
begin
connection = PG.connect(dbname: 'recipes')
yield(connection)
ensure
connection.close
end
end
def get_recipes
db_connection do |conn|
conn.exec("SELECT id, name FROM recipes")
end
end
def get_re... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.