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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
be5900c1d8253ded2ed88a21e9fd2696542e8360 | Ruby | rodgco/AdventOfCode | /day05part1.rb | UTF-8 | 226 | 3.296875 | 3 | [] | no_license | a = Array.new
File.open('day05input.txt').each do |line|
a << line.to_i
end
n = 0
c = 0
puts a.length
begin
c += 1
a[n] += 1
n += a[n]-1
rescue
puts n
end while n >= 0 and n <= a.length-1
puts c | true |
63fbc6dad11bbcb6763d6d3675541a419eb7308e | Ruby | otahi/network_drawer | /lib/network_drawer/element/node.rb | UTF-8 | 2,588 | 2.84375 | 3 | [
"MIT"
] | permissive | require 'network_drawer'
module NetworkDrawer
module Element
# Replesent of node
class Node < Element
DEFAULT_STYLE = { fontname: 'Helvetica', shape: 'box' }
def initialize(initial_values = {}, style = {})
super
@default_style = DEFAULT_STYLE
end
def to_code
... | true |
0f7a7e85f4bfb9e435bf958e26884d385e5a2685 | Ruby | mikecthurgood/playlister-sinatra-london-web-082619 | /app/models/artist.rb | UTF-8 | 438 | 2.8125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Artist < ActiveRecord::Base
has_many :songs
has_many :genres, through: :songs
def song_names_by_genre(genre_object)
a = self.songs.select { |song| song.genres.include? genre_object }
a.map(&:name)
end
def slug
slug = self.name.downcase.strip.gsub(' ', '-').gsub(/[^\w... | true |
960406de4f77e7547a2512f71bdaa9bc257e02bf | Ruby | treehouse/fyi | /lib/fyi.rb | UTF-8 | 1,509 | 2.734375 | 3 | [
"MIT"
] | permissive | require 'open3'
require 'fyi/config'
require 'fyi/core_ext'
#
# See /bin/fyi for documentation.
#
class Fyi
def self.run(command)
new(command).run
end
def initialize(command)
@command = command
@config = Config.new
end
def run
start_stopwatch
# Append ";" to command to force Ruby to inv... | true |
8e8373348a2ac70c6da650d96bfab0732e3fa152 | Ruby | virajs/ruby-in-practice | /CH2/2.4.3/test_using_mocha.rb | UTF-8 | 782 | 2.625 | 3 | [] | no_license | require 'rubygems'
require 'test/unit'
require 'mocha'
require 'material_supplier'
class TestSupplierInterface < Test::Unit::TestCase
def test_execute_purchase
data = [
{:item_name => 'Red Rug', :quantity => 2},
{:item_name => 'Set of Pens', :quantity => 17}
]
my_supplier = MaterialSup... | true |
e8c3e9d7307ec80283bf69bc9b9e53dce0656a83 | Ruby | ChristopherJamesN/playlister-sinatra-v-000 | /app/models/artist.rb | UTF-8 | 430 | 2.8125 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Artist < ActiveRecord::Base
has_many :songs
has_many :genres, through: :songs
def slug
self.name.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
end
def self.find_by_slug(slug)
unslug = slug.gsub('-', ' ')
all_artists = Artist.all
all_artists.each do |artist|
if artist.name.down... | true |
0288cc6e500c3bc34c23a2f7caa9b0762ea5897b | Ruby | zakkoltun/launch_school_prep | /hashes/ex7.rb | UTF-8 | 154 | 3.25 | 3 | [] | no_license | # the first hash my_hash sets a symbol :x as the key,
# while the second hash my_hash2 sets the key to
# the value of the variable x, which is "hi there" | true |
34efd4f1714419b24cdee7a05d2378bb63936aa4 | Ruby | ypadawann/2015_training | /testapp/model/helpers.rb | UTF-8 | 892 | 2.828125 | 3 | [] | no_license |
require 'digest/sha2'
require 'securerandom'
require 'active_support/all'
module Model
class Helper
DELIMITER = '$'
HASH_ITERATIONS = 1000
class <<self
private
def hash(password, salt)
password += salt
HASH_ITERATIONS.times do
password = Digest::SHA256.hexdi... | true |
dc869deb7ead6edfb4fe05f6234904c05556ddde | Ruby | ambervill/practice | /cube/cube_solving.rb | UTF-8 | 2,765 | 3.234375 | 3 | [] | no_license | require './cube'
cube = Cube.new
algorithm = "l r fi d bi f u di fi di li d bi" #Algorithm.generate(9)
cube << algorithm
puts cube
puts "_____________________________"
class CubeSolver
class << self
def solve(cube)
assemble_bottom_cross(cube)
assemble_bottom_corners(cube)
assemble_middle_corner... | true |
b0ac6299d175767ccd399e5d6cde359254d58926 | Ruby | aconstandinou/course-101-programming-foundations | /lesson_3/exercises_hard1.rb | UTF-8 | 886 | 3.828125 | 4 | [] | no_license | # question 1
# Typically, when you reference an uninitialized variable, Ruby will raise
# an exception, stating that it’s undefined. However, when you initialize a
# local variable within an if block, even if that if block doesn’t get executed,
# the local variable is initialized to nil.
# question 2
# greetings binds... | true |
8f28c1ec166346065d4baeabfd2d4a9f9db07af3 | Ruby | goldstar/emr-etl-runner | /config/convert_targets.rb | UTF-8 | 4,632 | 2.90625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | #!/usr/bin/ruby
# This script extracts storage targets from old-style (pre-R88) Snowplow config.yml
# and writes them as new-style self-describing JSONs
#
# Usage:
# $ ./convert_targets.rb /path/to/config.yml
require 'yaml'
require 'json'
KNOWN_TYPES = ['redshift', 'postgres', 'elasticsearch']
# Read YAML file ... | true |
310541914f6d08e9908f67dbbb3a6f48983052e4 | Ruby | djab/euler | /1.rb | UTF-8 | 331 | 4.0625 | 4 | [] | no_license | #Project Euler - #1
#If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. #The sum of these multiples is 23.
#Find the sum of all the multiples of 3 or 5 below 1000.
array = []
(1...1000).each do |n|
if (n % 3 == 0) || (n % 5 == 0)
array << n
end
end
sum = array.inject(:+... | true |
291e5fd7287c326328e8a73cac470dc21e536cf8 | Ruby | hand6763/furima-29098 | /spec/models/user_spec.rb | UTF-8 | 4,249 | 2.609375 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe User, type: :model do
before do
@user = FactoryBot.build(:user)
end
describe 'ユーザー新規登録' do
context '新規登録がうまくいくとき' do
it 'nicknameとemail、password,password_confirmation,sei,mei,sei_kana,mei_kana,birthdayが存在すれば登録できる' do
expect(@user).to be_valid
end... | true |
102bf270533528f6a14dd1b0a5f00d7471ec4a69 | Ruby | spicedteamaker/ruby-learning | /alien_escape/src/Door.rb | UTF-8 | 323 | 3.09375 | 3 | [] | no_license | class Door
def initialize(leads_to, is_locked = false, item_required)
@leads_to = leads_to
@is_locked = is_locked
@item_required = item_required
end
def unlock
@is_locked = false
end
def lock
@is_locked = true
end
def get_leads_to
return @leads_to
end
def is_locked?
return @is_locked
end
e... | true |
4c0a5afb9fe0e39e0120c59fec0d4ae304c63fe3 | Ruby | stanloo/launch-school | /101_exercises/problem_solving.rb | UTF-8 | 630 | 3.1875 | 3 | [] | no_license | =begin
# Omit unneccesary info
# Indent bullet points
1. Understanding the Problem
- input:
--- ...
- output:
--- ...
2. Examples / Test Cases
- ALLE
...
3. Data Structure
...
4. Algorithm / Abstraction
- 2a+1
...
=end
# Here goes the code
# Additional comments
##### My alternative
# Description
=begin # Opti... | true |
be91e487ad1f0bf1d80a9e2c70815391496b1e45 | Ruby | railskipl/coders | /lib/login_system.rb | UTF-8 | 844 | 2.515625 | 3 | [] | no_license | module LoginSystem
protected
def is_logged_in?
@logged_in_user = User.find(session[:user]) if session[:user]
end
def logged_in_user
return @logged_in_user if is_logged_in?
end
def logged_in_user=(user)
if !user.nil?
session[:user] = user.id
@logged_in_user = user
end
end
def self.included(ba... | true |
9f7f58bbdb2bea9bd73eb8560eb2c23bfc1789f8 | Ruby | heim/ruby_meta | /ep3/ep3-03.rb | UTF-8 | 151 | 2.640625 | 3 | [] | no_license | l = Proc.new { |a,b,c| p a,b,c}
l.call(1,2,3)
l.call(1,2)
l.call(1,2,3,4)
l = lambda { |a,b,*c| p a,b,c}
l.call(1,2,3)
l.call(1,2)
l.call(1,2,3,4)
| true |
41471ee57dbc0680786a71ab3a917f182d4849fa | Ruby | masao/fuwatto | /test/test_document.rb | UTF-8 | 3,357 | 2.53125 | 3 | [] | no_license | #!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# $Id$
require 'test/unit'
$:.unshift File.join( File.dirname( __FILE__ ), ".." )
require "fuwatto.rb"
class TestFuwatto < Test::Unit::TestCase
include Fuwatto
def test_document
text = "test test1 test2"
vector = Document.new( text )
assert( vector ... | true |
bc17b8da942fde1c40e367dc2cf27ff351975fab | Ruby | OursDavid/Exercice-Ruby | /exo_17.rb | UTF-8 | 310 | 3.4375 | 3 | [] | no_license | i =0
puts "entrez un nombre entre 1 et 25"
val = gets.chomp.to_i
while val > 25 || val < 1 && val.class != "Integer"
puts "entrez un nombre entre 1 et 25"
val = gets.chomp.to_i
end
space = " " * val
stone = "#"
while i < val
puts space + stone
space.slice!(-1)
stone += "##"
i+=1
end | true |
ca162e504172547d50cf5dd7a5fc8b13baf706cf | Ruby | paulliu87/phase-0-tracks | /ruby/santa.rb | UTF-8 | 2,294 | 3.421875 | 3 | [] | no_license | class Santa
attr_accessor :gender, :ethnicity, :reindeer_ranking, :age
def initialize(gender,ethnicity,age =0)
@gender = gender
@ethnicity = ethnicity
@reindeer_ranking = ["Rudolph", "Dasher", "Dancer", "Prancer", "Vixen", "Comet", "Cupid", "Donner", "Blitzen"]
@age = age
puts "Initializing Santa ... | true |
a4b4ea7ec3a164784f459f31875bedc309d3a35d | Ruby | evagabriela/BikeEurope_ruby | /lib/bike_europe.rb | UTF-8 | 11,458 | 3.796875 | 4 | [] | no_license | require 'debugger'
require_relative 'bike_europe/util'
require_relative 'bike_europe/city'
require_relative 'bike_europe/road'
class BikeEurope
attr_reader :visited_cities
def initialize(start_city, end_city)
@start_city, @end_city = start_city, end_city
@current_city = start_city
@visited_cities =... | true |
553e6779aa064d44c92aa5544628cccbc7932be9 | Ruby | picardantoine/codewars | /bouncing_ball/bouncing_ball.rb | UTF-8 | 378 | 3.09375 | 3 | [] | no_license | def bouncingBall(h, bounce, window)
if bounce <= 0 || bounce >=1 || h <= 0
return -1
else
return calculate_rebound_numbers(h, bounce, window)
end
end
def calculate_rebound_numbers(height, bounce, window)
if height < window
return -1
else
new_height = height * bounce
return 2 + calculate_r... | true |
655c7e3c0b2086f1a96ef814f021c6df23ed53c2 | Ruby | shumipro/tabearuki-api | /app/models/restaurant.rb | UTF-8 | 1,564 | 2.703125 | 3 | [] | no_license | class Restaurant
include ActiveModel::Model
attr_accessor :id, :name, :distance, :image_urls, :business_hour, :description_long, :description_short, :address, :tel, :url, :holiday
class << self
def build_list_from_gurunavi_response(response)
body = response.body
count = body["response"]["hit_per... | true |
feba49f7a77bad5323d6ba76d3afe1a55d2a968e | Ruby | thomasnawabi/aa-sandbox | /a01-prep/a01-practice-first-retry/lib/assessment01.rb | UTF-8 | 3,107 | 3.984375 | 4 | [] | no_license | require 'byebug'
class Array
# Monkey patch the Array class and add a my_inject method. If my_inject receives
# no argument, then use the first element of the array as the default accumulator.
def my_inject(accumulator = nil, &prc)
if accumulator == nil
accumulator = self.first
self.drop(1).eac... | true |
462815cc3210ae19ba4c2cc3bba056a54da05e9a | Ruby | coalest-zz/launch_school | /rb_101/lesson_4/pedac.rb | UTF-8 | 660 | 3.46875 | 3 | [] | no_license | def pyramid_array(row_num)
current_row = 1
array = []
start_num = 2
num_of_nums = 1
current_row_array = []
counter = 0
# while counter < 100
# array[counter] = (counter+1)*2
# counter += 1
# end
counter = 0
while current_row < row_num
current_row_array = Array.new(current_row) {|i|(cu... | true |
8932b2753e3e46a3eacfd192a33c6184c20fe0fd | Ruby | onebree/adventofcode | /2015/day10/day10.rb | UTF-8 | 463 | 4.09375 | 4 | [] | no_license | def look_and_say(string, iterations)
iterations.times do
string = string.chars.slice_when { |x,y| x != y }.map { |x| "#{x.count}#{x[0]}" }.join
end
string
end
input = File.read('input').strip
# PART ONE
sequence_40 = look_and_say(input, 40)
puts "Look-and-say string length after 40 iterations: #{sequence_40... | true |
afe3806e5deff49dac69e9da76102f9bfb6eca6e | Ruby | mShining/web_tasks | /B1/iMessageBoard/message.rb | UTF-8 | 2,711 | 2.90625 | 3 | [] | no_license |
#require 'sinatra'
require 'yaml'
require 'time'
#Module for messages
class Message#Normally used in read-and-show process
attr_accessor :id , :message, :author , :created_at
@@id=0
# yaml文件 -> Message对象
def self.load(dir, ext="yaml")
@messages ||= Hash.new
Dir.glob("#{dir}/**/*.#{ext}").each do |file|
a... | true |
420987e9f85c300b651c5d91655af8ee5e31dea2 | Ruby | Kotauror/Tic_Tac_Toe_8th_Light | /spec/game_spec.rb | UTF-8 | 2,449 | 3.1875 | 3 | [] | no_license | require 'game'
describe Game do
let(:displayer) {double('displayer')}
subject(:game) { described_class.new(:displayer) }
let(:human) {double('human')}
let(:computer) {double('computer')}
context 'Initialization' do
describe '#initialize' do
it 'has initial mode nil' do
expect(game.mode).t... | true |
c10eb62d4fffba87a2d35b63f3c033cb332b63a9 | Ruby | eoncourse/app1rubysamples | /05 - Soubory a vyjimky/03b_vyjimky.rb | UTF-8 | 265 | 2.953125 | 3 | [] | no_license | puts "Zadejte 1. cislo"
delenec = gets.to_i
puts "Zadejte 2. cislo"
delitel = gets.to_i
begin
soubor = File.open("data3.txt", "w")
podil = delenec / delitel
soubor.puts(podil)
rescue
soubor.puts "Nelze delit nulou"
ensure
soubor.close
end | true |
386574278007c680e5d1a64f91d6442548f51dc8 | Ruby | apache/arrow | /ruby/red-arrow/test/test-slicer.rb | UTF-8 | 11,939 | 2.546875 | 3 | [
"Apache-2.0",
"MIT",
"BSD-3-Clause",
"BSD-2-Clause",
"ZPL-2.1",
"BSL-1.0",
"LicenseRef-scancode-public-domain",
"NTP",
"OpenSSL",
"CC-BY-4.0",
"LLVM-exception",
"Python-2.0",
"CC0-1.0",
"LicenseRef-scancode-protobuf",
"JSON",
"Zlib",
"CC-BY-3.0",
"LicenseRef-scancode-unknown-licens... | permissive | # Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not u... | true |
210036b4c51ced72a09eb5086f7e8112d8e34af1 | Ruby | awchang12/badges-and-schedules-prework | /conference_badges.rb | UTF-8 | 526 | 3.875 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # Write your code here.
def badge_maker(name)
return "Hello, my name is #{name}."
end
def batch_badge_creator(arr)
badge_messages = []
arr.each do |x|
badge_messages.push(badge_maker(x))
end
return badge_messages
end
def assign_rooms(arr)
room_assignments = arr.each_with_index.collect {|x, i| "Hello,... | true |
bf04e55207f81e26e95d62dade8eae1b7bcef126 | Ruby | thomasvincent/ddd_sample_app_ruby | /domain/handling/handling_event.rb | UTF-8 | 561 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'uuidtools'
class HandlingEvent
attr_accessor :event_type
attr_accessor :location
attr_accessor :registration_date
attr_accessor :completion_date
attr_accessor :tracking_id
attr_accessor :id
def initialize(event_type, location, registration_date, completion_date, tracking_id, id)
@event_type... | true |
9092a499f4edf2db10d088b85a52d6f7b1686ef7 | Ruby | yohasebe/quickanswers | /quickanswers.rb | UTF-8 | 3,795 | 2.65625 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# -*- coding: utf-8 -*-
$: << File.dirname(__FILE__)
require 'sinatra'
require 'sequel'
require 'json'
require 'config'
Sequel::Model.plugin(:schema)
DB = Sequel.sqlite("quickanswers.db")
class Posts < Sequel::Model
set_schema do
primary_key :id
string :author
string :mail
str... | true |
7b74eebb731d7993888285212e57e338b38a9eae | Ruby | DouglasAllen/Ruby-midi-projects | /NSS-Skip-Theory-101/test/test_scales_major_sharps.rb | UTF-8 | 1,108 | 2.8125 | 3 | [] | no_license | require 'test/unit'
require 'scales_major_sharps'
class ScalesMajorSharpsTest < Test::Unit::TestCase
def example_scale1
ScalesMajorSharps.new("cmaj")
end
def example_scale2
ScalesMajorSharps.new("dmaj")
end
def example_scale3
ScalesMajorSharps.new("dbmaj")
end
def example_scale4
ScalesMa... | true |
a9a7809d54a2fbd58c1e07f9e3d36bc6746a3baf | Ruby | UNO-Scheduling-Assistant/Project | /app/helpers/application_helper.rb | UTF-8 | 1,577 | 3.03125 | 3 | [] | no_license | require 'time'
require 'date'
module ApplicationHelper
# === Parameters:
# model - model class name (eg: Instructor, Section, etc.)
#
# values - hash with column_names, and tuple values
#
# === Description
# Inserts values into model database and returns
# the id
#
# If values already exist in the ... | true |
9b558bac727cba4218c946e92c3e0084e18370af | Ruby | synion/Codeval | /211.rb | UTF-8 | 344 | 2.859375 | 3 | [] | no_license | File.open("211.txt").each_line do |line|
a = line.chomp.split(" | ")
c = a[0].split(' ')
b = a[1].split('')
d = []
0.upto c.length - 1 do |j|
d[j] = []
end
0.upto c.length - 1 do |i|
c[i].each_char {|a| d[i] << a}
end
0.upto b.length - 1 do |f|
0.upto c.length - 1 do |k|
c[k].index(... | true |
ed1065b8ec66e8a8debf98ec93fa1004e1b53e67 | Ruby | Jablooo/myAdventure | /myadventure.rb | UTF-8 | 5,889 | 3.703125 | 4 | [] | no_license |
# use blocks, get.chomp, yield
def intro
puts "."*30
puts ".......Yawn, yawn, yawn......."
puts "."*30
puts ".....Who am I? Where am I?...."
puts ".....What am I doing here....."
puts "..Maybe I should look around.."
puts "."*30
puts "."*30
puts "."*30
sleep(6)
system("clear")
end
def first_choi... | true |
32c5009089d0a4bc5c9265ae116e20715bb7fb13 | Ruby | FeodorFitsner/ruby-misc-tests | /test-dirs.rb | UTF-8 | 401 | 2.984375 | 3 | [] | no_license | require 'fileutils'
FileUtils::mkdir_p 'foo/bar'
puts "foo contents:"
files = Dir.entries('foo')
for file in files
puts file
end
File.open("foo/bar/text.txt", 'w') {|f| f.write("Hello, world!") }
puts "foo/bar contents:"
files = Dir.entries('foo/bar')
for file in files
puts file
end
puts "File contents:"
File.ope... | true |
ba9568ddc42da6f1087c64dbf99b7dfc7fad41fc | Ruby | igorsimdyanov/ruby | /class_methods/class_method_inner.rb | UTF-8 | 114 | 2.828125 | 3 | [] | no_license | class HelloWorld
def HelloWorld.greeting
'Hello, world!'
end
end
puts HelloWorld.greeting # Hello, world! | true |
c89dbf07fdfcb1e3aedaf68057e88efdcd5027cc | Ruby | hashmaster3k/futbol | /lib/game.rb | UTF-8 | 925 | 2.875 | 3 | [] | no_license | require 'csv'
class Game
attr_reader :game_id,
:season,
:type,
:date_time,
:away_team_id,
:home_team_id,
:away_goals,
:home_goals,
:venue,
:venue_link
def initialize(args)
@game_id ... | true |
1ab84bf2b7d1a58b438b1760376ea534bffa2128 | Ruby | auser/toystore | /lib/toy/reference.rb | UTF-8 | 3,027 | 2.6875 | 3 | [
"BSD-3-Clause"
] | permissive | module Toy
class Reference
attr_accessor :model, :name, :options
def initialize(model, name, *args)
@model = model
@name = name.to_sym
@options = args.extract_options!
@type = args.shift
model.references[name] = self
model.attribute(key, type.key_type)
creat... | true |
f18bc8bd25dffd0145cb3de047eda58407e61d48 | Ruby | HMKnapp/taxi | /src/taxi/commands/status.rb | UTF-8 | 4,811 | 2.671875 | 3 | [] | no_license | # frozen_string_literal: true
require 'taxi/config'
require 'date'
module Taxi
# Represents the status of translation packages
class Status
STATUS_FOLDERS = {
'open' => DirConfig::OPEN,
'deploy' => DirConfig::DEPLOY,
'done' => DirConfig::DONE
}.freeze
LS_REGEX = /^(?<type>[d|-])r[rwx... | true |
d0c17ecef42a5750597c3b06981d3c7405844325 | Ruby | tatsuio/juvet | /spec/juvet/attributable_spec.rb | UTF-8 | 2,020 | 2.90625 | 3 | [
"MIT"
] | permissive | describe Juvet::Attributable do
class Ava
include Juvet::Attributable
end
describe "#attributes" do
subject { Ava.new name: "Ava", model: 5.9 }
it "returns a hash of the objects public getters and their values" do
expect(subject.attributes).to eq({ name: "Ava", model: 5.9 })
end
end
d... | true |
b82a1eec66daa07c9561e165307f007a3992fd99 | Ruby | TylerRockwell/number_guessing | /guessing_game.rb | UTF-8 | 3,355 | 4.21875 | 4 | [] | no_license | def get_input(num_guess)
#Prompts user for input
print "Enter your guess (#{5-num_guess} remaining): "
gets.chomp
end
def is_a_number(input)
true if Float(input) rescue false
end
def terminate(message="Terminating...")
puts `clear`
puts "#{message}"
puts
exit
end
def check_guess(guess, answer)
if g... | true |
c5710bd9e282a81627ac647c0a7dc3dca12e04e6 | Ruby | fumi/openpark-data | /bin/convert-5-kz-chishin.rb | UTF-8 | 1,664 | 2.59375 | 3 | [] | no_license | #!/usr/bin/env ruby
# -*- coding: utf-8 -*-
require 'rdf'
require 'rdf/turtle'
require 'rdf/vocab'
require 'csv'
require 'securerandom'
INPUT_FILE="../data/original/14108/5-kz-chishin_utf8.csv"
OUTPUT_FILE="../data/dumps/park/14108/5-kz-chishin.ttl"
PARK_RESOURCE = RDF::Vocabulary.new("http://openpark.jp/parks/1410... | true |
c6364e6d730def3fd88f6e794518016eb5b6e788 | Ruby | charlesemery15/learn-to-program | /learn-to-program/learn-to-program/chap06/methods.rb | UTF-8 | 827 | 3.796875 | 4 | [] | no_license | var1 = "Hedgehog"
var2 = "Rabbit"
reverse
puts var1.reverse
puts var1.length
puts var2.length
puts var2
puts "Please enter your first name"
f_name = gets.chomp
puts "Please enter your middle name"
m_name = gets.chomp
puts "Please enter your last name"
l_name = gets.chomp
w_name_length = f_name.length + m_name.length + ... | true |
603cb21814d36f925ebaf9bd9ee67f214c48a50a | Ruby | aminnurr/celebdating | /lib/scrapper/people.rb | UTF-8 | 1,267 | 3.078125 | 3 | [] | no_license | require_relative'sharereq'
class People
def initialize(url)
doc = Nokogiri::HTML(open(url))
@doc = doc
end
def ul_tag(item_name)
items = @doc.xpath("//*[@id='mw-content-text']/div/ul[1]")
items.each do |list|
new_lists = list.css('li')
new_lists.ea... | true |
0ebfb960f466297fefedc38744012d4b5519940c | Ruby | nitanshu1808/ruby_design_pattern | /pattern_programming/inverted_full_pyramid.rb | UTF-8 | 266 | 3.3125 | 3 | [] | no_license | class InvertedFullPyramid
def self.print_pyramid
(1..4).to_a.reverse.each_with_index do |item, index|
for i in 0..index (print " ") end
(1..(2*item - 1)).to_a.each{|val| print "*"}
puts ""
end
end
end
InvertedFullPyramid.print_pyramid
| true |
5d29a8dfef132305bbc3d0c89ccf16b74b4fc3f6 | Ruby | whittleapp/backend | /app/models/business.rb | UTF-8 | 386 | 2.796875 | 3 | [] | no_license | class Business < ApplicationRecord
validates :name, presence: true
has_many :transactions
def monthly_total(date)
sum = 0
self.monthly_transactions(date).each do |transaction|
sum += transaction.posted_amount
end
sum.round(2)
end
def monthly_transactions(date)
self.transactions.... | true |
c0b29cdc9bc5771efa7dd14759685e6ed157b1b0 | Ruby | jrmhaig/AdventOfCode | /2016/day_1.rb | UTF-8 | 1,242 | 2.90625 | 3 | [
"Beerware",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/env ruby
require 'matrix'
input = 'L5, R1, R4, L5, L4, R3, R1, L1, R4, R5, L1, L3, R4, L2, L4, R2, L4, L1, R3, R1, R1, L1, R1, L5, R5, R2, L5, R2, R1, L2, L4, L4, R191, R2, R5, R1, L1, L2, R5, L2, L3, R4, L1, L1, R1, R50, L1, R1, R76, R5, R4, R2, L5, L3, L5, R2, R1, L1, R2, L3, R4, R2, L1, L1, R4, L1, L1, R... | true |
43ace4e024932198d85f1b5b0e5666b06bb2cf6d | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/cs169/1130/source/10926.rb | UTF-8 | 1,190 | 3.25 | 3 | [] | no_license | def combine_anagrams(words)
sorted = []
outer = []
inner = []
words.each { |word| sorted << word.downcase.chars.sort { |a, b| a.casecmp(b) } .join}
outerCount = 0
innerCount = 0
hash = {}
for matchOuter in sorted
if hash.has_key?(sorted.index(matchOuter)) == false
for matchInner in sorted
... | true |
c8543d7367685ba21505b9fd0c57279de4c9c355 | Ruby | bacancy-urmit/validation-form | /app/models/student.rb | UTF-8 | 740 | 2.703125 | 3 | [] | no_license | class Student < ApplicationRecord
validates :lastname,presence: true, if: :firstname_precent?
validates :firstname, format:{ with: /\A[A-Z]+\z/,messgae: "First latter should must be capital"}
validates :lastname, format:{ with: /\A[A-Z]+\z/,messgae: "First latter should must be capital"}
validates :ema... | true |
2ed642637e0fbaa95c6150b737b861946e5f5e5a | Ruby | Darktangent/Ruby | /method.rb | UTF-8 | 221 | 3.765625 | 4 | [] | no_license | class Piglet
def speak (inp)
#puts "oik, oink!"
puts inp
end
def pig_ears(age)
age*18
return age
end
end
hamlet = Piglet.new
hamlet.speak("oink oink!")
hamlet.age(1)
| true |
2397ca1fe29c06f6f460765cb495cee0563e9408 | Ruby | nstoeckigt/Ruby-First-Steps | /firstStep/entity.rb | UTF-8 | 309 | 3.03125 | 3 | [] | no_license | class Entity
def initialize(position, direction = nil)
@position = position
@direction = direction
end
def checkStep(field)
if field.is_a?(Rock) or field.is_a?(Border)
return false
else
return true
end
end
attr_accessor :position
attr_accessor :direction
end | true |
489ca2e6091123e97e000f1bbab5b2916077a46e | Ruby | ck3g/wimdu-cli | /lib/wimdu/option_handler/list.rb | UTF-8 | 447 | 2.546875 | 3 | [] | no_license | module Wimdu
module OptionHandler
class List < Base
def run
properties = Wimdu::Property.published
if properties.any?
cnt = properties.count
puts "Found #{cnt} #{"offer".pluralize(cnt)}."
puts
properties.each do |property|
puts "#{property.... | true |
eafbdb05dfcc9a794340552e68de4f52f53d1a5b | Ruby | Lucho7722/Shogi | /Class/piece_type.rb | UTF-8 | 129 | 2.6875 | 3 | [] | no_license | class Piece_type
attr_accessor :name, :letter
def initialize(name, letter)
@name = name
@letter = letter
end
end | true |
3ad47b1d4567b1f2aca66d501b3d9b886416ec1a | Ruby | colorshifter/caaers | /caAERS/software/core/tools/ctc_term_loader/ctcae.rb | UTF-8 | 1,977 | 2.890625 | 3 | [
"BSD-3-Clause",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | #!/usr/bin/env ruby
#
# Processes the CTCAEv3_M9 CSV into a bering migration
#
require 'csv'
$cat_order = []
$terms_by_cat = { }
def read()
reader = CSV::Reader.create(File.open("CTCAEv3_M9.txt"))
# skip first two rows
reader.shift
reader.shift
id = 3001
reader.each do |row|
cat, term, select, ct... | true |
b587f5dfa4e3f20fa70b23660215df950adffa25 | Ruby | dbarakoti/challenges | /fibonacci.rb | UTF-8 | 98 | 3.484375 | 3 | [] | no_license | # Do fibonacci
def fibo(n)
n <= 2 ? 1 : fibo(n-1) + fibo(n-2)
end
p (1..10).map{ |x| fibo(x) }
| true |
b63b40a87410b575c557c7998a19052fa235d569 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/hamming/abfaca5cf86644b6b63c7497ca726ab1.rb | UTF-8 | 304 | 3.59375 | 4 | [] | no_license | class Hamming
def self.compute(dna1, dna2)
@length = [dna1.length, dna2.length].min
count_the_distance(dna1, dna2)
end
private
def self.count_the_distance(dna1, dna2)
distance = 0
@length.times do |i|
distance += 1 unless dna1[i] == dna2[i]
end
distance
end
end
| true |
c54d9d19a13c38e3e9f1896b3d715cda6a5c44c9 | Ruby | paul-ylz/rubysteps_homework_paul_ylz | /015_refactoring_small_steps/ex2_refactoring_birthday_tracker.rb | UTF-8 | 1,528 | 3.546875 | 4 | [] | no_license | # Ex 2 refactor gently
class BirthdayTracker
def initialize(db_filename)
@entries = []
@db_file = db_filename
load_entries()
end
def load_entries
File.open(@db_file, 'a+') do |file|
file.each_line do |line|
name, month, date = line.split(':')
@entries << [name, month, date]... | true |
c26f939f3381bf1088e158be70ab2397ee840eb1 | Ruby | BinaryBlitz/justforyou | /app/models/address.rb | UTF-8 | 1,262 | 2.65625 | 3 | [] | no_license | # == Schema Information
#
# Table name: addresses
#
# id :integer not null, primary key
# content :text not null
# entrance :integer
# floor :integer
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# latitude :float ... | true |
9427877a43e89e8f7a6826c178b8cb38e1a59ec0 | Ruby | paletov/railway-system | /lib/controllers/railway_network_controller.rb | UTF-8 | 1,615 | 2.515625 | 3 | [] | no_license | require 'edge'
require 'edge_repository'
require 'priority_queue'
require 'edge_repository'
require 'path_finder'
require 'price_cost_comparator'
require 'price_time_cost_comparator'
require 'time_cost_comparator'
require 'time_price_cost_comparator'
class RailwayNetworkController
public
def find_shortest_path(st... | true |
f062bd410eb1e1c61b7f03acbe1baed8bb26bca5 | Ruby | wcpr/riakrest | /lib/riakrest/resource/jiak_resource.rb | UTF-8 | 23,034 | 2.5625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | module RiakRest
# JiakResource provides an abstraction to the Jiak interaction provided by
# the Core Client classes of RiakRest. JiakResource is built on top of Core
# Client and does not provide any functionality not possible through Core
# Client. However, JiakResource does provide a much simplier Jiak inter... | true |
8beb48837dcf6dc9f8d32532f3da163bd1f886da | Ruby | sdaubert/rasn1 | /spec/types/utc_time_spec.rb | UTF-8 | 1,814 | 2.625 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
require_relative '../spec_helper'
# rubocop:disable Metrics/BlockLength
module RASN1::Types
describe UtcTime do
describe '.type' do
it 'gets ASN.1 type' do
expect(UtcTime.type).to eq('UTCTime')
end
end
describe '#initialize' do
it 'creates a UtcTi... | true |
6b3409543b15fd2a075b5055210d1973cbd01dcb | Ruby | ichbinorange/AdaCohort14_HW | /w2ex_ride_share.rb | UTF-8 | 6,576 | 3.703125 | 4 | [] | no_license | =begin
Iterate through the data structure to display, by printing in terminal, the following info:
The number of rides each driver has given
The total amount of money each driver has made
The average rating for each driver
Which driver made the most money?
Which driver has the highest average rating... | true |
f4bca2f8398c3124fcc1e68b65abffcb980ef968 | Ruby | andyLaurito92/topologygenerator | /lib/network_entities/abstracts/path.rb | UTF-8 | 404 | 3.1875 | 3 | [
"MIT"
] | permissive | class Path
attr_reader :links, :source, :destination
def initialize(source, destination)
raise "Invalid 'source' argument received. Path must contain a source" unless source
raise "Invalid 'destination' argument received. Path must contain a destination" unless destination
@source = source
@destinati... | true |
6797a5ae1fe0bad19d04230bcd3b28b22f2bacea | Ruby | osvaldomiranda/gnatural | /app/models/event.rb | UTF-8 | 937 | 2.78125 | 3 | [] | no_license | class Event < ActiveRecord::Base
def self.day_name(date)
day = date.strftime("%A")
case day
when "Sunday"
return 'D'
when "Monday"
return 'L'
when "Tuesday"
return 'M'
when "Wednesday"
return 'M'
when "Thursday"
return 'J'
when "Friday"
return 'V'
... | true |
ebc8d2d3558cef1f1a144386cd0e7befb65cf7f0 | Ruby | GusGA/project_euler_exercises | /euler3.rb | UTF-8 | 582 | 3.921875 | 4 | [] | no_license | #What is the largest prime factor of the number 600851475143 ?
@number = ARGV.first.to_i
def divisores number
a = []
b = 1
x = 2
while b < number
if number % x == 0 && primo?(x)
a << x
b *= x
end
x += 1
end
a.max
end
def primo? number
a = 0
b = []
(1..number).each do |... | true |
3376f7d05fdbd38ef0d241b244cb4a7e4cac59b3 | Ruby | samuelefabbro/ruby-challenges2 | /1percent.rb | UTF-8 | 417 | 3.640625 | 4 | [] | no_license | money = 1500
days = 0
perc = 0.01
y_1 = 365
y_2 = 730
puts "Day n. #{days} You have €#{money.to_f}"
while days < y_2
days += 1
earning = money * perc
money = money * perc + money
puts "Day n. #{days} You have €#{money.round(2)} You've earned €#{earning.round(2)}"
end
# money = 1000
# (1..365).each do |day|
#... | true |
32e47ad743dc1e4baf09ab18a88ba3b8f979151c | Ruby | Macro80-20/ruby-object-initialize-lab-london-web-career-031119 | /lib/person.rb | UTF-8 | 340 | 3.5 | 4 | [] | no_license | class Person
attr_accessor :nameß
def initialize(name)
@name = name
end
end
# # You're going to be building a
# Person class that accepts a person's name
# when a person is
# # initialized. You're also going to be building a Dog class that accepts a dog's name and breed on
# ... | true |
a1b290d464cd686a9ac1284817b4fd0e3a4c8b6a | Ruby | gazay/norxrb | /lib/norx.rb | UTF-8 | 7,220 | 2.78125 | 3 | [
"CC0-1.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Norx
attr_reader :w, :r, :d, :t
def initialize(w = 64, r = 4, d = 1, t = 256)
@w = w
@r = r
@d = d
@t = t
raise unless valid_params?
end
def _load(x)
x.unpack(vars[:fmt]).first
end
def store(x)
if x.is_a?(Array)
x.pack(vars[:fmt])
else
[x].pack(vars[:fmt... | true |
4aed402cee974d6c19a18c2ac78d004d4cc76f51 | Ruby | gwenmorgana/The-Catbox | /ex34.rb | UTF-8 | 640 | 3.984375 | 4 | [] | no_license | # accessing elements of arrays
# Ordinal versus Cardinal numbers.
# Ordinal == ordered, 1st.
# Cardinal == cards at random, 0
animals = ['bear', 'tiger', 'penguin', 'zebra']
bear = animals[0]
animals = ['bear', 'ruby', 'peacock', 'kangaroo', 'whale', 'platypus']
# The animal at 1
e1 = animals[1]
# The third (3rd) a... | true |
7dd607e43cb581da01ed5bc9e83226fa1d7b77f5 | Ruby | PhilippePerret/WriterToolbox | /objet/analyse_build/lib/module/parser_reg/personnage/data.rb | UTF-8 | 543 | 2.53125 | 3 | [] | no_license | # encoding: UTF-8
=begin
Module principal de parsing du fichier brins
=end
class AnalyseBuild
class Film
class Personnage
attr_reader :id
attr_reader :patronyme, :prenom, :nom, :pseudo, :fonction
# Toutes les données sous forme de Hash qui doivent être enregistrées
# dans le fichier Marshal
def all_data... | true |
0169833b3bfa98e49d39c9f2ee5e17c9014812d6 | Ruby | crgc/srt-linter | /lib/srt_parser.rb | UTF-8 | 2,839 | 3.03125 | 3 | [] | no_license | require_relative 'srt_validator'
require_relative 'srt_parser_state'
class SRTParser
include SRTValidator
attr_reader :parser_state, :lines, :path, :offenses
PARSER_STATE_MACHINE = {
SRTParserState::NUMERIC_SEQUENCE => SRTParserState::TIMECODE,
SRTParserState::TIMECODE => SRTParserState::TEXT,
SRTPa... | true |
df0a840343abf955b798a9c9b4b45065aa5ac67f | Ruby | bojidarStanoev/TP | /task7.rb | UTF-8 | 632 | 3.53125 | 4 | [] | no_license | require"csv"
#Develop a program named FirstName_LastName_ClassNumber_fc52e8.rb
#1. you are given an argument that is the full path to CSV file
#1.1 if there are other arguments they should be discarded
#2. The CSV file has four columns
#3. The first row of the CSV are the headers with the following names
# C1, C2, C3,... | true |
20bbc0097228b4b91f478871bac3dd0264f30d4b | Ruby | adam-james/azure_storage_csv | /generate_csv.rb | UTF-8 | 241 | 3.046875 | 3 | [] | no_license | require 'faker'
TOTAL = 1_000_000
File.open('data.csv', 'wb') do |f|
f.write "first_name,last_name\n"
TOTAL.times do |index|
puts "#{index} of #{TOTAL}"
f.write "#{Faker::Name.first_name},#{Faker::Name.last_name}\n"
end
end
| true |
df0abbfd4acbe67996c333ed297ddd6978992b19 | Ruby | duduribeiro/rpn_calculator | /lib/calculator/interfaces/file.rb | UTF-8 | 253 | 2.671875 | 3 | [] | no_license | module Interfaces
class File < BaseInterface
def start(params)
::File.readlines(params.first).each do |line|
input = Input.new(line.chomp)
result = process_input(input)
puts "> #{result}"
end
end
end
end
| true |
50193acb772c72778eca612589d62617b635491a | Ruby | thatSignal/questions_database | /question.rb | UTF-8 | 1,407 | 2.609375 | 3 | [] | no_license | class Question < Model
def self.find_by_id(id)
result = QuestionsDatabase.instance.execute(<<-SQL, id)
SELECT
*
FROM
questions
WHERE
questions.id = ?
SQL
Question.new(result.first)
end
def self.find_by_author_id(author_id)
result = QuestionsDatabase.instance.execute... | true |
b454ffa83fcf33007e8f65129f2bdbd5b97224a6 | Ruby | 1UnboundedSentience/algos | /jan2probs.rb | UTF-8 | 1,820 | 4.28125 | 4 | [] | no_license | =begin
1. do 3, 5, 7 conditions
2. two things conditions
3. single thing conidtion
I: array of 15 booleans
O: new boolean array: at each index x, look at x-1 and and and x + 1 - perform boolean algebra on them
iterate through the array
access the values of x+1 and x-1 if they exist. Thus
=end
def fizzbuzzpop(... | true |
a259c73a85d365c53abd54abb2872620088134ab | Ruby | kstephens/rack_console | /lib/rack_console/expr_helpers.rb | UTF-8 | 1,006 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'time'
require 'date'
require 'rack_console/mock_method'
module RackConsole
module ExprHelpers
def expr_for_object! obj, mod = nil, kind = nil
@result = result_capture! do
@expr = expr_for_object obj, mod, kind
obj
end
@result_evaled = true
@result_ok = true
en... | true |
d49685d8e8fc410cf52488c6cc5b2a149ee776c5 | Ruby | Linzeur/codeable-exercises | /week-3/day-2/CarlosA/paginationhelper.rb | UTF-8 | 348 | 2.703125 | 3 | [] | no_license | class PaginationHelper
def initialization(collection, items_per_page)
@collection = collection
@items_per_page = items_per_page
end
def page_count
(@collection.length / @items_per_page).ceil
end
def item_count
@collection.length
end
def page_item_count(page_index)
end
def page... | true |
ac45224c7a885a66e2a08a65bd036a0b8090f04f | Ruby | LemonATL/dice_systems_experiment | /array.rb | UTF-8 | 439 | 3.421875 | 3 | [] | no_license | class Array
def sum
self.inject(0){|accum, i| accum + i }
end
def median
self.length.odd? ? self[self.length/2 + 1].to_f : (self[self.length/2-1] + self[self.length/2])/2.0
end
def mean
self.sum/self.length.to_f
end
def variance
m = self.mean
sum = self.inject(0){|accum, i| accum +(... | true |
581aaf10cce7b44b44e1ce61a09caef11210d657 | Ruby | coolbrg/progfun | /ruby_metaprogramming/course_day3/2.computer_info.rb | UTF-8 | 916 | 3.328125 | 3 | [] | no_license | require './1.computer_info'
class Computer
def initialize(computer_id, data_source)
@id = computer_id
@data_source = data_source
end
def mouse
info = @data_source.get_mouse_info(@id)
price = @data_source.get_mouse_price(@id)
result = "Mouse: #{info} (Rs #{price})"
return "* #{result}" if ... | true |
ce16b453e60035679068d53660a89054249ebaee | Ruby | bitgrease/IntroToProgrammingExercises | /conditionals/num_check_case.rb | UTF-8 | 667 | 4.1875 | 4 | [] | no_license | def say(str)
puts str
end
def check_num_case(num)
case num.to_i
when 0..50
say("You entered a number between 0 and 50")
when 51..100
say("You entered a number between 51 and 100")
else
say("That number is over 100!")
end
end
def check_num_if(num)
if num.to_i >= 0 && num.to_i < 51
say "Y... | true |
a87bd88ee73b2dd6b5dc3684be5365701cc47d3f | Ruby | mdvincen/tts_projects | /prime_number.rb | UTF-8 | 298 | 3.84375 | 4 | [] | no_license | require 'prime'
puts "Prime number generator"
puts "Please give me any number and I will try to determine how many prime numbers are between it and 1."
number = gets.chomp.to_i
Prime.each(number) do |prime_numbers|
puts prime_numbers
#this also works: puts Prime.take_while {|p| p <= number} t | true |
317b9a8249bdd1bc0c529c5cab384aef3cb0f31b | Ruby | ktp-forked-repos/rvr | /lib/rvr.rb | UTF-8 | 846 | 3.125 | 3 | [
"MIT"
] | permissive | require "active_model"
class Rvr
include ActiveModel::Validations
attr_accessor :regon
validates :regon, presence: true, numericality: true
validate :check_length
validate :checksum, if: :regon?
def initialize(value)
self.regon = value
end
def regon=(value)
@regon = value.to_s.delete(" ").d... | true |
cd5c140a8258952fd8cee5088dfc756f9e4df4be | Ruby | y-maltsev/RubyChess | /Game.rb | UTF-8 | 767 | 3.203125 | 3 | [] | no_license | require "./Board.rb"
require "./Renderer2D.rb"
require "./RendererCL.rb"
module Chess
class Game
def initialize
init_game_type
if @render_type == 2
@Renderer = Renderer2D.new(@rule_type)
else
@Renderer = RendererCL.new(@rule_type)
end
end
def init_game_type
... | true |
888f0898e9c80ecff5b0dd18c351bd4843ae4267 | Ruby | halil-bolat/Rspec | /rspec walkthrough/rspec_intro.rb | UTF-8 | 541 | 3.078125 | 3 | [] | no_license | require 'rspec'
#basic rspec test structure
describe 'this is the description of the product you are going to test' do
# the describe() method is to use describe a class, method or an example group
context 'context is merely another way to break out your code and description'do
it "the it block is where your ... | true |
ddd79a2d1a601ee906694596590aee4aaf24f4bd | Ruby | mwagner19446/wdi_work | /w01/d02/Quincy/methods.rb | UTF-8 | 749 | 3.359375 | 3 | [] | no_license | def drinking_age(age)
if age < 21
puts "Do you know what a beer tastes like??"
return false
else
puts "Remember to sip wine with a pinky out"
return true
end
end
drinking_age(22)
def ac_action(current, func, desire)
if func == "Yes" && current > desire
return "Turn on the A/C please"
elsif f... | true |
8f8b9fa7ca5067f80ac7d8c7a12eb9a6661b3a81 | Ruby | rbaxter11/capstone | /app/lib/game_importer.rb | UTF-8 | 1,224 | 2.78125 | 3 | [] | no_license | require "http"
class GameImporter
def self.import
response = HTTP.get("https://api.boardgameatlas.com/api/search?client_id=JLBr5npPhV")
data = response.parse
data["games"].each do |game|
# puts "name: #{game["name"]}"
new_game = Game.new(
name: game["name"],
boxart: game["ima... | true |
5eed56134c2abe061903515e3b63aba61e6bc19d | Ruby | takaxyz/atcoder | /ABC135/B.rb | UTF-8 | 120 | 3.21875 | 3 | [] | no_license | N=gets.to_i
t=0
gets.chomp.split.map(&:to_i).each_with_index do |v,i|
t += 1 if v != i+1
end
puts t<=2 ? "YES" : "NO"
| true |
2fa3babd497bf552ddbbcc2b7824a48dbce5a367 | Ruby | devgeniem/kontena-loadbalancer | /lib/kontena/cert_manager.rb | UTF-8 | 1,052 | 2.640625 | 3 | [
"Apache-2.0",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | require 'fileutils'
require 'openssl'
module Kontena
class CertManager
include Kontena::Logging
# Setup /etc/haproxy/certs from ENV
def self.boot(env = ENV)
cert_splitter = Kontena::CertSplitter.new(env)
cert_manager = new(cert_splitter.to_h)
if cert_manager.ssl_certs?
cert_ma... | true |
7f68f52d09a9a57a1bc72facacae0f2716c5d8c6 | Ruby | rodolfopeixoto/weather-challenge | /app/queries/favorite_cities_query.rb | UTF-8 | 252 | 2.53125 | 3 | [] | no_license | class FavoriteCitiesQuery
attr_reader :relation
def initialize(user_id, relation = FavoriteCity.includes(:user))
@relation = relation
@user_id = user_id
end
def search_names
relation.where(user_id: @user_id).map(&:name)
end
end
| true |
3c636fb40c151eb8ee54adf92409a4fabdb5e87f | Ruby | TaraMathur/GildedRose | /app/models/event_item.rb | UTF-8 | 384 | 2.6875 | 3 | [] | no_license | class EventItem < Item
def update_values
self.sellin = self.sellin - 1
if (self.sellin < 0)
self.quality = 0
elsif (self.sellin <= 5)
self.quality = self.quality + 3
elsif (self.sellin <= 10)
self.quality = self.quality + 2
else
self.quality = ... | true |
b428902b92b81cd0a3f38624c465ddd57e32bb40 | Ruby | Ahirini/intro_to_ruby | /examples/intro_to_ruby/pet_counter.rb | UTF-8 | 625 | 3.03125 | 3 | [
"MIT"
] | permissive | require 'erb'
class PetCounter
def initialize(data)
@data = data
end
def create_file
puts "Writing to #{self.outfile_name}"
File.open(self.outfile_name, 'w') do |f|
f.puts(
ERB.new(File.read(self.template_name)).result(binding)
)
end
end
def pet_types
@pet_types ||=... | true |
a13acdbb39257c5038f9f48500e1283a9ff32a97 | Ruby | burlesona/buttercms-ruby | /lib/buttercms/butter_resource.rb | UTF-8 | 1,273 | 2.578125 | 3 | [
"MIT"
] | permissive | module ButterCMS
class ButterResource
attr_reader :meta, :data
def initialize(json)
@json = json
@data = HashToObject.convert(json["data"])
@meta = HashToObject.convert(json["meta"]) if json["meta"]
if json["data"].is_a?(Hash)
json["data"].each do |key, value|
insta... | true |
879e63217c12a9d56c1590b67349ba8e7972efa7 | Ruby | chikamichi/marshalize | /lib/marshalize.rb | UTF-8 | 10,664 | 2.703125 | 3 | [
"WTFPL"
] | permissive | require 'activesupport'
# This module is split in several submodules for selective inclusion purpose
module Marshalization #:nodoc:
VERSION = 0.1
module Dirty #:nodoc:
private
def update_with_marshalization
if partial_updates?
# Serialized and marshalized attributes should always be writt... | true |
1c46bd8a2a1c350050f28769530ad02622ae2760 | Ruby | saikumar9/enroll | /lib/tasks/nfp.rake | UTF-8 | 1,448 | 2.53125 | 3 | [
"MIT",
"LicenseRef-scancode-warranty-disclaimer"
] | permissive | # This will upload the invoice to S3 and trigger notice
# To Run this Rake we have to pass invoice path as argument
# For Ex: RAILS_ENV=production bundle exec rake nfp:invoice_upload['/home/premshaganti/Downloads/invoices/']
namespace :nfp do
desc "Upload invoice to and associate with employer"
task :invoice_upload... | true |
be21f47d9ad1aa3a380bb808c16c7035613aa7a0 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/hamming/5f036fe6699545c18ba0f88f48c02bc3.rb | UTF-8 | 710 | 3.546875 | 4 | [] | no_license | class Hamming
def initialize ; end
def Hamming.testSingleNucleotide (c1, c2)
if c1==c2
return true
else
return false
end
end
#Calculate the Hamming distance of two DNA strands
def Hamming.compute (s1, s2)
distance = 0
@testLength = 0
#select shorter strand's length as... | true |
f2da84ffadf78e3fa63e4ba0715f2710163445d8 | Ruby | gchan/advent-of-code-ruby | /2017/day-16/day-16-part-2.rb | UTF-8 | 653 | 2.953125 | 3 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
file_path = File.expand_path("../day-16-input.txt", __FILE__)
input = File.read(file_path)
pro = ('a'..'p').to_a
visited = {}
dance = 0
until visited[pro.join]
visited[pro.join] = dance
dance += 1
input.split(",").each do |instr|
case instr[0]
when 's'
pro.rotate!(-inst... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.