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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
c369772539c9291cbc9a4fe5b5eccb3822ad0a44 | Ruby | imclab/pinboard-cli | /bin/pinboard | UTF-8 | 3,951 | 2.921875 | 3 | [] | no_license | #!/usr/bin/env ruby
# encoding: utf-8
require 'time'
require 'json'
require 'ostruct'
require 'optparse'
require 'pinboard'
CACHE_FILE = File.expand_path("~/.pinboard-cache.json")
TOKEN_FILE = File.expand_path("~/.pinboard-token")
Color = OpenStruct.new
if $stdout.tty?
COLORS = {
clear: "\033[0m",
red: ... | true |
b1be6eb6327f1ade6d11f29c80a593e315cd37d1 | Ruby | TimCPB/cautious-octo-guide | /spec/greed_is_good_spec.rb | UTF-8 | 1,129 | 3.453125 | 3 | [
"MIT"
] | permissive | # require '../src/greed_is_good.rb'
# describe "Score" do
# it "returns 100 for a single roll of 1" do
# expect(score([1])).to eq(100)
# end
# it "returns 50 for a single roll of 5" do
# expect(score([5])).to eq(50)
# end
# it "returns the correct score for the different triples"... | true |
ada564c0583908985c1d0fe3ea42493db087a605 | Ruby | TazzyG/gosu_friendlyroad | /spec/vector_spec.rb | UTF-8 | 505 | 2.890625 | 3 | [] | no_license | require_relative '../vector'
RSpec.describe Vec do
it 'can set itself' do
v1 = Vec[1,2]
v2 = Vec[3,4]
v1.set!(v2)
expect(v1).to eq(v2)
expect(v1).not_to be(v2)
end
it 'does scalar multiplication' do
expect(5 * Vec[1,2]).to eq(Vec[5,10])
end
it 'does vector addition' do
expect(Vec[1,2] + Vec[3,4]).... | true |
b7aad421839f21cfd51bf9f05839f329e77bc310 | Ruby | HassanAkbar/i_m_freezing | /spec/models/reading_spec.rb | UTF-8 | 2,486 | 2.515625 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Reading, type: :model do
describe "#update_thermostat_stats" do
let(:thermostat_stats) {
{ total_readings: 2, temperature_max: 30,
temperature_min: 10, temperature_avg: 20,
humidity_max: 100, humidity_min: 0,
humidity_avg: 50, b... | true |
fd709641d93a133a0d59dcddf853cc0506cf290a | Ruby | devopsdc/presentations | /vendor/bundle/ruby/2.1.0/gems/gli-1.6.0/lib/support/initconfig.rb | UTF-8 | 1,250 | 2.609375 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"Apache-2.0"
] | permissive | require 'gli'
require 'gli/command'
require 'yaml'
module GLI
class InitConfig < Command # :nodoc:
COMMANDS_KEY = 'commands'
def initialize(config_file_name)
@filename = config_file_name
super(:initconfig,"Initialize the config file using current global options",nil,'Initializes a configuration ... | true |
ca7482a3c77213d687ef43a0fd00dc5dacb96989 | Ruby | mwagner19446/wdi_work | /w01/d05/John/rental.rb | UTF-8 | 5,970 | 3.6875 | 4 | [] | no_license | def menu(building)
puts "Please select an option:"
puts "{b} Building details"
puts "{a} Add an apartment to the building"
puts "{t} Add a tenant"
puts "{r} Remove a tenant"
puts "{v} View apartment directory"
puts "{q} Quit"
choice = gets.chomp
case choice
when 'b'
building_details(building)
... | true |
1cdd354c052a6653d98c85984864872e9418d4b7 | Ruby | AndriyMiha/testREP | /Automat_training/PageObject_advanced_example.rb | UTF-8 | 1,988 | 2.859375 | 3 | [] | no_license | require 'selenium-webdriver'
require 'rspec-expectations'
def setup
Selenium::WebDriver::Chrome.driver_path = File.join(File.absolute_path('', File.dirname("C://Projects/chromedriver")),"chromedriver","chromedriver.exe")
@driver = Selenium::WebDriver.for :chrome
ENV['base_url'] = 'http://www.google.com'
e... | true |
8352e98d63210ac7139c631279dc3784d27a5cde | Ruby | has256/challenges | /uri/ruby/2963.rb | UTF-8 | 277 | 3.234375 | 3 | [
"Unlicense",
"CC-BY-3.0"
] | permissive | bobos = gets.chomp.to_i
carlos = gets.chomp.to_i
bobos -= 1
eleito = 'S'
mais_votado = ''
bobos.times do
bobo = gets.chomp.to_i
if bobo > carlos
eleito = 'N'
mais_votado = 'outro'
end
eleito = 'S' unless mais_votado == 'outro'
end
puts eleito
| true |
9bae1ab27e4f40237f59622dae67d2209a9b7024 | Ruby | hyperoslo/grumbles-the-lame-wizard | /app/models/item/master_key.rb | UTF-8 | 1,049 | 2.734375 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | class Item::MasterKey < Doodad
attr_accessor :tried
def initialize
super
@tried = false
end
def pick_up
@tried = true
'The <strong>master_key</strong> is behind a <strong>glass_pane</strong>. The <strong>goblin</strong> won’t allow me anywhere near the original one.'
end
def duplicate
... | true |
33b68fe89326a29c0aaef0ff4da0e676b45c132d | Ruby | chrislintw/practice_react_socket_redis_golang | /test.rb | UTF-8 | 784 | 2.890625 | 3 | [] | no_license | require 'json'
require 'redis'
$r = Redis.new
def test
i=1
rooms = []
loop do
sleep(rand())
if (rooms.count < 12 )
data = {action:'roominfo',room:{"Id" => i, "Title" => 'hello'+i.to_s,"Limit" => 6,"People" => rand(1..6)}}.to_json
$r.PUBLISH 'lobby', data
rooms << i
i+=1
end
... | true |
4a2b3d6593c3772f493cda96f49265d90c7c73ae | Ruby | znamenica/dneslov | /app/models/concerns/languageble.rb | UTF-8 | 5,612 | 2.65625 | 3 | [
"MIT"
] | permissive | module Languageble
extend ActiveSupport::Concern
def self.included base
base.extend(ClassMethods)
end
# :nodoc:
LANGUAGE_TREE = {
ру: %i(РП РУ),
др: %i(ДР),
цс: %i(ЦС РП РУ ЦР),
сс: %i(СС ЦР),
мс: %i(МСК МСЛ КМСК КМСЛ),
сц: :СЦ,
ук: :УК,
бл: :БЛ,
... | true |
b47ea63fd82275b9e0df951166528fd8087ee1bd | Ruby | MatthewTLackey/RubyMonk | /Keprekar Number.rb | UTF-8 | 578 | 3.453125 | 3 | [] | no_license | def kaprekar?(k)
squared = k**2
n = squared.to_s.length
num_string = squared.to_s
num_string.split('')
left = Array.new
right = Array.new
counter = 0
until counter == n / 2
left << num_string[counter]
counter += 1
end
puts left
until counter == (n + 1)
right << num_string[counter]
... | true |
f8d4373a2be574238a68a7f36f0da72328e85be1 | Ruby | D3icidal/AdventOfCode_2017 | /advent3_p2.rb | UTF-8 | 4,357 | 3.40625 | 3 | [] | no_license | require 'matrix'
puzzleInput = 325489
boardSize = (Math.sqrt(puzzleInput).ceil)+2
# arrayBoard = Array.new(boardSize){Array.new(boardSize)} #=> [[nil, nil], [nil, nil], [nil, nil]]
# arrayBoard index represents the number (so skip 0), with the values as polar cord
# row, col, default_value = 5, 4, 0
# arr_2d = Array.... | true |
168d8543089b163b7a3aa8d8c53f0f5830b389d8 | Ruby | RemyRamirez/BetterMotherFuckingWebsite | /exo_14.rb | UTF-8 | 157 | 2.96875 | 3 | [] | no_license | puts "Donnez moi un nombre"
puts ">"
rebours = gets.to_i
loop do
puts "#{rebours}"
rebours -= 1
if rebours == 0
break
end
end
| true |
86d8c9868fffb90659fb05cfbb373ddd14f889c5 | Ruby | hoov/ffi-rzmq | /lib/ffi-rzmq/util.rb | UTF-8 | 3,013 | 2.796875 | 3 | [
"MIT"
] | permissive |
module ZMQ
# These methods don't belong to any specific class. They get included
# in the #Context, #Socket and #Poller classes.
#
module Util
# Returns the +errno+ as set by the libzmq library.
#
def errno
LibZMQ.zmq_errno
end
# Returns a string corresponding to the currently set ... | true |
5db8f10b6fb4748b43a9fb00941a32786d68e08c | Ruby | Jimlian/programming-exercise | /13-nn.rb | UTF-8 | 231 | 3.921875 | 4 | [] | no_license | # 题目: 输入一个数字 N,输出 N * N 乘法表
print "请输入数字 N,然后按 Enter: "
n = gets.to_i
b =1
while ( b <= n )
h =1
while ( h <= n )
puts "#{b} * #{h} = #{b*h}"
h += 1
end
b +=1
end
| true |
d4caeec125dd5ceb96327d6895b5b50824b5aa2f | Ruby | arquitecturas-concurrentes/iasc-traditional-concurrency-sample-scrapper-ruby | /src/github_broken_worker.rb | UTF-8 | 1,353 | 2.9375 | 3 | [] | no_license | def run_worker(queue_link, headers, data)
table = data
while true
link = queue_link.pop
if link.eql? 'STOP_WORKER'
puts "Stopping worker id #{Thread.current.object_id}"
Thread.current.kill
end
complete_link = "https://github.com#{link}"
puts "Getting link #{complete_link} by worker... | true |
c2df32940d6b95edb738bc6b32b95407e4af635d | Ruby | SagarikaPaul/Basic-Ruby | /City.rb | UTF-8 | 702 | 3.578125 | 4 | [] | no_license | dial_book = {
"kolkata" => "003",
"bengalore" => "004",
"pune" => "005",
"mumbai" => "006",
"nagpur" => "007",
"noida" => "008"
}
def get_city_names(somehash)
somehash.keys
end
def get_area_code(somehash, key)
somehash[key]
end
loop do
puts "Do you want to lookup an area code based on a city name?(... | true |
71f080a482065c55029ab5f5b39d1f25f7824d42 | Ruby | FuePi/iOSprovisioningprofiles | /mobileprovisioning.rb | UTF-8 | 3,745 | 2.90625 | 3 | [] | no_license | #!/usr/bin/ruby
require "rubygems"
require "plist"
require "openssl"
require "optparse"
def ensure_file_specified_and_exists(name, file)
raise OptionParser::MissingArgument, name if file.nil?
raise OptionParser::InvalidArgument, "'#{file}' #{name} file doesn't exists" if not File.exists?(file)
end
def parse_comma... | true |
90103501f1a78a1ad3fc35e730e40c2286dbb932 | Ruby | tansaku/takeaway-3 | /lib/invitraunt.rb | UTF-8 | 2,615 | 3.765625 | 4 | [] | no_license | require_relative 'my_inject'
require 'rubygems'
require 'twilio-ruby'
class Invitraunt
def initialize
@full_order = []
end
attr_reader :full_order
def total_price
corresponding_prices.my_inject { |net_price, item| net_price + item }
end
def corresponding_prices
full_order.map {|dish| dishes[dish] }
... | true |
3900e7140020980e3a7b3a6a299959d4a4d08d76 | Ruby | barjit/learn_ruby_test_first | /08_book_titles/book.rb | UTF-8 | 320 | 3.609375 | 4 | [] | no_license | class Book
attr_accessor :title
def title=(name_of_book)
little_words = ["and", "or", "in", "on", "of", "the", "over", "under", "a", "an"]
words = name_of_book.split(" ").each{|word| little_words.include?(word) ? word : word.capitalize!}
words[0].capitalize!
@title = words.join(" ")
end
end
| true |
d112581c6c74690c5610045f21a1f396a74c2ed6 | Ruby | R-ed/RPG-Game-Prototype | /Episode1/Mechanics/(Tactical Combat) GTBSv2_4_Release1/Scripts/[GTBS] Window_Revive.rb | UTF-8 | 3,514 | 2.5625 | 3 | [] | no_license | #===============================================================================
# TBS_Window Revive - Used to revive dead actors when removed from map.
#===============================================================================
class TBS_Window_Revive < TBS_Window_Selectable
#-----------------------------------... | true |
5417cdc0f629df20364dd77a3282309d4bbe0b92 | Ruby | sarahharrs/rspec-fizzbuzz-online-web-prework | /fizzbuzz.rb | UTF-8 | 124 | 3.421875 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def fizzbuzz(int)
if int % 3 == 0
puts "Frizz"
elsif int % 5 ==0
puts "Buzz"
elsif int % 3==0 & 5==0
puts "FrizzBuzz"
end
| true |
ea24534868f427a3481ad4d8add316377486d55e | Ruby | pleyvaco89/array-CRUD-lab-onl01-seng-ft-061520 | /lib/array_crud.rb | UTF-8 | 1,111 | 3.515625 | 4 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | def create_an_empty_array
[]
end
def create_an_array
card_faces = ["spades", "clovers", "hearts", "diamonds"]
end
def add_element_to_end_of_array(array, element)
card_faces = ["spades", "clovers", "hearts", "diamonds"]
card_faces << "arrays!"
end
def add_element_to_start_of_array(array, element)
card_faces = ["spa... | true |
67dad98bc554014f7be340ada195bf602fd917cc | Ruby | bhserna/guests | /lib/leads.rb | UTF-8 | 1,221 | 2.796875 | 3 | [] | no_license | module Leads
def self.register_form
Form.new
end
def self.register_lead(data, store)
form = Form.new(data)
if form.errors.any?
RegistrationError.new(form)
else
store.save(data)
RegistrationSuccess.new
end
end
class RegistrationError
attr_reader :form
def initia... | true |
dd6ad0e25aa1a3db6cf589f5b6642b8f899d6319 | Ruby | Brown-University-Library/relevancy-tests | /spec/default_search_spec.rb | UTF-8 | 3,763 | 2.578125 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
describe "Default search" do
describe "Popular items" do
it "Should match popular items" do
default_search('b3340555', 'Pubmed', 3)
end
end
describe "Titles" do
it "Should match partial titles" do
default_search('b2041590', 'remains of the day', 10)
default_s... | true |
0a096800eb71cb0fe55b3ea8db3edbcafece7dd7 | Ruby | lovemercybiz/App-Academy | /practice-problems-2/no_comments/01_no_repeats.rb | UTF-8 | 359 | 3.609375 | 4 | [
"MIT"
] | permissive | def no_repeat?(year)
yearArr = year.to_s.split('').uniq
if year != yearArr.join.to_i
return false
else
return true
end
end
#p no_repeat?(1234)
def no_repeats(year_start, year_end)
years = (year_start..year_end).to_a
answer = []
for i in years
if no_repeat?(i) == true
answer <... | true |
e69e1cc35e580883fba7ec2b189818c2d1817e10 | Ruby | vova/utel | /lib/utel/balance.rb | UTF-8 | 889 | 2.6875 | 3 | [] | no_license | module Utel
class Balance
class << self
[:summary, :vas].each{|method| define_method(method) { new.send(method) }}
end
def summary
call_ussd "*100#"
end
def vas
call_ussd "*121#"
end
private
# @param [String] number USSD number service
def call_ussd number
... | true |
a9b7485f9a36c00ad7643fe45f231a3cef648428 | Ruby | JOlivier92/W2D3 | /Poker/spec/card_spec.rb | UTF-8 | 508 | 3.09375 | 3 | [] | no_license | require 'card.rb'
RSpec.describe Card do
#object that contains two values (type and suit)
card = Card.new
assign_card = Card.new(0,0)
describe "#initialize" do
it "initializes randomly if not passed values" do
expect(Card::TYPES.include?(card.type)).to eq(true)
expect(Card::SUITS.include?(card.... | true |
7155afc6ddfc82ea5d97aebb647298df15336404 | Ruby | AriT93/aoc2018 | /13/part1.rb | UTF-8 | 3,919 | 3.375 | 3 | [] | no_license | # frozen_string_literal: true
require 'set'
grid = []
File.open('input.txt', 'r').each_line do |line|
grid << line.chomp.split('')
end
p # class Postion
class Position
attr_accessor :x, :y
def initialize(x, y)
@x = x
@y = y
end
def eql?(other)
[@x, @y] == [other.x, other.y]
end
def ins... | true |
3621c4ac45e60ab37950f5996b654e4685225e4c | Ruby | toshiemon18/syoboemon | /lib/syoboemon/query_generator/program_detail_search.rb | UTF-8 | 814 | 2.734375 | 3 | [
"MIT"
] | permissive | #
# Syoboemon::QueryGenerator::ProgramDetailSearch
# included DB class and Json class
#
# DB => コンストラクタに渡されたTitle IDからdb.phpのクエリを生成する
# Json => コンストラクタに渡された番組タイトルからjson.phpのクエリを生成する
module Syoboemon
module QueryGenerator
module ProgramDetailSearch
class DB
def initialize(title_id="")
@tid = title_id.to... | true |
b27c6008f7c556ec59edee5200bc9e01fbad961d | Ruby | vkro/jungle-rails | /app/models/user.rb | UTF-8 | 650 | 2.53125 | 3 | [] | no_license | class User < ActiveRecord::Base
has_secure_password
def self.authenticate_with_credentials(email, password)
User.find_by(email: email.strip.downcase).try(:authenticate, password) || nil
end
validates :first_name, presence: true
validates :last_name, presence: true
validates :email, presence: true
v... | true |
0492dccf78d9c62e7f6b7a5d574387223a333f69 | Ruby | JakeDam/tic-tac-toe | /board.rb | UTF-8 | 1,284 | 3.703125 | 4 | [] | no_license | # frozen_string_literal: true
# Board class keeps track of state of the board during the game
class Board
WIN_COMBOS = [
[[0, 0], [0, 1], [0, 2]],
[[1, 0], [1, 1], [1, 2]],
[[2, 0], [2, 1], [2, 2]],
[[0, 0], [1, 0], [2, 0]],
[[0, 1], [1, 1], [2, 1]],
[[0, 2], [1, 2], [2, 2]],
[[0, 0], [1,... | true |
bce8bb88c7d14eb74655a4e953432bf8cd5a78cb | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/bob/5f9c6592caeb4858ae6d08deefa848cd.rb | UTF-8 | 693 | 3.625 | 4 | [] | no_license | class Bob
def hey(hotair)
retort Phrase.new(hotair)
end
def retort(to_phrase)
case
when to_phrase.silent? then 'Fine. Be that way!'
when to_phrase.questioning? then 'Sure.'
when to_phrase.exclaiming? then 'Whoa, chill out!'
else 'Whatever.'
end
end
end
class Ph... | true |
85ed4f12c9e526fbf1ca6b5fbd08e3810bf46aa8 | Ruby | sans-pulp/ruby-math-game | /players.rb | UTF-8 | 166 | 3.109375 | 3 | [] | no_license | class Players
attr_accessor :score, :name
def initialize(name, score=3)
@name = name
@score = score
end
def decrement_score
@score -= 1
end
end
| true |
440df4b95b48fc35e1f5645b6f7d795110698f87 | Ruby | atae/App-Academy-Work | /w1d3/recursion.rb | UTF-8 | 3,137 | 3.546875 | 4 | [] | no_license | require "byebug"
def range(start_num,end_num)
return [] if end_num < start_num
return [end_num] if start_num == end_num
range(start_num, end_num-1) + [end_num]
end
def range_it(start_num, end_num)
(start_num..end_num).to_a
end
def exp1(base, exp)
return 1 if exp == 0
base * exp1(base,exp-1)
end
def exp... | true |
dc68bbcc1dd735fec2e7b1418b062e3b0b9b7054 | Ruby | dhouglaspedruzzi/microblog-abler | /app/services/follow_user_service.rb | UTF-8 | 908 | 2.640625 | 3 | [] | no_license | class FollowUserService
def initialize user_id, user_to_follow_id
@user = User.find_by id: user_id
@user_to_follow = User.find_by id: user_to_follow_id
end
def call
return OpenStruct.new success?: false, error: 'Usuário não encontrado!' unless @user && @user_to_follow
follower = @user_to_follow.... | true |
e69bf5676d4e1514753dbadf86a6480250b1d34c | Ruby | twfarland/don | /lib/don.rb | UTF-8 | 996 | 3.09375 | 3 | [] | no_license | def renderInner(contentArray)
contentArray.collect {|elem|
if elem.is_a? Array then toHtml elem else elem end
}
end
def renderAttrs(attrHash)
attrHash.collect {|attr, val|
[' ',attr,'="',val,'"']
}
end
def toHtml(arr)
if arr.length == 0 #[]
''
elsif arr[0].is_a? Array #[htmlArra... | true |
4b84f0325b7ad8afc39a5f2b5cb27d776b025a53 | Ruby | njonsson/trapeze | /test/system/classes/with_instance_methods/taking_no_args/returning/an_object/input/bat.rb | UTF-8 | 404 | 3.03125 | 3 | [
"MIT"
] | permissive | class Bat
class Pwop
def initialize
@my_state1 = :something_else_again1
@my_state2 = :something_else_again2
end
end
class Ding
def initialize
@my_state1 = :something_else_entirely1
@my_state2 = :something_else_entirely2
end
end
... | true |
34d9cf5176816f1e0f3ab1465606203bcfeabbbb | Ruby | zjentohlauedy/MBA | /TeamRecords.rb | UTF-8 | 3,967 | 2.59375 | 3 | [] | no_license | class TeamRecords
attr_reader :team, :overall, :division, :league, :home, :road, :points_scored, :points_allowed, :opponents
TeamDivisions = {
'Sabres' => 0, 'Scorpions' => 1, 'Aces' => 2, 'Eclipse' => 3, 'Global' => 4,
'Portsmen' => 0, 'Lightning' => 1, 'Cyclone' => 2, 'Legends' => 3, 'Worl... | true |
c1002bd55b5df39798b84f6642995538ca9dba28 | Ruby | rapid7/rex-exploitation | /lib/rex/exploitation/cmdstager/echo.rb | UTF-8 | 4,457 | 2.734375 | 3 | [
"BSD-3-Clause"
] | permissive | # -*- coding: binary -*-
require 'rex/text'
require 'rex/arch'
require 'shellwords'
module Rex
module Exploitation
class CmdStagerEcho < CmdStagerBase
ENCODINGS = {
'hex' => "\\\\x",
'octal' => "\\\\",
'hex_double_quoted' => "\\x",
'hex_single_quoted' => "\\x",
... | true |
de262737fc1cbdb45bdc3d55dc631ddf854f9487 | Ruby | Hatlen/Hello-world | /club.rb | UTF-8 | 298 | 3.484375 | 3 | [] | no_license | class Club
def initialize
@members = {}
end
def [] (role)
@members[role]
end
def []= (role, person)
if @members[role].nil?
@members[role] = person
elsif @members[role].is_a? String
@members[role] = [ @members[role], person]
else
@members[role].push person
end
end
end
| true |
5f72894b45fdacaf824f99b5b0dc06d906a59c76 | Ruby | cesswairimu/Rubie | /chapter8/star.rb | UTF-8 | 314 | 2.859375 | 3 | [] | no_license | class CelestialBody
attr_accessor :type, :name
end
altair = CelestialBody.new
altair.name = 'Altair'
altair.type ='star'
polaris = CelestialBody.new
polaris.type ='star'
polaris.name = 'Polaris'
vega = CelestialBody.new
vega.type ='star'
vega.name = 'Vega'
puts altair.name, polaris.name, vega.name
| true |
20b9ca9459743dae6d45be6cc77bd8a48197b08c | Ruby | ktonon/cog | /lib/cog/generator.rb | UTF-8 | 5,157 | 2.703125 | 3 | [
"MIT"
] | permissive | module Cog
# This module defines an interface which can be used by generator objects.
# Specifically, it makes it easy to find ERB templates and render them into
# generated source code files, using the {#stamp} method.
#
# @see https://github.com/ktonon/cog#generators Introduction to Generators
module G... | true |
e9759dc4485d95c24e95db9ac1219329a3d268ef | Ruby | ucarion/consistent_hash | /benchmark.rb | UTF-8 | 681 | 3.265625 | 3 | [
"MIT"
] | permissive | require 'benchmark'
def random_string
length = rand(10000).to_i
length.times.map { (('a'..'z').to_a + ('A'..'Z').to_a).sample }.join
end
strings = 1000.times.map { random_string }
def naive_hash(s)
s.chars.reduce(0) { |acc, char| acc * 31 + char.ord }
end
def ruby_hash(s)
h = 0
i = 0
while i < s.bytesiz... | true |
643d1d08fce0eed40e5da77264323ffc5018bc7e | Ruby | EliseJane/algorithm-exercises | /algorithm_exercises/linked_lists/reverse_linked_list_between.rb | UTF-8 | 1,416 | 4 | 4 | [] | no_license | class ListNode
attr_accessor :val, :next
def initialize(val)
@val = val
@next = nil
end
end
def reverse_between(head, m, n)
node_num = 1
dummy = ListNode.new(nil)
middle = head
while node_num < m
dummy = middle
middle = middle.next
node_num += 1
end
dummy.next =... | true |
96fe64977add94866bb04414b87e7c68828403d9 | Ruby | meads58/chitter-challenge | /spec/features/sign_up_spec.rb | UTF-8 | 1,497 | 2.59375 | 3 | [] | no_license | require 'spec_helper'
require_relative './helpers/sign_up.rb'
feature 'In order to use Chitter as a user I want to sign up to the service' do
scenario "adding a new user increases the number of users by 1" do
expect{ sign_up }.to change(User, :count).by(1)
end
scenario "the correct email for the ... | true |
c9d6fa947e790d4e55a87782bcd07fee00508b17 | Ruby | zcfelix/exercise | /basics/rich-game/ruby/1/mechanism/lib/place/land.rb | UTF-8 | 1,056 | 3.140625 | 3 | [] | no_license | class Land < Place
attr_accessor :owner
attr_reader :level, :price
def initialize(price)
@price = price
@level = 0
@owner = nil
end
def visit_by(player)
if (@owner.nil?)
:wait_for_buy
elsif (@owner == player)
:wait_for_upgrade
else
if (player.can_be_punished? && own... | true |
2f29091fddf5bde1ce427dfef8cb9630a0d0bc46 | Ruby | 10kh-at-rb/AppAcademyCurriculum | /ProjectEulerRuby/Problem023/Problem023.rb | UTF-8 | 1,399 | 4.21875 | 4 | [] | no_license | # ---- PROBLEM 23 ---- #
# Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
# If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers.
#
# For example, the proper divisors of 220 are 1, 2, 4, 5, 10,... | true |
3afcd61fc70d7bff9d5f0a2692232440cb17b50b | Ruby | marccmartian/c2-module2 | /week-3/day-3/dad_joke.rb | UTF-8 | 165 | 2.765625 | 3 | [] | no_license | require 'http'
response = HTTP.headers(:accept => "application/json").get('https://icanhazdadjoke.com/')
data = response.parse
puts "The Joke is: "
p data["joke"] | true |
71a63d54c0d74717cb0f815306e8c1fdaa4286bd | Ruby | Crysicia/THPNext-Week-2 | /app/models/item.rb | UTF-8 | 1,117 | 2.796875 | 3 | [] | no_license | # frozen_string_literal: true
# == Schema Information
#
# Table name: items
#
# id :bigint(8) not null, primary key
# original_price :float not null
# has_discount :boolean default(FALSE)
# discount_percentage :integer default(0)
# created_at ... | true |
72efa1b8d3acf8ed40d87451175d46cb5ee001d6 | Ruby | amhursh/web_guesser | /web_guesser.rb | UTF-8 | 560 | 3.046875 | 3 | [] | no_license | require 'sinatra'
require 'sinatra/reloader'
RAND_NUM = rand(101)
def check_guess(guess)
counter_incrementor
if guess == 0
"By the way..."
elsif guess > RAND_NUM && (guess - RAND_NUM) > 5
"Way Too high!"
elsif guess < RAND_NUM && (RAND_NUM - guess) > 5
"Way Too low!"
elsif guess > RAND_NUM
"... | true |
fdf168b3274082a063b1cea760bb421f7130b8c8 | Ruby | vanetix/dns-comparator | /lib/dns-comparator/resolver.rb | UTF-8 | 1,137 | 2.8125 | 3 | [
"MIT"
] | permissive | require 'resolv'
class Resolver
TYPES = {
A: Resolv::DNS::Resource::IN::A,
AAAA: Resolv::DNS::Resource::IN::AAAA,
SRV: Resolv::DNS::Resource::IN::SRV,
MX: Resolv::DNS::Resource::IN::MX,
NS: Resolv::DNS::Resource::IN::NS,
TXT: Resolv::DNS::Resource::IN::TXT,
PTR: Resolv::DNS::Resource::IN:... | true |
aeafc26225228d27193dd38279e189403252a140 | Ruby | zpalmquist/bike_share | /app/models/cart.rb | UTF-8 | 674 | 3.40625 | 3 | [] | no_license | class Cart
attr_reader :contents
def initialize(initial_contents)
@contents = initial_contents || Hash.new(0)
end
def total_count
contents.values.sum
end
def add_item(id)
contents[id.to_s] = contents[id.to_s].to_i + 1
end
def remove_item(id)
contents.delete(id)
contents[id.to_s] ... | true |
eea9bde4fe08d25af0a00405ba762af3d1ed58dc | Ruby | vanderhoop/project_euler_ruby | /problems_01_to_10/euler4.rb | UTF-8 | 497 | 4.0625 | 4 | [] | no_license | # Find largest palindrome made from the product of two
# 3-digit numbers.
def is_palindromic?(num)
num_str = num.to_s
length = num_str.length
return false if length.odd?
first_half = num_str[0..length / 2 - 1]
second_half = num_str[length / 2..-1]
return true if first_half == second_half.reverse
return f... | true |
4977983becd11ea41e6b093d0b33c09185f50a1e | Ruby | GlobalNamesArchitecture/name-spotter | /spec/scientific_name_spec.rb | UTF-8 | 613 | 2.703125 | 3 | [
"MIT",
"LicenseRef-scancode-unknown-license-reference"
] | permissive | describe NameSpotter::ScientificName do
describe ".new" do
it "calculates end_pos" do
find_me = "M. musculus"
name = NameSpotter::ScientificName.new(
find_me, { start_position: 30, scientific_name: "Mus musculus" }
)
expect(name.end_pos).to eq(name.start_pos + find_me.length - 1)
... | true |
46d820f54f19d8b628b06187301869aaa7bc2985 | Ruby | GerganaPetrova/ruby-challenges | /Robot/solution.rb | UTF-8 | 391 | 3.296875 | 3 | [] | no_license | class Robot
attr_reader :current_position, :marked_path
def initialize(start_position)
@current_position = start_position
@marked_path = []
end
def move
@current_position += 1
end
def mark
@marked_path.push current_position
end
end
def robot(start_position = 0, &block)
robo = Robot.... | true |
49b56754fa7547324458f1bbd40669c33d133cc8 | Ruby | szpakk/tdd-connect-four | /spec/connect_four_spec.rb | UTF-8 | 8,014 | 3.15625 | 3 | [] | no_license | require "spec_helper"
require "connect_four"
RSpec.describe Board do
let(:game) { Board.new }
describe "#initialize" do
it "assigns board representation to 'board' variable" do
expect(game.board).to eq([[0,0,0,0,0,0,0]] * 6)
end
it "initializes @turn variable and assigns it value '0'" do
... | true |
06c8060e5bb57cb494beddb2c39b8ce2d475aaab | Ruby | emmanuel/aequitas | /spec/integration/virtus/array/length/range_spec.rb | UTF-8 | 1,704 | 2.5625 | 3 | [
"MIT"
] | permissive | require 'spec_helper'
require 'virtus'
require 'aequitas'
require 'aequitas/virtus_integration'
describe Aequitas::VirtusIntegration::ClassMethods do
let(:class_under_test) do
Class.new do
include Virtus
include Aequitas
attribute :validated_attribute, Array, :length => 1..3
self
en... | true |
d22155fd3a6395a09cd8b766276daaca12160a9f | Ruby | jmc27/ProgrammingAssignment1 | /movie_data.rb | UTF-8 | 2,207 | 3.671875 | 4 | [] | no_license | #Jonathan Chu
#Assignment 1
#MovieData class
class MovieData
attr_accessor :filename, :moviedata, :userdata
#loads data from a file and sets globals
def load_data(filename)
@filename = filename
@moviedata = Hash.new { |hash, key| hash[key] = [0, 0]}
@userdata = Hash.new { |hash, key| hash[key] = []}
numline... | true |
fce2231f02286dc18689bc09f803a795b0d8ebf0 | Ruby | kiddsoftware/srscollector | /app/models/playable_media.rb | UTF-8 | 2,089 | 2.546875 | 3 | [
"LicenseRef-scancode-public-domain",
"MIT",
"Unlicense"
] | permissive | require 'encoding_detector'
class PlayableMedia < ActiveRecord::Base
belongs_to :user
belongs_to :language
has_many :subtitles, dependent: :delete_all
validates :user, presence: true
validates :language, presence: true
validates :kind, presence: true, inclusion: { in: ['audio', 'video'] }
validates :url... | true |
26ee56eaeed28a3e63cfcaad05758bb1e0198a46 | Ruby | Uvalente/oyster-card | /spec/oystercard_spec.rb | UTF-8 | 2,180 | 2.875 | 3 | [] | no_license | # frozen_string_literal: true
require 'oystercard'
describe Oystercard do
let(:station) { double(:station) }
describe '#initialize' do
it 'has a balance of 0 by default' do
expect(subject.balance).to eq(0)
end
end
describe '#topup' do
it { is_expected .to respond_to(:top_up).with(1).argume... | true |
ab724fdbd85dad6fe6429921b21adb31c7da2aa9 | Ruby | Petey101/phase0 | /week-6/bingo-solution.rb | UTF-8 | 6,617 | 4.46875 | 4 | [
"MIT"
] | permissive | # A Nested Array to Model a Bingo Board SOLO CHALLENGE
# I spent [#] hours on this challenge.
=begin
# Release 0: Pseudocode
# Outline:
1. Initialize the BingoBoard class with a board
#Create board Instance variable here
2. Create a method to generate a letter ( b, i, n, g, o) and a number (1-100)
#Create instance v... | true |
af0e4db167f1ec8ad4f3a5ab07e35e50a38e4ba8 | Ruby | adamcreed/Texas-Hold-em | /lib/app.rb | UTF-8 | 1,151 | 3.046875 | 3 | [] | no_license | require_relative 'deck'
require_relative 'player'
require_relative 'table'
def main
deck, players, table = start_game
start_hand players: players, deck: deck, table: table
end
def start_game
deck = Deck.new
players = Array.new(9) { Player.new }
table = Table.new
[deck, players, table]
end
def start_hand... | true |
944ac0149d5ad5fdd1bb264d7052212171133136 | Ruby | ccedacero/active-record-associations-tvland-lab-nyc04-seng-ft-041920 | /app/models/actor.rb | UTF-8 | 464 | 2.640625 | 3 | [
"LicenseRef-scancode-unknown-license-reference",
"LicenseRef-scancode-public-domain"
] | permissive | class Actor < ActiveRecord::Base
has_many :characters
has_many :shows, through: :characters
def full_name
first = self.first_name
last = self.last_name
full = first + " " + last
end
def list_roles
arr = []
Character.all.map do |character|
if character.actor == self
name = c... | true |
ef19c237298fc098681c1c55affdd48d1eee75d2 | Ruby | TheGuth/launch_school | /Ruby_exercises/challenges/easy_1/word_count.rb | UTF-8 | 565 | 4.15625 | 4 | [] | no_license | # For example, if we count the words for the input "olly olly in come free", we should get:
# olly: 2
# in: 1
# come: 1
# free: 1
class Phrase
def initialize(words)
@words = words
end
def word_count
count = Hash.new(0)
@words.scan(/\b[\w']+\b/) do |word|
count[word.downcase] += 1
end
... | true |
e33c18f14b278cd81c10001e136fc132d39b3c50 | Ruby | PopularDemand/doggie-treats-austin | /app/models/scraper.rb | UTF-8 | 246 | 2.875 | 3 | [] | no_license | class Scraper
def initialize
@agent = Mechanize.new
end
def scrape(url)
@agent.get(url)
end
def get_image(url)
page = self.scrape(url)
unless page.images.empty?
page.images[0]
else
[]
end
end
end | true |
1b7cbdebca7b4b3658fd2671e8203513e115c028 | Ruby | dmattes/static-gmaps | /lib/static_gmaps.rb | UTF-8 | 6,995 | 2.578125 | 3 | [
"MIT"
] | permissive | # The MIT License
#
# Copyright (c) 2008 John Wulff <johnwulff@gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to... | true |
df24c6a89631a4c3e4974b3fe4c7a9f8f42b8a58 | Ruby | MITSURUYAMAZAKI/furima-33064 | /spec/models/buy_spec.rb | UTF-8 | 4,067 | 2.859375 | 3 | [] | no_license | require 'rails_helper'
RSpec.describe Buy, type: :model do
describe 'クレジットカード情報・配送先情報の保存' do
before do
user = FactoryBot.create(:user)
item = FactoryBot.build(:item)
item.user.email = "test@test"
item.save
@buy = FactoryBot.build(:buy, user_id: user.id, item_id: item.id)
sleep... | true |
ec772cdd135cc3071525c463a0d5c830ecf458bd | Ruby | indspenceable/maquis-ruby | /app/actions/trade.rb | UTF-8 | 1,463 | 3.21875 | 3 | [] | no_license | class Trade
def initialize(u1, u2, prev, &blk)
@u1, @u2 = u1, u2
@prev_action = prev
@index = 0
@cu, @ou = u1, u2
toggle_current_unit! unless @cu.inventory.any?
@i1, @i2 = @u1.inventory.dup, @u2.inventory.dup
@next_action = blk
end
def draw(window)
window.show_trade(@u1, @u2, hig... | true |
5795d8abf22d7ba143159bc3354346674322acb8 | Ruby | dsmcclain/Orbit | /Classes/Sector.rb | UTF-8 | 964 | 3.515625 | 4 | [] | no_license | class Sector
attr_accessor :location, :item
def initialize(location, item)
@location = location
@item = item
end
def arrive_at_sector(astronaut)
puts "You have arrived at sector #{location}!"
sleep(1)
discover_item(astronaut)
end
private
def discover_item(astronaut)
genera... | true |
8b59a4efcbf0cd7f4854cc634d38c44e0cb48de9 | Ruby | sameehkhan/W2D1 | /inheritance.rb | UTF-8 | 878 | 3.359375 | 3 | [] | no_license | class Employee
attr_reader :name :boss
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)
super(name, title, ... | true |
2f9ec9b913949479d10657be9c2f4a7d2caf8d3d | Ruby | denispolicarpocampos/exercism-ruby | /pascals-triangle/pascals_triangle.rb | UTF-8 | 346 | 3.65625 | 4 | [] | no_license | class Triangle
attr_reader :rows
def initialize(n_rows)
@rows = n_rows.times.map do |row|
(row+1).times.map { |col| Triangle.binomial(row, col) }
end
end
private
def self.binomial(n, k)
factorial(n) / (factorial(k) * factorial(n - k))
end
def self.factorial(n)
n == 0 ? 1 : 1.up... | true |
c60961a9622fb3cc39bde3aa6b10e316483be473 | Ruby | Zlatov/lab | /ruby/file/file_path.rb | UTF-8 | 2,075 | 2.828125 | 3 | [] | no_license | # encoding: UTF-8
require "awesome_print"
require "pathname"
# Путь к текущему файлу
puts 'Путь к текущему файлу'.green
print 'Dir.pwd: '.red; puts Dir.pwd
print '$0: '.red; puts $0
print '__FILE__: '.red; puts __FILE__
print '__dir__: '.red; puts __dir__
#
# __FILE__ равен $0 при запуске из sublime, но
# не всегда... | true |
67fb163792fa8a5a667037ac83bbe066cfc1bebe | Ruby | a-e/jiraby | /spec/json_resource_spec.rb | UTF-8 | 6,705 | 2.609375 | 3 | [
"MIT"
] | permissive | require_relative 'spec_helper'
require 'jiraby/jira'
require 'jiraby/json_resource'
describe Jiraby::JSONResource do
before(:each) do
@jr = Jiraby::JSONResource.new('http://example.com')
end
describe "#initialize" do
# Ensure that `options` contains appropriate JSON headers
def should_include_json_h... | true |
8df21b42641806cf6ac9e580fce5e50473457e78 | Ruby | poymanov/railswinter2017 | /np2/lesson31/task-31-05/main.rb | UTF-8 | 1,098 | 3.359375 | 3 | [] | no_license | # encoding: utf-8
require_relative 'lib/clothes_collection'
require_relative 'lib/clothing'
current_path = File.dirname(__FILE__)
clothes_path = current_path + "/data"
# Одежда из каталога
clothes_collection = ClothesCollection.new(clothes_path)
puts "Сколько градусов за окном? (можно с минусом)"
temperature = STDI... | true |
ab11220a956864edb121e5ea28e7bc762e370272 | Ruby | jackross/threequel | /lib/threequel/sql/statement_array.rb | UTF-8 | 2,031 | 2.59375 | 3 | [
"MIT"
] | permissive | module Threequel
module SQL
class StatementArray < Array
def initialize(unsanitized_sql, name = 'Anonymous SQL Block', opts = {})
@unsanitized_sql, @name = unsanitized_sql, name
@opts = opts.reverse_merge(default_opts)
@statement_terminator = @opts[:statement_ter... | true |
89d39da29bdbced7e10d1dfb1cccb39addfb5553 | Ruby | mlee1974/sea-c17-ruby | /class3/4_leap_years.rb | UTF-8 | 734 | 4.34375 | 4 | [] | no_license | # Section 7.5 on page 49
# 4 points
#
# Write a program that asks for a starting year and an ending year and then puts
# all the leap years between them (and including them, if they are also leap
# years). Leap years are years divisible by 4 (like 1984 and 2004). However,
# years divisible by 100 are not leap years (su... | true |
c0e29b5c5aab4caa6cb5fe1215a3d5b8b36e1cec | Ruby | koba-e964/lib-number | /detail/lenstra_elliptic_factor.rb | UTF-8 | 2,481 | 3.28125 | 3 | [] | no_license | require_relative "../ell.rb"
require_relative "../prime_util.rb"
def lenstra_elliptic_get_factor_one(n, b = 100, debug_level = 1)
curve = [n, rand(n)]
pt = [rand(n), rand(n)]
cur = pt
ctrial = 0
begin
mul(curve, pt, n)
for k in 2 .. b
ctrial = k
cur = mul(curve, cur, k)
if debug_le... | true |
e14b32bb1d2b1584b056b3855a0cabab91e2651e | Ruby | FHappy/Project-Euler-Exercises | /median_of_sorted.rb | UTF-8 | 838 | 4.15625 | 4 | [] | no_license | # PROMPT
# Find the median of two sorted arrays
def find_median(arr1, arr2)
# determine index value of median element
median_index = ((arr1.length + arr2.length) / 2.0).round
stitched = []
# merge in order until length of the merged and sorted array is enough to
# calculate the median
while arr1.length ... | true |
d41f25a663adbc180ecaddb7b8cd97274c26856d | Ruby | ckahn/aa-course | /w2d5/lib/poker/deck.rb | UTF-8 | 634 | 3.390625 | 3 | [] | no_license | require_relative 'card'
class Deck
attr_accessor :size, :cards
def initialize
@cards = Array.new(52) { Card.new }
init_cards
end
def distribute_card
card = @cards.sample
cards.delete_at(@cards.index(card))
card
end
def init_cards
@cards.each_with_index do |card,idx|
if idx ... | true |
e2dc50d1a156f2ac5a6a09c4c840ef91c36000a6 | Ruby | itsolutionscorp/AutoStyle-Clustering | /all_data/exercism_data/ruby/hamming/61bb0f1cb2314b2aadb9d4d984a71905.rb | UTF-8 | 700 | 3.46875 | 3 | [] | no_license | class Hamming
def self.compute (s,t)
counter = 0
if s.length == t.length
t.split('').each_with_index do |i,k|
if i != s[k]
counter += 1
end
end
elsif s.length > t.length
t.split('').each_with_index do |i,k|
if i != s[k]
counter += 1
end
end
else
s.split('').each_with_in... | true |
c37bf3279db5c74b657b1e8727662653beb1ce2d | Ruby | funwithcthulhu/exercism-solutions | /ruby/strain/strain.rb | UTF-8 | 452 | 2.953125 | 3 | [] | no_license | # Re-implementing #select and #reject
class Array
def keep
return to_enum(__method__) { size } unless block_given?
new_array = []
self.size.times do |x|
new_array << self[x] if yield self[x]
end
new_array
end
def discard
return to_enum(__method__) { size } unless block_given?
... | true |
52f85009b8cc70ceb8dac8c94ac1db21c48fde98 | Ruby | YeeTix/BST | /Binary Tree Search/BST.rb | UTF-8 | 712 | 3.34375 | 3 | [] | no_license | #Binary Tree Search
#31/03/18
#Alex
#University of Quebec in Chicoutimi - Computer Science
class BinaryTreeSearch
class Node
attr: key,:left,:right
def createNode(key)
@key = key
@left = nil
@right = nil
end
def insert(new_key)
if newKey <= @key
@left.nil ? @left = Node.new... | true |
26b092b2603f9797ae3764341ebb57abb59a2c82 | Ruby | carmenlogue/micropop_v2 | /lib/tasks/data_import.rake | UTF-8 | 1,137 | 2.609375 | 3 | [] | no_license | require 'csv'
namespace :data_import do
desc 'import data from csv to local DB'
task :from_csv_to_db => :environment do
# Prepare DB to index poems for elasticsearch
Artist.reindex
Song.reindex
Tag.reindex
Poem.includes({ song: :artist }, :categories, :tags).reindex
CSV.foreach('excel_data... | true |
3d688798aebbf9957d1e0b7aca7261c20bf817b0 | Ruby | iankigen/tit_tac_toe | /spec/tic_tac_toe_spec.rb | UTF-8 | 990 | 3.125 | 3 | [
"MIT"
] | permissive | RSpec.describe Game do
it 'has a version number' do
expect(TicTacToe::VERSION).not_to be nil
end
it 'initialize a new game' do
player = Game.new
expect(player.grid).to eq [' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
expect(player.positions).to eq %w[1 2 3 4 5 6 7 8 9]
expect(player.player_1... | true |
b9b34542bcb5ae80d4527b238d189f32c5752c5c | Ruby | BaihongQi/Tracking_items | /tracking2.rb | UTF-8 | 3,399 | 2.703125 | 3 | [] | no_license | require 'spreadsheet'
require './helpers'
require 'csv'
require 'optparse'
def mysql_query(connection,query)
begin
rs = connection.query(query)
rescue Exception => e
raise e
raise e if /Mysql::Error: Duplicate entry/.match(e.to_s)
end
end
options = {}
OptionParser.new do |opts|
opts.on("-f", "... | true |
a573e7f6d62050198d76346bcabee583e32ab756 | Ruby | J-Y/RubyQuiz | /ruby_quiz/quiz27_sols/solutions/Matthew D Moss/knights_travails.rb | UTF-8 | 2,182 | 4.03125 | 4 | [
"MIT"
] | permissive | #!/usr/bin/env ruby
# Helper class
class Tile
attr_reader :x, :y
protected :x, :y
def initialize(x, y)
@x, @y = x, y
end
def Tile.named(s)
Tile.new(s.downcase[0] - 'a'[0], s.downcase[1] - '1'[0])
end
def valid?
(0...8) === @x and (0...8) === @y
end
def to_s
to_str
end
def to_str
%w(a b c d ... | true |
08a34c6ab784c8b22850147bd862ea1fb17d617d | Ruby | trizen/sidef | /scripts/Tests/word_wrap_enumerator.sf | UTF-8 | 750 | 3.46875 | 3 | [
"Artistic-2.0"
] | permissive | #!/usr/bin/ruby
#
## Code from: http://ruby-doc.org/core-2.3.1/Enumeratorerable.html
#
func wordwrap(words, maxwidth) {
Enumerator({|y|
var cols = 0
words.slice_before { |w|
cols += 1 if (cols != 0)
cols += w.len
if (maxwidth < cols) {
cols = w.len
true
}
else {... | true |
91c98ead46fe5876e5958c369a5241334526d4ab | Ruby | mmkarim/buy_sell_api_app | /app/models/balance.rb | UTF-8 | 432 | 2.734375 | 3 | [] | no_license | class Balance < ApplicationRecord
belongs_to :user
validates :amount, numericality: { greater_than_or_equal_to: 0.0 }
CASH_TO_GOLD_RATE = 0.1
GOLD_TO_CASH_RATE = 10
def deduct_amount! value
return false if value > self.amount
self.with_lock do
self.amount -= value
self.save!
end
e... | true |
10eb1e608032ae46c5c405c7684a9843ee80feec | Ruby | rvachon1/rb101 | /exercises/medium1/rnd2/diamonds.rb | UTF-8 | 1,083 | 4.4375 | 4 | [] | no_license | =begin
Problem:
-Make a 4 pointed diamond with n rows
Rules:
-N is always odd
- middle row has n stars
- starts with 1 star, each row grows by 2 until middle, then shrinks by two until 1
ALGO:
-Print Top half
-spaces = n - stars
-stars = 1
-Loop
- Print spaces / 2 + stars + spaces / 2
- stars += 2
... | true |
30e02952cca3953f63dec07045eba654d429804b | Ruby | looping124/12_mini_jeu_POO | /app_2.rb | UTF-8 | 2,553 | 3.453125 | 3 | [] | no_license | require 'bundler'
Bundler.require
require_relative 'lib/player'
require_relative 'lib/game'
system ('clear')
puts "------------------------------------------------"
puts "|Bienvenue sur 'ILS VEULENT TOUS MA POO' ! |"
puts "|Le but du jeu est d'être le dernier survivant !|"
puts "---------------------------------... | true |
ae682ecc2761707e158bca0f163a5c3c193f9eca | Ruby | louismrose/coco-transform | /lib/tasks/clean_resources.rake | UTF-8 | 578 | 2.5625 | 3 | [] | no_license | namespace :resources do
desc "Deletes transient resources that were not updated in the last 48 hours"
task :clean => :environment do
transient_resources.each do |resource|
delete_expired(resource)
end
end
def transient_resources
[Instance]
end
def delete_expired(resource)
expired... | true |
15e6f39d7ed80ed768861c121d348743670bdaf1 | Ruby | zhangxue/searchgasm | /lib/searchgasm/core_ext/hash.rb | UTF-8 | 731 | 2.640625 | 3 | [
"MIT"
] | permissive | module Searchgasm
module CoreExt # :nodoc: all
module Hash
def deep_dup
new_hash = {}
self.each do |k, v|
case v
when Hash
new_hash[k] = v.deep_dup
else
new_hash[k] = v
end
end
new_hash
en... | true |
d2475be29d1d41076e791ca343408d1248f0ca48 | Ruby | SinkLineP/RubyOnRails-18.08.2021 | /Ruby on Rails/repozitories/ruby_development/ruby artem/projects/bak/4/MyApp1/app2.rb | IBM866 | 377 | 3.109375 | 3 | [] | no_license | # encoding: cp866
print "쪮 ࠧ 㤥 : "
nanno = gets.to_i
nanno.times do |x|
puts ": #{x+1}"
print" : "
num = gets.to_i
x = rand(1..3)
if x == num
puts " 㣠"
puts "============="
else
puts " நࠫ"
puts "============="
end
end
| true |
7c2ad4f1441b485975092721eeb23a85bbd30b3a | Ruby | jkopczyn/AssortedSnippets | /trie/wordsconcat.rb | UTF-8 | 3,076 | 3.46875 | 3 | [] | no_license | require 'set'
require 'byebug'
class Trie
attr_accessor :word_nodes, :root, :concatenated_words
def initialize
@root = TrieNode.new(trie: self, word_present: false)
@word_nodes = {}
@concatenated_words = Set.new
end
def add_word(word)
@root.add_word(word)
end
def import_words(word_list)
... | true |
a16a13fc2d10a012041aa4029d8fe6e4cbf34d28 | Ruby | DanielFarber/wdi | /w01/d01/Classwork/driverless/runner.rb | UTF-8 | 145 | 3.40625 | 3 | [] | no_license | puts "How much gas?"
gas = gets.chomp.to_i
while gas > 0
# puts "gas = #{gas}"
gas -= 1
puts "running..."
puts "car shut down" if gas <= 0
end | true |
63d68c2ae5eb0ba492ea78089704787ad9039f4e | Ruby | kaitlynfox/enigma | /spec/enigma_spec.rb | UTF-8 | 3,447 | 3.078125 | 3 | [] | no_license | require './lib/enigma'
RSpec.describe Enigma do
it "exists" do
enigma = Enigma.new
expect(enigma).to be_an(Enigma)
end
it "can have a character set of defined characters" do
enigma = Enigma.new
expected = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r"... | true |
c117b0f960bc39ea2a066ce95086e1ed3bdce286 | Ruby | C-gyorfi/X3-WordWrapKata | /WordWrap01/WordWrapTest.rb | UTF-8 | 1,001 | 3.046875 | 3 | [] | no_license | require "rspec/autorun"
require_relative './WordWrap'
describe "the wrap function" do
it "returns empty string when called with nothing" do
expect(wrap("", 1)).to eq("")
end
it "returns the word if shorter than the length" do
expect(wrap("word", 5)).to eq("word")
end
it "splits 2 words on the space... | true |
af21d5f076bc381f85acf93b956018608d1a0aae | Ruby | preetamreddy/bookingmegham | /app/models/taxi.rb | UTF-8 | 981 | 2.546875 | 3 | [] | no_license | class Taxi < ActiveRecord::Base
belongs_to :agency
has_many :taxi_bookings
validates :agency_id, :model, :max_passengers, :unit_price, presence: true
validates_numericality_of :max_passengers, allow_nil: true,
only_integer: true, greater_than: 0,
message: "should be a number greater than 0"
validates_numeric... | true |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.