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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
8a6c2662a5032eb70a1e3fbb829f0a8cc535c496 | Ruby | jem/non-haml | /gem/lib/non-haml/colorizer.rb | UTF-8 | 381 | 3.34375 | 3 | [] | no_license | module Color
COLORS = {clear: 0, red: 31, green: 32, yellow: 33, blue: 34, gray: 30, grey: 30}
def self.method_missing(color_name, *args)
if args.first.is_a? String
color(color_name) + args.first + color(:clear)
else
color(color_name) + args.first.inspect + color(:clear)
end
end
def s... | true |
a41326847396da114fa4a7ef0552b61f577b9203 | Ruby | angiemalaika/ruby-objects-has-many-through-lab-dc-web-career-040119 | /lib/genre.rb | UTF-8 | 566 | 3.03125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class Genre
attr_reader :name
@@all = []
def initialize(name)
@name= name
@@all << self
end
def songs
Song.all.select do |song|
song.genre == self
#self.Songeach do
#iterates through all songs
#finds the song that belongs genre
end
end
def artists
... | true |
51dafe1bba15a271880626b0578712c3c91653b7 | Ruby | justGrasse/phase-0-tracks | /databases/daily_todo/daily_todo.rb | UTF-8 | 5,852 | 3.25 | 3 | [] | no_license | # Justin's Daily To-Do List
# DOMAIN LOGIC (+ ORM w/SQLite3)
# require gems
require 'sqlite3'
require 'faker'
# create SQLite3 database
db = SQLite3::Database.new("todo.db")
db.results_as_hash = true
# create SQL command for activity table
create_activities_cmd = <<-SQL
CREATE TABLE IF NOT EXISTS activities(
id... | true |
b6021efc2bc1c7686563c11c76a059675dfe3445 | Ruby | automation551/ramf_rails | /installer/install_helper.rb | UTF-8 | 1,429 | 2.515625 | 3 | [
"MIT"
] | permissive | require 'fileutils'
module RAMF
module InstallHelper
def file_in_app(*args)
File.join(args.unshift(RAILS_ROOT))
end
def file_in_installer(*args)
File.join(args.unshift(File.dirname(__FILE__)))
end
def create_file_unless_exists!(path_under_rails, template=nil, verbose = true)... | true |
35c692bc691019f8ba4eb6e21fd7d6c3255fa87a | Ruby | qiushuizy/captcha_server | /captcha/get_img.rb | UTF-8 | 224 | 2.5625 | 3 | [] | no_license |
require 'memcached'
$cache = Memcached.new("localhost:11211")
i = 10000
until i == 0 do
key = $cache.get(i.to_s, false)
value = $cache.get(key, false)
puts "#{i}, #{key}, #{value.length}"
i = i - 1;
end
| true |
a37977f96fab487774aef616327b9cede591a5fe | Ruby | nana4gonta/gdd2011jp | /ruby/puzzle/gdd_puzzle.rb | UTF-8 | 6,890 | 3.015625 | 3 | [] | no_license | # -*- coding: utf-8 -*-
require 'digest/md5'
class Ctrl
def initialize(left, right, up, down)
@@left = left.to_i
@@right = right.to_i
@@up = up.to_i
@@down = down.to_i
end
def reduce(str)
str.split('').each do |c|
case c
when 'L'
@@left -= 1
when 'R'
@@right... | true |
2a14f6c38814d5354d1f601d9a390e9171a609c3 | Ruby | philcrissman/advent | /08/solution.rb | UTF-8 | 868 | 2.96875 | 3 | [] | no_license | def reset
@instructions = File.read("./input.txt").split("\n")
@vars = []
@vals = []
end
def run_instructions(instr = @instructions)
instr.each do |instruction|
instruction = instruction.split(" ")
unless @vars.include?("@#{instruction[0]}")
instance_variable_set(:"@#{instruction[0]}", 0)
@... | true |
29ce0f9326f81307a61485207168a832c5e0ecd9 | Ruby | AntoineMassoni/planet-invader | /app/models/booking.rb | UTF-8 | 994 | 2.59375 | 3 | [] | no_license | class Booking < ApplicationRecord
belongs_to :user
belongs_to :planet
validates :check_in, :check_out, :travelers, presence: true
validates :travelers, numericality: true
# def check_out_after_check_in
# errors.add(:check_out, "must be after the start date") if check_in > check_out
# end
# # def pars... | true |
53fd529789dfbba25d061734fa7e9a34b770f878 | Ruby | heath3conk/phase-0 | /week-5/gps2_2.rb | UTF-8 | 5,173 | 4.40625 | 4 | [
"MIT"
] | permissive | # Method to create a list
# input:
# String of items separated by spaces (example: "carrots apples cereal pizza")
# steps:
# Create a new array, splitting the given string of items into elements of the array
# Iterate over the elements of the array, putting them into a hash
# - key - item name
# - value - s... | true |
6cd4c543ba4bce3f726748cd4112ddd82177afd1 | Ruby | sarahrudy/battleship | /spec/cell_spec.rb | UTF-8 | 1,618 | 3.25 | 3 | [] | no_license | require 'rspec'
require './lib/ship'
require './lib/cell'
describe Cell do
it 'exists' do
cell = Cell.new("B4")
expect(cell).to be_instance_of(Cell)
end
it 'has attributes' do
cell = Cell.new("B4")
expect(cell.coordinate).to eq("B4")
end
it 'has a ship' do
cell = Cell.new("B4")
... | true |
8d7c68a4eee442a0047d2b93645d429b8eec1a98 | Ruby | warmer/quick_tools | /http_client.rb | UTF-8 | 1,666 | 3.078125 | 3 | [
"MIT"
] | permissive | require 'net/http'
require 'net/https'
require 'uri'
# This provides helper methods for common HTTP actions and is based on a
# several implementations of this basic functionality written over the years.
#
# Intended usage: simple HTTP library in a single, portable file, that
# abstracts the basic HTTP functionality f... | true |
1356558f00a03e10189821dc432b23f2dadf9c7d | Ruby | pav3ls/learn-to-code-with-ruby-lang | /Section-5-Methods_and_Conditionals_I/71_the_respond_to_method.rb | UTF-8 | 88 | 2.765625 | 3 | [] | no_license | num = 1000
p num.respond_to?("length")
if num.respond_to?("next")
p num.next
end
| true |
b9e550943c4ef2f8dd7ec0fabbc09b3fc5be484f | Ruby | juggernault/reportportal_sample_project | /features/support/helpers/wait_helper.rb | UTF-8 | 1,296 | 3.046875 | 3 | [] | no_license | require 'capybara/dsl'
module Zpg
module WaitHelper
include Capybara::DSL
# wait for ajax request to complete
def wait_for_ajax
counter = 0
while page.execute_script("return $.active").to_i > 0
counter += 1
sleep(0.1)
raise "AJAX request took longer than 20... | true |
af338de5a0318f3522db0554e57d34e9530cfff7 | Ruby | natalvz/oo-cash-register-v-000 | /lib/cash_register.rb | UTF-8 | 744 | 3.359375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class CashRegister
attr_accessor :total, :discount, :descuento, :items, :last_transaction
def initialize(dis=nil)
@total = 0
@discount = dis
@items = []
end
def add_item(item, price, quantity=1)
self.total += (price*quantity)
quantity.times do
@items << item
... | true |
606a81235f3eba059f4cf2362b8c917cada321e9 | Ruby | glenc/rpoint | /lib/rpoint/interop/webs.rb | UTF-8 | 2,503 | 2.59375 | 3 | [] | no_license | module RPoint
module Interop
##
# Interop methods for working with webs
class Webs
##
# Gets a web by its URL
def self.get_web(url)
return url if url.is_a? SPWeb
return url.RootWeb if url.is_a? SPSite
# to get the web, first we'll open the site collec... | true |
bc3f7b93f5c06d5c09c3304f99068358f9b92ae5 | Ruby | openware/peatio-core | /lib/peatio/ranger/connection.rb | UTF-8 | 3,093 | 2.53125 | 3 | [] | no_license | module Peatio::Ranger
class Connection
attr_reader :socket, :user, :authorized, :streams, :logger, :id
def initialize(router, socket, logger)
@id = SecureRandom.hex(10)
@router = router
@socket = socket
@logger = logger
@user = nil
@authorized = false
@streams = {}
... | true |
f53280cc36642e22375c662d22d7a2e63118d09b | Ruby | takagotch/rails1 | /super/binary/InstantRails-1.7-win/InstantRails/rails_apps/typo-2.6.0/script/process/reaper | UTF-8 | 4,392 | 2.9375 | 3 | [
"MIT"
] | permissive | #!/usr/local/bin/ruby
require 'optparse'
require 'net/http'
require 'uri'
def nudge(url, iterations)
print "Nudging #{url}: "
iterations.times { Net::HTTP.get_response(URI.parse(url)); print "."; STDOUT.flush }
puts
end
if RUBY_PLATFORM =~ /mswin32/ then abort("Reaper is only for Unix") end
class ProgramProc... | true |
e55190131ec9004dff8d17b85f938cb0c01f7fe1 | Ruby | teoucsb82/pokemongodb | /lib/pokemongodb/pokemon/beedrill.rb | UTF-8 | 1,243 | 2.75 | 3 | [] | no_license | class Pokemongodb
class Pokemon
class Beedrill < Pokemon
def self.id
15
end
def self.base_attack
144
end
def self.base_defense
130
end
def self.base_stamina
130
end
def self.buddy_candy_distance
1
end
de... | true |
d0e845b369bfeacfec9e88ccf568dcbf9f16505f | Ruby | JohnMarkLudwick/ruby-objects-has-many-lab-v-000 | /lib/post.rb | UTF-8 | 785 | 3.09375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Post
attr_accessor :title, :author
@@all = []
def initialize(title)
@title = title
@@all << self
end
def author_name
if self.author
self.author.name
else
nil
end
end
end
# class Post
# attr_accessor :name
# @@all = 0
# def initialize(title)
#... | true |
3783706767961946cabe9782b97432f8f59b35da | Ruby | Sheena-Marie/ruby-projects | /analyser.rb | UTF-8 | 1,317 | 4.96875 | 5 | [] | no_license | # Setting up the methods
def multiply(first_number, second_number)
first_number.to_f * second_number.to_f
end
def divide(first_number, second_number)
first_number.to_f / second_number.to_f
end
def subtract(first_number, second_number)
second_number.to_f - first_number.to_f
end
def mod(first_number, second_num... | true |
f3ea68ebaa8714c99e7ab8bdb02cae8285ed2ff5 | Ruby | merrua/ruby | /ex10_cat.rb | UTF-8 | 357 | 3.5 | 4 | [] | no_license | tabby_cat = "\tI'm tabbed in."
persian_cat = "I'm split\non a line."
backslash_cat = "I'm \\ a \\ cat."
fat_cat = <<MY_HEREDOC
I'll do a list:
\t* Cat food
\t* Fishies
\t* Catnip\n\t* Grass
MY_HEREDOC
puts tabby_cat
puts persian_cat
puts backslash_cat
puts fat_cat
poppy_cat = "This string has a quote: \". As you can... | true |
29e9000c94dd600d33f8e5bb17bbdc19566b432d | Ruby | jgt17/Minesweeper | /game_resources/positions/position.rb | UTF-8 | 376 | 3.046875 | 3 | [] | no_license | # frozen_string_literal: true
# basic position
# extended to map coordinates in different minefield topologies to the corresponding index in the underlying array
class Position
attr_reader :true_position
def initialize(index)
@true_position = index
end
def ==(other)
other.is_a?(Position) && @true_pos... | true |
bbdc8590208e885c02434e55ab651d7a584b39ee | Ruby | georgeu2000/volt | /lib/volt/extra_core/hash.rb | UTF-8 | 160 | 2.984375 | 3 | [
"MIT"
] | permissive | class Hash
def deep_cur
new_hash = {}
each_pair do |key, value|
new_hash[key.deep_cur] = value.deep_cur
end
return new_hash
end
end
| true |
3434e80bca72a9bb26ce72d94d0b3190b790e5b5 | Ruby | tanphan313/leet_works | /problems/array/palindrome_number.rb | UTF-8 | 550 | 3.875 | 4 | [] | no_license | <<-Doc
Given an integer x, return true if x is palindrome integer.
An integer is a palindrome when it reads the same backward as forward. For example, 121 is palindrome while 123 is not.
Input: x = 121
Output: true
solve it without converting the integer to string
Doc
# @param {Integer} x
# @return {Boolean}
def is... | true |
e5fc60a2e17afa36256bce7ea75194f11f3202ca | Ruby | champagnepappi/ruby | /sum2.rb | UTF-8 | 120 | 3.375 | 3 | [] | no_license | def get_sum(numbers)
sum = 0
numbers.map do |e|
passengers = e[1] - e[0]
sum += passengers
end
sum
end
| true |
2ea157a91a174073e3c8374af8eed780644726c7 | Ruby | weilihmen/simple-twitter | /lib/tasks/dev.rake | UTF-8 | 2,452 | 2.53125 | 3 | [] | no_license | namespace :dev do
# 請先執行 rails dev:fake_user,可以產生 20 個資料完整的 User 紀錄
# 其他測試用的假資料請依需要自行撰寫
task fake_user: :environment do
User.destroy_all
20.times do |i|
name = FFaker::Name::first_name
file = File.open("#{Rails.root}/public/avatar/user#{i+1}.jpg")
user = User.new(
name: name,
... | true |
b87335e09154dd476c179f9f003ac825a13ce5c3 | Ruby | sirramongabriel/lunch_panoply | /app/models/company.rb | UTF-8 | 1,463 | 2.8125 | 3 | [] | no_license | class Company < ActiveRecord::Base
attr_accessible :address, :city, :name, :phone, :state, :zip, :employee_id
validates_presence_of :name, :address, :city, :state, :zip, :phone
validates_length_of :state, is: 2, too_long: 'please enter a two character state abbreviation',
too_short: 'please enter a... | true |
a67ed5dd56f2580b5d1993dddc7ab4c296bc7b0b | Ruby | uk-gov-mirror/ministryofjustice.specialist-publisher | /bin/republish_withdrawn_document | UTF-8 | 957 | 2.578125 | 3 | [
"MIT",
"LicenseRef-scancode-proprietary-license"
] | permissive | #!/usr/bin/env ruby
require File.expand_path("../../config/environment", __FILE__)
require "specialist_publisher"
def republish_withdrawn_edition(edition)
# Change the state to published
edition.update_attribute(:state, "published")
# Get the services for the right document type
services = SpecialistPublishe... | true |
6bf8919b5cfb04d89e1ca17e9bd73f2767a014ff | Ruby | yoshitsugu/host_summary_parser | /lib/host_summary_parser.rb | UTF-8 | 722 | 2.796875 | 3 | [
"MIT"
] | permissive | require "host_summary_parser/version"
class HostSummaryParser
def self.parse(string)
parsed = ""
string.split("\n").each do |line|
line.gsub!(/\(.+\)/,"")
if line =~ /^(\s*)(\S+)\s*=\s*([\{\[])\s*$/
parsed << "#{$1}:#{$2} => #{$3}\n"
elsif line =~ /^(\s*)(\S+)\s*=\s*(.*),\s*$/
... | true |
10514f41f4923b5b41c9b0c19f5928e9caa11177 | Ruby | cesareferrari/programming-foundations | /exercises/101-109_small_problems/easy4/previous3/10_convert_number.rb | UTF-8 | 492 | 3.8125 | 4 | [] | no_license | def integer_to_string(integer)
digits = []
loop do
integer, digit = integer.divmod(10)
digits << digit
break if integer == 0
end
digits.reverse.join
end
def signed_integer_to_string(integer)
return '0' if integer == 0
return integer_to_string(integer.abs).prepend('-') if integer < 0
integer... | true |
b1168ba3f7e3fdf5e3591c0731b0c2ef6a289a9a | Ruby | mindreframer/datastructures-algorithms-stuff | /github.com/mindreframer/source-data-structures-and-algorithms-with-oop/ruby/pgm14_08.txt | UTF-8 | 456 | 3.15625 | 3 | [] | no_license | #
# This file contains the Ruby code from Program 14.8 of
# "Data Structures and Algorithms
# with Object-Oriented Design Patterns in Ruby"
# by Bruno R. Preiss.
#
# Copyright (c) 2004 by Bruno R. Preiss, P.Eng. All rights reserved.
#
# http://www.brpreiss.com/books/opus8/programs/pgm14_08.txt
#
def mergeSort(array, i... | true |
49ef618815607d695e59dc793935daebeef69075 | Ruby | locomotivecms/custom_fields | /lib/custom_fields/types/date_time.rb | UTF-8 | 3,181 | 2.703125 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module CustomFields
module Types
module DateTime
module Field; end
module Target
extend ActiveSupport::Concern
module ClassMethods
# Adds a date_time field
#
# @param [ Class ] klass The class to modify
# @param [... | true |
48f46732b23810ff4b0349ecd2bc97f359d3cb7b | Ruby | arthurnn/memcached-manager | /lib/extensions/memcached_inspector.rb | UTF-8 | 1,413 | 2.53125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Sinatra
module MemcachedInspector
def memcached_inspect options
host = options[:host]
port = options[:port]
key = options[:key]
inspect = inspector host, port
# Filter by key if defined
if !key.nil?
inspect = inspect.select{|pair| pair[:key] == key }.first
... | true |
d69152de30414b19cd4a3b979e14de12912aeea6 | Ruby | lbt/sourcify | /spec/proc/to_sexp_within_irb_spec.rb | UTF-8 | 3,886 | 2.640625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
describe "Proc#to_sexp within IRB" do
class << self
def irb_eval(string)
irb_exec(string)[-1]
end
def equal_to(expected)
lambda {|found| found == expected }
end
end
should 'handle non var' do
expected ... | true |
03158df3308550d3278de2c4b381b3f0dac11e0b | Ruby | lonelyelk/advent-of-code | /2020/23/test.rb | UTF-8 | 240 | 2.53125 | 3 | [] | no_license | require_relative "lib"
require "test/unit/assertions"
include Test::Unit::Assertions
input = "389125467"
assert_equal "92658374", crab_game(input, 10), "Wrong result"
assert_equal 149245887792, crab_game2(input, 10000000), "Wrong result"
| true |
d6c5fdd73acfcb3f10a379b443299e4e9a617be7 | Ruby | alexkorich/library_korich | /lib/library_korich/book.rb | UTF-8 | 335 | 3.03125 | 3 | [
"MIT"
] | permissive | module LibraryKorich
class Book
attr_reader :title, :author
def initialize(title, author)
if author.class==Author
@title=title
@author=author
else
raise "Author is not valid!"
end
end
def count(c)
@count=c
end
def to_s
"#{self.title.to_s}, #{self.author.name}"... | true |
24b5af8bbaebd257ccbaefdc07fc42fdf69baa51 | Ruby | Riyan-Bryant/CIT383 | /create_user_records2.rb | UTF-8 | 1,939 | 3.703125 | 4 | [] | no_license | #!/usr/bin/ruby
# Program 01
# Riyan Bryant
# CIT 383-003 Fall 2017
# 9/13/2017
#Initializing variabls and creates empty arrays for the user response to be stored in.
employee_id = []
first_name = []
last_name = []
dep_num = []
sup_name = []
linux_id = []
temp_pass = []
cont_prog = 'Y'
# A l... | true |
1c58e6096dd0728e570a0ab273494943d4003356 | Ruby | beckyrussoniello/multi-city-indeed-search | /spec/requests/search_spec.rb | UTF-8 | 2,537 | 2.609375 | 3 | [] | no_license | require 'spec_helper'
describe "job search" do
it "performs a search with multiple locations" do
visit root_url
expect {
fill_in "search_query", with: "phlebotomy"
fill_in "location_name", with: "new york chicago" #CITIES.sample(10) #rand(1..10))
click_button "Search"
}.to change(Searc... | true |
4ed86706fe48430105e8afa422cd8b92c2f09076 | Ruby | ZempTime/ConsciousSpendingPlan | /app/models/paycheck.rb | UTF-8 | 553 | 2.546875 | 3 | [] | no_license | class Paycheck < ActiveRecord::Base
has_many :disbursments
has_many :accounts, through: :disbursments
after_save :create_disbursements
validates :total_amount, presence: true
def create_disbursements
#TODO: Create our disbursements for this paycheck based upon accounts
# Iterate through each accou... | true |
9e23eeea297cdfcb848a4fa9b5988af093d30b35 | Ruby | roykim79/tdd_ruby_card_game_war | /lib/card_deck.rb | UTF-8 | 455 | 3.328125 | 3 | [] | no_license | require_relative './playing_card'
class CardDeck
def initialize
@cards_left = []
ranks = %w[A K Q J 10 9 8 7 6 5 4 3 2]
suits = %w[Spades Hearts Clubs Diamonds]
ranks.each do |rank|
suits.each do |suit|
@cards_left.push(PlayingCard.new({rank: rank, suit: suit}))
end
end
end
... | true |
8949118cd790f8c47bdb63c41f161b1194982384 | Ruby | Eden-Eltume/100 | /Introduction_to_Programming_with_Ruby/2_The_Basics4/ex4.rb | UTF-8 | 55 | 2.859375 | 3 | [] | no_license | movies = [2018, 2008, 2014]
movies.each{|el| puts el}
| true |
a2a0a2611d3ed4730e48951ab284f96b750a5ade | Ruby | doremidom/mastermind | /mastermind.rb | UTF-8 | 4,660 | 3.21875 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/reloader' if development?
class Mastermind
attr_accessor :computer_output, :guess_feedback, :code, :game_over
def initialize(gametype, code, saved_code=nil)
@colors = ['r','g','y','b','o','v']
@game_over = false
@tried_codes = []
if gametype == 1
@code = code.split(''... | true |
aad6a79cd7c888b449db3ae019c14023195673a6 | Ruby | magdalenamandat/homework-hashes | /loops.rb | UTF-8 | 1,109 | 4.125 | 4 | [] | no_license | # counter = 0
# my_number = 5
#
# while (counter < my_number)
# p "counter is #{counter}"
# counter += 1
# end
# my_number = 5
# p "What number am I thinking of?"
# value = gets.chomp().to_i()
#
# while (value != my_number)
# break if (value == 0)
# if (value > my_number)
# p "too high!"
# else
# p "... | true |
999d838e4316018c18119df2fa8117ff4cf427a8 | Ruby | albertbahia/wdi_june_2014 | /w04/d03/hoa_newton/movie_trailer/app/models/omdb.rb | UTF-8 | 610 | 2.875 | 3 | [] | no_license | class OMDB
def self.search(term)
search_url = URI.escape("http://omdbapi.com/?s=#{term}")
api_response = HTTParty.get(search_url) #string
results = JSON.parse(api_response)["Search"]
results_array = results.map do |movie|
movie["imdbID"]
end
movie_info_array = results_array.map do |imdbid|
movie = ... | true |
a04553b0935df7aff90af5585407bf1832596459 | Ruby | kathrynmbrown/epicodus | /address-book-ruby-master 3/address_book_main.rb | UTF-8 | 1,717 | 3.78125 | 4 | [] | no_license | require './lib/contact'
require './lib/phone'
require './lib/email'
require './lib/address'
# @contact = []
def main
puts "Press 'a' to add a contact or 'l' to view list of contacts"
puts "Press 'x' to exit"
main_choice = gets.chomp
case main_choice
when 'a'
add_contact
when 'l'
view_contacts
wh... | true |
2e173f58aba9d6203246b390da202f38dc6c9cf0 | Ruby | ysei/polite_programmer_presentation | /src/botwars/lib/botwars/basic_robot.rb | UTF-8 | 649 | 2.890625 | 3 | [] | no_license | class Robot
# Informs the robot that the game is starting. The
# control_unit is provided for getting sensor data and
# issuing commands.
def start_game(name, color, controller)
end
# Informs the robot that it has collided with an object
# and how much damage the collision caused.
def collision(damage)... | true |
b49d9dadf8b56aa0f20c231f19539ed9c859c690 | Ruby | raohmaru/romtools | /move_roms/move_roms.rb | UTF-8 | 3,010 | 3.1875 | 3 | [
"MIT"
] | permissive | require 'fileutils'
# Options
working_dir = '.'
output_dir = ''
romlist = false
inc_clones = false
dry_run = false
copy = false
# Variables
rom_count = 0
rom_total = 0
roms_found = {}
missing = []
# Const
RX_EXT_ZIP = /\.zip$/
HELP = <<eof
Move ROMs 1.0
-------------
Moves zipped ROMs files from the target dir to the ... | true |
08d92d337bb3b2cd034cddc010e58d6490c89aeb | Ruby | JulianNicholls/Advent-of-Code-Ruby | /day-12/day-12_2.rb | UTF-8 | 616 | 3.25 | 3 | [
"MIT"
] | permissive | require 'json'
require 'pp'
input = JSON.parse(File.read 'input.txt')
def trim(hash)
hash.delete_if { |k, v| v.is_a?(Hash) && v.values.include?('red') }
hash.keys.each do |key|
val = hash[key]
if val.is_a? Hash
trim(val)
elsif val.is_a? Array
trim_array(val)
end
end
end
def trim_ar... | true |
e4a3cd93f1d80b5fddc108a435d11c1a7232c75c | Ruby | pathbox/A-bit-of-ruby-code | /csv_big/csv_foreach.rb | UTF-8 | 302 | 2.84375 | 3 | [] | no_license | require_relative './print_helper'
require 'csv'
print_memory_usage do
print_time_spent do
sum = 0
CSV.foreach('data.csv', headers: true) do |row|
sum += row['id'].to_i
end
puts "Sum: #{sum}"
end
end
# ruby csv_foreach.rb
# Sum: 500000500000
# Time: 13.63
# Memory: 1.8 MB
| true |
903d8d0b2ab4c55ca1bb7a2ea37a307ac9dab92f | Ruby | matthope/pupistry | /exe/pupistry | UTF-8 | 11,784 | 2.65625 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
# Lancher for Pupistry CLI
require 'rubygems'
require 'thor'
require 'logger'
require 'fileutils'
require 'pupistry'
# Ensure all output is real time - this is a long running process with
# continual output, we want it to sync ASAP
STDOUT.sync = true
# Logging - STDOUT only
$logger = Logger.new(S... | true |
0a49ee5669d190625debc760816d27fffa4eb05b | Ruby | piaoyehong1107/sql-table-relations-crowdfunding-join-table-lab-hou01-seng-ft-071320 | /lib/sql_queries.rb | UTF-8 | 1,838 | 3.1875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your sql queries in this file in the appropriate method like the example below:
#
# def select_category_from_projects
# "SELECT category FROM projects;"
# end
# Make sure each ruby method returns a string containing a valid SQL statement.
def selects_the_titles_of_all_projects_and_their_pledge_amounts_alphabe... | true |
1803bbf34e4c4741d03980491374f1b55cccafd1 | Ruby | jbhannah/agate | /spec/agate/cli_spec.rb | UTF-8 | 2,110 | 2.828125 | 3 | [
"MIT"
] | permissive | # -*- coding: utf-8 -*-
require "spec_helper"
require "agate/cli"
RSpec.describe Agate::CLI do
let(:cli) { File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "bin", "agate") }
let(:text) { "勉【べん】強【きょう】します" }
context "with help option" do
it "shows the help message and exits" do
stub_cons... | true |
2d8e6549627135848cf99b04f5fb9d530cfe682f | Ruby | jean-baptiste-blanc/project-euler | /problem3.rb | UTF-8 | 158 | 2.765625 | 3 | [] | no_license | # search for the prime numbers
require 'prime'
primes =Prime.prime_division (600851475143)
primes.each {|prime,division| puts "Next prime factor #{prime}"}
| true |
0f249f4a75c57c7bb39454d844bbd7beaba99fff | Ruby | theouty/ruby-project-alt-guidelines | /lib/new_event_app.rb | UTF-8 | 3,259 | 3.5 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class NewEventApp
attr_reader :user
def run
welcome
login_and_signup
create_event
event_search
update_event
delete
bye
end
def welcome
puts "Welcome to the Events application!"
end
def login_and_signup
puts "Type your name"
... | true |
168e598d38bb13f961646ec20d58bfec25c247c4 | Ruby | thiagocanto/bowling | /spec/player_spec.rb | UTF-8 | 1,152 | 3.1875 | 3 | [] | no_license | require_relative '../src/models/player'
require_relative '../src/rules/ten_pin_rules'
RSpec.describe Player do
context 'having correct values' do
player = Player.new 'Steve', %w[8 2 7 3 3 4 10 2 8 10 10 8 0 10 8 2 9]
it 'should calculate round scores' do
expect(player.scores(TenPinRules)).to eq [17, 3... | true |
a16e167a2c2c796671a7633062cb2cdd317d05a7 | Ruby | taylortreece/pick-a-key | /lib/pick_a_key/cli.rb | UTF-8 | 5,826 | 3.734375 | 4 | [
"MIT"
] | permissive | require './lib/pick_a_key'
require 'pp'
class PickAKey::CLI
def start
puts "Welcome to your basic music theory coordinator!"
puts
puts "If you want to check out a key, choose from the list below by typing the key as you see it listed."
puts
puts "Pick a key:"
... | true |
9daf71787202e97d89d516845164adf0c35eb268 | Ruby | saghourkhalil/day-6 | /04_simon_says/simon_says.rb | UTF-8 | 696 | 3.953125 | 4 | [] | no_license | #write your code here
def echo say
return p "#{say}"
end
def shout say
return p "#{say.upcase}"
end
def repeat(string, nb = 2)
([string] * nb).join(" ")
end
def start_of_word string, nb
i = 0
char = ""
while i < nb
char << string[i]
i += 1
end
return char
end
def first_word mots
i = 0
... | true |
bee1051a59c62a4aaaf4ec1756bd812b8bd8d513 | Ruby | janefoster72/config | /lib/config/private_data.rb | UTF-8 | 1,374 | 2.734375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Config
# This class manages everything that's not checked into the project
# repository.
class PrivateData
def initialize(path)
@path = Pathname.new(path)
end
# Manage a secret.
#
# name - Symbol name of the secret.
#
# Returns a Config::Core::File.
def secret(name)
... | true |
2ea24a65a6d1e443d7aaad4a6d1614cbff8f5059 | Ruby | Kumassy/MCDotArtMaker | /lib/mc_dot_art_maker/extern_lib_extension.rb | UTF-8 | 1,180 | 2.71875 | 3 | [
"MIT"
] | permissive | #
# Add some features to extern gem.
#
module Magick
class Image
def get_color_rgb_at(x, y)
pixel = self.pixel_color(x,y)
r = pixel.red / 257
g = pixel.green / 257
b = pixel.blue / 257
::Color::RGB.new(r, g, b)
end
end
end
module Color
class RGB
# Add to check equality
... | true |
4cecea2bc912a4a526344631894a2a74640769c3 | Ruby | jhartwell/ironruby | /Tests/Experiments/CF/Return/Errors.rb | UTF-8 | 79 | 2.9375 | 3 | [] | no_license | def foo
$p = Proc.new { return }
end
def y
yield
end
foo
y &$p
| true |
f74e3119c6d38ce97445ed26418cd4cd109390c6 | Ruby | cupofjoy/the-bachelor-todo-prework | /lib/bachelor.rb | UTF-8 | 1,238 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def get_first_name_of_season_winner(data, season)
# code here
data.each do |season_num, people|
if season_num == season
people.each do |person|
if person["status"] == "Winner"
return person["name"].split(' ')[0]
end
end
end
end
end
def get_contestant_name(data, occup... | true |
c20fab9337920d56d480598e6942244a57381a1a | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/grade-school/279f97b411dc4da2a6a73f84ab6484c2.rb | UTF-8 | 331 | 3.421875 | 3 | [] | no_license | class School
attr_accessor :school
def initialize
@school = {}
end
def add(name, grade)
school[grade] ||= []
school[grade] << name
end
def to_hash
Hash[school.sort do |a, b|
a[-1].sort!
a.first <=> b.first
end]
end
def grade(num)
school[num] ? school[num].sort : []... | true |
5b371a609f27af608858cf5e705490d8c9010845 | Ruby | clee1996/Big_O_and_anagrams | /two_sum.rb | UTF-8 | 644 | 4 | 4 | [] | no_license | # def bad_two_sum?(arr, target)
# arr.each_with_index do |ele, i|
# arr.each_with_index do |ele2, i2|
# if ele + ele2 == target && i2 > i
# return true
# end
# end
# end
# false
# end
def okay_two_sum?(arr, target)
# arr.sort.bsearch(targ... | true |
58ebdee91c1535e30d59cac4af102895d50ec28b | Ruby | department-of-veterans-affairs/caseflow-efolder | /app/services/image_converter_service.rb | UTF-8 | 1,799 | 2.703125 | 3 | [] | no_license | # Converts images to PDFs
class ImageConverterService
class ImageConverterError < StandardError; end
include ActiveModel::Model
attr_accessor :image, :record
def process
# If we do not handle converting this mime_type, don't do any processing.
return image if self.class.converted_mime_type(record.mime... | true |
c7dc02d296a1edf3db318b28c1718b4fe1233d50 | Ruby | acelizondo1/connect_four | /lib/game_board.rb | UTF-8 | 2,145 | 3.734375 | 4 | [] | no_license | class GameBoard
attr_reader :board
def initialize
@board = Array.new(7){ Array.new(6) }
end
def make_move(column, player)
unless column > @board.length || column < 0
for row in 0..5
if @board[column-1][row] == nil
@board[column-1][row] = player
return @board[column-1][r... | true |
6e8c6f6e823f5be62f59d4ecee817f883aaa4757 | Ruby | ACMCMU/BoredPrototype | /vendor/bundle/ruby/1.9.1/gems/shoulda-matchers-2.4.0/lib/shoulda/matchers/active_model/comparison_matcher.rb | UTF-8 | 1,418 | 2.609375 | 3 | [
"Apache-2.0",
"MIT"
] | permissive | module Shoulda # :nodoc:
module Matchers
module ActiveModel # :nodoc:
# Examples:
# it { should validate_numericality_of(:attr).
# is_greater_than(6).
# less_than(20)...(and so on) }
class ComparisonMatcher < ValidationMatcher
def initialize(... | true |
df2fe8527a3308e8d44ecf176ce2c29a98ffdffa | Ruby | luizeof/mp3file | /lib/mp3file/mp3_file.rb | UTF-8 | 9,316 | 2.515625 | 3 | [] | no_license | module Mp3file
class InvalidMP3FileError < Mp3fileError; end
class MP3File
attr_reader(:file, :file_size, :audio_size)
attr_reader(:first_header_offset, :first_header)
attr_reader(:xing_header_offset, :xing_header)
attr_reader(:vbri_header_offset, :vbri_header)
attr_reader(:mpeg_version, :layer... | true |
204d10e84995bcb0274afe732ccec2aeafcf940b | Ruby | rdavid1099/poke-api-v2 | /spec/unit/poke_api/pokemon/pokemon_type_spec.rb | UTF-8 | 531 | 2.53125 | 3 | [
"MIT"
] | permissive | RSpec.describe PokeApi::Pokemon::PokemonType do
describe '#initialize' do
it 'creates a basic PokemonType object from raw json data' do
raw_data = {
slot: 2,
type: {
name: "flying",
url: "https://pokeapi.co/api/v2/type/3/"
}
}
poke_type = PokeApi::Poke... | true |
36dde17dc975c9605df4239c050f89646fdf13e8 | Ruby | shadabahmed/leetcode-problems | /1047-remove-all-adjacent-duplicates-in-string.rb | UTF-8 | 253 | 3.578125 | 4 | [] | no_license | # @param {String} s
# @return {String}
def remove_duplicates(s)
stack = []
s.each_char do |c|
if stack.last == c
stack.pop while c == stack.last
else
stack.push(c)
end
end
stack.join
end
p remove_duplicates "abbaca" | true |
b2236c5135ab512446a2f72c0e77476f38624efd | Ruby | libgit2/docurium | /lib/docurium/cparser.rb | UTF-8 | 13,503 | 2.78125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Docurium
class CParser
# Remove common prefix of all lines in comment.
# Otherwise tries to preserve formatting in case it is relevant.
def cleanup_comment(comment)
return "" unless comment
lines = 0
prefixed = 0
shortest = nil
compacted = comment.sub(/^\n+/,"").sub(... | true |
f16747934a29f6c3db203b5eb5cad5e9bd44f70a | Ruby | amirahaile/CenturyLink-Crime | /app/helpers/maps_helper.rb | UTF-8 | 359 | 2.53125 | 3 | [] | no_license | module MapsHelper
def format_link(event_type)
sanitized_str = event_type.downcase.delete(",").delete("-").gsub("/", " ")
words = sanitized_str.split(" ")
link = ""
words.each_with_index do |word, index|
if (index == (words.length - 1))
link += word
else
link += (word + "-")... | true |
09e82df7b86ce58dbfa71ac4f99346ee81e18ca5 | Ruby | rootulp/exercism | /ruby/exercises/say/say.rb | UTF-8 | 1,896 | 3.984375 | 4 | [
"MIT"
] | permissive | # Say
class Say
UNITS = {
1 => 'thousand',
2 => 'million',
3 => 'billion'
}.freeze
TENS = {
90 => 'ninety',
80 => 'eighty',
70 => 'seventy',
60 => 'sixty',
50 => 'fifty',
40 => 'forty',
30 => 'thirty',
20 => 'twenty'
}.freeze
NUMS = {
19 => 'nineteen',
17 =>... | true |
511685d4b256f6f9e55e84cb2dd2d7f8b077a34b | Ruby | dapmas/Ruby_MarsRover | /spec/grid_spec.rb | UTF-8 | 1,061 | 3.109375 | 3 | [] | no_license | require File.expand_path('../../lib/grid', __FILE__)
describe Grid, "behaviour" do
let (:input) { "5 5\n1 2 N\nLMLMLMLMM 3 3 E MMRMMRMRRM" }
before :each do
@grid = Grid.new input
end
it "initializes_correctly" do
expect(@grid).not_to be_nil
#@grid.should_not be_nil
end
it "sets up the grid ... | true |
58c2a4d2460488afa3e6950f8d6f591d09f0d83a | Ruby | rewinfrey/RubyTTT | /spec/ttt/ai_medium_spec.rb | UTF-8 | 1,809 | 2.84375 | 3 | [] | no_license | require 'spec_helper'
module TTT
describe AIMedium do
let(:ai) { AIMedium.new(side: "o") }
let(:board) { ThreeByThree.new }
describe "#minimax" do
it "blocks a potential fork win" do
#situation: x to move
# o | | x
# -----------------
# | o |... | true |
f8e3438572a2e85893e1b43c01b7ee1ddc9b8ed1 | Ruby | mapcloud/mdTranslator | /lib/adiwg/mdtranslator/readers/mdJson/modules/module_timeInterval.rb | UTF-8 | 2,895 | 2.546875 | 3 | [
"Unlicense"
] | permissive | # unpack time interval
# Reader - ADIwg JSON to internal data structure
# History:
# Stan Smith 2016-10-14 original script
module ADIWG
module Mdtranslator
module Readers
module MdJson
module TimeInterval
def self.unpack(hTimeInt, responseObj)
... | true |
5846a88b3518929fffd63096bb89f8c7deb2fdef | Ruby | aflatune/trackablaze-gem | /trackers/klout.rb | UTF-8 | 976 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'klout'
module Trackablaze
class Klout < Tracker
def get_metrics(tracker_items)
@klout_client = Kloutbg.new("zxz2p64gv3caabbqmvzaub9p")
tracker_items.collect {|tracker_item| get_metrics_single(tracker_item)}
end
def get_metrics_single(tracker_item)
metrics = {}
i... | true |
ac8f8b5f63e17c0348e9a1e6e3a754d4e19e847d | Ruby | abdul10a10/research-worker-aws | /app/services/transaction_service.rb | UTF-8 | 3,151 | 2.515625 | 3 | [] | no_license | class TransactionService
def self.total_monthly_transaction
total_transaction = 0
indian_transactions = 0
uae_transactions = 0
other_country_transactions = 0
total_payment = 0
total_indian_payment = 0
total_uae_payment = 0
total_other_country_payment = 0
end_time = Time.now.utc
... | true |
83823049147f54cd4012eff10c2587460d57249c | Ruby | jgmorse/greensub | /bin/restrict_items.rb | UTF-8 | 1,868 | 2.78125 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
require 'slop'
require_relative '../lib/product'
require_relative '../lib/subscriber'
require_relative '../lib/component'
begin
opts = Slop.parse strict: true do |opt|
opt.string '-p', '--product', 'product id'
opt.string '-i', '--id', 'external id of component (i.e. its id on ... | true |
c34dc4c8d0d9e114f4592b9993b27a6f79226b6d | Ruby | jaxxstorm/sensu-plugins-coinbase | /bin/check-coinbase-price.rb | UTF-8 | 2,252 | 2.8125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
#
require 'coinbase/exchange'
require 'sensu-plugin/check/cli'
require 'pp'
class CheckCoinbasePrice < Sensu::Plugin::Check::CLI
option :api_key,
short: '-k API_KEY',
long: '--api-key API_KEY',
description: 'gdax API key',
required: true
... | true |
3c010d6f4dbd3f162fb1992ee40617cf82c0631c | Ruby | DDuongNguyen/oo-cash-register-dumbo-web-051319 | /app.rb | UTF-8 | 672 | 3.3125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
require 'rest-client'
require 'json'
#
# i tell this app a theme it gives me list of books
# terminal should ask to enter a name
puts "tell me a book theme"
# get in put from user
input = gets.chomp
url= "https://www.googleapis.com/books/v1/volumes?q=#{input}"
response = RestClient.get url
#
response_ha... | true |
b724e62754a064b3483f0cfdf0349bbfc86a932d | Ruby | mjamesv19/Assignment3 | /accounts.rb | UTF-8 | 883 | 3.328125 | 3 | [] | no_license | # Create account
# add founds
# remove founds
# trasfer founds
# Time to reach goal
class Account
attr_accessor :name
attr_accessor :funds
attr_accessor :goal
attr_accessor :income_hash
attr_accessor :expense_hash
# variables
def initialize(name, funds)
# income_hash = {}
# ... | true |
6c9448e397b104dd98dd0a8a3cecb338d40b086f | Ruby | DausdasKreuz/ironhack-week1-ruby | /day_4-single_responsibility/login_solution.rb | UTF-8 | 1,037 | 3.703125 | 4 | [] | no_license | User.new.login
Text.new.get_text
class User
def login
user_data = UserData.get_data
while !Autenticator.autenticate(username,password)
puts "Incorrect name or password"
user_data = UserData.get_data
end
end
end
class UserData
def self.get_data
puts "Please, insert your username"
username = gets.c... | true |
74f90a6ac1791ed8047173ffb7d116f69bf05189 | Ruby | billma/bill_algorithms | /lib/dijkstra.rb | UTF-8 | 1,632 | 3.0625 | 3 | [] | no_license | class String
def is_correct_format?
return false unless
self[0] =~ /[a-zA-Z]/ and
self[1] =~ /[a-zA-Z]/ and
self[0] != self[1] and
self[2..(self.length-1)] =~ /[0-9]/
return true
end
end
class Dijkstra
attr_accessor :vertices, :edges
def initialize
@vertices = {}
... | true |
f04ca39acce0ddc40f1fbd1061b41380b7cf8a19 | Ruby | kristjan/code_eval | /fibonacci_series/fibonacci_series.rb | UTF-8 | 171 | 3.546875 | 4 | [] | no_license | #!/usr/bin/env ruby
def fibonacci(n)
a, b = [1, 1]
a, b = b, a + b while (n -= 1) > 0
a
end
File.readlines(ARGV[0]).each do |line|
puts fibonacci(line.to_i)
end
| true |
fd2e45ebe9d89676b8d300fa4e3b9c1e4058c4e9 | Ruby | hunglethanh9/leetcode | /283. Move Zeroes/Move Zeroes.rb | UTF-8 | 266 | 3.296875 | 3 | [] | no_license | # @param {Integer[]} nums
# @return {Void} Do not return anything, modify nums in-place instead.
def move_zeroes(nums)
temp = 0
nums.each_with_index{|n,i| n == 0 ? temp += 1: nums[i-temp] = n}
(nums.size - temp).upto(nums.size-1){|i| nums[i] = 0}
end
| true |
4bd2555ea16672d8e3e3f76f18a84821972a7d0a | Ruby | dianamora/cli_project | /lib/cli.rb | UTF-8 | 2,824 | 3.265625 | 3 | [
"MIT"
] | permissive | #this is what communicates with the user, controller
require 'pry'
class Cli
def start
puts "
This is a galaxy of wondrous aliens, bizarre monsters, strange Droids,
powerful weapons, great heroes, and terrible villains. It is a
galaxy of fantastic worlds, magical d... | true |
61017a06c7deca32a7db65986ca97e271886babe | Ruby | secretartist272/CLI_Dinosaur | /lib/cli_dinosaur/dinosaur.rb | UTF-8 | 786 | 3.53125 | 4 | [
"MIT"
] | permissive | require 'pry'
class CliDinosaur::Dinosaur
attr_accessor :name, :description
@@all = []
def initialize(attr_hash)
attr_hash.each do |key, value|
self.send("#{key.downcase}=", value) if self.respond_to?("#{key.downcase}=")
end
save
end
def ... | true |
342e7e9fbd256e82289c70444b89de9b35cfa9f8 | Ruby | usman-tahir/rubyeuler | /factors.rb | UTF-8 | 155 | 3.4375 | 3 | [] | no_license | # find factors of an int
def factors(n)
fctrs = []
(1...n).each do |factor|
fctrs << factor if n % factor == 0
end
fctrs
end
p factors(120)
| true |
4a2ab8e6a649e0692abc3c931f1f8b5eae10a056 | Ruby | amyanne/crud-with-validations-lab-online-web-sp-000 | /app/models/song.rb | UTF-8 | 584 | 2.609375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song < ApplicationRecord
validates :title, presence: true, uniqueness: true
validates :released, inclusion: {in: [true, false]}
validates :release_year, numericality: { only_integer: true, less_than_or_equal_to: Time.now.year}, length: {in: 1..4, message: "please enter a 4 (or less) digit year"}, if: :rel... | true |
d42b35ee4e4b7f6b83cbe31ecf0914e4c9d6f2a2 | Ruby | glenngillen/s3backup-manager | /bin/s3restore | UTF-8 | 2,483 | 2.734375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'optparse'
begin
require 's3backup-manager'
rescue LoadError
require "#{File.dirname(__FILE__)}/../lib/s3backup-manager"
end
options = {}
optparse = OptionParser.new do|opts|
opts.banner = "Usage: s3restore.rb [options] backup_file destination"
options[:adapter] = "postgres"
... | true |
e5aca0d835beef9137c476527b4c06aa979103b0 | Ruby | zafinar/ruby-advanced-class-methods-lab-web-022018 | /lib/song.rb | UTF-8 | 1,060 | 3.25 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'pry'
class Song
attr_accessor :name, :artist_name
def initialize
end
@@all = []
def self.all
@@all
end
def save
self.class.all << self
end
def self.create
@@all << Song.new
@@all.last
end
def self.new_by_name(title)
song = Song.new
song.name = title
song
... | true |
6a337c1772c1e81e0020ead8516414bf3f16a445 | Ruby | marciopocebon/flipdotwars | /lib/movie.rb | UTF-8 | 498 | 3.265625 | 3 | [] | no_license | class Movie
LINES_PER_FRAME = 13 # Do not include the separator line in this number
attr_reader :frames
def initialize(path)
@frames = []
read_frames_from(path)
end
private
def read_frames_from(path)
File.readlines(path).map(&:chomp).each_slice(LINES_PER_FRAME + 1) do |lines|
f... | true |
3c4c466d22df230c025e4e81bed2f7c7ec6269f0 | Ruby | tdg5/adaptive_polling | /lib/adaptive_polling/governor.rb | UTF-8 | 1,427 | 2.53125 | 3 | [
"MIT"
] | permissive | require "redis"
module AdaptivePolling
class Governor
COEFFICIENT_SUFFIX = ":co".freeze
LOCK_SUFFIX = ":lock".freeze
BASE_NAMESPACE = "rb:ap:".freeze
attr_reader :correction_algorithm, :id, :redis_client
def initialize(id, correction_algorithm, opts = {})
@id = id
@correction_algori... | true |
f5869ad7e084ef21a1b77f101fb9c09ca8ebda9e | Ruby | vilelajonas/launch_school | /exercises/ruby_basics/methods/3.rb | UTF-8 | 287 | 4.5625 | 5 | [] | no_license | # Using the following code, write a method called car that takes two arguments
# and prints a string containing the values of both arguments.
# car('Toyota', 'Corolla')
# Expected output:
# Toyota Corolla
def car(brand, model)
brand + ' ' + model
end
puts car('Toyota', 'Corolla') | true |
696d0e5c728854cbbe8e144a6dd37eada400e317 | Ruby | nyx-a/stim | /src/job.rb | UTF-8 | 2,862 | 2.96875 | 3 | [
"MIT"
] | permissive |
require_relative 'b.dhms.rb'
require_relative 'command.rb'
require_relative 'history.rb'
require_relative 'pendulum.rb'
class Job
@@mtx = { } # { ? => Mutex }
def self.dispense_mutex token
if token.nil?
nil
else
token = token.to_s
@@mtx.fetch(token){ @@mtx[token] = Mutex.new }
end
... | true |
e8b02e6ec2095db446bbf2b5add069409d01d419 | Ruby | kamaradclimber/Dotfiles | /gnothi_form.rb | UTF-8 | 2,967 | 2.8125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'net/http'
require 'uri'
require 'json'
require 'highline'
def get_tokens(login, password)
uri = URI.parse('https://api.gnothiai.com/auth/login')
request = Net::HTTP::Post.new(uri)
request.body = URI.encode_www_form(username: login, password: password)
req_options = {
use_ssl:... | true |
183ca8d20ac2a53a20b3a8e943a6cb1bac116022 | Ruby | kgoettling/intro_to_programming | /ch7_hashes/ex3_loop_keys_values.rb | UTF-8 | 601 | 4.5625 | 5 | [] | no_license | # Write a program that loops through a hash and prints all the keys.
# Then write a program that prints all the values. Finally, write
# a program that prints both.
my_hash = {key1: "value1",
key2: "value2",
key3: "value3",
key4: "value4",
key5: "value5",
key6: "v... | true |
d564158e3e1eec7d126092c97e4acc2583a4a2d5 | Ruby | ashtony42/midi_printer | /helpers/methods.rb | UTF-8 | 759 | 2.671875 | 3 | [] | no_license | def show_midi_info sequence
print "the file has #{sequence.tracks.count} tracks\n"
sequence.tracks.count.times do |track_index|
sequence.tracks[track_index].events.each do |event|
if event.respond_to? "program"
print "track #{track_index} has instrument of #{GM_PATCH_NAMES[event.program]}\n"
... | true |
642bd0705bf015939fd16b5f3d2eae4e7f9d4836 | Ruby | pbinkley/If_I_Should_Die_Tonight | /newspapers/lib/tasks/ingest.rake | UTF-8 | 2,242 | 2.5625 | 3 | [] | no_license | INGEST_REPORTS_LOCATION = Rails.root.join('tmp/ingest_reports')
INDEX_OFFSET = 1
# adapted from https://github.com/ualbertalib/jupiter/blob/integration_postmigration/lib/tasks/batch_ingest.rake
namespace :ingest do
desc 'Ingest newspapers.com item list from csv file'
task :ingest_csv, [:csv_path] => :environment d... | true |
dc7219fdeb8b263496eb716be56574a35cfff405 | Ruby | alekscp/exercism | /ruby/bob/bob.rb | UTF-8 | 556 | 3.109375 | 3 | [] | no_license | module Bob
ANSWERS = {
'question' => 'Sure.',
'yell' => 'Whoa, chill out!',
'without_saying_anything' => 'Fine. Be that way!',
'anything_else' => 'Whatever.'
}
def self.hey(remark)
if remark.scan(/[A-Z]/).count > remark.scan(/[a-z]/).count
ANSWERS['yell']
elsif remark.scan(/[^\n\s\t... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.