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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
bb9597888bbfd2180bd9b3f4976d8791eb77b36e | Ruby | huberb/eulerproblems | /euler43/euler43.rb | UTF-8 | 1,280 | 3.859375 | 4 | [] | no_license | # 0 [1,2,3]
# 01 [2, 3], 02 [1, 3], 03 [1, 2]
# 012 [3], 021 [3], 031 [2]
# def next_num(nums)
# while nums.map{ |n| n[1].length }.max > 0
# entry = nums[0]
# nums = nums[1..-1]
# str = entry[0]
# rest = entry[1]
# rest.each do |r|
# nums << [ str + r.to_s, rest.clone - [r] ]
# end
# ... | true |
733ccf2c91d257d6a18fcd2fbf4b7ef3c246fe6a | Ruby | bendelonlee/numonic | /app/generators/password_generator.rb | UTF-8 | 602 | 3.21875 | 3 | [] | no_license | class PasswordGenerator
COMMON_WORDS = Set.new
File.open('./app/data/common_words.txt').each { |line| COMMON_WORDS.add(line.chomp) }
def make_password(number, fact)
@fact = fact.delete('.,0123456789').downcase
@key_words = @fact.split().reject do |word|
COMMON_WORDS.include?(word)
end
ensur... | true |
f636f2d93311f9f6e3272955b16df80b7cc01202 | Ruby | zhangsu/seal | /demo/pitch.rb | UTF-8 | 425 | 2.8125 | 3 | [
"WTFPL"
] | permissive | require 'seal'
Seal.startup
source = Seal::Source.new
source.stream = Seal::Stream.open('audio/pipa.ogg')
source.play
source.looping = true
FACTOR = 0.01
puts "Enter [ to reduce the pitch by #{FACTOR}."
puts "Enter ] to raise the pitch by #{FACTOR}."
puts "Enter q to quit."
until (c = $stdin.getc) =~ /q/i
if c =... | true |
8f50048e658d7b4fb6a2ba06bb18f24b58ef6cec | Ruby | gkostin1966/turnsole | /lib/turnsole/handle/service.rb | UTF-8 | 2,697 | 2.65625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Turnsole
module Handle
class Service
DOI_ORG_PREFIX = 'https://doi.org/'
HANDLE_NET_PREFIX = 'https://hdl.handle.net/'
HANDLE_NET_API_HANDLES = "#{HANDLE_NET_PREFIX}api/handles/"
FULCRUM_PREFIX = '2027/fulcrum.'
def self.noid(handle_path_or_url)... | true |
9dc2ff9e98f5bc307f5f8b145fbdb4790b06ce4a | Ruby | XJhaoren/ann-benchmarks | /tools/split-dataset.rb | UTF-8 | 785 | 2.828125 | 3 | [] | no_license | require 'set'
if ARGV.length != 5
puts "Parameters: <inputfile> <outputdatafile> <outputqueryfile> <numberofqueries> <seed>"
exit(-1)
end
inputfile = ARGV[0]
outputdatafile = ARGV[1]
outputqueryfile = ARGV[2]
k = ARGV[3].to_i
seed = ARGV[4].to_i
numOfPoints = File.foreach(inputfile).inject(0) {|c, line| c + ... | true |
d22df6a2da56e49af568dd8cfe630a04c967a8a8 | Ruby | bingxie/code-questions | /lib/design/ruby-file/fileutils_module.rb | UTF-8 | 554 | 2.96875 | 3 | [
"MIT"
] | permissive | require 'fileutils'
FileUtils.compare_file('a.txt', 'b.txt')
FileUtils.touch('/tmp/lock') # update the last access & modification time
FileUtils.cp_r('data', 'backup') # the “r” in cp_r stands for “recursive”.
# mkdir_p that create nested directories in one step.
FileUtils.mkdir_p("/tmp/testing/a/b")
# FileUtils als... | true |
c948d9c26c911da21e256e3709cfc669e10d2924 | Ruby | T-LG/projet_thp2 | /exo_15.rb | UTF-8 | 209 | 3.8125 | 4 | [] | no_license | puts "Quel est ton année de naissance?"
year_of_birth = gets.chomp.to_i
begin
puts " Année: #{year_of_birth}" " " "age: #{2020 - year_of_birth}ans"
year_of_birth += 1
end while (year_of_birth <= 2020)
| true |
0b3b93ee4a1385931fb1708540e7591931156aa3 | Ruby | jinyingwu/W2D5 | /My_Hash_Map/lib/p02_hashing.rb | UTF-8 | 435 | 2.734375 | 3 | [] | no_license | class Fixnum
# Fixnum#hash already implemented for you
end
class Array
def hash
res = 0
tmp = 0
(0...self.length).each do |idx|
tmp = (tmp + 11) % 21
r
es ^= (self[idx]+1024) << tmp
end
res
end
end
class String
def hash
end
end
class Hash
# This returns 0 because r... | true |
4f51d2b1a5d78059dd22ea06525ffe0d0a86953f | Ruby | mtt/rubycal | /rubycal.rb | UTF-8 | 6,608 | 3.15625 | 3 | [] | no_license | #Events will be added to each day that they occur on, but will also keep track of the position which the main Calendar object will set
#Position will be the Event's position in the stack of events for that day(i.e)
# 1 2 3 4 5
# e1 e1 e1 ... | true |
cd2fc8f27c90b3587da1a7aa6b3062043f54cfa1 | Ruby | aperini/ruby-fundamentals | /Methods/methods_as_messages.rb | UTF-8 | 545 | 4.09375 | 4 | [] | no_license | # document this class
class ClassB
def aaa
puts 'aaaaaaaa'
end
def print(content)
puts content.to_s
end
end
b = ClassB.new
# calling a method is the same as sending a message to the object
b.aaa # aaaaaaaa
b.__send__(:aaa) # aaaaaaaa
b.send(:aaa) # aaaaaaaa
b.print('content') # con... | true |
efdf2f257feb610b78e8de45ac0efabcd88044ff | Ruby | andreazaupa/renee | /renee-core/lib/renee-core/settings.rb | UTF-8 | 784 | 2.78125 | 3 | [
"MIT"
] | permissive | class Renee
class Core
##
# Stores configuration settings for a particular Renee application.
# Powers the Renee setup block which is instance eval'ed into this object.
#
# @example
# Renee::Core.new { ... }.setup { views_path "./views" }
#
class Settings
attr_reader :includes
... | true |
918af9610a39687d775f790117c6f76ca990430b | Ruby | Montage-Inc/ruby-montage | /lib/montage/query.rb | UTF-8 | 7,111 | 2.984375 | 3 | [
"MIT"
] | permissive | require 'montage/errors'
require 'montage/query/query_parser'
require 'montage/query/order_parser'
require 'montage/support'
require 'json'
module Montage
class Query
include Montage::Support
attr_accessor :options
attr_reader :schema
# Initializes the query instance via a params hash
#
# *... | true |
955506090974cd2d8318d60d961494c99b377e12 | Ruby | dkroondijk/Blog | /app/models/comment.rb | UTF-8 | 862 | 2.5625 | 3 | [] | no_license | class Comment < ActiveRecord::Base
belongs_to :user
belongs_to :post
has_many :votes, dependent: :destroy
has_many :voted_users, through: :votes, source: :user
validates :body, presence: true
def self.search(search)
where("body ILIKE ?", "%#{search}%")
end
def self.most_recent
order("create... | true |
9e0979ea630f7224e1e1f6dc1db9143453a58301 | Ruby | anoopyadav/BlackJack | /Card.rb | UTF-8 | 625 | 3.59375 | 4 | [] | no_license | class Card
attr_accessor :suite, :face, :hard, :soft
# Constructor, creates a new Card with suite and value
def initialize(value, suite)
@suite = suite
if value == 1
@hard = 1
@soft = 11
@face = "A"
elsif value > 10
@value = 10
@hard = 10
@soft = 10
if value =... | true |
205d882499aa3d3780d7ad9ef180b98ba3b274a5 | Ruby | yinm/ruby-book-codes | /sample-codes/chapter_04/code_4.05.05.rb | UTF-8 | 508 | 4.25 | 4 | [] | no_license | # 範囲オブジェクトを配列に変換してから繰り返し処理を行う
numbers = (1..4).to_a
sum = 0
numbers.each { |n| sum += n }
sum #=> 10
# ----------------------------------------
sum = 0
# 範囲オブジェクトに対して直接eachメソッドを呼び出す
(1..4).each { |n| sum += n }
sum #=> 10
# ----------------------------------------
numbers = []
# 1から10まで2つ飛ばしで繰り返し処理を行う
(1..10).step(... | true |
77d2a57734922c5741308ac87410d0291b776480 | Ruby | usman-tahir/rubyeuler | /loopy_loops.rb | UTF-8 | 170 | 3.546875 | 4 | [] | no_license | # http://programmingpraxis.com/2011/03/18/loopy-loops/
# print 1 to 1000 without using loops or conditionals
def put_numbers
puts (1..1000).to_a
end
put_numbers
| true |
705f6bd391eb26e61a682faec152d96c748b0ff1 | Ruby | tonyc/urlbot2 | /urlbot.rb | UTF-8 | 925 | 2.5625 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'cinch'
require 'hpricot'
require 'htmlentities'
require 'net/http'
require 'open-uri'
require 'uri'
bot = Cinch::Bot.new do
configure do |c|
c.nick = ENV["NICK"]
c.server = ENV["SERVER"]
c.channels = Array(ENV["CHANNEL"])
end
on :channel do |m|
URI.extract(m... | true |
260b50cde212e0d1a979f300619605eebaa022dc | Ruby | ponsonio/learning_ruby | /basic_error_handle.rb | UTF-8 | 392 | 2.734375 | 3 | [] | no_license | begin
#puts nil + 10
#puts 8/0
rescue ZeroDivisionError => e
puts "rescue the error: #{e}"
rescue StandardError => e
puts "rescue the error: #{e}"
end
def error_logger(e)
File.open("error.log", 'a') do |file|
file.puts e
end
end
begin
#puts nil + 10
puts 8/0
rescue S... | true |
0138b209c51778220496963f77e04a370526d768 | Ruby | benjino/TaskListTDD | /duedatetask.rb | UTF-8 | 348 | 2.875 | 3 | [] | no_license | require_relative 'task'
require_relative 'task_list'
class DueDateTask < Task
def initialize(year, month, day)
@due_date = Date.new(year, month, day)
end
def get_duedate
@due_date
end
def print_status
@status = ("Title: " + get_title.to_s + "Description: " + get_description.to_s + "Due Date: " + ... | true |
0a862276403636e6f320ba61db261aad52cb0423 | Ruby | dazuma/toys | /toys-core/test/lookup-cases/tool-subclasses/.toys.rb | UTF-8 | 875 | 2.640625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
class Foo < Toys::Tool
desc "description of foo"
def foo
exit 9
end
def run
foo
end
end
class FooBar < Toys::Tool
desc "description of foo-bar"
class Baz < Toys.Tool()
desc "description of foo-bar baz"
end
tool "qux" do
desc "description of foo-bar q... | true |
3544ad6ac19dcedd3b1732ba1694bbed1d04cc42 | Ruby | Stijns84/rails-longest-word-game | /app/controllers/words_controller.rb | UTF-8 | 1,653 | 2.671875 | 3 | [] | no_license | class WordsController < ApplicationController
def game
@grid = Array.new(9) { [*"A".."Z"].sample }
@start_time = Time.now
@number_of_games = session.fetch(:number_of_games, 0)
end
def score
@grid = params[:grid].split("")
@start_time = params[:start_time].to_datetime
@end_time = Time.now... | true |
d14ca95945f7095a309931dcb9a5ab8df5245f1b | Ruby | derrick-long/Launch_Projects | /odd-numbers/odd_numbers.rb | UTF-8 | 114 | 3.171875 | 3 | [] | no_license | numbers = (1..100).to_a
odd_numbers = numbers.select{|num| num % 2 == 1}
odd_numbers.each do |num|
puts num
end
| true |
3cf609559da7d4f420deb71a3de6ca6afcabe212 | Ruby | jingzhao-git/five_in_a_row | /player_move.rb | UTF-8 | 690 | 3.5 | 4 | [] | no_license | class Move
def player_move(player, grid)
# invalid = true
loop do
print "Player #{player} move (row,column):"
move = gets.chomp.split(',')
@row, @col = move.map { |element| element.to_i }
if invalid_move?(@row, @col, grid)
puts "Invali... | true |
0e6418857ea0edcf71e2f6b876b4f3279289de8c | Ruby | Jirles/oo-email-parser-v-000 | /lib/email_parser.rb | UTF-8 | 645 | 3.671875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Build a class EmailParser that accepts a string of unformatted
# emails. The parse method on the class should separate them into
# unique email addresses. The delimiters to support are commas (',')
# or whitespace (' ').
require 'pry'
class EmailParser
attr_accessor :emails
def initialize(list)
@emails... | true |
332d2e689677dfeb65920f6383baf2a3c5927be4 | Ruby | chris-groves/Boris-Bikes-Me | /lib/dockingstation.rb | UTF-8 | 987 | 3.203125 | 3 | [] | no_license | require_relative 'bike'
class DockingStation
attr_accessor :capacity, :docked_working_bikes, :docked_broken_bikes
DEFAULT_CAPACITY = 20
def initialize(capacity=DEFAULT_CAPACITY)
@docked_working_bikes = []
@docked_broken_bikes = []
@capacity = capacity
end
def release_bike
if empty?
r... | true |
e4045ae7ba7942c11c1c44f423ad78db00c035bb | Ruby | ogontaro/slender-ruby | /lib/slender/core_extensions/hash.rb | UTF-8 | 78 | 2.5625 | 3 | [] | no_license | class Hash
def slim_down
map { |k, v| [k, v.slim_down] }.to_h
end
end
| true |
58484aa4905869987740e732fe0291c8924170e7 | Ruby | jweissman/dragon | /lib/dragon/saga.rb | UTF-8 | 453 | 2.59375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | module Dragon
class Saga < Entity
include Events
def on(event)
raise "override EventListener#on(event) in subclass"
end
def receive(event)
if self.class.listening_for?(event.class) && is_relevant?(event)
on(event)
end
end
def is_relevant?(evt)
true
end
... | true |
7acc95fb22ac22b0ce4b2d173cb6f2ebcf113963 | Ruby | neobay991/Battle-1 | /lib/attack.rb | UTF-8 | 296 | 3 | 3 | [] | no_license | require_relative './player.rb'
class Attack
def initialize(player)
@player = player
end
# this class method runs and creates a new instance of this object. You could also use Attack.new
def self.run(player)
new(player).run
end
def run
@player.receive_damage
end
end
| true |
25986809ed6cf152178c58d8f3dd36d2b8a3a96d | Ruby | bluguja/ruby-objects-belong-to-lab-onl01-seng-pt-032320 | /lib/artist.rb | UTF-8 | 644 | 3.421875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | #require 'pry'
class Artist
attr_accessor :name, :songs, :artist_name
@@all = []
def initialize(name ="Michael Jackson")# set default value
@name = name
@songs = []
end
def self.all
@@all
end
def save
self.class.all << self
end
def self.find_by_name(artist_nam... | true |
3b86cbd89e477c7de3c62d6bb8a569fc9b7c758b | Ruby | distler/heterotic_beast | /vendor/plugins/brain_buster/lib/brain_buster_system.rb | UTF-8 | 4,758 | 2.78125 | 3 | [
"MIT"
] | permissive | require 'digest/sha2'
# Controller level system that actually does the work of creating and validating
# the captcha via filters, and also providing helpers for determining if the captcha was already
# passed or if a previous captcha attempt failed.
#
# This module gets mixed directly into ActionController::Base on ini... | true |
5ca2131b5cfe409961f6e9ef332ad81475f760bf | Ruby | jeflanne/learnruby | /album_program.rb | UTF-8 | 313 | 2.78125 | 3 | [] | no_license | require ("./albums.rb")
alb=Albums.new
chr=alb.studio_albums.sort
loop do
$stdout.write('Type albums: ')
@ans = $stdin.gets.chomp
break if @ans == "quit"
dfs=alb.studio_albums[@ans]
if @ans.match(/^\d+$/)
puts(dfs)
elsif @ans == "albums"
puts(chr)
end
#response=alb.chron
#end
end
| true |
af0e631a5a1d6682f9f6fbb12ecd2cb799cc49fe | Ruby | taroooyan/Atcoder-solved | /ABC/010/b.rb | UTF-8 | 239 | 3.203125 | 3 | [] | no_license | # -*- coding: utf-8 -*-
n = gets.to_i
leaf = gets.split.map(&:to_i)
sum = 0
leaf.each do |l|
if l%2 == 0
sum += 1
l -= 1
end
if l%3 == 2
sum += 1
l -= 1
end
if l%2 == 0
sum += 1
l -= 1
end
end
puts sum
| true |
efa606dfb5c620a2eb0d80d0f70f71a9c2b16a60 | Ruby | giniedp/fancy_tools | /lib/fancy_tools/icon_helper.rb | UTF-8 | 4,796 | 2.71875 | 3 | [] | no_license | require "active_support/ordered_hash"
module FancyTools
# Provides helper methods that help writing image tags in a shorter and more efficient command.
# NOTE: this image tag spits out an image with a transparent pixel. The styling must be done in the css depend in the class attribute
module IconHelper
... | true |
dd788a6b3f403d2fcebd1b9eed0de0c458ad21fc | Ruby | EricRicketts/LaunchSchool | /exercises/Ruby/small_problems/easy/two/sixth_exercise.rb | UTF-8 | 506 | 3.5625 | 4 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require 'byebug'
class SixthExercise < Minitest::Test
=begin
Odd Numbers
Print all odd numbers from 1 to 99, inclusive.
All numbers should be printed on separate lines.
=end
def get_odds(num)
num.odd? ? (1..num).step(2).to_a : (1...num).step(2).to_a
end
... | true |
55321341564b13ec14e61374b1548513ce0a7cb0 | Ruby | rvedotrc/numbers | /spec/tree-to-string_spec.rb | UTF-8 | 1,218 | 3.03125 | 3 | [] | no_license | require 'numbers'
describe Numbers::TreeToString do
it "should handle a number" do
input = 7
actual = Numbers::TreeToString.to_string input
expect(actual).to eq("7")
end
it "should handle addition" do
input = { type: :+, positive: [6,5,4], negative: [3,2,1], value: 9 }
actual = Numbers::Tre... | true |
8eefeedfb5bef741050ec1c0d19349a0c6a8a28a | Ruby | Dav-Ho/angularjs-intro-app- | /employee/manager.rb | UTF-8 | 493 | 2.890625 | 3 | [] | no_license |
class Manager < Employee
include EmailReporter
def initialize(input_options)
super(input_options)
@employees = input_options[:employees]
end
def give_all_raises
@employees.each do |employee|
employee.give_annual_raise
end
end
def same_method
super
#puts "something"
end
... | true |
f9232db308e726588459edc55b3dc213161ce3b1 | Ruby | pasberth/lang_aptitude_test | /practice/sample.rb | UTF-8 | 2,921 | 3.375 | 3 | [] | no_license | # -*- coding: utf-8 -*-
###################################################################################################
#
# ちゅーんさんの色々と出来の悪い模範解答
# Rubyマトモに書くの初めてだから、テキトーな事しててもゴメンしてちょ
#
###################################################################################################
# 使用するライブラリの読み込み
require 'readl... | true |
a67b0be88e7cefd4551a0e7a4093dc63c7be27ef | Ruby | stip/vcardio | /lib/vcardio/parser/line_parser.rb | UTF-8 | 487 | 2.609375 | 3 | [
"MIT"
] | permissive | module VCardio
module Parser
#
# @private
#
class LineParser
def self.call(content_line)
parts = content_line.split(':', 2)
group = VCardio::Parser::GroupParser.call(parts[0])
name = VCardio::Parser::NameParser.call(parts[0])
params = VCardio::Parser::ParamPar... | true |
e2c7d985bee9cbcaa3875836a606c0b9059e9c3e | Ruby | yoshida-eth0/ruby-synthesizer | /jupyter/buffer_player.rb | UTF-8 | 1,028 | 2.546875 | 3 | [
"MIT"
] | permissive | class BufferPlayer
def initialize(soundinfo, id=nil, level: 0.0)
id ||= "tmp_#{Time.now.to_f.to_s.sub('.', '_')}"
@path = "output_#{id}.wav"
@sound = RubyAudio::Sound.open(@path, "w", soundinfo)
@a_gain = AudioStream::Fx::AGain.new(level: level)
end
def write(buffers)
[buffers].flatten.compac... | true |
6b8e175403689e369a7331ac0091cfc81e03e345 | Ruby | johnram528/activerecord-validations-lab-v-000 | /app/models/post.rb | UTF-8 | 1,888 | 2.859375 | 3 | [] | no_license | class Post < ActiveRecord::Base
validates :title, presence: true
validates :content, length: { minimum: 250}
validates :summary, length: { maximum: 250}
validates :category, inclusion: { in: %w(Fiction Non-Fiction)}
validate :clickbait?
end
def clickbait?
if [/(top)+\d/i, /won't believe/i, /secret guess/i]... | true |
c6cafdd49fb4490e93413d62f300f758cae8311b | Ruby | alexdowad/bit-twiddle | /spec/lshift_spec.rb | UTF-8 | 2,018 | 2.96875 | 3 | [
"LicenseRef-scancode-public-domain",
"CC0-1.0"
] | permissive | [[:lshift8, 8], [:lshift16, 16], [:lshift32, 32], [:lshift64, 64]].each do |method, bits|
describe "##{method}" do
bitmask = (1 << bits) - 1
it "shifts bits in a #{bits}-bit number to the left (but cuts off high bits)" do
100.times do
num = rand(1 << bits)
bnum = rand(1 << 100)
... | true |
ed7533ae03e864d0d431db9a25cc58bdb865d078 | Ruby | arthurstomp/pat | /db/seeds.rb | UTF-8 | 1,199 | 2.6875 | 3 | [] | no_license | def log_persisted(m)
if m.persisted?
logger.info "Created #{m}"
else
logger.error m.errors.messages
raise "Error on seeding #{m}"
end
end
def create_companies(user, other_user)
c1 = FactoryBot.create(:company, user: user)
admin = c1.departments.create name: "Admin"
sales = c1.departments.create... | true |
d72b8403c864ce86173697186d06d717f3366628 | Ruby | sarahabimay/TicTacToe_Gem | /lib/tictactoe/board.rb | UTF-8 | 3,517 | 3.40625 | 3 | [] | no_license | require 'enumerator'
require "tictactoe/mark"
module TicTacToe
class Board
attr_reader :board_size, :board_cells, :dimension
ZERO_INDEX_OFFSET = 1
LOWER_INDEX_LIMIT = 1
def initialize(dimension, cells = [])
@dimension = dimension
@board_size = dimension * dimension
@board_cells = ... | true |
dbd0b0a5087d8e7604ce4dfcafe2b676664ab4dc | Ruby | joaomarceloods/godesk_api | /app/models/user.rb | UTF-8 | 1,336 | 2.703125 | 3 | [] | no_license | # == Description
#
# Base model for all types of users.
# It has a username and authenticates with a password.
#
# This class should not be instantiated directly.
# Instead, one of its subclasses should be used.
#
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key... | true |
082274096dffd3d75d67b0878d52ab8736902a08 | Ruby | shloksoni/rails-citly | /app/models/url.rb | UTF-8 | 595 | 2.578125 | 3 | [] | no_license | class Url < ApplicationRecord
enum status: { unpinned: 0, pinned: 1 }
validates :url, presence: true, format: { with: URI.regexp }
validates :shortened, presence: true, length: { is: 6 }
private
def self.to_csv
attributes = %w{url shortened clicks}
CSV.generate(headers: true) do |csv|
csv... | true |
8f2dcd23edc4d9e8a728c6f7da70c0349b3eedb7 | Ruby | akr/tb | /lib/tb/headerreader.rb | UTF-8 | 3,367 | 2.90625 | 3 | [
"BSD-3-Clause"
] | permissive | # lib/tb/headerreaderm.rb - reader mixin for table with header
#
# Copyright (C) 2014 Tanaka Akira <akr@fsij.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the... | true |
36761e67557ccf6d54eb67ef03c7eab4ae59372d | Ruby | dehawkins/ruby_challenges | /refact1.rb | UTF-8 | 1,183 | 4.34375 | 4 | [] | no_license | # Always Threes
# - De Hawkins
puts "_____________________________________________"
puts "-"
puts "- Always Three Program"
puts "-"
puts "_____________________________________________"
# Ask the user to “Give me a number:”
print " Give me a number ? "
STDOUT.flush
# Grab that number and transform i... | true |
7b87666f473e3cae73e78615b9b8af9c5fce1e3e | Ruby | loganwohlers/NBA_RAILS_BACKEND | /app/controllers/seasons_controller.rb | UTF-8 | 674 | 2.671875 | 3 | [] | no_license | class SeasonsController < ApplicationController
def index
render json: Season.all.order(year: :asc)
end
#uses query string params to decide which class methods to return. as games belong to a season we can simply call season.games. if we want player averages we use the filter_player_seasons c... | true |
6b5397e3749c7922d5a5641d5351f0af82b00a5a | Ruby | inigotorres/polygons | /side.rb | UTF-8 | 181 | 3.140625 | 3 | [] | no_license | class Side
attr_reader :length
def initialize length
@length = length
raise 'Side length must be positive' unless valid?
end
def valid?
@length > 0
end
end
| true |
6b15fa764ffda849b3eb0b68dfe1081e5eb659de | Ruby | jackcasey/derelict | /spec/derelict/room_spec.rb | UTF-8 | 988 | 2.703125 | 3 | [] | no_license | require 'spec_helper'
module Derelict
describe Room do
let(:b){ Room.new("A Basement") }
it "should be able to be named" do
b.name.should == "A Basement"
end
it "should remember events" do
b.event( Event.new("An event happens.") )
b.events.should include Event.new("An ev... | true |
84bef108f35cf47f769c4b3768afff5663861cd7 | Ruby | carlkrause/phase_0_unit_2 | /week_5/4_boggle_board/my_solution.rb | UTF-8 | 4,253 | 4.8125 | 5 | [] | no_license | # U2.W5: A Nested Array to Model a Boggle Board
# I worked on this challenge with Catherine Farkas.
boggle_board = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
# Part 1: Access multiple elements of a nested array
# Pseudoco... | true |
8b2fd5c103a0009ee8941b4013c2665485d18776 | Ruby | jimcegelski/HudsonSC | /Haiku Review/spec/haiku_spec.rb | UTF-8 | 1,130 | 2.921875 | 3 | [] | no_license | require 'rspec'
require_relative '../lib/haiku_review'
describe HaikuReview do
it 'should return yes if it has three lines' do
expect(subject.review('one/two/three')).to eq('yes')
end
it 'should return no if it has less than three lines' do
expect(subject.review('one/two')).to eq('no')
end
it 'sho... | true |
813d034656878a76d10201b2ed311d622d8291ad | Ruby | chef/chef | /spec/unit/run_list_spec.rb | UTF-8 | 10,623 | 2.546875 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #
# Author:: Adam Jacob (<adam@chef.io>)
# Author:: Seth Falcon (<seth@chef.io>)
# Author:: Christopher Walters (<cw@chef.io>)
# Copyright:: Copyright (c) Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in ... | true |
e832244db415f8595c89170a84e6ff9aedff408a | Ruby | NarayanConnor/w4d2 | /chess/null_piece.rb | UTF-8 | 351 | 3.0625 | 3 | [] | no_license | require 'singleton'
require_relative "piece"
class NullPiece<Piece
include Singleton
attr_reader :color, :symbol
def initialize
@color = nil
@symbol = nil
end
def move
raise "NP.move not implemented"
end
def symbol
raise "NP.symbol not i... | true |
7590cab9c44264ff3f054720c88c9207ac7e4ca8 | Ruby | a-abdellatif98/simple_recommender | /lib/simple_recommender/recommendable.rb | UTF-8 | 3,087 | 2.53125 | 3 | [
"MIT"
] | permissive | module SimpleRecommender
module Recommendable
extend ActiveSupport::Concern
DEFAULT_N_RESULTS = 10
SIMILARITY_KEY = "similarity" # todo: allow renaming to avoid conflicts
AssociationMetadata = Struct.new(:join_table, :foreign_key, :association_foreign_key)
module ClassMethods
def similar_by... | true |
f81adbdd51bd95970f1be024e6ab026bf3d0e9ca | Ruby | hayamiz/gluent | /scripts/adduser | UTF-8 | 926 | 2.78125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'yaml'
require 'digest/sha1'
require 'io/console'
config_dir = File.expand_path("../config", __dir__)
passwd_file = File.expand_path("passwd", config_dir)
if File.exists?(passwd_file)
passwd_data = YAML.load(File.read(passwd_file))
else
passwd_data = []
end
puts("** Adding new user *... | true |
e69406835d9c5364a361193461896622658f6f9e | Ruby | DannyCrews/programming-test | /ex4/ecosystem.rb | UTF-8 | 769 | 3.75 | 4 | [] | no_license | #!/usr/bin/ruby
require_relative 'earth'
require_relative 'food'
require_relative 'animals'
# Lets make some food
lasagna = Food.new("lasagna")
steak = Food.new("steak")
kibble = Food.new("kibble")
mouse = Food.new("mouse")
# Let's make some animals
jon = Animals::Human.new
garfield = Animals::Cat.new
odie = Animals... | true |
a17dd49d859c65d6f27f88b325ab9191c81a0715 | Ruby | stefanverhoeff/euler | /ruby/test/problem12_tests.rb | UTF-8 | 4,353 | 3.15625 | 3 | [] | no_license | require 'test/unit'
require 'problem12.rb'
class TC_MyPrimeTest < Test::Unit::TestCase
# def setup
# end
# def teardown
# end
def test_prime?
assert_equal(true, prime?(3))
assert_equal(true, prime?(5))
assert_equal(false, prime?(21))
assert_equal(true, prime?(23))
ass... | true |
e0aeb1214a140fc336dde9555b8dc35e45b72301 | Ruby | mtdowd/Metis-Prework | /grandma1.rb | UTF-8 | 326 | 3.609375 | 4 | [] | no_license | puts 'You\'re grandmother is here. Say something to her!'
response = gets.chomp
while response != 'BYE'
if response == response.upcase
num = rand(21)
year = 1930 + num
puts 'NO, NOT SINCE ' + year.to_s + '!'
response = gets.chomp
else
puts 'HUH?! SPEAK UP, SONNY!'
response = gets.chomp
en... | true |
0221fec6800cdcebbf6c7b3774c18678f7e12c19 | Ruby | BradenLawrence/la-challenges | /tracking-donations/code.rb | UTF-8 | 816 | 3.4375 | 3 | [] | no_license | # PART 1
donations = 0
goal = 100
puts "Howdy folks, Crazy Ned's Discount Space Travel Agency has a lot of " +
"unaccounted expenses for things like 'legal fees' and 'explosions'.\n" +
"So to help ends meet, we are having a bake sale! One cupcake for each " +
"donation, amount doesn't matter!\nYou... | true |
4cd433b6bbc7d568828e8f0ed73bd73dfec3c4b3 | Ruby | cesarediaz/moviesstaff-api | /app/services/staff_service.rb | UTF-8 | 876 | 2.75 | 3 | [] | no_license | class StaffService
def initialize(movie, params)
@movie = movie
@params = params
end
def call
delete_staff_for_movie
set_staff_for_movie
end
private
def delete_staff_for_movie
ActiveRecord::Base.connection.execute <<-SQL.squish
DELETE FROM movies_people
WHERE movie_id=#{@m... | true |
c0bdf8dff3f60913e5eb349dddef6966cc574ac6 | Ruby | soufiane121/school-domain-nyc-clarke-web-100719 | /lib/school.rb | UTF-8 | 511 | 3.609375 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class School
def initialize(name)
@name = name
@roster = Hash.new {|k,v| k[v] = []}
end
def roster
@roster
end
def add_student(name, number)
@roster[number] << name
end
def grade(grad_level)
@roster[grad_level]
end
def sor... | true |
21a68b0e2116f79d2d4c1c9d257d4a121fd316a8 | Ruby | burtlo/ruby-metrics-core | /lib/ruby-metrics/statistics/exponential_sample.rb | UTF-8 | 1,932 | 2.96875 | 3 | [
"MIT"
] | permissive | module Metrics
module Statistics
class ExponentialSample
RESCALE_WINDOW_SECONDS = 60 * 60 # 1 hour
def initialize(size = 1028, alpha = 0.015)
@size = size
@alpha = alpha
clear
end
def clear
@values = { }
@start_time = tick
... | true |
86c6b2de67861a2ac12b561a1ba439641f28f71e | Ruby | shiiizuuukaaa/furima-33391 | /spec/models/user_spec.rb | UTF-8 | 4,832 | 2.5625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
before do
@user = FactoryBot.build(:user)
end
describe 'ユーザー新規登録' do
context 'ユーザーの新規登録ができる時' do
it '全ての項目が存在すれば登録できる' do
expect(@user).to be_valid
end
end
context 'ユーザーの新規登録ができない時' do
it 'ニックネームが空だと登録できない' do... | true |
771813010eef51b92a4fa6fa46112ae882a85d40 | Ruby | arrayoutofbounds/ruby_tutorials | /read_file.rb | UTF-8 | 305 | 3.640625 | 4 | [] | no_license | filename = ARGV.first
# returns a file object from the name given
txt = open(filename)
puts "Here is your file #{filename}"
# call the read function on the file object
print txt.read
print "Type the filename again: "
file_again = $stdin.gets.chomp
txt_again = open(file_again)
print txt_again.read
| true |
2e670f7e46df7246450297405ba0fa06ba9cf50a | Ruby | hoshito/AtCoder | /エイシング プログラミング コンテスト 2020/main_c.rb | UTF-8 | 179 | 3.15625 | 3 | [] | no_license | n,k = gets.chomp.split(" ").map(&:to_i)
a_arr = gets.chomp.split(" ").map(&:to_i)
0.upto(n-k-1) do |i|
if a_arr[i] < a_arr[k + i]
puts "Yes"
else
puts "No"
end
end
| true |
07550fefdd4e06311e76e96149f9abb6abf4b3fe | Ruby | ljackson96/programming-univbasics-3-labs-with-tdd-austin-web-030920 | /calculator.rb | UTF-8 | 1,121 | 4.09375 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # Add your variables here
=begin
The first test we've started to solve already. The test is looking for a
variable in `calculator.rb`, `first_number`. This variable should be set to
an integer or float
- The second test is similar, but this time, looking for `second_number`.
However, there is a second test her... | true |
b3056d9d49b25f4ce09fff587b649d8138cc1a10 | Ruby | violetaria/samplserv | /lib/samplserv.rb | UTF-8 | 3,124 | 2.578125 | 3 | [
"MIT"
] | permissive | require "samplserv/version"
require "sinatra/base"
require "pry"
module Samplserv
class App < Sinatra::Base
set :logging, true
get "/" do
"Welcome to Samplserv!"
end
post "/beat" do
spawn("afplay \"samples/beat.mp3\"")
"playing music..."
end
post "/better" do
versio... | true |
2d01320eac2c9d4f4e069b2b0ce65d769a78d966 | Ruby | manuuzkudun/cookbook-sinatra | /app/controller.rb | UTF-8 | 507 | 2.625 | 3 | [] | no_license | require_relative 'recipe'
class Controller
def initialize(cookbook)
@cookbook = cookbook
end
def list
recipe_list.all
end
def create
name = @view.ask_user_for_recipe_name
description = @view.ask_user_for_recipe_description
recipe = Recipe.new(name, description)
recipe_list.add_reci... | true |
70a13fdcac31a17bede3fbdccc360f8dc0027c19 | Ruby | BradleyTesterSpratt/RubyTextAdv | /lib/parser.rb | UTF-8 | 589 | 3.109375 | 3 | [] | no_license | require_relative 'command_word'
class Parser
def call(string)
#return hash commands => [], params => use .each_with_object
commands = []
params = []
string.downcase.split(" ").each { |word| CommandWord.new.call(word.to_s) ? commands << word : params << word }
commands.empty? ? nil : [commands.u... | true |
e6139d679fb3dde1361e79410b63bff24e9db26c | Ruby | rsanheim/braincron | /vendor/gems/chatterbox-0.3.3/examples/lib/chatterbox/notification_example.rb | UTF-8 | 5,912 | 2.59375 | 3 | [
"MIT"
] | permissive | require File.expand_path(File.join(File.dirname(__FILE__), *%w[.. .. example_helper]))
describe Chatterbox::Notification do
before do
Chatterbox.logger = Logger.new(nil)
end
describe "creating the notice" do
it "should safely handle nil" do
lambda {
Chatterbox::Notification.new(nil).noti... | true |
0605733f40251e580ba843439502fa34fdc7a414 | Ruby | Archeia/iek | /lib/iek/core_ext/object.rb | UTF-8 | 534 | 2.984375 | 3 | [] | no_license | class Object
##
# Uses Marshal to create a perfect copy of the object
# This does mean that, unmarshallable object will fail.
# @return [Object]
def marshal_clone
Marshal.load(Marshal.dump(self))
end unless method_defined? :marshal_clone
def presence
self || nil
end
def blank?
presence ?... | true |
5909289332d3371a2a5d6eb616f8a61587d0039f | Ruby | mattsroufe/scrabble | /spec/scrabble/word_spec.rb | UTF-8 | 2,227 | 3.453125 | 3 | [] | no_license | require 'spec_helper'
describe Word do
let(:hi) { Word.new('hi') }
let(:home) { Word.new('home') }
let(:ward) { Word.new('ward') }
let(:word) { Word.new('word') }
let(:hello) { Word.new('hello') }
let(:sound) { Word.new('sound') }
let(:silence) { Word.new('silence') }
describe ".new" do
... | true |
622c87ac65b0a9173d951a371428f4902c6094a8 | Ruby | henryk1229/dunder-mifflin-rails-review-nyc-web-career-042219 | /app/models/employee.rb | UTF-8 | 358 | 2.578125 | 3 | [] | no_license | class Employee < ApplicationRecord
validates :first_name, presence: true
validates :last_name, presence: true
validates :alias, uniqueness: true, if: :none?
belongs_to :dog
def none?
self.alias != 'none' ? true : false
end
#validates uniqueness of conditions where
def full_name
"#{self.first_... | true |
8a7639fb98c878d83436b8f488bc047fb0c7af7b | Ruby | leadurand/shipstar | /app/models/booking.rb | UTF-8 | 1,029 | 2.796875 | 3 | [] | no_license | class Booking < ApplicationRecord
belongs_to :user
belongs_to :ship
validates :start_at, presence: true, :uniqueness => { :scope => [:end_at, :start_at] }
validates :end_at, presence: true, :uniqueness => { :scope => [:end_at, :start_at] }
validates :ship_id, presence: true
validates :user_id, presence: tru... | true |
ff8dc24ec6222420a16950e36e1916ca9c7c5971 | Ruby | jglass/vet_clinic | /patient.rb | UTF-8 | 161 | 2.84375 | 3 | [] | no_license | class Patient; end
class Cat < Patient
def initialize(name)
@name = name
end
end
class Dog < Patient
def initialize(name)
@name = name
end
end
| true |
34d286c689d1f7815c321d5b774edd6ecef69c1b | Ruby | SirFlickka/ruby-cli-adventure | /spec/map_spec.rb | UTF-8 | 2,034 | 3.078125 | 3 | [] | no_license | # frozen_string_literal: true
require_relative '../map.rb'
RSpec.describe Map do
describe '.new' do
context 'valid arguments' do
it 'returns a new Map' do
map = Map.new(4, 4)
expect(map).to be_an_instance_of(Map)
end
end
end
describe '#place_room' do
let(:map) { Map.new... | true |
20cb313ca59d495f4ae0ae4f1f4f58ba2ed71163 | Ruby | AntonyBaasan/ruby-algorithms | /test/sort/test_quicksort.rb | UTF-8 | 648 | 3.03125 | 3 | [] | no_license | require 'minitest/autorun'
require_relative '../../src/sort/quick_sort'
class TestQuickSort < MiniTest::Test
def setup
end
# def test_sort_can_accept_only_array
#
# end
def test_sort_array_1
arr1 = [5, 4, 3]
resultArray = Sort::QuickSort.sort(arr1)
assert_equal(resultArray, [3, 4, 5])
en... | true |
67d0a399cefa9e445eab1a8fae32673b2e98ae75 | Ruby | sail-boat/WebScraping | /chkNotContributed.rb | UTF-8 | 1,711 | 3.28125 | 3 | [] | no_license | require 'open-uri'
require 'nokogiri'
# スクレイピング習作
# 投稿日から削除対象アカウントか判定
# 参考
# Nokogiri http://d.hatena.ne.jp/takeR/20140901/1409604244
# Nokogiriその2 http://morizyun.github.io/blog/ruby-nokogiri-scraping-tutorial/#7
# Nokogiri その3 http://d.hatena.ne.jp/otn/20090509/p1
def is_deleteTarget(url)
charset = nil
begin
... | true |
a19f7a9370c273b83fb83465853d12eab0c9e385 | Ruby | jkbrookover/dealership | /dealership/salespeople.rb | UTF-8 | 863 | 4.09375 | 4 | [] | no_license | ###Create a source file for Salespeople###
class Salesperson
###initialize variables within salesperson class###
attr_accessor :sales
def initialize(name, goal=10, sales)
@name = name
@goal = goal
@sales = sales
end
###create a formula function to calculate sales needed to meet each pers... | true |
7705fde3cfe2c0a3d5c2874e5b5839b485a83ce0 | Ruby | rennanoliveira/bnb_analyzer | /app/models/nyc_data/filter.rb | UTF-8 | 976 | 2.609375 | 3 | [] | no_license | module NYCData
class Filter
ACTIVE = 1
EXPIRED = 2
def initialize(params)
@page = set_page(params[:page])
@boro = params[:boro]
@geocode = params[:geocode]
@situation = params[:situation]
end
def dwellings
@dwellings ||= base_query.page(page)
end
def boros... | true |
e3a9456772376d0da8a7b1bf5acd2e3f3f9bccbd | Ruby | mschuerig/picture_frame | /lib/picture_frame.rb | UTF-8 | 727 | 2.953125 | 3 | [
"MIT"
] | permissive | require 'picture_frame/version'
require 'picture_frame/frame'
require 'picture_frame/predefined'
module PictureFrame
class << self
def create(frame_spec = nil, options = {})
case frame_spec
when String
template = frame_spec
when :random
template = Predefined.random
when S... | true |
a518a7790f95831f61287d6dad7f53e2dad9fe98 | Ruby | NEvans85/algorithms | /hacker_rank/cracking_the_coding_interview/data_structures/arrays:left_rotation.rb | UTF-8 | 230 | 3.40625 | 3 | [] | no_license | # prompt: https://www.hackerrank.com/challenges/ctci-array-left-rotation/problem
n,k = gets.strip.split(' ')
n = n.to_i
k = k.to_i
a = gets.strip
a = a.split(' ').map(&:to_i)
k.times do
a.push(a.shift)
end
puts a.join(" ")
| true |
2aa27ef8694a90ade0bb84938e70975d64197bca | Ruby | mvdiener/chipot | /db/seeds.rb | UTF-8 | 1,327 | 2.640625 | 3 | [
"MIT"
] | permissive | # This file contains all the record creation needed to seed the database from the data of city of chicago.
# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup).
class Seeder
def self.seed
(DateTime.new(2014,7,1).to_date..(DateTime.yesterday)).each do |d|
puts "THI... | true |
f525b72f0c4d2fb7679fcc294612700448248b9e | Ruby | nikkiricks/word-count | /word_count.rb | UTF-8 | 202 | 3.15625 | 3 | [] | no_license | class Phrase
def initialize(phrase)
@phrase = phrase
end
def word_count
@phrase.downcase.scan(/\w+'?\w|\w/).each_with_object(Hash.new(0)) { |word, count| count[word] += 1}
end
end
| true |
a421db240b9f8fe89c834ea2ac9abd2ba53434cd | Ruby | cfcosta/event_emitter | /samples/timer.rb | UTF-8 | 413 | 2.984375 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
$:.unshift File.expand_path '../lib', File.dirname(__FILE__)
require 'event_emitter'
class Timer
include EventEmitter
def start(sec, count)
count.times do
sleep sec
emit :tick
end
emit :end
end
end
timer = Timer.new
timer.on :tick do
puts Time.now
end
timer.once ... | true |
fe2e8e68db629e92a367ed2e3374a073cecd0543 | Ruby | jamalbran/desafio-flujo | /emprendedor1.rb | UTF-8 | 303 | 2.734375 | 3 | [] | no_license | precio = ARGV[0].to_i
usuarios = ARGV[1].to_i
gastos = ARGV[2].to_i
utilidades = precio * usuarios - gastos
if utilidades.positive?
utilidades *= 0.65
puts "Las utilidades depues de impuestos son $ #{utilidades}"
else
puts "Las utilidades son $ #{utilidades}, por lo que no pagan impuestos"
end
| true |
8b44dbdd1b1fb9c5cf483cc9fee34cd920370046 | Ruby | felixprograms/ruby-exercises | /mythical-creatures/lib/pirate.rb | UTF-8 | 395 | 2.9375 | 3 | [] | no_license | class Pirate
def initialize(name, job='Scallywag')
@name = name
@poi = 0
@job = job
@booty = 0
end
def name
@name
end
def job
@job
end
def commit_heinous_act
@poi += 1
end
def cursed?
@poi >= 3
end
def b... | true |
7dc7c880ac42e0de7d20d187a0779cf9dbc43777 | Ruby | tbui468/tealeaf-prep | /companion_workbook/intermediate_questions/quiz_1.rb | UTF-8 | 3,213 | 3.65625 | 4 | [] | no_license | #1
10.times { |i| puts " "*i + "The Flintstones Rock!" }
# book solution: 10.times { |i| puts "The Flintstones
# Rock!".rjust(21 + i) }
# 21 is the length of the sentence
#2
statement = "The Flintstones Rock"
statement = statement.delete(" ")
letter_hash = {}
statement.each_char do |letter|
if letter_hash.... | true |
c1b47cdf2d4c1665ea8881a161ae716aa3609626 | Ruby | sparsons808/W4D5 | /two_sum.rb | UTF-8 | 843 | 3.75 | 4 | [] | no_license | # def two_sum?(arr, target_sum) 0(n^2)
# arr.each_with_index do |num_1, idx_1|
# arr.each_with_index do |num_2, idx_2|
# if num_1 + num_2 == target_sum && idx_1 < idx_2
# return true
# end
# end
# end
# false
# end
def okay_two_sum?(arr, target_sum)
... | true |
30bea7bf16142ef63a6dda246bbb3f884db0b4aa | Ruby | ramortegui/sudoku-validator | /lib/validator.rb | UTF-8 | 249 | 2.78125 | 3 | [] | no_license | class Validator
def initialize(puzzle_string)
@puzzle_string = puzzle_string
end
def self.validate(puzzle_string)
new(puzzle_string).validate
end
def validate
sudoku = Sudoku.new(@puzzle_string)
sudoku.validate
end
end
| true |
d58291d3ab6b21da9316b1b6c389b2445ee10791 | Ruby | stan761/kanzapanoid | /lib/tilemap.rb | UTF-8 | 2,669 | 3.03125 | 3 | [] | no_license | module Tiles
Grass = 0
Earth = 1
end
class Map
attr_reader :width, :height, :gems
attr_accessor :window
def initialize(window, filename)
@window = window
@space = window.space
# Load 60x60 tiles, 5px overlap in all four directions.
@tileset = Image.load_tiles(window, "media/CptnRuby Tileset.png", 60, 60... | true |
259c82865036d2e9c27db4f09821aff6f07acb7a | Ruby | graywh/ccsc-se-contest | /1995/5/2-5.rb | UTF-8 | 794 | 3.640625 | 4 | [] | no_license | #!/usr/bin/env ruby
def getOne(n)
n % 10
end
def getTen(n)
(n % 100) / 10
end
def getHund(n)
n / 100
end
count = 1
STDIN.each_slice(2) do |act, line|
act.strip!
line.strip!
print "Message #{count} (#{act}d): "
case act
when "encode"
code = []
line.length.times do |i|
ch = line[i]... | true |
6001f8e673ed23187897c78b9fd9a73101693a12 | Ruby | acookson91/checkout-with-promotions | /lib/checkout.rb | UTF-8 | 1,073 | 3.15625 | 3 | [] | no_license | require_relative 'product_list'
require_relative 'basket'
require_relative 'multi_discount'
require_relative 'percentage_discount'
class Checkout
def initialize(promotional_rules = [], product_list = ProductList.new,basket = Basket.new)
@product_list = product_list
@basket = basket
@promotional_rules = ... | true |
e125b2fa456ee4c19b6c27e17680bf6ad75eda5f | Ruby | joelim01/flatiron-store-project-v-000 | /app/models/cart.rb | UTF-8 | 575 | 2.640625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Cart < ActiveRecord::Base
belongs_to :order
belongs_to :user
has_many :line_items
has_many :items, through: :line_items
def total
total_array = self.line_items.collect do |l_item|
l_item.item.price * l_item.quantity
end
total = total_array.inject 0, :+
# number_to_currency(total,... | true |
9df68e0ea6c7f238b9e177aa22f9ead983cf59c5 | Ruby | Zlatov/lab | /rails/task/task.rake | UTF-8 | 2,630 | 2.734375 | 3 | [] | no_license | # Rails.root/lib/tasks/temp.rake:
#
# Посмотреть список задач:
# `rails -T` - у которых есть описание
# `rails -P` - все
# `rails -T -A` - все с описанием
#
# Создать задачи генератором
rails g task closure_tree rebuild
# Данный код в начале Задач позволяет использовать метаданные задач, такие как имя, описани... | true |
595428ddb64cd64942affbbf66adf7416fc97d66 | Ruby | CoolElvis/gt06_server | /lib/gt06_server/messages/gps_information.rb | UTF-8 | 1,299 | 2.640625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
module Gt06Server
module Messages
class GpsInformation < BinData::Record
# GPS Information
# Date Time 6 0x0B 0x08 0x1D 0x11 0x2E 0x10
# Quantity of GPS information satellites 1 0xCF
# Latitude 4 0x02 0x7A 0xC7 0xEB
# Longitude 4 0x0C 0x46 0x58 ... | true |
23f01e5c2aafb8d8e1d3a6f26cb76f412dcf5d83 | Ruby | garyeh/projects | /chess/display.rb | UTF-8 | 840 | 3.375 | 3 | [] | no_license | require_relative 'board'
require_relative 'cursor'
require 'colorize'
class Display
attr_reader :board, :cursor
def initialize(board)
@board = board
@cursor = Cursor.new([0,0], board)
end
def render
puts " 0 1 2 3 4 5 6 7"
board.grid.each_with_index do |row,row_idx|
print "#{row_idx} "... | true |
8c72b3860f25fcdba6204460f797e2a0fbb960e5 | Ruby | TheVaigr/Projet_04 | /Classes/Ennemis/bomber.rb | UTF-8 | 808 | 2.75 | 3 | [] | no_license | require_relative 'ennemi'
class Bomber < Ennemi
attr_accessor :distanceX, :distanceY
def initialize(image = Gosu::Image.new("../Ressources/enemie_4_fighter_N.png"),
degatCollision = 30,
degatTir = 100,
vie = 150,
vitesseDeplacement = 100,
... | true |
b32b96b2396eeb427cdc23cc8e02efb4b9c075cd | Ruby | CeMuPaMuDa/RubyP2 | /lesson5_vera/1_say.rb | UTF-8 | 172 | 3.015625 | 3 | [] | no_license | # frozen_string_literal: true
require_relative 'lib/hello'
say1 = Hello.new('world')
say2 = Hello.new('Vera')
say3 = Hello.new('Igor')
puts say1.say, say2.say, say3.say
| true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.