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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
0378f2c1f03ac65bf1cea01af3be5192c959842e | Ruby | yvescabral/trace-reader | /trace_reader_with_layers.rb | UTF-8 | 1,865 | 3.3125 | 3 | [] | no_license | class CacheMemory
def initialize(positions, layers=1)
@lines = []
@layers = layers
for i in 0..positions-1
@lines << []
end
end
# Return true if is a hit and false if is a miss
def get(position, tag)
size = @lines[position].size
if size > 0
for i in 0..size-1
if @lin... | true |
b3e304c1f42074e82803d74d24223fc8467c96dd | Ruby | chromedia/rails-sample-code | /app/models/person.rb | UTF-8 | 1,135 | 2.59375 | 3 | [] | no_license | class Person
include Mongoid::Document
include SimpleEnum::Mongoid
field :first_name, type: String
validates_presence_of :first_name
field :middle_name, type: String
field :last_name, type: String
validates_presence_of :last_name
field :birthdate, type: Date, default: Date.today
as_enum :civil_stat... | true |
956946f5e8dcae245fbd75973bb4c2a2216c3c73 | Ruby | rjspencer/phase_0_unit_2 | /week_4/1_mathy_ruby_intro/harder_calculate_median/my_solution.rb | UTF-8 | 2,893 | 4.8125 | 5 | [] | no_license | # U2.W4: 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: ].
=begin
rspec ./median_spec.rb:9 # median is defined ... | true |
38de6336f3be882c4faa0abcf474fa4e316ffcf6 | Ruby | happiguru/Hackerrank | /RUBY/toh.rb | UTF-8 | 654 | 3.875 | 4 | [
"MIT"
] | permissive | def move(starting, goal)
n = 2
if starting == 1
mid = 2
toh(n, starting, goal, mid)
else
mid = 1
toh(n, starting, goal, mid)
end
end
# def toh(n, starting, mid, goal)
# if n == 1
# puts "#{starting} -> #{goal}"
# return
# end
# toh(n-1, starting, goal, mid)
# puts "#{startin... | true |
9e390b75fe68e762d514b4117120eb2a23173ff2 | Ruby | jruizes/One | /lib/mda.rb | UTF-8 | 2,669 | 3.359375 | 3 | [] | no_license | class Mda
def initialize(rows,columns)
@max_row = rows
@max_column = columns
@a = Array.new(rows)
@a.map! { Array.new(columns) }
@first_node = true
end
# =begin
# def fill_array(row,column,value)
# @a[row-1][column-1]=value
# end
# def create_file
# file = File... | true |
1be36425bfab313fc70df1a8eb8590e55e6577ad | Ruby | gregnar/snow_meet_rails | /app/models/tweet.rb | UTF-8 | 619 | 2.5625 | 3 | [] | no_license | class Tweet < ActiveRecord::Base
belongs_to :trip
belongs_to :user, foreign_key: :user_name, primary_key: :twitter_name
validates :twitter_time, uniqueness: true
def self.create_from_api_object(api_object, trip_id)
create(
text: api_object.text,
trip_id: trip_id,
user_name: ... | true |
f7f956a3b7400b7c28384a4c8753506f876daeca | Ruby | Dujota/reinforcing_exercise_tdd | /calculator.rb | UTF-8 | 114 | 3.078125 | 3 | [] | no_license | def add(num1, num2)
num1 + num2
end
def subtract(num1, num2)
num1 - num2
end
def sum(array)
array.sum
end
| true |
17ede9148bea6a1c1b42fb182bd03eef46cdfe69 | Ruby | daschl/DeveloperDay | /Ruby/03_storage_json.rb | UTF-8 | 911 | 2.78125 | 3 | [] | no_license | #!/usr/bin/env ruby
require "rubygems"
require "couchbase"
require "json"
require "rainbow"
require "pp"
system 'clear'
puts "--------------------------------------------------------------------------".bright.foreground(:red)
puts "Couchbase JSON Doc Storage".bright.foreground(:red)
puts "--------------------------... | true |
b5a83a0db10c793c4825ded9b37adbeaf227ba89 | Ruby | gregors/boilerpipe-ruby | /lib/boilerpipe/extractors/keep_everything_with_k_min_words_extractor.rb | UTF-8 | 737 | 2.75 | 3 | [
"Apache-2.0"
] | permissive | # A full-text extractor which extracts the largest text component of a page.
# For news articles, it may perform better than the DefaultExtractor, but
# usually worse than ArticleExtractor.
module Boilerpipe::Extractors
class KeepEverythingWithKMinWordsExtractor
def self.text(min, contents)
doc = ::Boilerp... | true |
44e8367d8f1b7beb566a409493d674060ff54405 | Ruby | machvee/blackjack-strategy-simulator | /player_hand_strategy.rb | UTF-8 | 5,140 | 3.15625 | 3 | [] | no_license | module Blackjack
module Action
#
# stay?
#
LEAVE=-1
PLAY=0
#
# play
#
HIT=1
STAND=2
SPLIT=3
DOUBLE_DOWN=4
SURRENDER=5
#
# insurance?
#
INSURANCE=6
NO_INSURANCE=7
EVEN_MONEY=8
def action_name(a)
#
# Action.action_name(Actio... | true |
eec2cf8a455640758380a60945d8a0ac835b77ab | Ruby | luizfonseca/Projeto-IFMT | /conditional/if_test_maxsuel.rb | UTF-8 | 210 | 3.890625 | 4 | [] | no_license | puts "Qual o seu nome?"
nome = gets.chomp()
if nome == "Maxsuel"
puts "Nome massa, curti! Meu chara"
else
if nome == "Luiz"
puts "Nome feio, muda de nome"
else
puts "Nome massa, curti tambem"
end
end | true |
a57b689878514cee1eabecba2e73b40e198da29c | Ruby | mikelewis/range_hash | /spec/rangehash_spec.rb | UTF-8 | 2,458 | 3.109375 | 3 | [] | no_license | require 'spec_helper'
describe RangeHash do
before do
@rh = RangeHash.new
end
[:[], :[]=].each do |meth|
it "should respond to #{meth}" do
@rh.should respond_to(meth)
end
end
context "integeration" do
before do
c = (13..16)
d = (20...25)
a = (1..10)
b = (10...1... | true |
a60d0649d513f8c14bb92f048f1d461830fe650f | Ruby | sattelbergerp/project-tracker | /spec/support/account_helpers.rb | UTF-8 | 424 | 2.671875 | 3 | [
"MIT"
] | permissive | module AccountHelpers
#Visits the signup page, filles in the form, and clicks submit
#Takes a usernma and password, then returns the created user (Assuming User.last is the created user)
def create_and_login_user(username, password)
visit "/signup"
fill_in('name', with: username)
fill_in('email', with... | true |
939351285e82319b43258f47f0fd9f004b3fe5d2 | Ruby | codeforasia/skillet | /cookbooks/site-cookbooks/hectic/libraries/hectic.rb | UTF-8 | 1,821 | 2.546875 | 3 | [] | no_license | class Hectic
# These class-level convenience methods are the ones I intend to call in my recipes.
def self.accounts(node)
new(node).accounts
end
def self.base_mailbox_paths(node)
new(node).accounts.map { |account| account['mailbox_path'] }.map do |mailbox_path|
if mailbox_path.end_with?('/')
... | true |
aaa85aeb6b40b429b4b486e5ef95926bed7ddee4 | Ruby | TopOneOfTopOne/revised_morningstar_scraper | /run.rb | UTF-8 | 937 | 2.859375 | 3 | [] | no_license | # Stock Info
# Scrapes mourning star website
require_relative 'dividends_scraper'
require_relative 'stock_info_scraper'
require_relative 'calc_profit' # for stock class
@EX_DIV_DATE = Time.parse('13/04/2016')
@MONEY = 4000
outputFile = File.open(File.expand_path('info.txt',File.dirname(__FILE__)), 'w')
def get... | true |
ec48d0103eeb70013ed6d60829e972313c0d9a6c | Ruby | nimaester/Ruby | /pair_sum.rb | UTF-8 | 254 | 3.421875 | 3 | [] | no_license | def pair_sum(array, sum)
result = []
i = 0
while i < array.length
j = i + 1
while j < array.length
if array[i] + array[j] == sum && j > i
result << [i, j]
end
j += 1
end
i += 1
end
result
end
| true |
1acb167fb8e275fe03ab619251d531c816840336 | Ruby | mackhowell/secret_cities | /app.rb | UTF-8 | 964 | 2.515625 | 3 | [] | no_license | require 'sinatra'
require 'dm-core'
#require 'json'
DataMapper::setup(:default, {:adapter => 'yaml', :path => 'db'})
class AnonPost
include DataMapper::Resource
property :id, Serial
property :username, String
property :secret, String
property :lat, Float
property :lng, Float
property :created_at, DateTim... | true |
faccd50baa08ce8baf2f960edbd3d1468c361d3b | Ruby | MiguelCarranza/bentheshark | /app/helpers/tweets_helper.rb | UTF-8 | 1,275 | 2.625 | 3 | [] | no_license | module TweetsHelper
def sightings_tweets
["Ahem! Who saw me in %s %s?",
"Aww, I'm starving and just remembered the amazing breakfast I had in %s %s",
"Boo! I hope I did not scared you guys too much in %s %s",
"I love to go fishing in %s. %s it was amazing",
"Shh, don't tell surfers and swimmer... | true |
a5f274e73b94024be01b66811150064cadd47723 | Ruby | ATouhou/shiavault | /app/services/bitbucket_service.rb | UTF-8 | 947 | 2.59375 | 3 | [] | no_license | require 'oauth_util'
require 'open-uri'
class BitbucketService
attr_reader :account, :repo, :branch
def initialize(account: Rails.application.secrets.bitbucket_account,
repo: 'dinesh-library',
key: Rails.application.secrets.bitbucket_key,
secret: Rails.applicatio... | true |
eebdb6e7fed86cd0fcc3e7b88a55693f76b85957 | Ruby | Nebopolis/project_euler | /Ruby/euler2.rb | UTF-8 | 761 | 4.1875 | 4 | [
"MIT"
] | permissive | def sumMultiple(sequence, *multiples)
sequence.select do |i|
multiples.any? do |multiple|
i % multiple == 0
end
end.reduce(:+)
end
fib = Enumerator.new do |yielder|
i1, i2 = 1, 1
loop do
yielder.yield i1
i1, i2 = i2, i1 + i2
end
end
puts sumMultiple(fib... | true |
34ed457bb8485ac12bd6f80a19fc82cda81f7391 | Ruby | richinseattle/clone-detection | /src/GroupingClones.rb | UTF-8 | 8,796 | 3.25 | 3 | [
"Apache-2.0"
] | permissive | #!/usr/bin/ruby
require 'set'
# Note:
#
# Responsibility of this script:
# 1. Read result from CodeSurfer scheme program that detect clones
# 2. Clean subsumed clones and grouping clones
# 3. Display statistic of the clones found
#
# An example of how input and output looks like can be found at the bottom of this f... | true |
08972b88f6ee5242e90c215c91c4a4db6480e2c2 | Ruby | TimeSmash/dice-roll-ruby-nyc-web-060319 | /dice_roll.rb | UTF-8 | 300 | 3.765625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Create method `roll` that returns a random number between 1 and 6
# Feel free to google "how to generate a random number in ruby"
# def roll_using_range
# roll_range = (1..6)
# rand(roll_range)
# end
def roll #uses array
die_sides = [1,2,3,4,5,6]
die_sides[rand(0..die_sides.size-1)]
end | true |
d0f4d4de14989452c990d8a662f88701cdcbd816 | Ruby | Ckath/yossarian-bot | /plugins/bofh_excuses/bofh_excuses.rb | UTF-8 | 893 | 2.8125 | 3 | [
"LicenseRef-scancode-proprietary-license",
"MIT"
] | permissive | # frozen_string_literal: true
# bofh_excuses.rb
# Author: William Woodruff
# ------------------------
# A Cinch plugin that provides BOFH excuses for yossarian-bot.
# bofh_excuses.txt adapted from Jeff Ballard's BOFH Excuse Server:
# http://pages.cs.wisc.edu/~ballard/bofh/
# ------------------------
# This cod... | true |
d36a0a8a761fbedd466de1421ca1c5f52a60cc87 | Ruby | mehrdad-shokri/cartodb | /lib/carto/tracking/services/pubsub_tracker.rb | UTF-8 | 1,407 | 2.578125 | 3 | [
"LicenseRef-scancode-generic-cla",
"BSD-3-Clause"
] | permissive | require 'singleton'
require 'google/cloud/pubsub'
class PubSubTracker
include Singleton
def initialize
@pubsub = init_pubsub
@errored = false
@topics = {
metrics: metrics_topic
}
rescue StandardError => e
@errored = true
CartoDB::Logger.error(message: 'PubSubTracker: initializat... | true |
d47e4aefe82f561ddb4ba283f75a9deaeb1130fc | Ruby | Nordstrom/teradata-cli | /lib/configuration.rb | UTF-8 | 2,535 | 2.828125 | 3 | [] | no_license | require 'yaml'
# Encapsulates configuration settings for tdsql
class Configuration
def initialize(*args)
@config_settings = {}
# if config_files.nil?
# config_files = [
# "#{File.expand_path File.dirname(__FILE__)}/../tdsql.conf",
# "~/tdsql.conf",
# command_args[:conf]
# ]
# end
# raise c... | true |
c4661bc99645eb36469880ab811f0bc337967419 | Ruby | C-Mike576/ruby-collaborating-objects-lab-online-web-ft-110419 | /lib/artist.rb | UTF-8 | 994 | 3.375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require './lib/song.rb'
require 'pry'
class Artist
attr_accessor :name
@@all = []
def initialize(name)
@name = name
@@all << self
end
def songs
@songs = Song.all.select { |title| title.artist == self }
end
def add_song(song)
#refactor Has/Many
song.arti... | true |
c2fc5c28bf3ae4f739d6059aa9c907c8640ef745 | Ruby | rmatambo8/Ruby-Small-Problems | /medium_1/1000_lights.rb | UTF-8 | 1,186 | 4.28125 | 4 | [] | no_license |
# prompt : write a method that will take one argument,
# the total numbre of switches and return an array that
# identifies which lights are on after n repetitions
# rules
# - each switch connected to one light that is off at first
# - you turn every one of them on
# - on the second pass you toggle evens
# - third... | true |
9428fda6ab5cc5dadc1c6fc8636c78bd737093f6 | Ruby | Larrire/Buby-Start | /Project/pages/user.rb | UTF-8 | 143 | 3.09375 | 3 | [] | no_license | def user(user)
puts "User page"
50.times {print '-'}
puts ''
puts user.name
puts user.email
route = gets.chomp()
return route
end | true |
864a5d96deedd35816adf55fa48f0b92fed7f56f | Ruby | sd/notso-rails-app | /lib/snippets/array/slice_and_dice.rb | UTF-8 | 1,599 | 4.125 | 4 | [] | no_license | #==============================================================================
# Array slice and dice - by Sebastian Delmont <sd@notso.net>
#==============================================================================
# You have an array with 99 elements, and you want to display it in 3 columns,
# with the first co... | true |
c8cb74e5316b253d17fcd3d3eaf5f328ac301a6d | Ruby | chidraqul/chidraqul9 | /keypresses.rb | UTF-8 | 388 | 3.109375 | 3 | [] | no_license | #!/usr/bin/ruby
def read_char
system("stty raw -echo")
c = STDIN.read_nonblock(1) rescue nil
system("stty -raw echo")
return c
end
def keypress_tick
c = read_char
if (c === "q")
exit
elsif (c === "d")
move_right
elsif (c === "a")
move_left
elsif (c === "w")
... | true |
a347f882a6f4e2dfee67827b4b06ebdea7903e6a | Ruby | fenjiot/Metis-Prework | /learn_to_program/practice.rb | UTF-8 | 502 | 3.234375 | 3 | [] | no_license | myString = '...you can say that again...'
puts myString
puts myString
name = 'Patricia Rosanna Jessica Mildred Oppenheimer'
puts 'My name is ' + name + '.'
puts 'Wow! ' + name + ' is a really long name!'
composer = 'Mozart'
puts composer + ' was "da bomb", in his day.'
composer = 'Beethoven'
puts 'But I prefer ' +... | true |
fc6ed6eeb1759c5aa98e48189be487d4e932fef8 | Ruby | butipanax/time-international | /app/models/cart.rb | UTF-8 | 721 | 2.796875 | 3 | [] | no_license | class Cart < ActiveRecord::Base
has_many :line_items
def add_product(product_id)
current_item = line_items.find_by_product_id(product_id)
product_price = Product.find_by_id(product_id).price
if current_item
current_item.quantity += 1
current_item.price += product_price
else
curr... | true |
ea3f87d0117e87c78de42829920cf026a20609e9 | Ruby | casualuser/EvernoteFuse | /spec/evernote_enml_spec.rb | UTF-8 | 1,905 | 2.625 | 3 | [] | no_license | require File.join(File.dirname(__FILE__), '..', 'evernote', 'evernote_enml.rb')
describe REvernote::ENML do
before :each do
@content = 'hello world'
@enml1 = REvernote::ENML.new(@content)
end
describe :new do
it 'should accept a string and convert to the ENML' do
enml = REvernote::ENML.new(@co... | true |
84a5a7f59956bd9babda894fd4bacbc01824c90e | Ruby | tiagogodinho/exercism-solutions | /ruby/gigasecond/gigasecond.rb | UTF-8 | 109 | 2.875 | 3 | [
"MIT"
] | permissive | class Gigasecond
GIGASECOND = 1e9
def self.from(time_of_birth)
time_of_birth + GIGASECOND
end
end
| true |
482c1105545478e1fbd2893afa6bf03bfdec62f1 | Ruby | gogolqx/nand2tetris-4 | /thagomizer/11/lib/compile_to_xml.rb | UTF-8 | 1,205 | 2.984375 | 3 | [] | no_license | #!/usr/bin/env ruby -w
require_relative 'jack_tokenizer'
require_relative 'compilation_engine_ast'
require 'builder'
class CompileToXML
def self.run path
paths = []
if File.directory?(path)
Dir.entries(path).each do |entry|
paths << "#{path}/#{entry}" if entry =~ /jack$/
end
else
... | true |
58fcabfe202e7a27323f42e29e4e56eabf1f9709 | Ruby | pearlbea/bloaty-mcbloatface | /app/helpers/stories_helper.rb | UTF-8 | 664 | 2.59375 | 3 | [] | no_license | require 'uri'
module StoriesHelper
def random_cute_animal_image
[
'andrew-pons-9713-unsplash.jpg',
'freddie-marriage-40645-unsplash.jpg',
'josh-bean-591099-unsplash.jpg',
'matheus-queiroz-361095-unsplash.jpg'
].sample
end
def host_name(url)
URI.parse(url).host if url.present?... | true |
83d56c0aaf50b38b864bab79849f87ac142374fb | Ruby | mikaelsn/tiralabra | /app/models/sort.rb | UTF-8 | 1,731 | 3.390625 | 3 | [
"MIT"
] | permissive | class Sort < ActiveRecord::Base
#Bubblesort
def self.bubble(list)
list.each_index do |i|
(list.length - i - 1).times do |k|
if list[k] > list[k + 1]
#Ruby parallel assignment (swap)
list[k], list[k + 1] = list[k + 1], list[k]
end
end
end
end
#Quicksort
def self.quick_sort(list)
#Ini... | true |
34fad3e09795dbe8ab1347d3914ca1af73306be6 | Ruby | salayhin/mini-shop | /app/models/line_item.rb | UTF-8 | 271 | 2.5625 | 3 | [] | no_license | class LineItem < ActiveRecord::Base
####<$ Model Association $>####
belongs_to :cart
belongs_to :product
####<$ Validation $>####
validates_presence_of :cart_id, :product_id, :quantity, :product_price
def total_price
product.price * quantity
end
end
| true |
2cfe8e095807637f5cc19f9fdb3b95290c5436a1 | Ruby | telerik/docs-seed | /_plugins/figure.rb | UTF-8 | 577 | 2.671875 | 3 | [
"Apache-2.0"
] | permissive | module Jekyll
class FigureTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
attributes = text.split(',')
@number = attributes[0].strip
@title = attributes[1].gsub!("\"","").strip
@imgSource = attributes[2].gsub!("\"","").strip
end
def rend... | true |
0345d97dc9f5880abf0aa208123b94810b309a71 | Ruby | RaMin0/messenger-ruby | /lib/messenger/client.rb | UTF-8 | 1,232 | 2.609375 | 3 | [
"MIT"
] | permissive | require 'rest-client'
module Messenger
class Client
attr_accessor :config
def initialize(page_access_token:, verify_token:)
@config = Configuration.new(
verify_token: verify_token,
page_access_token: page_access_token
)
end
def self.get_user_profile(user_id, page_access_... | true |
477bccee448242f8e93d5d6d1e5705a11e9f97c6 | Ruby | mmorales4050/mod1_project | /spec/project_spec.rb | UTF-8 | 4,408 | 2.96875 | 3 | [
"MIT"
] | permissive | require "spec_helper"
describe "Project" do
describe "The player can move up" do
it "Moves the player up by one space" do
game = Game.new
room = Room.new
player = Player.new
room.width = 100
room.height = 100
game.spawn_player(room, player)
start_location = player.loca... | true |
61b9d769255df53fedebc4c92e96deadda45fc52 | Ruby | linsuri/nyc-web-062518 | /04-one-to-many/models/user.rb | UTF-8 | 374 | 2.90625 | 3 | [] | no_license | require_relative "models/tweet"
class User
attr_reader :username
def initialize(username)
@username = username
end
# TODO
def post_tweet(message)
@tweets << Tweet.new(message, self)
end
def tweets
Tweet.all.select do |tweet|
#tweet belongs to this user
# tweet.author.name == s... | true |
4d3cf77c91cd0770bd168c820f878e1fc2381c2f | Ruby | selivanovm/dotfiles | /bin/cloudshot.rb | UTF-8 | 1,495 | 2.5625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'date'
require 'net/http'
$CLOUDAPP_USER = "pelletier.thomas@gmail.com"
$CLOUDAPP_PASS = "xjm41s3l"
# Generate a file name.
$FNAME = Time.now.to_s.gsub(':', '-').gsub(' ', '-').gsub('+','') + ".png"
# Function to send a notification using libnotify
def notify(message)
%x{notify-send "[... | true |
a9ec0477be6f3b05958d0ac30f4c5b6af8cd4976 | Ruby | JudeQuintana/service_monitor | /lib/service_monitor/base_service.rb | UTF-8 | 381 | 2.703125 | 3 | [
"MIT"
] | permissive | module ServiceMonitor
class BaseService
attr_accessor :cmd
def initialize(cmd:)
self.cmd = cmd
end
def call
begin
output = `#{cmd}`
rescue Exception => e
output = e.message
puts "[+] There was a problem running the #{cmd} command!\n[+] Please fix it!\n#{outp... | true |
2abb82d2085730566061c0f0060bc5d694fae3db | Ruby | sensu-plugins/sensu-plugins-aws | /bin/check-asg-instances-created.rb | UTF-8 | 4,284 | 2.59375 | 3 | [
"MIT"
] | permissive | #! /usr/bin/env ruby
#
# check-asg-instance-created
#
# DESCRIPTION:
# Check AutoScalingGroup Instances are Terminated & Launching last hour.
#
# OUTPUT:
# plain-text
#
# PLATFORMS:
# Linux
#
# DEPENDENCIES:
# gem: aws-sdk
# gem: sensu-plugin
#
# USAGE:
# all AutoScalingGroup
# ./check-asg-instance-create... | true |
f27461e80ba924799caea9b91dcf2b3650734d1d | Ruby | scw248/guessing-cli-online-web-prework | /guessing_cli.rb | UTF-8 | 362 | 3.625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def run_guessing_game
loop do
puts "Guess a number between 1 and 6."
program_guess = rand(6)
user_response = gets.downcase.chomp
if user_response.to_i == program_guess
puts "You guessed the correct number!"
elsif user_response == 'exit'
puts "Goodbye!"
break
else
puts "The compute... | true |
3db03daad9757ee296a67cbf67eaf7150a69fba3 | Ruby | ryanholm/opal | /spec/corelib/string/format_spec.rb | UTF-8 | 254 | 2.828125 | 3 | [
"MIT"
] | permissive | describe "String#%" do
it "returns formatted string as same as Kernel#format" do
("%-5d" % 123).should == "123 "
end
it "can accept multiple arguments by passing them in an array" do
("%d %s" % [456, "foo"]).should == "456 foo"
end
end
| true |
fd678c451e1f2c62b4903baf13b66979fad11383 | Ruby | lishulongVI/leetcode | /ruby/413.Arithmetic Slices(等差数列划分).rb | UTF-8 | 2,769 | 3.8125 | 4 | [
"MIT"
] | permissive | =begin
<p>A sequence of number is called arithmetic if it consists of at least three elements and if the difference between any two consecutive elements is the same.</p>
<p>For example, these are arithmetic sequence:</p>
<pre>1, 3, 5, 7, 9
7, 7, 7, 7
3, -1, -5, -9</pre>
<p>The following sequence is not arithmetic.</p... | true |
8aff0cdfe18182747d926c0f9668a687eb0301f0 | Ruby | menor/dbc_rspec_1 | /source/list_spec.rb | UTF-8 | 1,332 | 3.234375 | 3 | [] | no_license | require "rspec"
require_relative "list"
describe List do
let(:title) { "Be a billionaire playboy" }
let(:list) { List.new(title) }
let(:tasks) { ["Earn my first billion", "Get fit"] }
let(:larger_list) { List.new(title, tasks) }
describe "#initialize" do
it "takes a title for its fi... | true |
8fd85ea35842e57395c82861c7acfa6e1d4200bd | Ruby | sticklercarla/ruby-intro-to-arrays-lab-dumbo-web-career-042219 | /lib/intro_to_arrays.rb | UTF-8 | 454 | 3.609375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def instantiate_new_array
@my_new_array = []
end
def array_with_two_elements
new_array = ["element1", "element2"]
end
def first_element(argument)
argument[0]
end
def third_element(argument)
argument[2]
end
def last_element(argument)
argument[-1]
end
def first_element_with_array_methods(argument)
argu... | true |
fc1e511026704f81f8e1945757f813e52d10d810 | Ruby | miluku1018/Codewars | /7kyu/Maximum Length Difference.rb | UTF-8 | 678 | 3.828125 | 4 | [] | no_license | # You are given two arrays a1 and a2 of strings. Each string is composed with letters from a to z. Let x be any string in the first array and y be any string in the second array.
# Find max(abs(length(x) − length(y)))
# If a1 and/or a2 are empty return -1 in each language except in Haskell (F#) where you will return ... | true |
35013b67a12a6988ab929ba66f3ef3b0a113d258 | Ruby | MorganBat/weather-cli | /nokogiri.rb | UTF-8 | 741 | 2.796875 | 3 | [] | no_license | require 'net/ftp'
require 'nokogiri'
# Log into BoM ftp server and download the XML file
# Using the ruby NET class for this
# ftp://ftp.bom.gov.au/anon/gen/fwo/IDN11050.xml
Net::FTP.open('ftp.bom.gov.au') do |ftp|
puts "downloading files"
ftp.login
files = ftp.chdir('anon/gen/fwo')
files =... | true |
ed41cbb9ac6947056fce8f1e789f5c522de16c97 | Ruby | acornellier/adventofcode | /2020/19.rb | UTF-8 | 1,077 | 2.953125 | 3 | [] | no_license | require_relative 'util'
require_relative 'input'
# @example_extension = 'ex1'
rules, messages = str_groups_separated_by_blank_lines(__FILE__)
@rules =
rules.to_h do |rule|
id, details = rule.split(': ')
match =
if details.start_with?('"')
details[1..-2]
else
details.split(' | ').... | true |
c6d193589024b713d0f54e056d8203879abee46d | Ruby | Matecrate/ruby-lol | /lib/lol/dynamic_model.rb | UTF-8 | 1,524 | 3.03125 | 3 | [
"MIT"
] | permissive | require 'ostruct'
require 'active_support/core_ext/string/inflections'
module Lol
# DynamicModel extends OpenStruct adding the following features:
# - nested generation ({a: {}}) results in DynamicModel(a: DynamicModel)
# - parsing of date/time when property name ends with _at or _date and the value is a number
... | true |
913e482ba83b35c5948a6c935254f2f4f73da6f5 | Ruby | val00274/console_selector | /lib/console_selector.rb | UTF-8 | 3,081 | 3.40625 | 3 | [] | no_license | require "console_selector/version"
require 'io/console'
module Console
module Keys
C_f, C_b, C_n, C_p = [
"\u0006", "\u0002", "\u000E", "\u0010"
]
Up, Down, Right, Left = [
"\e[A","\e[B", "\e[C", "\e[D"
]
def self.get_key(io)
c = io.getch
case c
when "\e"
# ... | true |
d93a545972c19ef872856202e21600263e7c94c5 | Ruby | condor/altsv | /spec/lib/altsv_spec.rb | UTF-8 | 6,401 | 2.578125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require 'spec_helper'
RSpec.describe Altsv do
describe :parse do
context 'String argument' do
it 'can parse labeled tab separated values into a hash in an array' do
line = "label1:value1\tlabel2:value2"
expect(Altsv.parse(line)).to eq [{:label1 => 'value1', :... | true |
9788016741b2ae27d73885b4d73e7c827a555edb | Ruby | yusuf-abdulla3/TwO-O-Player_Math-Game | /game.rb | UTF-8 | 294 | 3.21875 | 3 | [] | no_license | class Game
attr_accessor :current_player
def initialize(p2, p1)
@current_player = p2
@answer_player = p1
end
def questioner_input
number1 = rand(1..10)
number2 = rand(1..10)
mathQ = Question.new(@answer_player)
mathQ.question(number1, number2)
end
end | true |
925cb1895c626996a2394bca2f898a4728c38b8f | Ruby | bstoecker/rabbit | /ruby/fork.rb | UTF-8 | 144 | 2.671875 | 3 | [] | no_license | puts "This is the first line before the fork (pid #{Process.pid})"
puts fork
puts "This is the second line after the fork (pid #{Process.pid})"
| true |
b71eed0cf472b7d68f991f3be5118bcc01b94a2e | Ruby | brockwc/instructor-code-challenge | /app.rb | UTF-8 | 529 | 2.515625 | 3 | [] | no_license | require 'sinatra'
require 'json'
get '/' do
@faves = JSON.parse(File.read('data.json'))
erb :index
end
get '/favourites' do
response.header['Content-Type'] = 'application/json'
@file = File.read('data.json')
end
post '/favourites' do
file = JSON.parse(File.read('data.json'))
unless params[:name] && para... | true |
5db7c3cff9223d6806bf27411d9d20ecb7b60284 | Ruby | ravi-deepsource/axlsx | /lib/axlsx/stylesheet/border_pr.rb | UTF-8 | 1,977 | 2.984375 | 3 | [
"MIT"
] | permissive | module Axlsx
# A border part.
class BorderPr
include Axlsx::OptionsParser
# @return [Color] The color of this border part.
attr_reader :color
# @return [Symbol] The syle of this border part.
# @note
# The following are allowed
# :none
# :thin
# :medium
# :dashed
... | true |
38f4a46547cb59e45fa20ecba9c2e15a8215f3c6 | Ruby | tdeo/advent_of_code | /2022/test/15.rb | UTF-8 | 1,368 | 2.671875 | 3 | [] | no_license | # typed: strict
# frozen_string_literal: true
require 'sorbet-runtime'
require 'minitest/autorun'
require_relative('../lib/15_beacon_exclusion_zone')
class BeaconExclusionZoneTest < Minitest::Spec
extend T::Sig
sig { returns(T.class_of(BeaconExclusionZone)) }
def described_class = BeaconExclusionZone
sig { r... | true |
c11f56bd28851b5a49c14dd24da9823fbb439f0a | Ruby | Bobby-H/2016-jax-ft-summer | /week3/classes/interracting-with-classes/ninjaBear/fighter.rb | UTF-8 | 669 | 4 | 4 | [] | no_license | class Fighter
attr_reader :name
attr_accessor :health, :power
def initialize(name, health, power)
@name = name
@health = health
@power = power
end
def lose_health(enemy_power, health)
self.health -= enemy_power
end
def attack(enemy)
enemy.lose_health(self.power, enemy.health)
end
... | true |
5f6a40a3dc3c8a3e4adcbd1213134428f3afe7b8 | Ruby | pickabee/gandi | /lib/gandi/connection.rb | UTF-8 | 2,361 | 2.609375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'xmlrpc/client'
require 'openssl'
XMLRPC::Config.module_eval { # avoid "RuntimeError: wrong/unknown XML-RPC type 'nil'" using Ruby 1.9
remove_const(:ENABLE_NIL_PARSER)
const_set(:ENABLE_NIL_PARSER, true)
}
module Gandi
class Connection
SSL_VERIFY_MODE = OpenSSL::SSL::VERIFY_NONE
#The 24-cha... | true |
8d213cea6e832a5dc99b20ea778b2df5ab3b28ca | Ruby | shingara/personal-presentation | /cours/ruby/exercices/test_car_11.rb | UTF-8 | 571 | 2.75 | 3 | [] | no_license | require 'car'
require 'test/unit'
require 'test_car_10'
class ParkingTest < Test::Unit::TestCase
def setup
@car1 = Car.new
@car2 = Car.new
@car3 = Car.new
end
def test_add_cars
park = Parking.new(2)
assert_equal [],park.cars
park << @car1
assert_equal [@car1], park.cars
park << ... | true |
ee44493fc23a1dc38a64c892f808ded5460c850f | Ruby | DanielleSucher/Kenobi-on-Rails | /app/helpers/askmeanswerscraper.rb | UTF-8 | 5,151 | 2.625 | 3 | [
"MIT"
] | permissive | # Scraper to grab a user's Ask Metafilter answers and fav counts
class AskMeAnswerScraper
attr_accessor :askme_id, :should_answer_training, :should_not_answer_training
def initialize(user)
@user = user
@agent = Mechanize.new
@agent.ca_file = "./lib/assets/cacert.pem"
@should_a... | true |
11ae9f2212a2df5c97a9df493c85345b033dbfa7 | Ruby | diplay/Project | /app/models/tokenline.rb | UTF-8 | 4,642 | 3.03125 | 3 | [] | no_license | #coding: utf-8
class Tokenline
###########################
#-------iAppleJack--------#
###########################
attr_accessor :mistakes # Ошибки трансляции
def getstruct (tokens)
for i in 0..tokens.length - 1
if i > 0 and tokens[i] == "("
return tokens[0..(i - 1)]
end
end
... | true |
263cf9141c88bc1608cead657993522b6965bbeb | Ruby | tiemei/KE-complex_modifications | /scripts/erb2json.rb | UTF-8 | 876 | 2.84375 | 3 | [
"Unlicense"
] | permissive | #!/usr/bin/ruby
require 'erb'
require 'json'
def from(key_code, mandatory_modifiers, optional_modifiers)
data = {}
data['key_code'] = key_code
mandatory_modifiers.each do |m|
data['modifiers'] = {} if data['modifiers'].nil?
data['modifiers']['mandatory'] = [] if data['modifiers']['mandatory'].nil?
... | true |
a288f91f39349bd4f2db025d60abb3ee5ce7fbae | Ruby | jisuanjixue/programming-exercise | /03-triangle.rb | UTF-8 | 306 | 3.96875 | 4 | [] | no_license | # 题目: 使用者输入直角三角形的宽和高,输出三角形的面积
print "请输入直角三角形的高,然后按 Enter: "
a = gets
a = a.to_f
print "请输入直角三角形的底边,然后按 Enter: "
b = gets
b = b.to_f
area = (a * b)/2
puts "直角三角形的面积是: #{area}"
| true |
0f1d9cc253deaf634dda57a74db79f0297d1dd9a | Ruby | johnbcable/Cucumber | /Ruby/code/step_definitions/05/assertions_sidebar/assertion.rb | UTF-8 | 650 | 2.5625 | 3 | [] | no_license | #---
# Excerpted from "The Cucumber Book, Second Edition",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material,
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose.
# V... | true |
0137f5585077faaaa1dfd370713044dab07ad22d | Ruby | yegeniy/JBS | /HW/HW2/myserver.rb | UTF-8 | 4,512 | 3.390625 | 3 | [] | no_license | ######
# Ruby Client and Server, HW1
# Serve content between client and server
# Eugene Wolfson
# No preconditions
# type ruby myserver.rb at the prompt and then connect to localhost port 8888
######
require 'gserver'
FORTUNES = ["You will learn a lot", "You will get an 'A", "You still have much to learn, Grasshopper"... | true |
cb793e193b7487c22bf10f0aaeb9abfb4eead876 | Ruby | gengogo5/atcoder | /ABC/abc100/abc100_C.rb | UTF-8 | 169 | 2.84375 | 3 | [] | no_license | N = gets.to_i
a = gets.split.map(&:to_i)
cnt = 0
N.times do |i|
loop do
if a[i].even?
a[i]/=2
cnt+=1
else
break
end
end
end
puts cnt
| true |
4719068fa411a999bca5aba13f9c54a7824e3c91 | Ruby | beyaz/exploring_miracle_19 | /appendix_1_superhuman_numerical_combinations_13.rb | UTF-8 | 1,335 | 3.6875 | 4 | [] | no_license | require_relative("surah_ayatNum_collection.rb")
# if we write down the numbers of verses in every sura next to each other, we end up with a 235-digit number that is a multiple of 19. To do this, write down the total number of numbered verses in the Quran (6234), followed by the number of verses in every sura, then clos... | true |
dcb701b856e7652ffb33c4f2b8fe06560438e85e | Ruby | brianli-whitbread/Contact-List-App | /contact_database.rb | UTF-8 | 3,207 | 3.3125 | 3 | [] | no_license | ## TODO: Implement CSV reading/writing
require 'csv'
class ContactDatabase
attr_accessor :array_of_contacts, :new_user_to_add
def load_contacts
@new_user_to_add = []
@array_of_contacts = []
#loops through list, and insers each row of items into variables
CSV.foreach('contacts.csv', converters: :... | true |
987ae371a728e3b4fa3b02b1ae3827fc489526e4 | Ruby | worashf/leetcode-solutions | /ruby/Q513/Q513.rb | UTF-8 | 769 | 3.40625 | 3 | [] | no_license | # 2017-04-13
# David Lin
# Leetcode 513
# Method: BFS
# Definition for a binary tree node.
# class TreeNode
# attr_accessor :val, :left, :right
# def initialize(val)
# @val = val
# @left, @right = nil, nil
# end
# end
# @param {TreeNode} root
# @return {Integer}
def find_bottom_left_value... | true |
290418a6b5ad9266c394d58dfffc5c23fece12e7 | Ruby | thpolwat/pick-engineer | /picker.rb | UTF-8 | 249 | 3.203125 | 3 | [] | no_license | def pick_engineer() #function for random name
engineer = Array.new() #create array
engineer = File.readlines("engineers.txt") #read file from name_engineer.txt
puts engineer[rand(engineer.count)] #print random_engineer_name
end
pick_engineer()
| true |
0ad91df98b25f589a3f97b984f9ba0dc81f03e84 | Ruby | Fallonious/OnTheClock | /app/models/developer.rb | UTF-8 | 377 | 2.703125 | 3 | [] | no_license | class Developer < ActiveRecord::Base
has_many :time_entries
has_secure_password
def hours_worked
total_hours = 0.0
start_week = Time.now.beginning_of_week
end_week = Time.now.end_of_week
time_entries.each do |t|
if start_week..end_week.include?(time.worked_on)
total_hours += t.dura... | true |
dfbb3459dd3dc2508398894c4f099b1eceaee710 | Ruby | bskillings/Odin-Ruby-Testing-with-RSpec | /ConnectFour/spec/connect_four_spec.rb | UTF-8 | 2,324 | 3.015625 | 3 | [] | no_license | require "spec_helper"
describe ConnectFourBackEnd do
before(:each) do
@c4 = ConnectFourBackEnd.new
end
context "at the beginning" do
it "makes a game board" do
expect(@c4.game_board.any?).to eq true
end
it "game board has all slots" do
expect(@c4.game_board.length).to eq 42
end
it "has two... | true |
0acb0249dd9211d318516300e71b1d4d5f8950d3 | Ruby | cfoust/leetcode-problems | /problems/longest-repeating-character-replacement/solution.rb | UTF-8 | 106 | 2.546875 | 3 | [] | no_license | # @param {String} s
# @param {Integer} k
# @return {Integer}
def character_replacement(s, k)
end | true |
e29084f9807f56bf3915b07ae5b0d7e2d9093176 | Ruby | usmansbk/ruby-group-project | /spec/book_spec.rb | UTF-8 | 703 | 2.53125 | 3 | [] | no_license | require_relative 'spec_helper'
describe Book do
describe '#can_be_archived' do
context 'when published over 10 years' do
item = Book.new('microverse', 'good', Time.new(1995, 1, 1))
it 'can be archived' do
expect(item.can_be_archived?).to be_truthy
end
end
context 'when cover st... | true |
3c7f3ee480828b525a2bf8c85a6f65b1352370a3 | Ruby | sp2410/RVNB | /app/models/availability.rb | UTF-8 | 1,380 | 2.765625 | 3 | [] | no_license | class Availability < ApplicationRecord
belongs_to :listing
has_many :reservations
def start_time
self.startdate ##Where 'start' is a attribute of type 'Date' accessible through MyModel's relationship
end
def end_time
self.enddate ##Where 'start' is a attribute of type 'Date' acc... | true |
746d6f896dced8641e4e2c6bed6dfda589480041 | Ruby | FernandaFranco/book-intro-programming | /arrays/exercise_2.rb | UTF-8 | 298 | 3.65625 | 4 | [] | no_license | 1. arr = ["b", "a"]
arr = arr.product(Array(1..3))
arr.first.delete(arr.first.last)
#returns 1
#the value of arr is [["b"], ["b",2]...]
2. arr = ["b", "a"]
arr = arr.product([Array(1..3)])
arr.first.delete(arr.first.last)
#returns [1,2,3]
#the value of arr is [["b"], ["a", [1,2,3]]] | true |
5dd3b240ad206b91d2d7970445345566dbf76e1b | Ruby | vibraniumforge/intro-to-simple-array-manipulations-seattle-web-career-042219 | /lib/intro_to_simple_array_manipulations.rb | UTF-8 | 551 | 3.265625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def using_push(ar, str)
ar << str
end
def using_unshift(ar, str)
ar.unshift(str)
end
def using_pop(ar)
ar.pop
end
def pop_with_args(ar)
ar.pop(2)
end
def using_shift(ar)
ar.shift
end
def shift_with_args(ar)
ar.shift(2)
end
def using_concat(ar1, ar2)
ar1.concat(ar2)
end
def using_inse... | true |
99afb74ee181407f5dd688e4ccaa1f953c8cd8ef | Ruby | SkinnyPigeon/Olympics | /models/athlete.rb | UTF-8 | 2,160 | 3.21875 | 3 | [] | no_license | require('pry-byebug')
require_relative('../db/sql_runner')
require_relative('nation')
class Athlete
attr_reader( :name, :id, :finishing_positions, :nation_id, :results, :gold, :silver, :bronze, :nation )
def initialize( options )
@name = options['name']
@id = options['id'].to_i
@nation_id = options['... | true |
47b6aaf01ab29cf4e20b9e694f6d22b7e6f2d2d6 | Ruby | cassioalmeidas/trabalho_ia | /adaline.rb | UTF-8 | 2,228 | 3.5 | 4 | [] | no_license | class Adaline
attr_accessor :quando_aprendeu, :pesos
TAXA_APRENDIZADO = 0.0025
PRECISAO = 10 ** (-6)
# Inicializa atributos
def initialize
@limiar = -1
@pesos = Array.new(5) { rand }
@quando_aprendeu = 0
end
def treinar!
puts "Treinando..."
puts "Pesos iniciais: #{@pesos}"
en... | true |
7e0b67c5103d7f26cbe76fca7aec73bf775ac971 | Ruby | DontJar/pokemon-scraper-dc-web-071618 | /lib/pokemon.rb | UTF-8 | 672 | 3.375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
require_relative "./scraper.rb"
class Pokemon
attr_accessor :id, :name, :type, :db, :hp
def initialize (name:, id:, type:, db:, hp: nil)
@id = id
@name = name
@type = type
@db = db
@hp = hp
end
def self.save(name, type, db)
db.execute("INSERT INTO pokemon (name, type) V... | true |
809a551223b7d958dfdf6ae0c0357f36892c3053 | Ruby | abadfish/ttt-8-turn-q-000 | /bin/turn | UTF-8 | 216 | 3.078125 | 3 | [] | no_license | #!/usr/bin/env ruby
require_relative '../lib/turn.rb'
board = [" ", " ", " ", " ", " ", " ", " ", " ", " "]
puts "Please enter 1-9:"
pos = gets.strip
valid_move?(board, pos)
turn(board)
display_board(board)
| true |
205c19d5ce499e069e539b53c1b7b5bb20a6a7c7 | Ruby | KentonWhite/see-me-crawl | /lib/entropy.rb | UTF-8 | 739 | 3.03125 | 3 | [] | no_license | require 'dm-chunked_query'
class Entropy
attr_accessor :distribution, :total_degree
def initialize
@distribution = Hash.new(0)
@total_degree = 0
load_distribution
end
def load_distribution
DataMapper.repository(:local) do
Sample.each_chunk(20) do |chunk|
chunk.each do |s|
... | true |
59a305aa371fc8ba3a2979e6d53d429277152117 | Ruby | nogtk/design_pattern_on_ruby | /06_prototype/message_box.rb | UTF-8 | 427 | 2.59375 | 3 | [] | no_license | require_relative 'framework/product'
module Prototype
class MessageBox
attr_reader :decochar
include Prototype::Framework::Product
def initialize(decochar)
@decochar = decochar
end
def use(str)
length = str.bytesize
puts @decochar*(length+4)
puts "#{@decochar} #{str} #{... | true |
5c3f101abfb6fb891d70428ed3f0deff0f9ac854 | Ruby | lucasaxm/graph_ruby | /laxm11-calm11/node.rb | UTF-8 | 1,277 | 3.109375 | 3 | [] | no_license | class Node
attr_accessor :name,
:graph
attr_reader :attrs
def initialize(name)
@name = name
@attrs = {}
end
def []( key )
@attrs[key.to_s]
end
def []=( key, value )
if value.nil? || key.nil?
warn "Key and Value can't be null"
return
end
if key.clas... | true |
b76918d0cc6d55b08403a70b3060d167893add2e | Ruby | vaxinate/clean-up-examples | /star_rating.rb | UTF-8 | 663 | 3.15625 | 3 | [] | no_license | def do_hotel_stars(rating, lit_star = nil, dim_star = nil)
lit_star ||= content_tag(:span, ' ', :class => 'yellow_star')
dim_star ||= content_tag(:span, ' ', :class => 'grey_star')
buff = ""
rating.times { buff += lit_star }
(5 - rating).times { buff += dim_star }
buff
end
# pass this a block... | true |
fa41ba7edf063f66fa33552794eef18c0ad7f0d7 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/nth-prime/b8af476ebf5e4f20a943f91139f8e39b.rb | UTF-8 | 578 | 3.703125 | 4 | [] | no_license | class Prime
def self.nth(n)
raise ArgumentError if n == 0
count = 2
primes = []
until primes.length == n
primes << count if is_prime(count)
count += 1
end
primes.last
end
def self.is_prime(number)
# 6n +- 1 <= sqrt(number)
if number <= 3
return number >= 2
elsif number %... | true |
e02c1d77e07f0acff5989e7d515d3c3872b03115 | Ruby | fbatz/scaleable_web_soa_workshop | /ReportSystem/report_system_api.rb | UTF-8 | 1,850 | 2.75 | 3 | [] | no_license | require 'sinatra'
require 'json'
require_relative '../ItemTracking/item_tracking_client'
require_relative '../LocationManagement/location_management_client'
require_relative '../USerManagement/user_management_client'
class ReportSystemAPI < Sinatra::Base
get '/reports/by_location' do
# creates a re... | true |
b2397e4f4840a01f21953946649638a0adf29468 | Ruby | bogdanovich/codeeval | /0-easy/road_trip/road_trip.rb | UTF-8 | 262 | 2.734375 | 3 | [] | no_license | ARGF.each do |line|
line = line.strip
distances = line.split(";").map {|city_info| city_info.split(",")[1].to_i}.sort
output = [distances[0]]
(1...distances.size).each do |i|
output << distances[i] - distances[i - 1]
end
puts output.join(",")
end | true |
1496a397ca760c222f9a25671b1e9da6c6ea90e3 | Ruby | rhomobile/rhodes | /res/build-tools/ruby-standalone/212/usr/local/lib/ruby/gems/2.1.0/gems/extlib-0.9.16/spec/blank_spec.rb | UTF-8 | 1,599 | 3.15625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT",
"MPL-1.1",
"BSD-3-Clause",
"GPL-2.0-only"
] | permissive | require 'spec_helper'
require 'extlib/blank'
describe Object do
it 'should provide blank?' do
Object.new.should respond_to(:blank?)
end
it 'should be blank if it is nil' do
object = Object.new
class << object
def nil?; true end
end
object.should be_blank
end
it 'should be blank if... | true |
c2eca60ed709dae3faf60cc03a9e02d90c6cd92d | Ruby | cep104/show_cli_group2 | /lib/show_cli_group2/api.rb | UTF-8 | 457 | 2.765625 | 3 | [] | no_license | class API
def self.get_data
response = RestClient.get("http://api.tvmaze.com/search/shows?q=friends")
shows = JSON.parse(response)
shows.each do |show|
new_show = show["show"]
# attr_accessor :name, :genres, :language, :status
Show.new(new_show["name"], new_show[... | true |
b966474a67004df54eaf6b286d6fccb2b6cc566c | Ruby | bio-org-au/search-server-graphql | /app/models/name_status/find.rb | UTF-8 | 680 | 2.53125 | 3 | [] | no_license | # frozen_string_literal: true
# Class that finds a Name Status record matching a URI (id).
# The instance object must respond to attribute methods
# on the Name Status record.
class NameStatus::Find
def initialize(args)
id = args['id']
@name_status = NameStatus.find_by(id: id)
raise 'no matching name sta... | true |
31b233426cc4f42e4bd7e7064c19efedcfb689b1 | Ruby | darthKwisatzHaderach/yandex_weather | /tests/select_city.rb | UTF-8 | 380 | 2.78125 | 3 | [] | no_license | #encoding: utf-8
require 'rubygems'
require 'selenium-webdriver'
require_relative '../page_object/weather_page.rb'
CITY = ARGV[0]
begin
browser = Selenium::WebDriver.for :ff
weather_page = WeatherPage.new(browser, true)
weather_page.search_field = CITY
weather_page.search_button
puts "Success!" if (weather... | true |
f10b221d33f4c105b4fd95d94474197ef05bf471 | Ruby | rohanphillips/school-domain-online-web-sp-000 | /lib/school.rb | UTF-8 | 433 | 3.578125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
class School
attr_reader :name
def initialize(name)
@school_name = name
@roster = {}
end
def roster()
@roster
end
def add_student(student_name, grade)
if @roster.key?(grade) == false
@roster[grade] = []
end
@roster[grade] << student_name
end
def grade(gra... | true |
88ef855024591230d4e76a6e02ca17cf3cb30102 | Ruby | alexander-horne/Exercice-Ruby | /exo_09.rb | UTF-8 | 179 | 3.53125 | 4 | [] | no_license | puts "Bonjour, est-ce que tu peux indiquer ton prenom et nom de famille s'il te plait ?"
prenom = gets.chomp
nom_de_famille = gets.chomp
puts "Bonjour, #{prenom + nom_de_famille}" | true |
53ff620c1cfdc76f78bc2b961181ad106cacb019 | Ruby | Hyunho/delay_paper | /test/compress_test.rb | UTF-8 | 3,002 | 2.9375 | 3 | [] | no_license | require './lib/compress'
require './lib/sensor_network'
require 'test/unit'
class ErrorTreeTest < Test::Unit::TestCase
def setup
@data = [11, -1, -6, 8, -2, 6, 6, 10]
@coefficients = [4,-1,2,-3,6,-7, -4, -2]
@error_tree = Compression::ErrorTree.new(@data)
end
def test_make_tree
assert_e... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.