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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
3b4949363be3d9b9948938229cc0c83ce0c613e7 | Ruby | EricSlick/regexp_m17n | /lib/regexp_m17n.rb | UTF-8 | 487 | 2.578125 | 3 | [
"Unlicense"
] | permissive | module RegexpM17N
def self.non_empty?(str, enc)
unless enc.dummy?
Regexp.new('^.+$'.encode(enc)).match(str.encode(enc))
else
begin
if conv = Encoding::Converter.asciicompat_encoding(enc)
Regexp.new('^.+$'.encode(conv)).match(str.encode(conv))
else
111
en... | true |
29c0dc289cd0d34073d754060780909a7306f38e | Ruby | digideskio/mynewg | /app/models/attachment.rb | UTF-8 | 1,240 | 2.796875 | 3 | [] | no_license | # Attachment Documentation
#
# The attachment table provides support for handling file uploads throughout the application.
# It has a polymorphic relation so can be utilised by various models.
# == Schema Information
#
# Table name: attachments
#
# id :integer not null, primary key
# att... | true |
bbb07b5ec5e2332dae7ddeebe41802bb35f9502b | Ruby | adriennedomingus/robodoku | /lib/board.rb | UTF-8 | 762 | 3.6875 | 4 | [] | no_license | require_relative './cell'
class Board
attr_reader :board
def initialize(input)
@board = create_cells(input)
end
def create_cells(input)
board = rows(input).map.with_index do |row, row_index|
row = row.map.with_index do |element, element_index|
Cell.new(element, row_index, element_index)... | true |
18fdbdc58e218236f4229d87559573799f65f5c5 | Ruby | dariogf/SeqtrimNext | /bin/split_fastq.rb | UTF-8 | 696 | 2.671875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'scbi_fastq'
if ARGV.count < 3
puts "#{$0} FASTQ OUTPUT_NAME SPLIT_BY [-gz]"
exit
end
fastq = ARGV.shift
output_name = ARGV.shift
split_by = ARGV.shift.to_i
gz_arg=ARGV.shift
gz=''
if !gz_arg.nil? and gz_arg.index('-gz')
gz='.gz'
end
file_index=1
out=FastqFile.new("#{output_n... | true |
a9eb05257cc1a67cdebc6d08ad58a4feefd101c0 | Ruby | singachea/ProjectEuler | /ruby/Problem051.rb | UTF-8 | 2,026 | 4.28125 | 4 | [] | no_license | # By replacing the 1st digit of the 2-digit number *3, it turns out that six of the nine possible values: 13, 23, 43, 53, 73, and 83, are all prime.
#
# By replacing the 3rd and 4th digits of 56**3 with the same digit, this 5-digit number is the first example having seven primes among the ten generated numbers, yieldin... | true |
74d70cb61d41be55e56849d2cc319bba9396e03b | Ruby | ssalinascalibar/E6CP1A1 | /2 ciclos/ejercicio3.rb | UTF-8 | 245 | 3.71875 | 4 | [] | no_license | # Mostrar todos los divisores del numero 990 con
# while, for, times.
i = 1
while i <= 990 do
puts i if 990 % i == 0
i += 1
end
for i in 1..990 do
puts i if 990 % i == 0
end
i = 1
990.times do
puts i if 990 % i == 0
i += 1
end
| true |
838ddd3c33a71ef720e61d054861e2e7eddac22e | Ruby | RutarAndriy/Ruby_Learning | /Lesson_14/Print_result.rb | UTF-8 | 1,649 | 3.375 | 3 | [
"MIT"
] | permissive | class Print_result
# Конструктор
def initialize (reader, path)
@you_win = reader.read_Text_From_File("#{path}/text/you_win.txt")
@game_over = reader.read_Text_From_File("#{path}/text/game_over.txt")
@errors = []
counter = 0
while counter < 7 do
@errors << reader.read_Text_From_File("#{path}/text/errors_#{c... | true |
d91d0e781fc1099c708851d6403331c4c3eaf9cc | Ruby | hooklock/w2d1revision | /specs/river_spec.rb | UTF-8 | 909 | 2.90625 | 3 | [] | no_license | require('minitest/autorun')
require('minitest/rg')
require_relative('../bears')
require_relative('../river')
require_relative('../fish')
class TestRiver <MiniTest::Test
def setup
blinky_fish = Fish.new('Blinky')
jp_fish = Fish.new('James Pond')
dory_fish = Fish.new('Dory')
cleo_fish = Fish.new('Cleo... | true |
5dc75792c8561b228bca0e6ee9d01238da02fbb4 | Ruby | filipows/web_crawler | /main/website_link.rb | UTF-8 | 437 | 2.71875 | 3 | [] | no_license | class WebsiteLink
attr_accessor :value, :description, :link_evaluation, :parent_website_evaluation, :website_evaluation
def initialize(value, description='', link_evaluation=0, parent_website_evaluation = 0, website_evaluation=0)
@value = value
@description = description
@link_evaluation = link_evaluat... | true |
9242dd635ddba0b278c5a5862d6a54639e3ddbee | Ruby | camat-usp/Referencias-Bibliograficas | /build | UTF-8 | 7,400 | 3.203125 | 3 | [] | no_license | #!/usr/bin/ruby
require "asciidoctor"
require "csv"
OUTPUT = File::open "index.html", "w"
DEPARTMENTS = CSV::read "data/departments.csv", headers: true
CODE = "CÓDIGO"
NAME = "NOME"
TITLE = "TÍTULO"
VOLUME = "VOLUME"
AUTHORS = "AUTORES"
YEAR = "ANO"
PDF = "PDF"
DJVU = "DJVU"
EPUB = "EPUB"
class Integer
ROMAN_NUMB... | true |
b06887ef56108fda1d7d612c1afd7ff9ae908e1a | Ruby | natew8/ruby_practice | /DataTypes/hashes.rb | UTF-8 | 284 | 3.78125 | 4 | [] | no_license | # *HASH
# *a data structure that allows us to store key value pairs
# How to create a hash wioth different ways to write the key value pairs.
states = {
:Utah => "UT",
:California => "CA",
"New York" => "NY",
1 => "OR"
}
#! ALl keys must be unique
puts states[1] | true |
1e47b72cad3b5cc62925091c7b89678fa268bef9 | Ruby | heepsters/microblogapp | /main.rb | UTF-8 | 4,186 | 2.65625 | 3 | [] | no_license | #requires all of the gems needed for the poject
require 'sinatra'
require 'sinatra/activerecord'
require 'sendgrid-ruby'
require 'pony'
include SendGrid
enable :sessions
set :database, "sqlite3:blog.sqlite3"
require './models'
# finds the user id of the current user so we can use the current user method
def current_use... | true |
7cc0701d94e4babd35adf4fad657095dbf9608e3 | Ruby | molly-cactus/encrust | /lib/encrust/cli.rb | UTF-8 | 2,626 | 3.03125 | 3 | [
"Unlicense"
] | permissive | require 'encrust'
module Encrust
class CLI
class << self
def start
paths = ARGV.map(&:freeze)
puts greeting(paths)
errors = convert(paths)
puts error_message(errors) if errors.any?
puts instructions if paths.size > errors.size
puts exit_message
end
... | true |
e4ca4991a1d2925ba858f98d538e5525be4afb65 | Ruby | victorsilent/learn-ruby | /function.rb | UTF-8 | 489 | 3.671875 | 4 | [] | no_license | def caesar_cipher(string, key)
new_string = []
string.each_byte do |x|
if x == 32 || (33..64 === x)
new_string << x
end
case x+key
when 65..90
new_string << x+key
when 91..96
new_string << (x+key)-26
when 97..122
new_string << x+key
when 122..300
new_string << (x+key)-26
end
end
... | true |
3ce37e3a5c2d7a825ef947e2ab30e7907af36cbf | Ruby | dominic0312/datashift | /lib/datashift/mapping_services.rb | UTF-8 | 2,507 | 2.90625 | 3 | [
"MIT"
] | permissive | # Copyright:: (c) Autotelik Media Ltd 2015
# Author :: Tom Statter
# Date :: Feb 2015
# License:: MIT
#
# Details:: Read mappings and provide cache type services for source=>destination mappings
#
require 'erubis'
module DataShift
class MappingServices
include DataShift::Logging
# N.B @mappings ... | true |
f6f76fe3884ff6594df66c8c6a952348840b7c79 | Ruby | jhollingworth/Site-performance | /lib/log.rb | UTF-8 | 455 | 2.828125 | 3 | [] | no_license | class Log
def self.message(message)
puts teamcity? ? "##teamcity[progressMessage '#{tc_sanitize(message)}']" : message
end
def self.stat(key, value)
puts teamcity? ? "##teamcity[buildStatisticValue key='#{key}' value='#{value}']" : "#{key}: #{value}"
end
private
def self.tc_sanitize(message)
me... | true |
01b0bc2e7d4fcc495ce5c5faff1a2c43abdab660 | Ruby | ryanwdaly/class-projects | /W2D3/poker/lib/card.rb | UTF-8 | 624 | 3.609375 | 4 | [] | no_license | class Card
attr_reader :suit, :value
CARD_TITLES = [nil,
"Ace",
"One",
"Two",
"Three",
"Four",
"Five",
"Six",
"Seven",
"Eight",
"Nine"... | true |
f6d861eabe30f7804a10b8a0a2e361b640b5cdb2 | Ruby | nlandolfi/dawn-2 | /lib/core/task.rb | UTF-8 | 2,304 | 2.59375 | 3 | [] | no_license |
module Dawn
class Task < ActiveRecord::Base
# --- Core {{{
def key
self.name.downcase.to_sym
end
# --- }}}
# --- Queues {{{
has_many :queued_tasks
has_many :queues, through: :queued_tasks
# --- }}}
# --- Dependencies {{{
has_and_belongs_to_many :dependencies,
... | true |
2eb1e00596b517689da7effba5a7f95f58e97e30 | Ruby | hebron-avant/movie_decision | /lib/start.rb | UTF-8 | 2,243 | 3.046875 | 3 | [] | no_license | require "movie_decision/person"
class MovieRunner
attr_reader :available_movies
def initialize
@available_movies = [
{name: "The Godfather", rating: :r, rotten_tomatoes: 0.98, length: 175},
{name: "Dumb and Dumber", rating: :pg_13, rotten_tomatoes: 0.67, length: 107},
{name: "Anchorman - The Legen... | true |
7984aa6f73e229d26eebc960bb0f86642e0d5002 | Ruby | kosjid/tesler | /lib/tesler/dsl.rb | UTF-8 | 615 | 2.671875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | # sets a directory where to copy files. If this directory doesn't exist, it is created
def directory(directory_name, &block)
Tesler::Copier.directory(directory_name.tesler, &block)
end
# sets the directory where the file that we are copying, are taken from
def source_directory(directory_name)
Tesler::Config... | true |
64044853a7335f9e81b113f24c65a5303eb9cdb1 | Ruby | ryanfield07/rubycode | /classy.rb | UTF-8 | 855 | 4.15625 | 4 | [] | no_license | class Person
attr_accessor :first_name, :last_name
def initialize(first_name, last_name)
@first_name = first_name
@last_name = last_name
end
def full_name
return @last_name + ", " + @first_name
end
def say_something
puts "hello classy! My name is " + @first_name
end
end
... | true |
7356fc9cfc5099c589497f2ba4fa0d7369a349a1 | Ruby | hyphenized/exercism | /ruby/gigasecond/gigasecond.rb | UTF-8 | 179 | 3.453125 | 3 | [] | no_license | class Gigasecond
def self.from(time)
time + 10**9
end
end
# Calculate the moment when someone has lived for 10^9 seconds.
# A gigasecond is 10^9 (1,000,000,000) seconds.
| true |
6a7c2f90644c13ae99d9fba26e16297c639f4ddc | Ruby | james-cape/sweater_weather | /app/services/coordinate_service.rb | UTF-8 | 758 | 2.53125 | 3 | [] | no_license | class CoordinateService
def get_results(address)
data = { address: address }
results = get_json("geocode/json", data)[:results][0]
citystate = "#{results[:address_components][0][:short_name]}, #{results[:address_components][2][:short_name]}"
country = results[:address_components][3][:long_name]
... | true |
5fb06b16f72ca0eb13b55b420e02bf667e9e5bb1 | Ruby | c-brenn/cache_simulator | /lib/cache.rb | UTF-8 | 1,099 | 3.140625 | 3 | [] | no_license | require_relative "./cache/set"
class Cache
attr_accessor :sets
attr_reader :set_bits, :offset_bits
def initialize(num_sets, lines_per_set, bytes_per_line, replacement_policy = :lru)
@set_bits = Math.log2(num_sets).ceil
@offset_bits = Math.log2(bytes_per_line).ceil
initilize_sets(num_sets, lines_per_... | true |
fa2af8ed077e907642ac71a3ce6e3868a0bc27b7 | Ruby | iaintshine/ruby-tracing-logger | /spec/tracing/composite_logger_spec.rb | UTF-8 | 1,140 | 2.515625 | 3 | [
"Apache-2.0"
] | permissive | require "spec_helper"
RSpec.describe Tracing::CompositeLogger do
let(:tracer) { Test::Tracer.new }
describe "initialization" do
it "allows to set multiple destination loggers" do
expect(Tracing::CompositeLogger.new(TestLogger.new, TestLogger.new).destinations.size).to eq(2)
end
end
describe :ad... | true |
25e6b90733d8d77de1e7ca35d208c6e090d9217f | Ruby | BIAINC/perf | /lib/perf/throughput_counter.rb | UTF-8 | 610 | 2.546875 | 3 | [
"MIT"
] | permissive | require_relative 'hash_processor'
module Perf
class ThroughputCounter
include HashProcessor
def initialize(increments)
@increments = increments
end
def start
@start_time = Time.now
end
def stop
duration = ((Time.now - @start_time) * 1000).round
increments = {}
... | true |
11b1812cd0abb069243a5fc73d3f248cca02232f | Ruby | johndillon773/101_109_small_problems | /medium_1/10.rb | UTF-8 | 965 | 4.125 | 4 | [] | no_license | # fibonacci numbers (last digit)
# fib[1] == 1 == 1
# fib[2] == 1 == 1 + 0 == fib[1] + fib[1-1] == fib[6-1-1-1-1-1] + fib[6-2-2-2-2-2]
# fib[3] == 2 == 1 + 1 == fib[2] + fib[2-1] == fib[6-1-1-1-1] + fib[6-2-2-2-2]
# fib[4] == 3 == 2 + 1 == fib[3] + fib[3-1] == fib[6-1-1-1] + fib[6-2-2-2]
# fib[5] == 5 == 3 + 2 == fib... | true |
ce8d6abbbf38a0a3b51652b94a036f9ddaf901e2 | Ruby | DatHT/poker_hands_api | /poker_hands_api/spec/api/v1/service/validation_service_spec.rb | UTF-8 | 1,927 | 2.59375 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe V1::Service::ValidationService do
include V1::Service::ValidationService
describe 'ValidationServiceのテストケース' do
example('入力されたデータが五つ項目があるかのチェック') do
expect(check_enough_items(['H1 H13 H12 H11 H10', 'H9 C9 S9 H2 C2', 'C13 D12 C11 H8 H7'])).to eql(false)
expect(ch... | true |
2e6922db580e4670d59b772ea943a5841ea6b4b7 | Ruby | sijos/homeworks | /Algorithms Projects/BinarySearchTrees/lib/tree_test.rb | UTF-8 | 187 | 3.265625 | 3 | [] | no_license | require_relative 'binary_search_tree'
bst = BinarySearchTree.new
[5, 3, 7, 1, 4, 9, 0, 2, 1.5, 10].each do |el|
bst.insert(el)
end
par = bst.parent(1)
p "Parent of 9 is #{par.value}" | true |
1d7de28d121285c499bb79d826aae619ace858db | Ruby | Vishalsh/book-sharing-app | /app/models/book.rb | UTF-8 | 924 | 2.625 | 3 | [] | no_license | class Book < ActiveRecord::Base
validates :title, :description, :author, presence: true
validates :isbn, :isbn_format => true
validates :edition, numericality: {only_integer: true}, :allow_nil => true
has_and_belongs_to_many :owners, class_name: User, join_table: :books_owners
has_and_belongs_to_many :tags
... | true |
a234e1005ed932dfde3ec260dba3d0eaf1ff427c | Ruby | link2prasad/campaign-manager | /app/models/concerns/tag_names.rb | UTF-8 | 798 | 2.984375 | 3 | [] | no_license | class TagNames
include Enumerable
def initialize(taggable)
@taggable = taggable
end
def self.new_with_names(taggable, names)
tag_names = new(taggable)
tag_names.clear
names.each { |name| tag_names << name } if names
tag_names
end
def to_a
taggable.tags.collect &:name
end
def... | true |
37bfcce28e3b0d5d7262146a224d02c89118cb59 | Ruby | NensiMakawana/hospital_system | /app/models/appointment.rb | UTF-8 | 1,464 | 2.65625 | 3 | [] | no_license | class Appointment < ApplicationRecord
########################Associations##################################
belongs_to :patient
belongs_to :doctor
belongs_to :availibility_time_slot, optional: true
########################Validations##################################
validate :valid_time_slot?, :check_avai... | true |
80f569f7c8b3201e30fba917e21d116f01ef54d1 | Ruby | haydenf/AssignmentOne | /name_class.rb | UTF-8 | 1,130 | 3.90625 | 4 | [] | no_license | #enter a name
require_relative 'zoo_story.rb'
require_relative 'jungle_story.rb'
require 'colorize'
##Requiring files needed to work
##class name method
class Name
attr_reader :names
#so we can use names in other files
def user_name
@names = [] #chose an array to store names, as it's eas... | true |
ac10ea860ac880b7ead2687c843e0bd5b0483678 | Ruby | kaalm1/CLI-Project-With-Sinatra | /app/models/tree.rb | UTF-8 | 1,010 | 2.84375 | 3 | [] | no_license | class Tree < ActiveRecord::Base
#belongs_to :hangman
def self.build_tree
newtree = "\n"
newtree += " ___\n"
newtree += " | |\n"
(1..5).each do
newtree += " |\n"
end
newtree += " --\n"
newtree
end
def self.new_tree_arr
newtree = ["\n"]
newtree << [" ","_","_","_","... | true |
c1746086e1bae153912a662b2fee821adbfb293e | Ruby | Jauny/connect_four | /lib/connect_four/game.rb | UTF-8 | 1,128 | 3.140625 | 3 | [] | no_license | class Game
attr_reader :player1, :player2, :winner, :board, :players
def initialize(player1, player2)
@player1 = player1
@player2 = player2
@players = [@player1, @player2]
@board = Board.new
end
def play
until over?
board.place_piece(current_player.move, current_player.piece)
t... | true |
7d0be9a970d52e0c29889eeabf6e55b636ccb23a | Ruby | saaineui/spineless | /test/models/book_test.rb | UTF-8 | 5,698 | 3 | 3 | [] | no_license | require 'test_helper'
class BookTest < ActiveSupport::TestCase
def setup
@book = Book.new(title: 'Ex ex', author: 'Ex Ex', logo_url: 'http://ex.png', cover_image_url: 'http://ex.png')
@book_with_sections = books(:public)
end
test 'should be valid' do
assert @book.valid?
end
test '#title shoul... | true |
1c9b420b4b7ee8c1c920067c3013c09db206c5ed | Ruby | Dice-K39/Flatiron_Ruby | /ttt-with-ai-project-onl01-seng-pt-041320/lib/board.rb | UTF-8 | 1,774 | 3.890625 | 4 | [] | no_license | require 'pry'
class Board
attr_accessor :cells
@cells = []
def initialize
self.cells = Array.new(9, " ")
#@cells = [" ", " ", " ", " ", " ", " ", " ", " ", " "]
end
def display
puts " #{self.cells[0]} | #{self.cells[1]} | #{self.cells[2]} "
puts "-----------"
... | true |
2bbb8f7ff83fdfe5bb1599fd39dee1db5858e2bc | Ruby | kandalf/cdmon_updater | /bin/cdmon_config | UTF-8 | 3,166 | 2.65625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require 'optparse'
options = {}
@config_options = {}
optparse = OptionParser.new do |opts|
opts.banner = "Usage cdmon_config [options]
If no options are given, current configuration will be shown."
opts.on('-g', '--generate', 'Generates configuration') do
options[:generate] = true
en... | true |
a6da7fee4660af3058120e1dd27a183a48f2a7c4 | Ruby | ktemkin-archive/ruby-adept | /lib/adept/data_formats/bitstream.rb | UTF-8 | 2,975 | 2.828125 | 3 | [
"MIT"
] | permissive |
require 'date'
require 'bindata'
require 'adept/data_formats/data_factories'
module Adept
module DataFormats
#
# Class for the Xilinx bitstream file format.
#
# Format used was described at
# <http://www.fpga-faq.com/FAQ_Pages/0026_Tell_me_about_bit_files.htm>
#
class Bitstream < BinD... | true |
4035609b8610037d1999df40136b03be20eb968a | Ruby | reid-andrew/museo_2001 | /test/curator_test.rb | UTF-8 | 6,974 | 2.9375 | 3 | [] | no_license | require 'minitest/autorun'
require 'minitest/pride'
require './lib/curator.rb'
require './lib/photograph.rb'
require './lib/artist.rb'
class CuratorTest < Minitest::Test
def setup
@curator = Curator.new
@photo_1 = Photograph.new({
id: "1",
name: "Rue Mouffetard, Paris (Boy with Bottles)",
... | true |
699b20d4de3f0a1e98333c0fae4a3d228a341e1c | Ruby | blainelawson/ruby-music-library-cli-online-web-sp-000 | /lib/music_library_controller.rb | UTF-8 | 3,058 | 3.703125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require "pry"
class MusicLibraryController
attr_accessor :path
attr_reader :music
def initialize(path = "./db/mp3s")
@music = MusicImporter.new(path)
@music.import
end
def call
input = nil
while input != "exit" do
puts "Welcome to your music library!"
puts "To list all of your ... | true |
4d5bcf278a5532f1000f819c7c9afb3d652bdaf3 | Ruby | timrogers/starling-ruby | /lib/starling/resources/base_resource.rb | UTF-8 | 2,481 | 3.125 | 3 | [
"MIT"
] | permissive | require 'json'
require 'time'
require 'date'
module Starling
module Resources
# A basic implementation of a resource representing a response from the Starling Bank
# API
class BaseResource
# A resource can be instantiated with either a Faraday::Response (including a
# #body), or with a Hash p... | true |
4b2a1ec88372b06668ff4880efe839ac63336038 | Ruby | chrisolsen/feedrrr | /lib/feedrrr.rb | UTF-8 | 3,405 | 2.84375 | 3 | [] | no_license | # Feedrrr
#
# Overview:
# Allows for conversion of RSS feeds to a JSON format
#
# Usage:
# # Will attempt to fetch from http://some_domain.com and will follow any redirects.
# # Will return the description, title and pubDate(default).
# > RSS::Feedrrr.new("http://some_domain.com", fields: [:description, :title]... | true |
2027aedcee6319d337df37f7d6291eddbd20b3fa | Ruby | dmasur/degu | /spec/renum_spec.rb | UTF-8 | 7,665 | 3.15625 | 3 | [
"MIT"
] | permissive | require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
enum :Status, [ :NOT_STARTED, :IN_PROGRESS, :COMPLETE ]
enum :Fuzzy, [ :FooBar, :BarFoo ]
describe "basic enum" do
it "creates a class for the value type" do
Status.should be_an_instance_of(Class)
end
it "makes each value an instance of th... | true |
cbf9f6d91f7b1a31bb8527bc5b838136f9e0ba5b | Ruby | bjornblomqvist/biosphere | /core/lib/biosphere/augmentations.rb | UTF-8 | 2,119 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'biosphere/resources/file'
require 'biosphere/errors'
require 'biosphere/paths'
require 'pathname'
module Biosphere
class Augmentations
def initialize(sphere: nil)
@sphere = sphere
end
# Convenience Wrapper
def self.implode
new.implode
end
def call
implode if sphe... | true |
bb7a8d0a09afca6423b128f972dcf612a8f0a259 | Ruby | kmcgrevey/backend_module_0_capstone | /day_1/exercises/variables.rb | UTF-8 | 1,237 | 4.65625 | 5 | [] | no_license | # In the exercises below, write your own code where indicated
# to achieve the desired result. You should be able to run this
# file from your terminal with the command `ruby day_1/exercises/variables.rb`
# example: Write code below to save your name to a variable and
# print that variable to the terminal:
name = "Har... | true |
6c7c12061ba01900f2586f532921e058fe1fd4c1 | Ruby | nfo/zenpush | /lib/zenpush/runner.rb | UTF-8 | 1,800 | 2.578125 | 3 | [
"MIT"
] | permissive | # encoding: UTF-8
require 'boson/runner'
require 'ap'
module ZenPush
class Runner < Boson::Runner
desc 'List categories'
def categories(options = {})
ap ZenPush.z.categories
end
desc 'List forums'
def forums(options = {})
ap ZenPush.z.forums
end
option :forum_id, :type => :... | true |
135d20347a485a6b00ccaaca1c8b860d225de9df | Ruby | Means88/practice | /leetcode/0005-longest-palindromic-substring.rb | UTF-8 | 502 | 3.625 | 4 | [
"MIT"
] | permissive | def get_palindrome(s, l, r)
return '' if l < 0 || r >= s.length
return '' if s[l] != s[r]
while l > 0 && r < s.length - 1
return s[l, r - l + 1] if s[l - 1] != s[r + 1]
l -= 1; r += 1
end
return s[l, r - l + 1]
end
# @param {String} s
# @return {String}
def longest_palindrome(s)
result = ''
s.eac... | true |
46214a17574e764f72e9ce5cf81e41e4981b3a71 | Ruby | Telephonist/flashcards | /db/seeds.rb | UTF-8 | 765 | 2.640625 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
b273a7532d90341c600fc17790633421c822f6ce | Ruby | YongLiang24/oo-relationships-practice-seattle-web-career-012819 | /app/models/ingredient.rb | UTF-8 | 570 | 3.453125 | 3 | [] | no_license | class Ingredients
attr_accessor :name, :calory, :dessert
@@all = []
def initialize(name, dessert, calory)
@name = name
@calory = calory
@dessert = dessert
@@all << self
end
def self.all
@@all
end
def bakery
#return the bakery object for the bakery that uses that ingredien... | true |
b41a95e8e30dd663e1e4a2cb784a877c9a0feed8 | Ruby | gougoudata/cygwin-1 | /usr/share/texmf-dist/scripts/epspdf/epspdf.rb | UTF-8 | 40,370 | 2.625 | 3 | [] | no_license | #!/usr/bin/env ruby
# epspdf conversion utility, main source
#####
# Copyright (C) 2006, 2008, 2009, 2010, 2011 Siep Kroonenberg
# n dot s dot kroonenberg at rug dot nl
#
# This program is free software, licensed under the GNU GPL, >=2.0.
# This software comes with absolutely NO WARRANTY. Use at your own risk!
#####
... | true |
767fe6e151397fd5bc2edd520ea7922047897cba | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/cs169/800/feature686/whelper_source/22375.rb | UTF-8 | 181 | 3.0625 | 3 | [] | no_license | def combine_anagrams(words)
hash = {}
words.each do |word|
key = word.downcase.split("").sort.join("")
hash[key] ||= []
(hash[key] << word)
end
hash.values
end
| true |
4164ad0970cbc3c1c8e6889fd3fbe4cb80e3a2b8 | Ruby | kdym/oqtaconteseno-web | /app/helpers/events_helper.rb | UTF-8 | 508 | 2.78125 | 3 | [] | no_license | module EventsHelper
def humanize_minutes minutes
text = []
days = minutes / (60 * 24)
if days.to_i > 0
text << sprintf('%s%s', days.to_i, I18n.t('time_units.days.small'))
end
hours = days.modulo(1) * 24
if hours.to_i > 0
text << sprintf('%s%s', hours.to_i, I18n.t('time_units.ho... | true |
05f44818163ac0e0e7c2b3b8c60e36b57229cea6 | Ruby | tylerruby/refresh | /app/searchers/cloth_searcher.rb | UTF-8 | 2,475 | 2.734375 | 3 | [] | no_license | class ClothSearcher
attr_accessor :store
def initialize(search_params)
self.store = Store.find_by(id: search_params[:store_id])
self.gender = search_params[:gender]
self.category_id = search_params[:category_id]
self.size = search_params[:size]
self.max_price = search_params... | true |
fbefd237ccde8ec0896aee69e745c1e01a97faf4 | Ruby | jan-czekawski/introduction-to-programming-exercises | /regex/using/ex_7.rb | UTF-8 | 851 | 4.09375 | 4 | [] | no_license | # Challenge: write a method that changes dates in the
# format 2016-06-17 or 2016/06/17 to the format 17.06.2016. You
# must use a regular expression and should only use methods
# described in this section.
def format_date(org_date)
# org_date.gsub(/\A(\d{4})([\-\/])(\d{2})\2(\d{2})\z/, '\4.\3.\1')
org_date.gsub... | true |
c9ee24c6567b6d40a086c677deebfb2745e2ca1f | Ruby | redferret/viewing_party | /spec/services/movies_api/api_calls_spec.rb | UTF-8 | 4,143 | 2.609375 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe MoviesAPI::Client do
describe 'API Call' do
describe '::trending_movies' do
it 'returns movies trending for the week' do
trending_movies_mock_path = EndpointStitch::stitch(MoviesAPI::Client::trending_movies_endpoint)
trending_movies_mock_data = MoviesAP... | true |
6333b3f5b6cac4ce09a5cce8001a1d13ec93864d | Ruby | bpot/sha1_hashing_ey_2009 | /bin/producer.rb | UTF-8 | 695 | 2.78125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'lib/shared'
STEMS_PER_MESSAGE = 32
THROTTLE = 15
def official_phrase
@official_phrase ||= File.open("data/official_phrase.txt") { |f| f.read }.chomp
end
# stem is ASCII string
def work_message(stems)
{
:official_phrase => official_phrase,
:stems => stems,
:permutations... | true |
ed9f8f7c7495943b8cc2a396df59c43614cb9435 | Ruby | klaubel/my-select-001-prework-web | /lib/my_select.rb | UTF-8 | 278 | 3.5625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def my_select(collection)
new_array = []
if collection.length != 0
i = 0
while i < collection.length do
if yield(collection[i])
new_array << collection[i]
end
i += 1
end
new_array
else puts "This block should not run!"
end
end | true |
f9d942f99c7fb2cd9a12fb95bdf2a6c41deb3eb4 | Ruby | wconrad/basic101 | /test/spec/transform_spec.rb | UTF-8 | 20,735 | 2.609375 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative 'spec_helper'
module Basic101
describe Transform do
let(:parser) {Parser.new}
def self.parse(rule_name, s)
parser = Parser.new.send(rule_name)
parser.parse(s)
end
def self.transform(rule_name, s)
parse_tree = parse(rule_name, s)
... | true |
3bde1de0974542effacc405ebc0b67d8965ba01f | Ruby | om-nishimoto-ryoga/ruby- | /lesson2.rb | UTF-8 | 80 | 2.640625 | 3 | [] | no_license | puts "私の名前は西本凌雅です。年齢は" + 22.to_s + "歳です。"
| true |
54b546009be3370c0d125d2db943cae7a8c301dc | Ruby | danielafdc/Cursos_Alura_Ruby | /Alura - Ruby I/Aula 1 e 2/teste.rb | UTF-8 | 89 | 3.296875 | 3 | [] | no_license | puts "Vou contar de 1 até 3"
for contagem in 1..3
puts "Contando: " + contagem.to_s
end | true |
4a6a14c4ddbaa184015617e568f68ef3e507c585 | Ruby | sonataFarm/cracking-the-coding-interview | /1.5.rb | UTF-8 | 732 | 3.234375 | 3 | [] | no_license | def one_edit_away?(a, b)
length_diff = (a.length - b.length).abs
return false if length_diff > 1
if length_diff == 1
# test for insert / remove
smaller = a.length < b.length ? a : b
bigger = a.length > b.length ? a : b
edit_found = false
i, j = 0, 0
while i < smaller.length do
if... | true |
fb7ad757f5a0296f0ac400556d71f9017997f4e0 | Ruby | SlavBorowski/adventure_game | /lib/room_list.rb | UTF-8 | 1,305 | 3.390625 | 3 | [] | no_license | # The RoomList stores all the individual rooms that make up the world.
class RoomList
attr_accessor :rooms
def initialize
@rooms = read_rooms
end
# Read all the rooms from a JSON file.
def read_rooms
file_data = File.read(WORLD_DATABASE)
JSON.parse(file_data).map do |room|
Room.new... | true |
aba4ea15483deb82bab0a8f497a088baedb7e997 | Ruby | MikeSalisbury/AppAcademy_Homeworks | /Week 2/W2D4/Octopus.rb | UTF-8 | 1,832 | 3.78125 | 4 | [] | no_license | fish_array = [
'fish',
'fiiish',
'fiiiiish',
'fiiiish',
'fffish',
'ffiiiiisshh',
'fsh',
'fiiiissshhhhhh']
def sluggish_octopus(arr)
result = arr[0]
arr[0...-1].each_with_index do |fish1, idx|
arr[idx + 1..-1].each do |fish2|
if fish2.length > fish1.length
result = fish2
else... | true |
5a3eee52bbda1a58be6886fd65bfb2769aa3e3fe | Ruby | nippysaurus/NuckChorris | /FormatFacts/GroupSortFacts.rb | UTF-8 | 3,243 | 3.109375 | 3 | [
"BSD-2-Clause-Views"
] | permissive | require 'csv'
values = CSV.read("FactsMasterList.csv")
$facts = { 1 => [], 2 => [], 3 => [], 4 => [], 5 => [] }
values.each do |bla|
if (bla[0].to_i == 0) then next end
#$facts[bla[0].to_i].push(bla[1])
data = { :number => bla[1], :hidden => bla[2], :string => bla[3] }
if (data[:hidde... | true |
753b4dee1f0f3910073b0e56e40f9860929b7f6d | Ruby | thiagoramos23/growing-oo-software-in-ruby | /src/12-ready-to-bid/app/sol-text.rb | UTF-8 | 884 | 3.484375 | 3 | [] | no_license | require 'enumerator'
# I made this string-creating class because I'm bad at typing out
# strings. I especially always forget the ending semicolon.
class SOLText
include Enumerable
def self.empty
# Used when any random message is to be sent.
make("UNDERSPECIFIED")
end
def self.join
make("JOIN")
... | true |
d1e17de979afc12023d7d31a44e02c71d6ae33bf | Ruby | priyapower/backend_module_0_capstone | /day_4/exercises/ex_three_drill3.rb | UTF-8 | 2,808 | 4.0625 | 4 | [] | no_license | #I wrote this program while trying to convince my husband we need more animals.
#The end answer is I can have my dog farm, we just need the farm first :)
def cats_and_dogs(cat_count, dog_count)
puts "There is/are #{cat_count} cunning, creative cat(s)!"
puts "There is/are #{dog_count} daring, dazzling dog(s)!"
if ... | true |
a5e33de1f20edc45fddbf42ee5023d8c73444061 | Ruby | stevefake/2016.03.10 | /currency_converter.rb | UTF-8 | 1,099 | 3.3125 | 3 | [] | no_license | require_relative 'currency'
class CurrencyConverter
# attr_accessor :target_code # => nil, nil
CODE_CONVERSION_RATES = {
:USD => {
:USD => 1,
:EUR => 0.88,
:JPY => 111.24
},
:EUR => {
:EUR => 1,
:USD => 1.13,
:JPY => 125.94
},
:JPY => {
:JPY => 1,
... | true |
82ed5aee0dd73fda9fc90e1114d485173aa781f6 | Ruby | Marvin-/wgc_groundwork | /primes.rb | UTF-8 | 464 | 3.546875 | 4 | [] | no_license | class Primes
def self.sum_to(n = 100)
#Pseudocode from wikipage of Sieve of Eratosthenes
list = [*2..n]
p = 2
loop do
i = p
until p >= n
p += i
list.delete(p)
end
if list.find{ |x| x > i }
p = list.find{ |x| x > ... | true |
2a7f0de18e1f27bcf49bfe1b15c2e58338404d99 | Ruby | Sureshkumar5694/test-rails | /app/models/user.rb | UTF-8 | 418 | 2.734375 | 3 | [] | no_license | class User < ActiveRecord::Base
validates :mobile_number,:presence => true, :numericality => true, :length => { :minimum => 10, :maximum => 11 }
def is_otp_expired?
otp_expires_at.nil?|| otp_expires_at.past?
end
def generate_otp
otp =(0...6).map { rand(9) }.join
update(otp: otp, otp_expires_at: DateTime.c... | true |
68827f6c998b294e28e9ca5b08d2ead214322f08 | Ruby | karagenit/dangerless | /test/test-dangerless.rb | UTF-8 | 650 | 3.015625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
require_relative '../lib/dangerless.rb'
require 'test/unit'
class TestClass
attr_reader :val
def set_val!(val)
@val = val
end
include Dangerless
def other_test!(val)
val
end
end
class TestDangerless < Test::Unit::TestCase
def test_exist
test = TestClass.new
asser... | true |
f0658d6acdf93663a564d96e3880f7ebf8558509 | Ruby | Heshamsalah/coaches_students | /app/services/student_service/serve.rb | UTF-8 | 559 | 2.515625 | 3 | [] | no_license | module StudentService
class Serve < ServiceBase
class << self
def index
Student.page(args[:page].to_i).per(args[:per_page].to_i)
end
def show
Student.find(args[:id])
end
def create
Student.create!(name: args[:name])
end
def update
studen... | true |
be914e38653fd49abb6930b2af9b76a8958bc472 | Ruby | adcousin/hops | /db/seeds.rb | UTF-8 | 6,168 | 2.875 | 3 | [] | no_license | # This file should contain all the record creation needed to seed the database with its default values.
# The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
#
# Examples:
#
# movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
# Ch... | true |
3c95305e096304fe2ec11dcc80e701fc60eaa6ec | Ruby | micsch91/ruby-oo-fundamentals-classes-and-instances-lab-nyc01-seng-ft-062220 | /lib/dog.rb | UTF-8 | 126 | 2.71875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Dog
end
#Below instantiates fido, snoopy, lassie as dogs in class Dog
fido = Dog.new
snoopy = Dog.new
lassie = Dog.new | true |
045035f26e977869ce290dbb353f216a0f7b8dda | Ruby | bellef/getaround_backend_application | /level1/main.rb | UTF-8 | 844 | 3.125 | 3 | [] | no_license | require_relative './rental'
require_relative './car'
INPUT_FILE_PATH = 'data/input.json'
OUTPUT_FILE_PATH = 'data/output.json'
def deserialize_input_cars(input_data)
input_data[:cars].map do |car_data|
Car.new(**car_data)
end
end
def deserialize_input_rentals(input_data, cars)
input_data[:rentals].map do ... | true |
a46d4db95fea859b75cd6050fc6c66d026ce1dc7 | Ruby | blargen/skillcrush-ruby-challenges | /ruby_challenges/blog.rb | UTF-8 | 2,051 | 3.65625 | 4 | [] | no_license | class Blog
@@blog_count = 0
@@all_posts = []
def store_blawg
post = {
title: @title,
date: @date,
content: @content,
author: @author
}
@@all_posts << post
@@blog_count += 1
end
def show_me_the_money?
puts "Would you like to see your amazing blog pos... | true |
9bc0fbcc9f51f7c85d41c6b128a9bd86dd865b6c | Ruby | ifasanelli/qsd-coupons | /app/models/product.rb | UTF-8 | 662 | 2.53125 | 3 | [] | no_license | class Product
attr_accessor :id, :key
def initialize(id, key)
@id = id
@key = key
end
def self.api_version
'v1'
end
def self.endpoint
Rails.configuration.qsd_apis[:product_url]
end
def self.product_url
"#{endpoint}/api/#{api_version}"
end
def self.all
request_url = "#{pro... | true |
7604f6349d47c34c184e9a8513643043384ba350 | Ruby | CamleGem/GemRepo | /wc.rb | UTF-8 | 304 | 2.625 | 3 | [] | no_license | ltotal = 0
wtotal = 0
ctotal = 0
file = File.open('testing')
begin
file.each_line do |line|
ltotal += 1
ctotal += line.size
line.sub!(/^\s+/, '')
ary = line.split(/\s+/)
wtotal += ary.size
end
rescue => ex
puts "#{ex.message}"
end
printf("%d %d %d %s\n", ltotal, ctotal, wtotal, 'total')
| true |
3f2755a51a7ea300c6a1777bbee0b8bcceef4b89 | Ruby | tassyo1/vota_prato | /app/models/concerns/capitalization.rb | UTF-8 | 303 | 3.34375 | 3 | [] | no_license | module Capitalization
extend ActiveSupport::Concern
module ClassMethods
end
module InstanceMethods
end
# Coloca o nome do restaurante em letra maiúscula. Ex: "bom grill" => "Bom Grill"
def maiuscula(variavel)
variavel.downcase.split.map { |e| e.capitalize }.join(" ")
end
end
| true |
f9e678a58c62665934732a64cdde0fd6c980b604 | Ruby | kkavita92/advent-of-code | /2017/ruby/day11/day11_part2.rb | UTF-8 | 534 | 3.359375 | 3 | [] | no_license |
file_path = File.expand_path("../input.txt", __FILE__)
input = File.read(file_path)
directions = input.strip.split(",")
x = 0
y = 0
start = [0, 0]
distances = []
def distance(start, finish)
y = finish[1] - start[1]
x = finish[0] - start[0]
[x.abs, y.abs, (y - x).abs].max
end
directions.each { |direction|
cas... | true |
2a30f09373cddbaff7a9a8db41ba4d204eea01e7 | Ruby | satyasinha94/the-bachelor-todo-nyc-web-111918 | /lib/bachelor.rb | UTF-8 | 1,133 | 3.578125 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | require 'pry'
def get_first_name_of_season_winner(data, season)
data[season].each do |contestants|
if contestants["status"] == 'Winner'
return contestants["name"].split(" ")[0]
end
end
end
def get_contestant_name(data, occupation)
data.each do |season, contestants|
contestants.each do |contest... | true |
887e0c120b806a83162f548b208a3b053b95990d | Ruby | mbj/unparser | /lib/unparser/emitter/pair.rb | UTF-8 | 611 | 2.71875 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
module Unparser
class Emitter
# Emitter for key value pairs in hash literals or kwargs
class Pair < self
BAREWORD = /\A[A-Za-z_][A-Za-z_0-9]*[?!]?\z/.freeze
private_constant(*constants(false))
handle :pair
children :key, :value
private
def ... | true |
8c41d3c4afe8cdeb93449a993dc305a4684e23c9 | Ruby | tor-oscar/resistance-web | /app/models/mission.rb | UTF-8 | 997 | 2.53125 | 3 | [
"MIT"
] | permissive | class Mission < ActiveRecord::Base
belongs_to :game
has_many :nominations
has_many :mission_results
validates :nominations, length: { maximum: 5,
too_many: "Only five nominations are allowed" }
validate :only_one_active_nomination
validate :one_mission_result_per_player
def only_one_active_nominatio... | true |
c1559bd3aaa4cc007cf8a626634cb713a96265a1 | Ruby | antoniojking/craft_time_2105 | /lib/person.rb | UTF-8 | 295 | 3.171875 | 3 | [] | no_license | class Person
attr_reader :name,
:interests,
:supplies
def initialize(attributes)
@name = attributes[:name]
@interests = attributes[:interests]
@supplies = {}
end
def add_supply(supply, quantity)
@supplies[supply] = quantity
end
end
| true |
b66f1b00c051f36e0334ef0a29011b730981ccff | Ruby | kematzy/alt-tmbundles | /_Alt_Experimental.tmbundle/Support/replace_colors.rb | UTF-8 | 1,721 | 2.90625 | 3 | [] | no_license | #!/usr/bin/env ruby
# Replace all of the occurrences of the selected color with the chosen color in the current document.
# Thomas Aylott -- subtleGradient.com
require ENV['TM_SUPPORT_PATH'] + "/lib/ui"
FILENAME = ENV['TM_FILEPATH']
VALID_COLOR = /^#?[0-9a-f]{3,6}$/i
VALID_COLOR_SHORT = /^#?([0-9a-f])([0-9a-f])([0-9a... | true |
66230bcd0d8f27aeb56f6c0a4f2601051ab2305a | Ruby | hugopacosta/enade | /test/models/curso_test.rb | UTF-8 | 654 | 2.609375 | 3 | [] | no_license | require 'test_helper'
class CursoTest < ActiveSupport::TestCase
test 'valida nome do curso' do
curso = Curso.new
assert_not curso.save, "Curso foi salvo sem nome!"
end
test 'nome do curso nao esta em branco' do
curso = Curso.new(:nome_do_curso => " ")
assert_not curso.save, "Curso salvo com nom... | true |
299d3d802c0bfa25a94841f8aab81f69e1bf0083 | Ruby | michaelmcbean/say-hello-ruby | /say_hello.rb | UTF-8 | 116 | 3.25 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Build your say_hello method here
def say_hello(marvin = "Ruby Programmer")
puts "Hello #{marvin}!"
end
| true |
f4d88a7d27c4f011682f7be39ba8e493d0457214 | Ruby | guardian/archivehunter | /cloudformation/make-dev-stack.rb | UTF-8 | 7,452 | 2.953125 | 3 | [] | no_license | #!/usr/bin/env ruby
require 'yaml'
require 'optimist'
require 'awesome_print'
def types_to_filter(exclude_lambdas)
types_to_filter_out = [
"AWS::Elasticsearch::Domain",
"AWS::ElasticLoadBalancing::LoadBalancer",
"AWS::IAM::InstanceProfile",
"AWS::EC2::SecurityGroupIngress",
"AWS::AutoS... | true |
8040952531a6489868fc315fd1cfb20628348ff9 | Ruby | LauraKirby/fun_code | /rubyc/lib/binary_tree.rb | UTF-8 | 1,917 | 4.28125 | 4 | [] | no_license | class Node
attr_accessor :left, :right, :val
def initialize(val, left = nil, right = nil)
@val = val
@left = left
@right = right
end
end
class BinaryTree
attr_accessor :insert, :print_tree
def initialize(root_value)
@root = insert(root_value)
end
def insert(val)
node = create_nod... | true |
12b7d800567ded11676e379661dba03bde9d5d01 | Ruby | jtb6179/ruby-oo-practice-has-many-through-template-dumbo-web-120919 | /lib/Bartenders.rb | UTF-8 | 1,308 | 3.296875 | 3 | [] | no_license | #class for Model3 goes here
#Feel free to change the name of the class
class Bartender
attr_reader :gender, :name
attr_accessor :age, :club
@@all = []
def initialize(name, age, gender, club)
@name = name
@age = age
@gender = gender
@club = club
@@all << self
... | true |
a20d0a732f4753f4315610d6f7250d27abc6695e | Ruby | pdwittig/rungo | /lib/tasks/seed_stop_data.rake | UTF-8 | 1,832 | 2.6875 | 3 | [] | no_license | namespace :seed do
desc "Get a list of all stops and populate db"
task populate_stop_data: :environment do
route_count = 0
api_client = TransitApiClient.new
agencies = Agency.all
agencies.each do |agency|
p "*********Agency: #{agency.name}************"
if agency.directional
agen... | true |
75169ce9bac844a73b1778004e9a0828ae8d9af5 | Ruby | jannade/meow | /app/models/goal.rb | UTF-8 | 378 | 2.59375 | 3 | [] | no_license | class Goal < ApplicationRecord
belongs_to :connection
has_many :milestones
def perc_completed
if self.milestones.count > 0
total_ms = self.milestones.count
completed_ms = self.milestones.where(is_completed: true).count
(completed_ms.to_f / total_ms.to_f)*100
else
0
end
end
... | true |
d025d2818fbfd456ff455dfa17f00e164246aa52 | Ruby | RamonSchmitt/Codaisseur_Week1_Beginner_bootcamp | /D3_store/my_store.rb | UTF-8 | 1,535 | 3.546875 | 4 | [] | no_license | require './department'
require './product'
require './shoppingcart'
#Departments
dept_name = []
dept_name << Department.new("Jewlery")
dept_name << Department.new("Clothes")
dept_name << Department.new("School Stuff")
dept_name << Department.new("Electronics")
#add them to the jukebox
box = Department.new(dept_name)
... | true |
18ffb23454974580294f0dfb98f745196b2e77bd | Ruby | aaronmgdr/learnTDD | /test_fb.rb | UTF-8 | 805 | 3.078125 | 3 | [] | no_license | require 'minitest/autorun'
require_relative 'fizzbuzz.rb'
class TestFizzBuzz < MiniTest::Test
def setup
@FizzBuzz = FizzBuzz.new(36)
@exptect_results = [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz", "Fizz", 22, 23, "Fizz", "Buzz", 26, "Fiz... | true |
f49a0185152eb89178d56f3a04133d0b91d66cc3 | Ruby | dominiek/kakuteru | /lib/friendfeed.rb | UTF-8 | 1,612 | 2.546875 | 3 | [
"CC-BY-3.0"
] | permissive |
require 'ostruct'
require 'mechanize'
require 'rexml/document'
require 'date'
class Friendfeed
def initialize(url)
@url = url
end
def fetch(&block)
agent = WWW::Mechanize.new
page = agent.get(@url)
xml = REXML::Document.new(page.body)
xml.elements['/feed'].each do |xml_entry|
nex... | true |
bc25e1a9c7152f78a59d478104765a630c9dd2e6 | Ruby | cranderson9/practice_problems | /hash_practice.rb | UTF-8 | 2,663 | 3.71875 | 4 | [] | no_license | # 1. Make a hash to store a person's first name, last name, and email address. Then print each attribute on separate lines.
person = {first_name: "Cale", last_name: "Anderson", email: "caleanderson@gmail.com"}
p person[:first_name]
p person[:last_name]
p person[:email]
# 2. Make an array of hashes to store the first... | true |
4606996f1bf259bfc7be0dcc227d7d126cca2540 | Ruby | MiraMarshall/hotel | /lib/manager.rb | UTF-8 | 340 | 2.765625 | 3 | [] | no_license |
require_relative "reservation"
require_relative "room"
class Manager
attr_reader :rooms
def initialize
@rooms = rooms
end
def make_rooms
@rooms = (1..20).to_a.map! do |room|
Room.new(id: room)
end
end
def all_reservations
@reservations << book_reservation(vacant_room, check_in, c... | true |
a9d07ee0b0565d664debd907cdcdf5675b160f8c | Ruby | aimeerivers/ruby_design_patterns | /creational_patterns/abstract_factory/lib/maze_factory.rb | UTF-8 | 221 | 2.90625 | 3 | [] | no_license | class MazeFactory
def make_maze
Maze.new
end
def make_wall
Wall.new
end
def make_room(room_number)
Room.new(room_number)
end
def make_door(room1, room2)
Door.new(room1, room2)
end
end
| true |
89463391379136db9e8b59ddc9310f22af00ddd2 | Ruby | codeunion/topics-in-cs | /session-notes/2015-03-11/shuffle_swap.rb | UTF-8 | 324 | 3.296875 | 3 | [] | no_license | def shuffle_swap(list)
n = list.length
n.times do
i, j = rand(0...n), rand(0...n)
list[j], list[i] = list[i], list[j]
end
list
end
if __FILE__ == $PROGRAM_NAME
sample_count = ARGV[0].to_i
values = ARGV[1].split(",")
sample_count.times do
puts shuffle_swap(values.dup).join("-")
end
... | true |
5527a3f9394caf6fa8c355f5680e275e6b729686 | Ruby | clacaille/sumo | /app/models/intercommunality.rb | UTF-8 | 671 | 2.75 | 3 | [] | no_license | class Intercommunality < ApplicationRecord
after_save :set_slug
has_many :communes
validates :name, presence: true
validates :siren, presence: true, uniqueness: { case_sensitive: false }, length: { is: 9 }
validates :form, inclusion: { in: ["ca", "cu", "cc", "met"] }
def communes_hash
communes.map { ... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.