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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
8bd0e06dfe8f1e335d5d6186dce27014148f6061 | Ruby | stuart/Ruby-OpenACN | /ddl/DDL.rb | UTF-8 | 3,907 | 2.78125 | 3 | [] | no_license | require 'nokogiri'
require 'open-uri'
require 'uuid'
require File.expand_path(File.dirname(__FILE__) + '/DDL_module.rb')
require File.expand_path(File.dirname(__FILE__) + '/DDL_element.rb')
require File.expand_path(File.dirname(__FILE__) + '/device_description.rb')
require File.expand_path(File.dirname(__FILE__) + '/l... | true |
f86dd46b126acae442d89bc8e251e30fc2cebe26 | Ruby | pelluch/ruby_kml | /lib/kml/polygon.rb | UTF-8 | 2,525 | 2.96875 | 3 | [
"MIT"
] | permissive | # Source file which generates a Polygon element.
#
# <Polygon id="ID">
# <!-- specific to Polygon -->
# <extrude>0</extrude> <!-- boolean -->
# <tessellate>0</tessellate> <!-- boolean -->
# <altitudeMode>clampToGround</altitudeMode>
# <!-- kml:altitudeModeEnum: clampTo... | true |
deb0a8ae1287f2dcb54c80ccc18b9492926488c2 | Ruby | nancyhawa/jotto | /misc/sortlist.rb | UTF-8 | 349 | 3.546875 | 4 | [] | no_license | require_relative '../app/models/wordlist'
def repeat_letters?(word)
x = 0
while x < word.split(//).length - 1
return true if word.split(//).count(word.split(//)[x]) > 1
x += 1
end
return false
end
def sort
list = []
dictionary.each do |x|
if (x.length == 5) && repeat_letters?(x) == false
list.push(x)
en... | true |
2385b53f157a76fd237a592aca51caf20eb919d1 | Ruby | zaydion/Rinstagram | /test/models/user_test.rb | UTF-8 | 1,342 | 2.703125 | 3 | [] | no_license | require 'test_helper'
class UserTest < ActiveSupport::TestCase
setup do
@user = User.new(name: "Example User", email: "example@email.com")
end
test "user should be valid" do
assert @user.valid?
end
test "user should have name" do
@user.name = " "
assert_not @user.valid?
end
test... | true |
328434e848c9d441cecb2de6f9d9b6816118b9c9 | Ruby | hioken/LOG__RubyCherryBook | /try/gate.rb | UTF-8 | 374 | 3.265625 | 3 | [] | no_license | class Gate
STAITIONS = [:umeda, :juso, :mikuni]
FARES = [150, 190]
def initialize(name)
@name = name
end
def enter(ticket)
ticket.stamp(@name)
end
def exit(ticket)
ticket.fare >= exit_fare(ticket)
end
private
def exit_fare(ticket)
distance = STAITIONS.index(@name) - STAITIONS.index... | true |
13271c2f9efbaecccf23ffccced7518a94d9bbde | Ruby | timmillwood/onboard | /lib/onboard/project.rb | UTF-8 | 1,897 | 2.578125 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
require 'fileutils'
require 'find'
require 'nokogiri'
require 'rubygems/package'
require 'zlib'
module Onboard
TAR_LONGLINK = '././@LongLink'
class Project
attr_reader :feed, :path, :dest
def initialize(args = {})
@feed = "http://updates.drupal.org/release-history/#{args['project... | true |
4a59d3bee37e702072ce4f163b7f0fd759946248 | Ruby | idkjay/Launch | /ignition/week5-rubydatastructures/voter-demographics/code.rb | UTF-8 | 2,876 | 2.921875 | 3 | [] | no_license | voter_demos = [
{first_name: "Jon", last_name: "Smith", age: 25, income: 50_000, household_size: 1, gender: "Male", edu: "College"},
{first_name: "Jane", last_name: "Davies", age: 30, income: 60_000, household_size: 3, gender: "Female", edu: "High School"},
{first_name: "Sam", last_name: "Farelly", age: 32, inc... | true |
9cd815abb05ca7c5804b0eb8505b0f8c864715a9 | Ruby | xuanxu/random_sources | /spec/random_org_spec.rb | UTF-8 | 7,878 | 2.671875 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__) + '/spec_helper'
describe RandomSources::RandomOrg do
describe 'Integers generator' do
before(:each) do
@base_url = "http://www.random.org/integers/"
@default_params = {'max' => 100,
'min' => 1,
'base' => 10,
... | true |
ea43bf662de945ad56f7cabaac61d44d2c2543b2 | Ruby | jasonmahony/ruby | /sequence.rb | UTF-8 | 426 | 3.671875 | 4 | [] | no_license | #!/usr/bin/env ruby
# Find the greatest sequence of 5 digits in an integer string
def solution(digits)
# Return nothing if input has less than 5 digits or it equals 0
return nil if digits.length < 5 || digits.to_i == 0
digits.chars.map { |c| digits[digits.index(c), 5].to_i }.max
end
puts solution("234506984")
p... | true |
0d9cb773d11eb94e02d7c74f97eb65dfd12a2090 | Ruby | ben-harvey/Small-problems-Ruby | /challenges/medium1/protein_translation.rb | UTF-8 | 1,474 | 3.28125 | 3 | [] | no_license | =begin description
class methods
of_codon(input)
input: string rep codon
output: string rep protein
rules
{
['AUG'] => 'Methionine',
%w(UUU UUC) => 'Phenylalanine'
%w(UUA UUG) => 'Leucine',
%w(UCU UCC UCA UCG) => 'Serine',
%w(UAU UAC) => 'Tyrosine',
%w[UGU UGC] 'Cysteine',
['UGG'] => 'Tryptop... | true |
7469e96769f97da30ca3884e6ec79a03d9905027 | Ruby | nicolas111boivin/Jeu | /jeux_correction.rb | UTF-8 | 472 | 3.65625 | 4 | [] | no_license | # coding: utf-8
puts "Bonjour pour jouer à ce petit jeux c'est simple:\nVous choisisez l'arme en entrant son chiffre (par exemple 1 pour choisir une épée"
puts "Vous êtes prêts ?"
oui = gets
vie = 30
if oui.chomp == "oui"
puts "C'est partit\nChoisiez une arme";
choixArme = gets.to_i
if (choixArme == 1)
puts ... | true |
935db295c0240dc579bc6afe2579decb30124d3b | Ruby | waldo/five_hundred | /lib/five_hundred/player.rb | UTF-8 | 1,773 | 3.046875 | 3 | [] | no_license | # encoding: UTF-8
require "five_hundred/team"
module FiveHundred
class Player
attr_reader :kitty, :discarded_kitty
attr_accessor :team, :game
def initialize
@cards = []
@kitty = []
@discarded_kitty = []
@team = Team.empty
@game = nil
end
def round
game.curren... | true |
65adce3f44bf00ec3ae5246aa116fa3d47848d29 | Ruby | opennorth-archive/pybossa-api-ruby | /lib/pybossa-api/task_run.rb | UTF-8 | 2,138 | 2.703125 | 3 | [
"MIT"
] | permissive | module PyBossa
module TaskRun
class << self
# @param [Hash] opts optional arguments
# @option opts [Integer] :limit number of results to return [default 20]
# @option opts [String] :api_key an API key
# @return [Array] a list of task runs
def list(opts = {})
PyBossa::API.many... | true |
5ed7df443449de68324ee5f108f1a26db1abaf87 | Ruby | patgraczyk/w2_d1_homework | /football.rb | UTF-8 | 488 | 3.234375 | 3 | [] | no_license | class FootballTeam
attr_reader :team_name, :players, :coach, :points
attr_writer :team_name, :players, :coach, :points
def initialize (team_name, players, coach)
@team_name = team_name
@players = players
@coach = coach
end
def add_players(new_player)
@players.push(new_player)
end
def check_players(check_... | true |
62245b5e85ddd54e9a9e4bfae9f4ed2b55746c9a | Ruby | roguerb/sort_algorithms | /spec/sort_helper_spec.rb | UTF-8 | 1,371 | 3.0625 | 3 | [] | no_license | require_relative '../sort_helper.rb'
describe 'sort helper' do
describe 'sorted?' do
context 'nil' do
it 'is already sorted' do
expect { sorted?(nil) }.to(
raise_error ArgumentError
)
end
end
context 'boolean' do
it 'raises an exception' do
expect { so... | true |
252afeaab4ff8652755d35cd7dd7c3244f197386 | Ruby | yahonda/active_pstore | /lib/active_pstore/persistence.rb | UTF-8 | 1,171 | 2.53125 | 3 | [
"MIT"
] | permissive | # -*- frozen-string-literal: true -*-
require 'securerandom'
module ActivePStore
module Persistence
attr_reader :id
def destroy
ActivePStore::Base.use_connection do |connection|
connection[self.class.pstore_key].delete_if {|obj| obj.id == self.id }
end
self
end
def new_r... | true |
5e2d668f39c72de245dd3756bc92dfce697def5a | Ruby | cjgoods/learn_ruby | /03_simon_says/simon_says.rb | UTF-8 | 449 | 3.953125 | 4 | [] | no_license | #write your code here
def echo(v)
"#{v}"
end
def shout(v)
"#{v}".upcase
end
def repeat(v, n=2)
("#{v} " * n).rstrip
end
def start_of_word(v, n)
if n == 1
v[n-1]
else
v[0..(n-1)]
end
end
def first_word(v)
v.split[0]
end
def titleize(v)
words = v.split
words[0].capitalize!
words.map do |i... | true |
e864b671e7cbf6ed55222df7e32c9e4c29029301 | Ruby | foberleitner/advent-of-code | /lib/assembunny.rb | UTF-8 | 9,340 | 3.21875 | 3 | [] | no_license | #!/usr/bin/env ruby
##
# History:
# 2016/23 Part 2 takes far too long to run
# -> transpile to C?
# -> also think about what does the Assembunny code do, not just instruction
# by instruction but in whole blocks of instructions
# Maybe some parts can be optimized by introducing new instructions?
#
# Ano... | true |
7a7d31c6fd0c6db0a01e408e2d9743902bd32cde | Ruby | doevelopper/badges2svg | /bin/badges2svg | UTF-8 | 693 | 2.75 | 3 | [
"MIT"
] | permissive | #! /usr/bin/env ruby
# -*- coding: UTF-8 -*-
require 'trollop'
require 'badges2svg'
opts = Trollop.options do
version "badges2svg #{BadgesToSVG.version}"
banner <<-EOS
badges2svg is a tool to replace your PNG GitHub badges with resolution-independant SVG ones.
Usage:
badges2svg [options] <file>
where [optio... | true |
c9d36a27e894d246efc3b500a16dadfb8111bcbc | Ruby | alexrothenberg/football_predictor | /lib/samples/reading_files.rb | UTF-8 | 238 | 2.640625 | 3 | [] | no_license | # __FILE__ is a keyword for the current file, run this file using: ruby reading_files.rb
puts __FILE__
contents = File.read(__FILE__)
puts contents
# Read more here:
# * http://www.engr.uconn.edu/~rohitm/tutorials/crash2/slide-0-6.html | true |
4d02dba705ee987b7c7911bbfb20980c331ca822 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/gigasecond/d84d8b0dbe6a406ca625d12990f675bb.rb | UTF-8 | 309 | 3.453125 | 3 | [] | no_license | require 'date'
require 'time'
class Gigasecond
def self.from(dateVal)
# Convert gigaseconds to number of days
days = 10**9/86400
# Use Julian Date and add the days to the date value passed in the method and return the resulting future date
futuredate = Date.jd(dateVal.jd + days)
end
end
| true |
77b4c90b0e6a1306c8f5afc042ef0297a5f742d0 | Ruby | andrey-hura/learn_ruby | /13_xml_document/xml_document.rb | UTF-8 | 506 | 3.078125 | 3 | [] | no_license |
class XmlDocument
def initialize(nested=false)
@nested = nested
@nest = ''
@newline = ""
if @nested then @newline = "\n" end
end
def method_missing(tag,attr={})
out = ''
out += "<#{tag}"
attr.each{|k,v| out += " #{k}='#{v}'" }
if block_given? then
out +=">#@newline"
... | true |
281dd194d58efebd43f363d29160718a62ded2cc | Ruby | juanmougan/file-tagger | /header_generator.rb | UTF-8 | 970 | 2.890625 | 3 | [] | no_license | require 'yaml'
require 'date'
require_relative 'commentable_file'
class HeaderGenerator include CommentableFile
attr_accessor :file
def initialize file_to_add_header_to
self.file = file_to_add_header_to
end
# TODO move to module? or to a new object (for testability)?
def serialize_commented_keywords... | true |
66ed0bdaca8b4ce4dcd4de469c58922c013ceea5 | Ruby | lanajen/hackster | /app/models/widgets/step_by_step_widget.rb | UTF-8 | 448 | 2.625 | 3 | [
"SHL-0.51"
] | permissive | class StepByStepWidget < Widget
include TablelessAssociation
has_many_tableless :steps, order: :position
def self.model_name
Widget.model_name
end
def to_text
out = "<h3>#{name}</h3>"
steps.each_with_index.map do |step, i|
out << "<h4>Step #{i+1}: #{step.title}</h4>"
out << step.det... | true |
ce920b6741ee9b6bd4922f8a8598066a34c24821 | Ruby | VictorArd/THP-VICLO | /J4/lib/00_hello.rb | UTF-8 | 277 | 4.1875 | 4 | [] | no_license |
def ask_first_name
puts "What's your name ?"
print "> "
first_name = gets.chomp
return first_name
end
def say_hello(first_name)
puts "Bonjour, #{first_name}"
end
def combine
first_name = ask_first_name
return say_hello(first_name)
end
combine | true |
3b45a3a4994fa6d70a75122b001179c24cda5874 | Ruby | karthikeyankkn/ruth-shipping | /app/models/lead.rb | UTF-8 | 1,022 | 2.65625 | 3 | [] | no_license | class Lead < ApplicationRecord
require 'csv'
belongs_to :user
before_save :downcase_data
default_scope -> { order(created_at: :desc) }
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
# avoid duplication for csv lead upload
# lead_check = Lead.where(phone_number: row.to_... | true |
17b4df06880bc8f704eeafeec4f53e5ccbc7f164 | Ruby | ronanduddy/exercises | /ruby/functions/blocks/yield.rb | UTF-8 | 744 | 4 | 4 | [] | no_license | # `yield` is functionally equivalent to fn.call. It will find and invoke
# the block function that a method has been called with. Or it will invoke
# the block that has been 'passed into' a method. There's no need for the
# `&block` parameter which can be used to accept the block.
def triple
yield
yield # implicit ... | true |
e76b6f5cdf3d3e5c40c2d8f056e8ef53ba33f593 | Ruby | blat/twitter-links | /lib/user.rb | UTF-8 | 3,324 | 2.53125 | 3 | [] | no_license | # encoding: UTF-8
require './lib/abstract'
require './lib/link'
module TwitterLinks
class User < Abstract
self.type = 'user'
self.attributes = [:screen_name, :token, :secret, :crawled_at]
# Init a user
# Overrided to handle internal hash/array
#
# Params:
... | true |
c27f5de9ead15106a0805d7754fd953958178043 | Ruby | ayeshafawad/aws-consumer | /app/AFawad/controllers/dynamotables_controller.rb | UTF-8 | 6,284 | 2.65625 | 3 | [] | no_license | class DynamotablesController < ApplicationController
# ----------------
# List all Tables
# ----------------
def index
@dynamotables = $dynamodb.tables.map{ |x| Dynamotable.new(name: x.name) }
end
def new
@dynamotable = Dynamotable.new
end
# ----------------------
# Create a Dynamo Tab... | true |
91d373f2066162165746e5e252f4e3f6ab08ea79 | Ruby | mlibrary/umich_catalog_indexing_old | /dindex/common_ht.rb | UTF-8 | 2,469 | 2.640625 | 3 | [] | no_license | #################################
# COMMON HT STUFF
#################################
# Start off by building up a data structure representing all the 974s
# and stick it in ht_fields. Also, query the database for the print
# holdings along the way with #fill_print_holdings!
each_record do |r, context|
itemset = H... | true |
4c1b4685d882b4dcdc42cf901a7f4db665f9dce6 | Ruby | agara93/redditscraper | /redditpcsales.rb | UTF-8 | 4,657 | 2.859375 | 3 | [] | no_license | #http,https,ftp wrapper
require 'open-uri'
#gem required for scraping the web page
require 'nokogiri'
loop do
count=0
puts " "
puts "======================="
puts "Reddit Build-a-PC Sales"
puts "======================="
puts " "
#prompts the user to choose which type of listing method that will be displayed
print "... | true |
0a95107afd793970da36748bceb7e3df6177981c | Ruby | rpush/rpush | /lib/rpush/reflection_public_methods.rb | UTF-8 | 197 | 2.75 | 3 | [
"MIT"
] | permissive | module Rpush
@reflection_stack ||= [ReflectionCollection.new]
class << self
attr_reader :reflection_stack
end
def self.reflect
yield reflection_stack[0] if block_given?
end
end
| true |
9dbeca714a6ed82e933910cef2c9b69a0bcd5349 | Ruby | basu0001/first-pr-Hacktoberfest--2019 | /codes/data_structures/linked_list/ruby/linked_list.rb | UTF-8 | 1,645 | 4.1875 | 4 | [
"MIT"
] | permissive | class Node
attr_writer :next
attr_reader :next, :data
def initialize(data, next_node = nil)
@data = data
@next = next_node
end
end
class LinkedList
def initialize
@head = nil
@tail = @head
end
def insertFront(data)
node = Node.new(data, @head)
... | true |
48f57f17b998deaa1fb6cd3a9cfbc9854bd13d74 | Ruby | knikadass/country_cli | /lib/country_cli/api.rb | UTF-8 | 641 | 2.765625 | 3 | [
"MIT"
] | permissive |
class Api
attr_accessor :url
def initialize()
@url = "https://restcountries.eu/rest/v2"
end
def search_country_by_name(name)
req_url="#{url}/name/#{name}"
data = HTTParty.get(req_url)
country_hash = {
name: data.first["name"],
region: data.first["region"],
population: data.first["p... | true |
5b878fe9882bef5e84d8a6d0a6bcbb3daf3137e1 | Ruby | elmirill/thinknetica_rails | /lesson_8/cargo_wagon.rb | UTF-8 | 767 | 3.359375 | 3 | [] | no_license | class CargoWagon < Wagon
attr_reader :capacity
attr_reader :taken_capacity
def initialize(options = {})
@capacity = options[:capacity].to_f
@taken_capacity = 0
super(options[:number])
end
def take_capacity(take_capacity)
self.taken_capacity += take_capacity if take_capacity <= empty_capacity... | true |
4421d5f2ab5d5becb95029da066dd8a2c1613c11 | Ruby | gbadesimple/odin-flight-booker | /app/models/flight.rb | UTF-8 | 942 | 2.78125 | 3 | [] | no_license | class Flight < ApplicationRecord
belongs_to :from_airport, class_name: 'Airport', foreign_key: 'from_airport_id'
belongs_to :to_airport, class_name: 'Airport', foreign_key: 'to_airport_id'
has_many :bookings, dependent: :destroy
has_many :passengers, through: :bookings
validates :from_airport_id, presence... | true |
5f30bdfa10622b4826193efc6a1d146973654b96 | Ruby | kgoettling/small_problems | /easy_3/easy_3_10_palnums.rb | UTF-8 | 448 | 3.671875 | 4 | [] | no_license | def palindromic_number?(int)
int.to_s == int.to_s.reverse
end
def palindromic_number2?(int)
div_arr = []
check_arr = []
while int > 0
div_arr = int.divmod(10)
check_arr << div_arr.last
int = div_arr.first
end
p check_arr
check_arr == check_arr.reverse
end
puts palindromic_number2?(3454... | true |
9f1456c501e628c4053c79cc5ddf723b71265a8e | Ruby | chiggins29/ruby-code-examples | /brayden_challenges/fizzbuzz_new.rb | UTF-8 | 231 | 3.96875 | 4 | [] | no_license | def fizzbuzz
(1..100).each do |num|
if num % 5 == 0 && num % 3 == 0
puts "FizzBuzz"
elsif num % 5 == 0
puts "Fizz"
elsif num % 3 == 0
puts "Buzz"
else
puts "Nope you are not divisible"
end
end
end
p fizzbuzz | true |
bc3c092289549df3c2b8f9a1c9e65afb18150923 | Ruby | francisco-rojas/ruby_learning | /Cami/cami_homework_6_while_loop.rb | UTF-8 | 594 | 4.03125 | 4 | [
"MIT"
] | permissive | class While_loop
def nums (a)
i = 0
numbers = []
while i <= a
puts "At the top i is #{i}"
numbers.push(i)
i += 1
puts "Numbers now: ", numbers
puts "At the bottom i is #{i}"
end
puts "The numbers: "
numbers.each {|num| puts num }
end
end
num = While_loop.new
num.nums(6)
puts "||||||||||... | true |
35cce2d88f077eba79b071c1021344b6c5ce7662 | Ruby | unrar/concensus | /app/models/login.rb | UTF-8 | 1,236 | 2.859375 | 3 | [
"MIT"
] | permissive | require './app/controllers/login_controller'
class LoginModel
# Does the username exist?
def self.exists?(given_username)
begin
db = SQLite3::Database.open('./db/census.db')
re = db.execute("SELECT * FROM users WHERE username='#{given_username}';")
if re.length > 0
return true
e... | true |
66a0fe3cdf862a0072209a2a6398bfb345f593ba | Ruby | FernandoBasso/programming-how-to | /ruby/well-grounded-rubyist/06-control-flow/03-modifiers.rb | UTF-8 | 129 | 3.546875 | 4 | [] | no_license | x, y = 50, 100
puts x if x < 100
def show(num)
return unless num > 100
p "Num is > 100: #{num}"
end
show(100)
show(101)
| true |
1137dce3ae086e5c10af049bde839374ba79b8a7 | Ruby | OllieSharpe/Sparta_Global_API_Testing_Lab | /lib/generating_data.rb | UTF-8 | 522 | 2.78125 | 3 | [] | no_license | require 'httparty'
require 'json'
class RandomPostcodes
include HTTParty
base_uri 'https://api.postcodes.io'
def get_random_postcode
json = JSON.parse(self.class.get("/random/postcodes/").body)
return json['result']['postcode']
end
def get_random_postcodes(quantity)
postcodes_array = []
fo... | true |
a46e0fc75e0116a4533d262ade816d074c99d120 | Ruby | wphelan45/phase-0-tracks | /ruby/shout.rb | UTF-8 | 831 | 4.21875 | 4 | [] | no_license | =begin
6.4 Release 1
1. Writing a simple module called shout
2. Declare the module here is the basic syntax:
module Shout
insert methods here
end
3. Run the code in IRB using: require_relative 'shout'
4. Add a method for yelling angrily (code already exists in assignment 6.4)
5. Add a method for yelling happily
6.... | true |
bfa3af2ea3ffd26101a59cc879747530a5935a62 | Ruby | mskubenich/Cashhoppers | /app/models/message.rb | UTF-8 | 3,288 | 2.5625 | 3 | [] | no_license | include ActionView::Helpers::DateHelper
class Message < ActiveRecord::Base
belongs_to :sender, :class_name => 'User'
belongs_to :receiver, :class_name => 'User'
has_many :notifications
attr_accessible :receiver_id, :sender_id, :schedule_date, :synchronized, :text, :sended
validates :text, presence: true
... | true |
b9f90c4c06a7d579d017e53573918b63478561be | Ruby | seligmar/ttt-game-status-bootcamp-prep-000 | /lib/game_status.rb | UTF-8 | 1,107 | 3.8125 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # # Helper Method
require "pry"
def position_taken?(board, index)
!(board[index].nil? || board[index] == " ")
end
def input_to_index(user_input)
user_input = user_input.to_i-1
puts user_input
end
# Define your WIN_COMBINATIONS constant
WIN_COMBINATIONS = [
[0,1,2],
[3,4,5],
[6,7,8],
[0,3,6],
[1... | true |
c99ac3b6c41824c65e74afc90dd993bb2e759165 | Ruby | curzonj/nephophobia | /lib/nephophobia/resource/image.rb | UTF-8 | 1,758 | 2.609375 | 3 | [
"Beerware"
] | permissive | module Nephophobia
module Resource
class Image
def initialize client
@client = client
end
##
# Returns information about AMIs, AKIs, and ARIs. Images returned include
# public images, private images that +@client+ owns, and private images
# owned by other AWS accounts ... | true |
d0a177a8aa6e85e6eff6a19cbe06c56d5a021c9b | Ruby | brandonricharda/Useful-Scripts-Algos | /Lineup Parse/lineup_parse.rb | UTF-8 | 4,410 | 3.296875 | 3 | [] | no_license | require 'docx'
require 'csv'
@file = Docx::Document.open('./Files/Schedules/FILENAME.docx')
@months = ["Jan", "Feb", "March", "April", "May", "June", "July", "Aug", "Sept", "Oct", "Nov", "Dec"]
@raw_text = []
@nested_text = {}
@result = {}
#grabs the raw text + formatting line by line (excluding spaces and time, wh... | true |
0e10b87f2c98d9cd8516316e279884c6134d19a0 | Ruby | TBespalko19/New_app | /My_App1/lesson_02/newfile.rb | UTF-8 | 29 | 2.546875 | 3 | [] | no_license | puts "Hello" print "Hello\n" | true |
5b038029ad75ee60ba2162fbf110cb6039aabcbd | Ruby | Candillan/ruby-oo-relationships-practice-recipes-exercise | /db/seeds.rb | UTF-8 | 1,273 | 2.515625 | 3 | [] | no_license | User.delete_all
Recipe.delete_all
Ingredient.delete_all
RecipeCard.delete_all
Allergy.delete_all
RecipeIngredient.delete_all
calvin = User.create(name: "Calvin")
alona = User.create(name: "Alona")
lasagna = Recipe.create(name: "Lasagna")
pizza = Recipe.create(name: "Pizza")
mac_and_cheese = Recipe.create(name: "Mac a... | true |
a2f82c521c80ed2ace7c066a028dce927dd32284 | Ruby | Kolumb555/black_jack_rev | /black_jack/interface.rb | UTF-8 | 1,495 | 3.390625 | 3 | [] | no_license | class Interface
def show_cards(gamer)
if gamer.instance_of?(Dealer)
puts 'Карты дилера, сумма очков:'
else
puts 'Ваши карты, сумма очков:'
end
gamer.hand.cards.each { |card| puts card.value.to_s + card.suit }
puts gamer.hand.total_value.to_s
end
def dealer_show_stars(cards_qty)
... | true |
19c7ad3e2aa2b340a8e967a9b4b3dfe3f720cadf | Ruby | chiragagrawal/asm-deployer-jenkins | /nagios/check-ipmi.rb | UTF-8 | 4,235 | 2.546875 | 3 | [] | no_license | #!/opt/puppet/bin/ruby
$: << "/opt/asm-deployer/lib"
require 'rubygems'
require 'optparse'
require 'csv'
require 'asm/cipher'
NAGIOS_OK = 0
NAGIOS_WARNING = 1
NAGIOS_CRITICAL = 2
NAGIOS_UNKNOWN = 3
options = {:host => nil,
:user => "root",
:password => "root",
:ipmimonitoring => "/u... | true |
039926a000fb951e26793466686718ce7c93f7e9 | Ruby | stephr3/hair-salon | /spec/client_spec.rb | UTF-8 | 2,999 | 2.734375 | 3 | [
"MIT"
] | permissive | require('spec_helper')
describe(Client) do
describe("#name") do
it("returns the client's name") do
client = Client.new({:name => "Billy Madison", :phone => "206-345-1273", :stylist_id => nil, :id => nil})
expect(client.name()).to(eq("Billy Madison"))
end
end
describe("#phone") do
it("ret... | true |
8a2d719da3368ead97738ed18aa33f6cf6670457 | Ruby | computationclub/jack-compiler | /spec/unit/labeller_spec.rb | UTF-8 | 655 | 2.625 | 3 | [] | no_license | require 'labeller'
RSpec.describe Labeller do
subject(:labeller) { described_class.new }
it 'appends 0 to a label the first time it sees it' do
expect(labeller.label('cheese')).to eq 'cheese0'
end
it 'appends 1 to a label the first time it sees it' do
labeller.label('cheese')
expect(labeller.label... | true |
4cdffff38c86af54cabe47d3ec84212c367595c3 | Ruby | adamhooper/opencensus | /script/scrape/scrape-2001-population-and-dwelling-counts.rb | UTF-8 | 4,423 | 2.625 | 3 | [] | no_license | #!/usr/bin/env ruby
# encoding: utf-8
require "#{File.dirname(__FILE__)}/scrape"
require 'csv'
require 'logger'
module PopulationRecords
def records
@records ||= doc.xpath('//table[@border = "1"]/tr[not(@bgcolor)]').collect do |tr|
next unless [5, 6].include?(tr.css('td').count)
next if tr.css('str... | true |
bf9b168985cf413bf9a70675d7953d2993daeb04 | Ruby | rarhoade/array_combine | /devescops_coding_test.rb | UTF-8 | 908 | 3.703125 | 4 | [] | no_license | class ArrayOperations
def self.combine_array(set_one = [], set_two = [])
result = []
#array indices
one_i = 0
two_i = 0
#loop through both arrays until the end of either
while one_i < set_one.length && two_i < set_two.length
#check for the lowest array value per array
if set_one[on... | true |
adfb99d74a5237566abab0658df990e55d0f109b | Ruby | eknovoa/Programming_Foundations | /Small_Problems/easy_7/lettercase_counter.rb | UTF-8 | 2,774 | 4.53125 | 5 | [] | no_license | =begin
Problem
-write a method that takes a string, and then returns a hash that contains 3 entries: one represents the number of characters in the string that are
lowercase letters, one the number of characters that are uppercase letters, and one the number of characters that are neither.
Input:
-string
Output... | true |
223be4c8f9f702ad08ddf8624b5f90ed00814626 | Ruby | kg-coderta/atcoder | /abc/171.rb | UTF-8 | 188 | 2.703125 | 3 | [] | no_license | A
x = gets.chomp
if x.ord <=90
puts "A"
else
puts "a"
end
B
n,k = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
min = 0
for num in 0..k-1 do
min += a[num]
end
p min
C
D
E
F | true |
14fe233dfb9d493203ec7ec5761daae3922f5028 | Ruby | hieuk09/tokyo-spaceship | /spec/velocity_spec.rb | UTF-8 | 2,460 | 3.046875 | 3 | [] | no_license | require_relative '../velocity'
describe Velocity do
describe '#*' do
it 'computes correctly' do
new_velocity = Velocity.new(2.0, 3.0) * 4
expect(new_velocity.angle).to eq 2.0
expect(new_velocity.speed).to eq 12.0
end
end
describe '#+' do
context 'when combining with point' do
... | true |
379515a94c944cffe94f40d53f2c3fa81ce15085 | Ruby | treppo/trains | /lib/connection.rb | UTF-8 | 547 | 3.46875 | 3 | [] | no_license | # knows the connection between cities
class Connection
def initialize(target, distance)
@target = target
@distance = distance
end
def shortest_routes(destination, visited_cities)
target.shortest_routes(destination, visited_cities).map(&method(:prepend_distance))
end
def budget_routes(destination... | true |
b0b7630b31497c0f4a317393818e9350a5b9a8df | Ruby | trnunes/explorationDSL | /lib/mixins/graph_converter.rb | UTF-8 | 773 | 2.9375 | 3 | [] | no_license | module Xplain
module GraphConverter
def hash_to_graph(items_hash)
nodes = []
items_hash.each do |item, relations|
children_set =
if relations.is_a? Hash
hash_to_graph(relations)
else
relations.map do |related_item|
... | true |
0f4fb998578c1ab377abb2e58fee7e1e81b20bbc | Ruby | TimCPB/cautious-octo-guide | /src/valid_braces.rb | UTF-8 | 548 | 3.640625 | 4 | [
"MIT"
] | permissive | def valid_braces(braces)
braces_array = braces.chars
open_parentheses = 0
close_parentheses = 0
open_curly_braces = 0
close_curly_braces = 0
braces_array.each do |brace|
if brace == "("
open_parentheses += 1
elsif brace == ")"
close_parentheses +=1
elsif brace == "{"
open_c... | true |
136301921471a16abe0536c1260a34b490d47ee1 | Ruby | gdotdesign/Lattice | /Site/include/packager.rb | UTF-8 | 2,798 | 2.859375 | 3 | [] | no_license | class Packager
attr_accessor :components
def initialize(path)
parse_manifest path
end
def parse_manifest(path)
@components = []
@provides = []
pathinfo = Pathname.new path
realpath = pathinfo.realpath.dirname
if File.exists?(path)
manifest = YAML::load(File.new(path))
ma... | true |
c7d5a7ec96a6d17bf24a6297f4ffba5ee8f5c4c1 | Ruby | youta777/AtCoder | /ABC/ABC170/c.rb | UTF-8 | 859 | 3.0625 | 3 | [] | no_license | =begin
date:2020.7.23 Thu
result:WA
問題URL:https://atcoder.jp/contests/abc170/tasks/abc170_c
結果URL:https://atcoder.jp/contests/abc170/submissions/15369328
=end
# 自分の解答 ------------------------
a, b = gets.chomp.split.map(&:to_i)
if b == 0
puts a
else
ex_arr = gets.chomp.split.map(&:to_i)
arr = [*1..... | true |
149b1ac04a58a2ec85536eb76373b2d9f52bc299 | Ruby | dooomlord/Image | /ImageArray.rb | UTF-8 | 1,209 | 2.984375 | 3 | [] | no_license | require 'rubygems'
require 'RMagick'
include Magick
class ImageRow < Magick::Image::View::Rows
def initialize(image, row)
@image = image
@row = row
end
def each
@image.columns.times do |j|
yield @row[j]
end
end
end
class ImageArray
include Enumerable
def initialize(file_path)
@image = ImageList.... | true |
e53c63b054a7bf4f90777d50a462400584c19a77 | Ruby | SuzHarrison/TaskListRails | /app/models/person.rb | UTF-8 | 417 | 2.59375 | 3 | [] | no_license | class Person < ActiveRecord::Base
has_many :tasks
def self.count_completed(person_id)
person = Person.find(person_id)
tasks = person.tasks
completed_at = tasks.where(completed_at: true)
return completed_at.length
end
def self.count_not_completed(person_id)
person = Person.find(person_id)
... | true |
b09941cfb78c63e1e7da80a44573358992561a9f | Ruby | teacplusplus/gorodok-proto | /lib/sms_gate.rb | UTF-8 | 947 | 2.515625 | 3 | [] | no_license | require 'net/https'
class SmsGate
class << self
attr_accessor :sent
def send msg, telephone
(self.sent ||= []) << {:message => msg, :telephone => telephone } and return if
ENV['RAILS_ENV'] == 'test'
send_request "https://smsc.ru/sys/send.php?login=xxx&translit=1&psw=xxx&phones=#{telephon... | true |
f18496688807a75997da7bad4b63f21be01aced8 | Ruby | denzyl/tealeaf | /LearntoProgram/Chapter8/sort.rb | UTF-8 | 208 | 3.453125 | 3 | [] | no_license | puts 'Type in as many words as you want. When finished press \'Enter\' on an empty line'
entry = "meaningless-word"
words = []
while entry != ''
entry = gets.chomp
words.push entry
end
puts
puts words.sort | true |
ea8c6d6e677b6afef14d599d1dfcef083fdc14d9 | Ruby | mendelcohen/movie-app | /app/models/movie.rb | UTF-8 | 431 | 2.5625 | 3 | [] | no_license | class Movie < ApplicationRecord
validates :title, uniqueness: true, length: { minimum: 3 }, presence: true
validates :year, length: { minimum: 4 }, numericality: true
validates :plot, length: { in: 10..100}
validates :director, length: { minimum: 5 }, presence: true
has_many :actors
has_many :movie_genres... | true |
dfc5cb9c127ea1aaf6ec9b91c00aef06bc2348de | Ruby | thehuff/7langs | /ruby/day_02_do_03_grep.rb | UTF-8 | 812 | 3.546875 | 4 | [] | no_license | #!/usr/bin/env ruby
# Third exercise in the Do section of Ruby day two.
#
# Implement a simple grep with Ruby.
if ARGV.size != 2
puts "usage: #{__FILE__} file_path search_phrase"
end
# Break out the CLI parameters and parse the search phrase as a regex.
file_path, search_phrase = ARGV
begin
search_regexp = Rege... | true |
03a68608d832d44d345902de665c6d85a3b3aa3b | Ruby | nyc-golden-bears-2016/Pan-Overflow | /app/controllers/questions.rb | UTF-8 | 2,329 | 2.734375 | 3 | [] | no_license | get '/questions' do
@questions = Question.all
erb :index
end
get '/questions/new' do
redirect_nologin
erb :'questions/new' #show new questions view
end
post '/questions' do
redirect_nologin
tags = params[:question].delete("tags")
if tags.nil?
@errors = "You have to tag your question"
erb :'q... | true |
b264763010a932f8c97c94fcf0cd9e92adaa76ab | Ruby | taganaka/adventofcode | /day3/day3.rb | UTF-8 | 295 | 3.03125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'pp'
require 'set'
data = File.read(ARGV[0]).strip.split(//)
points = Set.new
x = 0
y = 0
points << [x, y]
data.each do |c|
case c
when '^'
y += 1
when 'v'
y -= 1
when '>'
x -= 1
when '<'
x += 1
end
points << [x, y]
end
pp points.count
| true |
6c7b54c3ab5501d70649d71d0e42b90d98f213c8 | Ruby | Dbm289/NBA_Best_games | /lib/nba_best_games/cli.rb | UTF-8 | 2,146 | 3.375 | 3 | [
"MIT"
] | permissive | class NbaBestGames::CLI
def call
Get.set_teams
puts ""
puts "Welcome my NBA franchise information CLI!"
puts ""
puts "To see the full list of teams, hit '1'"
puts "To get the full information about a specific team, hit '2'"
puts ""
puts "What would yo... | true |
24d0e16c90b2363326f1c26743680f2dc68f3ff3 | Ruby | sindhu2323/Cucumber | /features/pages/dashboard.rb | UTF-8 | 1,117 | 2.75 | 3 | [] | no_license | class Dashboard
def initialize(browser)
@browser = browser
@txt_fields = @browser.elements(:xpath => "//*[starts-with(@id,'txt_val_')]")
end
def get_count_of_text_fields()
return @txt_fields.size
end
def visit()
@browser.goto "http://www.exercise1.com/values"
end
def verify_tot... | true |
03a0806d275b518c18bf9611af0a7325cdd22823 | Ruby | SOA-Upstart8/ShowMeSecurity-api | /app/domain/models/security_CVEs/mappers/vultype_mapper.rb | UTF-8 | 1,124 | 2.65625 | 3 | [] | no_license | # frozen_string_literal: true
module SMS
module CVE
# Data Mapper: NewsApi data -> News entity
class VulMapper
def initialize(api_key, gateway_class = CVE::Api)
@api_key = api_key
@gateway_class = gateway_class
@gateway = @gateway_class.new(@api_key)
end
def best
... | true |
9525d72d4c46de0311b1808be81dfd3ab993cc72 | Ruby | zioplox11/triangle_fun | /triangle_app/db/seeds.rb | UTF-8 | 475 | 2.53125 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
#
# Examples:
#
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel... | true |
4817b5547ef77267a1a6e523494a7479f82f9ae1 | Ruby | Chand-11/Two-Player-Math-Game | /Game.rb | UTF-8 | 1,008 | 3.734375 | 4 | [] | no_license | require 'active_support/all'
class Game
def initialize(a,b)
@player_A = a
@player_B = b
@current_player = @player_A
end
def start_game
cp="Player 1"
while @player_A.lives > 0 && @player_B.lives > 0
num1 = rand(1..20)
num2 = rand(1..20)
puts "----------New Turn---------------"
puts "#{cp... | true |
62c0d10ce492f031efb9f98ec0e048f050484348 | Ruby | shafouz/data-structures-practice | /exercises/linked-lists/find_kth_element/find_kth_element_test.rb | UTF-8 | 733 | 3.125 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/reporters'
require_relative './find_kth_element.rb'
Minitest::Reporters.use!
class NodeTest < Minitest::Test
def test_empty_list
root = Node.new
assert_nil find_to_last_element(root, 1)
end
def test_equal_or_higher_than_length
root = Node.new(2)
asser... | true |
941c37e5f97b5473f1cfd1d5d332b9cf014e0d1f | Ruby | shigemk2/rspec | /cb/production/spec/codebreaker/game_spec.rb | UTF-8 | 1,031 | 2.875 | 3 | [] | no_license | require 'spec_helper'
module Codebreaker
describe Game do
let(:output) { double('output').as_null_object }
let(:game) { Game.new(output) }
describe "#start" do
it "sends a welcome message" do
output.should_receive(:puts).with('Welcome to Codebreaker!')
game.start('1234')
e... | true |
c5ffa074b3f12d0f9f28e148dec5bdb15b241753 | Ruby | timbeiko/blackjack | /video.rb | UTF-8 | 2,412 | 4.0625 | 4 | [] | no_license | def calculate_total(cards)
# [['H', '3'], ['S', 'Q'], ... ]
arr = cards.map{|e| e[1] }
total = 0
arr.each do |value|
if value == "A"
total += 11
elsif value.to_i == 0 # J, Q, K
total += 10
else
total += value.to_i
end
end
#correct for Aces
arr.select{|e| e == "A"}.coun... | true |
3c29351f2e2b52378c91a3d497c6d281f8b07d2a | Ruby | robertobuso/collections_practice_vol_2-dumbo-web-071618 | /collections_practice.rb | UTF-8 | 2,622 | 3.375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def begins_with_r (argument)
count = 0
argument.each do |single_word|
if single_word[0,1] == "r"
count += 1
end
end
count == argument.length
end
def contain_a (argument)
a_array = []
argument.each do |single_word|
if single_word.include? ("a")
a_array << single_word... | true |
d2f766d42a84f3871ee0f496774b8a1ba8e0d32c | Ruby | toddt67878/Course_Ruby | /ArrayII/The_concat_Method.rb | UTF-8 | 173 | 3.171875 | 3 | [] | no_license | p [1, 2, 3, 4] + [4, 5]
p [1, 2, 3].concat([4, 5])
ar1 = ["A", "B", "C"]
ar2 = 0..10
def custom_cont(arra1, arra2)
p arra1.concat(arra2)
end
custom_cont(ar1, ar2.to_a)
| true |
b5ae67c9ba731bb9b5352297209943a103821498 | Ruby | mjeffryes/euler | /prob022.rb | UTF-8 | 241 | 2.84375 | 3 | [] | no_license | #!/usr/bin/ruby
out = 0
File.open("names.txt", 'r'){ |f|
lines = f.readlines
sorted = lines.sort
scores = sorted.map { |line|
line.strip.bytes.map{ |b| b - 0x40 }.reduce(:+)
}
scores.each_with_index{ |s,i| out += s*(i+1) }
}
p out
| true |
7c7079e0d6ab68e8ef997c963b56094e1a91c8bc | Ruby | ChuckBriggs/top_ruby_knight_travails | /lib/knight.rb | UTF-8 | 869 | 3.53125 | 4 | [] | no_license | # frozen_string_literal: true
#require 'pry'; binding.pry #rubocop:disable all
class Knight
attr_reader :position, :sire, :possible_moves
MOVEMENTS = [[-2, -1], [-2, 1], [-1, -2], [-1, 2], [1, -2], [1, 2], [2, -1], [2, 1]]
def initialize(position = [1, 0], sire = nil)
@position = position
@sire = sire
... | true |
9c86a1938f6f3744a09c7a2073a4e0b02f2ffa2a | Ruby | dgmike/teste-usando-codeship-e-stepup | /app/models/calc.rb | UTF-8 | 45 | 2.59375 | 3 | [
"MIT"
] | permissive | class Calc
def sum(a, b)
a+b
end
end
| true |
020916353d0b87b44362c2ad762ddabfda23ca73 | Ruby | janmilosh/exercises_for_programmers | /ch2_input_processing_output/saying_hello.rb | UTF-8 | 262 | 3.53125 | 4 | [] | no_license | class Hello
def prompt text
print text
gets.chomp
end
def output name
puts "\nHello #{ name }, nice to meet you!\n\n"
end
def run
output(prompt "\nWhat is your name? ")
end
end
if __FILE__ == $0
hello = Hello.new
hello.run
end
| true |
e7665cdf44731e7ab305592cd94d54f1bfa33aff | Ruby | yoikosugi/cherry | /section8/822.rb | UTF-8 | 346 | 3.203125 | 3 | [] | no_license | # module モジュール名
# モジュールの定義(メソッドや定数など)
# end
module Greeter
def hello
'hello'
end
end
# モジュールのインスタンスは作成できない
# greeter = Greeter.new
# ほかのmoduleを継承して新しいmoduleを作ることはできない
# module AwesomeGreeter < Greeter
# end
| true |
3e0364d1b82277da5b286b90370edab3998033b1 | Ruby | atl-code-immersion/ruby-winter16 | /homework-day2/test_average.rb | UTF-8 | 241 | 3.59375 | 4 | [] | no_license | # Question 3: Test Scores
scores = []
9.times do
scores.push(rand(1..100))
end
puts "The test scores were:"
puts scores.sort.join(", ")
sum = 0
scores.each do |x|
sum += x
end
puts "The average for this test was: #{sum/scores.length}" | true |
7c078c11d990eead97361ae63e25c26cccda1152 | Ruby | ngeballe/ls-130-lesson1 | /blocks3/each1.rb | UTF-8 | 284 | 3.796875 | 4 | [] | no_license | def each(array)
counter = 0
while counter < array.size
yield(array[counter])
counter += 1
end
array
end
result = each([1, 2, 3, 4, 5]) do |num|
puts num
end
p result
odds = each([1, 2, 3, 4, 5]) {|num| "do nothing"}.select{ |num| num.odd? }
p odds == [1, 3, 5]
| true |
d718af192ce1473c981b1816f1211a96dbf08d76 | Ruby | Zimpler/r509 | /spec/subject_spec.rb | UTF-8 | 8,088 | 2.5625 | 3 | [
"Apache-2.0"
] | permissive | require 'spec_helper'
require 'r509/subject'
require 'openssl'
describe R509::Subject do
before :all do
@csr_unknown_oid = TestFixtures::CSR_UNKNOWN_OID
end
it "initializes an empty subject and gets the name" do
subject = R509::Subject.new
subject.name.to_s.should == ""
end
... | true |
11a4da6bd18fdf4712ae003ba21031637d7f55a9 | Ruby | furkanusta/Competitive-Programming | /AdventOfCode/2016/4a.rb | UTF-8 | 736 | 3.046875 | 3 | [] | no_license | # Normally there is no need to sort the checksum and common[] but it works and easier this way
sum = 0
File.open('4.inp', 'r') do |f|
f.each_line do |line|
*rooms, rest = line.chomp.split('-')
rooms = rooms.flat_map{|r| r.split('')}
sorted = rooms.inject(Hash.new(0)) { |total, e| total[e] += 1; total }.so... | true |
dd625c77eed81d6a2a3ada21750bf452fbffdd9c | Ruby | hipe/hipe-gorillagrammar | /spec/shorthand_spec.rb | UTF-8 | 5,791 | 3.03125 | 3 | [
"MIT"
] | permissive | #rake spec SPEC=spec/shorthand_spec.rb
require File.dirname(__FILE__)+'/helpers.rb'
require 'hipe-gorillagrammar'
include Hipe::GorillaGrammar
class Grammar
include Helpers
# only for irb -- tokenize a string thru the shell. careful!
def parz str;
tox = shell!(str);
puts "your tokens tokenized from shell... | true |
a95020c0f25c1b482835840664f9b305b6a1a33d | Ruby | pact-foundation/pact-support | /lib/pact/consumer_contract/response.rb | UTF-8 | 1,016 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'pact/consumer_contract/headers'
require 'pact/symbolize_keys'
module Pact
class Response < Hash
include SymbolizeKeys
ALLOWED_KEYS = [:status, :headers, :body, 'status', 'headers', 'body'].freeze
private_constant :ALLOWED_KEYS
def initialize attributes
merge!(attributes.reject{|key... | true |
9aaebfb2163da55ada807e832f4c198af1cae930 | Ruby | kevin-j-m/clockwork-test | /spec/clockwork/test/job_history_spec.rb | UTF-8 | 2,797 | 2.53125 | 3 | [
"MIT"
] | permissive | require "spec_helper"
require "clockwork/test/job_history"
describe Clockwork::Test::JobHistory do
subject(:history) { Clockwork::Test::JobHistory.new(prior_history, prior_work) }
let(:prior_history) { {} }
let(:prior_work) { {} }
describe "#jobs" do
let(:prior_history) do
{
"#{first_job}" =... | true |
a62390455f3b5d8107da51c459857a26951fd6ff | Ruby | karthykarthick/Bubble-Sort | /bubble_sort.rb | UTF-8 | 439 | 3.171875 | 3 | [
"MIT"
] | permissive | number_array = [2, 100, 2, 887, 7, 88, 3, 22, 333, 33_333, 12_111, 33_434, 546_576_576, 6_788_799, 4_564_534]
def bubble_sort(array)
puts "Unsorted array : #{array}"
(0..array.length - 1).each do
(0..array.length - 2).each do |index|
array[index], array[index + 1] = array[index + 1], array[index] if (arra... | true |
5707704e8105c752c8b8d029af32e0c54c2d59ef | Ruby | alvarog55/Ironhack-Week-1- | /proc.rb | UTF-8 | 151 | 3.015625 | 3 | [] | no_license | my_proc = Proc.new {puts "Hi!!!"}
my_proc.call
my_proc = proc {puts "Hi!!!"}
my_proc.call
my_lambda = lambda {puts "Hello lambda!"}
my_lambda.call | true |
494c164496f8d03adc9aed52f7c019292fee0209 | Ruby | rbishop/eulers | /euler7.rb | UTF-8 | 300 | 3.734375 | 4 | [] | no_license | class Numeric
def is_prime?
return true if self == 2
3..(self-1).step(2) do |i|
return false if self % i == 0
end
return true
end
end
def get_primes how_many
count = 1
n = 3
while n
n += 1
count += 1 if n.is_prime?
return n if count == how_many
end
end
| true |
8c919b53c554f4cd7891e9b138a57fe1fa97bce3 | Ruby | rodrigorgs/bcr | /random_graphs.rb | UTF-8 | 2,559 | 2.671875 | 3 | [] | no_license | #!/usr/bin/env ruby
#require 'graph'
require 'network'
# choose one index, with probability proportional to its weight
def choose_random_acc(acc_weights, labels=(0..acc_weights.size-1).to_a)
return nil if acc_weights.nil? || acc_weights.empty?
n = rand * acc_weights[-1]
# XXX optimize using binary search
acc... | true |
9c39e209be42cde76730a6db515b22bc08c55699 | Ruby | esteban90-dev/Connect-Four | /spec/cell_spec.rb | UTF-8 | 488 | 2.84375 | 3 | [] | no_license | require "./lib/cell.rb"
describe Cell do
context "#initialize" do
it "initializes with nil by default" do
cell1 = Cell.new
expect(cell1.value).to eql(nil)
end
it "can be initialized with a character like 'X'" do
cell1 = Cell.new("X")
expect(cell1.value).to eql("X")
end
end
... | true |
9c6d0247f150bfa0b1d4d5741b4804ceb7b3f4c3 | Ruby | mpfilbin/conductor | /lib/conductor/parsers/options_parser.rb | UTF-8 | 2,806 | 3.046875 | 3 | [
"MIT"
] | permissive | require 'optparse'
module Conductor
module Parsers
# This class encapsulates the behavior for parsing commandline arguments and
# flags passed to Conductor from the commandline
class OptionsParser
attr_reader :config_path, :pid_path, :command, :stack, :logging_path
# @param[Array] argv
... | true |
e2d8c08f829b4b5aaca72b16205a418b6070506f | Ruby | gulazaro94/healios | /app/interactions/urls/generate_token.rb | UTF-8 | 386 | 2.53125 | 3 | [] | no_license | module Urls
class GenerateToken < ApplicationInteraction
MAX_ATTEMPTS = 5
TOKEN_SIZE = 10
def execute
MAX_ATTEMPTS.times do
token = generate_token
return token unless Url.exists?(token: token)
end
raise('max token attempts exceeded')
end
private
def genera... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.