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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
6a5da8df87b26de54afa7e2cc48a0732d936bd91 | Ruby | gcao/viewit | /lib/viewit/data_item.rb | UTF-8 | 1,705 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Viewit
class DataItem
attr :input
def initialize input
@input = input
end
def eql? other
return false unless other.is_a? DataItem
@input.eql?(other.input)
end
def == other
return false unless other.is_a? DataItem
@input == other.input
end... | true |
475c2accac4a467d1e286f62489215c0cef6a024 | Ruby | janko/tic-tac-toe | /lib/tic_tac_toe/tui/board.rb | UTF-8 | 1,660 | 3.171875 | 3 | [
"MIT"
] | permissive | require "strscan"
class TicTacToe
class TUI
class Board
SYMBOL_COLORS = {
"x" => Curses::COLOR_RED,
"○" => Curses::COLOR_BLUE,
"△" => Curses::COLOR_YELLOW,
"□" => Curses::COLOR_GREEN,
"◇" => Curses::COLOR_MAGENTA,
}
COLOR_GRAY = 8
attr_reader :wind... | true |
93251153f27ebcee887132f4ab6e6ffe28f29faf | Ruby | rockychiang/key-for-min-value-v-000 | /key_for_min.rb | UTF-8 | 326 | 3.65625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # prereqs: iterators, hashes, conditional logic
# Given a hash with numeric values, return the key for the smallest value
def key_for_min_value(name_hash)
key = {none: nil}
name_hash.each do |item, no|
if key[:none] == nil || no < key[:none]
key[:low] = item
key[:none] = no
end
end
key[:lo... | true |
26e6d068ce3b9f298cb7eedf0c1097114df30750 | Ruby | briancabbott/rb-programming-sandbox | /Open Source/Ruby VMs/XRuby/xruby-read-only/.svn/pristine/26/26e6d068ce3b9f298cb7eedf0c1097114df30750.svn-base | UTF-8 | 1,483 | 2.953125 | 3 | [
"Apache-2.0"
] | permissive | require 'common'
test_check('integer')
test_ok(1.to_i == 1)
#test_ok(1.to_i.object_id == 1.object_id)
test_ok(33.to_i == 33)
#test_ok(33.to_i.object_id == 33.object_id)
32.times do |index|
test_ok((1 << index).size == 4)
end
test_ok(1.to_f == 1.0)
test_ok(2.to_f == 2.0)
test_ok(3.to_f == 3.0)
test_ok((-3).to_f == -3... | true |
87c2fcb58a12e5ad9ec9cfc170c5ab3562a7c26e | Ruby | kkhskim/CodingPractice | /HackerRank/Algorithms/Implementation/18_AngryProfessor.rb | UTF-8 | 217 | 2.84375 | 3 | [] | no_license | #!/bin/ruby
t = gets.strip.to_i
for a0 in (0..t-1)
n,k = gets.strip.split(' ').map(&:to_i)
a = gets.strip.split(' ').map(&:to_i)
on_time = a.count { |t| t <= 0 }
puts (on_time < k) ? "YES" : "NO"
end
| true |
f3a690f99834f129ac31a8eb368e76dd9e2976c5 | Ruby | leahcodes/rock_paper_scissors | /lib/rps.rb | UTF-8 | 492 | 3.1875 | 3 | [
"MIT"
] | permissive | class String
define_method(:rps) do |player2|
p1w = "Player 1 wins!"
p2w = "Player 2 wins!"
if self == player2
"It's a tie!"
elsif self == "r" && player2 == "s"
p1w
elsif self == "r" && player2 == "p"
p2w
elsif self == "s" && player2 == "r"
p2w
elsif self == "s" && pl... | true |
97ef596d2c30d96e6721fe2ee0d01c23d5048463 | Ruby | jronallo/mead | /bin/emv | UTF-8 | 2,152 | 2.671875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/env ruby
require 'pp'
require 'rubygems'
require 'json'
# does an Mead::Ead validity check on a directory of EADs using the ead2meads tool
dir = ARGV[0] || (puts 'Give the path to a directory of EADs to validate!'; exit)
valid = []
invalid = []
invalid_responses = {}
files = Dir.glob(File.join(dir, '*.xml... | true |
ee8a4de724a59c0169b223c6315f193609894a01 | Ruby | rentes/design_patterns_in_ruby | /Structural/Composite/composite.rb | UTF-8 | 1,053 | 4.28125 | 4 | [
"MIT"
] | permissive | # The Component class
class Graphic
def print
end
end
# The Composite class
class CompositeGraphic < Graphic
attr_accessor :child_graphics
def initialize
@child_graphics = []
end
def print
@child_graphics.each(&:print)
end
# Adds the graphic to the composition
def add(graphic)
@child_g... | true |
e146cbc46f9634218b1ef93e0424e9ba76db63a3 | Ruby | svbarilov/ruby_kick_prologs_ass | /problems/logic/01.rb | UTF-8 | 1,005 | 3.765625 | 4 | [] | no_license | # 3.01 (**) Truth tables for logical expressions.
# Define predicates and/2, or/2, nand/2, nor/2, xor/2, impl/2 and equ/2 (for logical equivalence) which succeed or fail according to the result of their respective operations; e.g. and(A,B) will succeed, if and only if both A and B succeed. Note that A and B can be Prol... | true |
c0a3b9830c6ecf204d641bac0a8ee8f95db2e0a7 | Ruby | axprin/phase_0_unit_2 | /week_4/2_creative/make_a_homework_cheater/my_solution.rb | UTF-8 | 5,544 | 4.09375 | 4 | [] | no_license | # U2.W4: Homework Cheater!
# I worked on this challenge [by myself, with: Spencer Olson.
# 2. Pseudocode
# Input: The input will be a famous person and a list of their attributes.
# Output: The output will be a gramatically correct, ready-to-turn-in essay.
# Steps:
# 1) Define a function titled essay_writer
# 2) E... | true |
04f7d696c868d860d3282a9918d29db3dfeaa070 | Ruby | hathitrust/ht_sip_validator | /lib/ht_sip_validator/validator/image/sequence.rb | UTF-8 | 3,031 | 2.75 | 3 | [
"Apache-2.0"
] | permissive | # frozen_string_literal: true
module HathiTrust::Validator::Image
class Sequence < HathiTrust::Validator::Base
attr_accessor :image_files
def perform_validation
@image_files = @sip.group_files(:image).sort
return no_images_error if image_files.empty?
# filenames that have invalid sequence... | true |
6215949d89dc1793762fbc63eab3c427e415f67f | Ruby | skolznev/LearnRuby | /Cap3 Regular.rb | UTF-8 | 8,851 | 2.9375 | 3 | [] | no_license | #Глава 3. Регулярные Выражения
#3.4. Якоря
s1 = "abcXdefXghi"
puts /def/ =~ s1
puts /abc/ =~ s1
puts /ghi/ =~ s1
puts /^def/ =~ s1
puts /def$/ =~ s1
puts /^abc/ =~ s1
puts /ghi$/ =~ s1
puts
s2 = "abc\ndef\nghi"
puts /def/ =~ s2 # 4
puts /abc/ =~ s2 # 0
puts /ghi/ =~ s2 # 8
puts /^def/ =~ s2 # 4
puts /def$/ =~ s2 # ... | true |
2ea54a60469ed429bbf285208d1130db1bd54d50 | Ruby | souljuse/oystercard | /spec/oystercard_spec.rb | UTF-8 | 2,021 | 2.953125 | 3 | [] | no_license | require 'spec_helper'
describe Oystercard do
let(:station) { double :station, zone: 1 }
it 'has a balance of zero' do
expect(subject.balance).to eq(0)
end
describe '#top_up' do
it 'can top up the balance' do
expect { subject.top_up(10) }.to change{ subject.balance }.by 10
end
context ... | true |
a153bab9ca59e6c4f94671457d1b4e27560fdb9e | Ruby | bvicenzo/ruby2600 | /lib/ruby2600/frame_generator.rb | UTF-8 | 1,731 | 2.59375 | 3 | [
"MIT"
] | permissive | module Ruby2600
class FrameGenerator
# A scanline "lasts" 228 "color clocks" (CLKs), of which 68
# are the horizontal blank period, and 160 are visible pixels
HORIZONTAL_BLANK_CLK_COUNT = 68
VISIBLE_CLK_COUNT = 160
def initialize(cpu, tia, riot)
@cpu = cpu
@tia = tia
@riot = ... | true |
9aa4da0f5e34870023a78017d2e9164d05bcc0fb | Ruby | jackcglover/mocking | /lib/weather_service.rb | UTF-8 | 312 | 3.0625 | 3 | [] | no_license | class WeatherService
def sunny?
[true, false][(rand(2))]
end
def windy?
[true, false][(rand(2))]
end
def raining?
[true, false][(rand(2))]
end
def snowing?
[true, false][(rand(2))]
end
def current_temperature
[80, 60, 40, 20][(rand(4))]
end
end | true |
8a448d1fea082da8e80ca18158882aaa629431b8 | Ruby | SanaNasar/ruby_challenges_lab | /pTimes.rb | UTF-8 | 318 | 4.21875 | 4 | [] | no_license | # 1.) Write a method called pTimes that takes a statement
# and a num puts the statement some num of times to the
# console.
def pTimes(statement, num)
# //define a function using def keyword
num.times do
puts statement
# statement = gets.chomp //waits for the user input
end
end
pTimes("I am sleepy!", 10)
| true |
5b50f31f5c2ffa7854b895ed06e75c464d3088e6 | Ruby | JamesMcMull/fizzbuzz | /lib/fizzbuzz.rb | UTF-8 | 229 | 3.78125 | 4 | [] | no_license | def fizzbuzz(number)
if number%(3) == 0 && number%(5) == 0
return "fizzbuzz"
elsif number%(3) == 0
return "fizz"
elsif number%(5) == 0
return "buzz"
else
return number
end
end | true |
cc6d579336d39a5f59ce33027b840d17598e84c8 | Ruby | 10kh-at-rb/AppAcademyCurriculum | /Poker/lib/array.rb | UTF-8 | 976 | 3.46875 | 3 | [] | no_license |
class Array
def stock_picker
max_value = 0
best_pair = []
self.each_index do |i|
self.each_index do |j|
next unless i < j
diff = self[j] - self[i]
if diff > max_value
best_pair = [i,j]
max_value = diff
end
end
end
best_pair
end
... | true |
3ac5bf7ca991ee04cb0dab88b095aa801e2f44f1 | Ruby | jrhafer/programming_foundations | /ruby_101/easy9/easy9_ex10.rb | UTF-8 | 219 | 3.234375 | 3 | [] | no_license | def buy_fruit(produce_list)
produce_list.map { |array| [array[0]] * array[1] }.flatten
end
buy_fruit([["apples", 3], ["orange", 1], ["bananas", 2]]) ==
["apples", "apples", "apples", "orange", "bananas","bananas"]
| true |
f3cab86e3b8da2dd4e389c0f935d7bae05b2b2d2 | Ruby | dofuta/boat-licence | /config/initializers/custom_date.rb | UTF-8 | 739 | 2.59375 | 3 | [] | no_license | require "date"
require "holiday_jp"
class Date
def holiday?
if HolidayJp.holiday?(self)
return "hd"
end
end
def sun_or_sat?
case self.wday
when 0
return "sun"
when 6
return "sat"
else
return ""
end
end
def jitugi
return Lesson.where(type_number: 0).wher... | true |
331c80c9e20f693c0858a192053e2a55593aed6a | Ruby | ashwinkshenoy/vimeo_upload | /lib/vimeo_upload.rb | UTF-8 | 3,361 | 2.671875 | 3 | [
"MIT"
] | permissive | require "vimeo_upload/version"
require "httparty"
module VimeoUpload
# Upload function
def self.upload(filepath, filename, api_key)
# Upload a video to vimeo
# I prefer putting api_key as an environment variable. Use figaro gem if needed
# Call function in the following format
# VimeoUpload.uploa... | true |
d9a8073fb8ce120089bf790dbd0e1d9b1b106d06 | Ruby | ably/ably-ruby | /lib/ably/logger.rb | UTF-8 | 3,806 | 2.921875 | 3 | [
"Apache-2.0"
] | permissive | module Ably
# Logger unifies logging for #debug, #info, #warn, #error, and #fatal messages.
# A new Ably client uses this Logger and sets the appropriate log level.
# A custom Logger can be configured when instantiating the client, refer to the {Ably::Rest::Client} and {Ably::Realtime::Client} documentation
#
... | true |
c494246eaae1c773e6ce651c4e0aabddf70be201 | Ruby | covard/ruby | /log_message.rb | UTF-8 | 214 | 2.890625 | 3 | [] | no_license | require 'logger'
class LogMessage
def self.log(msg, file_path, duration)
begin
logger = Logger.new(file_path, duration)
logger.info{msg}
ensure
logger.close
end
end
end
| true |
83dcf7ae5289fc2178848eb11051ba6ebf59b5d0 | Ruby | thai321/Notes | /Interview/HR/Implementation/Kangaroo.rb | UTF-8 | 1,286 | 4.46875 | 4 | [] | no_license | # There are two kangaroos on a number line ready to jump in the positive direction (i.e, toward positive infinity). The first kangaroo starts at location x1 and moves at a rate of v1 meters per jump. The second kangaroo starts at location x2 and moves at a rate of v2 meters per jump. Given the starting locations and mo... | true |
d8014c6693af515747396dfa6fe180f5893867f6 | Ruby | thiennguyenenv/elunch | /app/models/shift.rb | UTF-8 | 389 | 2.5625 | 3 | [
"MIT"
] | permissive | class Shift < ActiveRecord::Base
validates :name, :start_time, :end_time, presence: true
validate :start_time_can_not_be_greater_than_end_time
has_many :tables
private
def start_time_can_not_be_greater_than_end_time
return if start_time.nil? || end_time.nil?
if start_time > end_time
errors.add(... | true |
897bb6c8713c56e531d6671249ff098324b2d4d7 | Ruby | phokz/ruby-agi | /lib/ruby-agi/return_status/set_extension.rb | UTF-8 | 551 | 2.625 | 3 | [] | no_license | class ReturnStatus
end
#
# Usage: SET EXTENSION <new extension>
# Changes the extension for continuation upon exiting the application.
#
class SetExtension < ReturnStatus
def to_s
result
end
def == (obj)
obj.to_s == result
end
private
def result
if @result.nil?
rgx = Regexp.new... | true |
346852854e7d21832d5bd613720f47d0928dea7d | Ruby | Abhisheknanda1344463/hello-world | /ex12.rb | UTF-8 | 373 | 3.53125 | 4 | [] | no_license | print "Give me a number"
number = gets.chomp.to_f
bigger = number * 100
puts "A bigger number is #{bigger}"
print "Give me another number"
number = gets.chomp.to_f
smaller = number/100
puts "A samller number is #{smaller}"
#studdy drills
puts "enter a amount"
amount = gets.chomp.to_f
ten_percnt = (amount * 0.1).rou... | true |
5c8512a024fb3dc9f8550c230b64cd5c20788026 | Ruby | mohnstrudel/robocop | /spec/robo_spec.rb | UTF-8 | 1,796 | 2.953125 | 3 | [] | no_license | require_relative '../robocop'
RSpec.describe Robot, '#chess' do
let(:robot) { Robot.new }
context 'initial placing' do
it "has valid values" do
robot.place(0,0,'NORTH')
expect(robot.x).to eq 0
expect(robot.y).to eq 0
expect(robot.f).to eq 'NORTH'
end
it 'has invalid values' do
robot.place(-1... | true |
97903965226f7e82acc118c111811ddb4dced4bb | Ruby | mongodb/mongoid | /lib/mongoid/contextual/atomic.rb | UTF-8 | 8,595 | 2.78125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# rubocop:todo all
module Mongoid
module Contextual
# Mixin module included in Mongoid::Criteria which provides a
# direct method interface to MongoDB's Update Operators ($set,
# $pull, $inc, etc.) These operators can be applied to update
# all documents in the database... | true |
8253bda9bceccd399435aa61377dec62f60c553c | Ruby | mgrebe-cu/calendar_app | /app/models/event.rb | UTF-8 | 1,887 | 2.953125 | 3 | [] | no_license | class StartTimeValidator < ActiveModel::Validator
def validate(record)
if (!record.start_time.nil? and !record.end_time.nil?)
if !record.all_day and record.start_time > record.end_time
record.errors[:start_time] << "Start time can't be after end time"
end
end
... | true |
6a00d5e6498087ba9b4f27ecb5d8c4d56f2a4e13 | Ruby | dlbeswick/dlbeswick-examples | /ruby/std/tempfile_dlb.rb | UTF-8 | 6,921 | 2.703125 | 3 | [] | no_license | #
# tempfile - manipulates temporary files
#
# $Id: tempfile.rb 11708 2007-02-12 23:01:19Z shyouhei $
# dbeswick: added 'binary' option
#
require 'std/abstract'
require 'delegate'
require 'tmpdir'
require 'std/path'
module DLB
# A class for managing temporary files. This library is written to be
# thread safe.
... | true |
48c6c7743efddc44e1109457fbe678cb23455672 | Ruby | gs2589/exercises | /CtCI_16_5.rb | UTF-8 | 205 | 3.078125 | 3 | [] | no_license | def factorial_zeros(n)
zeros=0
#add a zero for every multiple of 5
powers_of_five=Math.log10(n)/Math.log10(5)
for i in 1..powers_of_five
zeros+= n/(5**i)
end
return zeros
end
| true |
2e2519339fa096200d4064e69b3522470a4a91dc | Ruby | KalMegati/learn-co-sandbox | /Adventurer.rb | UTF-8 | 444 | 2.96875 | 3 | [] | no_license | require_relative 'ABCs.rb'
class Adventurer
attr_accessor :name, :ancestry, :background, :class, :description
@@all = []
def initialize(name)
@name = name
@@all << self
end
# def self.lookup(option)
# until
# if ABCs.ancestries.keys.include?(option)
# elsif
#... | true |
86ef1b3bcb29d12f515da7557666f2c1f44b7140 | Ruby | nicolasblanco/textmaster_checkout | /lib/rules/buy_one_get_one_fruit_tea.rb | UTF-8 | 459 | 2.953125 | 3 | [] | no_license | require 'rules/base'
module Rules
class BuyOneGetOneFruitTea < Base
def number_of_fruit_tea_items
@number_of_fruit_tea_items ||= @items.map(&:product_code).count('FR1')
end
def apply?
number_of_fruit_tea_items > 1
end
def total
product_discount = @items.find { |i| i.product_co... | true |
1c3179dc7daa42342e89631302a6410e29e29568 | Ruby | andhapp/rb_tnetstring | /lib/rb_tnetstring/encoder/dictionary_encoder.rb | UTF-8 | 335 | 2.671875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module RbTNetstring
class DictionaryEncoder < Encoder
def initialize(obj)
@obj = obj
end
def encode
contents = @obj.map do |key, value|
assert key.kind_of?(String), KEY_MUST_BE_STRING
"#{super(key)}#{super(value)}"
end.join
"#{contents.length}:#{contents}}"
... | true |
1499eeed0edd8a8574d52ded2d49e7eb6cde45ed | Ruby | awlunsfo/tvdb_client | /tasks/version_bump.rake | UTF-8 | 2,859 | 2.96875 | 3 | [
"MIT"
] | permissive | namespace :version do
desc "Bumps up the version number by the patch level"
task :patch do
bump_version( "patch" )
end
desc "Bumps up the version number by a minor release level"
task :minor do
bump_version( "minor" )
end
desc "Bumps up the version number by a major release level"
task :major... | true |
00a0ba53f84bdfaf6c5f158b268c0484f8783e12 | Ruby | medert/street-show | /street_show.rb | UTF-8 | 969 | 3.34375 | 3 | [] | no_license | knife_juggling = 2.1 + 0.77 + 5.00 + 1.00 + 3.00
torch_juggling = 6.00 + 3.50 + 7.00
hand_balancing = 2.00 + 1.00
human_blockhead = 0.75 + 0.43
puts "Knife Juggling:"
puts knife_juggling.round(2)
puts "Torch Juggling:"
puts torch_juggling.round(2)
puts "Hand Balancing:"
puts hand_balancing.round(2)
puts "Human Bloc... | true |
fa98d1b12505ede120b55907b52d3f6675d9db8a | Ruby | jimm/patchmaster | /test/connection_test.rb | UTF-8 | 3,853 | 2.6875 | 3 | [] | no_license | require 'test_helper'
class ConnectionTest < Test::Unit::TestCase
def setup
@in_instrument = PM::InputInstrument.new(:tin, 'test_in', 0, false)
@out_instrument = PM::OutputInstrument.new(:tout, 'test_out', 0, false)
@options = {:pc_prog => 3, :zone => (40..60), :xpose => 12}
@conn = PM::Connection.n... | true |
fb26ecee884f3b7440b93cae164bf58f17954fa9 | Ruby | Keisuke-Awa/algorithm | /atcoder/abc148/a.rb | UTF-8 | 104 | 3.234375 | 3 | [] | no_license | a = gets.to_i
b = gets.to_i
array = [1, 2, 3]
array.delete_if { |n| [a,b].include?(n) }
puts array.first | true |
57c393ebfc0c12bf0c6e07d15015222a07676908 | Ruby | raahii/fashion-shop-map | /db/branch_scrapers/SHOP_LIST/shop_list_from_zozotown.rb | UTF-8 | 2,311 | 3.046875 | 3 | [] | no_license | require 'open-uri'
require 'nokogiri'
require 'csv'
class ShopListScraper
def initialize(base_url, target_url)
@base_url = base_url
@target_url = target_url
@tmp_save_file = __FILE__.split('.')[0] + ".tmp.saved"
if File.exist?(@tmp_save_file)
File.open(@tmp_save_file, "r") do |file|
@sh... | true |
d98212df558b202b6ea6a6d3c60277963a6a1842 | Ruby | moguonyanko/moglabo | /lang/ruby/exam.rb | UTF-8 | 3,209 | 3.203125 | 3 | [] | no_license | #!/usr/bin/ruby1.9.1
# -*- encoding: utf-8 -*-
#
# 20120521 moguonyanko
# Exam training source code
# Reference:
# Metaprograming Ruby
# Ruby公式資格教科書
#
require 'thread'
module MetaPrograming
class Greeting
def initialize(text)
@text = text
end
def welcome
@text
end
end
module M
Y = "CONST"
class C
... | true |
baccace43f7ddd9cca1065c78d11ca00d0ae39b7 | Ruby | gr1d99-ke/AlgorithmsAndDataStructures | /leetcode/add_two_numbers.rb | UTF-8 | 540 | 3.515625 | 4 | [] | no_license | # Definition for singly-linked list.
class ListNode
attr_accessor :val, :next
def initialize(val)
@val = val
@next = nil
end
end
l1_2 = ListNode.new(3)
l1_1 = ListNode.new(4)
l1_0 = ListNode.new(2)
l1_0.next = l1_1
l1_1.next = l1_2
l2_2 = ListNode.new(4)
l2_1 = ListNode.new... | true |
207e085dbde4ba4365272fa3967ae410b06b4093 | Ruby | Rmole57/intro-to-programming-ruby-exercises | /more_stuff/ex1.rb | UTF-8 | 353 | 3.765625 | 4 | [] | no_license | # Exercise 1 from "More Stuff" chapter of the book.
# This program checks if the regex "lab" exists in a string (case-insensitive).
def has_lab?(string)
if /lab/i =~ string
puts string
else
puts "Not a match!"
end
end
has_lab?("laboratory")
has_lab?("experiment")
has_lab?("Pans Labyrinth")
has_lab?("el... | true |
858e3b01089ce759116fbfa5940b39a2c4ae2d84 | Ruby | livmaina/ruby_oct_2018 | /erin_averill/exercises/animals/dog.rb | UTF-8 | 264 | 3.328125 | 3 | [] | no_license | require_relative 'mammal'
class Dog < Mammal
# def display_health
# puts @health
# end
def pet
@health += 5
self
end
def walk
@health -= 1
self
end
def run
@health -= 10
self
end
end
dog = Dog.new.walk.walk.walk.run.run.pet.display_health | true |
aaa4cc6569b8e2b692414b0d541451f2fc682d39 | Ruby | jdrzj/prime_numbers | /lib/generate_primes.rb | UTF-8 | 363 | 3.53125 | 4 | [] | no_license | class GeneratePrimes
def self.get_primes(count)
primes = []
n = 2
loop do
primes << n if prime?(n)
break if primes.count == count
n += 1
end
primes
end
def self.prime?(number)
return false if number <= 1
2.upto(Math.sqrt(number).to_i) do |x|
return false if (nu... | true |
d927b1cf2823553af0ab95aa6ae42f019f1600af | Ruby | MarEdv/advent_of_code | /2016/day12/bin/day12 | UTF-8 | 443 | 2.671875 | 3 | [] | no_license | #!/usr/bin/env ruby
$LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
require "day12"
puts "I was called with #{ARGV.size} arguments: #{ARGV.join(', ')}."
lines = File.readlines(ARGV[0])
registers = ({
'a' => 0,
'b' => 0,
'c' => 0,
'd' => 0
})
puts "Step 1"
puts process(lines, registers... | true |
4e55b4b5c73ac6c8e9d088d8039edc712ce95f89 | Ruby | Schwad/baby_squeel | /lib/baby_squeel/table.rb | UTF-8 | 1,837 | 2.75 | 3 | [
"MIT"
] | permissive | require 'baby_squeel/join_dependency'
module BabySqueel
class Table
attr_accessor :_on, :_join, :_table
def initialize(arel_table)
@_table = arel_table
@_join = Arel::Nodes::InnerJoin
end
# See Arel::Table#[]
def [](key)
Nodes::Attribute.new(self, key)
end
# Alias a t... | true |
38d9ba5c86192335975bfb78b8e79688f950c800 | Ruby | TK2Day/labs | /questQuest.rb | UTF-8 | 4,214 | 3.5625 | 4 | [] | no_license | require 'pry'
puts "Welcome to Questquest! I wonder what kind of hero you will be?"
module Killable
def alive?
self.health > 0
end
def dead?
not self.alive?
end
end
class Adventurer
attr_reader :name
attr_accessor :health, :level
include Killable
def initialize(name, level=1)
@healt... | true |
ece613ef94038c4fc77cad5b5f81014e35dfda01 | Ruby | alehandermartins/leftbehind | /repos/actions_in_memory.rb | UTF-8 | 1,073 | 2.546875 | 3 | [] | no_license | require_relative '../lib/util'
module Repos
class ActionsInMemory
class << self
def for db
end
def actions_collection
@@collection ||= []
end
def clear
actions_collection.clear
end
def save data
string_indexed_data = data.map { |d|
Ha... | true |
f3820f366d24305cbd741cd0293fcce8ea9c07ed | Ruby | Warshavski/elplano-api | /app/finders/labels_finder.rb | UTF-8 | 1,115 | 2.515625 | 3 | [] | no_license | # frozen_string_literal: true
# LabelsFinder
#
# Used to search, filter, and sort the collection of student's labels
# (created by student)
#
# Arguments:
#
# params: optional search, filter and sort parameters
#
class LabelsFinder < ApplicationFinder
alias owner context
# @param context [Group] -
# (... | true |
2512394f92ffbf2b6495d68455dbef9e8e1748fc | Ruby | dcshiller/WhereDoTheyPublish | /app/services/author_matcher.rb | UTF-8 | 2,227 | 2.734375 | 3 | [] | no_license | class AuthorMatcher
attr_reader :author
def initialize(author)
@author = author
end
def match?
match_score > 1
end
def match_score(other_author)
info_value(other_author).to_f/20
end
# private
def info_value(other_author)
value = 0
value += name_info_value
value += publicat... | true |
937071e05a1faf1ba5fd8473f203680250422e87 | Ruby | tranc99/capitalize-gem | /spec/capitalize_spec.rb | UTF-8 | 537 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Capitalize do
subject { Capitalize.new }
describe '#process' do
let(:input) { 'Ten' }
let(:output) { subject.process(input) }
it 'handles exceptions well' do
expect(output).to eq 'Sorry, the Boss is sleeping.'
end
end
descri... | true |
3771f9b97b55995e9dd1e12776a821fa530f58ac | Ruby | xmarshallsito/metodos-numericos | /integracion.rb | UTF-8 | 1,819 | 3.703125 | 4 | [
"MIT"
] | permissive | # Regla de los Trapecios: utilizada para aproximar la integral I = Intregal(a..b){f(x)dx}.
# Entrada: los extremos a y b de la integral, un entero positivo n y f(x).
# Salida: una aproximacion AI de I.
def trapecios(a, b, n, &f)
h = (b - a).fdiv(n)
ai0 = f.call(a) + f.call(b)
ai = 0
(1..n - 1).each do |k|
... | true |
e2cf1f7bdc0d2134f59690b283b706243a48d209 | Ruby | emmasmithdev/zen-tracker-project | /models/city.rb | UTF-8 | 2,651 | 3.234375 | 3 | [] | no_license | require_relative('../db/sql_runner.rb')
require_relative('country.rb')
require_relative('yoga.rb')
class City
attr_reader :id, :name, :country_id, :map_url, :distance, :image_url
attr_accessor :visited
def initialize(options)
@id = options["id"] if options["id"]
@name = options["name"]
@visited = o... | true |
5585c40df33e27173322eec1eb8cb5202e173236 | Ruby | sahidursuman/crop_tracker | /lib/crop_tracker/input_parser.rb | UTF-8 | 512 | 3.5 | 4 | [
"MIT"
] | permissive | class InputParser
attr_reader :line, :line_data_array
def initialize(line)
@line = line
@line_data_array = line.split(" ")
end
def entered_name
# the name will be always the second item
line_data_array[2].downcase
end
def command_type
# the command_type will be always the first two it... | true |
e376efeefd5e05aa3595fe62f5d38d3d8c4a479f | Ruby | yomaytk/Yomazon | /test/models/user_test.rb | UTF-8 | 1,342 | 2.546875 | 3 | [] | no_license | require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@user = User.new(name: "Example User", email: "user@example.com",
password: "hogehoge", password: "hogehoge")
end
test "right user should be validate" do
assert @user.valid?
end
test "user have wrong name should not be val... | true |
f155ac4d607286fe4ad40c9b9ccbc65e7b719a11 | Ruby | adrianoasg/curso_ruby | /orientacao_objetos/exercicio1.rb | UTF-8 | 480 | 3.65625 | 4 | [] | no_license | class Cachorro
attr_accessor :nome
attr_reader :raca
def initialize(nome, raca)
@nome = nome
@raca = raca
end
def latir(texto = "au au!")
texto
end
end
cachorro1 = Cachorro.new('Snow', 'Shitzu')
cachorro2 = Cachorro.new('Kimera', 'Golden')
puts cachorro1.nome
puts cac... | true |
a06ddff78d8b23ad06f808d367804a5a905ce531 | Ruby | jtulick/exercise | /exercise.rb | UTF-8 | 1,712 | 3.0625 | 3 | [] | no_license | # File: exercise.rb
require_relative 'files'
require_relative 'formatter'
require_relative 'comparison'
require 'trollop'
opts = Trollop.options do
version 'Stelligent Exercise 0.1.0'
banner <<-EOS
This program will return a list of files in a given directory where 2 search
terms are not more than N words apart.
... | true |
aa863b4ab9f399038f28bd9be3a8f9349c27fb92 | Ruby | timcastillogill/oyster_challenge_2 | /playground_aka_feature_test.rb | UTF-8 | 556 | 2.703125 | 3 | [] | no_license | # frozen_string_literal: true
require './lib/oystercard.rb'
p my_oyster_card = Oystercard.new
p 'this is balance'
p my_oyster_card.balance
p my_oyster_card.top_up(20)
# p my_oyster_card.top_up(100)
p my_oyster_card.touch_out
p my_oyster_card.in_journey?
# p my_oyster_card.journey
p my_oyster_card.journeys
{entry_st... | true |
61ae06a77a3e4ab6070bd8069e649ed493bf2e0e | Ruby | brettb723/app | /vendor/bundle/ruby/2.0.0/gems/dehumanize-1.0.0/lib/dehumanize.rb | UTF-8 | 469 | 2.625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'active_support/inflector/inflections'
require 'active_support/inflector/transliterate'
require 'active_support/inflector/methods'
require 'active_support/inflections'
require 'active_support/core_ext/string/inflections'
module ActiveSupport::Inflector
def dehumanize s
s.titleize.gsub(" ", "").underscor... | true |
7f6ac5b7228866fe89ac651296cebd8ba258d9d9 | Ruby | zdennis/yap-shell-addon-tab-completion | /lib/yap-shell-addon-tab-completion.rb | UTF-8 | 6,167 | 2.625 | 3 | [
"MIT"
] | permissive | require 'yap/addon'
require 'yap-shell-addon-tab-completion/basic_completion'
require 'yap-shell-addon-tab-completion/completion_result'
require 'yap-shell-addon-tab-completion/custom_completion'
require 'yap-shell-addon-tab-completion/dsl_methods'
require 'yap-shell-addon-tab-completion/version'
module YapShellAddonT... | true |
5f0434931d1baaf586eb55edb3798834832f391f | Ruby | hy921598130/sobooks | /main.rb | UTF-8 | 2,378 | 2.78125 | 3 | [] | no_license | require 'selenium/webdriver'
include Selenium
D = WebDriver.for :safari
BOOKS = {
xiaoshuowenxue: 42,
lishizhuanji: 22,
renwensheke: 17,
lizhichenggong: 5,
# jingjiguanli: 21,
xuexiaojiaoyu: 3,
shenghoushishang: 2,
yingwenyuanban... | true |
6ecae35e805c29b0880f77b537149c7ae56e372f | Ruby | curzonj/starmade-mgr | /launcher.rb | UTF-8 | 996 | 2.59375 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'aws-sdk'
require 'socket'
server = TCPServer.new 4242
puts 'listening'
loop do
client = server.accept # Wait for a client to connect
puts 'received connection'
client.close
ec2 = Aws::EC2::Client.new(region: 'us-east-1')
game_inst = ec2.describe_instances(filters: [
{
... | true |
98dd70536abcb9ae87646496d8ba9a84b9b41a85 | Ruby | anikachristopher/learn-co-sandbox | /greeting.rb | UTF-8 | 48 | 3.140625 | 3 | [] | no_license | def greeting (name)
puts "Hello, #{name}!"
end | true |
20cca09bc80a2723e060cfdbda821fc289194889 | Ruby | jeniflorezl/Tuenlacetv | /lib/nombre_meses.rb | UTF-8 | 581 | 3.03125 | 3 | [] | no_license | module NombreMeses
def mes(nombre)
case nombre
when "January"
nombre = "ENERO"
when "February"
nombre = "FEBRERO"
when "March"
nombre = "MARZO"
when "April"
nombre = "ABRIL"
when "May"
nombre = "MAYO"
when "June"
nombre = "JUNIO"
when "July"
no... | true |
92fd2113f7e9570ad249eb54bb5a546591c273aa | Ruby | linuxsable/EightbitGo | /app.rb | UTF-8 | 3,352 | 3.21875 | 3 | [] | no_license | require 'treetop'
require 'kantan-sgf'
require 'bloops'
require 'feepogram'
require './lib/keys'
class EightbitGo
# Available octaves in bloops
OCTAVES = [1, 2, 3, 4, 5, 6, 7, 8]
BOARD_SIZE = { X: 19, Y: 19 }
def initialize(filename)
@filename = filename
@song = nil
parse_sgf
puts get_ga... | true |
3e2971607fa495f822401f46a95f771e10985eaf | Ruby | Catsquotl/gcal | /lib/shift.rb | UTF-8 | 914 | 3.078125 | 3 | [] | no_license | require 'csv'
require 'google_calendar'
class Shift
attr_reader :date, :shift_code, :event
def initialize(date,shift)
@shift_code = shift.upcase
@date = date
@exception = DateTime::strptime("#{date}",'%d-%m')
create_shift
end
def set_event
@event = Google::Event.new(title: @shift_code,
... | true |
e6769dec91721e4c1534b3a93a8260afece62060 | Ruby | LaughingNinja/ci | /w_example.rb | UTF-8 | 751 | 3.1875 | 3 | [] | no_license | # Open File
File.open('w_data.dat', 'r') do |f1|
# Set winning values to arbitrary amounts
wday = 0
wdiff = 9999
# Iterate through lines
while line = f1.gets
#puts line
# Parse relevant fields
day = line[1..3]
# check for valid entry
if day.to_i > 0
wmax = line[6..7]
wmin = ... | true |
7f1263d057e35f856e72f7d1d477456a89a4d975 | Ruby | debonairism/health_check | /health_check_url.rb | UTF-8 | 1,430 | 2.75 | 3 | [] | no_license | class HealthCheckUrl
require 'json'
attr_accessor :views, :region, :urls, :passed
def initialize(options = {})
options[:search] ||= {}
@views = options[:search][:view_options]
@region = options[:search][:region]
@passed = options[:search][:passed]
load_health_... | true |
791108c5ced97597baf949170fb04e39c15e807c | Ruby | wcpr/riakrest | /examples/jiak_client.data.rb | UTF-8 | 2,738 | 3.1875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require File.dirname(__FILE__) + '/example_helper.rb'
require 'date'
# JiakData class with a couple of attributes, one with conversion
class DateData
include JiakData
attr_accessor :name, :date
attr_converter :date => { :read => lambda{|value| Date.parse(value)} }
end
client = JiakClient.new(SERVER_URI)
bucket... | true |
5708b644b0bc6fefa7c9c22d8e89ebf2cb972763 | Ruby | tdeo/advent_of_code | /2017/lib/18_duet.rb | UTF-8 | 2,310 | 3.0625 | 3 | [] | no_license | # frozen_string_literal: true
class Duet
def initialize(input)
@instructions = input.split("\n").map(&:strip)
@registers = Hash.new { |h, k| h[k] = 0 }
@last_sound = 0
@cur_ins = 0
end
def value_for(a)
/^-?\d+$/.match?(a) ? a.to_i : @registers[a]
end
def apply!
tokens = @instruction... | true |
1d8a0f2b7ed5de0f16742c000c3b4dc0408695e3 | Ruby | teelawlz/ac-test | /lib/my_car.rb | UTF-8 | 1,171 | 2.75 | 3 | [] | no_license | class MyCar
MAKE = 'mazda'
MODEL = '3'
YEAR = '2014'
# In interest of saving precious calls per day, taking what I need into a
# separate class file, basically functioning as an info pillar. Will verify
# response body's contents against this array of styles my car comes in.
def self.styles
[
... | true |
58b2f0082dca83756c1eb1250e2ca2a50f40fc11 | Ruby | daniero/braingasm | /lib/braingasm/tokenizer.rb | UTF-8 | 1,957 | 3.0625 | 3 | [
"MIT"
] | permissive | require 'strscan'
module Braingasm
class Tokenizer < Enumerator
attr_accessor :input
attr_reader :line_numer, :column_number
def initialize(input)
@line_numer = 1
@column_number = 0
scanner = StringScanner.new(input)
super() do |y|
loop do
line_numer, column_n... | true |
a5bf72960450ce90edbc7d3c176e55b82ef8e823 | Ruby | project-kotinos/reinteractive___wallaby | /lib/parsers/wallaby/parser.rb | UTF-8 | 1,140 | 2.6875 | 3 | [
"MIT"
] | permissive | module Wallaby
# a parser to handle colon query
class Parser < Parslet::Parser
root(:statement)
rule(:statement) { expression >> (space >> expression).repeat }
rule(:expression) { colon_query | general_keyword }
rule(:colon_query) do
name.as(:left) >> operator.as(:op) >> keywords.as(:right)
... | true |
f8cf41f60451a9b30377545b6ddb6a0ad0451f84 | Ruby | LeslieWilson/marlboro_rails | /JimExam/test.rb | UTF-8 | 775 | 5.09375 | 5 | [] | no_license | # make an object that intializes with 3 variables - x y and z - thee variables will be integers when intialize the object with Thing.new
# make a method that adds all 3 variables together
# make a method that multiplies all 3 variables together
class Thing
def initialize(x, y, z)
@x = x
@y = y
... | true |
4dce1c626251ccb716837412d17da8cc54feab3c | Ruby | georgebancila/learn_ruby | /08_book_titles/book.rb | UTF-8 | 787 | 3.15625 | 3 | [] | no_license | def titleize(text)
small_words = %w[an a aboard about above across after against along amid among and anti around as at before behind below beneath beside besides between beyond but by concerning considering despite down during except excepting excluding following for from in inside into like minus near of off on ont... | true |
2664db7e785202c51b09f4b7279536a7fcab9916 | Ruby | wiemthebest/Ruby-basics_2 | /exo_14.rb | UTF-8 | 239 | 2.953125 | 3 | [] | no_license | emailList = Array.new
for n in 01..50
if n <10
email = "jean.dupont.0#{n}@email.fr"
else
email = "jean.dupont.#{n}@email.fr"
end
emailList.push(email)
end
for i in 1..emailList.length
if i.even?
puts emailList[i-1]
end
end
| true |
8446e6fd91c6d896a8459dfb483e7f0641dc88e7 | Ruby | srogier/7-languages-in-7-weeks | /ruby/day2/find.rb | UTF-8 | 1,220 | 3.9375 | 4 | [] | no_license | #Find out how to access files with and without code blocks. What is the benefit of the code block?
File.open('foo', 'w') { |file| file.puts 'write line with code block'}
file = File.new('foo', 'w')
file.puts 'write line without code block'
file.close
puts '---- read without code block ----'
file = File.new('bar', 'r'... | true |
f6de30312118eef438585af4ec36eebc3f844ba5 | Ruby | SpencerB3/launch_school | /RB120_object_oriented_programming/lesson_4/03_easy/ex_07.rb | UTF-8 | 455 | 3.578125 | 4 | [] | no_license | # What is used in this class but doesn't add any value?
class Light
attr_accessor :brightness, :color
def initialize(brightness, color)
@brightness = brightness
@color = color
end
def self.information
return "I want to turn on the light with a brightness level of super high and a color of green" ... | true |
78c6ce52b3f5d854d7398affd36915bcdaa275a3 | Ruby | NUBIC/ncs_navigator_configuration | /lib/ncs_navigator/configuration/sampling_units.rb | UTF-8 | 1,913 | 2.859375 | 3 | [] | no_license | require 'ncs_navigator/configuration'
class NcsNavigator::Configuration
class PrimarySamplingUnit < Struct.new(:id)
##
# @return [Array<SamplingUnitArea>] the areas in this PSU.
def sampling_unit_areas
@sampling_unit_areas ||= []
end
##
# @return [Array<SecondarySamplingUnit>] the SSUs... | true |
a5a54cba9732de0260b347f57e125c4b50e00356 | Ruby | pinpox/dailyprogrammer | /255_easy/solution.rb | UTF-8 | 471 | 3.5 | 4 | [] | no_license | # encoding: utf-8
#!/usr/bin/env ruby
def setup(num_switches)
switches = []
num_switches.to_i.times { switches << false}
return switches
end
def toggle_string_range(switches, range)
a,b = range.split(' ')
(a.to_i..b.to_i).each do |n|
switches[n] = !switches[n]
end
return switches
end
input = $stdin.read.s... | true |
b1fe414ea62d20db7a1323fe27736f2fbd6b5519 | Ruby | callunity/ruby_fundamentals2 | /exercise5.rb | UTF-8 | 230 | 4.125 | 4 | [] | no_license | puts "What temperature (Fahrenheit) would you like to convert?"
temp_F = gets.chomp
def F_to_C(temp_F)
(temp_F.to_i - 32) * 5/9
end
temp_c = F_to_C(temp_F)
puts "#{temp_F} degrees Fahrenheit is #{temp_c.to_s} degrees Celsius." | true |
fc2a08f445ecfec1974df5e5b9c51397de88e2ed | Ruby | RianaFerreira/wdi_sydney_2_hw | /w03/d01/nick/Memetube/main.rb | UTF-8 | 1,951 | 3.171875 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/reloader'
require 'pg'
require 'pry'
get '/' do
@movies = query_db('SELECT * FROM movies')
erb :index
end
get '/movies/new' do
# We're just showing a form here so no need to talk to the database.
erb :movienew
end
post '/movies/create' do
# Welcome to SQL quoting hell.
... | true |
b9f3595677e0368c24d37b1ea514344e9e57b5df | Ruby | mattsroufe/scrabble | /lib/scrabble/letter.rb | UTF-8 | 1,649 | 3.078125 | 3 | [] | no_license | class Letter
def self.letters
{ "" => {:score => 0, :count => 2},
"A" => {:score => 1, :count => 9},
"B" => {:score => 3, :count => 2},
"C" => {:score => 3, :count => 2},
"D" => {:score => 2, :count => 4},
"E" => {:score => 1, :count => 12},
"F" => {:score => 4, :count... | true |
3bab5cc4c12ccbaf677d61a40198cf117d99d51e | Ruby | bendee48/chess | /lib/save.rb | UTF-8 | 591 | 2.84375 | 3 | [] | no_license | # frozen_string_literal: true
require 'yaml'
require_relative 'game'
# Module to save and load game.
module SaveGame
def self.save(game)
Dir.mkdir('save_files') unless Dir.exist?('save_files')
game_obj = YAML.dump(game)
File.open('./save_files/game_save.yml', 'w') { |f| f.write(game_obj) }
end
def ... | true |
4b92c7ac93587f4384844120ad016d700eb65501 | Ruby | tbates1996/Ruby_stack_queue | /LinkedList.rb | UTF-8 | 3,159 | 3.5625 | 4 | [] | no_license | require_relative "Node.rb"
class LinkedList
#Shows the beginins and end node of the linked list
attr_reader :head,:tail
#Structure to define a slot data type
#Initialize an empty Linked list
def initialize size = nil, node = nil
@count = 0
@size = size
if node == nil
@head = nil
@tail = nil
else
... | true |
35b09b9ed43fcfb218a6e9faca8ea5041d5db553 | Ruby | pjotrp/bioruby-grid | /lib/bio/grid.rb | UTF-8 | 1,313 | 2.609375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Bio
class Grid
attr_accessor :input,:number
def initialize(input,number)
@input = input
@number = number
end
def self.run(options)
grid = self.new options[:input], options[:number]
groups = grid.prepare_input_groups
inputs = groups.keys.sort
groups[inputs.shift].each_with_index do... | true |
979b7edcc094baf8452d075b6c91698d3afbe3a5 | Ruby | Jmean/codewars | /ruby/sum_of_two_lower_integers.rb | UTF-8 | 90 | 3.046875 | 3 | [] | no_license | def sum_two_smallest_numbers(numbers)
numbers.sort!
return numbers[0] + numbers[1]
end | true |
602c8e0369928a4ee8f24dbc472d34dc40bcde1e | Ruby | kreopelle/activerecord-validations-lab-v-000 | /app/models/post.rb | UTF-8 | 636 | 2.796875 | 3 | [] | no_license | class TitleValidator < ActiveModel::Validator
def validate(record)
if record.title != nil
clickbait = ["Won't Believe", "Secret", "Top #{/\d/}", "Guess"]
unless clickbait.any? {|bait| record.title.include?(bait) }
record.errors[:title] << 'Title must be present and have clickbait!'
end
... | true |
503796c38f60093b51074f574fb0fb3af59c9994 | Ruby | hamstersky/the_odin_project | /mastermind/lib/colors.rb | UTF-8 | 503 | 3.65625 | 4 | [] | no_license | class String
def red
"\e[31m#{self}\e[0m"
end
def green
"\e[32m#{self}\e[0m"
end
def yellow
"\e[33m#{self}\e[0m"
end
def blue
"\e[34m#{self}\e[0m"
end
def purple
"\e[35m#{self}\e[0m"
end
end
class Array
def colorize
self.map do |element|
case element
when "... | true |
f81982d4793abc0714ab6254592a23d74eee6019 | Ruby | jimmoffitt/snow-workers | /common/requester.rb | UTF-8 | 4,068 | 3 | 3 | [] | no_license | # Knows how to make HTTP requests.
# A simple, common RESTful HTTP class put together for Twitter RESTful endpoints.
# Does authentication via header, so supports BASIC and BEARER TOKEN authentication. This class knows to use Basic Auth
# with enterprise endpoints, and Bearer Token authentication with premium endpoint... | true |
ca9bb2363986ea313f6a83b0f053c99cf8916fe9 | Ruby | kwx4github/facebook-hackercup-problem-sets | /2015/qualifying_round/2.New_Year's_Resolution/solutions/sources/5531.Trevor | UTF-8 | 1,608 | 3.703125 | 4 | [] | no_license | #!/usr/bin/env ruby
class Food
attr_accessor :protein, :carbohydrates, :fat
def initialize(protein, carbohydrates, fat)
@protein = protein
@carbohydrates = carbohydrates
@fat = fat
end
def self.sum_nutrients(foods)
totals = {
protein: 0,
carbohydrates: 0,
fat: 0
}
f... | true |
dbb83df0d12f78772c29f5384110d67f2b409f83 | Ruby | YasHartung/oo-cash-register-nyc-web-career-042219 | /lib/cash_register.rb | UTF-8 | 675 | 3.609375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class CashRegister
attr_accessor :total
attr_reader :discount, :items
def initialize (discount =0)
@total = 0
@discount = discount
@items = []
end
def add_item (title, price, quantity =1)
@total = @total + quantity*price
count = 0
while count < quantity
@items << title
... | true |
974c6d26b8f1756a07d61e8467f92aa48131111c | Ruby | liantics/wiki_bios_scraper | /app/controllers/biographies_controller.rb | UTF-8 | 2,161 | 2.703125 | 3 | [] | no_license | class BiographiesController < ApplicationController
include StringManipulator
include BiographyStatisticVariables
require 'nokogiri'
require 'open-uri'
def index
@number_of_biography_links_to_show = LINKS_TO_SHOW
female_biographies = Biography.where(rough_gender: "female")
@female_biography_link... | true |
53388713d7a850d8da546583287de9353335fc10 | Ruby | JacksonReynolds/oo-banking-onl01-seng-ft-070620 | /lib/bank_account.rb | UTF-8 | 481 | 3.671875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'transfer.rb'
class BankAccount
attr_accessor :status, :balance
attr_reader :name
def initialize(name)
@name = name
@balance = 1000
@status = 'open'
end #initialize
def deposit(amt)
@balance += amt
end #deposit
def close_account
@status = 'closed'
end #close_account
d... | true |
430d960ff54c644407df90dd7db1b402c9d51367 | Ruby | webfont-ge/webify_ruby | /lib/webify_ruby/css.rb | UTF-8 | 4,710 | 3 | 3 | [
"MIT"
] | permissive | require 'erb'
require 'fileutils'
require 'pathname'
module WebifyRuby
# Internal: Template which is according to what a CSS Styles
# will be generated. This might change in future versions,
# so that you will be able to pass in your own template definitions.
TEMPLATE = <<-CSS.gsub /^\s*/, ''
@font-face {
... | true |
dc1f09be08e978470a97f67dfae6d36c76249db2 | Ruby | EzraDoucet/tts-ruby | /cup.rb | UTF-8 | 1,655 | 4.125 | 4 | [] | no_license | class Cup
def initialize
puts "I'm alive! ~SPARKLE~"
@drink_amount = 0
end
def fill
puts "I'm filled up."
@drink_amount = 100
quantity
end
def empty
puts "All gone. :( "
@drink_amount = 0
end
def quantity
puts "There is #{@drink_amount}% left."
return "<<O < O > O>>"
end
def sip(amount... | true |
51e77ea61da2394fa13dc362f9a45e6bcf765c2b | Ruby | l33z3r/ruby_playground | /neural_network.rb | UTF-8 | 685 | 3.546875 | 4 | [] | no_license | require 'ai4r'
# Create the network with 4 inputs, 1 hidden layer with 3 neurons,
# and 2 outputs
net = Ai4r::NeuralNetwork::Backpropagation.new([2, 4, 4, 4, 2])
# Train the network
10_000.times do |i|
net.train([50, 25], [1, 0])
net.train([100, 50], [1, 0])
net.train([25, 50], [0, 1])
net.train([50, 100], [0... | true |
d641c6421291d56e7a4e519ae0d5fb68fcb57234 | Ruby | epicodus-codereview/dictionary | /lib/Dictionary.rb | UTF-8 | 635 | 3.046875 | 3 | [
"MIT"
] | permissive | class Word
@@all_words = []
attr_reader(:word, :word_id, :definition)
def initialize
@word = word
@word_id = @@all_words.length.+(1)
@definition = []
end
def save
@@all_words.push(self)
end
define_singleton_method(:all) do
@@all_words
end
define_singleton_method(:word_find)... | true |
17b35b4bc37ec8a9dc987bc40671205b524355f7 | Ruby | sflang/bowling_game | /main.rb | UTF-8 | 467 | 3.4375 | 3 | [] | no_license | require 'pry'
require './frame'
require './game'
def get_ball_sequence
puts "Enter ball sequence for game:"
gets.chomp
end
def put_game_score(game)
puts " Frame Score"
puts " -------------"
9.times do |i|
puts " #{i + 1} #{game.frames[i].frame_score}"
end
puts " 10 #{game.fram... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.