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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
b2c83448d6033a566ac7608eb5e5a7fb582d3ecc | Ruby | mark-kohrman/git_files | /practice.rb | UTF-8 | 236 | 3.09375 | 3 | [] | no_license |
count = 0
while count < 1
puts "Please enter a first name, last name, email:"
banking_customers = [{:first_name => gets.chomp, :last_name => gets.chomp, :email=> gets.chomp, :account_no => }]
count += 1
end
p banking_customers
| true |
e70f1c6683fb75655df4a1de46c5f98a528cbdd3 | Ruby | ovidiuanca/rails-refactoring | /introduce-parameter-object/lib/normal_shipping_cost.rb | UTF-8 | 304 | 3.15625 | 3 | [
"MIT"
] | permissive | class NormalShippingCost
NORMAL_CONVERSION_FACTOR = 6.67
NORMAL_RATE = 2.75
def initialize(package)
@package = package
end
def calculate
cost = package.volume * (package.weight / NORMAL_CONVERSION_FACTOR) * NORMAL_RATE
cost.round(2)
end
private
attr_accessor :package
end
| true |
b8a987d20eb0e8c5f7f0cfd39ea921d333ef5430 | Ruby | aschwartz1/tee_vee | /lib/character.rb | UTF-8 | 219 | 2.984375 | 3 | [] | no_license | class Character
def initialize(information)
@information = information
end
def name
@information[:name]
end
def actor
@information[:actor]
end
def salary
@information[:salary]
end
end
| true |
b0c59ac837d27ab18d3c9cce7569b53d0433a631 | Ruby | skarayan/active_tweet | /active_tweet.rb | UTF-8 | 1,166 | 2.828125 | 3 | [] | no_license | require 'rubygems'
require 'open-uri'
require 'json'
require 'uri'
class ActiveTweet
def initialize(data = nil)
@data = data
@hashtag = nil
@links = false
@limit = 100
end
def self.mock(data)
ActiveTweet.new(data)
end
def find_by_hashtag(hashtag)
raise ArgumentError.new('Please prov... | true |
bf30a8423198289f504db74e2e767e40f586f717 | Ruby | gourshete/Carom | /spec/play_spec.rb | UTF-8 | 1,687 | 2.796875 | 3 | [] | no_license | require_relative '../lib/play'
RSpec.describe Play do
def write_to_file(player, moves)
file_path = '/Users/swapnil/Learning/Carom'
File.open("#{file_path}/player_#{player}_input.txt", 'w'){|file| file.write(moves)}
end
context 'Check results' do
it "Case 1" do
write_to_file('one', '1, 1, 2, 1... | true |
5e75445fc85a9e67c8b9893b742910a3688807f2 | Ruby | wppurking/pulsar_sdk | /lib/pulsar_sdk/protocol/topic.rb | UTF-8 | 2,070 | 2.6875 | 3 | [
"Apache-2.0"
] | permissive | module PulsarSdk
module Protocol
class Topic
PUBLIC_TENANT = 'public'.freeze
DEFAULT_NAMESPACE = 'default'.freeze
PARTITIONED_TOPIC_SUFFIX = '-partition-'.freeze
prepend ::PulsarSdk::Tweaks::AssignAttributes
attr_accessor :domain, :namespace, :topic, :partition
def to_s
... | true |
d8996963a7d5b030259bba45d25ad3a74fc7c505 | Ruby | SOM-Timer/som_timer_gem | /lib/som_timer/facades/rest_facade.rb | UTF-8 | 762 | 2.546875 | 3 | [] | no_license | class SomTimer::RestFacade
attr_reader :path
def initialize(path)
@path = path
@service = SomTimer::Service.new(@path)
end
def response_rests
@service.rests
end
def response_create_rest(mood_rating_1, mood_rating_2, content_selected, focus_interval, rest_interval)
@service.create_rest(moo... | true |
f1f4746356905034cb053852cc1d9a04d3945be2 | Ruby | andistuder/themill-raffle-mailer | /lib/raffle_email.rb | UTF-8 | 566 | 2.625 | 3 | [] | no_license | require 'erb'
class RaffleEmail
def initialize(email_vars = {})
@draw_date_string = '1st October 2016'
@signatory = 'Andi Studer'
@first_name = email_vars[:first_name] || 'friend'
@raffle_numbers = email_vars[:raffle_numbers] || []
end
def subject_line
'The Mill E17 Raffle Confirmation'
en... | true |
c2e666240dca2b7fc3175cbd55fd07c6bae61f52 | Ruby | ravibkjoshi/phase-0-tracks | /ruby/iteration.rb | UTF-8 | 965 | 4.28125 | 4 | [] | no_license | def greeting
puts "Hi, how are you"
3.times {yield}
end
puts " Initialize Block"
greeting {puts "I am doing well"}
puts "Block Complete"
arr = [ "Cupertino", "Alameda", "San Francisco", "Seoul", "Vancouver"]
h = {"name1" => "Ravi", "name2" => "Katy", "age1" => 25, "age2" => 25}
arr.each do |locations|
puts locati... | true |
2200163a5f981ce9ce064b33d4228c0e3015f3a1 | Ruby | asvaata/black_jack | /game.rb | UTF-8 | 2,101 | 3.484375 | 3 | [] | no_license | require_relative 'lib/user'
require_relative 'lib/dealer'
require_relative 'lib/deck'
require_relative 'lib/interface'
class Game
attr_reader :user, :dealer, :name
def initialize
@interface = Interface.new
@deck = Deck.new
@dealer = Dealer.new
@user = User.new
start
end
def start
@na... | true |
b9920741e0568f57a6acd2e9a8c88b42a17845a3 | Ruby | njaffer/sufia_6 | /sufia_app/vendor/bundle/ruby/2.2.0/gems/nom-xml-0.5.2/lib/nom/xml/decorators/nodeset.rb | UTF-8 | 1,561 | 2.53125 | 3 | [] | no_license | module Nom::XML::Decorators::NodeSet
def values_for_term term
result = self
result = result.select &(term.options[:if]) if term.options[:if].is_a? Proc
result = result.reject &(term.options[:unless]) if term.options[:unless].is_a? Proc
m = term.options[:accessor]
return_value = case
... | true |
e77776c9fbc5b084fb3a69176382f4783333dd76 | Ruby | hojamaka/katakana-name-maker | /fetch_katakana.rb | UTF-8 | 769 | 2.703125 | 3 | [] | no_license | # coding: utf-8
require 'yaml'
require 'open-uri'
require 'nokogiri'
uris = [
"https://ja.wikipedia.org/wiki/%E3%82%AE%E3%83%AA%E3%82%B7%E3%82%A2%E7%A5%9E%E8%A9%B1%E3%81%AE%E5%9B%BA%E6%9C%89%E5%90%8D%E8%A9%9E%E4%B8%80%E8%A6%A7",
]
#user_agent = 'Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0)'
arr =... | true |
4a197ccb711e31c5793f1c528b7c0b7ff582ab4b | Ruby | movie-snob/backend | /app/serializers/reviewed_film_serializer.rb | UTF-8 | 774 | 2.59375 | 3 | [] | no_license | # frozen_string_literal: true
class ReviewedFilmSerializer < ActiveModel::Serializer
attributes :watched_on, :title, :year, :poster, :suggested_by, :scores, :avg, :director, :imdb_id
def watched_on
object.created_at.to_time.to_i
end
def suggested_by
user = object.user
{
id: user.id,
n... | true |
2b9d5b8601045b9b55b02b8ca7e4ff39c88f1a0a | Ruby | RubyUnit/RubyUnit | /lib/RubyUnit/Assertions/Methods.rb | UTF-8 | 5,051 | 3.046875 | 3 | [
"LicenseRef-scancode-public-domain",
"BSD-2-Clause"
] | permissive | require_relative 'Root'
module RubyUnit
module Assertions
module Methods
include RubyUnit::AssertionMessage
include Root
#
# Assert that an object responds to particular method
# * raises RubyUnit::AssertionFailure unless _object_ responds to _method_
#
# object::
... | true |
884b3ad8815b97864d6cfba9ac6f385ef9c92335 | Ruby | miltomasz/shift_day | /lib/shift_day.rb | UTF-8 | 1,137 | 3.421875 | 3 | [] | no_license | require 'date'
module ShiftDay
HOUR = 60*60
class Base
attr_reader :hour
def initialize(date = DateTime.now, hour = 0)
@date = date
@hour = hour
end
def self.today?(date)
year = Time.now.year
day = Time.now.yday
param_year = date.year
param_day = date.yday
... | true |
5393c20aa04ae0831278ffd8d934da1422ed02bc | Ruby | codex86/gestdip | /app/controllers/stats_controller.rb | UTF-8 | 1,683 | 2.546875 | 3 | [] | no_license | class StatsController < ApplicationController
def index
@data = Date.today.beginning_of_month
respond_to do |format|
format.html # index.html.erb
end
end
def create
if(Date.valid_date?(params[:data]['year'].to_i,params[:data]['month'].to_i,params[:data]['day'].to_i))
... | true |
05a55e17cb338626478a49ec9c2f50a53ec4e3dc | Ruby | aTeapot/ruby | /PKP/find.rb | UTF-8 | 882 | 3.015625 | 3 | [] | no_license | require './search'
require 'net/http'
require 'nokogiri'
module Pkp
class << self
def find(from = nil, to = nil, &block)
search = Search.new
search.from(from) if from
search.to(to) if to
search.instance_eval(&block) if block_given?
url_parts = search.compile
html = Net::HTTP... | true |
46e0d62dcce49123d579e072dccbaf916be67eff | Ruby | lane34800/- | /WDI_LDN_17_LESSON_NOTES/completed_examples/w04d01/example_askii.rb | UTF-8 | 5,029 | 3.453125 | 3 | [] | no_license | NUMBER_OF_DECKS = 6
def card_values_array
("2".."10").to_a + %w(J Q K A)
end
def new_deck
%w(h d c s).inject([]) do |deck, color|
deck + card_values_array.each {|value| value << color}
end
end
def new_shoe
shoe = []
NUMBER_OF_DECKS.times {shoe+=new_deck}
shoe.shuffle
end
def card_score(card_name, sc... | true |
af93dfc82c801ba9f130ba4893a3027eacdbd86e | Ruby | RomainCestari/git-thp | /Desktop/THP/Semaine 1 /Mercredi c'est Ruby/exo11.rb | UTF-8 | 51 | 2.703125 | 3 | [] | no_license | def say_hello
puts "Hello my friend"
end
say_hello
| true |
8a7d7b0260883bed68cc4a14136a89a87ce6ab36 | Ruby | bwanicur/nattysearch | /app/services/petfinder_service/queries/pets.rb | UTF-8 | 762 | 2.75 | 3 | [] | no_license | module PetfinderService
module Queries
class Pets
def initialize(pf_client, opts={})
@client = pf_client
@options = opts
@location = @options[:location]
@animal_type = @options[:animal_type]
raise PetfinderService::Queries::Error.new('Location is required') unless @l... | true |
2264ab9df6c04d263929e74d7fdd164266c9f644 | Ruby | CatWithAGatt/RubyProject | /02_calculator/calculator.rb | UTF-8 | 290 | 3.9375 | 4 | [] | no_license | def add a, b
a + b
end
def subtract a, b
a - b
end
def sum arr
arr.inject(0) { |sum, num| sum + num }
end
def multiply arr
arr.inject(1) { |n1, n2| n1 * n2 }
end
def power n1, n2
n1 ** n2
end
def factorial num
if num == 0 || num == 1
return 1
end
num * factorial(num - 1)
end | true |
f9521a7b893fdda1e86e1afe56e5c275c9e1f6e1 | Ruby | yunosuke924/runteq_basic_curricurm2 | /spec/models/board_spec.rb | UTF-8 | 1,974 | 2.546875 | 3 | [] | no_license | # == Schema Information
#
# Table name: boards
#
# id :bigint not null, primary key
# title :string(255) not null
# body :text(65535) not null
# user_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# board_image :string(25... | true |
b309294e4ea92df9b0cec501522c68086ae5515e | Ruby | adedayoominiyi/aws-doc-sdk-examples | /ruby/example_code/s3/s3-ruby-example-show-50-buckets.rb | UTF-8 | 1,731 | 3.0625 | 3 | [
"CC-BY-NC-SA-4.0",
"Apache-2.0"
] | permissive | # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX - License - Identifier: Apache - 2.0
# Purpose
# This code example demonstrates how to list the Amazon Simple Storage Service (Amazon S3)
# buckets owned by the authenticated sender of the request.
# snippet-start:[s3.ruby.s3-ruby-exam... | true |
828b9570bc5497026ff941c31fd6352ec7f26ff0 | Ruby | andreyvit/ujudge | /lib/international.rb | UTF-8 | 674 | 2.96875 | 3 | [] | no_license |
module International
@@strings = {}
def self.put(id, value, options = {})
@@strings[id] = value
end
def self.get(id, options = {})
@@strings[id]
end
end
class Symbol
def s(*args)
International::get(self, *args)
end
end
International::put :required_field_m, "Обязател... | true |
19589442f51176d865d5278f3df43bb9795d0877 | Ruby | OhCoder/designpatterns-ruby | /builder/run.rb | UTF-8 | 345 | 2.53125 | 3 | [
"MIT"
] | permissive | require_relative 'PersonThinBuilder'
require_relative 'PersonFatBuilder'
require_relative 'PersonDirector'
thin = PersonThinBuilder.new
fat = PersonFatBuilder.new
puts "----------------"
thinDirector = PersonDirector.new(thin)
thinDirector.createPerson
puts "----------------"
fatDirector = PersonDirector.new(fat)
... | true |
7eb6b999449e652d514e6f7ec92157527a3cf788 | Ruby | staffler-xyz/xing_api | /lib/xing_api/response_handler.rb | UTF-8 | 1,927 | 2.546875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module XingApi
module ResponseHandler
OAUTH_ERROR_RESPONSES = %w(
INVALID_OAUTH_CONSUMER
CONSUMER_MISMATCH
INVALID_OAUTH_SIGNATURE_METHOD
INVALID_OAUTH_SIGNATURE
INVALID_TIMESTAMP
TIMESTAMP_EXPIRED
NONCE_ALREADY_USED
NONCE_MISSING
INVALID_OAUTH_VERSION
R... | true |
72bc81921e59397700edde3f1d516cda264c94c7 | Ruby | jdixon3/ruby_exercises | /loops2.rb | UTF-8 | 338 | 3.640625 | 4 | [] | no_license |
number = 0 # local variable number referencing 0
until number == 10 # until loop initialzed, which will iterate until number local variable = 10
number += 1 #increment the value referenced by number local variable by +1
next if number.odd? # modifying code to print only even numbers
puts number # output value... | true |
f6201bf59596f7371558c6ccebff91d3329e94c8 | Ruby | davidmowrer/LRTHW-T3 | /chapter_5/my_ex5.rb | UTF-8 | 1,309 | 4.21875 | 4 | [] | no_license | name = 'Zed A. Shaw'
age = 35 # not a lie in 2009
height = 74 # inches
weight = 180 # lbs
eyes = 'Blue'
teeth = 'White'
hair = 'Brown'
kilogram = 0.453593
centimeter = 2.54
height_in_centimeters = height * centimeter
weight_in_kilograms = weight * kilogram
current_year = 2014
year_2009 = 2009
current_age = age + (curr... | true |
b8886c0f3160876052f16aba97d450fe3946dd4a | Ruby | mikelikesbikes/ruby_piet | /spec/stack_spec.rb | UTF-8 | 5,489 | 2.875 | 3 | [] | no_license | require 'spec_helper'
describe Piet::Stack do
describe "creating" do
specify { subject.dp.should == :right }
specify { subject.cc.should == :left }
end
describe "pushing" do
specify { subject.push(:first).should == [:first] }
end
describe "popping" do
before(:each) do
subject.push(:fi... | true |
9ac977af58dd70f5fa61ed7110f470a61782b97b | Ruby | phss/playground | /exercises/skiena/chapter_four/exercise_4_36/matrix_count_spec.rb | UTF-8 | 848 | 2.671875 | 3 | [] | no_license | require "matrix_count"
describe MatrixCount do
it "should return 0 for matrix without 0" do
MatrixCount.zeros_of([[1, 2], [3, 4]]).should == 0
end
it "should return 1 for matrix with one row" do
MatrixCount.zeros_of([[0]]).should == 1
end
it "should return 2 for matrix with two rows and 2 zeros" d... | true |
19dd71c5eea43091515a50a8cf20317e6aa0799b | Ruby | CompScienceClub/ruby-information-theory | /examples/hash.rb | UTF-8 | 887 | 3.21875 | 3 | [
"MIT"
] | permissive | # Information Theory demo
# Copyright (c) 2016, Colin Shaw
# Distributed under the terms of the MIT License
require 'digest'
require '../src/information_theory.rb'
require '../src/symbols.rb'
SYMBOLS = 10000
md5_hash = ''
(SYMBOLS/32+1).times { md5_hash = md5_hash + (Digest::MD5.hexdigest Random::rand.to_s) }
md5_s... | true |
bdebd4846221edfc033bfdaf2f67f42f1069b2e5 | Ruby | Trecs/renewed | /test.rb | UTF-8 | 7,911 | 2.90625 | 3 | [] | no_license | class MyStruct < Struct
def initialize(**attributes)
attributes.each do |k, v|
public_send "#{k}=", v
end
end
end
module Trecs
class Timer
def sleep(time)
puts " "*30 + "sleep #{time}"
end
end
class Frame
attr_accessor :time
attr_reader :content
def initialize(time: n... | true |
7d17608b519b37016b2dd8e8b1007e8bce44679b | Ruby | omajul85/learn_to_program | /ch11-reading-and-writing/build_a_better_playlist.rb | UTF-8 | 632 | 3.390625 | 3 | [] | no_license | require_relative '../ch10-nothing-new/shuffle'
def music_shuffle filenames
shuffle(filenames)
end
# # Change directory to the folder containing my music
# Dir.chdir '/home/ubuntu/workspace/projects/music'
# # Find the path of each song using Dir and put them on an array
# song_files = Dir['**/*.mp3']
# # Add the ... | true |
ea16a2e823545266903e1edd2b16708aa8a50441 | Ruby | omidbachari/systems_check_5_31 | /server.rb | UTF-8 | 1,720 | 2.96875 | 3 | [] | no_license | require "pry"
require "pg"
require "sinatra"
require 'pg'
def db_connection
begin
connection = PG.connect(dbname: 'recipes')
yield(connection)
ensure
connection.close
end
end
def create_array_of_recipe_names_ids
recipe_hashes =
db_connection do |conn|
conn.exec('SELECT name, id, descri... | true |
9197eae781d0992730141c7c49e71ae01ed495d1 | Ruby | rubycoder/glimmer-dsl-tk | /lib/glimmer/dsl/tk/bind_expression.rb | UTF-8 | 1,184 | 2.625 | 3 | [
"MIT"
] | permissive | require 'glimmer/dsl/static_expression'
require 'glimmer/data_binding/model_binding'
module Glimmer
module DSL
module Tk
# Responsible for setting up the return value of the bind keyword (command symbol)
# as a ModelBinding. It is then used by another command handler like
# DataBindingCommandHa... | true |
2177878e47c00dea3f29dfd9ad8371f6baeb398d | Ruby | bmuller/gridcli | /lib/gridcli/commands/dislike.rb | UTF-8 | 838 | 2.578125 | 3 | [] | no_license | module GridCLI
class DislikeCommand < BaseCommand
def initialize
super "dislike", "Dislike something. Specify friends/subgrids to restrict recipients."
add_format_option
end
def usage
super "<dislike> [<username>[,<username>]]"
end
def run(args)
usage if args.length == 0
... | true |
3e0c5ff82df8841a0cf3af246580b1e30549c752 | Ruby | senenalonso/RUBY | /collections.rb | UTF-8 | 2,480 | 3.734375 | 4 | [] | no_license | class Home
attr_reader(:name, :city, :capacity, :price)
def initialize(name, city, capacity, price)
@name = name
@city = city
@capacity = capacity
@price = price
end
end
=begin
homes = [
Home.new("Fernando's place", "Seville", 5, 47),
Home.new("Nizar's place", "San Juan", 2, 42),
Home.new(... | true |
3af10f14b9139d232de807e1ddd9ed2d4a55f92f | Ruby | BytemarkHosting/mauvealert | /test/tc_mauve_history.rb | UTF-8 | 902 | 2.515625 | 3 | [] | no_license | $:.unshift "../lib"
require 'th_mauve'
require 'mauve/history'
require 'mauve/server'
class TcMauveHistory < Mauve::UnitTest
include Mauve
def setup
super
setup_database
end
def teardown
teardown_database
super
end
def test_save
Server.instance.setup
#
# Make sure events s... | true |
b7104627da436f9c85285ce35c3e63d7ad0c5915 | Ruby | expede/Lambda-Interpreter | /lib/model/expression.rb | UTF-8 | 1,707 | 3.171875 | 3 | [
"Unlicense"
] | permissive | # encoding: utf-8
require_relative '../lex/branch'
module Model
# A lambda-expression (including recursive sub-expression)
class Expression
attr_accessor :parameters,
:body,
:arguments
def self.root
@@root ||= nil
end
def self.reduce!
fail 'No root'... | true |
df12536c11d67a81e783dffb80b3d3c5dab8b9e4 | Ruby | filaone/codewars | /ruby_wars/004_pd_7k.rb | UTF-8 | 171 | 2.515625 | 3 | [] | no_license | #padded numbers
def solution(value)
"Value is %.5d" % value
# "Value is %05d" % [value]
sprintf "Value is %05d", value
# we should use sprintf to get the 00005
end | true |
73a13b2232d17817a4468e769340f16e70f9215a | Ruby | JohnZBurnett/say-hello-ruby-bootcamp-prep-000 | /say_hello.rb | UTF-8 | 113 | 3.28125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Build your say_hello method here
def say_hello(personName = "Ruby Programmer")
puts "Hello " + personName + "!"
end
| true |
b58a3cb012e8cd7f8ec83bb51a65499857425a5b | Ruby | MyNameIsSpencer/Wed_Nov_1_2017 | /exercise11.rb | UTF-8 | 629 | 3.921875 | 4 | [] | no_license | puts "EXERCISE 11"
# Ask for number of pizzas
# Ask for number of toppings for each pizza
# Print out
# def
# => pizza_number
x_number = 0
puts "How many pizzas would you like?"
quantity = gets.chomp.to_i
quantity.times do
x_number += 1
puts "How many toppings for pizza #{x_number}?"
user_toppings = gets.cho... | true |
92edad867155576dfa93f7daf888e77b93c6fa2f | Ruby | Rockster160/Games | /aoc2022/d15_fail.rb | UTF-8 | 3,130 | 2.734375 | 3 | [] | no_license | $test = true
$draw = true
$part = 1
# $pryonce || ($pryonce ||= true) && binding.pry
require "/Users/rocco/code/games/aoc2022/base"
# Draw.cell_width = 1
input = File.read("/Users/rocco/code/games/aoc2022/d15.txt")
input = "Sensor at x=2, y=18: closest beacon is at x=-2, y=15
Sensor at x=9, y=16: closest beacon is at... | true |
0b86d7b9d56bbae9b5da15e4b29761d90462d658 | Ruby | itggot-carl-erneman/standard-biblioteket | /lib/factorial.rb | UTF-8 | 123 | 2.90625 | 3 | [] | no_license | def factorial(numb)
i = 0
ut = 1
while i < numb
i = i + 1
ut = ut * i
end
return ut
end | true |
5d8f572017a40da566f1c0db29cb00d033bdfe95 | Ruby | charaton/pusher-websocket-ruby | /lib/pusher-client/channels.rb | UTF-8 | 576 | 2.75 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module PusherClient
class Channels
attr_reader :channels
def initialize(logger=PusherClient.logger)
@logger = logger
@channels = {}
end
def add(channel_name, user_data=nil)
@channels[channel_name] ||= Channel.new(channel_name, user_data, @logger)
end
def find(channel_name... | true |
6cdd5eb3363d088ec45471599991b908b649ae59 | Ruby | Sijey/ArcheryStore | /app/models/cart.rb | UTF-8 | 635 | 2.765625 | 3 | [] | no_license | class Cart < ActiveRecord::Base
has_many :lina_items, dependent: :destroy
def total_price
lina_items.to_a.sum { |item| item.total_price }
end
def add_product(product_id)
current_item = lina_items.find_by(product_id: product_id)
if current_item
current_item.quantity += 1
else
... | true |
1340653d6a40b2b5735bc73b870c42373aa56e98 | Ruby | learn-co-students/nyc-web-091619 | /04-many-to-many/run.rb | UTF-8 | 764 | 3 | 3 | [] | no_license | require "pry"
require_relative "./doctor"
require_relative "./patient"
require_relative "./appointment"
d1 = Doctor.new("ka", "cardio" , "MD")
d2 = Doctor.new("doogie", "neuro" , "MD")
d3 = Doctor.new("doolittle", "pets" , "MD")
p1 = Patient.new("evans", 8 , "male", false)
p2 = Patient.new("chett", 9001 , "male", tr... | true |
d639c5c6c90dd0d310f089ab96c11e8983016bfa | Ruby | andre-rodrigues/task-manager | /spec/models/concerns/task_parser_spec.rb | UTF-8 | 1,135 | 2.6875 | 3 | [] | no_license | require "rails_helper"
RSpec.describe TaskParser do
describe ".parse" do
let(:valid_task_input) { "Estudar tecnologias 30 minutos" }
let!(:persisted_task) do
Task.create(
start_at: Time.current,
end_at: 10.minutes.from_now,
description: "Teste de 10 minutos"
)
... | true |
5efa7343ef12508049a8fe68c3d6263036e89350 | Ruby | chiragchawla345/Beryl_Training | /Ruby/diamond.rb | UTF-8 | 672 | 4.0625 | 4 | [] | no_license | def diamond(n)
puts ""
temp = n/2 +1
s = temp
e = temp
for i in 1..n
if(i < temp)
#puts "#{temp} #{temp.class}"
#puts "#{s} #{s.class}"
for j in 1 ..n
if(s<=j && j<=e)
print "* "
else
print " "
end
end
s-=1
e+=1
puts ""
elsif(i == ... | true |
12aaede1cb1ac35bd9e1d394fa3d230b4a94bb7f | Ruby | rudymatela/metric_fu | /lib/metric_fu/metrics/hotspots/analysis/analyzed_problems.rb | UTF-8 | 2,364 | 2.875 | 3 | [
"MIT"
] | permissive | module MetricFu
class HotspotAnalyzedProblems
def initialize(hotspot_rankings, analyzer_tables)
@hotspot_rankings = hotspot_rankings
@analyzer_tables = analyzer_tables
end
def worst_items
worst_items = {}
worst_items[:files] = worst(@hotspot_rankings.worst_files, :file)
... | true |
9dee243cdd4bb2fccca655281e5f01586dcb4113 | Ruby | joeyjoejoejr/rpn_calculator | /lib/rpn_calculator/lexer/operator_token.rb | UTF-8 | 320 | 2.796875 | 3 | [] | no_license | module RpnCalculator
class Lexer
class OperatorToken
attr_accessor :value
def initialize(value)
self.value = value
end
def execute(operands)
operands.pop(2).reduce(value).tap do |result|
operands.push(result).compact!
end.to_f
end
end
end
end
| true |
3df648382dc2cd84c39770d9bb2bca5a2fad5822 | Ruby | aaronshurley/shelvesy | /db/seeds.rb | UTF-8 | 8,314 | 3.5625 | 4 | [] | no_license | reviews = [];
reviews.push("Shakespeare was a real cool person for his time. Unfortunately, his plays are not a real cool thing to read for my time. It is English and I speak English. I just don't happen to speak Old English. Which is really ironic because I am old and speaking English. If you read slowly and put your ... | true |
161ab6d78429c34867ea693ff99d5fc12496ef6f | Ruby | ioannis85/rails_practice | /app/carriers/fedex_carrier.rb | UTF-8 | 1,778 | 2.9375 | 3 | [] | no_license | class FedexCarrier
attr_reader :fedex_service, :label
def initialize(label)
@fedex_service = FedexService.new
@label = label
end
def calculate_total_weight
label_weight = get_weight_label
label_weight_unit = get_mass_unit_label
label_weight_kgs = WeightConverto... | true |
7041bbb7342ef285529c59803d3affe433d3ddf5 | Ruby | RichardCharman/Learn-To-Program | /deafGrandma2.rb | UTF-8 | 419 | 4 | 4 | [] | no_license | puts "HELLO SONNY. WHAT DO YOU WANT?"
command = ''
exit = 0
while exit < 3
command = gets.chomp
if command == command.downcase
puts "HUH, SPEAK UP SONNY"
else
if command == "BYE"
age = 100 - (rand(16))
puts "EH? I'M " + age.to_s + " YOU KNOW?"
exit = exit+1
else
year = 1950 ... | true |
4f3cd6a07fd5aa1d54f209a670d35e5d6f9dd820 | Ruby | testinfected/adventofcode2017 | /lib/day07/recursive_circus.rb | UTF-8 | 1,630 | 3.421875 | 3 | [] | no_license | Tower = Struct.new(:program, :weight, :sub_programs) do
def total_weight(towers)
sub_programs.inject(weight) {|total, sub_program| total + towers[sub_program].total_weight(towers)}
end
def find_unbalanced(towers)
by_weight = sub_programs_by_weight(towers)
return [] if by_weight.length == 1
unbal... | true |
c912346ac0dd038b71d8d428cfcbef7a2d7a2f12 | Ruby | paulgeringer/cronit | /lib/cronit/parser.rb | UTF-8 | 279 | 2.859375 | 3 | [] | no_license | class Parser
attr_accessor :crontab
def initialize(crontab)
@crontab = crontab
end
def arrayify_crontab
crontab.split
end
def validate_crontab
raise InvalidCrontab if self.arrayify_crontab.length < 5
end
end
class InvalidCrontab < StandardError
end
| true |
f225b208a1a9655b24317f1174a77db066cb9b37 | Ruby | kkerrigan/alpha-blog | /test/models/category_test.rb | UTF-8 | 734 | 2.625 | 3 | [] | no_license | require 'test_helper'
class CategoryTest < ActiveSupport::TestCase
def setup
@category = Category.new(name: "sports")
end
test "categoryShouldBeValid" do
assert @category.valid?
end
test "nameShouldBePresent" do
@category.name = " "
assert_not @category.... | true |
51411eafc6e519840ebc854a60592b75ea4cd342 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/3197d8c8580f4f3c85ed7d0a8e6f2e12.rb | UTF-8 | 708 | 3.4375 | 3 | [] | no_license | class Bob
attr_reader :heard
def hey(heard)
@heard = heard
respond!
end
def responses
{
:chill => "Woah, chill out!",
:whatever => "Whatever.",
:sure => "Sure.",
:fine => "Fine. Be that way!"
}
end
private
def respond!
thought = process_what_was... | true |
7ac63acbede2a304f85bddf3119dfdb625c290a1 | Ruby | cbstodd/polis | /vendor/cache/ruby/2.1.0/gems/lumberjack-1.0.9/lib/lumberjack/formatter.rb | UTF-8 | 3,047 | 3.203125 | 3 | [
"MIT"
] | permissive | module Lumberjack
# This class controls the conversion of log entry messages into strings. This allows you
# to log any object you want and have the logging system worry about converting it into a string.
#
# Formats are added to a Formatter by associating them with a class using the +add+ method. Formats
# a... | true |
e26a80b0fde7217c1daeb14ad2a5873b084d4a9e | Ruby | sanami/git_tools | /update_all.rb | UTF-8 | 665 | 2.625 | 3 | [] | no_license | require 'pp'
class Tools
##
# Recursively update git repos
def git_update_all
find_dirs do
`git pull`
end
end
private
##
# Find all folders with git repos in .git
def find_dirs(dir_name = '.', &action)
Dir.foreach('.') do |dir|
next unless File.directory? dir
next if dir ==... | true |
b96f52924431bb07bd5bcedcb95f6c80756109a2 | Ruby | d-Pixie/ruby-poker | /lib/ruby-poker/cactus_kev_ruby_evaluator.rb | UTF-8 | 4,307 | 3.015625 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require File.expand_path('../cactus_kev_value', __FILE__)
require File.expand_path('../cactus_kev_five_card_evaluator_tables', __FILE__)
=begin rdoc
CactusKevRubyEvaluator (original), using a direct ruby hash from the product of prime numbers
corresponding to each card. Because so much of the heavy lifting is... | true |
8087fdcd8ad7b6b1a983e7fdb9f81a4f14588aa7 | Ruby | wkonkel/cache_bar | /test/benchmark-memcache-client.rb | UTF-8 | 354 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'benchmark'
require 'rubygems'
gem 'memcache-client'
require 'memcache'
c = MemCache.new('0.0.0.0')
5.times do
puts 'set: ' + Benchmark.realtime {
10000.times do |i|
c.set('test', 'testing 123')
end
}.to_s
end
5.times do
puts 'get: ' + Benchmark.realtime {
10000.times do |i|
c... | true |
b31d712f0a893c14d555b921aed5a9063edbf2f4 | Ruby | device-independent/hue-client | /lib/hue/client/models/whitelist_users.rb | UTF-8 | 1,031 | 2.734375 | 3 | [
"MIT"
] | permissive | require File.expand_path('../whitelist_user', __FILE__)
module Hue
module Client
module Models
class WhitelistUsers
include Enumerable
# Creates an instance of the WhitelistUsers
# collection
#
# @return [Hue::Client::Models::WhitelistUsers] Self
def initial... | true |
59b4fa83ee7dbb93feff35834de54da96a94674e | Ruby | ajlopez/PLangRe | /files/ruby/gist03.rb | UTF-8 | 94 | 3.125 | 3 | [
"MIT"
] | permissive | 3.times {print "Ruby!"} #Prints "Ruby!Ruby!Ruby!"
1.upto(9) {|x| print x} #Prints "123456789" | true |
09c7f03074e18d88418c57e31a218ccf2f49a201 | Ruby | svenfuchs/rails-i18n | /lib/rails_i18n/common_pluralizations/one_few_other.rb | UTF-8 | 863 | 2.734375 | 3 | [
"MIT"
] | permissive | module RailsI18n
module Pluralization
module OneFewOther
FROM_2_TO_4 = (2..4).to_a.freeze
FROM_12_TO_14 = (12..14).to_a.freeze
def self.rule
lambda do |n|
return :other unless n.is_a?(Numeric)
frac = (n.to_d % 1)
if frac.nonzero?
n = frac.to... | true |
5d445ed6b2e6e841e2c95943ca5f97368cdd68b6 | Ruby | ducarroz/refilling_queue | /lib/refilling_queue.rb | UTF-8 | 1,837 | 2.625 | 3 | [
"MIT"
] | permissive | require 'refilling_queue/version'
class RefillingQueue
class Locked < RuntimeError
end
DEFAULT_OPTIONS = {
:lock_timeout => 60,
:refresh_every => nil,
:paginate => false
}
def initialize(client, name, options={}, &block)
@client, @name, @block = client, name, block
@page_name = name + "... | true |
b5023a4a24e7a4f2368449d4b1f79ec86a8148f3 | Ruby | ywt222/api-homework | /lib/api/resources/products.rb | UTF-8 | 1,074 | 2.59375 | 3 | [
"MIT"
] | permissive | require 'sinatra'
require 'mysql'
require 'json'
require_relative '../../domain/models/product'
ActiveRecord::Base.establish_connection(
:adapter => 'mysql',
:host => 'localhost',
:username => 'root',
:password => '',
:database => 'product_service'
)
get '/products' do
all_pros = Product.a... | true |
f702e6510f90ac4e397f4c08a43bf6f02ed4e771 | Ruby | MikeBlumenthal/homework_day_2 | /ruby_functions_practice.rb | UTF-8 | 1,384 | 4.03125 | 4 | [] | no_license | def return_10
return 10
end
def add(number_1, number_2)
return number_1 + number_2
end
def subtract(number_1, number_2)
return number_1 - number_2
end
def multiply(number_1, number_2)
return number_1 * number_2
end
def divide(number_1, number_2)
return number_1 / number_2
end
def length_of_string(string)... | true |
ad8657af8d2c8aea7b19743c60ac9de0898f4c4f | Ruby | rom-rb/rom | /lib/rom/cache.rb | UTF-8 | 1,626 | 2.53125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # frozen_string_literal: true
require "concurrent/map"
module ROM
# Thread-safe cache used by various rom components
#
# @api private
class Cache
attr_reader :objects
# @api private
class Namespaced
# @api private
attr_reader :cache
# @api private
attr_reader :namespace
... | true |
c062d954459fce7a3ba009d4dc113c3afedcf0a8 | Ruby | RobertDober/lab42_curry | /lib/lab42/curry/arg_compiler/phase2.rb | UTF-8 | 2,496 | 2.578125 | 3 | [
"Apache-2.0"
] | permissive | require_relative '../errors'
require_relative 'positionals'
module Lab42
module Curry
class ArgCompiler
class Phase2
attr_reader :compiler, :rt_args, :rt_blk, :rt_kwds
# TODO: Easy, peasy sequential refactor
def compile
if rt_blk && compiler.ct_blk && !compiler.allows_ove... | true |
b4e8d882c3d6feded6fa8487fec2f7faabdc1f64 | Ruby | wisq/autocrew | /test/autocrew/line_test.rb | UTF-8 | 823 | 2.890625 | 3 | [] | no_license | require 'minitest_helper'
require 'autocrew/line'
module Autocrew
class LineTest < Minitest::Test
test "create from coords" do
line = Line.new(start = Coord.new(-1,2), Coord.new(2, -2))
assert_equal start, line.start
assert_equal 3, line.vector.x
assert_equal -4, line.vector.y
asse... | true |
c9b48f5534ef08dae310b86f5e094a6d609855b2 | Ruby | carson-jardine/futbol | /lib/games.rb | UTF-8 | 604 | 2.734375 | 3 | [] | no_license |
class Games
attr_reader :game_id, :season, :type, :date_time, :away_team_id, :home_team_id, :away_goals, :home_goals, :venue, :venue_link
def initialize(games_info)
@game_id = games_info[:game_id].to_i
@season = games_info[:season].to_i
@type = games_info[:type]
@date_time = games_info[:date_tim... | true |
979f96ebd1c275d804891884f47551d43bdc6742 | Ruby | QuinnMcHugh/tic-tac-toe-on-rails | /app/models/Move.rb | UTF-8 | 153 | 3.171875 | 3 | [] | no_license | class Move
attr_accessor :col, :row, :score
def initialize
col = nil
row = nil
score = nil
end
def to_s
"col: #{col}, row: #{row}"
end
end | true |
4922fc936bd6f5f542f05fb2890e240e0d2f88a3 | Ruby | Sruthisarav/My-computer-science-journey | /The Odin Project/Ruby Programming/Data Structures and Algorithms/Assignment2/node.rb | UTF-8 | 747 | 3.75 | 4 | [] | no_license | class Node
attr_reader :position, :parent, :children
def initialize(position, parent=nil)
@position = position
@parent = parent
@children = []
end
def valid_move?(pos)
return true if pos[0] >= 0 && pos[0] < 8 && pos[1] >= 0 && pos[1] < 8
return false
end
d... | true |
74d018ebed68feb65a1492eccaee111461d0a72f | Ruby | leishiguang/Ruby_Getting_Started | /3.LeetCode/001-100/022.generate_parentheses.rb | UTF-8 | 1,127 | 3.609375 | 4 | [] | no_license | # @param {Integer} n
# @return {String[]}
def generate_parenthesis(n)
generate_parenthesis_1(n)
# generate_parenthesis_2(n)
end
def generate_parenthesis_1(n)
n = n.to_i
result = []
generate_parenthesis_1_helper(n,n,'',result)
result
end
def generate_parenthesis_1_helper(left,right,out,result)
return if l... | true |
db5e9dbb815452be2e20dc11e6b157aa6a236eec | Ruby | dimitrybesson/object_oriented_programming | /rover/missioncontrol.rb | UTF-8 | 3,028 | 3.28125 | 3 | [] | no_license | class MissionControl
attr_reader :plateau_list, :rover_list
def initialize
@plateau_list = Array.new
@rover_list = Array.new
end
def display_plateau_list
puts "TOTAL PLATEAUS: #{Plateau.plateau_counter}\n"
@plateau_list.each do |plateau|
puts "ID: #{plateau.id}\t X-MAX: #{plateau.x_max}\... | true |
045e5d932f6b95128ca3935e186ea79733938b00 | Ruby | h-debin/ruby-code | /array.rb | UTF-8 | 444 | 3.75 | 4 | [] | no_license | #!/usr/bin/ruby
names = Array.new(20)
puts names.size # 返回 20
puts names.length # 返回 20
names = Array.new(4, "mac")
puts "#{names}"
nums = Array.new(10) { |e| e = e * 2 }
puts "#{nums}"
digits = Array(0..9)
puts "#{digits}"
num = digits.at(6)
puts "#{num}"
a = [ "a", "b", "c" ]
n = [ 65, 66, 67 ]
puts a.pack("A3A... | true |
6d0779b71b3ed40dc7e08d0bad95bff5203e8f03 | Ruby | playup/dew | /lib/dew/validations.rb | UTF-8 | 223 | 2.625 | 3 | [
"MIT"
] | permissive | module Validations
class Validation
def self.validates_format_of string, regex
raise ArgumentError, "Validation error. '#{string}' does not match '#{regex.inspect}'" unless regex.match(string)
end
end
end | true |
8acc199b2a738f66c9105ba1677a1921dfc3ec66 | Ruby | mg50/logistic-regression | /make | UTF-8 | 618 | 2.578125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'pry'
class File
def replace!(text, replacement)
content = read
content.sub!(text, replacement)
seek 0
write(content)
seek 0
end
end
ELM_MODULE_NAME = 'Main'
puts `elm make ./elm/#{ELM_MODULE_NAME}.elm --yes --output build/#{ELM_MODULE_NAME}.js`
native_js = File.r... | true |
c81f536a54be79ee405ac19fddad9aac32e7a34d | Ruby | andy-twosticks/nebulous_stomp | /lib/nebulous_stomp.rb | UTF-8 | 4,441 | 2.9375 | 3 | [] | no_license | require 'stomp'
require 'redis'
require 'logger'
require 'devnull'
require 'nebulous_stomp/version'
require 'nebulous_stomp/param'
require 'nebulous_stomp/message'
require 'nebulous_stomp/target'
require 'nebulous_stomp/listener'
require 'nebulous_stomp/request'
require 'nebulous_stomp/stomp_handler'
require 'nebulous... | true |
d8e4b03dcb883950a38a7f310428a952b8dfdb36 | Ruby | VijayEluri/DTDojo | /src/kata6/asantoro/statemachinetest.rb | UTF-8 | 676 | 2.75 | 3 | [] | no_license | require 'test/unit'
require 'fsm'
class FsmTest < Test::Unit::TestCase
def setup
@fsm = FiniteStateMachine.new("0,1","A:inA,B:inB","A:B:0,B:A:1")
end
def test_initial_state
assert_equal("A", @fsm.state)
assert_equal("inA", @fsm.state_value)
end
def test_transition
assert_equ... | true |
4bdb87a3e1fe567c7bdc4a06a10d7b730bd026a4 | Ruby | QaDeS/sequel_auto | /spec/waiting_hash_spec.rb | UTF-8 | 1,077 | 3.109375 | 3 | [
"MIT"
] | permissive | require 'waiting_hash'
unless [].respond_to? :each_cons
class Array
def each_cons(count)
buffer = []
each do |e|
buffer << e
next unless buffer.size == count
yield buffer
buffer.shift
end
end
end
end
describe WaitingHash do
it "should work properly" do
... | true |
5559d01b383305a52ced8d8bfd3ca6b3d645af1d | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/binary/ec8f06b386d54f068409617476f2014e.rb | UTF-8 | 234 | 3.46875 | 3 | [] | no_license | class Binary
def initialize(s)
if s.tr('^01', '') != s then
@s = "0"
else
@s = s
end
end
def to_decimal
n = 0
@s.chars.reverse.each_with_index { |c, i| n += c.to_i * (2 ** i) }
n
end
end
| true |
cf64a3e291303e7eeda95f848010ae8820cfa3e4 | Ruby | thinkerbot/data_graph | /lib/data_graph/linkage.rb | UTF-8 | 3,256 | 2.578125 | 3 | [
"MIT",
"X11-distribute-modifications-variant"
] | permissive | require 'data_graph/utils'
module DataGraph
class Linkage
include Utils
attr_reader :macro
attr_reader :name
attr_reader :through
attr_reader :table_name
attr_reader :connection
attr_reader :parent_columns
attr_reader :child_columns
attr_reader :child_node
def initia... | true |
f6b31db9604710cb9ca58f7bf764fc46844971f8 | Ruby | Em01/Takeaway | /lib/customer.rb | UTF-8 | 166 | 2.78125 | 3 | [] | no_license | class Customer
def initialize name, phone_number
@name = name
@phone_number = phone_number
end
def name
@name
end
def phone_number
@phone_number
end
end | true |
988dc5ab6ede0e983c653d78cd7d564028bdb5c8 | Ruby | iogr/cryptocurrency_cli | /lib/cryptocurrency_search.rb | UTF-8 | 379 | 2.578125 | 3 | [
"MIT"
] | permissive | class CRYPTO::CryptocurrencySearch
@@all = []
def initialize(crypto_hash)
crypto_hash.each do |key, value|
self.class.attr_accessor(key)
self.send("#{key}=", value)
#"#{key} #{value}" if key == "#{self.input}"
end
@@all << self
end
def self.all
@@all
end
def self.input(... | true |
5356839434b7fe64a20838e73a042423475c33fd | Ruby | Troemer16/learning_ruby | /sum.rb | UTF-8 | 176 | 3.609375 | 4 | [] | no_license | def sum (nums)
total = 0
nums.each do |i|
total += i
end
return total
end
my_array = [1, 2, 3, 4, 5, 6, 7]
puts my_array[3]
puts sum(my_array)
| true |
9f4dbb97ece85c05b81adf0a678ee0855325d0e3 | Ruby | hrwilliams/ping_pong_ruby | /spec/ping_pong_spec.rb | UTF-8 | 667 | 2.8125 | 3 | [] | no_license | require('rspec')
require('ping_pong')
describe('Fixnum') do
it("counts up to number provided") do
expect((2).ping_pong()).to(eq([1,2]))
end
it("when counting, replaces all multiples of 3 with ping") do
expect((7).ping_pong()).to(eq([1, 2, "ping", 4, "pong", "ping", 7]))
end
it("when counting, replace... | true |
cb35d605d97ea504cd30f43834418d0a620e1483 | Ruby | NikoRoberts/Ensure-encoding | /lib/ensure/encoding.rb | UTF-8 | 4,984 | 3.21875 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
module Ensure
module Encoding
BYTE_ORDER_MARKS = {
::Encoding::UTF_16BE => [0xfe, 0xff],
::Encoding::UTF_16LE => [0xff, 0xfe],
::Encoding::UTF_8 => [0xef, 0xbb, 0xbf]
}
# Tries to guess the encoding of the string and returns the most likely
# encoding.
... | true |
d61d66dda288f0d5a1ba8493b247d9b1ea5797c5 | Ruby | hxa7241/minilight-ruby | /SurfacePoint.rb | UTF-8 | 4,207 | 2.734375 | 3 | [
"CC0-1.0",
"LicenseRef-scancode-other-permissive"
] | permissive | #------------------------------------------------------------------------------#
# #
# MiniLight Ruby : minimal global illumination renderer #
# Harrison Ainsworth / HXA7241 : 2006-2008, 2013. ... | true |
6541dad131609bec8604f84645c17a45ca076c70 | Ruby | vedantshetty/Odin_Project_Code | /Ruby/bing_search/bing.rb | UTF-8 | 511 | 3.375 | 3 | [] | no_license | require 'rest-client'
class Bing
def search(search_term=input)
base = 'https://www.bing.com/search'
response = RestClient.get(base, {params:{:q =>search_term }})
if response.code == 200
puts response.body
else
puts 'error'
end
end
def format(search)
search.split(' ').join('+... | true |
2ca651045032c04c2cdd3ac69c92609138da5822 | Ruby | dpholbrook/flexodoro | /cycle.rb | UTF-8 | 1,719 | 2.921875 | 3 | [] | no_license | # state and logic for each current flexodoro cycle
class Cycle
attr_reader :focus_start, :rest_start, :rest_duration, :focus_duration,
:rest_end
def initialize(time_zone)
@time_zone_offset = time_zone * SECONDS_PER_HOUR
@focus_start = set_time
@pauses = []
end
def set_time
Time.n... | true |
d0ca717bff28e01242322c21dac1f1837cd58eb5 | Ruby | hoang-tranviet/queue.h | /script/pad.rb | UTF-8 | 254 | 2.546875 | 3 | [
"BSD-3-Clause"
] | permissive | #!/usr/bin/env ruby
# Created: May 15, 2013
# Author: Rogério Carvalho Schneider <stockrt@gmail.com>
o = File.open('pad.txt', 'wt')
File.open('queue.h', 'rt').each_line do |line|
if line =~ / \\$/
line['\\'] = ' ' * (79 - line.length) + '\\'
end
o.write(line)
end
o.close
| true |
749b35843bc2a278fb2c0014a43473cb0f5617da | Ruby | FergusLemon/boris_bikes | /lib/van.rb | UTF-8 | 304 | 2.734375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require_relative 'bike_container'
class Van
include BikeContainer
def collect_bikes(location)
collected_bikes = location.handover_bikes
collected_bikes.each { |bike| add_bike(bike) }
end
def deliver_bikes(location)
bikes.each { |bike| location.dock(bike) }
bikes.clear
end
end
| true |
6c2f1b46cbcf9b78560a9ee4da742e66eae688e1 | Ruby | natashamcintyre/battle-intro | /app.rb | UTF-8 | 451 | 2.546875 | 3 | [] | no_license | require 'sinatra'
set :session_secret, "not super secret"
get '/' do
"Hello - no exit!"
end
get '/secret' do
"Super secret message"
end
get '/slightlylesssecret' do
"Slightly less secret"
end
get '/anotherone' do
'Here we are'
end
get '/random-cat' do
@cat_name = ["Amigo", "Oscar", "Viking"].sample
er... | true |
76ef03a610d97f6ad48cb80eda90b5d9382180ab | Ruby | ajluxey/RailsProfDev | /app/services/subscriber_service.rb | UTF-8 | 557 | 2.546875 | 3 | [] | no_license | class SubscriberService
def initialize(user)
@user = user
end
def subscribe_on(question)
raise CanCan::AccessDenied.new('Not authorized!', :subscribe_on, question) if Ability.new(@user).cannot? :subscribe_on, question
@user.subscriptions.create!(question: question)
end
def unsubscrib... | true |
5317c3c9083a5087f4ed2bda69b8670716011c2e | Ruby | Haegin/ania | /lib/ania/matcher.rb | UTF-8 | 441 | 2.6875 | 3 | [
"Apache-2.0"
] | permissive | module Ania
class Matcher
attr_reader :expected, :actual
def initialize(expected, actual)
@expected = expected
@actual = actual
end
def match?
expected == actual
end
def write_output(suffix = "output", extension = "txt")
File.open("rails-#{suffix}.#{extension}", "w"... | true |
3761d9612ecd69d889205372e4af88b028698a96 | Ruby | Steinunn89/customer_relationship_application | /rolodex.rb | UTF-8 | 807 | 3.140625 | 3 | [] | no_license | class Rolodex
attr_reader :contacts
@@index = 1000
def initialize
@contacts = []
end
def add_contact(contact)
contact.id = @@index
@@index += 1
@contacts << contact
end
def display_particular_contact(id)
@contacts.each do |contact|
if contact.id == id
return contact
end
end
end
def ... | true |
a5e733acabd9932a3545ea00a7325843bda89157 | Ruby | ttrelle/mongodb-buch | /ruby/browse.rb | UTF-8 | 276 | 2.53125 | 3 | [] | no_license | require 'mongo'
connection = Mongo::Connection.new
connection.database_names.each { |db_name|
print db_name, ":\n"
db = connection.db(db_name)
db.collection_names.each { |cn|
collection = db.collection(cn)
print " - " + cn + " (", collection.count, ")\n"
}
}
| true |
c7b5d0c7006a9a61bfc12c3afae878392fdba0bf | Ruby | scottfirestone/black_thursday | /test/invoice_repository_test.rb | UTF-8 | 3,224 | 2.921875 | 3 | [] | no_license | require 'test_helper'
require 'invoice_repository'
class InvoiceRepositoryTest < Minitest::Test
attr_reader :sales_engine
def setup
@sales_engine = mock()
end
def test_it_is_an_invoice_repo_instance
inv_repo = InvoiceRepository.new("test_invoices.csv", sales_engine)
assert_equal InvoiceRepository,... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.