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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
c4784558ccd70281ec1670aa460a472a36741f85 | Ruby | fursich/hack_assembler | /lib/driver.rb | UTF-8 | 2,845 | 2.625 | 3 | [] | no_license | # usage
# load 'assembler.rb'
# assembler = Assembler::Driver.new('add/Add.asm')
# assembler.run
require 'forwardable'
require_relative 'parser/strategy.rb'
require_relative 'utils/fileio.rb'
require_relative 'linker/linker.rb'
require_relative 'assembler/code.rb'
require_relative 'assembler/visitors.rb'
require_rel... | true |
a109c68e165b20581dd099fb3d579771dc00b520 | Ruby | nickhoffman/eat-the-alphabet | /spec/models/animal_spec.rb | UTF-8 | 2,770 | 2.609375 | 3 | [] | no_license | require 'spec_helper'
describe Animal do
it 'includes Mongoid::Document' do
Animal.should include Mongoid::Document
end
it 'includes Mongoid::Timestamps' do
Animal.should include Mongoid::Timestamps
end
it 'stores valid "type" values in @@valid_types' do
Animal.class_variable_get(:@@valid_types... | true |
9c5dd0acc36b014e6f3c54cf0b0a303eb80581f9 | Ruby | snsavage/oo-tic-tac-toe-q-000 | /lib/tic_tac_toe.rb | UTF-8 | 1,797 | 4.125 | 4 | [] | no_license | class TicTacToe
WIN_COMBINATIONS = [
[0, 1, 2],
[3, 4, 5],
[6, 7, 8],
[0, 3, 6],
[1, 4, 7],
[2, 5, 8],
[0, 4, 8],
[6, 4, 2]]
def initialize
@board = Array.new(9, " ")
end
def display_board
puts " #{@board[0]} | #{@board[1]} | #{@board[2]} "
puts "-----------"
... | true |
b2be6b53bca2570e68811f2add7e923abc5c8bc9 | Ruby | aadilzbhatti/The-Odin-Project | /RubyProjects/SimpleServer/simple_browser.rb | UTF-8 | 773 | 2.921875 | 3 | [] | no_license | require 'socket'
require 'json'
host = 'localhost'
port = 2000
puts 'What type of request would you like to send? [GET, POST]'
input = gets.chomp.upcase
if input == 'POST'
path = "/thanks.html"
puts 'What is the name of your viking?'
name = gets.chomp
puts 'What is the email of your viking?'
email = gets.chomp
... | true |
f10591c65410529c1d66730dea4037bda1b680c4 | Ruby | mainmatter/excellent | /spec/unit/checks/cyclomatic_complexity_method_check_spec.rb | UTF-8 | 4,605 | 2.703125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe Simplabs::Excellent::Checks::CyclomaticComplexityMethodCheck do
before do
@excellent = Simplabs::Excellent::Runner.new([:CyclomaticComplexityMethodCheck => { :threshold => 0 }])
end
describe '#evaluate' do
it 'should find an if block' do
code = <<-END
def m... | true |
7d3d35139909be3308cbdc67333f7af218e7403a | Ruby | katou02/baseball-app | /spec/models/tweet_spec.rb | UTF-8 | 6,209 | 2.546875 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Tweet, type: :model do
let(:tweet){build(:tweet)}
describe 'バリデーションのテスト' do
subject { tweet.valid? }
it '全て入力していれば保存できる' do
expect(tweet).to be_valid
end
context 'titleカラム' do
it '未入力だと保存できない' do
tweet.title = ''
is_expected.to e... | true |
141d1c69fd68b0bb95f089d734a66012a217a89f | Ruby | kevinday/project-euler | /19.rb | UTF-8 | 186 | 3.453125 | 3 | [] | no_license | require 'date'
date = Date.new(1901,1,1)
end_date = Date.new(2000, 12, 1)
sundays = 0
while date < end_date do
sundays += 1 if date.sunday?
date = date.next_month
end
puts sundays | true |
81b63b31bfcb05b3d3e8975e67a5a6b9a606198f | Ruby | vienbk91/Ruby | /Advance/procs_lambda.rb | UTF-8 | 2,243 | 4.1875 | 4 | [] | no_license | # Proc và Lambda trong Ruby
#######################################################
## Block
#######################################################
m = [1,2,3,4,5]
n = [10,20,30,40,50]
# Xây dựng 1 hàm có sử dụng block
def double_block(x)
if block_given?
yield x*2
else
puts "Khong co block"
end
end
puts "M... | true |
3c63765523603d6a5302d011988c41c044cde254 | Ruby | Dob212/CADProject | /lib/order_decorator.rb | UTF-8 | 1,050 | 3.046875 | 3 | [] | no_license | class BasicOrder
def initialize(name, description, time, cost)
@oname = name
@odescription = description
@otime = time
@ocost = cost
end
def ocost
return @ocost
end
def details
return @odescription
end
end
class OrderDecorator
def initialize(base_order)
@base_order = b... | true |
be8b347b955ecfc7180346b41b9691f4cfa4745f | Ruby | RStankov/SearchObject | /lib/search_object/helper.rb | UTF-8 | 1,970 | 2.671875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
module SearchObject
# :api: private
module Helper
module_function
def stringify_keys(hash)
# Note(rstankov): From Rails 5+ ActionController::Parameters aren't Hash
# In a lot of cases `stringify_keys` is used on action params
hash = hash.to_unsafe_h if has... | true |
751c4d1f9690c30df2dde0097ff20f3d01d3f07f | Ruby | MarkLauer/languages | /sysadmins.rb | UTF-8 | 690 | 2.65625 | 3 | [] | no_license | if File.exist?("access.log")
input = File.new("access.log", "r")
regexp_ip = /(?:25[0-5]|2[0-4]\d|[0-1]?\d{1,2})(?:\.(?:25[0-5]|2[0-4]\d|[0-1]?\d{1,2})){3}\b/
regexp_sub = /[1-2]?[0-9]?[0-9]\.[1-2]?[0-9]?[0-9]\.[1-2]?[0-9]?[0-9]\./
ip_array = input.read.scan(regexp_ip)
input.close
ip_hash = Hash.new(0)
for ip in... | true |
168ebca2f4325aa5761b9c88879675e8e29f877a | Ruby | tdooner/advent-code | /2016/15/process.rb | UTF-8 | 498 | 3.125 | 3 | [] | no_license | def process_line(line, index)
num_positions = line.scan(/(\d+) positions/).first.first.to_i
initial_position = line.scan(/position (\d+)/).first.first.to_i
# puts "0 == (#{initial_position} + #{index} + tick) % #{num_positions}"
->(tick) { 0 == (initial_position + tick + index) % num_positions }
end
rules = [... | true |
de32f919fae61895e9ff75377ddc3665ff92c050 | Ruby | zpeller/aoc-2016 | /13_maze_of_cubicles.rb | UTF-8 | 1,956 | 3.484375 | 3 | [] | no_license | #!/usr/bin/ruby
require 'set'
input = 1358
$dest_coords = [31, 39]
#input = 10
#$dest_coords = [7, 4]
$start_pos = [1, 1]
$map_width, $map_height = 55, 55
def is_wall(x, y, favnum)
num_d = x*x + 3*x + 2*x*y + y + y*y + favnum
num_b = "%b" % num_d
one_bits = num_b.chars.select{ |x| x=='1' }.length
return ((one_... | true |
0fd2a130c93fbef24b50186947fbd39678ba3107 | Ruby | SciRuby/iruby | /lib/iruby/event_manager.rb | UTF-8 | 989 | 3 | 3 | [
"MIT"
] | permissive | module IRuby
class EventManager
def initialize(available_events)
@available_events = available_events.dup.freeze
@callbacks = available_events.map {|n| [n, []] }.to_h
end
attr_reader :available_events
def register(event, &block)
check_available_event(event)
@callbacks[event] ... | true |
529d41e10e9eb8db275c0e5c2da40ec447fff204 | Ruby | samesystem/social_security_number | /lib/social_security_number/validator.rb | UTF-8 | 1,454 | 2.90625 | 3 | [
"MIT"
] | permissive | module SocialSecurityNumber
# SocialSecurityNumber::Validator
class Validator
SUPPORTED_COUNTRY_CODES = %w[BE CA CH CN CZ DE DK EE ES FI FR GB IE
IS IT LT LV MX NL NO PK SE US].freeze
attr_accessor :civil_number, :country_code, :error
def initialize(params = {})
... | true |
a5b73de6c3bc1968fe8645aa759ca2653b8b8c4a | Ruby | dallinder/programming_basics | /lesson_5/practice10.rb | UTF-8 | 153 | 3.171875 | 3 | [] | no_license | hsh = [{a: 1}, {b: 2, c: 3}, {d: 4, e: 5, f: 6}]
hsh.map do |x|
new_hsh = {}
x.map do |key, value|
new_hsh[key] = value + 1
end
new_hsh
end | true |
aab42dd191750003f1a24807b0f557e88265d1a4 | Ruby | ably-forks/cloudyscripts | /lib/audit/lib/benchmark/rule_severity.rb | UTF-8 | 255 | 3.328125 | 3 | [
"MIT"
] | permissive | class RuleSeverity
UNKNOWN = "unknown"
INFO = "info"
LOW = "low"
MEDIUM = "medium"
HIGH = "high"
SEVERITIES = [UNKNOWN, INFO, LOW, MEDIUM, HIGH]
def self.parse(str)
return ((SEVERITIES.include? str.downcase) ? str.downcase : UNKNOWN)
end
end | true |
899d1c51cbe1703c67ee416c053c5cf27410ba96 | Ruby | toolsforteachers/Assess-Student-Needs | /features/step_definitions/group_steps.rb | UTF-8 | 1,720 | 2.640625 | 3 | [] | no_license | Given(/^I add a group named "(.*?)" with a student named "(.*?)"$/) do |group_name, student_name|
visit new_group_path
fill_in 'Class name', with: group_name
click_link 'Add a student'
fill_in 'Student', with: 'Ann'
click_button "Save"
end
When(/^I navigate to the "(.*?)" group page$/) do |group_name|
clic... | true |
fbd1d60599a706aa680d1c6821bfaeb62d274d8b | Ruby | Joelle5/goongit | /duck.rb | UTF-8 | 102 | 2.84375 | 3 | [] | no_license | def duck_duck_goose (players, goose)
rounds = goose % players.length
players(rounds - 1).name
end
| true |
537f7d77313fa7f5a84964227d6d4f44b7ddb530 | Ruby | bitprophet/redmine2github | /github.rb | UTF-8 | 1,957 | 2.53125 | 3 | [] | no_license | require 'rubygems'
require 'json'
POST_OK = true
REPO_PATH = ENV['REPO'] || "fabric/issuetest2"
#ENV['RESTCLIENT_LOG'] = 'stdout'
require 'rest_client'
class GithubAPI
def initialize(section="")
@api = RestClient::Resource.new(
"https://api.github.com/#{section}",
ENV['GITHUB_USERNAME'],
ENV... | true |
b57bc80e73b1e75547a3359a5812aa22d6dbc75f | Ruby | mikethorpe/ruby_codeclan_course | /cchw_wk2_day1/library.rb | UTF-8 | 1,135 | 3.421875 | 3 | [] | no_license | class Library
def initialize()
@books = [
{
title: "lord_of_the_rings",
rental_details: {
student_name: "Jeff",
date: "01/12/16"
}
},
{
title: "lord_of_the_flies",
rental_details: {
student_name: "Barry",
date: "01/... | true |
1a2a5d8bbc06a90c08c810910d96e8101ec25782 | Ruby | orangethunder/axlsx | /examples/data_validation.rb | UTF-8 | 1,397 | 2.65625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby -w -s
# -*- coding: utf-8 -*-
$LOAD_PATH.unshift "#{File.dirname(__FILE__)}/../lib"
require 'axlsx'
p = Axlsx::Package.new
p.workbook.add_worksheet do |ws|
ws.add_data_validation("A10", {
:type => :whole,
:operator => :between,
:formula1 => '5',
:formula2 => '10',
:showE... | true |
94bc3ab91b58ba924343c530f340ed92fb7cd567 | Ruby | thebravoman/software_engineering_2013 | /class8_homework/Petur_Pelovski_1.rb | UTF-8 | 826 | 2.8125 | 3 | [] | no_license | require "csv"
i = 0
a = ""
umri = 'test'
string = ""
names = []
broqch = 0
broqch2 = 0
File.open("sub_expected.txt", "r") do |file|
while line = file.gets
string = string + line
end
file.close
end
Dir["/home/petur/software_engineering_2013/class7_homework/*.rb"].each {|file|
a = file.scan(/test/)
a = a.to_s
if ... | true |
9c119b41f27cdc573caf2d6cfdd2bd0300eaa8d9 | Ruby | giddynaj/dedup | /dedup.rb | UTF-8 | 7,707 | 3.671875 | 4 | [] | no_license | require 'csv'
require 'text'
require 'json'
require 'sinatra'
require 'sinatra/json'
#
# Utility Methods
# clean - Clean a row from file
# gen_key - generate a key based on columns you want to combine
# add_to - generate a key and use it to insert a hash into the master hash
# load_file - open csv file, parse, and bu... | true |
7e3b303f5f59f19a5489288adf269b850c720a38 | Ruby | benders/blarg | /vendor/gems/data_objects-0.9.12/lib/data_objects/uri.rb | UTF-8 | 2,010 | 2.828125 | 3 | [
"MIT"
] | permissive | gem 'addressable', '~>2.0'
require 'addressable/uri'
module DataObjects
# A DataObjects URI is of the form scheme://user:password@host:port/path#fragment
#
# The elements are all optional except scheme and path:
# scheme:: The name of a DBMS for which you have a do_\<scheme\> adapter gem installed. If s... | true |
3b07b63e0224c03ba3768687b6c9a50b31a1e901 | Ruby | susan-wz/math-game | /questions.rb | UTF-8 | 560 | 3.9375 | 4 | [] | no_license | class Question
attr_reader :numbers, :ask_question
attr_accessor :player
def initialize(current_player)
@current_player = current_player
@number_1 = rand(21)
@number_2 = rand(21)
end
def ask_question
puts "#{@current_player.name}: What does #{@number_1} plus #{@number_2} equal?"
end
def... | true |
550d5352b139b6c63012229e28ac625ebd8649fc | Ruby | mmcgirr19/RB101_pgrm_fnds | /lesson_3/pp_easy2/q2.rb | UTF-8 | 224 | 3.15625 | 3 | [] | no_license | munsters_description = "The Munsters are creepy in a good way."
p munsters_description.upcase!.sub(/T/, 't').sub(/M/, 'm')
p munsters_description.capitalize
p munsters_description.downcase!
p munsters_description.upcase! | true |
16a458d1e59d47bc6795c428a1fa613e347b76d7 | Ruby | izumariu/hsanhalt-tools | /tools/ims2sched/RUN.rb | UTF-8 | 1,180 | 2.71875 | 3 | [] | no_license | #!/usr/bin/env ruby
require "time"
require "yaml"
require "#{File.dirname(__FILE__)}/libuniics.rb"
HOUR = 60*60
CLASSES = %w(FSL1 FSL3 FSL5 FSL7 IMS1Ü1 IMS1Ü2 IMS3Ü1 IMS3Ü2 IMS5 IMS7 MIM2 MS L2 MIAM2)
PROFS = YAML.load open("#{File.dirname(__FILE__)}/lecturers.yaml", &:read)
SUMMARY_REGEX = Regexp.new("(#{CLASSES.joi... | true |
0186a49773f50fa6b90609ea0f1cdb4dbc298094 | Ruby | edwardloveall/portfolio | /lib/tasks/tumblr.rake | UTF-8 | 1,765 | 2.6875 | 3 | [] | no_license | namespace :tumblr do
desc 'Import all posts from tumblr into database (indempotent)'
task import_posts: 'db:migrate' do
api_key = ENV.fetch('TUMBLR_API_KEY')
fetcher = TumblrFetcher.new(api_key: api_key)
post_data = fetcher.posts
creator = PostCreator.new(json: post_data)
creator.perform
end
... | true |
e932ce7a8794bdd5eb49dad65452abd0a19a1e09 | Ruby | gbellini90/activerecord-validations-lab-nyc-web-102918 | /app/models/post.rb | UTF-8 | 739 | 3.03125 | 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)}
validates :title, format: {with: /Won't Believe|Secret|Top \d|Guess/}
end
# If the title d... | true |
a1672b80fa201815567f49751970792a16bf01a9 | Ruby | mhar-andal/phase-0-tracks | /ruby/secret_agents.rb | UTF-8 | 1,918 | 4.3125 | 4 | [] | no_license | =begin
ENCRYPT METHOD
- advance each letter one letter forward
- run .next on each index
- use ! to change index in place
- spaces remain as spaces
DECRYPT METHOD
- reverse encrypt
- go backward one letter
-
=end
def encrypt(password)
index = 0
while index < password.length
if password[index] ==... | true |
433f621bca42074d2a9415c19cf8886e07cfb4cf | Ruby | CynthiaBin/Programacion-Paralela | /practica_7/models/user.rb | UTF-8 | 337 | 2.609375 | 3 | [] | no_license | # Model user
class User < AbstractBase
attr_reader :id
def initialize(name = nil, user_name = nil, email = nil)
@name = name
@user_name = user_name
@email = email
super(:users)
end
def register
data_set = DB[@table_name]
@id = data_set.insert(name: @name, userName: @user_name, email: @... | true |
61854777c807d3a331fcfca7981a3fc5ac514270 | Ruby | rn0rno/kyopro | /aoj/ruby/02_Volume0/0001.rb | UTF-8 | 173 | 3.5 | 4 | [] | no_license | #!/usr/bin/env ruby
# Input
mountains = []
while line = gets
mountains << line.chomp!.to_i # delete \n
end
# Sort & Output
mountains.sort!
3.times{ puts mountains.pop }
| true |
d208ba1be4086180ca2378a47f23d879115426d1 | Ruby | VDmitryO/pushkin-contest-bot | /app/services/tasks_service.rb | UTF-8 | 2,392 | 3.390625 | 3 | [] | no_license | class TasksService
attr_accessor :question, :level
def initialize(question, level)
@question = question
@level = level
end
def get_answer
case level
when '1'
POEMS_1[question]
when '2', '3', '4'
level_234(POEMS_234)
when '5'
level_5(question.include?(',') ... | true |
81b16f1755516abdd5f63e83b2d82d0d9f97ddf4 | Ruby | MrJons/boris_bikes | /lib/van.rb | UTF-8 | 332 | 2.515625 | 3 | [] | no_license | require_relative "docking_station"
require_relative "garage"
class Van
def initialize
@broken_bikes = []
@good_bikes = []
end
def collect(bikes)
until bikes.empty?
@broken_bikes << bikes.pop
end
@broken_bikes
end
def collect_fixed(bikes)
until bikes.empty?
@good_bikes << bikes.pop
end
@good_bikes... | true |
756257d3ef6bb8b26a5783334f4c4331a8a684a1 | Ruby | Warrenoo/qy_wechat_proxy | /wechat.rb | UTF-8 | 530 | 2.5625 | 3 | [] | no_license | require "qy_wechat_api"
require "forwardable"
QyWechatApi.configure do |config|
config.logger = Logger.new(STDOUT)
end
class Wechat
attr_accessor :wc, :appid #wechat_client
extend Forwardable
def_delegators :wc, :is_valid?
def initialize(corpid, corpsecret, appid)
@wc = QyWechatApi::Client.new(corpi... | true |
c56ba75eca36a3fb35fd386fd5553d438d068af7 | Ruby | Tcom242242/t_learn | /lib/t_learn/k_means.rb | UTF-8 | 2,620 | 2.875 | 3 | [
"MIT"
] | permissive | #!/usr/bin/ruby
# -*- encoding: utf-8 -*-
module TLearn
class K_Means
attr_accessor :data_list, :k, :c_list
def init(data_list, k=2)
@data_list = data_list
sliced_data_list = @data_list.each_slice(k).to_a
@dim = data_list[0].size
@k = k
@cluster_list = @k.times.map {|n| Clust... | true |
b7f09e3ec4f0d291bed8ffe8cab7a93fb8ddd863 | Ruby | paulba71/DesignPatternsTermPaperCode | /Object Pool/Without Pattern/main.rb | UTF-8 | 3,186 | 3.234375 | 3 | [] | no_license | require 'ruby-prof'
require_relative 'proofer'
@english_text=['hello', 'the', 'purpose', 'of', 'this', 'sample', 'is', 'to', 'test', 'some', 'spelling', 'mistakes', 'using', 'the', 'object pool', 'design', 'pattern', 'au reviour']
@french_text=['bonjour', 'le', 'but', 'de', 'cet', 'exemple', 'est', 'de', 'tester', 'q... | true |
3d0cca1836d9f97c353db8a2d23248b1969c33f1 | Ruby | jamesboyd2008/phase-0 | /week-6/gps2_3.rb | UTF-8 | 2,148 | 4.125 | 4 | [
"MIT"
] | permissive | # Your Names
# 1) Peter Stratoudakis
# 2) James Boyd
# We spent [1.5] hours on this challenge.
# Bakery Serving Size portion calculator.
def serving_size_calc(item_to_make, num_of_ingredients)
cook_book = {"cookie" => 1, "cake" => 5, "pie" => 7}
if !cook_book.include?(item_to_make)
raise ArgumentError.new("... | true |
51cd44d133993e5cd52d89ff681a8e98e96401f9 | Ruby | rhosyn/tldr | /lib/services/smmry.rb | UTF-8 | 712 | 2.609375 | 3 | [] | no_license | require 'open-uri'
require 'json'
class Smmry
def summarize
articles = AylienArticle.where(summary_sentences: nil)
articles.each do |a|
news_url = a.article_url
url = "http://api.smmry.com/&SM_API_KEY=#{ENV['Smmry_API_Key']}&SM_WITH_BREAK&SM_WITH_ENCODE&SM_QUOTE_AVOID&SM_QUESTION_AVOID&SM_EXC... | true |
79c1392cc866a9c8396835ad322a53e259ed5481 | Ruby | Bschlin/ruby-javascript-converter | /practice.rb | UTF-8 | 2,414 | 4.65625 | 5 | [] | no_license | # Write a method that prints out every number from 1 to 100.
def one_to_hunnit
numba = 1
100.times do
p numba
numba += 1
end
end
one_to_hunnit
# Write a method that prints out every other number from 1 to 100. (That is, 1, 3, 5, 7 ... 99).
def every_other_number
number = 0
while... | true |
f714c0c2a874b834d01e007eea56ed865811d451 | Ruby | lchandra1/nandomoreira-jekyll-theme | /source/_posts/clase.rb | UTF-8 | 1,115 | 3.34375 | 3 | [
"MIT"
] | permissive | class lchandra
def initialize(name, gender, age, location, email, password)
@name = name
@gender = gender
@age = age
@location = location
@email = email
@password = password
end
def name=(name)
@name = name
end
def name
return @name
end
def gender=(gender)
@gender = gender... | true |
68dabd6a0c2c1b86f11fe5e8a7998bbd9ba46ca9 | Ruby | niiccolas/aao | /03_ruby/02_enumerables_and_debugging/projects/02_ghost/spec/game_spec.rb | UTF-8 | 1,474 | 3.09375 | 3 | [] | no_license | require 'game'
describe "Game class" do
players = [Player.new('Slimer'), Player.new('Casper')]
ghost_game = Game.new(players)
describe "#initialize" do
it "should set @dictionary to a hash with keys being words of the dictionary" do
expect(ghost_game.dictionary.keys).to_not include(nil)
end
it... | true |
8de9546f7fd4266671c0e30f7a48ffbf705a57b5 | Ruby | samanthi22/app-academy-ruby | /Enumerables/lib/enumerables.rb | UTF-8 | 4,650 | 4.03125 | 4 | [] | no_license | class Array
def my_each(&prc)
i = 0
while i < length
yield self[i]
i += 1
end
return self
end
end
return_value = [1,2,3].my_each do |num|
puts num
end #=> 1,2,3
p return_value
class Array
def my_select(&prc)
result = []
each do |ele|
result << ele ... | true |
b3e129d00088ff375ac73509636c2a19e787ceef | Ruby | AliannyPerez1/array-CRUD-lab-ruby-apply-000 | /lib/array_crud.rb | UTF-8 | 1,148 | 4 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def create_an_empty_array
[]
end
def create_an_array
[1,2,3,4]
end
def add_element_to_end_of_array(array, element)
array = ["wow", "I", "am", "really", "learning"]
element = "arrays!"
array.push("arrays!")
end
def add_element_to_start_of_array(array, element)
array = ["I", "am", "really", "lear... | true |
84089f2fbb8db85eabf69483eaac33c8ea175402 | Ruby | molingyu/dnd | /lib/dnd_log/dnd_log_creator.rb | UTF-8 | 435 | 2.796875 | 3 | [] | no_license | require 'qmessage'
class DND::DndLogCreator
attr_reader :info
attr_reader :logs
def initialize(log, players)
@qm = QMsg.run(log)
@players = players
@info = OpenStruct.new
@logs = []
create
end
def create
@qm.each do |qm|
player_infos(qm)
end
end
def player_infos(qm)
... | true |
5fe4ed3493bf349ca6bb668cc4ae81a16dc9522f | Ruby | seryl/backdat | /lib/backdat/storage/local.rb | UTF-8 | 2,656 | 3 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'set'
require 'fileutils'
# The backdat Local storage object.
class Backdat::Storage::Local < Backdat::Storage::Base
attr_reader :excluded
# Creates a new Local storage object.
#
# @param [ Hash ] params The parameters to initialize the Local object with.
#
# @option params [ String ] :path The ... | true |
223dc3684d5338be50eb8a24262af1c10eda06c1 | Ruby | kenchan/competitive_programming | /atcoder/abc276/E.rb | UTF-8 | 150 | 2.90625 | 3 | [] | no_license | # https://atcoder.jp/contests/abc276/tasks/abc276_e
H, W = gets.split.map(&:to_i)
Css = Array.new(H) { gets.chomp.split }
puts cond ? 'Yes' : 'No'
| true |
f9d6f8089f92a42973ca6376d362be1ec23dd986 | Ruby | ShashKing/Training | /Ruby Training/ArrayTest25.rb | UTF-8 | 102 | 2.734375 | 3 | [] | no_license | arr=[22,55,65,78,12,55,50]
num=arr.sort
num.each { |e| puts e }
puts mutate(arr)
puts not_mutate(arr) | true |
944a6c995508465a9f51937ee6c1864dc8657d03 | Ruby | marswong/prime-ruby-cb-gh-000 | /prime.rb | UTF-8 | 274 | 3.4375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def prime?(n)
if n <= 1
false
elsif n <= 3
true
elsif n % 2 == 0 || n % 3 == 0
false
else
i = 5
result = true
while i ** 2 < n
if n % i == 0 || n % (i + 2) == 0
result = false
end
i += 6
end
result
end
end
| true |
4ced150ba82c8714b93aed07fa421a02a20b89af | Ruby | vijayakumarsuraj/automation | /automation/core/task.rb | UTF-8 | 2,631 | 2.546875 | 3 | [] | no_license | #
# Suraj Vijayakumar
# 04 Dec 2012
#
require 'automation/core/component'
require 'automation/enums/result'
require 'automation/enums/status'
require 'automation/support/runnable'
module Automation
# A task represents the most basic unit of work the framework can carry out.
class Task < Component
# Makes ... | true |
f524ddc1c8265c59f8c30f3271beaf190e708611 | Ruby | eichelbw/Conway | /gol_array.rb | UTF-8 | 5,067 | 3.640625 | 4 | [] | no_license | require 'rspec'
require "pry"
class World < Array
def initialize(x_dim, y_dim, seed_probabily, steps)
@x_dim, @y_dim, @steps = x_dim, y_dim, steps
@cells = Array.new(@y_dim) {
Array.new(@x_dim) {
Cell.new(seed_probabily)
}
}
end
def cells
@cells
end
def alive_nei... | true |
466db6038ab5e2fc6050036303cf9d4aafb8b565 | Ruby | zbadiru/ruby-oo-relationships-practice-blood-oath-exercise-lon01-seng-ft-042020 | /app/models/follower.rb | UTF-8 | 649 | 3.109375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Follower
attr_reader :name
attr_accessor :age, :life_motto
@@all = []
def initialize(name, age, life_motto)
@name = name
@ago = age
@life_motto = "life motto"
@@all << self
end
def bloodoaths_f
Bloodoath.all.select {|b| b.follower == sel... | true |
c015aff4665fe5987743e5826517edd2c54e64ea | Ruby | rails-girls-summer-of-code/rgsoc-teams | /spec/lib/selection/distance_spec.rb | UTF-8 | 1,062 | 2.953125 | 3 | [
"MIT"
] | permissive | require 'rails_helper'
require 'selection/distance'
RSpec.describe Selection::Distance do
let(:from) { ['30.1279442', '31.3300184'] }
let(:to) { ['30.0444196', '31.2357116000001'] }
# Validate via geocoder gem or web service
# see here: http://boulter.com/gps/distance/?from=30.1279442+31.3300184&to=30.04441... | true |
2e9c3cabd965b7d8a38dfe384018f7f9c2e9a529 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/triangle/b2441e1073c64cd2957529fa2525c54e.rb | UTF-8 | 767 | 3.46875 | 3 | [] | no_license | class TriangleError < Exception
end
class Triangle
def initialize(*sides)
@sides = sides
end
def kind
validate
return :equilateral if equilateral?
return :isosceles if isosceles?
return :scalene if scalene?
end
def validate
raise TriangleError if negative_or_zero_sides? || tria... | true |
0bfbb7a7d35147949bc94b3a4a5fb256c0c73294 | Ruby | BookBub/ruby-freshbooks | /spec/freshbooks_spec.rb | UTF-8 | 2,554 | 2.828125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'lib/ruby-freshbooks'
def build_xml(data)
FreshBooks::Client.build_xml data, Builder::XmlMarkup.new(:indent => 2)
end
describe "XML generation:" do
describe "simple hash" do
it "should serialize correctly" do
data = {"foo" => "bar"}
build_xml(data).should == "<foo>bar</foo>\n"
end
en... | true |
c9b4abfcdec3f5f728e8a5acd40cc357c574d79e | Ruby | BaptisteIg/Ruby_start | /exo_07_c.rb | UTF-8 | 405 | 3.25 | 3 | [] | no_license | user_name = gets.chomp
puts user_name
# gets.chomp permet la saisie pour l'utilisateur de la valeur à enregistrer dans la variable user_name.
# La différence entre les 3 codes est l'interface utilisateur, le code b est le plus agréable à utiliser pour une interface homme-machine agréable.
# L'autre différence est qu... | true |
b16456073579c564b696caf8f21cebc2ee0de28c | Ruby | coolhead/chef-git | /hello.rb | UTF-8 | 601 | 3.296875 | 3 | [] | no_license | puts "Hello World\n"
bacon_type = 'crispy'
2.times do
puts bacon_type
temperature = 300
end
x = "hello"
puts "#{x} world"
puts '#{x} world'
<<METHOD_DESCRIPTION
I Raghavendra learning Ruby for Chef.
Currently I have the liability of home loan and personal loans, which I need to clear ASAP.
METHOD_DESCRIPTION
type... | true |
6f570e09981c1afe2bcffb604e9ec4ddb0b0ee6c | Ruby | SplitTime/OpenSplitTime | /spec/support/concerns/locatable.rb | UTF-8 | 2,618 | 2.625 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | # frozen_string_literal: true
RSpec.shared_examples_for "locatable" do
describe "#distance_from" do
subject { described_class.new(latitude: 40, longitude: -105) }
context "when subject and other have latitude and longitude" do
let(:other) { described_class.new(latitude: 40.1, longitude: -105.1) }
... | true |
0616dec571ccc4cb4b62988f2b927b63521c8155 | Ruby | brenoperucchi/tdlib-ruby | /lib/tdlib/types/chat.rb | UTF-8 | 3,186 | 2.5625 | 3 | [
"MIT"
] | permissive | module TD::Types
# A chat.
# (Can be a private chat, basic group, supergroup, or secret chat).
#
# @attr id [Integer] Chat unique identifier.
# @attr type [TD::Types::ChatType] Type of the chat.
# @attr title [String] Chat title.
# @attr photo [TD::Types::ChatPhoto, nil] Chat photo; may be null.
# @attr... | true |
60bf4bdeef7b1681225cccd079ac3209fc22793b | Ruby | LouisaBarrett/String-Calculator | /string_calculator.rb | UTF-8 | 324 | 3.375 | 3 | [] | no_license | class StringCalculator
def self.add(input)
if input.include?("-")
negs = input.scan(/-\d+/)
raise "negatives not allowed, negatives passed: #{negs.join(', ')}"
else
numbers = input.split(/\n|,|\D/)
numbers.inject(0) do |sum, number|
sum + number.to_i
end
end
end
... | true |
e875d74f5d4dfa50c5cc618faf87c214ee713eab | Ruby | pelf/euler | /p19.rb | UTF-8 | 1,014 | 3.828125 | 4 | [] | no_license | # avoided using ruby's builtin date functions
@@ldom = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
@@dom = 1
@@year = 1900
@@dow = 0
@@month = 0
@@count = 0
def next_day
# day of week
@@dow = (@@dow+1)%7
# day of month
@@dom += 1
@@dom = 1 if end_of_month?
# month
@@month = (@@month+1)%12 if @@dom == 1
... | true |
3d54f71a3311ddb86271e7369bf0fafcdff6e80f | Ruby | paulghaddad/think_like_a_programmer_problems | /thinking_like_a_programmer/cheating_at_hangman_version_2/lib/cheater.rb | UTF-8 | 2,013 | 3.84375 | 4 | [] | no_license | class Cheater
attr_reader :word_set, :winning_word
def initialize(word_set:, winning_word:)
@word_set = word_set
@winning_word = winning_word
end
def match?(letter)
most_frequent_letter_count = patterns_by_count(letter).values.max
words_without_letter_count = words_without_letter(letter).size
... | true |
b1a7d19e811e4630dfa84dbdb196011ca7745af7 | Ruby | Chekushkin/threeofnine | /lib/script.rb | UTF-8 | 7,175 | 2.640625 | 3 | [] | no_license | require 'pry'
require 'mail'
require 'redis'
require 'base64'
require 'nokogiri'
require 'open-uri'
require 'digest/md5'
require 'unicode_utils'
require 'active_support'
require 'active_support/core_ext'
ARR_MOTH = [
'января Январь',
'февраля Февраль',
'марта Март',
'апреля Апрель',
'мая Май',
'июня Июнь',... | true |
935d993b0171c3f2cfe496a2607cc3abcb8db0b0 | Ruby | NikitaYaskin/RubyScreencasts | /7/conditions.rb | UTF-8 | 289 | 3.546875 | 4 | [] | no_license | i = 1
if i >= 1
puts "number is greater than or equals 1"
elsif i <= 1
puts "number is less than or equals 1"
else
puts "number equals 1"
end
puts "-" * 15
if i >= 1
puts "number is greater than or equals 1"
end
if i <= 1
puts "number is less than or equals 1"
end
| true |
c44b6a17662cc9318829439ad1bc341182862c03 | Ruby | yifeiwu/json_searcher | /lib/tokenizer.rb | UTF-8 | 526 | 3.15625 | 3 | [
"MIT"
] | permissive | # takes an array of json and creates a dictionary set for each term consisting of the values from each entry
module Tokenizer
# creates a inverted index using the unparsed string value
def self.simple_parse(entries)
dictionary_set = {}
entries.each_with_index do |entry, entry_index|
entry.each do |fi... | true |
0fd1fa46aa89640e0cad1a843d54e84a7fb17e27 | Ruby | mjester93/ruby-oo-practice-relationships-domains-wdc01-seng-ft-060120 | /app/models/actors.rb | UTF-8 | 559 | 3.5 | 4 | [] | no_license | class Actor
attr_accessor :name
@@all = []
def initialize(name)
@name = name
self.class.all << self
end
def self.all
return @@all
end
def self.most_characters
max_appearances = -1
max_name = nil
self.all.each do |actor|
curr_... | true |
0b62ade3732392a59b5aa3d6b8514adf5970c02e | Ruby | yonjinkoh/assignment5 | /testmatrix.rb | UTF-8 | 535 | 3.25 | 3 | [] | no_license | #this is to test symmetry.
require 'Matrix'
our_matrix = Matrix[[0, 1, 1, 1, 0, 0], [1, 0, 1, 1, 0, 0], [1, 1, 0, 0, 1, 0], [0, 1, 0, 0, 1, 1], [0, 0, 1, 1, 0, 0], [0, 0, 0, 1, 0, 0]]
m_array = our_matrix.to_a
our_matrix.each_with_index do |e, row, col|
# puts "#{e} at #{row}, #{col}"
# puts our_matrix[col, row... | true |
64d9199b1fd289035022264624087498c068f9f3 | Ruby | osdakira/bitwise_enum | /lib/bitwise_enum.rb | UTF-8 | 4,659 | 3.171875 | 3 | [
"MIT"
] | permissive | require 'active_record/base'
require "bitwise_enum/version"
# Clone from `ActiveRecord::Enum`.
#
# Declare an bitwise enum attribute where the values map to integers in the database, but can be queried by name. Example:
#
# class User < ActiveRecord::Base
# bitwise_enum role: [ :admin, :worker ]
# end
#
# # ... | true |
1cfec2373bc4f7b7d94e71d12ac05af9760924a9 | Ruby | Bigproblems55/sms_carrier | /lib/sms_carrier/test_case.rb | UTF-8 | 2,425 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'active_support/test_case'
module SmsCarrier
class NonInferrableCarrierError < ::StandardError
def initialize(name)
super "Unable to determine the carrier to test from #{name}. " +
"You'll need to specify it using tests YourCarrier in your " +
"test case definition"
end
... | true |
5ea8e9e8c6cc0c84d24e6fc7e42178b727d065d0 | Ruby | sitrox/inquery | /lib/inquery/query.rb | UTF-8 | 1,392 | 2.515625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module Inquery
class Query
include Mixins::SchemaValidation
include Mixins::RawSqlUtils
attr_reader :params
# Instantiates the query class using the given arguments
# and runs `call` and `process` on it.
def self.run(*args)
new(*args).run
end
# Instantiates the query class usi... | true |
c6ee8f9eb67a1ee5426fba8bd4c1f05af111e612 | Ruby | Sahana27/Ruby-Learning | /Ruby_assignment/page_two.rb | UTF-8 | 2,601 | 2.90625 | 3 | [] | no_license | #!/usr/bin/ruby
$LOAD_PATH.unshift("/usr/local/rvm/gems/ruby-1.9.3-p547/gems/ruby-mysql-2.9.12/lib")
require 'mysql'
require 'cgi'
cgi = CGI.new
puts cgi.header
#create connection to Mysql
def create_connection()
con = Mysql.new 'localhost', 'cloudera','', 'chartsearch' #opening a connection with Mysql
return con... | true |
7bb539b67478ad8e1478b84b03a37810dbe92fe1 | Ruby | christiebelle/Snowman-of-doom | /game.rb | UTF-8 | 616 | 3.5625 | 4 | [] | no_license | class Game
def initialize(players, word)
@playas = players
@word = word
@guessed_letters = []
end
def player_details
return "#{@name} has #{@lives} lives"
end
end
# MVP
#
# A Game will have properties for a Player object,
# a HiddenWord object, and an array of guessed_letters
# A Player wi... | true |
af5f89bf6d2c6cbdcad0617002d980c58bcebde4 | Ruby | T-monius/ruby_small_problems | /easy_9/name_swapping.rb | UTF-8 | 369 | 4.125 | 4 | [] | no_license | # name_swapping.rb
# Write a method that takes a first name, a space, and a last name passed
# as a single String argument, and returns a string that contains the last
# name, a comma, a space, and the first name.
def swap_name(str)
arr = str.split
"#{arr[1]}, #{arr[0]}"
end
# Examples
puts swap_name('Joe Rober... | true |
c6158f95b8b5bf9b556e57e0aaa9b89c4bfd1296 | Ruby | mega0319/key-for-min-value-web-031317 | /key_for_min.rb | UTF-8 | 401 | 3.671875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # prereqs: iterators, hashes, conditional logic
# Given a hash with numeric values, return the key for the smallest value
def key_for_min_value(name_hash)
smallest_number = ""
new_value = 10000000000000
key_house = nil
name_hash.each do |key, value|
if new_value > value
smallest_number = value
... | true |
d96fab0643e767167fc5ac8b49b5e51aec788445 | Ruby | sunaynab/AppAcademyProjects | /W2D1/class_inheritance.rb | UTF-8 | 1,101 | 3.609375 | 4 | [] | no_license | class Employee
attr_reader :salary
def initialize(name, title, salary, boss)
@name = name
@title = title
@salary = salary
@boss = boss
end
def bonus(multiplier)
salary * multiplier
end
end
class Manager < Employee
def initialize(name, title, salary, boss, employees)
super(name,... | true |
519e813e3f102f8f931f050c8693c9c0058308a3 | Ruby | wwilco/week9 | /d01/hogwarts/server.rb | UTF-8 | 692 | 2.859375 | 3 | [] | no_license | require 'sinatra'
students = {
0 => {
id: 0,
name: "Harry Potter",
age: 26,
spell: "Pow!"
}
}
counter = 1
get '/students' do
erb :index, locals:{students: students}
end
post '/student' do
newstudent = {
id: counter,
name: params["name"],
age: params["age"],
spell: params["spell"... | true |
436aba3f4f8143ea650067677ed90e71c0f1ff06 | Ruby | novarac23/ror-techfleet-class | /week-1/day-2-non-exercise/comparables.rb | UTF-8 | 1,531 | 4.28125 | 4 | [] | no_license | a = "something"
b = 1
c = nil
d = false
e = 5
f = true
# && operator only works if BOTH values are true
puts "&& operator --------"
if a && b
puts "I AM TRUE"
else
puts "I AM false"
end
if a && d
puts "I AM TRUE"
else
puts "I AM false"
end
puts "----------------"
# || operator allows the code to be execu... | true |
92b4d3c2213791516752bbf7d087261da57bdf3f | Ruby | gdistasi/omf-tools | /graphs/calc.rb | UTF-8 | 1,719 | 3.28125 | 3 | [] | no_license | #!/usr/bin/env ruby
# The script merges two dat files produced by ITGDec by summing up the Aggregate-flow columns of the two files
require 'getoptlong'
values = Array.new
times = Array.new
def usage()
puts "sum.rb --sum|--average [--skipline] file0.dat file1.dat [file2.dat, ...]"
end
if ARGV.size<2
usage()
e... | true |
293014d5ffab563429c56310da9cf6403d4a24d6 | Ruby | verg/dinner_dash | /spec/models/cart_spec.rb | UTF-8 | 2,012 | 2.59375 | 3 | [] | no_license | require 'spec_helper'
describe Cart do
it { should have_many(:line_items) }
it { should belong_to(:user) }
describe ".add_product" do
it "adds a line item to the cart for the product" do
cart = Cart.create
product = create(:product)
cart.add_product(product)
expect(cart.line_items.f... | true |
6eb8a4111949b790da7b4e0bf21815bba8da877b | Ruby | LagoLunatic/DSVEdit | /dsvedit/clickable_graphics_scene.rb | UTF-8 | 860 | 2.65625 | 3 | [
"MIT"
] | permissive |
class ClickableGraphicsScene < Qt::GraphicsScene
BACKGROUND_BRUSH = Qt::Brush.new(Qt::Color.new(240, 240, 240, 255))
signals "clicked(int, int, const Qt::MouseButton&)"
signals "moved(int, int, const Qt::MouseButton&)"
signals "released(int, int, const Qt::MouseButton&)"
def initialize
super
... | true |
2c31ebe20840469c9cbdfa9503dd0a83af245395 | Ruby | lisaychuang/ruby-collaborating-objects-lab-v-000 | /lib/song.rb | UTF-8 | 510 | 3.21875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song
attr_accessor :name, :artist
def initialize(song)
@name = song
end
def artist= (artist)
@artist = artist
end
def artist
@artist
end
def self.new_by_filename(filename)
#=> filename = "Thundercat - For Love I Come - dance.mp3"
song_file = filename.split(" - ")
ne... | true |
73939aaf211e05dc553cdead86537c80a998064d | Ruby | scotthuston82/object_oriented_programming | /exercise2.rb | UTF-8 | 134 | 3.359375 | 3 | [] | no_license | require './cat.rb'
one = Cat.new("izzy", "pate", 8)
two = Cat.new("bob", "kibble", 19)
puts one.eats_at
puts one.meow
puts two.meow
| true |
83b079c70365842d8abbdea827fd886d7b56434d | Ruby | jywei/ruby-toys | /OOP_file/file_operator.rb | UTF-8 | 614 | 3.03125 | 3 | [] | no_license | require_relative 'file_reader'
require_relative 'csv_reader'
require_relative 'yml_reader'
require_relative 'json_reader'
# x = FileReader.new('sample.txt')
# x = FileReader.new(ARGV[0])
# puts x.read
# FileReader.new(ARGV[0]).read
# CsvReader.new(ARGV[0]).read
# YmlReader.new(ARGV[0]).read
# JsonReader.new(ARGV[0]).... | true |
0b02e8bd4b99481bc4ff69c4530e7fbb127b7e8d | Ruby | javomorales/BiciMadAnalysis | /Code/FalloBicis.rb | UTF-8 | 1,998 | 3.03125 | 3 | [] | no_license | # ---------------------
# Saber cuántas veces se deja una bici en la misma estación
# Es decir, la bici funciona mal
# Recoge datos de los fichero .json de opendata de EMT que se le pasen
#
# EJECUTAR:
# ruby FalloBici.rb FICHERO_W FICHEROs_R
#
# EJEMPLOs:
# ruby FalloBici.rb DejarBiciMismaEstacion.csv 201806_Usage_Bi... | true |
75a8e16a949743fc5b5aa7cefe81b92578317818 | Ruby | CristianAbrante/NutritionalCalculator | /lib/nutritional_calculator/food.rb | UTF-8 | 3,823 | 3.5 | 4 | [
"MIT"
] | permissive |
module NutritionalCalculator
# Esta clase representa a un alimento de manera abstracta.
# Contiene su nombre y su información nutricional.
# Se ha incluido el módulo Comparable.
class Food
# valor nutricional de las proteinas: <b>4.0</b>
PROTEINS_VALUE = 4.0
# Valor nutricional de los glúcidos:... | true |
f73aa828bd5c210513ad7fa6857f1f2c8e6c3dc5 | Ruby | gerdadecio/bitmap_editor | /spec/commands/colour_spec.rb | UTF-8 | 1,655 | 2.953125 | 3 | [] | no_license | require 'bitmap'
require 'commands/create'
require 'commands/colour'
describe Commands::Colour do
let(:bitmap) { Bitmap.new }
let(:x) { 2 }
let(:y) { 3 }
let(:colour) { 'N' }
subject { described_class.new(bitmap, x, y, colour) }
before do
Commands::Create.new(bitmap, 5, 6).execute
end
describe '... | true |
20c3600317ff6408fb9ba7d8b32dc05c1aa32345 | Ruby | recyclery/vtracklery | /test/models/worker_test.rb | UTF-8 | 2,947 | 2.640625 | 3 | [] | no_license | require 'test_helper'
class WorkerTest < ActiveSupport::TestCase
test "sum_time_in_seconds" do
w = Worker.create(name: "test worker", status_id: 1, work_status_id: 1)
start_at = DateTime.new(2008, 10, 11, 1, 0)
end_at = DateTime.new(2008, 10, 11, 1, 30) # 30 minutes later
wt = w.work_times.create(st... | true |
5e278b714f00279c8848f6584d1f048717068e97 | Ruby | pdg137/hangman | /lib/move.rb | UTF-8 | 433 | 3.375 | 3 | [] | no_license | class Move
attr_reader :guess, :pattern
def self.guess(guess)
Move.new(nil, guess)
end
def self.pattern(pattern)
Move.new(pattern, nil)
end
def to_s
if @pattern
"respond with #{@pattern}"
else
"guess #{@guess}"
end
end
private
def initialize(pattern, guess)
rais... | true |
067a7819b0797c08c5a63c6ee2b43bc3fb2a8cf3 | Ruby | kyatul/ExercismRuby | /simple-linked-list/simple_linked_list.rb | UTF-8 | 1,268 | 3.375 | 3 | [] | no_license | # Exercism Ruby - Simple Linked List
class SimpleLinkedList
attr_accessor :head
def initialize
@size = 0
@nodes = []
@head = nil
end
def size
@size
end
def peek
if @head.nil?
nil
else
@head.datum
end
end
def empty?
@size.zero?
end
def pop
@size -=... | true |
28a9d763660acedadc5e140f3e7a52696fcc5028 | Ruby | nebanche/AdventOfCode2019 | /day1/puzzle1-1.rb | UTF-8 | 432 | 3.78125 | 4 | [] | no_license | # ###
# First poll, every elf is Go
# mass/3, round down, subtract 2
# sum of all inputs by (mass/3) - 2
# ##
def fuel_calcuation(mass)
(mass/3) - 2
end
def calculate_total_fuel(masses)
fuel_calcs = masses.map(&method(:fuel_calcuation))
fuel_calcs.reduce(:+)
end
def run_program
file = File.open("input.txt"... | true |
80e6796085142813d5c62fedebb0cb2b750ad872 | Ruby | tench-o/release-crawler | /run.rb | UTF-8 | 369 | 2.640625 | 3 | [] | no_license | require './lib/crawler'
require 'csv'
results = Crawler.all_execute
puts %w(サイト名 記事タイトル 公開日 記事URL).to_csv
results.each do |crawler, articles|
next if articles.nil?
klass = Crawler.get_executor(crawler)
articles.each do |article|
puts [klass.name, article[:title], article[:publish_date], article[:content_url... | true |
ee82ac91d1504e8697a55c75a9629d7aca9d052c | Ruby | zacwillmington/playlister-sinatra-v-000 | /app/models/song.rb | UTF-8 | 593 | 2.734375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Song < ActiveRecord::Base
belongs_to :artist
has_many :song_genres
has_many :genres, through: :song_genres
#extend Concerns::Slugifiable
def slug
self.name.downcase.gsub(" ", "-")
end
def self.find_by_slug(slug)
song = slug.split("-").collect do |name|
... | true |
3490aa9a6b192fdb34568c0733b18c84e0c36d71 | Ruby | brianhempel/base_x | /test/test_base_x.rb | UTF-8 | 8,457 | 2.84375 | 3 | [
"LicenseRef-scancode-warranty-disclaimer",
"CC0-1.0",
"LicenseRef-scancode-public-domain"
] | permissive | require 'bundler/setup'
Bundler.require(:test)
require 'base_x'
require 'minitest/autorun'
require 'minitest/reporters'
MiniTest::Reporters.use! Minitest::Reporters::DefaultReporter.new
class TestBaseX < Minitest::Test
def setup
@base_x = BaseX.new("012")
end
attr_reader :base_x
### Instance Methods ##... | true |
a27b2181a5161540fa99f4e890b5d3ac76d845a4 | Ruby | taganaka/link_thumbnailer | /lib/link_thumbnailer/graders/link_density.rb | UTF-8 | 497 | 2.59375 | 3 | [
"MIT"
] | permissive | module LinkThumbnailer
module Graders
class LinkDensity < ::LinkThumbnailer::Graders::Base
def call(current_score)
return 0 if density_ratio == 0
current_score *= density_ratio
end
private
def density
return 0 if text.length == 0
links.length / text.lengt... | true |
4f3e20840bfd8f16d08135973112d530deb5fbc4 | Ruby | drhinehart/data-engineering | /data_engineering/app/services/data_importer.rb | UTF-8 | 793 | 3.125 | 3 | [] | no_license | require 'csv'
class DataImporter
attr_reader :file, :gross_revenue, :purchases
def initialize(file)
@file = file
@purchases = []
end
def import
csv_options = {
headers: :first_row,
header_converters: :symbol,
converters: :all,
... | true |
97b565f62b354e3de56b649b502ad4838d9ac9c4 | Ruby | Mani082/RubyFiles | /aborting.rb | UTF-8 | 203 | 3.46875 | 3 | [] | no_license | fruits = ['banana', 'apple', 'Mangoe']
fruits.each do |fruit|
if fruit=='apple'
#exit
abort("I hate apple")
end
puts fruit.capitalize
end
puts "Total fruits: #{fruits.count}" | true |
6a7081dda3b35acb6d49558af6db20b91664cf64 | Ruby | DavisC0801/jungle_beats | /lib/node.rb | UTF-8 | 166 | 3.078125 | 3 | [] | no_license | class Node
attr_reader :next_node, :data
def initialize(data)
@data = data
@next_node = nil
end
def set_next(node)
@next_node = node
end
end
| true |
c352daa3ee1d8ac7da7de18d56d9860134725d4b | Ruby | mandareis/programming-univbasics-4-crud-lab-sfo01-seng-ft-100520 | /lib/array_crud.rb | UTF-8 | 673 | 3.890625 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def create_an_empty_array
[]
end
def create_an_array
an_array = ["Chocolate", "Wine", "Babe", "Money"]
end
def add_element_to_end_of_array(array, element)
array.push(element)
end
def add_element_to_start_of_array(array, element)
array.unshift(element)
end
def remove_element_from_end_of_array(array)
array.pop
end
... | true |
c67ac66508e7e0fdbaed386549e36a5d5df92f72 | Ruby | NewbiZ/sandbox | /gmail_lister/gmail_lister.rb | UTF-8 | 1,141 | 2.78125 | 3 | [] | no_license | #!/usr/bin/env ruby
# You need to define your login and password in JSON format in ~/.gmail :
# {
# "login": "user.name",
# "password": "your_password"
# }
require 'gmail'
require 'json'
require 'yaml'
require 'date'
require 'tmail'
gmail_config = JSON.parse( IO.read("/Users/newbiz/.gmail") )
gmail = Gmail.ne... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.