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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
c5c230338935555779b99184ab577a404fb6e0b9 | Ruby | zbyhoo/project_euler | /019.rb | UTF-8 | 975 | 4.09375 | 4 | [] | no_license | #!/usr/bin/ruby
# You are given the following information, but you may prefer to do
# some research for yourself.
#
# * 1 Jan 1900 was a Monday.
# * Thirty days has September,
# April, June and November.
# All the rest have thirty-one,
# Saving February alone,
# Which has twenty-eight, rain or shine.
# And ... | true |
09418f5c9044b0d3dec25c82f3970423740638f9 | Ruby | FrMazzo/ruby_programming | /event_manager/lib/event_manager.rb | UTF-8 | 1,780 | 3.140625 | 3 | [] | no_license | require 'csv'
require 'google/apis/civicinfo_v2'
require 'erb'
require 'date'
def clean_zipcode(zipcode)
(zipcode || "").rjust(5, '0')[0..4]
end
def clean_number(number)
number = number || ""
number.gsub!(/[^0-9]/, '')
number =
if number.length == 10
"(#{number[0..2]}) #{number[3..5]}-#{number[6.... | true |
c6e8e13b320a4c3d52ae0ca1ab645d32415e8dc2 | Ruby | cloudcache/vpsadmind | /lib/console.rb | UTF-8 | 2,110 | 2.65625 | 3 | [] | no_license | require 'monitor'
require 'rubygems'
require 'eventmachine'
class VzConsole < EventMachine::Connection
attr_accessor :usage
@@consoles = {}
@@mutex = Monitor.new
def initialize(veid, listener)
@veid = veid
@listeners = [listener,]
@usage = 1
@@mutex.synchronize do
@@consoles[@veid] = ... | true |
34e68b6ca8062d0d3427150de9b1a58610e709b6 | Ruby | treicko/SistemaGeneradorDePagos | /repositorios/repositorio_empleado.rb | UTF-8 | 1,490 | 3.015625 | 3 | [] | no_license | class RepositorioEmpleado
def initialize
@empleados= Array.new
@empleados.push(Empleado.crear_empleado('111', 'Juan', 'Perez Asturias', Date.new(2014,2,1), 3000, 'Mensual', 'Salario Fijo'))
@empleados.push(Empleado.crear_empleado('222', 'Daniel', 'Mendez Machado', Date.new(2014,2,1), 50, 'Mensual', 'Salar... | true |
f26b8303ba2973ddbac81a01219c3a2ca6ad4365 | Ruby | dfhoughton/list_matcher | /lib/list_matcher.rb | UTF-8 | 22,184 | 2.859375 | 3 | [
"MIT"
] | permissive | require "list_matcher/version"
module List
class Matcher
attr_reader :atomic, :backtracking, :bound, :case_insensitive, :strip, :left_bound,
:right_bound, :word_test, :normalize_whitespace, :multiline, :name, :vet, :not_extended,
:encoding
# a special exception class for List::Matcher
class ... | true |
ecef9436bc2a0345ff4468635723f8dcf6fb70c1 | Ruby | vinniefranco/blockhead | /lib/blockhead/extractors/abstract.rb | UTF-8 | 556 | 2.6875 | 3 | [
"MIT"
] | permissive | module Blockhead
module Extractors
class Abstract
attr_writer :next
attr_reader :object
def initialize(object, arg, proc)
@object = object
@arg = arg
@proc = proc
end
def valid?
fail '#valid? not implemented'
end
def extract_value
... | true |
ec15e2f731af789a708245fa431c4fde095c655c | Ruby | samkitchen94/Skills_workshops | /roman_numerals_app/spec/roman_numberals_spec.rb | UTF-8 | 751 | 3.140625 | 3 | [] | no_license | require 'roman_numerals'
describe RomanNumerals do
describe '#converter' do
it "should produce the roman numeral for 1" do
expect(subject.converter(1)).to eq("I")
end
it "should produce roman numeral for 2" do
expect(subject.converter(2)).to eq("II")
end
it "should produce roman num... | true |
ab6e9675499e19d1271a2ce1d124979271be819f | Ruby | meganbursey/githubday1 | /ruby101/homeworkmon.rb | UTF-8 | 4,077 | 3.515625 | 4 | [] | no_license | class Employee
attr_accessor :name, :role, :location
def initialize(name, role, location)
@name, @role, @location = name, role, location
end
end
def create_employee
@current_employee = ""
puts "What is your role?"
@role = gets.chomp
puts "What is your location?"
@location = gets.... | true |
c164df2c075af0de87a3321a7da94122ea58f08d | Ruby | kuccho524/git-practice1 | /2.rb | UTF-8 | 79 | 2.578125 | 3 | [] | no_license | puts "私の名前はカビゴンです。年齢は" + 24.to_s + "歳です。" | true |
f40c2ad53796ab5792499869d84b38bc636f84ae | Ruby | foscomputerservices/dmtd_vbmapp_data | /lib/dmtd_vbmapp_data/request_helpers.rb | UTF-8 | 3,243 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'net/http'
require 'uri'
module DmtdVbmappData
class RequestHelpers
# GET an authorized message from the vbmappdata server
#
# Params:
# +end_point+:: The end point to post
# +params+:: The parameters to send to the end point (may be nil)
# +client_id+:: The client id under which to... | true |
c2fb6b938e9c8a0b7106f54cda1f668a92f49f40 | Ruby | kegan-cunningham/Chess | /human_player.rb | UTF-8 | 911 | 3.53125 | 4 | [] | no_license | class HumanPlayer
attr_reader :name
def initialize(board, display, color, name)
@board = board
@cursor = display.cursor
@stored_pos = nil
@display = display
@color = color
@name = name
end
def play_turn
loop do
handle_rendering
selected_pos = @cursor.get_input
nex... | true |
8154111c8ae2e4a149a6c48e2b6f17a4ea35d5e8 | Ruby | nobyuki/matsue_ruby_jr | /H25-04_201312/ruby_quiz/answer/02.rb | UTF-8 | 132 | 2.640625 | 3 | [] | no_license | # coding: utf-8
def run02
puts "プログラムが動いた!"
end
# 「プログラムが動いた!」と表示する
run02
| true |
8d01db4848b898647c78415dc17f1f1f327c8774 | Ruby | RobotOptimist/caeser_encrypter | /caeser.rb | UTF-8 | 812 | 3.28125 | 3 | [] | no_license | class Caeser
attr_accessor :cypher
def self.cypher_encrypt (cypher, num)
code = []
cypher = cypher.split('')
cypher.each do |i|
if i == ' ' then
code << i
next
end
n = i.ord
if n.between?(97, 122) then casing = "down" end
if n.between?(65, 90) then casing = "up" end
if n.between... | true |
dd45878b0d96b57bf6d53121d20c1586d9b63933 | Ruby | p-lambert/monitoring | /lib/monitoring/repositories/probe_repository.rb | UTF-8 | 522 | 2.671875 | 3 | [
"MIT"
] | permissive | require 'forwardable'
module Monitoring
module Repositories
class ProbeRepository
extend Forwardable
def_delegators :data, :each, :to_enum, :[]
def initialize
@data = {}
end
def add(name, probe, handlers)
check!(probe)
data[name] = [probe, *handlers]
... | true |
aae51d23a65d9111869dd60ad09e89d7a3f8f642 | Ruby | goldbergyossi/Class_Creations- | /Class Project Jan 7/character.rb | UTF-8 | 474 | 3.796875 | 4 | [] | no_license | require_relative 'item.rb'
# Character
class Character
def initialize
@stuff = []
end
# attr_accessor
# attr_reader
def addItem(item)
@stuff.push(item)
end
# TODO
# have this method print
# out each item's name
# and description
def getItems
return @stuff
end
end
hammer = Item.new("This is a strong... | true |
b24e5d18696b792cd383006286718fa6f11dbdcc | Ruby | zacharytq/ruby-advanced-class-methods-lab-online-web-sp-000 | /lib/song.rb | UTF-8 | 1,350 | 3.3125 | 3 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Song
attr_accessor :name, :artist_name
@@all = []
def self.all
@@all
end
def save
self.class.all << self
end
def self.create
song = self.new
song.save
song
end
def self.new_by_name(name)
song = self.new
song.name = name
song.save
song
end
def self.cre... | true |
44c734039d9209cd1f0758e46cee3b9e9c72af7a | Ruby | kleberkunha/FInal_Project_3_week | /lib/crypto_coin.rb | UTF-8 | 305 | 2.640625 | 3 | [] | no_license | require 'rubygems'
require 'nokogiri'
require 'open-uri'
def getting_price
page = Nokogiri::HTML(URI.open('https://coinmarketcap.com/all/views/all/'))
list = page.css('tr.cmc-table-row').map do |row|
currency = { row.children[2].text => row.children[4].text }
end
puts list
end
getting_price
| true |
6304aa50280eb9ae6fb1e5c197b8bc52da438bfd | Ruby | da99/megauni.ruby | /modules/Optional_Constants.rb | UTF-8 | 511 | 2.65625 | 3 | [
"MIT"
] | permissive |
module Optional_Constants
def extend_if_exists target, name
begin
mod = eval( name )
target.extend mod
true
rescue NameError => e
raise e unless e.messages =~ /uninitialized constant #{name}/
false
end
end
def require_if_exists path
be... | true |
50ef00fcc5d9d41a8ac8711725783327e314dd42 | Ruby | Israelistic/object_oriented_programmin | /zombieapocalypse.rb | UTF-8 | 3,133 | 3.78125 | 4 | [] | no_license | #!/usr/bin/env ruby
require "pry"
class Zombie
# class variable
@@horde = [] # contain the collection of all zombies.
@@plague_level = 10 # value will increase. used to determine the rate at which new zombies are spawned.
@@max_speed = 5#indicates the maximum value for the speed attribute of any zombie. this value won... | true |
e5b60349a8e5c2bae44d95a10b6c0db413834da1 | Ruby | Georjane/Ruby-Linters | /bin/main.rb | UTF-8 | 503 | 2.734375 | 3 | [
"MIT"
] | permissive | # A file which has a shebang line as its first line is
# granted execute permission.
# !/usr/bin/env ruby
require './lib/files.rb'
def rubocop(filename)
num = counts(filename)
if num.positive?
puts "Inspecting 1 file\n\n\nOffenses:\n\n"
get_file(filename)
puts '1 file inspected, ' + num.to_s.red + ' o... | true |
66e6b1d95b8e370d0d27303d7c735a7405b5a622 | Ruby | antoniobelmar/learn-to-program | /Chapter_14/grandfather_clock.rb | UTF-8 | 200 | 3.40625 | 3 | [] | no_license | def clock &block
if Time.new.hour>=12
(Time.new.hour-12).times do
block.call
end
else
(Time.new.hour-12).times do
block.call
end
end
end
clock do
puts "Dong!"
end
| true |
90c1904c5e7a880793856ec55b72eacf9ea45338 | Ruby | mikecm1141/world_cup | /lib/world_cup.rb | UTF-8 | 996 | 3.40625 | 3 | [] | no_license | # frozen_string_literal: true
# World Cup class
class WorldCup
attr_reader :year,
:teams
def initialize(year, teams)
@year = year
@teams = teams
end
def active_teams
@teams.select do |team|
team.eliminated? == false
end
end
def active_players_by_position(position)
... | true |
127f41db431ba7d8394150fa7aa13e53fed04c88 | Ruby | neurodynamic/stripe_store_demo | /store.rb | UTF-8 | 1,908 | 3.53125 | 4 | [] | no_license | require 'stripe'
require_relative 'stripe_config'
Stripe.api_key = $STRIPE_SECRET_TEST_KEY
# method definitions
# this is a test change
def get_card_info
card = {}
puts "Enter your credit card number:"
card[:number] = gets.chomp
puts "Enter your expiration month:"
card[:exp_month] = gets.chomp
puts "Ente... | true |
a9633c405104548c5f21c5e824ffe1a7dbf28634 | Ruby | igorstacruz/QE_training_BDT_ruby | /Fernando/Session4/Person.rb | UTF-8 | 381 | 3.609375 | 4 | [] | no_license | class Person
attr_writer :name
attr_reader :greet1
attr_writer :specialMessage
def greeting
@greet1 = "Hi #{@name}"
end
def specialMessage
"#{@name} have a nice day"
end
end
person = Person.new()
person.name = "Fernando"
person.greeting
puts person.specialMessage
puts person.greet1
... | true |
5dc8eb1ef7378397c3b5e6e403a673332d1c5025 | Ruby | neerajpn47/AOC | /day_7/day7_1.rb | UTF-8 | 1,125 | 2.953125 | 3 | [] | no_license | filename = ARGV[0].strip
wires = {}
loop do
file = File.read(filename)
file.each_line do |line|
input = line.strip.split
l = input.length
if l == 3 and input[1] == '->'
if input[0] =~ /\d+/ or wires[input[0]]
wires[input[2]] = wires[input[0]] || input[0].to_i
end
elsif l == 4 ... | true |
69c134908b537de810188ed741ff83ef2fb2ba60 | Ruby | pakejo/Practicas-PDOO-UGR | /Version Ruby/lib/sorpresa.rb | UTF-8 | 528 | 2.625 | 3 | [] | no_license | #encoding: UTF-8
# To change this license header, choose License Headers in Project Properties.
# To change this template file, choose Tools | Templates
# and open the template in the editor.
module ModeloQytetet
class Sorpresa
attr_reader :descripcion, :tipo, :valor
def initialize(descripcion,val... | true |
70bf2bbdb0945867399830ae607f36470cb97797 | Ruby | marceldegraaf/billink | /lib/billink/check.rb | UTF-8 | 1,008 | 2.59375 | 3 | [] | no_license | module Billink
class Check
include Billink::Helpers::AttributeAssignment
attr_accessor :client, :uuid, :reason
def perform
Billink.log("Performing check (company name: #{client.company_name}, kvk number: #{client.kvk_number})")
if response.success?
@result = response.description == ... | true |
2601acb4272180b8810c0b1bc5740daea5c245a4 | Ruby | shioimm/til | /ruby/books/working_with_tcp_sockets/client_lifecycle/client_block_form.rb | UTF-8 | 278 | 2.625 | 3 | [] | no_license | # 引用: Working with TCP Sockets (Jesse Storimer)
# Client Lifecycle
require 'socket'
Socket.tcp('google.com', 80) do |connection|
connection.write "GET / HTTP/1.1 \r\n" # 接続ソケットにデータを書き込む
connection.close
end
client = Socket.tcp('google.com', 80)
| true |
e38ca27cb0d8427df99240794ce5184655335a20 | Ruby | juanprq/ruby-patterns | /creation/multitone_example.rb | UTF-8 | 579 | 3.234375 | 3 | [
"MIT"
] | permissive | class Dependency
# Definition of class methods
class << self
def instances
@instances ||= {}
end
def [](name)
instances[name] ||= new(name)
end
end
# Initialization of the instance
def initialize(name)
puts "Dependency: '#{name}' created!"
end
end
# if a dependency doesn'... | true |
1a1c173cc3f4ac776b322151f206382a235b975f | Ruby | jbarnette/sploit | /test/test_sploit.rb | UTF-8 | 514 | 2.765625 | 3 | [
"MIT"
] | permissive | require 'stringio'
require 'test/unit'
require 'sploit'
class Sploit
# manual, lame-ass stub of Sploit.fetch
def self.fetch *args
return StringIO.new <<-END
$stderr.puts "\nWhat, you actually expected a working test suite?"
$stderr.puts # blank line
exit 1
END
end
end
class TestSploit ... | true |
a2a25d0afe422acd09aa21c17bbf5206a42b7525 | Ruby | alexbeeken/mr_beeken_codes_ruby_intro | /examples/episode5/methods5.rb | UTF-8 | 65 | 3.25 | 3 | [] | no_license | def add_seven(number)
return number + 7
end
puts add_seven(4)
| true |
d1c0cb1c7fc2ee2d79c41252d32cc58152b2dfe1 | Ruby | mpochwat/Recursion | /fibonacci.rb | UTF-8 | 673 | 3.828125 | 4 | [] | no_license | def fibs(num, result=[])
for i in 1..num
num = ( i == 1 || i == 2 ) ? 1 : result[-1] + result[-2]
result << num
end
result
end
def fibonacci(n)
fib_num = ( n == 1 || n == 2 ) ? 1 : fibonacci(n-1) + fibonacci(n-2)
end
def fibs_rec(num, result=[])
if num == 0
elsif num == 1
result << 1
else
result... | true |
e9ed1b90f7bb1635a0445b539e18cc5f12ed9215 | Ruby | yaoyunchen/LH_warcraft3 | /spec/test_15.rb | UTF-8 | 2,761 | 3.5 | 4 | [] | no_license | require_relative 'spec_helper'
# Introduce a SiegeEngine Unit. The SiegeEngine is very effective against buildings such as the Barracks. It is however ineffective against other units (can't attack them, as though they were dead).
# So unlike with Footman (whose attacks do a fraction of the damage they normally would)... | true |
51c20a55811077228d18be5b252e53585198e7c8 | Ruby | buty4649/atcoder | /abc296/d/main.rb | UTF-8 | 457 | 3.21875 | 3 | [] | no_license | # frozen_string_literal: true
require 'prime'
n, m = gets.split.map(&:to_i)
if n.pow(2) < m
puts '-1'
exit
end
max = n.pow(2)
(m..max).each do |x|
if x.prime?
next if x > n
puts x
exit
end
div = x.prime_division
a = div.first.first.pow(div.first.last)
if div.size == 1
next if a > ma... | true |
8d7167636deeef911e72cd09c50122d5dbcc21e6 | Ruby | netoctone/tetris | /lib/tetris/timer.rb | UTF-8 | 930 | 3.109375 | 3 | [
"MIT"
] | permissive | module Tetris
class Timer
INITIAL_FALL_PERIOD = 0.5
MOVES_PER_FALL = 9
INITIAL_MOVE_PERIOD = INITIAL_FALL_PERIOD / MOVES_PER_FALL
REDUCE_BY = 1.2
# fall_period: time between two automatic down moves
# move_period: time between two user actions
def initialize
@fall_period = INITIAL_... | true |
44cc11090ab5353c932b75eaea634db0efbbe89d | Ruby | patmaddox/21-day-challenge | /2_adventures/001/skahlert/13_day13_sort_benchmark/sort_benchmark.rb | UTF-8 | 237 | 2.96875 | 3 | [] | no_license | require 'benchmark'
a = (1..100000).map { (1..rand(120)).map{ (65 + rand(25)).chr}.join("") }
Benchmark.bm(10) do |b|
b.report("Sort") { a.sort{|a,b| a.length <=> b.length} }
b.report("Sort by") { a.sort_by { |a| a.length } }
end
| true |
ed3d94b39b3d9069d95ad2e39814e998a4ab1efd | Ruby | FlowerWrong/mblog | /categories/ruby/demo/bubble_sort.rb | UTF-8 | 452 | 3.515625 | 4 | [] | no_license | def bubble_sort_asc(arr)
1.upto(arr.length - 1) do |i|
(arr.length - i).times do |j|
if arr[j] > arr[j + 1]
arr[j], arr[j + 1] = arr[j + 1], arr[j]
end
end
end
arr
end
def bubble_sort_desc(arr)
1.upto(arr.length - 1) do |i|
(arr.length - i).times do |j|
if arr[j] > arr[j +... | true |
60596c4c06c86b2f331fa8e9a34fc814f61e5520 | Ruby | kojix2/ruby-minigraph | /lib/minigraph.rb | UTF-8 | 1,882 | 2.6875 | 3 | [
"MIT"
] | permissive | # frozen_string_literal: true
# dependencies
require "ffi"
# modules
require_relative "minigraph/version"
# Minigraph
# https://github.com/lh3/minigraph
# Li, H., Feng, X. & Chu, C. The design and construction of reference pangenome graphs
# with minigraph. Genome Biol 21, 265 (2020). https://doi.org/10.1186
module... | true |
6a2bb8a7cd54f841a8b3e0e593056b486d5afbdf | Ruby | Arbeker01/toyfinder | /lib/toy_finder/toy.rb | UTF-8 | 1,329 | 2.875 | 3 | [
"MIT"
] | permissive | class ToyFinder::Toy
attr_accessor :name, :price, :url
def self.today
self.scrape_toys
end
def self.scrape_toys
toys = []
toys << self.scrape_chewy
toys << self.scrape_agitated
toys << self.scrape_sleep_challenged
toys
end
def self.scrape_chewy
doc = Nokogiri::HTML(open("https://funandfunc... | true |
e3f164b24c775e9179b98bed17fccced93fb4288 | Ruby | ledomarques/ruby_learn_the_hard_way | /ex12.rb | UTF-8 | 352 | 3.890625 | 4 | [] | no_license | print "Give me a number: "
number = gets.chomp.to_i
bigger = number * 100
puts "A bigger number is #{bigger}."
print "Give me a another number: "
another = gets.chomp
number = another.to_f
smaller = number / 100
puts "A smaller number is #{smaller}."
print "Give some dollar: "
dollar = gets.chomp.to_f
puts "Ok, i ... | true |
66e96e0c8d2038755c068c96764db26901a0b7d4 | Ruby | jpeterson14/DrivingEligibilityCalculatorLab | /main.rb | UTF-8 | 283 | 3.75 | 4 | [] | no_license | # Write your code here
def drivingEligibilty
person = {
name: "jake",
age: 22
}
if person[:age] > 15
puts "#{person[:name]}, you can drive!"
else
years_needed_to_wait = 16 - person[:age]
puts "#{person[:name]}, you can drive after #{years_needed_to_wait} years!"
end | true |
331075d3f4dce370f787ebcbb83a19c9414b50dd | Ruby | lvl0nax/test_checkout | /spec/checkout_spec.rb | UTF-8 | 3,029 | 3.078125 | 3 | [] | no_license | require_relative '../checkout'
describe Checkout do
let(:product1) { OpenStruct.new(code: '001', name: 'Lavender heart', price: 9.25) }
let(:product2) { OpenStruct.new(code: '002', name: 'Personalised cufflinks', price: 45.00) }
let(:product3) { OpenStruct.new(code: '003', name: 'Kids T-shirt', price: 19.95) }
... | true |
eb650be579be721efde1910e5e4663e4ac8a616d | Ruby | tyne/tyne | /lib/reports/issue_type_ratio.rb | UTF-8 | 1,000 | 2.765625 | 3 | [
"MIT"
] | permissive | module Reports
# Contains logic to create a issue type ratio report
class IssueTypeRatio
def initialize(project)
@project = project
@options = { :width => 800, :height => 600, :title => 'Issue Type Ratio', :is3D => false }
end
# Returns the chart data in a google chart tools compliant for... | true |
e94b4ef8bd7b9955440da7a74560adbb29d6e69d | Ruby | Maepera/ruby | /exo_13.rb | UTF-8 | 317 | 3.40625 | 3 | [] | no_license | #Écris un programme exo_13.rb qui demande l'année de naissance d'un utilisateur,
#et qui va ressortir chaque année depuis son année de naissance jusqu'à 2018.compteur = 0
print 'Quand est-ce que tu es né?'
annee = gets.chomp.to_i
compteur = 0
while (annee < 2018)
print annee
print " "
annee += 1
end
| true |
719a9d4b15a5b4d5a007a6794e1d4984d5d94b2a | Ruby | michaelcheny/Real-Life-RPG-Rails-Project | /app/helpers/skills_helper.rb | UTF-8 | 1,322 | 2.796875 | 3 | [
"MIT"
] | permissive | module SkillsHelper
# Iterate over user's skills, matche with the quest skills, and trains the correct skill
def update_user_skill_quest(user, user_quest, points)
quest = Quest.find_by(id: user_quest.quest_id)
user.user_skills.each do |user_skill|
quest.skills.each do |quest_skill|
if quest_... | true |
6fbec8f01fe818622d9bc7b0b2e365714b99dcbf | Ruby | VincenzoAltieri/LS_101 | /lesson_3/medium8.rb | UTF-8 | 931 | 4.4375 | 4 | [] | no_license | # medium8.rb
Question 8
One day Spot was playing with the Munster familys home computer and he wrote a small program to mess with their demographic data:
munsters = {
"Herman" => { "age" => 32, "gender" => "male" },
"Lily" => { "age" => 30, "gender" => "female" },
"Grandpa" => { "age" => 402, "gender" => "male... | true |
bcfc54eb7cfba514cbb095a868129cfd9194ef06 | Ruby | claudiahalip/test-cli | /lib/test/cli/character_class.rb | UTF-8 | 589 | 3.15625 | 3 | [
"MIT"
] | permissive | class Character
attr_accessor :id, :name, :occupation, :nickname , :actor
@@all = []
def initialize (hash)
@id = hash["char_id"]
@name = hash["name"]
@occupation = hash["occupation"]
@nickname = hash["nickname"]
@actor = hash["portrayed"]
@@all << self
end
... | true |
5c18b764afdbc031f6261f0cf455b73a94a7e3d4 | Ruby | matt-wallis/photo-utils | /photo_index/lib/photo_index/photo/metadata.rb | UTF-8 | 700 | 2.53125 | 3 | [] | no_license | require 'time'
# There are various tests that can be done on image files:
module PhotoIndex
module MetaData
class FileStat
attr_reader :atime, :ctime, :mtime
def initialize(atime, ctime,mtime)
@atime = atime
@ctime = ctime
@mtime = mtime
end
def to_xml(xml)
xml.atime(atime.to_s)
xm... | true |
2e6a89675cbd9f928cbd18fc1b68a60a4f7f78d1 | Ruby | neogenia-jp/neo-reminder | /backend-svc/src/ruby_backend_svc/src/kamada/clear_api.rb | UTF-8 | 1,235 | 2.640625 | 3 | [
"MIT"
] | permissive | require_relative './base_api'
module Kamada
class ClearApi < BaseApi
# 実行
# @param json_data [Hash] 送られてきたJSONデータ
# @return [Hash]
def run(json_data)
options = json_data['options']
case options['target']
when 'all'
clear_all
when 'finished'
clear_finis... | true |
9f711d44547cd303a9742f4cb5d5dfeea14533c4 | Ruby | sangiraldo/BootcampWeb | /Ruby/Clase_27_Junio/Zapateria.rb | UTF-8 | 475 | 3.140625 | 3 | [] | no_license | print "Digite la Cedula del cliente: "
cedula = gets.chomp
print "Valor de la compra: "
valor_Compra = gets.chomp
valor_Compra = valor_Compra.to_f
ultimo_Digito = cedula[cedula.length-1]
ultimo_Digito = ultimo_Digito.to_i
case ultimo_Digito
when 1..3 then
valor_Total = valor_Compra * 0.85
when 4..6 then
valor_Tot... | true |
1fce48b0a02ae7afc22bcea755e5e431e280b9e7 | Ruby | GuillaumeOcculy/mobile-doccasion | /app/helpers/application_helper.rb | UTF-8 | 402 | 3.046875 | 3 | [] | no_license | module ApplicationHelper
def print_amount(amount)
if amount.to_f == amount.round(0)
format("%d€", amount)
else
format("%.2f€", amount)
end
end
def print_boolean(value)
if value
'Oui'
else
'Non'
end
end
def print_state(value)
case value
when 0
'Mauvais'
when 1
'Moyen'
w... | true |
45d1f8db095fa64ad5fc590f3fade83fd6071ea6 | Ruby | neddy/Launch-School | /Exercises/Ruby-JavaScript_Challenges/Ruby/Easy/ex_1/triangles.rb | UTF-8 | 595 | 3.96875 | 4 | [] | no_license | require 'pry'
class Triangle
def initialize(*sides)
raise ArgumentError unless check(sides)
@sides = sides
end
def kind
if @sides.all? { |side| side == @sides[0] }
"equilateral"
elsif @sides.combination(2).any? { |side_a, side_b| side_a == side_b }
"isosceles"
else
"scalene... | true |
46a87ac51651185a998766c63d8b91711169c0b8 | Ruby | Tyagelsky/facemash | /lib/photoselector.rb | UTF-8 | 420 | 2.875 | 3 | [] | no_license | class Photoselector
def initialize(photo_winner, photo_looser)
@photo_winner = photo_winner
@photo_looser = photo_looser
end
def perform
result = Ratechanger.new(winner: @photo_winner.rating,
looser: @photo_looser.rating)
@photo_winner.update(rating: result.calculat... | true |
f23e9e87c436a2bed39fe0793570f946c6922731 | Ruby | prayjourney/RubyStudy | /TheHardWay/ext15.rb | UTF-8 | 405 | 3.921875 | 4 | [] | no_license | # ARGV 获取传入的参数
filename = ARGV.first
# 赋值变量`prompt`
prompt = "> "
# 获取文件名并传值给txt
txt = File.open(filename)
# 输出一段字元以及文件名
puts "Here's your file: #{filename}"
# 读取文件内容并输出
puts txt.read()
puts "Type the filename again: "
print prompt
file_again = STDIN.gets.chomp()
txt_again = File.open(file_again)
puts txt_again.re... | true |
5e2fd9ac089e169879817ff8ca49a0193d19f4f9 | Ruby | andrerferrer/phone_invoices | /app/models/phone_call.rb | UTF-8 | 629 | 2.734375 | 3 | [] | no_license | # frozen_string_literal: true
class PhoneCall < ApplicationRecord
before_save :set_call_price
ATTRIBUTES = %i[
called
caller
start_at
end_at
call_price_cents
].freeze
private
def set_call_price
return self.call_price_cents = 0 if start_at.nil?
# Tarifa reduzida (0:00 - 5:59) :... | true |
ecad996ff9a7144303fd8783158036a3dedbf755 | Ruby | micktaiwan/rel | /main.rb | UTF-8 | 1,376 | 3.296875 | 3 | [] | no_license | # DONE: A+B : if A or B is not defined => crashes
# TODO: last = last result
#require '../MLib/TextPrompt'
require 'mrel'
class App #< TextPrompt
def initialize
@rel = MRel.new
end
def start
puts 'Rel V0.1 - "h" helps'
while true
print '>'
c = gets.chomp
... | true |
b46883d1bb355a0f042c0f5df37fd796ff23d9df | Ruby | codedixon/programming-univbasics-4-array-concept-review-lab-atlanta-web-010620 | /lib/array_methods.rb | UTF-8 | 523 | 3.625 | 4 | [
"LicenseRef-scancode-public-domain",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | def find_element_index(array, value_to_find)
# Add your solution here
array.index(value_to_find)
end
def find_max_value(array)
# Add your solution here
counter = 0
max = 0
while counter < array.length()
if max <= array[counter]
max = array[counter]
end
counter += 1
end
return max
end
def find... | true |
dda02edebbf0774cbd168434a591f5cb1226a8ee | Ruby | tomclyde/day_01_lab | /student_class.rb | UTF-8 | 523 | 3.390625 | 3 | [] | no_license | class Student
def initialize(student_name, cohort_name)
@student_name = student_name
@cohort_name = cohort_name
end
def student_name
return @student_name
end
def cohort_name
return @cohort_name
end
def set_student_name(name)
@student_name = name
end
def set_cohort_name(name)... | true |
81e865b8eb4e342f48f3ddcfe984461cf08d497b | Ruby | jywei/connect-four | /lib/connect_four/computer.rb | UTF-8 | 227 | 2.5625 | 3 | [] | no_license | class Computer < Player
def prompt_column(_grid)
puts "#{name}'s move!"
sleep 1
rand(0..6)
end
def winning_message
puts "#{name} with '#{symbol}' RULES! 💀💀💀💀💀 Try again? (y/n)"
end
end
| true |
79e0929076980b9074698df6e1f16cdce7cd0b83 | Ruby | danpariente/socialization | /lib/socialization/likeable.rb | UTF-8 | 651 | 2.71875 | 3 | [
"MIT"
] | permissive | module Socialization
module Likeable
def self.included(base)
base.class_eval do
# A liking is the Like record of the liker liking self.
has_many :likings, :as => :likeable, :dependent => :destroy, :class_name => 'Like'
def is_likeable?
true
end
def liked_b... | true |
ef59eff7de505be3a4c9f0ab638bed51a9925d2d | Ruby | eriksk/kawaii | /lib/kawaii/command.rb | UTF-8 | 1,653 | 2.9375 | 3 | [
"MIT"
] | permissive | class String
# colorization
def colorize(text, color_code)
"\e[#{color_code}m#{text}\e[0m"
end
def red
colorize(self, 31)
end
def green
colorize(self, 32)
end
def yellow
colorize(self, 33)
end
def pink
colorize(self, 35)
end
end
module Kawaii
class Command
def self.run command, args
puts "... | true |
dee052e2f2ed6dde36a77c019c4dde5d130fa81e | Ruby | enricob/timesheets | /app/helpers/timesheets_helper.rb | UTF-8 | 260 | 2.53125 | 3 | [] | no_license | module TimesheetsHelper
def date_path(date)
"#{date.year}/#{date.month}/#{date.day}"
end
def this_week
Date.today.beginning_of_week
end
def week_array(date)
start = date.beginning_of_week
(start...start + 7.days).to_a
end
end
| true |
8911790ae573117fe6b5746f60e911b345ede0d7 | Ruby | Rddiazolivos/marvelRails | /app/models/battle.rb | UTF-8 | 994 | 2.671875 | 3 | [] | no_license | class Battle < ApplicationRecord
belongs_to :user
belongs_to :character
def self.resultado
random_boolean = [true, false].sample
end
def self.getCharacterBattle
personaje = Battle.where(created_at: Time.zone.now.beginning_of_day..Time.zone.now.end_of_day).last
if personaje.nil?
code = Character.f... | true |
c8401f6187ab017baa1e5991b0bfa606a109d7a6 | Ruby | henryaddison/text_linear | /spec/text_linear/string_tokeniser_spec.rb | UTF-8 | 620 | 2.625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"MIT"
] | permissive | require 'spec_helper'
describe TextLinear::StringTokeniser do
let(:tokeniser) { TextLinear::StringTokeniser }
describe '.tokenise' do
it 'should split a sentence into words' do
sentence = "how now brown cow"
tokeniser.tokenise(sentence).should == %w{how now brown cow}
end
it 'should make a... | true |
53f2039eef1e8d15b995d43303feec8f8dc00754 | Ruby | mintona/enigma | /test/key_test.rb | UTF-8 | 912 | 2.984375 | 3 | [] | no_license | require './test/test_helper'
require_relative '../lib/key'
class KeyTest < Minitest::Test
def test_it_exists
key = Key.new
assert_instance_of Key, key
end
def test_it_can_generate_random_five_digit_number_as_a_string
number_1 = Key.generate_number
assert_equal 5, number_1.length
number_2 =... | true |
c4b7b5fb5cdc562001f4ab08678b1abd81614597 | Ruby | samnang/rubylearning | /core/week5/ex2.rb | UTF-8 | 735 | 3.59375 | 4 | [] | no_license | class Shape
def click
rotate_360
play_sound
end
def rotate_360
raise "Must override on sub classes."
end
def play_sound
puts "Play sound: " + sound_file
end
def sound_file
"default file"
end
end
class Square < Shape
def rotate_360
puts "rotating square 360"
end
def sou... | true |
fbe2b5bd9a01f9a8792bf10832277438b6ec6b9a | Ruby | kaitlynfox/backend_mod_1_prework | /section3/exercises/ex4.rb | UTF-8 | 234 | 3.296875 | 3 | [] | no_license | produce = {
"apples" => 3,
"oranges" => 1,
"carrots" => 12
}
puts "There are #{produce["oranges"]} oranges in the fridge."
produce["grapes"] = 221
produce["oranges"] = 6
puts produce.keys
puts "-" * 20
puts produce.values
| true |
e6e3ce20687f398287d90c11a38ad005a37aa0fa | Ruby | Sidneyyy/kwk-l1-classes-and-instances-lab-ruby-kwk-students-l1-bos-070918 | /lib/dog.rb | UTF-8 | 283 | 3.5625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | # dog.rb
class Dog
attr_accessor :name , :breed
end
fido = Dog.new
snoopy = Dog.new
lassie = Dog.new
puts fido.name = "Fido"
puts fido.breed = "Husky"
puts snoopy.name = "Snoopy"
puts snoopy.breed = "Labrador"
puts lassie.name = "Lassie"
puts lassie.breed = "Border Collie" | true |
8e66b3e00a3c39ee8e95c8eb96655e4279f7b786 | Ruby | tahirror/vector-testing | /equilibrium_index_of_array.rb | UTF-8 | 567 | 3.703125 | 4 | [] | no_license | =begin
Equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes.
For example, in an arrya A:
A[]=[-7,1,5,2,-4,3,0]
3 is an equilibrium index, because:
A[0] + A[1] + A[2] = A[4] + A[5] + A[6]
Time-complexity: O(n)
Auxiliary-space: O(1)
=en... | true |
4cffdaf38b44a624a0e72b503dcde680eed0f828 | Ruby | jdcarey128/robot-game-api | /spec/requests/users_spec.rb | UTF-8 | 862 | 2.59375 | 3 | [] | no_license | require 'rails_helper'
describe 'Users API', type: :request do
before :each do
@user1, @user2, @user3 = create_list(:user, 3)
end
after :each do
User.destroy_all
end
it 'returns users' do
get '/users'
expect(response).to have_http_status(:success)
result = JSON.parse(response.body... | true |
97b03ff6b980788c1303336db3469772edc0159b | Ruby | Pistash/square_array-001-prework-web | /square_array.rb | UTF-8 | 103 | 3.140625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def square_array(array)
squares = []
array.each do |x|
x= x ** 2
squares << x
end
squares
end | true |
c3c64fa64a5dc1b509a396f187c82c609136c779 | Ruby | esunwookim619/aa-practice-test-generator | /specs/my_flatten_spec.rb | UTF-8 | 1,007 | 3.46875 | 3 | [] | no_license | describe "Array#my_flatten" do
let(:arr) { [1, 2, 3, [4, [5, 6]], [[[7]], 8]] }
before(:each) do
expect(arr).not_to receive(:flatten)
expect(arr).not_to receive(:flatten!)
end
it 'flattens arrays correctly' do
expect(arr.my_flatten).to eq([1, 2, 3, 4, 5, 6, 7, 8])
end
it 'works on one dimen... | true |
95c005400e9a230915f75859ed2bc2e36e057f1e | Ruby | kh45/oo-relationships-practice-dc-web-091619 | /app/models/codecamp.rb | UTF-8 | 336 | 2.65625 | 3 | [] | no_license | class Code_Camp
attr_accessor :name, :developers, :projects
@@all = []
def initialize(name, developer, projects)
@name = name
@developers = developer
@projects = projects
@@all << self
end
def self.all
@@all
end
def developers
end
def proj... | true |
169e6185ea902d41e2d138ec496e599ded3be0b3 | Ruby | zooootech/furima-31168 | /spec/models/item_spec.rb | UTF-8 | 3,931 | 2.71875 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Item, type: :model do
before do
@item = FactoryBot.build(:item)
end
describe '商品出品機能' do
context '商品の出品がうまくいくとき' do
it 'image、name、price、text、category_id、condition_id、shipping_chage_id、prefecture_id、days_to_ship_idが存在すれば出品できる' do
expect(@item).to be_va... | true |
894f79e485d223361ebf4e14bb8edfacaf955b5d | Ruby | pa-childs/Udemy_Courses | /learn_to_code-ruby/Section_03/the_step_method.rb | UTF-8 | 257 | 4.03125 | 4 | [] | no_license | # Used to increment through loops at values higher than 1
puts "Counting by five"
5.step(100, 5) do |current_count|
puts "Count is at: #{current_count}"
end
# Single line syntax
# 5.step(100, 5) { |current_count| puts "Count is at: #{current_count}"}
| true |
7d53966b8e1005f3c3278dff45fa684d27bab2d6 | Ruby | aptituz/puppler | /lib/puppler/git/refs.rb | UTF-8 | 3,816 | 3.265625 | 3 | [
"MIT"
] | permissive | module Puppler
class Git
# representation of a set of refs in a git-bundle or git repository
#
# provides access to the list of tags and branches, allows resolving ref names to commits
# and allows diffing to ref sets
class Refs
def initialize(ref_lines)
@refs = parse(ref_lines)
... | true |
a0e8cfa99b7579cd6ddb8c6d5b19b696cfaf4334 | Ruby | CentralMarin/central-marin-soccer | /spec/models/coach_spec.rb | UTF-8 | 2,699 | 2.6875 | 3 | [] | no_license | # == Schema Information
#
# Table name: coaches
#
# id :integer not null, primary key
# name :string(255)
# email :string(255)
# bio :text
# created_at :datetime not null
# updated_at :datetime not null
#
require 'rails_helper'
describe Coach do
it "has a val... | true |
eb220256bda16cd7deab9b75a3524a69e82e26bd | Ruby | minifast/chemtrail | /lib/chemtrail/cli.rb | UTF-8 | 1,798 | 2.625 | 3 | [
"MIT"
] | permissive | require "thor"
require "json"
require "chemtrail"
require "aws-sdk-core"
class Chemtrail::Cli < Thor
attr_writer :cloud_formation
default_task :list
desc "list", "Lists all available templates"
method_option :path, :default => File.expand_path("lib/templates")
def list
require_templates_from(options[:p... | true |
1a52b6258675bdfefccb9bc3146805b1c13628c8 | Ruby | aonoloki/rubyProject | /realCal.rb | UTF-8 | 367 | 3.890625 | 4 | [] | no_license | class Calcul
attr_accessor :value1, :value2
def initialize(value1, value2)
@value1 = value1
@value2 = value2
end
def add
puts @value1 + @value2
end
def subs
puts @value1 - @value2
end
end
c = Calcul.new(27, 13)
puts c.inspect
puts "Is the a1ddtion off these numbers #{ c.add }."
puts "I... | true |
03dc02dac2fa46fad188fef6a9d4f67f086f379f | Ruby | TetianaFilonenko/v_machine | /console_app.rb | UTF-8 | 623 | 2.875 | 3 | [] | no_license | require "./vending_machine.rb"
require "./vending_machine_process.rb"
products = {
"food1" => { "name" => "mars", "price" => 2.5, "count" => 2 },
"food2" => { "name" => "waffles", "price" => 1.5, "count" => 2 },
"drink1" => { "name" => "water", "price" => 1, "count" => 1 },
"non_food1" => { "name" => "... | true |
05b83fde8a8d7e59f0ca63f18e09c51c6e124b89 | Ruby | sebalugo/class02 | /team_spec.rb | UTF-8 | 4,730 | 3.390625 | 3 | [] | no_license | require_relative './player.rb'
require 'spec_helper.rb'
class PlayerError < RuntimeError
end
class Team
attr_accessor :team_name, :team
def initialize(team_name)
@team_name = team_name
@team = []
end
def add_player(name, position)
element = name + ' ' + position
team.each{|player|
if ... | true |
b145500f2f2ff1b8095b38adad26a36a52b55113 | Ruby | ccahill1117/mazerunner | /lib/room.rb | UTF-8 | 1,923 | 3.0625 | 3 | [] | no_license | class Game
attr_accessor(:game_difficulty, :levels, :current_location, :current_room, :current_level, :current_distance :has_key)
def initialize(game_difficulty)
@current_level = 0
@current_room = 0
@current_distance = 0
@has_key = false
@levels = []
@game_difficulty = game_difficulty
@... | true |
27eb437092e57da6b43a3ff342c168df3eec06c8 | Ruby | mmrobins/project-euler-solutions | /004_palindrome.rb | UTF-8 | 246 | 3.8125 | 4 | [] | no_license | class Integer
def is_palindrome?
self.to_s == self.to_s.reverse
end
end
nums = []
999.downto(900) do |n|
999.downto(900) do |m|
nums << m * n
end
end
nums = nums.sort.reverse
nums.each do |n|
break n if n.is_palindrome?
end
| true |
c42a0036967f0fd7661ebb720001562ae58b8dad | Ruby | neilljordan/gdata-ruby | /lib/gdata/spreadsheet.rb | UTF-8 | 1,997 | 2.515625 | 3 | [
"MIT"
] | permissive | require File.dirname(__FILE__)+'/base'
module GData
class Spreadsheet < GData::Base
attr_accessor :worksheet_id
def initialize(spreadsheet_id)
@spreadsheet_id = spreadsheet_id
@worksheet_id = 1
super 'wise', 'gdata-ruby', 'spreadsheets.google.com'
end
def evaluate_cell(cell)
... | true |
d251c7a0c5cca7c25e6d691f650700fe2f9fc655 | Ruby | MargoSolo/stared-repos-p2 | /AppAcademy/Curriculum/12 Career Quest/W24D4 Pair Boarding Continued/10B.rb | UTF-8 | 2,224 | 4.28125 | 4 | [] | no_license | # max_unique_psub
# Given a string, find the lexicographically greatest pseudo-substring.
# Example (read on for further explanation):
# max_unique_psub('abcdef')
# => 'f'
# max_unique_psub('abcdefedcba')
# => 'fedcba'
# max_unique_psub('algorithms')
# => 'ts'
# Let's define a pseudo-substring: psub is any subset t... | true |
93091ddb0f09735b11d8d82205729d93cc97f8fd | Ruby | brettrann/learning_with_robot | /lib/robot_simulator.rb | UTF-8 | 888 | 3.171875 | 3 | [
"MIT"
] | permissive | require "robot_simulator/version"
require 'robot'
require 'table'
require 'controller'
require 'command'
require 'command/turn_robot_left'
require 'command/turn_robot_right'
require 'command/place_robot'
require 'command/move_robot'
require 'command/report'
require 'command/help'
class RobotSimulator
def initialize... | true |
92a0d026e419bf7f898917d81abc2bc1dc7f1874 | Ruby | tetetratra/contest | /abc048/a/a.rb | UTF-8 | 62 | 2.953125 | 3 | [] | no_license | puts gets.chomp.split.map{|s|s[0]}.map(&:capitalize).join('')
| true |
d4cd87eae82dd98194d41aa775e61a93579b8d5a | Ruby | plagelao/PlageServer | /server/request_line_parser.rb | UTF-8 | 1,333 | 3.171875 | 3 | [] | no_license | require 'server/application_parser'
require 'URI'
class RequestLineParser
METHODS = ['GET']
HTTP_1_1 = "HTTP/1.1"
def initialize(options = {:application_parser => ApplicationParser.new})
@application_parser = options[:application_parser]
end
def parse(request_string)
@words = request_line_from(requ... | true |
269c7242eb476e148d68ecf7bb8307031e32f645 | Ruby | cedretaber/codes_for_atcoder | /other/fuka/5/b.rb | UTF-8 | 157 | 3.125 | 3 | [] | no_license | require "time"
loop do
t = gets.chomp
break if t == "0"
t = Time.parse t
s = gets.chomp.to_i(2)
t += s
puts t.strftime "%Y/%m/%d %H:%M:%S"
end
| true |
e89b81eaa2844fe9befccea8c18ce2bb735f3cd7 | Ruby | githubhjs/mushplatform | /lib/util/file_util.rb | UTF-8 | 560 | 2.625 | 3 | [] | no_license | require 'fileutils'
module FileUtil
class << self
def cp_r(form_path,to_path)
Dir.glob("#{form_path}/*") do |f_path|
if File.directory?(f_path)
cp_r(f_path,"#{to_path}/#{File.basename(f_path)}") if File.stat(f_path).readable?
elsif File.file?(f_path) && File.readable?(f_path)
... | true |
fa6d9bde340d0ae850f053dbd5bdf5e701c48702 | Ruby | kpastorczyk/interview-test | /Holiday.rb | UTF-8 | 631 | 2.828125 | 3 | [] | no_license | # == Schema Information
#
# Table name: holidays
#
# id :bigint(8) not null, primary key
# day :date
# kind :integer default("custom")
# created_at :datetime not null
# updated_at :datetime not null
#
class Holiday < ApplicationRecord
extend Enumerize
vali... | true |
2ac17c7adce9819e2e80a2bc05d8c2ea117e1097 | Ruby | msosland/phase-0 | /week-8/ruby/ruby-review.rb | UTF-8 | 4,363 | 4.4375 | 4 | [
"MIT"
] | permissive | # I worked on this challenge by myself
# This challenge took me
# is_fibonacci? 15 minutes
# super_fizzbuzz 15 minutes
# numbers to english 15 minutes
# reverse_words 30 minutes
# # Pseudocode for is_fibonacci?
# SET array equal to the first 3 numbers of the fibonacci sequence.
# WHILE the last element in the... | true |
89e803163fa9333a6bede5babdf2216e8d2767b9 | Ruby | dcoleman21/sweater-weather-api | /app/poros/image.rb | UTF-8 | 419 | 2.890625 | 3 | [] | no_license | class Image
attr_reader :image
def initialize(data, location)
@image = image_hash(data, location)
end
def image_hash(data, location)
{
location: location,
image_url: data[:photos][0][:src][:original],
credit: credit_hash(data)
}
end
def credit_hash(data)
{
source: ... | true |
4e21c1c7ad7fccfbca25551ea3f3b5fd019bbbea | Ruby | syon/utils | /edit-many-files/main.rb | UTF-8 | 401 | 2.703125 | 3 | [] | no_license | #
# Append front-matter text on all markdown files
#
files = []
Dir::glob("src/md/*.md").each do |path, idx|
buf = File.open path
files << buf
end
files.each do |file|
id = File.basename(file, ".md")
buf = file.read
fm = <<-"EOS"
---
slug: #{id}
title: #{id}
layout: page.jade
---
EOS
path = "src/md/... | true |
b9ff496e39b1b04e182e1ddd0c2bfbf1e0461c03 | Ruby | roryscot/Project-Euler | /Project Euler/Euler10.rb | UTF-8 | 422 | 3.96875 | 4 | [] | no_license | #Sum of Primes
def sum_of_primes(n)
sum = 0
div = (2...n).to_a
primes = []
i = 2
until i >= n/i
div.delete_if {|x| x % i == 0 }
i += 1
end
for p in 2 ... div[0] ; primes << p if prime?(p) ; end
primes += div
primes.each {|s| sum = s + sum }
sum
end #sum_of_primes(n)
def prime?(num)
for i in ... | true |
ddc3f0ce35565b629e9969047b3dd0ff141bf142 | Ruby | Elliot11/cards | /spec/hand_analyzer_spec.rb | UTF-8 | 4,945 | 3.203125 | 3 | [] | no_license | require 'handanalyzer'
RSpec.describe HandAnalyzer do
before :each do
board = [Card.new("2", "Spades"), Card.new("3", "Hearts"), Card.new("7", "Spades"), Card.new("A", "Hearts"), Card.new("9", "Spades")]
hand = [Card.new("10", "Spades"), Card.new("9", "Hearts") ]
@one_pair = board, hand
hand = [C... | true |
6c729c287f53e049aa232908d4c921a519b7af6c | Ruby | monkeywidget/argotifier | /bin/document | UTF-8 | 2,102 | 2.953125 | 3 | [] | no_license | #!/usr/bin/ruby
# 1.9 adds realpath to resolve symlinks; 1.8 doesn't
# have this method, so we add it so we get resolved symlinks
# and compatibility
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/../app/models')
$: << File.expand_path(File.dirname(File.realpath(__FILE__)) + '/lib')
# require 'rubyge... | true |
929b82de7c4ea1946b340461ebe0d2a051e232c7 | Ruby | jsanchy/launch-school-exercises | /small_problems_ruby/advanced1/rotating_matrices.rb | UTF-8 | 1,801 | 3.953125 | 4 | [] | no_license | def rotate90(matrix)
transpose(matrix).map!(&:reverse)
end
def transpose(matrix)
number_of_rows = matrix.size
number_of_columns = matrix[0].size
matrix_transpose = []
number_of_columns.times do
matrix_transpose << []
end
number_of_columns.times do |col|
number_of_rows.times do |ro... | true |
2a901c68cc89cd11e652efcedeabeee17cf79a43 | Ruby | madx/mdwn.in | /spec/mdwnin/keygen_spec.rb | UTF-8 | 754 | 2.5625 | 3 | [
"MIT"
] | permissive | # encoding: utf-8
require 'spec_helper'
require 'mdwnin/keygen'
describe Mdwnin::Keygen do
subject { Mdwnin::Keygen }
let(:time) { Time.at(42) }
describe ".generate" do
it "returns a non empty string" do
subject.generate.wont_be_empty
end
it "is comprised of lowercase letters, numbers, and ... | true |
bed878b8054586e9400f5c8cf308896e65bf0721 | Ruby | astrails/debitcredit | /app/models/debitcredit/entry/dsl.rb | UTF-8 | 814 | 2.65625 | 3 | [
"MIT"
] | permissive | class Debitcredit::Entry::Dsl
attr_accessor :entry
attr_accessor :accounts
def initialize(entry)
@entry = entry
end
def kind(kind)
@entry.kind = kind
end
def description(desc)
@entry.description = desc
end
alias desc description
def reference(ref)
@entry.reference = ref
end
a... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.