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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
e248bd58d8ae4f3a15ea2d577820b61dccbda468 | Ruby | DouglasAllen/gem-astro-calc | /lib/astro_calc/telescopes.rb | UTF-8 | 3,952 | 3.359375 | 3 | [
"MIT"
] | permissive |
# Credits
# {http://www.nexstarsite.com/_RAC/articles/formulas.htm Mike Swanson}
class Telescopes
MM_IN_INCH = 25.4
RAYLEIGH_LIMIT = 5.5
DAWES_LIMIT = 4.56
UNIT_MILLIMETERS = :millimeters
UNIT_INCHES = :inches
attr_accessor :unit
def initialize(unit = UNIT_MILLIMETERS)
@unit = unit
... | true |
1dcb9c3f0863d8e3a092dedbbc8d82798e853e90 | Ruby | Lampost42/oo-cash-register-v-000 | /lib/cash_register.rb | UTF-8 | 726 | 3.390625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
class CashRegister
attr_accessor :total, :discount, :items, :last_t
def initialize(discount = 0)
@total = 0
@discount = discount
@items = []
end
def add_item(title, price, quantity = 1)
quantity.times {|i| self.items << title}
self.total += price * quantity
self.las... | true |
3d0eafad6d95ec7c52ee886b22da9d408d5f7e95 | Ruby | PatrickMayoMoran/ruby-book | /01_basics/exercises.rb | UTF-8 | 659 | 4.15625 | 4 | [] | no_license | # 1
"Patrick " + "Moran"
# 2
n = 4167
# digit in ones place
puts n % 10
# digit in tens place
puts n / 10 % 10
# digit in hundreds place
puts n / 100 % 10
# digit in thousands place
puts n / 1000
# 3
my_movies = {
Lion_King: 1993,
Gattaca: 2005,
It_s_a_Wonderful_Life: 1939
}
puts my_movies[:Lion_King]
puts my... | true |
8524029313498cb41af3e6e135c6dd3902e54e2d | Ruby | mannakub1/cms | /app/models/api_key.rb | UTF-8 | 538 | 2.53125 | 3 | [] | no_license | class ApiKey < ApplicationRecord
before_create :generate_access_token
before_create :set_expiration
belongs_to :member
def expired?
DateTime.now.utc >= self.expires_at
end
def expired
self.expires_at = DateTime.now.utc
end
private
def generate_access_token
... | true |
94053f4f62d8b2a1ee7da0b4e7e9dbc13fd538ea | Ruby | User4574/Advent-of-Code-2017 | /day11/part2 | UTF-8 | 1,282 | 3.21875 | 3 | [] | no_license | #!/usr/bin/env ruby
def optimise_ortho_meta(loc, left, right, center)
opt = [loc[left], loc[right]].min
loc[left] -= opt
loc[right] -= opt
loc[center] += opt
return opt > 0
end
def optimise_para(loc, forth, back)
return false if loc[forth].zero? || loc[back].zero?
if loc[forth] > loc[back] then
loc... | true |
a0234c67bf596ca56e53a21cfa611ce4f3929c4e | Ruby | roomorama/concierge | /lib/concierge/flows/external_error_creation.rb | UTF-8 | 2,649 | 2.6875 | 3 | [] | no_license | module Concierge::Flows
# +Concierge::Flows::ExternalErrorCreation+
#
# This use case class wraps the creation of an +ExternalError+ record, performing
# attribute validations prior to triggering the database call.
#
# All parameters except +description+ must be present, and the operation
# given must be... | true |
c941322857d2c5381002956670c7a2abf55c5b32 | Ruby | Maumagnaguagno/HyperTensioN | /tests/again.rb | UTF-8 | 8,618 | 2.625 | 3 | [] | no_license | require 'test/unit'
require './extensions/Dejavu'
class Again < Test::Unit::TestCase
def visit_operators(name, label)
[
["invisible_#{name}_#{label}", ['?a', '?b'],
# Preconditions
[],
[],
# Effects
[["visited_#{label}", '?a', '?b']],
[]
],
["inv... | true |
e2b42ce8c7f6c950466426c25c20b37491b1e600 | Ruby | TRP1991/desafio-herencia-polimorfismo-modulos | /ejercicio2.rb | UTF-8 | 2,815 | 4.21875 | 4 | [] | no_license | =begin
Estudiante: Tamara Rubilar Pinilla
Ejercicio 2
Crear la clase Animal con un atributo nombre. Agregar un método getter para el atributo nombre(1 punto)Crear las clases Ave, Mamifero e Insecto. Ambas heredan de Animal(1 punto)
Crear las clases Pingüino, Paloma y Pato. Las tres heredan de Ave(1 punto)
Crear la... | true |
a056b480e349d6cbf940796feefccd3b6c50ca26 | Ruby | m-budryte/refactoring_codewars | /spec/vowel_count_spec.rb | UTF-8 | 295 | 2.828125 | 3 | [] | no_license | require 'vowel_count'
describe '#getCount' do
it 'returns 0 for no vowels' do
expect(getCount('grrrrrrrr')).to eq(0)
end
it 'returns 1 for 1 vowel' do
expect(getCount('oh!')).to eq(1)
end
it 'returns 5 for 5 vowels' do
expect(getCount('abracadabra')).to eq(5)
end
end
| true |
32ff3b35f7c8caa63571545a64badaebe6f7cb96 | Ruby | tvojnar/hotel | /lib/reservation.rb | UTF-8 | 815 | 3.3125 | 3 | [] | no_license | # The reservation class will create an instance of a reservation with the following attributes: a reservation ID, the total cost of the reservation, the rooms included in the reservation, and the date range of the reservation (reservation starting on the 5th and ending on the 7th will be an array [5, 6] because the 7th... | true |
6387c2ee58e6ffc6d8d4d19d617594c20879ab25 | Ruby | chaoshades/rmvx-ebjb-menu | /src/Windows/Window_Equip_Item.rb | UTF-8 | 2,938 | 2.828125 | 3 | [
"MIT"
] | permissive | #==============================================================================
# ** Window_Equip_Item
#------------------------------------------------------------------------------
# This window displays choices when opting to change equipment on the
# equipment screen.
#=============================================... | true |
36ebd0d91197e4e73123d00905d3787aa45ae45f | Ruby | dediane/THP_TicTacToe | /lib/app/board.rb | UTF-8 | 3,429 | 3.515625 | 4 | [] | no_license | #initialize board object
class Board
attr_accessor :array
#initialize a blank board
def initialize
@array = []
for i in 0..8
@array[i] = BoardCase.new
end
end
#methods to play the game with all prompt infos.
def play_turn(player)
puts "\n\n" + "Voici l'état de la grille:".underline.... | true |
6ca8e47a2af43d356c13d7b9f66b136351a791a2 | Ruby | rfamorim/booking_hotel | /search_file.rb | UTF-8 | 823 | 2.859375 | 3 | [] | no_license | # file_path :string
# file_extension :string
require_relative 'base_class'
require_relative 'booking_search'
class SearchFile < BaseClass
attr_accessor :force_tests, :file_path, :file_extension
def initialize(attributes)
self.file_path = attributes[:file_path]
set_file_extension
get_searches
... | true |
bd8303113737d196b5f4f44993b81ba7e87a5f5f | Ruby | maxmind/minfraud-api-ruby | /lib/minfraud/error_handler.rb | UTF-8 | 2,467 | 2.71875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Minfraud
# ErrorHandler provides a method to raise exceptions on errors.
module ErrorHandler
class << self
# Return the response if the HTTP status code is 2xx. Otherwise raise
# an error.
#
# @param response [Minfraud::HTTPService::Response]
#... | true |
4a69f07a7f8a8b1f47c1e34f6f2d48330c446e36 | Ruby | kenanwarren/HackerRanking | /gems.rb | UTF-8 | 187 | 3.1875 | 3 | [
"MIT"
] | permissive | # https://www.hackerrank.com/challenges/gem-stones
numRocks = gets.to_i
gems = gets.chomp.chars.uniq
(numRocks - 1).times do
gems = gets.chomp.chars.uniq & gems
end
puts gems.length
| true |
9c1da2669b98d2a96a2a96a247d6e433a56aefa3 | Ruby | abdulfataiaka/archive | /filemgr/server/support/response.rb | UTF-8 | 640 | 3 | 3 | [] | no_license | class Response
attr_writer :status, :body
attr_accessor :headers
def initialize
@status = nil
@body = nil
@headers = {}
end
def make
[
actual_status,
actual_headers,
actual_body
]
end
private
def actual_body
object = if @body.nil? then {} else @body end
... | true |
5a34e30441bd497047b43ed717b61a2959edb202 | Ruby | NelsonScott/TDD-Linked-List | /llspecs.rb | UTF-8 | 2,454 | 3.421875 | 3 | [] | no_license | require_relative 'linkedlist.rb'
require_relative 'link.rb'
describe "link" do
let(:my_link) {Link.new(7)}
describe "#initialize" do
it "makes a new link" do
expect(my_link).to be_an_instance_of Link
end
it "has data" do
expect(my_link.data).to equal 7
end
it "has a default nil n... | true |
79223faabe4016f38fa4533174ef5b1a8a9ec991 | Ruby | ndaniele/ttt-7-valid-move-q-000 | /lib/valid_move.rb | UTF-8 | 223 | 3.09375 | 3 | [] | no_license | def valid_move?(board,position)
position = position.to_i
(position.between?(1, 9) && !position_taken?(board, position-1))
end
def position_taken?(board,position)
(board[position] == "X" || board[position] == "O")
end | true |
6403c9863567224c31552d49d2f02c63071ab0b9 | Ruby | emileswarts/wumpus | /spec/wumpus_spec.rb | UTF-8 | 714 | 3.03125 | 3 | [] | no_license | require 'set'
require_relative '../lib/cave'
describe 'Cave' do
it 'has 20 rooms' do
expect(Cave.new.rooms.count).to eq(20)
end
it 'one room has a player' do
cave = Cave.new
expect(cave.rooms.select do |room|
room[:type] == :bats
end.count).to eq(2)
expect(cave.rooms.select do |room... | true |
3cddcb8a0ba945f95da17ef4ae157929c8702c0c | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/rna-transcription/f9bd3baf08374dbe849de2a6524878c1.rb | UTF-8 | 421 | 3.171875 | 3 | [] | no_license | class Complement
@base_dna_complement = {'A' => 'U', 'C' => 'G', 'G' => 'C', 'T' => 'A'}
@base_rna_complement = @base_dna_complement.invert
def self.of_dna(dna_sequence)
dna_sequence.chars.map { |nucleotide|
@base_dna_complement[nucleotide]
}.join
end
def self.of_rna(rna_sequence)
rn... | true |
dce86549f8637c20bd805b2bbfd7c119c4f22eb9 | Ruby | Eye-la/obj_oriented_programming | /rover.rb | UTF-8 | 2,246 | 4.21875 | 4 | [] | no_license | #Object Oriented Programming: Exercise 2
class Rover
attr_accessor :x, :y, :direction, :p_x, :p_y
attr_reader :command
def initialize(x, y, direction)
@@x = x.to_i
@@y = y.to_i
@@direction = direction.to_s
end
def read_instruction(command)
command.split(//).each do |s|
if s =="M"
... | true |
ba8892e9daaf516c54b3ed4f3c30dec1d5d18db4 | Ruby | wataruhayashi/study-ruby | /Sample3.rb | UTF-8 | 188 | 3.546875 | 4 | [] | no_license |
puts "文字を入力してください。"
s = gets.chomp
a = Regexp.new(s)
if a =~ "あいうえおかきくけこ"
print "有ります。"
else
print "無いです。"
end | true |
16df540677f9c17fd5983421805fa048607c6ab5 | Ruby | acareaga/chisel | /tests/header_test.rb | UTF-8 | 1,552 | 2.96875 | 3 | [] | no_license | require 'minitest'
require 'minitest/autorun'
require 'minitest/pride'
require '../lib/header'
class HeaderTest < Minitest::Test
def test_it_exists
assert HeaderTest.new("# Test Markdown\n")
end
def test_h1
text = Header.new("# My Life in Desserts\n")
assert_equal "<h1>My Life in Desserts</h1>\n", ... | true |
011276e0cb51aa5ca4015fbf73a5e1d8f9518249 | Ruby | YuheiHori0422/ruby_task | /chapter4/range/4.5.1.rb | UTF-8 | 447 | 4.0625 | 4 | [] | no_license | #配列や文字列の一部を抜き出す
#配列に対して添字を代わりに範囲オブジェクトを渡すと、指定した範囲の要素を取得できます。
a = [1,2,3,4,5]
#2番目から4番目までの要素を取得する
print a[1..3]
#以下が実行結果
[2, 3, 4]
#文字列に対しても同じ操作ができます。
b = 'abcdef'
#2文字目から4文字までを抜き出す
print b[1..3]
#以下が実行結果
bcd
| true |
04c164e032af1f79d38965a98eb90d51790be35b | Ruby | leungwensen/70-math-quizs-for-programmers | /zh_CN/q45_01.rb | UTF-8 | 568 | 3.109375 | 3 | [
"MIT"
] | permissive | N = 7
checked = {(1..N).to_a => 0} # 已检查的数组
check = [(1..N).to_a] # 检查目标
depth = 0 # 交换次数
while check.size > 0 do # 如果存在检查目标,则循环
next_check = []
(0..(N-1)).to_a.combination(2){|i, j| # 选择两个数字交换
check.each{|c|
d = c.clone
d[i], d[j] = d[j], d[i]
if !c... | true |
9a2f58fcfb61e9fec25931e0bc0e578315520d96 | Ruby | prudhvi-hack/day1 | /ex2.rb | UTF-8 | 99 | 2.84375 | 3 | [] | no_license | for i in [1,2,3,4,5,6,7,8,9,10]
puts i
end
for i in [1,2,3,4,5,6,7,8,9,10]
print i
end
| true |
79b1fab8170b4a03d1f79c22915826a0a5dfe1a3 | Ruby | hitode909/higashi-dance-network | /public/kasanegi/create-cities.rb | UTF-8 | 346 | 2.671875 | 3 | [] | no_license | require 'open-uri'
require 'json'
csv = open('https://gist.githubusercontent.com/ctsaran/42728dad3c7d8bd91f1d/raw/017718dde64f70e221f0e2bb0487a6c975d6195d/gistfile1.txt').read
puts JSON.pretty_generate(csv.each_line.map{|line|
(number, name, lat, lon) = * line.chomp.split(/\t/)
{
name: name,
lat: lat.to_f,... | true |
94bb06b648e793ef74bf4cc32759de8d34208504 | Ruby | tigerknee1/Didnapper | /Data/Scripts/Skill Shop.rb | UTF-8 | 11,099 | 3.34375 | 3 | [] | no_license | #===============================================================================
# Skill Shop
# Author: Game_guy
# Date: June 7th, 2009
# Version: 1.8
#===============================================================================
#
# Intro:
# What this script does is act as a shop but sells skills instead.
#
# Inst... | true |
24dbe349940f0a4ade0120fb37f37ef58072a265 | Ruby | DanBehrman/movie-quotes | /app/models/round.rb | UTF-8 | 469 | 2.765625 | 3 | [] | no_license | class Round < ApplicationRecord
belongs_to :game
belongs_to :quote
def wrong_answers
incorrect_answers = []
authors = []
while incorrect_answers.length < 3
sample = Quote.all.sample
if sample.author != self.quote.author && !authors.include?(sample.author)
... | true |
fedc6ca4f92e48167d75dce39d34c12757623395 | Ruby | bsielski/bsielski_control_flow | /lib/c_flow/pipeline.rb | UTF-8 | 212 | 2.671875 | 3 | [
"MIT"
] | permissive | module CFlow
class Pipeline
def initialize(procs:)
@procs = procs
end
def call(input)
@procs.each do |proc|
input = proc.call(input)
end
input
end
end
end
| true |
6364c82ab976e72e606d6c55c8d0c8be6b19d8da | Ruby | stlk/rust-talk | /compare.rb | UTF-8 | 1,117 | 2.921875 | 3 | [] | no_license | require 'benchmark'
require 'fast_blank'
require "ffi"
module Rust
extend FFI::Library
lib_ext = "dylib" if `uname` =~ /Darwin/
lib_ext = "so" if `uname` =~ /Linux/
ffi_lib "./libfastblank/target/release/libfastblank.#{lib_ext}"
attach_function :fast_blank, [:string], :bool
end
n = 5000000
text = """
Hi, t... | true |
f6decf1d4e04f5a29f1615c962f097cafd3ca2cf | Ruby | jsvd/mangaru | /lib/getter.rb | UTF-8 | 234 | 2.640625 | 3 | [] | no_license | require 'lib/manga'
module Mangaru
class Getter
attr :name
def initialize name = "unnamed"
@name = name
end
def list
[]
end
def manga name
Mangaru::Manga.new
end
end
end
| true |
9baef8731cb041ef12b71b57d4e66e6274dae5fb | Ruby | jasmsong/elevator | /floor.rb | UTF-8 | 696 | 3.640625 | 4 | [] | no_license | require_relative 'person'
class Floor
attr_accessor :floor_number, :waiting_persons, :up_button, :up_button
def initialize(number, sum_floor_number)
person_num=rand(1..5)
@floor_number=number
@waiting_persons=Queue.new
@up_button=0
@down_button=0
for i in 1..person_num
temp... | true |
777f587871ecab2f012500beaf047160ba8b72c6 | Ruby | relrod/dirt | /spec/tokenizer_spec.rb | UTF-8 | 2,218 | 3.015625 | 3 | [
"ISC"
] | permissive | require 'dirt/tokenizer'
describe Dirt::Tokenizer do
def scan_shebang(s)
described_class.new(s).scan_shebang
end
def tokenize(s)
described_class.new(s).tokenize
end
it 'scans shebangs' do
scan_shebang('#!/bin/bash').should == '#!bash'
scan_shebang('#!/usr/bin/ruby').should == '#!ruby'
s... | true |
f7f7113feacf90fd349d38794bc5fb8c69d5d320 | Ruby | NatalieTapias/hotel | /lib/room.rb | UTF-8 | 1,117 | 3.421875 | 3 | [] | no_license | require_relative "date_range"
class Room
attr_reader :id, :rate, :reservation_list
def initialize(id)
incorrect_id?(id)
@id = id
@rate = 200.00
@reservation_list = []
end
# this may be unnecessary?
def incorrect_id?(given_id)
if given_id.class != Integer
raise ArgumentError.n... | true |
16e5bc99405c781db2af316ddfca905dd1e3c9b6 | Ruby | MSoud/Mail | /app/models/user.rb | UTF-8 | 770 | 2.828125 | 3 | [] | no_license | class User < ActiveRecord::Base
has_many :messages
# converts the parameters passed in urls from id's to email addresses
def to_param
email
end
#extracts the email without the '.com' from the user
def self.getEmail(user)
emailString = user.email
if !(defined?(emailString)).nil?
emailStr... | true |
d896ad00d30b14dbca993b57d5c66972dc0d7605 | Ruby | ShannonLCapper/zorkda | /lib/zorkda-web/Actors/Thing/Enemy/Keese/Keese.rb | UTF-8 | 1,502 | 2.75 | 3 | [] | no_license | module Zorkda
module Actors
#DONE
class Keese < Enemy
def initialize(name, description)
super(name, "Keese", "Keese", 1, "RNG", 5)
@description = description
@navi_description = "These bats like to fly around and attack. Hit it with " +
"a ranged weapon if it's far away, or use your ... | true |
530865ed91c7af9eef2e47364af7523cb8d3d208 | Ruby | AttyC/battle | /spec/player_spec.rb | UTF-8 | 453 | 2.8125 | 3 | [] | no_license | require 'player'
describe Player do
# let (:name) { double :name }
subject(:player1) { described_class.new('Alice', 100) }
subject(:player2) { described_class.new('Bob', 100) }
describe 'initialize' do
it 'returns player1 name' do
expect(player1.name).to eq 'Alice'
end
end
describe "#damage... | true |
c358faffd4355e4de429260e6a9e09d33d7de284 | Ruby | termtter/termtter | /lib/plugins/defaults/alias.rb | UTF-8 | 1,678 | 2.671875 | 3 | [
"MIT"
] | permissive | # -*- coding: utf-8 -*-
#
# Examples:
#
# ~/termtter/config
#
# config.plugins.alias.aliases = {:ls => 'list', :hoge => 'update hoge'}
#
# command line
#
# > alias ls list
# > alias me list @jugyo
# > alias st search termtter
#
# > remove_alias ls
#
config.plugins.alias.set_default(:aliases, {}... | true |
4a378078c78d7f38b90b550d8d53500cc4f24bd9 | Ruby | southpawgeek/perlweeklychallenge-club | /challenge-120/abigail/ruby/ch-2.rb | UTF-8 | 499 | 2.9375 | 3 | [] | no_license | #!/usr/bin/ruby
#
# See ../README.md
#
#
# Run as: ruby ch-2.rb < input-file
#
diff_per_minute = 11
min_per_hour = 60
full_circle = 720
ARGF . each_line do
|time|
hours, minutes = time . split (/:/)
angle = (diff_per_minute * (hours . to_i * min_per_hour + minutes . to_i))\
... | true |
0361f715a7e8b627644b0673034d39588db1a04d | Ruby | ZeusWPI/Tap | /app/models/ability.rb | UTF-8 | 2,092 | 2.765625 | 3 | [] | no_license | # frozen_string_literal: true
class Ability
include CanCan::Ability
def initialize(user)
return unless user
# Special permissions for certain users
initialize_admin if user.admin?
initialize_koelkast if user.koelkast?
# Default permissions for all users
initialize_user(user)
end
... | true |
e6fd482a5307045ce7a8d22841d549ebf25be7ad | Ruby | bryewalks/deep_dives_revisited | /dnd_dice.rb | UTF-8 | 1,432 | 3.578125 | 4 | [] | no_license | class Die
attr_reader :sides, :face_up
def initialize(input_die)
@sides = input_die
@face_up = 1
end
def roll
@rolled_die = rand(1..@sides)
@face_up = @rolled_die
return @rolled_die
end
end
class DiceCup
attr_reader :sides, :face_up
def initialize(*input_dice)
@cup = input_dic... | true |
ccc3c810b5ced127c6057fcc4da62dbe0c20df1c | Ruby | glassjoseph/black_thursday | /lib/invoice_item_repository.rb | UTF-8 | 967 | 3.0625 | 3 | [] | no_license | require_relative "../lib/invoice_item"
require_relative "../lib/data_access"
class InvoiceItemRepository
attr_reader :all
include DataAccess
def initialize(parent)
@all = []
@parent = parent
end
def from_csv(path)
file = CSV.open(path, headers: true, header_converters: :symbol)
populate_rep... | true |
3ac6a112db6af06b929ae8068035531ff0cd59d8 | Ruby | chrisdel101/crm-web-assignment | /crm.rb | UTF-8 | 2,353 | 2.859375 | 3 | [] | no_license | # Implement the new web-based CRM here.
# Do NOT copy the CRM class from the old crm assignment, as it won't work at all for the web-based version!
# You'll have to implement it from scratch.
require 'sinatra'
require_relative 'contact'
#
# puts the app name and time
get '/' do
@crm_app_name = "the CRM web app"
@... | true |
0cb84e5b63416798a2f4a7699c7d8d87130e7e1a | Ruby | SeanMNorton/BabySitterKata2 | /lib/sitterQuestionaire.rb | UTF-8 | 647 | 3.171875 | 3 | [] | no_license | require './shared/set_times.rb'
def sitterQuestionaire
def getStartTime
print "Start Time: "
startTime = gets.chomp.to_i
if startTime > $latestTime
return startTime
else
puts "I'll start no earlier than 5:00PM!"
getStartTime
end
end
def getBedTime
print "Bed Time: "
... | true |
ecb7acc505cb87a40494daf965c5b707c10377f0 | Ruby | bshlgrs/tictactoe | /app/controllers/tictactoe_controller.rb | UTF-8 | 615 | 2.671875 | 3 | [] | no_license | class TictactoeController < ApplicationController
def move
sent_board = Board.from_string(params["board"])
if sent_board
if sent_board.is_valid?
if sent_board.plausibly_the_turn_of_o?
sent_board.make_move_for_o
render text: sent_board.to_wave_string
else
r... | true |
fa6b89cfc6c9ffe55b384e139e48e6f14c00bbc1 | Ruby | Thermatix/simples | /middlewares/headers.rb | UTF-8 | 501 | 2.75 | 3 | [] | no_license | class Headers
def initialize(app=nil)
@app = app
end
def call(env,key='HEADERS')
env[key] = self.class.get_headers(env)
@app.call(env)
end
def self.get_headers(env,start="HTTP")
env.select {|k,v| k.start_with? "#{start}_"}.
inject({}) {|h,(k,v)| h[k.sub(/^#{start}_/,'').downcase... | true |
2459cff3fc5053d8f6cfc8219276b17999594f3a | Ruby | nickrobson/adventofcode-2017 | /day02/day02a.rb | UTF-8 | 227 | 2.96875 | 3 | [] | no_license | #!/usr/bin/env ruby
def line_diff(line)
xs = line.split /\t/
xs.map! { |s| Integer s }
return xs.max - xs.min
end
input_lines = IO.readlines 'input.txt'
input_lines.map! { |line| line_diff line }
p input_lines.inject 0, :+ | true |
5cc6aa1c03e34a55b87cc8bb5b72adb46f3e55ee | Ruby | nickcen/leetcode | /p561.rb | UTF-8 | 158 | 3.53125 | 4 | [] | no_license | def array_pair_sum(nums)
ns = nums.sort
ret = 0
0.step(ns.length - 1, 2).each do |i|
ret += ns[i]
end
ret
end
puts array_pair_sum([1,2,3,2]) | true |
37d1c9b5379a2239361b60afb1e78b891daa962e | Ruby | jeremycartesse/behalfway | /app/helpers/offers_helper.rb | UTF-8 | 793 | 2.5625 | 3 | [] | no_license | module OffersHelper
def departure_css_class_name(filter)
return "active" if filter == @filters[:departure_time_there]
end
def arrival_css_class_name(filter)
return "active" if filter == @filters[:arrival_time_back]
end
def price_difference_styling(price1, price2)
if price2 > price1
return ... | true |
eaa6947e11f5a8992a869bce8ce1e0e7405d4e8a | Ruby | ulternate/2016-Diploma-Sem1-RAD-Cluster | /Week4-Tutorials/tut_4_1.rb | UTF-8 | 1,313 | 4.15625 | 4 | [] | no_license | puts "Exercise 1:\n\n"
puts 12.is_a?(Integer)
puts 12.is_a?(Float)
puts 12.is_a?(String)
puts '12'.is_a?(Integer)
puts '12'.is_a?(Float)
puts '12'.is_a?(String)
puts 12.0.is_a?(Integer)
puts 12.0.is_a?(Float)
puts 12.0.is_a?(String)
puts "Hit enter to continue"
do_nothing = gets.chomp
puts "\n\nEx... | true |
7d20d2e2915e3f7a303e85f06f65d0aba8fb4dc8 | Ruby | marcwright/WDI_ATL_1_Instructors | /REPO - DC - Students/w10/d04/Mikael/zip_code_matcher.rb | UTF-8 | 561 | 3.640625 | 4 | [] | no_license | ## Partner Activity - ZIP Code
# Partner up and take a stab at writing a ruby method, `is_valid_zip`, that validates a user-submitted ZIP Code, keeping in mind that ZIP codes can be 5 digits, as in 20008, or 5 digits followed by a dash and four more digits, as in 90210-0876. Anything else is invalid, and should result ... | true |
6a47b32538fb51fe76a3f7582ec6a2e9b4a09c57 | Ruby | regedor/ror-course | /Class01/Ruby Code/membro_familia.rb | UTF-8 | 1,254 | 3.375 | 3 | [] | no_license | require 'humano'
class MembroFamilia < Humano
attr_accessor :nome, :idade
attr_reader :created_at
#####################
## Instance Methods
def initialize(nome_da_instancia="Desconhecido", sobrenome_da_familia=nil, options={})
self.nome = nome_da_instancia
self.class.sobrenome = so... | true |
5719ad8cf7570a1ac7cee74aa748519459bfb866 | Ruby | adrianbraca/launch_school | /exercises/ex_04.rb | UTF-8 | 350 | 4.71875 | 5 | [] | no_license | # Now, using the same array from #2, use the select method to extract all odd
#numbers into a new array.
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
odd_arr = []
odd_arr = arr.select do |value|
value.odd?
end
puts odd_arr
#Append "11" to the end of the original array. Prepend "0" to the beginning.
odd_arr.push(11)
odd... | true |
295e9556aaae715dcf983ddfe3d87e4585f2ba9e | Ruby | yalokin/thinknetica_basic_course | /lesson6/route.rb | UTF-8 | 655 | 3.625 | 4 | [] | no_license | require_relative 'validate'
class Route
attr_reader :stations
include Validate
def initialize(start_station, end_station)
@stations = [start_station, end_station]
validate!
end
def add_station(station)
@stations.insert(-2, station)
end
def remove_station(station)
if station != @statio... | true |
ecb6659d1b5f7cb223b498df674de96656952416 | Ruby | danbernier/CosmicWimpout | /lib/cosmic_wimpout/controller.rb | UTF-8 | 703 | 2.75 | 3 | [] | no_license | module CosmicWimpout
class Controller
def self.start
controller = self.new
controller.start
until controller.over?
controller.take_turn
end
end
attr_reader :game
def initialize(view=Views::StartView.new)
@start_view = view
end
... | true |
175d12bfd2844f2326e7920d17e263ac3d76df40 | Ruby | aarongough/triangular | /lib/triangular/polyline.rb | UTF-8 | 902 | 2.75 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module Triangular
class Polyline
attr_accessor :lines
def initialize(lines)
@lines = lines
end
def to_svg(width, height, units, x_offset = 0, y_offset = 0)
output = "<?xml version=\"1.0\" standalone=\"no\"?>\n"
output += "<!DOCTYPE svg PUBLIC \"-//W3... | true |
4acb413e0a46a073f06b3533a90b8341005611e7 | Ruby | Calvin0125/launch_school_rb130 | /lesson_1/select.rb | UTF-8 | 225 | 3.921875 | 4 | [] | no_license | def select(array)
index = 0
new_array = []
while index < array.length
if yield(array[index])
new_array << array[index]
end
index += 1
end
new_array
end
p select([1, 2, 3, 4, 5]) { |num| num.odd? } | true |
1642d60ac2b8d4806693c4b1aeec8bd951c5c6bd | Ruby | jpmaggs11/ruby-challenges | /parent_classes.rb | UTF-8 | 631 | 3.703125 | 4 | [] | no_license | class Primate
def set_name=(name)
@name = name
end
def get_name
return @name
end
end
class Orangutan < Primate
def orange_orangutan
return "is drinking Tang."
end
end
class Monkey < Primate
def monkeying_around
return "the monkey stole your car."
end
end
my_monkey = Monkey.new
my_monkey.set_nam... | true |
d91e1fabb6bd2ce559741ca2cc942ad86f36d067 | Ruby | jdegrand/AdventOfCode | /2020/Day24/24.rb | UTF-8 | 2,148 | 3.546875 | 4 | [] | no_license | file = 'input.txt'
input = File.read(file)
$lines = input.lines.map(&:chomp)
$PI = Math::PI
def sin(x)
Math.sin(x*$PI/180)
end
def cos(x)
Math.cos(x*$Pi/180)
end
def tan(x)
end
def day24_1
tiles = Hash.new(:white)
reg = /(ne|nw|se|sw|e|w)/
$lines.each do |l|
x, y, z = 0, 0, 0
l... | true |
919e6a34d3fd4090909b21c676c25906ad0a82cc | Ruby | sbafsk/ruby-react-course-practice | /sections/3_methods_ruby/3-12 chaining methods.rb | UTF-8 | 1,022 | 4.40625 | 4 | [] | no_license | # frozen_string_literal: true
# - We can call object methods on the return value,
# which looks like object.method_one.method_two
# - We can pass the return value of a method as an argument
# for another method: method_two(method_one(object))
# - And we can combine these:
# method_two(object.method_one) or
# m... | true |
157bdf168eeb67393ba4a65d254c71a98005b4a6 | Ruby | perpepajn25/single-source-of-truth | /lib/has_many_through/Visitor.rb | UTF-8 | 406 | 3.203125 | 3 | [] | no_license | class Visitor
attr_reader :name
def initialize(name)
@name = name
end
def take_trip(destination)
Trip.new(self, destination)
end
def trips
Trip.all.select do |trip|
trip.visitor == self
end
#returns all of a user's trips
end
def destinations
self.trips.collect do |trip... | true |
4e697101bf1fe64c8db5d3a298723a4f746ca223 | Ruby | tmm1/stackprof | /sample.rb | UTF-8 | 662 | 2.59375 | 3 | [
"MIT"
] | permissive | $:.unshift File.expand_path('../lib', __FILE__)
require 'stackprof'
class A
def initialize
pow
self.class.newobj
math
end
def pow
2 ** 100
end
def self.newobj
Object.new
Object.new
end
def math
2.times do
2 + 3 * 4 ^ 5 / 6
end
end
end
#profile = StackProf.run(m... | true |
7bd2d84fffee707204b026aedd4c038348f558a3 | Ruby | tomdalling/dabooks | /spec/dowl_opt_parse_spec.rb | UTF-8 | 4,949 | 2.96875 | 3 | [] | no_license | require 'dowl_opt_parse'
RSpec.describe DowlOptParse do
SCHEMA = {
cat: {
long: '--cat',
short: '-c',
doc: 'Enable cats.'
},
dog: {
long: '--dog',
short: '-d',
doc: "Enable dogs. This is a particularly long string, so here is a line break:\nThere. Wasn't that easy."
... | true |
1c8935796df310f9063f0c26748650fb2a1819aa | Ruby | tstaros23/enigma | /lib/decrypt.rb | UTF-8 | 876 | 3.328125 | 3 | [] | no_license | require './lib/key'
require './lib/offset'
require './lib/encrypt'
class Decrypt
attr_reader :alphabet, :message, :key_shifts, :offset
def initialize(message, key_shifts, offset)
@alphabet = (("a".."z").to_a << " ")
@message = message.downcase
@key_shifts = key_shifts
@offset = offset
end
de... | true |
c2f73c0f29b29731dbfdceccd5b7f09fdb09ec86 | Ruby | J-Y/RubyQuiz | /ruby_quiz/quiz73_sols/solutions/digraph.rb | UTF-8 | 2,928 | 3.5 | 4 | [
"MIT"
] | permissive | # A simple and untested DiGraph implementation.
#
class DiGraph
attr_reader :edges, :nodes
# The edges are given as arrays of size 1 (simply adding a node without
# any edges) or size 2 (adding both nodes with an edge from the first one
# to the second one). Nodes can be any Ruby object.
def initialize(*edg... | true |
5ada6e8ae5505f8cfb689e891a8b032e4c38828b | Ruby | aidasv/Monopoly | /lib/monopoly/board.rb | UTF-8 | 1,041 | 3.203125 | 3 | [] | no_license | require 'erb'
class Board
attr_accessor :cards, :sides
SIZE = 10
VERTICAL = 0
HORIZONTAL = 1
def initialize
@cards = [
JailCard.new,
Vcard.new,
Vcard.new,
Vcard.new,
Vcard.new,
Vcard.new,
Vcard.new,
Vcard.new,
Vcard.new,
FreeParkingCard.new
... | true |
1ea90fca563643ef9f41bb3566da9399dc02a74d | Ruby | brunobispo/dog-walking | /spec/services/create_dog_walking_spec.rb | UTF-8 | 3,204 | 2.546875 | 3 | [] | no_license | describe CreateDogWalking do
describe '.call' do
subject(:result) { described_class.call(params) }
before do
allow(CreateAddress).to receive(:call)
.and_return(instance_double(CreateAddress,
success?: true,
address: create(... | true |
7c46a6749db89ecb320074b6af0f3c2b1b536646 | Ruby | thread-pond/scrum-lint | /lib/scrum_lint/interactive_linters/card/missing_hash_tag.rb | UTF-8 | 534 | 2.640625 | 3 | [
"MIT"
] | permissive | module ScrumLint
module InteractiveLinter
# checks that cards have #HashTag and interactively assigns
class MissingHashTag < InteractiveLinter::Base
MESSAGE = 'missing hashtag'.freeze
def call(card, reporter:, **_context)
return if card.hashtags.any?
reporter.fail(card, MESSAGE)... | true |
c7b2ee9fef3c6c98c1f56b199575b25ac3529425 | Ruby | markburns/turnip | /examples/steps/steps.rb | UTF-8 | 2,060 | 3.359375 | 3 | [
"MIT"
] | permissive | step "there is a monster" do
@monster = 1
end
step "there is a strong monster" do
@monster = 2
end
step "I attack it" do
@monster -= 1
end
step "it should die" do
@monster.should eq(0)
end
step "this is ambiguous" do
end
step "this is :ambiguous" do
end
step "there is a monster called :name" do |name|
@... | true |
a18eb87ff5f1aaec531e226303aafcb18be44328 | Ruby | aristofun/hangman | /viselitsa.rb | UTF-8 | 800 | 2.71875 | 3 | [] | no_license | if Gem.win_platform?
Encoding.default_external = Encoding.find(Encoding.locale_charmap)
Encoding.default_internal = __ENCODING__
[STDIN, STDOUT].each do |io|
io.set_encoding(Encoding.default_external, Encoding.default_internal)
end
end
require_relative "game"
require_relative "result_printer"
require_rela... | true |
a5b61948f334ffa359e5745e323849f8db86fe44 | Ruby | hosh/htmlbeautifier | /test/html_beautifier_test_utilities.rb | UTF-8 | 454 | 2.625 | 3 | [
"MIT"
] | permissive | module HtmlBeautifierTestUtilities
def code(str)
str = str.gsub(/\A\n|\n\s*\Z/, '')
indentation = str[/\A +/]
lines = str.split(/\n/)
lines.map{ |line| line.sub(/^#{indentation}/, '') }.join("\n")
end
def assert_beautifies(expected, source)
actual = ''
beautifier = HtmlBeautifier::Be... | true |
0bd9b701ad8d8dbfbb7cd8de6f97ff1d820dc3a0 | Ruby | aarmora/dota2caster | /lib/tasks/import.rake | UTF-8 | 519 | 2.546875 | 3 | [] | no_license | namespace :dota do
task :import => :environment do
require 'csv'
fields_to_insert = %w{ name steam_id twitch email }
rows_to_insert = []
CSV.foreach("casters.csv", headers: true) do |row|
row_to_insert = row.to_hash.select { |k, v| fields_to_insert.include?(k) }
rows_to_insert << row_to_inse... | true |
5d8060d299b7be151d2f5d481965c26d77c636cd | Ruby | yannvery/windward | /lib/windward.rb | UTF-8 | 3,385 | 3.265625 | 3 | [
"MIT"
] | permissive | require 'windward/version'
require 'mechanize'
# Just a naming module
module Windward
# Instantiate an object to get meteo france previsions
class Weather
def initialize
@departments = load_departments_data
@cities = load_cities_data
@regions = load_regions_data
end
def regions
... | true |
f37cb232ce83dbf83aac1aca5c400e6884174c12 | Ruby | collabnix/dockerlabs | /vendor/bundle/ruby/2.6.0/gems/rubyzip-2.3.2/samples/zipfind.rb | UTF-8 | 1,502 | 2.65625 | 3 | [
"Ruby",
"BSD-2-Clause",
"Apache-2.0"
] | permissive | #!/usr/bin/env ruby
$VERBOSE = true
$LOAD_PATH << '../lib'
require 'zip'
require 'find'
module Zip
module ZipFind
def self.find(path, zip_file_pattern = /\.zip$/i)
Find.find(path) do |filename|
yield(filename)
next unless zip_file_pattern.match(filename) && File.file?(filename)
... | true |
39be45abfd538d3a98ab2a793c8e4ac7954404c6 | Ruby | donburks/w6d2_ar_intro | /app.rb | UTF-8 | 685 | 2.859375 | 3 | [] | no_license | require_relative 'app_config'
require_relative 'models/player'
require_relative 'models/team'
AppConfig.establish_connection
#players = Player.all
#teams = Team.all
#player = Player.find(10);
#p player
#p player.number
#
#player = Player.where("number > 17")
#p player
#p player.first.number
#
#player = Player.find_b... | true |
225b72fee469e9eb7a6d2c593e3c5ae98ee2c189 | Ruby | TeleSign/ruby_telesign_enterprise | /lib/telesignenterprise/telebureau.rb | UTF-8 | 2,186 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'telesign/rest'
TELEBUREAU_CREATE_RESOURCE = '/v1/telebureau/event'
TELEBUREAU_RETRIEVE_RESOURCE = '/v1/telebureau/event/%{reference_id}'
TELEBUREAU_DELETE_RESOURCE = '/v1/telebureau/event/%{reference_id}'
module TelesignEnterprise
# TeleBureau is a service is based on TeleSign's watchlist, which is a prop... | true |
a61c9c04ddc0bc74d93bc20bdc7d669d47fcf8d9 | Ruby | woojinc/bookish-memory | /coding-problems/ruby/m-98-validate-binary-search-tree.rb | UTF-8 | 585 | 3.8125 | 4 | [] | no_license | # Definition for a binary tree node.
class TreeNode
attr_accessor :val, :left, :right
def initialize(val)
@val = val
@left, @right = nil, nil
end
end
# @param {TreeNode} root
# @return {Boolean}
def is_valid_bst(root, lower_limit = -Float::INFINITY, upper_limit = Float::INFINITY)
return t... | true |
f41fac151e3a3343d25aa77bfe8480a97be1cfc4 | Ruby | globocom/query_string_interface | /spec/query_string_interface/filter_spec.rb | UTF-8 | 15,534 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'active_support/core_ext'
describe QueryStringInterface::Filter do
describe "simple filters" do
subject do
described_class.new('title', 'Some Title')
end
it "should return the raw attribute as attribute" do
subject.attribute.should eq(subject.raw_attribute)
... | true |
e70afee796eb02b6b25bb9ee09e41b5c89d12e98 | Ruby | padualima/algorithms | /trocadevariaveis.rb | UTF-8 | 399 | 3.703125 | 4 | [] | no_license | puts "Digite o Valor de A:"
a = gets.chomp.to_i
puts "Digite o valor de B:"
b = gets.chomp.to_i
puts "O valor de A = #{a} e B = #{b}"
sleep 2
puts "Só um instante agora estamos fazendo uma conversao maluca sem uma terceira
variavel hahaha..."
sleep 6
# for a = 1 b = 4
a = a + b # a = 5 , b = 4
b = a - b # a = 5 , b ... | true |
02962af80f17cd50982c5d8d173872196b081b50 | Ruby | goronfreeman/alfred-genius | /workflow/search.rb | UTF-8 | 2,508 | 2.578125 | 3 | [] | no_license | require_relative 'base'
require 'open-uri'
module AlfredGenius
class Search
include AlfredGenius::Base
attr_reader :query
def initialize
@query = ARGV.join(' ')
end
def search
set_access_token
output_json
rescue
rescue_json
ensure
print Base.workflow.outp... | true |
ec332179d462c8a3ff69313a8197c0e16cdcb357 | Ruby | Arthur/wikimate | /lib/wikimate/builder.rb | UTF-8 | 470 | 2.609375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Wikimate
class Builder
def initialize(root,output_dir, options = {})
@root = root
@output_dir = output_dir
@options = options
end
def run
FileUtils.mkdir_p @output_dir
interpreter = Interpreter.new(@root, @options)
interpreter.pages.each do |page|
File.o... | true |
63a914e8d0996b762565eb75ae79c4426c40c044 | Ruby | kerrieyee/algorithms | /three_sum.rb | UTF-8 | 1,286 | 3.84375 | 4 | [] | no_license | class ThreeSum
def initialize(array)
@array = array
@last_index = @array.length - 1
@count = 0
@triples = []
end
def find_triples
@array[0..-3].each_with_index do |e, i|
num = i + 1
array2 = @array[num..-2]
array2.each_with_index do |d, j|
num2 = j + 1
array3... | true |
47abc83fe5c8f5abd11cde9f47ba004e48f04ae6 | Ruby | Smulligan85/ttt-with-ai-project-v-000 | /lib/players/human.rb | UTF-8 | 95 | 2.84375 | 3 | [] | no_license | class Player::Human < Player
def move(move)
move = gets.chomp.upcase
move
end
end
| true |
c0c36b1dce685f3c5256e66a31cbf7c202bd8aaa | Ruby | eriq-augustine/psl-distributed-examples | /friendship/scripts/run.rb | UTF-8 | 4,915 | 2.6875 | 3 | [] | no_license | require_relative 'computeNumberGroundins'
require_relative 'genData'
require 'fileutils'
require 'open3'
require 'socket'
START_PEOPLE = 300
END_PEOPLE = 600
PEOPLE_INCREMENT = 100
START_LOCATIONS = 10
END_LOCATIONS = 30
LOCATIONS_INCREMENT = 10
RESULTS_DIR = 'results'
OUT_FILE = 'out.txt'
ERR_FILE = 'out.err'
BASH... | true |
5c52f4807e901a53dfa67e1ecafdde8d9aa840df | Ruby | yagilm/ruby_workshop | /02-probability/test_probability.rb | UTF-8 | 1,315 | 3.515625 | 4 | [] | no_license | require "minitest/autorun"
require_relative "probability"
# Ensures Probability Class functions correctly
class TestProbability < Minitest::Test
# def test_chance_reader
# assert_equal 20, Probability.new(20).chance
# end
# and, or, xor, xand,
def setup
@chance_000 = Probability.new(0)
@chance_100 = Probabil... | true |
42e41928e32d750ae255c096df211ea5c7f78741 | Ruby | benrodenhaeuser/exercises | /small_problems/11_Medium_02/05_triangle_sides.rb | UTF-8 | 2,085 | 4.6875 | 5 | [] | no_license | # Triangle sides
=begin
A triangle is classified as follows:
- equilateral All 3 sides are of equal length
- isosceles 2 sides are of equal length, while the 3rd is different
- scalene All 3 sides are of different length
To be a valid triangle,
- the sum of the lengths of the two shortest sides must be greater than t... | true |
89dda085014bc6277a0b34b7c80e2670a9408a84 | Ruby | wismer/bit-torrent | /lib/torrenter/torrent_reader/piece.rb | UTF-8 | 2,699 | 2.71875 | 3 | [] | no_license | module Torrenter
class TorrentReader
class Piece
attr_accessor :range, :path, :hash, :index, :status
attr_reader :peers, :data
def initialize(piece_length)
@range = []
@path = []
@piece_length = piece_length
@status = :available
@data ... | true |
c51e12a9f3a8228b6d6c0e63e1cdd9bca470c5bb | Ruby | PillMopper/Data-Fetching-and-Organizing | /drugsatfda/scrape-drugs-at-fda.rb | UTF-8 | 2,310 | 2.6875 | 3 | [] | no_license | ## PillMopper
# Fetching Drugs@FDA
#
#
# Skill level:
# Easy
#
# Description:
# We need a canonical list of drug names, including generic equivalents
# The Drugs@FDA is a good place to start
#
# This is a pretty standard scraping operation, though there are nested pages
# http://www.accessdata.fda.gov/scripts/cder/dr... | true |
606ee666ac82be549319287d948fb5da13905482 | Ruby | cout/quiz | /lib/quiz/question_picker.rb | UTF-8 | 750 | 2.828125 | 3 | [] | no_license | require 'set'
module Quiz
class QuestionPicker
def initialize(*generators)
@generators = generators
@ask_more = Set.new
end
def pick_question
generator = self.pick_question_generator()
question = generator.generate_question()
return question
end
def pick_question_generator
if rand(... | true |
3913fa8c1703619abe08a8d1d78dc8174887e248 | Ruby | jenniferemshepherd/GildedRose-Refactoring-Kata | /ruby/spec/backstage_pass_spec.rb | UTF-8 | 998 | 2.890625 | 3 | [
"MIT"
] | permissive | require 'backstage_pass'
describe BackstagePass do
describe "#update_quality" do
it "cannot increase quality beyond 50" do
item = BackstagePass.new(2, 49)
item.update
expect(item.quality).to eq 50
end
it "increases quality by 1 with >10 days to go" do
item = BackstagePass.new(15,... | true |
61050bb56deda54e459833a13e76e152c234ee11 | Ruby | dougdroper/anagram_finder | /app/models/anagram_search.rb | UTF-8 | 524 | 3.03125 | 3 | [] | no_license | class AnagramSearch
attr_reader :load_time
def initialize(file="public/data/dictionary.txt")
time = Time.now
@content = File.read(file)
@anagram_map = map_annagrams
@load_time = Time.now - time
end
def find_annagrams(word)
@anagram_map[word.split('').sort.join] || []
end
private
de... | true |
5a8c9e2d8c2ea9ca7b20a3dd2bf273503cc59336 | Ruby | doooby/open_questionnare | /app/lib/project_config.rb | UTF-8 | 2,403 | 2.515625 | 3 | [
"MIT"
] | permissive | module ProjectConfig
extend ActiveSupport::Concern
class_methods do
def project_label
@project_label ||= self.name.demodulize.underscore.dasherize.freeze
end
def questionnaires
@questionnaires ||= {}
end
def questionnaire label, &block
label = label.to_s
q = Questionn... | true |
eca8283ff703b0abbaf0acfd48d30106b73615e1 | Ruby | zeroleaf/secv | /lib/secv/db_logic.rb | UTF-8 | 802 | 2.71875 | 3 | [
"MIT"
] | permissive | require 'secv/domain/word'
require 'secv/domain/word_info'
require 'secv/domain/alias'
require 'secv/domain/domain'
class DbLogic
def initialize(cfg)
Domain.init cfg
end
def save_word(word)
word.save
WordInfo.new_info(word.identify).save
end
def save_als_word(input, word)
save_word word
... | true |
321396ce6c3c8c7fd757bab048c075e4680f4340 | Ruby | edgenard/appAcademyPrep | /learnToProgramExercises.rb | UTF-8 | 19,676 | 3.890625 | 4 | [] | no_license | # Learn to Program by Chris Pine exercises.
=begin
2.5 A few things to try
write a program that tells you the following
1. Hours in a year. How many hours are in a year?
2. Minutes in a decade. How many minutes are in a decade?
3. Your age in seconds. How many seconds old are you?
4. Our dear authors age if our dear... | true |
03485801ded5db768bc6abfbf77ab6849101a4cb | Ruby | rubicon44/search-algorithm-in-ruby | /lib/linear_search.rb | UTF-8 | 729 | 3.625 | 4 | [] | no_license | require_relative './text_file_reading'
# 番号探索
start_time = Time.now
set_number = 88
array_length = number_data.count - 1
for int in 0...array_length do
if number_data[int].to_i == set_number
puts "#{number_data[int]}が見つかったよ!"
break
end
end
# 文字列探索
# set_text = "さんそ"
# puts hiragana_data.find_index(set_te... | true |
209347e32e6d809eb57b0857cbbbe0a09867638c | Ruby | choihz/study-ruby | /Chapter 2/symbol.rb | UTF-8 | 1,743 | 4.09375 | 4 | [] | no_license | # 프로그래밍을 하다 보면 어떤 중요한 것에 대한 이름을 지어야만 할 때가 있다.
# 예를 들어 나침반의 4방향을 나타내는 이름에 대해 다음과 같이 상수를 정의할 수 있다.
NORTH = 1
EAST = 2
SOUTH = 3
WEST = 4
# 대부분의 경우 이렇게 상수에 특정 값을 대입하는 방법은 특별히 문제가 되지 않지만, 루비에는 이에 대한 좀 더 깔끔한 대안이 있다.
# 심벌은 미리 정의할 필요가 없는 동시에 유일한 값이 보장되는 상수 이름이다.
# 심벌 리터럴은 콜론(:)으로 시작하며 그 다음에 이름이 온다.
walk(:north)
look(:east)... | true |
ec5efc9cb8911dc76a2cf9d14882e396dea47c01 | Ruby | YanaLo/tweet-shortener-nyc-web-051319 | /tweet_shortener.rb | UTF-8 | 847 | 3.6875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def word_substituter(words)
subs=words.split(" ")
another_word=[]
subs.each do |word|
case word.downcase
when "hello"
another_word<<"hi"
when "to","two","too"
another_word<<"2"
when "for", "four"
another_word<<"4"
when "be"
anoth... | true |
43b1d58e3b0e778079015095762dc74420128de4 | Ruby | nohaderf/programming-univbasics-3-build-a-calculator-lab-nyc01-seng-ft-100520 | /lib/math.rb | UTF-8 | 419 | 3.65625 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive |
def addition(num1, num2)
num1 + num2
end
def subtraction(num1, num2)
num1 - num2
end
def division(num1, num2)
num1/num2
end
def multiplication(num1, num2)
num1 * num2
end
def modulo(num1, num2)
num1 % num2
end
def square_root(num)
Math.sqrt(num)
end
#Learning Goals
# Use Ruby math operations to buil... | true |
108cbd8fa78de6638bcc7e94c7f9e34a87b3803c | Ruby | harshatjk/CodeEval | /AgeDistribution.rb | UTF-8 | 550 | 3.546875 | 4 | [] | no_license | def age_distribution
f = File.open("C:/Ruby200/Files/Tes.txt")
f.each_line do |value|
#puts value
number = value.to_i
case number
when 0..2
puts "Still in Mama's arms"
when 3..4
puts "Preschool Manaic"
when 5..11
puts "Elementary school"
when 12..14
puts "Middle school"
when 15..... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.